]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/doc/gdb.texinfo
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / doc / gdb.texinfo
1 \input texinfo @c -*-texinfo-*-
2 @c Copyright (C) 1988--2021 Free Software Foundation, Inc.
3 @c
4 @c %**start of header
5 @c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
6 @c of @set vars. However, you can override filename with makeinfo -o.
7 @setfilename gdb.info
8 @c
9 @c man begin INCLUDE
10 @include gdb-cfg.texi
11 @c man end
12 @c
13 @settitle Debugging with @value{GDBN}
14 @setchapternewpage odd
15 @c %**end of header
16
17 @iftex
18 @c @smallbook
19 @c @cropmarks
20 @end iftex
21
22 @finalout
23 @c To avoid file-name clashes between index.html and Index.html, when
24 @c the manual is produced on a Posix host and then moved to a
25 @c case-insensitive filesystem (e.g., MS-Windows), we separate the
26 @c indices into two: Concept Index and all the rest.
27 @syncodeindex ky fn
28 @syncodeindex tp fn
29
30 @c readline appendices use @vindex, @findex and @ftable,
31 @c annotate.texi and gdbmi use @findex.
32 @syncodeindex vr fn
33
34 @c !!set GDB manual's edition---not the same as GDB version!
35 @c This is updated by GNU Press.
36 @set EDITION Tenth
37
38 @c !!set GDB edit command default editor
39 @set EDITOR /bin/ex
40
41 @c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
42
43 @c This is a dir.info fragment to support semi-automated addition of
44 @c manuals to an info tree.
45 @dircategory Software development
46 @direntry
47 * Gdb: (gdb). The GNU debugger.
48 * gdbserver: (gdb) Server. The GNU debugging server.
49 @end direntry
50
51 @copying
52 @c man begin COPYRIGHT
53 Copyright @copyright{} 1988-2020 Free Software Foundation, Inc.
54
55 Permission is granted to copy, distribute and/or modify this document
56 under the terms of the GNU Free Documentation License, Version 1.3 or
57 any later version published by the Free Software Foundation; with the
58 Invariant Sections being ``Free Software'' and ``Free Software Needs
59 Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
60 and with the Back-Cover Texts as in (a) below.
61
62 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
63 this GNU Manual. Buying copies from GNU Press supports the FSF in
64 developing GNU and promoting software freedom.''
65 @c man end
66 @end copying
67
68 @ifnottex
69 This file documents the @sc{gnu} debugger @value{GDBN}.
70
71 This is the @value{EDITION} Edition, of @cite{Debugging with
72 @value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
73 @ifset VERSION_PACKAGE
74 @value{VERSION_PACKAGE}
75 @end ifset
76 Version @value{GDBVN}.
77
78 @insertcopying
79 @end ifnottex
80
81 @titlepage
82 @title Debugging with @value{GDBN}
83 @subtitle The @sc{gnu} Source-Level Debugger
84 @sp 1
85 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
86 @ifset VERSION_PACKAGE
87 @sp 1
88 @subtitle @value{VERSION_PACKAGE}
89 @end ifset
90 @author Richard Stallman, Roland Pesch, Stan Shebs, et al.
91 @page
92 @tex
93 {\parskip=0pt
94 \hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
95 \hfill {\it Debugging with @value{GDBN}}\par
96 \hfill \TeX{}info \texinfoversion\par
97 }
98 @end tex
99
100 @vskip 0pt plus 1filll
101 Published by the Free Software Foundation @*
102 51 Franklin Street, Fifth Floor,
103 Boston, MA 02110-1301, USA@*
104 ISBN 978-0-9831592-3-0 @*
105
106 @insertcopying
107 @end titlepage
108 @page
109
110 @ifnottex
111 @node Top, Summary
112
113 @top Debugging with @value{GDBN}
114
115 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
117 This is the @value{EDITION} Edition, for @value{GDBN}
118 @ifset VERSION_PACKAGE
119 @value{VERSION_PACKAGE}
120 @end ifset
121 Version @value{GDBVN}.
122
123 Copyright (C) 1988-2020 Free Software Foundation, Inc.
124
125 This edition of the GDB manual is dedicated to the memory of Fred
126 Fish. Fred was a long-standing contributor to GDB and to Free
127 software in general. We will miss him.
128
129 @menu
130 * Summary:: Summary of @value{GDBN}
131 * Sample Session:: A sample @value{GDBN} session
132
133 * Invocation:: Getting in and out of @value{GDBN}
134 * Commands:: @value{GDBN} commands
135 * Running:: Running programs under @value{GDBN}
136 * Stopping:: Stopping and continuing
137 * Reverse Execution:: Running programs backward
138 * Process Record and Replay:: Recording inferior's execution and replaying it
139 * Stack:: Examining the stack
140 * Source:: Examining source files
141 * Data:: Examining data
142 * Optimized Code:: Debugging optimized code
143 * Macros:: Preprocessor Macros
144 * Tracepoints:: Debugging remote targets non-intrusively
145 * Overlays:: Debugging programs that use overlays
146
147 * Languages:: Using @value{GDBN} with different languages
148
149 * Symbols:: Examining the symbol table
150 * Altering:: Altering execution
151 * GDB Files:: @value{GDBN} files
152 * Targets:: Specifying a debugging target
153 * Remote Debugging:: Debugging remote programs
154 * Configurations:: Configuration-specific information
155 * Controlling GDB:: Controlling @value{GDBN}
156 * Extending GDB:: Extending @value{GDBN}
157 * Interpreters:: Command Interpreters
158 * TUI:: @value{GDBN} Text User Interface
159 * Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
160 * GDB/MI:: @value{GDBN}'s Machine Interface.
161 * Annotations:: @value{GDBN}'s annotation interface.
162 * JIT Interface:: Using the JIT debugging interface.
163 * In-Process Agent:: In-Process Agent
164
165 * GDB Bugs:: Reporting bugs in @value{GDBN}
166
167 @ifset SYSTEM_READLINE
168 * Command Line Editing: (rluserman). Command Line Editing
169 * Using History Interactively: (history). Using History Interactively
170 @end ifset
171 @ifclear SYSTEM_READLINE
172 * Command Line Editing:: Command Line Editing
173 * Using History Interactively:: Using History Interactively
174 @end ifclear
175 * In Memoriam:: In Memoriam
176 * Formatting Documentation:: How to format and print @value{GDBN} documentation
177 * Installing GDB:: Installing GDB
178 * Maintenance Commands:: Maintenance Commands
179 * Remote Protocol:: GDB Remote Serial Protocol
180 * Agent Expressions:: The GDB Agent Expression Mechanism
181 * Target Descriptions:: How targets can describe themselves to
182 @value{GDBN}
183 * Operating System Information:: Getting additional information from
184 the operating system
185 * Trace File Format:: GDB trace file format
186 * Index Section Format:: .gdb_index section format
187 * Man Pages:: Manual pages
188 * Copying:: GNU General Public License says
189 how you can copy and share GDB
190 * GNU Free Documentation License:: The license for this documentation
191 * Concept Index:: Index of @value{GDBN} concepts
192 * Command and Variable Index:: Index of @value{GDBN} commands, variables,
193 functions, and Python data types
194 @end menu
195
196 @end ifnottex
197
198 @contents
199
200 @node Summary
201 @unnumbered Summary of @value{GDBN}
202
203 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
204 going on ``inside'' another program while it executes---or what another
205 program was doing at the moment it crashed.
206
207 @value{GDBN} can do four main kinds of things (plus other things in support of
208 these) to help you catch bugs in the act:
209
210 @itemize @bullet
211 @item
212 Start your program, specifying anything that might affect its behavior.
213
214 @item
215 Make your program stop on specified conditions.
216
217 @item
218 Examine what has happened, when your program has stopped.
219
220 @item
221 Change things in your program, so you can experiment with correcting the
222 effects of one bug and go on to learn about another.
223 @end itemize
224
225 You can use @value{GDBN} to debug programs written in C and C@t{++}.
226 For more information, see @ref{Supported Languages,,Supported Languages}.
227 For more information, see @ref{C,,C and C++}.
228
229 Support for D is partial. For information on D, see
230 @ref{D,,D}.
231
232 @cindex Modula-2
233 Support for Modula-2 is partial. For information on Modula-2, see
234 @ref{Modula-2,,Modula-2}.
235
236 Support for OpenCL C is partial. For information on OpenCL C, see
237 @ref{OpenCL C,,OpenCL C}.
238
239 @cindex Pascal
240 Debugging Pascal programs which use sets, subranges, file variables, or
241 nested functions does not currently work. @value{GDBN} does not support
242 entering expressions, printing values, or similar features using Pascal
243 syntax.
244
245 @cindex Fortran
246 @value{GDBN} can be used to debug programs written in Fortran, although
247 it may be necessary to refer to some variables with a trailing
248 underscore.
249
250 @value{GDBN} can be used to debug programs written in Objective-C,
251 using either the Apple/NeXT or the GNU Objective-C runtime.
252
253 @menu
254 * Free Software:: Freely redistributable software
255 * Free Documentation:: Free Software Needs Free Documentation
256 * Contributors:: Contributors to GDB
257 @end menu
258
259 @node Free Software
260 @unnumberedsec Free Software
261
262 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
263 General Public License
264 (GPL). The GPL gives you the freedom to copy or adapt a licensed
265 program---but every person getting a copy also gets with it the
266 freedom to modify that copy (which means that they must get access to
267 the source code), and the freedom to distribute further copies.
268 Typical software companies use copyrights to limit your freedoms; the
269 Free Software Foundation uses the GPL to preserve these freedoms.
270
271 Fundamentally, the General Public License is a license which says that
272 you have these freedoms and that you cannot take these freedoms away
273 from anyone else.
274
275 @node Free Documentation
276 @unnumberedsec Free Software Needs Free Documentation
277
278 The biggest deficiency in the free software community today is not in
279 the software---it is the lack of good free documentation that we can
280 include with the free software. Many of our most important
281 programs do not come with free reference manuals and free introductory
282 texts. Documentation is an essential part of any software package;
283 when an important free software package does not come with a free
284 manual and a free tutorial, that is a major gap. We have many such
285 gaps today.
286
287 Consider Perl, for instance. The tutorial manuals that people
288 normally use are non-free. How did this come about? Because the
289 authors of those manuals published them with restrictive terms---no
290 copying, no modification, source files not available---which exclude
291 them from the free software world.
292
293 That wasn't the first time this sort of thing happened, and it was far
294 from the last. Many times we have heard a GNU user eagerly describe a
295 manual that he is writing, his intended contribution to the community,
296 only to learn that he had ruined everything by signing a publication
297 contract to make it non-free.
298
299 Free documentation, like free software, is a matter of freedom, not
300 price. The problem with the non-free manual is not that publishers
301 charge a price for printed copies---that in itself is fine. (The Free
302 Software Foundation sells printed copies of manuals, too.) The
303 problem is the restrictions on the use of the manual. Free manuals
304 are available in source code form, and give you permission to copy and
305 modify. Non-free manuals do not allow this.
306
307 The criteria of freedom for a free manual are roughly the same as for
308 free software. Redistribution (including the normal kinds of
309 commercial redistribution) must be permitted, so that the manual can
310 accompany every copy of the program, both on-line and on paper.
311
312 Permission for modification of the technical content is crucial too.
313 When people modify the software, adding or changing features, if they
314 are conscientious they will change the manual too---so they can
315 provide accurate and clear documentation for the modified program. A
316 manual that leaves you no choice but to write a new manual to document
317 a changed version of the program is not really available to our
318 community.
319
320 Some kinds of limits on the way modification is handled are
321 acceptable. For example, requirements to preserve the original
322 author's copyright notice, the distribution terms, or the list of
323 authors, are ok. It is also no problem to require modified versions
324 to include notice that they were modified. Even entire sections that
325 may not be deleted or changed are acceptable, as long as they deal
326 with nontechnical topics (like this one). These kinds of restrictions
327 are acceptable because they don't obstruct the community's normal use
328 of the manual.
329
330 However, it must be possible to modify all the @emph{technical}
331 content of the manual, and then distribute the result in all the usual
332 media, through all the usual channels. Otherwise, the restrictions
333 obstruct the use of the manual, it is not free, and we need another
334 manual to replace it.
335
336 Please spread the word about this issue. Our community continues to
337 lose manuals to proprietary publishing. If we spread the word that
338 free software needs free reference manuals and free tutorials, perhaps
339 the next person who wants to contribute by writing documentation will
340 realize, before it is too late, that only free manuals contribute to
341 the free software community.
342
343 If you are writing documentation, please insist on publishing it under
344 the GNU Free Documentation License or another free documentation
345 license. Remember that this decision requires your approval---you
346 don't have to let the publisher decide. Some commercial publishers
347 will use a free license if you insist, but they will not propose the
348 option; it is up to you to raise the issue and say firmly that this is
349 what you want. If the publisher you are dealing with refuses, please
350 try other publishers. If you're not sure whether a proposed license
351 is free, write to @email{licensing@@gnu.org}.
352
353 You can encourage commercial publishers to sell more free, copylefted
354 manuals and tutorials by buying them, and particularly by buying
355 copies from the publishers that paid for their writing or for major
356 improvements. Meanwhile, try to avoid buying non-free documentation
357 at all. Check the distribution terms of a manual before you buy it,
358 and insist that whoever seeks your business must respect your freedom.
359 Check the history of the book, and try to reward the publishers that
360 have paid or pay the authors to work on it.
361
362 The Free Software Foundation maintains a list of free documentation
363 published by other publishers, at
364 @url{http://www.fsf.org/doc/other-free-books.html}.
365
366 @node Contributors
367 @unnumberedsec Contributors to @value{GDBN}
368
369 Richard Stallman was the original author of @value{GDBN}, and of many
370 other @sc{gnu} programs. Many others have contributed to its
371 development. This section attempts to credit major contributors. One
372 of the virtues of free software is that everyone is free to contribute
373 to it; with regret, we cannot actually acknowledge everyone here. The
374 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
375 blow-by-blow account.
376
377 Changes much prior to version 2.0 are lost in the mists of time.
378
379 @quotation
380 @emph{Plea:} Additions to this section are particularly welcome. If you
381 or your friends (or enemies, to be evenhanded) have been unfairly
382 omitted from this list, we would like to add your names!
383 @end quotation
384
385 So that they may not regard their many labors as thankless, we
386 particularly thank those who shepherded @value{GDBN} through major
387 releases:
388 Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
389 Jim Blandy (release 4.18);
390 Jason Molenda (release 4.17);
391 Stan Shebs (release 4.14);
392 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
393 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
394 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
395 Jim Kingdon (releases 3.5, 3.4, and 3.3);
396 and Randy Smith (releases 3.2, 3.1, and 3.0).
397
398 Richard Stallman, assisted at various times by Peter TerMaat, Chris
399 Hanson, and Richard Mlynarik, handled releases through 2.8.
400
401 Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
402 in @value{GDBN}, with significant additional contributions from Per
403 Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
404 demangler. Early work on C@t{++} was by Peter TerMaat (who also did
405 much general update work leading to release 3.0).
406
407 @value{GDBN} uses the BFD subroutine library to examine multiple
408 object-file formats; BFD was a joint project of David V.
409 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
410
411 David Johnson wrote the original COFF support; Pace Willison did
412 the original support for encapsulated COFF.
413
414 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
415
416 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
417 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
418 support.
419 Jean-Daniel Fekete contributed Sun 386i support.
420 Chris Hanson improved the HP9000 support.
421 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
422 David Johnson contributed Encore Umax support.
423 Jyrki Kuoppala contributed Altos 3068 support.
424 Jeff Law contributed HP PA and SOM support.
425 Keith Packard contributed NS32K support.
426 Doug Rabson contributed Acorn Risc Machine support.
427 Bob Rusk contributed Harris Nighthawk CX-UX support.
428 Chris Smith contributed Convex support (and Fortran debugging).
429 Jonathan Stone contributed Pyramid support.
430 Michael Tiemann contributed SPARC support.
431 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
432 Pace Willison contributed Intel 386 support.
433 Jay Vosburgh contributed Symmetry support.
434 Marko Mlinar contributed OpenRISC 1000 support.
435
436 Andreas Schwab contributed M68K @sc{gnu}/Linux support.
437
438 Rich Schaefer and Peter Schauer helped with support of SunOS shared
439 libraries.
440
441 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
442 about several machine instruction sets.
443
444 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
445 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
446 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
447 and RDI targets, respectively.
448
449 Brian Fox is the author of the readline libraries providing
450 command-line editing and command history.
451
452 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
453 Modula-2 support, and contributed the Languages chapter of this manual.
454
455 Fred Fish wrote most of the support for Unix System Vr4.
456 He also enhanced the command-completion support to cover C@t{++} overloaded
457 symbols.
458
459 Hitachi America (now Renesas America), Ltd. sponsored the support for
460 H8/300, H8/500, and Super-H processors.
461
462 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
463
464 Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
465 processors.
466
467 Toshiba sponsored the support for the TX39 Mips processor.
468
469 Matsushita sponsored the support for the MN10200 and MN10300 processors.
470
471 Fujitsu sponsored the support for SPARClite and FR30 processors.
472
473 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
474 watchpoints.
475
476 Michael Snyder added support for tracepoints.
477
478 Stu Grossman wrote gdbserver.
479
480 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
481 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
482
483 The following people at the Hewlett-Packard Company contributed
484 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
485 (narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
486 compiler, and the Text User Interface (nee Terminal User Interface):
487 Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
488 Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
489 provided HP-specific information in this manual.
490
491 DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
492 Robert Hoehne made significant contributions to the DJGPP port.
493
494 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
495 development since 1991. Cygnus engineers who have worked on @value{GDBN}
496 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
497 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
498 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
499 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
500 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
501 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
502 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
503 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
504 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
505 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
506 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
507 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
508 Zuhn have made contributions both large and small.
509
510 Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
511 Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
512
513 Jim Blandy added support for preprocessor macros, while working for Red
514 Hat.
515
516 Andrew Cagney designed @value{GDBN}'s architecture vector. Many
517 people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
518 Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
519 Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
520 Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
521 with the migration of old architectures to this new framework.
522
523 Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
524 unwinder framework, this consisting of a fresh new design featuring
525 frame IDs, independent frame sniffers, and the sentinel frame. Mark
526 Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
527 libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
528 trad unwinders. The architecture-specific changes, each involving a
529 complete rewrite of the architecture's frame code, were carried out by
530 Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
531 Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
532 Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
533 Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
534 Weigand.
535
536 Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
537 Tensilica, Inc.@: contributed support for Xtensa processors. Others
538 who have worked on the Xtensa port of @value{GDBN} in the past include
539 Steve Tjiang, John Newlin, and Scott Foehner.
540
541 Michael Eager and staff of Xilinx, Inc., contributed support for the
542 Xilinx MicroBlaze architecture.
543
544 Initial support for the FreeBSD/mips target and native configuration
545 was developed by SRI International and the University of Cambridge
546 Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
547 ("CTSRD"), as part of the DARPA CRASH research programme.
548
549 Initial support for the FreeBSD/riscv target and native configuration
550 was developed by SRI International and the University of Cambridge
551 Computer Laboratory (Department of Computer Science and Technology)
552 under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the DARPA
553 SSITH research programme.
554
555 The original port to the OpenRISC 1000 is believed to be due to
556 Alessandro Forin and Per Bothner. More recent ports have been the work
557 of Jeremy Bennett, Franck Jullien, Stefan Wallentowitz and
558 Stafford Horne.
559
560 Weimin Pan, David Faust and Jose E. Marchesi contributed support for
561 the Linux kernel BPF virtual architecture. This work was sponsored by
562 Oracle.
563
564 @node Sample Session
565 @chapter A Sample @value{GDBN} Session
566
567 You can use this manual at your leisure to read all about @value{GDBN}.
568 However, a handful of commands are enough to get started using the
569 debugger. This chapter illustrates those commands.
570
571 @iftex
572 In this sample session, we emphasize user input like this: @b{input},
573 to make it easier to pick out from the surrounding output.
574 @end iftex
575
576 @c FIXME: this example may not be appropriate for some configs, where
577 @c FIXME...primary interest is in remote use.
578
579 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
580 processor) exhibits the following bug: sometimes, when we change its
581 quote strings from the default, the commands used to capture one macro
582 definition within another stop working. In the following short @code{m4}
583 session, we define a macro @code{foo} which expands to @code{0000}; we
584 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
585 same thing. However, when we change the open quote string to
586 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
587 procedure fails to define a new synonym @code{baz}:
588
589 @smallexample
590 $ @b{cd gnu/m4}
591 $ @b{./m4}
592 @b{define(foo,0000)}
593
594 @b{foo}
595 0000
596 @b{define(bar,defn(`foo'))}
597
598 @b{bar}
599 0000
600 @b{changequote(<QUOTE>,<UNQUOTE>)}
601
602 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
603 @b{baz}
604 @b{Ctrl-d}
605 m4: End of input: 0: fatal error: EOF in string
606 @end smallexample
607
608 @noindent
609 Let us use @value{GDBN} to try to see what is going on.
610
611 @smallexample
612 $ @b{@value{GDBP} m4}
613 @c FIXME: this falsifies the exact text played out, to permit smallbook
614 @c FIXME... format to come out better.
615 @value{GDBN} is free software and you are welcome to distribute copies
616 of it under certain conditions; type "show copying" to see
617 the conditions.
618 There is absolutely no warranty for @value{GDBN}; type "show warranty"
619 for details.
620
621 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
622 (@value{GDBP})
623 @end smallexample
624
625 @noindent
626 @value{GDBN} reads only enough symbol data to know where to find the
627 rest when needed; as a result, the first prompt comes up very quickly.
628 We now tell @value{GDBN} to use a narrower display width than usual, so
629 that examples fit in this manual.
630
631 @smallexample
632 (@value{GDBP}) @b{set width 70}
633 @end smallexample
634
635 @noindent
636 We need to see how the @code{m4} built-in @code{changequote} works.
637 Having looked at the source, we know the relevant subroutine is
638 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
639 @code{break} command.
640
641 @smallexample
642 (@value{GDBP}) @b{break m4_changequote}
643 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
644 @end smallexample
645
646 @noindent
647 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
648 control; as long as control does not reach the @code{m4_changequote}
649 subroutine, the program runs as usual:
650
651 @smallexample
652 (@value{GDBP}) @b{run}
653 Starting program: /work/Editorial/gdb/gnu/m4/m4
654 @b{define(foo,0000)}
655
656 @b{foo}
657 0000
658 @end smallexample
659
660 @noindent
661 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
662 suspends execution of @code{m4}, displaying information about the
663 context where it stops.
664
665 @smallexample
666 @b{changequote(<QUOTE>,<UNQUOTE>)}
667
668 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
669 at builtin.c:879
670 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
671 @end smallexample
672
673 @noindent
674 Now we use the command @code{n} (@code{next}) to advance execution to
675 the next line of the current function.
676
677 @smallexample
678 (@value{GDBP}) @b{n}
679 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
680 : nil,
681 @end smallexample
682
683 @noindent
684 @code{set_quotes} looks like a promising subroutine. We can go into it
685 by using the command @code{s} (@code{step}) instead of @code{next}.
686 @code{step} goes to the next line to be executed in @emph{any}
687 subroutine, so it steps into @code{set_quotes}.
688
689 @smallexample
690 (@value{GDBP}) @b{s}
691 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
692 at input.c:530
693 530 if (lquote != def_lquote)
694 @end smallexample
695
696 @noindent
697 The display that shows the subroutine where @code{m4} is now
698 suspended (and its arguments) is called a stack frame display. It
699 shows a summary of the stack. We can use the @code{backtrace}
700 command (which can also be spelled @code{bt}), to see where we are
701 in the stack as a whole: the @code{backtrace} command displays a
702 stack frame for each active subroutine.
703
704 @smallexample
705 (@value{GDBP}) @b{bt}
706 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
707 at input.c:530
708 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
709 at builtin.c:882
710 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
711 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
712 at macro.c:71
713 #4 0x79dc in expand_input () at macro.c:40
714 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
715 @end smallexample
716
717 @noindent
718 We step through a few more lines to see what happens. The first two
719 times, we can use @samp{s}; the next two times we use @code{n} to avoid
720 falling into the @code{xstrdup} subroutine.
721
722 @smallexample
723 (@value{GDBP}) @b{s}
724 0x3b5c 532 if (rquote != def_rquote)
725 (@value{GDBP}) @b{s}
726 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
727 def_lquote : xstrdup(lq);
728 (@value{GDBP}) @b{n}
729 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
730 : xstrdup(rq);
731 (@value{GDBP}) @b{n}
732 538 len_lquote = strlen(rquote);
733 @end smallexample
734
735 @noindent
736 The last line displayed looks a little odd; we can examine the variables
737 @code{lquote} and @code{rquote} to see if they are in fact the new left
738 and right quotes we specified. We use the command @code{p}
739 (@code{print}) to see their values.
740
741 @smallexample
742 (@value{GDBP}) @b{p lquote}
743 $1 = 0x35d40 "<QUOTE>"
744 (@value{GDBP}) @b{p rquote}
745 $2 = 0x35d50 "<UNQUOTE>"
746 @end smallexample
747
748 @noindent
749 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
750 To look at some context, we can display ten lines of source
751 surrounding the current line with the @code{l} (@code{list}) command.
752
753 @smallexample
754 (@value{GDBP}) @b{l}
755 533 xfree(rquote);
756 534
757 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
758 : xstrdup (lq);
759 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
760 : xstrdup (rq);
761 537
762 538 len_lquote = strlen(rquote);
763 539 len_rquote = strlen(lquote);
764 540 @}
765 541
766 542 void
767 @end smallexample
768
769 @noindent
770 Let us step past the two lines that set @code{len_lquote} and
771 @code{len_rquote}, and then examine the values of those variables.
772
773 @smallexample
774 (@value{GDBP}) @b{n}
775 539 len_rquote = strlen(lquote);
776 (@value{GDBP}) @b{n}
777 540 @}
778 (@value{GDBP}) @b{p len_lquote}
779 $3 = 9
780 (@value{GDBP}) @b{p len_rquote}
781 $4 = 7
782 @end smallexample
783
784 @noindent
785 That certainly looks wrong, assuming @code{len_lquote} and
786 @code{len_rquote} are meant to be the lengths of @code{lquote} and
787 @code{rquote} respectively. We can set them to better values using
788 the @code{p} command, since it can print the value of
789 any expression---and that expression can include subroutine calls and
790 assignments.
791
792 @smallexample
793 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
794 $5 = 7
795 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
796 $6 = 9
797 @end smallexample
798
799 @noindent
800 Is that enough to fix the problem of using the new quotes with the
801 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
802 executing with the @code{c} (@code{continue}) command, and then try the
803 example that caused trouble initially:
804
805 @smallexample
806 (@value{GDBP}) @b{c}
807 Continuing.
808
809 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
810
811 baz
812 0000
813 @end smallexample
814
815 @noindent
816 Success! The new quotes now work just as well as the default ones. The
817 problem seems to have been just the two typos defining the wrong
818 lengths. We allow @code{m4} exit by giving it an EOF as input:
819
820 @smallexample
821 @b{Ctrl-d}
822 Program exited normally.
823 @end smallexample
824
825 @noindent
826 The message @samp{Program exited normally.} is from @value{GDBN}; it
827 indicates @code{m4} has finished executing. We can end our @value{GDBN}
828 session with the @value{GDBN} @code{quit} command.
829
830 @smallexample
831 (@value{GDBP}) @b{quit}
832 @end smallexample
833
834 @node Invocation
835 @chapter Getting In and Out of @value{GDBN}
836
837 This chapter discusses how to start @value{GDBN}, and how to get out of it.
838 The essentials are:
839 @itemize @bullet
840 @item
841 type @samp{@value{GDBP}} to start @value{GDBN}.
842 @item
843 type @kbd{quit} or @kbd{Ctrl-d} to exit.
844 @end itemize
845
846 @menu
847 * Invoking GDB:: How to start @value{GDBN}
848 * Quitting GDB:: How to quit @value{GDBN}
849 * Shell Commands:: How to use shell commands inside @value{GDBN}
850 * Logging Output:: How to log @value{GDBN}'s output to a file
851 @end menu
852
853 @node Invoking GDB
854 @section Invoking @value{GDBN}
855
856 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
857 @value{GDBN} reads commands from the terminal until you tell it to exit.
858
859 You can also run @code{@value{GDBP}} with a variety of arguments and options,
860 to specify more of your debugging environment at the outset.
861
862 The command-line options described here are designed
863 to cover a variety of situations; in some environments, some of these
864 options may effectively be unavailable.
865
866 The most usual way to start @value{GDBN} is with one argument,
867 specifying an executable program:
868
869 @smallexample
870 @value{GDBP} @var{program}
871 @end smallexample
872
873 @noindent
874 You can also start with both an executable program and a core file
875 specified:
876
877 @smallexample
878 @value{GDBP} @var{program} @var{core}
879 @end smallexample
880
881 You can, instead, specify a process ID as a second argument or use option
882 @code{-p}, if you want to debug a running process:
883
884 @smallexample
885 @value{GDBP} @var{program} 1234
886 @value{GDBP} -p 1234
887 @end smallexample
888
889 @noindent
890 would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
891 can omit the @var{program} filename.
892
893 Taking advantage of the second command-line argument requires a fairly
894 complete operating system; when you use @value{GDBN} as a remote
895 debugger attached to a bare board, there may not be any notion of
896 ``process'', and there is often no way to get a core dump. @value{GDBN}
897 will warn you if it is unable to attach or to read core dumps.
898
899 You can optionally have @code{@value{GDBP}} pass any arguments after the
900 executable file to the inferior using @code{--args}. This option stops
901 option processing.
902 @smallexample
903 @value{GDBP} --args gcc -O2 -c foo.c
904 @end smallexample
905 This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
906 @code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
907
908 You can run @code{@value{GDBP}} without printing the front material, which describes
909 @value{GDBN}'s non-warranty, by specifying @code{--silent}
910 (or @code{-q}/@code{--quiet}):
911
912 @smallexample
913 @value{GDBP} --silent
914 @end smallexample
915
916 @noindent
917 You can further control how @value{GDBN} starts up by using command-line
918 options. @value{GDBN} itself can remind you of the options available.
919
920 @noindent
921 Type
922
923 @smallexample
924 @value{GDBP} -help
925 @end smallexample
926
927 @noindent
928 to display all available options and briefly describe their use
929 (@samp{@value{GDBP} -h} is a shorter equivalent).
930
931 All options and command line arguments you give are processed
932 in sequential order. The order makes a difference when the
933 @samp{-x} option is used.
934
935
936 @menu
937 * File Options:: Choosing files
938 * Mode Options:: Choosing modes
939 * Startup:: What @value{GDBN} does during startup
940 * Initialization Files:: Initialization Files
941 @end menu
942
943 @node File Options
944 @subsection Choosing Files
945
946 When @value{GDBN} starts, it reads any arguments other than options as
947 specifying an executable file and core file (or process ID). This is
948 the same as if the arguments were specified by the @samp{-se} and
949 @samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
950 first argument that does not have an associated option flag as
951 equivalent to the @samp{-se} option followed by that argument; and the
952 second argument that does not have an associated option flag, if any, as
953 equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
954 If the second argument begins with a decimal digit, @value{GDBN} will
955 first attempt to attach to it as a process, and if that fails, attempt
956 to open it as a corefile. If you have a corefile whose name begins with
957 a digit, you can prevent @value{GDBN} from treating it as a pid by
958 prefixing it with @file{./}, e.g.@: @file{./12345}.
959
960 If @value{GDBN} has not been configured to included core file support,
961 such as for most embedded targets, then it will complain about a second
962 argument and ignore it.
963
964 Many options have both long and short forms; both are shown in the
965 following list. @value{GDBN} also recognizes the long forms if you truncate
966 them, so long as enough of the option is present to be unambiguous.
967 (If you prefer, you can flag option arguments with @samp{--} rather
968 than @samp{-}, though we illustrate the more usual convention.)
969
970 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
971 @c way, both those who look for -foo and --foo in the index, will find
972 @c it.
973
974 @table @code
975 @item -symbols @var{file}
976 @itemx -s @var{file}
977 @cindex @code{--symbols}
978 @cindex @code{-s}
979 Read symbol table from file @var{file}.
980
981 @item -exec @var{file}
982 @itemx -e @var{file}
983 @cindex @code{--exec}
984 @cindex @code{-e}
985 Use file @var{file} as the executable file to execute when appropriate,
986 and for examining pure data in conjunction with a core dump.
987
988 @item -se @var{file}
989 @cindex @code{--se}
990 Read symbol table from file @var{file} and use it as the executable
991 file.
992
993 @item -core @var{file}
994 @itemx -c @var{file}
995 @cindex @code{--core}
996 @cindex @code{-c}
997 Use file @var{file} as a core dump to examine.
998
999 @item -pid @var{number}
1000 @itemx -p @var{number}
1001 @cindex @code{--pid}
1002 @cindex @code{-p}
1003 Connect to process ID @var{number}, as with the @code{attach} command.
1004
1005 @item -command @var{file}
1006 @itemx -x @var{file}
1007 @cindex @code{--command}
1008 @cindex @code{-x}
1009 Execute commands from file @var{file}. The contents of this file is
1010 evaluated exactly as the @code{source} command would.
1011 @xref{Command Files,, Command files}.
1012
1013 @item -eval-command @var{command}
1014 @itemx -ex @var{command}
1015 @cindex @code{--eval-command}
1016 @cindex @code{-ex}
1017 Execute a single @value{GDBN} command.
1018
1019 This option may be used multiple times to call multiple commands. It may
1020 also be interleaved with @samp{-command} as required.
1021
1022 @smallexample
1023 @value{GDBP} -ex 'target sim' -ex 'load' \
1024 -x setbreakpoints -ex 'run' a.out
1025 @end smallexample
1026
1027 @item -init-command @var{file}
1028 @itemx -ix @var{file}
1029 @cindex @code{--init-command}
1030 @cindex @code{-ix}
1031 Execute commands from file @var{file} before loading the inferior (but
1032 after loading gdbinit files).
1033 @xref{Startup}.
1034
1035 @item -init-eval-command @var{command}
1036 @itemx -iex @var{command}
1037 @cindex @code{--init-eval-command}
1038 @cindex @code{-iex}
1039 Execute a single @value{GDBN} command before loading the inferior (but
1040 after loading gdbinit files).
1041 @xref{Startup}.
1042
1043 @item -directory @var{directory}
1044 @itemx -d @var{directory}
1045 @cindex @code{--directory}
1046 @cindex @code{-d}
1047 Add @var{directory} to the path to search for source and script files.
1048
1049 @item -r
1050 @itemx -readnow
1051 @cindex @code{--readnow}
1052 @cindex @code{-r}
1053 Read each symbol file's entire symbol table immediately, rather than
1054 the default, which is to read it incrementally as it is needed.
1055 This makes startup slower, but makes future operations faster.
1056
1057 @item --readnever
1058 @anchor{--readnever}
1059 @cindex @code{--readnever}, command-line option
1060 Do not read each symbol file's symbolic debug information. This makes
1061 startup faster but at the expense of not being able to perform
1062 symbolic debugging. DWARF unwind information is also not read,
1063 meaning backtraces may become incomplete or inaccurate. One use of
1064 this is when a user simply wants to do the following sequence: attach,
1065 dump core, detach. Loading the debugging information in this case is
1066 an unnecessary cause of delay.
1067 @end table
1068
1069 @node Mode Options
1070 @subsection Choosing Modes
1071
1072 You can run @value{GDBN} in various alternative modes---for example, in
1073 batch mode or quiet mode.
1074
1075 @table @code
1076 @anchor{-nx}
1077 @item -nx
1078 @itemx -n
1079 @cindex @code{--nx}
1080 @cindex @code{-n}
1081 Do not execute commands found in any initialization files
1082 (@pxref{Initialization Files}).
1083
1084 @anchor{-nh}
1085 @item -nh
1086 @cindex @code{--nh}
1087 Do not execute commands found in any home directory initialization
1088 file (@pxref{Initialization Files,,Home directory initialization
1089 file}). The system wide and current directory initialization files
1090 are still loaded.
1091
1092 @item -quiet
1093 @itemx -silent
1094 @itemx -q
1095 @cindex @code{--quiet}
1096 @cindex @code{--silent}
1097 @cindex @code{-q}
1098 ``Quiet''. Do not print the introductory and copyright messages. These
1099 messages are also suppressed in batch mode.
1100
1101 @item -batch
1102 @cindex @code{--batch}
1103 Run in batch mode. Exit with status @code{0} after processing all the
1104 command files specified with @samp{-x} (and all commands from
1105 initialization files, if not inhibited with @samp{-n}). Exit with
1106 nonzero status if an error occurs in executing the @value{GDBN} commands
1107 in the command files. Batch mode also disables pagination, sets unlimited
1108 terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1109 off} were in effect (@pxref{Messages/Warnings}).
1110
1111 Batch mode may be useful for running @value{GDBN} as a filter, for
1112 example to download and run a program on another computer; in order to
1113 make this more useful, the message
1114
1115 @smallexample
1116 Program exited normally.
1117 @end smallexample
1118
1119 @noindent
1120 (which is ordinarily issued whenever a program running under
1121 @value{GDBN} control terminates) is not issued when running in batch
1122 mode.
1123
1124 @item -batch-silent
1125 @cindex @code{--batch-silent}
1126 Run in batch mode exactly like @samp{-batch}, but totally silently. All
1127 @value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1128 unaffected). This is much quieter than @samp{-silent} and would be useless
1129 for an interactive session.
1130
1131 This is particularly useful when using targets that give @samp{Loading section}
1132 messages, for example.
1133
1134 Note that targets that give their output via @value{GDBN}, as opposed to
1135 writing directly to @code{stdout}, will also be made silent.
1136
1137 @item -return-child-result
1138 @cindex @code{--return-child-result}
1139 The return code from @value{GDBN} will be the return code from the child
1140 process (the process being debugged), with the following exceptions:
1141
1142 @itemize @bullet
1143 @item
1144 @value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1145 internal error. In this case the exit code is the same as it would have been
1146 without @samp{-return-child-result}.
1147 @item
1148 The user quits with an explicit value. E.g., @samp{quit 1}.
1149 @item
1150 The child process never runs, or is not allowed to terminate, in which case
1151 the exit code will be -1.
1152 @end itemize
1153
1154 This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1155 when @value{GDBN} is being used as a remote program loader or simulator
1156 interface.
1157
1158 @item -nowindows
1159 @itemx -nw
1160 @cindex @code{--nowindows}
1161 @cindex @code{-nw}
1162 ``No windows''. If @value{GDBN} comes with a graphical user interface
1163 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1164 interface. If no GUI is available, this option has no effect.
1165
1166 @item -windows
1167 @itemx -w
1168 @cindex @code{--windows}
1169 @cindex @code{-w}
1170 If @value{GDBN} includes a GUI, then this option requires it to be
1171 used if possible.
1172
1173 @item -cd @var{directory}
1174 @cindex @code{--cd}
1175 Run @value{GDBN} using @var{directory} as its working directory,
1176 instead of the current directory.
1177
1178 @item -data-directory @var{directory}
1179 @itemx -D @var{directory}
1180 @cindex @code{--data-directory}
1181 @cindex @code{-D}
1182 Run @value{GDBN} using @var{directory} as its data directory.
1183 The data directory is where @value{GDBN} searches for its
1184 auxiliary files. @xref{Data Files}.
1185
1186 @item -fullname
1187 @itemx -f
1188 @cindex @code{--fullname}
1189 @cindex @code{-f}
1190 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1191 subprocess. It tells @value{GDBN} to output the full file name and line
1192 number in a standard, recognizable fashion each time a stack frame is
1193 displayed (which includes each time your program stops). This
1194 recognizable format looks like two @samp{\032} characters, followed by
1195 the file name, line number and character position separated by colons,
1196 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1197 @samp{\032} characters as a signal to display the source code for the
1198 frame.
1199
1200 @item -annotate @var{level}
1201 @cindex @code{--annotate}
1202 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1203 effect is identical to using @samp{set annotate @var{level}}
1204 (@pxref{Annotations}). The annotation @var{level} controls how much
1205 information @value{GDBN} prints together with its prompt, values of
1206 expressions, source lines, and other types of output. Level 0 is the
1207 normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1208 @sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1209 that control @value{GDBN}, and level 2 has been deprecated.
1210
1211 The annotation mechanism has largely been superseded by @sc{gdb/mi}
1212 (@pxref{GDB/MI}).
1213
1214 @item --args
1215 @cindex @code{--args}
1216 Change interpretation of command line so that arguments following the
1217 executable file are passed as command line arguments to the inferior.
1218 This option stops option processing.
1219
1220 @item -baud @var{bps}
1221 @itemx -b @var{bps}
1222 @cindex @code{--baud}
1223 @cindex @code{-b}
1224 Set the line speed (baud rate or bits per second) of any serial
1225 interface used by @value{GDBN} for remote debugging.
1226
1227 @item -l @var{timeout}
1228 @cindex @code{-l}
1229 Set the timeout (in seconds) of any communication used by @value{GDBN}
1230 for remote debugging.
1231
1232 @item -tty @var{device}
1233 @itemx -t @var{device}
1234 @cindex @code{--tty}
1235 @cindex @code{-t}
1236 Run using @var{device} for your program's standard input and output.
1237 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1238
1239 @c resolve the situation of these eventually
1240 @item -tui
1241 @cindex @code{--tui}
1242 Activate the @dfn{Text User Interface} when starting. The Text User
1243 Interface manages several text windows on the terminal, showing
1244 source, assembly, registers and @value{GDBN} command outputs
1245 (@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1246 option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1247 Using @value{GDBN} under @sc{gnu} Emacs}).
1248
1249 @item -interpreter @var{interp}
1250 @cindex @code{--interpreter}
1251 Use the interpreter @var{interp} for interface with the controlling
1252 program or device. This option is meant to be set by programs which
1253 communicate with @value{GDBN} using it as a back end.
1254 @xref{Interpreters, , Command Interpreters}.
1255
1256 @samp{--interpreter=mi} (or @samp{--interpreter=mi3}) causes
1257 @value{GDBN} to use the @dfn{@sc{gdb/mi} interface} version 3 (@pxref{GDB/MI, ,
1258 The @sc{gdb/mi} Interface}) included since @value{GDBN} version 9.1. @sc{gdb/mi}
1259 version 2 (@code{mi2}), included in @value{GDBN} 6.0 and version 1 (@code{mi1}),
1260 included in @value{GDBN} 5.3, are also available. Earlier @sc{gdb/mi}
1261 interfaces are no longer supported.
1262
1263 @item -write
1264 @cindex @code{--write}
1265 Open the executable and core files for both reading and writing. This
1266 is equivalent to the @samp{set write on} command inside @value{GDBN}
1267 (@pxref{Patching}).
1268
1269 @item -statistics
1270 @cindex @code{--statistics}
1271 This option causes @value{GDBN} to print statistics about time and
1272 memory usage after it completes each command and returns to the prompt.
1273
1274 @item -version
1275 @cindex @code{--version}
1276 This option causes @value{GDBN} to print its version number and
1277 no-warranty blurb, and exit.
1278
1279 @item -configuration
1280 @cindex @code{--configuration}
1281 This option causes @value{GDBN} to print details about its build-time
1282 configuration parameters, and then exit. These details can be
1283 important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1284
1285 @end table
1286
1287 @node Startup
1288 @subsection What @value{GDBN} Does During Startup
1289 @cindex @value{GDBN} startup
1290
1291 Here's the description of what @value{GDBN} does during session startup:
1292
1293 @enumerate
1294 @item
1295 Sets up the command interpreter as specified by the command line
1296 (@pxref{Mode Options, interpreter}).
1297
1298 @item
1299 @cindex init file
1300 Reads the system wide initialization file and the files from the
1301 system wide initialization directory, @pxref{System Wide Init Files}.
1302
1303 @item
1304 Reads the initialization file (if any) in your home directory and
1305 executes all the commands in that file, @pxref{Home Directory Init
1306 File}.
1307
1308 @anchor{Option -init-eval-command}
1309 @item
1310 Executes commands and command files specified by the @samp{-iex} and
1311 @samp{-ix} options in their specified order. Usually you should use the
1312 @samp{-ex} and @samp{-x} options instead, but this way you can apply
1313 settings before @value{GDBN} init files get executed and before inferior
1314 gets loaded.
1315
1316 @item
1317 Processes command line options and operands.
1318
1319 @item
1320 Reads and executes the commands from the initialization file (if any)
1321 in the current working directory as long as @samp{set auto-load
1322 local-gdbinit} is set to @samp{on} (@pxref{Init File in the Current
1323 Directory}). This is only done if the current directory is different
1324 from your home directory. Thus, you can have more than one init file,
1325 one generic in your home directory, and another, specific to the
1326 program you are debugging, in the directory where you invoke
1327 @value{GDBN}. @xref{Init File in the Current Directory during
1328 Startup}.
1329
1330 @item
1331 If the command line specified a program to debug, or a process to
1332 attach to, or a core file, @value{GDBN} loads any auto-loaded
1333 scripts provided for the program or for its loaded shared libraries.
1334 @xref{Auto-loading}.
1335
1336 If you wish to disable the auto-loading during startup,
1337 you must do something like the following:
1338
1339 @smallexample
1340 $ gdb -iex "set auto-load python-scripts off" myprogram
1341 @end smallexample
1342
1343 Option @samp{-ex} does not work because the auto-loading is then turned
1344 off too late.
1345
1346 @item
1347 Executes commands and command files specified by the @samp{-ex} and
1348 @samp{-x} options in their specified order. @xref{Command Files}, for
1349 more details about @value{GDBN} command files.
1350
1351 @item
1352 Reads the command history recorded in the @dfn{history file}.
1353 @xref{Command History}, for more details about the command history and the
1354 files where @value{GDBN} records it.
1355 @end enumerate
1356
1357 @node Initialization Files
1358 @subsection Initialization Files
1359 @cindex init file name
1360
1361 During startup (@pxref{Startup}) @value{GDBN} will execute commands
1362 from several initialization files. These initialization files use the
1363 same syntax as @dfn{command files} (@pxref{Command Files}) and are
1364 processed by @value{GDBN} in the same way.
1365
1366 To display the list of initialization files loaded by @value{GDBN} at
1367 startup, in the order they will be loaded, you can use @kbd{gdb
1368 --help}.
1369
1370 As the system wide and home directory initialization files are
1371 processed before most command line options, changes to settings
1372 (e.g. @samp{set complaints}) can affect subsequent processing of
1373 command line options and operands.
1374
1375 The following sections describe where @value{GDBN} looks for the
1376 initialization and the order that the files are searched for.
1377
1378 @anchor{System Wide Init Files}
1379 @subsubsection System wide initialization files
1380
1381 There are two locations that are searched for system wide
1382 initialization files. Both of these locations are always checked:
1383
1384 @table @code
1385
1386 @item @file{system.gdbinit}
1387 This is a single system-wide initialization file. Its location is
1388 specified with the @code{--with-system-gdbinit} configure option
1389 (@pxref{System-wide configuration}). It is loaded first when
1390 @value{GDBN} starts, before command line options have been processed.
1391
1392 @item @file{system.gdbinit.d}
1393 This is the system-wide initialization directory. Its location is
1394 specified with the @code{--with-system-gdbinit-dir} configure option
1395 (@pxref{System-wide configuration}). Files in this directory are
1396 loaded in alphabetical order immediately after @file{system.gdbinit}
1397 (if enabled) when @value{GDBN} starts, before command line options
1398 have been processed. Files need to have a recognized scripting
1399 language extension (@file{.py}/@file{.scm}) or be named with a
1400 @file{.gdb} extension to be interpreted as regular @value{GDBN}
1401 commands. @value{GDBN} will not recurse into any subdirectories of
1402 this directory.
1403
1404 @end table
1405
1406 It is possible to prevent the system wide initialization files from
1407 being loaded using the @samp{-nx} command line option, @pxref{Mode
1408 Options,,Choosing Modes}.
1409
1410 @anchor{Home Directory Init File}
1411 @subsubsection Home directory initialization file
1412 @cindex @file{gdbinit}
1413 @cindex @file{.gdbinit}
1414 @cindex @file{gdb.ini}
1415
1416 After loading the system wide initialization files @value{GDBN} will
1417 look for an initialization file in the users home
1418 directory@footnote{On DOS/Windows systems, the home directory is the
1419 one pointed to by the @code{HOME} environment variable.}. There are a
1420 number of locations that @value{GDBN} will search in the home
1421 directory, these locations are searched in order and @value{GDBN} will
1422 load the first file that it finds, and subsequent locations will not
1423 be checked.
1424
1425 On non-Apple hosts the locations searched are:
1426 @table @file
1427 @item $XDG_CONFIG_HOME/gdb/gdbinit
1428 @item $HOME/.config/gdb/gdbinit
1429 @item $HOME/.gdbinit
1430 @end table
1431
1432 While on Apple hosts the locations searched are:
1433 @table @file
1434 @item $HOME/Library/Preferences/gdb/gdbinit
1435 @item $HOME/.gdbinit
1436 @end table
1437
1438 It is possible to prevent the home directory initialization file from
1439 being loaded using the @samp{-nx} or @samp{-nh} command line options,
1440 @pxref{Mode Options,,Choosing Modes}.
1441
1442 The DJGPP port of @value{GDBN} uses the name @file{gdb.ini} instead of
1443 @file{.gdbinit} or @file{gdbinit}, due to the limitations of file
1444 names imposed by DOS filesystems. The Windows port of @value{GDBN}
1445 uses the standard name, but if it finds a @file{gdb.ini} file in your
1446 home directory, it warns you about that and suggests to rename the
1447 file to the standard name.
1448
1449 @anchor{Init File in the Current Directory during Startup}
1450 @subsubsection Local directory initialization file
1451
1452 @value{GDBN} will check the current directory for a file called
1453 @file{.gdbinit}. It is loaded last, after command line options
1454 other than @samp{-x} and @samp{-ex} have been processed. The command
1455 line options @samp{-x} and @samp{-ex} are processed last, after
1456 @file{.gdbinit} has been loaded, @pxref{File Options,,Choosing
1457 Files}.
1458
1459 If the file in the current directory was already loaded as the home
1460 directory initialization file then it will not be loaded a second
1461 time.
1462
1463 It is possible to prevent the local directory initialization file from
1464 being loaded using the @samp{-nx} command line option, @pxref{Mode
1465 Options,,Choosing Modes}.
1466
1467 @node Quitting GDB
1468 @section Quitting @value{GDBN}
1469 @cindex exiting @value{GDBN}
1470 @cindex leaving @value{GDBN}
1471
1472 @table @code
1473 @kindex quit @r{[}@var{expression}@r{]}
1474 @kindex q @r{(@code{quit})}
1475 @item quit @r{[}@var{expression}@r{]}
1476 @itemx q
1477 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1478 @code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
1479 do not supply @var{expression}, @value{GDBN} will terminate normally;
1480 otherwise it will terminate using the result of @var{expression} as the
1481 error code.
1482 @end table
1483
1484 @cindex interrupt
1485 An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
1486 terminates the action of any @value{GDBN} command that is in progress and
1487 returns to @value{GDBN} command level. It is safe to type the interrupt
1488 character at any time because @value{GDBN} does not allow it to take effect
1489 until a time when it is safe.
1490
1491 If you have been using @value{GDBN} to control an attached process or
1492 device, you can release it with the @code{detach} command
1493 (@pxref{Attach, ,Debugging an Already-running Process}).
1494
1495 @node Shell Commands
1496 @section Shell Commands
1497
1498 If you need to execute occasional shell commands during your
1499 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1500 just use the @code{shell} command.
1501
1502 @table @code
1503 @kindex shell
1504 @kindex !
1505 @cindex shell escape
1506 @item shell @var{command-string}
1507 @itemx !@var{command-string}
1508 Invoke a standard shell to execute @var{command-string}.
1509 Note that no space is needed between @code{!} and @var{command-string}.
1510 On GNU and Unix systems, the environment variable @code{SHELL}, if it
1511 exists, determines which shell to run. Otherwise @value{GDBN} uses
1512 the default shell (@file{/bin/sh} on GNU and Unix systems,
1513 @file{cmd.exe} on MS-Windows, @file{COMMAND.COM} on MS-DOS, etc.).
1514 @end table
1515
1516 The utility @code{make} is often needed in development environments.
1517 You do not have to use the @code{shell} command for this purpose in
1518 @value{GDBN}:
1519
1520 @table @code
1521 @kindex make
1522 @cindex calling make
1523 @item make @var{make-args}
1524 Execute the @code{make} program with the specified
1525 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1526 @end table
1527
1528 @table @code
1529 @kindex pipe
1530 @kindex |
1531 @cindex send the output of a gdb command to a shell command
1532 @anchor{pipe}
1533 @item pipe [@var{command}] | @var{shell_command}
1534 @itemx | [@var{command}] | @var{shell_command}
1535 @itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1536 @itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1537 Executes @var{command} and sends its output to @var{shell_command}.
1538 Note that no space is needed around @code{|}.
1539 If no @var{command} is provided, the last command executed is repeated.
1540
1541 In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1542 can be used to specify an alternate delimiter string @var{delim} that separates
1543 the @var{command} from the @var{shell_command}.
1544
1545 Example:
1546 @smallexample
1547 @group
1548 (gdb) p var
1549 $1 = @{
1550 black = 144,
1551 red = 233,
1552 green = 377,
1553 blue = 610,
1554 white = 987
1555 @}
1556 @end group
1557 @group
1558 (gdb) pipe p var|wc
1559 7 19 80
1560 (gdb) |p var|wc -l
1561 7
1562 @end group
1563 @group
1564 (gdb) p /x var
1565 $4 = @{
1566 black = 0x90,
1567 red = 0xe9,
1568 green = 0x179,
1569 blue = 0x262,
1570 white = 0x3db
1571 @}
1572 (gdb) ||grep red
1573 red => 0xe9,
1574 @end group
1575 @group
1576 (gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1577 this contains a PIPE char
1578 (gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1579 this contains a PIPE char!
1580 (gdb)
1581 @end group
1582 @end smallexample
1583 @end table
1584
1585 The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1586 can be used to examine the exit status of the last shell command launched
1587 by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1588 @xref{Convenience Vars,, Convenience Variables}.
1589
1590 @node Logging Output
1591 @section Logging Output
1592 @cindex logging @value{GDBN} output
1593 @cindex save @value{GDBN} output to a file
1594
1595 You may want to save the output of @value{GDBN} commands to a file.
1596 There are several commands to control @value{GDBN}'s logging.
1597
1598 @table @code
1599 @kindex set logging
1600 @item set logging on
1601 Enable logging.
1602 @item set logging off
1603 Disable logging.
1604 @cindex logging file name
1605 @item set logging file @var{file}
1606 Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1607 @item set logging overwrite [on|off]
1608 By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1609 you want @code{set logging on} to overwrite the logfile instead.
1610 @item set logging redirect [on|off]
1611 By default, @value{GDBN} output will go to both the terminal and the logfile.
1612 Set @code{redirect} if you want output to go only to the log file.
1613 @item set logging debugredirect [on|off]
1614 By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1615 Set @code{debugredirect} if you want debug output to go only to the log file.
1616 @kindex show logging
1617 @item show logging
1618 Show the current values of the logging settings.
1619 @end table
1620
1621 You can also redirect the output of a @value{GDBN} command to a
1622 shell command. @xref{pipe}.
1623 @node Commands
1624 @chapter @value{GDBN} Commands
1625
1626 You can abbreviate a @value{GDBN} command to the first few letters of the command
1627 name, if that abbreviation is unambiguous; and you can repeat certain
1628 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1629 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1630 show you the alternatives available, if there is more than one possibility).
1631
1632 @menu
1633 * Command Syntax:: How to give commands to @value{GDBN}
1634 * Command Settings:: How to change default behavior of commands
1635 * Completion:: Command completion
1636 * Command Options:: Command options
1637 * Command aliases default args:: Automatically prepend default arguments to user-defined aliases
1638 * Help:: How to ask @value{GDBN} for help
1639 @end menu
1640
1641 @node Command Syntax
1642 @section Command Syntax
1643
1644 A @value{GDBN} command is a single line of input. There is no limit on
1645 how long it can be. It starts with a command name, which is followed by
1646 arguments whose meaning depends on the command name. For example, the
1647 command @code{step} accepts an argument which is the number of times to
1648 step, as in @samp{step 5}. You can also use the @code{step} command
1649 with no arguments. Some commands do not allow any arguments.
1650
1651 @cindex abbreviation
1652 @value{GDBN} command names may always be truncated if that abbreviation is
1653 unambiguous. Other possible command abbreviations are listed in the
1654 documentation for individual commands. In some cases, even ambiguous
1655 abbreviations are allowed; for example, @code{s} is specially defined as
1656 equivalent to @code{step} even though there are other commands whose
1657 names start with @code{s}. You can test abbreviations by using them as
1658 arguments to the @code{help} command.
1659
1660 @cindex repeating commands
1661 @kindex RET @r{(repeat last command)}
1662 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1663 repeat the previous command. Certain commands (for example, @code{run})
1664 will not repeat this way; these are commands whose unintentional
1665 repetition might cause trouble and which you are unlikely to want to
1666 repeat. User-defined commands can disable this feature; see
1667 @ref{Define, dont-repeat}.
1668
1669 The @code{list} and @code{x} commands, when you repeat them with
1670 @key{RET}, construct new arguments rather than repeating
1671 exactly as typed. This permits easy scanning of source or memory.
1672
1673 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1674 output, in a way similar to the common utility @code{more}
1675 (@pxref{Screen Size,,Screen Size}). Since it is easy to press one
1676 @key{RET} too many in this situation, @value{GDBN} disables command
1677 repetition after any command that generates this sort of display.
1678
1679 @kindex # @r{(a comment)}
1680 @cindex comment
1681 Any text from a @kbd{#} to the end of the line is a comment; it does
1682 nothing. This is useful mainly in command files (@pxref{Command
1683 Files,,Command Files}).
1684
1685 @cindex repeating command sequences
1686 @kindex Ctrl-o @r{(operate-and-get-next)}
1687 The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1688 commands. This command accepts the current line, like @key{RET}, and
1689 then fetches the next line relative to the current line from the history
1690 for editing.
1691
1692
1693 @node Command Settings
1694 @section Command Settings
1695 @cindex default behavior of commands, changing
1696 @cindex default settings, changing
1697
1698 Many commands change their behavior according to command-specific
1699 variables or settings. These settings can be changed with the
1700 @code{set} subcommands. For example, the @code{print} command
1701 (@pxref{Data, ,Examining Data}) prints arrays differently depending on
1702 settings changeable with the commands @code{set print elements
1703 NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1704
1705 You can change these settings to your preference in the gdbinit files
1706 loaded at @value{GDBN} startup. @xref{Startup}.
1707
1708 The settings can also be changed interactively during the debugging
1709 session. For example, to change the limit of array elements to print,
1710 you can do the following:
1711 @smallexample
1712 (@value{GDBN}) set print elements 10
1713 (@value{GDBN}) print some_array
1714 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1715 @end smallexample
1716
1717 The above @code{set print elements 10} command changes the number of
1718 elements to print from the default of 200 to 10. If you only intend
1719 this limit of 10 to be used for printing @code{some_array}, then you
1720 must restore the limit back to 200, with @code{set print elements
1721 200}.
1722
1723 Some commands allow overriding settings with command options. For
1724 example, the @code{print} command supports a number of options that
1725 allow overriding relevant global print settings as set by @code{set
1726 print} subcommands. @xref{print options}. The example above could be
1727 rewritten as:
1728 @smallexample
1729 (@value{GDBN}) print -elements 10 -- some_array
1730 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1731 @end smallexample
1732
1733 Alternatively, you can use the @code{with} command to change a setting
1734 temporarily, for the duration of a command invocation.
1735
1736 @table @code
1737 @kindex with command
1738 @kindex w @r{(@code{with})}
1739 @cindex settings
1740 @cindex temporarily change settings
1741 @item with @var{setting} [@var{value}] [-- @var{command}]
1742 @itemx w @var{setting} [@var{value}] [-- @var{command}]
1743 Temporarily set @var{setting} to @var{value} for the duration of
1744 @var{command}.
1745
1746 @var{setting} is any setting you can change with the @code{set}
1747 subcommands. @var{value} is the value to assign to @code{setting}
1748 while running @code{command}.
1749
1750 If no @var{command} is provided, the last command executed is
1751 repeated.
1752
1753 If a @var{command} is provided, it must be preceded by a double dash
1754 (@code{--}) separator. This is required because some settings accept
1755 free-form arguments, such as expressions or filenames.
1756
1757 For example, the command
1758 @smallexample
1759 (@value{GDBN}) with print array on -- print some_array
1760 @end smallexample
1761 @noindent
1762 is equivalent to the following 3 commands:
1763 @smallexample
1764 (@value{GDBN}) set print array on
1765 (@value{GDBN}) print some_array
1766 (@value{GDBN}) set print array off
1767 @end smallexample
1768
1769 The @code{with} command is particularly useful when you want to
1770 override a setting while running user-defined commands, or commands
1771 defined in Python or Guile. @xref{Extending GDB,, Extending GDB}.
1772
1773 @smallexample
1774 (@value{GDBN}) with print pretty on -- my_complex_command
1775 @end smallexample
1776
1777 To change several settings for the same command, you can nest
1778 @code{with} commands. For example, @code{with language ada -- with
1779 print elements 10} temporarily changes the language to Ada and sets a
1780 limit of 10 elements to print for arrays and strings.
1781
1782 @end table
1783
1784 @node Completion
1785 @section Command Completion
1786
1787 @cindex completion
1788 @cindex word completion
1789 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1790 only one possibility; it can also show you what the valid possibilities
1791 are for the next word in a command, at any time. This works for @value{GDBN}
1792 commands, @value{GDBN} subcommands, command options, and the names of symbols
1793 in your program.
1794
1795 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1796 of a word. If there is only one possibility, @value{GDBN} fills in the
1797 word, and waits for you to finish the command (or press @key{RET} to
1798 enter it). For example, if you type
1799
1800 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1801 @c complete accuracy in these examples; space introduced for clarity.
1802 @c If texinfo enhancements make it unnecessary, it would be nice to
1803 @c replace " @key" by "@key" in the following...
1804 @smallexample
1805 (@value{GDBP}) info bre @key{TAB}
1806 @end smallexample
1807
1808 @noindent
1809 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1810 the only @code{info} subcommand beginning with @samp{bre}:
1811
1812 @smallexample
1813 (@value{GDBP}) info breakpoints
1814 @end smallexample
1815
1816 @noindent
1817 You can either press @key{RET} at this point, to run the @code{info
1818 breakpoints} command, or backspace and enter something else, if
1819 @samp{breakpoints} does not look like the command you expected. (If you
1820 were sure you wanted @code{info breakpoints} in the first place, you
1821 might as well just type @key{RET} immediately after @samp{info bre},
1822 to exploit command abbreviations rather than command completion).
1823
1824 If there is more than one possibility for the next word when you press
1825 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1826 characters and try again, or just press @key{TAB} a second time;
1827 @value{GDBN} displays all the possible completions for that word. For
1828 example, you might want to set a breakpoint on a subroutine whose name
1829 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1830 just sounds the bell. Typing @key{TAB} again displays all the
1831 function names in your program that begin with those characters, for
1832 example:
1833
1834 @smallexample
1835 (@value{GDBP}) b make_ @key{TAB}
1836 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1837 make_a_section_from_file make_environ
1838 make_abs_section make_function_type
1839 make_blockvector make_pointer_type
1840 make_cleanup make_reference_type
1841 make_command make_symbol_completion_list
1842 (@value{GDBP}) b make_
1843 @end smallexample
1844
1845 @noindent
1846 After displaying the available possibilities, @value{GDBN} copies your
1847 partial input (@samp{b make_} in the example) so you can finish the
1848 command.
1849
1850 If you just want to see the list of alternatives in the first place, you
1851 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1852 means @kbd{@key{META} ?}. You can type this either by holding down a
1853 key designated as the @key{META} shift on your keyboard (if there is
1854 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1855
1856 If the number of possible completions is large, @value{GDBN} will
1857 print as much of the list as it has collected, as well as a message
1858 indicating that the list may be truncated.
1859
1860 @smallexample
1861 (@value{GDBP}) b m@key{TAB}@key{TAB}
1862 main
1863 <... the rest of the possible completions ...>
1864 *** List may be truncated, max-completions reached. ***
1865 (@value{GDBP}) b m
1866 @end smallexample
1867
1868 @noindent
1869 This behavior can be controlled with the following commands:
1870
1871 @table @code
1872 @kindex set max-completions
1873 @item set max-completions @var{limit}
1874 @itemx set max-completions unlimited
1875 Set the maximum number of completion candidates. @value{GDBN} will
1876 stop looking for more completions once it collects this many candidates.
1877 This is useful when completing on things like function names as collecting
1878 all the possible candidates can be time consuming.
1879 The default value is 200. A value of zero disables tab-completion.
1880 Note that setting either no limit or a very large limit can make
1881 completion slow.
1882 @kindex show max-completions
1883 @item show max-completions
1884 Show the maximum number of candidates that @value{GDBN} will collect and show
1885 during completion.
1886 @end table
1887
1888 @cindex quotes in commands
1889 @cindex completion of quoted strings
1890 Sometimes the string you need, while logically a ``word'', may contain
1891 parentheses or other characters that @value{GDBN} normally excludes from
1892 its notion of a word. To permit word completion to work in this
1893 situation, you may enclose words in @code{'} (single quote marks) in
1894 @value{GDBN} commands.
1895
1896 A likely situation where you might need this is in typing an
1897 expression that involves a C@t{++} symbol name with template
1898 parameters. This is because when completing expressions, GDB treats
1899 the @samp{<} character as word delimiter, assuming that it's the
1900 less-than comparison operator (@pxref{C Operators, , C and C@t{++}
1901 Operators}).
1902
1903 For example, when you want to call a C@t{++} template function
1904 interactively using the @code{print} or @code{call} commands, you may
1905 need to distinguish whether you mean the version of @code{name} that
1906 was specialized for @code{int}, @code{name<int>()}, or the version
1907 that was specialized for @code{float}, @code{name<float>()}. To use
1908 the word-completion facilities in this situation, type a single quote
1909 @code{'} at the beginning of the function name. This alerts
1910 @value{GDBN} that it may need to consider more information than usual
1911 when you press @key{TAB} or @kbd{M-?} to request word completion:
1912
1913 @smallexample
1914 (@value{GDBP}) p 'func< @kbd{M-?}
1915 func<int>() func<float>()
1916 (@value{GDBP}) p 'func<
1917 @end smallexample
1918
1919 When setting breakpoints however (@pxref{Specify Location}), you don't
1920 usually need to type a quote before the function name, because
1921 @value{GDBN} understands that you want to set a breakpoint on a
1922 function:
1923
1924 @smallexample
1925 (@value{GDBP}) b func< @kbd{M-?}
1926 func<int>() func<float>()
1927 (@value{GDBP}) b func<
1928 @end smallexample
1929
1930 This is true even in the case of typing the name of C@t{++} overloaded
1931 functions (multiple definitions of the same function, distinguished by
1932 argument type). For example, when you want to set a breakpoint you
1933 don't need to distinguish whether you mean the version of @code{name}
1934 that takes an @code{int} parameter, @code{name(int)}, or the version
1935 that takes a @code{float} parameter, @code{name(float)}.
1936
1937 @smallexample
1938 (@value{GDBP}) b bubble( @kbd{M-?}
1939 bubble(int) bubble(double)
1940 (@value{GDBP}) b bubble(dou @kbd{M-?}
1941 bubble(double)
1942 @end smallexample
1943
1944 See @ref{quoting names} for a description of other scenarios that
1945 require quoting.
1946
1947 For more information about overloaded functions, see @ref{C Plus Plus
1948 Expressions, ,C@t{++} Expressions}. You can use the command @code{set
1949 overload-resolution off} to disable overload resolution;
1950 see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
1951
1952 @cindex completion of structure field names
1953 @cindex structure field name completion
1954 @cindex completion of union field names
1955 @cindex union field name completion
1956 When completing in an expression which looks up a field in a
1957 structure, @value{GDBN} also tries@footnote{The completer can be
1958 confused by certain kinds of invalid expressions. Also, it only
1959 examines the static type of the expression, not the dynamic type.} to
1960 limit completions to the field names available in the type of the
1961 left-hand-side:
1962
1963 @smallexample
1964 (@value{GDBP}) p gdb_stdout.@kbd{M-?}
1965 magic to_fputs to_rewind
1966 to_data to_isatty to_write
1967 to_delete to_put to_write_async_safe
1968 to_flush to_read
1969 @end smallexample
1970
1971 @noindent
1972 This is because the @code{gdb_stdout} is a variable of the type
1973 @code{struct ui_file} that is defined in @value{GDBN} sources as
1974 follows:
1975
1976 @smallexample
1977 struct ui_file
1978 @{
1979 int *magic;
1980 ui_file_flush_ftype *to_flush;
1981 ui_file_write_ftype *to_write;
1982 ui_file_write_async_safe_ftype *to_write_async_safe;
1983 ui_file_fputs_ftype *to_fputs;
1984 ui_file_read_ftype *to_read;
1985 ui_file_delete_ftype *to_delete;
1986 ui_file_isatty_ftype *to_isatty;
1987 ui_file_rewind_ftype *to_rewind;
1988 ui_file_put_ftype *to_put;
1989 void *to_data;
1990 @}
1991 @end smallexample
1992
1993 @node Command Options
1994 @section Command options
1995
1996 @cindex command options
1997 Some commands accept options starting with a leading dash. For
1998 example, @code{print -pretty}. Similarly to command names, you can
1999 abbreviate a @value{GDBN} option to the first few letters of the
2000 option name, if that abbreviation is unambiguous, and you can also use
2001 the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
2002 in an option (or to show you the alternatives available, if there is
2003 more than one possibility).
2004
2005 @cindex command options, raw input
2006 Some commands take raw input as argument. For example, the print
2007 command processes arbitrary expressions in any of the languages
2008 supported by @value{GDBN}. With such commands, because raw input may
2009 start with a leading dash that would be confused with an option or any
2010 of its abbreviations, e.g.@: @code{print -p} (short for @code{print
2011 -pretty} or printing negative @code{p}?), if you specify any command
2012 option, then you must use a double-dash (@code{--}) delimiter to
2013 indicate the end of options.
2014
2015 @cindex command options, boolean
2016
2017 Some options are described as accepting an argument which can be
2018 either @code{on} or @code{off}. These are known as @dfn{boolean
2019 options}. Similarly to boolean settings commands---@code{on} and
2020 @code{off} are the typical values, but any of @code{1}, @code{yes} and
2021 @code{enable} can also be used as ``true'' value, and any of @code{0},
2022 @code{no} and @code{disable} can also be used as ``false'' value. You
2023 can also omit a ``true'' value, as it is implied by default.
2024
2025 For example, these are equivalent:
2026
2027 @smallexample
2028 (@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
2029 (@value{GDBP}) p -o -p 0 -e u -- *myptr
2030 @end smallexample
2031
2032 You can discover the set of options some command accepts by completing
2033 on @code{-} after the command name. For example:
2034
2035 @smallexample
2036 (@value{GDBP}) print -@key{TAB}@key{TAB}
2037 -address -max-depth -raw-values -union
2038 -array -null-stop -repeats -vtbl
2039 -array-indexes -object -static-members
2040 -elements -pretty -symbol
2041 @end smallexample
2042
2043 Completion will in some cases guide you with a suggestion of what kind
2044 of argument an option expects. For example:
2045
2046 @smallexample
2047 (@value{GDBP}) print -elements @key{TAB}@key{TAB}
2048 NUMBER unlimited
2049 @end smallexample
2050
2051 Here, the option expects a number (e.g., @code{100}), not literal
2052 @code{NUMBER}. Such metasyntactical arguments are always presented in
2053 uppercase.
2054
2055 (For more on using the @code{print} command, see @ref{Data, ,Examining
2056 Data}.)
2057
2058 @node Command aliases default args
2059 @section Automatically prepend default arguments to user-defined aliases
2060
2061 You can tell @value{GDBN} to always prepend some default arguments to
2062 the list of arguments provided explicitly by the user when using a
2063 user-defined alias.
2064
2065 If you repeatedly use the same arguments or options for a command, you
2066 can define an alias for this command and tell @value{GDBN} to
2067 automatically prepend these arguments or options to the list of
2068 arguments you type explicitly when using the alias@footnote{@value{GDBN}
2069 could easily accept default arguments for pre-defined commands and aliases,
2070 but it was deemed this would be confusing, and so is not allowed.}.
2071
2072 For example, if you often use the command @code{thread apply all}
2073 specifying to work on the threads in ascending order and to continue in case it
2074 encounters an error, you can tell @value{GDBN} to automatically preprend
2075 the @code{-ascending} and @code{-c} options by using:
2076
2077 @smallexample
2078 (@value{GDBP}) alias thread apply asc-all = thread apply all -ascending -c
2079 @end smallexample
2080
2081 Once you have defined this alias with its default args, any time you type
2082 the @code{thread apply asc-all} followed by @code{some arguments},
2083 @value{GDBN} will execute @code{thread apply all -ascending -c some arguments}.
2084
2085 To have even less to type, you can also define a one word alias:
2086 @smallexample
2087 (@value{GDBP}) alias t_a_c = thread apply all -ascending -c
2088 @end smallexample
2089
2090 As usual, unambiguous abbreviations can be used for @var{alias}
2091 and @var{default-args}.
2092
2093 The different aliases of a command do not share their default args.
2094 For example, you define a new alias @code{bt_ALL} showing all possible
2095 information and another alias @code{bt_SMALL} showing very limited information
2096 using:
2097 @smallexample
2098 (@value{GDBP}) alias bt_ALL = backtrace -entry-values both -frame-arg all \
2099 -past-main -past-entry -full
2100 (@value{GDBP}) alias bt_SMALL = backtrace -entry-values no -frame-arg none \
2101 -past-main off -past-entry off
2102 @end smallexample
2103
2104 (For more on using the @code{alias} command, see @ref{Aliases}.)
2105
2106 Default args are not limited to the arguments and options of @var{command},
2107 but can specify nested commands if @var{command} accepts such a nested command
2108 as argument.
2109 For example, the below defines @code{faalocalsoftype} that lists the
2110 frames having locals of a certain type, together with the matching
2111 local vars:
2112 @smallexample
2113 (@value{GDBP}) alias faalocalsoftype = frame apply all info locals -q -t
2114 (@value{GDBP}) faalocalsoftype int
2115 #1 0x55554f5e in sleeper_or_burner (v=0xdf50) at sleepers.c:86
2116 i = 0
2117 ret = 21845
2118 @end smallexample
2119
2120 This is also very useful to define an alias for a set of nested @code{with}
2121 commands to have a particular combination of temporary settings. For example,
2122 the below defines the alias @code{pp10} that pretty prints an expression
2123 argument, with a maximum of 10 elements if the expression is a string or
2124 an array:
2125 @smallexample
2126 (@value{GDBP}) alias pp10 = with print pretty -- with print elements 10 -- print
2127 @end smallexample
2128 This defines the alias @code{pp10} as being a sequence of 3 commands.
2129 The first part @code{with print pretty --} temporarily activates the setting
2130 @code{set print pretty}, then launches the command that follows the separator
2131 @code{--}.
2132 The command following the first part is also a @code{with} command that
2133 temporarily changes the setting @code{set print elements} to 10, then
2134 launches the command that follows the second separator @code{--}.
2135 The third part @code{print} is the command the @code{pp10} alias will launch,
2136 using the temporary values of the settings and the arguments explicitly given
2137 by the user.
2138 For more information about the @code{with} command usage,
2139 see @ref{Command Settings}.
2140
2141 @node Help
2142 @section Getting Help
2143 @cindex online documentation
2144 @kindex help
2145
2146 You can always ask @value{GDBN} itself for information on its commands,
2147 using the command @code{help}.
2148
2149 @table @code
2150 @kindex h @r{(@code{help})}
2151 @item help
2152 @itemx h
2153 You can use @code{help} (abbreviated @code{h}) with no arguments to
2154 display a short list of named classes of commands:
2155
2156 @smallexample
2157 (@value{GDBP}) help
2158 List of classes of commands:
2159
2160 aliases -- User-defined aliases of other commands
2161 breakpoints -- Making program stop at certain points
2162 data -- Examining data
2163 files -- Specifying and examining files
2164 internals -- Maintenance commands
2165 obscure -- Obscure features
2166 running -- Running the program
2167 stack -- Examining the stack
2168 status -- Status inquiries
2169 support -- Support facilities
2170 tracepoints -- Tracing of program execution without
2171 stopping the program
2172 user-defined -- User-defined commands
2173
2174 Type "help" followed by a class name for a list of
2175 commands in that class.
2176 Type "help" followed by command name for full
2177 documentation.
2178 Command name abbreviations are allowed if unambiguous.
2179 (@value{GDBP})
2180 @end smallexample
2181 @c the above line break eliminates huge line overfull...
2182
2183 @item help @var{class}
2184 Using one of the general help classes as an argument, you can get a
2185 list of the individual commands in that class. If a command has
2186 aliases, the aliases are given after the command name, separated by
2187 commas. If an alias has default arguments, the full definition of
2188 the alias is given after the first line.
2189 For example, here is the help display for the class @code{status}:
2190
2191 @smallexample
2192 (@value{GDBP}) help status
2193 Status inquiries.
2194
2195 List of commands:
2196
2197 @c Line break in "show" line falsifies real output, but needed
2198 @c to fit in smallbook page size.
2199 info, inf, i -- Generic command for showing things
2200 about the program being debugged
2201 info address, iamain -- Describe where symbol SYM is stored.
2202 alias iamain = info address main
2203 info all-registers -- List of all registers and their contents,
2204 for selected stack frame.
2205 ...
2206 show, info set -- Generic command for showing things
2207 about the debugger
2208
2209 Type "help" followed by command name for full
2210 documentation.
2211 Command name abbreviations are allowed if unambiguous.
2212 (@value{GDBP})
2213 @end smallexample
2214
2215 @item help @var{command}
2216 With a command name as @code{help} argument, @value{GDBN} displays a
2217 short paragraph on how to use that command. If that command has
2218 one or more aliases, @value{GDBN} will display a first line with
2219 the command name and all its aliases separated by commas.
2220 This first line will be followed by the full definition of all aliases
2221 having default arguments.
2222
2223 @kindex apropos
2224 @item apropos [-v] @var{regexp}
2225 The @code{apropos} command searches through all of the @value{GDBN}
2226 commands, and their documentation, for the regular expression specified in
2227 @var{args}. It prints out all matches found. The optional flag @samp{-v},
2228 which stands for @samp{verbose}, indicates to output the full documentation
2229 of the matching commands and highlight the parts of the documentation
2230 matching @var{regexp}. For example:
2231
2232 @smallexample
2233 apropos alias
2234 @end smallexample
2235
2236 @noindent
2237 results in:
2238
2239 @smallexample
2240 @group
2241 alias -- Define a new command that is an alias of an existing command
2242 aliases -- User-defined aliases of other commands
2243 @end group
2244 @end smallexample
2245
2246 @noindent
2247 while
2248
2249 @smallexample
2250 apropos -v cut.*thread apply
2251 @end smallexample
2252
2253 @noindent
2254 results in the below output, where @samp{cut for 'thread apply}
2255 is highlighted if styling is enabled.
2256
2257 @smallexample
2258 @group
2259 taas -- Apply a command to all threads (ignoring errors
2260 and empty output).
2261 Usage: taas COMMAND
2262 shortcut for 'thread apply all -s COMMAND'
2263
2264 tfaas -- Apply a command to all frames of all threads
2265 (ignoring errors and empty output).
2266 Usage: tfaas COMMAND
2267 shortcut for 'thread apply all -s frame apply all -s COMMAND'
2268 @end group
2269 @end smallexample
2270
2271 @kindex complete
2272 @item complete @var{args}
2273 The @code{complete @var{args}} command lists all the possible completions
2274 for the beginning of a command. Use @var{args} to specify the beginning of the
2275 command you want completed. For example:
2276
2277 @smallexample
2278 complete i
2279 @end smallexample
2280
2281 @noindent results in:
2282
2283 @smallexample
2284 @group
2285 if
2286 ignore
2287 info
2288 inspect
2289 @end group
2290 @end smallexample
2291
2292 @noindent This is intended for use by @sc{gnu} Emacs.
2293 @end table
2294
2295 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2296 and @code{show} to inquire about the state of your program, or the state
2297 of @value{GDBN} itself. Each command supports many topics of inquiry; this
2298 manual introduces each of them in the appropriate context. The listings
2299 under @code{info} and under @code{show} in the Command, Variable, and
2300 Function Index point to all the sub-commands. @xref{Command and Variable
2301 Index}.
2302
2303 @c @group
2304 @table @code
2305 @kindex info
2306 @kindex i @r{(@code{info})}
2307 @item info
2308 This command (abbreviated @code{i}) is for describing the state of your
2309 program. For example, you can show the arguments passed to a function
2310 with @code{info args}, list the registers currently in use with @code{info
2311 registers}, or list the breakpoints you have set with @code{info breakpoints}.
2312 You can get a complete list of the @code{info} sub-commands with
2313 @w{@code{help info}}.
2314
2315 @kindex set
2316 @item set
2317 You can assign the result of an expression to an environment variable with
2318 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2319 @code{set prompt $}.
2320
2321 @kindex show
2322 @item show
2323 In contrast to @code{info}, @code{show} is for describing the state of
2324 @value{GDBN} itself.
2325 You can change most of the things you can @code{show}, by using the
2326 related command @code{set}; for example, you can control what number
2327 system is used for displays with @code{set radix}, or simply inquire
2328 which is currently in use with @code{show radix}.
2329
2330 @kindex info set
2331 To display all the settable parameters and their current
2332 values, you can use @code{show} with no arguments; you may also use
2333 @code{info set}. Both commands produce the same display.
2334 @c FIXME: "info set" violates the rule that "info" is for state of
2335 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2336 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2337 @end table
2338 @c @end group
2339
2340 Here are several miscellaneous @code{show} subcommands, all of which are
2341 exceptional in lacking corresponding @code{set} commands:
2342
2343 @table @code
2344 @kindex show version
2345 @cindex @value{GDBN} version number
2346 @item show version
2347 Show what version of @value{GDBN} is running. You should include this
2348 information in @value{GDBN} bug-reports. If multiple versions of
2349 @value{GDBN} are in use at your site, you may need to determine which
2350 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2351 commands are introduced, and old ones may wither away. Also, many
2352 system vendors ship variant versions of @value{GDBN}, and there are
2353 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2354 The version number is the same as the one announced when you start
2355 @value{GDBN}.
2356
2357 @kindex show copying
2358 @kindex info copying
2359 @cindex display @value{GDBN} copyright
2360 @item show copying
2361 @itemx info copying
2362 Display information about permission for copying @value{GDBN}.
2363
2364 @kindex show warranty
2365 @kindex info warranty
2366 @item show warranty
2367 @itemx info warranty
2368 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
2369 if your version of @value{GDBN} comes with one.
2370
2371 @kindex show configuration
2372 @item show configuration
2373 Display detailed information about the way @value{GDBN} was configured
2374 when it was built. This displays the optional arguments passed to the
2375 @file{configure} script and also configuration parameters detected
2376 automatically by @command{configure}. When reporting a @value{GDBN}
2377 bug (@pxref{GDB Bugs}), it is important to include this information in
2378 your report.
2379
2380 @end table
2381
2382 @node Running
2383 @chapter Running Programs Under @value{GDBN}
2384
2385 When you run a program under @value{GDBN}, you must first generate
2386 debugging information when you compile it.
2387
2388 You may start @value{GDBN} with its arguments, if any, in an environment
2389 of your choice. If you are doing native debugging, you may redirect
2390 your program's input and output, debug an already running process, or
2391 kill a child process.
2392
2393 @menu
2394 * Compilation:: Compiling for debugging
2395 * Starting:: Starting your program
2396 * Arguments:: Your program's arguments
2397 * Environment:: Your program's environment
2398
2399 * Working Directory:: Your program's working directory
2400 * Input/Output:: Your program's input and output
2401 * Attach:: Debugging an already-running process
2402 * Kill Process:: Killing the child process
2403 * Inferiors Connections and Programs:: Debugging multiple inferiors
2404 connections and programs
2405 * Threads:: Debugging programs with multiple threads
2406 * Forks:: Debugging forks
2407 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
2408 @end menu
2409
2410 @node Compilation
2411 @section Compiling for Debugging
2412
2413 In order to debug a program effectively, you need to generate
2414 debugging information when you compile it. This debugging information
2415 is stored in the object file; it describes the data type of each
2416 variable or function and the correspondence between source line numbers
2417 and addresses in the executable code.
2418
2419 To request debugging information, specify the @samp{-g} option when you run
2420 the compiler.
2421
2422 Programs that are to be shipped to your customers are compiled with
2423 optimizations, using the @samp{-O} compiler option. However, some
2424 compilers are unable to handle the @samp{-g} and @samp{-O} options
2425 together. Using those compilers, you cannot generate optimized
2426 executables containing debugging information.
2427
2428 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
2429 without @samp{-O}, making it possible to debug optimized code. We
2430 recommend that you @emph{always} use @samp{-g} whenever you compile a
2431 program. You may think your program is correct, but there is no sense
2432 in pushing your luck. For more information, see @ref{Optimized Code}.
2433
2434 Older versions of the @sc{gnu} C compiler permitted a variant option
2435 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2436 format; if your @sc{gnu} C compiler has this option, do not use it.
2437
2438 @value{GDBN} knows about preprocessor macros and can show you their
2439 expansion (@pxref{Macros}). Most compilers do not include information
2440 about preprocessor macros in the debugging information if you specify
2441 the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2442 the @sc{gnu} C compiler, provides macro information if you are using
2443 the DWARF debugging format, and specify the option @option{-g3}.
2444
2445 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
2446 gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
2447 information on @value{NGCC} options affecting debug information.
2448
2449 You will have the best debugging experience if you use the latest
2450 version of the DWARF debugging format that your compiler supports.
2451 DWARF is currently the most expressive and best supported debugging
2452 format in @value{GDBN}.
2453
2454 @need 2000
2455 @node Starting
2456 @section Starting your Program
2457 @cindex starting
2458 @cindex running
2459
2460 @table @code
2461 @kindex run
2462 @kindex r @r{(@code{run})}
2463 @item run
2464 @itemx r
2465 Use the @code{run} command to start your program under @value{GDBN}.
2466 You must first specify the program name with an argument to
2467 @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2468 @value{GDBN}}), or by using the @code{file} or @code{exec-file}
2469 command (@pxref{Files, ,Commands to Specify Files}).
2470
2471 @end table
2472
2473 If you are running your program in an execution environment that
2474 supports processes, @code{run} creates an inferior process and makes
2475 that process run your program. In some environments without processes,
2476 @code{run} jumps to the start of your program. Other targets,
2477 like @samp{remote}, are always running. If you get an error
2478 message like this one:
2479
2480 @smallexample
2481 The "remote" target does not support "run".
2482 Try "help target" or "continue".
2483 @end smallexample
2484
2485 @noindent
2486 then use @code{continue} to run your program. You may need @code{load}
2487 first (@pxref{load}).
2488
2489 The execution of a program is affected by certain information it
2490 receives from its superior. @value{GDBN} provides ways to specify this
2491 information, which you must do @emph{before} starting your program. (You
2492 can change it after starting your program, but such changes only affect
2493 your program the next time you start it.) This information may be
2494 divided into four categories:
2495
2496 @table @asis
2497 @item The @emph{arguments.}
2498 Specify the arguments to give your program as the arguments of the
2499 @code{run} command. If a shell is available on your target, the shell
2500 is used to pass the arguments, so that you may use normal conventions
2501 (such as wildcard expansion or variable substitution) in describing
2502 the arguments.
2503 In Unix systems, you can control which shell is used with the
2504 @code{SHELL} environment variable. If you do not define @code{SHELL},
2505 @value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2506 use of any shell with the @code{set startup-with-shell} command (see
2507 below for details).
2508
2509 @item The @emph{environment.}
2510 Your program normally inherits its environment from @value{GDBN}, but you can
2511 use the @value{GDBN} commands @code{set environment} and @code{unset
2512 environment} to change parts of the environment that affect
2513 your program. @xref{Environment, ,Your Program's Environment}.
2514
2515 @item The @emph{working directory.}
2516 You can set your program's working directory with the command
2517 @kbd{set cwd}. If you do not set any working directory with this
2518 command, your program will inherit @value{GDBN}'s working directory if
2519 native debugging, or the remote server's working directory if remote
2520 debugging. @xref{Working Directory, ,Your Program's Working
2521 Directory}.
2522
2523 @item The @emph{standard input and output.}
2524 Your program normally uses the same device for standard input and
2525 standard output as @value{GDBN} is using. You can redirect input and output
2526 in the @code{run} command line, or you can use the @code{tty} command to
2527 set a different device for your program.
2528 @xref{Input/Output, ,Your Program's Input and Output}.
2529
2530 @cindex pipes
2531 @emph{Warning:} While input and output redirection work, you cannot use
2532 pipes to pass the output of the program you are debugging to another
2533 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2534 wrong program.
2535 @end table
2536
2537 When you issue the @code{run} command, your program begins to execute
2538 immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
2539 of how to arrange for your program to stop. Once your program has
2540 stopped, you may call functions in your program, using the @code{print}
2541 or @code{call} commands. @xref{Data, ,Examining Data}.
2542
2543 If the modification time of your symbol file has changed since the last
2544 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2545 table, and reads it again. When it does this, @value{GDBN} tries to retain
2546 your current breakpoints.
2547
2548 @table @code
2549 @kindex start
2550 @item start
2551 @cindex run to main procedure
2552 The name of the main procedure can vary from language to language.
2553 With C or C@t{++}, the main procedure name is always @code{main}, but
2554 other languages such as Ada do not require a specific name for their
2555 main procedure. The debugger provides a convenient way to start the
2556 execution of the program and to stop at the beginning of the main
2557 procedure, depending on the language used.
2558
2559 The @samp{start} command does the equivalent of setting a temporary
2560 breakpoint at the beginning of the main procedure and then invoking
2561 the @samp{run} command.
2562
2563 @cindex elaboration phase
2564 Some programs contain an @dfn{elaboration} phase where some startup code is
2565 executed before the main procedure is called. This depends on the
2566 languages used to write your program. In C@t{++}, for instance,
2567 constructors for static and global objects are executed before
2568 @code{main} is called. It is therefore possible that the debugger stops
2569 before reaching the main procedure. However, the temporary breakpoint
2570 will remain to halt execution.
2571
2572 Specify the arguments to give to your program as arguments to the
2573 @samp{start} command. These arguments will be given verbatim to the
2574 underlying @samp{run} command. Note that the same arguments will be
2575 reused if no argument is provided during subsequent calls to
2576 @samp{start} or @samp{run}.
2577
2578 It is sometimes necessary to debug the program during elaboration. In
2579 these cases, using the @code{start} command would stop the execution
2580 of your program too late, as the program would have already completed
2581 the elaboration phase. Under these circumstances, either insert
2582 breakpoints in your elaboration code before running your program or
2583 use the @code{starti} command.
2584
2585 @kindex starti
2586 @item starti
2587 @cindex run to first instruction
2588 The @samp{starti} command does the equivalent of setting a temporary
2589 breakpoint at the first instruction of a program's execution and then
2590 invoking the @samp{run} command. For programs containing an
2591 elaboration phase, the @code{starti} command will stop execution at
2592 the start of the elaboration phase.
2593
2594 @anchor{set exec-wrapper}
2595 @kindex set exec-wrapper
2596 @item set exec-wrapper @var{wrapper}
2597 @itemx show exec-wrapper
2598 @itemx unset exec-wrapper
2599 When @samp{exec-wrapper} is set, the specified wrapper is used to
2600 launch programs for debugging. @value{GDBN} starts your program
2601 with a shell command of the form @kbd{exec @var{wrapper}
2602 @var{program}}. Quoting is added to @var{program} and its
2603 arguments, but not to @var{wrapper}, so you should add quotes if
2604 appropriate for your shell. The wrapper runs until it executes
2605 your program, and then @value{GDBN} takes control.
2606
2607 You can use any program that eventually calls @code{execve} with
2608 its arguments as a wrapper. Several standard Unix utilities do
2609 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2610 with @code{exec "$@@"} will also work.
2611
2612 For example, you can use @code{env} to pass an environment variable to
2613 the debugged program, without setting the variable in your shell's
2614 environment:
2615
2616 @smallexample
2617 (@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2618 (@value{GDBP}) run
2619 @end smallexample
2620
2621 This command is available when debugging locally on most targets, excluding
2622 @sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2623
2624 @kindex set startup-with-shell
2625 @anchor{set startup-with-shell}
2626 @item set startup-with-shell
2627 @itemx set startup-with-shell on
2628 @itemx set startup-with-shell off
2629 @itemx show startup-with-shell
2630 On Unix systems, by default, if a shell is available on your target,
2631 @value{GDBN}) uses it to start your program. Arguments of the
2632 @code{run} command are passed to the shell, which does variable
2633 substitution, expands wildcard characters and performs redirection of
2634 I/O. In some circumstances, it may be useful to disable such use of a
2635 shell, for example, when debugging the shell itself or diagnosing
2636 startup failures such as:
2637
2638 @smallexample
2639 (@value{GDBP}) run
2640 Starting program: ./a.out
2641 During startup program terminated with signal SIGSEGV, Segmentation fault.
2642 @end smallexample
2643
2644 @noindent
2645 which indicates the shell or the wrapper specified with
2646 @samp{exec-wrapper} crashed, not your program. Most often, this is
2647 caused by something odd in your shell's non-interactive mode
2648 initialization file---such as @file{.cshrc} for C-shell,
2649 $@file{.zshenv} for the Z shell, or the file specified in the
2650 @samp{BASH_ENV} environment variable for BASH.
2651
2652 @anchor{set auto-connect-native-target}
2653 @kindex set auto-connect-native-target
2654 @item set auto-connect-native-target
2655 @itemx set auto-connect-native-target on
2656 @itemx set auto-connect-native-target off
2657 @itemx show auto-connect-native-target
2658
2659 By default, if the current inferior is not connected to any target yet
2660 (e.g., with @code{target remote}), the @code{run} command starts your
2661 program as a native process under @value{GDBN}, on your local machine.
2662 If you're sure you don't want to debug programs on your local machine,
2663 you can tell @value{GDBN} to not connect to the native target
2664 automatically with the @code{set auto-connect-native-target off}
2665 command.
2666
2667 If @code{on}, which is the default, and if the current inferior is not
2668 connected to a target already, the @code{run} command automaticaly
2669 connects to the native target, if one is available.
2670
2671 If @code{off}, and if the current inferior is not connected to a
2672 target already, the @code{run} command fails with an error:
2673
2674 @smallexample
2675 (@value{GDBP}) run
2676 Don't know how to run. Try "help target".
2677 @end smallexample
2678
2679 If the current inferior is already connected to a target, @value{GDBN}
2680 always uses it with the @code{run} command.
2681
2682 In any case, you can explicitly connect to the native target with the
2683 @code{target native} command. For example,
2684
2685 @smallexample
2686 (@value{GDBP}) set auto-connect-native-target off
2687 (@value{GDBP}) run
2688 Don't know how to run. Try "help target".
2689 (@value{GDBP}) target native
2690 (@value{GDBP}) run
2691 Starting program: ./a.out
2692 [Inferior 1 (process 10421) exited normally]
2693 @end smallexample
2694
2695 In case you connected explicitly to the @code{native} target,
2696 @value{GDBN} remains connected even if all inferiors exit, ready for
2697 the next @code{run} command. Use the @code{disconnect} command to
2698 disconnect.
2699
2700 Examples of other commands that likewise respect the
2701 @code{auto-connect-native-target} setting: @code{attach}, @code{info
2702 proc}, @code{info os}.
2703
2704 @kindex set disable-randomization
2705 @item set disable-randomization
2706 @itemx set disable-randomization on
2707 This option (enabled by default in @value{GDBN}) will turn off the native
2708 randomization of the virtual address space of the started program. This option
2709 is useful for multiple debugging sessions to make the execution better
2710 reproducible and memory addresses reusable across debugging sessions.
2711
2712 This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2713 On @sc{gnu}/Linux you can get the same behavior using
2714
2715 @smallexample
2716 (@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2717 @end smallexample
2718
2719 @item set disable-randomization off
2720 Leave the behavior of the started executable unchanged. Some bugs rear their
2721 ugly heads only when the program is loaded at certain addresses. If your bug
2722 disappears when you run the program under @value{GDBN}, that might be because
2723 @value{GDBN} by default disables the address randomization on platforms, such
2724 as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2725 disable-randomization off} to try to reproduce such elusive bugs.
2726
2727 On targets where it is available, virtual address space randomization
2728 protects the programs against certain kinds of security attacks. In these
2729 cases the attacker needs to know the exact location of a concrete executable
2730 code. Randomizing its location makes it impossible to inject jumps misusing
2731 a code at its expected addresses.
2732
2733 Prelinking shared libraries provides a startup performance advantage but it
2734 makes addresses in these libraries predictable for privileged processes by
2735 having just unprivileged access at the target system. Reading the shared
2736 library binary gives enough information for assembling the malicious code
2737 misusing it. Still even a prelinked shared library can get loaded at a new
2738 random address just requiring the regular relocation process during the
2739 startup. Shared libraries not already prelinked are always loaded at
2740 a randomly chosen address.
2741
2742 Position independent executables (PIE) contain position independent code
2743 similar to the shared libraries and therefore such executables get loaded at
2744 a randomly chosen address upon startup. PIE executables always load even
2745 already prelinked shared libraries at a random address. You can build such
2746 executable using @command{gcc -fPIE -pie}.
2747
2748 Heap (malloc storage), stack and custom mmap areas are always placed randomly
2749 (as long as the randomization is enabled).
2750
2751 @item show disable-randomization
2752 Show the current setting of the explicit disable of the native randomization of
2753 the virtual address space of the started program.
2754
2755 @end table
2756
2757 @node Arguments
2758 @section Your Program's Arguments
2759
2760 @cindex arguments (to your program)
2761 The arguments to your program can be specified by the arguments of the
2762 @code{run} command.
2763 They are passed to a shell, which expands wildcard characters and
2764 performs redirection of I/O, and thence to your program. Your
2765 @code{SHELL} environment variable (if it exists) specifies what shell
2766 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
2767 the default shell (@file{/bin/sh} on Unix).
2768
2769 On non-Unix systems, the program is usually invoked directly by
2770 @value{GDBN}, which emulates I/O redirection via the appropriate system
2771 calls, and the wildcard characters are expanded by the startup code of
2772 the program, not by the shell.
2773
2774 @code{run} with no arguments uses the same arguments used by the previous
2775 @code{run}, or those set by the @code{set args} command.
2776
2777 @table @code
2778 @kindex set args
2779 @item set args
2780 Specify the arguments to be used the next time your program is run. If
2781 @code{set args} has no arguments, @code{run} executes your program
2782 with no arguments. Once you have run your program with arguments,
2783 using @code{set args} before the next @code{run} is the only way to run
2784 it again without arguments.
2785
2786 @kindex show args
2787 @item show args
2788 Show the arguments to give your program when it is started.
2789 @end table
2790
2791 @node Environment
2792 @section Your Program's Environment
2793
2794 @cindex environment (of your program)
2795 The @dfn{environment} consists of a set of environment variables and
2796 their values. Environment variables conventionally record such things as
2797 your user name, your home directory, your terminal type, and your search
2798 path for programs to run. Usually you set up environment variables with
2799 the shell and they are inherited by all the other programs you run. When
2800 debugging, it can be useful to try running your program with a modified
2801 environment without having to start @value{GDBN} over again.
2802
2803 @table @code
2804 @kindex path
2805 @item path @var{directory}
2806 Add @var{directory} to the front of the @code{PATH} environment variable
2807 (the search path for executables) that will be passed to your program.
2808 The value of @code{PATH} used by @value{GDBN} does not change.
2809 You may specify several directory names, separated by whitespace or by a
2810 system-dependent separator character (@samp{:} on Unix, @samp{;} on
2811 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2812 is moved to the front, so it is searched sooner.
2813
2814 You can use the string @samp{$cwd} to refer to whatever is the current
2815 working directory at the time @value{GDBN} searches the path. If you
2816 use @samp{.} instead, it refers to the directory where you executed the
2817 @code{path} command. @value{GDBN} replaces @samp{.} in the
2818 @var{directory} argument (with the current path) before adding
2819 @var{directory} to the search path.
2820 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2821 @c document that, since repeating it would be a no-op.
2822
2823 @kindex show paths
2824 @item show paths
2825 Display the list of search paths for executables (the @code{PATH}
2826 environment variable).
2827
2828 @kindex show environment
2829 @item show environment @r{[}@var{varname}@r{]}
2830 Print the value of environment variable @var{varname} to be given to
2831 your program when it starts. If you do not supply @var{varname},
2832 print the names and values of all environment variables to be given to
2833 your program. You can abbreviate @code{environment} as @code{env}.
2834
2835 @kindex set environment
2836 @anchor{set environment}
2837 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2838 Set environment variable @var{varname} to @var{value}. The value
2839 changes for your program (and the shell @value{GDBN} uses to launch
2840 it), not for @value{GDBN} itself. The @var{value} may be any string; the
2841 values of environment variables are just strings, and any
2842 interpretation is supplied by your program itself. The @var{value}
2843 parameter is optional; if it is eliminated, the variable is set to a
2844 null value.
2845 @c "any string" here does not include leading, trailing
2846 @c blanks. Gnu asks: does anyone care?
2847
2848 For example, this command:
2849
2850 @smallexample
2851 set env USER = foo
2852 @end smallexample
2853
2854 @noindent
2855 tells the debugged program, when subsequently run, that its user is named
2856 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2857 are not actually required.)
2858
2859 Note that on Unix systems, @value{GDBN} runs your program via a shell,
2860 which also inherits the environment set with @code{set environment}.
2861 If necessary, you can avoid that by using the @samp{env} program as a
2862 wrapper instead of using @code{set environment}. @xref{set
2863 exec-wrapper}, for an example doing just that.
2864
2865 Environment variables that are set by the user are also transmitted to
2866 @command{gdbserver} to be used when starting the remote inferior.
2867 @pxref{QEnvironmentHexEncoded}.
2868
2869 @kindex unset environment
2870 @anchor{unset environment}
2871 @item unset environment @var{varname}
2872 Remove variable @var{varname} from the environment to be passed to your
2873 program. This is different from @samp{set env @var{varname} =};
2874 @code{unset environment} removes the variable from the environment,
2875 rather than assigning it an empty value.
2876
2877 Environment variables that are unset by the user are also unset on
2878 @command{gdbserver} when starting the remote inferior.
2879 @pxref{QEnvironmentUnset}.
2880 @end table
2881
2882 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2883 the shell indicated by your @code{SHELL} environment variable if it
2884 exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2885 names a shell that runs an initialization file when started
2886 non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2887 for the Z shell, or the file specified in the @samp{BASH_ENV}
2888 environment variable for BASH---any variables you set in that file
2889 affect your program. You may wish to move setting of environment
2890 variables to files that are only run when you sign on, such as
2891 @file{.login} or @file{.profile}.
2892
2893 @node Working Directory
2894 @section Your Program's Working Directory
2895
2896 @cindex working directory (of your program)
2897 Each time you start your program with @code{run}, the inferior will be
2898 initialized with the current working directory specified by the
2899 @kbd{set cwd} command. If no directory has been specified by this
2900 command, then the inferior will inherit @value{GDBN}'s current working
2901 directory as its working directory if native debugging, or it will
2902 inherit the remote server's current working directory if remote
2903 debugging.
2904
2905 @table @code
2906 @kindex set cwd
2907 @cindex change inferior's working directory
2908 @anchor{set cwd command}
2909 @item set cwd @r{[}@var{directory}@r{]}
2910 Set the inferior's working directory to @var{directory}, which will be
2911 @code{glob}-expanded in order to resolve tildes (@file{~}). If no
2912 argument has been specified, the command clears the setting and resets
2913 it to an empty state. This setting has no effect on @value{GDBN}'s
2914 working directory, and it only takes effect the next time you start
2915 the inferior. The @file{~} in @var{directory} is a short for the
2916 @dfn{home directory}, usually pointed to by the @env{HOME} environment
2917 variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2918 uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2919 fallback.
2920
2921 You can also change @value{GDBN}'s current working directory by using
2922 the @code{cd} command.
2923 @xref{cd command}.
2924
2925 @kindex show cwd
2926 @cindex show inferior's working directory
2927 @item show cwd
2928 Show the inferior's working directory. If no directory has been
2929 specified by @kbd{set cwd}, then the default inferior's working
2930 directory is the same as @value{GDBN}'s working directory.
2931
2932 @kindex cd
2933 @cindex change @value{GDBN}'s working directory
2934 @anchor{cd command}
2935 @item cd @r{[}@var{directory}@r{]}
2936 Set the @value{GDBN} working directory to @var{directory}. If not
2937 given, @var{directory} uses @file{'~'}.
2938
2939 The @value{GDBN} working directory serves as a default for the
2940 commands that specify files for @value{GDBN} to operate on.
2941 @xref{Files, ,Commands to Specify Files}.
2942 @xref{set cwd command}.
2943
2944 @kindex pwd
2945 @item pwd
2946 Print the @value{GDBN} working directory.
2947 @end table
2948
2949 It is generally impossible to find the current working directory of
2950 the process being debugged (since a program can change its directory
2951 during its run). If you work on a system where @value{GDBN} supports
2952 the @code{info proc} command (@pxref{Process Information}), you can
2953 use the @code{info proc} command to find out the
2954 current working directory of the debuggee.
2955
2956 @node Input/Output
2957 @section Your Program's Input and Output
2958
2959 @cindex redirection
2960 @cindex i/o
2961 @cindex terminal
2962 By default, the program you run under @value{GDBN} does input and output to
2963 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
2964 to its own terminal modes to interact with you, but it records the terminal
2965 modes your program was using and switches back to them when you continue
2966 running your program.
2967
2968 @table @code
2969 @kindex info terminal
2970 @item info terminal
2971 Displays information recorded by @value{GDBN} about the terminal modes your
2972 program is using.
2973 @end table
2974
2975 You can redirect your program's input and/or output using shell
2976 redirection with the @code{run} command. For example,
2977
2978 @smallexample
2979 run > outfile
2980 @end smallexample
2981
2982 @noindent
2983 starts your program, diverting its output to the file @file{outfile}.
2984
2985 @kindex tty
2986 @cindex controlling terminal
2987 Another way to specify where your program should do input and output is
2988 with the @code{tty} command. This command accepts a file name as
2989 argument, and causes this file to be the default for future @code{run}
2990 commands. It also resets the controlling terminal for the child
2991 process, for future @code{run} commands. For example,
2992
2993 @smallexample
2994 tty /dev/ttyb
2995 @end smallexample
2996
2997 @noindent
2998 directs that processes started with subsequent @code{run} commands
2999 default to do input and output on the terminal @file{/dev/ttyb} and have
3000 that as their controlling terminal.
3001
3002 An explicit redirection in @code{run} overrides the @code{tty} command's
3003 effect on the input/output device, but not its effect on the controlling
3004 terminal.
3005
3006 When you use the @code{tty} command or redirect input in the @code{run}
3007 command, only the input @emph{for your program} is affected. The input
3008 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
3009 for @code{set inferior-tty}.
3010
3011 @cindex inferior tty
3012 @cindex set inferior controlling terminal
3013 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
3014 display the name of the terminal that will be used for future runs of your
3015 program.
3016
3017 @table @code
3018 @item set inferior-tty [ @var{tty} ]
3019 @kindex set inferior-tty
3020 Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
3021 restores the default behavior, which is to use the same terminal as
3022 @value{GDBN}.
3023
3024 @item show inferior-tty
3025 @kindex show inferior-tty
3026 Show the current tty for the program being debugged.
3027 @end table
3028
3029 @node Attach
3030 @section Debugging an Already-running Process
3031 @kindex attach
3032 @cindex attach
3033
3034 @table @code
3035 @item attach @var{process-id}
3036 This command attaches to a running process---one that was started
3037 outside @value{GDBN}. (@code{info files} shows your active
3038 targets.) The command takes as argument a process ID. The usual way to
3039 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
3040 or with the @samp{jobs -l} shell command.
3041
3042 @code{attach} does not repeat if you press @key{RET} a second time after
3043 executing the command.
3044 @end table
3045
3046 To use @code{attach}, your program must be running in an environment
3047 which supports processes; for example, @code{attach} does not work for
3048 programs on bare-board targets that lack an operating system. You must
3049 also have permission to send the process a signal.
3050
3051 When you use @code{attach}, the debugger finds the program running in
3052 the process first by looking in the current working directory, then (if
3053 the program is not found) by using the source file search path
3054 (@pxref{Source Path, ,Specifying Source Directories}). You can also use
3055 the @code{file} command to load the program. @xref{Files, ,Commands to
3056 Specify Files}.
3057
3058 @anchor{set exec-file-mismatch}
3059 If the debugger can determine that the executable file running in the
3060 process it is attaching to does not match the current exec-file loaded
3061 by @value{GDBN}, the option @code{exec-file-mismatch} specifies how to
3062 handle the mismatch. @value{GDBN} tries to compare the files by
3063 comparing their build IDs (@pxref{build ID}), if available.
3064
3065 @table @code
3066 @kindex exec-file-mismatch
3067 @cindex set exec-file-mismatch
3068 @item set exec-file-mismatch @samp{ask|warn|off}
3069
3070 Whether to detect mismatch between the current executable file loaded
3071 by @value{GDBN} and the executable file used to start the process. If
3072 @samp{ask}, the default, display a warning and ask the user whether to
3073 load the process executable file; if @samp{warn}, just display a
3074 warning; if @samp{off}, don't attempt to detect a mismatch.
3075 If the user confirms loading the process executable file, then its symbols
3076 will be loaded as well.
3077
3078 @cindex show exec-file-mismatch
3079 @item show exec-file-mismatch
3080 Show the current value of @code{exec-file-mismatch}.
3081
3082 @end table
3083
3084 The first thing @value{GDBN} does after arranging to debug the specified
3085 process is to stop it. You can examine and modify an attached process
3086 with all the @value{GDBN} commands that are ordinarily available when
3087 you start processes with @code{run}. You can insert breakpoints; you
3088 can step and continue; you can modify storage. If you would rather the
3089 process continue running, you may use the @code{continue} command after
3090 attaching @value{GDBN} to the process.
3091
3092 @table @code
3093 @kindex detach
3094 @item detach
3095 When you have finished debugging the attached process, you can use the
3096 @code{detach} command to release it from @value{GDBN} control. Detaching
3097 the process continues its execution. After the @code{detach} command,
3098 that process and @value{GDBN} become completely independent once more, and you
3099 are ready to @code{attach} another process or start one with @code{run}.
3100 @code{detach} does not repeat if you press @key{RET} again after
3101 executing the command.
3102 @end table
3103
3104 If you exit @value{GDBN} while you have an attached process, you detach
3105 that process. If you use the @code{run} command, you kill that process.
3106 By default, @value{GDBN} asks for confirmation if you try to do either of these
3107 things; you can control whether or not you need to confirm by using the
3108 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
3109 Messages}).
3110
3111 @node Kill Process
3112 @section Killing the Child Process
3113
3114 @table @code
3115 @kindex kill
3116 @item kill
3117 Kill the child process in which your program is running under @value{GDBN}.
3118 @end table
3119
3120 This command is useful if you wish to debug a core dump instead of a
3121 running process. @value{GDBN} ignores any core dump file while your program
3122 is running.
3123
3124 On some operating systems, a program cannot be executed outside @value{GDBN}
3125 while you have breakpoints set on it inside @value{GDBN}. You can use the
3126 @code{kill} command in this situation to permit running your program
3127 outside the debugger.
3128
3129 The @code{kill} command is also useful if you wish to recompile and
3130 relink your program, since on many systems it is impossible to modify an
3131 executable file while it is running in a process. In this case, when you
3132 next type @code{run}, @value{GDBN} notices that the file has changed, and
3133 reads the symbol table again (while trying to preserve your current
3134 breakpoint settings).
3135
3136 @node Inferiors Connections and Programs
3137 @section Debugging Multiple Inferiors Connections and Programs
3138
3139 @value{GDBN} lets you run and debug multiple programs in a single
3140 session. In addition, @value{GDBN} on some systems may let you run
3141 several programs simultaneously (otherwise you have to exit from one
3142 before starting another). On some systems @value{GDBN} may even let
3143 you debug several programs simultaneously on different remote systems.
3144 In the most general case, you can have multiple threads of execution
3145 in each of multiple processes, launched from multiple executables,
3146 running on different machines.
3147
3148 @cindex inferior
3149 @value{GDBN} represents the state of each program execution with an
3150 object called an @dfn{inferior}. An inferior typically corresponds to
3151 a process, but is more general and applies also to targets that do not
3152 have processes. Inferiors may be created before a process runs, and
3153 may be retained after a process exits. Inferiors have unique
3154 identifiers that are different from process ids. Usually each
3155 inferior will also have its own distinct address space, although some
3156 embedded targets may have several inferiors running in different parts
3157 of a single address space. Each inferior may in turn have multiple
3158 threads running in it.
3159
3160 To find out what inferiors exist at any moment, use @w{@code{info
3161 inferiors}}:
3162
3163 @table @code
3164 @kindex info inferiors [ @var{id}@dots{} ]
3165 @item info inferiors
3166 Print a list of all inferiors currently being managed by @value{GDBN}.
3167 By default all inferiors are printed, but the argument @var{id}@dots{}
3168 -- a space separated list of inferior numbers -- can be used to limit
3169 the display to just the requested inferiors.
3170
3171 @value{GDBN} displays for each inferior (in this order):
3172
3173 @enumerate
3174 @item
3175 the inferior number assigned by @value{GDBN}
3176
3177 @item
3178 the target system's inferior identifier
3179
3180 @item
3181 the target connection the inferior is bound to, including the unique
3182 connection number assigned by @value{GDBN}, and the protocol used by
3183 the connection.
3184
3185 @item
3186 the name of the executable the inferior is running.
3187
3188 @end enumerate
3189
3190 @noindent
3191 An asterisk @samp{*} preceding the @value{GDBN} inferior number
3192 indicates the current inferior.
3193
3194 For example,
3195 @end table
3196 @c end table here to get a little more width for example
3197
3198 @smallexample
3199 (@value{GDBP}) info inferiors
3200 Num Description Connection Executable
3201 * 1 process 3401 1 (native) goodbye
3202 2 process 2307 2 (extended-remote host:10000) hello
3203 @end smallexample
3204
3205 To find out what open target connections exist at any moment, use
3206 @w{@code{info connections}}:
3207
3208 @table @code
3209 @kindex info connections [ @var{id}@dots{} ]
3210 @item info connections
3211 Print a list of all open target connections currently being managed by
3212 @value{GDBN}. By default all connections are printed, but the
3213 argument @var{id}@dots{} -- a space separated list of connections
3214 numbers -- can be used to limit the display to just the requested
3215 connections.
3216
3217 @value{GDBN} displays for each connection (in this order):
3218
3219 @enumerate
3220 @item
3221 the connection number assigned by @value{GDBN}.
3222
3223 @item
3224 the protocol used by the connection.
3225
3226 @item
3227 a textual description of the protocol used by the connection.
3228
3229 @end enumerate
3230
3231 @noindent
3232 An asterisk @samp{*} preceding the connection number indicates the
3233 connection of the current inferior.
3234
3235 For example,
3236 @end table
3237 @c end table here to get a little more width for example
3238
3239 @smallexample
3240 (@value{GDBP}) info connections
3241 Num What Description
3242 * 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3243 2 native Native process
3244 3 core Local core dump file
3245 @end smallexample
3246
3247 To switch focus between inferiors, use the @code{inferior} command:
3248
3249 @table @code
3250 @kindex inferior @var{infno}
3251 @item inferior @var{infno}
3252 Make inferior number @var{infno} the current inferior. The argument
3253 @var{infno} is the inferior number assigned by @value{GDBN}, as shown
3254 in the first field of the @samp{info inferiors} display.
3255 @end table
3256
3257 @vindex $_inferior@r{, convenience variable}
3258 The debugger convenience variable @samp{$_inferior} contains the
3259 number of the current inferior. You may find this useful in writing
3260 breakpoint conditional expressions, command scripts, and so forth.
3261 @xref{Convenience Vars,, Convenience Variables}, for general
3262 information on convenience variables.
3263
3264 You can get multiple executables into a debugging session via the
3265 @code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3266 systems @value{GDBN} can add inferiors to the debug session
3267 automatically by following calls to @code{fork} and @code{exec}. To
3268 remove inferiors from the debugging session use the
3269 @w{@code{remove-inferiors}} command.
3270
3271 @table @code
3272 @kindex add-inferior
3273 @item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
3274 Adds @var{n} inferiors to be run using @var{executable} as the
3275 executable; @var{n} defaults to 1. If no executable is specified,
3276 the inferiors begins empty, with no program. You can still assign or
3277 change the program assigned to the inferior at any time by using the
3278 @code{file} command with the executable name as its argument.
3279
3280 By default, the new inferior begins connected to the same target
3281 connection as the current inferior. For example, if the current
3282 inferior was connected to @code{gdbserver} with @code{target remote},
3283 then the new inferior will be connected to the same @code{gdbserver}
3284 instance. The @samp{-no-connection} option starts the new inferior
3285 with no connection yet. You can then for example use the @code{target
3286 remote} command to connect to some other @code{gdbserver} instance,
3287 use @code{run} to spawn a local program, etc.
3288
3289 @kindex clone-inferior
3290 @item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3291 Adds @var{n} inferiors ready to execute the same program as inferior
3292 @var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
3293 number of the current inferior. This is a convenient command when you
3294 want to run another instance of the inferior you are debugging.
3295
3296 @smallexample
3297 (@value{GDBP}) info inferiors
3298 Num Description Connection Executable
3299 * 1 process 29964 1 (native) helloworld
3300 (@value{GDBP}) clone-inferior
3301 Added inferior 2.
3302 1 inferiors added.
3303 (@value{GDBP}) info inferiors
3304 Num Description Connection Executable
3305 * 1 process 29964 1 (native) helloworld
3306 2 <null> 1 (native) helloworld
3307 @end smallexample
3308
3309 You can now simply switch focus to inferior 2 and run it.
3310
3311 @kindex remove-inferiors
3312 @item remove-inferiors @var{infno}@dots{}
3313 Removes the inferior or inferiors @var{infno}@dots{}. It is not
3314 possible to remove an inferior that is running with this command. For
3315 those, use the @code{kill} or @code{detach} command first.
3316
3317 @end table
3318
3319 To quit debugging one of the running inferiors that is not the current
3320 inferior, you can either detach from it by using the @w{@code{detach
3321 inferior}} command (allowing it to run independently), or kill it
3322 using the @w{@code{kill inferiors}} command:
3323
3324 @table @code
3325 @kindex detach inferiors @var{infno}@dots{}
3326 @item detach inferior @var{infno}@dots{}
3327 Detach from the inferior or inferiors identified by @value{GDBN}
3328 inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
3329 still stays on the list of inferiors shown by @code{info inferiors},
3330 but its Description will show @samp{<null>}.
3331
3332 @kindex kill inferiors @var{infno}@dots{}
3333 @item kill inferiors @var{infno}@dots{}
3334 Kill the inferior or inferiors identified by @value{GDBN} inferior
3335 number(s) @var{infno}@dots{}. Note that the inferior's entry still
3336 stays on the list of inferiors shown by @code{info inferiors}, but its
3337 Description will show @samp{<null>}.
3338 @end table
3339
3340 After the successful completion of a command such as @code{detach},
3341 @code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
3342 a normal process exit, the inferior is still valid and listed with
3343 @code{info inferiors}, ready to be restarted.
3344
3345
3346 To be notified when inferiors are started or exit under @value{GDBN}'s
3347 control use @w{@code{set print inferior-events}}:
3348
3349 @table @code
3350 @kindex set print inferior-events
3351 @cindex print messages on inferior start and exit
3352 @item set print inferior-events
3353 @itemx set print inferior-events on
3354 @itemx set print inferior-events off
3355 The @code{set print inferior-events} command allows you to enable or
3356 disable printing of messages when @value{GDBN} notices that new
3357 inferiors have started or that inferiors have exited or have been
3358 detached. By default, these messages will not be printed.
3359
3360 @kindex show print inferior-events
3361 @item show print inferior-events
3362 Show whether messages will be printed when @value{GDBN} detects that
3363 inferiors have started, exited or have been detached.
3364 @end table
3365
3366 Many commands will work the same with multiple programs as with a
3367 single program: e.g., @code{print myglobal} will simply display the
3368 value of @code{myglobal} in the current inferior.
3369
3370
3371 Occasionally, when debugging @value{GDBN} itself, it may be useful to
3372 get more info about the relationship of inferiors, programs, address
3373 spaces in a debug session. You can do that with the @w{@code{maint
3374 info program-spaces}} command.
3375
3376 @table @code
3377 @kindex maint info program-spaces
3378 @item maint info program-spaces
3379 Print a list of all program spaces currently being managed by
3380 @value{GDBN}.
3381
3382 @value{GDBN} displays for each program space (in this order):
3383
3384 @enumerate
3385 @item
3386 the program space number assigned by @value{GDBN}
3387
3388 @item
3389 the name of the executable loaded into the program space, with e.g.,
3390 the @code{file} command.
3391
3392 @end enumerate
3393
3394 @noindent
3395 An asterisk @samp{*} preceding the @value{GDBN} program space number
3396 indicates the current program space.
3397
3398 In addition, below each program space line, @value{GDBN} prints extra
3399 information that isn't suitable to display in tabular form. For
3400 example, the list of inferiors bound to the program space.
3401
3402 @smallexample
3403 (@value{GDBP}) maint info program-spaces
3404 Id Executable
3405 * 1 hello
3406 2 goodbye
3407 Bound inferiors: ID 1 (process 21561)
3408 @end smallexample
3409
3410 Here we can see that no inferior is running the program @code{hello},
3411 while @code{process 21561} is running the program @code{goodbye}. On
3412 some targets, it is possible that multiple inferiors are bound to the
3413 same program space. The most common example is that of debugging both
3414 the parent and child processes of a @code{vfork} call. For example,
3415
3416 @smallexample
3417 (@value{GDBP}) maint info program-spaces
3418 Id Executable
3419 * 1 vfork-test
3420 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3421 @end smallexample
3422
3423 Here, both inferior 2 and inferior 1 are running in the same program
3424 space as a result of inferior 1 having executed a @code{vfork} call.
3425 @end table
3426
3427 @node Threads
3428 @section Debugging Programs with Multiple Threads
3429
3430 @cindex threads of execution
3431 @cindex multiple threads
3432 @cindex switching threads
3433 In some operating systems, such as GNU/Linux and Solaris, a single program
3434 may have more than one @dfn{thread} of execution. The precise semantics
3435 of threads differ from one operating system to another, but in general
3436 the threads of a single program are akin to multiple processes---except
3437 that they share one address space (that is, they can all examine and
3438 modify the same variables). On the other hand, each thread has its own
3439 registers and execution stack, and perhaps private memory.
3440
3441 @value{GDBN} provides these facilities for debugging multi-thread
3442 programs:
3443
3444 @itemize @bullet
3445 @item automatic notification of new threads
3446 @item @samp{thread @var{thread-id}}, a command to switch among threads
3447 @item @samp{info threads}, a command to inquire about existing threads
3448 @item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
3449 a command to apply a command to a list of threads
3450 @item thread-specific breakpoints
3451 @item @samp{set print thread-events}, which controls printing of
3452 messages on thread start and exit.
3453 @item @samp{set libthread-db-search-path @var{path}}, which lets
3454 the user specify which @code{libthread_db} to use if the default choice
3455 isn't compatible with the program.
3456 @end itemize
3457
3458 @cindex focus of debugging
3459 @cindex current thread
3460 The @value{GDBN} thread debugging facility allows you to observe all
3461 threads while your program runs---but whenever @value{GDBN} takes
3462 control, one thread in particular is always the focus of debugging.
3463 This thread is called the @dfn{current thread}. Debugging commands show
3464 program information from the perspective of the current thread.
3465
3466 @cindex @code{New} @var{systag} message
3467 @cindex thread identifier (system)
3468 @c FIXME-implementors!! It would be more helpful if the [New...] message
3469 @c included GDB's numeric thread handle, so you could just go to that
3470 @c thread without first checking `info threads'.
3471 Whenever @value{GDBN} detects a new thread in your program, it displays
3472 the target system's identification for the thread with a message in the
3473 form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
3474 whose form varies depending on the particular system. For example, on
3475 @sc{gnu}/Linux, you might see
3476
3477 @smallexample
3478 [New Thread 0x41e02940 (LWP 25582)]
3479 @end smallexample
3480
3481 @noindent
3482 when @value{GDBN} notices a new thread. In contrast, on other systems,
3483 the @var{systag} is simply something like @samp{process 368}, with no
3484 further qualifier.
3485
3486 @c FIXME!! (1) Does the [New...] message appear even for the very first
3487 @c thread of a program, or does it only appear for the
3488 @c second---i.e.@: when it becomes obvious we have a multithread
3489 @c program?
3490 @c (2) *Is* there necessarily a first thread always? Or do some
3491 @c multithread systems permit starting a program with multiple
3492 @c threads ab initio?
3493
3494 @anchor{thread numbers}
3495 @cindex thread number, per inferior
3496 @cindex thread identifier (GDB)
3497 For debugging purposes, @value{GDBN} associates its own thread number
3498 ---always a single integer---with each thread of an inferior. This
3499 number is unique between all threads of an inferior, but not unique
3500 between threads of different inferiors.
3501
3502 @cindex qualified thread ID
3503 You can refer to a given thread in an inferior using the qualified
3504 @var{inferior-num}.@var{thread-num} syntax, also known as
3505 @dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3506 number and @var{thread-num} being the thread number of the given
3507 inferior. For example, thread @code{2.3} refers to thread number 3 of
3508 inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3509 then @value{GDBN} infers you're referring to a thread of the current
3510 inferior.
3511
3512 Until you create a second inferior, @value{GDBN} does not show the
3513 @var{inferior-num} part of thread IDs, even though you can always use
3514 the full @var{inferior-num}.@var{thread-num} form to refer to threads
3515 of inferior 1, the initial inferior.
3516
3517 @anchor{thread ID lists}
3518 @cindex thread ID lists
3519 Some commands accept a space-separated @dfn{thread ID list} as
3520 argument. A list element can be:
3521
3522 @enumerate
3523 @item
3524 A thread ID as shown in the first field of the @samp{info threads}
3525 display, with or without an inferior qualifier. E.g., @samp{2.1} or
3526 @samp{1}.
3527
3528 @item
3529 A range of thread numbers, again with or without an inferior
3530 qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3531 @var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3532
3533 @item
3534 All threads of an inferior, specified with a star wildcard, with or
3535 without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3536 @samp{1.*}) or @code{*}. The former refers to all threads of the
3537 given inferior, and the latter form without an inferior qualifier
3538 refers to all threads of the current inferior.
3539
3540 @end enumerate
3541
3542 For example, if the current inferior is 1, and inferior 7 has one
3543 thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3544 includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
3545 7 to 9 of inferior 6 and all threads of inferior 7. That is, in
3546 expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
3547 7.1}.
3548
3549
3550 @anchor{global thread numbers}
3551 @cindex global thread number
3552 @cindex global thread identifier (GDB)
3553 In addition to a @emph{per-inferior} number, each thread is also
3554 assigned a unique @emph{global} number, also known as @dfn{global
3555 thread ID}, a single integer. Unlike the thread number component of
3556 the thread ID, no two threads have the same global ID, even when
3557 you're debugging multiple inferiors.
3558
3559 From @value{GDBN}'s perspective, a process always has at least one
3560 thread. In other words, @value{GDBN} assigns a thread number to the
3561 program's ``main thread'' even if the program is not multi-threaded.
3562
3563 @vindex $_thread@r{, convenience variable}
3564 @vindex $_gthread@r{, convenience variable}
3565 The debugger convenience variables @samp{$_thread} and
3566 @samp{$_gthread} contain, respectively, the per-inferior thread number
3567 and the global thread number of the current thread. You may find this
3568 useful in writing breakpoint conditional expressions, command scripts,
3569 and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3570 general information on convenience variables.
3571
3572 If @value{GDBN} detects the program is multi-threaded, it augments the
3573 usual message about stopping at a breakpoint with the ID and name of
3574 the thread that hit the breakpoint.
3575
3576 @smallexample
3577 Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3578 @end smallexample
3579
3580 Likewise when the program receives a signal:
3581
3582 @smallexample
3583 Thread 1 "main" received signal SIGINT, Interrupt.
3584 @end smallexample
3585
3586 @table @code
3587 @kindex info threads
3588 @item info threads @r{[}@var{thread-id-list}@r{]}
3589
3590 Display information about one or more threads. With no arguments
3591 displays information about all threads. You can specify the list of
3592 threads that you want to display using the thread ID list syntax
3593 (@pxref{thread ID lists}).
3594
3595 @value{GDBN} displays for each thread (in this order):
3596
3597 @enumerate
3598 @item
3599 the per-inferior thread number assigned by @value{GDBN}
3600
3601 @item
3602 the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3603 option was specified
3604
3605 @item
3606 the target system's thread identifier (@var{systag})
3607
3608 @item
3609 the thread's name, if one is known. A thread can either be named by
3610 the user (see @code{thread name}, below), or, in some cases, by the
3611 program itself.
3612
3613 @item
3614 the current stack frame summary for that thread
3615 @end enumerate
3616
3617 @noindent
3618 An asterisk @samp{*} to the left of the @value{GDBN} thread number
3619 indicates the current thread.
3620
3621 For example,
3622 @end table
3623 @c end table here to get a little more width for example
3624
3625 @smallexample
3626 (@value{GDBP}) info threads
3627 Id Target Id Frame
3628 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3629 2 process 35 thread 23 0x34e5 in sigpause ()
3630 3 process 35 thread 27 0x34e5 in sigpause ()
3631 at threadtest.c:68
3632 @end smallexample
3633
3634 If you're debugging multiple inferiors, @value{GDBN} displays thread
3635 IDs using the qualified @var{inferior-num}.@var{thread-num} format.
3636 Otherwise, only @var{thread-num} is shown.
3637
3638 If you specify the @samp{-gid} option, @value{GDBN} displays a column
3639 indicating each thread's global thread ID:
3640
3641 @smallexample
3642 (@value{GDBP}) info threads
3643 Id GId Target Id Frame
3644 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3645 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3646 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3647 * 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
3648 @end smallexample
3649
3650 On Solaris, you can display more information about user threads with a
3651 Solaris-specific command:
3652
3653 @table @code
3654 @item maint info sol-threads
3655 @kindex maint info sol-threads
3656 @cindex thread info (Solaris)
3657 Display info on Solaris user threads.
3658 @end table
3659
3660 @table @code
3661 @kindex thread @var{thread-id}
3662 @item thread @var{thread-id}
3663 Make thread ID @var{thread-id} the current thread. The command
3664 argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3665 the first field of the @samp{info threads} display, with or without an
3666 inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3667
3668 @value{GDBN} responds by displaying the system identifier of the
3669 thread you selected, and its current stack frame summary:
3670
3671 @smallexample
3672 (@value{GDBP}) thread 2
3673 [Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3674 #0 some_function (ignore=0x0) at example.c:8
3675 8 printf ("hello\n");
3676 @end smallexample
3677
3678 @noindent
3679 As with the @samp{[New @dots{}]} message, the form of the text after
3680 @samp{Switching to} depends on your system's conventions for identifying
3681 threads.
3682
3683 @anchor{thread apply all}
3684 @kindex thread apply
3685 @cindex apply command to several threads
3686 @item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
3687 The @code{thread apply} command allows you to apply the named
3688 @var{command} to one or more threads. Specify the threads that you
3689 want affected using the thread ID list syntax (@pxref{thread ID
3690 lists}), or specify @code{all} to apply to all threads. To apply a
3691 command to all threads in descending order, type @kbd{thread apply all
3692 @var{command}}. To apply a command to all threads in ascending order,
3693 type @kbd{thread apply all -ascending @var{command}}.
3694
3695 The @var{flag} arguments control what output to produce and how to handle
3696 errors raised when applying @var{command} to a thread. @var{flag}
3697 must start with a @code{-} directly followed by one letter in
3698 @code{qcs}. If several flags are provided, they must be given
3699 individually, such as @code{-c -q}.
3700
3701 By default, @value{GDBN} displays some thread information before the
3702 output produced by @var{command}, and an error raised during the
3703 execution of a @var{command} will abort @code{thread apply}. The
3704 following flags can be used to fine-tune this behavior:
3705
3706 @table @code
3707 @item -c
3708 The flag @code{-c}, which stands for @samp{continue}, causes any
3709 errors in @var{command} to be displayed, and the execution of
3710 @code{thread apply} then continues.
3711 @item -s
3712 The flag @code{-s}, which stands for @samp{silent}, causes any errors
3713 or empty output produced by a @var{command} to be silently ignored.
3714 That is, the execution continues, but the thread information and errors
3715 are not printed.
3716 @item -q
3717 The flag @code{-q} (@samp{quiet}) disables printing the thread
3718 information.
3719 @end table
3720
3721 Flags @code{-c} and @code{-s} cannot be used together.
3722
3723 @kindex taas
3724 @cindex apply command to all threads (ignoring errors and empty output)
3725 @item taas [@var{option}]@dots{} @var{command}
3726 Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
3727 Applies @var{command} on all threads, ignoring errors and empty output.
3728
3729 The @code{taas} command accepts the same options as the @code{thread
3730 apply all} command. @xref{thread apply all}.
3731
3732 @kindex tfaas
3733 @cindex apply a command to all frames of all threads (ignoring errors and empty output)
3734 @item tfaas [@var{option}]@dots{} @var{command}
3735 Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
3736 Applies @var{command} on all frames of all threads, ignoring errors
3737 and empty output. Note that the flag @code{-s} is specified twice:
3738 The first @code{-s} ensures that @code{thread apply} only shows the thread
3739 information of the threads for which @code{frame apply} produces
3740 some output. The second @code{-s} is needed to ensure that @code{frame
3741 apply} shows the frame information of a frame only if the
3742 @var{command} successfully produced some output.
3743
3744 It can for example be used to print a local variable or a function
3745 argument without knowing the thread or frame where this variable or argument
3746 is, using:
3747 @smallexample
3748 (@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3749 @end smallexample
3750
3751 The @code{tfaas} command accepts the same options as the @code{frame
3752 apply} command. @xref{Frame Apply,,frame apply}.
3753
3754 @kindex thread name
3755 @cindex name a thread
3756 @item thread name [@var{name}]
3757 This command assigns a name to the current thread. If no argument is
3758 given, any existing user-specified name is removed. The thread name
3759 appears in the @samp{info threads} display.
3760
3761 On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3762 determine the name of the thread as given by the OS. On these
3763 systems, a name specified with @samp{thread name} will override the
3764 system-give name, and removing the user-specified name will cause
3765 @value{GDBN} to once again display the system-specified name.
3766
3767 @kindex thread find
3768 @cindex search for a thread
3769 @item thread find [@var{regexp}]
3770 Search for and display thread ids whose name or @var{systag}
3771 matches the supplied regular expression.
3772
3773 As well as being the complement to the @samp{thread name} command,
3774 this command also allows you to identify a thread by its target
3775 @var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3776 is the LWP id.
3777
3778 @smallexample
3779 (@value{GDBN}) thread find 26688
3780 Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3781 (@value{GDBN}) info thread 4
3782 Id Target Id Frame
3783 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3784 @end smallexample
3785
3786 @kindex set print thread-events
3787 @cindex print messages on thread start and exit
3788 @item set print thread-events
3789 @itemx set print thread-events on
3790 @itemx set print thread-events off
3791 The @code{set print thread-events} command allows you to enable or
3792 disable printing of messages when @value{GDBN} notices that new threads have
3793 started or that threads have exited. By default, these messages will
3794 be printed if detection of these events is supported by the target.
3795 Note that these messages cannot be disabled on all targets.
3796
3797 @kindex show print thread-events
3798 @item show print thread-events
3799 Show whether messages will be printed when @value{GDBN} detects that threads
3800 have started and exited.
3801 @end table
3802
3803 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
3804 more information about how @value{GDBN} behaves when you stop and start
3805 programs with multiple threads.
3806
3807 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
3808 watchpoints in programs with multiple threads.
3809
3810 @anchor{set libthread-db-search-path}
3811 @table @code
3812 @kindex set libthread-db-search-path
3813 @cindex search path for @code{libthread_db}
3814 @item set libthread-db-search-path @r{[}@var{path}@r{]}
3815 If this variable is set, @var{path} is a colon-separated list of
3816 directories @value{GDBN} will use to search for @code{libthread_db}.
3817 If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
3818 its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
3819 Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3820 macro.
3821
3822 On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3823 @code{libthread_db} library to obtain information about threads in the
3824 inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
3825 to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3826 specific thread debugging library loading is enabled
3827 by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
3828
3829 A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3830 refers to the default system directories that are
3831 normally searched for loading shared libraries. The @samp{$sdir} entry
3832 is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3833 (@pxref{libthread_db.so.1 file}).
3834
3835 A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3836 refers to the directory from which @code{libpthread}
3837 was loaded in the inferior process.
3838
3839 For any @code{libthread_db} library @value{GDBN} finds in above directories,
3840 @value{GDBN} attempts to initialize it with the current inferior process.
3841 If this initialization fails (which could happen because of a version
3842 mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3843 will unload @code{libthread_db}, and continue with the next directory.
3844 If none of @code{libthread_db} libraries initialize successfully,
3845 @value{GDBN} will issue a warning and thread debugging will be disabled.
3846
3847 Setting @code{libthread-db-search-path} is currently implemented
3848 only on some platforms.
3849
3850 @kindex show libthread-db-search-path
3851 @item show libthread-db-search-path
3852 Display current libthread_db search path.
3853
3854 @kindex set debug libthread-db
3855 @kindex show debug libthread-db
3856 @cindex debugging @code{libthread_db}
3857 @item set debug libthread-db
3858 @itemx show debug libthread-db
3859 Turns on or off display of @code{libthread_db}-related events.
3860 Use @code{1} to enable, @code{0} to disable.
3861 @end table
3862
3863 @node Forks
3864 @section Debugging Forks
3865
3866 @cindex fork, debugging programs which call
3867 @cindex multiple processes
3868 @cindex processes, multiple
3869 On most systems, @value{GDBN} has no special support for debugging
3870 programs which create additional processes using the @code{fork}
3871 function. When a program forks, @value{GDBN} will continue to debug the
3872 parent process and the child process will run unimpeded. If you have
3873 set a breakpoint in any code which the child then executes, the child
3874 will get a @code{SIGTRAP} signal which (unless it catches the signal)
3875 will cause it to terminate.
3876
3877 However, if you want to debug the child process there is a workaround
3878 which isn't too painful. Put a call to @code{sleep} in the code which
3879 the child process executes after the fork. It may be useful to sleep
3880 only if a certain environment variable is set, or a certain file exists,
3881 so that the delay need not occur when you don't want to run @value{GDBN}
3882 on the child. While the child is sleeping, use the @code{ps} program to
3883 get its process ID. Then tell @value{GDBN} (a new invocation of
3884 @value{GDBN} if you are also debugging the parent process) to attach to
3885 the child process (@pxref{Attach}). From that point on you can debug
3886 the child process just like any other process which you attached to.
3887
3888 On some systems, @value{GDBN} provides support for debugging programs
3889 that create additional processes using the @code{fork} or @code{vfork}
3890 functions. On @sc{gnu}/Linux platforms, this feature is supported
3891 with kernel version 2.5.46 and later.
3892
3893 The fork debugging commands are supported in native mode and when
3894 connected to @code{gdbserver} in either @code{target remote} mode or
3895 @code{target extended-remote} mode.
3896
3897 By default, when a program forks, @value{GDBN} will continue to debug
3898 the parent process and the child process will run unimpeded.
3899
3900 If you want to follow the child process instead of the parent process,
3901 use the command @w{@code{set follow-fork-mode}}.
3902
3903 @table @code
3904 @kindex set follow-fork-mode
3905 @item set follow-fork-mode @var{mode}
3906 Set the debugger response to a program call of @code{fork} or
3907 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
3908 process. The @var{mode} argument can be:
3909
3910 @table @code
3911 @item parent
3912 The original process is debugged after a fork. The child process runs
3913 unimpeded. This is the default.
3914
3915 @item child
3916 The new process is debugged after a fork. The parent process runs
3917 unimpeded.
3918
3919 @end table
3920
3921 @kindex show follow-fork-mode
3922 @item show follow-fork-mode
3923 Display the current debugger response to a @code{fork} or @code{vfork} call.
3924 @end table
3925
3926 @cindex debugging multiple processes
3927 On Linux, if you want to debug both the parent and child processes, use the
3928 command @w{@code{set detach-on-fork}}.
3929
3930 @table @code
3931 @kindex set detach-on-fork
3932 @item set detach-on-fork @var{mode}
3933 Tells gdb whether to detach one of the processes after a fork, or
3934 retain debugger control over them both.
3935
3936 @table @code
3937 @item on
3938 The child process (or parent process, depending on the value of
3939 @code{follow-fork-mode}) will be detached and allowed to run
3940 independently. This is the default.
3941
3942 @item off
3943 Both processes will be held under the control of @value{GDBN}.
3944 One process (child or parent, depending on the value of
3945 @code{follow-fork-mode}) is debugged as usual, while the other
3946 is held suspended.
3947
3948 @end table
3949
3950 @kindex show detach-on-fork
3951 @item show detach-on-fork
3952 Show whether detach-on-fork mode is on/off.
3953 @end table
3954
3955 If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3956 will retain control of all forked processes (including nested forks).
3957 You can list the forked processes under the control of @value{GDBN} by
3958 using the @w{@code{info inferiors}} command, and switch from one fork
3959 to another by using the @code{inferior} command (@pxref{Inferiors Connections and
3960 Programs, ,Debugging Multiple Inferiors Connections and Programs}).
3961
3962 To quit debugging one of the forked processes, you can either detach
3963 from it by using the @w{@code{detach inferiors}} command (allowing it
3964 to run independently), or kill it using the @w{@code{kill inferiors}}
3965 command. @xref{Inferiors Connections and Programs, ,Debugging
3966 Multiple Inferiors Connections and Programs}.
3967
3968 If you ask to debug a child process and a @code{vfork} is followed by an
3969 @code{exec}, @value{GDBN} executes the new target up to the first
3970 breakpoint in the new target. If you have a breakpoint set on
3971 @code{main} in your original program, the breakpoint will also be set on
3972 the child process's @code{main}.
3973
3974 On some systems, when a child process is spawned by @code{vfork}, you
3975 cannot debug the child or parent until an @code{exec} call completes.
3976
3977 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
3978 call executes, the new target restarts. To restart the parent
3979 process, use the @code{file} command with the parent executable name
3980 as its argument. By default, after an @code{exec} call executes,
3981 @value{GDBN} discards the symbols of the previous executable image.
3982 You can change this behaviour with the @w{@code{set follow-exec-mode}}
3983 command.
3984
3985 @table @code
3986 @kindex set follow-exec-mode
3987 @item set follow-exec-mode @var{mode}
3988
3989 Set debugger response to a program call of @code{exec}. An
3990 @code{exec} call replaces the program image of a process.
3991
3992 @code{follow-exec-mode} can be:
3993
3994 @table @code
3995 @item new
3996 @value{GDBN} creates a new inferior and rebinds the process to this
3997 new inferior. The program the process was running before the
3998 @code{exec} call can be restarted afterwards by restarting the
3999 original inferior.
4000
4001 For example:
4002
4003 @smallexample
4004 (@value{GDBP}) info inferiors
4005 (gdb) info inferior
4006 Id Description Executable
4007 * 1 <null> prog1
4008 (@value{GDBP}) run
4009 process 12020 is executing new program: prog2
4010 Program exited normally.
4011 (@value{GDBP}) info inferiors
4012 Id Description Executable
4013 1 <null> prog1
4014 * 2 <null> prog2
4015 @end smallexample
4016
4017 @item same
4018 @value{GDBN} keeps the process bound to the same inferior. The new
4019 executable image replaces the previous executable loaded in the
4020 inferior. Restarting the inferior after the @code{exec} call, with
4021 e.g., the @code{run} command, restarts the executable the process was
4022 running after the @code{exec} call. This is the default mode.
4023
4024 For example:
4025
4026 @smallexample
4027 (@value{GDBP}) info inferiors
4028 Id Description Executable
4029 * 1 <null> prog1
4030 (@value{GDBP}) run
4031 process 12020 is executing new program: prog2
4032 Program exited normally.
4033 (@value{GDBP}) info inferiors
4034 Id Description Executable
4035 * 1 <null> prog2
4036 @end smallexample
4037
4038 @end table
4039 @end table
4040
4041 @code{follow-exec-mode} is supported in native mode and
4042 @code{target extended-remote} mode.
4043
4044 You can use the @code{catch} command to make @value{GDBN} stop whenever
4045 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
4046 Catchpoints, ,Setting Catchpoints}.
4047
4048 @node Checkpoint/Restart
4049 @section Setting a @emph{Bookmark} to Return to Later
4050
4051 @cindex checkpoint
4052 @cindex restart
4053 @cindex bookmark
4054 @cindex snapshot of a process
4055 @cindex rewind program state
4056
4057 On certain operating systems@footnote{Currently, only
4058 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
4059 program's state, called a @dfn{checkpoint}, and come back to it
4060 later.
4061
4062 Returning to a checkpoint effectively undoes everything that has
4063 happened in the program since the @code{checkpoint} was saved. This
4064 includes changes in memory, registers, and even (within some limits)
4065 system state. Effectively, it is like going back in time to the
4066 moment when the checkpoint was saved.
4067
4068 Thus, if you're stepping thru a program and you think you're
4069 getting close to the point where things go wrong, you can save
4070 a checkpoint. Then, if you accidentally go too far and miss
4071 the critical statement, instead of having to restart your program
4072 from the beginning, you can just go back to the checkpoint and
4073 start again from there.
4074
4075 This can be especially useful if it takes a lot of time or
4076 steps to reach the point where you think the bug occurs.
4077
4078 To use the @code{checkpoint}/@code{restart} method of debugging:
4079
4080 @table @code
4081 @kindex checkpoint
4082 @item checkpoint
4083 Save a snapshot of the debugged program's current execution state.
4084 The @code{checkpoint} command takes no arguments, but each checkpoint
4085 is assigned a small integer id, similar to a breakpoint id.
4086
4087 @kindex info checkpoints
4088 @item info checkpoints
4089 List the checkpoints that have been saved in the current debugging
4090 session. For each checkpoint, the following information will be
4091 listed:
4092
4093 @table @code
4094 @item Checkpoint ID
4095 @item Process ID
4096 @item Code Address
4097 @item Source line, or label
4098 @end table
4099
4100 @kindex restart @var{checkpoint-id}
4101 @item restart @var{checkpoint-id}
4102 Restore the program state that was saved as checkpoint number
4103 @var{checkpoint-id}. All program variables, registers, stack frames
4104 etc.@: will be returned to the values that they had when the checkpoint
4105 was saved. In essence, gdb will ``wind back the clock'' to the point
4106 in time when the checkpoint was saved.
4107
4108 Note that breakpoints, @value{GDBN} variables, command history etc.
4109 are not affected by restoring a checkpoint. In general, a checkpoint
4110 only restores things that reside in the program being debugged, not in
4111 the debugger.
4112
4113 @kindex delete checkpoint @var{checkpoint-id}
4114 @item delete checkpoint @var{checkpoint-id}
4115 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
4116
4117 @end table
4118
4119 Returning to a previously saved checkpoint will restore the user state
4120 of the program being debugged, plus a significant subset of the system
4121 (OS) state, including file pointers. It won't ``un-write'' data from
4122 a file, but it will rewind the file pointer to the previous location,
4123 so that the previously written data can be overwritten. For files
4124 opened in read mode, the pointer will also be restored so that the
4125 previously read data can be read again.
4126
4127 Of course, characters that have been sent to a printer (or other
4128 external device) cannot be ``snatched back'', and characters received
4129 from eg.@: a serial device can be removed from internal program buffers,
4130 but they cannot be ``pushed back'' into the serial pipeline, ready to
4131 be received again. Similarly, the actual contents of files that have
4132 been changed cannot be restored (at this time).
4133
4134 However, within those constraints, you actually can ``rewind'' your
4135 program to a previously saved point in time, and begin debugging it
4136 again --- and you can change the course of events so as to debug a
4137 different execution path this time.
4138
4139 @cindex checkpoints and process id
4140 Finally, there is one bit of internal program state that will be
4141 different when you return to a checkpoint --- the program's process
4142 id. Each checkpoint will have a unique process id (or @var{pid}),
4143 and each will be different from the program's original @var{pid}.
4144 If your program has saved a local copy of its process id, this could
4145 potentially pose a problem.
4146
4147 @subsection A Non-obvious Benefit of Using Checkpoints
4148
4149 On some systems such as @sc{gnu}/Linux, address space randomization
4150 is performed on new processes for security reasons. This makes it
4151 difficult or impossible to set a breakpoint, or watchpoint, on an
4152 absolute address if you have to restart the program, since the
4153 absolute location of a symbol will change from one execution to the
4154 next.
4155
4156 A checkpoint, however, is an @emph{identical} copy of a process.
4157 Therefore if you create a checkpoint at (eg.@:) the start of main,
4158 and simply return to that checkpoint instead of restarting the
4159 process, you can avoid the effects of address randomization and
4160 your symbols will all stay in the same place.
4161
4162 @node Stopping
4163 @chapter Stopping and Continuing
4164
4165 The principal purposes of using a debugger are so that you can stop your
4166 program before it terminates; or so that, if your program runs into
4167 trouble, you can investigate and find out why.
4168
4169 Inside @value{GDBN}, your program may stop for any of several reasons,
4170 such as a signal, a breakpoint, or reaching a new line after a
4171 @value{GDBN} command such as @code{step}. You may then examine and
4172 change variables, set new breakpoints or remove old ones, and then
4173 continue execution. Usually, the messages shown by @value{GDBN} provide
4174 ample explanation of the status of your program---but you can also
4175 explicitly request this information at any time.
4176
4177 @table @code
4178 @kindex info program
4179 @item info program
4180 Display information about the status of your program: whether it is
4181 running or not, what process it is, and why it stopped.
4182 @end table
4183
4184 @menu
4185 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
4186 * Continuing and Stepping:: Resuming execution
4187 * Skipping Over Functions and Files::
4188 Skipping over functions and files
4189 * Signals:: Signals
4190 * Thread Stops:: Stopping and starting multi-thread programs
4191 @end menu
4192
4193 @node Breakpoints
4194 @section Breakpoints, Watchpoints, and Catchpoints
4195
4196 @cindex breakpoints
4197 A @dfn{breakpoint} makes your program stop whenever a certain point in
4198 the program is reached. For each breakpoint, you can add conditions to
4199 control in finer detail whether your program stops. You can set
4200 breakpoints with the @code{break} command and its variants (@pxref{Set
4201 Breaks, ,Setting Breakpoints}), to specify the place where your program
4202 should stop by line number, function name or exact address in the
4203 program.
4204
4205 On some systems, you can set breakpoints in shared libraries before
4206 the executable is run.
4207
4208 @cindex watchpoints
4209 @cindex data breakpoints
4210 @cindex memory tracing
4211 @cindex breakpoint on memory address
4212 @cindex breakpoint on variable modification
4213 A @dfn{watchpoint} is a special breakpoint that stops your program
4214 when the value of an expression changes. The expression may be a value
4215 of a variable, or it could involve values of one or more variables
4216 combined by operators, such as @samp{a + b}. This is sometimes called
4217 @dfn{data breakpoints}. You must use a different command to set
4218 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
4219 from that, you can manage a watchpoint like any other breakpoint: you
4220 enable, disable, and delete both breakpoints and watchpoints using the
4221 same commands.
4222
4223 You can arrange to have values from your program displayed automatically
4224 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
4225 Automatic Display}.
4226
4227 @cindex catchpoints
4228 @cindex breakpoint on events
4229 A @dfn{catchpoint} is another special breakpoint that stops your program
4230 when a certain kind of event occurs, such as the throwing of a C@t{++}
4231 exception or the loading of a library. As with watchpoints, you use a
4232 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
4233 Catchpoints}), but aside from that, you can manage a catchpoint like any
4234 other breakpoint. (To stop when your program receives a signal, use the
4235 @code{handle} command; see @ref{Signals, ,Signals}.)
4236
4237 @cindex breakpoint numbers
4238 @cindex numbers for breakpoints
4239 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
4240 catchpoint when you create it; these numbers are successive integers
4241 starting with one. In many of the commands for controlling various
4242 features of breakpoints you use the breakpoint number to say which
4243 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4244 @dfn{disabled}; if disabled, it has no effect on your program until you
4245 enable it again.
4246
4247 @cindex breakpoint ranges
4248 @cindex breakpoint lists
4249 @cindex ranges of breakpoints
4250 @cindex lists of breakpoints
4251 Some @value{GDBN} commands accept a space-separated list of breakpoints
4252 on which to operate. A list element can be either a single breakpoint number,
4253 like @samp{5}, or a range of such numbers, like @samp{5-7}.
4254 When a breakpoint list is given to a command, all breakpoints in that list
4255 are operated on.
4256
4257 @menu
4258 * Set Breaks:: Setting breakpoints
4259 * Set Watchpoints:: Setting watchpoints
4260 * Set Catchpoints:: Setting catchpoints
4261 * Delete Breaks:: Deleting breakpoints
4262 * Disabling:: Disabling breakpoints
4263 * Conditions:: Break conditions
4264 * Break Commands:: Breakpoint command lists
4265 * Dynamic Printf:: Dynamic printf
4266 * Save Breakpoints:: How to save breakpoints in a file
4267 * Static Probe Points:: Listing static probe points
4268 * Error in Breakpoints:: ``Cannot insert breakpoints''
4269 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
4270 @end menu
4271
4272 @node Set Breaks
4273 @subsection Setting Breakpoints
4274
4275 @c FIXME LMB what does GDB do if no code on line of breakpt?
4276 @c consider in particular declaration with/without initialization.
4277 @c
4278 @c FIXME 2 is there stuff on this already? break at fun start, already init?
4279
4280 @kindex break
4281 @kindex b @r{(@code{break})}
4282 @vindex $bpnum@r{, convenience variable}
4283 @cindex latest breakpoint
4284 Breakpoints are set with the @code{break} command (abbreviated
4285 @code{b}). The debugger convenience variable @samp{$bpnum} records the
4286 number of the breakpoint you've set most recently; see @ref{Convenience
4287 Vars,, Convenience Variables}, for a discussion of what you can do with
4288 convenience variables.
4289
4290 @table @code
4291 @item break @var{location}
4292 Set a breakpoint at the given @var{location}, which can specify a
4293 function name, a line number, or an address of an instruction.
4294 (@xref{Specify Location}, for a list of all the possible ways to
4295 specify a @var{location}.) The breakpoint will stop your program just
4296 before it executes any of the code in the specified @var{location}.
4297
4298 When using source languages that permit overloading of symbols, such as
4299 C@t{++}, a function name may refer to more than one possible place to break.
4300 @xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
4301 that situation.
4302
4303 It is also possible to insert a breakpoint that will stop the program
4304 only if a specific thread (@pxref{Thread-Specific Breakpoints})
4305 or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
4306
4307 @item break
4308 When called without any arguments, @code{break} sets a breakpoint at
4309 the next instruction to be executed in the selected stack frame
4310 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4311 innermost, this makes your program stop as soon as control
4312 returns to that frame. This is similar to the effect of a
4313 @code{finish} command in the frame inside the selected frame---except
4314 that @code{finish} does not leave an active breakpoint. If you use
4315 @code{break} without an argument in the innermost frame, @value{GDBN} stops
4316 the next time it reaches the current location; this may be useful
4317 inside loops.
4318
4319 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
4320 least one instruction has been executed. If it did not do this, you
4321 would be unable to proceed past a breakpoint without first disabling the
4322 breakpoint. This rule applies whether or not the breakpoint already
4323 existed when your program stopped.
4324
4325 @item break @dots{} if @var{cond}
4326 Set a breakpoint with condition @var{cond}; evaluate the expression
4327 @var{cond} each time the breakpoint is reached, and stop only if the
4328 value is nonzero---that is, if @var{cond} evaluates as true.
4329 @samp{@dots{}} stands for one of the possible arguments described
4330 above (or no argument) specifying where to break. @xref{Conditions,
4331 ,Break Conditions}, for more information on breakpoint conditions.
4332
4333 The breakpoint may be mapped to multiple locations. If the breakpoint
4334 condition @var{cond} is invalid at some but not all of the locations,
4335 the locations for which the condition is invalid are disabled. For
4336 example, @value{GDBN} reports below that two of the three locations
4337 are disabled.
4338
4339 @smallexample
4340 (@value{GDBP}) break func if a == 10
4341 warning: failed to validate condition at location 0x11ce, disabling:
4342 No symbol "a" in current context.
4343 warning: failed to validate condition at location 0x11b6, disabling:
4344 No symbol "a" in current context.
4345 Breakpoint 1 at 0x11b6: func. (3 locations)
4346 @end smallexample
4347
4348 Locations that are disabled because of the condition are denoted by an
4349 uppercase @code{N} in the output of the @code{info breakpoints}
4350 command:
4351
4352 @smallexample
4353 (@value{GDBP}) info breakpoints
4354 Num Type Disp Enb Address What
4355 1 breakpoint keep y <MULTIPLE>
4356 stop only if a == 10
4357 1.1 N* 0x00000000000011b6 in ...
4358 1.2 y 0x00000000000011c2 in ...
4359 1.3 N* 0x00000000000011ce in ...
4360 (*): Breakpoint condition is invalid at this location.
4361 @end smallexample
4362
4363 If the breakpoint condition @var{cond} is invalid in the context of
4364 @emph{all} the locations of the breakpoint, @value{GDBN} refuses to
4365 define the breakpoint. For example, if variable @code{foo} is an
4366 undefined variable:
4367
4368 @smallexample
4369 (@value{GDBP}) break func if foo
4370 No symbol "foo" in current context.
4371 @end smallexample
4372
4373 @item break @dots{} -force-condition if @var{cond}
4374 There may be cases where the condition @var{cond} is invalid at all
4375 the current locations, but the user knows that it will be valid at a
4376 future location; for example, because of a library load. In such
4377 cases, by using the @code{-force-condition} keyword before @samp{if},
4378 @value{GDBN} can be forced to define the breakpoint with the given
4379 condition expression instead of refusing it.
4380
4381 @smallexample
4382 (@value{GDBP}) break func -force-condition if foo
4383 warning: failed to validate condition at location 1, disabling:
4384 No symbol "foo" in current context.
4385 warning: failed to validate condition at location 2, disabling:
4386 No symbol "foo" in current context.
4387 warning: failed to validate condition at location 3, disabling:
4388 No symbol "foo" in current context.
4389 Breakpoint 1 at 0x1158: test.c:18. (3 locations)
4390 @end smallexample
4391
4392 This causes all the present locations where the breakpoint would
4393 otherwise be inserted, to be disabled, as seen in the example above.
4394 However, if there exist locations at which the condition is valid, the
4395 @code{-force-condition} keyword has no effect.
4396
4397 @kindex tbreak
4398 @item tbreak @var{args}
4399 Set a breakpoint enabled only for one stop. The @var{args} are the
4400 same as for the @code{break} command, and the breakpoint is set in the same
4401 way, but the breakpoint is automatically deleted after the first time your
4402 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
4403
4404 @kindex hbreak
4405 @cindex hardware breakpoints
4406 @item hbreak @var{args}
4407 Set a hardware-assisted breakpoint. The @var{args} are the same as for the
4408 @code{break} command and the breakpoint is set in the same way, but the
4409 breakpoint requires hardware support and some target hardware may not
4410 have this support. The main purpose of this is EPROM/ROM code
4411 debugging, so you can set a breakpoint at an instruction without
4412 changing the instruction. This can be used with the new trap-generation
4413 provided by SPARClite DSU and most x86-based targets. These targets
4414 will generate traps when a program accesses some data or instruction
4415 address that is assigned to the debug registers. However the hardware
4416 breakpoint registers can take a limited number of breakpoints. For
4417 example, on the DSU, only two data breakpoints can be set at a time, and
4418 @value{GDBN} will reject this command if more than two are used. Delete
4419 or disable unused hardware breakpoints before setting new ones
4420 (@pxref{Disabling, ,Disabling Breakpoints}).
4421 @xref{Conditions, ,Break Conditions}.
4422 For remote targets, you can restrict the number of hardware
4423 breakpoints @value{GDBN} will use, see @ref{set remote
4424 hardware-breakpoint-limit}.
4425
4426 @kindex thbreak
4427 @item thbreak @var{args}
4428 Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
4429 are the same as for the @code{hbreak} command and the breakpoint is set in
4430 the same way. However, like the @code{tbreak} command,
4431 the breakpoint is automatically deleted after the
4432 first time your program stops there. Also, like the @code{hbreak}
4433 command, the breakpoint requires hardware support and some target hardware
4434 may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4435 See also @ref{Conditions, ,Break Conditions}.
4436
4437 @kindex rbreak
4438 @cindex regular expression
4439 @cindex breakpoints at functions matching a regexp
4440 @cindex set breakpoints in many functions
4441 @item rbreak @var{regex}
4442 Set breakpoints on all functions matching the regular expression
4443 @var{regex}. This command sets an unconditional breakpoint on all
4444 matches, printing a list of all breakpoints it set. Once these
4445 breakpoints are set, they are treated just like the breakpoints set with
4446 the @code{break} command. You can delete them, disable them, or make
4447 them conditional the same way as any other breakpoint.
4448
4449 In programs using different languages, @value{GDBN} chooses the syntax
4450 to print the list of all breakpoints it sets according to the
4451 @samp{set language} value: using @samp{set language auto}
4452 (see @ref{Automatically, ,Set Language Automatically}) means to use the
4453 language of the breakpoint's function, other values mean to use
4454 the manually specified language (see @ref{Manually, ,Set Language Manually}).
4455
4456 The syntax of the regular expression is the standard one used with tools
4457 like @file{grep}. Note that this is different from the syntax used by
4458 shells, so for instance @code{foo*} matches all functions that include
4459 an @code{fo} followed by zero or more @code{o}s. There is an implicit
4460 @code{.*} leading and trailing the regular expression you supply, so to
4461 match only functions that begin with @code{foo}, use @code{^foo}.
4462
4463 @cindex non-member C@t{++} functions, set breakpoint in
4464 When debugging C@t{++} programs, @code{rbreak} is useful for setting
4465 breakpoints on overloaded functions that are not members of any special
4466 classes.
4467
4468 @cindex set breakpoints on all functions
4469 The @code{rbreak} command can be used to set breakpoints in
4470 @strong{all} the functions in a program, like this:
4471
4472 @smallexample
4473 (@value{GDBP}) rbreak .
4474 @end smallexample
4475
4476 @item rbreak @var{file}:@var{regex}
4477 If @code{rbreak} is called with a filename qualification, it limits
4478 the search for functions matching the given regular expression to the
4479 specified @var{file}. This can be used, for example, to set breakpoints on
4480 every function in a given file:
4481
4482 @smallexample
4483 (@value{GDBP}) rbreak file.c:.
4484 @end smallexample
4485
4486 The colon separating the filename qualifier from the regex may
4487 optionally be surrounded by spaces.
4488
4489 @kindex info breakpoints
4490 @cindex @code{$_} and @code{info breakpoints}
4491 @item info breakpoints @r{[}@var{list}@dots{}@r{]}
4492 @itemx info break @r{[}@var{list}@dots{}@r{]}
4493 Print a table of all breakpoints, watchpoints, and catchpoints set and
4494 not deleted. Optional argument @var{n} means print information only
4495 about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4496 For each breakpoint, following columns are printed:
4497
4498 @table @emph
4499 @item Breakpoint Numbers
4500 @item Type
4501 Breakpoint, watchpoint, or catchpoint.
4502 @item Disposition
4503 Whether the breakpoint is marked to be disabled or deleted when hit.
4504 @item Enabled or Disabled
4505 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
4506 that are not enabled.
4507 @item Address
4508 Where the breakpoint is in your program, as a memory address. For a
4509 pending breakpoint whose address is not yet known, this field will
4510 contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4511 library that has the symbol or line referred by breakpoint is loaded.
4512 See below for details. A breakpoint with several locations will
4513 have @samp{<MULTIPLE>} in this field---see below for details.
4514 @item What
4515 Where the breakpoint is in the source for your program, as a file and
4516 line number. For a pending breakpoint, the original string passed to
4517 the breakpoint command will be listed as it cannot be resolved until
4518 the appropriate shared library is loaded in the future.
4519 @end table
4520
4521 @noindent
4522 If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4523 ``target''. If mode is ``host'', breakpoint condition evaluation is done by
4524 @value{GDBN} on the host's side. If it is ``target'', then the condition
4525 is evaluated by the target. The @code{info break} command shows
4526 the condition on the line following the affected breakpoint, together with
4527 its condition evaluation mode in between parentheses.
4528
4529 Breakpoint commands, if any, are listed after that. A pending breakpoint is
4530 allowed to have a condition specified for it. The condition is not parsed for
4531 validity until a shared library is loaded that allows the pending
4532 breakpoint to resolve to a valid location.
4533
4534 @noindent
4535 @code{info break} with a breakpoint
4536 number @var{n} as argument lists only that breakpoint. The
4537 convenience variable @code{$_} and the default examining-address for
4538 the @code{x} command are set to the address of the last breakpoint
4539 listed (@pxref{Memory, ,Examining Memory}).
4540
4541 @noindent
4542 @code{info break} displays a count of the number of times the breakpoint
4543 has been hit. This is especially useful in conjunction with the
4544 @code{ignore} command. You can ignore a large number of breakpoint
4545 hits, look at the breakpoint info to see how many times the breakpoint
4546 was hit, and then run again, ignoring one less than that number. This
4547 will get you quickly to the last hit of that breakpoint.
4548
4549 @noindent
4550 For a breakpoints with an enable count (xref) greater than 1,
4551 @code{info break} also displays that count.
4552
4553 @end table
4554
4555 @value{GDBN} allows you to set any number of breakpoints at the same place in
4556 your program. There is nothing silly or meaningless about this. When
4557 the breakpoints are conditional, this is even useful
4558 (@pxref{Conditions, ,Break Conditions}).
4559
4560 @cindex multiple locations, breakpoints
4561 @cindex breakpoints, multiple locations
4562 It is possible that a breakpoint corresponds to several locations
4563 in your program. Examples of this situation are:
4564
4565 @itemize @bullet
4566 @item
4567 Multiple functions in the program may have the same name.
4568
4569 @item
4570 For a C@t{++} constructor, the @value{NGCC} compiler generates several
4571 instances of the function body, used in different cases.
4572
4573 @item
4574 For a C@t{++} template function, a given line in the function can
4575 correspond to any number of instantiations.
4576
4577 @item
4578 For an inlined function, a given source line can correspond to
4579 several places where that function is inlined.
4580 @end itemize
4581
4582 In all those cases, @value{GDBN} will insert a breakpoint at all
4583 the relevant locations.
4584
4585 A breakpoint with multiple locations is displayed in the breakpoint
4586 table using several rows---one header row, followed by one row for
4587 each breakpoint location. The header row has @samp{<MULTIPLE>} in the
4588 address column. The rows for individual locations contain the actual
4589 addresses for locations, and show the functions to which those
4590 locations belong. The number column for a location is of the form
4591 @var{breakpoint-number}.@var{location-number}.
4592
4593 For example:
4594
4595 @smallexample
4596 Num Type Disp Enb Address What
4597 1 breakpoint keep y <MULTIPLE>
4598 stop only if i==1
4599 breakpoint already hit 1 time
4600 1.1 y 0x080486a2 in void foo<int>() at t.cc:8
4601 1.2 y 0x080486ca in void foo<double>() at t.cc:8
4602 @end smallexample
4603
4604 You cannot delete the individual locations from a breakpoint. However,
4605 each location can be individually enabled or disabled by passing
4606 @var{breakpoint-number}.@var{location-number} as argument to the
4607 @code{enable} and @code{disable} commands. It's also possible to
4608 @code{enable} and @code{disable} a range of @var{location-number}
4609 locations using a @var{breakpoint-number} and two @var{location-number}s,
4610 in increasing order, separated by a hyphen, like
4611 @kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4612 in which case @value{GDBN} acts on all the locations in the range (inclusive).
4613 Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4614 all of the locations that belong to that breakpoint.
4615
4616 @cindex pending breakpoints
4617 It's quite common to have a breakpoint inside a shared library.
4618 Shared libraries can be loaded and unloaded explicitly,
4619 and possibly repeatedly, as the program is executed. To support
4620 this use case, @value{GDBN} updates breakpoint locations whenever
4621 any shared library is loaded or unloaded. Typically, you would
4622 set a breakpoint in a shared library at the beginning of your
4623 debugging session, when the library is not loaded, and when the
4624 symbols from the library are not available. When you try to set
4625 breakpoint, @value{GDBN} will ask you if you want to set
4626 a so called @dfn{pending breakpoint}---breakpoint whose address
4627 is not yet resolved.
4628
4629 After the program is run, whenever a new shared library is loaded,
4630 @value{GDBN} reevaluates all the breakpoints. When a newly loaded
4631 shared library contains the symbol or line referred to by some
4632 pending breakpoint, that breakpoint is resolved and becomes an
4633 ordinary breakpoint. When a library is unloaded, all breakpoints
4634 that refer to its symbols or source lines become pending again.
4635
4636 This logic works for breakpoints with multiple locations, too. For
4637 example, if you have a breakpoint in a C@t{++} template function, and
4638 a newly loaded shared library has an instantiation of that template,
4639 a new location is added to the list of locations for the breakpoint.
4640
4641 Except for having unresolved address, pending breakpoints do not
4642 differ from regular breakpoints. You can set conditions or commands,
4643 enable and disable them and perform other breakpoint operations.
4644
4645 @value{GDBN} provides some additional commands for controlling what
4646 happens when the @samp{break} command cannot resolve breakpoint
4647 address specification to an address:
4648
4649 @kindex set breakpoint pending
4650 @kindex show breakpoint pending
4651 @table @code
4652 @item set breakpoint pending auto
4653 This is the default behavior. When @value{GDBN} cannot find the breakpoint
4654 location, it queries you whether a pending breakpoint should be created.
4655
4656 @item set breakpoint pending on
4657 This indicates that an unrecognized breakpoint location should automatically
4658 result in a pending breakpoint being created.
4659
4660 @item set breakpoint pending off
4661 This indicates that pending breakpoints are not to be created. Any
4662 unrecognized breakpoint location results in an error. This setting does
4663 not affect any pending breakpoints previously created.
4664
4665 @item show breakpoint pending
4666 Show the current behavior setting for creating pending breakpoints.
4667 @end table
4668
4669 The settings above only affect the @code{break} command and its
4670 variants. Once breakpoint is set, it will be automatically updated
4671 as shared libraries are loaded and unloaded.
4672
4673 @cindex automatic hardware breakpoints
4674 For some targets, @value{GDBN} can automatically decide if hardware or
4675 software breakpoints should be used, depending on whether the
4676 breakpoint address is read-only or read-write. This applies to
4677 breakpoints set with the @code{break} command as well as to internal
4678 breakpoints set by commands like @code{next} and @code{finish}. For
4679 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
4680 breakpoints.
4681
4682 You can control this automatic behaviour with the following commands:
4683
4684 @kindex set breakpoint auto-hw
4685 @kindex show breakpoint auto-hw
4686 @table @code
4687 @item set breakpoint auto-hw on
4688 This is the default behavior. When @value{GDBN} sets a breakpoint, it
4689 will try to use the target memory map to decide if software or hardware
4690 breakpoint must be used.
4691
4692 @item set breakpoint auto-hw off
4693 This indicates @value{GDBN} should not automatically select breakpoint
4694 type. If the target provides a memory map, @value{GDBN} will warn when
4695 trying to set software breakpoint at a read-only address.
4696 @end table
4697
4698 @value{GDBN} normally implements breakpoints by replacing the program code
4699 at the breakpoint address with a special instruction, which, when
4700 executed, given control to the debugger. By default, the program
4701 code is so modified only when the program is resumed. As soon as
4702 the program stops, @value{GDBN} restores the original instructions. This
4703 behaviour guards against leaving breakpoints inserted in the
4704 target should gdb abrubptly disconnect. However, with slow remote
4705 targets, inserting and removing breakpoint can reduce the performance.
4706 This behavior can be controlled with the following commands::
4707
4708 @kindex set breakpoint always-inserted
4709 @kindex show breakpoint always-inserted
4710 @table @code
4711 @item set breakpoint always-inserted off
4712 All breakpoints, including newly added by the user, are inserted in
4713 the target only when the target is resumed. All breakpoints are
4714 removed from the target when it stops. This is the default mode.
4715
4716 @item set breakpoint always-inserted on
4717 Causes all breakpoints to be inserted in the target at all times. If
4718 the user adds a new breakpoint, or changes an existing breakpoint, the
4719 breakpoints in the target are updated immediately. A breakpoint is
4720 removed from the target only when breakpoint itself is deleted.
4721 @end table
4722
4723 @value{GDBN} handles conditional breakpoints by evaluating these conditions
4724 when a breakpoint breaks. If the condition is true, then the process being
4725 debugged stops, otherwise the process is resumed.
4726
4727 If the target supports evaluating conditions on its end, @value{GDBN} may
4728 download the breakpoint, together with its conditions, to it.
4729
4730 This feature can be controlled via the following commands:
4731
4732 @kindex set breakpoint condition-evaluation
4733 @kindex show breakpoint condition-evaluation
4734 @table @code
4735 @item set breakpoint condition-evaluation host
4736 This option commands @value{GDBN} to evaluate the breakpoint
4737 conditions on the host's side. Unconditional breakpoints are sent to
4738 the target which in turn receives the triggers and reports them back to GDB
4739 for condition evaluation. This is the standard evaluation mode.
4740
4741 @item set breakpoint condition-evaluation target
4742 This option commands @value{GDBN} to download breakpoint conditions
4743 to the target at the moment of their insertion. The target
4744 is responsible for evaluating the conditional expression and reporting
4745 breakpoint stop events back to @value{GDBN} whenever the condition
4746 is true. Due to limitations of target-side evaluation, some conditions
4747 cannot be evaluated there, e.g., conditions that depend on local data
4748 that is only known to the host. Examples include
4749 conditional expressions involving convenience variables, complex types
4750 that cannot be handled by the agent expression parser and expressions
4751 that are too long to be sent over to the target, specially when the
4752 target is a remote system. In these cases, the conditions will be
4753 evaluated by @value{GDBN}.
4754
4755 @item set breakpoint condition-evaluation auto
4756 This is the default mode. If the target supports evaluating breakpoint
4757 conditions on its end, @value{GDBN} will download breakpoint conditions to
4758 the target (limitations mentioned previously apply). If the target does
4759 not support breakpoint condition evaluation, then @value{GDBN} will fallback
4760 to evaluating all these conditions on the host's side.
4761 @end table
4762
4763
4764 @cindex negative breakpoint numbers
4765 @cindex internal @value{GDBN} breakpoints
4766 @value{GDBN} itself sometimes sets breakpoints in your program for
4767 special purposes, such as proper handling of @code{longjmp} (in C
4768 programs). These internal breakpoints are assigned negative numbers,
4769 starting with @code{-1}; @samp{info breakpoints} does not display them.
4770 You can see these breakpoints with the @value{GDBN} maintenance command
4771 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
4772
4773
4774 @node Set Watchpoints
4775 @subsection Setting Watchpoints
4776
4777 @cindex setting watchpoints
4778 You can use a watchpoint to stop execution whenever the value of an
4779 expression changes, without having to predict a particular place where
4780 this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4781 The expression may be as simple as the value of a single variable, or
4782 as complex as many variables combined by operators. Examples include:
4783
4784 @itemize @bullet
4785 @item
4786 A reference to the value of a single variable.
4787
4788 @item
4789 An address cast to an appropriate data type. For example,
4790 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4791 address (assuming an @code{int} occupies 4 bytes).
4792
4793 @item
4794 An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4795 expression can use any operators valid in the program's native
4796 language (@pxref{Languages}).
4797 @end itemize
4798
4799 You can set a watchpoint on an expression even if the expression can
4800 not be evaluated yet. For instance, you can set a watchpoint on
4801 @samp{*global_ptr} before @samp{global_ptr} is initialized.
4802 @value{GDBN} will stop when your program sets @samp{global_ptr} and
4803 the expression produces a valid value. If the expression becomes
4804 valid in some other way than changing a variable (e.g.@: if the memory
4805 pointed to by @samp{*global_ptr} becomes readable as the result of a
4806 @code{malloc} call), @value{GDBN} may not stop until the next time
4807 the expression changes.
4808
4809 @cindex software watchpoints
4810 @cindex hardware watchpoints
4811 Depending on your system, watchpoints may be implemented in software or
4812 hardware. @value{GDBN} does software watchpointing by single-stepping your
4813 program and testing the variable's value each time, which is hundreds of
4814 times slower than normal execution. (But this may still be worth it, to
4815 catch errors where you have no clue what part of your program is the
4816 culprit.)
4817
4818 On some systems, such as most PowerPC or x86-based targets,
4819 @value{GDBN} includes support for hardware watchpoints, which do not
4820 slow down the running of your program.
4821
4822 @table @code
4823 @kindex watch
4824 @item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4825 Set a watchpoint for an expression. @value{GDBN} will break when the
4826 expression @var{expr} is written into by the program and its value
4827 changes. The simplest (and the most popular) use of this command is
4828 to watch the value of a single variable:
4829
4830 @smallexample
4831 (@value{GDBP}) watch foo
4832 @end smallexample
4833
4834 If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
4835 argument, @value{GDBN} breaks only when the thread identified by
4836 @var{thread-id} changes the value of @var{expr}. If any other threads
4837 change the value of @var{expr}, @value{GDBN} will not break. Note
4838 that watchpoints restricted to a single thread in this way only work
4839 with Hardware Watchpoints.
4840
4841 Ordinarily a watchpoint respects the scope of variables in @var{expr}
4842 (see below). The @code{-location} argument tells @value{GDBN} to
4843 instead watch the memory referred to by @var{expr}. In this case,
4844 @value{GDBN} will evaluate @var{expr}, take the address of the result,
4845 and watch the memory at that address. The type of the result is used
4846 to determine the size of the watched memory. If the expression's
4847 result does not have an address, then @value{GDBN} will print an
4848 error.
4849
4850 The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4851 of masked watchpoints, if the current architecture supports this
4852 feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4853 Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4854 to an address to watch. The mask specifies that some bits of an address
4855 (the bits which are reset in the mask) should be ignored when matching
4856 the address accessed by the inferior against the watchpoint address.
4857 Thus, a masked watchpoint watches many addresses simultaneously---those
4858 addresses whose unmasked bits are identical to the unmasked bits in the
4859 watchpoint address. The @code{mask} argument implies @code{-location}.
4860 Examples:
4861
4862 @smallexample
4863 (@value{GDBP}) watch foo mask 0xffff00ff
4864 (@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4865 @end smallexample
4866
4867 @kindex rwatch
4868 @item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4869 Set a watchpoint that will break when the value of @var{expr} is read
4870 by the program.
4871
4872 @kindex awatch
4873 @item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4874 Set a watchpoint that will break when @var{expr} is either read from
4875 or written into by the program.
4876
4877 @kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4878 @item info watchpoints @r{[}@var{list}@dots{}@r{]}
4879 This command prints a list of watchpoints, using the same format as
4880 @code{info break} (@pxref{Set Breaks}).
4881 @end table
4882
4883 If you watch for a change in a numerically entered address you need to
4884 dereference it, as the address itself is just a constant number which will
4885 never change. @value{GDBN} refuses to create a watchpoint that watches
4886 a never-changing value:
4887
4888 @smallexample
4889 (@value{GDBP}) watch 0x600850
4890 Cannot watch constant value 0x600850.
4891 (@value{GDBP}) watch *(int *) 0x600850
4892 Watchpoint 1: *(int *) 6293584
4893 @end smallexample
4894
4895 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4896 watchpoints execute very quickly, and the debugger reports a change in
4897 value at the exact instruction where the change occurs. If @value{GDBN}
4898 cannot set a hardware watchpoint, it sets a software watchpoint, which
4899 executes more slowly and reports the change in value at the next
4900 @emph{statement}, not the instruction, after the change occurs.
4901
4902 @cindex use only software watchpoints
4903 You can force @value{GDBN} to use only software watchpoints with the
4904 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4905 zero, @value{GDBN} will never try to use hardware watchpoints, even if
4906 the underlying system supports them. (Note that hardware-assisted
4907 watchpoints that were set @emph{before} setting
4908 @code{can-use-hw-watchpoints} to zero will still use the hardware
4909 mechanism of watching expression values.)
4910
4911 @table @code
4912 @item set can-use-hw-watchpoints
4913 @kindex set can-use-hw-watchpoints
4914 Set whether or not to use hardware watchpoints.
4915
4916 @item show can-use-hw-watchpoints
4917 @kindex show can-use-hw-watchpoints
4918 Show the current mode of using hardware watchpoints.
4919 @end table
4920
4921 For remote targets, you can restrict the number of hardware
4922 watchpoints @value{GDBN} will use, see @ref{set remote
4923 hardware-breakpoint-limit}.
4924
4925 When you issue the @code{watch} command, @value{GDBN} reports
4926
4927 @smallexample
4928 Hardware watchpoint @var{num}: @var{expr}
4929 @end smallexample
4930
4931 @noindent
4932 if it was able to set a hardware watchpoint.
4933
4934 Currently, the @code{awatch} and @code{rwatch} commands can only set
4935 hardware watchpoints, because accesses to data that don't change the
4936 value of the watched expression cannot be detected without examining
4937 every instruction as it is being executed, and @value{GDBN} does not do
4938 that currently. If @value{GDBN} finds that it is unable to set a
4939 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4940 will print a message like this:
4941
4942 @smallexample
4943 Expression cannot be implemented with read/access watchpoint.
4944 @end smallexample
4945
4946 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4947 data type of the watched expression is wider than what a hardware
4948 watchpoint on the target machine can handle. For example, some systems
4949 can only watch regions that are up to 4 bytes wide; on such systems you
4950 cannot set hardware watchpoints for an expression that yields a
4951 double-precision floating-point number (which is typically 8 bytes
4952 wide). As a work-around, it might be possible to break the large region
4953 into a series of smaller ones and watch them with separate watchpoints.
4954
4955 If you set too many hardware watchpoints, @value{GDBN} might be unable
4956 to insert all of them when you resume the execution of your program.
4957 Since the precise number of active watchpoints is unknown until such
4958 time as the program is about to be resumed, @value{GDBN} might not be
4959 able to warn you about this when you set the watchpoints, and the
4960 warning will be printed only when the program is resumed:
4961
4962 @smallexample
4963 Hardware watchpoint @var{num}: Could not insert watchpoint
4964 @end smallexample
4965
4966 @noindent
4967 If this happens, delete or disable some of the watchpoints.
4968
4969 Watching complex expressions that reference many variables can also
4970 exhaust the resources available for hardware-assisted watchpoints.
4971 That's because @value{GDBN} needs to watch every variable in the
4972 expression with separately allocated resources.
4973
4974 If you call a function interactively using @code{print} or @code{call},
4975 any watchpoints you have set will be inactive until @value{GDBN} reaches another
4976 kind of breakpoint or the call completes.
4977
4978 @value{GDBN} automatically deletes watchpoints that watch local
4979 (automatic) variables, or expressions that involve such variables, when
4980 they go out of scope, that is, when the execution leaves the block in
4981 which these variables were defined. In particular, when the program
4982 being debugged terminates, @emph{all} local variables go out of scope,
4983 and so only watchpoints that watch global variables remain set. If you
4984 rerun the program, you will need to set all such watchpoints again. One
4985 way of doing that would be to set a code breakpoint at the entry to the
4986 @code{main} function and when it breaks, set all the watchpoints.
4987
4988 @cindex watchpoints and threads
4989 @cindex threads and watchpoints
4990 In multi-threaded programs, watchpoints will detect changes to the
4991 watched expression from every thread.
4992
4993 @quotation
4994 @emph{Warning:} In multi-threaded programs, software watchpoints
4995 have only limited usefulness. If @value{GDBN} creates a software
4996 watchpoint, it can only watch the value of an expression @emph{in a
4997 single thread}. If you are confident that the expression can only
4998 change due to the current thread's activity (and if you are also
4999 confident that no other thread can become current), then you can use
5000 software watchpoints as usual. However, @value{GDBN} may not notice
5001 when a non-current thread's activity changes the expression. (Hardware
5002 watchpoints, in contrast, watch an expression in all threads.)
5003 @end quotation
5004
5005 @xref{set remote hardware-watchpoint-limit}.
5006
5007 @node Set Catchpoints
5008 @subsection Setting Catchpoints
5009 @cindex catchpoints, setting
5010 @cindex exception handlers
5011 @cindex event handling
5012
5013 You can use @dfn{catchpoints} to cause the debugger to stop for certain
5014 kinds of program events, such as C@t{++} exceptions or the loading of a
5015 shared library. Use the @code{catch} command to set a catchpoint.
5016
5017 @table @code
5018 @kindex catch
5019 @item catch @var{event}
5020 Stop when @var{event} occurs. The @var{event} can be any of the following:
5021
5022 @table @code
5023 @item throw @r{[}@var{regexp}@r{]}
5024 @itemx rethrow @r{[}@var{regexp}@r{]}
5025 @itemx catch @r{[}@var{regexp}@r{]}
5026 @kindex catch throw
5027 @kindex catch rethrow
5028 @kindex catch catch
5029 @cindex stop on C@t{++} exceptions
5030 The throwing, re-throwing, or catching of a C@t{++} exception.
5031
5032 If @var{regexp} is given, then only exceptions whose type matches the
5033 regular expression will be caught.
5034
5035 @vindex $_exception@r{, convenience variable}
5036 The convenience variable @code{$_exception} is available at an
5037 exception-related catchpoint, on some systems. This holds the
5038 exception being thrown.
5039
5040 There are currently some limitations to C@t{++} exception handling in
5041 @value{GDBN}:
5042
5043 @itemize @bullet
5044 @item
5045 The support for these commands is system-dependent. Currently, only
5046 systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
5047 supported.
5048
5049 @item
5050 The regular expression feature and the @code{$_exception} convenience
5051 variable rely on the presence of some SDT probes in @code{libstdc++}.
5052 If these probes are not present, then these features cannot be used.
5053 These probes were first available in the GCC 4.8 release, but whether
5054 or not they are available in your GCC also depends on how it was
5055 built.
5056
5057 @item
5058 The @code{$_exception} convenience variable is only valid at the
5059 instruction at which an exception-related catchpoint is set.
5060
5061 @item
5062 When an exception-related catchpoint is hit, @value{GDBN} stops at a
5063 location in the system library which implements runtime exception
5064 support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
5065 (@pxref{Selection}) to get to your code.
5066
5067 @item
5068 If you call a function interactively, @value{GDBN} normally returns
5069 control to you when the function has finished executing. If the call
5070 raises an exception, however, the call may bypass the mechanism that
5071 returns control to you and cause your program either to abort or to
5072 simply continue running until it hits a breakpoint, catches a signal
5073 that @value{GDBN} is listening for, or exits. This is the case even if
5074 you set a catchpoint for the exception; catchpoints on exceptions are
5075 disabled within interactive calls. @xref{Calling}, for information on
5076 controlling this with @code{set unwind-on-terminating-exception}.
5077
5078 @item
5079 You cannot raise an exception interactively.
5080
5081 @item
5082 You cannot install an exception handler interactively.
5083 @end itemize
5084
5085 @item exception @r{[}@var{name}@r{]}
5086 @kindex catch exception
5087 @cindex Ada exception catching
5088 @cindex catch Ada exceptions
5089 An Ada exception being raised. If an exception name is specified
5090 at the end of the command (eg @code{catch exception Program_Error}),
5091 the debugger will stop only when this specific exception is raised.
5092 Otherwise, the debugger stops execution when any Ada exception is raised.
5093
5094 When inserting an exception catchpoint on a user-defined exception whose
5095 name is identical to one of the exceptions defined by the language, the
5096 fully qualified name must be used as the exception name. Otherwise,
5097 @value{GDBN} will assume that it should stop on the pre-defined exception
5098 rather than the user-defined one. For instance, assuming an exception
5099 called @code{Constraint_Error} is defined in package @code{Pck}, then
5100 the command to use to catch such exceptions is @kbd{catch exception
5101 Pck.Constraint_Error}.
5102
5103 @vindex $_ada_exception@r{, convenience variable}
5104 The convenience variable @code{$_ada_exception} holds the address of
5105 the exception being thrown. This can be useful when setting a
5106 condition for such a catchpoint.
5107
5108 @item exception unhandled
5109 @kindex catch exception unhandled
5110 An exception that was raised but is not handled by the program. The
5111 convenience variable @code{$_ada_exception} is set as for @code{catch
5112 exception}.
5113
5114 @item handlers @r{[}@var{name}@r{]}
5115 @kindex catch handlers
5116 @cindex Ada exception handlers catching
5117 @cindex catch Ada exceptions when handled
5118 An Ada exception being handled. If an exception name is
5119 specified at the end of the command
5120 (eg @kbd{catch handlers Program_Error}), the debugger will stop
5121 only when this specific exception is handled.
5122 Otherwise, the debugger stops execution when any Ada exception is handled.
5123
5124 When inserting a handlers catchpoint on a user-defined
5125 exception whose name is identical to one of the exceptions
5126 defined by the language, the fully qualified name must be used
5127 as the exception name. Otherwise, @value{GDBN} will assume that it
5128 should stop on the pre-defined exception rather than the
5129 user-defined one. For instance, assuming an exception called
5130 @code{Constraint_Error} is defined in package @code{Pck}, then the
5131 command to use to catch such exceptions handling is
5132 @kbd{catch handlers Pck.Constraint_Error}.
5133
5134 The convenience variable @code{$_ada_exception} is set as for
5135 @code{catch exception}.
5136
5137 @item assert
5138 @kindex catch assert
5139 A failed Ada assertion. Note that the convenience variable
5140 @code{$_ada_exception} is @emph{not} set by this catchpoint.
5141
5142 @item exec
5143 @kindex catch exec
5144 @cindex break on fork/exec
5145 A call to @code{exec}.
5146
5147 @anchor{catch syscall}
5148 @item syscall
5149 @itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
5150 @kindex catch syscall
5151 @cindex break on a system call.
5152 A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
5153 syscall is a mechanism for application programs to request a service
5154 from the operating system (OS) or one of the OS system services.
5155 @value{GDBN} can catch some or all of the syscalls issued by the
5156 debuggee, and show the related information for each syscall. If no
5157 argument is specified, calls to and returns from all system calls
5158 will be caught.
5159
5160 @var{name} can be any system call name that is valid for the
5161 underlying OS. Just what syscalls are valid depends on the OS. On
5162 GNU and Unix systems, you can find the full list of valid syscall
5163 names on @file{/usr/include/asm/unistd.h}.
5164
5165 @c For MS-Windows, the syscall names and the corresponding numbers
5166 @c can be found, e.g., on this URL:
5167 @c http://www.metasploit.com/users/opcode/syscalls.html
5168 @c but we don't support Windows syscalls yet.
5169
5170 Normally, @value{GDBN} knows in advance which syscalls are valid for
5171 each OS, so you can use the @value{GDBN} command-line completion
5172 facilities (@pxref{Completion,, command completion}) to list the
5173 available choices.
5174
5175 You may also specify the system call numerically. A syscall's
5176 number is the value passed to the OS's syscall dispatcher to
5177 identify the requested service. When you specify the syscall by its
5178 name, @value{GDBN} uses its database of syscalls to convert the name
5179 into the corresponding numeric code, but using the number directly
5180 may be useful if @value{GDBN}'s database does not have the complete
5181 list of syscalls on your system (e.g., because @value{GDBN} lags
5182 behind the OS upgrades).
5183
5184 You may specify a group of related syscalls to be caught at once using
5185 the @code{group:} syntax (@code{g:} is a shorter equivalent). For
5186 instance, on some platforms @value{GDBN} allows you to catch all
5187 network related syscalls, by passing the argument @code{group:network}
5188 to @code{catch syscall}. Note that not all syscall groups are
5189 available in every system. You can use the command completion
5190 facilities (@pxref{Completion,, command completion}) to list the
5191 syscall groups available on your environment.
5192
5193 The example below illustrates how this command works if you don't provide
5194 arguments to it:
5195
5196 @smallexample
5197 (@value{GDBP}) catch syscall
5198 Catchpoint 1 (syscall)
5199 (@value{GDBP}) r
5200 Starting program: /tmp/catch-syscall
5201
5202 Catchpoint 1 (call to syscall 'close'), \
5203 0xffffe424 in __kernel_vsyscall ()
5204 (@value{GDBP}) c
5205 Continuing.
5206
5207 Catchpoint 1 (returned from syscall 'close'), \
5208 0xffffe424 in __kernel_vsyscall ()
5209 (@value{GDBP})
5210 @end smallexample
5211
5212 Here is an example of catching a system call by name:
5213
5214 @smallexample
5215 (@value{GDBP}) catch syscall chroot
5216 Catchpoint 1 (syscall 'chroot' [61])
5217 (@value{GDBP}) r
5218 Starting program: /tmp/catch-syscall
5219
5220 Catchpoint 1 (call to syscall 'chroot'), \
5221 0xffffe424 in __kernel_vsyscall ()
5222 (@value{GDBP}) c
5223 Continuing.
5224
5225 Catchpoint 1 (returned from syscall 'chroot'), \
5226 0xffffe424 in __kernel_vsyscall ()
5227 (@value{GDBP})
5228 @end smallexample
5229
5230 An example of specifying a system call numerically. In the case
5231 below, the syscall number has a corresponding entry in the XML
5232 file, so @value{GDBN} finds its name and prints it:
5233
5234 @smallexample
5235 (@value{GDBP}) catch syscall 252
5236 Catchpoint 1 (syscall(s) 'exit_group')
5237 (@value{GDBP}) r
5238 Starting program: /tmp/catch-syscall
5239
5240 Catchpoint 1 (call to syscall 'exit_group'), \
5241 0xffffe424 in __kernel_vsyscall ()
5242 (@value{GDBP}) c
5243 Continuing.
5244
5245 Program exited normally.
5246 (@value{GDBP})
5247 @end smallexample
5248
5249 Here is an example of catching a syscall group:
5250
5251 @smallexample
5252 (@value{GDBP}) catch syscall group:process
5253 Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5254 'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5255 'exit_group' [252] 'waitid' [284] 'unshare' [310])
5256 (@value{GDBP}) r
5257 Starting program: /tmp/catch-syscall
5258
5259 Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5260 from /lib64/ld-linux-x86-64.so.2
5261
5262 (@value{GDBP}) c
5263 Continuing.
5264 @end smallexample
5265
5266 However, there can be situations when there is no corresponding name
5267 in XML file for that syscall number. In this case, @value{GDBN} prints
5268 a warning message saying that it was not able to find the syscall name,
5269 but the catchpoint will be set anyway. See the example below:
5270
5271 @smallexample
5272 (@value{GDBP}) catch syscall 764
5273 warning: The number '764' does not represent a known syscall.
5274 Catchpoint 2 (syscall 764)
5275 (@value{GDBP})
5276 @end smallexample
5277
5278 If you configure @value{GDBN} using the @samp{--without-expat} option,
5279 it will not be able to display syscall names. Also, if your
5280 architecture does not have an XML file describing its system calls,
5281 you will not be able to see the syscall names. It is important to
5282 notice that these two features are used for accessing the syscall
5283 name database. In either case, you will see a warning like this:
5284
5285 @smallexample
5286 (@value{GDBP}) catch syscall
5287 warning: Could not open "syscalls/i386-linux.xml"
5288 warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5289 GDB will not be able to display syscall names.
5290 Catchpoint 1 (syscall)
5291 (@value{GDBP})
5292 @end smallexample
5293
5294 Of course, the file name will change depending on your architecture and system.
5295
5296 Still using the example above, you can also try to catch a syscall by its
5297 number. In this case, you would see something like:
5298
5299 @smallexample
5300 (@value{GDBP}) catch syscall 252
5301 Catchpoint 1 (syscall(s) 252)
5302 @end smallexample
5303
5304 Again, in this case @value{GDBN} would not be able to display syscall's names.
5305
5306 @item fork
5307 @kindex catch fork
5308 A call to @code{fork}.
5309
5310 @item vfork
5311 @kindex catch vfork
5312 A call to @code{vfork}.
5313
5314 @item load @r{[}@var{regexp}@r{]}
5315 @itemx unload @r{[}@var{regexp}@r{]}
5316 @kindex catch load
5317 @kindex catch unload
5318 The loading or unloading of a shared library. If @var{regexp} is
5319 given, then the catchpoint will stop only if the regular expression
5320 matches one of the affected libraries.
5321
5322 @item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5323 @kindex catch signal
5324 The delivery of a signal.
5325
5326 With no arguments, this catchpoint will catch any signal that is not
5327 used internally by @value{GDBN}, specifically, all signals except
5328 @samp{SIGTRAP} and @samp{SIGINT}.
5329
5330 With the argument @samp{all}, all signals, including those used by
5331 @value{GDBN}, will be caught. This argument cannot be used with other
5332 signal names.
5333
5334 Otherwise, the arguments are a list of signal names as given to
5335 @code{handle} (@pxref{Signals}). Only signals specified in this list
5336 will be caught.
5337
5338 One reason that @code{catch signal} can be more useful than
5339 @code{handle} is that you can attach commands and conditions to the
5340 catchpoint.
5341
5342 When a signal is caught by a catchpoint, the signal's @code{stop} and
5343 @code{print} settings, as specified by @code{handle}, are ignored.
5344 However, whether the signal is still delivered to the inferior depends
5345 on the @code{pass} setting; this can be changed in the catchpoint's
5346 commands.
5347
5348 @end table
5349
5350 @item tcatch @var{event}
5351 @kindex tcatch
5352 Set a catchpoint that is enabled only for one stop. The catchpoint is
5353 automatically deleted after the first time the event is caught.
5354
5355 @end table
5356
5357 Use the @code{info break} command to list the current catchpoints.
5358
5359
5360 @node Delete Breaks
5361 @subsection Deleting Breakpoints
5362
5363 @cindex clearing breakpoints, watchpoints, catchpoints
5364 @cindex deleting breakpoints, watchpoints, catchpoints
5365 It is often necessary to eliminate a breakpoint, watchpoint, or
5366 catchpoint once it has done its job and you no longer want your program
5367 to stop there. This is called @dfn{deleting} the breakpoint. A
5368 breakpoint that has been deleted no longer exists; it is forgotten.
5369
5370 With the @code{clear} command you can delete breakpoints according to
5371 where they are in your program. With the @code{delete} command you can
5372 delete individual breakpoints, watchpoints, or catchpoints by specifying
5373 their breakpoint numbers.
5374
5375 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5376 automatically ignores breakpoints on the first instruction to be executed
5377 when you continue execution without changing the execution address.
5378
5379 @table @code
5380 @kindex clear
5381 @item clear
5382 Delete any breakpoints at the next instruction to be executed in the
5383 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
5384 the innermost frame is selected, this is a good way to delete a
5385 breakpoint where your program just stopped.
5386
5387 @item clear @var{location}
5388 Delete any breakpoints set at the specified @var{location}.
5389 @xref{Specify Location}, for the various forms of @var{location}; the
5390 most useful ones are listed below:
5391
5392 @table @code
5393 @item clear @var{function}
5394 @itemx clear @var{filename}:@var{function}
5395 Delete any breakpoints set at entry to the named @var{function}.
5396
5397 @item clear @var{linenum}
5398 @itemx clear @var{filename}:@var{linenum}
5399 Delete any breakpoints set at or within the code of the specified
5400 @var{linenum} of the specified @var{filename}.
5401 @end table
5402
5403 @cindex delete breakpoints
5404 @kindex delete
5405 @kindex d @r{(@code{delete})}
5406 @item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5407 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
5408 list specified as argument. If no argument is specified, delete all
5409 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5410 confirm off}). You can abbreviate this command as @code{d}.
5411 @end table
5412
5413 @node Disabling
5414 @subsection Disabling Breakpoints
5415
5416 @cindex enable/disable a breakpoint
5417 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5418 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5419 it had been deleted, but remembers the information on the breakpoint so
5420 that you can @dfn{enable} it again later.
5421
5422 You disable and enable breakpoints, watchpoints, and catchpoints with
5423 the @code{enable} and @code{disable} commands, optionally specifying
5424 one or more breakpoint numbers as arguments. Use @code{info break} to
5425 print a list of all breakpoints, watchpoints, and catchpoints if you
5426 do not know which numbers to use.
5427
5428 Disabling and enabling a breakpoint that has multiple locations
5429 affects all of its locations.
5430
5431 A breakpoint, watchpoint, or catchpoint can have any of several
5432 different states of enablement:
5433
5434 @itemize @bullet
5435 @item
5436 Enabled. The breakpoint stops your program. A breakpoint set
5437 with the @code{break} command starts out in this state.
5438 @item
5439 Disabled. The breakpoint has no effect on your program.
5440 @item
5441 Enabled once. The breakpoint stops your program, but then becomes
5442 disabled.
5443 @item
5444 Enabled for a count. The breakpoint stops your program for the next
5445 N times, then becomes disabled.
5446 @item
5447 Enabled for deletion. The breakpoint stops your program, but
5448 immediately after it does so it is deleted permanently. A breakpoint
5449 set with the @code{tbreak} command starts out in this state.
5450 @end itemize
5451
5452 You can use the following commands to enable or disable breakpoints,
5453 watchpoints, and catchpoints:
5454
5455 @table @code
5456 @kindex disable
5457 @kindex dis @r{(@code{disable})}
5458 @item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5459 Disable the specified breakpoints---or all breakpoints, if none are
5460 listed. A disabled breakpoint has no effect but is not forgotten. All
5461 options such as ignore-counts, conditions and commands are remembered in
5462 case the breakpoint is enabled again later. You may abbreviate
5463 @code{disable} as @code{dis}.
5464
5465 @kindex enable
5466 @item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5467 Enable the specified breakpoints (or all defined breakpoints). They
5468 become effective once again in stopping your program.
5469
5470 @item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
5471 Enable the specified breakpoints temporarily. @value{GDBN} disables any
5472 of these breakpoints immediately after stopping your program.
5473
5474 @item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
5475 Enable the specified breakpoints temporarily. @value{GDBN} records
5476 @var{count} with each of the specified breakpoints, and decrements a
5477 breakpoint's count when it is hit. When any count reaches 0,
5478 @value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5479 count (@pxref{Conditions, ,Break Conditions}), that will be
5480 decremented to 0 before @var{count} is affected.
5481
5482 @item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
5483 Enable the specified breakpoints to work once, then die. @value{GDBN}
5484 deletes any of these breakpoints as soon as your program stops there.
5485 Breakpoints set by the @code{tbreak} command start out in this state.
5486 @end table
5487
5488 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5489 @c confusing: tbreak is also initially enabled.
5490 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
5491 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
5492 subsequently, they become disabled or enabled only when you use one of
5493 the commands above. (The command @code{until} can set and delete a
5494 breakpoint of its own, but it does not change the state of your other
5495 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
5496 Stepping}.)
5497
5498 @node Conditions
5499 @subsection Break Conditions
5500 @cindex conditional breakpoints
5501 @cindex breakpoint conditions
5502
5503 @c FIXME what is scope of break condition expr? Context where wanted?
5504 @c in particular for a watchpoint?
5505 The simplest sort of breakpoint breaks every time your program reaches a
5506 specified place. You can also specify a @dfn{condition} for a
5507 breakpoint. A condition is just a Boolean expression in your
5508 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5509 a condition evaluates the expression each time your program reaches it,
5510 and your program stops only if the condition is @emph{true}.
5511
5512 This is the converse of using assertions for program validation; in that
5513 situation, you want to stop when the assertion is violated---that is,
5514 when the condition is false. In C, if you want to test an assertion expressed
5515 by the condition @var{assert}, you should set the condition
5516 @samp{! @var{assert}} on the appropriate breakpoint.
5517
5518 Conditions are also accepted for watchpoints; you may not need them,
5519 since a watchpoint is inspecting the value of an expression anyhow---but
5520 it might be simpler, say, to just set a watchpoint on a variable name,
5521 and specify a condition that tests whether the new value is an interesting
5522 one.
5523
5524 Break conditions can have side effects, and may even call functions in
5525 your program. This can be useful, for example, to activate functions
5526 that log program progress, or to use your own print functions to
5527 format special data structures. The effects are completely predictable
5528 unless there is another enabled breakpoint at the same address. (In
5529 that case, @value{GDBN} might see the other breakpoint first and stop your
5530 program without checking the condition of this one.) Note that
5531 breakpoint commands are usually more convenient and flexible than break
5532 conditions for the
5533 purpose of performing side effects when a breakpoint is reached
5534 (@pxref{Break Commands, ,Breakpoint Command Lists}).
5535
5536 Breakpoint conditions can also be evaluated on the target's side if
5537 the target supports it. Instead of evaluating the conditions locally,
5538 @value{GDBN} encodes the expression into an agent expression
5539 (@pxref{Agent Expressions}) suitable for execution on the target,
5540 independently of @value{GDBN}. Global variables become raw memory
5541 locations, locals become stack accesses, and so forth.
5542
5543 In this case, @value{GDBN} will only be notified of a breakpoint trigger
5544 when its condition evaluates to true. This mechanism may provide faster
5545 response times depending on the performance characteristics of the target
5546 since it does not need to keep @value{GDBN} informed about
5547 every breakpoint trigger, even those with false conditions.
5548
5549 Break conditions can be specified when a breakpoint is set, by using
5550 @samp{if} in the arguments to the @code{break} command. @xref{Set
5551 Breaks, ,Setting Breakpoints}. They can also be changed at any time
5552 with the @code{condition} command.
5553
5554 You can also use the @code{if} keyword with the @code{watch} command.
5555 The @code{catch} command does not recognize the @code{if} keyword;
5556 @code{condition} is the only way to impose a further condition on a
5557 catchpoint.
5558
5559 @table @code
5560 @kindex condition
5561 @item condition @var{bnum} @var{expression}
5562 Specify @var{expression} as the break condition for breakpoint,
5563 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5564 breakpoint @var{bnum} stops your program only if the value of
5565 @var{expression} is true (nonzero, in C). When you use
5566 @code{condition}, @value{GDBN} checks @var{expression} immediately for
5567 syntactic correctness, and to determine whether symbols in it have
5568 referents in the context of your breakpoint. If @var{expression} uses
5569 symbols not referenced in the context of the breakpoint, @value{GDBN}
5570 prints an error message:
5571
5572 @smallexample
5573 No symbol "foo" in current context.
5574 @end smallexample
5575
5576 @noindent
5577 @value{GDBN} does
5578 not actually evaluate @var{expression} at the time the @code{condition}
5579 command (or a command that sets a breakpoint with a condition, like
5580 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
5581
5582 @item condition -force @var{bnum} @var{expression}
5583 When the @code{-force} flag is used, define the condition even if
5584 @var{expression} is invalid at all the current locations of breakpoint
5585 @var{bnum}. This is similar to the @code{-force-condition} option
5586 of the @code{break} command.
5587
5588 @item condition @var{bnum}
5589 Remove the condition from breakpoint number @var{bnum}. It becomes
5590 an ordinary unconditional breakpoint.
5591 @end table
5592
5593 @cindex ignore count (of breakpoint)
5594 A special case of a breakpoint condition is to stop only when the
5595 breakpoint has been reached a certain number of times. This is so
5596 useful that there is a special way to do it, using the @dfn{ignore
5597 count} of the breakpoint. Every breakpoint has an ignore count, which
5598 is an integer. Most of the time, the ignore count is zero, and
5599 therefore has no effect. But if your program reaches a breakpoint whose
5600 ignore count is positive, then instead of stopping, it just decrements
5601 the ignore count by one and continues. As a result, if the ignore count
5602 value is @var{n}, the breakpoint does not stop the next @var{n} times
5603 your program reaches it.
5604
5605 @table @code
5606 @kindex ignore
5607 @item ignore @var{bnum} @var{count}
5608 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5609 The next @var{count} times the breakpoint is reached, your program's
5610 execution does not stop; other than to decrement the ignore count, @value{GDBN}
5611 takes no action.
5612
5613 To make the breakpoint stop the next time it is reached, specify
5614 a count of zero.
5615
5616 When you use @code{continue} to resume execution of your program from a
5617 breakpoint, you can specify an ignore count directly as an argument to
5618 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
5619 Stepping,,Continuing and Stepping}.
5620
5621 If a breakpoint has a positive ignore count and a condition, the
5622 condition is not checked. Once the ignore count reaches zero,
5623 @value{GDBN} resumes checking the condition.
5624
5625 You could achieve the effect of the ignore count with a condition such
5626 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5627 is decremented each time. @xref{Convenience Vars, ,Convenience
5628 Variables}.
5629 @end table
5630
5631 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5632
5633
5634 @node Break Commands
5635 @subsection Breakpoint Command Lists
5636
5637 @cindex breakpoint commands
5638 You can give any breakpoint (or watchpoint or catchpoint) a series of
5639 commands to execute when your program stops due to that breakpoint. For
5640 example, you might want to print the values of certain expressions, or
5641 enable other breakpoints.
5642
5643 @table @code
5644 @kindex commands
5645 @kindex end@r{ (breakpoint commands)}
5646 @item commands @r{[}@var{list}@dots{}@r{]}
5647 @itemx @dots{} @var{command-list} @dots{}
5648 @itemx end
5649 Specify a list of commands for the given breakpoints. The commands
5650 themselves appear on the following lines. Type a line containing just
5651 @code{end} to terminate the commands.
5652
5653 To remove all commands from a breakpoint, type @code{commands} and
5654 follow it immediately with @code{end}; that is, give no commands.
5655
5656 With no argument, @code{commands} refers to the last breakpoint,
5657 watchpoint, or catchpoint set (not to the breakpoint most recently
5658 encountered). If the most recent breakpoints were set with a single
5659 command, then the @code{commands} will apply to all the breakpoints
5660 set by that command. This applies to breakpoints set by
5661 @code{rbreak}, and also applies when a single @code{break} command
5662 creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5663 Expressions}).
5664 @end table
5665
5666 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5667 disabled within a @var{command-list}.
5668
5669 You can use breakpoint commands to start your program up again. Simply
5670 use the @code{continue} command, or @code{step}, or any other command
5671 that resumes execution.
5672
5673 Any other commands in the command list, after a command that resumes
5674 execution, are ignored. This is because any time you resume execution
5675 (even with a simple @code{next} or @code{step}), you may encounter
5676 another breakpoint---which could have its own command list, leading to
5677 ambiguities about which list to execute.
5678
5679 @kindex silent
5680 If the first command you specify in a command list is @code{silent}, the
5681 usual message about stopping at a breakpoint is not printed. This may
5682 be desirable for breakpoints that are to print a specific message and
5683 then continue. If none of the remaining commands print anything, you
5684 see no sign that the breakpoint was reached. @code{silent} is
5685 meaningful only at the beginning of a breakpoint command list.
5686
5687 The commands @code{echo}, @code{output}, and @code{printf} allow you to
5688 print precisely controlled output, and are often useful in silent
5689 breakpoints. @xref{Output, ,Commands for Controlled Output}.
5690
5691 For example, here is how you could use breakpoint commands to print the
5692 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5693
5694 @smallexample
5695 break foo if x>0
5696 commands
5697 silent
5698 printf "x is %d\n",x
5699 cont
5700 end
5701 @end smallexample
5702
5703 One application for breakpoint commands is to compensate for one bug so
5704 you can test for another. Put a breakpoint just after the erroneous line
5705 of code, give it a condition to detect the case in which something
5706 erroneous has been done, and give it commands to assign correct values
5707 to any variables that need them. End with the @code{continue} command
5708 so that your program does not stop, and start with the @code{silent}
5709 command so that no output is produced. Here is an example:
5710
5711 @smallexample
5712 break 403
5713 commands
5714 silent
5715 set x = y + 4
5716 cont
5717 end
5718 @end smallexample
5719
5720 @node Dynamic Printf
5721 @subsection Dynamic Printf
5722
5723 @cindex dynamic printf
5724 @cindex dprintf
5725 The dynamic printf command @code{dprintf} combines a breakpoint with
5726 formatted printing of your program's data to give you the effect of
5727 inserting @code{printf} calls into your program on-the-fly, without
5728 having to recompile it.
5729
5730 In its most basic form, the output goes to the GDB console. However,
5731 you can set the variable @code{dprintf-style} for alternate handling.
5732 For instance, you can ask to format the output by calling your
5733 program's @code{printf} function. This has the advantage that the
5734 characters go to the program's output device, so they can recorded in
5735 redirects to files and so forth.
5736
5737 If you are doing remote debugging with a stub or agent, you can also
5738 ask to have the printf handled by the remote agent. In addition to
5739 ensuring that the output goes to the remote program's device along
5740 with any other output the program might produce, you can also ask that
5741 the dprintf remain active even after disconnecting from the remote
5742 target. Using the stub/agent is also more efficient, as it can do
5743 everything without needing to communicate with @value{GDBN}.
5744
5745 @table @code
5746 @kindex dprintf
5747 @item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5748 Whenever execution reaches @var{location}, print the values of one or
5749 more @var{expressions} under the control of the string @var{template}.
5750 To print several values, separate them with commas.
5751
5752 @item set dprintf-style @var{style}
5753 Set the dprintf output to be handled in one of several different
5754 styles enumerated below. A change of style affects all existing
5755 dynamic printfs immediately. (If you need individual control over the
5756 print commands, simply define normal breakpoints with
5757 explicitly-supplied command lists.)
5758
5759 @table @code
5760 @item gdb
5761 @kindex dprintf-style gdb
5762 Handle the output using the @value{GDBN} @code{printf} command.
5763
5764 @item call
5765 @kindex dprintf-style call
5766 Handle the output by calling a function in your program (normally
5767 @code{printf}).
5768
5769 @item agent
5770 @kindex dprintf-style agent
5771 Have the remote debugging agent (such as @code{gdbserver}) handle
5772 the output itself. This style is only available for agents that
5773 support running commands on the target.
5774 @end table
5775
5776 @item set dprintf-function @var{function}
5777 Set the function to call if the dprintf style is @code{call}. By
5778 default its value is @code{printf}. You may set it to any expression.
5779 that @value{GDBN} can evaluate to a function, as per the @code{call}
5780 command.
5781
5782 @item set dprintf-channel @var{channel}
5783 Set a ``channel'' for dprintf. If set to a non-empty value,
5784 @value{GDBN} will evaluate it as an expression and pass the result as
5785 a first argument to the @code{dprintf-function}, in the manner of
5786 @code{fprintf} and similar functions. Otherwise, the dprintf format
5787 string will be the first argument, in the manner of @code{printf}.
5788
5789 As an example, if you wanted @code{dprintf} output to go to a logfile
5790 that is a standard I/O stream assigned to the variable @code{mylog},
5791 you could do the following:
5792
5793 @example
5794 (gdb) set dprintf-style call
5795 (gdb) set dprintf-function fprintf
5796 (gdb) set dprintf-channel mylog
5797 (gdb) dprintf 25,"at line 25, glob=%d\n",glob
5798 Dprintf 1 at 0x123456: file main.c, line 25.
5799 (gdb) info break
5800 1 dprintf keep y 0x00123456 in main at main.c:25
5801 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5802 continue
5803 (gdb)
5804 @end example
5805
5806 Note that the @code{info break} displays the dynamic printf commands
5807 as normal breakpoint commands; you can thus easily see the effect of
5808 the variable settings.
5809
5810 @item set disconnected-dprintf on
5811 @itemx set disconnected-dprintf off
5812 @kindex set disconnected-dprintf
5813 Choose whether @code{dprintf} commands should continue to run if
5814 @value{GDBN} has disconnected from the target. This only applies
5815 if the @code{dprintf-style} is @code{agent}.
5816
5817 @item show disconnected-dprintf off
5818 @kindex show disconnected-dprintf
5819 Show the current choice for disconnected @code{dprintf}.
5820
5821 @end table
5822
5823 @value{GDBN} does not check the validity of function and channel,
5824 relying on you to supply values that are meaningful for the contexts
5825 in which they are being used. For instance, the function and channel
5826 may be the values of local variables, but if that is the case, then
5827 all enabled dynamic prints must be at locations within the scope of
5828 those locals. If evaluation fails, @value{GDBN} will report an error.
5829
5830 @node Save Breakpoints
5831 @subsection How to save breakpoints to a file
5832
5833 To save breakpoint definitions to a file use the @w{@code{save
5834 breakpoints}} command.
5835
5836 @table @code
5837 @kindex save breakpoints
5838 @cindex save breakpoints to a file for future sessions
5839 @item save breakpoints [@var{filename}]
5840 This command saves all current breakpoint definitions together with
5841 their commands and ignore counts, into a file @file{@var{filename}}
5842 suitable for use in a later debugging session. This includes all
5843 types of breakpoints (breakpoints, watchpoints, catchpoints,
5844 tracepoints). To read the saved breakpoint definitions, use the
5845 @code{source} command (@pxref{Command Files}). Note that watchpoints
5846 with expressions involving local variables may fail to be recreated
5847 because it may not be possible to access the context where the
5848 watchpoint is valid anymore. Because the saved breakpoint definitions
5849 are simply a sequence of @value{GDBN} commands that recreate the
5850 breakpoints, you can edit the file in your favorite editing program,
5851 and remove the breakpoint definitions you're not interested in, or
5852 that can no longer be recreated.
5853 @end table
5854
5855 @node Static Probe Points
5856 @subsection Static Probe Points
5857
5858 @cindex static probe point, SystemTap
5859 @cindex static probe point, DTrace
5860 @value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5861 for Statically Defined Tracing, and the probes are designed to have a tiny
5862 runtime code and data footprint, and no dynamic relocations.
5863
5864 Currently, the following types of probes are supported on
5865 ELF-compatible systems:
5866
5867 @itemize @bullet
5868
5869 @item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5870 @acronym{SDT} probes@footnote{See
5871 @uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
5872 for more information on how to add @code{SystemTap} @acronym{SDT}
5873 probes in your applications.}. @code{SystemTap} probes are usable
5874 from assembly, C and C@t{++} languages@footnote{See
5875 @uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5876 for a good reference on how the @acronym{SDT} probes are implemented.}.
5877
5878 @item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5879 @acronym{USDT} probes. @code{DTrace} probes are usable from C and
5880 C@t{++} languages.
5881 @end itemize
5882
5883 @cindex semaphores on static probe points
5884 Some @code{SystemTap} probes have an associated semaphore variable;
5885 for instance, this happens automatically if you defined your probe
5886 using a DTrace-style @file{.d} file. If your probe has a semaphore,
5887 @value{GDBN} will automatically enable it when you specify a
5888 breakpoint using the @samp{-probe-stap} notation. But, if you put a
5889 breakpoint at a probe's location by some other method (e.g.,
5890 @code{break file:line}), then @value{GDBN} will not automatically set
5891 the semaphore. @code{DTrace} probes do not support semaphores.
5892
5893 You can examine the available static static probes using @code{info
5894 probes}, with optional arguments:
5895
5896 @table @code
5897 @kindex info probes
5898 @item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5899 If given, @var{type} is either @code{stap} for listing
5900 @code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5901 probes. If omitted all probes are listed regardless of their types.
5902
5903 If given, @var{provider} is a regular expression used to match against provider
5904 names when selecting which probes to list. If omitted, probes by all
5905 probes from all providers are listed.
5906
5907 If given, @var{name} is a regular expression to match against probe names
5908 when selecting which probes to list. If omitted, probe names are not
5909 considered when deciding whether to display them.
5910
5911 If given, @var{objfile} is a regular expression used to select which
5912 object files (executable or shared libraries) to examine. If not
5913 given, all object files are considered.
5914
5915 @item info probes all
5916 List the available static probes, from all types.
5917 @end table
5918
5919 @cindex enabling and disabling probes
5920 Some probe points can be enabled and/or disabled. The effect of
5921 enabling or disabling a probe depends on the type of probe being
5922 handled. Some @code{DTrace} probes can be enabled or
5923 disabled, but @code{SystemTap} probes cannot be disabled.
5924
5925 You can enable (or disable) one or more probes using the following
5926 commands, with optional arguments:
5927
5928 @table @code
5929 @kindex enable probes
5930 @item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5931 If given, @var{provider} is a regular expression used to match against
5932 provider names when selecting which probes to enable. If omitted,
5933 all probes from all providers are enabled.
5934
5935 If given, @var{name} is a regular expression to match against probe
5936 names when selecting which probes to enable. If omitted, probe names
5937 are not considered when deciding whether to enable them.
5938
5939 If given, @var{objfile} is a regular expression used to select which
5940 object files (executable or shared libraries) to examine. If not
5941 given, all object files are considered.
5942
5943 @kindex disable probes
5944 @item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5945 See the @code{enable probes} command above for a description of the
5946 optional arguments accepted by this command.
5947 @end table
5948
5949 @vindex $_probe_arg@r{, convenience variable}
5950 A probe may specify up to twelve arguments. These are available at the
5951 point at which the probe is defined---that is, when the current PC is
5952 at the probe's location. The arguments are available using the
5953 convenience variables (@pxref{Convenience Vars})
5954 @code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5955 probes each probe argument is an integer of the appropriate size;
5956 types are not preserved. In @code{DTrace} probes types are preserved
5957 provided that they are recognized as such by @value{GDBN}; otherwise
5958 the value of the probe argument will be a long integer. The
5959 convenience variable @code{$_probe_argc} holds the number of arguments
5960 at the current probe point.
5961
5962 These variables are always available, but attempts to access them at
5963 any location other than a probe point will cause @value{GDBN} to give
5964 an error message.
5965
5966
5967 @c @ifclear BARETARGET
5968 @node Error in Breakpoints
5969 @subsection ``Cannot insert breakpoints''
5970
5971 If you request too many active hardware-assisted breakpoints and
5972 watchpoints, you will see this error message:
5973
5974 @c FIXME: the precise wording of this message may change; the relevant
5975 @c source change is not committed yet (Sep 3, 1999).
5976 @smallexample
5977 Stopped; cannot insert breakpoints.
5978 You may have requested too many hardware breakpoints and watchpoints.
5979 @end smallexample
5980
5981 @noindent
5982 This message is printed when you attempt to resume the program, since
5983 only then @value{GDBN} knows exactly how many hardware breakpoints and
5984 watchpoints it needs to insert.
5985
5986 When this message is printed, you need to disable or remove some of the
5987 hardware-assisted breakpoints and watchpoints, and then continue.
5988
5989 @node Breakpoint-related Warnings
5990 @subsection ``Breakpoint address adjusted...''
5991 @cindex breakpoint address adjusted
5992
5993 Some processor architectures place constraints on the addresses at
5994 which breakpoints may be placed. For architectures thus constrained,
5995 @value{GDBN} will attempt to adjust the breakpoint's address to comply
5996 with the constraints dictated by the architecture.
5997
5998 One example of such an architecture is the Fujitsu FR-V. The FR-V is
5999 a VLIW architecture in which a number of RISC-like instructions may be
6000 bundled together for parallel execution. The FR-V architecture
6001 constrains the location of a breakpoint instruction within such a
6002 bundle to the instruction with the lowest address. @value{GDBN}
6003 honors this constraint by adjusting a breakpoint's address to the
6004 first in the bundle.
6005
6006 It is not uncommon for optimized code to have bundles which contain
6007 instructions from different source statements, thus it may happen that
6008 a breakpoint's address will be adjusted from one source statement to
6009 another. Since this adjustment may significantly alter @value{GDBN}'s
6010 breakpoint related behavior from what the user expects, a warning is
6011 printed when the breakpoint is first set and also when the breakpoint
6012 is hit.
6013
6014 A warning like the one below is printed when setting a breakpoint
6015 that's been subject to address adjustment:
6016
6017 @smallexample
6018 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
6019 @end smallexample
6020
6021 Such warnings are printed both for user settable and @value{GDBN}'s
6022 internal breakpoints. If you see one of these warnings, you should
6023 verify that a breakpoint set at the adjusted address will have the
6024 desired affect. If not, the breakpoint in question may be removed and
6025 other breakpoints may be set which will have the desired behavior.
6026 E.g., it may be sufficient to place the breakpoint at a later
6027 instruction. A conditional breakpoint may also be useful in some
6028 cases to prevent the breakpoint from triggering too often.
6029
6030 @value{GDBN} will also issue a warning when stopping at one of these
6031 adjusted breakpoints:
6032
6033 @smallexample
6034 warning: Breakpoint 1 address previously adjusted from 0x00010414
6035 to 0x00010410.
6036 @end smallexample
6037
6038 When this warning is encountered, it may be too late to take remedial
6039 action except in cases where the breakpoint is hit earlier or more
6040 frequently than expected.
6041
6042 @node Continuing and Stepping
6043 @section Continuing and Stepping
6044
6045 @cindex stepping
6046 @cindex continuing
6047 @cindex resuming execution
6048 @dfn{Continuing} means resuming program execution until your program
6049 completes normally. In contrast, @dfn{stepping} means executing just
6050 one more ``step'' of your program, where ``step'' may mean either one
6051 line of source code, or one machine instruction (depending on what
6052 particular command you use). Either when continuing or when stepping,
6053 your program may stop even sooner, due to a breakpoint or a signal. (If
6054 it stops due to a signal, you may want to use @code{handle}, or use
6055 @samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
6056 or you may step into the signal's handler (@pxref{stepping and signal
6057 handlers}).)
6058
6059 @table @code
6060 @kindex continue
6061 @kindex c @r{(@code{continue})}
6062 @kindex fg @r{(resume foreground execution)}
6063 @item continue @r{[}@var{ignore-count}@r{]}
6064 @itemx c @r{[}@var{ignore-count}@r{]}
6065 @itemx fg @r{[}@var{ignore-count}@r{]}
6066 Resume program execution, at the address where your program last stopped;
6067 any breakpoints set at that address are bypassed. The optional argument
6068 @var{ignore-count} allows you to specify a further number of times to
6069 ignore a breakpoint at this location; its effect is like that of
6070 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
6071
6072 The argument @var{ignore-count} is meaningful only when your program
6073 stopped due to a breakpoint. At other times, the argument to
6074 @code{continue} is ignored.
6075
6076 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
6077 debugged program is deemed to be the foreground program) are provided
6078 purely for convenience, and have exactly the same behavior as
6079 @code{continue}.
6080 @end table
6081
6082 To resume execution at a different place, you can use @code{return}
6083 (@pxref{Returning, ,Returning from a Function}) to go back to the
6084 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
6085 Different Address}) to go to an arbitrary location in your program.
6086
6087 A typical technique for using stepping is to set a breakpoint
6088 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
6089 beginning of the function or the section of your program where a problem
6090 is believed to lie, run your program until it stops at that breakpoint,
6091 and then step through the suspect area, examining the variables that are
6092 interesting, until you see the problem happen.
6093
6094 @table @code
6095 @kindex step
6096 @kindex s @r{(@code{step})}
6097 @item step
6098 Continue running your program until control reaches a different source
6099 line, then stop it and return control to @value{GDBN}. This command is
6100 abbreviated @code{s}.
6101
6102 @quotation
6103 @c "without debugging information" is imprecise; actually "without line
6104 @c numbers in the debugging information". (gcc -g1 has debugging info but
6105 @c not line numbers). But it seems complex to try to make that
6106 @c distinction here.
6107 @emph{Warning:} If you use the @code{step} command while control is
6108 within a function that was compiled without debugging information,
6109 execution proceeds until control reaches a function that does have
6110 debugging information. Likewise, it will not step into a function which
6111 is compiled without debugging information. To step through functions
6112 without debugging information, use the @code{stepi} command, described
6113 below.
6114 @end quotation
6115
6116 The @code{step} command only stops at the first instruction of a source
6117 line. This prevents the multiple stops that could otherwise occur in
6118 @code{switch} statements, @code{for} loops, etc. @code{step} continues
6119 to stop if a function that has debugging information is called within
6120 the line. In other words, @code{step} @emph{steps inside} any functions
6121 called within the line.
6122
6123 Also, the @code{step} command only enters a function if there is line
6124 number information for the function. Otherwise it acts like the
6125 @code{next} command. This avoids problems when using @code{cc -gl}
6126 on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
6127 was any debugging information about the routine.
6128
6129 @item step @var{count}
6130 Continue running as in @code{step}, but do so @var{count} times. If a
6131 breakpoint is reached, or a signal not related to stepping occurs before
6132 @var{count} steps, stepping stops right away.
6133
6134 @kindex next
6135 @kindex n @r{(@code{next})}
6136 @item next @r{[}@var{count}@r{]}
6137 Continue to the next source line in the current (innermost) stack frame.
6138 This is similar to @code{step}, but function calls that appear within
6139 the line of code are executed without stopping. Execution stops when
6140 control reaches a different line of code at the original stack level
6141 that was executing when you gave the @code{next} command. This command
6142 is abbreviated @code{n}.
6143
6144 An argument @var{count} is a repeat count, as for @code{step}.
6145
6146
6147 @c FIX ME!! Do we delete this, or is there a way it fits in with
6148 @c the following paragraph? --- Vctoria
6149 @c
6150 @c @code{next} within a function that lacks debugging information acts like
6151 @c @code{step}, but any function calls appearing within the code of the
6152 @c function are executed without stopping.
6153
6154 The @code{next} command only stops at the first instruction of a
6155 source line. This prevents multiple stops that could otherwise occur in
6156 @code{switch} statements, @code{for} loops, etc.
6157
6158 @kindex set step-mode
6159 @item set step-mode
6160 @cindex functions without line info, and stepping
6161 @cindex stepping into functions with no line info
6162 @itemx set step-mode on
6163 The @code{set step-mode on} command causes the @code{step} command to
6164 stop at the first instruction of a function which contains no debug line
6165 information rather than stepping over it.
6166
6167 This is useful in cases where you may be interested in inspecting the
6168 machine instructions of a function which has no symbolic info and do not
6169 want @value{GDBN} to automatically skip over this function.
6170
6171 @item set step-mode off
6172 Causes the @code{step} command to step over any functions which contains no
6173 debug information. This is the default.
6174
6175 @item show step-mode
6176 Show whether @value{GDBN} will stop in or step over functions without
6177 source line debug information.
6178
6179 @kindex finish
6180 @kindex fin @r{(@code{finish})}
6181 @item finish
6182 Continue running until just after function in the selected stack frame
6183 returns. Print the returned value (if any). This command can be
6184 abbreviated as @code{fin}.
6185
6186 Contrast this with the @code{return} command (@pxref{Returning,
6187 ,Returning from a Function}).
6188
6189 @kindex set print finish
6190 @kindex show print finish
6191 @item set print finish @r{[}on|off@r{]}
6192 @itemx show print finish
6193 By default the @code{finish} command will show the value that is
6194 returned by the function. This can be disabled using @code{set print
6195 finish off}. When disabled, the value is still entered into the value
6196 history (@pxref{Value History}), but not displayed.
6197
6198 @kindex until
6199 @kindex u @r{(@code{until})}
6200 @cindex run until specified location
6201 @item until
6202 @itemx u
6203 Continue running until a source line past the current line, in the
6204 current stack frame, is reached. This command is used to avoid single
6205 stepping through a loop more than once. It is like the @code{next}
6206 command, except that when @code{until} encounters a jump, it
6207 automatically continues execution until the program counter is greater
6208 than the address of the jump.
6209
6210 This means that when you reach the end of a loop after single stepping
6211 though it, @code{until} makes your program continue execution until it
6212 exits the loop. In contrast, a @code{next} command at the end of a loop
6213 simply steps back to the beginning of the loop, which forces you to step
6214 through the next iteration.
6215
6216 @code{until} always stops your program if it attempts to exit the current
6217 stack frame.
6218
6219 @code{until} may produce somewhat counterintuitive results if the order
6220 of machine code does not match the order of the source lines. For
6221 example, in the following excerpt from a debugging session, the @code{f}
6222 (@code{frame}) command shows that execution is stopped at line
6223 @code{206}; yet when we use @code{until}, we get to line @code{195}:
6224
6225 @smallexample
6226 (@value{GDBP}) f
6227 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
6228 206 expand_input();
6229 (@value{GDBP}) until
6230 195 for ( ; argc > 0; NEXTARG) @{
6231 @end smallexample
6232
6233 This happened because, for execution efficiency, the compiler had
6234 generated code for the loop closure test at the end, rather than the
6235 start, of the loop---even though the test in a C @code{for}-loop is
6236 written before the body of the loop. The @code{until} command appeared
6237 to step back to the beginning of the loop when it advanced to this
6238 expression; however, it has not really gone to an earlier
6239 statement---not in terms of the actual machine code.
6240
6241 @code{until} with no argument works by means of single
6242 instruction stepping, and hence is slower than @code{until} with an
6243 argument.
6244
6245 @item until @var{location}
6246 @itemx u @var{location}
6247 Continue running your program until either the specified @var{location} is
6248 reached, or the current stack frame returns. The location is any of
6249 the forms described in @ref{Specify Location}.
6250 This form of the command uses temporary breakpoints, and
6251 hence is quicker than @code{until} without an argument. The specified
6252 location is actually reached only if it is in the current frame. This
6253 implies that @code{until} can be used to skip over recursive function
6254 invocations. For instance in the code below, if the current location is
6255 line @code{96}, issuing @code{until 99} will execute the program up to
6256 line @code{99} in the same invocation of factorial, i.e., after the inner
6257 invocations have returned.
6258
6259 @smallexample
6260 94 int factorial (int value)
6261 95 @{
6262 96 if (value > 1) @{
6263 97 value *= factorial (value - 1);
6264 98 @}
6265 99 return (value);
6266 100 @}
6267 @end smallexample
6268
6269
6270 @kindex advance @var{location}
6271 @item advance @var{location}
6272 Continue running the program up to the given @var{location}. An argument is
6273 required, which should be of one of the forms described in
6274 @ref{Specify Location}.
6275 Execution will also stop upon exit from the current stack
6276 frame. This command is similar to @code{until}, but @code{advance} will
6277 not skip over recursive function calls, and the target location doesn't
6278 have to be in the same frame as the current one.
6279
6280
6281 @kindex stepi
6282 @kindex si @r{(@code{stepi})}
6283 @item stepi
6284 @itemx stepi @var{arg}
6285 @itemx si
6286 Execute one machine instruction, then stop and return to the debugger.
6287
6288 It is often useful to do @samp{display/i $pc} when stepping by machine
6289 instructions. This makes @value{GDBN} automatically display the next
6290 instruction to be executed, each time your program stops. @xref{Auto
6291 Display,, Automatic Display}.
6292
6293 An argument is a repeat count, as in @code{step}.
6294
6295 @need 750
6296 @kindex nexti
6297 @kindex ni @r{(@code{nexti})}
6298 @item nexti
6299 @itemx nexti @var{arg}
6300 @itemx ni
6301 Execute one machine instruction, but if it is a function call,
6302 proceed until the function returns.
6303
6304 An argument is a repeat count, as in @code{next}.
6305
6306 @end table
6307
6308 @anchor{range stepping}
6309 @cindex range stepping
6310 @cindex target-assisted range stepping
6311 By default, and if available, @value{GDBN} makes use of
6312 target-assisted @dfn{range stepping}. In other words, whenever you
6313 use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6314 tells the target to step the corresponding range of instruction
6315 addresses instead of issuing multiple single-steps. This speeds up
6316 line stepping, particularly for remote targets. Ideally, there should
6317 be no reason you would want to turn range stepping off. However, it's
6318 possible that a bug in the debug info, a bug in the remote stub (for
6319 remote targets), or even a bug in @value{GDBN} could make line
6320 stepping behave incorrectly when target-assisted range stepping is
6321 enabled. You can use the following command to turn off range stepping
6322 if necessary:
6323
6324 @table @code
6325 @kindex set range-stepping
6326 @kindex show range-stepping
6327 @item set range-stepping
6328 @itemx show range-stepping
6329 Control whether range stepping is enabled.
6330
6331 If @code{on}, and the target supports it, @value{GDBN} tells the
6332 target to step a range of addresses itself, instead of issuing
6333 multiple single-steps. If @code{off}, @value{GDBN} always issues
6334 single-steps, even if range stepping is supported by the target. The
6335 default is @code{on}.
6336
6337 @end table
6338
6339 @node Skipping Over Functions and Files
6340 @section Skipping Over Functions and Files
6341 @cindex skipping over functions and files
6342
6343 The program you are debugging may contain some functions which are
6344 uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
6345 skip a function, all functions in a file or a particular function in
6346 a particular file when stepping.
6347
6348 For example, consider the following C function:
6349
6350 @smallexample
6351 101 int func()
6352 102 @{
6353 103 foo(boring());
6354 104 bar(boring());
6355 105 @}
6356 @end smallexample
6357
6358 @noindent
6359 Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6360 are not interested in stepping through @code{boring}. If you run @code{step}
6361 at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6362 step over both @code{foo} and @code{boring}!
6363
6364 One solution is to @code{step} into @code{boring} and use the @code{finish}
6365 command to immediately exit it. But this can become tedious if @code{boring}
6366 is called from many places.
6367
6368 A more flexible solution is to execute @kbd{skip boring}. This instructs
6369 @value{GDBN} never to step into @code{boring}. Now when you execute
6370 @code{step} at line 103, you'll step over @code{boring} and directly into
6371 @code{foo}.
6372
6373 Functions may be skipped by providing either a function name, linespec
6374 (@pxref{Specify Location}), regular expression that matches the function's
6375 name, file name or a @code{glob}-style pattern that matches the file name.
6376
6377 On Posix systems the form of the regular expression is
6378 ``Extended Regular Expressions''. See for example @samp{man 7 regex}
6379 on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6380 expression is whatever is provided by the @code{regcomp} function of
6381 the underlying system.
6382 See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6383 description of @code{glob}-style patterns.
6384
6385 @table @code
6386 @kindex skip
6387 @item skip @r{[}@var{options}@r{]}
6388 The basic form of the @code{skip} command takes zero or more options
6389 that specify what to skip.
6390 The @var{options} argument is any useful combination of the following:
6391
6392 @table @code
6393 @item -file @var{file}
6394 @itemx -fi @var{file}
6395 Functions in @var{file} will be skipped over when stepping.
6396
6397 @item -gfile @var{file-glob-pattern}
6398 @itemx -gfi @var{file-glob-pattern}
6399 @cindex skipping over files via glob-style patterns
6400 Functions in files matching @var{file-glob-pattern} will be skipped
6401 over when stepping.
6402
6403 @smallexample
6404 (gdb) skip -gfi utils/*.c
6405 @end smallexample
6406
6407 @item -function @var{linespec}
6408 @itemx -fu @var{linespec}
6409 Functions named by @var{linespec} or the function containing the line
6410 named by @var{linespec} will be skipped over when stepping.
6411 @xref{Specify Location}.
6412
6413 @item -rfunction @var{regexp}
6414 @itemx -rfu @var{regexp}
6415 @cindex skipping over functions via regular expressions
6416 Functions whose name matches @var{regexp} will be skipped over when stepping.
6417
6418 This form is useful for complex function names.
6419 For example, there is generally no need to step into C@t{++} @code{std::string}
6420 constructors or destructors. Plus with C@t{++} templates it can be hard to
6421 write out the full name of the function, and often it doesn't matter what
6422 the template arguments are. Specifying the function to be skipped as a
6423 regular expression makes this easier.
6424
6425 @smallexample
6426 (gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6427 @end smallexample
6428
6429 If you want to skip every templated C@t{++} constructor and destructor
6430 in the @code{std} namespace you can do:
6431
6432 @smallexample
6433 (gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6434 @end smallexample
6435 @end table
6436
6437 If no options are specified, the function you're currently debugging
6438 will be skipped.
6439
6440 @kindex skip function
6441 @item skip function @r{[}@var{linespec}@r{]}
6442 After running this command, the function named by @var{linespec} or the
6443 function containing the line named by @var{linespec} will be skipped over when
6444 stepping. @xref{Specify Location}.
6445
6446 If you do not specify @var{linespec}, the function you're currently debugging
6447 will be skipped.
6448
6449 (If you have a function called @code{file} that you want to skip, use
6450 @kbd{skip function file}.)
6451
6452 @kindex skip file
6453 @item skip file @r{[}@var{filename}@r{]}
6454 After running this command, any function whose source lives in @var{filename}
6455 will be skipped over when stepping.
6456
6457 @smallexample
6458 (gdb) skip file boring.c
6459 File boring.c will be skipped when stepping.
6460 @end smallexample
6461
6462 If you do not specify @var{filename}, functions whose source lives in the file
6463 you're currently debugging will be skipped.
6464 @end table
6465
6466 Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6467 These are the commands for managing your list of skips:
6468
6469 @table @code
6470 @kindex info skip
6471 @item info skip @r{[}@var{range}@r{]}
6472 Print details about the specified skip(s). If @var{range} is not specified,
6473 print a table with details about all functions and files marked for skipping.
6474 @code{info skip} prints the following information about each skip:
6475
6476 @table @emph
6477 @item Identifier
6478 A number identifying this skip.
6479 @item Enabled or Disabled
6480 Enabled skips are marked with @samp{y}.
6481 Disabled skips are marked with @samp{n}.
6482 @item Glob
6483 If the file name is a @samp{glob} pattern this is @samp{y}.
6484 Otherwise it is @samp{n}.
6485 @item File
6486 The name or @samp{glob} pattern of the file to be skipped.
6487 If no file is specified this is @samp{<none>}.
6488 @item RE
6489 If the function name is a @samp{regular expression} this is @samp{y}.
6490 Otherwise it is @samp{n}.
6491 @item Function
6492 The name or regular expression of the function to skip.
6493 If no function is specified this is @samp{<none>}.
6494 @end table
6495
6496 @kindex skip delete
6497 @item skip delete @r{[}@var{range}@r{]}
6498 Delete the specified skip(s). If @var{range} is not specified, delete all
6499 skips.
6500
6501 @kindex skip enable
6502 @item skip enable @r{[}@var{range}@r{]}
6503 Enable the specified skip(s). If @var{range} is not specified, enable all
6504 skips.
6505
6506 @kindex skip disable
6507 @item skip disable @r{[}@var{range}@r{]}
6508 Disable the specified skip(s). If @var{range} is not specified, disable all
6509 skips.
6510
6511 @kindex set debug skip
6512 @item set debug skip @r{[}on|off@r{]}
6513 Set whether to print the debug output about skipping files and functions.
6514
6515 @kindex show debug skip
6516 @item show debug skip
6517 Show whether the debug output about skipping files and functions is printed.
6518
6519 @end table
6520
6521 @node Signals
6522 @section Signals
6523 @cindex signals
6524
6525 A signal is an asynchronous event that can happen in a program. The
6526 operating system defines the possible kinds of signals, and gives each
6527 kind a name and a number. For example, in Unix @code{SIGINT} is the
6528 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
6529 @code{SIGSEGV} is the signal a program gets from referencing a place in
6530 memory far away from all the areas in use; @code{SIGALRM} occurs when
6531 the alarm clock timer goes off (which happens only if your program has
6532 requested an alarm).
6533
6534 @cindex fatal signals
6535 Some signals, including @code{SIGALRM}, are a normal part of the
6536 functioning of your program. Others, such as @code{SIGSEGV}, indicate
6537 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
6538 program has not specified in advance some other way to handle the signal.
6539 @code{SIGINT} does not indicate an error in your program, but it is normally
6540 fatal so it can carry out the purpose of the interrupt: to kill the program.
6541
6542 @value{GDBN} has the ability to detect any occurrence of a signal in your
6543 program. You can tell @value{GDBN} in advance what to do for each kind of
6544 signal.
6545
6546 @cindex handling signals
6547 Normally, @value{GDBN} is set up to let the non-erroneous signals like
6548 @code{SIGALRM} be silently passed to your program
6549 (so as not to interfere with their role in the program's functioning)
6550 but to stop your program immediately whenever an error signal happens.
6551 You can change these settings with the @code{handle} command.
6552
6553 @table @code
6554 @kindex info signals
6555 @kindex info handle
6556 @item info signals
6557 @itemx info handle
6558 Print a table of all the kinds of signals and how @value{GDBN} has been told to
6559 handle each one. You can use this to see the signal numbers of all
6560 the defined types of signals.
6561
6562 @item info signals @var{sig}
6563 Similar, but print information only about the specified signal number.
6564
6565 @code{info handle} is an alias for @code{info signals}.
6566
6567 @item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6568 Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6569 for details about this command.
6570
6571 @kindex handle
6572 @item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
6573 Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
6574 can be the number of a signal or its name (with or without the
6575 @samp{SIG} at the beginning); a list of signal numbers of the form
6576 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
6577 known signals. Optional arguments @var{keywords}, described below,
6578 say what change to make.
6579 @end table
6580
6581 @c @group
6582 The keywords allowed by the @code{handle} command can be abbreviated.
6583 Their full names are:
6584
6585 @table @code
6586 @item nostop
6587 @value{GDBN} should not stop your program when this signal happens. It may
6588 still print a message telling you that the signal has come in.
6589
6590 @item stop
6591 @value{GDBN} should stop your program when this signal happens. This implies
6592 the @code{print} keyword as well.
6593
6594 @item print
6595 @value{GDBN} should print a message when this signal happens.
6596
6597 @item noprint
6598 @value{GDBN} should not mention the occurrence of the signal at all. This
6599 implies the @code{nostop} keyword as well.
6600
6601 @item pass
6602 @itemx noignore
6603 @value{GDBN} should allow your program to see this signal; your program
6604 can handle the signal, or else it may terminate if the signal is fatal
6605 and not handled. @code{pass} and @code{noignore} are synonyms.
6606
6607 @item nopass
6608 @itemx ignore
6609 @value{GDBN} should not allow your program to see this signal.
6610 @code{nopass} and @code{ignore} are synonyms.
6611 @end table
6612 @c @end group
6613
6614 When a signal stops your program, the signal is not visible to the
6615 program until you
6616 continue. Your program sees the signal then, if @code{pass} is in
6617 effect for the signal in question @emph{at that time}. In other words,
6618 after @value{GDBN} reports a signal, you can use the @code{handle}
6619 command with @code{pass} or @code{nopass} to control whether your
6620 program sees that signal when you continue.
6621
6622 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6623 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6624 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6625 erroneous signals.
6626
6627 You can also use the @code{signal} command to prevent your program from
6628 seeing a signal, or cause it to see a signal it normally would not see,
6629 or to give it any signal at any time. For example, if your program stopped
6630 due to some sort of memory reference error, you might store correct
6631 values into the erroneous variables and continue, hoping to see more
6632 execution; but your program would probably terminate immediately as
6633 a result of the fatal signal once it saw the signal. To prevent this,
6634 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
6635 Program a Signal}.
6636
6637 @cindex stepping and signal handlers
6638 @anchor{stepping and signal handlers}
6639
6640 @value{GDBN} optimizes for stepping the mainline code. If a signal
6641 that has @code{handle nostop} and @code{handle pass} set arrives while
6642 a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6643 in progress, @value{GDBN} lets the signal handler run and then resumes
6644 stepping the mainline code once the signal handler returns. In other
6645 words, @value{GDBN} steps over the signal handler. This prevents
6646 signals that you've specified as not interesting (with @code{handle
6647 nostop}) from changing the focus of debugging unexpectedly. Note that
6648 the signal handler itself may still hit a breakpoint, stop for another
6649 signal that has @code{handle stop} in effect, or for any other event
6650 that normally results in stopping the stepping command sooner. Also
6651 note that @value{GDBN} still informs you that the program received a
6652 signal if @code{handle print} is set.
6653
6654 @anchor{stepping into signal handlers}
6655
6656 If you set @code{handle pass} for a signal, and your program sets up a
6657 handler for it, then issuing a stepping command, such as @code{step}
6658 or @code{stepi}, when your program is stopped due to the signal will
6659 step @emph{into} the signal handler (if the target supports that).
6660
6661 Likewise, if you use the @code{queue-signal} command to queue a signal
6662 to be delivered to the current thread when execution of the thread
6663 resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6664 stepping command will step into the signal handler.
6665
6666 Here's an example, using @code{stepi} to step to the first instruction
6667 of @code{SIGUSR1}'s handler:
6668
6669 @smallexample
6670 (@value{GDBP}) handle SIGUSR1
6671 Signal Stop Print Pass to program Description
6672 SIGUSR1 Yes Yes Yes User defined signal 1
6673 (@value{GDBP}) c
6674 Continuing.
6675
6676 Program received signal SIGUSR1, User defined signal 1.
6677 main () sigusr1.c:28
6678 28 p = 0;
6679 (@value{GDBP}) si
6680 sigusr1_handler () at sigusr1.c:9
6681 9 @{
6682 @end smallexample
6683
6684 The same, but using @code{queue-signal} instead of waiting for the
6685 program to receive the signal first:
6686
6687 @smallexample
6688 (@value{GDBP}) n
6689 28 p = 0;
6690 (@value{GDBP}) queue-signal SIGUSR1
6691 (@value{GDBP}) si
6692 sigusr1_handler () at sigusr1.c:9
6693 9 @{
6694 (@value{GDBP})
6695 @end smallexample
6696
6697 @cindex extra signal information
6698 @anchor{extra signal information}
6699
6700 On some targets, @value{GDBN} can inspect extra signal information
6701 associated with the intercepted signal, before it is actually
6702 delivered to the program being debugged. This information is exported
6703 by the convenience variable @code{$_siginfo}, and consists of data
6704 that is passed by the kernel to the signal handler at the time of the
6705 receipt of a signal. The data type of the information itself is
6706 target dependent. You can see the data type using the @code{ptype
6707 $_siginfo} command. On Unix systems, it typically corresponds to the
6708 standard @code{siginfo_t} type, as defined in the @file{signal.h}
6709 system header.
6710
6711 Here's an example, on a @sc{gnu}/Linux system, printing the stray
6712 referenced address that raised a segmentation fault.
6713
6714 @smallexample
6715 @group
6716 (@value{GDBP}) continue
6717 Program received signal SIGSEGV, Segmentation fault.
6718 0x0000000000400766 in main ()
6719 69 *(int *)p = 0;
6720 (@value{GDBP}) ptype $_siginfo
6721 type = struct @{
6722 int si_signo;
6723 int si_errno;
6724 int si_code;
6725 union @{
6726 int _pad[28];
6727 struct @{...@} _kill;
6728 struct @{...@} _timer;
6729 struct @{...@} _rt;
6730 struct @{...@} _sigchld;
6731 struct @{...@} _sigfault;
6732 struct @{...@} _sigpoll;
6733 @} _sifields;
6734 @}
6735 (@value{GDBP}) ptype $_siginfo._sifields._sigfault
6736 type = struct @{
6737 void *si_addr;
6738 @}
6739 (@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6740 $1 = (void *) 0x7ffff7ff7000
6741 @end group
6742 @end smallexample
6743
6744 Depending on target support, @code{$_siginfo} may also be writable.
6745
6746 @cindex Intel MPX boundary violations
6747 @cindex boundary violations, Intel MPX
6748 On some targets, a @code{SIGSEGV} can be caused by a boundary
6749 violation, i.e., accessing an address outside of the allowed range.
6750 In those cases @value{GDBN} may displays additional information,
6751 depending on how @value{GDBN} has been told to handle the signal.
6752 With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6753 kind: "Upper" or "Lower", the memory address accessed and the
6754 bounds, while with @code{handle nostop SIGSEGV} no additional
6755 information is displayed.
6756
6757 The usual output of a segfault is:
6758 @smallexample
6759 Program received signal SIGSEGV, Segmentation fault
6760 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6761 68 value = *(p + len);
6762 @end smallexample
6763
6764 While a bound violation is presented as:
6765 @smallexample
6766 Program received signal SIGSEGV, Segmentation fault
6767 Upper bound violation while accessing address 0x7fffffffc3b3
6768 Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
6769 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6770 68 value = *(p + len);
6771 @end smallexample
6772
6773 @node Thread Stops
6774 @section Stopping and Starting Multi-thread Programs
6775
6776 @cindex stopped threads
6777 @cindex threads, stopped
6778
6779 @cindex continuing threads
6780 @cindex threads, continuing
6781
6782 @value{GDBN} supports debugging programs with multiple threads
6783 (@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6784 are two modes of controlling execution of your program within the
6785 debugger. In the default mode, referred to as @dfn{all-stop mode},
6786 when any thread in your program stops (for example, at a breakpoint
6787 or while being stepped), all other threads in the program are also stopped by
6788 @value{GDBN}. On some targets, @value{GDBN} also supports
6789 @dfn{non-stop mode}, in which other threads can continue to run freely while
6790 you examine the stopped thread in the debugger.
6791
6792 @menu
6793 * All-Stop Mode:: All threads stop when GDB takes control
6794 * Non-Stop Mode:: Other threads continue to execute
6795 * Background Execution:: Running your program asynchronously
6796 * Thread-Specific Breakpoints:: Controlling breakpoints
6797 * Interrupted System Calls:: GDB may interfere with system calls
6798 * Observer Mode:: GDB does not alter program behavior
6799 @end menu
6800
6801 @node All-Stop Mode
6802 @subsection All-Stop Mode
6803
6804 @cindex all-stop mode
6805
6806 In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6807 @emph{all} threads of execution stop, not just the current thread. This
6808 allows you to examine the overall state of the program, including
6809 switching between threads, without worrying that things may change
6810 underfoot.
6811
6812 Conversely, whenever you restart the program, @emph{all} threads start
6813 executing. @emph{This is true even when single-stepping} with commands
6814 like @code{step} or @code{next}.
6815
6816 In particular, @value{GDBN} cannot single-step all threads in lockstep.
6817 Since thread scheduling is up to your debugging target's operating
6818 system (not controlled by @value{GDBN}), other threads may
6819 execute more than one statement while the current thread completes a
6820 single step. Moreover, in general other threads stop in the middle of a
6821 statement, rather than at a clean statement boundary, when the program
6822 stops.
6823
6824 You might even find your program stopped in another thread after
6825 continuing or even single-stepping. This happens whenever some other
6826 thread runs into a breakpoint, a signal, or an exception before the
6827 first thread completes whatever you requested.
6828
6829 @cindex automatic thread selection
6830 @cindex switching threads automatically
6831 @cindex threads, automatic switching
6832 Whenever @value{GDBN} stops your program, due to a breakpoint or a
6833 signal, it automatically selects the thread where that breakpoint or
6834 signal happened. @value{GDBN} alerts you to the context switch with a
6835 message such as @samp{[Switching to Thread @var{n}]} to identify the
6836 thread.
6837
6838 On some OSes, you can modify @value{GDBN}'s default behavior by
6839 locking the OS scheduler to allow only a single thread to run.
6840
6841 @table @code
6842 @item set scheduler-locking @var{mode}
6843 @cindex scheduler locking mode
6844 @cindex lock scheduler
6845 Set the scheduler locking mode. It applies to normal execution,
6846 record mode, and replay mode. If it is @code{off}, then there is no
6847 locking and any thread may run at any time. If @code{on}, then only
6848 the current thread may run when the inferior is resumed. The
6849 @code{step} mode optimizes for single-stepping; it prevents other
6850 threads from preempting the current thread while you are stepping, so
6851 that the focus of debugging does not change unexpectedly. Other
6852 threads never get a chance to run when you step, and they are
6853 completely free to run when you use commands like @samp{continue},
6854 @samp{until}, or @samp{finish}. However, unless another thread hits a
6855 breakpoint during its timeslice, @value{GDBN} does not change the
6856 current thread away from the thread that you are debugging. The
6857 @code{replay} mode behaves like @code{off} in record mode and like
6858 @code{on} in replay mode.
6859
6860 @item show scheduler-locking
6861 Display the current scheduler locking mode.
6862 @end table
6863
6864 @cindex resume threads of multiple processes simultaneously
6865 By default, when you issue one of the execution commands such as
6866 @code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6867 threads of the current inferior to run. For example, if @value{GDBN}
6868 is attached to two inferiors, each with two threads, the
6869 @code{continue} command resumes only the two threads of the current
6870 inferior. This is useful, for example, when you debug a program that
6871 forks and you want to hold the parent stopped (so that, for instance,
6872 it doesn't run to exit), while you debug the child. In other
6873 situations, you may not be interested in inspecting the current state
6874 of any of the processes @value{GDBN} is attached to, and you may want
6875 to resume them all until some breakpoint is hit. In the latter case,
6876 you can instruct @value{GDBN} to allow all threads of all the
6877 inferiors to run with the @w{@code{set schedule-multiple}} command.
6878
6879 @table @code
6880 @kindex set schedule-multiple
6881 @item set schedule-multiple
6882 Set the mode for allowing threads of multiple processes to be resumed
6883 when an execution command is issued. When @code{on}, all threads of
6884 all processes are allowed to run. When @code{off}, only the threads
6885 of the current process are resumed. The default is @code{off}. The
6886 @code{scheduler-locking} mode takes precedence when set to @code{on},
6887 or while you are stepping and set to @code{step}.
6888
6889 @item show schedule-multiple
6890 Display the current mode for resuming the execution of threads of
6891 multiple processes.
6892 @end table
6893
6894 @node Non-Stop Mode
6895 @subsection Non-Stop Mode
6896
6897 @cindex non-stop mode
6898
6899 @c This section is really only a place-holder, and needs to be expanded
6900 @c with more details.
6901
6902 For some multi-threaded targets, @value{GDBN} supports an optional
6903 mode of operation in which you can examine stopped program threads in
6904 the debugger while other threads continue to execute freely. This
6905 minimizes intrusion when debugging live systems, such as programs
6906 where some threads have real-time constraints or must continue to
6907 respond to external events. This is referred to as @dfn{non-stop} mode.
6908
6909 In non-stop mode, when a thread stops to report a debugging event,
6910 @emph{only} that thread is stopped; @value{GDBN} does not stop other
6911 threads as well, in contrast to the all-stop mode behavior. Additionally,
6912 execution commands such as @code{continue} and @code{step} apply by default
6913 only to the current thread in non-stop mode, rather than all threads as
6914 in all-stop mode. This allows you to control threads explicitly in
6915 ways that are not possible in all-stop mode --- for example, stepping
6916 one thread while allowing others to run freely, stepping
6917 one thread while holding all others stopped, or stepping several threads
6918 independently and simultaneously.
6919
6920 To enter non-stop mode, use this sequence of commands before you run
6921 or attach to your program:
6922
6923 @smallexample
6924 # If using the CLI, pagination breaks non-stop.
6925 set pagination off
6926
6927 # Finally, turn it on!
6928 set non-stop on
6929 @end smallexample
6930
6931 You can use these commands to manipulate the non-stop mode setting:
6932
6933 @table @code
6934 @kindex set non-stop
6935 @item set non-stop on
6936 Enable selection of non-stop mode.
6937 @item set non-stop off
6938 Disable selection of non-stop mode.
6939 @kindex show non-stop
6940 @item show non-stop
6941 Show the current non-stop enablement setting.
6942 @end table
6943
6944 Note these commands only reflect whether non-stop mode is enabled,
6945 not whether the currently-executing program is being run in non-stop mode.
6946 In particular, the @code{set non-stop} preference is only consulted when
6947 @value{GDBN} starts or connects to the target program, and it is generally
6948 not possible to switch modes once debugging has started. Furthermore,
6949 since not all targets support non-stop mode, even when you have enabled
6950 non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6951 default.
6952
6953 In non-stop mode, all execution commands apply only to the current thread
6954 by default. That is, @code{continue} only continues one thread.
6955 To continue all threads, issue @code{continue -a} or @code{c -a}.
6956
6957 You can use @value{GDBN}'s background execution commands
6958 (@pxref{Background Execution}) to run some threads in the background
6959 while you continue to examine or step others from @value{GDBN}.
6960 The MI execution commands (@pxref{GDB/MI Program Execution}) are
6961 always executed asynchronously in non-stop mode.
6962
6963 Suspending execution is done with the @code{interrupt} command when
6964 running in the background, or @kbd{Ctrl-c} during foreground execution.
6965 In all-stop mode, this stops the whole process;
6966 but in non-stop mode the interrupt applies only to the current thread.
6967 To stop the whole program, use @code{interrupt -a}.
6968
6969 Other execution commands do not currently support the @code{-a} option.
6970
6971 In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
6972 that thread current, as it does in all-stop mode. This is because the
6973 thread stop notifications are asynchronous with respect to @value{GDBN}'s
6974 command interpreter, and it would be confusing if @value{GDBN} unexpectedly
6975 changed to a different thread just as you entered a command to operate on the
6976 previously current thread.
6977
6978 @node Background Execution
6979 @subsection Background Execution
6980
6981 @cindex foreground execution
6982 @cindex background execution
6983 @cindex asynchronous execution
6984 @cindex execution, foreground, background and asynchronous
6985
6986 @value{GDBN}'s execution commands have two variants: the normal
6987 foreground (synchronous) behavior, and a background
6988 (asynchronous) behavior. In foreground execution, @value{GDBN} waits for
6989 the program to report that some thread has stopped before prompting for
6990 another command. In background execution, @value{GDBN} immediately gives
6991 a command prompt so that you can issue other commands while your program runs.
6992
6993 If the target doesn't support async mode, @value{GDBN} issues an error
6994 message if you attempt to use the background execution commands.
6995
6996 @cindex @code{&}, background execution of commands
6997 To specify background execution, add a @code{&} to the command. For example,
6998 the background form of the @code{continue} command is @code{continue&}, or
6999 just @code{c&}. The execution commands that accept background execution
7000 are:
7001
7002 @table @code
7003 @kindex run&
7004 @item run
7005 @xref{Starting, , Starting your Program}.
7006
7007 @item attach
7008 @kindex attach&
7009 @xref{Attach, , Debugging an Already-running Process}.
7010
7011 @item step
7012 @kindex step&
7013 @xref{Continuing and Stepping, step}.
7014
7015 @item stepi
7016 @kindex stepi&
7017 @xref{Continuing and Stepping, stepi}.
7018
7019 @item next
7020 @kindex next&
7021 @xref{Continuing and Stepping, next}.
7022
7023 @item nexti
7024 @kindex nexti&
7025 @xref{Continuing and Stepping, nexti}.
7026
7027 @item continue
7028 @kindex continue&
7029 @xref{Continuing and Stepping, continue}.
7030
7031 @item finish
7032 @kindex finish&
7033 @xref{Continuing and Stepping, finish}.
7034
7035 @item until
7036 @kindex until&
7037 @xref{Continuing and Stepping, until}.
7038
7039 @end table
7040
7041 Background execution is especially useful in conjunction with non-stop
7042 mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
7043 However, you can also use these commands in the normal all-stop mode with
7044 the restriction that you cannot issue another execution command until the
7045 previous one finishes. Examples of commands that are valid in all-stop
7046 mode while the program is running include @code{help} and @code{info break}.
7047
7048 You can interrupt your program while it is running in the background by
7049 using the @code{interrupt} command.
7050
7051 @table @code
7052 @kindex interrupt
7053 @item interrupt
7054 @itemx interrupt -a
7055
7056 Suspend execution of the running program. In all-stop mode,
7057 @code{interrupt} stops the whole process, but in non-stop mode, it stops
7058 only the current thread. To stop the whole program in non-stop mode,
7059 use @code{interrupt -a}.
7060 @end table
7061
7062 @node Thread-Specific Breakpoints
7063 @subsection Thread-Specific Breakpoints
7064
7065 When your program has multiple threads (@pxref{Threads,, Debugging
7066 Programs with Multiple Threads}), you can choose whether to set
7067 breakpoints on all threads, or on a particular thread.
7068
7069 @table @code
7070 @cindex breakpoints and threads
7071 @cindex thread breakpoints
7072 @kindex break @dots{} thread @var{thread-id}
7073 @item break @var{location} thread @var{thread-id}
7074 @itemx break @var{location} thread @var{thread-id} if @dots{}
7075 @var{location} specifies source lines; there are several ways of
7076 writing them (@pxref{Specify Location}), but the effect is always to
7077 specify some source line.
7078
7079 Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
7080 to specify that you only want @value{GDBN} to stop the program when a
7081 particular thread reaches this breakpoint. The @var{thread-id} specifier
7082 is one of the thread identifiers assigned by @value{GDBN}, shown
7083 in the first column of the @samp{info threads} display.
7084
7085 If you do not specify @samp{thread @var{thread-id}} when you set a
7086 breakpoint, the breakpoint applies to @emph{all} threads of your
7087 program.
7088
7089 You can use the @code{thread} qualifier on conditional breakpoints as
7090 well; in this case, place @samp{thread @var{thread-id}} before or
7091 after the breakpoint condition, like this:
7092
7093 @smallexample
7094 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
7095 @end smallexample
7096
7097 @end table
7098
7099 Thread-specific breakpoints are automatically deleted when
7100 @value{GDBN} detects the corresponding thread is no longer in the
7101 thread list. For example:
7102
7103 @smallexample
7104 (@value{GDBP}) c
7105 Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
7106 @end smallexample
7107
7108 There are several ways for a thread to disappear, such as a regular
7109 thread exit, but also when you detach from the process with the
7110 @code{detach} command (@pxref{Attach, ,Debugging an Already-running
7111 Process}), or if @value{GDBN} loses the remote connection
7112 (@pxref{Remote Debugging}), etc. Note that with some targets,
7113 @value{GDBN} is only able to detect a thread has exited when the user
7114 explictly asks for the thread list with the @code{info threads}
7115 command.
7116
7117 @node Interrupted System Calls
7118 @subsection Interrupted System Calls
7119
7120 @cindex thread breakpoints and system calls
7121 @cindex system calls and thread breakpoints
7122 @cindex premature return from system calls
7123 There is an unfortunate side effect when using @value{GDBN} to debug
7124 multi-threaded programs. If one thread stops for a
7125 breakpoint, or for some other reason, and another thread is blocked in a
7126 system call, then the system call may return prematurely. This is a
7127 consequence of the interaction between multiple threads and the signals
7128 that @value{GDBN} uses to implement breakpoints and other events that
7129 stop execution.
7130
7131 To handle this problem, your program should check the return value of
7132 each system call and react appropriately. This is good programming
7133 style anyways.
7134
7135 For example, do not write code like this:
7136
7137 @smallexample
7138 sleep (10);
7139 @end smallexample
7140
7141 The call to @code{sleep} will return early if a different thread stops
7142 at a breakpoint or for some other reason.
7143
7144 Instead, write this:
7145
7146 @smallexample
7147 int unslept = 10;
7148 while (unslept > 0)
7149 unslept = sleep (unslept);
7150 @end smallexample
7151
7152 A system call is allowed to return early, so the system is still
7153 conforming to its specification. But @value{GDBN} does cause your
7154 multi-threaded program to behave differently than it would without
7155 @value{GDBN}.
7156
7157 Also, @value{GDBN} uses internal breakpoints in the thread library to
7158 monitor certain events such as thread creation and thread destruction.
7159 When such an event happens, a system call in another thread may return
7160 prematurely, even though your program does not appear to stop.
7161
7162 @node Observer Mode
7163 @subsection Observer Mode
7164
7165 If you want to build on non-stop mode and observe program behavior
7166 without any chance of disruption by @value{GDBN}, you can set
7167 variables to disable all of the debugger's attempts to modify state,
7168 whether by writing memory, inserting breakpoints, etc. These operate
7169 at a low level, intercepting operations from all commands.
7170
7171 When all of these are set to @code{off}, then @value{GDBN} is said to
7172 be @dfn{observer mode}. As a convenience, the variable
7173 @code{observer} can be set to disable these, plus enable non-stop
7174 mode.
7175
7176 Note that @value{GDBN} will not prevent you from making nonsensical
7177 combinations of these settings. For instance, if you have enabled
7178 @code{may-insert-breakpoints} but disabled @code{may-write-memory},
7179 then breakpoints that work by writing trap instructions into the code
7180 stream will still not be able to be placed.
7181
7182 @table @code
7183
7184 @kindex observer
7185 @item set observer on
7186 @itemx set observer off
7187 When set to @code{on}, this disables all the permission variables
7188 below (except for @code{insert-fast-tracepoints}), plus enables
7189 non-stop debugging. Setting this to @code{off} switches back to
7190 normal debugging, though remaining in non-stop mode.
7191
7192 @item show observer
7193 Show whether observer mode is on or off.
7194
7195 @kindex may-write-registers
7196 @item set may-write-registers on
7197 @itemx set may-write-registers off
7198 This controls whether @value{GDBN} will attempt to alter the values of
7199 registers, such as with assignment expressions in @code{print}, or the
7200 @code{jump} command. It defaults to @code{on}.
7201
7202 @item show may-write-registers
7203 Show the current permission to write registers.
7204
7205 @kindex may-write-memory
7206 @item set may-write-memory on
7207 @itemx set may-write-memory off
7208 This controls whether @value{GDBN} will attempt to alter the contents
7209 of memory, such as with assignment expressions in @code{print}. It
7210 defaults to @code{on}.
7211
7212 @item show may-write-memory
7213 Show the current permission to write memory.
7214
7215 @kindex may-insert-breakpoints
7216 @item set may-insert-breakpoints on
7217 @itemx set may-insert-breakpoints off
7218 This controls whether @value{GDBN} will attempt to insert breakpoints.
7219 This affects all breakpoints, including internal breakpoints defined
7220 by @value{GDBN}. It defaults to @code{on}.
7221
7222 @item show may-insert-breakpoints
7223 Show the current permission to insert breakpoints.
7224
7225 @kindex may-insert-tracepoints
7226 @item set may-insert-tracepoints on
7227 @itemx set may-insert-tracepoints off
7228 This controls whether @value{GDBN} will attempt to insert (regular)
7229 tracepoints at the beginning of a tracing experiment. It affects only
7230 non-fast tracepoints, fast tracepoints being under the control of
7231 @code{may-insert-fast-tracepoints}. It defaults to @code{on}.
7232
7233 @item show may-insert-tracepoints
7234 Show the current permission to insert tracepoints.
7235
7236 @kindex may-insert-fast-tracepoints
7237 @item set may-insert-fast-tracepoints on
7238 @itemx set may-insert-fast-tracepoints off
7239 This controls whether @value{GDBN} will attempt to insert fast
7240 tracepoints at the beginning of a tracing experiment. It affects only
7241 fast tracepoints, regular (non-fast) tracepoints being under the
7242 control of @code{may-insert-tracepoints}. It defaults to @code{on}.
7243
7244 @item show may-insert-fast-tracepoints
7245 Show the current permission to insert fast tracepoints.
7246
7247 @kindex may-interrupt
7248 @item set may-interrupt on
7249 @itemx set may-interrupt off
7250 This controls whether @value{GDBN} will attempt to interrupt or stop
7251 program execution. When this variable is @code{off}, the
7252 @code{interrupt} command will have no effect, nor will
7253 @kbd{Ctrl-c}. It defaults to @code{on}.
7254
7255 @item show may-interrupt
7256 Show the current permission to interrupt or stop the program.
7257
7258 @end table
7259
7260 @node Reverse Execution
7261 @chapter Running programs backward
7262 @cindex reverse execution
7263 @cindex running programs backward
7264
7265 When you are debugging a program, it is not unusual to realize that
7266 you have gone too far, and some event of interest has already happened.
7267 If the target environment supports it, @value{GDBN} can allow you to
7268 ``rewind'' the program by running it backward.
7269
7270 A target environment that supports reverse execution should be able
7271 to ``undo'' the changes in machine state that have taken place as the
7272 program was executing normally. Variables, registers etc.@: should
7273 revert to their previous values. Obviously this requires a great
7274 deal of sophistication on the part of the target environment; not
7275 all target environments can support reverse execution.
7276
7277 When a program is executed in reverse, the instructions that
7278 have most recently been executed are ``un-executed'', in reverse
7279 order. The program counter runs backward, following the previous
7280 thread of execution in reverse. As each instruction is ``un-executed'',
7281 the values of memory and/or registers that were changed by that
7282 instruction are reverted to their previous states. After executing
7283 a piece of source code in reverse, all side effects of that code
7284 should be ``undone'', and all variables should be returned to their
7285 prior values@footnote{
7286 Note that some side effects are easier to undo than others. For instance,
7287 memory and registers are relatively easy, but device I/O is hard. Some
7288 targets may be able undo things like device I/O, and some may not.
7289
7290 The contract between @value{GDBN} and the reverse executing target
7291 requires only that the target do something reasonable when
7292 @value{GDBN} tells it to execute backwards, and then report the
7293 results back to @value{GDBN}. Whatever the target reports back to
7294 @value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7295 assumes that the memory and registers that the target reports are in a
7296 consistent state, but @value{GDBN} accepts whatever it is given.
7297 }.
7298
7299 On some platforms, @value{GDBN} has built-in support for reverse
7300 execution, activated with the @code{record} or @code{record btrace}
7301 commands. @xref{Process Record and Replay}. Some remote targets,
7302 typically full system emulators, support reverse execution directly
7303 without requiring any special command.
7304
7305 If you are debugging in a target environment that supports
7306 reverse execution, @value{GDBN} provides the following commands.
7307
7308 @table @code
7309 @kindex reverse-continue
7310 @kindex rc @r{(@code{reverse-continue})}
7311 @item reverse-continue @r{[}@var{ignore-count}@r{]}
7312 @itemx rc @r{[}@var{ignore-count}@r{]}
7313 Beginning at the point where your program last stopped, start executing
7314 in reverse. Reverse execution will stop for breakpoints and synchronous
7315 exceptions (signals), just like normal execution. Behavior of
7316 asynchronous signals depends on the target environment.
7317
7318 @kindex reverse-step
7319 @kindex rs @r{(@code{step})}
7320 @item reverse-step @r{[}@var{count}@r{]}
7321 Run the program backward until control reaches the start of a
7322 different source line; then stop it, and return control to @value{GDBN}.
7323
7324 Like the @code{step} command, @code{reverse-step} will only stop
7325 at the beginning of a source line. It ``un-executes'' the previously
7326 executed source line. If the previous source line included calls to
7327 debuggable functions, @code{reverse-step} will step (backward) into
7328 the called function, stopping at the beginning of the @emph{last}
7329 statement in the called function (typically a return statement).
7330
7331 Also, as with the @code{step} command, if non-debuggable functions are
7332 called, @code{reverse-step} will run thru them backward without stopping.
7333
7334 @kindex reverse-stepi
7335 @kindex rsi @r{(@code{reverse-stepi})}
7336 @item reverse-stepi @r{[}@var{count}@r{]}
7337 Reverse-execute one machine instruction. Note that the instruction
7338 to be reverse-executed is @emph{not} the one pointed to by the program
7339 counter, but the instruction executed prior to that one. For instance,
7340 if the last instruction was a jump, @code{reverse-stepi} will take you
7341 back from the destination of the jump to the jump instruction itself.
7342
7343 @kindex reverse-next
7344 @kindex rn @r{(@code{reverse-next})}
7345 @item reverse-next @r{[}@var{count}@r{]}
7346 Run backward to the beginning of the previous line executed in
7347 the current (innermost) stack frame. If the line contains function
7348 calls, they will be ``un-executed'' without stopping. Starting from
7349 the first line of a function, @code{reverse-next} will take you back
7350 to the caller of that function, @emph{before} the function was called,
7351 just as the normal @code{next} command would take you from the last
7352 line of a function back to its return to its caller
7353 @footnote{Unless the code is too heavily optimized.}.
7354
7355 @kindex reverse-nexti
7356 @kindex rni @r{(@code{reverse-nexti})}
7357 @item reverse-nexti @r{[}@var{count}@r{]}
7358 Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7359 in reverse, except that called functions are ``un-executed'' atomically.
7360 That is, if the previously executed instruction was a return from
7361 another function, @code{reverse-nexti} will continue to execute
7362 in reverse until the call to that function (from the current stack
7363 frame) is reached.
7364
7365 @kindex reverse-finish
7366 @item reverse-finish
7367 Just as the @code{finish} command takes you to the point where the
7368 current function returns, @code{reverse-finish} takes you to the point
7369 where it was called. Instead of ending up at the end of the current
7370 function invocation, you end up at the beginning.
7371
7372 @kindex set exec-direction
7373 @item set exec-direction
7374 Set the direction of target execution.
7375 @item set exec-direction reverse
7376 @cindex execute forward or backward in time
7377 @value{GDBN} will perform all execution commands in reverse, until the
7378 exec-direction mode is changed to ``forward''. Affected commands include
7379 @code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7380 command cannot be used in reverse mode.
7381 @item set exec-direction forward
7382 @value{GDBN} will perform all execution commands in the normal fashion.
7383 This is the default.
7384 @end table
7385
7386
7387 @node Process Record and Replay
7388 @chapter Recording Inferior's Execution and Replaying It
7389 @cindex process record and replay
7390 @cindex recording inferior's execution and replaying it
7391
7392 On some platforms, @value{GDBN} provides a special @dfn{process record
7393 and replay} target that can record a log of the process execution, and
7394 replay it later with both forward and reverse execution commands.
7395
7396 @cindex replay mode
7397 When this target is in use, if the execution log includes the record
7398 for the next instruction, @value{GDBN} will debug in @dfn{replay
7399 mode}. In the replay mode, the inferior does not really execute code
7400 instructions. Instead, all the events that normally happen during
7401 code execution are taken from the execution log. While code is not
7402 really executed in replay mode, the values of registers (including the
7403 program counter register) and the memory of the inferior are still
7404 changed as they normally would. Their contents are taken from the
7405 execution log.
7406
7407 @cindex record mode
7408 If the record for the next instruction is not in the execution log,
7409 @value{GDBN} will debug in @dfn{record mode}. In this mode, the
7410 inferior executes normally, and @value{GDBN} records the execution log
7411 for future replay.
7412
7413 The process record and replay target supports reverse execution
7414 (@pxref{Reverse Execution}), even if the platform on which the
7415 inferior runs does not. However, the reverse execution is limited in
7416 this case by the range of the instructions recorded in the execution
7417 log. In other words, reverse execution on platforms that don't
7418 support it directly can only be done in the replay mode.
7419
7420 When debugging in the reverse direction, @value{GDBN} will work in
7421 replay mode as long as the execution log includes the record for the
7422 previous instruction; otherwise, it will work in record mode, if the
7423 platform supports reverse execution, or stop if not.
7424
7425 Currently, process record and replay is supported on ARM, Aarch64,
7426 Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7427 GNU/Linux. Process record and replay can be used both when native
7428 debugging, and when remote debugging via @code{gdbserver}.
7429
7430 For architecture environments that support process record and replay,
7431 @value{GDBN} provides the following commands:
7432
7433 @table @code
7434 @kindex target record
7435 @kindex target record-full
7436 @kindex target record-btrace
7437 @kindex record
7438 @kindex record full
7439 @kindex record btrace
7440 @kindex record btrace bts
7441 @kindex record btrace pt
7442 @kindex record bts
7443 @kindex record pt
7444 @kindex rec
7445 @kindex rec full
7446 @kindex rec btrace
7447 @kindex rec btrace bts
7448 @kindex rec btrace pt
7449 @kindex rec bts
7450 @kindex rec pt
7451 @item record @var{method}
7452 This command starts the process record and replay target. The
7453 recording method can be specified as parameter. Without a parameter
7454 the command uses the @code{full} recording method. The following
7455 recording methods are available:
7456
7457 @table @code
7458 @item full
7459 Full record/replay recording using @value{GDBN}'s software record and
7460 replay implementation. This method allows replaying and reverse
7461 execution.
7462
7463 @item btrace @var{format}
7464 Hardware-supported instruction recording, supported on Intel
7465 processors. This method does not record data. Further, the data is
7466 collected in a ring buffer so old data will be overwritten when the
7467 buffer is full. It allows limited reverse execution. Variables and
7468 registers are not available during reverse execution. In remote
7469 debugging, recording continues on disconnect. Recorded data can be
7470 inspected after reconnecting. The recording may be stopped using
7471 @code{record stop}.
7472
7473 The recording format can be specified as parameter. Without a parameter
7474 the command chooses the recording format. The following recording
7475 formats are available:
7476
7477 @table @code
7478 @item bts
7479 @cindex branch trace store
7480 Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7481 this format, the processor stores a from/to record for each executed
7482 branch in the btrace ring buffer.
7483
7484 @item pt
7485 @cindex Intel Processor Trace
7486 Use the @dfn{Intel Processor Trace} recording format. In this
7487 format, the processor stores the execution trace in a compressed form
7488 that is afterwards decoded by @value{GDBN}.
7489
7490 The trace can be recorded with very low overhead. The compressed
7491 trace format also allows small trace buffers to already contain a big
7492 number of instructions compared to @acronym{BTS}.
7493
7494 Decoding the recorded execution trace, on the other hand, is more
7495 expensive than decoding @acronym{BTS} trace. This is mostly due to the
7496 increased number of instructions to process. You should increase the
7497 buffer-size with care.
7498 @end table
7499
7500 Not all recording formats may be available on all processors.
7501 @end table
7502
7503 The process record and replay target can only debug a process that is
7504 already running. Therefore, you need first to start the process with
7505 the @kbd{run} or @kbd{start} commands, and then start the recording
7506 with the @kbd{record @var{method}} command.
7507
7508 @cindex displaced stepping, and process record and replay
7509 Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7510 will be automatically disabled when process record and replay target
7511 is started. That's because the process record and replay target
7512 doesn't support displaced stepping.
7513
7514 @cindex non-stop mode, and process record and replay
7515 @cindex asynchronous execution, and process record and replay
7516 If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
7517 the asynchronous execution mode (@pxref{Background Execution}), not
7518 all recording methods are available. The @code{full} recording method
7519 does not support these two modes.
7520
7521 @kindex record stop
7522 @kindex rec s
7523 @item record stop
7524 Stop the process record and replay target. When process record and
7525 replay target stops, the entire execution log will be deleted and the
7526 inferior will either be terminated, or will remain in its final state.
7527
7528 When you stop the process record and replay target in record mode (at
7529 the end of the execution log), the inferior will be stopped at the
7530 next instruction that would have been recorded. In other words, if
7531 you record for a while and then stop recording, the inferior process
7532 will be left in the same state as if the recording never happened.
7533
7534 On the other hand, if the process record and replay target is stopped
7535 while in replay mode (that is, not at the end of the execution log,
7536 but at some earlier point), the inferior process will become ``live''
7537 at that earlier state, and it will then be possible to continue the
7538 usual ``live'' debugging of the process from that state.
7539
7540 When the inferior process exits, or @value{GDBN} detaches from it,
7541 process record and replay target will automatically stop itself.
7542
7543 @kindex record goto
7544 @item record goto
7545 Go to a specific location in the execution log. There are several
7546 ways to specify the location to go to:
7547
7548 @table @code
7549 @item record goto begin
7550 @itemx record goto start
7551 Go to the beginning of the execution log.
7552
7553 @item record goto end
7554 Go to the end of the execution log.
7555
7556 @item record goto @var{n}
7557 Go to instruction number @var{n} in the execution log.
7558 @end table
7559
7560 @kindex record save
7561 @item record save @var{filename}
7562 Save the execution log to a file @file{@var{filename}}.
7563 Default filename is @file{gdb_record.@var{process_id}}, where
7564 @var{process_id} is the process ID of the inferior.
7565
7566 This command may not be available for all recording methods.
7567
7568 @kindex record restore
7569 @item record restore @var{filename}
7570 Restore the execution log from a file @file{@var{filename}}.
7571 File must have been created with @code{record save}.
7572
7573 @kindex set record full
7574 @item set record full insn-number-max @var{limit}
7575 @itemx set record full insn-number-max unlimited
7576 Set the limit of instructions to be recorded for the @code{full}
7577 recording method. Default value is 200000.
7578
7579 If @var{limit} is a positive number, then @value{GDBN} will start
7580 deleting instructions from the log once the number of the record
7581 instructions becomes greater than @var{limit}. For every new recorded
7582 instruction, @value{GDBN} will delete the earliest recorded
7583 instruction to keep the number of recorded instructions at the limit.
7584 (Since deleting recorded instructions loses information, @value{GDBN}
7585 lets you control what happens when the limit is reached, by means of
7586 the @code{stop-at-limit} option, described below.)
7587
7588 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7589 delete recorded instructions from the execution log. The number of
7590 recorded instructions is limited only by the available memory.
7591
7592 @kindex show record full
7593 @item show record full insn-number-max
7594 Show the limit of instructions to be recorded with the @code{full}
7595 recording method.
7596
7597 @item set record full stop-at-limit
7598 Control the behavior of the @code{full} recording method when the
7599 number of recorded instructions reaches the limit. If ON (the
7600 default), @value{GDBN} will stop when the limit is reached for the
7601 first time and ask you whether you want to stop the inferior or
7602 continue running it and recording the execution log. If you decide
7603 to continue recording, each new recorded instruction will cause the
7604 oldest one to be deleted.
7605
7606 If this option is OFF, @value{GDBN} will automatically delete the
7607 oldest record to make room for each new one, without asking.
7608
7609 @item show record full stop-at-limit
7610 Show the current setting of @code{stop-at-limit}.
7611
7612 @item set record full memory-query
7613 Control the behavior when @value{GDBN} is unable to record memory
7614 changes caused by an instruction for the @code{full} recording method.
7615 If ON, @value{GDBN} will query whether to stop the inferior in that
7616 case.
7617
7618 If this option is OFF (the default), @value{GDBN} will automatically
7619 ignore the effect of such instructions on memory. Later, when
7620 @value{GDBN} replays this execution log, it will mark the log of this
7621 instruction as not accessible, and it will not affect the replay
7622 results.
7623
7624 @item show record full memory-query
7625 Show the current setting of @code{memory-query}.
7626
7627 @kindex set record btrace
7628 The @code{btrace} record target does not trace data. As a
7629 convenience, when replaying, @value{GDBN} reads read-only memory off
7630 the live program directly, assuming that the addresses of the
7631 read-only areas don't change. This for example makes it possible to
7632 disassemble code while replaying, but not to print variables.
7633 In some cases, being able to inspect variables might be useful.
7634 You can use the following command for that:
7635
7636 @item set record btrace replay-memory-access
7637 Control the behavior of the @code{btrace} recording method when
7638 accessing memory during replay. If @code{read-only} (the default),
7639 @value{GDBN} will only allow accesses to read-only memory.
7640 If @code{read-write}, @value{GDBN} will allow accesses to read-only
7641 and to read-write memory. Beware that the accessed memory corresponds
7642 to the live target and not necessarily to the current replay
7643 position.
7644
7645 @item set record btrace cpu @var{identifier}
7646 Set the processor to be used for enabling workarounds for processor
7647 errata when decoding the trace.
7648
7649 Processor errata are defects in processor operation, caused by its
7650 design or manufacture. They can cause a trace not to match the
7651 specification. This, in turn, may cause trace decode to fail.
7652 @value{GDBN} can detect erroneous trace packets and correct them, thus
7653 avoiding the decoding failures. These corrections are known as
7654 @dfn{errata workarounds}, and are enabled based on the processor on
7655 which the trace was recorded.
7656
7657 By default, @value{GDBN} attempts to detect the processor
7658 automatically, and apply the necessary workarounds for it. However,
7659 you may need to specify the processor if @value{GDBN} does not yet
7660 support it. This command allows you to do that, and also allows to
7661 disable the workarounds.
7662
7663 The argument @var{identifier} identifies the @sc{cpu} and is of the
7664 form: @code{@var{vendor}:@var{processor identifier}}. In addition,
7665 there are two special identifiers, @code{none} and @code{auto}
7666 (default).
7667
7668 The following vendor identifiers and corresponding processor
7669 identifiers are currently supported:
7670
7671 @multitable @columnfractions .1 .9
7672
7673 @item @code{intel}
7674 @tab @var{family}/@var{model}[/@var{stepping}]
7675
7676 @end multitable
7677
7678 On GNU/Linux systems, the processor @var{family}, @var{model}, and
7679 @var{stepping} can be obtained from @code{/proc/cpuinfo}.
7680
7681 If @var{identifier} is @code{auto}, enable errata workarounds for the
7682 processor on which the trace was recorded. If @var{identifier} is
7683 @code{none}, errata workarounds are disabled.
7684
7685 For example, when using an old @value{GDBN} on a new system, decode
7686 may fail because @value{GDBN} does not support the new processor. It
7687 often suffices to specify an older processor that @value{GDBN}
7688 supports.
7689
7690 @smallexample
7691 (gdb) info record
7692 Active record target: record-btrace
7693 Recording format: Intel Processor Trace.
7694 Buffer size: 16kB.
7695 Failed to configure the Intel Processor Trace decoder: unknown cpu.
7696 (gdb) set record btrace cpu intel:6/158
7697 (gdb) info record
7698 Active record target: record-btrace
7699 Recording format: Intel Processor Trace.
7700 Buffer size: 16kB.
7701 Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7702 @end smallexample
7703
7704 @kindex show record btrace
7705 @item show record btrace replay-memory-access
7706 Show the current setting of @code{replay-memory-access}.
7707
7708 @item show record btrace cpu
7709 Show the processor to be used for enabling trace decode errata
7710 workarounds.
7711
7712 @kindex set record btrace bts
7713 @item set record btrace bts buffer-size @var{size}
7714 @itemx set record btrace bts buffer-size unlimited
7715 Set the requested ring buffer size for branch tracing in @acronym{BTS}
7716 format. Default is 64KB.
7717
7718 If @var{size} is a positive number, then @value{GDBN} will try to
7719 allocate a buffer of at least @var{size} bytes for each new thread
7720 that uses the btrace recording method and the @acronym{BTS} format.
7721 The actually obtained buffer size may differ from the requested
7722 @var{size}. Use the @code{info record} command to see the actual
7723 buffer size for each thread that uses the btrace recording method and
7724 the @acronym{BTS} format.
7725
7726 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7727 allocate a buffer of 4MB.
7728
7729 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7730 also need longer to process the branch trace data before it can be used.
7731
7732 @item show record btrace bts buffer-size @var{size}
7733 Show the current setting of the requested ring buffer size for branch
7734 tracing in @acronym{BTS} format.
7735
7736 @kindex set record btrace pt
7737 @item set record btrace pt buffer-size @var{size}
7738 @itemx set record btrace pt buffer-size unlimited
7739 Set the requested ring buffer size for branch tracing in Intel
7740 Processor Trace format. Default is 16KB.
7741
7742 If @var{size} is a positive number, then @value{GDBN} will try to
7743 allocate a buffer of at least @var{size} bytes for each new thread
7744 that uses the btrace recording method and the Intel Processor Trace
7745 format. The actually obtained buffer size may differ from the
7746 requested @var{size}. Use the @code{info record} command to see the
7747 actual buffer size for each thread.
7748
7749 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7750 allocate a buffer of 4MB.
7751
7752 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7753 also need longer to process the branch trace data before it can be used.
7754
7755 @item show record btrace pt buffer-size @var{size}
7756 Show the current setting of the requested ring buffer size for branch
7757 tracing in Intel Processor Trace format.
7758
7759 @kindex info record
7760 @item info record
7761 Show various statistics about the recording depending on the recording
7762 method:
7763
7764 @table @code
7765 @item full
7766 For the @code{full} recording method, it shows the state of process
7767 record and its in-memory execution log buffer, including:
7768
7769 @itemize @bullet
7770 @item
7771 Whether in record mode or replay mode.
7772 @item
7773 Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7774 @item
7775 Highest recorded instruction number.
7776 @item
7777 Current instruction about to be replayed (if in replay mode).
7778 @item
7779 Number of instructions contained in the execution log.
7780 @item
7781 Maximum number of instructions that may be contained in the execution log.
7782 @end itemize
7783
7784 @item btrace
7785 For the @code{btrace} recording method, it shows:
7786
7787 @itemize @bullet
7788 @item
7789 Recording format.
7790 @item
7791 Number of instructions that have been recorded.
7792 @item
7793 Number of blocks of sequential control-flow formed by the recorded
7794 instructions.
7795 @item
7796 Whether in record mode or replay mode.
7797 @end itemize
7798
7799 For the @code{bts} recording format, it also shows:
7800 @itemize @bullet
7801 @item
7802 Size of the perf ring buffer.
7803 @end itemize
7804
7805 For the @code{pt} recording format, it also shows:
7806 @itemize @bullet
7807 @item
7808 Size of the perf ring buffer.
7809 @end itemize
7810 @end table
7811
7812 @kindex record delete
7813 @kindex rec del
7814 @item record delete
7815 When record target runs in replay mode (``in the past''), delete the
7816 subsequent execution log and begin to record a new execution log starting
7817 from the current address. This means you will abandon the previously
7818 recorded ``future'' and begin recording a new ``future''.
7819
7820 @kindex record instruction-history
7821 @kindex rec instruction-history
7822 @item record instruction-history
7823 Disassembles instructions from the recorded execution log. By
7824 default, ten instructions are disassembled. This can be changed using
7825 the @code{set record instruction-history-size} command. Instructions
7826 are printed in execution order.
7827
7828 It can also print mixed source+disassembly if you specify the the
7829 @code{/m} or @code{/s} modifier, and print the raw instructions in hex
7830 as well as in symbolic form by specifying the @code{/r} modifier.
7831
7832 The current position marker is printed for the instruction at the
7833 current program counter value. This instruction can appear multiple
7834 times in the trace and the current position marker will be printed
7835 every time. To omit the current position marker, specify the
7836 @code{/p} modifier.
7837
7838 To better align the printed instructions when the trace contains
7839 instructions from more than one function, the function name may be
7840 omitted by specifying the @code{/f} modifier.
7841
7842 Speculatively executed instructions are prefixed with @samp{?}. This
7843 feature is not available for all recording formats.
7844
7845 There are several ways to specify what part of the execution log to
7846 disassemble:
7847
7848 @table @code
7849 @item record instruction-history @var{insn}
7850 Disassembles ten instructions starting from instruction number
7851 @var{insn}.
7852
7853 @item record instruction-history @var{insn}, +/-@var{n}
7854 Disassembles @var{n} instructions around instruction number
7855 @var{insn}. If @var{n} is preceded with @code{+}, disassembles
7856 @var{n} instructions after instruction number @var{insn}. If
7857 @var{n} is preceded with @code{-}, disassembles @var{n}
7858 instructions before instruction number @var{insn}.
7859
7860 @item record instruction-history
7861 Disassembles ten more instructions after the last disassembly.
7862
7863 @item record instruction-history -
7864 Disassembles ten more instructions before the last disassembly.
7865
7866 @item record instruction-history @var{begin}, @var{end}
7867 Disassembles instructions beginning with instruction number
7868 @var{begin} until instruction number @var{end}. The instruction
7869 number @var{end} is included.
7870 @end table
7871
7872 This command may not be available for all recording methods.
7873
7874 @kindex set record
7875 @item set record instruction-history-size @var{size}
7876 @itemx set record instruction-history-size unlimited
7877 Define how many instructions to disassemble in the @code{record
7878 instruction-history} command. The default value is 10.
7879 A @var{size} of @code{unlimited} means unlimited instructions.
7880
7881 @kindex show record
7882 @item show record instruction-history-size
7883 Show how many instructions to disassemble in the @code{record
7884 instruction-history} command.
7885
7886 @kindex record function-call-history
7887 @kindex rec function-call-history
7888 @item record function-call-history
7889 Prints the execution history at function granularity. It prints one
7890 line for each sequence of instructions that belong to the same
7891 function giving the name of that function, the source lines
7892 for this instruction sequence (if the @code{/l} modifier is
7893 specified), and the instructions numbers that form the sequence (if
7894 the @code{/i} modifier is specified). The function names are indented
7895 to reflect the call stack depth if the @code{/c} modifier is
7896 specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7897 given together.
7898
7899 @smallexample
7900 (@value{GDBP}) @b{list 1, 10}
7901 1 void foo (void)
7902 2 @{
7903 3 @}
7904 4
7905 5 void bar (void)
7906 6 @{
7907 7 ...
7908 8 foo ();
7909 9 ...
7910 10 @}
7911 (@value{GDBP}) @b{record function-call-history /ilc}
7912 1 bar inst 1,4 at foo.c:6,8
7913 2 foo inst 5,10 at foo.c:2,3
7914 3 bar inst 11,13 at foo.c:9,10
7915 @end smallexample
7916
7917 By default, ten lines are printed. This can be changed using the
7918 @code{set record function-call-history-size} command. Functions are
7919 printed in execution order. There are several ways to specify what
7920 to print:
7921
7922 @table @code
7923 @item record function-call-history @var{func}
7924 Prints ten functions starting from function number @var{func}.
7925
7926 @item record function-call-history @var{func}, +/-@var{n}
7927 Prints @var{n} functions around function number @var{func}. If
7928 @var{n} is preceded with @code{+}, prints @var{n} functions after
7929 function number @var{func}. If @var{n} is preceded with @code{-},
7930 prints @var{n} functions before function number @var{func}.
7931
7932 @item record function-call-history
7933 Prints ten more functions after the last ten-line print.
7934
7935 @item record function-call-history -
7936 Prints ten more functions before the last ten-line print.
7937
7938 @item record function-call-history @var{begin}, @var{end}
7939 Prints functions beginning with function number @var{begin} until
7940 function number @var{end}. The function number @var{end} is included.
7941 @end table
7942
7943 This command may not be available for all recording methods.
7944
7945 @item set record function-call-history-size @var{size}
7946 @itemx set record function-call-history-size unlimited
7947 Define how many lines to print in the
7948 @code{record function-call-history} command. The default value is 10.
7949 A size of @code{unlimited} means unlimited lines.
7950
7951 @item show record function-call-history-size
7952 Show how many lines to print in the
7953 @code{record function-call-history} command.
7954 @end table
7955
7956
7957 @node Stack
7958 @chapter Examining the Stack
7959
7960 When your program has stopped, the first thing you need to know is where it
7961 stopped and how it got there.
7962
7963 @cindex call stack
7964 Each time your program performs a function call, information about the call
7965 is generated.
7966 That information includes the location of the call in your program,
7967 the arguments of the call,
7968 and the local variables of the function being called.
7969 The information is saved in a block of data called a @dfn{stack frame}.
7970 The stack frames are allocated in a region of memory called the @dfn{call
7971 stack}.
7972
7973 When your program stops, the @value{GDBN} commands for examining the
7974 stack allow you to see all of this information.
7975
7976 @cindex selected frame
7977 One of the stack frames is @dfn{selected} by @value{GDBN} and many
7978 @value{GDBN} commands refer implicitly to the selected frame. In
7979 particular, whenever you ask @value{GDBN} for the value of a variable in
7980 your program, the value is found in the selected frame. There are
7981 special @value{GDBN} commands to select whichever frame you are
7982 interested in. @xref{Selection, ,Selecting a Frame}.
7983
7984 When your program stops, @value{GDBN} automatically selects the
7985 currently executing frame and describes it briefly, similar to the
7986 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
7987
7988 @menu
7989 * Frames:: Stack frames
7990 * Backtrace:: Backtraces
7991 * Selection:: Selecting a frame
7992 * Frame Info:: Information on a frame
7993 * Frame Apply:: Applying a command to several frames
7994 * Frame Filter Management:: Managing frame filters
7995
7996 @end menu
7997
7998 @node Frames
7999 @section Stack Frames
8000
8001 @cindex frame, definition
8002 @cindex stack frame
8003 The call stack is divided up into contiguous pieces called @dfn{stack
8004 frames}, or @dfn{frames} for short; each frame is the data associated
8005 with one call to one function. The frame contains the arguments given
8006 to the function, the function's local variables, and the address at
8007 which the function is executing.
8008
8009 @cindex initial frame
8010 @cindex outermost frame
8011 @cindex innermost frame
8012 When your program is started, the stack has only one frame, that of the
8013 function @code{main}. This is called the @dfn{initial} frame or the
8014 @dfn{outermost} frame. Each time a function is called, a new frame is
8015 made. Each time a function returns, the frame for that function invocation
8016 is eliminated. If a function is recursive, there can be many frames for
8017 the same function. The frame for the function in which execution is
8018 actually occurring is called the @dfn{innermost} frame. This is the most
8019 recently created of all the stack frames that still exist.
8020
8021 @cindex frame pointer
8022 Inside your program, stack frames are identified by their addresses. A
8023 stack frame consists of many bytes, each of which has its own address; each
8024 kind of computer has a convention for choosing one byte whose
8025 address serves as the address of the frame. Usually this address is kept
8026 in a register called the @dfn{frame pointer register}
8027 (@pxref{Registers, $fp}) while execution is going on in that frame.
8028
8029 @cindex frame level
8030 @cindex frame number
8031 @value{GDBN} labels each existing stack frame with a @dfn{level}, a
8032 number that is zero for the innermost frame, one for the frame that
8033 called it, and so on upward. These level numbers give you a way of
8034 designating stack frames in @value{GDBN} commands. The terms
8035 @dfn{frame number} and @dfn{frame level} can be used interchangeably to
8036 describe this number.
8037
8038 @c The -fomit-frame-pointer below perennially causes hbox overflow
8039 @c underflow problems.
8040 @cindex frameless execution
8041 Some compilers provide a way to compile functions so that they operate
8042 without stack frames. (For example, the @value{NGCC} option
8043 @smallexample
8044 @samp{-fomit-frame-pointer}
8045 @end smallexample
8046 generates functions without a frame.)
8047 This is occasionally done with heavily used library functions to save
8048 the frame setup time. @value{GDBN} has limited facilities for dealing
8049 with these function invocations. If the innermost function invocation
8050 has no stack frame, @value{GDBN} nevertheless regards it as though
8051 it had a separate frame, which is numbered zero as usual, allowing
8052 correct tracing of the function call chain. However, @value{GDBN} has
8053 no provision for frameless functions elsewhere in the stack.
8054
8055 @node Backtrace
8056 @section Backtraces
8057
8058 @cindex traceback
8059 @cindex call stack traces
8060 A backtrace is a summary of how your program got where it is. It shows one
8061 line per frame, for many frames, starting with the currently executing
8062 frame (frame zero), followed by its caller (frame one), and on up the
8063 stack.
8064
8065 @anchor{backtrace-command}
8066 @kindex backtrace
8067 @kindex bt @r{(@code{backtrace})}
8068 To print a backtrace of the entire stack, use the @code{backtrace}
8069 command, or its alias @code{bt}. This command will print one line per
8070 frame for frames in the stack. By default, all stack frames are
8071 printed. You can stop the backtrace at any time by typing the system
8072 interrupt character, normally @kbd{Ctrl-c}.
8073
8074 @table @code
8075 @item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8076 @itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8077 Print the backtrace of the entire stack.
8078
8079 The optional @var{count} can be one of the following:
8080
8081 @table @code
8082 @item @var{n}
8083 @itemx @var{n}
8084 Print only the innermost @var{n} frames, where @var{n} is a positive
8085 number.
8086
8087 @item -@var{n}
8088 @itemx -@var{n}
8089 Print only the outermost @var{n} frames, where @var{n} is a positive
8090 number.
8091 @end table
8092
8093 Options:
8094
8095 @table @code
8096 @item -full
8097 Print the values of the local variables also. This can be combined
8098 with the optional @var{count} to limit the number of frames shown.
8099
8100 @item -no-filters
8101 Do not run Python frame filters on this backtrace. @xref{Frame
8102 Filter API}, for more information. Additionally use @ref{disable
8103 frame-filter all} to turn off all frame filters. This is only
8104 relevant when @value{GDBN} has been configured with @code{Python}
8105 support.
8106
8107 @item -hide
8108 A Python frame filter might decide to ``elide'' some frames. Normally
8109 such elided frames are still printed, but they are indented relative
8110 to the filtered frames that cause them to be elided. The @code{-hide}
8111 option causes elided frames to not be printed at all.
8112 @end table
8113
8114 The @code{backtrace} command also supports a number of options that
8115 allow overriding relevant global print settings as set by @code{set
8116 backtrace} and @code{set print} subcommands:
8117
8118 @table @code
8119 @item -past-main [@code{on}|@code{off}]
8120 Set whether backtraces should continue past @code{main}. Related setting:
8121 @ref{set backtrace past-main}.
8122
8123 @item -past-entry [@code{on}|@code{off}]
8124 Set whether backtraces should continue past the entry point of a program.
8125 Related setting: @ref{set backtrace past-entry}.
8126
8127 @item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
8128 Set printing of function arguments at function entry.
8129 Related setting: @ref{set print entry-values}.
8130
8131 @item -frame-arguments @code{all}|@code{scalars}|@code{none}
8132 Set printing of non-scalar frame arguments.
8133 Related setting: @ref{set print frame-arguments}.
8134
8135 @item -raw-frame-arguments [@code{on}|@code{off}]
8136 Set whether to print frame arguments in raw form.
8137 Related setting: @ref{set print raw-frame-arguments}.
8138
8139 @item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
8140 Set printing of frame information.
8141 Related setting: @ref{set print frame-info}.
8142 @end table
8143
8144 The optional @var{qualifier} is maintained for backward compatibility.
8145 It can be one of the following:
8146
8147 @table @code
8148 @item full
8149 Equivalent to the @code{-full} option.
8150
8151 @item no-filters
8152 Equivalent to the @code{-no-filters} option.
8153
8154 @item hide
8155 Equivalent to the @code{-hide} option.
8156 @end table
8157
8158 @end table
8159
8160 @kindex where
8161 @kindex info stack
8162 The names @code{where} and @code{info stack} (abbreviated @code{info s})
8163 are additional aliases for @code{backtrace}.
8164
8165 @cindex multiple threads, backtrace
8166 In a multi-threaded program, @value{GDBN} by default shows the
8167 backtrace only for the current thread. To display the backtrace for
8168 several or all of the threads, use the command @code{thread apply}
8169 (@pxref{Threads, thread apply}). For example, if you type @kbd{thread
8170 apply all backtrace}, @value{GDBN} will display the backtrace for all
8171 the threads; this is handy when you debug a core dump of a
8172 multi-threaded program.
8173
8174 Each line in the backtrace shows the frame number and the function name.
8175 The program counter value is also shown---unless you use @code{set
8176 print address off}. The backtrace also shows the source file name and
8177 line number, as well as the arguments to the function. The program
8178 counter value is omitted if it is at the beginning of the code for that
8179 line number.
8180
8181 Here is an example of a backtrace. It was made with the command
8182 @samp{bt 3}, so it shows the innermost three frames.
8183
8184 @smallexample
8185 @group
8186 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8187 at builtin.c:993
8188 #1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
8189 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
8190 at macro.c:71
8191 (More stack frames follow...)
8192 @end group
8193 @end smallexample
8194
8195 @noindent
8196 The display for frame zero does not begin with a program counter
8197 value, indicating that your program has stopped at the beginning of the
8198 code for line @code{993} of @code{builtin.c}.
8199
8200 @noindent
8201 The value of parameter @code{data} in frame 1 has been replaced by
8202 @code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
8203 only if it is a scalar (integer, pointer, enumeration, etc). See command
8204 @kbd{set print frame-arguments} in @ref{Print Settings} for more details
8205 on how to configure the way function parameter values are printed.
8206 The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
8207 what frame information is printed.
8208
8209 @cindex optimized out, in backtrace
8210 @cindex function call arguments, optimized out
8211 If your program was compiled with optimizations, some compilers will
8212 optimize away arguments passed to functions if those arguments are
8213 never used after the call. Such optimizations generate code that
8214 passes arguments through registers, but doesn't store those arguments
8215 in the stack frame. @value{GDBN} has no way of displaying such
8216 arguments in stack frames other than the innermost one. Here's what
8217 such a backtrace might look like:
8218
8219 @smallexample
8220 @group
8221 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8222 at builtin.c:993
8223 #1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
8224 #2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
8225 at macro.c:71
8226 (More stack frames follow...)
8227 @end group
8228 @end smallexample
8229
8230 @noindent
8231 The values of arguments that were not saved in their stack frames are
8232 shown as @samp{<optimized out>}.
8233
8234 If you need to display the values of such optimized-out arguments,
8235 either deduce that from other variables whose values depend on the one
8236 you are interested in, or recompile without optimizations.
8237
8238 @cindex backtrace beyond @code{main} function
8239 @cindex program entry point
8240 @cindex startup code, and backtrace
8241 Most programs have a standard user entry point---a place where system
8242 libraries and startup code transition into user code. For C this is
8243 @code{main}@footnote{
8244 Note that embedded programs (the so-called ``free-standing''
8245 environment) are not required to have a @code{main} function as the
8246 entry point. They could even have multiple entry points.}.
8247 When @value{GDBN} finds the entry function in a backtrace
8248 it will terminate the backtrace, to avoid tracing into highly
8249 system-specific (and generally uninteresting) code.
8250
8251 If you need to examine the startup code, or limit the number of levels
8252 in a backtrace, you can change this behavior:
8253
8254 @table @code
8255 @item set backtrace past-main
8256 @itemx set backtrace past-main on
8257 @anchor{set backtrace past-main}
8258 @kindex set backtrace
8259 Backtraces will continue past the user entry point.
8260
8261 @item set backtrace past-main off
8262 Backtraces will stop when they encounter the user entry point. This is the
8263 default.
8264
8265 @item show backtrace past-main
8266 @kindex show backtrace
8267 Display the current user entry point backtrace policy.
8268
8269 @item set backtrace past-entry
8270 @itemx set backtrace past-entry on
8271 @anchor{set backtrace past-entry}
8272 Backtraces will continue past the internal entry point of an application.
8273 This entry point is encoded by the linker when the application is built,
8274 and is likely before the user entry point @code{main} (or equivalent) is called.
8275
8276 @item set backtrace past-entry off
8277 Backtraces will stop when they encounter the internal entry point of an
8278 application. This is the default.
8279
8280 @item show backtrace past-entry
8281 Display the current internal entry point backtrace policy.
8282
8283 @item set backtrace limit @var{n}
8284 @itemx set backtrace limit 0
8285 @itemx set backtrace limit unlimited
8286 @anchor{set backtrace limit}
8287 @cindex backtrace limit
8288 Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8289 or zero means unlimited levels.
8290
8291 @item show backtrace limit
8292 Display the current limit on backtrace levels.
8293 @end table
8294
8295 You can control how file names are displayed.
8296
8297 @table @code
8298 @item set filename-display
8299 @itemx set filename-display relative
8300 @cindex filename-display
8301 Display file names relative to the compilation directory. This is the default.
8302
8303 @item set filename-display basename
8304 Display only basename of a filename.
8305
8306 @item set filename-display absolute
8307 Display an absolute filename.
8308
8309 @item show filename-display
8310 Show the current way to display filenames.
8311 @end table
8312
8313 @node Selection
8314 @section Selecting a Frame
8315
8316 Most commands for examining the stack and other data in your program work on
8317 whichever stack frame is selected at the moment. Here are the commands for
8318 selecting a stack frame; all of them finish by printing a brief description
8319 of the stack frame just selected.
8320
8321 @table @code
8322 @kindex frame@r{, selecting}
8323 @kindex f @r{(@code{frame})}
8324 @item frame @r{[} @var{frame-selection-spec} @r{]}
8325 @item f @r{[} @var{frame-selection-spec} @r{]}
8326 The @command{frame} command allows different stack frames to be
8327 selected. The @var{frame-selection-spec} can be any of the following:
8328
8329 @table @code
8330 @kindex frame level
8331 @item @var{num}
8332 @item level @var{num}
8333 Select frame level @var{num}. Recall that frame zero is the innermost
8334 (currently executing) frame, frame one is the frame that called the
8335 innermost one, and so on. The highest level frame is usually the one
8336 for @code{main}.
8337
8338 As this is the most common method of navigating the frame stack, the
8339 string @command{level} can be omitted. For example, the following two
8340 commands are equivalent:
8341
8342 @smallexample
8343 (@value{GDBP}) frame 3
8344 (@value{GDBP}) frame level 3
8345 @end smallexample
8346
8347 @kindex frame address
8348 @item address @var{stack-address}
8349 Select the frame with stack address @var{stack-address}. The
8350 @var{stack-address} for a frame can be seen in the output of
8351 @command{info frame}, for example:
8352
8353 @smallexample
8354 (gdb) info frame
8355 Stack level 1, frame at 0x7fffffffda30:
8356 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8357 tail call frame, caller of frame at 0x7fffffffda30
8358 source language c++.
8359 Arglist at unknown address.
8360 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8361 @end smallexample
8362
8363 The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8364 indicated by the line:
8365
8366 @smallexample
8367 Stack level 1, frame at 0x7fffffffda30:
8368 @end smallexample
8369
8370 @kindex frame function
8371 @item function @var{function-name}
8372 Select the stack frame for function @var{function-name}. If there are
8373 multiple stack frames for function @var{function-name} then the inner
8374 most stack frame is selected.
8375
8376 @kindex frame view
8377 @item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8378 View a frame that is not part of @value{GDBN}'s backtrace. The frame
8379 viewed has stack address @var{stack-addr}, and optionally, a program
8380 counter address of @var{pc-addr}.
8381
8382 This is useful mainly if the chaining of stack frames has been
8383 damaged by a bug, making it impossible for @value{GDBN} to assign
8384 numbers properly to all frames. In addition, this can be useful
8385 when your program has multiple stacks and switches between them.
8386
8387 When viewing a frame outside the current backtrace using
8388 @command{frame view} then you can always return to the original
8389 stack using one of the previous stack frame selection instructions,
8390 for example @command{frame level 0}.
8391
8392 @end table
8393
8394 @kindex up
8395 @item up @var{n}
8396 Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8397 numbers @var{n}, this advances toward the outermost frame, to higher
8398 frame numbers, to frames that have existed longer.
8399
8400 @kindex down
8401 @kindex do @r{(@code{down})}
8402 @item down @var{n}
8403 Move @var{n} frames down the stack; @var{n} defaults to 1. For
8404 positive numbers @var{n}, this advances toward the innermost frame, to
8405 lower frame numbers, to frames that were created more recently.
8406 You may abbreviate @code{down} as @code{do}.
8407 @end table
8408
8409 All of these commands end by printing two lines of output describing the
8410 frame. The first line shows the frame number, the function name, the
8411 arguments, and the source file and line number of execution in that
8412 frame. The second line shows the text of that source line.
8413
8414 @need 1000
8415 For example:
8416
8417 @smallexample
8418 @group
8419 (@value{GDBP}) up
8420 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8421 at env.c:10
8422 10 read_input_file (argv[i]);
8423 @end group
8424 @end smallexample
8425
8426 After such a printout, the @code{list} command with no arguments
8427 prints ten lines centered on the point of execution in the frame.
8428 You can also edit the program at the point of execution with your favorite
8429 editing program by typing @code{edit}.
8430 @xref{List, ,Printing Source Lines},
8431 for details.
8432
8433 @table @code
8434 @kindex select-frame
8435 @item select-frame @r{[} @var{frame-selection-spec} @r{]}
8436 The @code{select-frame} command is a variant of @code{frame} that does
8437 not display the new frame after selecting it. This command is
8438 intended primarily for use in @value{GDBN} command scripts, where the
8439 output might be unnecessary and distracting. The
8440 @var{frame-selection-spec} is as for the @command{frame} command
8441 described in @ref{Selection, ,Selecting a Frame}.
8442
8443 @kindex down-silently
8444 @kindex up-silently
8445 @item up-silently @var{n}
8446 @itemx down-silently @var{n}
8447 These two commands are variants of @code{up} and @code{down},
8448 respectively; they differ in that they do their work silently, without
8449 causing display of the new frame. They are intended primarily for use
8450 in @value{GDBN} command scripts, where the output might be unnecessary and
8451 distracting.
8452 @end table
8453
8454 @node Frame Info
8455 @section Information About a Frame
8456
8457 There are several other commands to print information about the selected
8458 stack frame.
8459
8460 @table @code
8461 @item frame
8462 @itemx f
8463 When used without any argument, this command does not change which
8464 frame is selected, but prints a brief description of the currently
8465 selected stack frame. It can be abbreviated @code{f}. With an
8466 argument, this command is used to select a stack frame.
8467 @xref{Selection, ,Selecting a Frame}.
8468
8469 @kindex info frame
8470 @kindex info f @r{(@code{info frame})}
8471 @item info frame
8472 @itemx info f
8473 This command prints a verbose description of the selected stack frame,
8474 including:
8475
8476 @itemize @bullet
8477 @item
8478 the address of the frame
8479 @item
8480 the address of the next frame down (called by this frame)
8481 @item
8482 the address of the next frame up (caller of this frame)
8483 @item
8484 the language in which the source code corresponding to this frame is written
8485 @item
8486 the address of the frame's arguments
8487 @item
8488 the address of the frame's local variables
8489 @item
8490 the program counter saved in it (the address of execution in the caller frame)
8491 @item
8492 which registers were saved in the frame
8493 @end itemize
8494
8495 @noindent The verbose description is useful when
8496 something has gone wrong that has made the stack format fail to fit
8497 the usual conventions.
8498
8499 @item info frame @r{[} @var{frame-selection-spec} @r{]}
8500 @itemx info f @r{[} @var{frame-selection-spec} @r{]}
8501 Print a verbose description of the frame selected by
8502 @var{frame-selection-spec}. The @var{frame-selection-spec} is the
8503 same as for the @command{frame} command (@pxref{Selection, ,Selecting
8504 a Frame}). The selected frame remains unchanged by this command.
8505
8506 @kindex info args
8507 @item info args [-q]
8508 Print the arguments of the selected frame, each on a separate line.
8509
8510 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8511 printing header information and messages explaining why no argument
8512 have been printed.
8513
8514 @item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8515 Like @kbd{info args}, but only print the arguments selected
8516 with the provided regexp(s).
8517
8518 If @var{regexp} is provided, print only the arguments whose names
8519 match the regular expression @var{regexp}.
8520
8521 If @var{type_regexp} is provided, print only the arguments whose
8522 types, as printed by the @code{whatis} command, match
8523 the regular expression @var{type_regexp}.
8524 If @var{type_regexp} contains space(s), it should be enclosed in
8525 quote characters. If needed, use backslash to escape the meaning
8526 of special characters or quotes.
8527
8528 If both @var{regexp} and @var{type_regexp} are provided, an argument
8529 is printed only if its name matches @var{regexp} and its type matches
8530 @var{type_regexp}.
8531
8532 @item info locals [-q]
8533 @kindex info locals
8534 Print the local variables of the selected frame, each on a separate
8535 line. These are all variables (declared either static or automatic)
8536 accessible at the point of execution of the selected frame.
8537
8538 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8539 printing header information and messages explaining why no local variables
8540 have been printed.
8541
8542 @item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8543 Like @kbd{info locals}, but only print the local variables selected
8544 with the provided regexp(s).
8545
8546 If @var{regexp} is provided, print only the local variables whose names
8547 match the regular expression @var{regexp}.
8548
8549 If @var{type_regexp} is provided, print only the local variables whose
8550 types, as printed by the @code{whatis} command, match
8551 the regular expression @var{type_regexp}.
8552 If @var{type_regexp} contains space(s), it should be enclosed in
8553 quote characters. If needed, use backslash to escape the meaning
8554 of special characters or quotes.
8555
8556 If both @var{regexp} and @var{type_regexp} are provided, a local variable
8557 is printed only if its name matches @var{regexp} and its type matches
8558 @var{type_regexp}.
8559
8560 The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8561 combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8562 For example, your program might use Resource Acquisition Is
8563 Initialization types (RAII) such as @code{lock_something_t}: each
8564 local variable of type @code{lock_something_t} automatically places a
8565 lock that is destroyed when the variable goes out of scope. You can
8566 then list all acquired locks in your program by doing
8567 @smallexample
8568 thread apply all -s frame apply all -s info locals -q -t lock_something_t
8569 @end smallexample
8570 @noindent
8571 or the equivalent shorter form
8572 @smallexample
8573 tfaas i lo -q -t lock_something_t
8574 @end smallexample
8575
8576 @end table
8577
8578 @node Frame Apply
8579 @section Applying a Command to Several Frames.
8580 @kindex frame apply
8581 @cindex apply command to several frames
8582 @table @code
8583 @item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
8584 The @code{frame apply} command allows you to apply the named
8585 @var{command} to one or more frames.
8586
8587 @table @code
8588 @item @code{all}
8589 Specify @code{all} to apply @var{command} to all frames.
8590
8591 @item @var{count}
8592 Use @var{count} to apply @var{command} to the innermost @var{count}
8593 frames, where @var{count} is a positive number.
8594
8595 @item @var{-count}
8596 Use @var{-count} to apply @var{command} to the outermost @var{count}
8597 frames, where @var{count} is a positive number.
8598
8599 @item @code{level}
8600 Use @code{level} to apply @var{command} to the set of frames identified
8601 by the @var{level} list. @var{level} is a frame level or a range of frame
8602 levels as @var{level1}-@var{level2}. The frame level is the number shown
8603 in the first field of the @samp{backtrace} command output.
8604 E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8605 at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8606
8607 @end table
8608
8609 Note that the frames on which @code{frame apply} applies a command are
8610 also influenced by the @code{set backtrace} settings such as @code{set
8611 backtrace past-main} and @code{set backtrace limit N}.
8612 @xref{Backtrace,,Backtraces}.
8613
8614 The @code{frame apply} command also supports a number of options that
8615 allow overriding relevant @code{set backtrace} settings:
8616
8617 @table @code
8618 @item -past-main [@code{on}|@code{off}]
8619 Whether backtraces should continue past @code{main}.
8620 Related setting: @ref{set backtrace past-main}.
8621
8622 @item -past-entry [@code{on}|@code{off}]
8623 Whether backtraces should continue past the entry point of a program.
8624 Related setting: @ref{set backtrace past-entry}.
8625 @end table
8626
8627 By default, @value{GDBN} displays some frame information before the
8628 output produced by @var{command}, and an error raised during the
8629 execution of a @var{command} will abort @code{frame apply}. The
8630 following options can be used to fine-tune these behaviors:
8631
8632 @table @code
8633 @item -c
8634 The flag @code{-c}, which stands for @samp{continue}, causes any
8635 errors in @var{command} to be displayed, and the execution of
8636 @code{frame apply} then continues.
8637 @item -s
8638 The flag @code{-s}, which stands for @samp{silent}, causes any errors
8639 or empty output produced by a @var{command} to be silently ignored.
8640 That is, the execution continues, but the frame information and errors
8641 are not printed.
8642 @item -q
8643 The flag @code{-q} (@samp{quiet}) disables printing the frame
8644 information.
8645 @end table
8646
8647 The following example shows how the flags @code{-c} and @code{-s} are
8648 working when applying the command @code{p j} to all frames, where
8649 variable @code{j} can only be successfully printed in the outermost
8650 @code{#1 main} frame.
8651
8652 @smallexample
8653 @group
8654 (gdb) frame apply all p j
8655 #0 some_function (i=5) at fun.c:4
8656 No symbol "j" in current context.
8657 (gdb) frame apply all -c p j
8658 #0 some_function (i=5) at fun.c:4
8659 No symbol "j" in current context.
8660 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8661 $1 = 5
8662 (gdb) frame apply all -s p j
8663 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8664 $2 = 5
8665 (gdb)
8666 @end group
8667 @end smallexample
8668
8669 By default, @samp{frame apply}, prints the frame location
8670 information before the command output:
8671
8672 @smallexample
8673 @group
8674 (gdb) frame apply all p $sp
8675 #0 some_function (i=5) at fun.c:4
8676 $4 = (void *) 0xffffd1e0
8677 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8678 $5 = (void *) 0xffffd1f0
8679 (gdb)
8680 @end group
8681 @end smallexample
8682
8683 If the flag @code{-q} is given, no frame information is printed:
8684 @smallexample
8685 @group
8686 (gdb) frame apply all -q p $sp
8687 $12 = (void *) 0xffffd1e0
8688 $13 = (void *) 0xffffd1f0
8689 (gdb)
8690 @end group
8691 @end smallexample
8692
8693 @end table
8694
8695 @table @code
8696
8697 @kindex faas
8698 @cindex apply a command to all frames (ignoring errors and empty output)
8699 @item faas @var{command}
8700 Shortcut for @code{frame apply all -s @var{command}}.
8701 Applies @var{command} on all frames, ignoring errors and empty output.
8702
8703 It can for example be used to print a local variable or a function
8704 argument without knowing the frame where this variable or argument
8705 is, using:
8706 @smallexample
8707 (@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8708 @end smallexample
8709
8710 The @code{faas} command accepts the same options as the @code{frame
8711 apply} command. @xref{Frame Apply,,frame apply}.
8712
8713 Note that the command @code{tfaas @var{command}} applies @var{command}
8714 on all frames of all threads. See @xref{Threads,,Threads}.
8715 @end table
8716
8717
8718 @node Frame Filter Management
8719 @section Management of Frame Filters.
8720 @cindex managing frame filters
8721
8722 Frame filters are Python based utilities to manage and decorate the
8723 output of frames. @xref{Frame Filter API}, for further information.
8724
8725 Managing frame filters is performed by several commands available
8726 within @value{GDBN}, detailed here.
8727
8728 @table @code
8729 @kindex info frame-filter
8730 @item info frame-filter
8731 Print a list of installed frame filters from all dictionaries, showing
8732 their name, priority and enabled status.
8733
8734 @kindex disable frame-filter
8735 @anchor{disable frame-filter all}
8736 @item disable frame-filter @var{filter-dictionary} @var{filter-name}
8737 Disable a frame filter in the dictionary matching
8738 @var{filter-dictionary} and @var{filter-name}. The
8739 @var{filter-dictionary} may be @code{all}, @code{global},
8740 @code{progspace}, or the name of the object file where the frame filter
8741 dictionary resides. When @code{all} is specified, all frame filters
8742 across all dictionaries are disabled. The @var{filter-name} is the name
8743 of the frame filter and is used when @code{all} is not the option for
8744 @var{filter-dictionary}. A disabled frame-filter is not deleted, it
8745 may be enabled again later.
8746
8747 @kindex enable frame-filter
8748 @item enable frame-filter @var{filter-dictionary} @var{filter-name}
8749 Enable a frame filter in the dictionary matching
8750 @var{filter-dictionary} and @var{filter-name}. The
8751 @var{filter-dictionary} may be @code{all}, @code{global},
8752 @code{progspace} or the name of the object file where the frame filter
8753 dictionary resides. When @code{all} is specified, all frame filters across
8754 all dictionaries are enabled. The @var{filter-name} is the name of the frame
8755 filter and is used when @code{all} is not the option for
8756 @var{filter-dictionary}.
8757
8758 Example:
8759
8760 @smallexample
8761 (gdb) info frame-filter
8762
8763 global frame-filters:
8764 Priority Enabled Name
8765 1000 No PrimaryFunctionFilter
8766 100 Yes Reverse
8767
8768 progspace /build/test frame-filters:
8769 Priority Enabled Name
8770 100 Yes ProgspaceFilter
8771
8772 objfile /build/test frame-filters:
8773 Priority Enabled Name
8774 999 Yes BuildProgramFilter
8775
8776 (gdb) disable frame-filter /build/test BuildProgramFilter
8777 (gdb) info frame-filter
8778
8779 global frame-filters:
8780 Priority Enabled Name
8781 1000 No PrimaryFunctionFilter
8782 100 Yes Reverse
8783
8784 progspace /build/test frame-filters:
8785 Priority Enabled Name
8786 100 Yes ProgspaceFilter
8787
8788 objfile /build/test frame-filters:
8789 Priority Enabled Name
8790 999 No BuildProgramFilter
8791
8792 (gdb) enable frame-filter global PrimaryFunctionFilter
8793 (gdb) info frame-filter
8794
8795 global frame-filters:
8796 Priority Enabled Name
8797 1000 Yes PrimaryFunctionFilter
8798 100 Yes Reverse
8799
8800 progspace /build/test frame-filters:
8801 Priority Enabled Name
8802 100 Yes ProgspaceFilter
8803
8804 objfile /build/test frame-filters:
8805 Priority Enabled Name
8806 999 No BuildProgramFilter
8807 @end smallexample
8808
8809 @kindex set frame-filter priority
8810 @item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8811 Set the @var{priority} of a frame filter in the dictionary matching
8812 @var{filter-dictionary}, and the frame filter name matching
8813 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8814 @code{progspace} or the name of the object file where the frame filter
8815 dictionary resides. The @var{priority} is an integer.
8816
8817 @kindex show frame-filter priority
8818 @item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8819 Show the @var{priority} of a frame filter in the dictionary matching
8820 @var{filter-dictionary}, and the frame filter name matching
8821 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8822 @code{progspace} or the name of the object file where the frame filter
8823 dictionary resides.
8824
8825 Example:
8826
8827 @smallexample
8828 (gdb) info frame-filter
8829
8830 global frame-filters:
8831 Priority Enabled Name
8832 1000 Yes PrimaryFunctionFilter
8833 100 Yes Reverse
8834
8835 progspace /build/test frame-filters:
8836 Priority Enabled Name
8837 100 Yes ProgspaceFilter
8838
8839 objfile /build/test frame-filters:
8840 Priority Enabled Name
8841 999 No BuildProgramFilter
8842
8843 (gdb) set frame-filter priority global Reverse 50
8844 (gdb) info frame-filter
8845
8846 global frame-filters:
8847 Priority Enabled Name
8848 1000 Yes PrimaryFunctionFilter
8849 50 Yes Reverse
8850
8851 progspace /build/test frame-filters:
8852 Priority Enabled Name
8853 100 Yes ProgspaceFilter
8854
8855 objfile /build/test frame-filters:
8856 Priority Enabled Name
8857 999 No BuildProgramFilter
8858 @end smallexample
8859 @end table
8860
8861 @node Source
8862 @chapter Examining Source Files
8863
8864 @value{GDBN} can print parts of your program's source, since the debugging
8865 information recorded in the program tells @value{GDBN} what source files were
8866 used to build it. When your program stops, @value{GDBN} spontaneously prints
8867 the line where it stopped. Likewise, when you select a stack frame
8868 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
8869 execution in that frame has stopped. You can print other portions of
8870 source files by explicit command.
8871
8872 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
8873 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
8874 @value{GDBN} under @sc{gnu} Emacs}.
8875
8876 @menu
8877 * List:: Printing source lines
8878 * Specify Location:: How to specify code locations
8879 * Edit:: Editing source files
8880 * Search:: Searching source files
8881 * Source Path:: Specifying source directories
8882 * Machine Code:: Source and machine code
8883 @end menu
8884
8885 @node List
8886 @section Printing Source Lines
8887
8888 @kindex list
8889 @kindex l @r{(@code{list})}
8890 To print lines from a source file, use the @code{list} command
8891 (abbreviated @code{l}). By default, ten lines are printed.
8892 There are several ways to specify what part of the file you want to
8893 print; see @ref{Specify Location}, for the full list.
8894
8895 Here are the forms of the @code{list} command most commonly used:
8896
8897 @table @code
8898 @item list @var{linenum}
8899 Print lines centered around line number @var{linenum} in the
8900 current source file.
8901
8902 @item list @var{function}
8903 Print lines centered around the beginning of function
8904 @var{function}.
8905
8906 @item list
8907 Print more lines. If the last lines printed were printed with a
8908 @code{list} command, this prints lines following the last lines
8909 printed; however, if the last line printed was a solitary line printed
8910 as part of displaying a stack frame (@pxref{Stack, ,Examining the
8911 Stack}), this prints lines centered around that line.
8912
8913 @item list -
8914 Print lines just before the lines last printed.
8915 @end table
8916
8917 @cindex @code{list}, how many lines to display
8918 By default, @value{GDBN} prints ten source lines with any of these forms of
8919 the @code{list} command. You can change this using @code{set listsize}:
8920
8921 @table @code
8922 @kindex set listsize
8923 @item set listsize @var{count}
8924 @itemx set listsize unlimited
8925 Make the @code{list} command display @var{count} source lines (unless
8926 the @code{list} argument explicitly specifies some other number).
8927 Setting @var{count} to @code{unlimited} or 0 means there's no limit.
8928
8929 @kindex show listsize
8930 @item show listsize
8931 Display the number of lines that @code{list} prints.
8932 @end table
8933
8934 Repeating a @code{list} command with @key{RET} discards the argument,
8935 so it is equivalent to typing just @code{list}. This is more useful
8936 than listing the same lines again. An exception is made for an
8937 argument of @samp{-}; that argument is preserved in repetition so that
8938 each repetition moves up in the source file.
8939
8940 In general, the @code{list} command expects you to supply zero, one or two
8941 @dfn{locations}. Locations specify source lines; there are several ways
8942 of writing them (@pxref{Specify Location}), but the effect is always
8943 to specify some source line.
8944
8945 Here is a complete description of the possible arguments for @code{list}:
8946
8947 @table @code
8948 @item list @var{location}
8949 Print lines centered around the line specified by @var{location}.
8950
8951 @item list @var{first},@var{last}
8952 Print lines from @var{first} to @var{last}. Both arguments are
8953 locations. When a @code{list} command has two locations, and the
8954 source file of the second location is omitted, this refers to
8955 the same source file as the first location.
8956
8957 @item list ,@var{last}
8958 Print lines ending with @var{last}.
8959
8960 @item list @var{first},
8961 Print lines starting with @var{first}.
8962
8963 @item list +
8964 Print lines just after the lines last printed.
8965
8966 @item list -
8967 Print lines just before the lines last printed.
8968
8969 @item list
8970 As described in the preceding table.
8971 @end table
8972
8973 @node Specify Location
8974 @section Specifying a Location
8975 @cindex specifying location
8976 @cindex location
8977 @cindex source location
8978
8979 @menu
8980 * Linespec Locations:: Linespec locations
8981 * Explicit Locations:: Explicit locations
8982 * Address Locations:: Address locations
8983 @end menu
8984
8985 Several @value{GDBN} commands accept arguments that specify a location
8986 of your program's code. Since @value{GDBN} is a source-level
8987 debugger, a location usually specifies some line in the source code.
8988 Locations may be specified using three different formats:
8989 linespec locations, explicit locations, or address locations.
8990
8991 @node Linespec Locations
8992 @subsection Linespec Locations
8993 @cindex linespec locations
8994
8995 A @dfn{linespec} is a colon-separated list of source location parameters such
8996 as file name, function name, etc. Here are all the different ways of
8997 specifying a linespec:
8998
8999 @table @code
9000 @item @var{linenum}
9001 Specifies the line number @var{linenum} of the current source file.
9002
9003 @item -@var{offset}
9004 @itemx +@var{offset}
9005 Specifies the line @var{offset} lines before or after the @dfn{current
9006 line}. For the @code{list} command, the current line is the last one
9007 printed; for the breakpoint commands, this is the line at which
9008 execution stopped in the currently selected @dfn{stack frame}
9009 (@pxref{Frames, ,Frames}, for a description of stack frames.) When
9010 used as the second of the two linespecs in a @code{list} command,
9011 this specifies the line @var{offset} lines up or down from the first
9012 linespec.
9013
9014 @item @var{filename}:@var{linenum}
9015 Specifies the line @var{linenum} in the source file @var{filename}.
9016 If @var{filename} is a relative file name, then it will match any
9017 source file name with the same trailing components. For example, if
9018 @var{filename} is @samp{gcc/expr.c}, then it will match source file
9019 name of @file{/build/trunk/gcc/expr.c}, but not
9020 @file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
9021
9022 @item @var{function}
9023 Specifies the line that begins the body of the function @var{function}.
9024 For example, in C, this is the line with the open brace.
9025
9026 By default, in C@t{++} and Ada, @var{function} is interpreted as
9027 specifying all functions named @var{function} in all scopes. For
9028 C@t{++}, this means in all namespaces and classes. For Ada, this
9029 means in all packages.
9030
9031 For example, assuming a program with C@t{++} symbols named
9032 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9033 func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
9034
9035 Commands that accept a linespec let you override this with the
9036 @code{-qualified} option. For example, @w{@kbd{break -qualified
9037 func}} sets a breakpoint on a free-function named @code{func} ignoring
9038 any C@t{++} class methods and namespace functions called @code{func}.
9039
9040 @xref{Explicit Locations}.
9041
9042 @item @var{function}:@var{label}
9043 Specifies the line where @var{label} appears in @var{function}.
9044
9045 @item @var{filename}:@var{function}
9046 Specifies the line that begins the body of the function @var{function}
9047 in the file @var{filename}. You only need the file name with a
9048 function name to avoid ambiguity when there are identically named
9049 functions in different source files.
9050
9051 @item @var{label}
9052 Specifies the line at which the label named @var{label} appears
9053 in the function corresponding to the currently selected stack frame.
9054 If there is no current selected stack frame (for instance, if the inferior
9055 is not running), then @value{GDBN} will not search for a label.
9056
9057 @cindex breakpoint at static probe point
9058 @item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
9059 The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
9060 applications to embed static probes. @xref{Static Probe Points}, for more
9061 information on finding and using static probes. This form of linespec
9062 specifies the location of such a static probe.
9063
9064 If @var{objfile} is given, only probes coming from that shared library
9065 or executable matching @var{objfile} as a regular expression are considered.
9066 If @var{provider} is given, then only probes from that provider are considered.
9067 If several probes match the spec, @value{GDBN} will insert a breakpoint at
9068 each one of those probes.
9069 @end table
9070
9071 @node Explicit Locations
9072 @subsection Explicit Locations
9073 @cindex explicit locations
9074
9075 @dfn{Explicit locations} allow the user to directly specify the source
9076 location's parameters using option-value pairs.
9077
9078 Explicit locations are useful when several functions, labels, or
9079 file names have the same name (base name for files) in the program's
9080 sources. In these cases, explicit locations point to the source
9081 line you meant more accurately and unambiguously. Also, using
9082 explicit locations might be faster in large programs.
9083
9084 For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
9085 defined in the file named @file{foo} or the label @code{bar} in a function
9086 named @code{foo}. @value{GDBN} must search either the file system or
9087 the symbol table to know.
9088
9089 The list of valid explicit location options is summarized in the
9090 following table:
9091
9092 @table @code
9093 @item -source @var{filename}
9094 The value specifies the source file name. To differentiate between
9095 files with the same base name, prepend as many directories as is necessary
9096 to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
9097 @value{GDBN} will use the first file it finds with the given base
9098 name. This option requires the use of either @code{-function} or @code{-line}.
9099
9100 @item -function @var{function}
9101 The value specifies the name of a function. Operations
9102 on function locations unmodified by other options (such as @code{-label}
9103 or @code{-line}) refer to the line that begins the body of the function.
9104 In C, for example, this is the line with the open brace.
9105
9106 By default, in C@t{++} and Ada, @var{function} is interpreted as
9107 specifying all functions named @var{function} in all scopes. For
9108 C@t{++}, this means in all namespaces and classes. For Ada, this
9109 means in all packages.
9110
9111 For example, assuming a program with C@t{++} symbols named
9112 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9113 -function func}} and @w{@kbd{break -function B::func}} set a
9114 breakpoint on both symbols.
9115
9116 You can use the @kbd{-qualified} flag to override this (see below).
9117
9118 @item -qualified
9119
9120 This flag makes @value{GDBN} interpret a function name specified with
9121 @kbd{-function} as a complete fully-qualified name.
9122
9123 For example, assuming a C@t{++} program with symbols named
9124 @code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
9125 -function B::func}} command sets a breakpoint on @code{B::func}, only.
9126
9127 (Note: the @kbd{-qualified} option can precede a linespec as well
9128 (@pxref{Linespec Locations}), so the particular example above could be
9129 simplified as @w{@kbd{break -qualified B::func}}.)
9130
9131 @item -label @var{label}
9132 The value specifies the name of a label. When the function
9133 name is not specified, the label is searched in the function of the currently
9134 selected stack frame.
9135
9136 @item -line @var{number}
9137 The value specifies a line offset for the location. The offset may either
9138 be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
9139 the command. When specified without any other options, the line offset is
9140 relative to the current line.
9141 @end table
9142
9143 Explicit location options may be abbreviated by omitting any non-unique
9144 trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
9145
9146 @node Address Locations
9147 @subsection Address Locations
9148 @cindex address locations
9149
9150 @dfn{Address locations} indicate a specific program address. They have
9151 the generalized form *@var{address}.
9152
9153 For line-oriented commands, such as @code{list} and @code{edit}, this
9154 specifies a source line that contains @var{address}. For @code{break} and
9155 other breakpoint-oriented commands, this can be used to set breakpoints in
9156 parts of your program which do not have debugging information or
9157 source files.
9158
9159 Here @var{address} may be any expression valid in the current working
9160 language (@pxref{Languages, working language}) that specifies a code
9161 address. In addition, as a convenience, @value{GDBN} extends the
9162 semantics of expressions used in locations to cover several situations
9163 that frequently occur during debugging. Here are the various forms
9164 of @var{address}:
9165
9166 @table @code
9167 @item @var{expression}
9168 Any expression valid in the current working language.
9169
9170 @item @var{funcaddr}
9171 An address of a function or procedure derived from its name. In C,
9172 C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
9173 simply the function's name @var{function} (and actually a special case
9174 of a valid expression). In Pascal and Modula-2, this is
9175 @code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
9176 (although the Pascal form also works).
9177
9178 This form specifies the address of the function's first instruction,
9179 before the stack frame and arguments have been set up.
9180
9181 @item '@var{filename}':@var{funcaddr}
9182 Like @var{funcaddr} above, but also specifies the name of the source
9183 file explicitly. This is useful if the name of the function does not
9184 specify the function unambiguously, e.g., if there are several
9185 functions with identical names in different source files.
9186 @end table
9187
9188 @node Edit
9189 @section Editing Source Files
9190 @cindex editing source files
9191
9192 @kindex edit
9193 @kindex e @r{(@code{edit})}
9194 To edit the lines in a source file, use the @code{edit} command.
9195 The editing program of your choice
9196 is invoked with the current line set to
9197 the active line in the program.
9198 Alternatively, there are several ways to specify what part of the file you
9199 want to print if you want to see other parts of the program:
9200
9201 @table @code
9202 @item edit @var{location}
9203 Edit the source file specified by @code{location}. Editing starts at
9204 that @var{location}, e.g., at the specified source line of the
9205 specified file. @xref{Specify Location}, for all the possible forms
9206 of the @var{location} argument; here are the forms of the @code{edit}
9207 command most commonly used:
9208
9209 @table @code
9210 @item edit @var{number}
9211 Edit the current source file with @var{number} as the active line number.
9212
9213 @item edit @var{function}
9214 Edit the file containing @var{function} at the beginning of its definition.
9215 @end table
9216
9217 @end table
9218
9219 @subsection Choosing your Editor
9220 You can customize @value{GDBN} to use any editor you want
9221 @footnote{
9222 The only restriction is that your editor (say @code{ex}), recognizes the
9223 following command-line syntax:
9224 @smallexample
9225 ex +@var{number} file
9226 @end smallexample
9227 The optional numeric value +@var{number} specifies the number of the line in
9228 the file where to start editing.}.
9229 By default, it is @file{@value{EDITOR}}, but you can change this
9230 by setting the environment variable @code{EDITOR} before using
9231 @value{GDBN}. For example, to configure @value{GDBN} to use the
9232 @code{vi} editor, you could use these commands with the @code{sh} shell:
9233 @smallexample
9234 EDITOR=/usr/bin/vi
9235 export EDITOR
9236 gdb @dots{}
9237 @end smallexample
9238 or in the @code{csh} shell,
9239 @smallexample
9240 setenv EDITOR /usr/bin/vi
9241 gdb @dots{}
9242 @end smallexample
9243
9244 @node Search
9245 @section Searching Source Files
9246 @cindex searching source files
9247
9248 There are two commands for searching through the current source file for a
9249 regular expression.
9250
9251 @table @code
9252 @kindex search
9253 @kindex forward-search
9254 @kindex fo @r{(@code{forward-search})}
9255 @item forward-search @var{regexp}
9256 @itemx search @var{regexp}
9257 The command @samp{forward-search @var{regexp}} checks each line,
9258 starting with the one following the last line listed, for a match for
9259 @var{regexp}. It lists the line that is found. You can use the
9260 synonym @samp{search @var{regexp}} or abbreviate the command name as
9261 @code{fo}.
9262
9263 @kindex reverse-search
9264 @item reverse-search @var{regexp}
9265 The command @samp{reverse-search @var{regexp}} checks each line, starting
9266 with the one before the last line listed and going backward, for a match
9267 for @var{regexp}. It lists the line that is found. You can abbreviate
9268 this command as @code{rev}.
9269 @end table
9270
9271 @node Source Path
9272 @section Specifying Source Directories
9273
9274 @cindex source path
9275 @cindex directories for source files
9276 Executable programs sometimes do not record the directories of the source
9277 files from which they were compiled, just the names. Even when they do,
9278 the directories could be moved between the compilation and your debugging
9279 session. @value{GDBN} has a list of directories to search for source files;
9280 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9281 it tries all the directories in the list, in the order they are present
9282 in the list, until it finds a file with the desired name.
9283
9284 For example, suppose an executable references the file
9285 @file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9286 directory, and the @dfn{source path} is @file{/mnt/cross}.
9287 @value{GDBN} would look for the source file in the following
9288 locations:
9289
9290 @enumerate
9291
9292 @item @file{/usr/src/foo-1.0/lib/foo.c}
9293 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9294 @item @file{/mnt/cross/foo.c}
9295
9296 @end enumerate
9297
9298 If the source file is not present at any of the above locations then
9299 an error is printed. @value{GDBN} does not look up the parts of the
9300 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9301 Likewise, the subdirectories of the source path are not searched: if
9302 the source path is @file{/mnt/cross}, and the binary refers to
9303 @file{foo.c}, @value{GDBN} would not find it under
9304 @file{/mnt/cross/usr/src/foo-1.0/lib}.
9305
9306 Plain file names, relative file names with leading directories, file
9307 names containing dots, etc.@: are all treated as described above,
9308 except that non-absolute file names are not looked up literally. If
9309 the @dfn{source path} is @file{/mnt/cross}, the source file is
9310 recorded as @file{../lib/foo.c}, and no compilation directory is
9311 recorded, then @value{GDBN} will search in the following locations:
9312
9313 @enumerate
9314
9315 @item @file{/mnt/cross/../lib/foo.c}
9316 @item @file{/mnt/cross/foo.c}
9317
9318 @end enumerate
9319
9320 @kindex cdir
9321 @kindex cwd
9322 @vindex $cdir@r{, convenience variable}
9323 @vindex $cwd@r{, convenience variable}
9324 @cindex compilation directory
9325 @cindex current directory
9326 @cindex working directory
9327 @cindex directory, current
9328 @cindex directory, compilation
9329 The @dfn{source path} will always include two special entries
9330 @samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9331 (if one is recorded) and the current working directory respectively.
9332
9333 @samp{$cdir} causes @value{GDBN} to search within the compilation
9334 directory, if one is recorded in the debug information. If no
9335 compilation directory is recorded in the debug information then
9336 @samp{$cdir} is ignored.
9337
9338 @samp{$cwd} is not the same as @samp{.}---the former tracks the
9339 current working directory as it changes during your @value{GDBN}
9340 session, while the latter is immediately expanded to the current
9341 directory at the time you add an entry to the source path.
9342
9343 If a compilation directory is recorded in the debug information, and
9344 @value{GDBN} has not found the source file after the first search
9345 using @dfn{source path}, then @value{GDBN} will combine the
9346 compilation directory and the filename, and then search for the source
9347 file again using the @dfn{source path}.
9348
9349 For example, if the executable records the source file as
9350 @file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9351 recorded as @file{/project/build}, and the @dfn{source path} is
9352 @file{/mnt/cross:$cdir:$cwd} while the current working directory of
9353 the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
9354 search for the source file in the following locations:
9355
9356 @enumerate
9357
9358 @item @file{/usr/src/foo-1.0/lib/foo.c}
9359 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9360 @item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9361 @item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9362 @item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9363 @item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9364 @item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9365 @item @file{/mnt/cross/foo.c}
9366 @item @file{/project/build/foo.c}
9367 @item @file{/home/user/foo.c}
9368
9369 @end enumerate
9370
9371 If the file name in the previous example had been recorded in the
9372 executable as a relative path rather than an absolute path, then the
9373 first look up would not have occurred, but all of the remaining steps
9374 would be similar.
9375
9376 When searching for source files on MS-DOS and MS-Windows, where
9377 absolute paths start with a drive letter (e.g.
9378 @file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9379 from the file name before appending it to a search directory from
9380 @dfn{source path}; for instance if the executable references the
9381 source file @file{C:/project/foo.c} and @dfn{source path} is set to
9382 @file{D:/mnt/cross}, then @value{GDBN} will search in the following
9383 locations for the source file:
9384
9385 @enumerate
9386
9387 @item @file{C:/project/foo.c}
9388 @item @file{D:/mnt/cross/project/foo.c}
9389 @item @file{D:/mnt/cross/foo.c}
9390
9391 @end enumerate
9392
9393 Note that the executable search path is @emph{not} used to locate the
9394 source files.
9395
9396 Whenever you reset or rearrange the source path, @value{GDBN} clears out
9397 any information it has cached about where source files are found and where
9398 each line is in the file.
9399
9400 @kindex directory
9401 @kindex dir
9402 When you start @value{GDBN}, its source path includes only @samp{$cdir}
9403 and @samp{$cwd}, in that order.
9404 To add other directories, use the @code{directory} command.
9405
9406 The search path is used to find both program source files and @value{GDBN}
9407 script files (read using the @samp{-command} option and @samp{source} command).
9408
9409 In addition to the source path, @value{GDBN} provides a set of commands
9410 that manage a list of source path substitution rules. A @dfn{substitution
9411 rule} specifies how to rewrite source directories stored in the program's
9412 debug information in case the sources were moved to a different
9413 directory between compilation and debugging. A rule is made of
9414 two strings, the first specifying what needs to be rewritten in
9415 the path, and the second specifying how it should be rewritten.
9416 In @ref{set substitute-path}, we name these two parts @var{from} and
9417 @var{to} respectively. @value{GDBN} does a simple string replacement
9418 of @var{from} with @var{to} at the start of the directory part of the
9419 source file name, and uses that result instead of the original file
9420 name to look up the sources.
9421
9422 Using the previous example, suppose the @file{foo-1.0} tree has been
9423 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
9424 @value{GDBN} to replace @file{/usr/src} in all source path names with
9425 @file{/mnt/cross}. The first lookup will then be
9426 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9427 of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9428 substitution rule, use the @code{set substitute-path} command
9429 (@pxref{set substitute-path}).
9430
9431 To avoid unexpected substitution results, a rule is applied only if the
9432 @var{from} part of the directory name ends at a directory separator.
9433 For instance, a rule substituting @file{/usr/source} into
9434 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9435 not to @file{/usr/sourceware/foo-2.0}. And because the substitution
9436 is applied only at the beginning of the directory name, this rule will
9437 not be applied to @file{/root/usr/source/baz.c} either.
9438
9439 In many cases, you can achieve the same result using the @code{directory}
9440 command. However, @code{set substitute-path} can be more efficient in
9441 the case where the sources are organized in a complex tree with multiple
9442 subdirectories. With the @code{directory} command, you need to add each
9443 subdirectory of your project. If you moved the entire tree while
9444 preserving its internal organization, then @code{set substitute-path}
9445 allows you to direct the debugger to all the sources with one single
9446 command.
9447
9448 @code{set substitute-path} is also more than just a shortcut command.
9449 The source path is only used if the file at the original location no
9450 longer exists. On the other hand, @code{set substitute-path} modifies
9451 the debugger behavior to look at the rewritten location instead. So, if
9452 for any reason a source file that is not relevant to your executable is
9453 located at the original location, a substitution rule is the only
9454 method available to point @value{GDBN} at the new location.
9455
9456 @cindex @samp{--with-relocated-sources}
9457 @cindex default source path substitution
9458 You can configure a default source path substitution rule by
9459 configuring @value{GDBN} with the
9460 @samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9461 should be the name of a directory under @value{GDBN}'s configured
9462 prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9463 directory names in debug information under @var{dir} will be adjusted
9464 automatically if the installed @value{GDBN} is moved to a new
9465 location. This is useful if @value{GDBN}, libraries or executables
9466 with debug information and corresponding source code are being moved
9467 together.
9468
9469 @table @code
9470 @item directory @var{dirname} @dots{}
9471 @item dir @var{dirname} @dots{}
9472 Add directory @var{dirname} to the front of the source path. Several
9473 directory names may be given to this command, separated by @samp{:}
9474 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9475 part of absolute file names) or
9476 whitespace. You may specify a directory that is already in the source
9477 path; this moves it forward, so @value{GDBN} searches it sooner.
9478
9479 The special strings @samp{$cdir} (to refer to the compilation
9480 directory, if one is recorded), and @samp{$cwd} (to refer to the
9481 current working directory) can also be included in the list of
9482 directories @var{dirname}. Though these will already be in the source
9483 path they will be moved forward in the list so @value{GDBN} searches
9484 them sooner.
9485
9486 @item directory
9487 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
9488
9489 @c RET-repeat for @code{directory} is explicitly disabled, but since
9490 @c repeating it would be a no-op we do not say that. (thanks to RMS)
9491
9492 @item set directories @var{path-list}
9493 @kindex set directories
9494 Set the source path to @var{path-list}.
9495 @samp{$cdir:$cwd} are added if missing.
9496
9497 @item show directories
9498 @kindex show directories
9499 Print the source path: show which directories it contains.
9500
9501 @anchor{set substitute-path}
9502 @item set substitute-path @var{from} @var{to}
9503 @kindex set substitute-path
9504 Define a source path substitution rule, and add it at the end of the
9505 current list of existing substitution rules. If a rule with the same
9506 @var{from} was already defined, then the old rule is also deleted.
9507
9508 For example, if the file @file{/foo/bar/baz.c} was moved to
9509 @file{/mnt/cross/baz.c}, then the command
9510
9511 @smallexample
9512 (@value{GDBP}) set substitute-path /foo/bar /mnt/cross
9513 @end smallexample
9514
9515 @noindent
9516 will tell @value{GDBN} to replace @samp{/foo/bar} with
9517 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9518 @file{baz.c} even though it was moved.
9519
9520 In the case when more than one substitution rule have been defined,
9521 the rules are evaluated one by one in the order where they have been
9522 defined. The first one matching, if any, is selected to perform
9523 the substitution.
9524
9525 For instance, if we had entered the following commands:
9526
9527 @smallexample
9528 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9529 (@value{GDBP}) set substitute-path /usr/src /mnt/src
9530 @end smallexample
9531
9532 @noindent
9533 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9534 @file{/mnt/include/defs.h} by using the first rule. However, it would
9535 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9536 @file{/mnt/src/lib/foo.c}.
9537
9538
9539 @item unset substitute-path [path]
9540 @kindex unset substitute-path
9541 If a path is specified, search the current list of substitution rules
9542 for a rule that would rewrite that path. Delete that rule if found.
9543 A warning is emitted by the debugger if no rule could be found.
9544
9545 If no path is specified, then all substitution rules are deleted.
9546
9547 @item show substitute-path [path]
9548 @kindex show substitute-path
9549 If a path is specified, then print the source path substitution rule
9550 which would rewrite that path, if any.
9551
9552 If no path is specified, then print all existing source path substitution
9553 rules.
9554
9555 @end table
9556
9557 If your source path is cluttered with directories that are no longer of
9558 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9559 versions of source. You can correct the situation as follows:
9560
9561 @enumerate
9562 @item
9563 Use @code{directory} with no argument to reset the source path to its default value.
9564
9565 @item
9566 Use @code{directory} with suitable arguments to reinstall the
9567 directories you want in the source path. You can add all the
9568 directories in one command.
9569 @end enumerate
9570
9571 @node Machine Code
9572 @section Source and Machine Code
9573 @cindex source line and its code address
9574
9575 You can use the command @code{info line} to map source lines to program
9576 addresses (and vice versa), and the command @code{disassemble} to display
9577 a range of addresses as machine instructions. You can use the command
9578 @code{set disassemble-next-line} to set whether to disassemble next
9579 source line when execution stops. When run under @sc{gnu} Emacs
9580 mode, the @code{info line} command causes the arrow to point to the
9581 line specified. Also, @code{info line} prints addresses in symbolic form as
9582 well as hex.
9583
9584 @table @code
9585 @kindex info line
9586 @item info line
9587 @itemx info line @var{location}
9588 Print the starting and ending addresses of the compiled code for
9589 source line @var{location}. You can specify source lines in any of
9590 the ways documented in @ref{Specify Location}. With no @var{location}
9591 information about the current source line is printed.
9592 @end table
9593
9594 For example, we can use @code{info line} to discover the location of
9595 the object code for the first line of function
9596 @code{m4_changequote}:
9597
9598 @smallexample
9599 (@value{GDBP}) info line m4_changequote
9600 Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9601 ends at 0x6350 <m4_changequote+4>.
9602 @end smallexample
9603
9604 @noindent
9605 @cindex code address and its source line
9606 We can also inquire (using @code{*@var{addr}} as the form for
9607 @var{location}) what source line covers a particular address:
9608 @smallexample
9609 (@value{GDBP}) info line *0x63ff
9610 Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9611 ends at 0x6404 <m4_changequote+184>.
9612 @end smallexample
9613
9614 @cindex @code{$_} and @code{info line}
9615 @cindex @code{x} command, default address
9616 @kindex x@r{(examine), and} info line
9617 After @code{info line}, the default address for the @code{x} command
9618 is changed to the starting address of the line, so that @samp{x/i} is
9619 sufficient to begin examining the machine code (@pxref{Memory,
9620 ,Examining Memory}). Also, this address is saved as the value of the
9621 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
9622 Variables}).
9623
9624 @cindex info line, repeated calls
9625 After @code{info line}, using @code{info line} again without
9626 specifying a location will display information about the next source
9627 line.
9628
9629 @table @code
9630 @kindex disassemble
9631 @cindex assembly instructions
9632 @cindex instructions, assembly
9633 @cindex machine instructions
9634 @cindex listing machine instructions
9635 @item disassemble
9636 @itemx disassemble /m
9637 @itemx disassemble /s
9638 @itemx disassemble /r
9639 This specialized command dumps a range of memory as machine
9640 instructions. It can also print mixed source+disassembly by specifying
9641 the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9642 as well as in symbolic form by specifying the @code{/r} modifier.
9643 The default memory range is the function surrounding the
9644 program counter of the selected frame. A single argument to this
9645 command is a program counter value; @value{GDBN} dumps the function
9646 surrounding this value. When two arguments are given, they should
9647 be separated by a comma, possibly surrounded by whitespace. The
9648 arguments specify a range of addresses to dump, in one of two forms:
9649
9650 @table @code
9651 @item @var{start},@var{end}
9652 the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9653 @item @var{start},+@var{length}
9654 the addresses from @var{start} (inclusive) to
9655 @code{@var{start}+@var{length}} (exclusive).
9656 @end table
9657
9658 @noindent
9659 When 2 arguments are specified, the name of the function is also
9660 printed (since there could be several functions in the given range).
9661
9662 The argument(s) can be any expression yielding a numeric value, such as
9663 @samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
9664
9665 If the range of memory being disassembled contains current program counter,
9666 the instruction at that location is shown with a @code{=>} marker.
9667 @end table
9668
9669 The following example shows the disassembly of a range of addresses of
9670 HP PA-RISC 2.0 code:
9671
9672 @smallexample
9673 (@value{GDBP}) disas 0x32c4, 0x32e4
9674 Dump of assembler code from 0x32c4 to 0x32e4:
9675 0x32c4 <main+204>: addil 0,dp
9676 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9677 0x32cc <main+212>: ldil 0x3000,r31
9678 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9679 0x32d4 <main+220>: ldo 0(r31),rp
9680 0x32d8 <main+224>: addil -0x800,dp
9681 0x32dc <main+228>: ldo 0x588(r1),r26
9682 0x32e0 <main+232>: ldil 0x3000,r31
9683 End of assembler dump.
9684 @end smallexample
9685
9686 Here is an example showing mixed source+assembly for Intel x86
9687 with @code{/m} or @code{/s}, when the program is stopped just after
9688 function prologue in a non-optimized function with no inline code.
9689
9690 @smallexample
9691 (@value{GDBP}) disas /m main
9692 Dump of assembler code for function main:
9693 5 @{
9694 0x08048330 <+0>: push %ebp
9695 0x08048331 <+1>: mov %esp,%ebp
9696 0x08048333 <+3>: sub $0x8,%esp
9697 0x08048336 <+6>: and $0xfffffff0,%esp
9698 0x08048339 <+9>: sub $0x10,%esp
9699
9700 6 printf ("Hello.\n");
9701 => 0x0804833c <+12>: movl $0x8048440,(%esp)
9702 0x08048343 <+19>: call 0x8048284 <puts@@plt>
9703
9704 7 return 0;
9705 8 @}
9706 0x08048348 <+24>: mov $0x0,%eax
9707 0x0804834d <+29>: leave
9708 0x0804834e <+30>: ret
9709
9710 End of assembler dump.
9711 @end smallexample
9712
9713 The @code{/m} option is deprecated as its output is not useful when
9714 there is either inlined code or re-ordered code.
9715 The @code{/s} option is the preferred choice.
9716 Here is an example for AMD x86-64 showing the difference between
9717 @code{/m} output and @code{/s} output.
9718 This example has one inline function defined in a header file,
9719 and the code is compiled with @samp{-O2} optimization.
9720 Note how the @code{/m} output is missing the disassembly of
9721 several instructions that are present in the @code{/s} output.
9722
9723 @file{foo.h}:
9724
9725 @smallexample
9726 int
9727 foo (int a)
9728 @{
9729 if (a < 0)
9730 return a * 2;
9731 if (a == 0)
9732 return 1;
9733 return a + 10;
9734 @}
9735 @end smallexample
9736
9737 @file{foo.c}:
9738
9739 @smallexample
9740 #include "foo.h"
9741 volatile int x, y;
9742 int
9743 main ()
9744 @{
9745 x = foo (y);
9746 return 0;
9747 @}
9748 @end smallexample
9749
9750 @smallexample
9751 (@value{GDBP}) disas /m main
9752 Dump of assembler code for function main:
9753 5 @{
9754
9755 6 x = foo (y);
9756 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9757 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9758
9759 7 return 0;
9760 8 @}
9761 0x000000000040041d <+29>: xor %eax,%eax
9762 0x000000000040041f <+31>: retq
9763 0x0000000000400420 <+32>: add %eax,%eax
9764 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9765
9766 End of assembler dump.
9767 (@value{GDBP}) disas /s main
9768 Dump of assembler code for function main:
9769 foo.c:
9770 5 @{
9771 6 x = foo (y);
9772 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9773
9774 foo.h:
9775 4 if (a < 0)
9776 0x0000000000400406 <+6>: test %eax,%eax
9777 0x0000000000400408 <+8>: js 0x400420 <main+32>
9778
9779 6 if (a == 0)
9780 7 return 1;
9781 8 return a + 10;
9782 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9783 0x000000000040040d <+13>: test %eax,%eax
9784 0x000000000040040f <+15>: mov $0x1,%eax
9785 0x0000000000400414 <+20>: cmovne %edx,%eax
9786
9787 foo.c:
9788 6 x = foo (y);
9789 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9790
9791 7 return 0;
9792 8 @}
9793 0x000000000040041d <+29>: xor %eax,%eax
9794 0x000000000040041f <+31>: retq
9795
9796 foo.h:
9797 5 return a * 2;
9798 0x0000000000400420 <+32>: add %eax,%eax
9799 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9800 End of assembler dump.
9801 @end smallexample
9802
9803 Here is another example showing raw instructions in hex for AMD x86-64,
9804
9805 @smallexample
9806 (gdb) disas /r 0x400281,+10
9807 Dump of assembler code from 0x400281 to 0x40028b:
9808 0x0000000000400281: 38 36 cmp %dh,(%rsi)
9809 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
9810 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
9811 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
9812 End of assembler dump.
9813 @end smallexample
9814
9815 Addresses cannot be specified as a location (@pxref{Specify Location}).
9816 So, for example, if you want to disassemble function @code{bar}
9817 in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9818 and not @samp{disassemble foo.c:bar}.
9819
9820 Some architectures have more than one commonly-used set of instruction
9821 mnemonics or other syntax.
9822
9823 For programs that were dynamically linked and use shared libraries,
9824 instructions that call functions or branch to locations in the shared
9825 libraries might show a seemingly bogus location---it's actually a
9826 location of the relocation table. On some architectures, @value{GDBN}
9827 might be able to resolve these to actual function names.
9828
9829 @table @code
9830 @kindex set disassembler-options
9831 @cindex disassembler options
9832 @item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9833 This command controls the passing of target specific information to
9834 the disassembler. For a list of valid options, please refer to the
9835 @code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9836 manual and/or the output of @kbd{objdump --help}
9837 (@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
9838 The default value is the empty string.
9839
9840 If it is necessary to specify more than one disassembler option, then
9841 multiple options can be placed together into a comma separated list.
9842 Currently this command is only supported on targets ARM, MIPS, PowerPC
9843 and S/390.
9844
9845 @kindex show disassembler-options
9846 @item show disassembler-options
9847 Show the current setting of the disassembler options.
9848 @end table
9849
9850 @table @code
9851 @kindex set disassembly-flavor
9852 @cindex Intel disassembly flavor
9853 @cindex AT&T disassembly flavor
9854 @item set disassembly-flavor @var{instruction-set}
9855 Select the instruction set to use when disassembling the
9856 program via the @code{disassemble} or @code{x/i} commands.
9857
9858 Currently this command is only defined for the Intel x86 family. You
9859 can set @var{instruction-set} to either @code{intel} or @code{att}.
9860 The default is @code{att}, the AT&T flavor used by default by Unix
9861 assemblers for x86-based targets.
9862
9863 @kindex show disassembly-flavor
9864 @item show disassembly-flavor
9865 Show the current setting of the disassembly flavor.
9866 @end table
9867
9868 @table @code
9869 @kindex set disassemble-next-line
9870 @kindex show disassemble-next-line
9871 @item set disassemble-next-line
9872 @itemx show disassemble-next-line
9873 Control whether or not @value{GDBN} will disassemble the next source
9874 line or instruction when execution stops. If ON, @value{GDBN} will
9875 display disassembly of the next source line when execution of the
9876 program being debugged stops. This is @emph{in addition} to
9877 displaying the source line itself, which @value{GDBN} always does if
9878 possible. If the next source line cannot be displayed for some reason
9879 (e.g., if @value{GDBN} cannot find the source file, or there's no line
9880 info in the debug info), @value{GDBN} will display disassembly of the
9881 next @emph{instruction} instead of showing the next source line. If
9882 AUTO, @value{GDBN} will display disassembly of next instruction only
9883 if the source line cannot be displayed. This setting causes
9884 @value{GDBN} to display some feedback when you step through a function
9885 with no line info or whose source file is unavailable. The default is
9886 OFF, which means never display the disassembly of the next line or
9887 instruction.
9888 @end table
9889
9890
9891 @node Data
9892 @chapter Examining Data
9893
9894 @cindex printing data
9895 @cindex examining data
9896 @kindex print
9897 @kindex inspect
9898 The usual way to examine data in your program is with the @code{print}
9899 command (abbreviated @code{p}), or its synonym @code{inspect}. It
9900 evaluates and prints the value of an expression of the language your
9901 program is written in (@pxref{Languages, ,Using @value{GDBN} with
9902 Different Languages}). It may also print the expression using a
9903 Python-based pretty-printer (@pxref{Pretty Printing}).
9904
9905 @table @code
9906 @item print [[@var{options}] --] @var{expr}
9907 @itemx print [[@var{options}] --] /@var{f} @var{expr}
9908 @var{expr} is an expression (in the source language). By default the
9909 value of @var{expr} is printed in a format appropriate to its data type;
9910 you can choose a different format by specifying @samp{/@var{f}}, where
9911 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
9912 Formats}.
9913
9914 @anchor{print options}
9915 The @code{print} command supports a number of options that allow
9916 overriding relevant global print settings as set by @code{set print}
9917 subcommands:
9918
9919 @table @code
9920 @item -address [@code{on}|@code{off}]
9921 Set printing of addresses.
9922 Related setting: @ref{set print address}.
9923
9924 @item -array [@code{on}|@code{off}]
9925 Pretty formatting of arrays.
9926 Related setting: @ref{set print array}.
9927
9928 @item -array-indexes [@code{on}|@code{off}]
9929 Set printing of array indexes.
9930 Related setting: @ref{set print array-indexes}.
9931
9932 @item -elements @var{number-of-elements}|@code{unlimited}
9933 Set limit on string chars or array elements to print. The value
9934 @code{unlimited} causes there to be no limit. Related setting:
9935 @ref{set print elements}.
9936
9937 @item -max-depth @var{depth}|@code{unlimited}
9938 Set the threshold after which nested structures are replaced with
9939 ellipsis. Related setting: @ref{set print max-depth}.
9940
9941 @item -null-stop [@code{on}|@code{off}]
9942 Set printing of char arrays to stop at first null char. Related
9943 setting: @ref{set print null-stop}.
9944
9945 @item -object [@code{on}|@code{off}]
9946 Set printing C@t{++} virtual function tables. Related setting:
9947 @ref{set print object}.
9948
9949 @item -pretty [@code{on}|@code{off}]
9950 Set pretty formatting of structures. Related setting: @ref{set print
9951 pretty}.
9952
9953 @item -raw-values [@code{on}|@code{off}]
9954 Set whether to print values in raw form, bypassing any
9955 pretty-printers for that value. Related setting: @ref{set print
9956 raw-values}.
9957
9958 @item -repeats @var{number-of-repeats}|@code{unlimited}
9959 Set threshold for repeated print elements. @code{unlimited} causes
9960 all elements to be individually printed. Related setting: @ref{set
9961 print repeats}.
9962
9963 @item -static-members [@code{on}|@code{off}]
9964 Set printing C@t{++} static members. Related setting: @ref{set print
9965 static-members}.
9966
9967 @item -symbol [@code{on}|@code{off}]
9968 Set printing of symbol names when printing pointers. Related setting:
9969 @ref{set print symbol}.
9970
9971 @item -union [@code{on}|@code{off}]
9972 Set printing of unions interior to structures. Related setting:
9973 @ref{set print union}.
9974
9975 @item -vtbl [@code{on}|@code{off}]
9976 Set printing of C++ virtual function tables. Related setting:
9977 @ref{set print vtbl}.
9978 @end table
9979
9980 Because the @code{print} command accepts arbitrary expressions which
9981 may look like options (including abbreviations), if you specify any
9982 command option, then you must use a double dash (@code{--}) to mark
9983 the end of option processing.
9984
9985 For example, this prints the value of the @code{-p} expression:
9986
9987 @smallexample
9988 (@value{GDBP}) print -p
9989 @end smallexample
9990
9991 While this repeats the last value in the value history (see below)
9992 with the @code{-pretty} option in effect:
9993
9994 @smallexample
9995 (@value{GDBP}) print -p --
9996 @end smallexample
9997
9998 Here is an example including both on option and an expression:
9999
10000 @smallexample
10001 @group
10002 (@value{GDBP}) print -pretty -- *myptr
10003 $1 = @{
10004 next = 0x0,
10005 flags = @{
10006 sweet = 1,
10007 sour = 1
10008 @},
10009 meat = 0x54 "Pork"
10010 @}
10011 @end group
10012 @end smallexample
10013
10014 @item print [@var{options}]
10015 @itemx print [@var{options}] /@var{f}
10016 @cindex reprint the last value
10017 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
10018 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
10019 conveniently inspect the same value in an alternative format.
10020 @end table
10021
10022 A more low-level way of examining data is with the @code{x} command.
10023 It examines data in memory at a specified address and prints it in a
10024 specified format. @xref{Memory, ,Examining Memory}.
10025
10026 If you are interested in information about types, or about how the
10027 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
10028 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
10029 Table}.
10030
10031 @cindex exploring hierarchical data structures
10032 @kindex explore
10033 Another way of examining values of expressions and type information is
10034 through the Python extension command @code{explore} (available only if
10035 the @value{GDBN} build is configured with @code{--with-python}). It
10036 offers an interactive way to start at the highest level (or, the most
10037 abstract level) of the data type of an expression (or, the data type
10038 itself) and explore all the way down to leaf scalar values/fields
10039 embedded in the higher level data types.
10040
10041 @table @code
10042 @item explore @var{arg}
10043 @var{arg} is either an expression (in the source language), or a type
10044 visible in the current context of the program being debugged.
10045 @end table
10046
10047 The working of the @code{explore} command can be illustrated with an
10048 example. If a data type @code{struct ComplexStruct} is defined in your
10049 C program as
10050
10051 @smallexample
10052 struct SimpleStruct
10053 @{
10054 int i;
10055 double d;
10056 @};
10057
10058 struct ComplexStruct
10059 @{
10060 struct SimpleStruct *ss_p;
10061 int arr[10];
10062 @};
10063 @end smallexample
10064
10065 @noindent
10066 followed by variable declarations as
10067
10068 @smallexample
10069 struct SimpleStruct ss = @{ 10, 1.11 @};
10070 struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
10071 @end smallexample
10072
10073 @noindent
10074 then, the value of the variable @code{cs} can be explored using the
10075 @code{explore} command as follows.
10076
10077 @smallexample
10078 (gdb) explore cs
10079 The value of `cs' is a struct/class of type `struct ComplexStruct' with
10080 the following fields:
10081
10082 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
10083 arr = <Enter 1 to explore this field of type `int [10]'>
10084
10085 Enter the field number of choice:
10086 @end smallexample
10087
10088 @noindent
10089 Since the fields of @code{cs} are not scalar values, you are being
10090 prompted to chose the field you want to explore. Let's say you choose
10091 the field @code{ss_p} by entering @code{0}. Then, since this field is a
10092 pointer, you will be asked if it is pointing to a single value. From
10093 the declaration of @code{cs} above, it is indeed pointing to a single
10094 value, hence you enter @code{y}. If you enter @code{n}, then you will
10095 be asked if it were pointing to an array of values, in which case this
10096 field will be explored as if it were an array.
10097
10098 @smallexample
10099 `cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
10100 Continue exploring it as a pointer to a single value [y/n]: y
10101 The value of `*(cs.ss_p)' is a struct/class of type `struct
10102 SimpleStruct' with the following fields:
10103
10104 i = 10 .. (Value of type `int')
10105 d = 1.1100000000000001 .. (Value of type `double')
10106
10107 Press enter to return to parent value:
10108 @end smallexample
10109
10110 @noindent
10111 If the field @code{arr} of @code{cs} was chosen for exploration by
10112 entering @code{1} earlier, then since it is as array, you will be
10113 prompted to enter the index of the element in the array that you want
10114 to explore.
10115
10116 @smallexample
10117 `cs.arr' is an array of `int'.
10118 Enter the index of the element you want to explore in `cs.arr': 5
10119
10120 `(cs.arr)[5]' is a scalar value of type `int'.
10121
10122 (cs.arr)[5] = 4
10123
10124 Press enter to return to parent value:
10125 @end smallexample
10126
10127 In general, at any stage of exploration, you can go deeper towards the
10128 leaf values by responding to the prompts appropriately, or hit the
10129 return key to return to the enclosing data structure (the @i{higher}
10130 level data structure).
10131
10132 Similar to exploring values, you can use the @code{explore} command to
10133 explore types. Instead of specifying a value (which is typically a
10134 variable name or an expression valid in the current context of the
10135 program being debugged), you specify a type name. If you consider the
10136 same example as above, your can explore the type
10137 @code{struct ComplexStruct} by passing the argument
10138 @code{struct ComplexStruct} to the @code{explore} command.
10139
10140 @smallexample
10141 (gdb) explore struct ComplexStruct
10142 @end smallexample
10143
10144 @noindent
10145 By responding to the prompts appropriately in the subsequent interactive
10146 session, you can explore the type @code{struct ComplexStruct} in a
10147 manner similar to how the value @code{cs} was explored in the above
10148 example.
10149
10150 The @code{explore} command also has two sub-commands,
10151 @code{explore value} and @code{explore type}. The former sub-command is
10152 a way to explicitly specify that value exploration of the argument is
10153 being invoked, while the latter is a way to explicitly specify that type
10154 exploration of the argument is being invoked.
10155
10156 @table @code
10157 @item explore value @var{expr}
10158 @cindex explore value
10159 This sub-command of @code{explore} explores the value of the
10160 expression @var{expr} (if @var{expr} is an expression valid in the
10161 current context of the program being debugged). The behavior of this
10162 command is identical to that of the behavior of the @code{explore}
10163 command being passed the argument @var{expr}.
10164
10165 @item explore type @var{arg}
10166 @cindex explore type
10167 This sub-command of @code{explore} explores the type of @var{arg} (if
10168 @var{arg} is a type visible in the current context of program being
10169 debugged), or the type of the value/expression @var{arg} (if @var{arg}
10170 is an expression valid in the current context of the program being
10171 debugged). If @var{arg} is a type, then the behavior of this command is
10172 identical to that of the @code{explore} command being passed the
10173 argument @var{arg}. If @var{arg} is an expression, then the behavior of
10174 this command will be identical to that of the @code{explore} command
10175 being passed the type of @var{arg} as the argument.
10176 @end table
10177
10178 @menu
10179 * Expressions:: Expressions
10180 * Ambiguous Expressions:: Ambiguous Expressions
10181 * Variables:: Program variables
10182 * Arrays:: Artificial arrays
10183 * Output Formats:: Output formats
10184 * Memory:: Examining memory
10185 * Auto Display:: Automatic display
10186 * Print Settings:: Print settings
10187 * Pretty Printing:: Python pretty printing
10188 * Value History:: Value history
10189 * Convenience Vars:: Convenience variables
10190 * Convenience Funs:: Convenience functions
10191 * Registers:: Registers
10192 * Floating Point Hardware:: Floating point hardware
10193 * Vector Unit:: Vector Unit
10194 * OS Information:: Auxiliary data provided by operating system
10195 * Memory Region Attributes:: Memory region attributes
10196 * Dump/Restore Files:: Copy between memory and a file
10197 * Core File Generation:: Cause a program dump its core
10198 * Character Sets:: Debugging programs that use a different
10199 character set than GDB does
10200 * Caching Target Data:: Data caching for targets
10201 * Searching Memory:: Searching memory for a sequence of bytes
10202 * Value Sizes:: Managing memory allocated for values
10203 @end menu
10204
10205 @node Expressions
10206 @section Expressions
10207
10208 @cindex expressions
10209 @code{print} and many other @value{GDBN} commands accept an expression and
10210 compute its value. Any kind of constant, variable or operator defined
10211 by the programming language you are using is valid in an expression in
10212 @value{GDBN}. This includes conditional expressions, function calls,
10213 casts, and string constants. It also includes preprocessor macros, if
10214 you compiled your program to include this information; see
10215 @ref{Compilation}.
10216
10217 @cindex arrays in expressions
10218 @value{GDBN} supports array constants in expressions input by
10219 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
10220 you can use the command @code{print @{1, 2, 3@}} to create an array
10221 of three integers. If you pass an array to a function or assign it
10222 to a program variable, @value{GDBN} copies the array to memory that
10223 is @code{malloc}ed in the target program.
10224
10225 Because C is so widespread, most of the expressions shown in examples in
10226 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
10227 Languages}, for information on how to use expressions in other
10228 languages.
10229
10230 In this section, we discuss operators that you can use in @value{GDBN}
10231 expressions regardless of your programming language.
10232
10233 @cindex casts, in expressions
10234 Casts are supported in all languages, not just in C, because it is so
10235 useful to cast a number into a pointer in order to examine a structure
10236 at that address in memory.
10237 @c FIXME: casts supported---Mod2 true?
10238
10239 @value{GDBN} supports these operators, in addition to those common
10240 to programming languages:
10241
10242 @table @code
10243 @item @@
10244 @samp{@@} is a binary operator for treating parts of memory as arrays.
10245 @xref{Arrays, ,Artificial Arrays}, for more information.
10246
10247 @item ::
10248 @samp{::} allows you to specify a variable in terms of the file or
10249 function where it is defined. @xref{Variables, ,Program Variables}.
10250
10251 @cindex @{@var{type}@}
10252 @cindex type casting memory
10253 @cindex memory, viewing as typed object
10254 @cindex casts, to view memory
10255 @item @{@var{type}@} @var{addr}
10256 Refers to an object of type @var{type} stored at address @var{addr} in
10257 memory. The address @var{addr} may be any expression whose value is
10258 an integer or pointer (but parentheses are required around binary
10259 operators, just as in a cast). This construct is allowed regardless
10260 of what kind of data is normally supposed to reside at @var{addr}.
10261 @end table
10262
10263 @node Ambiguous Expressions
10264 @section Ambiguous Expressions
10265 @cindex ambiguous expressions
10266
10267 Expressions can sometimes contain some ambiguous elements. For instance,
10268 some programming languages (notably Ada, C@t{++} and Objective-C) permit
10269 a single function name to be defined several times, for application in
10270 different contexts. This is called @dfn{overloading}. Another example
10271 involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10272 templates and is typically instantiated several times, resulting in
10273 the same function name being defined in different contexts.
10274
10275 In some cases and depending on the language, it is possible to adjust
10276 the expression to remove the ambiguity. For instance in C@t{++}, you
10277 can specify the signature of the function you want to break on, as in
10278 @kbd{break @var{function}(@var{types})}. In Ada, using the fully
10279 qualified name of your function often makes the expression unambiguous
10280 as well.
10281
10282 When an ambiguity that needs to be resolved is detected, the debugger
10283 has the capability to display a menu of numbered choices for each
10284 possibility, and then waits for the selection with the prompt @samp{>}.
10285 The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10286 aborts the current command. If the command in which the expression was
10287 used allows more than one choice to be selected, the next option in the
10288 menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10289 choices.
10290
10291 For example, the following session excerpt shows an attempt to set a
10292 breakpoint at the overloaded symbol @code{String::after}.
10293 We choose three particular definitions of that function name:
10294
10295 @c FIXME! This is likely to change to show arg type lists, at least
10296 @smallexample
10297 @group
10298 (@value{GDBP}) b String::after
10299 [0] cancel
10300 [1] all
10301 [2] file:String.cc; line number:867
10302 [3] file:String.cc; line number:860
10303 [4] file:String.cc; line number:875
10304 [5] file:String.cc; line number:853
10305 [6] file:String.cc; line number:846
10306 [7] file:String.cc; line number:735
10307 > 2 4 6
10308 Breakpoint 1 at 0xb26c: file String.cc, line 867.
10309 Breakpoint 2 at 0xb344: file String.cc, line 875.
10310 Breakpoint 3 at 0xafcc: file String.cc, line 846.
10311 Multiple breakpoints were set.
10312 Use the "delete" command to delete unwanted
10313 breakpoints.
10314 (@value{GDBP})
10315 @end group
10316 @end smallexample
10317
10318 @table @code
10319 @kindex set multiple-symbols
10320 @item set multiple-symbols @var{mode}
10321 @cindex multiple-symbols menu
10322
10323 This option allows you to adjust the debugger behavior when an expression
10324 is ambiguous.
10325
10326 By default, @var{mode} is set to @code{all}. If the command with which
10327 the expression is used allows more than one choice, then @value{GDBN}
10328 automatically selects all possible choices. For instance, inserting
10329 a breakpoint on a function using an ambiguous name results in a breakpoint
10330 inserted on each possible match. However, if a unique choice must be made,
10331 then @value{GDBN} uses the menu to help you disambiguate the expression.
10332 For instance, printing the address of an overloaded function will result
10333 in the use of the menu.
10334
10335 When @var{mode} is set to @code{ask}, the debugger always uses the menu
10336 when an ambiguity is detected.
10337
10338 Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10339 an error due to the ambiguity and the command is aborted.
10340
10341 @kindex show multiple-symbols
10342 @item show multiple-symbols
10343 Show the current value of the @code{multiple-symbols} setting.
10344 @end table
10345
10346 @node Variables
10347 @section Program Variables
10348
10349 The most common kind of expression to use is the name of a variable
10350 in your program.
10351
10352 Variables in expressions are understood in the selected stack frame
10353 (@pxref{Selection, ,Selecting a Frame}); they must be either:
10354
10355 @itemize @bullet
10356 @item
10357 global (or file-static)
10358 @end itemize
10359
10360 @noindent or
10361
10362 @itemize @bullet
10363 @item
10364 visible according to the scope rules of the
10365 programming language from the point of execution in that frame
10366 @end itemize
10367
10368 @noindent This means that in the function
10369
10370 @smallexample
10371 foo (a)
10372 int a;
10373 @{
10374 bar (a);
10375 @{
10376 int b = test ();
10377 bar (b);
10378 @}
10379 @}
10380 @end smallexample
10381
10382 @noindent
10383 you can examine and use the variable @code{a} whenever your program is
10384 executing within the function @code{foo}, but you can only use or
10385 examine the variable @code{b} while your program is executing inside
10386 the block where @code{b} is declared.
10387
10388 @cindex variable name conflict
10389 There is an exception: you can refer to a variable or function whose
10390 scope is a single source file even if the current execution point is not
10391 in this file. But it is possible to have more than one such variable or
10392 function with the same name (in different source files). If that
10393 happens, referring to that name has unpredictable effects. If you wish,
10394 you can specify a static variable in a particular function or file by
10395 using the colon-colon (@code{::}) notation:
10396
10397 @cindex colon-colon, context for variables/functions
10398 @ifnotinfo
10399 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
10400 @cindex @code{::}, context for variables/functions
10401 @end ifnotinfo
10402 @smallexample
10403 @var{file}::@var{variable}
10404 @var{function}::@var{variable}
10405 @end smallexample
10406
10407 @noindent
10408 Here @var{file} or @var{function} is the name of the context for the
10409 static @var{variable}. In the case of file names, you can use quotes to
10410 make sure @value{GDBN} parses the file name as a single word---for example,
10411 to print a global value of @code{x} defined in @file{f2.c}:
10412
10413 @smallexample
10414 (@value{GDBP}) p 'f2.c'::x
10415 @end smallexample
10416
10417 The @code{::} notation is normally used for referring to
10418 static variables, since you typically disambiguate uses of local variables
10419 in functions by selecting the appropriate frame and using the
10420 simple name of the variable. However, you may also use this notation
10421 to refer to local variables in frames enclosing the selected frame:
10422
10423 @smallexample
10424 void
10425 foo (int a)
10426 @{
10427 if (a < 10)
10428 bar (a);
10429 else
10430 process (a); /* Stop here */
10431 @}
10432
10433 int
10434 bar (int a)
10435 @{
10436 foo (a + 5);
10437 @}
10438 @end smallexample
10439
10440 @noindent
10441 For example, if there is a breakpoint at the commented line,
10442 here is what you might see
10443 when the program stops after executing the call @code{bar(0)}:
10444
10445 @smallexample
10446 (@value{GDBP}) p a
10447 $1 = 10
10448 (@value{GDBP}) p bar::a
10449 $2 = 5
10450 (@value{GDBP}) up 2
10451 #2 0x080483d0 in foo (a=5) at foobar.c:12
10452 (@value{GDBP}) p a
10453 $3 = 5
10454 (@value{GDBP}) p bar::a
10455 $4 = 0
10456 @end smallexample
10457
10458 @cindex C@t{++} scope resolution
10459 These uses of @samp{::} are very rarely in conflict with the very
10460 similar use of the same notation in C@t{++}. When they are in
10461 conflict, the C@t{++} meaning takes precedence; however, this can be
10462 overridden by quoting the file or function name with single quotes.
10463
10464 For example, suppose the program is stopped in a method of a class
10465 that has a field named @code{includefile}, and there is also an
10466 include file named @file{includefile} that defines a variable,
10467 @code{some_global}.
10468
10469 @smallexample
10470 (@value{GDBP}) p includefile
10471 $1 = 23
10472 (@value{GDBP}) p includefile::some_global
10473 A syntax error in expression, near `'.
10474 (@value{GDBP}) p 'includefile'::some_global
10475 $2 = 27
10476 @end smallexample
10477
10478 @cindex wrong values
10479 @cindex variable values, wrong
10480 @cindex function entry/exit, wrong values of variables
10481 @cindex optimized code, wrong values of variables
10482 @quotation
10483 @emph{Warning:} Occasionally, a local variable may appear to have the
10484 wrong value at certain points in a function---just after entry to a new
10485 scope, and just before exit.
10486 @end quotation
10487 You may see this problem when you are stepping by machine instructions.
10488 This is because, on most machines, it takes more than one instruction to
10489 set up a stack frame (including local variable definitions); if you are
10490 stepping by machine instructions, variables may appear to have the wrong
10491 values until the stack frame is completely built. On exit, it usually
10492 also takes more than one machine instruction to destroy a stack frame;
10493 after you begin stepping through that group of instructions, local
10494 variable definitions may be gone.
10495
10496 This may also happen when the compiler does significant optimizations.
10497 To be sure of always seeing accurate values, turn off all optimization
10498 when compiling.
10499
10500 @cindex ``No symbol "foo" in current context''
10501 Another possible effect of compiler optimizations is to optimize
10502 unused variables out of existence, or assign variables to registers (as
10503 opposed to memory addresses). Depending on the support for such cases
10504 offered by the debug info format used by the compiler, @value{GDBN}
10505 might not be able to display values for such local variables. If that
10506 happens, @value{GDBN} will print a message like this:
10507
10508 @smallexample
10509 No symbol "foo" in current context.
10510 @end smallexample
10511
10512 To solve such problems, either recompile without optimizations, or use a
10513 different debug info format, if the compiler supports several such
10514 formats. @xref{Compilation}, for more information on choosing compiler
10515 options. @xref{C, ,C and C@t{++}}, for more information about debug
10516 info formats that are best suited to C@t{++} programs.
10517
10518 If you ask to print an object whose contents are unknown to
10519 @value{GDBN}, e.g., because its data type is not completely specified
10520 by the debug information, @value{GDBN} will say @samp{<incomplete
10521 type>}. @xref{Symbols, incomplete type}, for more about this.
10522
10523 @cindex no debug info variables
10524 If you try to examine or use the value of a (global) variable for
10525 which @value{GDBN} has no type information, e.g., because the program
10526 includes no debug information, @value{GDBN} displays an error message.
10527 @xref{Symbols, unknown type}, for more about unknown types. If you
10528 cast the variable to its declared type, @value{GDBN} gets the
10529 variable's value using the cast-to type as the variable's type. For
10530 example, in a C program:
10531
10532 @smallexample
10533 (@value{GDBP}) p var
10534 'var' has unknown type; cast it to its declared type
10535 (@value{GDBP}) p (float) var
10536 $1 = 3.14
10537 @end smallexample
10538
10539 If you append @kbd{@@entry} string to a function parameter name you get its
10540 value at the time the function got called. If the value is not available an
10541 error message is printed. Entry values are available only with some compilers.
10542 Entry values are normally also printed at the function parameter list according
10543 to @ref{set print entry-values}.
10544
10545 @smallexample
10546 Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
10547 29 i++;
10548 (gdb) next
10549 30 e (i);
10550 (gdb) print i
10551 $1 = 31
10552 (gdb) print i@@entry
10553 $2 = 30
10554 @end smallexample
10555
10556 Strings are identified as arrays of @code{char} values without specified
10557 signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10558 printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10559 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10560 defines literal string type @code{"char"} as @code{char} without a sign.
10561 For program code
10562
10563 @smallexample
10564 char var0[] = "A";
10565 signed char var1[] = "A";
10566 @end smallexample
10567
10568 You get during debugging
10569 @smallexample
10570 (gdb) print var0
10571 $1 = "A"
10572 (gdb) print var1
10573 $2 = @{65 'A', 0 '\0'@}
10574 @end smallexample
10575
10576 @node Arrays
10577 @section Artificial Arrays
10578
10579 @cindex artificial array
10580 @cindex arrays
10581 @kindex @@@r{, referencing memory as an array}
10582 It is often useful to print out several successive objects of the
10583 same type in memory; a section of an array, or an array of
10584 dynamically determined size for which only a pointer exists in the
10585 program.
10586
10587 You can do this by referring to a contiguous span of memory as an
10588 @dfn{artificial array}, using the binary operator @samp{@@}. The left
10589 operand of @samp{@@} should be the first element of the desired array
10590 and be an individual object. The right operand should be the desired length
10591 of the array. The result is an array value whose elements are all of
10592 the type of the left argument. The first element is actually the left
10593 argument; the second element comes from bytes of memory immediately
10594 following those that hold the first element, and so on. Here is an
10595 example. If a program says
10596
10597 @smallexample
10598 int *array = (int *) malloc (len * sizeof (int));
10599 @end smallexample
10600
10601 @noindent
10602 you can print the contents of @code{array} with
10603
10604 @smallexample
10605 p *array@@len
10606 @end smallexample
10607
10608 The left operand of @samp{@@} must reside in memory. Array values made
10609 with @samp{@@} in this way behave just like other arrays in terms of
10610 subscripting, and are coerced to pointers when used in expressions.
10611 Artificial arrays most often appear in expressions via the value history
10612 (@pxref{Value History, ,Value History}), after printing one out.
10613
10614 Another way to create an artificial array is to use a cast.
10615 This re-interprets a value as if it were an array.
10616 The value need not be in memory:
10617 @smallexample
10618 (@value{GDBP}) p/x (short[2])0x12345678
10619 $1 = @{0x1234, 0x5678@}
10620 @end smallexample
10621
10622 As a convenience, if you leave the array length out (as in
10623 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
10624 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
10625 @smallexample
10626 (@value{GDBP}) p/x (short[])0x12345678
10627 $2 = @{0x1234, 0x5678@}
10628 @end smallexample
10629
10630 Sometimes the artificial array mechanism is not quite enough; in
10631 moderately complex data structures, the elements of interest may not
10632 actually be adjacent---for example, if you are interested in the values
10633 of pointers in an array. One useful work-around in this situation is
10634 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
10635 Variables}) as a counter in an expression that prints the first
10636 interesting value, and then repeat that expression via @key{RET}. For
10637 instance, suppose you have an array @code{dtab} of pointers to
10638 structures, and you are interested in the values of a field @code{fv}
10639 in each structure. Here is an example of what you might type:
10640
10641 @smallexample
10642 set $i = 0
10643 p dtab[$i++]->fv
10644 @key{RET}
10645 @key{RET}
10646 @dots{}
10647 @end smallexample
10648
10649 @node Output Formats
10650 @section Output Formats
10651
10652 @cindex formatted output
10653 @cindex output formats
10654 By default, @value{GDBN} prints a value according to its data type. Sometimes
10655 this is not what you want. For example, you might want to print a number
10656 in hex, or a pointer in decimal. Or you might want to view data in memory
10657 at a certain address as a character string or as an instruction. To do
10658 these things, specify an @dfn{output format} when you print a value.
10659
10660 The simplest use of output formats is to say how to print a value
10661 already computed. This is done by starting the arguments of the
10662 @code{print} command with a slash and a format letter. The format
10663 letters supported are:
10664
10665 @table @code
10666 @item x
10667 Regard the bits of the value as an integer, and print the integer in
10668 hexadecimal.
10669
10670 @item d
10671 Print as integer in signed decimal.
10672
10673 @item u
10674 Print as integer in unsigned decimal.
10675
10676 @item o
10677 Print as integer in octal.
10678
10679 @item t
10680 Print as integer in binary. The letter @samp{t} stands for ``two''.
10681 @footnote{@samp{b} cannot be used because these format letters are also
10682 used with the @code{x} command, where @samp{b} stands for ``byte'';
10683 see @ref{Memory,,Examining Memory}.}
10684
10685 @item a
10686 @cindex unknown address, locating
10687 @cindex locate address
10688 Print as an address, both absolute in hexadecimal and as an offset from
10689 the nearest preceding symbol. You can use this format used to discover
10690 where (in what function) an unknown address is located:
10691
10692 @smallexample
10693 (@value{GDBP}) p/a 0x54320
10694 $3 = 0x54320 <_initialize_vx+396>
10695 @end smallexample
10696
10697 @noindent
10698 The command @code{info symbol 0x54320} yields similar results.
10699 @xref{Symbols, info symbol}.
10700
10701 @item c
10702 Regard as an integer and print it as a character constant. This
10703 prints both the numerical value and its character representation. The
10704 character representation is replaced with the octal escape @samp{\nnn}
10705 for characters outside the 7-bit @sc{ascii} range.
10706
10707 Without this format, @value{GDBN} displays @code{char},
10708 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10709 constants. Single-byte members of vectors are displayed as integer
10710 data.
10711
10712 @item f
10713 Regard the bits of the value as a floating point number and print
10714 using typical floating point syntax.
10715
10716 @item s
10717 @cindex printing strings
10718 @cindex printing byte arrays
10719 Regard as a string, if possible. With this format, pointers to single-byte
10720 data are displayed as null-terminated strings and arrays of single-byte data
10721 are displayed as fixed-length strings. Other values are displayed in their
10722 natural types.
10723
10724 Without this format, @value{GDBN} displays pointers to and arrays of
10725 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10726 strings. Single-byte members of a vector are displayed as an integer
10727 array.
10728
10729 @item z
10730 Like @samp{x} formatting, the value is treated as an integer and
10731 printed as hexadecimal, but leading zeros are printed to pad the value
10732 to the size of the integer type.
10733
10734 @item r
10735 @cindex raw printing
10736 Print using the @samp{raw} formatting. By default, @value{GDBN} will
10737 use a Python-based pretty-printer, if one is available (@pxref{Pretty
10738 Printing}). This typically results in a higher-level display of the
10739 value's contents. The @samp{r} format bypasses any Python
10740 pretty-printer which might exist.
10741 @end table
10742
10743 For example, to print the program counter in hex (@pxref{Registers}), type
10744
10745 @smallexample
10746 p/x $pc
10747 @end smallexample
10748
10749 @noindent
10750 Note that no space is required before the slash; this is because command
10751 names in @value{GDBN} cannot contain a slash.
10752
10753 To reprint the last value in the value history with a different format,
10754 you can use the @code{print} command with just a format and no
10755 expression. For example, @samp{p/x} reprints the last value in hex.
10756
10757 @node Memory
10758 @section Examining Memory
10759
10760 You can use the command @code{x} (for ``examine'') to examine memory in
10761 any of several formats, independently of your program's data types.
10762
10763 @cindex examining memory
10764 @table @code
10765 @kindex x @r{(examine memory)}
10766 @item x/@var{nfu} @var{addr}
10767 @itemx x @var{addr}
10768 @itemx x
10769 Use the @code{x} command to examine memory.
10770 @end table
10771
10772 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10773 much memory to display and how to format it; @var{addr} is an
10774 expression giving the address where you want to start displaying memory.
10775 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10776 Several commands set convenient defaults for @var{addr}.
10777
10778 @table @r
10779 @item @var{n}, the repeat count
10780 The repeat count is a decimal integer; the default is 1. It specifies
10781 how much memory (counting by units @var{u}) to display. If a negative
10782 number is specified, memory is examined backward from @var{addr}.
10783 @c This really is **decimal**; unaffected by 'set radix' as of GDB
10784 @c 4.1.2.
10785
10786 @item @var{f}, the display format
10787 The display format is one of the formats used by @code{print}
10788 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
10789 @samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
10790 The default is @samp{x} (hexadecimal) initially. The default changes
10791 each time you use either @code{x} or @code{print}.
10792
10793 @item @var{u}, the unit size
10794 The unit size is any of
10795
10796 @table @code
10797 @item b
10798 Bytes.
10799 @item h
10800 Halfwords (two bytes).
10801 @item w
10802 Words (four bytes). This is the initial default.
10803 @item g
10804 Giant words (eight bytes).
10805 @end table
10806
10807 Each time you specify a unit size with @code{x}, that size becomes the
10808 default unit the next time you use @code{x}. For the @samp{i} format,
10809 the unit size is ignored and is normally not written. For the @samp{s} format,
10810 the unit size defaults to @samp{b}, unless it is explicitly given.
10811 Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
10812 32-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
10813 Note that the results depend on the programming language of the
10814 current compilation unit. If the language is C, the @samp{s}
10815 modifier will use the UTF-16 encoding while @samp{w} will use
10816 UTF-32. The encoding is set by the programming language and cannot
10817 be altered.
10818
10819 @item @var{addr}, starting display address
10820 @var{addr} is the address where you want @value{GDBN} to begin displaying
10821 memory. The expression need not have a pointer value (though it may);
10822 it is always interpreted as an integer address of a byte of memory.
10823 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
10824 @var{addr} is usually just after the last address examined---but several
10825 other commands also set the default address: @code{info breakpoints} (to
10826 the address of the last breakpoint listed), @code{info line} (to the
10827 starting address of a line), and @code{print} (if you use it to display
10828 a value from memory).
10829 @end table
10830
10831 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10832 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10833 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
10834 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
10835 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
10836
10837 You can also specify a negative repeat count to examine memory backward
10838 from the given address. For example, @samp{x/-3uh 0x54320} prints three
10839 halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
10840
10841 Since the letters indicating unit sizes are all distinct from the
10842 letters specifying output formats, you do not have to remember whether
10843 unit size or format comes first; either order works. The output
10844 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10845 (However, the count @var{n} must come first; @samp{wx4} does not work.)
10846
10847 Even though the unit size @var{u} is ignored for the formats @samp{s}
10848 and @samp{i}, you might still want to use a count @var{n}; for example,
10849 @samp{3i} specifies that you want to see three machine instructions,
10850 including any operands. For convenience, especially when used with
10851 the @code{display} command, the @samp{i} format also prints branch delay
10852 slot instructions, if any, beyond the count specified, which immediately
10853 follow the last instruction that is within the count. The command
10854 @code{disassemble} gives an alternative way of inspecting machine
10855 instructions; see @ref{Machine Code,,Source and Machine Code}.
10856
10857 If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10858 the command displays null-terminated strings or instructions before the given
10859 address as many as the absolute value of the given number. For the @samp{i}
10860 format, we use line number information in the debug info to accurately locate
10861 instruction boundaries while disassembling backward. If line info is not
10862 available, the command stops examining memory with an error message.
10863
10864 All the defaults for the arguments to @code{x} are designed to make it
10865 easy to continue scanning memory with minimal specifications each time
10866 you use @code{x}. For example, after you have inspected three machine
10867 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10868 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
10869 the repeat count @var{n} is used again; the other arguments default as
10870 for successive uses of @code{x}.
10871
10872 When examining machine instructions, the instruction at current program
10873 counter is shown with a @code{=>} marker. For example:
10874
10875 @smallexample
10876 (@value{GDBP}) x/5i $pc-6
10877 0x804837f <main+11>: mov %esp,%ebp
10878 0x8048381 <main+13>: push %ecx
10879 0x8048382 <main+14>: sub $0x4,%esp
10880 => 0x8048385 <main+17>: movl $0x8048460,(%esp)
10881 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
10882 @end smallexample
10883
10884 @cindex @code{$_}, @code{$__}, and value history
10885 The addresses and contents printed by the @code{x} command are not saved
10886 in the value history because there is often too much of them and they
10887 would get in the way. Instead, @value{GDBN} makes these values available for
10888 subsequent use in expressions as values of the convenience variables
10889 @code{$_} and @code{$__}. After an @code{x} command, the last address
10890 examined is available for use in expressions in the convenience variable
10891 @code{$_}. The contents of that address, as examined, are available in
10892 the convenience variable @code{$__}.
10893
10894 If the @code{x} command has a repeat count, the address and contents saved
10895 are from the last memory unit printed; this is not the same as the last
10896 address printed if several units were printed on the last line of output.
10897
10898 @anchor{addressable memory unit}
10899 @cindex addressable memory unit
10900 Most targets have an addressable memory unit size of 8 bits. This means
10901 that to each memory address are associated 8 bits of data. Some
10902 targets, however, have other addressable memory unit sizes.
10903 Within @value{GDBN} and this document, the term
10904 @dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
10905 when explicitly referring to a chunk of data of that size. The word
10906 @dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
10907 the addressable memory unit size of the target. For most systems,
10908 addressable memory unit is a synonym of byte.
10909
10910 @cindex remote memory comparison
10911 @cindex target memory comparison
10912 @cindex verify remote memory image
10913 @cindex verify target memory image
10914 When you are debugging a program running on a remote target machine
10915 (@pxref{Remote Debugging}), you may wish to verify the program's image
10916 in the remote machine's memory against the executable file you
10917 downloaded to the target. Or, on any target, you may want to check
10918 whether the program has corrupted its own read-only sections. The
10919 @code{compare-sections} command is provided for such situations.
10920
10921 @table @code
10922 @kindex compare-sections
10923 @item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
10924 Compare the data of a loadable section @var{section-name} in the
10925 executable file of the program being debugged with the same section in
10926 the target machine's memory, and report any mismatches. With no
10927 arguments, compares all loadable sections. With an argument of
10928 @code{-r}, compares all loadable read-only sections.
10929
10930 Note: for remote targets, this command can be accelerated if the
10931 target supports computing the CRC checksum of a block of memory
10932 (@pxref{qCRC packet}).
10933 @end table
10934
10935 @node Auto Display
10936 @section Automatic Display
10937 @cindex automatic display
10938 @cindex display of expressions
10939
10940 If you find that you want to print the value of an expression frequently
10941 (to see how it changes), you might want to add it to the @dfn{automatic
10942 display list} so that @value{GDBN} prints its value each time your program stops.
10943 Each expression added to the list is given a number to identify it;
10944 to remove an expression from the list, you specify that number.
10945 The automatic display looks like this:
10946
10947 @smallexample
10948 2: foo = 38
10949 3: bar[5] = (struct hack *) 0x3804
10950 @end smallexample
10951
10952 @noindent
10953 This display shows item numbers, expressions and their current values. As with
10954 displays you request manually using @code{x} or @code{print}, you can
10955 specify the output format you prefer; in fact, @code{display} decides
10956 whether to use @code{print} or @code{x} depending your format
10957 specification---it uses @code{x} if you specify either the @samp{i}
10958 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
10959
10960 @table @code
10961 @kindex display
10962 @item display @var{expr}
10963 Add the expression @var{expr} to the list of expressions to display
10964 each time your program stops. @xref{Expressions, ,Expressions}.
10965
10966 @code{display} does not repeat if you press @key{RET} again after using it.
10967
10968 @item display/@var{fmt} @var{expr}
10969 For @var{fmt} specifying only a display format and not a size or
10970 count, add the expression @var{expr} to the auto-display list but
10971 arrange to display it each time in the specified format @var{fmt}.
10972 @xref{Output Formats,,Output Formats}.
10973
10974 @item display/@var{fmt} @var{addr}
10975 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
10976 number of units, add the expression @var{addr} as a memory address to
10977 be examined each time your program stops. Examining means in effect
10978 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
10979 @end table
10980
10981 For example, @samp{display/i $pc} can be helpful, to see the machine
10982 instruction about to be executed each time execution stops (@samp{$pc}
10983 is a common name for the program counter; @pxref{Registers, ,Registers}).
10984
10985 @table @code
10986 @kindex delete display
10987 @kindex undisplay
10988 @item undisplay @var{dnums}@dots{}
10989 @itemx delete display @var{dnums}@dots{}
10990 Remove items from the list of expressions to display. Specify the
10991 numbers of the displays that you want affected with the command
10992 argument @var{dnums}. It can be a single display number, one of the
10993 numbers shown in the first field of the @samp{info display} display;
10994 or it could be a range of display numbers, as in @code{2-4}.
10995
10996 @code{undisplay} does not repeat if you press @key{RET} after using it.
10997 (Otherwise you would just get the error @samp{No display number @dots{}}.)
10998
10999 @kindex disable display
11000 @item disable display @var{dnums}@dots{}
11001 Disable the display of item numbers @var{dnums}. A disabled display
11002 item is not printed automatically, but is not forgotten. It may be
11003 enabled again later. Specify the numbers of the displays that you
11004 want affected with the command argument @var{dnums}. It can be a
11005 single display number, one of the numbers shown in the first field of
11006 the @samp{info display} display; or it could be a range of display
11007 numbers, as in @code{2-4}.
11008
11009 @kindex enable display
11010 @item enable display @var{dnums}@dots{}
11011 Enable display of item numbers @var{dnums}. It becomes effective once
11012 again in auto display of its expression, until you specify otherwise.
11013 Specify the numbers of the displays that you want affected with the
11014 command argument @var{dnums}. It can be a single display number, one
11015 of the numbers shown in the first field of the @samp{info display}
11016 display; or it could be a range of display numbers, as in @code{2-4}.
11017
11018 @item display
11019 Display the current values of the expressions on the list, just as is
11020 done when your program stops.
11021
11022 @kindex info display
11023 @item info display
11024 Print the list of expressions previously set up to display
11025 automatically, each one with its item number, but without showing the
11026 values. This includes disabled expressions, which are marked as such.
11027 It also includes expressions which would not be displayed right now
11028 because they refer to automatic variables not currently available.
11029 @end table
11030
11031 @cindex display disabled out of scope
11032 If a display expression refers to local variables, then it does not make
11033 sense outside the lexical context for which it was set up. Such an
11034 expression is disabled when execution enters a context where one of its
11035 variables is not defined. For example, if you give the command
11036 @code{display last_char} while inside a function with an argument
11037 @code{last_char}, @value{GDBN} displays this argument while your program
11038 continues to stop inside that function. When it stops elsewhere---where
11039 there is no variable @code{last_char}---the display is disabled
11040 automatically. The next time your program stops where @code{last_char}
11041 is meaningful, you can enable the display expression once again.
11042
11043 @node Print Settings
11044 @section Print Settings
11045
11046 @cindex format options
11047 @cindex print settings
11048 @value{GDBN} provides the following ways to control how arrays, structures,
11049 and symbols are printed.
11050
11051 @noindent
11052 These settings are useful for debugging programs in any language:
11053
11054 @table @code
11055 @kindex set print
11056 @anchor{set print address}
11057 @item set print address
11058 @itemx set print address on
11059 @cindex print/don't print memory addresses
11060 @value{GDBN} prints memory addresses showing the location of stack
11061 traces, structure values, pointer values, breakpoints, and so forth,
11062 even when it also displays the contents of those addresses. The default
11063 is @code{on}. For example, this is what a stack frame display looks like with
11064 @code{set print address on}:
11065
11066 @smallexample
11067 @group
11068 (@value{GDBP}) f
11069 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
11070 at input.c:530
11071 530 if (lquote != def_lquote)
11072 @end group
11073 @end smallexample
11074
11075 @item set print address off
11076 Do not print addresses when displaying their contents. For example,
11077 this is the same stack frame displayed with @code{set print address off}:
11078
11079 @smallexample
11080 @group
11081 (@value{GDBP}) set print addr off
11082 (@value{GDBP}) f
11083 #0 set_quotes (lq="<<", rq=">>") at input.c:530
11084 530 if (lquote != def_lquote)
11085 @end group
11086 @end smallexample
11087
11088 You can use @samp{set print address off} to eliminate all machine
11089 dependent displays from the @value{GDBN} interface. For example, with
11090 @code{print address off}, you should get the same text for backtraces on
11091 all machines---whether or not they involve pointer arguments.
11092
11093 @kindex show print
11094 @item show print address
11095 Show whether or not addresses are to be printed.
11096 @end table
11097
11098 When @value{GDBN} prints a symbolic address, it normally prints the
11099 closest earlier symbol plus an offset. If that symbol does not uniquely
11100 identify the address (for example, it is a name whose scope is a single
11101 source file), you may need to clarify. One way to do this is with
11102 @code{info line}, for example @samp{info line *0x4537}. Alternately,
11103 you can set @value{GDBN} to print the source file and line number when
11104 it prints a symbolic address:
11105
11106 @table @code
11107 @item set print symbol-filename on
11108 @cindex source file and line of a symbol
11109 @cindex symbol, source file and line
11110 Tell @value{GDBN} to print the source file name and line number of a
11111 symbol in the symbolic form of an address.
11112
11113 @item set print symbol-filename off
11114 Do not print source file name and line number of a symbol. This is the
11115 default.
11116
11117 @item show print symbol-filename
11118 Show whether or not @value{GDBN} will print the source file name and
11119 line number of a symbol in the symbolic form of an address.
11120 @end table
11121
11122 Another situation where it is helpful to show symbol filenames and line
11123 numbers is when disassembling code; @value{GDBN} shows you the line
11124 number and source file that corresponds to each instruction.
11125
11126 Also, you may wish to see the symbolic form only if the address being
11127 printed is reasonably close to the closest earlier symbol:
11128
11129 @table @code
11130 @item set print max-symbolic-offset @var{max-offset}
11131 @itemx set print max-symbolic-offset unlimited
11132 @cindex maximum value for offset of closest symbol
11133 Tell @value{GDBN} to only display the symbolic form of an address if the
11134 offset between the closest earlier symbol and the address is less than
11135 @var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
11136 to always print the symbolic form of an address if any symbol precedes
11137 it. Zero is equivalent to @code{unlimited}.
11138
11139 @item show print max-symbolic-offset
11140 Ask how large the maximum offset is that @value{GDBN} prints in a
11141 symbolic address.
11142 @end table
11143
11144 @cindex wild pointer, interpreting
11145 @cindex pointer, finding referent
11146 If you have a pointer and you are not sure where it points, try
11147 @samp{set print symbol-filename on}. Then you can determine the name
11148 and source file location of the variable where it points, using
11149 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
11150 For example, here @value{GDBN} shows that a variable @code{ptt} points
11151 at another variable @code{t}, defined in @file{hi2.c}:
11152
11153 @smallexample
11154 (@value{GDBP}) set print symbol-filename on
11155 (@value{GDBP}) p/a ptt
11156 $4 = 0xe008 <t in hi2.c>
11157 @end smallexample
11158
11159 @quotation
11160 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
11161 does not show the symbol name and filename of the referent, even with
11162 the appropriate @code{set print} options turned on.
11163 @end quotation
11164
11165 You can also enable @samp{/a}-like formatting all the time using
11166 @samp{set print symbol on}:
11167
11168 @anchor{set print symbol}
11169 @table @code
11170 @item set print symbol on
11171 Tell @value{GDBN} to print the symbol corresponding to an address, if
11172 one exists.
11173
11174 @item set print symbol off
11175 Tell @value{GDBN} not to print the symbol corresponding to an
11176 address. In this mode, @value{GDBN} will still print the symbol
11177 corresponding to pointers to functions. This is the default.
11178
11179 @item show print symbol
11180 Show whether @value{GDBN} will display the symbol corresponding to an
11181 address.
11182 @end table
11183
11184 Other settings control how different kinds of objects are printed:
11185
11186 @table @code
11187 @anchor{set print array}
11188 @item set print array
11189 @itemx set print array on
11190 @cindex pretty print arrays
11191 Pretty print arrays. This format is more convenient to read,
11192 but uses more space. The default is off.
11193
11194 @item set print array off
11195 Return to compressed format for arrays.
11196
11197 @item show print array
11198 Show whether compressed or pretty format is selected for displaying
11199 arrays.
11200
11201 @cindex print array indexes
11202 @anchor{set print array-indexes}
11203 @item set print array-indexes
11204 @itemx set print array-indexes on
11205 Print the index of each element when displaying arrays. May be more
11206 convenient to locate a given element in the array or quickly find the
11207 index of a given element in that printed array. The default is off.
11208
11209 @item set print array-indexes off
11210 Stop printing element indexes when displaying arrays.
11211
11212 @item show print array-indexes
11213 Show whether the index of each element is printed when displaying
11214 arrays.
11215
11216 @anchor{set print elements}
11217 @item set print elements @var{number-of-elements}
11218 @itemx set print elements unlimited
11219 @cindex number of array elements to print
11220 @cindex limit on number of printed array elements
11221 Set a limit on how many elements of an array @value{GDBN} will print.
11222 If @value{GDBN} is printing a large array, it stops printing after it has
11223 printed the number of elements set by the @code{set print elements} command.
11224 This limit also applies to the display of strings.
11225 When @value{GDBN} starts, this limit is set to 200.
11226 Setting @var{number-of-elements} to @code{unlimited} or zero means
11227 that the number of elements to print is unlimited.
11228
11229 @item show print elements
11230 Display the number of elements of a large array that @value{GDBN} will print.
11231 If the number is 0, then the printing is unlimited.
11232
11233 @anchor{set print frame-arguments}
11234 @item set print frame-arguments @var{value}
11235 @kindex set print frame-arguments
11236 @cindex printing frame argument values
11237 @cindex print all frame argument values
11238 @cindex print frame argument values for scalars only
11239 @cindex do not print frame arguments
11240 This command allows to control how the values of arguments are printed
11241 when the debugger prints a frame (@pxref{Frames}). The possible
11242 values are:
11243
11244 @table @code
11245 @item all
11246 The values of all arguments are printed.
11247
11248 @item scalars
11249 Print the value of an argument only if it is a scalar. The value of more
11250 complex arguments such as arrays, structures, unions, etc, is replaced
11251 by @code{@dots{}}. This is the default. Here is an example where
11252 only scalar arguments are shown:
11253
11254 @smallexample
11255 #1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11256 at frame-args.c:23
11257 @end smallexample
11258
11259 @item none
11260 None of the argument values are printed. Instead, the value of each argument
11261 is replaced by @code{@dots{}}. In this case, the example above now becomes:
11262
11263 @smallexample
11264 #1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11265 at frame-args.c:23
11266 @end smallexample
11267
11268 @item presence
11269 Only the presence of arguments is indicated by @code{@dots{}}.
11270 The @code{@dots{}} are not printed for function without any arguments.
11271 None of the argument names and values are printed.
11272 In this case, the example above now becomes:
11273
11274 @smallexample
11275 #1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11276 @end smallexample
11277
11278 @end table
11279
11280 By default, only scalar arguments are printed. This command can be used
11281 to configure the debugger to print the value of all arguments, regardless
11282 of their type. However, it is often advantageous to not print the value
11283 of more complex parameters. For instance, it reduces the amount of
11284 information printed in each frame, making the backtrace more readable.
11285 Also, it improves performance when displaying Ada frames, because
11286 the computation of large arguments can sometimes be CPU-intensive,
11287 especially in large applications. Setting @code{print frame-arguments}
11288 to @code{scalars} (the default), @code{none} or @code{presence} avoids
11289 this computation, thus speeding up the display of each Ada frame.
11290
11291 @item show print frame-arguments
11292 Show how the value of arguments should be displayed when printing a frame.
11293
11294 @anchor{set print raw-frame-arguments}
11295 @item set print raw-frame-arguments on
11296 Print frame arguments in raw, non pretty-printed, form.
11297
11298 @item set print raw-frame-arguments off
11299 Print frame arguments in pretty-printed form, if there is a pretty-printer
11300 for the value (@pxref{Pretty Printing}),
11301 otherwise print the value in raw form.
11302 This is the default.
11303
11304 @item show print raw-frame-arguments
11305 Show whether to print frame arguments in raw form.
11306
11307 @anchor{set print entry-values}
11308 @item set print entry-values @var{value}
11309 @kindex set print entry-values
11310 Set printing of frame argument values at function entry. In some cases
11311 @value{GDBN} can determine the value of function argument which was passed by
11312 the function caller, even if the value was modified inside the called function
11313 and therefore is different. With optimized code, the current value could be
11314 unavailable, but the entry value may still be known.
11315
11316 The default value is @code{default} (see below for its description). Older
11317 @value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11318 this feature will behave in the @code{default} setting the same way as with the
11319 @code{no} setting.
11320
11321 This functionality is currently supported only by DWARF 2 debugging format and
11322 the compiler has to produce @samp{DW_TAG_call_site} tags. With
11323 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11324 this information.
11325
11326 The @var{value} parameter can be one of the following:
11327
11328 @table @code
11329 @item no
11330 Print only actual parameter values, never print values from function entry
11331 point.
11332 @smallexample
11333 #0 equal (val=5)
11334 #0 different (val=6)
11335 #0 lost (val=<optimized out>)
11336 #0 born (val=10)
11337 #0 invalid (val=<optimized out>)
11338 @end smallexample
11339
11340 @item only
11341 Print only parameter values from function entry point. The actual parameter
11342 values are never printed.
11343 @smallexample
11344 #0 equal (val@@entry=5)
11345 #0 different (val@@entry=5)
11346 #0 lost (val@@entry=5)
11347 #0 born (val@@entry=<optimized out>)
11348 #0 invalid (val@@entry=<optimized out>)
11349 @end smallexample
11350
11351 @item preferred
11352 Print only parameter values from function entry point. If value from function
11353 entry point is not known while the actual value is known, print the actual
11354 value for such parameter.
11355 @smallexample
11356 #0 equal (val@@entry=5)
11357 #0 different (val@@entry=5)
11358 #0 lost (val@@entry=5)
11359 #0 born (val=10)
11360 #0 invalid (val@@entry=<optimized out>)
11361 @end smallexample
11362
11363 @item if-needed
11364 Print actual parameter values. If actual parameter value is not known while
11365 value from function entry point is known, print the entry point value for such
11366 parameter.
11367 @smallexample
11368 #0 equal (val=5)
11369 #0 different (val=6)
11370 #0 lost (val@@entry=5)
11371 #0 born (val=10)
11372 #0 invalid (val=<optimized out>)
11373 @end smallexample
11374
11375 @item both
11376 Always print both the actual parameter value and its value from function entry
11377 point, even if values of one or both are not available due to compiler
11378 optimizations.
11379 @smallexample
11380 #0 equal (val=5, val@@entry=5)
11381 #0 different (val=6, val@@entry=5)
11382 #0 lost (val=<optimized out>, val@@entry=5)
11383 #0 born (val=10, val@@entry=<optimized out>)
11384 #0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11385 @end smallexample
11386
11387 @item compact
11388 Print the actual parameter value if it is known and also its value from
11389 function entry point if it is known. If neither is known, print for the actual
11390 value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11391 values are known and identical, print the shortened
11392 @code{param=param@@entry=VALUE} notation.
11393 @smallexample
11394 #0 equal (val=val@@entry=5)
11395 #0 different (val=6, val@@entry=5)
11396 #0 lost (val@@entry=5)
11397 #0 born (val=10)
11398 #0 invalid (val=<optimized out>)
11399 @end smallexample
11400
11401 @item default
11402 Always print the actual parameter value. Print also its value from function
11403 entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11404 if both values are known and identical, print the shortened
11405 @code{param=param@@entry=VALUE} notation.
11406 @smallexample
11407 #0 equal (val=val@@entry=5)
11408 #0 different (val=6, val@@entry=5)
11409 #0 lost (val=<optimized out>, val@@entry=5)
11410 #0 born (val=10)
11411 #0 invalid (val=<optimized out>)
11412 @end smallexample
11413 @end table
11414
11415 For analysis messages on possible failures of frame argument values at function
11416 entry resolution see @ref{set debug entry-values}.
11417
11418 @item show print entry-values
11419 Show the method being used for printing of frame argument values at function
11420 entry.
11421
11422 @anchor{set print frame-info}
11423 @item set print frame-info @var{value}
11424 @kindex set print frame-info
11425 @cindex printing frame information
11426 @cindex frame information, printing
11427 This command allows to control the information printed when
11428 the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11429 for a general explanation about frames and frame information.
11430 Note that some other settings (such as @code{set print frame-arguments}
11431 and @code{set print address}) are also influencing if and how some frame
11432 information is displayed. In particular, the frame program counter is never
11433 printed if @code{set print address} is off.
11434
11435 The possible values for @code{set print frame-info} are:
11436 @table @code
11437 @item short-location
11438 Print the frame level, the program counter (if not at the
11439 beginning of the location source line), the function, the function
11440 arguments.
11441 @item location
11442 Same as @code{short-location} but also print the source file and source line
11443 number.
11444 @item location-and-address
11445 Same as @code{location} but print the program counter even if located at the
11446 beginning of the location source line.
11447 @item source-line
11448 Print the program counter (if not at the beginning of the location
11449 source line), the line number and the source line.
11450 @item source-and-location
11451 Print what @code{location} and @code{source-line} are printing.
11452 @item auto
11453 The information printed for a frame is decided automatically
11454 by the @value{GDBN} command that prints a frame.
11455 For example, @code{frame} prints the information printed by
11456 @code{source-and-location} while @code{stepi} will switch between
11457 @code{source-line} and @code{source-and-location} depending on the program
11458 counter.
11459 The default value is @code{auto}.
11460 @end table
11461
11462 @anchor{set print repeats}
11463 @item set print repeats @var{number-of-repeats}
11464 @itemx set print repeats unlimited
11465 @cindex repeated array elements
11466 Set the threshold for suppressing display of repeated array
11467 elements. When the number of consecutive identical elements of an
11468 array exceeds the threshold, @value{GDBN} prints the string
11469 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
11470 identical repetitions, instead of displaying the identical elements
11471 themselves. Setting the threshold to @code{unlimited} or zero will
11472 cause all elements to be individually printed. The default threshold
11473 is 10.
11474
11475 @item show print repeats
11476 Display the current threshold for printing repeated identical
11477 elements.
11478
11479 @anchor{set print max-depth}
11480 @item set print max-depth @var{depth}
11481 @item set print max-depth unlimited
11482 @cindex printing nested structures
11483 Set the threshold after which nested structures are replaced with
11484 ellipsis, this can make visualising deeply nested structures easier.
11485
11486 For example, given this C code
11487
11488 @smallexample
11489 typedef struct s1 @{ int a; @} s1;
11490 typedef struct s2 @{ s1 b; @} s2;
11491 typedef struct s3 @{ s2 c; @} s3;
11492 typedef struct s4 @{ s3 d; @} s4;
11493
11494 s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11495 @end smallexample
11496
11497 The following table shows how different values of @var{depth} will
11498 effect how @code{var} is printed by @value{GDBN}:
11499
11500 @multitable @columnfractions .3 .7
11501 @headitem @var{depth} setting @tab Result of @samp{p var}
11502 @item unlimited
11503 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11504 @item @code{0}
11505 @tab @code{$1 = @{...@}}
11506 @item @code{1}
11507 @tab @code{$1 = @{d = @{...@}@}}
11508 @item @code{2}
11509 @tab @code{$1 = @{d = @{c = @{...@}@}@}}
11510 @item @code{3}
11511 @tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11512 @item @code{4}
11513 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11514 @end multitable
11515
11516 To see the contents of structures that have been hidden the user can
11517 either increase the print max-depth, or they can print the elements of
11518 the structure that are visible, for example
11519
11520 @smallexample
11521 (gdb) set print max-depth 2
11522 (gdb) p var
11523 $1 = @{d = @{c = @{...@}@}@}
11524 (gdb) p var.d
11525 $2 = @{c = @{b = @{...@}@}@}
11526 (gdb) p var.d.c
11527 $3 = @{b = @{a = 3@}@}
11528 @end smallexample
11529
11530 The pattern used to replace nested structures varies based on
11531 language, for most languages @code{@{...@}} is used, but Fortran uses
11532 @code{(...)}.
11533
11534 @item show print max-depth
11535 Display the current threshold after which nested structures are
11536 replaces with ellipsis.
11537
11538 @anchor{set print null-stop}
11539 @item set print null-stop
11540 @cindex @sc{null} elements in arrays
11541 Cause @value{GDBN} to stop printing the characters of an array when the first
11542 @sc{null} is encountered. This is useful when large arrays actually
11543 contain only short strings.
11544 The default is off.
11545
11546 @item show print null-stop
11547 Show whether @value{GDBN} stops printing an array on the first
11548 @sc{null} character.
11549
11550 @anchor{set print pretty}
11551 @item set print pretty on
11552 @cindex print structures in indented form
11553 @cindex indentation in structure display
11554 Cause @value{GDBN} to print structures in an indented format with one member
11555 per line, like this:
11556
11557 @smallexample
11558 @group
11559 $1 = @{
11560 next = 0x0,
11561 flags = @{
11562 sweet = 1,
11563 sour = 1
11564 @},
11565 meat = 0x54 "Pork"
11566 @}
11567 @end group
11568 @end smallexample
11569
11570 @item set print pretty off
11571 Cause @value{GDBN} to print structures in a compact format, like this:
11572
11573 @smallexample
11574 @group
11575 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11576 meat = 0x54 "Pork"@}
11577 @end group
11578 @end smallexample
11579
11580 @noindent
11581 This is the default format.
11582
11583 @item show print pretty
11584 Show which format @value{GDBN} is using to print structures.
11585
11586 @anchor{set print raw-values}
11587 @item set print raw-values on
11588 Print values in raw form, without applying the pretty
11589 printers for the value.
11590
11591 @item set print raw-values off
11592 Print values in pretty-printed form, if there is a pretty-printer
11593 for the value (@pxref{Pretty Printing}),
11594 otherwise print the value in raw form.
11595
11596 The default setting is ``off''.
11597
11598 @item show print raw-values
11599 Show whether to print values in raw form.
11600
11601 @item set print sevenbit-strings on
11602 @cindex eight-bit characters in strings
11603 @cindex octal escapes in strings
11604 Print using only seven-bit characters; if this option is set,
11605 @value{GDBN} displays any eight-bit characters (in strings or
11606 character values) using the notation @code{\}@var{nnn}. This setting is
11607 best if you are working in English (@sc{ascii}) and you use the
11608 high-order bit of characters as a marker or ``meta'' bit.
11609
11610 @item set print sevenbit-strings off
11611 Print full eight-bit characters. This allows the use of more
11612 international character sets, and is the default.
11613
11614 @item show print sevenbit-strings
11615 Show whether or not @value{GDBN} is printing only seven-bit characters.
11616
11617 @anchor{set print union}
11618 @item set print union on
11619 @cindex unions in structures, printing
11620 Tell @value{GDBN} to print unions which are contained in structures
11621 and other unions. This is the default setting.
11622
11623 @item set print union off
11624 Tell @value{GDBN} not to print unions which are contained in
11625 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
11626 instead.
11627
11628 @item show print union
11629 Ask @value{GDBN} whether or not it will print unions which are contained in
11630 structures and other unions.
11631
11632 For example, given the declarations
11633
11634 @smallexample
11635 typedef enum @{Tree, Bug@} Species;
11636 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
11637 typedef enum @{Caterpillar, Cocoon, Butterfly@}
11638 Bug_forms;
11639
11640 struct thing @{
11641 Species it;
11642 union @{
11643 Tree_forms tree;
11644 Bug_forms bug;
11645 @} form;
11646 @};
11647
11648 struct thing foo = @{Tree, @{Acorn@}@};
11649 @end smallexample
11650
11651 @noindent
11652 with @code{set print union on} in effect @samp{p foo} would print
11653
11654 @smallexample
11655 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
11656 @end smallexample
11657
11658 @noindent
11659 and with @code{set print union off} in effect it would print
11660
11661 @smallexample
11662 $1 = @{it = Tree, form = @{...@}@}
11663 @end smallexample
11664
11665 @noindent
11666 @code{set print union} affects programs written in C-like languages
11667 and in Pascal.
11668 @end table
11669
11670 @need 1000
11671 @noindent
11672 These settings are of interest when debugging C@t{++} programs:
11673
11674 @table @code
11675 @cindex demangling C@t{++} names
11676 @item set print demangle
11677 @itemx set print demangle on
11678 Print C@t{++} names in their source form rather than in the encoded
11679 (``mangled'') form passed to the assembler and linker for type-safe
11680 linkage. The default is on.
11681
11682 @item show print demangle
11683 Show whether C@t{++} names are printed in mangled or demangled form.
11684
11685 @item set print asm-demangle
11686 @itemx set print asm-demangle on
11687 Print C@t{++} names in their source form rather than their mangled form, even
11688 in assembler code printouts such as instruction disassemblies.
11689 The default is off.
11690
11691 @item show print asm-demangle
11692 Show whether C@t{++} names in assembly listings are printed in mangled
11693 or demangled form.
11694
11695 @cindex C@t{++} symbol decoding style
11696 @cindex symbol decoding style, C@t{++}
11697 @kindex set demangle-style
11698 @item set demangle-style @var{style}
11699 Choose among several encoding schemes used by different compilers to represent
11700 C@t{++} names. If you omit @var{style}, you will see a list of possible
11701 formats. The default value is @var{auto}, which lets @value{GDBN} choose a
11702 decoding style by inspecting your program.
11703
11704 @item show demangle-style
11705 Display the encoding style currently in use for decoding C@t{++} symbols.
11706
11707 @anchor{set print object}
11708 @item set print object
11709 @itemx set print object on
11710 @cindex derived type of an object, printing
11711 @cindex display derived types
11712 When displaying a pointer to an object, identify the @emph{actual}
11713 (derived) type of the object rather than the @emph{declared} type, using
11714 the virtual function table. Note that the virtual function table is
11715 required---this feature can only work for objects that have run-time
11716 type identification; a single virtual method in the object's declared
11717 type is sufficient. Note that this setting is also taken into account when
11718 working with variable objects via MI (@pxref{GDB/MI}).
11719
11720 @item set print object off
11721 Display only the declared type of objects, without reference to the
11722 virtual function table. This is the default setting.
11723
11724 @item show print object
11725 Show whether actual, or declared, object types are displayed.
11726
11727 @anchor{set print static-members}
11728 @item set print static-members
11729 @itemx set print static-members on
11730 @cindex static members of C@t{++} objects
11731 Print static members when displaying a C@t{++} object. The default is on.
11732
11733 @item set print static-members off
11734 Do not print static members when displaying a C@t{++} object.
11735
11736 @item show print static-members
11737 Show whether C@t{++} static members are printed or not.
11738
11739 @item set print pascal_static-members
11740 @itemx set print pascal_static-members on
11741 @cindex static members of Pascal objects
11742 @cindex Pascal objects, static members display
11743 Print static members when displaying a Pascal object. The default is on.
11744
11745 @item set print pascal_static-members off
11746 Do not print static members when displaying a Pascal object.
11747
11748 @item show print pascal_static-members
11749 Show whether Pascal static members are printed or not.
11750
11751 @c These don't work with HP ANSI C++ yet.
11752 @anchor{set print vtbl}
11753 @item set print vtbl
11754 @itemx set print vtbl on
11755 @cindex pretty print C@t{++} virtual function tables
11756 @cindex virtual functions (C@t{++}) display
11757 @cindex VTBL display
11758 Pretty print C@t{++} virtual function tables. The default is off.
11759 (The @code{vtbl} commands do not work on programs compiled with the HP
11760 ANSI C@t{++} compiler (@code{aCC}).)
11761
11762 @item set print vtbl off
11763 Do not pretty print C@t{++} virtual function tables.
11764
11765 @item show print vtbl
11766 Show whether C@t{++} virtual function tables are pretty printed, or not.
11767 @end table
11768
11769 @node Pretty Printing
11770 @section Pretty Printing
11771
11772 @value{GDBN} provides a mechanism to allow pretty-printing of values using
11773 Python code. It greatly simplifies the display of complex objects. This
11774 mechanism works for both MI and the CLI.
11775
11776 @menu
11777 * Pretty-Printer Introduction:: Introduction to pretty-printers
11778 * Pretty-Printer Example:: An example pretty-printer
11779 * Pretty-Printer Commands:: Pretty-printer commands
11780 @end menu
11781
11782 @node Pretty-Printer Introduction
11783 @subsection Pretty-Printer Introduction
11784
11785 When @value{GDBN} prints a value, it first sees if there is a pretty-printer
11786 registered for the value. If there is then @value{GDBN} invokes the
11787 pretty-printer to print the value. Otherwise the value is printed normally.
11788
11789 Pretty-printers are normally named. This makes them easy to manage.
11790 The @samp{info pretty-printer} command will list all the installed
11791 pretty-printers with their names.
11792 If a pretty-printer can handle multiple data types, then its
11793 @dfn{subprinters} are the printers for the individual data types.
11794 Each such subprinter has its own name.
11795 The format of the name is @var{printer-name};@var{subprinter-name}.
11796
11797 Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
11798 Typically they are automatically loaded and registered when the corresponding
11799 debug information is loaded, thus making them available without having to
11800 do anything special.
11801
11802 There are three places where a pretty-printer can be registered.
11803
11804 @itemize @bullet
11805 @item
11806 Pretty-printers registered globally are available when debugging
11807 all inferiors.
11808
11809 @item
11810 Pretty-printers registered with a program space are available only
11811 when debugging that program.
11812 @xref{Progspaces In Python}, for more details on program spaces in Python.
11813
11814 @item
11815 Pretty-printers registered with an objfile are loaded and unloaded
11816 with the corresponding objfile (e.g., shared library).
11817 @xref{Objfiles In Python}, for more details on objfiles in Python.
11818 @end itemize
11819
11820 @xref{Selecting Pretty-Printers}, for further information on how
11821 pretty-printers are selected,
11822
11823 @xref{Writing a Pretty-Printer}, for implementing pretty printers
11824 for new types.
11825
11826 @node Pretty-Printer Example
11827 @subsection Pretty-Printer Example
11828
11829 Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
11830
11831 @smallexample
11832 (@value{GDBP}) print s
11833 $1 = @{
11834 static npos = 4294967295,
11835 _M_dataplus = @{
11836 <std::allocator<char>> = @{
11837 <__gnu_cxx::new_allocator<char>> = @{
11838 <No data fields>@}, <No data fields>
11839 @},
11840 members of std::basic_string<char, std::char_traits<char>,
11841 std::allocator<char> >::_Alloc_hider:
11842 _M_p = 0x804a014 "abcd"
11843 @}
11844 @}
11845 @end smallexample
11846
11847 With a pretty-printer for @code{std::string} only the contents are printed:
11848
11849 @smallexample
11850 (@value{GDBP}) print s
11851 $2 = "abcd"
11852 @end smallexample
11853
11854 @node Pretty-Printer Commands
11855 @subsection Pretty-Printer Commands
11856 @cindex pretty-printer commands
11857
11858 @table @code
11859 @kindex info pretty-printer
11860 @item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11861 Print the list of installed pretty-printers.
11862 This includes disabled pretty-printers, which are marked as such.
11863
11864 @var{object-regexp} is a regular expression matching the objects
11865 whose pretty-printers to list.
11866 Objects can be @code{global}, the program space's file
11867 (@pxref{Progspaces In Python}),
11868 and the object files within that program space (@pxref{Objfiles In Python}).
11869 @xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
11870 looks up a printer from these three objects.
11871
11872 @var{name-regexp} is a regular expression matching the name of the printers
11873 to list.
11874
11875 @kindex disable pretty-printer
11876 @item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11877 Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11878 A disabled pretty-printer is not forgotten, it may be enabled again later.
11879
11880 @kindex enable pretty-printer
11881 @item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11882 Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11883 @end table
11884
11885 Example:
11886
11887 Suppose we have three pretty-printers installed: one from library1.so
11888 named @code{foo} that prints objects of type @code{foo}, and
11889 another from library2.so named @code{bar} that prints two types of objects,
11890 @code{bar1} and @code{bar2}.
11891
11892 @smallexample
11893 (gdb) info pretty-printer
11894 library1.so:
11895 foo
11896 library2.so:
11897 bar
11898 bar1
11899 bar2
11900 (gdb) info pretty-printer library2
11901 library2.so:
11902 bar
11903 bar1
11904 bar2
11905 (gdb) disable pretty-printer library1
11906 1 printer disabled
11907 2 of 3 printers enabled
11908 (gdb) info pretty-printer
11909 library1.so:
11910 foo [disabled]
11911 library2.so:
11912 bar
11913 bar1
11914 bar2
11915 (gdb) disable pretty-printer library2 bar;bar1
11916 1 printer disabled
11917 1 of 3 printers enabled
11918 (gdb) info pretty-printer library2
11919 library1.so:
11920 foo [disabled]
11921 library2.so:
11922 bar
11923 bar1 [disabled]
11924 bar2
11925 (gdb) disable pretty-printer library2 bar
11926 1 printer disabled
11927 0 of 3 printers enabled
11928 (gdb) info pretty-printer library2
11929 library1.so:
11930 foo [disabled]
11931 library2.so:
11932 bar [disabled]
11933 bar1 [disabled]
11934 bar2
11935 @end smallexample
11936
11937 Note that for @code{bar} the entire printer can be disabled,
11938 as can each individual subprinter.
11939
11940 Printing values and frame arguments is done by default using
11941 the enabled pretty printers.
11942
11943 The print option @code{-raw-values} and @value{GDBN} setting
11944 @code{set print raw-values} (@pxref{set print raw-values}) can be
11945 used to print values without applying the enabled pretty printers.
11946
11947 Similarly, the backtrace option @code{-raw-frame-arguments} and
11948 @value{GDBN} setting @code{set print raw-frame-arguments}
11949 (@pxref{set print raw-frame-arguments}) can be used to ignore the
11950 enabled pretty printers when printing frame argument values.
11951
11952 @node Value History
11953 @section Value History
11954
11955 @cindex value history
11956 @cindex history of values printed by @value{GDBN}
11957 Values printed by the @code{print} command are saved in the @value{GDBN}
11958 @dfn{value history}. This allows you to refer to them in other expressions.
11959 Values are kept until the symbol table is re-read or discarded
11960 (for example with the @code{file} or @code{symbol-file} commands).
11961 When the symbol table changes, the value history is discarded,
11962 since the values may contain pointers back to the types defined in the
11963 symbol table.
11964
11965 @cindex @code{$}
11966 @cindex @code{$$}
11967 @cindex history number
11968 The values printed are given @dfn{history numbers} by which you can
11969 refer to them. These are successive integers starting with one.
11970 @code{print} shows you the history number assigned to a value by
11971 printing @samp{$@var{num} = } before the value; here @var{num} is the
11972 history number.
11973
11974 To refer to any previous value, use @samp{$} followed by the value's
11975 history number. The way @code{print} labels its output is designed to
11976 remind you of this. Just @code{$} refers to the most recent value in
11977 the history, and @code{$$} refers to the value before that.
11978 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
11979 is the value just prior to @code{$$}, @code{$$1} is equivalent to
11980 @code{$$}, and @code{$$0} is equivalent to @code{$}.
11981
11982 For example, suppose you have just printed a pointer to a structure and
11983 want to see the contents of the structure. It suffices to type
11984
11985 @smallexample
11986 p *$
11987 @end smallexample
11988
11989 If you have a chain of structures where the component @code{next} points
11990 to the next one, you can print the contents of the next one with this:
11991
11992 @smallexample
11993 p *$.next
11994 @end smallexample
11995
11996 @noindent
11997 You can print successive links in the chain by repeating this
11998 command---which you can do by just typing @key{RET}.
11999
12000 Note that the history records values, not expressions. If the value of
12001 @code{x} is 4 and you type these commands:
12002
12003 @smallexample
12004 print x
12005 set x=5
12006 @end smallexample
12007
12008 @noindent
12009 then the value recorded in the value history by the @code{print} command
12010 remains 4 even though the value of @code{x} has changed.
12011
12012 @table @code
12013 @kindex show values
12014 @item show values
12015 Print the last ten values in the value history, with their item numbers.
12016 This is like @samp{p@ $$9} repeated ten times, except that @code{show
12017 values} does not change the history.
12018
12019 @item show values @var{n}
12020 Print ten history values centered on history item number @var{n}.
12021
12022 @item show values +
12023 Print ten history values just after the values last printed. If no more
12024 values are available, @code{show values +} produces no display.
12025 @end table
12026
12027 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
12028 same effect as @samp{show values +}.
12029
12030 @node Convenience Vars
12031 @section Convenience Variables
12032
12033 @cindex convenience variables
12034 @cindex user-defined variables
12035 @value{GDBN} provides @dfn{convenience variables} that you can use within
12036 @value{GDBN} to hold on to a value and refer to it later. These variables
12037 exist entirely within @value{GDBN}; they are not part of your program, and
12038 setting a convenience variable has no direct effect on further execution
12039 of your program. That is why you can use them freely.
12040
12041 Convenience variables are prefixed with @samp{$}. Any name preceded by
12042 @samp{$} can be used for a convenience variable, unless it is one of
12043 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
12044 (Value history references, in contrast, are @emph{numbers} preceded
12045 by @samp{$}. @xref{Value History, ,Value History}.)
12046
12047 You can save a value in a convenience variable with an assignment
12048 expression, just as you would set a variable in your program.
12049 For example:
12050
12051 @smallexample
12052 set $foo = *object_ptr
12053 @end smallexample
12054
12055 @noindent
12056 would save in @code{$foo} the value contained in the object pointed to by
12057 @code{object_ptr}.
12058
12059 Using a convenience variable for the first time creates it, but its
12060 value is @code{void} until you assign a new value. You can alter the
12061 value with another assignment at any time.
12062
12063 Convenience variables have no fixed types. You can assign a convenience
12064 variable any type of value, including structures and arrays, even if
12065 that variable already has a value of a different type. The convenience
12066 variable, when used as an expression, has the type of its current value.
12067
12068 @table @code
12069 @kindex show convenience
12070 @cindex show all user variables and functions
12071 @item show convenience
12072 Print a list of convenience variables used so far, and their values,
12073 as well as a list of the convenience functions.
12074 Abbreviated @code{show conv}.
12075
12076 @kindex init-if-undefined
12077 @cindex convenience variables, initializing
12078 @item init-if-undefined $@var{variable} = @var{expression}
12079 Set a convenience variable if it has not already been set. This is useful
12080 for user-defined commands that keep some state. It is similar, in concept,
12081 to using local static variables with initializers in C (except that
12082 convenience variables are global). It can also be used to allow users to
12083 override default values used in a command script.
12084
12085 If the variable is already defined then the expression is not evaluated so
12086 any side-effects do not occur.
12087 @end table
12088
12089 One of the ways to use a convenience variable is as a counter to be
12090 incremented or a pointer to be advanced. For example, to print
12091 a field from successive elements of an array of structures:
12092
12093 @smallexample
12094 set $i = 0
12095 print bar[$i++]->contents
12096 @end smallexample
12097
12098 @noindent
12099 Repeat that command by typing @key{RET}.
12100
12101 Some convenience variables are created automatically by @value{GDBN} and given
12102 values likely to be useful.
12103
12104 @table @code
12105 @vindex $_@r{, convenience variable}
12106 @item $_
12107 The variable @code{$_} is automatically set by the @code{x} command to
12108 the last address examined (@pxref{Memory, ,Examining Memory}). Other
12109 commands which provide a default address for @code{x} to examine also
12110 set @code{$_} to that address; these commands include @code{info line}
12111 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
12112 except when set by the @code{x} command, in which case it is a pointer
12113 to the type of @code{$__}.
12114
12115 @vindex $__@r{, convenience variable}
12116 @item $__
12117 The variable @code{$__} is automatically set by the @code{x} command
12118 to the value found in the last address examined. Its type is chosen
12119 to match the format in which the data was printed.
12120
12121 @item $_exitcode
12122 @vindex $_exitcode@r{, convenience variable}
12123 When the program being debugged terminates normally, @value{GDBN}
12124 automatically sets this variable to the exit code of the program, and
12125 resets @code{$_exitsignal} to @code{void}.
12126
12127 @item $_exitsignal
12128 @vindex $_exitsignal@r{, convenience variable}
12129 When the program being debugged dies due to an uncaught signal,
12130 @value{GDBN} automatically sets this variable to that signal's number,
12131 and resets @code{$_exitcode} to @code{void}.
12132
12133 To distinguish between whether the program being debugged has exited
12134 (i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
12135 @code{$_exitsignal} is not @code{void}), the convenience function
12136 @code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
12137 Functions}). For example, considering the following source code:
12138
12139 @smallexample
12140 #include <signal.h>
12141
12142 int
12143 main (int argc, char *argv[])
12144 @{
12145 raise (SIGALRM);
12146 return 0;
12147 @}
12148 @end smallexample
12149
12150 A valid way of telling whether the program being debugged has exited
12151 or signalled would be:
12152
12153 @smallexample
12154 (@value{GDBP}) define has_exited_or_signalled
12155 Type commands for definition of ``has_exited_or_signalled''.
12156 End with a line saying just ``end''.
12157 >if $_isvoid ($_exitsignal)
12158 >echo The program has exited\n
12159 >else
12160 >echo The program has signalled\n
12161 >end
12162 >end
12163 (@value{GDBP}) run
12164 Starting program:
12165
12166 Program terminated with signal SIGALRM, Alarm clock.
12167 The program no longer exists.
12168 (@value{GDBP}) has_exited_or_signalled
12169 The program has signalled
12170 @end smallexample
12171
12172 As can be seen, @value{GDBN} correctly informs that the program being
12173 debugged has signalled, since it calls @code{raise} and raises a
12174 @code{SIGALRM} signal. If the program being debugged had not called
12175 @code{raise}, then @value{GDBN} would report a normal exit:
12176
12177 @smallexample
12178 (@value{GDBP}) has_exited_or_signalled
12179 The program has exited
12180 @end smallexample
12181
12182 @item $_exception
12183 The variable @code{$_exception} is set to the exception object being
12184 thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
12185
12186 @item $_ada_exception
12187 The variable @code{$_ada_exception} is set to the address of the
12188 exception being caught or thrown at an Ada exception-related
12189 catchpoint. @xref{Set Catchpoints}.
12190
12191 @item $_probe_argc
12192 @itemx $_probe_arg0@dots{}$_probe_arg11
12193 Arguments to a static probe. @xref{Static Probe Points}.
12194
12195 @item $_sdata
12196 @vindex $_sdata@r{, inspect, convenience variable}
12197 The variable @code{$_sdata} contains extra collected static tracepoint
12198 data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
12199 @code{$_sdata} could be empty, if not inspecting a trace buffer, or
12200 if extra static tracepoint data has not been collected.
12201
12202 @item $_siginfo
12203 @vindex $_siginfo@r{, convenience variable}
12204 The variable @code{$_siginfo} contains extra signal information
12205 (@pxref{extra signal information}). Note that @code{$_siginfo}
12206 could be empty, if the application has not yet received any signals.
12207 For example, it will be empty before you execute the @code{run} command.
12208
12209 @item $_tlb
12210 @vindex $_tlb@r{, convenience variable}
12211 The variable @code{$_tlb} is automatically set when debugging
12212 applications running on MS-Windows in native mode or connected to
12213 gdbserver that supports the @code{qGetTIBAddr} request.
12214 @xref{General Query Packets}.
12215 This variable contains the address of the thread information block.
12216
12217 @item $_inferior
12218 The number of the current inferior. @xref{Inferiors Connections and
12219 Programs, ,Debugging Multiple Inferiors Connections and Programs}.
12220
12221 @item $_thread
12222 The thread number of the current thread. @xref{thread numbers}.
12223
12224 @item $_gthread
12225 The global number of the current thread. @xref{global thread numbers}.
12226
12227 @item $_gdb_major
12228 @itemx $_gdb_minor
12229 @vindex $_gdb_major@r{, convenience variable}
12230 @vindex $_gdb_minor@r{, convenience variable}
12231 The major and minor version numbers of the running @value{GDBN}.
12232 Development snapshots and pretest versions have their minor version
12233 incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
12234 the value 12 for @code{$_gdb_minor}. These variables allow you to
12235 write scripts that work with different versions of @value{GDBN}
12236 without errors caused by features unavailable in some of those
12237 versions.
12238
12239 @item $_shell_exitcode
12240 @itemx $_shell_exitsignal
12241 @vindex $_shell_exitcode@r{, convenience variable}
12242 @vindex $_shell_exitsignal@r{, convenience variable}
12243 @cindex shell command, exit code
12244 @cindex shell command, exit signal
12245 @cindex exit status of shell commands
12246 @value{GDBN} commands such as @code{shell} and @code{|} are launching
12247 shell commands. When a launched command terminates, @value{GDBN}
12248 automatically maintains the variables @code{$_shell_exitcode}
12249 and @code{$_shell_exitsignal} according to the exit status of the last
12250 launched command. These variables are set and used similarly to
12251 the variables @code{$_exitcode} and @code{$_exitsignal}.
12252
12253 @end table
12254
12255 @node Convenience Funs
12256 @section Convenience Functions
12257
12258 @cindex convenience functions
12259 @value{GDBN} also supplies some @dfn{convenience functions}. These
12260 have a syntax similar to convenience variables. A convenience
12261 function can be used in an expression just like an ordinary function;
12262 however, a convenience function is implemented internally to
12263 @value{GDBN}.
12264
12265 These functions do not require @value{GDBN} to be configured with
12266 @code{Python} support, which means that they are always available.
12267
12268 @table @code
12269
12270 @item $_isvoid (@var{expr})
12271 @findex $_isvoid@r{, convenience function}
12272 Return one if the expression @var{expr} is @code{void}. Otherwise it
12273 returns zero.
12274
12275 A @code{void} expression is an expression where the type of the result
12276 is @code{void}. For example, you can examine a convenience variable
12277 (see @ref{Convenience Vars,, Convenience Variables}) to check whether
12278 it is @code{void}:
12279
12280 @smallexample
12281 (@value{GDBP}) print $_exitcode
12282 $1 = void
12283 (@value{GDBP}) print $_isvoid ($_exitcode)
12284 $2 = 1
12285 (@value{GDBP}) run
12286 Starting program: ./a.out
12287 [Inferior 1 (process 29572) exited normally]
12288 (@value{GDBP}) print $_exitcode
12289 $3 = 0
12290 (@value{GDBP}) print $_isvoid ($_exitcode)
12291 $4 = 0
12292 @end smallexample
12293
12294 In the example above, we used @code{$_isvoid} to check whether
12295 @code{$_exitcode} is @code{void} before and after the execution of the
12296 program being debugged. Before the execution there is no exit code to
12297 be examined, therefore @code{$_exitcode} is @code{void}. After the
12298 execution the program being debugged returned zero, therefore
12299 @code{$_exitcode} is zero, which means that it is not @code{void}
12300 anymore.
12301
12302 The @code{void} expression can also be a call of a function from the
12303 program being debugged. For example, given the following function:
12304
12305 @smallexample
12306 void
12307 foo (void)
12308 @{
12309 @}
12310 @end smallexample
12311
12312 The result of calling it inside @value{GDBN} is @code{void}:
12313
12314 @smallexample
12315 (@value{GDBP}) print foo ()
12316 $1 = void
12317 (@value{GDBP}) print $_isvoid (foo ())
12318 $2 = 1
12319 (@value{GDBP}) set $v = foo ()
12320 (@value{GDBP}) print $v
12321 $3 = void
12322 (@value{GDBP}) print $_isvoid ($v)
12323 $4 = 1
12324 @end smallexample
12325
12326 @item $_gdb_setting_str (@var{setting})
12327 @findex $_gdb_setting_str@r{, convenience function}
12328 Return the value of the @value{GDBN} @var{setting} as a string.
12329 @var{setting} is any setting that can be used in a @code{set} or
12330 @code{show} command (@pxref{Controlling GDB}).
12331
12332 @smallexample
12333 (@value{GDBP}) show print frame-arguments
12334 Printing of non-scalar frame arguments is "scalars".
12335 (@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12336 $1 = "scalars"
12337 (@value{GDBP}) p $_gdb_setting_str("height")
12338 $2 = "30"
12339 (@value{GDBP})
12340 @end smallexample
12341
12342 @item $_gdb_setting (@var{setting})
12343 @findex $_gdb_setting@r{, convenience function}
12344 Return the value of the @value{GDBN} @var{setting}.
12345 The type of the returned value depends on the setting.
12346
12347 The value type for boolean and auto boolean settings is @code{int}.
12348 The boolean values @code{off} and @code{on} are converted to
12349 the integer values @code{0} and @code{1}. The value @code{auto} is
12350 converted to the value @code{-1}.
12351
12352 The value type for integer settings is either @code{unsigned int}
12353 or @code{int}, depending on the setting.
12354
12355 Some integer settings accept an @code{unlimited} value.
12356 Depending on the setting, the @code{set} command also accepts
12357 the value @code{0} or the value @code{@minus{}1} as a synonym for
12358 @code{unlimited}.
12359 For example, @code{set height unlimited} is equivalent to
12360 @code{set height 0}.
12361
12362 Some other settings that accept the @code{unlimited} value
12363 use the value @code{0} to literally mean zero.
12364 For example, @code{set history size 0} indicates to not
12365 record any @value{GDBN} commands in the command history.
12366 For such settings, @code{@minus{}1} is the synonym
12367 for @code{unlimited}.
12368
12369 See the documentation of the corresponding @code{set} command for
12370 the numerical value equivalent to @code{unlimited}.
12371
12372 The @code{$_gdb_setting} function converts the unlimited value
12373 to a @code{0} or a @code{@minus{}1} value according to what the
12374 @code{set} command uses.
12375
12376 @smallexample
12377 @group
12378 (@value{GDBP}) p $_gdb_setting_str("height")
12379 $1 = "30"
12380 (@value{GDBP}) p $_gdb_setting("height")
12381 $2 = 30
12382 (@value{GDBP}) set height unlimited
12383 (@value{GDBP}) p $_gdb_setting_str("height")
12384 $3 = "unlimited"
12385 (@value{GDBP}) p $_gdb_setting("height")
12386 $4 = 0
12387 @end group
12388 @group
12389 (@value{GDBP}) p $_gdb_setting_str("history size")
12390 $5 = "unlimited"
12391 (@value{GDBP}) p $_gdb_setting("history size")
12392 $6 = -1
12393 (@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12394 $7 = "auto"
12395 (@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12396 $8 = -1
12397 (@value{GDBP})
12398 @end group
12399 @end smallexample
12400
12401 Other setting types (enum, filename, optional filename, string, string noescape)
12402 are returned as string values.
12403
12404
12405 @item $_gdb_maint_setting_str (@var{setting})
12406 @findex $_gdb_maint_setting_str@r{, convenience function}
12407 Like the @code{$_gdb_setting_str} function, but works with
12408 @code{maintenance set} variables.
12409
12410 @item $_gdb_maint_setting (@var{setting})
12411 @findex $_gdb_maint_setting@r{, convenience function}
12412 Like the @code{$_gdb_setting} function, but works with
12413 @code{maintenance set} variables.
12414
12415 @end table
12416
12417 The following functions require @value{GDBN} to be configured with
12418 @code{Python} support.
12419
12420 @table @code
12421
12422 @item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12423 @findex $_memeq@r{, convenience function}
12424 Returns one if the @var{length} bytes at the addresses given by
12425 @var{buf1} and @var{buf2} are equal.
12426 Otherwise it returns zero.
12427
12428 @item $_regex(@var{str}, @var{regex})
12429 @findex $_regex@r{, convenience function}
12430 Returns one if the string @var{str} matches the regular expression
12431 @var{regex}. Otherwise it returns zero.
12432 The syntax of the regular expression is that specified by @code{Python}'s
12433 regular expression support.
12434
12435 @item $_streq(@var{str1}, @var{str2})
12436 @findex $_streq@r{, convenience function}
12437 Returns one if the strings @var{str1} and @var{str2} are equal.
12438 Otherwise it returns zero.
12439
12440 @item $_strlen(@var{str})
12441 @findex $_strlen@r{, convenience function}
12442 Returns the length of string @var{str}.
12443
12444 @item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12445 @findex $_caller_is@r{, convenience function}
12446 Returns one if the calling function's name is equal to @var{name}.
12447 Otherwise it returns zero.
12448
12449 If the optional argument @var{number_of_frames} is provided,
12450 it is the number of frames up in the stack to look.
12451 The default is 1.
12452
12453 Example:
12454
12455 @smallexample
12456 (gdb) backtrace
12457 #0 bottom_func ()
12458 at testsuite/gdb.python/py-caller-is.c:21
12459 #1 0x00000000004005a0 in middle_func ()
12460 at testsuite/gdb.python/py-caller-is.c:27
12461 #2 0x00000000004005ab in top_func ()
12462 at testsuite/gdb.python/py-caller-is.c:33
12463 #3 0x00000000004005b6 in main ()
12464 at testsuite/gdb.python/py-caller-is.c:39
12465 (gdb) print $_caller_is ("middle_func")
12466 $1 = 1
12467 (gdb) print $_caller_is ("top_func", 2)
12468 $1 = 1
12469 @end smallexample
12470
12471 @item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12472 @findex $_caller_matches@r{, convenience function}
12473 Returns one if the calling function's name matches the regular expression
12474 @var{regexp}. Otherwise it returns zero.
12475
12476 If the optional argument @var{number_of_frames} is provided,
12477 it is the number of frames up in the stack to look.
12478 The default is 1.
12479
12480 @item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12481 @findex $_any_caller_is@r{, convenience function}
12482 Returns one if any calling function's name is equal to @var{name}.
12483 Otherwise it returns zero.
12484
12485 If the optional argument @var{number_of_frames} is provided,
12486 it is the number of frames up in the stack to look.
12487 The default is 1.
12488
12489 This function differs from @code{$_caller_is} in that this function
12490 checks all stack frames from the immediate caller to the frame specified
12491 by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12492 frame specified by @var{number_of_frames}.
12493
12494 @item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12495 @findex $_any_caller_matches@r{, convenience function}
12496 Returns one if any calling function's name matches the regular expression
12497 @var{regexp}. Otherwise it returns zero.
12498
12499 If the optional argument @var{number_of_frames} is provided,
12500 it is the number of frames up in the stack to look.
12501 The default is 1.
12502
12503 This function differs from @code{$_caller_matches} in that this function
12504 checks all stack frames from the immediate caller to the frame specified
12505 by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12506 frame specified by @var{number_of_frames}.
12507
12508 @item $_as_string(@var{value})
12509 @findex $_as_string@r{, convenience function}
12510 Return the string representation of @var{value}.
12511
12512 This function is useful to obtain the textual label (enumerator) of an
12513 enumeration value. For example, assuming the variable @var{node} is of
12514 an enumerated type:
12515
12516 @smallexample
12517 (gdb) printf "Visiting node of type %s\n", $_as_string(node)
12518 Visiting node of type NODE_INTEGER
12519 @end smallexample
12520
12521 @item $_cimag(@var{value})
12522 @itemx $_creal(@var{value})
12523 @findex $_cimag@r{, convenience function}
12524 @findex $_creal@r{, convenience function}
12525 Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12526 the complex number @var{value}.
12527
12528 The type of the imaginary or real part depends on the type of the
12529 complex number, e.g., using @code{$_cimag} on a @code{float complex}
12530 will return an imaginary part of type @code{float}.
12531
12532 @end table
12533
12534 @value{GDBN} provides the ability to list and get help on
12535 convenience functions.
12536
12537 @table @code
12538 @item help function
12539 @kindex help function
12540 @cindex show all convenience functions
12541 Print a list of all convenience functions.
12542 @end table
12543
12544 @node Registers
12545 @section Registers
12546
12547 @cindex registers
12548 You can refer to machine register contents, in expressions, as variables
12549 with names starting with @samp{$}. The names of registers are different
12550 for each machine; use @code{info registers} to see the names used on
12551 your machine.
12552
12553 @table @code
12554 @kindex info registers
12555 @item info registers
12556 Print the names and values of all registers except floating-point
12557 and vector registers (in the selected stack frame).
12558
12559 @kindex info all-registers
12560 @cindex floating point registers
12561 @item info all-registers
12562 Print the names and values of all registers, including floating-point
12563 and vector registers (in the selected stack frame).
12564
12565 @anchor{info_registers_reggroup}
12566 @item info registers @var{reggroup} @dots{}
12567 Print the name and value of the registers in each of the specified
12568 @var{reggroup}s. The @var{reggroup} can be any of those returned by
12569 @code{maint print reggroups} (@pxref{Maintenance Commands}).
12570
12571 @item info registers @var{regname} @dots{}
12572 Print the @dfn{relativized} value of each specified register @var{regname}.
12573 As discussed in detail below, register values are normally relative to
12574 the selected stack frame. The @var{regname} may be any register name valid on
12575 the machine you are using, with or without the initial @samp{$}.
12576 @end table
12577
12578 @anchor{standard registers}
12579 @cindex stack pointer register
12580 @cindex program counter register
12581 @cindex process status register
12582 @cindex frame pointer register
12583 @cindex standard registers
12584 @value{GDBN} has four ``standard'' register names that are available (in
12585 expressions) on most machines---whenever they do not conflict with an
12586 architecture's canonical mnemonics for registers. The register names
12587 @code{$pc} and @code{$sp} are used for the program counter register and
12588 the stack pointer. @code{$fp} is used for a register that contains a
12589 pointer to the current stack frame, and @code{$ps} is used for a
12590 register that contains the processor status. For example,
12591 you could print the program counter in hex with
12592
12593 @smallexample
12594 p/x $pc
12595 @end smallexample
12596
12597 @noindent
12598 or print the instruction to be executed next with
12599
12600 @smallexample
12601 x/i $pc
12602 @end smallexample
12603
12604 @noindent
12605 or add four to the stack pointer@footnote{This is a way of removing
12606 one word from the stack, on machines where stacks grow downward in
12607 memory (most machines, nowadays). This assumes that the innermost
12608 stack frame is selected; setting @code{$sp} is not allowed when other
12609 stack frames are selected. To pop entire frames off the stack,
12610 regardless of machine architecture, use @code{return};
12611 see @ref{Returning, ,Returning from a Function}.} with
12612
12613 @smallexample
12614 set $sp += 4
12615 @end smallexample
12616
12617 Whenever possible, these four standard register names are available on
12618 your machine even though the machine has different canonical mnemonics,
12619 so long as there is no conflict. The @code{info registers} command
12620 shows the canonical names. For example, on the SPARC, @code{info
12621 registers} displays the processor status register as @code{$psr} but you
12622 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12623 is an alias for the @sc{eflags} register.
12624
12625 @value{GDBN} always considers the contents of an ordinary register as an
12626 integer when the register is examined in this way. Some machines have
12627 special registers which can hold nothing but floating point; these
12628 registers are considered to have floating point values. There is no way
12629 to refer to the contents of an ordinary register as floating point value
12630 (although you can @emph{print} it as a floating point value with
12631 @samp{print/f $@var{regname}}).
12632
12633 Some registers have distinct ``raw'' and ``virtual'' data formats. This
12634 means that the data format in which the register contents are saved by
12635 the operating system is not the same one that your program normally
12636 sees. For example, the registers of the 68881 floating point
12637 coprocessor are always saved in ``extended'' (raw) format, but all C
12638 programs expect to work with ``double'' (virtual) format. In such
12639 cases, @value{GDBN} normally works with the virtual format only (the format
12640 that makes sense for your program), but the @code{info registers} command
12641 prints the data in both formats.
12642
12643 @cindex SSE registers (x86)
12644 @cindex MMX registers (x86)
12645 Some machines have special registers whose contents can be interpreted
12646 in several different ways. For example, modern x86-based machines
12647 have SSE and MMX registers that can hold several values packed
12648 together in several different formats. @value{GDBN} refers to such
12649 registers in @code{struct} notation:
12650
12651 @smallexample
12652 (@value{GDBP}) print $xmm1
12653 $1 = @{
12654 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
12655 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
12656 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
12657 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
12658 v4_int32 = @{0, 20657912, 11, 13@},
12659 v2_int64 = @{88725056443645952, 55834574859@},
12660 uint128 = 0x0000000d0000000b013b36f800000000
12661 @}
12662 @end smallexample
12663
12664 @noindent
12665 To set values of such registers, you need to tell @value{GDBN} which
12666 view of the register you wish to change, as if you were assigning
12667 value to a @code{struct} member:
12668
12669 @smallexample
12670 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
12671 @end smallexample
12672
12673 Normally, register values are relative to the selected stack frame
12674 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
12675 value that the register would contain if all stack frames farther in
12676 were exited and their saved registers restored. In order to see the
12677 true contents of hardware registers, you must select the innermost
12678 frame (with @samp{frame 0}).
12679
12680 @cindex caller-saved registers
12681 @cindex call-clobbered registers
12682 @cindex volatile registers
12683 @cindex <not saved> values
12684 Usually ABIs reserve some registers as not needed to be saved by the
12685 callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
12686 registers). It may therefore not be possible for @value{GDBN} to know
12687 the value a register had before the call (in other words, in the outer
12688 frame), if the register value has since been changed by the callee.
12689 @value{GDBN} tries to deduce where the inner frame saved
12690 (``callee-saved'') registers, from the debug info, unwind info, or the
12691 machine code generated by your compiler. If some register is not
12692 saved, and @value{GDBN} knows the register is ``caller-saved'' (via
12693 its own knowledge of the ABI, or because the debug/unwind info
12694 explicitly says the register's value is undefined), @value{GDBN}
12695 displays @w{@samp{<not saved>}} as the register's value. With targets
12696 that @value{GDBN} has no knowledge of the register saving convention,
12697 if a register was not saved by the callee, then its value and location
12698 in the outer frame are assumed to be the same of the inner frame.
12699 This is usually harmless, because if the register is call-clobbered,
12700 the caller either does not care what is in the register after the
12701 call, or has code to restore the value that it does care about. Note,
12702 however, that if you change such a register in the outer frame, you
12703 may also be affecting the inner frame. Also, the more ``outer'' the
12704 frame is you're looking at, the more likely a call-clobbered
12705 register's value is to be wrong, in the sense that it doesn't actually
12706 represent the value the register had just before the call.
12707
12708 @node Floating Point Hardware
12709 @section Floating Point Hardware
12710 @cindex floating point
12711
12712 Depending on the configuration, @value{GDBN} may be able to give
12713 you more information about the status of the floating point hardware.
12714
12715 @table @code
12716 @kindex info float
12717 @item info float
12718 Display hardware-dependent information about the floating
12719 point unit. The exact contents and layout vary depending on the
12720 floating point chip. Currently, @samp{info float} is supported on
12721 the ARM and x86 machines.
12722 @end table
12723
12724 @node Vector Unit
12725 @section Vector Unit
12726 @cindex vector unit
12727
12728 Depending on the configuration, @value{GDBN} may be able to give you
12729 more information about the status of the vector unit.
12730
12731 @table @code
12732 @kindex info vector
12733 @item info vector
12734 Display information about the vector unit. The exact contents and
12735 layout vary depending on the hardware.
12736 @end table
12737
12738 @node OS Information
12739 @section Operating System Auxiliary Information
12740 @cindex OS information
12741
12742 @value{GDBN} provides interfaces to useful OS facilities that can help
12743 you debug your program.
12744
12745 @cindex auxiliary vector
12746 @cindex vector, auxiliary
12747 Some operating systems supply an @dfn{auxiliary vector} to programs at
12748 startup. This is akin to the arguments and environment that you
12749 specify for a program, but contains a system-dependent variety of
12750 binary values that tell system libraries important details about the
12751 hardware, operating system, and process. Each value's purpose is
12752 identified by an integer tag; the meanings are well-known but system-specific.
12753 Depending on the configuration and operating system facilities,
12754 @value{GDBN} may be able to show you this information. For remote
12755 targets, this functionality may further depend on the remote stub's
12756 support of the @samp{qXfer:auxv:read} packet, see
12757 @ref{qXfer auxiliary vector read}.
12758
12759 @table @code
12760 @kindex info auxv
12761 @item info auxv
12762 Display the auxiliary vector of the inferior, which can be either a
12763 live process or a core dump file. @value{GDBN} prints each tag value
12764 numerically, and also shows names and text descriptions for recognized
12765 tags. Some values in the vector are numbers, some bit masks, and some
12766 pointers to strings or other data. @value{GDBN} displays each value in the
12767 most appropriate form for a recognized tag, and in hexadecimal for
12768 an unrecognized tag.
12769 @end table
12770
12771 On some targets, @value{GDBN} can access operating system-specific
12772 information and show it to you. The types of information available
12773 will differ depending on the type of operating system running on the
12774 target. The mechanism used to fetch the data is described in
12775 @ref{Operating System Information}. For remote targets, this
12776 functionality depends on the remote stub's support of the
12777 @samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
12778
12779 @table @code
12780 @kindex info os
12781 @item info os @var{infotype}
12782
12783 Display OS information of the requested type.
12784
12785 On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
12786
12787 @anchor{linux info os infotypes}
12788 @table @code
12789 @kindex info os cpus
12790 @item cpus
12791 Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
12792 the available fields from /proc/cpuinfo. For each supported architecture
12793 different fields are available. Two common entries are processor which gives
12794 CPU number and bogomips; a system constant that is calculated during
12795 kernel initialization.
12796
12797 @kindex info os files
12798 @item files
12799 Display the list of open file descriptors on the target. For each
12800 file descriptor, @value{GDBN} prints the identifier of the process
12801 owning the descriptor, the command of the owning process, the value
12802 of the descriptor, and the target of the descriptor.
12803
12804 @kindex info os modules
12805 @item modules
12806 Display the list of all loaded kernel modules on the target. For each
12807 module, @value{GDBN} prints the module name, the size of the module in
12808 bytes, the number of times the module is used, the dependencies of the
12809 module, the status of the module, and the address of the loaded module
12810 in memory.
12811
12812 @kindex info os msg
12813 @item msg
12814 Display the list of all System V message queues on the target. For each
12815 message queue, @value{GDBN} prints the message queue key, the message
12816 queue identifier, the access permissions, the current number of bytes
12817 on the queue, the current number of messages on the queue, the processes
12818 that last sent and received a message on the queue, the user and group
12819 of the owner and creator of the message queue, the times at which a
12820 message was last sent and received on the queue, and the time at which
12821 the message queue was last changed.
12822
12823 @kindex info os processes
12824 @item processes
12825 Display the list of processes on the target. For each process,
12826 @value{GDBN} prints the process identifier, the name of the user, the
12827 command corresponding to the process, and the list of processor cores
12828 that the process is currently running on. (To understand what these
12829 properties mean, for this and the following info types, please consult
12830 the general @sc{gnu}/Linux documentation.)
12831
12832 @kindex info os procgroups
12833 @item procgroups
12834 Display the list of process groups on the target. For each process,
12835 @value{GDBN} prints the identifier of the process group that it belongs
12836 to, the command corresponding to the process group leader, the process
12837 identifier, and the command line of the process. The list is sorted
12838 first by the process group identifier, then by the process identifier,
12839 so that processes belonging to the same process group are grouped together
12840 and the process group leader is listed first.
12841
12842 @kindex info os semaphores
12843 @item semaphores
12844 Display the list of all System V semaphore sets on the target. For each
12845 semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
12846 set identifier, the access permissions, the number of semaphores in the
12847 set, the user and group of the owner and creator of the semaphore set,
12848 and the times at which the semaphore set was operated upon and changed.
12849
12850 @kindex info os shm
12851 @item shm
12852 Display the list of all System V shared-memory regions on the target.
12853 For each shared-memory region, @value{GDBN} prints the region key,
12854 the shared-memory identifier, the access permissions, the size of the
12855 region, the process that created the region, the process that last
12856 attached to or detached from the region, the current number of live
12857 attaches to the region, and the times at which the region was last
12858 attached to, detach from, and changed.
12859
12860 @kindex info os sockets
12861 @item sockets
12862 Display the list of Internet-domain sockets on the target. For each
12863 socket, @value{GDBN} prints the address and port of the local and
12864 remote endpoints, the current state of the connection, the creator of
12865 the socket, the IP address family of the socket, and the type of the
12866 connection.
12867
12868 @kindex info os threads
12869 @item threads
12870 Display the list of threads running on the target. For each thread,
12871 @value{GDBN} prints the identifier of the process that the thread
12872 belongs to, the command of the process, the thread identifier, and the
12873 processor core that it is currently running on. The main thread of a
12874 process is not listed.
12875 @end table
12876
12877 @item info os
12878 If @var{infotype} is omitted, then list the possible values for
12879 @var{infotype} and the kind of OS information available for each
12880 @var{infotype}. If the target does not return a list of possible
12881 types, this command will report an error.
12882 @end table
12883
12884 @node Memory Region Attributes
12885 @section Memory Region Attributes
12886 @cindex memory region attributes
12887
12888 @dfn{Memory region attributes} allow you to describe special handling
12889 required by regions of your target's memory. @value{GDBN} uses
12890 attributes to determine whether to allow certain types of memory
12891 accesses; whether to use specific width accesses; and whether to cache
12892 target memory. By default the description of memory regions is
12893 fetched from the target (if the current target supports this), but the
12894 user can override the fetched regions.
12895
12896 Defined memory regions can be individually enabled and disabled. When a
12897 memory region is disabled, @value{GDBN} uses the default attributes when
12898 accessing memory in that region. Similarly, if no memory regions have
12899 been defined, @value{GDBN} uses the default attributes when accessing
12900 all memory.
12901
12902 When a memory region is defined, it is given a number to identify it;
12903 to enable, disable, or remove a memory region, you specify that number.
12904
12905 @table @code
12906 @kindex mem
12907 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
12908 Define a memory region bounded by @var{lower} and @var{upper} with
12909 attributes @var{attributes}@dots{}, and add it to the list of regions
12910 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
12911 case: it is treated as the target's maximum memory address.
12912 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
12913
12914 @item mem auto
12915 Discard any user changes to the memory regions and use target-supplied
12916 regions, if available, or no regions if the target does not support.
12917
12918 @kindex delete mem
12919 @item delete mem @var{nums}@dots{}
12920 Remove memory regions @var{nums}@dots{} from the list of regions
12921 monitored by @value{GDBN}.
12922
12923 @kindex disable mem
12924 @item disable mem @var{nums}@dots{}
12925 Disable monitoring of memory regions @var{nums}@dots{}.
12926 A disabled memory region is not forgotten.
12927 It may be enabled again later.
12928
12929 @kindex enable mem
12930 @item enable mem @var{nums}@dots{}
12931 Enable monitoring of memory regions @var{nums}@dots{}.
12932
12933 @kindex info mem
12934 @item info mem
12935 Print a table of all defined memory regions, with the following columns
12936 for each region:
12937
12938 @table @emph
12939 @item Memory Region Number
12940 @item Enabled or Disabled.
12941 Enabled memory regions are marked with @samp{y}.
12942 Disabled memory regions are marked with @samp{n}.
12943
12944 @item Lo Address
12945 The address defining the inclusive lower bound of the memory region.
12946
12947 @item Hi Address
12948 The address defining the exclusive upper bound of the memory region.
12949
12950 @item Attributes
12951 The list of attributes set for this memory region.
12952 @end table
12953 @end table
12954
12955
12956 @subsection Attributes
12957
12958 @subsubsection Memory Access Mode
12959 The access mode attributes set whether @value{GDBN} may make read or
12960 write accesses to a memory region.
12961
12962 While these attributes prevent @value{GDBN} from performing invalid
12963 memory accesses, they do nothing to prevent the target system, I/O DMA,
12964 etc.@: from accessing memory.
12965
12966 @table @code
12967 @item ro
12968 Memory is read only.
12969 @item wo
12970 Memory is write only.
12971 @item rw
12972 Memory is read/write. This is the default.
12973 @end table
12974
12975 @subsubsection Memory Access Size
12976 The access size attribute tells @value{GDBN} to use specific sized
12977 accesses in the memory region. Often memory mapped device registers
12978 require specific sized accesses. If no access size attribute is
12979 specified, @value{GDBN} may use accesses of any size.
12980
12981 @table @code
12982 @item 8
12983 Use 8 bit memory accesses.
12984 @item 16
12985 Use 16 bit memory accesses.
12986 @item 32
12987 Use 32 bit memory accesses.
12988 @item 64
12989 Use 64 bit memory accesses.
12990 @end table
12991
12992 @c @subsubsection Hardware/Software Breakpoints
12993 @c The hardware/software breakpoint attributes set whether @value{GDBN}
12994 @c will use hardware or software breakpoints for the internal breakpoints
12995 @c used by the step, next, finish, until, etc. commands.
12996 @c
12997 @c @table @code
12998 @c @item hwbreak
12999 @c Always use hardware breakpoints
13000 @c @item swbreak (default)
13001 @c @end table
13002
13003 @subsubsection Data Cache
13004 The data cache attributes set whether @value{GDBN} will cache target
13005 memory. While this generally improves performance by reducing debug
13006 protocol overhead, it can lead to incorrect results because @value{GDBN}
13007 does not know about volatile variables or memory mapped device
13008 registers.
13009
13010 @table @code
13011 @item cache
13012 Enable @value{GDBN} to cache target memory.
13013 @item nocache
13014 Disable @value{GDBN} from caching target memory. This is the default.
13015 @end table
13016
13017 @subsection Memory Access Checking
13018 @value{GDBN} can be instructed to refuse accesses to memory that is
13019 not explicitly described. This can be useful if accessing such
13020 regions has undesired effects for a specific target, or to provide
13021 better error checking. The following commands control this behaviour.
13022
13023 @table @code
13024 @kindex set mem inaccessible-by-default
13025 @item set mem inaccessible-by-default [on|off]
13026 If @code{on} is specified, make @value{GDBN} treat memory not
13027 explicitly described by the memory ranges as non-existent and refuse accesses
13028 to such memory. The checks are only performed if there's at least one
13029 memory range defined. If @code{off} is specified, make @value{GDBN}
13030 treat the memory not explicitly described by the memory ranges as RAM.
13031 The default value is @code{on}.
13032 @kindex show mem inaccessible-by-default
13033 @item show mem inaccessible-by-default
13034 Show the current handling of accesses to unknown memory.
13035 @end table
13036
13037
13038 @c @subsubsection Memory Write Verification
13039 @c The memory write verification attributes set whether @value{GDBN}
13040 @c will re-reads data after each write to verify the write was successful.
13041 @c
13042 @c @table @code
13043 @c @item verify
13044 @c @item noverify (default)
13045 @c @end table
13046
13047 @node Dump/Restore Files
13048 @section Copy Between Memory and a File
13049 @cindex dump/restore files
13050 @cindex append data to a file
13051 @cindex dump data to a file
13052 @cindex restore data from a file
13053
13054 You can use the commands @code{dump}, @code{append}, and
13055 @code{restore} to copy data between target memory and a file. The
13056 @code{dump} and @code{append} commands write data to a file, and the
13057 @code{restore} command reads data from a file back into the inferior's
13058 memory. Files may be in binary, Motorola S-record, Intel hex,
13059 Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
13060 append to binary files, and cannot read from Verilog Hex files.
13061
13062 @table @code
13063
13064 @kindex dump
13065 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13066 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
13067 Dump the contents of memory from @var{start_addr} to @var{end_addr},
13068 or the value of @var{expr}, to @var{filename} in the given format.
13069
13070 The @var{format} parameter may be any one of:
13071 @table @code
13072 @item binary
13073 Raw binary form.
13074 @item ihex
13075 Intel hex format.
13076 @item srec
13077 Motorola S-record format.
13078 @item tekhex
13079 Tektronix Hex format.
13080 @item verilog
13081 Verilog Hex format.
13082 @end table
13083
13084 @value{GDBN} uses the same definitions of these formats as the
13085 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
13086 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
13087 form.
13088
13089 @kindex append
13090 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13091 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
13092 Append the contents of memory from @var{start_addr} to @var{end_addr},
13093 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
13094 (@value{GDBN} can only append data to files in raw binary form.)
13095
13096 @kindex restore
13097 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
13098 Restore the contents of file @var{filename} into memory. The
13099 @code{restore} command can automatically recognize any known @sc{bfd}
13100 file format, except for raw binary. To restore a raw binary file you
13101 must specify the optional keyword @code{binary} after the filename.
13102
13103 If @var{bias} is non-zero, its value will be added to the addresses
13104 contained in the file. Binary files always start at address zero, so
13105 they will be restored at address @var{bias}. Other bfd files have
13106 a built-in location; they will be restored at offset @var{bias}
13107 from that location.
13108
13109 If @var{start} and/or @var{end} are non-zero, then only data between
13110 file offset @var{start} and file offset @var{end} will be restored.
13111 These offsets are relative to the addresses in the file, before
13112 the @var{bias} argument is applied.
13113
13114 @end table
13115
13116 @node Core File Generation
13117 @section How to Produce a Core File from Your Program
13118 @cindex dump core from inferior
13119
13120 A @dfn{core file} or @dfn{core dump} is a file that records the memory
13121 image of a running process and its process status (register values
13122 etc.). Its primary use is post-mortem debugging of a program that
13123 crashed while it ran outside a debugger. A program that crashes
13124 automatically produces a core file, unless this feature is disabled by
13125 the user. @xref{Files}, for information on invoking @value{GDBN} in
13126 the post-mortem debugging mode.
13127
13128 Occasionally, you may wish to produce a core file of the program you
13129 are debugging in order to preserve a snapshot of its state.
13130 @value{GDBN} has a special command for that.
13131
13132 @table @code
13133 @kindex gcore
13134 @kindex generate-core-file
13135 @item generate-core-file [@var{file}]
13136 @itemx gcore [@var{file}]
13137 Produce a core dump of the inferior process. The optional argument
13138 @var{file} specifies the file name where to put the core dump. If not
13139 specified, the file name defaults to @file{core.@var{pid}}, where
13140 @var{pid} is the inferior process ID.
13141
13142 Note that this command is implemented only for some systems (as of
13143 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
13144
13145 On @sc{gnu}/Linux, this command can take into account the value of the
13146 file @file{/proc/@var{pid}/coredump_filter} when generating the core
13147 dump (@pxref{set use-coredump-filter}), and by default honors the
13148 @code{VM_DONTDUMP} flag for mappings where it is present in the file
13149 @file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
13150
13151 @kindex set use-coredump-filter
13152 @anchor{set use-coredump-filter}
13153 @item set use-coredump-filter on
13154 @itemx set use-coredump-filter off
13155 Enable or disable the use of the file
13156 @file{/proc/@var{pid}/coredump_filter} when generating core dump
13157 files. This file is used by the Linux kernel to decide what types of
13158 memory mappings will be dumped or ignored when generating a core dump
13159 file. @var{pid} is the process ID of a currently running process.
13160
13161 To make use of this feature, you have to write in the
13162 @file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
13163 which is a bit mask representing the memory mapping types. If a bit
13164 is set in the bit mask, then the memory mappings of the corresponding
13165 types will be dumped; otherwise, they will be ignored. This
13166 configuration is inherited by child processes. For more information
13167 about the bits that can be set in the
13168 @file{/proc/@var{pid}/coredump_filter} file, please refer to the
13169 manpage of @code{core(5)}.
13170
13171 By default, this option is @code{on}. If this option is turned
13172 @code{off}, @value{GDBN} does not read the @file{coredump_filter} file
13173 and instead uses the same default value as the Linux kernel in order
13174 to decide which pages will be dumped in the core dump file. This
13175 value is currently @code{0x33}, which means that bits @code{0}
13176 (anonymous private mappings), @code{1} (anonymous shared mappings),
13177 @code{4} (ELF headers) and @code{5} (private huge pages) are active.
13178 This will cause these memory mappings to be dumped automatically.
13179
13180 @kindex set dump-excluded-mappings
13181 @anchor{set dump-excluded-mappings}
13182 @item set dump-excluded-mappings on
13183 @itemx set dump-excluded-mappings off
13184 If @code{on} is specified, @value{GDBN} will dump memory mappings
13185 marked with the @code{VM_DONTDUMP} flag. This flag is represented in
13186 the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
13187
13188 The default value is @code{off}.
13189 @end table
13190
13191 @node Character Sets
13192 @section Character Sets
13193 @cindex character sets
13194 @cindex charset
13195 @cindex translating between character sets
13196 @cindex host character set
13197 @cindex target character set
13198
13199 If the program you are debugging uses a different character set to
13200 represent characters and strings than the one @value{GDBN} uses itself,
13201 @value{GDBN} can automatically translate between the character sets for
13202 you. The character set @value{GDBN} uses we call the @dfn{host
13203 character set}; the one the inferior program uses we call the
13204 @dfn{target character set}.
13205
13206 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
13207 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
13208 remote protocol (@pxref{Remote Debugging}) to debug a program
13209 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
13210 then the host character set is Latin-1, and the target character set is
13211 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
13212 target-charset EBCDIC-US}, then @value{GDBN} translates between
13213 @sc{ebcdic} and Latin 1 as you print character or string values, or use
13214 character and string literals in expressions.
13215
13216 @value{GDBN} has no way to automatically recognize which character set
13217 the inferior program uses; you must tell it, using the @code{set
13218 target-charset} command, described below.
13219
13220 Here are the commands for controlling @value{GDBN}'s character set
13221 support:
13222
13223 @table @code
13224 @item set target-charset @var{charset}
13225 @kindex set target-charset
13226 Set the current target character set to @var{charset}. To display the
13227 list of supported target character sets, type
13228 @kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
13229
13230 @item set host-charset @var{charset}
13231 @kindex set host-charset
13232 Set the current host character set to @var{charset}.
13233
13234 By default, @value{GDBN} uses a host character set appropriate to the
13235 system it is running on; you can override that default using the
13236 @code{set host-charset} command. On some systems, @value{GDBN} cannot
13237 automatically determine the appropriate host character set. In this
13238 case, @value{GDBN} uses @samp{UTF-8}.
13239
13240 @value{GDBN} can only use certain character sets as its host character
13241 set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
13242 @value{GDBN} will list the host character sets it supports.
13243
13244 @item set charset @var{charset}
13245 @kindex set charset
13246 Set the current host and target character sets to @var{charset}. As
13247 above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13248 @value{GDBN} will list the names of the character sets that can be used
13249 for both host and target.
13250
13251 @item show charset
13252 @kindex show charset
13253 Show the names of the current host and target character sets.
13254
13255 @item show host-charset
13256 @kindex show host-charset
13257 Show the name of the current host character set.
13258
13259 @item show target-charset
13260 @kindex show target-charset
13261 Show the name of the current target character set.
13262
13263 @item set target-wide-charset @var{charset}
13264 @kindex set target-wide-charset
13265 Set the current target's wide character set to @var{charset}. This is
13266 the character set used by the target's @code{wchar_t} type. To
13267 display the list of supported wide character sets, type
13268 @kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13269
13270 @item show target-wide-charset
13271 @kindex show target-wide-charset
13272 Show the name of the current target's wide character set.
13273 @end table
13274
13275 Here is an example of @value{GDBN}'s character set support in action.
13276 Assume that the following source code has been placed in the file
13277 @file{charset-test.c}:
13278
13279 @smallexample
13280 #include <stdio.h>
13281
13282 char ascii_hello[]
13283 = @{72, 101, 108, 108, 111, 44, 32, 119,
13284 111, 114, 108, 100, 33, 10, 0@};
13285 char ibm1047_hello[]
13286 = @{200, 133, 147, 147, 150, 107, 64, 166,
13287 150, 153, 147, 132, 90, 37, 0@};
13288
13289 main ()
13290 @{
13291 printf ("Hello, world!\n");
13292 @}
13293 @end smallexample
13294
13295 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13296 containing the string @samp{Hello, world!} followed by a newline,
13297 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13298
13299 We compile the program, and invoke the debugger on it:
13300
13301 @smallexample
13302 $ gcc -g charset-test.c -o charset-test
13303 $ gdb -nw charset-test
13304 GNU gdb 2001-12-19-cvs
13305 Copyright 2001 Free Software Foundation, Inc.
13306 @dots{}
13307 (@value{GDBP})
13308 @end smallexample
13309
13310 We can use the @code{show charset} command to see what character sets
13311 @value{GDBN} is currently using to interpret and display characters and
13312 strings:
13313
13314 @smallexample
13315 (@value{GDBP}) show charset
13316 The current host and target character set is `ISO-8859-1'.
13317 (@value{GDBP})
13318 @end smallexample
13319
13320 For the sake of printing this manual, let's use @sc{ascii} as our
13321 initial character set:
13322 @smallexample
13323 (@value{GDBP}) set charset ASCII
13324 (@value{GDBP}) show charset
13325 The current host and target character set is `ASCII'.
13326 (@value{GDBP})
13327 @end smallexample
13328
13329 Let's assume that @sc{ascii} is indeed the correct character set for our
13330 host system --- in other words, let's assume that if @value{GDBN} prints
13331 characters using the @sc{ascii} character set, our terminal will display
13332 them properly. Since our current target character set is also
13333 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
13334
13335 @smallexample
13336 (@value{GDBP}) print ascii_hello
13337 $1 = 0x401698 "Hello, world!\n"
13338 (@value{GDBP}) print ascii_hello[0]
13339 $2 = 72 'H'
13340 (@value{GDBP})
13341 @end smallexample
13342
13343 @value{GDBN} uses the target character set for character and string
13344 literals you use in expressions:
13345
13346 @smallexample
13347 (@value{GDBP}) print '+'
13348 $3 = 43 '+'
13349 (@value{GDBP})
13350 @end smallexample
13351
13352 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13353 character.
13354
13355 @value{GDBN} relies on the user to tell it which character set the
13356 target program uses. If we print @code{ibm1047_hello} while our target
13357 character set is still @sc{ascii}, we get jibberish:
13358
13359 @smallexample
13360 (@value{GDBP}) print ibm1047_hello
13361 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
13362 (@value{GDBP}) print ibm1047_hello[0]
13363 $5 = 200 '\310'
13364 (@value{GDBP})
13365 @end smallexample
13366
13367 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
13368 @value{GDBN} tells us the character sets it supports:
13369
13370 @smallexample
13371 (@value{GDBP}) set target-charset
13372 ASCII EBCDIC-US IBM1047 ISO-8859-1
13373 (@value{GDBP}) set target-charset
13374 @end smallexample
13375
13376 We can select @sc{ibm1047} as our target character set, and examine the
13377 program's strings again. Now the @sc{ascii} string is wrong, but
13378 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
13379 target character set, @sc{ibm1047}, to the host character set,
13380 @sc{ascii}, and they display correctly:
13381
13382 @smallexample
13383 (@value{GDBP}) set target-charset IBM1047
13384 (@value{GDBP}) show charset
13385 The current host character set is `ASCII'.
13386 The current target character set is `IBM1047'.
13387 (@value{GDBP}) print ascii_hello
13388 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
13389 (@value{GDBP}) print ascii_hello[0]
13390 $7 = 72 '\110'
13391 (@value{GDBP}) print ibm1047_hello
13392 $8 = 0x4016a8 "Hello, world!\n"
13393 (@value{GDBP}) print ibm1047_hello[0]
13394 $9 = 200 'H'
13395 (@value{GDBP})
13396 @end smallexample
13397
13398 As above, @value{GDBN} uses the target character set for character and
13399 string literals you use in expressions:
13400
13401 @smallexample
13402 (@value{GDBP}) print '+'
13403 $10 = 78 '+'
13404 (@value{GDBP})
13405 @end smallexample
13406
13407 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
13408 character.
13409
13410 @node Caching Target Data
13411 @section Caching Data of Targets
13412 @cindex caching data of targets
13413
13414 @value{GDBN} caches data exchanged between the debugger and a target.
13415 Each cache is associated with the address space of the inferior.
13416 @xref{Inferiors Connections and Programs}, about inferior and address space.
13417 Such caching generally improves performance in remote debugging
13418 (@pxref{Remote Debugging}), because it reduces the overhead of the
13419 remote protocol by bundling memory reads and writes into large chunks.
13420 Unfortunately, simply caching everything would lead to incorrect results,
13421 since @value{GDBN} does not necessarily know anything about volatile
13422 values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
13423 (@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13424 is executing.
13425 Therefore, by default, @value{GDBN} only caches data
13426 known to be on the stack@footnote{In non-stop mode, it is moderately
13427 rare for a running thread to modify the stack of a stopped thread
13428 in a way that would interfere with a backtrace, and caching of
13429 stack reads provides a significant speed up of remote backtraces.} or
13430 in the code segment.
13431 Other regions of memory can be explicitly marked as
13432 cacheable; @pxref{Memory Region Attributes}.
13433
13434 @table @code
13435 @kindex set remotecache
13436 @item set remotecache on
13437 @itemx set remotecache off
13438 This option no longer does anything; it exists for compatibility
13439 with old scripts.
13440
13441 @kindex show remotecache
13442 @item show remotecache
13443 Show the current state of the obsolete remotecache flag.
13444
13445 @kindex set stack-cache
13446 @item set stack-cache on
13447 @itemx set stack-cache off
13448 Enable or disable caching of stack accesses. When @code{on}, use
13449 caching. By default, this option is @code{on}.
13450
13451 @kindex show stack-cache
13452 @item show stack-cache
13453 Show the current state of data caching for memory accesses.
13454
13455 @kindex set code-cache
13456 @item set code-cache on
13457 @itemx set code-cache off
13458 Enable or disable caching of code segment accesses. When @code{on},
13459 use caching. By default, this option is @code{on}. This improves
13460 performance of disassembly in remote debugging.
13461
13462 @kindex show code-cache
13463 @item show code-cache
13464 Show the current state of target memory cache for code segment
13465 accesses.
13466
13467 @kindex info dcache
13468 @item info dcache @r{[}line@r{]}
13469 Print the information about the performance of data cache of the
13470 current inferior's address space. The information displayed
13471 includes the dcache width and depth, and for each cache line, its
13472 number, address, and how many times it was referenced. This
13473 command is useful for debugging the data cache operation.
13474
13475 If a line number is specified, the contents of that line will be
13476 printed in hex.
13477
13478 @item set dcache size @var{size}
13479 @cindex dcache size
13480 @kindex set dcache size
13481 Set maximum number of entries in dcache (dcache depth above).
13482
13483 @item set dcache line-size @var{line-size}
13484 @cindex dcache line-size
13485 @kindex set dcache line-size
13486 Set number of bytes each dcache entry caches (dcache width above).
13487 Must be a power of 2.
13488
13489 @item show dcache size
13490 @kindex show dcache size
13491 Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
13492
13493 @item show dcache line-size
13494 @kindex show dcache line-size
13495 Show default size of dcache lines.
13496
13497 @item maint flush dcache
13498 @cindex dcache, flushing
13499 @kindex maint flush dcache
13500 Flush the contents (if any) of the dcache. This maintainer command is
13501 useful when debugging the dcache implementation.
13502
13503 @end table
13504
13505 @node Searching Memory
13506 @section Search Memory
13507 @cindex searching memory
13508
13509 Memory can be searched for a particular sequence of bytes with the
13510 @code{find} command.
13511
13512 @table @code
13513 @kindex find
13514 @item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13515 @itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13516 Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13517 etc. The search begins at address @var{start_addr} and continues for either
13518 @var{len} bytes or through to @var{end_addr} inclusive.
13519 @end table
13520
13521 @var{s} and @var{n} are optional parameters.
13522 They may be specified in either order, apart or together.
13523
13524 @table @r
13525 @item @var{s}, search query size
13526 The size of each search query value.
13527
13528 @table @code
13529 @item b
13530 bytes
13531 @item h
13532 halfwords (two bytes)
13533 @item w
13534 words (four bytes)
13535 @item g
13536 giant words (eight bytes)
13537 @end table
13538
13539 All values are interpreted in the current language.
13540 This means, for example, that if the current source language is C/C@t{++}
13541 then searching for the string ``hello'' includes the trailing '\0'.
13542 The null terminator can be removed from searching by using casts,
13543 e.g.: @samp{@{char[5]@}"hello"}.
13544
13545 If the value size is not specified, it is taken from the
13546 value's type in the current language.
13547 This is useful when one wants to specify the search
13548 pattern as a mixture of types.
13549 Note that this means, for example, that in the case of C-like languages
13550 a search for an untyped 0x42 will search for @samp{(int) 0x42}
13551 which is typically four bytes.
13552
13553 @item @var{n}, maximum number of finds
13554 The maximum number of matches to print. The default is to print all finds.
13555 @end table
13556
13557 You can use strings as search values. Quote them with double-quotes
13558 (@code{"}).
13559 The string value is copied into the search pattern byte by byte,
13560 regardless of the endianness of the target and the size specification.
13561
13562 The address of each match found is printed as well as a count of the
13563 number of matches found.
13564
13565 The address of the last value found is stored in convenience variable
13566 @samp{$_}.
13567 A count of the number of matches is stored in @samp{$numfound}.
13568
13569 For example, if stopped at the @code{printf} in this function:
13570
13571 @smallexample
13572 void
13573 hello ()
13574 @{
13575 static char hello[] = "hello-hello";
13576 static struct @{ char c; short s; int i; @}
13577 __attribute__ ((packed)) mixed
13578 = @{ 'c', 0x1234, 0x87654321 @};
13579 printf ("%s\n", hello);
13580 @}
13581 @end smallexample
13582
13583 @noindent
13584 you get during debugging:
13585
13586 @smallexample
13587 (gdb) find &hello[0], +sizeof(hello), "hello"
13588 0x804956d <hello.1620+6>
13589 1 pattern found
13590 (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
13591 0x8049567 <hello.1620>
13592 0x804956d <hello.1620+6>
13593 2 patterns found.
13594 (gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
13595 0x8049567 <hello.1620>
13596 0x804956d <hello.1620+6>
13597 2 patterns found.
13598 (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
13599 0x8049567 <hello.1620>
13600 1 pattern found
13601 (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
13602 0x8049560 <mixed.1625>
13603 1 pattern found
13604 (gdb) print $numfound
13605 $1 = 1
13606 (gdb) print $_
13607 $2 = (void *) 0x8049560
13608 @end smallexample
13609
13610 @node Value Sizes
13611 @section Value Sizes
13612
13613 Whenever @value{GDBN} prints a value memory will be allocated within
13614 @value{GDBN} to hold the contents of the value. It is possible in
13615 some languages with dynamic typing systems, that an invalid program
13616 may indicate a value that is incorrectly large, this in turn may cause
13617 @value{GDBN} to try and allocate an overly large amount of memory.
13618
13619 @table @code
13620 @kindex set max-value-size
13621 @item set max-value-size @var{bytes}
13622 @itemx set max-value-size unlimited
13623 Set the maximum size of memory that @value{GDBN} will allocate for the
13624 contents of a value to @var{bytes}, trying to display a value that
13625 requires more memory than that will result in an error.
13626
13627 Setting this variable does not effect values that have already been
13628 allocated within @value{GDBN}, only future allocations.
13629
13630 There's a minimum size that @code{max-value-size} can be set to in
13631 order that @value{GDBN} can still operate correctly, this minimum is
13632 currently 16 bytes.
13633
13634 The limit applies to the results of some subexpressions as well as to
13635 complete expressions. For example, an expression denoting a simple
13636 integer component, such as @code{x.y.z}, may fail if the size of
13637 @var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
13638 @value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13639 @var{A} is an array variable with non-constant size, will generally
13640 succeed regardless of the bounds on @var{A}, as long as the component
13641 size is less than @var{bytes}.
13642
13643 The default value of @code{max-value-size} is currently 64k.
13644
13645 @kindex show max-value-size
13646 @item show max-value-size
13647 Show the maximum size of memory, in bytes, that @value{GDBN} will
13648 allocate for the contents of a value.
13649 @end table
13650
13651 @node Optimized Code
13652 @chapter Debugging Optimized Code
13653 @cindex optimized code, debugging
13654 @cindex debugging optimized code
13655
13656 Almost all compilers support optimization. With optimization
13657 disabled, the compiler generates assembly code that corresponds
13658 directly to your source code, in a simplistic way. As the compiler
13659 applies more powerful optimizations, the generated assembly code
13660 diverges from your original source code. With help from debugging
13661 information generated by the compiler, @value{GDBN} can map from
13662 the running program back to constructs from your original source.
13663
13664 @value{GDBN} is more accurate with optimization disabled. If you
13665 can recompile without optimization, it is easier to follow the
13666 progress of your program during debugging. But, there are many cases
13667 where you may need to debug an optimized version.
13668
13669 When you debug a program compiled with @samp{-g -O}, remember that the
13670 optimizer has rearranged your code; the debugger shows you what is
13671 really there. Do not be too surprised when the execution path does not
13672 exactly match your source file! An extreme example: if you define a
13673 variable, but never use it, @value{GDBN} never sees that
13674 variable---because the compiler optimizes it out of existence.
13675
13676 Some things do not work as well with @samp{-g -O} as with just
13677 @samp{-g}, particularly on machines with instruction scheduling. If in
13678 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
13679 please report it to us as a bug (including a test case!).
13680 @xref{Variables}, for more information about debugging optimized code.
13681
13682 @menu
13683 * Inline Functions:: How @value{GDBN} presents inlining
13684 * Tail Call Frames:: @value{GDBN} analysis of jumps to functions
13685 @end menu
13686
13687 @node Inline Functions
13688 @section Inline Functions
13689 @cindex inline functions, debugging
13690
13691 @dfn{Inlining} is an optimization that inserts a copy of the function
13692 body directly at each call site, instead of jumping to a shared
13693 routine. @value{GDBN} displays inlined functions just like
13694 non-inlined functions. They appear in backtraces. You can view their
13695 arguments and local variables, step into them with @code{step}, skip
13696 them with @code{next}, and escape from them with @code{finish}.
13697 You can check whether a function was inlined by using the
13698 @code{info frame} command.
13699
13700 For @value{GDBN} to support inlined functions, the compiler must
13701 record information about inlining in the debug information ---
13702 @value{NGCC} using the @sc{dwarf 2} format does this, and several
13703 other compilers do also. @value{GDBN} only supports inlined functions
13704 when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
13705 do not emit two required attributes (@samp{DW_AT_call_file} and
13706 @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
13707 function calls with earlier versions of @value{NGCC}. It instead
13708 displays the arguments and local variables of inlined functions as
13709 local variables in the caller.
13710
13711 The body of an inlined function is directly included at its call site;
13712 unlike a non-inlined function, there are no instructions devoted to
13713 the call. @value{GDBN} still pretends that the call site and the
13714 start of the inlined function are different instructions. Stepping to
13715 the call site shows the call site, and then stepping again shows
13716 the first line of the inlined function, even though no additional
13717 instructions are executed.
13718
13719 This makes source-level debugging much clearer; you can see both the
13720 context of the call and then the effect of the call. Only stepping by
13721 a single instruction using @code{stepi} or @code{nexti} does not do
13722 this; single instruction steps always show the inlined body.
13723
13724 There are some ways that @value{GDBN} does not pretend that inlined
13725 function calls are the same as normal calls:
13726
13727 @itemize @bullet
13728 @item
13729 Setting breakpoints at the call site of an inlined function may not
13730 work, because the call site does not contain any code. @value{GDBN}
13731 may incorrectly move the breakpoint to the next line of the enclosing
13732 function, after the call. This limitation will be removed in a future
13733 version of @value{GDBN}; until then, set a breakpoint on an earlier line
13734 or inside the inlined function instead.
13735
13736 @item
13737 @value{GDBN} cannot locate the return value of inlined calls after
13738 using the @code{finish} command. This is a limitation of compiler-generated
13739 debugging information; after @code{finish}, you can step to the next line
13740 and print a variable where your program stored the return value.
13741
13742 @end itemize
13743
13744 @node Tail Call Frames
13745 @section Tail Call Frames
13746 @cindex tail call frames, debugging
13747
13748 Function @code{B} can call function @code{C} in its very last statement. In
13749 unoptimized compilation the call of @code{C} is immediately followed by return
13750 instruction at the end of @code{B} code. Optimizing compiler may replace the
13751 call and return in function @code{B} into one jump to function @code{C}
13752 instead. Such use of a jump instruction is called @dfn{tail call}.
13753
13754 During execution of function @code{C}, there will be no indication in the
13755 function call stack frames that it was tail-called from @code{B}. If function
13756 @code{A} regularly calls function @code{B} which tail-calls function @code{C},
13757 then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
13758 some cases @value{GDBN} can determine that @code{C} was tail-called from
13759 @code{B}, and it will then create fictitious call frame for that, with the
13760 return address set up as if @code{B} called @code{C} normally.
13761
13762 This functionality is currently supported only by DWARF 2 debugging format and
13763 the compiler has to produce @samp{DW_TAG_call_site} tags. With
13764 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
13765 this information.
13766
13767 @kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
13768 kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
13769
13770 @smallexample
13771 (gdb) x/i $pc - 2
13772 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
13773 (gdb) info frame
13774 Stack level 1, frame at 0x7fffffffda30:
13775 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
13776 tail call frame, caller of frame at 0x7fffffffda30
13777 source language c++.
13778 Arglist at unknown address.
13779 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
13780 @end smallexample
13781
13782 The detection of all the possible code path executions can find them ambiguous.
13783 There is no execution history stored (possible @ref{Reverse Execution} is never
13784 used for this purpose) and the last known caller could have reached the known
13785 callee by multiple different jump sequences. In such case @value{GDBN} still
13786 tries to show at least all the unambiguous top tail callers and all the
13787 unambiguous bottom tail calees, if any.
13788
13789 @table @code
13790 @anchor{set debug entry-values}
13791 @item set debug entry-values
13792 @kindex set debug entry-values
13793 When set to on, enables printing of analysis messages for both frame argument
13794 values at function entry and tail calls. It will show all the possible valid
13795 tail calls code paths it has considered. It will also print the intersection
13796 of them with the final unambiguous (possibly partial or even empty) code path
13797 result.
13798
13799 @item show debug entry-values
13800 @kindex show debug entry-values
13801 Show the current state of analysis messages printing for both frame argument
13802 values at function entry and tail calls.
13803 @end table
13804
13805 The analysis messages for tail calls can for example show why the virtual tail
13806 call frame for function @code{c} has not been recognized (due to the indirect
13807 reference by variable @code{x}):
13808
13809 @smallexample
13810 static void __attribute__((noinline, noclone)) c (void);
13811 void (*x) (void) = c;
13812 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13813 static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
13814 int main (void) @{ x (); return 0; @}
13815
13816 Breakpoint 1, DW_OP_entry_value resolving cannot find
13817 DW_TAG_call_site 0x40039a in main
13818 a () at t.c:3
13819 3 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13820 (gdb) bt
13821 #0 a () at t.c:3
13822 #1 0x000000000040039a in main () at t.c:5
13823 @end smallexample
13824
13825 Another possibility is an ambiguous virtual tail call frames resolution:
13826
13827 @smallexample
13828 int i;
13829 static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
13830 static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
13831 static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
13832 static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
13833 static void __attribute__((noinline, noclone)) b (void)
13834 @{ if (i) c (); else e (); @}
13835 static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
13836 int main (void) @{ a (); return 0; @}
13837
13838 tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
13839 tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
13840 tailcall: reduced: 0x4004d2(a) |
13841 (gdb) bt
13842 #0 f () at t.c:2
13843 #1 0x00000000004004d2 in a () at t.c:8
13844 #2 0x0000000000400395 in main () at t.c:9
13845 @end smallexample
13846
13847 @set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
13848 @set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
13849
13850 @c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
13851 @ifset HAVE_MAKEINFO_CLICK
13852 @set ARROW @click{}
13853 @set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
13854 @set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
13855 @end ifset
13856 @ifclear HAVE_MAKEINFO_CLICK
13857 @set ARROW ->
13858 @set CALLSEQ1B @value{CALLSEQ1A}
13859 @set CALLSEQ2B @value{CALLSEQ2A}
13860 @end ifclear
13861
13862 Frames #0 and #2 are real, #1 is a virtual tail call frame.
13863 The code can have possible execution paths @value{CALLSEQ1B} or
13864 @value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
13865
13866 @code{initial:} state shows some random possible calling sequence @value{GDBN}
13867 has found. It then finds another possible calling sequence - that one is
13868 prefixed by @code{compare:}. The non-ambiguous intersection of these two is
13869 printed as the @code{reduced:} calling sequence. That one could have many
13870 further @code{compare:} and @code{reduced:} statements as long as there remain
13871 any non-ambiguous sequence entries.
13872
13873 For the frame of function @code{b} in both cases there are different possible
13874 @code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
13875 also ambiguous. The only non-ambiguous frame is the one for function @code{a},
13876 therefore this one is displayed to the user while the ambiguous frames are
13877 omitted.
13878
13879 There can be also reasons why printing of frame argument values at function
13880 entry may fail:
13881
13882 @smallexample
13883 int v;
13884 static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
13885 static void __attribute__((noinline, noclone)) a (int i);
13886 static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
13887 static void __attribute__((noinline, noclone)) a (int i)
13888 @{ if (i) b (i - 1); else c (0); @}
13889 int main (void) @{ a (5); return 0; @}
13890
13891 (gdb) bt
13892 #0 c (i=i@@entry=0) at t.c:2
13893 #1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
13894 function "a" at 0x400420 can call itself via tail calls
13895 i=<optimized out>) at t.c:6
13896 #2 0x000000000040036e in main () at t.c:7
13897 @end smallexample
13898
13899 @value{GDBN} cannot find out from the inferior state if and how many times did
13900 function @code{a} call itself (via function @code{b}) as these calls would be
13901 tail calls. Such tail calls would modify the @code{i} variable, therefore
13902 @value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
13903 prints @code{<optimized out>} instead.
13904
13905 @node Macros
13906 @chapter C Preprocessor Macros
13907
13908 Some languages, such as C and C@t{++}, provide a way to define and invoke
13909 ``preprocessor macros'' which expand into strings of tokens.
13910 @value{GDBN} can evaluate expressions containing macro invocations, show
13911 the result of macro expansion, and show a macro's definition, including
13912 where it was defined.
13913
13914 You may need to compile your program specially to provide @value{GDBN}
13915 with information about preprocessor macros. Most compilers do not
13916 include macros in their debugging information, even when you compile
13917 with the @option{-g} flag. @xref{Compilation}.
13918
13919 A program may define a macro at one point, remove that definition later,
13920 and then provide a different definition after that. Thus, at different
13921 points in the program, a macro may have different definitions, or have
13922 no definition at all. If there is a current stack frame, @value{GDBN}
13923 uses the macros in scope at that frame's source code line. Otherwise,
13924 @value{GDBN} uses the macros in scope at the current listing location;
13925 see @ref{List}.
13926
13927 Whenever @value{GDBN} evaluates an expression, it always expands any
13928 macro invocations present in the expression. @value{GDBN} also provides
13929 the following commands for working with macros explicitly.
13930
13931 @table @code
13932
13933 @kindex macro expand
13934 @cindex macro expansion, showing the results of preprocessor
13935 @cindex preprocessor macro expansion, showing the results of
13936 @cindex expanding preprocessor macros
13937 @item macro expand @var{expression}
13938 @itemx macro exp @var{expression}
13939 Show the results of expanding all preprocessor macro invocations in
13940 @var{expression}. Since @value{GDBN} simply expands macros, but does
13941 not parse the result, @var{expression} need not be a valid expression;
13942 it can be any string of tokens.
13943
13944 @kindex macro exp1
13945 @item macro expand-once @var{expression}
13946 @itemx macro exp1 @var{expression}
13947 @cindex expand macro once
13948 @i{(This command is not yet implemented.)} Show the results of
13949 expanding those preprocessor macro invocations that appear explicitly in
13950 @var{expression}. Macro invocations appearing in that expansion are
13951 left unchanged. This command allows you to see the effect of a
13952 particular macro more clearly, without being confused by further
13953 expansions. Since @value{GDBN} simply expands macros, but does not
13954 parse the result, @var{expression} need not be a valid expression; it
13955 can be any string of tokens.
13956
13957 @kindex info macro
13958 @cindex macro definition, showing
13959 @cindex definition of a macro, showing
13960 @cindex macros, from debug info
13961 @item info macro [-a|-all] [--] @var{macro}
13962 Show the current definition or all definitions of the named @var{macro},
13963 and describe the source location or compiler command-line where that
13964 definition was established. The optional double dash is to signify the end of
13965 argument processing and the beginning of @var{macro} for non C-like macros where
13966 the macro may begin with a hyphen.
13967
13968 @kindex info macros
13969 @item info macros @var{location}
13970 Show all macro definitions that are in effect at the location specified
13971 by @var{location}, and describe the source location or compiler
13972 command-line where those definitions were established.
13973
13974 @kindex macro define
13975 @cindex user-defined macros
13976 @cindex defining macros interactively
13977 @cindex macros, user-defined
13978 @item macro define @var{macro} @var{replacement-list}
13979 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
13980 Introduce a definition for a preprocessor macro named @var{macro},
13981 invocations of which are replaced by the tokens given in
13982 @var{replacement-list}. The first form of this command defines an
13983 ``object-like'' macro, which takes no arguments; the second form
13984 defines a ``function-like'' macro, which takes the arguments given in
13985 @var{arglist}.
13986
13987 A definition introduced by this command is in scope in every
13988 expression evaluated in @value{GDBN}, until it is removed with the
13989 @code{macro undef} command, described below. The definition overrides
13990 all definitions for @var{macro} present in the program being debugged,
13991 as well as any previous user-supplied definition.
13992
13993 @kindex macro undef
13994 @item macro undef @var{macro}
13995 Remove any user-supplied definition for the macro named @var{macro}.
13996 This command only affects definitions provided with the @code{macro
13997 define} command, described above; it cannot remove definitions present
13998 in the program being debugged.
13999
14000 @kindex macro list
14001 @item macro list
14002 List all the macros defined using the @code{macro define} command.
14003 @end table
14004
14005 @cindex macros, example of debugging with
14006 Here is a transcript showing the above commands in action. First, we
14007 show our source files:
14008
14009 @smallexample
14010 $ cat sample.c
14011 #include <stdio.h>
14012 #include "sample.h"
14013
14014 #define M 42
14015 #define ADD(x) (M + x)
14016
14017 main ()
14018 @{
14019 #define N 28
14020 printf ("Hello, world!\n");
14021 #undef N
14022 printf ("We're so creative.\n");
14023 #define N 1729
14024 printf ("Goodbye, world!\n");
14025 @}
14026 $ cat sample.h
14027 #define Q <
14028 $
14029 @end smallexample
14030
14031 Now, we compile the program using the @sc{gnu} C compiler,
14032 @value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
14033 minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
14034 and @option{-gdwarf-4}; we recommend always choosing the most recent
14035 version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
14036 includes information about preprocessor macros in the debugging
14037 information.
14038
14039 @smallexample
14040 $ gcc -gdwarf-2 -g3 sample.c -o sample
14041 $
14042 @end smallexample
14043
14044 Now, we start @value{GDBN} on our sample program:
14045
14046 @smallexample
14047 $ gdb -nw sample
14048 GNU gdb 2002-05-06-cvs
14049 Copyright 2002 Free Software Foundation, Inc.
14050 GDB is free software, @dots{}
14051 (@value{GDBP})
14052 @end smallexample
14053
14054 We can expand macros and examine their definitions, even when the
14055 program is not running. @value{GDBN} uses the current listing position
14056 to decide which macro definitions are in scope:
14057
14058 @smallexample
14059 (@value{GDBP}) list main
14060 3
14061 4 #define M 42
14062 5 #define ADD(x) (M + x)
14063 6
14064 7 main ()
14065 8 @{
14066 9 #define N 28
14067 10 printf ("Hello, world!\n");
14068 11 #undef N
14069 12 printf ("We're so creative.\n");
14070 (@value{GDBP}) info macro ADD
14071 Defined at /home/jimb/gdb/macros/play/sample.c:5
14072 #define ADD(x) (M + x)
14073 (@value{GDBP}) info macro Q
14074 Defined at /home/jimb/gdb/macros/play/sample.h:1
14075 included at /home/jimb/gdb/macros/play/sample.c:2
14076 #define Q <
14077 (@value{GDBP}) macro expand ADD(1)
14078 expands to: (42 + 1)
14079 (@value{GDBP}) macro expand-once ADD(1)
14080 expands to: once (M + 1)
14081 (@value{GDBP})
14082 @end smallexample
14083
14084 In the example above, note that @code{macro expand-once} expands only
14085 the macro invocation explicit in the original text --- the invocation of
14086 @code{ADD} --- but does not expand the invocation of the macro @code{M},
14087 which was introduced by @code{ADD}.
14088
14089 Once the program is running, @value{GDBN} uses the macro definitions in
14090 force at the source line of the current stack frame:
14091
14092 @smallexample
14093 (@value{GDBP}) break main
14094 Breakpoint 1 at 0x8048370: file sample.c, line 10.
14095 (@value{GDBP}) run
14096 Starting program: /home/jimb/gdb/macros/play/sample
14097
14098 Breakpoint 1, main () at sample.c:10
14099 10 printf ("Hello, world!\n");
14100 (@value{GDBP})
14101 @end smallexample
14102
14103 At line 10, the definition of the macro @code{N} at line 9 is in force:
14104
14105 @smallexample
14106 (@value{GDBP}) info macro N
14107 Defined at /home/jimb/gdb/macros/play/sample.c:9
14108 #define N 28
14109 (@value{GDBP}) macro expand N Q M
14110 expands to: 28 < 42
14111 (@value{GDBP}) print N Q M
14112 $1 = 1
14113 (@value{GDBP})
14114 @end smallexample
14115
14116 As we step over directives that remove @code{N}'s definition, and then
14117 give it a new definition, @value{GDBN} finds the definition (or lack
14118 thereof) in force at each point:
14119
14120 @smallexample
14121 (@value{GDBP}) next
14122 Hello, world!
14123 12 printf ("We're so creative.\n");
14124 (@value{GDBP}) info macro N
14125 The symbol `N' has no definition as a C/C++ preprocessor macro
14126 at /home/jimb/gdb/macros/play/sample.c:12
14127 (@value{GDBP}) next
14128 We're so creative.
14129 14 printf ("Goodbye, world!\n");
14130 (@value{GDBP}) info macro N
14131 Defined at /home/jimb/gdb/macros/play/sample.c:13
14132 #define N 1729
14133 (@value{GDBP}) macro expand N Q M
14134 expands to: 1729 < 42
14135 (@value{GDBP}) print N Q M
14136 $2 = 0
14137 (@value{GDBP})
14138 @end smallexample
14139
14140 In addition to source files, macros can be defined on the compilation command
14141 line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
14142 such a way, @value{GDBN} displays the location of their definition as line zero
14143 of the source file submitted to the compiler.
14144
14145 @smallexample
14146 (@value{GDBP}) info macro __STDC__
14147 Defined at /home/jimb/gdb/macros/play/sample.c:0
14148 -D__STDC__=1
14149 (@value{GDBP})
14150 @end smallexample
14151
14152
14153 @node Tracepoints
14154 @chapter Tracepoints
14155 @c This chapter is based on the documentation written by Michael
14156 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
14157
14158 @cindex tracepoints
14159 In some applications, it is not feasible for the debugger to interrupt
14160 the program's execution long enough for the developer to learn
14161 anything helpful about its behavior. If the program's correctness
14162 depends on its real-time behavior, delays introduced by a debugger
14163 might cause the program to change its behavior drastically, or perhaps
14164 fail, even when the code itself is correct. It is useful to be able
14165 to observe the program's behavior without interrupting it.
14166
14167 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
14168 specify locations in the program, called @dfn{tracepoints}, and
14169 arbitrary expressions to evaluate when those tracepoints are reached.
14170 Later, using the @code{tfind} command, you can examine the values
14171 those expressions had when the program hit the tracepoints. The
14172 expressions may also denote objects in memory---structures or arrays,
14173 for example---whose values @value{GDBN} should record; while visiting
14174 a particular tracepoint, you may inspect those objects as if they were
14175 in memory at that moment. However, because @value{GDBN} records these
14176 values without interacting with you, it can do so quickly and
14177 unobtrusively, hopefully not disturbing the program's behavior.
14178
14179 The tracepoint facility is currently available only for remote
14180 targets. @xref{Targets}. In addition, your remote target must know
14181 how to collect trace data. This functionality is implemented in the
14182 remote stub; however, none of the stubs distributed with @value{GDBN}
14183 support tracepoints as of this writing. The format of the remote
14184 packets used to implement tracepoints are described in @ref{Tracepoint
14185 Packets}.
14186
14187 It is also possible to get trace data from a file, in a manner reminiscent
14188 of corefiles; you specify the filename, and use @code{tfind} to search
14189 through the file. @xref{Trace Files}, for more details.
14190
14191 This chapter describes the tracepoint commands and features.
14192
14193 @menu
14194 * Set Tracepoints::
14195 * Analyze Collected Data::
14196 * Tracepoint Variables::
14197 * Trace Files::
14198 @end menu
14199
14200 @node Set Tracepoints
14201 @section Commands to Set Tracepoints
14202
14203 Before running such a @dfn{trace experiment}, an arbitrary number of
14204 tracepoints can be set. A tracepoint is actually a special type of
14205 breakpoint (@pxref{Set Breaks}), so you can manipulate it using
14206 standard breakpoint commands. For instance, as with breakpoints,
14207 tracepoint numbers are successive integers starting from one, and many
14208 of the commands associated with tracepoints take the tracepoint number
14209 as their argument, to identify which tracepoint to work on.
14210
14211 For each tracepoint, you can specify, in advance, some arbitrary set
14212 of data that you want the target to collect in the trace buffer when
14213 it hits that tracepoint. The collected data can include registers,
14214 local variables, or global data. Later, you can use @value{GDBN}
14215 commands to examine the values these data had at the time the
14216 tracepoint was hit.
14217
14218 Tracepoints do not support every breakpoint feature. Ignore counts on
14219 tracepoints have no effect, and tracepoints cannot run @value{GDBN}
14220 commands when they are hit. Tracepoints may not be thread-specific
14221 either.
14222
14223 @cindex fast tracepoints
14224 Some targets may support @dfn{fast tracepoints}, which are inserted in
14225 a different way (such as with a jump instead of a trap), that is
14226 faster but possibly restricted in where they may be installed.
14227
14228 @cindex static tracepoints
14229 @cindex markers, static tracepoints
14230 @cindex probing markers, static tracepoints
14231 Regular and fast tracepoints are dynamic tracing facilities, meaning
14232 that they can be used to insert tracepoints at (almost) any location
14233 in the target. Some targets may also support controlling @dfn{static
14234 tracepoints} from @value{GDBN}. With static tracing, a set of
14235 instrumentation points, also known as @dfn{markers}, are embedded in
14236 the target program, and can be activated or deactivated by name or
14237 address. These are usually placed at locations which facilitate
14238 investigating what the target is actually doing. @value{GDBN}'s
14239 support for static tracing includes being able to list instrumentation
14240 points, and attach them with @value{GDBN} defined high level
14241 tracepoints that expose the whole range of convenience of
14242 @value{GDBN}'s tracepoints support. Namely, support for collecting
14243 registers values and values of global or local (to the instrumentation
14244 point) variables; tracepoint conditions and trace state variables.
14245 The act of installing a @value{GDBN} static tracepoint on an
14246 instrumentation point, or marker, is referred to as @dfn{probing} a
14247 static tracepoint marker.
14248
14249 @code{gdbserver} supports tracepoints on some target systems.
14250 @xref{Server,,Tracepoints support in @code{gdbserver}}.
14251
14252 This section describes commands to set tracepoints and associated
14253 conditions and actions.
14254
14255 @menu
14256 * Create and Delete Tracepoints::
14257 * Enable and Disable Tracepoints::
14258 * Tracepoint Passcounts::
14259 * Tracepoint Conditions::
14260 * Trace State Variables::
14261 * Tracepoint Actions::
14262 * Listing Tracepoints::
14263 * Listing Static Tracepoint Markers::
14264 * Starting and Stopping Trace Experiments::
14265 * Tracepoint Restrictions::
14266 @end menu
14267
14268 @node Create and Delete Tracepoints
14269 @subsection Create and Delete Tracepoints
14270
14271 @table @code
14272 @cindex set tracepoint
14273 @kindex trace
14274 @item trace @var{location}
14275 The @code{trace} command is very similar to the @code{break} command.
14276 Its argument @var{location} can be any valid location.
14277 @xref{Specify Location}. The @code{trace} command defines a tracepoint,
14278 which is a point in the target program where the debugger will briefly stop,
14279 collect some data, and then allow the program to continue. Setting a tracepoint
14280 or changing its actions takes effect immediately if the remote stub
14281 supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14282 in tracing}).
14283 If remote stub doesn't support the @samp{InstallInTrace} feature, all
14284 these changes don't take effect until the next @code{tstart}
14285 command, and once a trace experiment is running, further changes will
14286 not have any effect until the next trace experiment starts. In addition,
14287 @value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14288 address is not yet resolved. (This is similar to pending breakpoints.)
14289 Pending tracepoints are not downloaded to the target and not installed
14290 until they are resolved. The resolution of pending tracepoints requires
14291 @value{GDBN} support---when debugging with the remote target, and
14292 @value{GDBN} disconnects from the remote stub (@pxref{disconnected
14293 tracing}), pending tracepoints can not be resolved (and downloaded to
14294 the remote stub) while @value{GDBN} is disconnected.
14295
14296 Here are some examples of using the @code{trace} command:
14297
14298 @smallexample
14299 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14300
14301 (@value{GDBP}) @b{trace +2} // 2 lines forward
14302
14303 (@value{GDBP}) @b{trace my_function} // first source line of function
14304
14305 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14306
14307 (@value{GDBP}) @b{trace *0x2117c4} // an address
14308 @end smallexample
14309
14310 @noindent
14311 You can abbreviate @code{trace} as @code{tr}.
14312
14313 @item trace @var{location} if @var{cond}
14314 Set a tracepoint with condition @var{cond}; evaluate the expression
14315 @var{cond} each time the tracepoint is reached, and collect data only
14316 if the value is nonzero---that is, if @var{cond} evaluates as true.
14317 @xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14318 information on tracepoint conditions.
14319
14320 @item ftrace @var{location} [ if @var{cond} ]
14321 @cindex set fast tracepoint
14322 @cindex fast tracepoints, setting
14323 @kindex ftrace
14324 The @code{ftrace} command sets a fast tracepoint. For targets that
14325 support them, fast tracepoints will use a more efficient but possibly
14326 less general technique to trigger data collection, such as a jump
14327 instruction instead of a trap, or some sort of hardware support. It
14328 may not be possible to create a fast tracepoint at the desired
14329 location, in which case the command will exit with an explanatory
14330 message.
14331
14332 @value{GDBN} handles arguments to @code{ftrace} exactly as for
14333 @code{trace}.
14334
14335 On 32-bit x86-architecture systems, fast tracepoints normally need to
14336 be placed at an instruction that is 5 bytes or longer, but can be
14337 placed at 4-byte instructions if the low 64K of memory of the target
14338 program is available to install trampolines. Some Unix-type systems,
14339 such as @sc{gnu}/Linux, exclude low addresses from the program's
14340 address space; but for instance with the Linux kernel it is possible
14341 to let @value{GDBN} use this area by doing a @command{sysctl} command
14342 to set the @code{mmap_min_addr} kernel parameter, as in
14343
14344 @example
14345 sudo sysctl -w vm.mmap_min_addr=32768
14346 @end example
14347
14348 @noindent
14349 which sets the low address to 32K, which leaves plenty of room for
14350 trampolines. The minimum address should be set to a page boundary.
14351
14352 @item strace @var{location} [ if @var{cond} ]
14353 @cindex set static tracepoint
14354 @cindex static tracepoints, setting
14355 @cindex probe static tracepoint marker
14356 @kindex strace
14357 The @code{strace} command sets a static tracepoint. For targets that
14358 support it, setting a static tracepoint probes a static
14359 instrumentation point, or marker, found at @var{location}. It may not
14360 be possible to set a static tracepoint at the desired location, in
14361 which case the command will exit with an explanatory message.
14362
14363 @value{GDBN} handles arguments to @code{strace} exactly as for
14364 @code{trace}, with the addition that the user can also specify
14365 @code{-m @var{marker}} as @var{location}. This probes the marker
14366 identified by the @var{marker} string identifier. This identifier
14367 depends on the static tracepoint backend library your program is
14368 using. You can find all the marker identifiers in the @samp{ID} field
14369 of the @code{info static-tracepoint-markers} command output.
14370 @xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14371 Markers}. For example, in the following small program using the UST
14372 tracing engine:
14373
14374 @smallexample
14375 main ()
14376 @{
14377 trace_mark(ust, bar33, "str %s", "FOOBAZ");
14378 @}
14379 @end smallexample
14380
14381 @noindent
14382 the marker id is composed of joining the first two arguments to the
14383 @code{trace_mark} call with a slash, which translates to:
14384
14385 @smallexample
14386 (@value{GDBP}) info static-tracepoint-markers
14387 Cnt Enb ID Address What
14388 1 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
14389 Data: "str %s"
14390 [etc...]
14391 @end smallexample
14392
14393 @noindent
14394 so you may probe the marker above with:
14395
14396 @smallexample
14397 (@value{GDBP}) strace -m ust/bar33
14398 @end smallexample
14399
14400 Static tracepoints accept an extra collect action --- @code{collect
14401 $_sdata}. This collects arbitrary user data passed in the probe point
14402 call to the tracing library. In the UST example above, you'll see
14403 that the third argument to @code{trace_mark} is a printf-like format
14404 string. The user data is then the result of running that formatting
14405 string against the following arguments. Note that @code{info
14406 static-tracepoint-markers} command output lists that format string in
14407 the @samp{Data:} field.
14408
14409 You can inspect this data when analyzing the trace buffer, by printing
14410 the $_sdata variable like any other variable available to
14411 @value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14412
14413 @vindex $tpnum
14414 @cindex last tracepoint number
14415 @cindex recent tracepoint number
14416 @cindex tracepoint number
14417 The convenience variable @code{$tpnum} records the tracepoint number
14418 of the most recently set tracepoint.
14419
14420 @kindex delete tracepoint
14421 @cindex tracepoint deletion
14422 @item delete tracepoint @r{[}@var{num}@r{]}
14423 Permanently delete one or more tracepoints. With no argument, the
14424 default is to delete all tracepoints. Note that the regular
14425 @code{delete} command can remove tracepoints also.
14426
14427 Examples:
14428
14429 @smallexample
14430 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14431
14432 (@value{GDBP}) @b{delete trace} // remove all tracepoints
14433 @end smallexample
14434
14435 @noindent
14436 You can abbreviate this command as @code{del tr}.
14437 @end table
14438
14439 @node Enable and Disable Tracepoints
14440 @subsection Enable and Disable Tracepoints
14441
14442 These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14443
14444 @table @code
14445 @kindex disable tracepoint
14446 @item disable tracepoint @r{[}@var{num}@r{]}
14447 Disable tracepoint @var{num}, or all tracepoints if no argument
14448 @var{num} is given. A disabled tracepoint will have no effect during
14449 a trace experiment, but it is not forgotten. You can re-enable
14450 a disabled tracepoint using the @code{enable tracepoint} command.
14451 If the command is issued during a trace experiment and the debug target
14452 has support for disabling tracepoints during a trace experiment, then the
14453 change will be effective immediately. Otherwise, it will be applied to the
14454 next trace experiment.
14455
14456 @kindex enable tracepoint
14457 @item enable tracepoint @r{[}@var{num}@r{]}
14458 Enable tracepoint @var{num}, or all tracepoints. If this command is
14459 issued during a trace experiment and the debug target supports enabling
14460 tracepoints during a trace experiment, then the enabled tracepoints will
14461 become effective immediately. Otherwise, they will become effective the
14462 next time a trace experiment is run.
14463 @end table
14464
14465 @node Tracepoint Passcounts
14466 @subsection Tracepoint Passcounts
14467
14468 @table @code
14469 @kindex passcount
14470 @cindex tracepoint pass count
14471 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14472 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
14473 automatically stop a trace experiment. If a tracepoint's passcount is
14474 @var{n}, then the trace experiment will be automatically stopped on
14475 the @var{n}'th time that tracepoint is hit. If the tracepoint number
14476 @var{num} is not specified, the @code{passcount} command sets the
14477 passcount of the most recently defined tracepoint. If no passcount is
14478 given, the trace experiment will run until stopped explicitly by the
14479 user.
14480
14481 Examples:
14482
14483 @smallexample
14484 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
14485 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
14486
14487 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
14488 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
14489 (@value{GDBP}) @b{trace foo}
14490 (@value{GDBP}) @b{pass 3}
14491 (@value{GDBP}) @b{trace bar}
14492 (@value{GDBP}) @b{pass 2}
14493 (@value{GDBP}) @b{trace baz}
14494 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
14495 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14496 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14497 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
14498 @end smallexample
14499 @end table
14500
14501 @node Tracepoint Conditions
14502 @subsection Tracepoint Conditions
14503 @cindex conditional tracepoints
14504 @cindex tracepoint conditions
14505
14506 The simplest sort of tracepoint collects data every time your program
14507 reaches a specified place. You can also specify a @dfn{condition} for
14508 a tracepoint. A condition is just a Boolean expression in your
14509 programming language (@pxref{Expressions, ,Expressions}). A
14510 tracepoint with a condition evaluates the expression each time your
14511 program reaches it, and data collection happens only if the condition
14512 is true.
14513
14514 Tracepoint conditions can be specified when a tracepoint is set, by
14515 using @samp{if} in the arguments to the @code{trace} command.
14516 @xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
14517 also be set or changed at any time with the @code{condition} command,
14518 just as with breakpoints.
14519
14520 Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14521 the conditional expression itself. Instead, @value{GDBN} encodes the
14522 expression into an agent expression (@pxref{Agent Expressions})
14523 suitable for execution on the target, independently of @value{GDBN}.
14524 Global variables become raw memory locations, locals become stack
14525 accesses, and so forth.
14526
14527 For instance, suppose you have a function that is usually called
14528 frequently, but should not be called after an error has occurred. You
14529 could use the following tracepoint command to collect data about calls
14530 of that function that happen while the error code is propagating
14531 through the program; an unconditional tracepoint could end up
14532 collecting thousands of useless trace frames that you would have to
14533 search through.
14534
14535 @smallexample
14536 (@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14537 @end smallexample
14538
14539 @node Trace State Variables
14540 @subsection Trace State Variables
14541 @cindex trace state variables
14542
14543 A @dfn{trace state variable} is a special type of variable that is
14544 created and managed by target-side code. The syntax is the same as
14545 that for GDB's convenience variables (a string prefixed with ``$''),
14546 but they are stored on the target. They must be created explicitly,
14547 using a @code{tvariable} command. They are always 64-bit signed
14548 integers.
14549
14550 Trace state variables are remembered by @value{GDBN}, and downloaded
14551 to the target along with tracepoint information when the trace
14552 experiment starts. There are no intrinsic limits on the number of
14553 trace state variables, beyond memory limitations of the target.
14554
14555 @cindex convenience variables, and trace state variables
14556 Although trace state variables are managed by the target, you can use
14557 them in print commands and expressions as if they were convenience
14558 variables; @value{GDBN} will get the current value from the target
14559 while the trace experiment is running. Trace state variables share
14560 the same namespace as other ``$'' variables, which means that you
14561 cannot have trace state variables with names like @code{$23} or
14562 @code{$pc}, nor can you have a trace state variable and a convenience
14563 variable with the same name.
14564
14565 @table @code
14566
14567 @item tvariable $@var{name} [ = @var{expression} ]
14568 @kindex tvariable
14569 The @code{tvariable} command creates a new trace state variable named
14570 @code{$@var{name}}, and optionally gives it an initial value of
14571 @var{expression}. The @var{expression} is evaluated when this command is
14572 entered; the result will be converted to an integer if possible,
14573 otherwise @value{GDBN} will report an error. A subsequent
14574 @code{tvariable} command specifying the same name does not create a
14575 variable, but instead assigns the supplied initial value to the
14576 existing variable of that name, overwriting any previous initial
14577 value. The default initial value is 0.
14578
14579 @item info tvariables
14580 @kindex info tvariables
14581 List all the trace state variables along with their initial values.
14582 Their current values may also be displayed, if the trace experiment is
14583 currently running.
14584
14585 @item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14586 @kindex delete tvariable
14587 Delete the given trace state variables, or all of them if no arguments
14588 are specified.
14589
14590 @end table
14591
14592 @node Tracepoint Actions
14593 @subsection Tracepoint Action Lists
14594
14595 @table @code
14596 @kindex actions
14597 @cindex tracepoint actions
14598 @item actions @r{[}@var{num}@r{]}
14599 This command will prompt for a list of actions to be taken when the
14600 tracepoint is hit. If the tracepoint number @var{num} is not
14601 specified, this command sets the actions for the one that was most
14602 recently defined (so that you can define a tracepoint and then say
14603 @code{actions} without bothering about its number). You specify the
14604 actions themselves on the following lines, one action at a time, and
14605 terminate the actions list with a line containing just @code{end}. So
14606 far, the only defined actions are @code{collect}, @code{teval}, and
14607 @code{while-stepping}.
14608
14609 @code{actions} is actually equivalent to @code{commands} (@pxref{Break
14610 Commands, ,Breakpoint Command Lists}), except that only the defined
14611 actions are allowed; any other @value{GDBN} command is rejected.
14612
14613 @cindex remove actions from a tracepoint
14614 To remove all actions from a tracepoint, type @samp{actions @var{num}}
14615 and follow it immediately with @samp{end}.
14616
14617 @smallexample
14618 (@value{GDBP}) @b{collect @var{data}} // collect some data
14619
14620 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
14621
14622 (@value{GDBP}) @b{end} // signals the end of actions.
14623 @end smallexample
14624
14625 In the following example, the action list begins with @code{collect}
14626 commands indicating the things to be collected when the tracepoint is
14627 hit. Then, in order to single-step and collect additional data
14628 following the tracepoint, a @code{while-stepping} command is used,
14629 followed by the list of things to be collected after each step in a
14630 sequence of single steps. The @code{while-stepping} command is
14631 terminated by its own separate @code{end} command. Lastly, the action
14632 list is terminated by an @code{end} command.
14633
14634 @smallexample
14635 (@value{GDBP}) @b{trace foo}
14636 (@value{GDBP}) @b{actions}
14637 Enter actions for tracepoint 1, one per line:
14638 > collect bar,baz
14639 > collect $regs
14640 > while-stepping 12
14641 > collect $pc, arr[i]
14642 > end
14643 end
14644 @end smallexample
14645
14646 @kindex collect @r{(tracepoints)}
14647 @item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
14648 Collect values of the given expressions when the tracepoint is hit.
14649 This command accepts a comma-separated list of any valid expressions.
14650 In addition to global, static, or local variables, the following
14651 special arguments are supported:
14652
14653 @table @code
14654 @item $regs
14655 Collect all registers.
14656
14657 @item $args
14658 Collect all function arguments.
14659
14660 @item $locals
14661 Collect all local variables.
14662
14663 @item $_ret
14664 Collect the return address. This is helpful if you want to see more
14665 of a backtrace.
14666
14667 @emph{Note:} The return address location can not always be reliably
14668 determined up front, and the wrong address / registers may end up
14669 collected instead. On some architectures the reliability is higher
14670 for tracepoints at function entry, while on others it's the opposite.
14671 When this happens, backtracing will stop because the return address is
14672 found unavailable (unless another collect rule happened to match it).
14673
14674 @item $_probe_argc
14675 Collects the number of arguments from the static probe at which the
14676 tracepoint is located.
14677 @xref{Static Probe Points}.
14678
14679 @item $_probe_arg@var{n}
14680 @var{n} is an integer between 0 and 11. Collects the @var{n}th argument
14681 from the static probe at which the tracepoint is located.
14682 @xref{Static Probe Points}.
14683
14684 @item $_sdata
14685 @vindex $_sdata@r{, collect}
14686 Collect static tracepoint marker specific data. Only available for
14687 static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
14688 Lists}. On the UST static tracepoints library backend, an
14689 instrumentation point resembles a @code{printf} function call. The
14690 tracing library is able to collect user specified data formatted to a
14691 character string using the format provided by the programmer that
14692 instrumented the program. Other backends have similar mechanisms.
14693 Here's an example of a UST marker call:
14694
14695 @smallexample
14696 const char master_name[] = "$your_name";
14697 trace_mark(channel1, marker1, "hello %s", master_name)
14698 @end smallexample
14699
14700 In this case, collecting @code{$_sdata} collects the string
14701 @samp{hello $yourname}. When analyzing the trace buffer, you can
14702 inspect @samp{$_sdata} like any other variable available to
14703 @value{GDBN}.
14704 @end table
14705
14706 You can give several consecutive @code{collect} commands, each one
14707 with a single argument, or one @code{collect} command with several
14708 arguments separated by commas; the effect is the same.
14709
14710 The optional @var{mods} changes the usual handling of the arguments.
14711 @code{s} requests that pointers to chars be handled as strings, in
14712 particular collecting the contents of the memory being pointed at, up
14713 to the first zero. The upper bound is by default the value of the
14714 @code{print elements} variable; if @code{s} is followed by a decimal
14715 number, that is the upper bound instead. So for instance
14716 @samp{collect/s25 mystr} collects as many as 25 characters at
14717 @samp{mystr}.
14718
14719 The command @code{info scope} (@pxref{Symbols, info scope}) is
14720 particularly useful for figuring out what data to collect.
14721
14722 @kindex teval @r{(tracepoints)}
14723 @item teval @var{expr1}, @var{expr2}, @dots{}
14724 Evaluate the given expressions when the tracepoint is hit. This
14725 command accepts a comma-separated list of expressions. The results
14726 are discarded, so this is mainly useful for assigning values to trace
14727 state variables (@pxref{Trace State Variables}) without adding those
14728 values to the trace buffer, as would be the case if the @code{collect}
14729 action were used.
14730
14731 @kindex while-stepping @r{(tracepoints)}
14732 @item while-stepping @var{n}
14733 Perform @var{n} single-step instruction traces after the tracepoint,
14734 collecting new data after each step. The @code{while-stepping}
14735 command is followed by the list of what to collect while stepping
14736 (followed by its own @code{end} command):
14737
14738 @smallexample
14739 > while-stepping 12
14740 > collect $regs, myglobal
14741 > end
14742 >
14743 @end smallexample
14744
14745 @noindent
14746 Note that @code{$pc} is not automatically collected by
14747 @code{while-stepping}; you need to explicitly collect that register if
14748 you need it. You may abbreviate @code{while-stepping} as @code{ws} or
14749 @code{stepping}.
14750
14751 @item set default-collect @var{expr1}, @var{expr2}, @dots{}
14752 @kindex set default-collect
14753 @cindex default collection action
14754 This variable is a list of expressions to collect at each tracepoint
14755 hit. It is effectively an additional @code{collect} action prepended
14756 to every tracepoint action list. The expressions are parsed
14757 individually for each tracepoint, so for instance a variable named
14758 @code{xyz} may be interpreted as a global for one tracepoint, and a
14759 local for another, as appropriate to the tracepoint's location.
14760
14761 @item show default-collect
14762 @kindex show default-collect
14763 Show the list of expressions that are collected by default at each
14764 tracepoint hit.
14765
14766 @end table
14767
14768 @node Listing Tracepoints
14769 @subsection Listing Tracepoints
14770
14771 @table @code
14772 @kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
14773 @kindex info tp @r{[}@var{n}@dots{}@r{]}
14774 @cindex information about tracepoints
14775 @item info tracepoints @r{[}@var{num}@dots{}@r{]}
14776 Display information about the tracepoint @var{num}. If you don't
14777 specify a tracepoint number, displays information about all the
14778 tracepoints defined so far. The format is similar to that used for
14779 @code{info breakpoints}; in fact, @code{info tracepoints} is the same
14780 command, simply restricting itself to tracepoints.
14781
14782 A tracepoint's listing may include additional information specific to
14783 tracing:
14784
14785 @itemize @bullet
14786 @item
14787 its passcount as given by the @code{passcount @var{n}} command
14788
14789 @item
14790 the state about installed on target of each location
14791 @end itemize
14792
14793 @smallexample
14794 (@value{GDBP}) @b{info trace}
14795 Num Type Disp Enb Address What
14796 1 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
14797 while-stepping 20
14798 collect globfoo, $regs
14799 end
14800 collect globfoo2
14801 end
14802 pass count 1200
14803 2 tracepoint keep y <MULTIPLE>
14804 collect $eip
14805 2.1 y 0x0804859c in func4 at change-loc.h:35
14806 installed on target
14807 2.2 y 0xb7ffc480 in func4 at change-loc.h:35
14808 installed on target
14809 2.3 y <PENDING> set_tracepoint
14810 3 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
14811 not installed on target
14812 (@value{GDBP})
14813 @end smallexample
14814
14815 @noindent
14816 This command can be abbreviated @code{info tp}.
14817 @end table
14818
14819 @node Listing Static Tracepoint Markers
14820 @subsection Listing Static Tracepoint Markers
14821
14822 @table @code
14823 @kindex info static-tracepoint-markers
14824 @cindex information about static tracepoint markers
14825 @item info static-tracepoint-markers
14826 Display information about all static tracepoint markers defined in the
14827 program.
14828
14829 For each marker, the following columns are printed:
14830
14831 @table @emph
14832 @item Count
14833 An incrementing counter, output to help readability. This is not a
14834 stable identifier.
14835 @item ID
14836 The marker ID, as reported by the target.
14837 @item Enabled or Disabled
14838 Probed markers are tagged with @samp{y}. @samp{n} identifies marks
14839 that are not enabled.
14840 @item Address
14841 Where the marker is in your program, as a memory address.
14842 @item What
14843 Where the marker is in the source for your program, as a file and line
14844 number. If the debug information included in the program does not
14845 allow @value{GDBN} to locate the source of the marker, this column
14846 will be left blank.
14847 @end table
14848
14849 @noindent
14850 In addition, the following information may be printed for each marker:
14851
14852 @table @emph
14853 @item Data
14854 User data passed to the tracing library by the marker call. In the
14855 UST backend, this is the format string passed as argument to the
14856 marker call.
14857 @item Static tracepoints probing the marker
14858 The list of static tracepoints attached to the marker.
14859 @end table
14860
14861 @smallexample
14862 (@value{GDBP}) info static-tracepoint-markers
14863 Cnt ID Enb Address What
14864 1 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
14865 Data: number1 %d number2 %d
14866 Probed by static tracepoints: #2
14867 2 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
14868 Data: str %s
14869 (@value{GDBP})
14870 @end smallexample
14871 @end table
14872
14873 @node Starting and Stopping Trace Experiments
14874 @subsection Starting and Stopping Trace Experiments
14875
14876 @table @code
14877 @kindex tstart [ @var{notes} ]
14878 @cindex start a new trace experiment
14879 @cindex collected data discarded
14880 @item tstart
14881 This command starts the trace experiment, and begins collecting data.
14882 It has the side effect of discarding all the data collected in the
14883 trace buffer during the previous trace experiment. If any arguments
14884 are supplied, they are taken as a note and stored with the trace
14885 experiment's state. The notes may be arbitrary text, and are
14886 especially useful with disconnected tracing in a multi-user context;
14887 the notes can explain what the trace is doing, supply user contact
14888 information, and so forth.
14889
14890 @kindex tstop [ @var{notes} ]
14891 @cindex stop a running trace experiment
14892 @item tstop
14893 This command stops the trace experiment. If any arguments are
14894 supplied, they are recorded with the experiment as a note. This is
14895 useful if you are stopping a trace started by someone else, for
14896 instance if the trace is interfering with the system's behavior and
14897 needs to be stopped quickly.
14898
14899 @strong{Note}: a trace experiment and data collection may stop
14900 automatically if any tracepoint's passcount is reached
14901 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
14902
14903 @kindex tstatus
14904 @cindex status of trace data collection
14905 @cindex trace experiment, status of
14906 @item tstatus
14907 This command displays the status of the current trace data
14908 collection.
14909 @end table
14910
14911 Here is an example of the commands we described so far:
14912
14913 @smallexample
14914 (@value{GDBP}) @b{trace gdb_c_test}
14915 (@value{GDBP}) @b{actions}
14916 Enter actions for tracepoint #1, one per line.
14917 > collect $regs,$locals,$args
14918 > while-stepping 11
14919 > collect $regs
14920 > end
14921 > end
14922 (@value{GDBP}) @b{tstart}
14923 [time passes @dots{}]
14924 (@value{GDBP}) @b{tstop}
14925 @end smallexample
14926
14927 @anchor{disconnected tracing}
14928 @cindex disconnected tracing
14929 You can choose to continue running the trace experiment even if
14930 @value{GDBN} disconnects from the target, voluntarily or
14931 involuntarily. For commands such as @code{detach}, the debugger will
14932 ask what you want to do with the trace. But for unexpected
14933 terminations (@value{GDBN} crash, network outage), it would be
14934 unfortunate to lose hard-won trace data, so the variable
14935 @code{disconnected-tracing} lets you decide whether the trace should
14936 continue running without @value{GDBN}.
14937
14938 @table @code
14939 @item set disconnected-tracing on
14940 @itemx set disconnected-tracing off
14941 @kindex set disconnected-tracing
14942 Choose whether a tracing run should continue to run if @value{GDBN}
14943 has disconnected from the target. Note that @code{detach} or
14944 @code{quit} will ask you directly what to do about a running trace no
14945 matter what this variable's setting, so the variable is mainly useful
14946 for handling unexpected situations, such as loss of the network.
14947
14948 @item show disconnected-tracing
14949 @kindex show disconnected-tracing
14950 Show the current choice for disconnected tracing.
14951
14952 @end table
14953
14954 When you reconnect to the target, the trace experiment may or may not
14955 still be running; it might have filled the trace buffer in the
14956 meantime, or stopped for one of the other reasons. If it is running,
14957 it will continue after reconnection.
14958
14959 Upon reconnection, the target will upload information about the
14960 tracepoints in effect. @value{GDBN} will then compare that
14961 information to the set of tracepoints currently defined, and attempt
14962 to match them up, allowing for the possibility that the numbers may
14963 have changed due to creation and deletion in the meantime. If one of
14964 the target's tracepoints does not match any in @value{GDBN}, the
14965 debugger will create a new tracepoint, so that you have a number with
14966 which to specify that tracepoint. This matching-up process is
14967 necessarily heuristic, and it may result in useless tracepoints being
14968 created; you may simply delete them if they are of no use.
14969
14970 @cindex circular trace buffer
14971 If your target agent supports a @dfn{circular trace buffer}, then you
14972 can run a trace experiment indefinitely without filling the trace
14973 buffer; when space runs out, the agent deletes already-collected trace
14974 frames, oldest first, until there is enough room to continue
14975 collecting. This is especially useful if your tracepoints are being
14976 hit too often, and your trace gets terminated prematurely because the
14977 buffer is full. To ask for a circular trace buffer, simply set
14978 @samp{circular-trace-buffer} to on. You can set this at any time,
14979 including during tracing; if the agent can do it, it will change
14980 buffer handling on the fly, otherwise it will not take effect until
14981 the next run.
14982
14983 @table @code
14984 @item set circular-trace-buffer on
14985 @itemx set circular-trace-buffer off
14986 @kindex set circular-trace-buffer
14987 Choose whether a tracing run should use a linear or circular buffer
14988 for trace data. A linear buffer will not lose any trace data, but may
14989 fill up prematurely, while a circular buffer will discard old trace
14990 data, but it will have always room for the latest tracepoint hits.
14991
14992 @item show circular-trace-buffer
14993 @kindex show circular-trace-buffer
14994 Show the current choice for the trace buffer. Note that this may not
14995 match the agent's current buffer handling, nor is it guaranteed to
14996 match the setting that might have been in effect during a past run,
14997 for instance if you are looking at frames from a trace file.
14998
14999 @end table
15000
15001 @table @code
15002 @item set trace-buffer-size @var{n}
15003 @itemx set trace-buffer-size unlimited
15004 @kindex set trace-buffer-size
15005 Request that the target use a trace buffer of @var{n} bytes. Not all
15006 targets will honor the request; they may have a compiled-in size for
15007 the trace buffer, or some other limitation. Set to a value of
15008 @code{unlimited} or @code{-1} to let the target use whatever size it
15009 likes. This is also the default.
15010
15011 @item show trace-buffer-size
15012 @kindex show trace-buffer-size
15013 Show the current requested size for the trace buffer. Note that this
15014 will only match the actual size if the target supports size-setting,
15015 and was able to handle the requested size. For instance, if the
15016 target can only change buffer size between runs, this variable will
15017 not reflect the change until the next run starts. Use @code{tstatus}
15018 to get a report of the actual buffer size.
15019 @end table
15020
15021 @table @code
15022 @item set trace-user @var{text}
15023 @kindex set trace-user
15024
15025 @item show trace-user
15026 @kindex show trace-user
15027
15028 @item set trace-notes @var{text}
15029 @kindex set trace-notes
15030 Set the trace run's notes.
15031
15032 @item show trace-notes
15033 @kindex show trace-notes
15034 Show the trace run's notes.
15035
15036 @item set trace-stop-notes @var{text}
15037 @kindex set trace-stop-notes
15038 Set the trace run's stop notes. The handling of the note is as for
15039 @code{tstop} arguments; the set command is convenient way to fix a
15040 stop note that is mistaken or incomplete.
15041
15042 @item show trace-stop-notes
15043 @kindex show trace-stop-notes
15044 Show the trace run's stop notes.
15045
15046 @end table
15047
15048 @node Tracepoint Restrictions
15049 @subsection Tracepoint Restrictions
15050
15051 @cindex tracepoint restrictions
15052 There are a number of restrictions on the use of tracepoints. As
15053 described above, tracepoint data gathering occurs on the target
15054 without interaction from @value{GDBN}. Thus the full capabilities of
15055 the debugger are not available during data gathering, and then at data
15056 examination time, you will be limited by only having what was
15057 collected. The following items describe some common problems, but it
15058 is not exhaustive, and you may run into additional difficulties not
15059 mentioned here.
15060
15061 @itemize @bullet
15062
15063 @item
15064 Tracepoint expressions are intended to gather objects (lvalues). Thus
15065 the full flexibility of GDB's expression evaluator is not available.
15066 You cannot call functions, cast objects to aggregate types, access
15067 convenience variables or modify values (except by assignment to trace
15068 state variables). Some language features may implicitly call
15069 functions (for instance Objective-C fields with accessors), and therefore
15070 cannot be collected either.
15071
15072 @item
15073 Collection of local variables, either individually or in bulk with
15074 @code{$locals} or @code{$args}, during @code{while-stepping} may
15075 behave erratically. The stepping action may enter a new scope (for
15076 instance by stepping into a function), or the location of the variable
15077 may change (for instance it is loaded into a register). The
15078 tracepoint data recorded uses the location information for the
15079 variables that is correct for the tracepoint location. When the
15080 tracepoint is created, it is not possible, in general, to determine
15081 where the steps of a @code{while-stepping} sequence will advance the
15082 program---particularly if a conditional branch is stepped.
15083
15084 @item
15085 Collection of an incompletely-initialized or partially-destroyed object
15086 may result in something that @value{GDBN} cannot display, or displays
15087 in a misleading way.
15088
15089 @item
15090 When @value{GDBN} displays a pointer to character it automatically
15091 dereferences the pointer to also display characters of the string
15092 being pointed to. However, collecting the pointer during tracing does
15093 not automatically collect the string. You need to explicitly
15094 dereference the pointer and provide size information if you want to
15095 collect not only the pointer, but the memory pointed to. For example,
15096 @code{*ptr@@50} can be used to collect the 50 element array pointed to
15097 by @code{ptr}.
15098
15099 @item
15100 It is not possible to collect a complete stack backtrace at a
15101 tracepoint. Instead, you may collect the registers and a few hundred
15102 bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
15103 (adjust to use the name of the actual stack pointer register on your
15104 target architecture, and the amount of stack you wish to capture).
15105 Then the @code{backtrace} command will show a partial backtrace when
15106 using a trace frame. The number of stack frames that can be examined
15107 depends on the sizes of the frames in the collected stack. Note that
15108 if you ask for a block so large that it goes past the bottom of the
15109 stack, the target agent may report an error trying to read from an
15110 invalid address.
15111
15112 @item
15113 If you do not collect registers at a tracepoint, @value{GDBN} can
15114 infer that the value of @code{$pc} must be the same as the address of
15115 the tracepoint and use that when you are looking at a trace frame
15116 for that tracepoint. However, this cannot work if the tracepoint has
15117 multiple locations (for instance if it was set in a function that was
15118 inlined), or if it has a @code{while-stepping} loop. In those cases
15119 @value{GDBN} will warn you that it can't infer @code{$pc}, and default
15120 it to zero.
15121
15122 @end itemize
15123
15124 @node Analyze Collected Data
15125 @section Using the Collected Data
15126
15127 After the tracepoint experiment ends, you use @value{GDBN} commands
15128 for examining the trace data. The basic idea is that each tracepoint
15129 collects a trace @dfn{snapshot} every time it is hit and another
15130 snapshot every time it single-steps. All these snapshots are
15131 consecutively numbered from zero and go into a buffer, and you can
15132 examine them later. The way you examine them is to @dfn{focus} on a
15133 specific trace snapshot. When the remote stub is focused on a trace
15134 snapshot, it will respond to all @value{GDBN} requests for memory and
15135 registers by reading from the buffer which belongs to that snapshot,
15136 rather than from @emph{real} memory or registers of the program being
15137 debugged. This means that @strong{all} @value{GDBN} commands
15138 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
15139 behave as if we were currently debugging the program state as it was
15140 when the tracepoint occurred. Any requests for data that are not in
15141 the buffer will fail.
15142
15143 @menu
15144 * tfind:: How to select a trace snapshot
15145 * tdump:: How to display all data for a snapshot
15146 * save tracepoints:: How to save tracepoints for a future run
15147 @end menu
15148
15149 @node tfind
15150 @subsection @code{tfind @var{n}}
15151
15152 @kindex tfind
15153 @cindex select trace snapshot
15154 @cindex find trace snapshot
15155 The basic command for selecting a trace snapshot from the buffer is
15156 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
15157 counting from zero. If no argument @var{n} is given, the next
15158 snapshot is selected.
15159
15160 Here are the various forms of using the @code{tfind} command.
15161
15162 @table @code
15163 @item tfind start
15164 Find the first snapshot in the buffer. This is a synonym for
15165 @code{tfind 0} (since 0 is the number of the first snapshot).
15166
15167 @item tfind none
15168 Stop debugging trace snapshots, resume @emph{live} debugging.
15169
15170 @item tfind end
15171 Same as @samp{tfind none}.
15172
15173 @item tfind
15174 No argument means find the next trace snapshot or find the first
15175 one if no trace snapshot is selected.
15176
15177 @item tfind -
15178 Find the previous trace snapshot before the current one. This permits
15179 retracing earlier steps.
15180
15181 @item tfind tracepoint @var{num}
15182 Find the next snapshot associated with tracepoint @var{num}. Search
15183 proceeds forward from the last examined trace snapshot. If no
15184 argument @var{num} is given, it means find the next snapshot collected
15185 for the same tracepoint as the current snapshot.
15186
15187 @item tfind pc @var{addr}
15188 Find the next snapshot associated with the value @var{addr} of the
15189 program counter. Search proceeds forward from the last examined trace
15190 snapshot. If no argument @var{addr} is given, it means find the next
15191 snapshot with the same value of PC as the current snapshot.
15192
15193 @item tfind outside @var{addr1}, @var{addr2}
15194 Find the next snapshot whose PC is outside the given range of
15195 addresses (exclusive).
15196
15197 @item tfind range @var{addr1}, @var{addr2}
15198 Find the next snapshot whose PC is between @var{addr1} and
15199 @var{addr2} (inclusive).
15200
15201 @item tfind line @r{[}@var{file}:@r{]}@var{n}
15202 Find the next snapshot associated with the source line @var{n}. If
15203 the optional argument @var{file} is given, refer to line @var{n} in
15204 that source file. Search proceeds forward from the last examined
15205 trace snapshot. If no argument @var{n} is given, it means find the
15206 next line other than the one currently being examined; thus saying
15207 @code{tfind line} repeatedly can appear to have the same effect as
15208 stepping from line to line in a @emph{live} debugging session.
15209 @end table
15210
15211 The default arguments for the @code{tfind} commands are specifically
15212 designed to make it easy to scan through the trace buffer. For
15213 instance, @code{tfind} with no argument selects the next trace
15214 snapshot, and @code{tfind -} with no argument selects the previous
15215 trace snapshot. So, by giving one @code{tfind} command, and then
15216 simply hitting @key{RET} repeatedly you can examine all the trace
15217 snapshots in order. Or, by saying @code{tfind -} and then hitting
15218 @key{RET} repeatedly you can examine the snapshots in reverse order.
15219 The @code{tfind line} command with no argument selects the snapshot
15220 for the next source line executed. The @code{tfind pc} command with
15221 no argument selects the next snapshot with the same program counter
15222 (PC) as the current frame. The @code{tfind tracepoint} command with
15223 no argument selects the next trace snapshot collected by the same
15224 tracepoint as the current one.
15225
15226 In addition to letting you scan through the trace buffer manually,
15227 these commands make it easy to construct @value{GDBN} scripts that
15228 scan through the trace buffer and print out whatever collected data
15229 you are interested in. Thus, if we want to examine the PC, FP, and SP
15230 registers from each trace frame in the buffer, we can say this:
15231
15232 @smallexample
15233 (@value{GDBP}) @b{tfind start}
15234 (@value{GDBP}) @b{while ($trace_frame != -1)}
15235 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
15236 $trace_frame, $pc, $sp, $fp
15237 > tfind
15238 > end
15239
15240 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
15241 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
15242 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
15243 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
15244 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
15245 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
15246 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
15247 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
15248 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
15249 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
15250 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
15251 @end smallexample
15252
15253 Or, if we want to examine the variable @code{X} at each source line in
15254 the buffer:
15255
15256 @smallexample
15257 (@value{GDBP}) @b{tfind start}
15258 (@value{GDBP}) @b{while ($trace_frame != -1)}
15259 > printf "Frame %d, X == %d\n", $trace_frame, X
15260 > tfind line
15261 > end
15262
15263 Frame 0, X = 1
15264 Frame 7, X = 2
15265 Frame 13, X = 255
15266 @end smallexample
15267
15268 @node tdump
15269 @subsection @code{tdump}
15270 @kindex tdump
15271 @cindex dump all data collected at tracepoint
15272 @cindex tracepoint data, display
15273
15274 This command takes no arguments. It prints all the data collected at
15275 the current trace snapshot.
15276
15277 @smallexample
15278 (@value{GDBP}) @b{trace 444}
15279 (@value{GDBP}) @b{actions}
15280 Enter actions for tracepoint #2, one per line:
15281 > collect $regs, $locals, $args, gdb_long_test
15282 > end
15283
15284 (@value{GDBP}) @b{tstart}
15285
15286 (@value{GDBP}) @b{tfind line 444}
15287 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15288 at gdb_test.c:444
15289 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15290
15291 (@value{GDBP}) @b{tdump}
15292 Data collected at tracepoint 2, trace frame 1:
15293 d0 0xc4aa0085 -995491707
15294 d1 0x18 24
15295 d2 0x80 128
15296 d3 0x33 51
15297 d4 0x71aea3d 119204413
15298 d5 0x22 34
15299 d6 0xe0 224
15300 d7 0x380035 3670069
15301 a0 0x19e24a 1696330
15302 a1 0x3000668 50333288
15303 a2 0x100 256
15304 a3 0x322000 3284992
15305 a4 0x3000698 50333336
15306 a5 0x1ad3cc 1758156
15307 fp 0x30bf3c 0x30bf3c
15308 sp 0x30bf34 0x30bf34
15309 ps 0x0 0
15310 pc 0x20b2c8 0x20b2c8
15311 fpcontrol 0x0 0
15312 fpstatus 0x0 0
15313 fpiaddr 0x0 0
15314 p = 0x20e5b4 "gdb-test"
15315 p1 = (void *) 0x11
15316 p2 = (void *) 0x22
15317 p3 = (void *) 0x33
15318 p4 = (void *) 0x44
15319 p5 = (void *) 0x55
15320 p6 = (void *) 0x66
15321 gdb_long_test = 17 '\021'
15322
15323 (@value{GDBP})
15324 @end smallexample
15325
15326 @code{tdump} works by scanning the tracepoint's current collection
15327 actions and printing the value of each expression listed. So
15328 @code{tdump} can fail, if after a run, you change the tracepoint's
15329 actions to mention variables that were not collected during the run.
15330
15331 Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15332 uses the collected value of @code{$pc} to distinguish between trace
15333 frames that were collected at the tracepoint hit, and frames that were
15334 collected while stepping. This allows it to correctly choose whether
15335 to display the basic list of collections, or the collections from the
15336 body of the while-stepping loop. However, if @code{$pc} was not collected,
15337 then @code{tdump} will always attempt to dump using the basic collection
15338 list, and may fail if a while-stepping frame does not include all the
15339 same data that is collected at the tracepoint hit.
15340 @c This is getting pretty arcane, example would be good.
15341
15342 @node save tracepoints
15343 @subsection @code{save tracepoints @var{filename}}
15344 @kindex save tracepoints
15345 @kindex save-tracepoints
15346 @cindex save tracepoints for future sessions
15347
15348 This command saves all current tracepoint definitions together with
15349 their actions and passcounts, into a file @file{@var{filename}}
15350 suitable for use in a later debugging session. To read the saved
15351 tracepoint definitions, use the @code{source} command (@pxref{Command
15352 Files}). The @w{@code{save-tracepoints}} command is a deprecated
15353 alias for @w{@code{save tracepoints}}
15354
15355 @node Tracepoint Variables
15356 @section Convenience Variables for Tracepoints
15357 @cindex tracepoint variables
15358 @cindex convenience variables for tracepoints
15359
15360 @table @code
15361 @vindex $trace_frame
15362 @item (int) $trace_frame
15363 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15364 snapshot is selected.
15365
15366 @vindex $tracepoint
15367 @item (int) $tracepoint
15368 The tracepoint for the current trace snapshot.
15369
15370 @vindex $trace_line
15371 @item (int) $trace_line
15372 The line number for the current trace snapshot.
15373
15374 @vindex $trace_file
15375 @item (char []) $trace_file
15376 The source file for the current trace snapshot.
15377
15378 @vindex $trace_func
15379 @item (char []) $trace_func
15380 The name of the function containing @code{$tracepoint}.
15381 @end table
15382
15383 Note: @code{$trace_file} is not suitable for use in @code{printf},
15384 use @code{output} instead.
15385
15386 Here's a simple example of using these convenience variables for
15387 stepping through all the trace snapshots and printing some of their
15388 data. Note that these are not the same as trace state variables,
15389 which are managed by the target.
15390
15391 @smallexample
15392 (@value{GDBP}) @b{tfind start}
15393
15394 (@value{GDBP}) @b{while $trace_frame != -1}
15395 > output $trace_file
15396 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15397 > tfind
15398 > end
15399 @end smallexample
15400
15401 @node Trace Files
15402 @section Using Trace Files
15403 @cindex trace files
15404
15405 In some situations, the target running a trace experiment may no
15406 longer be available; perhaps it crashed, or the hardware was needed
15407 for a different activity. To handle these cases, you can arrange to
15408 dump the trace data into a file, and later use that file as a source
15409 of trace data, via the @code{target tfile} command.
15410
15411 @table @code
15412
15413 @kindex tsave
15414 @item tsave [ -r ] @var{filename}
15415 @itemx tsave [-ctf] @var{dirname}
15416 Save the trace data to @var{filename}. By default, this command
15417 assumes that @var{filename} refers to the host filesystem, so if
15418 necessary @value{GDBN} will copy raw trace data up from the target and
15419 then save it. If the target supports it, you can also supply the
15420 optional argument @code{-r} (``remote'') to direct the target to save
15421 the data directly into @var{filename} in its own filesystem, which may be
15422 more efficient if the trace buffer is very large. (Note, however, that
15423 @code{target tfile} can only read from files accessible to the host.)
15424 By default, this command will save trace frame in tfile format.
15425 You can supply the optional argument @code{-ctf} to save data in CTF
15426 format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15427 that can be shared by multiple debugging and tracing tools. Please go to
15428 @indicateurl{http://www.efficios.com/ctf} to get more information.
15429
15430 @kindex target tfile
15431 @kindex tfile
15432 @kindex target ctf
15433 @kindex ctf
15434 @item target tfile @var{filename}
15435 @itemx target ctf @var{dirname}
15436 Use the file named @var{filename} or directory named @var{dirname} as
15437 a source of trace data. Commands that examine data work as they do with
15438 a live target, but it is not possible to run any new trace experiments.
15439 @code{tstatus} will report the state of the trace run at the moment
15440 the data was saved, as well as the current trace frame you are examining.
15441 Both @var{filename} and @var{dirname} must be on a filesystem accessible to
15442 the host.
15443
15444 @smallexample
15445 (@value{GDBP}) target ctf ctf.ctf
15446 (@value{GDBP}) tfind
15447 Found trace frame 0, tracepoint 2
15448 39 ++a; /* set tracepoint 1 here */
15449 (@value{GDBP}) tdump
15450 Data collected at tracepoint 2, trace frame 0:
15451 i = 0
15452 a = 0
15453 b = 1 '\001'
15454 c = @{"123", "456", "789", "123", "456", "789"@}
15455 d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15456 (@value{GDBP}) p b
15457 $1 = 1
15458 @end smallexample
15459
15460 @end table
15461
15462 @node Overlays
15463 @chapter Debugging Programs That Use Overlays
15464 @cindex overlays
15465
15466 If your program is too large to fit completely in your target system's
15467 memory, you can sometimes use @dfn{overlays} to work around this
15468 problem. @value{GDBN} provides some support for debugging programs that
15469 use overlays.
15470
15471 @menu
15472 * How Overlays Work:: A general explanation of overlays.
15473 * Overlay Commands:: Managing overlays in @value{GDBN}.
15474 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
15475 mapped by asking the inferior.
15476 * Overlay Sample Program:: A sample program using overlays.
15477 @end menu
15478
15479 @node How Overlays Work
15480 @section How Overlays Work
15481 @cindex mapped overlays
15482 @cindex unmapped overlays
15483 @cindex load address, overlay's
15484 @cindex mapped address
15485 @cindex overlay area
15486
15487 Suppose you have a computer whose instruction address space is only 64
15488 kilobytes long, but which has much more memory which can be accessed by
15489 other means: special instructions, segment registers, or memory
15490 management hardware, for example. Suppose further that you want to
15491 adapt a program which is larger than 64 kilobytes to run on this system.
15492
15493 One solution is to identify modules of your program which are relatively
15494 independent, and need not call each other directly; call these modules
15495 @dfn{overlays}. Separate the overlays from the main program, and place
15496 their machine code in the larger memory. Place your main program in
15497 instruction memory, but leave at least enough space there to hold the
15498 largest overlay as well.
15499
15500 Now, to call a function located in an overlay, you must first copy that
15501 overlay's machine code from the large memory into the space set aside
15502 for it in the instruction memory, and then jump to its entry point
15503 there.
15504
15505 @c NB: In the below the mapped area's size is greater or equal to the
15506 @c size of all overlays. This is intentional to remind the developer
15507 @c that overlays don't necessarily need to be the same size.
15508
15509 @smallexample
15510 @group
15511 Data Instruction Larger
15512 Address Space Address Space Address Space
15513 +-----------+ +-----------+ +-----------+
15514 | | | | | |
15515 +-----------+ +-----------+ +-----------+<-- overlay 1
15516 | program | | main | .----| overlay 1 | load address
15517 | variables | | program | | +-----------+
15518 | and heap | | | | | |
15519 +-----------+ | | | +-----------+<-- overlay 2
15520 | | +-----------+ | | | load address
15521 +-----------+ | | | .-| overlay 2 |
15522 | | | | | |
15523 mapped --->+-----------+ | | +-----------+
15524 address | | | | | |
15525 | overlay | <-' | | |
15526 | area | <---' +-----------+<-- overlay 3
15527 | | <---. | | load address
15528 +-----------+ `--| overlay 3 |
15529 | | | |
15530 +-----------+ | |
15531 +-----------+
15532 | |
15533 +-----------+
15534
15535 @anchor{A code overlay}A code overlay
15536 @end group
15537 @end smallexample
15538
15539 The diagram (@pxref{A code overlay}) shows a system with separate data
15540 and instruction address spaces. To map an overlay, the program copies
15541 its code from the larger address space to the instruction address space.
15542 Since the overlays shown here all use the same mapped address, only one
15543 may be mapped at a time. For a system with a single address space for
15544 data and instructions, the diagram would be similar, except that the
15545 program variables and heap would share an address space with the main
15546 program and the overlay area.
15547
15548 An overlay loaded into instruction memory and ready for use is called a
15549 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15550 instruction memory. An overlay not present (or only partially present)
15551 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15552 is its address in the larger memory. The mapped address is also called
15553 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15554 called the @dfn{load memory address}, or @dfn{LMA}.
15555
15556 Unfortunately, overlays are not a completely transparent way to adapt a
15557 program to limited instruction memory. They introduce a new set of
15558 global constraints you must keep in mind as you design your program:
15559
15560 @itemize @bullet
15561
15562 @item
15563 Before calling or returning to a function in an overlay, your program
15564 must make sure that overlay is actually mapped. Otherwise, the call or
15565 return will transfer control to the right address, but in the wrong
15566 overlay, and your program will probably crash.
15567
15568 @item
15569 If the process of mapping an overlay is expensive on your system, you
15570 will need to choose your overlays carefully to minimize their effect on
15571 your program's performance.
15572
15573 @item
15574 The executable file you load onto your system must contain each
15575 overlay's instructions, appearing at the overlay's load address, not its
15576 mapped address. However, each overlay's instructions must be relocated
15577 and its symbols defined as if the overlay were at its mapped address.
15578 You can use GNU linker scripts to specify different load and relocation
15579 addresses for pieces of your program; see @ref{Overlay Description,,,
15580 ld.info, Using ld: the GNU linker}.
15581
15582 @item
15583 The procedure for loading executable files onto your system must be able
15584 to load their contents into the larger address space as well as the
15585 instruction and data spaces.
15586
15587 @end itemize
15588
15589 The overlay system described above is rather simple, and could be
15590 improved in many ways:
15591
15592 @itemize @bullet
15593
15594 @item
15595 If your system has suitable bank switch registers or memory management
15596 hardware, you could use those facilities to make an overlay's load area
15597 contents simply appear at their mapped address in instruction space.
15598 This would probably be faster than copying the overlay to its mapped
15599 area in the usual way.
15600
15601 @item
15602 If your overlays are small enough, you could set aside more than one
15603 overlay area, and have more than one overlay mapped at a time.
15604
15605 @item
15606 You can use overlays to manage data, as well as instructions. In
15607 general, data overlays are even less transparent to your design than
15608 code overlays: whereas code overlays only require care when you call or
15609 return to functions, data overlays require care every time you access
15610 the data. Also, if you change the contents of a data overlay, you
15611 must copy its contents back out to its load address before you can copy a
15612 different data overlay into the same mapped area.
15613
15614 @end itemize
15615
15616
15617 @node Overlay Commands
15618 @section Overlay Commands
15619
15620 To use @value{GDBN}'s overlay support, each overlay in your program must
15621 correspond to a separate section of the executable file. The section's
15622 virtual memory address and load memory address must be the overlay's
15623 mapped and load addresses. Identifying overlays with sections allows
15624 @value{GDBN} to determine the appropriate address of a function or
15625 variable, depending on whether the overlay is mapped or not.
15626
15627 @value{GDBN}'s overlay commands all start with the word @code{overlay};
15628 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
15629
15630 @table @code
15631 @item overlay off
15632 @kindex overlay
15633 Disable @value{GDBN}'s overlay support. When overlay support is
15634 disabled, @value{GDBN} assumes that all functions and variables are
15635 always present at their mapped addresses. By default, @value{GDBN}'s
15636 overlay support is disabled.
15637
15638 @item overlay manual
15639 @cindex manual overlay debugging
15640 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
15641 relies on you to tell it which overlays are mapped, and which are not,
15642 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
15643 commands described below.
15644
15645 @item overlay map-overlay @var{overlay}
15646 @itemx overlay map @var{overlay}
15647 @cindex map an overlay
15648 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
15649 be the name of the object file section containing the overlay. When an
15650 overlay is mapped, @value{GDBN} assumes it can find the overlay's
15651 functions and variables at their mapped addresses. @value{GDBN} assumes
15652 that any other overlays whose mapped ranges overlap that of
15653 @var{overlay} are now unmapped.
15654
15655 @item overlay unmap-overlay @var{overlay}
15656 @itemx overlay unmap @var{overlay}
15657 @cindex unmap an overlay
15658 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
15659 must be the name of the object file section containing the overlay.
15660 When an overlay is unmapped, @value{GDBN} assumes it can find the
15661 overlay's functions and variables at their load addresses.
15662
15663 @item overlay auto
15664 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
15665 consults a data structure the overlay manager maintains in the inferior
15666 to see which overlays are mapped. For details, see @ref{Automatic
15667 Overlay Debugging}.
15668
15669 @item overlay load-target
15670 @itemx overlay load
15671 @cindex reloading the overlay table
15672 Re-read the overlay table from the inferior. Normally, @value{GDBN}
15673 re-reads the table @value{GDBN} automatically each time the inferior
15674 stops, so this command should only be necessary if you have changed the
15675 overlay mapping yourself using @value{GDBN}. This command is only
15676 useful when using automatic overlay debugging.
15677
15678 @item overlay list-overlays
15679 @itemx overlay list
15680 @cindex listing mapped overlays
15681 Display a list of the overlays currently mapped, along with their mapped
15682 addresses, load addresses, and sizes.
15683
15684 @end table
15685
15686 Normally, when @value{GDBN} prints a code address, it includes the name
15687 of the function the address falls in:
15688
15689 @smallexample
15690 (@value{GDBP}) print main
15691 $3 = @{int ()@} 0x11a0 <main>
15692 @end smallexample
15693 @noindent
15694 When overlay debugging is enabled, @value{GDBN} recognizes code in
15695 unmapped overlays, and prints the names of unmapped functions with
15696 asterisks around them. For example, if @code{foo} is a function in an
15697 unmapped overlay, @value{GDBN} prints it this way:
15698
15699 @smallexample
15700 (@value{GDBP}) overlay list
15701 No sections are mapped.
15702 (@value{GDBP}) print foo
15703 $5 = @{int (int)@} 0x100000 <*foo*>
15704 @end smallexample
15705 @noindent
15706 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
15707 name normally:
15708
15709 @smallexample
15710 (@value{GDBP}) overlay list
15711 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
15712 mapped at 0x1016 - 0x104a
15713 (@value{GDBP}) print foo
15714 $6 = @{int (int)@} 0x1016 <foo>
15715 @end smallexample
15716
15717 When overlay debugging is enabled, @value{GDBN} can find the correct
15718 address for functions and variables in an overlay, whether or not the
15719 overlay is mapped. This allows most @value{GDBN} commands, like
15720 @code{break} and @code{disassemble}, to work normally, even on unmapped
15721 code. However, @value{GDBN}'s breakpoint support has some limitations:
15722
15723 @itemize @bullet
15724 @item
15725 @cindex breakpoints in overlays
15726 @cindex overlays, setting breakpoints in
15727 You can set breakpoints in functions in unmapped overlays, as long as
15728 @value{GDBN} can write to the overlay at its load address.
15729 @item
15730 @value{GDBN} can not set hardware or simulator-based breakpoints in
15731 unmapped overlays. However, if you set a breakpoint at the end of your
15732 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
15733 you are using manual overlay management), @value{GDBN} will re-set its
15734 breakpoints properly.
15735 @end itemize
15736
15737
15738 @node Automatic Overlay Debugging
15739 @section Automatic Overlay Debugging
15740 @cindex automatic overlay debugging
15741
15742 @value{GDBN} can automatically track which overlays are mapped and which
15743 are not, given some simple co-operation from the overlay manager in the
15744 inferior. If you enable automatic overlay debugging with the
15745 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
15746 looks in the inferior's memory for certain variables describing the
15747 current state of the overlays.
15748
15749 Here are the variables your overlay manager must define to support
15750 @value{GDBN}'s automatic overlay debugging:
15751
15752 @table @asis
15753
15754 @item @code{_ovly_table}:
15755 This variable must be an array of the following structures:
15756
15757 @smallexample
15758 struct
15759 @{
15760 /* The overlay's mapped address. */
15761 unsigned long vma;
15762
15763 /* The size of the overlay, in bytes. */
15764 unsigned long size;
15765
15766 /* The overlay's load address. */
15767 unsigned long lma;
15768
15769 /* Non-zero if the overlay is currently mapped;
15770 zero otherwise. */
15771 unsigned long mapped;
15772 @}
15773 @end smallexample
15774
15775 @item @code{_novlys}:
15776 This variable must be a four-byte signed integer, holding the total
15777 number of elements in @code{_ovly_table}.
15778
15779 @end table
15780
15781 To decide whether a particular overlay is mapped or not, @value{GDBN}
15782 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
15783 @code{lma} members equal the VMA and LMA of the overlay's section in the
15784 executable file. When @value{GDBN} finds a matching entry, it consults
15785 the entry's @code{mapped} member to determine whether the overlay is
15786 currently mapped.
15787
15788 In addition, your overlay manager may define a function called
15789 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
15790 will silently set a breakpoint there. If the overlay manager then
15791 calls this function whenever it has changed the overlay table, this
15792 will enable @value{GDBN} to accurately keep track of which overlays
15793 are in program memory, and update any breakpoints that may be set
15794 in overlays. This will allow breakpoints to work even if the
15795 overlays are kept in ROM or other non-writable memory while they
15796 are not being executed.
15797
15798 @node Overlay Sample Program
15799 @section Overlay Sample Program
15800 @cindex overlay example program
15801
15802 When linking a program which uses overlays, you must place the overlays
15803 at their load addresses, while relocating them to run at their mapped
15804 addresses. To do this, you must write a linker script (@pxref{Overlay
15805 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
15806 since linker scripts are specific to a particular host system, target
15807 architecture, and target memory layout, this manual cannot provide
15808 portable sample code demonstrating @value{GDBN}'s overlay support.
15809
15810 However, the @value{GDBN} source distribution does contain an overlaid
15811 program, with linker scripts for a few systems, as part of its test
15812 suite. The program consists of the following files from
15813 @file{gdb/testsuite/gdb.base}:
15814
15815 @table @file
15816 @item overlays.c
15817 The main program file.
15818 @item ovlymgr.c
15819 A simple overlay manager, used by @file{overlays.c}.
15820 @item foo.c
15821 @itemx bar.c
15822 @itemx baz.c
15823 @itemx grbx.c
15824 Overlay modules, loaded and used by @file{overlays.c}.
15825 @item d10v.ld
15826 @itemx m32r.ld
15827 Linker scripts for linking the test program on the @code{d10v-elf}
15828 and @code{m32r-elf} targets.
15829 @end table
15830
15831 You can build the test program using the @code{d10v-elf} GCC
15832 cross-compiler like this:
15833
15834 @smallexample
15835 $ d10v-elf-gcc -g -c overlays.c
15836 $ d10v-elf-gcc -g -c ovlymgr.c
15837 $ d10v-elf-gcc -g -c foo.c
15838 $ d10v-elf-gcc -g -c bar.c
15839 $ d10v-elf-gcc -g -c baz.c
15840 $ d10v-elf-gcc -g -c grbx.c
15841 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
15842 baz.o grbx.o -Wl,-Td10v.ld -o overlays
15843 @end smallexample
15844
15845 The build process is identical for any other architecture, except that
15846 you must substitute the appropriate compiler and linker script for the
15847 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
15848
15849
15850 @node Languages
15851 @chapter Using @value{GDBN} with Different Languages
15852 @cindex languages
15853
15854 Although programming languages generally have common aspects, they are
15855 rarely expressed in the same manner. For instance, in ANSI C,
15856 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
15857 Modula-2, it is accomplished by @code{p^}. Values can also be
15858 represented (and displayed) differently. Hex numbers in C appear as
15859 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
15860
15861 @cindex working language
15862 Language-specific information is built into @value{GDBN} for some languages,
15863 allowing you to express operations like the above in your program's
15864 native language, and allowing @value{GDBN} to output values in a manner
15865 consistent with the syntax of your program's native language. The
15866 language you use to build expressions is called the @dfn{working
15867 language}.
15868
15869 @menu
15870 * Setting:: Switching between source languages
15871 * Show:: Displaying the language
15872 * Checks:: Type and range checks
15873 * Supported Languages:: Supported languages
15874 * Unsupported Languages:: Unsupported languages
15875 @end menu
15876
15877 @node Setting
15878 @section Switching Between Source Languages
15879
15880 There are two ways to control the working language---either have @value{GDBN}
15881 set it automatically, or select it manually yourself. You can use the
15882 @code{set language} command for either purpose. On startup, @value{GDBN}
15883 defaults to setting the language automatically. The working language is
15884 used to determine how expressions you type are interpreted, how values
15885 are printed, etc.
15886
15887 In addition to the working language, every source file that
15888 @value{GDBN} knows about has its own working language. For some object
15889 file formats, the compiler might indicate which language a particular
15890 source file is in. However, most of the time @value{GDBN} infers the
15891 language from the name of the file. The language of a source file
15892 controls whether C@t{++} names are demangled---this way @code{backtrace} can
15893 show each frame appropriately for its own language. There is no way to
15894 set the language of a source file from within @value{GDBN}, but you can
15895 set the language associated with a filename extension. @xref{Show, ,
15896 Displaying the Language}.
15897
15898 This is most commonly a problem when you use a program, such
15899 as @code{cfront} or @code{f2c}, that generates C but is written in
15900 another language. In that case, make the
15901 program use @code{#line} directives in its C output; that way
15902 @value{GDBN} will know the correct language of the source code of the original
15903 program, and will display that source code, not the generated C code.
15904
15905 @menu
15906 * Filenames:: Filename extensions and languages.
15907 * Manually:: Setting the working language manually
15908 * Automatically:: Having @value{GDBN} infer the source language
15909 @end menu
15910
15911 @node Filenames
15912 @subsection List of Filename Extensions and Languages
15913
15914 If a source file name ends in one of the following extensions, then
15915 @value{GDBN} infers that its language is the one indicated.
15916
15917 @table @file
15918 @item .ada
15919 @itemx .ads
15920 @itemx .adb
15921 @itemx .a
15922 Ada source file.
15923
15924 @item .c
15925 C source file
15926
15927 @item .C
15928 @itemx .cc
15929 @itemx .cp
15930 @itemx .cpp
15931 @itemx .cxx
15932 @itemx .c++
15933 C@t{++} source file
15934
15935 @item .d
15936 D source file
15937
15938 @item .m
15939 Objective-C source file
15940
15941 @item .f
15942 @itemx .F
15943 Fortran source file
15944
15945 @item .mod
15946 Modula-2 source file
15947
15948 @item .s
15949 @itemx .S
15950 Assembler source file. This actually behaves almost like C, but
15951 @value{GDBN} does not skip over function prologues when stepping.
15952 @end table
15953
15954 In addition, you may set the language associated with a filename
15955 extension. @xref{Show, , Displaying the Language}.
15956
15957 @node Manually
15958 @subsection Setting the Working Language
15959
15960 If you allow @value{GDBN} to set the language automatically,
15961 expressions are interpreted the same way in your debugging session and
15962 your program.
15963
15964 @kindex set language
15965 If you wish, you may set the language manually. To do this, issue the
15966 command @samp{set language @var{lang}}, where @var{lang} is the name of
15967 a language, such as
15968 @code{c} or @code{modula-2}.
15969 For a list of the supported languages, type @samp{set language}.
15970
15971 Setting the language manually prevents @value{GDBN} from updating the working
15972 language automatically. This can lead to confusion if you try
15973 to debug a program when the working language is not the same as the
15974 source language, when an expression is acceptable to both
15975 languages---but means different things. For instance, if the current
15976 source file were written in C, and @value{GDBN} was parsing Modula-2, a
15977 command such as:
15978
15979 @smallexample
15980 print a = b + c
15981 @end smallexample
15982
15983 @noindent
15984 might not have the effect you intended. In C, this means to add
15985 @code{b} and @code{c} and place the result in @code{a}. The result
15986 printed would be the value of @code{a}. In Modula-2, this means to compare
15987 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
15988
15989 @node Automatically
15990 @subsection Having @value{GDBN} Infer the Source Language
15991
15992 To have @value{GDBN} set the working language automatically, use
15993 @samp{set language local} or @samp{set language auto}. @value{GDBN}
15994 then infers the working language. That is, when your program stops in a
15995 frame (usually by encountering a breakpoint), @value{GDBN} sets the
15996 working language to the language recorded for the function in that
15997 frame. If the language for a frame is unknown (that is, if the function
15998 or block corresponding to the frame was defined in a source file that
15999 does not have a recognized extension), the current working language is
16000 not changed, and @value{GDBN} issues a warning.
16001
16002 This may not seem necessary for most programs, which are written
16003 entirely in one source language. However, program modules and libraries
16004 written in one source language can be used by a main program written in
16005 a different source language. Using @samp{set language auto} in this
16006 case frees you from having to set the working language manually.
16007
16008 @node Show
16009 @section Displaying the Language
16010
16011 The following commands help you find out which language is the
16012 working language, and also what language source files were written in.
16013
16014 @table @code
16015 @item show language
16016 @anchor{show language}
16017 @kindex show language
16018 Display the current working language. This is the
16019 language you can use with commands such as @code{print} to
16020 build and compute expressions that may involve variables in your program.
16021
16022 @item info frame
16023 @kindex info frame@r{, show the source language}
16024 Display the source language for this frame. This language becomes the
16025 working language if you use an identifier from this frame.
16026 @xref{Frame Info, ,Information about a Frame}, to identify the other
16027 information listed here.
16028
16029 @item info source
16030 @kindex info source@r{, show the source language}
16031 Display the source language of this source file.
16032 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
16033 information listed here.
16034 @end table
16035
16036 In unusual circumstances, you may have source files with extensions
16037 not in the standard list. You can then set the extension associated
16038 with a language explicitly:
16039
16040 @table @code
16041 @item set extension-language @var{ext} @var{language}
16042 @kindex set extension-language
16043 Tell @value{GDBN} that source files with extension @var{ext} are to be
16044 assumed as written in the source language @var{language}.
16045
16046 @item info extensions
16047 @kindex info extensions
16048 List all the filename extensions and the associated languages.
16049 @end table
16050
16051 @node Checks
16052 @section Type and Range Checking
16053
16054 Some languages are designed to guard you against making seemingly common
16055 errors through a series of compile- and run-time checks. These include
16056 checking the type of arguments to functions and operators and making
16057 sure mathematical overflows are caught at run time. Checks such as
16058 these help to ensure a program's correctness once it has been compiled
16059 by eliminating type mismatches and providing active checks for range
16060 errors when your program is running.
16061
16062 By default @value{GDBN} checks for these errors according to the
16063 rules of the current source language. Although @value{GDBN} does not check
16064 the statements in your program, it can check expressions entered directly
16065 into @value{GDBN} for evaluation via the @code{print} command, for example.
16066
16067 @menu
16068 * Type Checking:: An overview of type checking
16069 * Range Checking:: An overview of range checking
16070 @end menu
16071
16072 @cindex type checking
16073 @cindex checks, type
16074 @node Type Checking
16075 @subsection An Overview of Type Checking
16076
16077 Some languages, such as C and C@t{++}, are strongly typed, meaning that the
16078 arguments to operators and functions have to be of the correct type,
16079 otherwise an error occurs. These checks prevent type mismatch
16080 errors from ever causing any run-time problems. For example,
16081
16082 @smallexample
16083 int klass::my_method(char *b) @{ return b ? 1 : 2; @}
16084
16085 (@value{GDBP}) print obj.my_method (0)
16086 $1 = 2
16087 @exdent but
16088 (@value{GDBP}) print obj.my_method (0x1234)
16089 Cannot resolve method klass::my_method to any overloaded instance
16090 @end smallexample
16091
16092 The second example fails because in C@t{++} the integer constant
16093 @samp{0x1234} is not type-compatible with the pointer parameter type.
16094
16095 For the expressions you use in @value{GDBN} commands, you can tell
16096 @value{GDBN} to not enforce strict type checking or
16097 to treat any mismatches as errors and abandon the expression;
16098 When type checking is disabled, @value{GDBN} successfully evaluates
16099 expressions like the second example above.
16100
16101 Even if type checking is off, there may be other reasons
16102 related to type that prevent @value{GDBN} from evaluating an expression.
16103 For instance, @value{GDBN} does not know how to add an @code{int} and
16104 a @code{struct foo}. These particular type errors have nothing to do
16105 with the language in use and usually arise from expressions which make
16106 little sense to evaluate anyway.
16107
16108 @value{GDBN} provides some additional commands for controlling type checking:
16109
16110 @kindex set check type
16111 @kindex show check type
16112 @table @code
16113 @item set check type on
16114 @itemx set check type off
16115 Set strict type checking on or off. If any type mismatches occur in
16116 evaluating an expression while type checking is on, @value{GDBN} prints a
16117 message and aborts evaluation of the expression.
16118
16119 @item show check type
16120 Show the current setting of type checking and whether @value{GDBN}
16121 is enforcing strict type checking rules.
16122 @end table
16123
16124 @cindex range checking
16125 @cindex checks, range
16126 @node Range Checking
16127 @subsection An Overview of Range Checking
16128
16129 In some languages (such as Modula-2), it is an error to exceed the
16130 bounds of a type; this is enforced with run-time checks. Such range
16131 checking is meant to ensure program correctness by making sure
16132 computations do not overflow, or indices on an array element access do
16133 not exceed the bounds of the array.
16134
16135 For expressions you use in @value{GDBN} commands, you can tell
16136 @value{GDBN} to treat range errors in one of three ways: ignore them,
16137 always treat them as errors and abandon the expression, or issue
16138 warnings but evaluate the expression anyway.
16139
16140 A range error can result from numerical overflow, from exceeding an
16141 array index bound, or when you type a constant that is not a member
16142 of any type. Some languages, however, do not treat overflows as an
16143 error. In many implementations of C, mathematical overflow causes the
16144 result to ``wrap around'' to lower values---for example, if @var{m} is
16145 the largest integer value, and @var{s} is the smallest, then
16146
16147 @smallexample
16148 @var{m} + 1 @result{} @var{s}
16149 @end smallexample
16150
16151 This, too, is specific to individual languages, and in some cases
16152 specific to individual compilers or machines. @xref{Supported Languages, ,
16153 Supported Languages}, for further details on specific languages.
16154
16155 @value{GDBN} provides some additional commands for controlling the range checker:
16156
16157 @kindex set check range
16158 @kindex show check range
16159 @table @code
16160 @item set check range auto
16161 Set range checking on or off based on the current working language.
16162 @xref{Supported Languages, ,Supported Languages}, for the default settings for
16163 each language.
16164
16165 @item set check range on
16166 @itemx set check range off
16167 Set range checking on or off, overriding the default setting for the
16168 current working language. A warning is issued if the setting does not
16169 match the language default. If a range error occurs and range checking is on,
16170 then a message is printed and evaluation of the expression is aborted.
16171
16172 @item set check range warn
16173 Output messages when the @value{GDBN} range checker detects a range error,
16174 but attempt to evaluate the expression anyway. Evaluating the
16175 expression may still be impossible for other reasons, such as accessing
16176 memory that the process does not own (a typical example from many Unix
16177 systems).
16178
16179 @item show check range
16180 Show the current setting of the range checker, and whether or not it is
16181 being set automatically by @value{GDBN}.
16182 @end table
16183
16184 @node Supported Languages
16185 @section Supported Languages
16186
16187 @value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
16188 OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
16189 @c This is false ...
16190 Some @value{GDBN} features may be used in expressions regardless of the
16191 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
16192 and the @samp{@{type@}addr} construct (@pxref{Expressions,
16193 ,Expressions}) can be used with the constructs of any supported
16194 language.
16195
16196 The following sections detail to what degree each source language is
16197 supported by @value{GDBN}. These sections are not meant to be language
16198 tutorials or references, but serve only as a reference guide to what the
16199 @value{GDBN} expression parser accepts, and what input and output
16200 formats should look like for different languages. There are many good
16201 books written on each of these languages; please look to these for a
16202 language reference or tutorial.
16203
16204 @menu
16205 * C:: C and C@t{++}
16206 * D:: D
16207 * Go:: Go
16208 * Objective-C:: Objective-C
16209 * OpenCL C:: OpenCL C
16210 * Fortran:: Fortran
16211 * Pascal:: Pascal
16212 * Rust:: Rust
16213 * Modula-2:: Modula-2
16214 * Ada:: Ada
16215 @end menu
16216
16217 @node C
16218 @subsection C and C@t{++}
16219
16220 @cindex C and C@t{++}
16221 @cindex expressions in C or C@t{++}
16222
16223 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
16224 to both languages. Whenever this is the case, we discuss those languages
16225 together.
16226
16227 @cindex C@t{++}
16228 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
16229 @cindex @sc{gnu} C@t{++}
16230 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
16231 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
16232 effectively, you must compile your C@t{++} programs with a supported
16233 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
16234 compiler (@code{aCC}).
16235
16236 @menu
16237 * C Operators:: C and C@t{++} operators
16238 * C Constants:: C and C@t{++} constants
16239 * C Plus Plus Expressions:: C@t{++} expressions
16240 * C Defaults:: Default settings for C and C@t{++}
16241 * C Checks:: C and C@t{++} type and range checks
16242 * Debugging C:: @value{GDBN} and C
16243 * Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
16244 * Decimal Floating Point:: Numbers in Decimal Floating Point format
16245 @end menu
16246
16247 @node C Operators
16248 @subsubsection C and C@t{++} Operators
16249
16250 @cindex C and C@t{++} operators
16251
16252 Operators must be defined on values of specific types. For instance,
16253 @code{+} is defined on numbers, but not on structures. Operators are
16254 often defined on groups of types.
16255
16256 For the purposes of C and C@t{++}, the following definitions hold:
16257
16258 @itemize @bullet
16259
16260 @item
16261 @emph{Integral types} include @code{int} with any of its storage-class
16262 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
16263
16264 @item
16265 @emph{Floating-point types} include @code{float}, @code{double}, and
16266 @code{long double} (if supported by the target platform).
16267
16268 @item
16269 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
16270
16271 @item
16272 @emph{Scalar types} include all of the above.
16273
16274 @end itemize
16275
16276 @noindent
16277 The following operators are supported. They are listed here
16278 in order of increasing precedence:
16279
16280 @table @code
16281 @item ,
16282 The comma or sequencing operator. Expressions in a comma-separated list
16283 are evaluated from left to right, with the result of the entire
16284 expression being the last expression evaluated.
16285
16286 @item =
16287 Assignment. The value of an assignment expression is the value
16288 assigned. Defined on scalar types.
16289
16290 @item @var{op}=
16291 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16292 and translated to @w{@code{@var{a} = @var{a op b}}}.
16293 @w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
16294 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16295 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16296
16297 @item ?:
16298 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
16299 of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16300 should be of an integral type.
16301
16302 @item ||
16303 Logical @sc{or}. Defined on integral types.
16304
16305 @item &&
16306 Logical @sc{and}. Defined on integral types.
16307
16308 @item |
16309 Bitwise @sc{or}. Defined on integral types.
16310
16311 @item ^
16312 Bitwise exclusive-@sc{or}. Defined on integral types.
16313
16314 @item &
16315 Bitwise @sc{and}. Defined on integral types.
16316
16317 @item ==@r{, }!=
16318 Equality and inequality. Defined on scalar types. The value of these
16319 expressions is 0 for false and non-zero for true.
16320
16321 @item <@r{, }>@r{, }<=@r{, }>=
16322 Less than, greater than, less than or equal, greater than or equal.
16323 Defined on scalar types. The value of these expressions is 0 for false
16324 and non-zero for true.
16325
16326 @item <<@r{, }>>
16327 left shift, and right shift. Defined on integral types.
16328
16329 @item @@
16330 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16331
16332 @item +@r{, }-
16333 Addition and subtraction. Defined on integral types, floating-point types and
16334 pointer types.
16335
16336 @item *@r{, }/@r{, }%
16337 Multiplication, division, and modulus. Multiplication and division are
16338 defined on integral and floating-point types. Modulus is defined on
16339 integral types.
16340
16341 @item ++@r{, }--
16342 Increment and decrement. When appearing before a variable, the
16343 operation is performed before the variable is used in an expression;
16344 when appearing after it, the variable's value is used before the
16345 operation takes place.
16346
16347 @item *
16348 Pointer dereferencing. Defined on pointer types. Same precedence as
16349 @code{++}.
16350
16351 @item &
16352 Address operator. Defined on variables. Same precedence as @code{++}.
16353
16354 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16355 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
16356 to examine the address
16357 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
16358 stored.
16359
16360 @item -
16361 Negative. Defined on integral and floating-point types. Same
16362 precedence as @code{++}.
16363
16364 @item !
16365 Logical negation. Defined on integral types. Same precedence as
16366 @code{++}.
16367
16368 @item ~
16369 Bitwise complement operator. Defined on integral types. Same precedence as
16370 @code{++}.
16371
16372
16373 @item .@r{, }->
16374 Structure member, and pointer-to-structure member. For convenience,
16375 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
16376 pointer based on the stored type information.
16377 Defined on @code{struct} and @code{union} data.
16378
16379 @item .*@r{, }->*
16380 Dereferences of pointers to members.
16381
16382 @item []
16383 Array indexing. @code{@var{a}[@var{i}]} is defined as
16384 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
16385
16386 @item ()
16387 Function parameter list. Same precedence as @code{->}.
16388
16389 @item ::
16390 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
16391 and @code{class} types.
16392
16393 @item ::
16394 Doubled colons also represent the @value{GDBN} scope operator
16395 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
16396 above.
16397 @end table
16398
16399 If an operator is redefined in the user code, @value{GDBN} usually
16400 attempts to invoke the redefined version instead of using the operator's
16401 predefined meaning.
16402
16403 @node C Constants
16404 @subsubsection C and C@t{++} Constants
16405
16406 @cindex C and C@t{++} constants
16407
16408 @value{GDBN} allows you to express the constants of C and C@t{++} in the
16409 following ways:
16410
16411 @itemize @bullet
16412 @item
16413 Integer constants are a sequence of digits. Octal constants are
16414 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16415 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
16416 @samp{l}, specifying that the constant should be treated as a
16417 @code{long} value.
16418
16419 @item
16420 Floating point constants are a sequence of digits, followed by a decimal
16421 point, followed by a sequence of digits, and optionally followed by an
16422 exponent. An exponent is of the form:
16423 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16424 sequence of digits. The @samp{+} is optional for positive exponents.
16425 A floating-point constant may also end with a letter @samp{f} or
16426 @samp{F}, specifying that the constant should be treated as being of
16427 the @code{float} (as opposed to the default @code{double}) type; or with
16428 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16429 constant.
16430
16431 @item
16432 Enumerated constants consist of enumerated identifiers, or their
16433 integral equivalents.
16434
16435 @item
16436 Character constants are a single character surrounded by single quotes
16437 (@code{'}), or a number---the ordinal value of the corresponding character
16438 (usually its @sc{ascii} value). Within quotes, the single character may
16439 be represented by a letter or by @dfn{escape sequences}, which are of
16440 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16441 of the character's ordinal value; or of the form @samp{\@var{x}}, where
16442 @samp{@var{x}} is a predefined special character---for example,
16443 @samp{\n} for newline.
16444
16445 Wide character constants can be written by prefixing a character
16446 constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
16447 form of @samp{x}. The target wide character set is used when
16448 computing the value of this constant (@pxref{Character Sets}).
16449
16450 @item
16451 String constants are a sequence of character constants surrounded by
16452 double quotes (@code{"}). Any valid character constant (as described
16453 above) may appear. Double quotes within the string must be preceded by
16454 a backslash, so for instance @samp{"a\"b'c"} is a string of five
16455 characters.
16456
16457 Wide string constants can be written by prefixing a string constant
16458 with @samp{L}, as in C. The target wide character set is used when
16459 computing the value of this constant (@pxref{Character Sets}).
16460
16461 @item
16462 Pointer constants are an integral value. You can also write pointers
16463 to constants using the C operator @samp{&}.
16464
16465 @item
16466 Array constants are comma-separated lists surrounded by braces @samp{@{}
16467 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16468 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16469 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16470 @end itemize
16471
16472 @node C Plus Plus Expressions
16473 @subsubsection C@t{++} Expressions
16474
16475 @cindex expressions in C@t{++}
16476 @value{GDBN} expression handling can interpret most C@t{++} expressions.
16477
16478 @cindex debugging C@t{++} programs
16479 @cindex C@t{++} compilers
16480 @cindex debug formats and C@t{++}
16481 @cindex @value{NGCC} and C@t{++}
16482 @quotation
16483 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16484 the proper compiler and the proper debug format. Currently,
16485 @value{GDBN} works best when debugging C@t{++} code that is compiled
16486 with the most recent version of @value{NGCC} possible. The DWARF
16487 debugging format is preferred; @value{NGCC} defaults to this on most
16488 popular platforms. Other compilers and/or debug formats are likely to
16489 work badly or not at all when using @value{GDBN} to debug C@t{++}
16490 code. @xref{Compilation}.
16491 @end quotation
16492
16493 @enumerate
16494
16495 @cindex member functions
16496 @item
16497 Member function calls are allowed; you can use expressions like
16498
16499 @smallexample
16500 count = aml->GetOriginal(x, y)
16501 @end smallexample
16502
16503 @vindex this@r{, inside C@t{++} member functions}
16504 @cindex namespace in C@t{++}
16505 @item
16506 While a member function is active (in the selected stack frame), your
16507 expressions have the same namespace available as the member function;
16508 that is, @value{GDBN} allows implicit references to the class instance
16509 pointer @code{this} following the same rules as C@t{++}. @code{using}
16510 declarations in the current scope are also respected by @value{GDBN}.
16511
16512 @cindex call overloaded functions
16513 @cindex overloaded functions, calling
16514 @cindex type conversions in C@t{++}
16515 @item
16516 You can call overloaded functions; @value{GDBN} resolves the function
16517 call to the right definition, with some restrictions. @value{GDBN} does not
16518 perform overload resolution involving user-defined type conversions,
16519 calls to constructors, or instantiations of templates that do not exist
16520 in the program. It also cannot handle ellipsis argument lists or
16521 default arguments.
16522
16523 It does perform integral conversions and promotions, floating-point
16524 promotions, arithmetic conversions, pointer conversions, conversions of
16525 class objects to base classes, and standard conversions such as those of
16526 functions or arrays to pointers; it requires an exact match on the
16527 number of function arguments.
16528
16529 Overload resolution is always performed, unless you have specified
16530 @code{set overload-resolution off}. @xref{Debugging C Plus Plus,
16531 ,@value{GDBN} Features for C@t{++}}.
16532
16533 You must specify @code{set overload-resolution off} in order to use an
16534 explicit function signature to call an overloaded function, as in
16535 @smallexample
16536 p 'foo(char,int)'('x', 13)
16537 @end smallexample
16538
16539 The @value{GDBN} command-completion facility can simplify this;
16540 see @ref{Completion, ,Command Completion}.
16541
16542 @cindex reference declarations
16543 @item
16544 @value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16545 references; you can use them in expressions just as you do in C@t{++}
16546 source---they are automatically dereferenced.
16547
16548 In the parameter list shown when @value{GDBN} displays a frame, the values of
16549 reference variables are not displayed (unlike other variables); this
16550 avoids clutter, since references are often used for large structures.
16551 The @emph{address} of a reference variable is always shown, unless
16552 you have specified @samp{set print address off}.
16553
16554 @item
16555 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
16556 expressions can use it just as expressions in your program do. Since
16557 one scope may be defined in another, you can use @code{::} repeatedly if
16558 necessary, for example in an expression like
16559 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
16560 resolving name scope by reference to source files, in both C and C@t{++}
16561 debugging (@pxref{Variables, ,Program Variables}).
16562
16563 @item
16564 @value{GDBN} performs argument-dependent lookup, following the C@t{++}
16565 specification.
16566 @end enumerate
16567
16568 @node C Defaults
16569 @subsubsection C and C@t{++} Defaults
16570
16571 @cindex C and C@t{++} defaults
16572
16573 If you allow @value{GDBN} to set range checking automatically, it
16574 defaults to @code{off} whenever the working language changes to
16575 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
16576 selects the working language.
16577
16578 If you allow @value{GDBN} to set the language automatically, it
16579 recognizes source files whose names end with @file{.c}, @file{.C}, or
16580 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
16581 these files, it sets the working language to C or C@t{++}.
16582 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
16583 for further details.
16584
16585 @node C Checks
16586 @subsubsection C and C@t{++} Type and Range Checks
16587
16588 @cindex C and C@t{++} checks
16589
16590 By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16591 checking is used. However, if you turn type checking off, @value{GDBN}
16592 will allow certain non-standard conversions, such as promoting integer
16593 constants to pointers.
16594
16595 Range checking, if turned on, is done on mathematical operations. Array
16596 indices are not checked, since they are often used to index a pointer
16597 that is not itself an array.
16598
16599 @node Debugging C
16600 @subsubsection @value{GDBN} and C
16601
16602 The @code{set print union} and @code{show print union} commands apply to
16603 the @code{union} type. When set to @samp{on}, any @code{union} that is
16604 inside a @code{struct} or @code{class} is also printed. Otherwise, it
16605 appears as @samp{@{...@}}.
16606
16607 The @code{@@} operator aids in the debugging of dynamic arrays, formed
16608 with pointers and a memory allocation function. @xref{Expressions,
16609 ,Expressions}.
16610
16611 @node Debugging C Plus Plus
16612 @subsubsection @value{GDBN} Features for C@t{++}
16613
16614 @cindex commands for C@t{++}
16615
16616 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16617 designed specifically for use with C@t{++}. Here is a summary:
16618
16619 @table @code
16620 @cindex break in overloaded functions
16621 @item @r{breakpoint menus}
16622 When you want a breakpoint in a function whose name is overloaded,
16623 @value{GDBN} has the capability to display a menu of possible breakpoint
16624 locations to help you specify which function definition you want.
16625 @xref{Ambiguous Expressions,,Ambiguous Expressions}.
16626
16627 @cindex overloading in C@t{++}
16628 @item rbreak @var{regex}
16629 Setting breakpoints using regular expressions is helpful for setting
16630 breakpoints on overloaded functions that are not members of any special
16631 classes.
16632 @xref{Set Breaks, ,Setting Breakpoints}.
16633
16634 @cindex C@t{++} exception handling
16635 @item catch throw
16636 @itemx catch rethrow
16637 @itemx catch catch
16638 Debug C@t{++} exception handling using these commands. @xref{Set
16639 Catchpoints, , Setting Catchpoints}.
16640
16641 @cindex inheritance
16642 @item ptype @var{typename}
16643 Print inheritance relationships as well as other information for type
16644 @var{typename}.
16645 @xref{Symbols, ,Examining the Symbol Table}.
16646
16647 @item info vtbl @var{expression}.
16648 The @code{info vtbl} command can be used to display the virtual
16649 method tables of the object computed by @var{expression}. This shows
16650 one entry per virtual table; there may be multiple virtual tables when
16651 multiple inheritance is in use.
16652
16653 @cindex C@t{++} demangling
16654 @item demangle @var{name}
16655 Demangle @var{name}.
16656 @xref{Symbols}, for a more complete description of the @code{demangle} command.
16657
16658 @cindex C@t{++} symbol display
16659 @item set print demangle
16660 @itemx show print demangle
16661 @itemx set print asm-demangle
16662 @itemx show print asm-demangle
16663 Control whether C@t{++} symbols display in their source form, both when
16664 displaying code as C@t{++} source and when displaying disassemblies.
16665 @xref{Print Settings, ,Print Settings}.
16666
16667 @item set print object
16668 @itemx show print object
16669 Choose whether to print derived (actual) or declared types of objects.
16670 @xref{Print Settings, ,Print Settings}.
16671
16672 @item set print vtbl
16673 @itemx show print vtbl
16674 Control the format for printing virtual function tables.
16675 @xref{Print Settings, ,Print Settings}.
16676 (The @code{vtbl} commands do not work on programs compiled with the HP
16677 ANSI C@t{++} compiler (@code{aCC}).)
16678
16679 @kindex set overload-resolution
16680 @cindex overloaded functions, overload resolution
16681 @item set overload-resolution on
16682 Enable overload resolution for C@t{++} expression evaluation. The default
16683 is on. For overloaded functions, @value{GDBN} evaluates the arguments
16684 and searches for a function whose signature matches the argument types,
16685 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
16686 Expressions, ,C@t{++} Expressions}, for details).
16687 If it cannot find a match, it emits a message.
16688
16689 @item set overload-resolution off
16690 Disable overload resolution for C@t{++} expression evaluation. For
16691 overloaded functions that are not class member functions, @value{GDBN}
16692 chooses the first function of the specified name that it finds in the
16693 symbol table, whether or not its arguments are of the correct type. For
16694 overloaded functions that are class member functions, @value{GDBN}
16695 searches for a function whose signature @emph{exactly} matches the
16696 argument types.
16697
16698 @kindex show overload-resolution
16699 @item show overload-resolution
16700 Show the current setting of overload resolution.
16701
16702 @item @r{Overloaded symbol names}
16703 You can specify a particular definition of an overloaded symbol, using
16704 the same notation that is used to declare such symbols in C@t{++}: type
16705 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
16706 also use the @value{GDBN} command-line word completion facilities to list the
16707 available choices, or to finish the type list for you.
16708 @xref{Completion,, Command Completion}, for details on how to do this.
16709
16710 @item @r{Breakpoints in functions with ABI tags}
16711
16712 The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
16713 correspond to changes in the ABI of a type, function, or variable that
16714 would not otherwise be reflected in a mangled name. See
16715 @url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
16716 for more detail.
16717
16718 The ABI tags are visible in C@t{++} demangled names. For example, a
16719 function that returns a std::string:
16720
16721 @smallexample
16722 std::string function(int);
16723 @end smallexample
16724
16725 @noindent
16726 when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
16727 tag, and @value{GDBN} displays the symbol like this:
16728
16729 @smallexample
16730 function[abi:cxx11](int)
16731 @end smallexample
16732
16733 You can set a breakpoint on such functions simply as if they had no
16734 tag. For example:
16735
16736 @smallexample
16737 (gdb) b function(int)
16738 Breakpoint 2 at 0x40060d: file main.cc, line 10.
16739 (gdb) info breakpoints
16740 Num Type Disp Enb Address What
16741 1 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
16742 at main.cc:10
16743 @end smallexample
16744
16745 On the rare occasion you need to disambiguate between different ABI
16746 tags, you can do so by simply including the ABI tag in the function
16747 name, like:
16748
16749 @smallexample
16750 (@value{GDBP}) b ambiguous[abi:other_tag](int)
16751 @end smallexample
16752 @end table
16753
16754 @node Decimal Floating Point
16755 @subsubsection Decimal Floating Point format
16756 @cindex decimal floating point format
16757
16758 @value{GDBN} can examine, set and perform computations with numbers in
16759 decimal floating point format, which in the C language correspond to the
16760 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
16761 specified by the extension to support decimal floating-point arithmetic.
16762
16763 There are two encodings in use, depending on the architecture: BID (Binary
16764 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
16765 PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
16766 configured target.
16767
16768 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
16769 to manipulate decimal floating point numbers, it is not possible to convert
16770 (using a cast, for example) integers wider than 32-bit to decimal float.
16771
16772 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
16773 point computations, error checking in decimal float operations ignores
16774 underflow, overflow and divide by zero exceptions.
16775
16776 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
16777 to inspect @code{_Decimal128} values stored in floating point registers.
16778 See @ref{PowerPC,,PowerPC} for more details.
16779
16780 @node D
16781 @subsection D
16782
16783 @cindex D
16784 @value{GDBN} can be used to debug programs written in D and compiled with
16785 GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
16786 specific feature --- dynamic arrays.
16787
16788 @node Go
16789 @subsection Go
16790
16791 @cindex Go (programming language)
16792 @value{GDBN} can be used to debug programs written in Go and compiled with
16793 @file{gccgo} or @file{6g} compilers.
16794
16795 Here is a summary of the Go-specific features and restrictions:
16796
16797 @table @code
16798 @cindex current Go package
16799 @item The current Go package
16800 The name of the current package does not need to be specified when
16801 specifying global variables and functions.
16802
16803 For example, given the program:
16804
16805 @example
16806 package main
16807 var myglob = "Shall we?"
16808 func main () @{
16809 // ...
16810 @}
16811 @end example
16812
16813 When stopped inside @code{main} either of these work:
16814
16815 @example
16816 (gdb) p myglob
16817 (gdb) p main.myglob
16818 @end example
16819
16820 @cindex builtin Go types
16821 @item Builtin Go types
16822 The @code{string} type is recognized by @value{GDBN} and is printed
16823 as a string.
16824
16825 @cindex builtin Go functions
16826 @item Builtin Go functions
16827 The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
16828 function and handles it internally.
16829
16830 @cindex restrictions on Go expressions
16831 @item Restrictions on Go expressions
16832 All Go operators are supported except @code{&^}.
16833 The Go @code{_} ``blank identifier'' is not supported.
16834 Automatic dereferencing of pointers is not supported.
16835 @end table
16836
16837 @node Objective-C
16838 @subsection Objective-C
16839
16840 @cindex Objective-C
16841 This section provides information about some commands and command
16842 options that are useful for debugging Objective-C code. See also
16843 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
16844 few more commands specific to Objective-C support.
16845
16846 @menu
16847 * Method Names in Commands::
16848 * The Print Command with Objective-C::
16849 @end menu
16850
16851 @node Method Names in Commands
16852 @subsubsection Method Names in Commands
16853
16854 The following commands have been extended to accept Objective-C method
16855 names as line specifications:
16856
16857 @kindex clear@r{, and Objective-C}
16858 @kindex break@r{, and Objective-C}
16859 @kindex info line@r{, and Objective-C}
16860 @kindex jump@r{, and Objective-C}
16861 @kindex list@r{, and Objective-C}
16862 @itemize
16863 @item @code{clear}
16864 @item @code{break}
16865 @item @code{info line}
16866 @item @code{jump}
16867 @item @code{list}
16868 @end itemize
16869
16870 A fully qualified Objective-C method name is specified as
16871
16872 @smallexample
16873 -[@var{Class} @var{methodName}]
16874 @end smallexample
16875
16876 where the minus sign is used to indicate an instance method and a
16877 plus sign (not shown) is used to indicate a class method. The class
16878 name @var{Class} and method name @var{methodName} are enclosed in
16879 brackets, similar to the way messages are specified in Objective-C
16880 source code. For example, to set a breakpoint at the @code{create}
16881 instance method of class @code{Fruit} in the program currently being
16882 debugged, enter:
16883
16884 @smallexample
16885 break -[Fruit create]
16886 @end smallexample
16887
16888 To list ten program lines around the @code{initialize} class method,
16889 enter:
16890
16891 @smallexample
16892 list +[NSText initialize]
16893 @end smallexample
16894
16895 In the current version of @value{GDBN}, the plus or minus sign is
16896 required. In future versions of @value{GDBN}, the plus or minus
16897 sign will be optional, but you can use it to narrow the search. It
16898 is also possible to specify just a method name:
16899
16900 @smallexample
16901 break create
16902 @end smallexample
16903
16904 You must specify the complete method name, including any colons. If
16905 your program's source files contain more than one @code{create} method,
16906 you'll be presented with a numbered list of classes that implement that
16907 method. Indicate your choice by number, or type @samp{0} to exit if
16908 none apply.
16909
16910 As another example, to clear a breakpoint established at the
16911 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
16912
16913 @smallexample
16914 clear -[NSWindow makeKeyAndOrderFront:]
16915 @end smallexample
16916
16917 @node The Print Command with Objective-C
16918 @subsubsection The Print Command With Objective-C
16919 @cindex Objective-C, print objects
16920 @kindex print-object
16921 @kindex po @r{(@code{print-object})}
16922
16923 The print command has also been extended to accept methods. For example:
16924
16925 @smallexample
16926 print -[@var{object} hash]
16927 @end smallexample
16928
16929 @cindex print an Objective-C object description
16930 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
16931 @noindent
16932 will tell @value{GDBN} to send the @code{hash} message to @var{object}
16933 and print the result. Also, an additional command has been added,
16934 @code{print-object} or @code{po} for short, which is meant to print
16935 the description of an object. However, this command may only work
16936 with certain Objective-C libraries that have a particular hook
16937 function, @code{_NSPrintForDebugger}, defined.
16938
16939 @node OpenCL C
16940 @subsection OpenCL C
16941
16942 @cindex OpenCL C
16943 This section provides information about @value{GDBN}s OpenCL C support.
16944
16945 @menu
16946 * OpenCL C Datatypes::
16947 * OpenCL C Expressions::
16948 * OpenCL C Operators::
16949 @end menu
16950
16951 @node OpenCL C Datatypes
16952 @subsubsection OpenCL C Datatypes
16953
16954 @cindex OpenCL C Datatypes
16955 @value{GDBN} supports the builtin scalar and vector datatypes specified
16956 by OpenCL 1.1. In addition the half- and double-precision floating point
16957 data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
16958 extensions are also known to @value{GDBN}.
16959
16960 @node OpenCL C Expressions
16961 @subsubsection OpenCL C Expressions
16962
16963 @cindex OpenCL C Expressions
16964 @value{GDBN} supports accesses to vector components including the access as
16965 lvalue where possible. Since OpenCL C is based on C99 most C expressions
16966 supported by @value{GDBN} can be used as well.
16967
16968 @node OpenCL C Operators
16969 @subsubsection OpenCL C Operators
16970
16971 @cindex OpenCL C Operators
16972 @value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
16973 vector data types.
16974
16975 @node Fortran
16976 @subsection Fortran
16977 @cindex Fortran-specific support in @value{GDBN}
16978
16979 @value{GDBN} can be used to debug programs written in Fortran, but it
16980 currently supports only the features of Fortran 77 language.
16981
16982 @cindex trailing underscore, in Fortran symbols
16983 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
16984 among them) append an underscore to the names of variables and
16985 functions. When you debug programs compiled by those compilers, you
16986 will need to refer to variables and functions with a trailing
16987 underscore.
16988
16989 @menu
16990 * Fortran Operators:: Fortran operators and expressions
16991 * Fortran Defaults:: Default settings for Fortran
16992 * Special Fortran Commands:: Special @value{GDBN} commands for Fortran
16993 @end menu
16994
16995 @node Fortran Operators
16996 @subsubsection Fortran Operators and Expressions
16997
16998 @cindex Fortran operators and expressions
16999
17000 Operators must be defined on values of specific types. For instance,
17001 @code{+} is defined on numbers, but not on characters or other non-
17002 arithmetic types. Operators are often defined on groups of types.
17003
17004 @table @code
17005 @item **
17006 The exponentiation operator. It raises the first operand to the power
17007 of the second one.
17008
17009 @item :
17010 The range operator. Normally used in the form of array(low:high) to
17011 represent a section of array.
17012
17013 @item %
17014 The access component operator. Normally used to access elements in derived
17015 types. Also suitable for unions. As unions aren't part of regular Fortran,
17016 this can only happen when accessing a register that uses a gdbarch-defined
17017 union type.
17018 @item ::
17019 The scope operator. Normally used to access variables in modules or
17020 to set breakpoints on subroutines nested in modules or in other
17021 subroutines (internal subroutines).
17022 @end table
17023
17024 @node Fortran Defaults
17025 @subsubsection Fortran Defaults
17026
17027 @cindex Fortran Defaults
17028
17029 Fortran symbols are usually case-insensitive, so @value{GDBN} by
17030 default uses case-insensitive matches for Fortran symbols. You can
17031 change that with the @samp{set case-insensitive} command, see
17032 @ref{Symbols}, for the details.
17033
17034 @node Special Fortran Commands
17035 @subsubsection Special Fortran Commands
17036
17037 @cindex Special Fortran commands
17038
17039 @value{GDBN} has some commands to support Fortran-specific features,
17040 such as displaying common blocks.
17041
17042 @table @code
17043 @cindex @code{COMMON} blocks, Fortran
17044 @kindex info common
17045 @item info common @r{[}@var{common-name}@r{]}
17046 This command prints the values contained in the Fortran @code{COMMON}
17047 block whose name is @var{common-name}. With no argument, the names of
17048 all @code{COMMON} blocks visible at the current program location are
17049 printed.
17050 @cindex arrays slices (Fortran)
17051 @kindex set fortran repack-array-slices
17052 @kindex show fortran repack-array-slices
17053 @item set fortran repack-array-slices [on|off]
17054 @item show fortran repack-array-slices
17055 When taking a slice from an array, a Fortran compiler can choose to
17056 either produce an array descriptor that describes the slice in place,
17057 or it may repack the slice, copying the elements of the slice into a
17058 new region of memory.
17059
17060 When this setting is on, then @value{GDBN} will also repack array
17061 slices in some situations. When this setting is off, then
17062 @value{GDBN} will create array descriptors for slices that reference
17063 the original data in place.
17064
17065 @value{GDBN} will never repack an array slice if the data for the
17066 slice is contiguous within the original array.
17067
17068 @value{GDBN} will always repack string slices if the data for the
17069 slice is non-contiguous within the original string as @value{GDBN}
17070 does not support printing non-contiguous strings.
17071
17072 The default for this setting is @code{off}.
17073 @end table
17074
17075 @node Pascal
17076 @subsection Pascal
17077
17078 @cindex Pascal support in @value{GDBN}, limitations
17079 Debugging Pascal programs which use sets, subranges, file variables, or
17080 nested functions does not currently work. @value{GDBN} does not support
17081 entering expressions, printing values, or similar features using Pascal
17082 syntax.
17083
17084 The Pascal-specific command @code{set print pascal_static-members}
17085 controls whether static members of Pascal objects are displayed.
17086 @xref{Print Settings, pascal_static-members}.
17087
17088 @node Rust
17089 @subsection Rust
17090
17091 @value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
17092 Programming Language}. Type- and value-printing, and expression
17093 parsing, are reasonably complete. However, there are a few
17094 peculiarities and holes to be aware of.
17095
17096 @itemize @bullet
17097 @item
17098 Linespecs (@pxref{Specify Location}) are never relative to the current
17099 crate. Instead, they act as if there were a global namespace of
17100 crates, somewhat similar to the way @code{extern crate} behaves.
17101
17102 That is, if @value{GDBN} is stopped at a breakpoint in a function in
17103 crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
17104 to set a breakpoint in a function named @samp{f} in a crate named
17105 @samp{B}.
17106
17107 As a consequence of this approach, linespecs also cannot refer to
17108 items using @samp{self::} or @samp{super::}.
17109
17110 @item
17111 Because @value{GDBN} implements Rust name-lookup semantics in
17112 expressions, it will sometimes prepend the current crate to a name.
17113 For example, if @value{GDBN} is stopped at a breakpoint in the crate
17114 @samp{K}, then @code{print ::x::y} will try to find the symbol
17115 @samp{K::x::y}.
17116
17117 However, since it is useful to be able to refer to other crates when
17118 debugging, @value{GDBN} provides the @code{extern} extension to
17119 circumvent this. To use the extension, just put @code{extern} before
17120 a path expression to refer to the otherwise unavailable ``global''
17121 scope.
17122
17123 In the above example, if you wanted to refer to the symbol @samp{y} in
17124 the crate @samp{x}, you would use @code{print extern x::y}.
17125
17126 @item
17127 The Rust expression evaluator does not support ``statement-like''
17128 expressions such as @code{if} or @code{match}, or lambda expressions.
17129
17130 @item
17131 Tuple expressions are not implemented.
17132
17133 @item
17134 The Rust expression evaluator does not currently implement the
17135 @code{Drop} trait. Objects that may be created by the evaluator will
17136 never be destroyed.
17137
17138 @item
17139 @value{GDBN} does not implement type inference for generics. In order
17140 to call generic functions or otherwise refer to generic items, you
17141 will have to specify the type parameters manually.
17142
17143 @item
17144 @value{GDBN} currently uses the C@t{++} demangler for Rust. In most
17145 cases this does not cause any problems. However, in an expression
17146 context, completing a generic function name will give syntactically
17147 invalid results. This happens because Rust requires the @samp{::}
17148 operator between the function name and its generic arguments. For
17149 example, @value{GDBN} might provide a completion like
17150 @code{crate::f<u32>}, where the parser would require
17151 @code{crate::f::<u32>}.
17152
17153 @item
17154 As of this writing, the Rust compiler (version 1.8) has a few holes in
17155 the debugging information it generates. These holes prevent certain
17156 features from being implemented by @value{GDBN}:
17157 @itemize @bullet
17158
17159 @item
17160 Method calls cannot be made via traits.
17161
17162 @item
17163 Operator overloading is not implemented.
17164
17165 @item
17166 When debugging in a monomorphized function, you cannot use the generic
17167 type names.
17168
17169 @item
17170 The type @code{Self} is not available.
17171
17172 @item
17173 @code{use} statements are not available, so some names may not be
17174 available in the crate.
17175 @end itemize
17176 @end itemize
17177
17178 @node Modula-2
17179 @subsection Modula-2
17180
17181 @cindex Modula-2, @value{GDBN} support
17182
17183 The extensions made to @value{GDBN} to support Modula-2 only support
17184 output from the @sc{gnu} Modula-2 compiler (which is currently being
17185 developed). Other Modula-2 compilers are not currently supported, and
17186 attempting to debug executables produced by them is most likely
17187 to give an error as @value{GDBN} reads in the executable's symbol
17188 table.
17189
17190 @cindex expressions in Modula-2
17191 @menu
17192 * M2 Operators:: Built-in operators
17193 * Built-In Func/Proc:: Built-in functions and procedures
17194 * M2 Constants:: Modula-2 constants
17195 * M2 Types:: Modula-2 types
17196 * M2 Defaults:: Default settings for Modula-2
17197 * Deviations:: Deviations from standard Modula-2
17198 * M2 Checks:: Modula-2 type and range checks
17199 * M2 Scope:: The scope operators @code{::} and @code{.}
17200 * GDB/M2:: @value{GDBN} and Modula-2
17201 @end menu
17202
17203 @node M2 Operators
17204 @subsubsection Operators
17205 @cindex Modula-2 operators
17206
17207 Operators must be defined on values of specific types. For instance,
17208 @code{+} is defined on numbers, but not on structures. Operators are
17209 often defined on groups of types. For the purposes of Modula-2, the
17210 following definitions hold:
17211
17212 @itemize @bullet
17213
17214 @item
17215 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
17216 their subranges.
17217
17218 @item
17219 @emph{Character types} consist of @code{CHAR} and its subranges.
17220
17221 @item
17222 @emph{Floating-point types} consist of @code{REAL}.
17223
17224 @item
17225 @emph{Pointer types} consist of anything declared as @code{POINTER TO
17226 @var{type}}.
17227
17228 @item
17229 @emph{Scalar types} consist of all of the above.
17230
17231 @item
17232 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
17233
17234 @item
17235 @emph{Boolean types} consist of @code{BOOLEAN}.
17236 @end itemize
17237
17238 @noindent
17239 The following operators are supported, and appear in order of
17240 increasing precedence:
17241
17242 @table @code
17243 @item ,
17244 Function argument or array index separator.
17245
17246 @item :=
17247 Assignment. The value of @var{var} @code{:=} @var{value} is
17248 @var{value}.
17249
17250 @item <@r{, }>
17251 Less than, greater than on integral, floating-point, or enumerated
17252 types.
17253
17254 @item <=@r{, }>=
17255 Less than or equal to, greater than or equal to
17256 on integral, floating-point and enumerated types, or set inclusion on
17257 set types. Same precedence as @code{<}.
17258
17259 @item =@r{, }<>@r{, }#
17260 Equality and two ways of expressing inequality, valid on scalar types.
17261 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
17262 available for inequality, since @code{#} conflicts with the script
17263 comment character.
17264
17265 @item IN
17266 Set membership. Defined on set types and the types of their members.
17267 Same precedence as @code{<}.
17268
17269 @item OR
17270 Boolean disjunction. Defined on boolean types.
17271
17272 @item AND@r{, }&
17273 Boolean conjunction. Defined on boolean types.
17274
17275 @item @@
17276 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17277
17278 @item +@r{, }-
17279 Addition and subtraction on integral and floating-point types, or union
17280 and difference on set types.
17281
17282 @item *
17283 Multiplication on integral and floating-point types, or set intersection
17284 on set types.
17285
17286 @item /
17287 Division on floating-point types, or symmetric set difference on set
17288 types. Same precedence as @code{*}.
17289
17290 @item DIV@r{, }MOD
17291 Integer division and remainder. Defined on integral types. Same
17292 precedence as @code{*}.
17293
17294 @item -
17295 Negative. Defined on @code{INTEGER} and @code{REAL} data.
17296
17297 @item ^
17298 Pointer dereferencing. Defined on pointer types.
17299
17300 @item NOT
17301 Boolean negation. Defined on boolean types. Same precedence as
17302 @code{^}.
17303
17304 @item .
17305 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
17306 precedence as @code{^}.
17307
17308 @item []
17309 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
17310
17311 @item ()
17312 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
17313 as @code{^}.
17314
17315 @item ::@r{, }.
17316 @value{GDBN} and Modula-2 scope operators.
17317 @end table
17318
17319 @quotation
17320 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
17321 treats the use of the operator @code{IN}, or the use of operators
17322 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17323 @code{<=}, and @code{>=} on sets as an error.
17324 @end quotation
17325
17326
17327 @node Built-In Func/Proc
17328 @subsubsection Built-in Functions and Procedures
17329 @cindex Modula-2 built-ins
17330
17331 Modula-2 also makes available several built-in procedures and functions.
17332 In describing these, the following metavariables are used:
17333
17334 @table @var
17335
17336 @item a
17337 represents an @code{ARRAY} variable.
17338
17339 @item c
17340 represents a @code{CHAR} constant or variable.
17341
17342 @item i
17343 represents a variable or constant of integral type.
17344
17345 @item m
17346 represents an identifier that belongs to a set. Generally used in the
17347 same function with the metavariable @var{s}. The type of @var{s} should
17348 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17349
17350 @item n
17351 represents a variable or constant of integral or floating-point type.
17352
17353 @item r
17354 represents a variable or constant of floating-point type.
17355
17356 @item t
17357 represents a type.
17358
17359 @item v
17360 represents a variable.
17361
17362 @item x
17363 represents a variable or constant of one of many types. See the
17364 explanation of the function for details.
17365 @end table
17366
17367 All Modula-2 built-in procedures also return a result, described below.
17368
17369 @table @code
17370 @item ABS(@var{n})
17371 Returns the absolute value of @var{n}.
17372
17373 @item CAP(@var{c})
17374 If @var{c} is a lower case letter, it returns its upper case
17375 equivalent, otherwise it returns its argument.
17376
17377 @item CHR(@var{i})
17378 Returns the character whose ordinal value is @var{i}.
17379
17380 @item DEC(@var{v})
17381 Decrements the value in the variable @var{v} by one. Returns the new value.
17382
17383 @item DEC(@var{v},@var{i})
17384 Decrements the value in the variable @var{v} by @var{i}. Returns the
17385 new value.
17386
17387 @item EXCL(@var{m},@var{s})
17388 Removes the element @var{m} from the set @var{s}. Returns the new
17389 set.
17390
17391 @item FLOAT(@var{i})
17392 Returns the floating point equivalent of the integer @var{i}.
17393
17394 @item HIGH(@var{a})
17395 Returns the index of the last member of @var{a}.
17396
17397 @item INC(@var{v})
17398 Increments the value in the variable @var{v} by one. Returns the new value.
17399
17400 @item INC(@var{v},@var{i})
17401 Increments the value in the variable @var{v} by @var{i}. Returns the
17402 new value.
17403
17404 @item INCL(@var{m},@var{s})
17405 Adds the element @var{m} to the set @var{s} if it is not already
17406 there. Returns the new set.
17407
17408 @item MAX(@var{t})
17409 Returns the maximum value of the type @var{t}.
17410
17411 @item MIN(@var{t})
17412 Returns the minimum value of the type @var{t}.
17413
17414 @item ODD(@var{i})
17415 Returns boolean TRUE if @var{i} is an odd number.
17416
17417 @item ORD(@var{x})
17418 Returns the ordinal value of its argument. For example, the ordinal
17419 value of a character is its @sc{ascii} value (on machines supporting
17420 the @sc{ascii} character set). The argument @var{x} must be of an
17421 ordered type, which include integral, character and enumerated types.
17422
17423 @item SIZE(@var{x})
17424 Returns the size of its argument. The argument @var{x} can be a
17425 variable or a type.
17426
17427 @item TRUNC(@var{r})
17428 Returns the integral part of @var{r}.
17429
17430 @item TSIZE(@var{x})
17431 Returns the size of its argument. The argument @var{x} can be a
17432 variable or a type.
17433
17434 @item VAL(@var{t},@var{i})
17435 Returns the member of the type @var{t} whose ordinal value is @var{i}.
17436 @end table
17437
17438 @quotation
17439 @emph{Warning:} Sets and their operations are not yet supported, so
17440 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17441 an error.
17442 @end quotation
17443
17444 @cindex Modula-2 constants
17445 @node M2 Constants
17446 @subsubsection Constants
17447
17448 @value{GDBN} allows you to express the constants of Modula-2 in the following
17449 ways:
17450
17451 @itemize @bullet
17452
17453 @item
17454 Integer constants are simply a sequence of digits. When used in an
17455 expression, a constant is interpreted to be type-compatible with the
17456 rest of the expression. Hexadecimal integers are specified by a
17457 trailing @samp{H}, and octal integers by a trailing @samp{B}.
17458
17459 @item
17460 Floating point constants appear as a sequence of digits, followed by a
17461 decimal point and another sequence of digits. An optional exponent can
17462 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17463 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
17464 digits of the floating point constant must be valid decimal (base 10)
17465 digits.
17466
17467 @item
17468 Character constants consist of a single character enclosed by a pair of
17469 like quotes, either single (@code{'}) or double (@code{"}). They may
17470 also be expressed by their ordinal value (their @sc{ascii} value, usually)
17471 followed by a @samp{C}.
17472
17473 @item
17474 String constants consist of a sequence of characters enclosed by a
17475 pair of like quotes, either single (@code{'}) or double (@code{"}).
17476 Escape sequences in the style of C are also allowed. @xref{C
17477 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
17478 sequences.
17479
17480 @item
17481 Enumerated constants consist of an enumerated identifier.
17482
17483 @item
17484 Boolean constants consist of the identifiers @code{TRUE} and
17485 @code{FALSE}.
17486
17487 @item
17488 Pointer constants consist of integral values only.
17489
17490 @item
17491 Set constants are not yet supported.
17492 @end itemize
17493
17494 @node M2 Types
17495 @subsubsection Modula-2 Types
17496 @cindex Modula-2 types
17497
17498 Currently @value{GDBN} can print the following data types in Modula-2
17499 syntax: array types, record types, set types, pointer types, procedure
17500 types, enumerated types, subrange types and base types. You can also
17501 print the contents of variables declared using these type.
17502 This section gives a number of simple source code examples together with
17503 sample @value{GDBN} sessions.
17504
17505 The first example contains the following section of code:
17506
17507 @smallexample
17508 VAR
17509 s: SET OF CHAR ;
17510 r: [20..40] ;
17511 @end smallexample
17512
17513 @noindent
17514 and you can request @value{GDBN} to interrogate the type and value of
17515 @code{r} and @code{s}.
17516
17517 @smallexample
17518 (@value{GDBP}) print s
17519 @{'A'..'C', 'Z'@}
17520 (@value{GDBP}) ptype s
17521 SET OF CHAR
17522 (@value{GDBP}) print r
17523 21
17524 (@value{GDBP}) ptype r
17525 [20..40]
17526 @end smallexample
17527
17528 @noindent
17529 Likewise if your source code declares @code{s} as:
17530
17531 @smallexample
17532 VAR
17533 s: SET ['A'..'Z'] ;
17534 @end smallexample
17535
17536 @noindent
17537 then you may query the type of @code{s} by:
17538
17539 @smallexample
17540 (@value{GDBP}) ptype s
17541 type = SET ['A'..'Z']
17542 @end smallexample
17543
17544 @noindent
17545 Note that at present you cannot interactively manipulate set
17546 expressions using the debugger.
17547
17548 The following example shows how you might declare an array in Modula-2
17549 and how you can interact with @value{GDBN} to print its type and contents:
17550
17551 @smallexample
17552 VAR
17553 s: ARRAY [-10..10] OF CHAR ;
17554 @end smallexample
17555
17556 @smallexample
17557 (@value{GDBP}) ptype s
17558 ARRAY [-10..10] OF CHAR
17559 @end smallexample
17560
17561 Note that the array handling is not yet complete and although the type
17562 is printed correctly, expression handling still assumes that all
17563 arrays have a lower bound of zero and not @code{-10} as in the example
17564 above.
17565
17566 Here are some more type related Modula-2 examples:
17567
17568 @smallexample
17569 TYPE
17570 colour = (blue, red, yellow, green) ;
17571 t = [blue..yellow] ;
17572 VAR
17573 s: t ;
17574 BEGIN
17575 s := blue ;
17576 @end smallexample
17577
17578 @noindent
17579 The @value{GDBN} interaction shows how you can query the data type
17580 and value of a variable.
17581
17582 @smallexample
17583 (@value{GDBP}) print s
17584 $1 = blue
17585 (@value{GDBP}) ptype t
17586 type = [blue..yellow]
17587 @end smallexample
17588
17589 @noindent
17590 In this example a Modula-2 array is declared and its contents
17591 displayed. Observe that the contents are written in the same way as
17592 their @code{C} counterparts.
17593
17594 @smallexample
17595 VAR
17596 s: ARRAY [1..5] OF CARDINAL ;
17597 BEGIN
17598 s[1] := 1 ;
17599 @end smallexample
17600
17601 @smallexample
17602 (@value{GDBP}) print s
17603 $1 = @{1, 0, 0, 0, 0@}
17604 (@value{GDBP}) ptype s
17605 type = ARRAY [1..5] OF CARDINAL
17606 @end smallexample
17607
17608 The Modula-2 language interface to @value{GDBN} also understands
17609 pointer types as shown in this example:
17610
17611 @smallexample
17612 VAR
17613 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
17614 BEGIN
17615 NEW(s) ;
17616 s^[1] := 1 ;
17617 @end smallexample
17618
17619 @noindent
17620 and you can request that @value{GDBN} describes the type of @code{s}.
17621
17622 @smallexample
17623 (@value{GDBP}) ptype s
17624 type = POINTER TO ARRAY [1..5] OF CARDINAL
17625 @end smallexample
17626
17627 @value{GDBN} handles compound types as we can see in this example.
17628 Here we combine array types, record types, pointer types and subrange
17629 types:
17630
17631 @smallexample
17632 TYPE
17633 foo = RECORD
17634 f1: CARDINAL ;
17635 f2: CHAR ;
17636 f3: myarray ;
17637 END ;
17638
17639 myarray = ARRAY myrange OF CARDINAL ;
17640 myrange = [-2..2] ;
17641 VAR
17642 s: POINTER TO ARRAY myrange OF foo ;
17643 @end smallexample
17644
17645 @noindent
17646 and you can ask @value{GDBN} to describe the type of @code{s} as shown
17647 below.
17648
17649 @smallexample
17650 (@value{GDBP}) ptype s
17651 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
17652 f1 : CARDINAL;
17653 f2 : CHAR;
17654 f3 : ARRAY [-2..2] OF CARDINAL;
17655 END
17656 @end smallexample
17657
17658 @node M2 Defaults
17659 @subsubsection Modula-2 Defaults
17660 @cindex Modula-2 defaults
17661
17662 If type and range checking are set automatically by @value{GDBN}, they
17663 both default to @code{on} whenever the working language changes to
17664 Modula-2. This happens regardless of whether you or @value{GDBN}
17665 selected the working language.
17666
17667 If you allow @value{GDBN} to set the language automatically, then entering
17668 code compiled from a file whose name ends with @file{.mod} sets the
17669 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
17670 Infer the Source Language}, for further details.
17671
17672 @node Deviations
17673 @subsubsection Deviations from Standard Modula-2
17674 @cindex Modula-2, deviations from
17675
17676 A few changes have been made to make Modula-2 programs easier to debug.
17677 This is done primarily via loosening its type strictness:
17678
17679 @itemize @bullet
17680 @item
17681 Unlike in standard Modula-2, pointer constants can be formed by
17682 integers. This allows you to modify pointer variables during
17683 debugging. (In standard Modula-2, the actual address contained in a
17684 pointer variable is hidden from you; it can only be modified
17685 through direct assignment to another pointer variable or expression that
17686 returned a pointer.)
17687
17688 @item
17689 C escape sequences can be used in strings and characters to represent
17690 non-printable characters. @value{GDBN} prints out strings with these
17691 escape sequences embedded. Single non-printable characters are
17692 printed using the @samp{CHR(@var{nnn})} format.
17693
17694 @item
17695 The assignment operator (@code{:=}) returns the value of its right-hand
17696 argument.
17697
17698 @item
17699 All built-in procedures both modify @emph{and} return their argument.
17700 @end itemize
17701
17702 @node M2 Checks
17703 @subsubsection Modula-2 Type and Range Checks
17704 @cindex Modula-2 checks
17705
17706 @quotation
17707 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
17708 range checking.
17709 @end quotation
17710 @c FIXME remove warning when type/range checks added
17711
17712 @value{GDBN} considers two Modula-2 variables type equivalent if:
17713
17714 @itemize @bullet
17715 @item
17716 They are of types that have been declared equivalent via a @code{TYPE
17717 @var{t1} = @var{t2}} statement
17718
17719 @item
17720 They have been declared on the same line. (Note: This is true of the
17721 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
17722 @end itemize
17723
17724 As long as type checking is enabled, any attempt to combine variables
17725 whose types are not equivalent is an error.
17726
17727 Range checking is done on all mathematical operations, assignment, array
17728 index bounds, and all built-in functions and procedures.
17729
17730 @node M2 Scope
17731 @subsubsection The Scope Operators @code{::} and @code{.}
17732 @cindex scope
17733 @cindex @code{.}, Modula-2 scope operator
17734 @cindex colon, doubled as scope operator
17735 @ifinfo
17736 @vindex colon-colon@r{, in Modula-2}
17737 @c Info cannot handle :: but TeX can.
17738 @end ifinfo
17739 @ifnotinfo
17740 @vindex ::@r{, in Modula-2}
17741 @end ifnotinfo
17742
17743 There are a few subtle differences between the Modula-2 scope operator
17744 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
17745 similar syntax:
17746
17747 @smallexample
17748
17749 @var{module} . @var{id}
17750 @var{scope} :: @var{id}
17751 @end smallexample
17752
17753 @noindent
17754 where @var{scope} is the name of a module or a procedure,
17755 @var{module} the name of a module, and @var{id} is any declared
17756 identifier within your program, except another module.
17757
17758 Using the @code{::} operator makes @value{GDBN} search the scope
17759 specified by @var{scope} for the identifier @var{id}. If it is not
17760 found in the specified scope, then @value{GDBN} searches all scopes
17761 enclosing the one specified by @var{scope}.
17762
17763 Using the @code{.} operator makes @value{GDBN} search the current scope for
17764 the identifier specified by @var{id} that was imported from the
17765 definition module specified by @var{module}. With this operator, it is
17766 an error if the identifier @var{id} was not imported from definition
17767 module @var{module}, or if @var{id} is not an identifier in
17768 @var{module}.
17769
17770 @node GDB/M2
17771 @subsubsection @value{GDBN} and Modula-2
17772
17773 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
17774 Five subcommands of @code{set print} and @code{show print} apply
17775 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
17776 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
17777 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
17778 analogue in Modula-2.
17779
17780 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
17781 with any language, is not useful with Modula-2. Its
17782 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
17783 created in Modula-2 as they can in C or C@t{++}. However, because an
17784 address can be specified by an integral constant, the construct
17785 @samp{@{@var{type}@}@var{adrexp}} is still useful.
17786
17787 @cindex @code{#} in Modula-2
17788 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
17789 interpreted as the beginning of a comment. Use @code{<>} instead.
17790
17791 @node Ada
17792 @subsection Ada
17793 @cindex Ada
17794
17795 The extensions made to @value{GDBN} for Ada only support
17796 output from the @sc{gnu} Ada (GNAT) compiler.
17797 Other Ada compilers are not currently supported, and
17798 attempting to debug executables produced by them is most likely
17799 to be difficult.
17800
17801
17802 @cindex expressions in Ada
17803 @menu
17804 * Ada Mode Intro:: General remarks on the Ada syntax
17805 and semantics supported by Ada mode
17806 in @value{GDBN}.
17807 * Omissions from Ada:: Restrictions on the Ada expression syntax.
17808 * Additions to Ada:: Extensions of the Ada expression syntax.
17809 * Overloading support for Ada:: Support for expressions involving overloaded
17810 subprograms.
17811 * Stopping Before Main Program:: Debugging the program during elaboration.
17812 * Ada Exceptions:: Ada Exceptions
17813 * Ada Tasks:: Listing and setting breakpoints in tasks.
17814 * Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
17815 * Ravenscar Profile:: Tasking Support when using the Ravenscar
17816 Profile
17817 * Ada Settings:: New settable GDB parameters for Ada.
17818 * Ada Glitches:: Known peculiarities of Ada mode.
17819 @end menu
17820
17821 @node Ada Mode Intro
17822 @subsubsection Introduction
17823 @cindex Ada mode, general
17824
17825 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
17826 syntax, with some extensions.
17827 The philosophy behind the design of this subset is
17828
17829 @itemize @bullet
17830 @item
17831 That @value{GDBN} should provide basic literals and access to operations for
17832 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
17833 leaving more sophisticated computations to subprograms written into the
17834 program (which therefore may be called from @value{GDBN}).
17835
17836 @item
17837 That type safety and strict adherence to Ada language restrictions
17838 are not particularly important to the @value{GDBN} user.
17839
17840 @item
17841 That brevity is important to the @value{GDBN} user.
17842 @end itemize
17843
17844 Thus, for brevity, the debugger acts as if all names declared in
17845 user-written packages are directly visible, even if they are not visible
17846 according to Ada rules, thus making it unnecessary to fully qualify most
17847 names with their packages, regardless of context. Where this causes
17848 ambiguity, @value{GDBN} asks the user's intent.
17849
17850 The debugger will start in Ada mode if it detects an Ada main program.
17851 As for other languages, it will enter Ada mode when stopped in a program that
17852 was translated from an Ada source file.
17853
17854 While in Ada mode, you may use `@t{--}' for comments. This is useful
17855 mostly for documenting command files. The standard @value{GDBN} comment
17856 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
17857 middle (to allow based literals).
17858
17859 @node Omissions from Ada
17860 @subsubsection Omissions from Ada
17861 @cindex Ada, omissions from
17862
17863 Here are the notable omissions from the subset:
17864
17865 @itemize @bullet
17866 @item
17867 Only a subset of the attributes are supported:
17868
17869 @itemize @minus
17870 @item
17871 @t{'First}, @t{'Last}, and @t{'Length}
17872 on array objects (not on types and subtypes).
17873
17874 @item
17875 @t{'Min} and @t{'Max}.
17876
17877 @item
17878 @t{'Pos} and @t{'Val}.
17879
17880 @item
17881 @t{'Tag}.
17882
17883 @item
17884 @t{'Range} on array objects (not subtypes), but only as the right
17885 operand of the membership (@code{in}) operator.
17886
17887 @item
17888 @t{'Access}, @t{'Unchecked_Access}, and
17889 @t{'Unrestricted_Access} (a GNAT extension).
17890
17891 @item
17892 @t{'Address}.
17893 @end itemize
17894
17895 @item
17896 The names in
17897 @code{Characters.Latin_1} are not available and
17898 concatenation is not implemented. Thus, escape characters in strings are
17899 not currently available.
17900
17901 @item
17902 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
17903 equality of representations. They will generally work correctly
17904 for strings and arrays whose elements have integer or enumeration types.
17905 They may not work correctly for arrays whose element
17906 types have user-defined equality, for arrays of real values
17907 (in particular, IEEE-conformant floating point, because of negative
17908 zeroes and NaNs), and for arrays whose elements contain unused bits with
17909 indeterminate values.
17910
17911 @item
17912 The other component-by-component array operations (@code{and}, @code{or},
17913 @code{xor}, @code{not}, and relational tests other than equality)
17914 are not implemented.
17915
17916 @item
17917 @cindex array aggregates (Ada)
17918 @cindex record aggregates (Ada)
17919 @cindex aggregates (Ada)
17920 There is limited support for array and record aggregates. They are
17921 permitted only on the right sides of assignments, as in these examples:
17922
17923 @smallexample
17924 (@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
17925 (@value{GDBP}) set An_Array := (1, others => 0)
17926 (@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
17927 (@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
17928 (@value{GDBP}) set A_Record := (1, "Peter", True);
17929 (@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
17930 @end smallexample
17931
17932 Changing a
17933 discriminant's value by assigning an aggregate has an
17934 undefined effect if that discriminant is used within the record.
17935 However, you can first modify discriminants by directly assigning to
17936 them (which normally would not be allowed in Ada), and then performing an
17937 aggregate assignment. For example, given a variable @code{A_Rec}
17938 declared to have a type such as:
17939
17940 @smallexample
17941 type Rec (Len : Small_Integer := 0) is record
17942 Id : Integer;
17943 Vals : IntArray (1 .. Len);
17944 end record;
17945 @end smallexample
17946
17947 you can assign a value with a different size of @code{Vals} with two
17948 assignments:
17949
17950 @smallexample
17951 (@value{GDBP}) set A_Rec.Len := 4
17952 (@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
17953 @end smallexample
17954
17955 As this example also illustrates, @value{GDBN} is very loose about the usual
17956 rules concerning aggregates. You may leave out some of the
17957 components of an array or record aggregate (such as the @code{Len}
17958 component in the assignment to @code{A_Rec} above); they will retain their
17959 original values upon assignment. You may freely use dynamic values as
17960 indices in component associations. You may even use overlapping or
17961 redundant component associations, although which component values are
17962 assigned in such cases is not defined.
17963
17964 @item
17965 Calls to dispatching subprograms are not implemented.
17966
17967 @item
17968 The overloading algorithm is much more limited (i.e., less selective)
17969 than that of real Ada. It makes only limited use of the context in
17970 which a subexpression appears to resolve its meaning, and it is much
17971 looser in its rules for allowing type matches. As a result, some
17972 function calls will be ambiguous, and the user will be asked to choose
17973 the proper resolution.
17974
17975 @item
17976 The @code{new} operator is not implemented.
17977
17978 @item
17979 Entry calls are not implemented.
17980
17981 @item
17982 Aside from printing, arithmetic operations on the native VAX floating-point
17983 formats are not supported.
17984
17985 @item
17986 It is not possible to slice a packed array.
17987
17988 @item
17989 The names @code{True} and @code{False}, when not part of a qualified name,
17990 are interpreted as if implicitly prefixed by @code{Standard}, regardless of
17991 context.
17992 Should your program
17993 redefine these names in a package or procedure (at best a dubious practice),
17994 you will have to use fully qualified names to access their new definitions.
17995 @end itemize
17996
17997 @node Additions to Ada
17998 @subsubsection Additions to Ada
17999 @cindex Ada, deviations from
18000
18001 As it does for other languages, @value{GDBN} makes certain generic
18002 extensions to Ada (@pxref{Expressions}):
18003
18004 @itemize @bullet
18005 @item
18006 If the expression @var{E} is a variable residing in memory (typically
18007 a local variable or array element) and @var{N} is a positive integer,
18008 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
18009 @var{N}-1 adjacent variables following it in memory as an array. In
18010 Ada, this operator is generally not necessary, since its prime use is
18011 in displaying parts of an array, and slicing will usually do this in
18012 Ada. However, there are occasional uses when debugging programs in
18013 which certain debugging information has been optimized away.
18014
18015 @item
18016 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
18017 appears in function or file @var{B}.'' When @var{B} is a file name,
18018 you must typically surround it in single quotes.
18019
18020 @item
18021 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
18022 @var{type} that appears at address @var{addr}.''
18023
18024 @item
18025 A name starting with @samp{$} is a convenience variable
18026 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
18027 @end itemize
18028
18029 In addition, @value{GDBN} provides a few other shortcuts and outright
18030 additions specific to Ada:
18031
18032 @itemize @bullet
18033 @item
18034 The assignment statement is allowed as an expression, returning
18035 its right-hand operand as its value. Thus, you may enter
18036
18037 @smallexample
18038 (@value{GDBP}) set x := y + 3
18039 (@value{GDBP}) print A(tmp := y + 1)
18040 @end smallexample
18041
18042 @item
18043 The semicolon is allowed as an ``operator,'' returning as its value
18044 the value of its right-hand operand.
18045 This allows, for example,
18046 complex conditional breaks:
18047
18048 @smallexample
18049 (@value{GDBP}) break f
18050 (@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
18051 @end smallexample
18052
18053 @item
18054 Rather than use catenation and symbolic character names to introduce special
18055 characters into strings, one may instead use a special bracket notation,
18056 which is also used to print strings. A sequence of characters of the form
18057 @samp{["@var{XX}"]} within a string or character literal denotes the
18058 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
18059 sequence of characters @samp{["""]} also denotes a single quotation mark
18060 in strings. For example,
18061 @smallexample
18062 "One line.["0a"]Next line.["0a"]"
18063 @end smallexample
18064 @noindent
18065 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
18066 after each period.
18067
18068 @item
18069 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
18070 @t{'Max} is optional (and is ignored in any case). For example, it is valid
18071 to write
18072
18073 @smallexample
18074 (@value{GDBP}) print 'max(x, y)
18075 @end smallexample
18076
18077 @item
18078 When printing arrays, @value{GDBN} uses positional notation when the
18079 array has a lower bound of 1, and uses a modified named notation otherwise.
18080 For example, a one-dimensional array of three integers with a lower bound
18081 of 3 might print as
18082
18083 @smallexample
18084 (3 => 10, 17, 1)
18085 @end smallexample
18086
18087 @noindent
18088 That is, in contrast to valid Ada, only the first component has a @code{=>}
18089 clause.
18090
18091 @item
18092 You may abbreviate attributes in expressions with any unique,
18093 multi-character subsequence of
18094 their names (an exact match gets preference).
18095 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
18096 in place of @t{a'length}.
18097
18098 @item
18099 @cindex quoting Ada internal identifiers
18100 Since Ada is case-insensitive, the debugger normally maps identifiers you type
18101 to lower case. The GNAT compiler uses upper-case characters for
18102 some of its internal identifiers, which are normally of no interest to users.
18103 For the rare occasions when you actually have to look at them,
18104 enclose them in angle brackets to avoid the lower-case mapping.
18105 For example,
18106 @smallexample
18107 (@value{GDBP}) print <JMPBUF_SAVE>[0]
18108 @end smallexample
18109
18110 @item
18111 Printing an object of class-wide type or dereferencing an
18112 access-to-class-wide value will display all the components of the object's
18113 specific type (as indicated by its run-time tag). Likewise, component
18114 selection on such a value will operate on the specific type of the
18115 object.
18116
18117 @end itemize
18118
18119 @node Overloading support for Ada
18120 @subsubsection Overloading support for Ada
18121 @cindex overloading, Ada
18122
18123 The debugger supports limited overloading. Given a subprogram call in which
18124 the function symbol has multiple definitions, it will use the number of
18125 actual parameters and some information about their types to attempt to narrow
18126 the set of definitions. It also makes very limited use of context, preferring
18127 procedures to functions in the context of the @code{call} command, and
18128 functions to procedures elsewhere.
18129
18130 If, after narrowing, the set of matching definitions still contains more than
18131 one definition, @value{GDBN} will display a menu to query which one it should
18132 use, for instance:
18133
18134 @smallexample
18135 (@value{GDBP}) print f(1)
18136 Multiple matches for f
18137 [0] cancel
18138 [1] foo.f (integer) return boolean at foo.adb:23
18139 [2] foo.f (foo.new_integer) return boolean at foo.adb:28
18140 >
18141 @end smallexample
18142
18143 In this case, just select one menu entry either to cancel expression evaluation
18144 (type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
18145 instance (type the corresponding number and press @key{RET}).
18146
18147 Here are a couple of commands to customize @value{GDBN}'s behavior in this
18148 case:
18149
18150 @table @code
18151
18152 @kindex set ada print-signatures
18153 @item set ada print-signatures
18154 Control whether parameter types and return types are displayed in overloads
18155 selection menus. It is @code{on} by default.
18156 @xref{Overloading support for Ada}.
18157
18158 @kindex show ada print-signatures
18159 @item show ada print-signatures
18160 Show the current setting for displaying parameter types and return types in
18161 overloads selection menu.
18162 @xref{Overloading support for Ada}.
18163
18164 @end table
18165
18166 @node Stopping Before Main Program
18167 @subsubsection Stopping at the Very Beginning
18168
18169 @cindex breakpointing Ada elaboration code
18170 It is sometimes necessary to debug the program during elaboration, and
18171 before reaching the main procedure.
18172 As defined in the Ada Reference
18173 Manual, the elaboration code is invoked from a procedure called
18174 @code{adainit}. To run your program up to the beginning of
18175 elaboration, simply use the following two commands:
18176 @code{tbreak adainit} and @code{run}.
18177
18178 @node Ada Exceptions
18179 @subsubsection Ada Exceptions
18180
18181 A command is provided to list all Ada exceptions:
18182
18183 @table @code
18184 @kindex info exceptions
18185 @item info exceptions
18186 @itemx info exceptions @var{regexp}
18187 The @code{info exceptions} command allows you to list all Ada exceptions
18188 defined within the program being debugged, as well as their addresses.
18189 With a regular expression, @var{regexp}, as argument, only those exceptions
18190 whose names match @var{regexp} are listed.
18191 @end table
18192
18193 Below is a small example, showing how the command can be used, first
18194 without argument, and next with a regular expression passed as an
18195 argument.
18196
18197 @smallexample
18198 (@value{GDBP}) info exceptions
18199 All defined Ada exceptions:
18200 constraint_error: 0x613da0
18201 program_error: 0x613d20
18202 storage_error: 0x613ce0
18203 tasking_error: 0x613ca0
18204 const.aint_global_e: 0x613b00
18205 (@value{GDBP}) info exceptions const.aint
18206 All Ada exceptions matching regular expression "const.aint":
18207 constraint_error: 0x613da0
18208 const.aint_global_e: 0x613b00
18209 @end smallexample
18210
18211 It is also possible to ask @value{GDBN} to stop your program's execution
18212 when an exception is raised. For more details, see @ref{Set Catchpoints}.
18213
18214 @node Ada Tasks
18215 @subsubsection Extensions for Ada Tasks
18216 @cindex Ada, tasking
18217
18218 Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
18219 @value{GDBN} provides the following task-related commands:
18220
18221 @table @code
18222 @kindex info tasks
18223 @item info tasks
18224 This command shows a list of current Ada tasks, as in the following example:
18225
18226
18227 @smallexample
18228 @iftex
18229 @leftskip=0.5cm
18230 @end iftex
18231 (@value{GDBP}) info tasks
18232 ID TID P-ID Pri State Name
18233 1 8088000 0 15 Child Activation Wait main_task
18234 2 80a4000 1 15 Accept Statement b
18235 3 809a800 1 15 Child Activation Wait a
18236 * 4 80ae800 3 15 Runnable c
18237
18238 @end smallexample
18239
18240 @noindent
18241 In this listing, the asterisk before the last task indicates it to be the
18242 task currently being inspected.
18243
18244 @table @asis
18245 @item ID
18246 Represents @value{GDBN}'s internal task number.
18247
18248 @item TID
18249 The Ada task ID.
18250
18251 @item P-ID
18252 The parent's task ID (@value{GDBN}'s internal task number).
18253
18254 @item Pri
18255 The base priority of the task.
18256
18257 @item State
18258 Current state of the task.
18259
18260 @table @code
18261 @item Unactivated
18262 The task has been created but has not been activated. It cannot be
18263 executing.
18264
18265 @item Runnable
18266 The task is not blocked for any reason known to Ada. (It may be waiting
18267 for a mutex, though.) It is conceptually "executing" in normal mode.
18268
18269 @item Terminated
18270 The task is terminated, in the sense of ARM 9.3 (5). Any dependents
18271 that were waiting on terminate alternatives have been awakened and have
18272 terminated themselves.
18273
18274 @item Child Activation Wait
18275 The task is waiting for created tasks to complete activation.
18276
18277 @item Accept Statement
18278 The task is waiting on an accept or selective wait statement.
18279
18280 @item Waiting on entry call
18281 The task is waiting on an entry call.
18282
18283 @item Async Select Wait
18284 The task is waiting to start the abortable part of an asynchronous
18285 select statement.
18286
18287 @item Delay Sleep
18288 The task is waiting on a select statement with only a delay
18289 alternative open.
18290
18291 @item Child Termination Wait
18292 The task is sleeping having completed a master within itself, and is
18293 waiting for the tasks dependent on that master to become terminated or
18294 waiting on a terminate Phase.
18295
18296 @item Wait Child in Term Alt
18297 The task is sleeping waiting for tasks on terminate alternatives to
18298 finish terminating.
18299
18300 @item Accepting RV with @var{taskno}
18301 The task is accepting a rendez-vous with the task @var{taskno}.
18302 @end table
18303
18304 @item Name
18305 Name of the task in the program.
18306
18307 @end table
18308
18309 @kindex info task @var{taskno}
18310 @item info task @var{taskno}
18311 This command shows detailed informations on the specified task, as in
18312 the following example:
18313 @smallexample
18314 @iftex
18315 @leftskip=0.5cm
18316 @end iftex
18317 (@value{GDBP}) info tasks
18318 ID TID P-ID Pri State Name
18319 1 8077880 0 15 Child Activation Wait main_task
18320 * 2 807c468 1 15 Runnable task_1
18321 (@value{GDBP}) info task 2
18322 Ada Task: 0x807c468
18323 Name: "task_1"
18324 Thread: 0
18325 LWP: 0x1fac
18326 Parent: 1 ("main_task")
18327 Base Priority: 15
18328 State: Runnable
18329 @end smallexample
18330
18331 @item task
18332 @kindex task@r{ (Ada)}
18333 @cindex current Ada task ID
18334 This command prints the ID and name of the current task.
18335
18336 @smallexample
18337 @iftex
18338 @leftskip=0.5cm
18339 @end iftex
18340 (@value{GDBP}) info tasks
18341 ID TID P-ID Pri State Name
18342 1 8077870 0 15 Child Activation Wait main_task
18343 * 2 807c458 1 15 Runnable some_task
18344 (@value{GDBP}) task
18345 [Current task is 2 "some_task"]
18346 @end smallexample
18347
18348 @item task @var{taskno}
18349 @cindex Ada task switching
18350 This command is like the @code{thread @var{thread-id}}
18351 command (@pxref{Threads}). It switches the context of debugging
18352 from the current task to the given task.
18353
18354 @smallexample
18355 @iftex
18356 @leftskip=0.5cm
18357 @end iftex
18358 (@value{GDBP}) info tasks
18359 ID TID P-ID Pri State Name
18360 1 8077870 0 15 Child Activation Wait main_task
18361 * 2 807c458 1 15 Runnable some_task
18362 (@value{GDBP}) task 1
18363 [Switching to task 1 "main_task"]
18364 #0 0x8067726 in pthread_cond_wait ()
18365 (@value{GDBP}) bt
18366 #0 0x8067726 in pthread_cond_wait ()
18367 #1 0x8056714 in system.os_interface.pthread_cond_wait ()
18368 #2 0x805cb63 in system.task_primitives.operations.sleep ()
18369 #3 0x806153e in system.tasking.stages.activate_tasks ()
18370 #4 0x804aacc in un () at un.adb:5
18371 @end smallexample
18372
18373 @item break @var{location} task @var{taskno}
18374 @itemx break @var{location} task @var{taskno} if @dots{}
18375 @cindex breakpoints and tasks, in Ada
18376 @cindex task breakpoints, in Ada
18377 @kindex break @dots{} task @var{taskno}@r{ (Ada)}
18378 These commands are like the @code{break @dots{} thread @dots{}}
18379 command (@pxref{Thread Stops}). The
18380 @var{location} argument specifies source lines, as described
18381 in @ref{Specify Location}.
18382
18383 Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18384 to specify that you only want @value{GDBN} to stop the program when a
18385 particular Ada task reaches this breakpoint. The @var{taskno} is one of the
18386 numeric task identifiers assigned by @value{GDBN}, shown in the first
18387 column of the @samp{info tasks} display.
18388
18389 If you do not specify @samp{task @var{taskno}} when you set a
18390 breakpoint, the breakpoint applies to @emph{all} tasks of your
18391 program.
18392
18393 You can use the @code{task} qualifier on conditional breakpoints as
18394 well; in this case, place @samp{task @var{taskno}} before the
18395 breakpoint condition (before the @code{if}).
18396
18397 For example,
18398
18399 @smallexample
18400 @iftex
18401 @leftskip=0.5cm
18402 @end iftex
18403 (@value{GDBP}) info tasks
18404 ID TID P-ID Pri State Name
18405 1 140022020 0 15 Child Activation Wait main_task
18406 2 140045060 1 15 Accept/Select Wait t2
18407 3 140044840 1 15 Runnable t1
18408 * 4 140056040 1 15 Runnable t3
18409 (@value{GDBP}) b 15 task 2
18410 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18411 (@value{GDBP}) cont
18412 Continuing.
18413 task # 1 running
18414 task # 2 running
18415
18416 Breakpoint 5, test_task_debug () at test_task_debug.adb:15
18417 15 flush;
18418 (@value{GDBP}) info tasks
18419 ID TID P-ID Pri State Name
18420 1 140022020 0 15 Child Activation Wait main_task
18421 * 2 140045060 1 15 Runnable t2
18422 3 140044840 1 15 Runnable t1
18423 4 140056040 1 15 Delay Sleep t3
18424 @end smallexample
18425 @end table
18426
18427 @node Ada Tasks and Core Files
18428 @subsubsection Tasking Support when Debugging Core Files
18429 @cindex Ada tasking and core file debugging
18430
18431 When inspecting a core file, as opposed to debugging a live program,
18432 tasking support may be limited or even unavailable, depending on
18433 the platform being used.
18434 For instance, on x86-linux, the list of tasks is available, but task
18435 switching is not supported.
18436
18437 On certain platforms, the debugger needs to perform some
18438 memory writes in order to provide Ada tasking support. When inspecting
18439 a core file, this means that the core file must be opened with read-write
18440 privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18441 Under these circumstances, you should make a backup copy of the core
18442 file before inspecting it with @value{GDBN}.
18443
18444 @node Ravenscar Profile
18445 @subsubsection Tasking Support when using the Ravenscar Profile
18446 @cindex Ravenscar Profile
18447
18448 The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18449 specifically designed for systems with safety-critical real-time
18450 requirements.
18451
18452 @table @code
18453 @kindex set ravenscar task-switching on
18454 @cindex task switching with program using Ravenscar Profile
18455 @item set ravenscar task-switching on
18456 Allows task switching when debugging a program that uses the Ravenscar
18457 Profile. This is the default.
18458
18459 @kindex set ravenscar task-switching off
18460 @item set ravenscar task-switching off
18461 Turn off task switching when debugging a program that uses the Ravenscar
18462 Profile. This is mostly intended to disable the code that adds support
18463 for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
18464 the Ravenscar runtime is preventing @value{GDBN} from working properly.
18465 To be effective, this command should be run before the program is started.
18466
18467 @kindex show ravenscar task-switching
18468 @item show ravenscar task-switching
18469 Show whether it is possible to switch from task to task in a program
18470 using the Ravenscar Profile.
18471
18472 @end table
18473
18474 @cindex Ravenscar thread
18475 When Ravenscar task-switching is enabled, Ravenscar tasks are
18476 announced by @value{GDBN} as if they were threads:
18477
18478 @smallexample
18479 (gdb) continue
18480 [New Ravenscar Thread 0x2b8f0]
18481 @end smallexample
18482
18483 Both Ravenscar tasks and the underlying CPU threads will show up in
18484 the output of @code{info threads}:
18485
18486 @smallexample
18487 (gdb) info threads
18488 Id Target Id Frame
18489 1 Thread 1 (CPU#0 [running]) simple () at simple.adb:10
18490 2 Thread 2 (CPU#1 [running]) 0x0000000000003d34 in __gnat_initialize_cpu_devices ()
18491 3 Thread 3 (CPU#2 [running]) 0x0000000000003d28 in __gnat_initialize_cpu_devices ()
18492 4 Thread 4 (CPU#3 [halted ]) 0x000000000000c6ec in system.task_primitives.operations.idle ()
18493 * 5 Ravenscar Thread 0x2b8f0 simple () at simple.adb:10
18494 6 Ravenscar Thread 0x2f150 0x000000000000c6ec in system.task_primitives.operations.idle ()
18495 @end smallexample
18496
18497 One known limitation of the Ravenscar support in @value{GDBN} is that
18498 it isn't currently possible to single-step through the runtime
18499 initialization sequence. If you need to debug this code, you should
18500 use @code{set ravenscar task-switching off}.
18501
18502 @node Ada Settings
18503 @subsubsection Ada Settings
18504 @cindex Ada settings
18505
18506 @table @code
18507 @kindex set varsize-limit
18508 @item set varsize-limit @var{size}
18509 Prevent @value{GDBN} from attempting to evaluate objects whose size
18510 is above the given limit (@var{size}) when those sizes are computed
18511 from run-time quantities. This is typically the case when the object
18512 has a variable size, such as an array whose bounds are not known at
18513 compile time for example. Setting @var{size} to @code{unlimited}
18514 removes the size limitation. By default, the limit is about 65KB.
18515
18516 The purpose of having such a limit is to prevent @value{GDBN} from
18517 trying to grab enormous chunks of virtual memory when asked to evaluate
18518 a quantity whose bounds have been corrupted or have not yet been fully
18519 initialized. The limit applies to the results of some subexpressions
18520 as well as to complete expressions. For example, an expression denoting
18521 a simple integer component, such as @code{x.y.z}, may fail if the size of
18522 @code{x.y} is variable and exceeds @code{size}. On the other hand,
18523 @value{GDBN} is sometimes clever; the expression @code{A(i)}, where
18524 @code{A} is an array variable with non-constant size, will generally
18525 succeed regardless of the bounds on @code{A}, as long as the component
18526 size is less than @var{size}.
18527
18528 @kindex show varsize-limit
18529 @item show varsize-limit
18530 Show the limit on types whose size is determined by run-time quantities.
18531 @end table
18532
18533 @node Ada Glitches
18534 @subsubsection Known Peculiarities of Ada Mode
18535 @cindex Ada, problems
18536
18537 Besides the omissions listed previously (@pxref{Omissions from Ada}),
18538 we know of several problems with and limitations of Ada mode in
18539 @value{GDBN},
18540 some of which will be fixed with planned future releases of the debugger
18541 and the GNU Ada compiler.
18542
18543 @itemize @bullet
18544 @item
18545 Static constants that the compiler chooses not to materialize as objects in
18546 storage are invisible to the debugger.
18547
18548 @item
18549 Named parameter associations in function argument lists are ignored (the
18550 argument lists are treated as positional).
18551
18552 @item
18553 Many useful library packages are currently invisible to the debugger.
18554
18555 @item
18556 Fixed-point arithmetic, conversions, input, and output is carried out using
18557 floating-point arithmetic, and may give results that only approximate those on
18558 the host machine.
18559
18560 @item
18561 The GNAT compiler never generates the prefix @code{Standard} for any of
18562 the standard symbols defined by the Ada language. @value{GDBN} knows about
18563 this: it will strip the prefix from names when you use it, and will never
18564 look for a name you have so qualified among local symbols, nor match against
18565 symbols in other packages or subprograms. If you have
18566 defined entities anywhere in your program other than parameters and
18567 local variables whose simple names match names in @code{Standard},
18568 GNAT's lack of qualification here can cause confusion. When this happens,
18569 you can usually resolve the confusion
18570 by qualifying the problematic names with package
18571 @code{Standard} explicitly.
18572 @end itemize
18573
18574 Older versions of the compiler sometimes generate erroneous debugging
18575 information, resulting in the debugger incorrectly printing the value
18576 of affected entities. In some cases, the debugger is able to work
18577 around an issue automatically. In other cases, the debugger is able
18578 to work around the issue, but the work-around has to be specifically
18579 enabled.
18580
18581 @kindex set ada trust-PAD-over-XVS
18582 @kindex show ada trust-PAD-over-XVS
18583 @table @code
18584
18585 @item set ada trust-PAD-over-XVS on
18586 Configure GDB to strictly follow the GNAT encoding when computing the
18587 value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
18588 types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
18589 a complete description of the encoding used by the GNAT compiler).
18590 This is the default.
18591
18592 @item set ada trust-PAD-over-XVS off
18593 This is related to the encoding using by the GNAT compiler. If @value{GDBN}
18594 sometimes prints the wrong value for certain entities, changing @code{ada
18595 trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
18596 the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
18597 @code{off}, but this incurs a slight performance penalty, so it is
18598 recommended to leave this setting to @code{on} unless necessary.
18599
18600 @end table
18601
18602 @cindex GNAT descriptive types
18603 @cindex GNAT encoding
18604 Internally, the debugger also relies on the compiler following a number
18605 of conventions known as the @samp{GNAT Encoding}, all documented in
18606 @file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
18607 how the debugging information should be generated for certain types.
18608 In particular, this convention makes use of @dfn{descriptive types},
18609 which are artificial types generated purely to help the debugger.
18610
18611 These encodings were defined at a time when the debugging information
18612 format used was not powerful enough to describe some of the more complex
18613 types available in Ada. Since DWARF allows us to express nearly all
18614 Ada features, the long-term goal is to slowly replace these descriptive
18615 types by their pure DWARF equivalent. To facilitate that transition,
18616 a new maintenance option is available to force the debugger to ignore
18617 those descriptive types. It allows the user to quickly evaluate how
18618 well @value{GDBN} works without them.
18619
18620 @table @code
18621
18622 @kindex maint ada set ignore-descriptive-types
18623 @item maintenance ada set ignore-descriptive-types [on|off]
18624 Control whether the debugger should ignore descriptive types.
18625 The default is not to ignore descriptives types (@code{off}).
18626
18627 @kindex maint ada show ignore-descriptive-types
18628 @item maintenance ada show ignore-descriptive-types
18629 Show if descriptive types are ignored by @value{GDBN}.
18630
18631 @end table
18632
18633 @node Unsupported Languages
18634 @section Unsupported Languages
18635
18636 @cindex unsupported languages
18637 @cindex minimal language
18638 In addition to the other fully-supported programming languages,
18639 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
18640 It does not represent a real programming language, but provides a set
18641 of capabilities close to what the C or assembly languages provide.
18642 This should allow most simple operations to be performed while debugging
18643 an application that uses a language currently not supported by @value{GDBN}.
18644
18645 If the language is set to @code{auto}, @value{GDBN} will automatically
18646 select this language if the current frame corresponds to an unsupported
18647 language.
18648
18649 @node Symbols
18650 @chapter Examining the Symbol Table
18651
18652 The commands described in this chapter allow you to inquire about the
18653 symbols (names of variables, functions and types) defined in your
18654 program. This information is inherent in the text of your program and
18655 does not change as your program executes. @value{GDBN} finds it in your
18656 program's symbol table, in the file indicated when you started @value{GDBN}
18657 (@pxref{File Options, ,Choosing Files}), or by one of the
18658 file-management commands (@pxref{Files, ,Commands to Specify Files}).
18659
18660 @cindex symbol names
18661 @cindex names of symbols
18662 @cindex quoting names
18663 @anchor{quoting names}
18664 Occasionally, you may need to refer to symbols that contain unusual
18665 characters, which @value{GDBN} ordinarily treats as word delimiters. The
18666 most frequent case is in referring to static variables in other
18667 source files (@pxref{Variables,,Program Variables}). File names
18668 are recorded in object files as debugging symbols, but @value{GDBN} would
18669 ordinarily parse a typical file name, like @file{foo.c}, as the three words
18670 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
18671 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
18672
18673 @smallexample
18674 p 'foo.c'::x
18675 @end smallexample
18676
18677 @noindent
18678 looks up the value of @code{x} in the scope of the file @file{foo.c}.
18679
18680 @table @code
18681 @cindex case-insensitive symbol names
18682 @cindex case sensitivity in symbol names
18683 @kindex set case-sensitive
18684 @item set case-sensitive on
18685 @itemx set case-sensitive off
18686 @itemx set case-sensitive auto
18687 Normally, when @value{GDBN} looks up symbols, it matches their names
18688 with case sensitivity determined by the current source language.
18689 Occasionally, you may wish to control that. The command @code{set
18690 case-sensitive} lets you do that by specifying @code{on} for
18691 case-sensitive matches or @code{off} for case-insensitive ones. If
18692 you specify @code{auto}, case sensitivity is reset to the default
18693 suitable for the source language. The default is case-sensitive
18694 matches for all languages except for Fortran, for which the default is
18695 case-insensitive matches.
18696
18697 @kindex show case-sensitive
18698 @item show case-sensitive
18699 This command shows the current setting of case sensitivity for symbols
18700 lookups.
18701
18702 @kindex set print type methods
18703 @item set print type methods
18704 @itemx set print type methods on
18705 @itemx set print type methods off
18706 Normally, when @value{GDBN} prints a class, it displays any methods
18707 declared in that class. You can control this behavior either by
18708 passing the appropriate flag to @code{ptype}, or using @command{set
18709 print type methods}. Specifying @code{on} will cause @value{GDBN} to
18710 display the methods; this is the default. Specifying @code{off} will
18711 cause @value{GDBN} to omit the methods.
18712
18713 @kindex show print type methods
18714 @item show print type methods
18715 This command shows the current setting of method display when printing
18716 classes.
18717
18718 @kindex set print type nested-type-limit
18719 @item set print type nested-type-limit @var{limit}
18720 @itemx set print type nested-type-limit unlimited
18721 Set the limit of displayed nested types that the type printer will
18722 show. A @var{limit} of @code{unlimited} or @code{-1} will show all
18723 nested definitions. By default, the type printer will not show any nested
18724 types defined in classes.
18725
18726 @kindex show print type nested-type-limit
18727 @item show print type nested-type-limit
18728 This command shows the current display limit of nested types when
18729 printing classes.
18730
18731 @kindex set print type typedefs
18732 @item set print type typedefs
18733 @itemx set print type typedefs on
18734 @itemx set print type typedefs off
18735
18736 Normally, when @value{GDBN} prints a class, it displays any typedefs
18737 defined in that class. You can control this behavior either by
18738 passing the appropriate flag to @code{ptype}, or using @command{set
18739 print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
18740 display the typedef definitions; this is the default. Specifying
18741 @code{off} will cause @value{GDBN} to omit the typedef definitions.
18742 Note that this controls whether the typedef definition itself is
18743 printed, not whether typedef names are substituted when printing other
18744 types.
18745
18746 @kindex show print type typedefs
18747 @item show print type typedefs
18748 This command shows the current setting of typedef display when
18749 printing classes.
18750
18751 @kindex info address
18752 @cindex address of a symbol
18753 @item info address @var{symbol}
18754 Describe where the data for @var{symbol} is stored. For a register
18755 variable, this says which register it is kept in. For a non-register
18756 local variable, this prints the stack-frame offset at which the variable
18757 is always stored.
18758
18759 Note the contrast with @samp{print &@var{symbol}}, which does not work
18760 at all for a register variable, and for a stack local variable prints
18761 the exact address of the current instantiation of the variable.
18762
18763 @kindex info symbol
18764 @cindex symbol from address
18765 @cindex closest symbol and offset for an address
18766 @item info symbol @var{addr}
18767 Print the name of a symbol which is stored at the address @var{addr}.
18768 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
18769 nearest symbol and an offset from it:
18770
18771 @smallexample
18772 (@value{GDBP}) info symbol 0x54320
18773 _initialize_vx + 396 in section .text
18774 @end smallexample
18775
18776 @noindent
18777 This is the opposite of the @code{info address} command. You can use
18778 it to find out the name of a variable or a function given its address.
18779
18780 For dynamically linked executables, the name of executable or shared
18781 library containing the symbol is also printed:
18782
18783 @smallexample
18784 (@value{GDBP}) info symbol 0x400225
18785 _start + 5 in section .text of /tmp/a.out
18786 (@value{GDBP}) info symbol 0x2aaaac2811cf
18787 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
18788 @end smallexample
18789
18790 @kindex demangle
18791 @cindex demangle
18792 @item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
18793 Demangle @var{name}.
18794 If @var{language} is provided it is the name of the language to demangle
18795 @var{name} in. Otherwise @var{name} is demangled in the current language.
18796
18797 The @samp{--} option specifies the end of options,
18798 and is useful when @var{name} begins with a dash.
18799
18800 The parameter @code{demangle-style} specifies how to interpret the kind
18801 of mangling used. @xref{Print Settings}.
18802
18803 @kindex whatis
18804 @item whatis[/@var{flags}] [@var{arg}]
18805 Print the data type of @var{arg}, which can be either an expression
18806 or a name of a data type. With no argument, print the data type of
18807 @code{$}, the last value in the value history.
18808
18809 If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
18810 is not actually evaluated, and any side-effecting operations (such as
18811 assignments or function calls) inside it do not take place.
18812
18813 If @var{arg} is a variable or an expression, @code{whatis} prints its
18814 literal type as it is used in the source code. If the type was
18815 defined using a @code{typedef}, @code{whatis} will @emph{not} print
18816 the data type underlying the @code{typedef}. If the type of the
18817 variable or the expression is a compound data type, such as
18818 @code{struct} or @code{class}, @code{whatis} never prints their
18819 fields or methods. It just prints the @code{struct}/@code{class}
18820 name (a.k.a.@: its @dfn{tag}). If you want to see the members of
18821 such a compound data type, use @code{ptype}.
18822
18823 If @var{arg} is a type name that was defined using @code{typedef},
18824 @code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
18825 Unrolling means that @code{whatis} will show the underlying type used
18826 in the @code{typedef} declaration of @var{arg}. However, if that
18827 underlying type is also a @code{typedef}, @code{whatis} will not
18828 unroll it.
18829
18830 For C code, the type names may also have the form @samp{class
18831 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
18832 @var{union-tag}} or @samp{enum @var{enum-tag}}.
18833
18834 @var{flags} can be used to modify how the type is displayed.
18835 Available flags are:
18836
18837 @table @code
18838 @item r
18839 Display in ``raw'' form. Normally, @value{GDBN} substitutes template
18840 parameters and typedefs defined in a class when printing the class'
18841 members. The @code{/r} flag disables this.
18842
18843 @item m
18844 Do not print methods defined in the class.
18845
18846 @item M
18847 Print methods defined in the class. This is the default, but the flag
18848 exists in case you change the default with @command{set print type methods}.
18849
18850 @item t
18851 Do not print typedefs defined in the class. Note that this controls
18852 whether the typedef definition itself is printed, not whether typedef
18853 names are substituted when printing other types.
18854
18855 @item T
18856 Print typedefs defined in the class. This is the default, but the flag
18857 exists in case you change the default with @command{set print type typedefs}.
18858
18859 @item o
18860 Print the offsets and sizes of fields in a struct, similar to what the
18861 @command{pahole} tool does. This option implies the @code{/tm} flags.
18862
18863 For example, given the following declarations:
18864
18865 @smallexample
18866 struct tuv
18867 @{
18868 int a1;
18869 char *a2;
18870 int a3;
18871 @};
18872
18873 struct xyz
18874 @{
18875 int f1;
18876 char f2;
18877 void *f3;
18878 struct tuv f4;
18879 @};
18880
18881 union qwe
18882 @{
18883 struct tuv fff1;
18884 struct xyz fff2;
18885 @};
18886
18887 struct tyu
18888 @{
18889 int a1 : 1;
18890 int a2 : 3;
18891 int a3 : 23;
18892 char a4 : 2;
18893 int64_t a5;
18894 int a6 : 5;
18895 int64_t a7 : 3;
18896 @};
18897 @end smallexample
18898
18899 Issuing a @kbd{ptype /o struct tuv} command would print:
18900
18901 @smallexample
18902 (@value{GDBP}) ptype /o struct tuv
18903 /* offset | size */ type = struct tuv @{
18904 /* 0 | 4 */ int a1;
18905 /* XXX 4-byte hole */
18906 /* 8 | 8 */ char *a2;
18907 /* 16 | 4 */ int a3;
18908
18909 /* total size (bytes): 24 */
18910 @}
18911 @end smallexample
18912
18913 Notice the format of the first column of comments. There, you can
18914 find two parts separated by the @samp{|} character: the @emph{offset},
18915 which indicates where the field is located inside the struct, in
18916 bytes, and the @emph{size} of the field. Another interesting line is
18917 the marker of a @emph{hole} in the struct, indicating that it may be
18918 possible to pack the struct and make it use less space by reorganizing
18919 its fields.
18920
18921 It is also possible to print offsets inside an union:
18922
18923 @smallexample
18924 (@value{GDBP}) ptype /o union qwe
18925 /* offset | size */ type = union qwe @{
18926 /* 24 */ struct tuv @{
18927 /* 0 | 4 */ int a1;
18928 /* XXX 4-byte hole */
18929 /* 8 | 8 */ char *a2;
18930 /* 16 | 4 */ int a3;
18931
18932 /* total size (bytes): 24 */
18933 @} fff1;
18934 /* 40 */ struct xyz @{
18935 /* 0 | 4 */ int f1;
18936 /* 4 | 1 */ char f2;
18937 /* XXX 3-byte hole */
18938 /* 8 | 8 */ void *f3;
18939 /* 16 | 24 */ struct tuv @{
18940 /* 16 | 4 */ int a1;
18941 /* XXX 4-byte hole */
18942 /* 24 | 8 */ char *a2;
18943 /* 32 | 4 */ int a3;
18944
18945 /* total size (bytes): 24 */
18946 @} f4;
18947
18948 /* total size (bytes): 40 */
18949 @} fff2;
18950
18951 /* total size (bytes): 40 */
18952 @}
18953 @end smallexample
18954
18955 In this case, since @code{struct tuv} and @code{struct xyz} occupy the
18956 same space (because we are dealing with an union), the offset is not
18957 printed for them. However, you can still examine the offset of each
18958 of these structures' fields.
18959
18960 Another useful scenario is printing the offsets of a struct containing
18961 bitfields:
18962
18963 @smallexample
18964 (@value{GDBP}) ptype /o struct tyu
18965 /* offset | size */ type = struct tyu @{
18966 /* 0:31 | 4 */ int a1 : 1;
18967 /* 0:28 | 4 */ int a2 : 3;
18968 /* 0: 5 | 4 */ int a3 : 23;
18969 /* 3: 3 | 1 */ signed char a4 : 2;
18970 /* XXX 3-bit hole */
18971 /* XXX 4-byte hole */
18972 /* 8 | 8 */ int64_t a5;
18973 /* 16: 0 | 4 */ int a6 : 5;
18974 /* 16: 5 | 8 */ int64_t a7 : 3;
18975 "/* XXX 7-byte padding */
18976
18977 /* total size (bytes): 24 */
18978 @}
18979 @end smallexample
18980
18981 Note how the offset information is now extended to also include the
18982 first bit of the bitfield.
18983 @end table
18984
18985 @kindex ptype
18986 @item ptype[/@var{flags}] [@var{arg}]
18987 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
18988 detailed description of the type, instead of just the name of the type.
18989 @xref{Expressions, ,Expressions}.
18990
18991 Contrary to @code{whatis}, @code{ptype} always unrolls any
18992 @code{typedef}s in its argument declaration, whether the argument is
18993 a variable, expression, or a data type. This means that @code{ptype}
18994 of a variable or an expression will not print literally its type as
18995 present in the source code---use @code{whatis} for that. @code{typedef}s at
18996 the pointer or reference targets are also unrolled. Only @code{typedef}s of
18997 fields, methods and inner @code{class typedef}s of @code{struct}s,
18998 @code{class}es and @code{union}s are not unrolled even with @code{ptype}.
18999
19000 For example, for this variable declaration:
19001
19002 @smallexample
19003 typedef double real_t;
19004 struct complex @{ real_t real; double imag; @};
19005 typedef struct complex complex_t;
19006 complex_t var;
19007 real_t *real_pointer_var;
19008 @end smallexample
19009
19010 @noindent
19011 the two commands give this output:
19012
19013 @smallexample
19014 @group
19015 (@value{GDBP}) whatis var
19016 type = complex_t
19017 (@value{GDBP}) ptype var
19018 type = struct complex @{
19019 real_t real;
19020 double imag;
19021 @}
19022 (@value{GDBP}) whatis complex_t
19023 type = struct complex
19024 (@value{GDBP}) whatis struct complex
19025 type = struct complex
19026 (@value{GDBP}) ptype struct complex
19027 type = struct complex @{
19028 real_t real;
19029 double imag;
19030 @}
19031 (@value{GDBP}) whatis real_pointer_var
19032 type = real_t *
19033 (@value{GDBP}) ptype real_pointer_var
19034 type = double *
19035 @end group
19036 @end smallexample
19037
19038 @noindent
19039 As with @code{whatis}, using @code{ptype} without an argument refers to
19040 the type of @code{$}, the last value in the value history.
19041
19042 @cindex incomplete type
19043 Sometimes, programs use opaque data types or incomplete specifications
19044 of complex data structure. If the debug information included in the
19045 program does not allow @value{GDBN} to display a full declaration of
19046 the data type, it will say @samp{<incomplete type>}. For example,
19047 given these declarations:
19048
19049 @smallexample
19050 struct foo;
19051 struct foo *fooptr;
19052 @end smallexample
19053
19054 @noindent
19055 but no definition for @code{struct foo} itself, @value{GDBN} will say:
19056
19057 @smallexample
19058 (@value{GDBP}) ptype foo
19059 $1 = <incomplete type>
19060 @end smallexample
19061
19062 @noindent
19063 ``Incomplete type'' is C terminology for data types that are not
19064 completely specified.
19065
19066 @cindex unknown type
19067 Othertimes, information about a variable's type is completely absent
19068 from the debug information included in the program. This most often
19069 happens when the program or library where the variable is defined
19070 includes no debug information at all. @value{GDBN} knows the variable
19071 exists from inspecting the linker/loader symbol table (e.g., the ELF
19072 dynamic symbol table), but such symbols do not contain type
19073 information. Inspecting the type of a (global) variable for which
19074 @value{GDBN} has no type information shows:
19075
19076 @smallexample
19077 (@value{GDBP}) ptype var
19078 type = <data variable, no debug info>
19079 @end smallexample
19080
19081 @xref{Variables, no debug info variables}, for how to print the values
19082 of such variables.
19083
19084 @kindex info types
19085 @item info types [-q] [@var{regexp}]
19086 Print a brief description of all types whose names match the regular
19087 expression @var{regexp} (or all types in your program, if you supply
19088 no argument). Each complete typename is matched as though it were a
19089 complete line; thus, @samp{i type value} gives information on all
19090 types in your program whose names include the string @code{value}, but
19091 @samp{i type ^value$} gives information only on types whose complete
19092 name is @code{value}.
19093
19094 In programs using different languages, @value{GDBN} chooses the syntax
19095 to print the type description according to the
19096 @samp{set language} value: using @samp{set language auto}
19097 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19098 language of the type, other values mean to use
19099 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19100
19101 This command differs from @code{ptype} in two ways: first, like
19102 @code{whatis}, it does not print a detailed description; second, it
19103 lists all source files and line numbers where a type is defined.
19104
19105 The output from @samp{into types} is proceeded with a header line
19106 describing what types are being listed. The optional flag @samp{-q},
19107 which stands for @samp{quiet}, disables printing this header
19108 information.
19109
19110 @kindex info type-printers
19111 @item info type-printers
19112 Versions of @value{GDBN} that ship with Python scripting enabled may
19113 have ``type printers'' available. When using @command{ptype} or
19114 @command{whatis}, these printers are consulted when the name of a type
19115 is needed. @xref{Type Printing API}, for more information on writing
19116 type printers.
19117
19118 @code{info type-printers} displays all the available type printers.
19119
19120 @kindex enable type-printer
19121 @kindex disable type-printer
19122 @item enable type-printer @var{name}@dots{}
19123 @item disable type-printer @var{name}@dots{}
19124 These commands can be used to enable or disable type printers.
19125
19126 @kindex info scope
19127 @cindex local variables
19128 @item info scope @var{location}
19129 List all the variables local to a particular scope. This command
19130 accepts a @var{location} argument---a function name, a source line, or
19131 an address preceded by a @samp{*}, and prints all the variables local
19132 to the scope defined by that location. (@xref{Specify Location}, for
19133 details about supported forms of @var{location}.) For example:
19134
19135 @smallexample
19136 (@value{GDBP}) @b{info scope command_line_handler}
19137 Scope for command_line_handler:
19138 Symbol rl is an argument at stack/frame offset 8, length 4.
19139 Symbol linebuffer is in static storage at address 0x150a18, length 4.
19140 Symbol linelength is in static storage at address 0x150a1c, length 4.
19141 Symbol p is a local variable in register $esi, length 4.
19142 Symbol p1 is a local variable in register $ebx, length 4.
19143 Symbol nline is a local variable in register $edx, length 4.
19144 Symbol repeat is a local variable at frame offset -8, length 4.
19145 @end smallexample
19146
19147 @noindent
19148 This command is especially useful for determining what data to collect
19149 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
19150 collect}.
19151
19152 @kindex info source
19153 @item info source
19154 Show information about the current source file---that is, the source file for
19155 the function containing the current point of execution:
19156 @itemize @bullet
19157 @item
19158 the name of the source file, and the directory containing it,
19159 @item
19160 the directory it was compiled in,
19161 @item
19162 its length, in lines,
19163 @item
19164 which programming language it is written in,
19165 @item
19166 if the debug information provides it, the program that compiled the file
19167 (which may include, e.g., the compiler version and command line arguments),
19168 @item
19169 whether the executable includes debugging information for that file, and
19170 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
19171 @item
19172 whether the debugging information includes information about
19173 preprocessor macros.
19174 @end itemize
19175
19176
19177 @kindex info sources
19178 @item info sources
19179 Print the names of all source files in your program for which there is
19180 debugging information, organized into two lists: files whose symbols
19181 have already been read, and files whose symbols will be read when needed.
19182
19183 @item info sources [-dirname | -basename] [--] [@var{regexp}]
19184 Like @samp{info sources}, but only print the names of the files
19185 matching the provided @var{regexp}.
19186 By default, the @var{regexp} is used to match anywhere in the filename.
19187 If @code{-dirname}, only files having a dirname matching @var{regexp} are shown.
19188 If @code{-basename}, only files having a basename matching @var{regexp}
19189 are shown.
19190 The matching is case-sensitive, except on operating systems that
19191 have case-insensitive filesystem (e.g., MS-Windows).
19192
19193 @kindex info functions
19194 @item info functions [-q] [-n]
19195 Print the names and data types of all defined functions.
19196 Similarly to @samp{info types}, this command groups its output by source
19197 files and annotates each function definition with its source line
19198 number.
19199
19200 In programs using different languages, @value{GDBN} chooses the syntax
19201 to print the function name and type according to the
19202 @samp{set language} value: using @samp{set language auto}
19203 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19204 language of the function, other values mean to use
19205 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19206
19207 The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
19208 results. A non-debugging symbol is a symbol that comes from the
19209 executable's symbol table, not from the debug information (for
19210 example, DWARF) associated with the executable.
19211
19212 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19213 printing header information and messages explaining why no functions
19214 have been printed.
19215
19216 @item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
19217 Like @samp{info functions}, but only print the names and data types
19218 of the functions selected with the provided regexp(s).
19219
19220 If @var{regexp} is provided, print only the functions whose names
19221 match the regular expression @var{regexp}.
19222 Thus, @samp{info fun step} finds all functions whose
19223 names include @code{step}; @samp{info fun ^step} finds those whose names
19224 start with @code{step}. If a function name contains characters that
19225 conflict with the regular expression language (e.g.@:
19226 @samp{operator*()}), they may be quoted with a backslash.
19227
19228 If @var{type_regexp} is provided, print only the functions whose
19229 types, as printed by the @code{whatis} command, match
19230 the regular expression @var{type_regexp}.
19231 If @var{type_regexp} contains space(s), it should be enclosed in
19232 quote characters. If needed, use backslash to escape the meaning
19233 of special characters or quotes.
19234 Thus, @samp{info fun -t '^int ('} finds the functions that return
19235 an integer; @samp{info fun -t '(.*int.*'} finds the functions that
19236 have an argument type containing int; @samp{info fun -t '^int (' ^step}
19237 finds the functions whose names start with @code{step} and that return
19238 int.
19239
19240 If both @var{regexp} and @var{type_regexp} are provided, a function
19241 is printed only if its name matches @var{regexp} and its type matches
19242 @var{type_regexp}.
19243
19244
19245 @kindex info variables
19246 @item info variables [-q] [-n]
19247 Print the names and data types of all variables that are defined
19248 outside of functions (i.e.@: excluding local variables).
19249 The printed variables are grouped by source files and annotated with
19250 their respective source line numbers.
19251
19252 In programs using different languages, @value{GDBN} chooses the syntax
19253 to print the variable name and type according to the
19254 @samp{set language} value: using @samp{set language auto}
19255 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19256 language of the variable, other values mean to use
19257 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19258
19259 The @samp{-n} flag excludes non-debugging symbols from the results.
19260
19261 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19262 printing header information and messages explaining why no variables
19263 have been printed.
19264
19265 @item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
19266 Like @kbd{info variables}, but only print the variables selected
19267 with the provided regexp(s).
19268
19269 If @var{regexp} is provided, print only the variables whose names
19270 match the regular expression @var{regexp}.
19271
19272 If @var{type_regexp} is provided, print only the variables whose
19273 types, as printed by the @code{whatis} command, match
19274 the regular expression @var{type_regexp}.
19275 If @var{type_regexp} contains space(s), it should be enclosed in
19276 quote characters. If needed, use backslash to escape the meaning
19277 of special characters or quotes.
19278
19279 If both @var{regexp} and @var{type_regexp} are provided, an argument
19280 is printed only if its name matches @var{regexp} and its type matches
19281 @var{type_regexp}.
19282
19283 @kindex info modules
19284 @cindex modules
19285 @item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
19286 List all Fortran modules in the program, or all modules matching the
19287 optional regular expression @var{regexp}.
19288
19289 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19290 printing header information and messages explaining why no modules
19291 have been printed.
19292
19293 @kindex info module
19294 @cindex Fortran modules, information about
19295 @cindex functions and variables by Fortran module
19296 @cindex module functions and variables
19297 @item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19298 @itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19299 List all functions or variables within all Fortran modules. The set
19300 of functions or variables listed can be limited by providing some or
19301 all of the optional regular expressions. If @var{module-regexp} is
19302 provided, then only Fortran modules matching @var{module-regexp} will
19303 be searched. Only functions or variables whose type matches the
19304 optional regular expression @var{type-regexp} will be listed. And
19305 only functions or variables whose name matches the optional regular
19306 expression @var{regexp} will be listed.
19307
19308 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19309 printing header information and messages explaining why no functions
19310 or variables have been printed.
19311
19312 @kindex info classes
19313 @cindex Objective-C, classes and selectors
19314 @item info classes
19315 @itemx info classes @var{regexp}
19316 Display all Objective-C classes in your program, or
19317 (with the @var{regexp} argument) all those matching a particular regular
19318 expression.
19319
19320 @kindex info selectors
19321 @item info selectors
19322 @itemx info selectors @var{regexp}
19323 Display all Objective-C selectors in your program, or
19324 (with the @var{regexp} argument) all those matching a particular regular
19325 expression.
19326
19327 @ignore
19328 This was never implemented.
19329 @kindex info methods
19330 @item info methods
19331 @itemx info methods @var{regexp}
19332 The @code{info methods} command permits the user to examine all defined
19333 methods within C@t{++} program, or (with the @var{regexp} argument) a
19334 specific set of methods found in the various C@t{++} classes. Many
19335 C@t{++} classes provide a large number of methods. Thus, the output
19336 from the @code{ptype} command can be overwhelming and hard to use. The
19337 @code{info-methods} command filters the methods, printing only those
19338 which match the regular-expression @var{regexp}.
19339 @end ignore
19340
19341 @cindex opaque data types
19342 @kindex set opaque-type-resolution
19343 @item set opaque-type-resolution on
19344 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
19345 declared as a pointer to a @code{struct}, @code{class}, or
19346 @code{union}---for example, @code{struct MyType *}---that is used in one
19347 source file although the full declaration of @code{struct MyType} is in
19348 another source file. The default is on.
19349
19350 A change in the setting of this subcommand will not take effect until
19351 the next time symbols for a file are loaded.
19352
19353 @item set opaque-type-resolution off
19354 Tell @value{GDBN} not to resolve opaque types. In this case, the type
19355 is printed as follows:
19356 @smallexample
19357 @{<no data fields>@}
19358 @end smallexample
19359
19360 @kindex show opaque-type-resolution
19361 @item show opaque-type-resolution
19362 Show whether opaque types are resolved or not.
19363
19364 @kindex set print symbol-loading
19365 @cindex print messages when symbols are loaded
19366 @item set print symbol-loading
19367 @itemx set print symbol-loading full
19368 @itemx set print symbol-loading brief
19369 @itemx set print symbol-loading off
19370 The @code{set print symbol-loading} command allows you to control the
19371 printing of messages when @value{GDBN} loads symbol information.
19372 By default a message is printed for the executable and one for each
19373 shared library, and normally this is what you want. However, when
19374 debugging apps with large numbers of shared libraries these messages
19375 can be annoying.
19376 When set to @code{brief} a message is printed for each executable,
19377 and when @value{GDBN} loads a collection of shared libraries at once
19378 it will only print one message regardless of the number of shared
19379 libraries. When set to @code{off} no messages are printed.
19380
19381 @kindex show print symbol-loading
19382 @item show print symbol-loading
19383 Show whether messages will be printed when a @value{GDBN} command
19384 entered from the keyboard causes symbol information to be loaded.
19385
19386 @kindex maint print symbols
19387 @cindex symbol dump
19388 @kindex maint print psymbols
19389 @cindex partial symbol dump
19390 @kindex maint print msymbols
19391 @cindex minimal symbol dump
19392 @item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19393 @itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19394 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19395 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19396 @itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19397 Write a dump of debugging symbol data into the file @var{filename} or
19398 the terminal if @var{filename} is unspecified.
19399 If @code{-objfile @var{objfile}} is specified, only dump symbols for
19400 that objfile.
19401 If @code{-pc @var{address}} is specified, only dump symbols for the file
19402 with code at that address. Note that @var{address} may be a symbol like
19403 @code{main}.
19404 If @code{-source @var{source}} is specified, only dump symbols for that
19405 source file.
19406
19407 These commands are used to debug the @value{GDBN} symbol-reading code.
19408 These commands do not modify internal @value{GDBN} state, therefore
19409 @samp{maint print symbols} will only print symbols for already expanded symbol
19410 tables.
19411 You can use the command @code{info sources} to find out which files these are.
19412 If you use @samp{maint print psymbols} instead, the dump shows information
19413 about symbols that @value{GDBN} only knows partially---that is, symbols
19414 defined in files that @value{GDBN} has skimmed, but not yet read completely.
19415 Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19416 ``ELF symbols''.
19417
19418 @xref{Files, ,Commands to Specify Files}, for a discussion of how
19419 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
19420
19421 @kindex maint info symtabs
19422 @kindex maint info psymtabs
19423 @cindex listing @value{GDBN}'s internal symbol tables
19424 @cindex symbol tables, listing @value{GDBN}'s internal
19425 @cindex full symbol tables, listing @value{GDBN}'s internal
19426 @cindex partial symbol tables, listing @value{GDBN}'s internal
19427 @item maint info symtabs @r{[} @var{regexp} @r{]}
19428 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
19429
19430 List the @code{struct symtab} or @code{struct partial_symtab}
19431 structures whose names match @var{regexp}. If @var{regexp} is not
19432 given, list them all. The output includes expressions which you can
19433 copy into a @value{GDBN} debugging this one to examine a particular
19434 structure in more detail. For example:
19435
19436 @smallexample
19437 (@value{GDBP}) maint info psymtabs dwarf2read
19438 @{ objfile /home/gnu/build/gdb/gdb
19439 ((struct objfile *) 0x82e69d0)
19440 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
19441 ((struct partial_symtab *) 0x8474b10)
19442 readin no
19443 fullname (null)
19444 text addresses 0x814d3c8 -- 0x8158074
19445 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
19446 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
19447 dependencies (none)
19448 @}
19449 @}
19450 (@value{GDBP}) maint info symtabs
19451 (@value{GDBP})
19452 @end smallexample
19453 @noindent
19454 We see that there is one partial symbol table whose filename contains
19455 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
19456 and we see that @value{GDBN} has not read in any symtabs yet at all.
19457 If we set a breakpoint on a function, that will cause @value{GDBN} to
19458 read the symtab for the compilation unit containing that function:
19459
19460 @smallexample
19461 (@value{GDBP}) break dwarf2_psymtab_to_symtab
19462 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
19463 line 1574.
19464 (@value{GDBP}) maint info symtabs
19465 @{ objfile /home/gnu/build/gdb/gdb
19466 ((struct objfile *) 0x82e69d0)
19467 @{ symtab /home/gnu/src/gdb/dwarf2read.c
19468 ((struct symtab *) 0x86c1f38)
19469 dirname (null)
19470 fullname (null)
19471 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
19472 linetable ((struct linetable *) 0x8370fa0)
19473 debugformat DWARF 2
19474 @}
19475 @}
19476 (@value{GDBP})
19477 @end smallexample
19478
19479 @kindex maint info line-table
19480 @cindex listing @value{GDBN}'s internal line tables
19481 @cindex line tables, listing @value{GDBN}'s internal
19482 @item maint info line-table @r{[} @var{regexp} @r{]}
19483
19484 List the @code{struct linetable} from all @code{struct symtab}
19485 instances whose name matches @var{regexp}. If @var{regexp} is not
19486 given, list the @code{struct linetable} from all @code{struct symtab}.
19487
19488 @kindex maint set symbol-cache-size
19489 @cindex symbol cache size
19490 @item maint set symbol-cache-size @var{size}
19491 Set the size of the symbol cache to @var{size}.
19492 The default size is intended to be good enough for debugging
19493 most applications. This option exists to allow for experimenting
19494 with different sizes.
19495
19496 @kindex maint show symbol-cache-size
19497 @item maint show symbol-cache-size
19498 Show the size of the symbol cache.
19499
19500 @kindex maint print symbol-cache
19501 @cindex symbol cache, printing its contents
19502 @item maint print symbol-cache
19503 Print the contents of the symbol cache.
19504 This is useful when debugging symbol cache issues.
19505
19506 @kindex maint print symbol-cache-statistics
19507 @cindex symbol cache, printing usage statistics
19508 @item maint print symbol-cache-statistics
19509 Print symbol cache usage statistics.
19510 This helps determine how well the cache is being utilized.
19511
19512 @kindex maint flush symbol-cache
19513 @kindex maint flush-symbol-cache
19514 @cindex symbol cache, flushing
19515 @item maint flush symbol-cache
19516 @itemx maint flush-symbol-cache
19517 Flush the contents of the symbol cache, all entries are removed. This
19518 command is useful when debugging the symbol cache. It is also useful
19519 when collecting performance data. The command @code{maint
19520 flush-symbol-cache} is deprecated in favor of @code{maint flush
19521 symbol-cache}..
19522
19523 @end table
19524
19525 @node Altering
19526 @chapter Altering Execution
19527
19528 Once you think you have found an error in your program, you might want to
19529 find out for certain whether correcting the apparent error would lead to
19530 correct results in the rest of the run. You can find the answer by
19531 experiment, using the @value{GDBN} features for altering execution of the
19532 program.
19533
19534 For example, you can store new values into variables or memory
19535 locations, give your program a signal, restart it at a different
19536 address, or even return prematurely from a function.
19537
19538 @menu
19539 * Assignment:: Assignment to variables
19540 * Jumping:: Continuing at a different address
19541 * Signaling:: Giving your program a signal
19542 * Returning:: Returning from a function
19543 * Calling:: Calling your program's functions
19544 * Patching:: Patching your program
19545 * Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
19546 @end menu
19547
19548 @node Assignment
19549 @section Assignment to Variables
19550
19551 @cindex assignment
19552 @cindex setting variables
19553 To alter the value of a variable, evaluate an assignment expression.
19554 @xref{Expressions, ,Expressions}. For example,
19555
19556 @smallexample
19557 print x=4
19558 @end smallexample
19559
19560 @noindent
19561 stores the value 4 into the variable @code{x}, and then prints the
19562 value of the assignment expression (which is 4).
19563 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
19564 information on operators in supported languages.
19565
19566 @kindex set variable
19567 @cindex variables, setting
19568 If you are not interested in seeing the value of the assignment, use the
19569 @code{set} command instead of the @code{print} command. @code{set} is
19570 really the same as @code{print} except that the expression's value is
19571 not printed and is not put in the value history (@pxref{Value History,
19572 ,Value History}). The expression is evaluated only for its effects.
19573
19574 If the beginning of the argument string of the @code{set} command
19575 appears identical to a @code{set} subcommand, use the @code{set
19576 variable} command instead of just @code{set}. This command is identical
19577 to @code{set} except for its lack of subcommands. For example, if your
19578 program has a variable @code{width}, you get an error if you try to set
19579 a new value with just @samp{set width=13}, because @value{GDBN} has the
19580 command @code{set width}:
19581
19582 @smallexample
19583 (@value{GDBP}) whatis width
19584 type = double
19585 (@value{GDBP}) p width
19586 $4 = 13
19587 (@value{GDBP}) set width=47
19588 Invalid syntax in expression.
19589 @end smallexample
19590
19591 @noindent
19592 The invalid expression, of course, is @samp{=47}. In
19593 order to actually set the program's variable @code{width}, use
19594
19595 @smallexample
19596 (@value{GDBP}) set var width=47
19597 @end smallexample
19598
19599 Because the @code{set} command has many subcommands that can conflict
19600 with the names of program variables, it is a good idea to use the
19601 @code{set variable} command instead of just @code{set}. For example, if
19602 your program has a variable @code{g}, you run into problems if you try
19603 to set a new value with just @samp{set g=4}, because @value{GDBN} has
19604 the command @code{set gnutarget}, abbreviated @code{set g}:
19605
19606 @smallexample
19607 @group
19608 (@value{GDBP}) whatis g
19609 type = double
19610 (@value{GDBP}) p g
19611 $1 = 1
19612 (@value{GDBP}) set g=4
19613 (@value{GDBP}) p g
19614 $2 = 1
19615 (@value{GDBP}) r
19616 The program being debugged has been started already.
19617 Start it from the beginning? (y or n) y
19618 Starting program: /home/smith/cc_progs/a.out
19619 "/home/smith/cc_progs/a.out": can't open to read symbols:
19620 Invalid bfd target.
19621 (@value{GDBP}) show g
19622 The current BFD target is "=4".
19623 @end group
19624 @end smallexample
19625
19626 @noindent
19627 The program variable @code{g} did not change, and you silently set the
19628 @code{gnutarget} to an invalid value. In order to set the variable
19629 @code{g}, use
19630
19631 @smallexample
19632 (@value{GDBP}) set var g=4
19633 @end smallexample
19634
19635 @value{GDBN} allows more implicit conversions in assignments than C; you can
19636 freely store an integer value into a pointer variable or vice versa,
19637 and you can convert any structure to any other structure that is the
19638 same length or shorter.
19639 @comment FIXME: how do structs align/pad in these conversions?
19640 @comment /doc@cygnus.com 18dec1990
19641
19642 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
19643 construct to generate a value of specified type at a specified address
19644 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
19645 to memory location @code{0x83040} as an integer (which implies a certain size
19646 and representation in memory), and
19647
19648 @smallexample
19649 set @{int@}0x83040 = 4
19650 @end smallexample
19651
19652 @noindent
19653 stores the value 4 into that memory location.
19654
19655 @node Jumping
19656 @section Continuing at a Different Address
19657
19658 Ordinarily, when you continue your program, you do so at the place where
19659 it stopped, with the @code{continue} command. You can instead continue at
19660 an address of your own choosing, with the following commands:
19661
19662 @table @code
19663 @kindex jump
19664 @kindex j @r{(@code{jump})}
19665 @item jump @var{location}
19666 @itemx j @var{location}
19667 Resume execution at @var{location}. Execution stops again immediately
19668 if there is a breakpoint there. @xref{Specify Location}, for a description
19669 of the different forms of @var{location}. It is common
19670 practice to use the @code{tbreak} command in conjunction with
19671 @code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
19672
19673 The @code{jump} command does not change the current stack frame, or
19674 the stack pointer, or the contents of any memory location or any
19675 register other than the program counter. If @var{location} is in
19676 a different function from the one currently executing, the results may
19677 be bizarre if the two functions expect different patterns of arguments or
19678 of local variables. For this reason, the @code{jump} command requests
19679 confirmation if the specified line is not in the function currently
19680 executing. However, even bizarre results are predictable if you are
19681 well acquainted with the machine-language code of your program.
19682 @end table
19683
19684 On many systems, you can get much the same effect as the @code{jump}
19685 command by storing a new value into the register @code{$pc}. The
19686 difference is that this does not start your program running; it only
19687 changes the address of where it @emph{will} run when you continue. For
19688 example,
19689
19690 @smallexample
19691 set $pc = 0x485
19692 @end smallexample
19693
19694 @noindent
19695 makes the next @code{continue} command or stepping command execute at
19696 address @code{0x485}, rather than at the address where your program stopped.
19697 @xref{Continuing and Stepping, ,Continuing and Stepping}.
19698
19699 The most common occasion to use the @code{jump} command is to back
19700 up---perhaps with more breakpoints set---over a portion of a program
19701 that has already executed, in order to examine its execution in more
19702 detail.
19703
19704 @c @group
19705 @node Signaling
19706 @section Giving your Program a Signal
19707 @cindex deliver a signal to a program
19708
19709 @table @code
19710 @kindex signal
19711 @item signal @var{signal}
19712 Resume execution where your program is stopped, but immediately give it the
19713 signal @var{signal}. The @var{signal} can be the name or the number of a
19714 signal. For example, on many systems @code{signal 2} and @code{signal
19715 SIGINT} are both ways of sending an interrupt signal.
19716
19717 Alternatively, if @var{signal} is zero, continue execution without
19718 giving a signal. This is useful when your program stopped on account of
19719 a signal and would ordinarily see the signal when resumed with the
19720 @code{continue} command; @samp{signal 0} causes it to resume without a
19721 signal.
19722
19723 @emph{Note:} When resuming a multi-threaded program, @var{signal} is
19724 delivered to the currently selected thread, not the thread that last
19725 reported a stop. This includes the situation where a thread was
19726 stopped due to a signal. So if you want to continue execution
19727 suppressing the signal that stopped a thread, you should select that
19728 same thread before issuing the @samp{signal 0} command. If you issue
19729 the @samp{signal 0} command with another thread as the selected one,
19730 @value{GDBN} detects that and asks for confirmation.
19731
19732 Invoking the @code{signal} command is not the same as invoking the
19733 @code{kill} utility from the shell. Sending a signal with @code{kill}
19734 causes @value{GDBN} to decide what to do with the signal depending on
19735 the signal handling tables (@pxref{Signals}). The @code{signal} command
19736 passes the signal directly to your program.
19737
19738 @code{signal} does not repeat when you press @key{RET} a second time
19739 after executing the command.
19740
19741 @kindex queue-signal
19742 @item queue-signal @var{signal}
19743 Queue @var{signal} to be delivered immediately to the current thread
19744 when execution of the thread resumes. The @var{signal} can be the name or
19745 the number of a signal. For example, on many systems @code{signal 2} and
19746 @code{signal SIGINT} are both ways of sending an interrupt signal.
19747 The handling of the signal must be set to pass the signal to the program,
19748 otherwise @value{GDBN} will report an error.
19749 You can control the handling of signals from @value{GDBN} with the
19750 @code{handle} command (@pxref{Signals}).
19751
19752 Alternatively, if @var{signal} is zero, any currently queued signal
19753 for the current thread is discarded and when execution resumes no signal
19754 will be delivered. This is useful when your program stopped on account
19755 of a signal and would ordinarily see the signal when resumed with the
19756 @code{continue} command.
19757
19758 This command differs from the @code{signal} command in that the signal
19759 is just queued, execution is not resumed. And @code{queue-signal} cannot
19760 be used to pass a signal whose handling state has been set to @code{nopass}
19761 (@pxref{Signals}).
19762 @end table
19763 @c @end group
19764
19765 @xref{stepping into signal handlers}, for information on how stepping
19766 commands behave when the thread has a signal queued.
19767
19768 @node Returning
19769 @section Returning from a Function
19770
19771 @table @code
19772 @cindex returning from a function
19773 @kindex return
19774 @item return
19775 @itemx return @var{expression}
19776 You can cancel execution of a function call with the @code{return}
19777 command. If you give an
19778 @var{expression} argument, its value is used as the function's return
19779 value.
19780 @end table
19781
19782 When you use @code{return}, @value{GDBN} discards the selected stack frame
19783 (and all frames within it). You can think of this as making the
19784 discarded frame return prematurely. If you wish to specify a value to
19785 be returned, give that value as the argument to @code{return}.
19786
19787 This pops the selected stack frame (@pxref{Selection, ,Selecting a
19788 Frame}), and any other frames inside of it, leaving its caller as the
19789 innermost remaining frame. That frame becomes selected. The
19790 specified value is stored in the registers used for returning values
19791 of functions.
19792
19793 The @code{return} command does not resume execution; it leaves the
19794 program stopped in the state that would exist if the function had just
19795 returned. In contrast, the @code{finish} command (@pxref{Continuing
19796 and Stepping, ,Continuing and Stepping}) resumes execution until the
19797 selected stack frame returns naturally.
19798
19799 @value{GDBN} needs to know how the @var{expression} argument should be set for
19800 the inferior. The concrete registers assignment depends on the OS ABI and the
19801 type being returned by the selected stack frame. For example it is common for
19802 OS ABI to return floating point values in FPU registers while integer values in
19803 CPU registers. Still some ABIs return even floating point values in CPU
19804 registers. Larger integer widths (such as @code{long long int}) also have
19805 specific placement rules. @value{GDBN} already knows the OS ABI from its
19806 current target so it needs to find out also the type being returned to make the
19807 assignment into the right register(s).
19808
19809 Normally, the selected stack frame has debug info. @value{GDBN} will always
19810 use the debug info instead of the implicit type of @var{expression} when the
19811 debug info is available. For example, if you type @kbd{return -1}, and the
19812 function in the current stack frame is declared to return a @code{long long
19813 int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
19814 into a @code{long long int}:
19815
19816 @smallexample
19817 Breakpoint 1, func () at gdb.base/return-nodebug.c:29
19818 29 return 31;
19819 (@value{GDBP}) return -1
19820 Make func return now? (y or n) y
19821 #0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
19822 43 printf ("result=%lld\n", func ());
19823 (@value{GDBP})
19824 @end smallexample
19825
19826 However, if the selected stack frame does not have a debug info, e.g., if the
19827 function was compiled without debug info, @value{GDBN} has to find out the type
19828 to return from user. Specifying a different type by mistake may set the value
19829 in different inferior registers than the caller code expects. For example,
19830 typing @kbd{return -1} with its implicit type @code{int} would set only a part
19831 of a @code{long long int} result for a debug info less function (on 32-bit
19832 architectures). Therefore the user is required to specify the return type by
19833 an appropriate cast explicitly:
19834
19835 @smallexample
19836 Breakpoint 2, 0x0040050b in func ()
19837 (@value{GDBP}) return -1
19838 Return value type not available for selected stack frame.
19839 Please use an explicit cast of the value to return.
19840 (@value{GDBP}) return (long long int) -1
19841 Make selected stack frame return now? (y or n) y
19842 #0 0x00400526 in main ()
19843 (@value{GDBP})
19844 @end smallexample
19845
19846 @node Calling
19847 @section Calling Program Functions
19848
19849 @table @code
19850 @cindex calling functions
19851 @cindex inferior functions, calling
19852 @item print @var{expr}
19853 Evaluate the expression @var{expr} and display the resulting value.
19854 The expression may include calls to functions in the program being
19855 debugged.
19856
19857 @kindex call
19858 @item call @var{expr}
19859 Evaluate the expression @var{expr} without displaying @code{void}
19860 returned values.
19861
19862 You can use this variant of the @code{print} command if you want to
19863 execute a function from your program that does not return anything
19864 (a.k.a.@: @dfn{a void function}), but without cluttering the output
19865 with @code{void} returned values that @value{GDBN} will otherwise
19866 print. If the result is not void, it is printed and saved in the
19867 value history.
19868 @end table
19869
19870 It is possible for the function you call via the @code{print} or
19871 @code{call} command to generate a signal (e.g., if there's a bug in
19872 the function, or if you passed it incorrect arguments). What happens
19873 in that case is controlled by the @code{set unwindonsignal} command.
19874
19875 Similarly, with a C@t{++} program it is possible for the function you
19876 call via the @code{print} or @code{call} command to generate an
19877 exception that is not handled due to the constraints of the dummy
19878 frame. In this case, any exception that is raised in the frame, but has
19879 an out-of-frame exception handler will not be found. GDB builds a
19880 dummy-frame for the inferior function call, and the unwinder cannot
19881 seek for exception handlers outside of this dummy-frame. What happens
19882 in that case is controlled by the
19883 @code{set unwind-on-terminating-exception} command.
19884
19885 @table @code
19886 @item set unwindonsignal
19887 @kindex set unwindonsignal
19888 @cindex unwind stack in called functions
19889 @cindex call dummy stack unwinding
19890 Set unwinding of the stack if a signal is received while in a function
19891 that @value{GDBN} called in the program being debugged. If set to on,
19892 @value{GDBN} unwinds the stack it created for the call and restores
19893 the context to what it was before the call. If set to off (the
19894 default), @value{GDBN} stops in the frame where the signal was
19895 received.
19896
19897 @item show unwindonsignal
19898 @kindex show unwindonsignal
19899 Show the current setting of stack unwinding in the functions called by
19900 @value{GDBN}.
19901
19902 @item set unwind-on-terminating-exception
19903 @kindex set unwind-on-terminating-exception
19904 @cindex unwind stack in called functions with unhandled exceptions
19905 @cindex call dummy stack unwinding on unhandled exception.
19906 Set unwinding of the stack if a C@t{++} exception is raised, but left
19907 unhandled while in a function that @value{GDBN} called in the program being
19908 debugged. If set to on (the default), @value{GDBN} unwinds the stack
19909 it created for the call and restores the context to what it was before
19910 the call. If set to off, @value{GDBN} the exception is delivered to
19911 the default C@t{++} exception handler and the inferior terminated.
19912
19913 @item show unwind-on-terminating-exception
19914 @kindex show unwind-on-terminating-exception
19915 Show the current setting of stack unwinding in the functions called by
19916 @value{GDBN}.
19917
19918 @item set may-call-functions
19919 @kindex set may-call-functions
19920 @cindex disabling calling functions in the program
19921 @cindex calling functions in the program, disabling
19922 Set permission to call functions in the program.
19923 This controls whether @value{GDBN} will attempt to call functions in
19924 the program, such as with expressions in the @code{print} command. It
19925 defaults to @code{on}.
19926
19927 To call a function in the program, @value{GDBN} has to temporarily
19928 modify the state of the inferior. This has potentially undesired side
19929 effects. Also, having @value{GDBN} call nested functions is likely to
19930 be erroneous and may even crash the program being debugged. You can
19931 avoid such hazards by forbidding @value{GDBN} from calling functions
19932 in the program being debugged. If calling functions in the program
19933 is forbidden, GDB will throw an error when a command (such as printing
19934 an expression) starts a function call in the program.
19935
19936 @item show may-call-functions
19937 @kindex show may-call-functions
19938 Show permission to call functions in the program.
19939
19940 @end table
19941
19942 @subsection Calling functions with no debug info
19943
19944 @cindex no debug info functions
19945 Sometimes, a function you wish to call is missing debug information.
19946 In such case, @value{GDBN} does not know the type of the function,
19947 including the types of the function's parameters. To avoid calling
19948 the inferior function incorrectly, which could result in the called
19949 function functioning erroneously and even crash, @value{GDBN} refuses
19950 to call the function unless you tell it the type of the function.
19951
19952 For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
19953 to do that. The simplest is to cast the call to the function's
19954 declared return type. For example:
19955
19956 @smallexample
19957 (@value{GDBP}) p getenv ("PATH")
19958 'getenv' has unknown return type; cast the call to its declared return type
19959 (@value{GDBP}) p (char *) getenv ("PATH")
19960 $1 = 0x7fffffffe7ba "/usr/local/bin:/"...
19961 @end smallexample
19962
19963 Casting the return type of a no-debug function is equivalent to
19964 casting the function to a pointer to a prototyped function that has a
19965 prototype that matches the types of the passed-in arguments, and
19966 calling that. I.e., the call above is equivalent to:
19967
19968 @smallexample
19969 (@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
19970 @end smallexample
19971
19972 @noindent
19973 and given this prototyped C or C++ function with float parameters:
19974
19975 @smallexample
19976 float multiply (float v1, float v2) @{ return v1 * v2; @}
19977 @end smallexample
19978
19979 @noindent
19980 these calls are equivalent:
19981
19982 @smallexample
19983 (@value{GDBP}) p (float) multiply (2.0f, 3.0f)
19984 (@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
19985 @end smallexample
19986
19987 If the function you wish to call is declared as unprototyped (i.e.@:
19988 old K&R style), you must use the cast-to-function-pointer syntax, so
19989 that @value{GDBN} knows that it needs to apply default argument
19990 promotions (promote float arguments to double). @xref{ABI, float
19991 promotion}. For example, given this unprototyped C function with
19992 float parameters, and no debug info:
19993
19994 @smallexample
19995 float
19996 multiply_noproto (v1, v2)
19997 float v1, v2;
19998 @{
19999 return v1 * v2;
20000 @}
20001 @end smallexample
20002
20003 @noindent
20004 you call it like this:
20005
20006 @smallexample
20007 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
20008 @end smallexample
20009
20010 @node Patching
20011 @section Patching Programs
20012
20013 @cindex patching binaries
20014 @cindex writing into executables
20015 @cindex writing into corefiles
20016
20017 By default, @value{GDBN} opens the file containing your program's
20018 executable code (or the corefile) read-only. This prevents accidental
20019 alterations to machine code; but it also prevents you from intentionally
20020 patching your program's binary.
20021
20022 If you'd like to be able to patch the binary, you can specify that
20023 explicitly with the @code{set write} command. For example, you might
20024 want to turn on internal debugging flags, or even to make emergency
20025 repairs.
20026
20027 @table @code
20028 @kindex set write
20029 @item set write on
20030 @itemx set write off
20031 If you specify @samp{set write on}, @value{GDBN} opens executable and
20032 core files for both reading and writing; if you specify @kbd{set write
20033 off} (the default), @value{GDBN} opens them read-only.
20034
20035 If you have already loaded a file, you must load it again (using the
20036 @code{exec-file} or @code{core-file} command) after changing @code{set
20037 write}, for your new setting to take effect.
20038
20039 @item show write
20040 @kindex show write
20041 Display whether executable files and core files are opened for writing
20042 as well as reading.
20043 @end table
20044
20045 @node Compiling and Injecting Code
20046 @section Compiling and injecting code in @value{GDBN}
20047 @cindex injecting code
20048 @cindex writing into executables
20049 @cindex compiling code
20050
20051 @value{GDBN} supports on-demand compilation and code injection into
20052 programs running under @value{GDBN}. GCC 5.0 or higher built with
20053 @file{libcc1.so} must be installed for this functionality to be enabled.
20054 This functionality is implemented with the following commands.
20055
20056 @table @code
20057 @kindex compile code
20058 @item compile code @var{source-code}
20059 @itemx compile code -raw @var{--} @var{source-code}
20060 Compile @var{source-code} with the compiler language found as the current
20061 language in @value{GDBN} (@pxref{Languages}). If compilation and
20062 injection is not supported with the current language specified in
20063 @value{GDBN}, or the compiler does not support this feature, an error
20064 message will be printed. If @var{source-code} compiles and links
20065 successfully, @value{GDBN} will load the object-code emitted,
20066 and execute it within the context of the currently selected inferior.
20067 It is important to note that the compiled code is executed immediately.
20068 After execution, the compiled code is removed from @value{GDBN} and any
20069 new types or variables you have defined will be deleted.
20070
20071 The command allows you to specify @var{source-code} in two ways.
20072 The simplest method is to provide a single line of code to the command.
20073 E.g.:
20074
20075 @smallexample
20076 compile code printf ("hello world\n");
20077 @end smallexample
20078
20079 If you specify options on the command line as well as source code, they
20080 may conflict. The @samp{--} delimiter can be used to separate options
20081 from actual source code. E.g.:
20082
20083 @smallexample
20084 compile code -r -- printf ("hello world\n");
20085 @end smallexample
20086
20087 Alternatively you can enter source code as multiple lines of text. To
20088 enter this mode, invoke the @samp{compile code} command without any text
20089 following the command. This will start the multiple-line editor and
20090 allow you to type as many lines of source code as required. When you
20091 have completed typing, enter @samp{end} on its own line to exit the
20092 editor.
20093
20094 @smallexample
20095 compile code
20096 >printf ("hello\n");
20097 >printf ("world\n");
20098 >end
20099 @end smallexample
20100
20101 Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
20102 provided @var{source-code} in a callable scope. In this case, you must
20103 specify the entry point of the code by defining a function named
20104 @code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
20105 inferior. Using @samp{-raw} option may be needed for example when
20106 @var{source-code} requires @samp{#include} lines which may conflict with
20107 inferior symbols otherwise.
20108
20109 @kindex compile file
20110 @item compile file @var{filename}
20111 @itemx compile file -raw @var{filename}
20112 Like @code{compile code}, but take the source code from @var{filename}.
20113
20114 @smallexample
20115 compile file /home/user/example.c
20116 @end smallexample
20117 @end table
20118
20119 @table @code
20120 @item compile print [[@var{options}] --] @var{expr}
20121 @itemx compile print [[@var{options}] --] /@var{f} @var{expr}
20122 Compile and execute @var{expr} with the compiler language found as the
20123 current language in @value{GDBN} (@pxref{Languages}). By default the
20124 value of @var{expr} is printed in a format appropriate to its data type;
20125 you can choose a different format by specifying @samp{/@var{f}}, where
20126 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
20127 Formats}. The @code{compile print} command accepts the same options
20128 as the @code{print} command; see @ref{print options}.
20129
20130 @item compile print [[@var{options}] --]
20131 @itemx compile print [[@var{options}] --] /@var{f}
20132 @cindex reprint the last value
20133 Alternatively you can enter the expression (source code producing it) as
20134 multiple lines of text. To enter this mode, invoke the @samp{compile print}
20135 command without any text following the command. This will start the
20136 multiple-line editor.
20137 @end table
20138
20139 @noindent
20140 The process of compiling and injecting the code can be inspected using:
20141
20142 @table @code
20143 @anchor{set debug compile}
20144 @item set debug compile
20145 @cindex compile command debugging info
20146 Turns on or off display of @value{GDBN} process of compiling and
20147 injecting the code. The default is off.
20148
20149 @item show debug compile
20150 Displays the current state of displaying @value{GDBN} process of
20151 compiling and injecting the code.
20152
20153 @anchor{set debug compile-cplus-types}
20154 @item set debug compile-cplus-types
20155 @cindex compile C@t{++} type conversion
20156 Turns on or off the display of C@t{++} type conversion debugging information.
20157 The default is off.
20158
20159 @item show debug compile-cplus-types
20160 Displays the current state of displaying debugging information for
20161 C@t{++} type conversion.
20162 @end table
20163
20164 @subsection Compilation options for the @code{compile} command
20165
20166 @value{GDBN} needs to specify the right compilation options for the code
20167 to be injected, in part to make its ABI compatible with the inferior
20168 and in part to make the injected code compatible with @value{GDBN}'s
20169 injecting process.
20170
20171 @noindent
20172 The options used, in increasing precedence:
20173
20174 @table @asis
20175 @item target architecture and OS options (@code{gdbarch})
20176 These options depend on target processor type and target operating
20177 system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
20178 (@code{-m64}) compilation option.
20179
20180 @item compilation options recorded in the target
20181 @value{NGCC} (since version 4.7) stores the options used for compilation
20182 into @code{DW_AT_producer} part of DWARF debugging information according
20183 to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
20184 explicitly specify @code{-g} during inferior compilation otherwise
20185 @value{NGCC} produces no DWARF. This feature is only relevant for
20186 platforms where @code{-g} produces DWARF by default, otherwise one may
20187 try to enforce DWARF by using @code{-gdwarf-4}.
20188
20189 @item compilation options set by @code{set compile-args}
20190 @end table
20191
20192 @noindent
20193 You can override compilation options using the following command:
20194
20195 @table @code
20196 @item set compile-args
20197 @cindex compile command options override
20198 Set compilation options used for compiling and injecting code with the
20199 @code{compile} commands. These options override any conflicting ones
20200 from the target architecture and/or options stored during inferior
20201 compilation.
20202
20203 @item show compile-args
20204 Displays the current state of compilation options override.
20205 This does not show all the options actually used during compilation,
20206 use @ref{set debug compile} for that.
20207 @end table
20208
20209 @subsection Caveats when using the @code{compile} command
20210
20211 There are a few caveats to keep in mind when using the @code{compile}
20212 command. As the caveats are different per language, the table below
20213 highlights specific issues on a per language basis.
20214
20215 @table @asis
20216 @item C code examples and caveats
20217 When the language in @value{GDBN} is set to @samp{C}, the compiler will
20218 attempt to compile the source code with a @samp{C} compiler. The source
20219 code provided to the @code{compile} command will have much the same
20220 access to variables and types as it normally would if it were part of
20221 the program currently being debugged in @value{GDBN}.
20222
20223 Below is a sample program that forms the basis of the examples that
20224 follow. This program has been compiled and loaded into @value{GDBN},
20225 much like any other normal debugging session.
20226
20227 @smallexample
20228 void function1 (void)
20229 @{
20230 int i = 42;
20231 printf ("function 1\n");
20232 @}
20233
20234 void function2 (void)
20235 @{
20236 int j = 12;
20237 function1 ();
20238 @}
20239
20240 int main(void)
20241 @{
20242 int k = 6;
20243 int *p;
20244 function2 ();
20245 return 0;
20246 @}
20247 @end smallexample
20248
20249 For the purposes of the examples in this section, the program above has
20250 been compiled, loaded into @value{GDBN}, stopped at the function
20251 @code{main}, and @value{GDBN} is awaiting input from the user.
20252
20253 To access variables and types for any program in @value{GDBN}, the
20254 program must be compiled and packaged with debug information. The
20255 @code{compile} command is not an exception to this rule. Without debug
20256 information, you can still use the @code{compile} command, but you will
20257 be very limited in what variables and types you can access.
20258
20259 So with that in mind, the example above has been compiled with debug
20260 information enabled. The @code{compile} command will have access to
20261 all variables and types (except those that may have been optimized
20262 out). Currently, as @value{GDBN} has stopped the program in the
20263 @code{main} function, the @code{compile} command would have access to
20264 the variable @code{k}. You could invoke the @code{compile} command
20265 and type some source code to set the value of @code{k}. You can also
20266 read it, or do anything with that variable you would normally do in
20267 @code{C}. Be aware that changes to inferior variables in the
20268 @code{compile} command are persistent. In the following example:
20269
20270 @smallexample
20271 compile code k = 3;
20272 @end smallexample
20273
20274 @noindent
20275 the variable @code{k} is now 3. It will retain that value until
20276 something else in the example program changes it, or another
20277 @code{compile} command changes it.
20278
20279 Normal scope and access rules apply to source code compiled and
20280 injected by the @code{compile} command. In the example, the variables
20281 @code{j} and @code{k} are not accessible yet, because the program is
20282 currently stopped in the @code{main} function, where these variables
20283 are not in scope. Therefore, the following command
20284
20285 @smallexample
20286 compile code j = 3;
20287 @end smallexample
20288
20289 @noindent
20290 will result in a compilation error message.
20291
20292 Once the program is continued, execution will bring these variables in
20293 scope, and they will become accessible; then the code you specify via
20294 the @code{compile} command will be able to access them.
20295
20296 You can create variables and types with the @code{compile} command as
20297 part of your source code. Variables and types that are created as part
20298 of the @code{compile} command are not visible to the rest of the program for
20299 the duration of its run. This example is valid:
20300
20301 @smallexample
20302 compile code int ff = 5; printf ("ff is %d\n", ff);
20303 @end smallexample
20304
20305 However, if you were to type the following into @value{GDBN} after that
20306 command has completed:
20307
20308 @smallexample
20309 compile code printf ("ff is %d\n'', ff);
20310 @end smallexample
20311
20312 @noindent
20313 a compiler error would be raised as the variable @code{ff} no longer
20314 exists. Object code generated and injected by the @code{compile}
20315 command is removed when its execution ends. Caution is advised
20316 when assigning to program variables values of variables created by the
20317 code submitted to the @code{compile} command. This example is valid:
20318
20319 @smallexample
20320 compile code int ff = 5; k = ff;
20321 @end smallexample
20322
20323 The value of the variable @code{ff} is assigned to @code{k}. The variable
20324 @code{k} does not require the existence of @code{ff} to maintain the value
20325 it has been assigned. However, pointers require particular care in
20326 assignment. If the source code compiled with the @code{compile} command
20327 changed the address of a pointer in the example program, perhaps to a
20328 variable created in the @code{compile} command, that pointer would point
20329 to an invalid location when the command exits. The following example
20330 would likely cause issues with your debugged program:
20331
20332 @smallexample
20333 compile code int ff = 5; p = &ff;
20334 @end smallexample
20335
20336 In this example, @code{p} would point to @code{ff} when the
20337 @code{compile} command is executing the source code provided to it.
20338 However, as variables in the (example) program persist with their
20339 assigned values, the variable @code{p} would point to an invalid
20340 location when the command exists. A general rule should be followed
20341 in that you should either assign @code{NULL} to any assigned pointers,
20342 or restore a valid location to the pointer before the command exits.
20343
20344 Similar caution must be exercised with any structs, unions, and typedefs
20345 defined in @code{compile} command. Types defined in the @code{compile}
20346 command will no longer be available in the next @code{compile} command.
20347 Therefore, if you cast a variable to a type defined in the
20348 @code{compile} command, care must be taken to ensure that any future
20349 need to resolve the type can be achieved.
20350
20351 @smallexample
20352 (gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20353 (gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20354 gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20355 Compilation failed.
20356 (gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
20357 42
20358 @end smallexample
20359
20360 Variables that have been optimized away by the compiler are not
20361 accessible to the code submitted to the @code{compile} command.
20362 Access to those variables will generate a compiler error which @value{GDBN}
20363 will print to the console.
20364 @end table
20365
20366 @subsection Compiler search for the @code{compile} command
20367
20368 @value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20369 which may not be obvious for remote targets of different architecture
20370 than where @value{GDBN} is running. Environment variable @code{PATH} on
20371 @value{GDBN} host is searched for @value{NGCC} binary matching the
20372 target architecture and operating system. This search can be overriden
20373 by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is
20374 taken from shell that executed @value{GDBN}, it is not the value set by
20375 @value{GDBN} command @code{set environment}). @xref{Environment}.
20376
20377
20378 Specifically @code{PATH} is searched for binaries matching regular expression
20379 @code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20380 debugged. @var{arch} is processor name --- multiarch is supported, so for
20381 example both @code{i386} and @code{x86_64} targets look for pattern
20382 @code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
20383 for pattern @code{s390x?}. @var{os} is currently supported only for
20384 pattern @code{linux(-gnu)?}.
20385
20386 On Posix hosts the compiler driver @value{GDBN} needs to find also
20387 shared library @file{libcc1.so} from the compiler. It is searched in
20388 default shared library search path (overridable with usual environment
20389 variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
20390 compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
20391 according to the installation of the found compiler --- as possibly
20392 specified by the @code{set compile-gcc} command.
20393
20394 @table @code
20395 @item set compile-gcc
20396 @cindex compile command driver filename override
20397 Set compilation command used for compiling and injecting code with the
20398 @code{compile} commands. If this option is not set (it is set to
20399 an empty string), the search described above will occur --- that is the
20400 default.
20401
20402 @item show compile-gcc
20403 Displays the current compile command @value{NGCC} driver filename.
20404 If set, it is the main command @command{gcc}, found usually for example
20405 under name @file{x86_64-linux-gnu-gcc}.
20406 @end table
20407
20408 @node GDB Files
20409 @chapter @value{GDBN} Files
20410
20411 @value{GDBN} needs to know the file name of the program to be debugged,
20412 both in order to read its symbol table and in order to start your
20413 program. To debug a core dump of a previous run, you must also tell
20414 @value{GDBN} the name of the core dump file.
20415
20416 @menu
20417 * Files:: Commands to specify files
20418 * File Caching:: Information about @value{GDBN}'s file caching
20419 * Separate Debug Files:: Debugging information in separate files
20420 * MiniDebugInfo:: Debugging information in a special section
20421 * Index Files:: Index files speed up GDB
20422 * Symbol Errors:: Errors reading symbol files
20423 * Data Files:: GDB data files
20424 @end menu
20425
20426 @node Files
20427 @section Commands to Specify Files
20428
20429 @cindex symbol table
20430 @cindex core dump file
20431
20432 You may want to specify executable and core dump file names. The usual
20433 way to do this is at start-up time, using the arguments to
20434 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
20435 Out of @value{GDBN}}).
20436
20437 Occasionally it is necessary to change to a different file during a
20438 @value{GDBN} session. Or you may run @value{GDBN} and forget to
20439 specify a file you want to use. Or you are debugging a remote target
20440 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
20441 Program}). In these situations the @value{GDBN} commands to specify
20442 new files are useful.
20443
20444 @table @code
20445 @cindex executable file
20446 @kindex file
20447 @item file @var{filename}
20448 Use @var{filename} as the program to be debugged. It is read for its
20449 symbols and for the contents of pure memory. It is also the program
20450 executed when you use the @code{run} command. If you do not specify a
20451 directory and the file is not found in the @value{GDBN} working directory,
20452 @value{GDBN} uses the environment variable @code{PATH} as a list of
20453 directories to search, just as the shell does when looking for a program
20454 to run. You can change the value of this variable, for both @value{GDBN}
20455 and your program, using the @code{path} command.
20456
20457 @cindex unlinked object files
20458 @cindex patching object files
20459 You can load unlinked object @file{.o} files into @value{GDBN} using
20460 the @code{file} command. You will not be able to ``run'' an object
20461 file, but you can disassemble functions and inspect variables. Also,
20462 if the underlying BFD functionality supports it, you could use
20463 @kbd{gdb -write} to patch object files using this technique. Note
20464 that @value{GDBN} can neither interpret nor modify relocations in this
20465 case, so branches and some initialized variables will appear to go to
20466 the wrong place. But this feature is still handy from time to time.
20467
20468 @item file
20469 @code{file} with no argument makes @value{GDBN} discard any information it
20470 has on both executable file and the symbol table.
20471
20472 @kindex exec-file
20473 @item exec-file @r{[} @var{filename} @r{]}
20474 Specify that the program to be run (but not the symbol table) is found
20475 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
20476 if necessary to locate your program. Omitting @var{filename} means to
20477 discard information on the executable file.
20478
20479 @kindex symbol-file
20480 @item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
20481 Read symbol table information from file @var{filename}. @code{PATH} is
20482 searched when necessary. Use the @code{file} command to get both symbol
20483 table and program to run from the same file.
20484
20485 If an optional @var{offset} is specified, it is added to the start
20486 address of each section in the symbol file. This is useful if the
20487 program is relocated at runtime, such as the Linux kernel with kASLR
20488 enabled.
20489
20490 @code{symbol-file} with no argument clears out @value{GDBN} information on your
20491 program's symbol table.
20492
20493 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
20494 some breakpoints and auto-display expressions. This is because they may
20495 contain pointers to the internal data recording symbols and data types,
20496 which are part of the old symbol table data being discarded inside
20497 @value{GDBN}.
20498
20499 @code{symbol-file} does not repeat if you press @key{RET} again after
20500 executing it once.
20501
20502 When @value{GDBN} is configured for a particular environment, it
20503 understands debugging information in whatever format is the standard
20504 generated for that environment; you may use either a @sc{gnu} compiler, or
20505 other compilers that adhere to the local conventions.
20506 Best results are usually obtained from @sc{gnu} compilers; for example,
20507 using @code{@value{NGCC}} you can generate debugging information for
20508 optimized code.
20509
20510 For most kinds of object files, with the exception of old SVR3 systems
20511 using COFF, the @code{symbol-file} command does not normally read the
20512 symbol table in full right away. Instead, it scans the symbol table
20513 quickly to find which source files and which symbols are present. The
20514 details are read later, one source file at a time, as they are needed.
20515
20516 The purpose of this two-stage reading strategy is to make @value{GDBN}
20517 start up faster. For the most part, it is invisible except for
20518 occasional pauses while the symbol table details for a particular source
20519 file are being read. (The @code{set verbose} command can turn these
20520 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
20521 Warnings and Messages}.)
20522
20523 We have not implemented the two-stage strategy for COFF yet. When the
20524 symbol table is stored in COFF format, @code{symbol-file} reads the
20525 symbol table data in full right away. Note that ``stabs-in-COFF''
20526 still does the two-stage strategy, since the debug info is actually
20527 in stabs format.
20528
20529 @kindex readnow
20530 @cindex reading symbols immediately
20531 @cindex symbols, reading immediately
20532 @item symbol-file @r{[} -readnow @r{]} @var{filename}
20533 @itemx file @r{[} -readnow @r{]} @var{filename}
20534 You can override the @value{GDBN} two-stage strategy for reading symbol
20535 tables by using the @samp{-readnow} option with any of the commands that
20536 load symbol table information, if you want to be sure @value{GDBN} has the
20537 entire symbol table available.
20538
20539 @cindex @code{-readnever}, option for symbol-file command
20540 @cindex never read symbols
20541 @cindex symbols, never read
20542 @item symbol-file @r{[} -readnever @r{]} @var{filename}
20543 @itemx file @r{[} -readnever @r{]} @var{filename}
20544 You can instruct @value{GDBN} to never read the symbolic information
20545 contained in @var{filename} by using the @samp{-readnever} option.
20546 @xref{--readnever}.
20547
20548 @c FIXME: for now no mention of directories, since this seems to be in
20549 @c flux. 13mar1992 status is that in theory GDB would look either in
20550 @c current dir or in same dir as myprog; but issues like competing
20551 @c GDB's, or clutter in system dirs, mean that in practice right now
20552 @c only current dir is used. FFish says maybe a special GDB hierarchy
20553 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
20554 @c files.
20555
20556 @kindex core-file
20557 @item core-file @r{[}@var{filename}@r{]}
20558 @itemx core
20559 Specify the whereabouts of a core dump file to be used as the ``contents
20560 of memory''. Traditionally, core files contain only some parts of the
20561 address space of the process that generated them; @value{GDBN} can access the
20562 executable file itself for other parts.
20563
20564 @code{core-file} with no argument specifies that no core file is
20565 to be used.
20566
20567 Note that the core file is ignored when your program is actually running
20568 under @value{GDBN}. So, if you have been running your program and you
20569 wish to debug a core file instead, you must kill the subprocess in which
20570 the program is running. To do this, use the @code{kill} command
20571 (@pxref{Kill Process, ,Killing the Child Process}).
20572
20573 @kindex add-symbol-file
20574 @cindex dynamic linking
20575 @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{]}
20576 The @code{add-symbol-file} command reads additional symbol table
20577 information from the file @var{filename}. You would use this command
20578 when @var{filename} has been dynamically loaded (by some other means)
20579 into the program that is running. The @var{textaddress} parameter gives
20580 the memory address at which the file's text section has been loaded.
20581 You can additionally specify the base address of other sections using
20582 an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
20583 If a section is omitted, @value{GDBN} will use its default addresses
20584 as found in @var{filename}. Any @var{address} or @var{textaddress}
20585 can be given as an expression.
20586
20587 If an optional @var{offset} is specified, it is added to the start
20588 address of each section, except those for which the address was
20589 specified explicitly.
20590
20591 The symbol table of the file @var{filename} is added to the symbol table
20592 originally read with the @code{symbol-file} command. You can use the
20593 @code{add-symbol-file} command any number of times; the new symbol data
20594 thus read is kept in addition to the old.
20595
20596 Changes can be reverted using the command @code{remove-symbol-file}.
20597
20598 @cindex relocatable object files, reading symbols from
20599 @cindex object files, relocatable, reading symbols from
20600 @cindex reading symbols from relocatable object files
20601 @cindex symbols, reading from relocatable object files
20602 @cindex @file{.o} files, reading symbols from
20603 Although @var{filename} is typically a shared library file, an
20604 executable file, or some other object file which has been fully
20605 relocated for loading into a process, you can also load symbolic
20606 information from relocatable @file{.o} files, as long as:
20607
20608 @itemize @bullet
20609 @item
20610 the file's symbolic information refers only to linker symbols defined in
20611 that file, not to symbols defined by other object files,
20612 @item
20613 every section the file's symbolic information refers to has actually
20614 been loaded into the inferior, as it appears in the file, and
20615 @item
20616 you can determine the address at which every section was loaded, and
20617 provide these to the @code{add-symbol-file} command.
20618 @end itemize
20619
20620 @noindent
20621 Some embedded operating systems, like Sun Chorus and VxWorks, can load
20622 relocatable files into an already running program; such systems
20623 typically make the requirements above easy to meet. However, it's
20624 important to recognize that many native systems use complex link
20625 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
20626 assembly, for example) that make the requirements difficult to meet. In
20627 general, one cannot assume that using @code{add-symbol-file} to read a
20628 relocatable object file's symbolic information will have the same effect
20629 as linking the relocatable object file into the program in the normal
20630 way.
20631
20632 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
20633
20634 @kindex remove-symbol-file
20635 @item remove-symbol-file @var{filename}
20636 @item remove-symbol-file -a @var{address}
20637 Remove a symbol file added via the @code{add-symbol-file} command. The
20638 file to remove can be identified by its @var{filename} or by an @var{address}
20639 that lies within the boundaries of this symbol file in memory. Example:
20640
20641 @smallexample
20642 (gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
20643 add symbol table from file "/home/user/gdb/mylib.so" at
20644 .text_addr = 0x7ffff7ff9480
20645 (y or n) y
20646 Reading symbols from /home/user/gdb/mylib.so...
20647 (gdb) remove-symbol-file -a 0x7ffff7ff9480
20648 Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
20649 (gdb)
20650 @end smallexample
20651
20652
20653 @code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
20654
20655 @kindex add-symbol-file-from-memory
20656 @cindex @code{syscall DSO}
20657 @cindex load symbols from memory
20658 @item add-symbol-file-from-memory @var{address}
20659 Load symbols from the given @var{address} in a dynamically loaded
20660 object file whose image is mapped directly into the inferior's memory.
20661 For example, the Linux kernel maps a @code{syscall DSO} into each
20662 process's address space; this DSO provides kernel-specific code for
20663 some system calls. The argument can be any expression whose
20664 evaluation yields the address of the file's shared object file header.
20665 For this command to work, you must have used @code{symbol-file} or
20666 @code{exec-file} commands in advance.
20667
20668 @kindex section
20669 @item section @var{section} @var{addr}
20670 The @code{section} command changes the base address of the named
20671 @var{section} of the exec file to @var{addr}. This can be used if the
20672 exec file does not contain section addresses, (such as in the
20673 @code{a.out} format), or when the addresses specified in the file
20674 itself are wrong. Each section must be changed separately. The
20675 @code{info files} command, described below, lists all the sections and
20676 their addresses.
20677
20678 @kindex info files
20679 @kindex info target
20680 @item info files
20681 @itemx info target
20682 @code{info files} and @code{info target} are synonymous; both print the
20683 current target (@pxref{Targets, ,Specifying a Debugging Target}),
20684 including the names of the executable and core dump files currently in
20685 use by @value{GDBN}, and the files from which symbols were loaded. The
20686 command @code{help target} lists all possible targets rather than
20687 current ones.
20688
20689 @kindex maint info sections
20690 @item maint info sections
20691 Another command that can give you extra information about program sections
20692 is @code{maint info sections}. In addition to the section information
20693 displayed by @code{info files}, this command displays the flags and file
20694 offset of each section in the executable and core dump files. In addition,
20695 @code{maint info sections} provides the following command options (which
20696 may be arbitrarily combined):
20697
20698 @table @code
20699 @item ALLOBJ
20700 Display sections for all loaded object files, including shared libraries.
20701 @item @var{sections}
20702 Display info only for named @var{sections}.
20703 @item @var{section-flags}
20704 Display info only for sections for which @var{section-flags} are true.
20705 The section flags that @value{GDBN} currently knows about are:
20706 @table @code
20707 @item ALLOC
20708 Section will have space allocated in the process when loaded.
20709 Set for all sections except those containing debug information.
20710 @item LOAD
20711 Section will be loaded from the file into the child process memory.
20712 Set for pre-initialized code and data, clear for @code{.bss} sections.
20713 @item RELOC
20714 Section needs to be relocated before loading.
20715 @item READONLY
20716 Section cannot be modified by the child process.
20717 @item CODE
20718 Section contains executable code only.
20719 @item DATA
20720 Section contains data only (no executable code).
20721 @item ROM
20722 Section will reside in ROM.
20723 @item CONSTRUCTOR
20724 Section contains data for constructor/destructor lists.
20725 @item HAS_CONTENTS
20726 Section is not empty.
20727 @item NEVER_LOAD
20728 An instruction to the linker to not output the section.
20729 @item COFF_SHARED_LIBRARY
20730 A notification to the linker that the section contains
20731 COFF shared library information.
20732 @item IS_COMMON
20733 Section contains common symbols.
20734 @end table
20735 @end table
20736 @kindex set trust-readonly-sections
20737 @cindex read-only sections
20738 @item set trust-readonly-sections on
20739 Tell @value{GDBN} that readonly sections in your object file
20740 really are read-only (i.e.@: that their contents will not change).
20741 In that case, @value{GDBN} can fetch values from these sections
20742 out of the object file, rather than from the target program.
20743 For some targets (notably embedded ones), this can be a significant
20744 enhancement to debugging performance.
20745
20746 The default is off.
20747
20748 @item set trust-readonly-sections off
20749 Tell @value{GDBN} not to trust readonly sections. This means that
20750 the contents of the section might change while the program is running,
20751 and must therefore be fetched from the target when needed.
20752
20753 @item show trust-readonly-sections
20754 Show the current setting of trusting readonly sections.
20755 @end table
20756
20757 All file-specifying commands allow both absolute and relative file names
20758 as arguments. @value{GDBN} always converts the file name to an absolute file
20759 name and remembers it that way.
20760
20761 @cindex shared libraries
20762 @anchor{Shared Libraries}
20763 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
20764 Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
20765 DSBT (TIC6X) shared libraries.
20766
20767 On MS-Windows @value{GDBN} must be linked with the Expat library to support
20768 shared libraries. @xref{Expat}.
20769
20770 @value{GDBN} automatically loads symbol definitions from shared libraries
20771 when you use the @code{run} command, or when you examine a core file.
20772 (Before you issue the @code{run} command, @value{GDBN} does not understand
20773 references to a function in a shared library, however---unless you are
20774 debugging a core file).
20775
20776 @c FIXME: some @value{GDBN} release may permit some refs to undef
20777 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
20778 @c FIXME...lib; check this from time to time when updating manual
20779
20780 There are times, however, when you may wish to not automatically load
20781 symbol definitions from shared libraries, such as when they are
20782 particularly large or there are many of them.
20783
20784 To control the automatic loading of shared library symbols, use the
20785 commands:
20786
20787 @table @code
20788 @kindex set auto-solib-add
20789 @item set auto-solib-add @var{mode}
20790 If @var{mode} is @code{on}, symbols from all shared object libraries
20791 will be loaded automatically when the inferior begins execution, you
20792 attach to an independently started inferior, or when the dynamic linker
20793 informs @value{GDBN} that a new library has been loaded. If @var{mode}
20794 is @code{off}, symbols must be loaded manually, using the
20795 @code{sharedlibrary} command. The default value is @code{on}.
20796
20797 @cindex memory used for symbol tables
20798 If your program uses lots of shared libraries with debug info that
20799 takes large amounts of memory, you can decrease the @value{GDBN}
20800 memory footprint by preventing it from automatically loading the
20801 symbols from shared libraries. To that end, type @kbd{set
20802 auto-solib-add off} before running the inferior, then load each
20803 library whose debug symbols you do need with @kbd{sharedlibrary
20804 @var{regexp}}, where @var{regexp} is a regular expression that matches
20805 the libraries whose symbols you want to be loaded.
20806
20807 @kindex show auto-solib-add
20808 @item show auto-solib-add
20809 Display the current autoloading mode.
20810 @end table
20811
20812 @cindex load shared library
20813 To explicitly load shared library symbols, use the @code{sharedlibrary}
20814 command:
20815
20816 @table @code
20817 @kindex info sharedlibrary
20818 @kindex info share
20819 @item info share @var{regex}
20820 @itemx info sharedlibrary @var{regex}
20821 Print the names of the shared libraries which are currently loaded
20822 that match @var{regex}. If @var{regex} is omitted then print
20823 all shared libraries that are loaded.
20824
20825 @kindex info dll
20826 @item info dll @var{regex}
20827 This is an alias of @code{info sharedlibrary}.
20828
20829 @kindex sharedlibrary
20830 @kindex share
20831 @item sharedlibrary @var{regex}
20832 @itemx share @var{regex}
20833 Load shared object library symbols for files matching a
20834 Unix regular expression.
20835 As with files loaded automatically, it only loads shared libraries
20836 required by your program for a core file or after typing @code{run}. If
20837 @var{regex} is omitted all shared libraries required by your program are
20838 loaded.
20839
20840 @item nosharedlibrary
20841 @kindex nosharedlibrary
20842 @cindex unload symbols from shared libraries
20843 Unload all shared object library symbols. This discards all symbols
20844 that have been loaded from all shared libraries. Symbols from shared
20845 libraries that were loaded by explicit user requests are not
20846 discarded.
20847 @end table
20848
20849 Sometimes you may wish that @value{GDBN} stops and gives you control
20850 when any of shared library events happen. The best way to do this is
20851 to use @code{catch load} and @code{catch unload} (@pxref{Set
20852 Catchpoints}).
20853
20854 @value{GDBN} also supports the @code{set stop-on-solib-events}
20855 command for this. This command exists for historical reasons. It is
20856 less useful than setting a catchpoint, because it does not allow for
20857 conditions or commands as a catchpoint does.
20858
20859 @table @code
20860 @item set stop-on-solib-events
20861 @kindex set stop-on-solib-events
20862 This command controls whether @value{GDBN} should give you control
20863 when the dynamic linker notifies it about some shared library event.
20864 The most common event of interest is loading or unloading of a new
20865 shared library.
20866
20867 @item show stop-on-solib-events
20868 @kindex show stop-on-solib-events
20869 Show whether @value{GDBN} stops and gives you control when shared
20870 library events happen.
20871 @end table
20872
20873 Shared libraries are also supported in many cross or remote debugging
20874 configurations. @value{GDBN} needs to have access to the target's libraries;
20875 this can be accomplished either by providing copies of the libraries
20876 on the host system, or by asking @value{GDBN} to automatically retrieve the
20877 libraries from the target. If copies of the target libraries are
20878 provided, they need to be the same as the target libraries, although the
20879 copies on the target can be stripped as long as the copies on the host are
20880 not.
20881
20882 @cindex where to look for shared libraries
20883 For remote debugging, you need to tell @value{GDBN} where the target
20884 libraries are, so that it can load the correct copies---otherwise, it
20885 may try to load the host's libraries. @value{GDBN} has two variables
20886 to specify the search directories for target libraries.
20887
20888 @table @code
20889 @cindex prefix for executable and shared library file names
20890 @cindex system root, alternate
20891 @kindex set solib-absolute-prefix
20892 @kindex set sysroot
20893 @item set sysroot @var{path}
20894 Use @var{path} as the system root for the program being debugged. Any
20895 absolute shared library paths will be prefixed with @var{path}; many
20896 runtime loaders store the absolute paths to the shared library in the
20897 target program's memory. When starting processes remotely, and when
20898 attaching to already-running processes (local or remote), their
20899 executable filenames will be prefixed with @var{path} if reported to
20900 @value{GDBN} as absolute by the operating system. If you use
20901 @code{set sysroot} to find executables and shared libraries, they need
20902 to be laid out in the same way that they are on the target, with
20903 e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
20904 @var{path}.
20905
20906 If @var{path} starts with the sequence @file{target:} and the target
20907 system is remote then @value{GDBN} will retrieve the target binaries
20908 from the remote system. This is only supported when using a remote
20909 target that supports the @code{remote get} command (@pxref{File
20910 Transfer,,Sending files to a remote system}). The part of @var{path}
20911 following the initial @file{target:} (if present) is used as system
20912 root prefix on the remote file system. If @var{path} starts with the
20913 sequence @file{remote:} this is converted to the sequence
20914 @file{target:} by @code{set sysroot}@footnote{Historically the
20915 functionality to retrieve binaries from the remote system was
20916 provided by prefixing @var{path} with @file{remote:}}. If you want
20917 to specify a local system root using a directory that happens to be
20918 named @file{target:} or @file{remote:}, you need to use some
20919 equivalent variant of the name like @file{./target:}.
20920
20921 For targets with an MS-DOS based filesystem, such as MS-Windows and
20922 SymbianOS, @value{GDBN} tries prefixing a few variants of the target
20923 absolute file name with @var{path}. But first, on Unix hosts,
20924 @value{GDBN} converts all backslash directory separators into forward
20925 slashes, because the backslash is not a directory separator on Unix:
20926
20927 @smallexample
20928 c:\foo\bar.dll @result{} c:/foo/bar.dll
20929 @end smallexample
20930
20931 Then, @value{GDBN} attempts prefixing the target file name with
20932 @var{path}, and looks for the resulting file name in the host file
20933 system:
20934
20935 @smallexample
20936 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
20937 @end smallexample
20938
20939 If that does not find the binary, @value{GDBN} tries removing
20940 the @samp{:} character from the drive spec, both for convenience, and,
20941 for the case of the host file system not supporting file names with
20942 colons:
20943
20944 @smallexample
20945 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
20946 @end smallexample
20947
20948 This makes it possible to have a system root that mirrors a target
20949 with more than one drive. E.g., you may want to setup your local
20950 copies of the target system shared libraries like so (note @samp{c} vs
20951 @samp{z}):
20952
20953 @smallexample
20954 @file{/path/to/sysroot/c/sys/bin/foo.dll}
20955 @file{/path/to/sysroot/c/sys/bin/bar.dll}
20956 @file{/path/to/sysroot/z/sys/bin/bar.dll}
20957 @end smallexample
20958
20959 @noindent
20960 and point the system root at @file{/path/to/sysroot}, so that
20961 @value{GDBN} can find the correct copies of both
20962 @file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
20963
20964 If that still does not find the binary, @value{GDBN} tries
20965 removing the whole drive spec from the target file name:
20966
20967 @smallexample
20968 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
20969 @end smallexample
20970
20971 This last lookup makes it possible to not care about the drive name,
20972 if you don't want or need to.
20973
20974 The @code{set solib-absolute-prefix} command is an alias for @code{set
20975 sysroot}.
20976
20977 @cindex default system root
20978 @cindex @samp{--with-sysroot}
20979 You can set the default system root by using the configure-time
20980 @samp{--with-sysroot} option. If the system root is inside
20981 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
20982 @samp{--exec-prefix}), then the default system root will be updated
20983 automatically if the installed @value{GDBN} is moved to a new
20984 location.
20985
20986 @kindex show sysroot
20987 @item show sysroot
20988 Display the current executable and shared library prefix.
20989
20990 @kindex set solib-search-path
20991 @item set solib-search-path @var{path}
20992 If this variable is set, @var{path} is a colon-separated list of
20993 directories to search for shared libraries. @samp{solib-search-path}
20994 is used after @samp{sysroot} fails to locate the library, or if the
20995 path to the library is relative instead of absolute. If you want to
20996 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
20997 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
20998 finding your host's libraries. @samp{sysroot} is preferred; setting
20999 it to a nonexistent directory may interfere with automatic loading
21000 of shared library symbols.
21001
21002 @kindex show solib-search-path
21003 @item show solib-search-path
21004 Display the current shared library search path.
21005
21006 @cindex DOS file-name semantics of file names.
21007 @kindex set target-file-system-kind (unix|dos-based|auto)
21008 @kindex show target-file-system-kind
21009 @item set target-file-system-kind @var{kind}
21010 Set assumed file system kind for target reported file names.
21011
21012 Shared library file names as reported by the target system may not
21013 make sense as is on the system @value{GDBN} is running on. For
21014 example, when remote debugging a target that has MS-DOS based file
21015 system semantics, from a Unix host, the target may be reporting to
21016 @value{GDBN} a list of loaded shared libraries with file names such as
21017 @file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
21018 drive letters, so the @samp{c:\} prefix is not normally understood as
21019 indicating an absolute file name, and neither is the backslash
21020 normally considered a directory separator character. In that case,
21021 the native file system would interpret this whole absolute file name
21022 as a relative file name with no directory components. This would make
21023 it impossible to point @value{GDBN} at a copy of the remote target's
21024 shared libraries on the host using @code{set sysroot}, and impractical
21025 with @code{set solib-search-path}. Setting
21026 @code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
21027 to interpret such file names similarly to how the target would, and to
21028 map them to file names valid on @value{GDBN}'s native file system
21029 semantics. The value of @var{kind} can be @code{"auto"}, in addition
21030 to one of the supported file system kinds. In that case, @value{GDBN}
21031 tries to determine the appropriate file system variant based on the
21032 current target's operating system (@pxref{ABI, ,Configuring the
21033 Current ABI}). The supported file system settings are:
21034
21035 @table @code
21036 @item unix
21037 Instruct @value{GDBN} to assume the target file system is of Unix
21038 kind. Only file names starting the forward slash (@samp{/}) character
21039 are considered absolute, and the directory separator character is also
21040 the forward slash.
21041
21042 @item dos-based
21043 Instruct @value{GDBN} to assume the target file system is DOS based.
21044 File names starting with either a forward slash, or a drive letter
21045 followed by a colon (e.g., @samp{c:}), are considered absolute, and
21046 both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
21047 considered directory separators.
21048
21049 @item auto
21050 Instruct @value{GDBN} to use the file system kind associated with the
21051 target operating system (@pxref{ABI, ,Configuring the Current ABI}).
21052 This is the default.
21053 @end table
21054 @end table
21055
21056 @cindex file name canonicalization
21057 @cindex base name differences
21058 When processing file names provided by the user, @value{GDBN}
21059 frequently needs to compare them to the file names recorded in the
21060 program's debug info. Normally, @value{GDBN} compares just the
21061 @dfn{base names} of the files as strings, which is reasonably fast
21062 even for very large programs. (The base name of a file is the last
21063 portion of its name, after stripping all the leading directories.)
21064 This shortcut in comparison is based upon the assumption that files
21065 cannot have more than one base name. This is usually true, but
21066 references to files that use symlinks or similar filesystem
21067 facilities violate that assumption. If your program records files
21068 using such facilities, or if you provide file names to @value{GDBN}
21069 using symlinks etc., you can set @code{basenames-may-differ} to
21070 @code{true} to instruct @value{GDBN} to completely canonicalize each
21071 pair of file names it needs to compare. This will make file-name
21072 comparisons accurate, but at a price of a significant slowdown.
21073
21074 @table @code
21075 @item set basenames-may-differ
21076 @kindex set basenames-may-differ
21077 Set whether a source file may have multiple base names.
21078
21079 @item show basenames-may-differ
21080 @kindex show basenames-may-differ
21081 Show whether a source file may have multiple base names.
21082 @end table
21083
21084 @node File Caching
21085 @section File Caching
21086 @cindex caching of opened files
21087 @cindex caching of bfd objects
21088
21089 To speed up file loading, and reduce memory usage, @value{GDBN} will
21090 reuse the @code{bfd} objects used to track open files. @xref{Top, ,
21091 BFD, bfd, The Binary File Descriptor Library}. The following commands
21092 allow visibility and control of the caching behavior.
21093
21094 @table @code
21095 @kindex maint info bfds
21096 @item maint info bfds
21097 This prints information about each @code{bfd} object that is known to
21098 @value{GDBN}.
21099
21100 @kindex maint set bfd-sharing
21101 @kindex maint show bfd-sharing
21102 @kindex bfd caching
21103 @item maint set bfd-sharing
21104 @item maint show bfd-sharing
21105 Control whether @code{bfd} objects can be shared. When sharing is
21106 enabled @value{GDBN} reuses already open @code{bfd} objects rather
21107 than reopening the same file. Turning sharing off does not cause
21108 already shared @code{bfd} objects to be unshared, but all future files
21109 that are opened will create a new @code{bfd} object. Similarly,
21110 re-enabling sharing does not cause multiple existing @code{bfd}
21111 objects to be collapsed into a single shared @code{bfd} object.
21112
21113 @kindex set debug bfd-cache @var{level}
21114 @kindex bfd caching
21115 @item set debug bfd-cache @var{level}
21116 Turns on debugging of the bfd cache, setting the level to @var{level}.
21117
21118 @kindex show debug bfd-cache
21119 @kindex bfd caching
21120 @item show debug bfd-cache
21121 Show the current debugging level of the bfd cache.
21122 @end table
21123
21124 @node Separate Debug Files
21125 @section Debugging Information in Separate Files
21126 @cindex separate debugging information files
21127 @cindex debugging information in separate files
21128 @cindex @file{.debug} subdirectories
21129 @cindex debugging information directory, global
21130 @cindex global debugging information directories
21131 @cindex build ID, and separate debugging files
21132 @cindex @file{.build-id} directory
21133
21134 @value{GDBN} allows you to put a program's debugging information in a
21135 file separate from the executable itself, in a way that allows
21136 @value{GDBN} to find and load the debugging information automatically.
21137 Since debugging information can be very large---sometimes larger
21138 than the executable code itself---some systems distribute debugging
21139 information for their executables in separate files, which users can
21140 install only when they need to debug a problem.
21141
21142 @value{GDBN} supports two ways of specifying the separate debug info
21143 file:
21144
21145 @itemize @bullet
21146 @item
21147 The executable contains a @dfn{debug link} that specifies the name of
21148 the separate debug info file. The separate debug file's name is
21149 usually @file{@var{executable}.debug}, where @var{executable} is the
21150 name of the corresponding executable file without leading directories
21151 (e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
21152 debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
21153 checksum for the debug file, which @value{GDBN} uses to validate that
21154 the executable and the debug file came from the same build.
21155
21156 @item
21157 @anchor{build ID}
21158 The executable contains a @dfn{build ID}, a unique bit string that is
21159 also present in the corresponding debug info file. (This is supported
21160 only on some operating systems, when using the ELF or PE file formats
21161 for binary files and the @sc{gnu} Binutils.) For more details about
21162 this feature, see the description of the @option{--build-id}
21163 command-line option in @ref{Options, , Command Line Options, ld,
21164 The GNU Linker}. The debug info file's name is not specified
21165 explicitly by the build ID, but can be computed from the build ID, see
21166 below.
21167 @end itemize
21168
21169 Depending on the way the debug info file is specified, @value{GDBN}
21170 uses two different methods of looking for the debug file:
21171
21172 @itemize @bullet
21173 @item
21174 For the ``debug link'' method, @value{GDBN} looks up the named file in
21175 the directory of the executable file, then in a subdirectory of that
21176 directory named @file{.debug}, and finally under each one of the
21177 global debug directories, in a subdirectory whose name is identical to
21178 the leading directories of the executable's absolute file name. (On
21179 MS-Windows/MS-DOS, the drive letter of the executable's leading
21180 directories is converted to a one-letter subdirectory, i.e.@:
21181 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
21182 filesystems disallow colons in file names.)
21183
21184 @item
21185 For the ``build ID'' method, @value{GDBN} looks in the
21186 @file{.build-id} subdirectory of each one of the global debug directories for
21187 a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
21188 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
21189 are the rest of the bit string. (Real build ID strings are 32 or more
21190 hex characters, not 10.)
21191 @end itemize
21192
21193 So, for example, suppose you ask @value{GDBN} to debug
21194 @file{/usr/bin/ls}, which has a debug link that specifies the
21195 file @file{ls.debug}, and a build ID whose value in hex is
21196 @code{abcdef1234}. If the list of the global debug directories includes
21197 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
21198 debug information files, in the indicated order:
21199
21200 @itemize @minus
21201 @item
21202 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
21203 @item
21204 @file{/usr/bin/ls.debug}
21205 @item
21206 @file{/usr/bin/.debug/ls.debug}
21207 @item
21208 @file{/usr/lib/debug/usr/bin/ls.debug}.
21209 @end itemize
21210
21211 @anchor{debug-file-directory}
21212 Global debugging info directories default to what is set by @value{GDBN}
21213 configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
21214 you can also set the global debugging info directories, and view the list
21215 @value{GDBN} is currently using.
21216
21217 @table @code
21218
21219 @kindex set debug-file-directory
21220 @item set debug-file-directory @var{directories}
21221 Set the directories which @value{GDBN} searches for separate debugging
21222 information files to @var{directory}. Multiple path components can be set
21223 concatenating them by a path separator.
21224
21225 @kindex show debug-file-directory
21226 @item show debug-file-directory
21227 Show the directories @value{GDBN} searches for separate debugging
21228 information files.
21229
21230 @end table
21231
21232 @cindex @code{.gnu_debuglink} sections
21233 @cindex debug link sections
21234 A debug link is a special section of the executable file named
21235 @code{.gnu_debuglink}. The section must contain:
21236
21237 @itemize
21238 @item
21239 A filename, with any leading directory components removed, followed by
21240 a zero byte,
21241 @item
21242 zero to three bytes of padding, as needed to reach the next four-byte
21243 boundary within the section, and
21244 @item
21245 a four-byte CRC checksum, stored in the same endianness used for the
21246 executable file itself. The checksum is computed on the debugging
21247 information file's full contents by the function given below, passing
21248 zero as the @var{crc} argument.
21249 @end itemize
21250
21251 Any executable file format can carry a debug link, as long as it can
21252 contain a section named @code{.gnu_debuglink} with the contents
21253 described above.
21254
21255 @cindex @code{.note.gnu.build-id} sections
21256 @cindex build ID sections
21257 The build ID is a special section in the executable file (and in other
21258 ELF binary files that @value{GDBN} may consider). This section is
21259 often named @code{.note.gnu.build-id}, but that name is not mandatory.
21260 It contains unique identification for the built files---the ID remains
21261 the same across multiple builds of the same build tree. The default
21262 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
21263 content for the build ID string. The same section with an identical
21264 value is present in the original built binary with symbols, in its
21265 stripped variant, and in the separate debugging information file.
21266
21267 The debugging information file itself should be an ordinary
21268 executable, containing a full set of linker symbols, sections, and
21269 debugging information. The sections of the debugging information file
21270 should have the same names, addresses, and sizes as the original file,
21271 but they need not contain any data---much like a @code{.bss} section
21272 in an ordinary executable.
21273
21274 The @sc{gnu} binary utilities (Binutils) package includes the
21275 @samp{objcopy} utility that can produce
21276 the separated executable / debugging information file pairs using the
21277 following commands:
21278
21279 @smallexample
21280 @kbd{objcopy --only-keep-debug foo foo.debug}
21281 @kbd{strip -g foo}
21282 @end smallexample
21283
21284 @noindent
21285 These commands remove the debugging
21286 information from the executable file @file{foo} and place it in the file
21287 @file{foo.debug}. You can use the first, second or both methods to link the
21288 two files:
21289
21290 @itemize @bullet
21291 @item
21292 The debug link method needs the following additional command to also leave
21293 behind a debug link in @file{foo}:
21294
21295 @smallexample
21296 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
21297 @end smallexample
21298
21299 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
21300 a version of the @code{strip} command such that the command @kbd{strip foo -f
21301 foo.debug} has the same functionality as the two @code{objcopy} commands and
21302 the @code{ln -s} command above, together.
21303
21304 @item
21305 Build ID gets embedded into the main executable using @code{ld --build-id} or
21306 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
21307 compatibility fixes for debug files separation are present in @sc{gnu} binary
21308 utilities (Binutils) package since version 2.18.
21309 @end itemize
21310
21311 @noindent
21312
21313 @cindex CRC algorithm definition
21314 The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21315 IEEE 802.3 using the polynomial:
21316
21317 @c TexInfo requires naked braces for multi-digit exponents for Tex
21318 @c output, but this causes HTML output to barf. HTML has to be set using
21319 @c raw commands. So we end up having to specify this equation in 2
21320 @c different ways!
21321 @ifhtml
21322 @display
21323 @html
21324 <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>
21325 + <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
21326 @end html
21327 @end display
21328 @end ifhtml
21329 @ifnothtml
21330 @display
21331 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21332 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21333 @end display
21334 @end ifnothtml
21335
21336 The function is computed byte at a time, taking the least
21337 significant bit of each byte first. The initial pattern
21338 @code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21339 the final result is inverted to ensure trailing zeros also affect the
21340 CRC.
21341
21342 @emph{Note:} This is the same CRC polynomial as used in handling the
21343 @dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21344 However in the case of the Remote Serial Protocol, the CRC is computed
21345 @emph{most} significant bit first, and the result is not inverted, so
21346 trailing zeros have no effect on the CRC value.
21347
21348 To complete the description, we show below the code of the function
21349 which produces the CRC used in @code{.gnu_debuglink}. Inverting the
21350 initially supplied @code{crc} argument means that an initial call to
21351 this function passing in zero will start computing the CRC using
21352 @code{0xffffffff}.
21353
21354 @kindex gnu_debuglink_crc32
21355 @smallexample
21356 unsigned long
21357 gnu_debuglink_crc32 (unsigned long crc,
21358 unsigned char *buf, size_t len)
21359 @{
21360 static const unsigned long crc32_table[256] =
21361 @{
21362 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21363 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21364 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
21365 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
21366 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
21367 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
21368 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
21369 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
21370 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
21371 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
21372 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
21373 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
21374 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
21375 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
21376 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
21377 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
21378 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
21379 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
21380 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
21381 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
21382 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
21383 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
21384 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
21385 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
21386 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
21387 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
21388 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
21389 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
21390 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
21391 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
21392 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
21393 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
21394 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
21395 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
21396 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
21397 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
21398 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
21399 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
21400 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
21401 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
21402 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
21403 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
21404 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
21405 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
21406 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
21407 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
21408 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
21409 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
21410 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
21411 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
21412 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
21413 0x2d02ef8d
21414 @};
21415 unsigned char *end;
21416
21417 crc = ~crc & 0xffffffff;
21418 for (end = buf + len; buf < end; ++buf)
21419 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
21420 return ~crc & 0xffffffff;
21421 @}
21422 @end smallexample
21423
21424 @noindent
21425 This computation does not apply to the ``build ID'' method.
21426
21427 @node MiniDebugInfo
21428 @section Debugging information in a special section
21429 @cindex separate debug sections
21430 @cindex @samp{.gnu_debugdata} section
21431
21432 Some systems ship pre-built executables and libraries that have a
21433 special @samp{.gnu_debugdata} section. This feature is called
21434 @dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
21435 is used to supply extra symbols for backtraces.
21436
21437 The intent of this section is to provide extra minimal debugging
21438 information for use in simple backtraces. It is not intended to be a
21439 replacement for full separate debugging information (@pxref{Separate
21440 Debug Files}). The example below shows the intended use; however,
21441 @value{GDBN} does not currently put restrictions on what sort of
21442 debugging information might be included in the section.
21443
21444 @value{GDBN} has support for this extension. If the section exists,
21445 then it is used provided that no other source of debugging information
21446 can be found, and that @value{GDBN} was configured with LZMA support.
21447
21448 This section can be easily created using @command{objcopy} and other
21449 standard utilities:
21450
21451 @smallexample
21452 # Extract the dynamic symbols from the main binary, there is no need
21453 # to also have these in the normal symbol table.
21454 nm -D @var{binary} --format=posix --defined-only \
21455 | awk '@{ print $1 @}' | sort > dynsyms
21456
21457 # Extract all the text (i.e. function) symbols from the debuginfo.
21458 # (Note that we actually also accept "D" symbols, for the benefit
21459 # of platforms like PowerPC64 that use function descriptors.)
21460 nm @var{binary} --format=posix --defined-only \
21461 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
21462 | sort > funcsyms
21463
21464 # Keep all the function symbols not already in the dynamic symbol
21465 # table.
21466 comm -13 dynsyms funcsyms > keep_symbols
21467
21468 # Separate full debug info into debug binary.
21469 objcopy --only-keep-debug @var{binary} debug
21470
21471 # Copy the full debuginfo, keeping only a minimal set of symbols and
21472 # removing some unnecessary sections.
21473 objcopy -S --remove-section .gdb_index --remove-section .comment \
21474 --keep-symbols=keep_symbols debug mini_debuginfo
21475
21476 # Drop the full debug info from the original binary.
21477 strip --strip-all -R .comment @var{binary}
21478
21479 # Inject the compressed data into the .gnu_debugdata section of the
21480 # original binary.
21481 xz mini_debuginfo
21482 objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
21483 @end smallexample
21484
21485 @node Index Files
21486 @section Index Files Speed Up @value{GDBN}
21487 @cindex index files
21488 @cindex @samp{.gdb_index} section
21489
21490 When @value{GDBN} finds a symbol file, it scans the symbols in the
21491 file in order to construct an internal symbol table. This lets most
21492 @value{GDBN} operations work quickly---at the cost of a delay early
21493 on. For large programs, this delay can be quite lengthy, so
21494 @value{GDBN} provides a way to build an index, which speeds up
21495 startup.
21496
21497 For convenience, @value{GDBN} comes with a program,
21498 @command{gdb-add-index}, which can be used to add the index to a
21499 symbol file. It takes the symbol file as its only argument:
21500
21501 @smallexample
21502 $ gdb-add-index symfile
21503 @end smallexample
21504
21505 @xref{gdb-add-index}.
21506
21507 It is also possible to do the work manually. Here is what
21508 @command{gdb-add-index} does behind the curtains.
21509
21510 The index is stored as a section in the symbol file. @value{GDBN} can
21511 write the index to a file, then you can put it into the symbol file
21512 using @command{objcopy}.
21513
21514 To create an index file, use the @code{save gdb-index} command:
21515
21516 @table @code
21517 @item save gdb-index [-dwarf-5] @var{directory}
21518 @kindex save gdb-index
21519 Create index files for all symbol files currently known by
21520 @value{GDBN}. For each known @var{symbol-file}, this command by
21521 default creates it produces a single file
21522 @file{@var{symbol-file}.gdb-index}. If you invoke this command with
21523 the @option{-dwarf-5} option, it produces 2 files:
21524 @file{@var{symbol-file}.debug_names} and
21525 @file{@var{symbol-file}.debug_str}. The files are created in the
21526 given @var{directory}.
21527 @end table
21528
21529 Once you have created an index file you can merge it into your symbol
21530 file, here named @file{symfile}, using @command{objcopy}:
21531
21532 @smallexample
21533 $ objcopy --add-section .gdb_index=symfile.gdb-index \
21534 --set-section-flags .gdb_index=readonly symfile symfile
21535 @end smallexample
21536
21537 Or for @code{-dwarf-5}:
21538
21539 @smallexample
21540 $ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
21541 $ cat symfile.debug_str >>symfile.debug_str.new
21542 $ objcopy --add-section .debug_names=symfile.gdb-index \
21543 --set-section-flags .debug_names=readonly \
21544 --update-section .debug_str=symfile.debug_str.new symfile symfile
21545 @end smallexample
21546
21547 @value{GDBN} will normally ignore older versions of @file{.gdb_index}
21548 sections that have been deprecated. Usually they are deprecated because
21549 they are missing a new feature or have performance issues.
21550 To tell @value{GDBN} to use a deprecated index section anyway
21551 specify @code{set use-deprecated-index-sections on}.
21552 The default is @code{off}.
21553 This can speed up startup, but may result in some functionality being lost.
21554 @xref{Index Section Format}.
21555
21556 @emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
21557 must be done before gdb reads the file. The following will not work:
21558
21559 @smallexample
21560 $ gdb -ex "set use-deprecated-index-sections on" <program>
21561 @end smallexample
21562
21563 Instead you must do, for example,
21564
21565 @smallexample
21566 $ gdb -iex "set use-deprecated-index-sections on" <program>
21567 @end smallexample
21568
21569 Indices only work when using DWARF debugging information, not stabs.
21570
21571 @subsection Automatic symbol index cache
21572
21573 @cindex automatic symbol index cache
21574 It is possible for @value{GDBN} to automatically save a copy of this index in a
21575 cache on disk and retrieve it from there when loading the same binary in the
21576 future. This feature can be turned on with @kbd{set index-cache on}. The
21577 following commands can be used to tweak the behavior of the index cache.
21578
21579 @table @code
21580
21581 @kindex set index-cache
21582 @item set index-cache on
21583 @itemx set index-cache off
21584 Enable or disable the use of the symbol index cache.
21585
21586 @item set index-cache directory @var{directory}
21587 @kindex show index-cache
21588 @itemx show index-cache directory
21589 Set/show the directory where index files will be saved.
21590
21591 The default value for this directory depends on the host platform. On
21592 most systems, the index is cached in the @file{gdb} subdirectory of
21593 the directory pointed to by the @env{XDG_CACHE_HOME} environment
21594 variable, if it is defined, else in the @file{.cache/gdb} subdirectory
21595 of your home directory. However, on some systems, the default may
21596 differ according to local convention.
21597
21598 There is no limit on the disk space used by index cache. It is perfectly safe
21599 to delete the content of that directory to free up disk space.
21600
21601 @item show index-cache stats
21602 Print the number of cache hits and misses since the launch of @value{GDBN}.
21603
21604 @end table
21605
21606 @node Symbol Errors
21607 @section Errors Reading Symbol Files
21608
21609 While reading a symbol file, @value{GDBN} occasionally encounters problems,
21610 such as symbol types it does not recognize, or known bugs in compiler
21611 output. By default, @value{GDBN} does not notify you of such problems, since
21612 they are relatively common and primarily of interest to people
21613 debugging compilers. If you are interested in seeing information
21614 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
21615 only one message about each such type of problem, no matter how many
21616 times the problem occurs; or you can ask @value{GDBN} to print more messages,
21617 to see how many times the problems occur, with the @code{set
21618 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
21619 Messages}).
21620
21621 The messages currently printed, and their meanings, include:
21622
21623 @table @code
21624 @item inner block not inside outer block in @var{symbol}
21625
21626 The symbol information shows where symbol scopes begin and end
21627 (such as at the start of a function or a block of statements). This
21628 error indicates that an inner scope block is not fully contained
21629 in its outer scope blocks.
21630
21631 @value{GDBN} circumvents the problem by treating the inner block as if it had
21632 the same scope as the outer block. In the error message, @var{symbol}
21633 may be shown as ``@code{(don't know)}'' if the outer block is not a
21634 function.
21635
21636 @item block at @var{address} out of order
21637
21638 The symbol information for symbol scope blocks should occur in
21639 order of increasing addresses. This error indicates that it does not
21640 do so.
21641
21642 @value{GDBN} does not circumvent this problem, and has trouble
21643 locating symbols in the source file whose symbols it is reading. (You
21644 can often determine what source file is affected by specifying
21645 @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
21646 Messages}.)
21647
21648 @item bad block start address patched
21649
21650 The symbol information for a symbol scope block has a start address
21651 smaller than the address of the preceding source line. This is known
21652 to occur in the SunOS 4.1.1 (and earlier) C compiler.
21653
21654 @value{GDBN} circumvents the problem by treating the symbol scope block as
21655 starting on the previous source line.
21656
21657 @item bad string table offset in symbol @var{n}
21658
21659 @cindex foo
21660 Symbol number @var{n} contains a pointer into the string table which is
21661 larger than the size of the string table.
21662
21663 @value{GDBN} circumvents the problem by considering the symbol to have the
21664 name @code{foo}, which may cause other problems if many symbols end up
21665 with this name.
21666
21667 @item unknown symbol type @code{0x@var{nn}}
21668
21669 The symbol information contains new data types that @value{GDBN} does
21670 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
21671 uncomprehended information, in hexadecimal.
21672
21673 @value{GDBN} circumvents the error by ignoring this symbol information.
21674 This usually allows you to debug your program, though certain symbols
21675 are not accessible. If you encounter such a problem and feel like
21676 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
21677 on @code{complain}, then go up to the function @code{read_dbx_symtab}
21678 and examine @code{*bufp} to see the symbol.
21679
21680 @item stub type has NULL name
21681
21682 @value{GDBN} could not find the full definition for a struct or class.
21683
21684 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
21685 The symbol information for a C@t{++} member function is missing some
21686 information that recent versions of the compiler should have output for
21687 it.
21688
21689 @item info mismatch between compiler and debugger
21690
21691 @value{GDBN} could not parse a type specification output by the compiler.
21692
21693 @end table
21694
21695 @node Data Files
21696 @section GDB Data Files
21697
21698 @cindex prefix for data files
21699 @value{GDBN} will sometimes read an auxiliary data file. These files
21700 are kept in a directory known as the @dfn{data directory}.
21701
21702 You can set the data directory's name, and view the name @value{GDBN}
21703 is currently using.
21704
21705 @table @code
21706 @kindex set data-directory
21707 @item set data-directory @var{directory}
21708 Set the directory which @value{GDBN} searches for auxiliary data files
21709 to @var{directory}.
21710
21711 @kindex show data-directory
21712 @item show data-directory
21713 Show the directory @value{GDBN} searches for auxiliary data files.
21714 @end table
21715
21716 @cindex default data directory
21717 @cindex @samp{--with-gdb-datadir}
21718 You can set the default data directory by using the configure-time
21719 @samp{--with-gdb-datadir} option. If the data directory is inside
21720 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21721 @samp{--exec-prefix}), then the default data directory will be updated
21722 automatically if the installed @value{GDBN} is moved to a new
21723 location.
21724
21725 The data directory may also be specified with the
21726 @code{--data-directory} command line option.
21727 @xref{Mode Options}.
21728
21729 @node Targets
21730 @chapter Specifying a Debugging Target
21731
21732 @cindex debugging target
21733 A @dfn{target} is the execution environment occupied by your program.
21734
21735 Often, @value{GDBN} runs in the same host environment as your program;
21736 in that case, the debugging target is specified as a side effect when
21737 you use the @code{file} or @code{core} commands. When you need more
21738 flexibility---for example, running @value{GDBN} on a physically separate
21739 host, or controlling a standalone system over a serial port or a
21740 realtime system over a TCP/IP connection---you can use the @code{target}
21741 command to specify one of the target types configured for @value{GDBN}
21742 (@pxref{Target Commands, ,Commands for Managing Targets}).
21743
21744 @cindex target architecture
21745 It is possible to build @value{GDBN} for several different @dfn{target
21746 architectures}. When @value{GDBN} is built like that, you can choose
21747 one of the available architectures with the @kbd{set architecture}
21748 command.
21749
21750 @table @code
21751 @kindex set architecture
21752 @kindex show architecture
21753 @item set architecture @var{arch}
21754 This command sets the current target architecture to @var{arch}. The
21755 value of @var{arch} can be @code{"auto"}, in addition to one of the
21756 supported architectures.
21757
21758 @item show architecture
21759 Show the current target architecture.
21760
21761 @item set processor
21762 @itemx processor
21763 @kindex set processor
21764 @kindex show processor
21765 These are alias commands for, respectively, @code{set architecture}
21766 and @code{show architecture}.
21767 @end table
21768
21769 @menu
21770 * Active Targets:: Active targets
21771 * Target Commands:: Commands for managing targets
21772 * Byte Order:: Choosing target byte order
21773 @end menu
21774
21775 @node Active Targets
21776 @section Active Targets
21777
21778 @cindex stacking targets
21779 @cindex active targets
21780 @cindex multiple targets
21781
21782 There are multiple classes of targets such as: processes, executable files or
21783 recording sessions. Core files belong to the process class, making core file
21784 and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
21785 on multiple active targets, one in each class. This allows you to (for
21786 example) start a process and inspect its activity, while still having access to
21787 the executable file after the process finishes. Or if you start process
21788 recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
21789 presented a virtual layer of the recording target, while the process target
21790 remains stopped at the chronologically last point of the process execution.
21791
21792 Use the @code{core-file} and @code{exec-file} commands to select a new core
21793 file or executable target (@pxref{Files, ,Commands to Specify Files}). To
21794 specify as a target a process that is already running, use the @code{attach}
21795 command (@pxref{Attach, ,Debugging an Already-running Process}).
21796
21797 @node Target Commands
21798 @section Commands for Managing Targets
21799
21800 @table @code
21801 @item target @var{type} @var{parameters}
21802 Connects the @value{GDBN} host environment to a target machine or
21803 process. A target is typically a protocol for talking to debugging
21804 facilities. You use the argument @var{type} to specify the type or
21805 protocol of the target machine.
21806
21807 Further @var{parameters} are interpreted by the target protocol, but
21808 typically include things like device names or host names to connect
21809 with, process numbers, and baud rates.
21810
21811 The @code{target} command does not repeat if you press @key{RET} again
21812 after executing the command.
21813
21814 @kindex help target
21815 @item help target
21816 Displays the names of all targets available. To display targets
21817 currently selected, use either @code{info target} or @code{info files}
21818 (@pxref{Files, ,Commands to Specify Files}).
21819
21820 @item help target @var{name}
21821 Describe a particular target, including any parameters necessary to
21822 select it.
21823
21824 @kindex set gnutarget
21825 @item set gnutarget @var{args}
21826 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
21827 knows whether it is reading an @dfn{executable},
21828 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
21829 with the @code{set gnutarget} command. Unlike most @code{target} commands,
21830 with @code{gnutarget} the @code{target} refers to a program, not a machine.
21831
21832 @quotation
21833 @emph{Warning:} To specify a file format with @code{set gnutarget},
21834 you must know the actual BFD name.
21835 @end quotation
21836
21837 @noindent
21838 @xref{Files, , Commands to Specify Files}.
21839
21840 @kindex show gnutarget
21841 @item show gnutarget
21842 Use the @code{show gnutarget} command to display what file format
21843 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
21844 @value{GDBN} will determine the file format for each file automatically,
21845 and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
21846 @end table
21847
21848 @cindex common targets
21849 Here are some common targets (available, or not, depending on the GDB
21850 configuration):
21851
21852 @table @code
21853 @kindex target
21854 @item target exec @var{program}
21855 @cindex executable file target
21856 An executable file. @samp{target exec @var{program}} is the same as
21857 @samp{exec-file @var{program}}.
21858
21859 @item target core @var{filename}
21860 @cindex core dump file target
21861 A core dump file. @samp{target core @var{filename}} is the same as
21862 @samp{core-file @var{filename}}.
21863
21864 @item target remote @var{medium}
21865 @cindex remote target
21866 A remote system connected to @value{GDBN} via a serial line or network
21867 connection. This command tells @value{GDBN} to use its own remote
21868 protocol over @var{medium} for debugging. @xref{Remote Debugging}.
21869
21870 For example, if you have a board connected to @file{/dev/ttya} on the
21871 machine running @value{GDBN}, you could say:
21872
21873 @smallexample
21874 target remote /dev/ttya
21875 @end smallexample
21876
21877 @code{target remote} supports the @code{load} command. This is only
21878 useful if you have some other way of getting the stub to the target
21879 system, and you can put it somewhere in memory where it won't get
21880 clobbered by the download.
21881
21882 @item target sim @r{[}@var{simargs}@r{]} @dots{}
21883 @cindex built-in simulator target
21884 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
21885 In general,
21886 @smallexample
21887 target sim
21888 load
21889 run
21890 @end smallexample
21891 @noindent
21892 works; however, you cannot assume that a specific memory map, device
21893 drivers, or even basic I/O is available, although some simulators do
21894 provide these. For info about any processor-specific simulator details,
21895 see the appropriate section in @ref{Embedded Processors, ,Embedded
21896 Processors}.
21897
21898 @item target native
21899 @cindex native target
21900 Setup for local/native process debugging. Useful to make the
21901 @code{run} command spawn native processes (likewise @code{attach},
21902 etc.@:) even when @code{set auto-connect-native-target} is @code{off}
21903 (@pxref{set auto-connect-native-target}).
21904
21905 @end table
21906
21907 Different targets are available on different configurations of @value{GDBN};
21908 your configuration may have more or fewer targets.
21909
21910 Many remote targets require you to download the executable's code once
21911 you've successfully established a connection. You may wish to control
21912 various aspects of this process.
21913
21914 @table @code
21915
21916 @item set hash
21917 @kindex set hash@r{, for remote monitors}
21918 @cindex hash mark while downloading
21919 This command controls whether a hash mark @samp{#} is displayed while
21920 downloading a file to the remote monitor. If on, a hash mark is
21921 displayed after each S-record is successfully downloaded to the
21922 monitor.
21923
21924 @item show hash
21925 @kindex show hash@r{, for remote monitors}
21926 Show the current status of displaying the hash mark.
21927
21928 @item set debug monitor
21929 @kindex set debug monitor
21930 @cindex display remote monitor communications
21931 Enable or disable display of communications messages between
21932 @value{GDBN} and the remote monitor.
21933
21934 @item show debug monitor
21935 @kindex show debug monitor
21936 Show the current status of displaying communications between
21937 @value{GDBN} and the remote monitor.
21938 @end table
21939
21940 @table @code
21941
21942 @kindex load @var{filename} @var{offset}
21943 @item load @var{filename} @var{offset}
21944 @anchor{load}
21945 Depending on what remote debugging facilities are configured into
21946 @value{GDBN}, the @code{load} command may be available. Where it exists, it
21947 is meant to make @var{filename} (an executable) available for debugging
21948 on the remote system---by downloading, or dynamic linking, for example.
21949 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
21950 the @code{add-symbol-file} command.
21951
21952 If your @value{GDBN} does not have a @code{load} command, attempting to
21953 execute it gets the error message ``@code{You can't do that when your
21954 target is @dots{}}''
21955
21956 The file is loaded at whatever address is specified in the executable.
21957 For some object file formats, you can specify the load address when you
21958 link the program; for other formats, like a.out, the object file format
21959 specifies a fixed address.
21960 @c FIXME! This would be a good place for an xref to the GNU linker doc.
21961
21962 It is also possible to tell @value{GDBN} to load the executable file at a
21963 specific offset described by the optional argument @var{offset}. When
21964 @var{offset} is provided, @var{filename} must also be provided.
21965
21966 Depending on the remote side capabilities, @value{GDBN} may be able to
21967 load programs into flash memory.
21968
21969 @code{load} does not repeat if you press @key{RET} again after using it.
21970 @end table
21971
21972 @table @code
21973
21974 @kindex flash-erase
21975 @item flash-erase
21976 @anchor{flash-erase}
21977
21978 Erases all known flash memory regions on the target.
21979
21980 @end table
21981
21982 @node Byte Order
21983 @section Choosing Target Byte Order
21984
21985 @cindex choosing target byte order
21986 @cindex target byte order
21987
21988 Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
21989 offer the ability to run either big-endian or little-endian byte
21990 orders. Usually the executable or symbol will include a bit to
21991 designate the endian-ness, and you will not need to worry about
21992 which to use. However, you may still find it useful to adjust
21993 @value{GDBN}'s idea of processor endian-ness manually.
21994
21995 @table @code
21996 @kindex set endian
21997 @item set endian big
21998 Instruct @value{GDBN} to assume the target is big-endian.
21999
22000 @item set endian little
22001 Instruct @value{GDBN} to assume the target is little-endian.
22002
22003 @item set endian auto
22004 Instruct @value{GDBN} to use the byte order associated with the
22005 executable.
22006
22007 @item show endian
22008 Display @value{GDBN}'s current idea of the target byte order.
22009
22010 @end table
22011
22012 If the @code{set endian auto} mode is in effect and no executable has
22013 been selected, then the endianness used is the last one chosen either
22014 by one of the @code{set endian big} and @code{set endian little}
22015 commands or by inferring from the last executable used. If no
22016 endianness has been previously chosen, then the default for this mode
22017 is inferred from the target @value{GDBN} has been built for, and is
22018 @code{little} if the name of the target CPU has an @code{el} suffix
22019 and @code{big} otherwise.
22020
22021 Note that these commands merely adjust interpretation of symbolic
22022 data on the host, and that they have absolutely no effect on the
22023 target system.
22024
22025
22026 @node Remote Debugging
22027 @chapter Debugging Remote Programs
22028 @cindex remote debugging
22029
22030 If you are trying to debug a program running on a machine that cannot run
22031 @value{GDBN} in the usual way, it is often useful to use remote debugging.
22032 For example, you might use remote debugging on an operating system kernel,
22033 or on a small system which does not have a general purpose operating system
22034 powerful enough to run a full-featured debugger.
22035
22036 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
22037 to make this work with particular debugging targets. In addition,
22038 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
22039 but not specific to any particular target system) which you can use if you
22040 write the remote stubs---the code that runs on the remote system to
22041 communicate with @value{GDBN}.
22042
22043 Other remote targets may be available in your
22044 configuration of @value{GDBN}; use @code{help target} to list them.
22045
22046 @menu
22047 * Connecting:: Connecting to a remote target
22048 * File Transfer:: Sending files to a remote system
22049 * Server:: Using the gdbserver program
22050 * Remote Configuration:: Remote configuration
22051 * Remote Stub:: Implementing a remote stub
22052 @end menu
22053
22054 @node Connecting
22055 @section Connecting to a Remote Target
22056 @cindex remote debugging, connecting
22057 @cindex @code{gdbserver}, connecting
22058 @cindex remote debugging, types of connections
22059 @cindex @code{gdbserver}, types of connections
22060 @cindex @code{gdbserver}, @code{target remote} mode
22061 @cindex @code{gdbserver}, @code{target extended-remote} mode
22062
22063 This section describes how to connect to a remote target, including the
22064 types of connections and their differences, how to set up executable and
22065 symbol files on the host and target, and the commands used for
22066 connecting to and disconnecting from the remote target.
22067
22068 @subsection Types of Remote Connections
22069
22070 @value{GDBN} supports two types of remote connections, @code{target remote}
22071 mode and @code{target extended-remote} mode. Note that many remote targets
22072 support only @code{target remote} mode. There are several major
22073 differences between the two types of connections, enumerated here:
22074
22075 @table @asis
22076
22077 @cindex remote debugging, detach and program exit
22078 @item Result of detach or program exit
22079 @strong{With target remote mode:} When the debugged program exits or you
22080 detach from it, @value{GDBN} disconnects from the target. When using
22081 @code{gdbserver}, @code{gdbserver} will exit.
22082
22083 @strong{With target extended-remote mode:} When the debugged program exits or
22084 you detach from it, @value{GDBN} remains connected to the target, even
22085 though no program is running. You can rerun the program, attach to a
22086 running program, or use @code{monitor} commands specific to the target.
22087
22088 When using @code{gdbserver} in this case, it does not exit unless it was
22089 invoked using the @option{--once} option. If the @option{--once} option
22090 was not used, you can ask @code{gdbserver} to exit using the
22091 @code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
22092
22093 @item Specifying the program to debug
22094 For both connection types you use the @code{file} command to specify the
22095 program on the host system. If you are using @code{gdbserver} there are
22096 some differences in how to specify the location of the program on the
22097 target.
22098
22099 @strong{With target remote mode:} You must either specify the program to debug
22100 on the @code{gdbserver} command line or use the @option{--attach} option
22101 (@pxref{Attaching to a program,,Attaching to a Running Program}).
22102
22103 @cindex @option{--multi}, @code{gdbserver} option
22104 @strong{With target extended-remote mode:} You may specify the program to debug
22105 on the @code{gdbserver} command line, or you can load the program or attach
22106 to it using @value{GDBN} commands after connecting to @code{gdbserver}.
22107
22108 @anchor{--multi Option in Types of Remote Connnections}
22109 You can start @code{gdbserver} without supplying an initial command to run
22110 or process ID to attach. To do this, use the @option{--multi} command line
22111 option. Then you can connect using @code{target extended-remote} and start
22112 the program you want to debug (see below for details on using the
22113 @code{run} command in this scenario). Note that the conditions under which
22114 @code{gdbserver} terminates depend on how @value{GDBN} connects to it
22115 (@code{target remote} or @code{target extended-remote}). The
22116 @option{--multi} option to @code{gdbserver} has no influence on that.
22117
22118 @item The @code{run} command
22119 @strong{With target remote mode:} The @code{run} command is not
22120 supported. Once a connection has been established, you can use all
22121 the usual @value{GDBN} commands to examine and change data. The
22122 remote program is already running, so you can use commands like
22123 @kbd{step} and @kbd{continue}.
22124
22125 @strong{With target extended-remote mode:} The @code{run} command is
22126 supported. The @code{run} command uses the value set by
22127 @code{set remote exec-file} (@pxref{set remote exec-file}) to select
22128 the program to run. Command line arguments are supported, except for
22129 wildcard expansion and I/O redirection (@pxref{Arguments}).
22130
22131 If you specify the program to debug on the command line, then the
22132 @code{run} command is not required to start execution, and you can
22133 resume using commands like @kbd{step} and @kbd{continue} as with
22134 @code{target remote} mode.
22135
22136 @anchor{Attaching in Types of Remote Connections}
22137 @item Attaching
22138 @strong{With target remote mode:} The @value{GDBN} command @code{attach} is
22139 not supported. To attach to a running program using @code{gdbserver}, you
22140 must use the @option{--attach} option (@pxref{Running gdbserver}).
22141
22142 @strong{With target extended-remote mode:} To attach to a running program,
22143 you may use the @code{attach} command after the connection has been
22144 established. If you are using @code{gdbserver}, you may also invoke
22145 @code{gdbserver} using the @option{--attach} option
22146 (@pxref{Running gdbserver}).
22147
22148 Some remote targets allow @value{GDBN} to determine the executable file running
22149 in the process the debugger is attaching to. In such a case, @value{GDBN}
22150 uses the value of @code{exec-file-mismatch} to handle a possible mismatch
22151 between the executable file name running in the process and the name of the
22152 current exec-file loaded by @value{GDBN} (@pxref{set exec-file-mismatch}).
22153
22154 @end table
22155
22156 @anchor{Host and target files}
22157 @subsection Host and Target Files
22158 @cindex remote debugging, symbol files
22159 @cindex symbol files, remote debugging
22160
22161 @value{GDBN}, running on the host, needs access to symbol and debugging
22162 information for your program running on the target. This requires
22163 access to an unstripped copy of your program, and possibly any associated
22164 symbol files. Note that this section applies equally to both @code{target
22165 remote} mode and @code{target extended-remote} mode.
22166
22167 Some remote targets (@pxref{qXfer executable filename read}, and
22168 @pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
22169 the same connection used to communicate with @value{GDBN}. With such a
22170 target, if the remote program is unstripped, the only command you need is
22171 @code{target remote} (or @code{target extended-remote}).
22172
22173 If the remote program is stripped, or the target does not support remote
22174 program file access, start up @value{GDBN} using the name of the local
22175 unstripped copy of your program as the first argument, or use the
22176 @code{file} command. Use @code{set sysroot} to specify the location (on
22177 the host) of target libraries (unless your @value{GDBN} was compiled with
22178 the correct sysroot using @code{--with-sysroot}). Alternatively, you
22179 may use @code{set solib-search-path} to specify how @value{GDBN} locates
22180 target libraries.
22181
22182 The symbol file and target libraries must exactly match the executable
22183 and libraries on the target, with one exception: the files on the host
22184 system should not be stripped, even if the files on the target system
22185 are. Mismatched or missing files will lead to confusing results
22186 during debugging. On @sc{gnu}/Linux targets, mismatched or missing
22187 files may also prevent @code{gdbserver} from debugging multi-threaded
22188 programs.
22189
22190 @subsection Remote Connection Commands
22191 @cindex remote connection commands
22192 @value{GDBN} can communicate with the target over a serial line, a
22193 local Unix domain socket, or
22194 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
22195 each case, @value{GDBN} uses the same protocol for debugging your
22196 program; only the medium carrying the debugging packets varies. The
22197 @code{target remote} and @code{target extended-remote} commands
22198 establish a connection to the target. Both commands accept the same
22199 arguments, which indicate the medium to use:
22200
22201 @table @code
22202
22203 @item target remote @var{serial-device}
22204 @itemx target extended-remote @var{serial-device}
22205 @cindex serial line, @code{target remote}
22206 Use @var{serial-device} to communicate with the target. For example,
22207 to use a serial line connected to the device named @file{/dev/ttyb}:
22208
22209 @smallexample
22210 target remote /dev/ttyb
22211 @end smallexample
22212
22213 If you're using a serial line, you may want to give @value{GDBN} the
22214 @samp{--baud} option, or use the @code{set serial baud} command
22215 (@pxref{Remote Configuration, set serial baud}) before the
22216 @code{target} command.
22217
22218 @item target remote @var{local-socket}
22219 @itemx target extended-remote @var{local-socket}
22220 @cindex local socket, @code{target remote}
22221 @cindex Unix domain socket
22222 Use @var{local-socket} to communicate with the target. For example,
22223 to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
22224
22225 @smallexample
22226 target remote /tmp/gdb-socket0
22227 @end smallexample
22228
22229 Note that this command has the same form as the command to connect
22230 to a serial line. @value{GDBN} will automatically determine which
22231 kind of file you have specified and will make the appropriate kind
22232 of connection.
22233 This feature is not available if the host system does not support
22234 Unix domain sockets.
22235
22236 @item target remote @code{@var{host}:@var{port}}
22237 @itemx target remote @code{[@var{host}]:@var{port}}
22238 @itemx target remote @code{tcp:@var{host}:@var{port}}
22239 @itemx target remote @code{tcp:[@var{host}]:@var{port}}
22240 @itemx target remote @code{tcp4:@var{host}:@var{port}}
22241 @itemx target remote @code{tcp6:@var{host}:@var{port}}
22242 @itemx target remote @code{tcp6:[@var{host}]:@var{port}}
22243 @itemx target extended-remote @code{@var{host}:@var{port}}
22244 @itemx target extended-remote @code{[@var{host}]:@var{port}}
22245 @itemx target extended-remote @code{tcp:@var{host}:@var{port}}
22246 @itemx target extended-remote @code{tcp:[@var{host}]:@var{port}}
22247 @itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
22248 @itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
22249 @itemx target extended-remote @code{tcp6:[@var{host}]:@var{port}}
22250 @cindex @acronym{TCP} port, @code{target remote}
22251 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
22252 The @var{host} may be either a host name, a numeric @acronym{IPv4}
22253 address, or a numeric @acronym{IPv6} address (with or without the
22254 square brackets to separate the address from the port); @var{port}
22255 must be a decimal number. The @var{host} could be the target machine
22256 itself, if it is directly connected to the net, or it might be a
22257 terminal server which in turn has a serial line to the target.
22258
22259 For example, to connect to port 2828 on a terminal server named
22260 @code{manyfarms}:
22261
22262 @smallexample
22263 target remote manyfarms:2828
22264 @end smallexample
22265
22266 To connect to port 2828 on a terminal server whose address is
22267 @code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
22268 square bracket syntax:
22269
22270 @smallexample
22271 target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
22272 @end smallexample
22273
22274 @noindent
22275 or explicitly specify the @acronym{IPv6} protocol:
22276
22277 @smallexample
22278 target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
22279 @end smallexample
22280
22281 This last example may be confusing to the reader, because there is no
22282 visible separation between the hostname and the port number.
22283 Therefore, we recommend the user to provide @acronym{IPv6} addresses
22284 using square brackets for clarity. However, it is important to
22285 mention that for @value{GDBN} there is no ambiguity: the number after
22286 the last colon is considered to be the port number.
22287
22288 If your remote target is actually running on the same machine as your
22289 debugger session (e.g.@: a simulator for your target running on the
22290 same host), you can omit the hostname. For example, to connect to
22291 port 1234 on your local machine:
22292
22293 @smallexample
22294 target remote :1234
22295 @end smallexample
22296 @noindent
22297
22298 Note that the colon is still required here.
22299
22300 @item target remote @code{udp:@var{host}:@var{port}}
22301 @itemx target remote @code{udp:[@var{host}]:@var{port}}
22302 @itemx target remote @code{udp4:@var{host}:@var{port}}
22303 @itemx target remote @code{udp6:[@var{host}]:@var{port}}
22304 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
22305 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
22306 @itemx target extended-remote @code{udp:[@var{host}]:@var{port}}
22307 @itemx target extended-remote @code{udp4:@var{host}:@var{port}}
22308 @itemx target extended-remote @code{udp6:@var{host}:@var{port}}
22309 @itemx target extended-remote @code{udp6:[@var{host}]:@var{port}}
22310 @cindex @acronym{UDP} port, @code{target remote}
22311 Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
22312 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
22313
22314 @smallexample
22315 target remote udp:manyfarms:2828
22316 @end smallexample
22317
22318 When using a @acronym{UDP} connection for remote debugging, you should
22319 keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
22320 can silently drop packets on busy or unreliable networks, which will
22321 cause havoc with your debugging session.
22322
22323 @item target remote | @var{command}
22324 @itemx target extended-remote | @var{command}
22325 @cindex pipe, @code{target remote} to
22326 Run @var{command} in the background and communicate with it using a
22327 pipe. The @var{command} is a shell command, to be parsed and expanded
22328 by the system's command shell, @code{/bin/sh}; it should expect remote
22329 protocol packets on its standard input, and send replies on its
22330 standard output. You could use this to run a stand-alone simulator
22331 that speaks the remote debugging protocol, to make net connections
22332 using programs like @code{ssh}, or for other similar tricks.
22333
22334 If @var{command} closes its standard output (perhaps by exiting),
22335 @value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
22336 program has already exited, this will have no effect.)
22337
22338 @end table
22339
22340 @cindex interrupting remote programs
22341 @cindex remote programs, interrupting
22342 Whenever @value{GDBN} is waiting for the remote program, if you type the
22343 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
22344 program. This may or may not succeed, depending in part on the hardware
22345 and the serial drivers the remote system uses. If you type the
22346 interrupt character once again, @value{GDBN} displays this prompt:
22347
22348 @smallexample
22349 Interrupted while waiting for the program.
22350 Give up (and stop debugging it)? (y or n)
22351 @end smallexample
22352
22353 In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22354 the remote debugging session. (If you decide you want to try again later,
22355 you can use @kbd{target remote} again to connect once more.) If you type
22356 @kbd{n}, @value{GDBN} goes back to waiting.
22357
22358 In @code{target extended-remote} mode, typing @kbd{n} will leave
22359 @value{GDBN} connected to the target.
22360
22361 @table @code
22362 @kindex detach (remote)
22363 @item detach
22364 When you have finished debugging the remote program, you can use the
22365 @code{detach} command to release it from @value{GDBN} control.
22366 Detaching from the target normally resumes its execution, but the results
22367 will depend on your particular remote stub. After the @code{detach}
22368 command in @code{target remote} mode, @value{GDBN} is free to connect to
22369 another target. In @code{target extended-remote} mode, @value{GDBN} is
22370 still connected to the target.
22371
22372 @kindex disconnect
22373 @item disconnect
22374 The @code{disconnect} command closes the connection to the target, and
22375 the target is generally not resumed. It will wait for @value{GDBN}
22376 (this instance or another one) to connect and continue debugging. After
22377 the @code{disconnect} command, @value{GDBN} is again free to connect to
22378 another target.
22379
22380 @cindex send command to remote monitor
22381 @cindex extend @value{GDBN} for remote targets
22382 @cindex add new commands for external monitor
22383 @kindex monitor
22384 @item monitor @var{cmd}
22385 This command allows you to send arbitrary commands directly to the
22386 remote monitor. Since @value{GDBN} doesn't care about the commands it
22387 sends like this, this command is the way to extend @value{GDBN}---you
22388 can add new commands that only the external monitor will understand
22389 and implement.
22390 @end table
22391
22392 @node File Transfer
22393 @section Sending files to a remote system
22394 @cindex remote target, file transfer
22395 @cindex file transfer
22396 @cindex sending files to remote systems
22397
22398 Some remote targets offer the ability to transfer files over the same
22399 connection used to communicate with @value{GDBN}. This is convenient
22400 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
22401 running @code{gdbserver} over a network interface. For other targets,
22402 e.g.@: embedded devices with only a single serial port, this may be
22403 the only way to upload or download files.
22404
22405 Not all remote targets support these commands.
22406
22407 @table @code
22408 @kindex remote put
22409 @item remote put @var{hostfile} @var{targetfile}
22410 Copy file @var{hostfile} from the host system (the machine running
22411 @value{GDBN}) to @var{targetfile} on the target system.
22412
22413 @kindex remote get
22414 @item remote get @var{targetfile} @var{hostfile}
22415 Copy file @var{targetfile} from the target system to @var{hostfile}
22416 on the host system.
22417
22418 @kindex remote delete
22419 @item remote delete @var{targetfile}
22420 Delete @var{targetfile} from the target system.
22421
22422 @end table
22423
22424 @node Server
22425 @section Using the @code{gdbserver} Program
22426
22427 @kindex gdbserver
22428 @cindex remote connection without stubs
22429 @code{gdbserver} is a control program for Unix-like systems, which
22430 allows you to connect your program with a remote @value{GDBN} via
22431 @code{target remote} or @code{target extended-remote}---but without
22432 linking in the usual debugging stub.
22433
22434 @code{gdbserver} is not a complete replacement for the debugging stubs,
22435 because it requires essentially the same operating-system facilities
22436 that @value{GDBN} itself does. In fact, a system that can run
22437 @code{gdbserver} to connect to a remote @value{GDBN} could also run
22438 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
22439 because it is a much smaller program than @value{GDBN} itself. It is
22440 also easier to port than all of @value{GDBN}, so you may be able to get
22441 started more quickly on a new system by using @code{gdbserver}.
22442 Finally, if you develop code for real-time systems, you may find that
22443 the tradeoffs involved in real-time operation make it more convenient to
22444 do as much development work as possible on another system, for example
22445 by cross-compiling. You can use @code{gdbserver} to make a similar
22446 choice for debugging.
22447
22448 @value{GDBN} and @code{gdbserver} communicate via either a serial line
22449 or a TCP connection, using the standard @value{GDBN} remote serial
22450 protocol.
22451
22452 @quotation
22453 @emph{Warning:} @code{gdbserver} does not have any built-in security.
22454 Do not run @code{gdbserver} connected to any public network; a
22455 @value{GDBN} connection to @code{gdbserver} provides access to the
22456 target system with the same privileges as the user running
22457 @code{gdbserver}.
22458 @end quotation
22459
22460 @anchor{Running gdbserver}
22461 @subsection Running @code{gdbserver}
22462 @cindex arguments, to @code{gdbserver}
22463 @cindex @code{gdbserver}, command-line arguments
22464
22465 Run @code{gdbserver} on the target system. You need a copy of the
22466 program you want to debug, including any libraries it requires.
22467 @code{gdbserver} does not need your program's symbol table, so you can
22468 strip the program if necessary to save space. @value{GDBN} on the host
22469 system does all the symbol handling.
22470
22471 To use the server, you must tell it how to communicate with @value{GDBN};
22472 the name of your program; and the arguments for your program. The usual
22473 syntax is:
22474
22475 @smallexample
22476 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
22477 @end smallexample
22478
22479 @var{comm} is either a device name (to use a serial line), or a TCP
22480 hostname and portnumber, or @code{-} or @code{stdio} to use
22481 stdin/stdout of @code{gdbserver}.
22482 For example, to debug Emacs with the argument
22483 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
22484 @file{/dev/com1}:
22485
22486 @smallexample
22487 target> gdbserver /dev/com1 emacs foo.txt
22488 @end smallexample
22489
22490 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
22491 with it.
22492
22493 To use a TCP connection instead of a serial line:
22494
22495 @smallexample
22496 target> gdbserver host:2345 emacs foo.txt
22497 @end smallexample
22498
22499 The only difference from the previous example is the first argument,
22500 specifying that you are communicating with the host @value{GDBN} via
22501 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
22502 expect a TCP connection from machine @samp{host} to local TCP port 2345.
22503 (Currently, the @samp{host} part is ignored.) You can choose any number
22504 you want for the port number as long as it does not conflict with any
22505 TCP ports already in use on the target system (for example, @code{23} is
22506 reserved for @code{telnet}).@footnote{If you choose a port number that
22507 conflicts with another service, @code{gdbserver} prints an error message
22508 and exits.} You must use the same port number with the host @value{GDBN}
22509 @code{target remote} command.
22510
22511 The @code{stdio} connection is useful when starting @code{gdbserver}
22512 with ssh:
22513
22514 @smallexample
22515 (gdb) target remote | ssh -T hostname gdbserver - hello
22516 @end smallexample
22517
22518 The @samp{-T} option to ssh is provided because we don't need a remote pty,
22519 and we don't want escape-character handling. Ssh does this by default when
22520 a command is provided, the flag is provided to make it explicit.
22521 You could elide it if you want to.
22522
22523 Programs started with stdio-connected gdbserver have @file{/dev/null} for
22524 @code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
22525 display through a pipe connected to gdbserver.
22526 Both @code{stdout} and @code{stderr} use the same pipe.
22527
22528 @anchor{Attaching to a program}
22529 @subsubsection Attaching to a Running Program
22530 @cindex attach to a program, @code{gdbserver}
22531 @cindex @option{--attach}, @code{gdbserver} option
22532
22533 On some targets, @code{gdbserver} can also attach to running programs.
22534 This is accomplished via the @code{--attach} argument. The syntax is:
22535
22536 @smallexample
22537 target> gdbserver --attach @var{comm} @var{pid}
22538 @end smallexample
22539
22540 @var{pid} is the process ID of a currently running process. It isn't
22541 necessary to point @code{gdbserver} at a binary for the running process.
22542
22543 In @code{target extended-remote} mode, you can also attach using the
22544 @value{GDBN} attach command
22545 (@pxref{Attaching in Types of Remote Connections}).
22546
22547 @pindex pidof
22548 You can debug processes by name instead of process ID if your target has the
22549 @code{pidof} utility:
22550
22551 @smallexample
22552 target> gdbserver --attach @var{comm} `pidof @var{program}`
22553 @end smallexample
22554
22555 In case more than one copy of @var{program} is running, or @var{program}
22556 has multiple threads, most versions of @code{pidof} support the
22557 @code{-s} option to only return the first process ID.
22558
22559 @subsubsection TCP port allocation lifecycle of @code{gdbserver}
22560
22561 This section applies only when @code{gdbserver} is run to listen on a TCP
22562 port.
22563
22564 @code{gdbserver} normally terminates after all of its debugged processes have
22565 terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
22566 extended-remote}, @code{gdbserver} stays running even with no processes left.
22567 @value{GDBN} normally terminates the spawned debugged process on its exit,
22568 which normally also terminates @code{gdbserver} in the @kbd{target remote}
22569 mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
22570 cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
22571 stays running even in the @kbd{target remote} mode.
22572
22573 When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
22574 Such reconnecting is useful for features like @ref{disconnected tracing}. For
22575 completeness, at most one @value{GDBN} can be connected at a time.
22576
22577 @cindex @option{--once}, @code{gdbserver} option
22578 By default, @code{gdbserver} keeps the listening TCP port open, so that
22579 subsequent connections are possible. However, if you start @code{gdbserver}
22580 with the @option{--once} option, it will stop listening for any further
22581 connection attempts after connecting to the first @value{GDBN} session. This
22582 means no further connections to @code{gdbserver} will be possible after the
22583 first one. It also means @code{gdbserver} will terminate after the first
22584 connection with remote @value{GDBN} has closed, even for unexpectedly closed
22585 connections and even in the @kbd{target extended-remote} mode. The
22586 @option{--once} option allows reusing the same port number for connecting to
22587 multiple instances of @code{gdbserver} running on the same host, since each
22588 instance closes its port after the first connection.
22589
22590 @anchor{Other Command-Line Arguments for gdbserver}
22591 @subsubsection Other Command-Line Arguments for @code{gdbserver}
22592
22593 You can use the @option{--multi} option to start @code{gdbserver} without
22594 specifying a program to debug or a process to attach to. Then you can
22595 attach in @code{target extended-remote} mode and run or attach to a
22596 program. For more information,
22597 @pxref{--multi Option in Types of Remote Connnections}.
22598
22599 @cindex @option{--debug}, @code{gdbserver} option
22600 The @option{--debug} option tells @code{gdbserver} to display extra
22601 status information about the debugging process.
22602 @cindex @option{--remote-debug}, @code{gdbserver} option
22603 The @option{--remote-debug} option tells @code{gdbserver} to display
22604 remote protocol debug output.
22605 @cindex @option{--debug-file}, @code{gdbserver} option
22606 @cindex @code{gdbserver}, send all debug output to a single file
22607 The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
22608 write any debug output to the given @var{filename}. These options are intended
22609 for @code{gdbserver} development and for bug reports to the developers.
22610
22611 @cindex @option{--debug-format}, @code{gdbserver} option
22612 The @option{--debug-format=option1[,option2,...]} option tells
22613 @code{gdbserver} to include additional information in each output.
22614 Possible options are:
22615
22616 @table @code
22617 @item none
22618 Turn off all extra information in debugging output.
22619 @item all
22620 Turn on all extra information in debugging output.
22621 @item timestamps
22622 Include a timestamp in each line of debugging output.
22623 @end table
22624
22625 Options are processed in order. Thus, for example, if @option{none}
22626 appears last then no additional information is added to debugging output.
22627
22628 @cindex @option{--wrapper}, @code{gdbserver} option
22629 The @option{--wrapper} option specifies a wrapper to launch programs
22630 for debugging. The option should be followed by the name of the
22631 wrapper, then any command-line arguments to pass to the wrapper, then
22632 @kbd{--} indicating the end of the wrapper arguments.
22633
22634 @code{gdbserver} runs the specified wrapper program with a combined
22635 command line including the wrapper arguments, then the name of the
22636 program to debug, then any arguments to the program. The wrapper
22637 runs until it executes your program, and then @value{GDBN} gains control.
22638
22639 You can use any program that eventually calls @code{execve} with
22640 its arguments as a wrapper. Several standard Unix utilities do
22641 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
22642 with @code{exec "$@@"} will also work.
22643
22644 For example, you can use @code{env} to pass an environment variable to
22645 the debugged program, without setting the variable in @code{gdbserver}'s
22646 environment:
22647
22648 @smallexample
22649 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
22650 @end smallexample
22651
22652 @cindex @option{--selftest}
22653 The @option{--selftest} option runs the self tests in @code{gdbserver}:
22654
22655 @smallexample
22656 $ gdbserver --selftest
22657 Ran 2 unit tests, 0 failed
22658 @end smallexample
22659
22660 These tests are disabled in release.
22661 @subsection Connecting to @code{gdbserver}
22662
22663 The basic procedure for connecting to the remote target is:
22664 @itemize
22665
22666 @item
22667 Run @value{GDBN} on the host system.
22668
22669 @item
22670 Make sure you have the necessary symbol files
22671 (@pxref{Host and target files}).
22672 Load symbols for your application using the @code{file} command before you
22673 connect. Use @code{set sysroot} to locate target libraries (unless your
22674 @value{GDBN} was compiled with the correct sysroot using
22675 @code{--with-sysroot}).
22676
22677 @item
22678 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
22679 For TCP connections, you must start up @code{gdbserver} prior to using
22680 the @code{target} command. Otherwise you may get an error whose
22681 text depends on the host system, but which usually looks something like
22682 @samp{Connection refused}. Don't use the @code{load}
22683 command in @value{GDBN} when using @code{target remote} mode, since the
22684 program is already on the target.
22685
22686 @end itemize
22687
22688 @anchor{Monitor Commands for gdbserver}
22689 @subsection Monitor Commands for @code{gdbserver}
22690 @cindex monitor commands, for @code{gdbserver}
22691
22692 During a @value{GDBN} session using @code{gdbserver}, you can use the
22693 @code{monitor} command to send special requests to @code{gdbserver}.
22694 Here are the available commands.
22695
22696 @table @code
22697 @item monitor help
22698 List the available monitor commands.
22699
22700 @item monitor set debug 0
22701 @itemx monitor set debug 1
22702 Disable or enable general debugging messages.
22703
22704 @item monitor set remote-debug 0
22705 @itemx monitor set remote-debug 1
22706 Disable or enable specific debugging messages associated with the remote
22707 protocol (@pxref{Remote Protocol}).
22708
22709 @item monitor set debug-file filename
22710 @itemx monitor set debug-file
22711 Send any debug output to the given file, or to stderr.
22712
22713 @item monitor set debug-format option1@r{[},option2,...@r{]}
22714 Specify additional text to add to debugging messages.
22715 Possible options are:
22716
22717 @table @code
22718 @item none
22719 Turn off all extra information in debugging output.
22720 @item all
22721 Turn on all extra information in debugging output.
22722 @item timestamps
22723 Include a timestamp in each line of debugging output.
22724 @end table
22725
22726 Options are processed in order. Thus, for example, if @option{none}
22727 appears last then no additional information is added to debugging output.
22728
22729 @item monitor set libthread-db-search-path [PATH]
22730 @cindex gdbserver, search path for @code{libthread_db}
22731 When this command is issued, @var{path} is a colon-separated list of
22732 directories to search for @code{libthread_db} (@pxref{Threads,,set
22733 libthread-db-search-path}). If you omit @var{path},
22734 @samp{libthread-db-search-path} will be reset to its default value.
22735
22736 The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
22737 not supported in @code{gdbserver}.
22738
22739 @item monitor exit
22740 Tell gdbserver to exit immediately. This command should be followed by
22741 @code{disconnect} to close the debugging session. @code{gdbserver} will
22742 detach from any attached processes and kill any processes it created.
22743 Use @code{monitor exit} to terminate @code{gdbserver} at the end
22744 of a multi-process mode debug session.
22745
22746 @end table
22747
22748 @subsection Tracepoints support in @code{gdbserver}
22749 @cindex tracepoints support in @code{gdbserver}
22750
22751 On some targets, @code{gdbserver} supports tracepoints, fast
22752 tracepoints and static tracepoints.
22753
22754 For fast or static tracepoints to work, a special library called the
22755 @dfn{in-process agent} (IPA), must be loaded in the inferior process.
22756 This library is built and distributed as an integral part of
22757 @code{gdbserver}. In addition, support for static tracepoints
22758 requires building the in-process agent library with static tracepoints
22759 support. At present, the UST (LTTng Userspace Tracer,
22760 @url{http://lttng.org/ust}) tracing engine is supported. This support
22761 is automatically available if UST development headers are found in the
22762 standard include path when @code{gdbserver} is built, or if
22763 @code{gdbserver} was explicitly configured using @option{--with-ust}
22764 to point at such headers. You can explicitly disable the support
22765 using @option{--with-ust=no}.
22766
22767 There are several ways to load the in-process agent in your program:
22768
22769 @table @code
22770 @item Specifying it as dependency at link time
22771
22772 You can link your program dynamically with the in-process agent
22773 library. On most systems, this is accomplished by adding
22774 @code{-linproctrace} to the link command.
22775
22776 @item Using the system's preloading mechanisms
22777
22778 You can force loading the in-process agent at startup time by using
22779 your system's support for preloading shared libraries. Many Unixes
22780 support the concept of preloading user defined libraries. In most
22781 cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
22782 in the environment. See also the description of @code{gdbserver}'s
22783 @option{--wrapper} command line option.
22784
22785 @item Using @value{GDBN} to force loading the agent at run time
22786
22787 On some systems, you can force the inferior to load a shared library,
22788 by calling a dynamic loader function in the inferior that takes care
22789 of dynamically looking up and loading a shared library. On most Unix
22790 systems, the function is @code{dlopen}. You'll use the @code{call}
22791 command for that. For example:
22792
22793 @smallexample
22794 (@value{GDBP}) call dlopen ("libinproctrace.so", ...)
22795 @end smallexample
22796
22797 Note that on most Unix systems, for the @code{dlopen} function to be
22798 available, the program needs to be linked with @code{-ldl}.
22799 @end table
22800
22801 On systems that have a userspace dynamic loader, like most Unix
22802 systems, when you connect to @code{gdbserver} using @code{target
22803 remote}, you'll find that the program is stopped at the dynamic
22804 loader's entry point, and no shared library has been loaded in the
22805 program's address space yet, including the in-process agent. In that
22806 case, before being able to use any of the fast or static tracepoints
22807 features, you need to let the loader run and load the shared
22808 libraries. The simplest way to do that is to run the program to the
22809 main procedure. E.g., if debugging a C or C@t{++} program, start
22810 @code{gdbserver} like so:
22811
22812 @smallexample
22813 $ gdbserver :9999 myprogram
22814 @end smallexample
22815
22816 Start GDB and connect to @code{gdbserver} like so, and run to main:
22817
22818 @smallexample
22819 $ gdb myprogram
22820 (@value{GDBP}) target remote myhost:9999
22821 0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
22822 (@value{GDBP}) b main
22823 (@value{GDBP}) continue
22824 @end smallexample
22825
22826 The in-process tracing agent library should now be loaded into the
22827 process; you can confirm it with the @code{info sharedlibrary}
22828 command, which will list @file{libinproctrace.so} as loaded in the
22829 process. You are now ready to install fast tracepoints, list static
22830 tracepoint markers, probe static tracepoints markers, and start
22831 tracing.
22832
22833 @node Remote Configuration
22834 @section Remote Configuration
22835
22836 @kindex set remote
22837 @kindex show remote
22838 This section documents the configuration options available when
22839 debugging remote programs. For the options related to the File I/O
22840 extensions of the remote protocol, see @ref{system,
22841 system-call-allowed}.
22842
22843 @table @code
22844 @item set remoteaddresssize @var{bits}
22845 @cindex address size for remote targets
22846 @cindex bits in remote address
22847 Set the maximum size of address in a memory packet to the specified
22848 number of bits. @value{GDBN} will mask off the address bits above
22849 that number, when it passes addresses to the remote target. The
22850 default value is the number of bits in the target's address.
22851
22852 @item show remoteaddresssize
22853 Show the current value of remote address size in bits.
22854
22855 @item set serial baud @var{n}
22856 @cindex baud rate for remote targets
22857 Set the baud rate for the remote serial I/O to @var{n} baud. The
22858 value is used to set the speed of the serial port used for debugging
22859 remote targets.
22860
22861 @item show serial baud
22862 Show the current speed of the remote connection.
22863
22864 @item set serial parity @var{parity}
22865 Set the parity for the remote serial I/O. Supported values of @var{parity} are:
22866 @code{even}, @code{none}, and @code{odd}. The default is @code{none}.
22867
22868 @item show serial parity
22869 Show the current parity of the serial port.
22870
22871 @item set remotebreak
22872 @cindex interrupt remote programs
22873 @cindex BREAK signal instead of Ctrl-C
22874 @anchor{set remotebreak}
22875 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
22876 when you type @kbd{Ctrl-c} to interrupt the program running
22877 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
22878 character instead. The default is off, since most remote systems
22879 expect to see @samp{Ctrl-C} as the interrupt signal.
22880
22881 @item show remotebreak
22882 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
22883 interrupt the remote program.
22884
22885 @item set remoteflow on
22886 @itemx set remoteflow off
22887 @kindex set remoteflow
22888 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
22889 on the serial port used to communicate to the remote target.
22890
22891 @item show remoteflow
22892 @kindex show remoteflow
22893 Show the current setting of hardware flow control.
22894
22895 @item set remotelogbase @var{base}
22896 Set the base (a.k.a.@: radix) of logging serial protocol
22897 communications to @var{base}. Supported values of @var{base} are:
22898 @code{ascii}, @code{octal}, and @code{hex}. The default is
22899 @code{ascii}.
22900
22901 @item show remotelogbase
22902 Show the current setting of the radix for logging remote serial
22903 protocol.
22904
22905 @item set remotelogfile @var{file}
22906 @cindex record serial communications on file
22907 Record remote serial communications on the named @var{file}. The
22908 default is not to record at all.
22909
22910 @item show remotelogfile
22911 Show the current setting of the file name on which to record the
22912 serial communications.
22913
22914 @item set remotetimeout @var{num}
22915 @cindex timeout for serial communications
22916 @cindex remote timeout
22917 Set the timeout limit to wait for the remote target to respond to
22918 @var{num} seconds. The default is 2 seconds.
22919
22920 @item show remotetimeout
22921 Show the current number of seconds to wait for the remote target
22922 responses.
22923
22924 @cindex limit hardware breakpoints and watchpoints
22925 @cindex remote target, limit break- and watchpoints
22926 @anchor{set remote hardware-watchpoint-limit}
22927 @anchor{set remote hardware-breakpoint-limit}
22928 @item set remote hardware-watchpoint-limit @var{limit}
22929 @itemx set remote hardware-breakpoint-limit @var{limit}
22930 Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
22931 or breakpoints. The @var{limit} can be set to 0 to disable hardware
22932 watchpoints or breakpoints, and @code{unlimited} for unlimited
22933 watchpoints or breakpoints.
22934
22935 @item show remote hardware-watchpoint-limit
22936 @itemx show remote hardware-breakpoint-limit
22937 Show the current limit for the number of hardware watchpoints or
22938 breakpoints that @value{GDBN} can use.
22939
22940 @cindex limit hardware watchpoints length
22941 @cindex remote target, limit watchpoints length
22942 @anchor{set remote hardware-watchpoint-length-limit}
22943 @item set remote hardware-watchpoint-length-limit @var{limit}
22944 Restrict @value{GDBN} to using @var{limit} bytes for the maximum
22945 length of a remote hardware watchpoint. A @var{limit} of 0 disables
22946 hardware watchpoints and @code{unlimited} allows watchpoints of any
22947 length.
22948
22949 @item show remote hardware-watchpoint-length-limit
22950 Show the current limit (in bytes) of the maximum length of
22951 a remote hardware watchpoint.
22952
22953 @item set remote exec-file @var{filename}
22954 @itemx show remote exec-file
22955 @anchor{set remote exec-file}
22956 @cindex executable file, for remote target
22957 Select the file used for @code{run} with @code{target
22958 extended-remote}. This should be set to a filename valid on the
22959 target system. If it is not set, the target will use a default
22960 filename (e.g.@: the last program run).
22961
22962 @item set remote interrupt-sequence
22963 @cindex interrupt remote programs
22964 @cindex select Ctrl-C, BREAK or BREAK-g
22965 Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
22966 @samp{BREAK-g} as the
22967 sequence to the remote target in order to interrupt the execution.
22968 @samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
22969 is high level of serial line for some certain time.
22970 Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
22971 It is @code{BREAK} signal followed by character @code{g}.
22972
22973 @item show interrupt-sequence
22974 Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
22975 is sent by @value{GDBN} to interrupt the remote program.
22976 @code{BREAK-g} is BREAK signal followed by @code{g} and
22977 also known as Magic SysRq g.
22978
22979 @item set remote interrupt-on-connect
22980 @cindex send interrupt-sequence on start
22981 Specify whether interrupt-sequence is sent to remote target when
22982 @value{GDBN} connects to it. This is mostly needed when you debug
22983 Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
22984 which is known as Magic SysRq g in order to connect @value{GDBN}.
22985
22986 @item show interrupt-on-connect
22987 Show whether interrupt-sequence is sent
22988 to remote target when @value{GDBN} connects to it.
22989
22990 @kindex set tcp
22991 @kindex show tcp
22992 @item set tcp auto-retry on
22993 @cindex auto-retry, for remote TCP target
22994 Enable auto-retry for remote TCP connections. This is useful if the remote
22995 debugging agent is launched in parallel with @value{GDBN}; there is a race
22996 condition because the agent may not become ready to accept the connection
22997 before @value{GDBN} attempts to connect. When auto-retry is
22998 enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
22999 to establish the connection using the timeout specified by
23000 @code{set tcp connect-timeout}.
23001
23002 @item set tcp auto-retry off
23003 Do not auto-retry failed TCP connections.
23004
23005 @item show tcp auto-retry
23006 Show the current auto-retry setting.
23007
23008 @item set tcp connect-timeout @var{seconds}
23009 @itemx set tcp connect-timeout unlimited
23010 @cindex connection timeout, for remote TCP target
23011 @cindex timeout, for remote target connection
23012 Set the timeout for establishing a TCP connection to the remote target to
23013 @var{seconds}. The timeout affects both polling to retry failed connections
23014 (enabled by @code{set tcp auto-retry on}) and waiting for connections
23015 that are merely slow to complete, and represents an approximate cumulative
23016 value. If @var{seconds} is @code{unlimited}, there is no timeout and
23017 @value{GDBN} will keep attempting to establish a connection forever,
23018 unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
23019
23020 @item show tcp connect-timeout
23021 Show the current connection timeout setting.
23022 @end table
23023
23024 @cindex remote packets, enabling and disabling
23025 The @value{GDBN} remote protocol autodetects the packets supported by
23026 your debugging stub. If you need to override the autodetection, you
23027 can use these commands to enable or disable individual packets. Each
23028 packet can be set to @samp{on} (the remote target supports this
23029 packet), @samp{off} (the remote target does not support this packet),
23030 or @samp{auto} (detect remote target support for this packet). They
23031 all default to @samp{auto}. For more information about each packet,
23032 see @ref{Remote Protocol}.
23033
23034 During normal use, you should not have to use any of these commands.
23035 If you do, that may be a bug in your remote debugging stub, or a bug
23036 in @value{GDBN}. You may want to report the problem to the
23037 @value{GDBN} developers.
23038
23039 For each packet @var{name}, the command to enable or disable the
23040 packet is @code{set remote @var{name}-packet}. The available settings
23041 are:
23042
23043 @multitable @columnfractions 0.28 0.32 0.25
23044 @item Command Name
23045 @tab Remote Packet
23046 @tab Related Features
23047
23048 @item @code{fetch-register}
23049 @tab @code{p}
23050 @tab @code{info registers}
23051
23052 @item @code{set-register}
23053 @tab @code{P}
23054 @tab @code{set}
23055
23056 @item @code{binary-download}
23057 @tab @code{X}
23058 @tab @code{load}, @code{set}
23059
23060 @item @code{read-aux-vector}
23061 @tab @code{qXfer:auxv:read}
23062 @tab @code{info auxv}
23063
23064 @item @code{symbol-lookup}
23065 @tab @code{qSymbol}
23066 @tab Detecting multiple threads
23067
23068 @item @code{attach}
23069 @tab @code{vAttach}
23070 @tab @code{attach}
23071
23072 @item @code{verbose-resume}
23073 @tab @code{vCont}
23074 @tab Stepping or resuming multiple threads
23075
23076 @item @code{run}
23077 @tab @code{vRun}
23078 @tab @code{run}
23079
23080 @item @code{software-breakpoint}
23081 @tab @code{Z0}
23082 @tab @code{break}
23083
23084 @item @code{hardware-breakpoint}
23085 @tab @code{Z1}
23086 @tab @code{hbreak}
23087
23088 @item @code{write-watchpoint}
23089 @tab @code{Z2}
23090 @tab @code{watch}
23091
23092 @item @code{read-watchpoint}
23093 @tab @code{Z3}
23094 @tab @code{rwatch}
23095
23096 @item @code{access-watchpoint}
23097 @tab @code{Z4}
23098 @tab @code{awatch}
23099
23100 @item @code{pid-to-exec-file}
23101 @tab @code{qXfer:exec-file:read}
23102 @tab @code{attach}, @code{run}
23103
23104 @item @code{target-features}
23105 @tab @code{qXfer:features:read}
23106 @tab @code{set architecture}
23107
23108 @item @code{library-info}
23109 @tab @code{qXfer:libraries:read}
23110 @tab @code{info sharedlibrary}
23111
23112 @item @code{memory-map}
23113 @tab @code{qXfer:memory-map:read}
23114 @tab @code{info mem}
23115
23116 @item @code{read-sdata-object}
23117 @tab @code{qXfer:sdata:read}
23118 @tab @code{print $_sdata}
23119
23120 @item @code{read-siginfo-object}
23121 @tab @code{qXfer:siginfo:read}
23122 @tab @code{print $_siginfo}
23123
23124 @item @code{write-siginfo-object}
23125 @tab @code{qXfer:siginfo:write}
23126 @tab @code{set $_siginfo}
23127
23128 @item @code{threads}
23129 @tab @code{qXfer:threads:read}
23130 @tab @code{info threads}
23131
23132 @item @code{get-thread-local-@*storage-address}
23133 @tab @code{qGetTLSAddr}
23134 @tab Displaying @code{__thread} variables
23135
23136 @item @code{get-thread-information-block-address}
23137 @tab @code{qGetTIBAddr}
23138 @tab Display MS-Windows Thread Information Block.
23139
23140 @item @code{search-memory}
23141 @tab @code{qSearch:memory}
23142 @tab @code{find}
23143
23144 @item @code{supported-packets}
23145 @tab @code{qSupported}
23146 @tab Remote communications parameters
23147
23148 @item @code{catch-syscalls}
23149 @tab @code{QCatchSyscalls}
23150 @tab @code{catch syscall}
23151
23152 @item @code{pass-signals}
23153 @tab @code{QPassSignals}
23154 @tab @code{handle @var{signal}}
23155
23156 @item @code{program-signals}
23157 @tab @code{QProgramSignals}
23158 @tab @code{handle @var{signal}}
23159
23160 @item @code{hostio-close-packet}
23161 @tab @code{vFile:close}
23162 @tab @code{remote get}, @code{remote put}
23163
23164 @item @code{hostio-open-packet}
23165 @tab @code{vFile:open}
23166 @tab @code{remote get}, @code{remote put}
23167
23168 @item @code{hostio-pread-packet}
23169 @tab @code{vFile:pread}
23170 @tab @code{remote get}, @code{remote put}
23171
23172 @item @code{hostio-pwrite-packet}
23173 @tab @code{vFile:pwrite}
23174 @tab @code{remote get}, @code{remote put}
23175
23176 @item @code{hostio-unlink-packet}
23177 @tab @code{vFile:unlink}
23178 @tab @code{remote delete}
23179
23180 @item @code{hostio-readlink-packet}
23181 @tab @code{vFile:readlink}
23182 @tab Host I/O
23183
23184 @item @code{hostio-fstat-packet}
23185 @tab @code{vFile:fstat}
23186 @tab Host I/O
23187
23188 @item @code{hostio-setfs-packet}
23189 @tab @code{vFile:setfs}
23190 @tab Host I/O
23191
23192 @item @code{noack-packet}
23193 @tab @code{QStartNoAckMode}
23194 @tab Packet acknowledgment
23195
23196 @item @code{osdata}
23197 @tab @code{qXfer:osdata:read}
23198 @tab @code{info os}
23199
23200 @item @code{query-attached}
23201 @tab @code{qAttached}
23202 @tab Querying remote process attach state.
23203
23204 @item @code{trace-buffer-size}
23205 @tab @code{QTBuffer:size}
23206 @tab @code{set trace-buffer-size}
23207
23208 @item @code{trace-status}
23209 @tab @code{qTStatus}
23210 @tab @code{tstatus}
23211
23212 @item @code{traceframe-info}
23213 @tab @code{qXfer:traceframe-info:read}
23214 @tab Traceframe info
23215
23216 @item @code{install-in-trace}
23217 @tab @code{InstallInTrace}
23218 @tab Install tracepoint in tracing
23219
23220 @item @code{disable-randomization}
23221 @tab @code{QDisableRandomization}
23222 @tab @code{set disable-randomization}
23223
23224 @item @code{startup-with-shell}
23225 @tab @code{QStartupWithShell}
23226 @tab @code{set startup-with-shell}
23227
23228 @item @code{environment-hex-encoded}
23229 @tab @code{QEnvironmentHexEncoded}
23230 @tab @code{set environment}
23231
23232 @item @code{environment-unset}
23233 @tab @code{QEnvironmentUnset}
23234 @tab @code{unset environment}
23235
23236 @item @code{environment-reset}
23237 @tab @code{QEnvironmentReset}
23238 @tab @code{Reset the inferior environment (i.e., unset user-set variables)}
23239
23240 @item @code{set-working-dir}
23241 @tab @code{QSetWorkingDir}
23242 @tab @code{set cwd}
23243
23244 @item @code{conditional-breakpoints-packet}
23245 @tab @code{Z0 and Z1}
23246 @tab @code{Support for target-side breakpoint condition evaluation}
23247
23248 @item @code{multiprocess-extensions}
23249 @tab @code{multiprocess extensions}
23250 @tab Debug multiple processes and remote process PID awareness
23251
23252 @item @code{swbreak-feature}
23253 @tab @code{swbreak stop reason}
23254 @tab @code{break}
23255
23256 @item @code{hwbreak-feature}
23257 @tab @code{hwbreak stop reason}
23258 @tab @code{hbreak}
23259
23260 @item @code{fork-event-feature}
23261 @tab @code{fork stop reason}
23262 @tab @code{fork}
23263
23264 @item @code{vfork-event-feature}
23265 @tab @code{vfork stop reason}
23266 @tab @code{vfork}
23267
23268 @item @code{exec-event-feature}
23269 @tab @code{exec stop reason}
23270 @tab @code{exec}
23271
23272 @item @code{thread-events}
23273 @tab @code{QThreadEvents}
23274 @tab Tracking thread lifetime.
23275
23276 @item @code{no-resumed-stop-reply}
23277 @tab @code{no resumed thread left stop reply}
23278 @tab Tracking thread lifetime.
23279
23280 @end multitable
23281
23282 @node Remote Stub
23283 @section Implementing a Remote Stub
23284
23285 @cindex debugging stub, example
23286 @cindex remote stub, example
23287 @cindex stub example, remote debugging
23288 The stub files provided with @value{GDBN} implement the target side of the
23289 communication protocol, and the @value{GDBN} side is implemented in the
23290 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
23291 these subroutines to communicate, and ignore the details. (If you're
23292 implementing your own stub file, you can still ignore the details: start
23293 with one of the existing stub files. @file{sparc-stub.c} is the best
23294 organized, and therefore the easiest to read.)
23295
23296 @cindex remote serial debugging, overview
23297 To debug a program running on another machine (the debugging
23298 @dfn{target} machine), you must first arrange for all the usual
23299 prerequisites for the program to run by itself. For example, for a C
23300 program, you need:
23301
23302 @enumerate
23303 @item
23304 A startup routine to set up the C runtime environment; these usually
23305 have a name like @file{crt0}. The startup routine may be supplied by
23306 your hardware supplier, or you may have to write your own.
23307
23308 @item
23309 A C subroutine library to support your program's
23310 subroutine calls, notably managing input and output.
23311
23312 @item
23313 A way of getting your program to the other machine---for example, a
23314 download program. These are often supplied by the hardware
23315 manufacturer, but you may have to write your own from hardware
23316 documentation.
23317 @end enumerate
23318
23319 The next step is to arrange for your program to use a serial port to
23320 communicate with the machine where @value{GDBN} is running (the @dfn{host}
23321 machine). In general terms, the scheme looks like this:
23322
23323 @table @emph
23324 @item On the host,
23325 @value{GDBN} already understands how to use this protocol; when everything
23326 else is set up, you can simply use the @samp{target remote} command
23327 (@pxref{Targets,,Specifying a Debugging Target}).
23328
23329 @item On the target,
23330 you must link with your program a few special-purpose subroutines that
23331 implement the @value{GDBN} remote serial protocol. The file containing these
23332 subroutines is called a @dfn{debugging stub}.
23333
23334 On certain remote targets, you can use an auxiliary program
23335 @code{gdbserver} instead of linking a stub into your program.
23336 @xref{Server,,Using the @code{gdbserver} Program}, for details.
23337 @end table
23338
23339 The debugging stub is specific to the architecture of the remote
23340 machine; for example, use @file{sparc-stub.c} to debug programs on
23341 @sc{sparc} boards.
23342
23343 @cindex remote serial stub list
23344 These working remote stubs are distributed with @value{GDBN}:
23345
23346 @table @code
23347
23348 @item i386-stub.c
23349 @cindex @file{i386-stub.c}
23350 @cindex Intel
23351 @cindex i386
23352 For Intel 386 and compatible architectures.
23353
23354 @item m68k-stub.c
23355 @cindex @file{m68k-stub.c}
23356 @cindex Motorola 680x0
23357 @cindex m680x0
23358 For Motorola 680x0 architectures.
23359
23360 @item sh-stub.c
23361 @cindex @file{sh-stub.c}
23362 @cindex Renesas
23363 @cindex SH
23364 For Renesas SH architectures.
23365
23366 @item sparc-stub.c
23367 @cindex @file{sparc-stub.c}
23368 @cindex Sparc
23369 For @sc{sparc} architectures.
23370
23371 @item sparcl-stub.c
23372 @cindex @file{sparcl-stub.c}
23373 @cindex Fujitsu
23374 @cindex SparcLite
23375 For Fujitsu @sc{sparclite} architectures.
23376
23377 @end table
23378
23379 The @file{README} file in the @value{GDBN} distribution may list other
23380 recently added stubs.
23381
23382 @menu
23383 * Stub Contents:: What the stub can do for you
23384 * Bootstrapping:: What you must do for the stub
23385 * Debug Session:: Putting it all together
23386 @end menu
23387
23388 @node Stub Contents
23389 @subsection What the Stub Can Do for You
23390
23391 @cindex remote serial stub
23392 The debugging stub for your architecture supplies these three
23393 subroutines:
23394
23395 @table @code
23396 @item set_debug_traps
23397 @findex set_debug_traps
23398 @cindex remote serial stub, initialization
23399 This routine arranges for @code{handle_exception} to run when your
23400 program stops. You must call this subroutine explicitly in your
23401 program's startup code.
23402
23403 @item handle_exception
23404 @findex handle_exception
23405 @cindex remote serial stub, main routine
23406 This is the central workhorse, but your program never calls it
23407 explicitly---the setup code arranges for @code{handle_exception} to
23408 run when a trap is triggered.
23409
23410 @code{handle_exception} takes control when your program stops during
23411 execution (for example, on a breakpoint), and mediates communications
23412 with @value{GDBN} on the host machine. This is where the communications
23413 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
23414 representative on the target machine. It begins by sending summary
23415 information on the state of your program, then continues to execute,
23416 retrieving and transmitting any information @value{GDBN} needs, until you
23417 execute a @value{GDBN} command that makes your program resume; at that point,
23418 @code{handle_exception} returns control to your own code on the target
23419 machine.
23420
23421 @item breakpoint
23422 @cindex @code{breakpoint} subroutine, remote
23423 Use this auxiliary subroutine to make your program contain a
23424 breakpoint. Depending on the particular situation, this may be the only
23425 way for @value{GDBN} to get control. For instance, if your target
23426 machine has some sort of interrupt button, you won't need to call this;
23427 pressing the interrupt button transfers control to
23428 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
23429 simply receiving characters on the serial port may also trigger a trap;
23430 again, in that situation, you don't need to call @code{breakpoint} from
23431 your own program---simply running @samp{target remote} from the host
23432 @value{GDBN} session gets control.
23433
23434 Call @code{breakpoint} if none of these is true, or if you simply want
23435 to make certain your program stops at a predetermined point for the
23436 start of your debugging session.
23437 @end table
23438
23439 @node Bootstrapping
23440 @subsection What You Must Do for the Stub
23441
23442 @cindex remote stub, support routines
23443 The debugging stubs that come with @value{GDBN} are set up for a particular
23444 chip architecture, but they have no information about the rest of your
23445 debugging target machine.
23446
23447 First of all you need to tell the stub how to communicate with the
23448 serial port.
23449
23450 @table @code
23451 @item int getDebugChar()
23452 @findex getDebugChar
23453 Write this subroutine to read a single character from the serial port.
23454 It may be identical to @code{getchar} for your target system; a
23455 different name is used to allow you to distinguish the two if you wish.
23456
23457 @item void putDebugChar(int)
23458 @findex putDebugChar
23459 Write this subroutine to write a single character to the serial port.
23460 It may be identical to @code{putchar} for your target system; a
23461 different name is used to allow you to distinguish the two if you wish.
23462 @end table
23463
23464 @cindex control C, and remote debugging
23465 @cindex interrupting remote targets
23466 If you want @value{GDBN} to be able to stop your program while it is
23467 running, you need to use an interrupt-driven serial driver, and arrange
23468 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
23469 character). That is the character which @value{GDBN} uses to tell the
23470 remote system to stop.
23471
23472 Getting the debugging target to return the proper status to @value{GDBN}
23473 probably requires changes to the standard stub; one quick and dirty way
23474 is to just execute a breakpoint instruction (the ``dirty'' part is that
23475 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
23476
23477 Other routines you need to supply are:
23478
23479 @table @code
23480 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
23481 @findex exceptionHandler
23482 Write this function to install @var{exception_address} in the exception
23483 handling tables. You need to do this because the stub does not have any
23484 way of knowing what the exception handling tables on your target system
23485 are like (for example, the processor's table might be in @sc{rom},
23486 containing entries which point to a table in @sc{ram}).
23487 The @var{exception_number} specifies the exception which should be changed;
23488 its meaning is architecture-dependent (for example, different numbers
23489 might represent divide by zero, misaligned access, etc). When this
23490 exception occurs, control should be transferred directly to
23491 @var{exception_address}, and the processor state (stack, registers,
23492 and so on) should be just as it is when a processor exception occurs. So if
23493 you want to use a jump instruction to reach @var{exception_address}, it
23494 should be a simple jump, not a jump to subroutine.
23495
23496 For the 386, @var{exception_address} should be installed as an interrupt
23497 gate so that interrupts are masked while the handler runs. The gate
23498 should be at privilege level 0 (the most privileged level). The
23499 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
23500 help from @code{exceptionHandler}.
23501
23502 @item void flush_i_cache()
23503 @findex flush_i_cache
23504 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
23505 instruction cache, if any, on your target machine. If there is no
23506 instruction cache, this subroutine may be a no-op.
23507
23508 On target machines that have instruction caches, @value{GDBN} requires this
23509 function to make certain that the state of your program is stable.
23510 @end table
23511
23512 @noindent
23513 You must also make sure this library routine is available:
23514
23515 @table @code
23516 @item void *memset(void *, int, int)
23517 @findex memset
23518 This is the standard library function @code{memset} that sets an area of
23519 memory to a known value. If you have one of the free versions of
23520 @code{libc.a}, @code{memset} can be found there; otherwise, you must
23521 either obtain it from your hardware manufacturer, or write your own.
23522 @end table
23523
23524 If you do not use the GNU C compiler, you may need other standard
23525 library subroutines as well; this varies from one stub to another,
23526 but in general the stubs are likely to use any of the common library
23527 subroutines which @code{@value{NGCC}} generates as inline code.
23528
23529
23530 @node Debug Session
23531 @subsection Putting it All Together
23532
23533 @cindex remote serial debugging summary
23534 In summary, when your program is ready to debug, you must follow these
23535 steps.
23536
23537 @enumerate
23538 @item
23539 Make sure you have defined the supporting low-level routines
23540 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
23541 @display
23542 @code{getDebugChar}, @code{putDebugChar},
23543 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
23544 @end display
23545
23546 @item
23547 Insert these lines in your program's startup code, before the main
23548 procedure is called:
23549
23550 @smallexample
23551 set_debug_traps();
23552 breakpoint();
23553 @end smallexample
23554
23555 On some machines, when a breakpoint trap is raised, the hardware
23556 automatically makes the PC point to the instruction after the
23557 breakpoint. If your machine doesn't do that, you may need to adjust
23558 @code{handle_exception} to arrange for it to return to the instruction
23559 after the breakpoint on this first invocation, so that your program
23560 doesn't keep hitting the initial breakpoint instead of making
23561 progress.
23562
23563 @item
23564 For the 680x0 stub only, you need to provide a variable called
23565 @code{exceptionHook}. Normally you just use:
23566
23567 @smallexample
23568 void (*exceptionHook)() = 0;
23569 @end smallexample
23570
23571 @noindent
23572 but if before calling @code{set_debug_traps}, you set it to point to a
23573 function in your program, that function is called when
23574 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
23575 error). The function indicated by @code{exceptionHook} is called with
23576 one parameter: an @code{int} which is the exception number.
23577
23578 @item
23579 Compile and link together: your program, the @value{GDBN} debugging stub for
23580 your target architecture, and the supporting subroutines.
23581
23582 @item
23583 Make sure you have a serial connection between your target machine and
23584 the @value{GDBN} host, and identify the serial port on the host.
23585
23586 @item
23587 @c The "remote" target now provides a `load' command, so we should
23588 @c document that. FIXME.
23589 Download your program to your target machine (or get it there by
23590 whatever means the manufacturer provides), and start it.
23591
23592 @item
23593 Start @value{GDBN} on the host, and connect to the target
23594 (@pxref{Connecting,,Connecting to a Remote Target}).
23595
23596 @end enumerate
23597
23598 @node Configurations
23599 @chapter Configuration-Specific Information
23600
23601 While nearly all @value{GDBN} commands are available for all native and
23602 cross versions of the debugger, there are some exceptions. This chapter
23603 describes things that are only available in certain configurations.
23604
23605 There are three major categories of configurations: native
23606 configurations, where the host and target are the same, embedded
23607 operating system configurations, which are usually the same for several
23608 different processor architectures, and bare embedded processors, which
23609 are quite different from each other.
23610
23611 @menu
23612 * Native::
23613 * Embedded OS::
23614 * Embedded Processors::
23615 * Architectures::
23616 @end menu
23617
23618 @node Native
23619 @section Native
23620
23621 This section describes details specific to particular native
23622 configurations.
23623
23624 @menu
23625 * BSD libkvm Interface:: Debugging BSD kernel memory images
23626 * Process Information:: Process information
23627 * DJGPP Native:: Features specific to the DJGPP port
23628 * Cygwin Native:: Features specific to the Cygwin port
23629 * Hurd Native:: Features specific to @sc{gnu} Hurd
23630 * Darwin:: Features specific to Darwin
23631 * FreeBSD:: Features specific to FreeBSD
23632 @end menu
23633
23634 @node BSD libkvm Interface
23635 @subsection BSD libkvm Interface
23636
23637 @cindex libkvm
23638 @cindex kernel memory image
23639 @cindex kernel crash dump
23640
23641 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
23642 interface that provides a uniform interface for accessing kernel virtual
23643 memory images, including live systems and crash dumps. @value{GDBN}
23644 uses this interface to allow you to debug live kernels and kernel crash
23645 dumps on many native BSD configurations. This is implemented as a
23646 special @code{kvm} debugging target. For debugging a live system, load
23647 the currently running kernel into @value{GDBN} and connect to the
23648 @code{kvm} target:
23649
23650 @smallexample
23651 (@value{GDBP}) @b{target kvm}
23652 @end smallexample
23653
23654 For debugging crash dumps, provide the file name of the crash dump as an
23655 argument:
23656
23657 @smallexample
23658 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
23659 @end smallexample
23660
23661 Once connected to the @code{kvm} target, the following commands are
23662 available:
23663
23664 @table @code
23665 @kindex kvm
23666 @item kvm pcb
23667 Set current context from the @dfn{Process Control Block} (PCB) address.
23668
23669 @item kvm proc
23670 Set current context from proc address. This command isn't available on
23671 modern FreeBSD systems.
23672 @end table
23673
23674 @node Process Information
23675 @subsection Process Information
23676 @cindex /proc
23677 @cindex examine process image
23678 @cindex process info via @file{/proc}
23679
23680 Some operating systems provide interfaces to fetch additional
23681 information about running processes beyond memory and per-thread
23682 register state. If @value{GDBN} is configured for an operating system
23683 with a supported interface, the command @code{info proc} is available
23684 to report information about the process running your program, or about
23685 any process running on your system.
23686
23687 One supported interface is a facility called @samp{/proc} that can be
23688 used to examine the image of a running process using file-system
23689 subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
23690 systems.
23691
23692 On FreeBSD and NetBSD systems, system control nodes are used to query
23693 process information.
23694
23695 In addition, some systems may provide additional process information
23696 in core files. Note that a core file may include a subset of the
23697 information available from a live process. Process information is
23698 currently available from cores created on @sc{gnu}/Linux and FreeBSD
23699 systems.
23700
23701 @table @code
23702 @kindex info proc
23703 @cindex process ID
23704 @item info proc
23705 @itemx info proc @var{process-id}
23706 Summarize available information about a process. If a
23707 process ID is specified by @var{process-id}, display information about
23708 that process; otherwise display information about the program being
23709 debugged. The summary includes the debugged process ID, the command
23710 line used to invoke it, its current working directory, and its
23711 executable file's absolute file name.
23712
23713 On some systems, @var{process-id} can be of the form
23714 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
23715 within a process. If the optional @var{pid} part is missing, it means
23716 a thread from the process being debugged (the leading @samp{/} still
23717 needs to be present, or else @value{GDBN} will interpret the number as
23718 a process ID rather than a thread ID).
23719
23720 @item info proc cmdline
23721 @cindex info proc cmdline
23722 Show the original command line of the process. This command is
23723 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
23724
23725 @item info proc cwd
23726 @cindex info proc cwd
23727 Show the current working directory of the process. This command is
23728 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
23729
23730 @item info proc exe
23731 @cindex info proc exe
23732 Show the name of executable of the process. This command is supported
23733 on @sc{gnu}/Linux, FreeBSD and NetBSD.
23734
23735 @item info proc files
23736 @cindex info proc files
23737 Show the file descriptors open by the process. For each open file
23738 descriptor, @value{GDBN} shows its number, type (file, directory,
23739 character device, socket), file pointer offset, and the name of the
23740 resource open on the descriptor. The resource name can be a file name
23741 (for files, directories, and devices) or a protocol followed by socket
23742 address (for network connections). This command is supported on
23743 FreeBSD.
23744
23745 This example shows the open file descriptors for a process using a
23746 tty for standard input and output as well as two network sockets:
23747
23748 @smallexample
23749 (gdb) info proc files 22136
23750 process 22136
23751 Open files:
23752
23753 FD Type Offset Flags Name
23754 text file - r-------- /usr/bin/ssh
23755 ctty chr - rw------- /dev/pts/20
23756 cwd dir - r-------- /usr/home/john
23757 root dir - r-------- /
23758 0 chr 0x32933a4 rw------- /dev/pts/20
23759 1 chr 0x32933a4 rw------- /dev/pts/20
23760 2 chr 0x32933a4 rw------- /dev/pts/20
23761 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
23762 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
23763 @end smallexample
23764
23765 @item info proc mappings
23766 @cindex memory address space mappings
23767 Report the memory address space ranges accessible in a process. On
23768 Solaris, FreeBSD and NetBSD systems, each memory range includes information
23769 on whether the process has read, write, or execute access rights to each
23770 range. On @sc{gnu}/Linux, FreeBSD and NetBSD systems, each memory range
23771 includes the object file which is mapped to that range.
23772
23773 @item info proc stat
23774 @itemx info proc status
23775 @cindex process detailed status information
23776 Show additional process-related information, including the user ID and
23777 group ID; virtual memory usage; the signals that are pending, blocked,
23778 and ignored; its TTY; its consumption of system and user time; its
23779 stack size; its @samp{nice} value; etc. These commands are supported
23780 on @sc{gnu}/Linux, FreeBSD and NetBSD.
23781
23782 For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
23783 information (type @kbd{man 5 proc} from your shell prompt).
23784
23785 For FreeBSD and NetBSD systems, @code{info proc stat} is an alias for
23786 @code{info proc status}.
23787
23788 @item info proc all
23789 Show all the information about the process described under all of the
23790 above @code{info proc} subcommands.
23791
23792 @ignore
23793 @comment These sub-options of 'info proc' were not included when
23794 @comment procfs.c was re-written. Keep their descriptions around
23795 @comment against the day when someone finds the time to put them back in.
23796 @kindex info proc times
23797 @item info proc times
23798 Starting time, user CPU time, and system CPU time for your program and
23799 its children.
23800
23801 @kindex info proc id
23802 @item info proc id
23803 Report on the process IDs related to your program: its own process ID,
23804 the ID of its parent, the process group ID, and the session ID.
23805 @end ignore
23806
23807 @item set procfs-trace
23808 @kindex set procfs-trace
23809 @cindex @code{procfs} API calls
23810 This command enables and disables tracing of @code{procfs} API calls.
23811
23812 @item show procfs-trace
23813 @kindex show procfs-trace
23814 Show the current state of @code{procfs} API call tracing.
23815
23816 @item set procfs-file @var{file}
23817 @kindex set procfs-file
23818 Tell @value{GDBN} to write @code{procfs} API trace to the named
23819 @var{file}. @value{GDBN} appends the trace info to the previous
23820 contents of the file. The default is to display the trace on the
23821 standard output.
23822
23823 @item show procfs-file
23824 @kindex show procfs-file
23825 Show the file to which @code{procfs} API trace is written.
23826
23827 @item proc-trace-entry
23828 @itemx proc-trace-exit
23829 @itemx proc-untrace-entry
23830 @itemx proc-untrace-exit
23831 @kindex proc-trace-entry
23832 @kindex proc-trace-exit
23833 @kindex proc-untrace-entry
23834 @kindex proc-untrace-exit
23835 These commands enable and disable tracing of entries into and exits
23836 from the @code{syscall} interface.
23837
23838 @item info pidlist
23839 @kindex info pidlist
23840 @cindex process list, QNX Neutrino
23841 For QNX Neutrino only, this command displays the list of all the
23842 processes and all the threads within each process.
23843
23844 @item info meminfo
23845 @kindex info meminfo
23846 @cindex mapinfo list, QNX Neutrino
23847 For QNX Neutrino only, this command displays the list of all mapinfos.
23848 @end table
23849
23850 @node DJGPP Native
23851 @subsection Features for Debugging @sc{djgpp} Programs
23852 @cindex @sc{djgpp} debugging
23853 @cindex native @sc{djgpp} debugging
23854 @cindex MS-DOS-specific commands
23855
23856 @cindex DPMI
23857 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
23858 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
23859 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
23860 top of real-mode DOS systems and their emulations.
23861
23862 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
23863 defines a few commands specific to the @sc{djgpp} port. This
23864 subsection describes those commands.
23865
23866 @table @code
23867 @kindex info dos
23868 @item info dos
23869 This is a prefix of @sc{djgpp}-specific commands which print
23870 information about the target system and important OS structures.
23871
23872 @kindex sysinfo
23873 @cindex MS-DOS system info
23874 @cindex free memory information (MS-DOS)
23875 @item info dos sysinfo
23876 This command displays assorted information about the underlying
23877 platform: the CPU type and features, the OS version and flavor, the
23878 DPMI version, and the available conventional and DPMI memory.
23879
23880 @cindex GDT
23881 @cindex LDT
23882 @cindex IDT
23883 @cindex segment descriptor tables
23884 @cindex descriptor tables display
23885 @item info dos gdt
23886 @itemx info dos ldt
23887 @itemx info dos idt
23888 These 3 commands display entries from, respectively, Global, Local,
23889 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
23890 tables are data structures which store a descriptor for each segment
23891 that is currently in use. The segment's selector is an index into a
23892 descriptor table; the table entry for that index holds the
23893 descriptor's base address and limit, and its attributes and access
23894 rights.
23895
23896 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
23897 segment (used for both data and the stack), and a DOS segment (which
23898 allows access to DOS/BIOS data structures and absolute addresses in
23899 conventional memory). However, the DPMI host will usually define
23900 additional segments in order to support the DPMI environment.
23901
23902 @cindex garbled pointers
23903 These commands allow to display entries from the descriptor tables.
23904 Without an argument, all entries from the specified table are
23905 displayed. An argument, which should be an integer expression, means
23906 display a single entry whose index is given by the argument. For
23907 example, here's a convenient way to display information about the
23908 debugged program's data segment:
23909
23910 @smallexample
23911 @exdent @code{(@value{GDBP}) info dos ldt $ds}
23912 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
23913 @end smallexample
23914
23915 @noindent
23916 This comes in handy when you want to see whether a pointer is outside
23917 the data segment's limit (i.e.@: @dfn{garbled}).
23918
23919 @cindex page tables display (MS-DOS)
23920 @item info dos pde
23921 @itemx info dos pte
23922 These two commands display entries from, respectively, the Page
23923 Directory and the Page Tables. Page Directories and Page Tables are
23924 data structures which control how virtual memory addresses are mapped
23925 into physical addresses. A Page Table includes an entry for every
23926 page of memory that is mapped into the program's address space; there
23927 may be several Page Tables, each one holding up to 4096 entries. A
23928 Page Directory has up to 4096 entries, one each for every Page Table
23929 that is currently in use.
23930
23931 Without an argument, @kbd{info dos pde} displays the entire Page
23932 Directory, and @kbd{info dos pte} displays all the entries in all of
23933 the Page Tables. An argument, an integer expression, given to the
23934 @kbd{info dos pde} command means display only that entry from the Page
23935 Directory table. An argument given to the @kbd{info dos pte} command
23936 means display entries from a single Page Table, the one pointed to by
23937 the specified entry in the Page Directory.
23938
23939 @cindex direct memory access (DMA) on MS-DOS
23940 These commands are useful when your program uses @dfn{DMA} (Direct
23941 Memory Access), which needs physical addresses to program the DMA
23942 controller.
23943
23944 These commands are supported only with some DPMI servers.
23945
23946 @cindex physical address from linear address
23947 @item info dos address-pte @var{addr}
23948 This command displays the Page Table entry for a specified linear
23949 address. The argument @var{addr} is a linear address which should
23950 already have the appropriate segment's base address added to it,
23951 because this command accepts addresses which may belong to @emph{any}
23952 segment. For example, here's how to display the Page Table entry for
23953 the page where a variable @code{i} is stored:
23954
23955 @smallexample
23956 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
23957 @exdent @code{Page Table entry for address 0x11a00d30:}
23958 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
23959 @end smallexample
23960
23961 @noindent
23962 This says that @code{i} is stored at offset @code{0xd30} from the page
23963 whose physical base address is @code{0x02698000}, and shows all the
23964 attributes of that page.
23965
23966 Note that you must cast the addresses of variables to a @code{char *},
23967 since otherwise the value of @code{__djgpp_base_address}, the base
23968 address of all variables and functions in a @sc{djgpp} program, will
23969 be added using the rules of C pointer arithmetics: if @code{i} is
23970 declared an @code{int}, @value{GDBN} will add 4 times the value of
23971 @code{__djgpp_base_address} to the address of @code{i}.
23972
23973 Here's another example, it displays the Page Table entry for the
23974 transfer buffer:
23975
23976 @smallexample
23977 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
23978 @exdent @code{Page Table entry for address 0x29110:}
23979 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
23980 @end smallexample
23981
23982 @noindent
23983 (The @code{+ 3} offset is because the transfer buffer's address is the
23984 3rd member of the @code{_go32_info_block} structure.) The output
23985 clearly shows that this DPMI server maps the addresses in conventional
23986 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
23987 linear (@code{0x29110}) addresses are identical.
23988
23989 This command is supported only with some DPMI servers.
23990 @end table
23991
23992 @cindex DOS serial data link, remote debugging
23993 In addition to native debugging, the DJGPP port supports remote
23994 debugging via a serial data link. The following commands are specific
23995 to remote serial debugging in the DJGPP port of @value{GDBN}.
23996
23997 @table @code
23998 @kindex set com1base
23999 @kindex set com1irq
24000 @kindex set com2base
24001 @kindex set com2irq
24002 @kindex set com3base
24003 @kindex set com3irq
24004 @kindex set com4base
24005 @kindex set com4irq
24006 @item set com1base @var{addr}
24007 This command sets the base I/O port address of the @file{COM1} serial
24008 port.
24009
24010 @item set com1irq @var{irq}
24011 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
24012 for the @file{COM1} serial port.
24013
24014 There are similar commands @samp{set com2base}, @samp{set com3irq},
24015 etc.@: for setting the port address and the @code{IRQ} lines for the
24016 other 3 COM ports.
24017
24018 @kindex show com1base
24019 @kindex show com1irq
24020 @kindex show com2base
24021 @kindex show com2irq
24022 @kindex show com3base
24023 @kindex show com3irq
24024 @kindex show com4base
24025 @kindex show com4irq
24026 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
24027 display the current settings of the base address and the @code{IRQ}
24028 lines used by the COM ports.
24029
24030 @item info serial
24031 @kindex info serial
24032 @cindex DOS serial port status
24033 This command prints the status of the 4 DOS serial ports. For each
24034 port, it prints whether it's active or not, its I/O base address and
24035 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
24036 counts of various errors encountered so far.
24037 @end table
24038
24039
24040 @node Cygwin Native
24041 @subsection Features for Debugging MS Windows PE Executables
24042 @cindex MS Windows debugging
24043 @cindex native Cygwin debugging
24044 @cindex Cygwin-specific commands
24045
24046 @value{GDBN} supports native debugging of MS Windows programs, including
24047 DLLs with and without symbolic debugging information.
24048
24049 @cindex Ctrl-BREAK, MS-Windows
24050 @cindex interrupt debuggee on MS-Windows
24051 MS-Windows programs that call @code{SetConsoleMode} to switch off the
24052 special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
24053 by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
24054 supports @kbd{C-@key{BREAK}} as an alternative interrupt key
24055 sequence, which can be used to interrupt the debuggee even if it
24056 ignores @kbd{C-c}.
24057
24058 There are various additional Cygwin-specific commands, described in
24059 this section. Working with DLLs that have no debugging symbols is
24060 described in @ref{Non-debug DLL Symbols}.
24061
24062 @table @code
24063 @kindex info w32
24064 @item info w32
24065 This is a prefix of MS Windows-specific commands which print
24066 information about the target system and important OS structures.
24067
24068 @item info w32 selector
24069 This command displays information returned by
24070 the Win32 API @code{GetThreadSelectorEntry} function.
24071 It takes an optional argument that is evaluated to
24072 a long value to give the information about this given selector.
24073 Without argument, this command displays information
24074 about the six segment registers.
24075
24076 @item info w32 thread-information-block
24077 This command displays thread specific information stored in the
24078 Thread Information Block (readable on the X86 CPU family using @code{$fs}
24079 selector for 32-bit programs and @code{$gs} for 64-bit programs).
24080
24081 @kindex signal-event
24082 @item signal-event @var{id}
24083 This command signals an event with user-provided @var{id}. Used to resume
24084 crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
24085
24086 To use it, create or edit the following keys in
24087 @code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
24088 @code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
24089 (for x86_64 versions):
24090
24091 @itemize @minus
24092 @item
24093 @code{Debugger} (REG_SZ) --- a command to launch the debugger.
24094 Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
24095 "attach %ld" -ex "signal-event %ld" -ex "continue"}.
24096
24097 The first @code{%ld} will be replaced by the process ID of the
24098 crashing process, the second @code{%ld} will be replaced by the ID of
24099 the event that blocks the crashing process, waiting for @value{GDBN}
24100 to attach.
24101
24102 @item
24103 @code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
24104 make the system run debugger specified by the Debugger key
24105 automatically, @code{0} will cause a dialog box with ``OK'' and
24106 ``Cancel'' buttons to appear, which allows the user to either
24107 terminate the crashing process (OK) or debug it (Cancel).
24108 @end itemize
24109
24110 @kindex set cygwin-exceptions
24111 @cindex debugging the Cygwin DLL
24112 @cindex Cygwin DLL, debugging
24113 @item set cygwin-exceptions @var{mode}
24114 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
24115 happen inside the Cygwin DLL. If @var{mode} is @code{off},
24116 @value{GDBN} will delay recognition of exceptions, and may ignore some
24117 exceptions which seem to be caused by internal Cygwin DLL
24118 ``bookkeeping''. This option is meant primarily for debugging the
24119 Cygwin DLL itself; the default value is @code{off} to avoid annoying
24120 @value{GDBN} users with false @code{SIGSEGV} signals.
24121
24122 @kindex show cygwin-exceptions
24123 @item show cygwin-exceptions
24124 Displays whether @value{GDBN} will break on exceptions that happen
24125 inside the Cygwin DLL itself.
24126
24127 @kindex set new-console
24128 @item set new-console @var{mode}
24129 If @var{mode} is @code{on} the debuggee will
24130 be started in a new console on next start.
24131 If @var{mode} is @code{off}, the debuggee will
24132 be started in the same console as the debugger.
24133
24134 @kindex show new-console
24135 @item show new-console
24136 Displays whether a new console is used
24137 when the debuggee is started.
24138
24139 @kindex set new-group
24140 @item set new-group @var{mode}
24141 This boolean value controls whether the debuggee should
24142 start a new group or stay in the same group as the debugger.
24143 This affects the way the Windows OS handles
24144 @samp{Ctrl-C}.
24145
24146 @kindex show new-group
24147 @item show new-group
24148 Displays current value of new-group boolean.
24149
24150 @kindex set debugevents
24151 @item set debugevents
24152 This boolean value adds debug output concerning kernel events related
24153 to the debuggee seen by the debugger. This includes events that
24154 signal thread and process creation and exit, DLL loading and
24155 unloading, console interrupts, and debugging messages produced by the
24156 Windows @code{OutputDebugString} API call.
24157
24158 @kindex set debugexec
24159 @item set debugexec
24160 This boolean value adds debug output concerning execute events
24161 (such as resume thread) seen by the debugger.
24162
24163 @kindex set debugexceptions
24164 @item set debugexceptions
24165 This boolean value adds debug output concerning exceptions in the
24166 debuggee seen by the debugger.
24167
24168 @kindex set debugmemory
24169 @item set debugmemory
24170 This boolean value adds debug output concerning debuggee memory reads
24171 and writes by the debugger.
24172
24173 @kindex set shell
24174 @item set shell
24175 This boolean values specifies whether the debuggee is called
24176 via a shell or directly (default value is on).
24177
24178 @kindex show shell
24179 @item show shell
24180 Displays if the debuggee will be started with a shell.
24181
24182 @end table
24183
24184 @menu
24185 * Non-debug DLL Symbols:: Support for DLLs without debugging symbols
24186 @end menu
24187
24188 @node Non-debug DLL Symbols
24189 @subsubsection Support for DLLs without Debugging Symbols
24190 @cindex DLLs with no debugging symbols
24191 @cindex Minimal symbols and DLLs
24192
24193 Very often on windows, some of the DLLs that your program relies on do
24194 not include symbolic debugging information (for example,
24195 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
24196 symbols in a DLL, it relies on the minimal amount of symbolic
24197 information contained in the DLL's export table. This section
24198 describes working with such symbols, known internally to @value{GDBN} as
24199 ``minimal symbols''.
24200
24201 Note that before the debugged program has started execution, no DLLs
24202 will have been loaded. The easiest way around this problem is simply to
24203 start the program --- either by setting a breakpoint or letting the
24204 program run once to completion.
24205
24206 @subsubsection DLL Name Prefixes
24207
24208 In keeping with the naming conventions used by the Microsoft debugging
24209 tools, DLL export symbols are made available with a prefix based on the
24210 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
24211 also entered into the symbol table, so @code{CreateFileA} is often
24212 sufficient. In some cases there will be name clashes within a program
24213 (particularly if the executable itself includes full debugging symbols)
24214 necessitating the use of the fully qualified name when referring to the
24215 contents of the DLL. Use single-quotes around the name to avoid the
24216 exclamation mark (``!'') being interpreted as a language operator.
24217
24218 Note that the internal name of the DLL may be all upper-case, even
24219 though the file name of the DLL is lower-case, or vice-versa. Since
24220 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
24221 some confusion. If in doubt, try the @code{info functions} and
24222 @code{info variables} commands or even @code{maint print msymbols}
24223 (@pxref{Symbols}). Here's an example:
24224
24225 @smallexample
24226 (@value{GDBP}) info function CreateFileA
24227 All functions matching regular expression "CreateFileA":
24228
24229 Non-debugging symbols:
24230 0x77e885f4 CreateFileA
24231 0x77e885f4 KERNEL32!CreateFileA
24232 @end smallexample
24233
24234 @smallexample
24235 (@value{GDBP}) info function !
24236 All functions matching regular expression "!":
24237
24238 Non-debugging symbols:
24239 0x6100114c cygwin1!__assert
24240 0x61004034 cygwin1!_dll_crt0@@0
24241 0x61004240 cygwin1!dll_crt0(per_process *)
24242 [etc...]
24243 @end smallexample
24244
24245 @subsubsection Working with Minimal Symbols
24246
24247 Symbols extracted from a DLL's export table do not contain very much
24248 type information. All that @value{GDBN} can do is guess whether a symbol
24249 refers to a function or variable depending on the linker section that
24250 contains the symbol. Also note that the actual contents of the memory
24251 contained in a DLL are not available unless the program is running. This
24252 means that you cannot examine the contents of a variable or disassemble
24253 a function within a DLL without a running program.
24254
24255 Variables are generally treated as pointers and dereferenced
24256 automatically. For this reason, it is often necessary to prefix a
24257 variable name with the address-of operator (``&'') and provide explicit
24258 type information in the command. Here's an example of the type of
24259 problem:
24260
24261 @smallexample
24262 (@value{GDBP}) print 'cygwin1!__argv'
24263 'cygwin1!__argv' has unknown type; cast it to its declared type
24264 @end smallexample
24265
24266 @smallexample
24267 (@value{GDBP}) x 'cygwin1!__argv'
24268 'cygwin1!__argv' has unknown type; cast it to its declared type
24269 @end smallexample
24270
24271 And two possible solutions:
24272
24273 @smallexample
24274 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
24275 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
24276 @end smallexample
24277
24278 @smallexample
24279 (@value{GDBP}) x/2x &'cygwin1!__argv'
24280 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
24281 (@value{GDBP}) x/x 0x10021608
24282 0x10021608: 0x0022fd98
24283 (@value{GDBP}) x/s 0x0022fd98
24284 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
24285 @end smallexample
24286
24287 Setting a break point within a DLL is possible even before the program
24288 starts execution. However, under these circumstances, @value{GDBN} can't
24289 examine the initial instructions of the function in order to skip the
24290 function's frame set-up code. You can work around this by using ``*&''
24291 to set the breakpoint at a raw memory address:
24292
24293 @smallexample
24294 (@value{GDBP}) break *&'python22!PyOS_Readline'
24295 Breakpoint 1 at 0x1e04eff0
24296 @end smallexample
24297
24298 The author of these extensions is not entirely convinced that setting a
24299 break point within a shared DLL like @file{kernel32.dll} is completely
24300 safe.
24301
24302 @node Hurd Native
24303 @subsection Commands Specific to @sc{gnu} Hurd Systems
24304 @cindex @sc{gnu} Hurd debugging
24305
24306 This subsection describes @value{GDBN} commands specific to the
24307 @sc{gnu} Hurd native debugging.
24308
24309 @table @code
24310 @item set signals
24311 @itemx set sigs
24312 @kindex set signals@r{, Hurd command}
24313 @kindex set sigs@r{, Hurd command}
24314 This command toggles the state of inferior signal interception by
24315 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
24316 affected by this command. @code{sigs} is a shorthand alias for
24317 @code{signals}.
24318
24319 @item show signals
24320 @itemx show sigs
24321 @kindex show signals@r{, Hurd command}
24322 @kindex show sigs@r{, Hurd command}
24323 Show the current state of intercepting inferior's signals.
24324
24325 @item set signal-thread
24326 @itemx set sigthread
24327 @kindex set signal-thread
24328 @kindex set sigthread
24329 This command tells @value{GDBN} which thread is the @code{libc} signal
24330 thread. That thread is run when a signal is delivered to a running
24331 process. @code{set sigthread} is the shorthand alias of @code{set
24332 signal-thread}.
24333
24334 @item show signal-thread
24335 @itemx show sigthread
24336 @kindex show signal-thread
24337 @kindex show sigthread
24338 These two commands show which thread will run when the inferior is
24339 delivered a signal.
24340
24341 @item set stopped
24342 @kindex set stopped@r{, Hurd command}
24343 This commands tells @value{GDBN} that the inferior process is stopped,
24344 as with the @code{SIGSTOP} signal. The stopped process can be
24345 continued by delivering a signal to it.
24346
24347 @item show stopped
24348 @kindex show stopped@r{, Hurd command}
24349 This command shows whether @value{GDBN} thinks the debuggee is
24350 stopped.
24351
24352 @item set exceptions
24353 @kindex set exceptions@r{, Hurd command}
24354 Use this command to turn off trapping of exceptions in the inferior.
24355 When exception trapping is off, neither breakpoints nor
24356 single-stepping will work. To restore the default, set exception
24357 trapping on.
24358
24359 @item show exceptions
24360 @kindex show exceptions@r{, Hurd command}
24361 Show the current state of trapping exceptions in the inferior.
24362
24363 @item set task pause
24364 @kindex set task@r{, Hurd commands}
24365 @cindex task attributes (@sc{gnu} Hurd)
24366 @cindex pause current task (@sc{gnu} Hurd)
24367 This command toggles task suspension when @value{GDBN} has control.
24368 Setting it to on takes effect immediately, and the task is suspended
24369 whenever @value{GDBN} gets control. Setting it to off will take
24370 effect the next time the inferior is continued. If this option is set
24371 to off, you can use @code{set thread default pause on} or @code{set
24372 thread pause on} (see below) to pause individual threads.
24373
24374 @item show task pause
24375 @kindex show task@r{, Hurd commands}
24376 Show the current state of task suspension.
24377
24378 @item set task detach-suspend-count
24379 @cindex task suspend count
24380 @cindex detach from task, @sc{gnu} Hurd
24381 This command sets the suspend count the task will be left with when
24382 @value{GDBN} detaches from it.
24383
24384 @item show task detach-suspend-count
24385 Show the suspend count the task will be left with when detaching.
24386
24387 @item set task exception-port
24388 @itemx set task excp
24389 @cindex task exception port, @sc{gnu} Hurd
24390 This command sets the task exception port to which @value{GDBN} will
24391 forward exceptions. The argument should be the value of the @dfn{send
24392 rights} of the task. @code{set task excp} is a shorthand alias.
24393
24394 @item set noninvasive
24395 @cindex noninvasive task options
24396 This command switches @value{GDBN} to a mode that is the least
24397 invasive as far as interfering with the inferior is concerned. This
24398 is the same as using @code{set task pause}, @code{set exceptions}, and
24399 @code{set signals} to values opposite to the defaults.
24400
24401 @item info send-rights
24402 @itemx info receive-rights
24403 @itemx info port-rights
24404 @itemx info port-sets
24405 @itemx info dead-names
24406 @itemx info ports
24407 @itemx info psets
24408 @cindex send rights, @sc{gnu} Hurd
24409 @cindex receive rights, @sc{gnu} Hurd
24410 @cindex port rights, @sc{gnu} Hurd
24411 @cindex port sets, @sc{gnu} Hurd
24412 @cindex dead names, @sc{gnu} Hurd
24413 These commands display information about, respectively, send rights,
24414 receive rights, port rights, port sets, and dead names of a task.
24415 There are also shorthand aliases: @code{info ports} for @code{info
24416 port-rights} and @code{info psets} for @code{info port-sets}.
24417
24418 @item set thread pause
24419 @kindex set thread@r{, Hurd command}
24420 @cindex thread properties, @sc{gnu} Hurd
24421 @cindex pause current thread (@sc{gnu} Hurd)
24422 This command toggles current thread suspension when @value{GDBN} has
24423 control. Setting it to on takes effect immediately, and the current
24424 thread is suspended whenever @value{GDBN} gets control. Setting it to
24425 off will take effect the next time the inferior is continued.
24426 Normally, this command has no effect, since when @value{GDBN} has
24427 control, the whole task is suspended. However, if you used @code{set
24428 task pause off} (see above), this command comes in handy to suspend
24429 only the current thread.
24430
24431 @item show thread pause
24432 @kindex show thread@r{, Hurd command}
24433 This command shows the state of current thread suspension.
24434
24435 @item set thread run
24436 This command sets whether the current thread is allowed to run.
24437
24438 @item show thread run
24439 Show whether the current thread is allowed to run.
24440
24441 @item set thread detach-suspend-count
24442 @cindex thread suspend count, @sc{gnu} Hurd
24443 @cindex detach from thread, @sc{gnu} Hurd
24444 This command sets the suspend count @value{GDBN} will leave on a
24445 thread when detaching. This number is relative to the suspend count
24446 found by @value{GDBN} when it notices the thread; use @code{set thread
24447 takeover-suspend-count} to force it to an absolute value.
24448
24449 @item show thread detach-suspend-count
24450 Show the suspend count @value{GDBN} will leave on the thread when
24451 detaching.
24452
24453 @item set thread exception-port
24454 @itemx set thread excp
24455 Set the thread exception port to which to forward exceptions. This
24456 overrides the port set by @code{set task exception-port} (see above).
24457 @code{set thread excp} is the shorthand alias.
24458
24459 @item set thread takeover-suspend-count
24460 Normally, @value{GDBN}'s thread suspend counts are relative to the
24461 value @value{GDBN} finds when it notices each thread. This command
24462 changes the suspend counts to be absolute instead.
24463
24464 @item set thread default
24465 @itemx show thread default
24466 @cindex thread default settings, @sc{gnu} Hurd
24467 Each of the above @code{set thread} commands has a @code{set thread
24468 default} counterpart (e.g., @code{set thread default pause}, @code{set
24469 thread default exception-port}, etc.). The @code{thread default}
24470 variety of commands sets the default thread properties for all
24471 threads; you can then change the properties of individual threads with
24472 the non-default commands.
24473 @end table
24474
24475 @node Darwin
24476 @subsection Darwin
24477 @cindex Darwin
24478
24479 @value{GDBN} provides the following commands specific to the Darwin target:
24480
24481 @table @code
24482 @item set debug darwin @var{num}
24483 @kindex set debug darwin
24484 When set to a non zero value, enables debugging messages specific to
24485 the Darwin support. Higher values produce more verbose output.
24486
24487 @item show debug darwin
24488 @kindex show debug darwin
24489 Show the current state of Darwin messages.
24490
24491 @item set debug mach-o @var{num}
24492 @kindex set debug mach-o
24493 When set to a non zero value, enables debugging messages while
24494 @value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
24495 file format used on Darwin for object and executable files.) Higher
24496 values produce more verbose output. This is a command to diagnose
24497 problems internal to @value{GDBN} and should not be needed in normal
24498 usage.
24499
24500 @item show debug mach-o
24501 @kindex show debug mach-o
24502 Show the current state of Mach-O file messages.
24503
24504 @item set mach-exceptions on
24505 @itemx set mach-exceptions off
24506 @kindex set mach-exceptions
24507 On Darwin, faults are first reported as a Mach exception and are then
24508 mapped to a Posix signal. Use this command to turn on trapping of
24509 Mach exceptions in the inferior. This might be sometimes useful to
24510 better understand the cause of a fault. The default is off.
24511
24512 @item show mach-exceptions
24513 @kindex show mach-exceptions
24514 Show the current state of exceptions trapping.
24515 @end table
24516
24517 @node FreeBSD
24518 @subsection FreeBSD
24519 @cindex FreeBSD
24520
24521 When the ABI of a system call is changed in the FreeBSD kernel, this
24522 is implemented by leaving a compatibility system call using the old
24523 ABI at the existing number and allocating a new system call number for
24524 the version using the new ABI. As a convenience, when a system call
24525 is caught by name (@pxref{catch syscall}), compatibility system calls
24526 are also caught.
24527
24528 For example, FreeBSD 12 introduced a new variant of the @code{kevent}
24529 system call and catching the @code{kevent} system call by name catches
24530 both variants:
24531
24532 @smallexample
24533 (@value{GDBP}) catch syscall kevent
24534 Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
24535 (@value{GDBP})
24536 @end smallexample
24537
24538
24539 @node Embedded OS
24540 @section Embedded Operating Systems
24541
24542 This section describes configurations involving the debugging of
24543 embedded operating systems that are available for several different
24544 architectures.
24545
24546 @value{GDBN} includes the ability to debug programs running on
24547 various real-time operating systems.
24548
24549 @node Embedded Processors
24550 @section Embedded Processors
24551
24552 This section goes into details specific to particular embedded
24553 configurations.
24554
24555 @cindex send command to simulator
24556 Whenever a specific embedded processor has a simulator, @value{GDBN}
24557 allows to send an arbitrary command to the simulator.
24558
24559 @table @code
24560 @item sim @var{command}
24561 @kindex sim@r{, a command}
24562 Send an arbitrary @var{command} string to the simulator. Consult the
24563 documentation for the specific simulator in use for information about
24564 acceptable commands.
24565 @end table
24566
24567
24568 @menu
24569 * ARC:: Synopsys ARC
24570 * ARM:: ARM
24571 * BPF:: eBPF
24572 * M68K:: Motorola M68K
24573 * MicroBlaze:: Xilinx MicroBlaze
24574 * MIPS Embedded:: MIPS Embedded
24575 * OpenRISC 1000:: OpenRISC 1000 (or1k)
24576 * PowerPC Embedded:: PowerPC Embedded
24577 * AVR:: Atmel AVR
24578 * CRIS:: CRIS
24579 * Super-H:: Renesas Super-H
24580 @end menu
24581
24582 @node ARC
24583 @subsection Synopsys ARC
24584 @cindex Synopsys ARC
24585 @cindex ARC specific commands
24586 @cindex ARC600
24587 @cindex ARC700
24588 @cindex ARC EM
24589 @cindex ARC HS
24590
24591 @value{GDBN} provides the following ARC-specific commands:
24592
24593 @table @code
24594 @item set debug arc
24595 @kindex set debug arc
24596 Control the level of ARC specific debug messages. Use 0 for no messages (the
24597 default), 1 for debug messages, and 2 for even more debug messages.
24598
24599 @item show debug arc
24600 @kindex show debug arc
24601 Show the level of ARC specific debugging in operation.
24602
24603 @item maint print arc arc-instruction @var{address}
24604 @kindex maint print arc arc-instruction
24605 Print internal disassembler information about instruction at a given address.
24606
24607 @end table
24608
24609 @node ARM
24610 @subsection ARM
24611
24612 @value{GDBN} provides the following ARM-specific commands:
24613
24614 @table @code
24615 @item set arm disassembler
24616 @kindex set arm
24617 This commands selects from a list of disassembly styles. The
24618 @code{"std"} style is the standard style.
24619
24620 @item show arm disassembler
24621 @kindex show arm
24622 Show the current disassembly style.
24623
24624 @item set arm apcs32
24625 @cindex ARM 32-bit mode
24626 This command toggles ARM operation mode between 32-bit and 26-bit.
24627
24628 @item show arm apcs32
24629 Display the current usage of the ARM 32-bit mode.
24630
24631 @item set arm fpu @var{fputype}
24632 This command sets the ARM floating-point unit (FPU) type. The
24633 argument @var{fputype} can be one of these:
24634
24635 @table @code
24636 @item auto
24637 Determine the FPU type by querying the OS ABI.
24638 @item softfpa
24639 Software FPU, with mixed-endian doubles on little-endian ARM
24640 processors.
24641 @item fpa
24642 GCC-compiled FPA co-processor.
24643 @item softvfp
24644 Software FPU with pure-endian doubles.
24645 @item vfp
24646 VFP co-processor.
24647 @end table
24648
24649 @item show arm fpu
24650 Show the current type of the FPU.
24651
24652 @item set arm abi
24653 This command forces @value{GDBN} to use the specified ABI.
24654
24655 @item show arm abi
24656 Show the currently used ABI.
24657
24658 @item set arm fallback-mode (arm|thumb|auto)
24659 @value{GDBN} uses the symbol table, when available, to determine
24660 whether instructions are ARM or Thumb. This command controls
24661 @value{GDBN}'s default behavior when the symbol table is not
24662 available. The default is @samp{auto}, which causes @value{GDBN} to
24663 use the current execution mode (from the @code{T} bit in the @code{CPSR}
24664 register).
24665
24666 @item show arm fallback-mode
24667 Show the current fallback instruction mode.
24668
24669 @item set arm force-mode (arm|thumb|auto)
24670 This command overrides use of the symbol table to determine whether
24671 instructions are ARM or Thumb. The default is @samp{auto}, which
24672 causes @value{GDBN} to use the symbol table and then the setting
24673 of @samp{set arm fallback-mode}.
24674
24675 @item show arm force-mode
24676 Show the current forced instruction mode.
24677
24678 @item set debug arm
24679 Toggle whether to display ARM-specific debugging messages from the ARM
24680 target support subsystem.
24681
24682 @item show debug arm
24683 Show whether ARM-specific debugging messages are enabled.
24684 @end table
24685
24686 @table @code
24687 @item target sim @r{[}@var{simargs}@r{]} @dots{}
24688 The @value{GDBN} ARM simulator accepts the following optional arguments.
24689
24690 @table @code
24691 @item --swi-support=@var{type}
24692 Tell the simulator which SWI interfaces to support. The argument
24693 @var{type} may be a comma separated list of the following values.
24694 The default value is @code{all}.
24695
24696 @table @code
24697 @item none
24698 @item demon
24699 @item angel
24700 @item redboot
24701 @item all
24702 @end table
24703 @end table
24704 @end table
24705
24706 @node BPF
24707 @subsection BPF
24708
24709 @table @code
24710 @item target sim @r{[}@var{simargs}@r{]} @dots{}
24711 The @value{GDBN} BPF simulator accepts the following optional arguments.
24712
24713 @table @code
24714 @item --skb-data-offset=@var{offset}
24715 Tell the simulator the offset, measured in bytes, of the
24716 @code{skb_data} field in the kernel @code{struct sk_buff} structure.
24717 This offset is used by some BPF specific-purpose load/store
24718 instructions. Defaults to 0.
24719 @end table
24720 @end table
24721
24722 @node M68K
24723 @subsection M68k
24724
24725 The Motorola m68k configuration includes ColdFire support.
24726
24727 @node MicroBlaze
24728 @subsection MicroBlaze
24729 @cindex Xilinx MicroBlaze
24730 @cindex XMD, Xilinx Microprocessor Debugger
24731
24732 The MicroBlaze is a soft-core processor supported on various Xilinx
24733 FPGAs, such as Spartan or Virtex series. Boards with these processors
24734 usually have JTAG ports which connect to a host system running the Xilinx
24735 Embedded Development Kit (EDK) or Software Development Kit (SDK).
24736 This host system is used to download the configuration bitstream to
24737 the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
24738 communicates with the target board using the JTAG interface and
24739 presents a @code{gdbserver} interface to the board. By default
24740 @code{xmd} uses port @code{1234}. (While it is possible to change
24741 this default port, it requires the use of undocumented @code{xmd}
24742 commands. Contact Xilinx support if you need to do this.)
24743
24744 Use these GDB commands to connect to the MicroBlaze target processor.
24745
24746 @table @code
24747 @item target remote :1234
24748 Use this command to connect to the target if you are running @value{GDBN}
24749 on the same system as @code{xmd}.
24750
24751 @item target remote @var{xmd-host}:1234
24752 Use this command to connect to the target if it is connected to @code{xmd}
24753 running on a different system named @var{xmd-host}.
24754
24755 @item load
24756 Use this command to download a program to the MicroBlaze target.
24757
24758 @item set debug microblaze @var{n}
24759 Enable MicroBlaze-specific debugging messages if non-zero.
24760
24761 @item show debug microblaze @var{n}
24762 Show MicroBlaze-specific debugging level.
24763 @end table
24764
24765 @node MIPS Embedded
24766 @subsection @acronym{MIPS} Embedded
24767
24768 @noindent
24769 @value{GDBN} supports these special commands for @acronym{MIPS} targets:
24770
24771 @table @code
24772 @item set mipsfpu double
24773 @itemx set mipsfpu single
24774 @itemx set mipsfpu none
24775 @itemx set mipsfpu auto
24776 @itemx show mipsfpu
24777 @kindex set mipsfpu
24778 @kindex show mipsfpu
24779 @cindex @acronym{MIPS} remote floating point
24780 @cindex floating point, @acronym{MIPS} remote
24781 If your target board does not support the @acronym{MIPS} floating point
24782 coprocessor, you should use the command @samp{set mipsfpu none} (if you
24783 need this, you may wish to put the command in your @value{GDBN} init
24784 file). This tells @value{GDBN} how to find the return value of
24785 functions which return floating point values. It also allows
24786 @value{GDBN} to avoid saving the floating point registers when calling
24787 functions on the board. If you are using a floating point coprocessor
24788 with only single precision floating point support, as on the @sc{r4650}
24789 processor, use the command @samp{set mipsfpu single}. The default
24790 double precision floating point coprocessor may be selected using
24791 @samp{set mipsfpu double}.
24792
24793 In previous versions the only choices were double precision or no
24794 floating point, so @samp{set mipsfpu on} will select double precision
24795 and @samp{set mipsfpu off} will select no floating point.
24796
24797 As usual, you can inquire about the @code{mipsfpu} variable with
24798 @samp{show mipsfpu}.
24799 @end table
24800
24801 @node OpenRISC 1000
24802 @subsection OpenRISC 1000
24803 @cindex OpenRISC 1000
24804
24805 @noindent
24806 The OpenRISC 1000 provides a free RISC instruction set architecture. It is
24807 mainly provided as a soft-core which can run on Xilinx, Altera and other
24808 FPGA's.
24809
24810 @value{GDBN} for OpenRISC supports the below commands when connecting to
24811 a target:
24812
24813 @table @code
24814
24815 @kindex target sim
24816 @item target sim
24817
24818 Runs the builtin CPU simulator which can run very basic
24819 programs but does not support most hardware functions like MMU.
24820 For more complex use cases the user is advised to run an external
24821 target, and connect using @samp{target remote}.
24822
24823 Example: @code{target sim}
24824
24825 @item set debug or1k
24826 Toggle whether to display OpenRISC-specific debugging messages from the
24827 OpenRISC target support subsystem.
24828
24829 @item show debug or1k
24830 Show whether OpenRISC-specific debugging messages are enabled.
24831 @end table
24832
24833 @node PowerPC Embedded
24834 @subsection PowerPC Embedded
24835
24836 @cindex DVC register
24837 @value{GDBN} supports using the DVC (Data Value Compare) register to
24838 implement in hardware simple hardware watchpoint conditions of the form:
24839
24840 @smallexample
24841 (@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
24842 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
24843 @end smallexample
24844
24845 The DVC register will be automatically used when @value{GDBN} detects
24846 such pattern in a condition expression, and the created watchpoint uses one
24847 debug register (either the @code{exact-watchpoints} option is on and the
24848 variable is scalar, or the variable has a length of one byte). This feature
24849 is available in native @value{GDBN} running on a Linux kernel version 2.6.34
24850 or newer.
24851
24852 When running on PowerPC embedded processors, @value{GDBN} automatically uses
24853 ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
24854 in which case watchpoints using only one debug register are created when
24855 watching variables of scalar types.
24856
24857 You can create an artificial array to watch an arbitrary memory
24858 region using one of the following commands (@pxref{Expressions}):
24859
24860 @smallexample
24861 (@value{GDBP}) watch *((char *) @var{address})@@@var{length}
24862 (@value{GDBP}) watch @{char[@var{length}]@} @var{address}
24863 @end smallexample
24864
24865 PowerPC embedded processors support masked watchpoints. See the discussion
24866 about the @code{mask} argument in @ref{Set Watchpoints}.
24867
24868 @cindex ranged breakpoint
24869 PowerPC embedded processors support hardware accelerated
24870 @dfn{ranged breakpoints}. A ranged breakpoint stops execution of
24871 the inferior whenever it executes an instruction at any address within
24872 the range it specifies. To set a ranged breakpoint in @value{GDBN},
24873 use the @code{break-range} command.
24874
24875 @value{GDBN} provides the following PowerPC-specific commands:
24876
24877 @table @code
24878 @kindex break-range
24879 @item break-range @var{start-location}, @var{end-location}
24880 Set a breakpoint for an address range given by
24881 @var{start-location} and @var{end-location}, which can specify a function name,
24882 a line number, an offset of lines from the current line or from the start
24883 location, or an address of an instruction (see @ref{Specify Location},
24884 for a list of all the possible ways to specify a @var{location}.)
24885 The breakpoint will stop execution of the inferior whenever it
24886 executes an instruction at any address within the specified range,
24887 (including @var{start-location} and @var{end-location}.)
24888
24889 @kindex set powerpc
24890 @item set powerpc soft-float
24891 @itemx show powerpc soft-float
24892 Force @value{GDBN} to use (or not use) a software floating point calling
24893 convention. By default, @value{GDBN} selects the calling convention based
24894 on the selected architecture and the provided executable file.
24895
24896 @item set powerpc vector-abi
24897 @itemx show powerpc vector-abi
24898 Force @value{GDBN} to use the specified calling convention for vector
24899 arguments and return values. The valid options are @samp{auto};
24900 @samp{generic}, to avoid vector registers even if they are present;
24901 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
24902 registers. By default, @value{GDBN} selects the calling convention
24903 based on the selected architecture and the provided executable file.
24904
24905 @item set powerpc exact-watchpoints
24906 @itemx show powerpc exact-watchpoints
24907 Allow @value{GDBN} to use only one debug register when watching a variable
24908 of scalar type, thus assuming that the variable is accessed through the
24909 address of its first byte.
24910
24911 @end table
24912
24913 @node AVR
24914 @subsection Atmel AVR
24915 @cindex AVR
24916
24917 When configured for debugging the Atmel AVR, @value{GDBN} supports the
24918 following AVR-specific commands:
24919
24920 @table @code
24921 @item info io_registers
24922 @kindex info io_registers@r{, AVR}
24923 @cindex I/O registers (Atmel AVR)
24924 This command displays information about the AVR I/O registers. For
24925 each register, @value{GDBN} prints its number and value.
24926 @end table
24927
24928 @node CRIS
24929 @subsection CRIS
24930 @cindex CRIS
24931
24932 When configured for debugging CRIS, @value{GDBN} provides the
24933 following CRIS-specific commands:
24934
24935 @table @code
24936 @item set cris-version @var{ver}
24937 @cindex CRIS version
24938 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
24939 The CRIS version affects register names and sizes. This command is useful in
24940 case autodetection of the CRIS version fails.
24941
24942 @item show cris-version
24943 Show the current CRIS version.
24944
24945 @item set cris-dwarf2-cfi
24946 @cindex DWARF-2 CFI and CRIS
24947 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
24948 Change to @samp{off} when using @code{gcc-cris} whose version is below
24949 @code{R59}.
24950
24951 @item show cris-dwarf2-cfi
24952 Show the current state of using DWARF-2 CFI.
24953
24954 @item set cris-mode @var{mode}
24955 @cindex CRIS mode
24956 Set the current CRIS mode to @var{mode}. It should only be changed when
24957 debugging in guru mode, in which case it should be set to
24958 @samp{guru} (the default is @samp{normal}).
24959
24960 @item show cris-mode
24961 Show the current CRIS mode.
24962 @end table
24963
24964 @node Super-H
24965 @subsection Renesas Super-H
24966 @cindex Super-H
24967
24968 For the Renesas Super-H processor, @value{GDBN} provides these
24969 commands:
24970
24971 @table @code
24972 @item set sh calling-convention @var{convention}
24973 @kindex set sh calling-convention
24974 Set the calling-convention used when calling functions from @value{GDBN}.
24975 Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
24976 With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
24977 convention. If the DWARF-2 information of the called function specifies
24978 that the function follows the Renesas calling convention, the function
24979 is called using the Renesas calling convention. If the calling convention
24980 is set to @samp{renesas}, the Renesas calling convention is always used,
24981 regardless of the DWARF-2 information. This can be used to override the
24982 default of @samp{gcc} if debug information is missing, or the compiler
24983 does not emit the DWARF-2 calling convention entry for a function.
24984
24985 @item show sh calling-convention
24986 @kindex show sh calling-convention
24987 Show the current calling convention setting.
24988
24989 @end table
24990
24991
24992 @node Architectures
24993 @section Architectures
24994
24995 This section describes characteristics of architectures that affect
24996 all uses of @value{GDBN} with the architecture, both native and cross.
24997
24998 @menu
24999 * AArch64::
25000 * i386::
25001 * Alpha::
25002 * MIPS::
25003 * HPPA:: HP PA architecture
25004 * PowerPC::
25005 * Nios II::
25006 * Sparc64::
25007 * S12Z::
25008 @end menu
25009
25010 @node AArch64
25011 @subsection AArch64
25012 @cindex AArch64 support
25013
25014 When @value{GDBN} is debugging the AArch64 architecture, it provides the
25015 following special commands:
25016
25017 @table @code
25018 @item set debug aarch64
25019 @kindex set debug aarch64
25020 This command determines whether AArch64 architecture-specific debugging
25021 messages are to be displayed.
25022
25023 @item show debug aarch64
25024 Show whether AArch64 debugging messages are displayed.
25025
25026 @end table
25027
25028 @subsubsection AArch64 SVE.
25029 @cindex AArch64 SVE.
25030
25031 When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
25032 Extension (SVE) is present, then @value{GDBN} will provide the vector registers
25033 @code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
25034 @code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
25035 @code{$vg} will be provided. This is the vector granule for the current thread
25036 and represents the number of 64-bit chunks in an SVE @code{z} register.
25037
25038 If the vector length changes, then the @code{$vg} register will be updated,
25039 but the lengths of the @code{z} and @code{p} registers will not change. This
25040 is a known limitation of @value{GDBN} and does not affect the execution of the
25041 target process.
25042
25043 @subsubsection AArch64 Pointer Authentication.
25044 @cindex AArch64 Pointer Authentication.
25045
25046 When @value{GDBN} is debugging the AArch64 architecture, and the program is
25047 using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
25048 register @code{$lr} is pointing to an PAC function its value will be masked.
25049 When GDB prints a backtrace, any addresses that required unmasking will be
25050 postfixed with the marker [PAC]. When using the MI, this is printed as part
25051 of the @code{addr_flags} field.
25052
25053 @node i386
25054 @subsection x86 Architecture-specific Issues
25055
25056 @table @code
25057 @item set struct-convention @var{mode}
25058 @kindex set struct-convention
25059 @cindex struct return convention
25060 @cindex struct/union returned in registers
25061 Set the convention used by the inferior to return @code{struct}s and
25062 @code{union}s from functions to @var{mode}. Possible values of
25063 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
25064 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
25065 are returned on the stack, while @code{"reg"} means that a
25066 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
25067 be returned in a register.
25068
25069 @item show struct-convention
25070 @kindex show struct-convention
25071 Show the current setting of the convention to return @code{struct}s
25072 from functions.
25073 @end table
25074
25075
25076 @subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
25077 @cindex Intel Memory Protection Extensions (MPX).
25078
25079 Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
25080 @footnote{The register named with capital letters represent the architecture
25081 registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
25082 which are the lower bound and upper bound. Bounds are effective addresses or
25083 memory locations. The upper bounds are architecturally represented in 1's
25084 complement form. A bound having lower bound = 0, and upper bound = 0
25085 (1's complement of all bits set) will allow access to the entire address space.
25086
25087 @samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
25088 through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
25089 display the upper bound performing the complement of one operation on the
25090 upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
25091 @value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
25092 can also be noted that the upper bounds are inclusive.
25093
25094 As an example, assume that the register BND0 holds bounds for a pointer having
25095 access allowed for the range between 0x32 and 0x71. The values present on
25096 bnd0raw and bnd registers are presented as follows:
25097
25098 @smallexample
25099 bnd0raw = @{0x32, 0xffffffff8e@}
25100 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
25101 @end smallexample
25102
25103 This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
25104 change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
25105 counterpart. When the bnd0@dots{}bnd3 registers are displayed via
25106 Python, the display includes the memory size, in bits, accessible to
25107 the pointer.
25108
25109 Bounds can also be stored in bounds tables, which are stored in
25110 application memory. These tables store bounds for pointers by specifying
25111 the bounds pointer's value along with its bounds. Evaluating and changing
25112 bounds located in bound tables is therefore interesting while investigating
25113 bugs on MPX context. @value{GDBN} provides commands for this purpose:
25114
25115 @table @code
25116 @item show mpx bound @var{pointer}
25117 @kindex show mpx bound
25118 Display bounds of the given @var{pointer}.
25119
25120 @item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
25121 @kindex set mpx bound
25122 Set the bounds of a pointer in the bound table.
25123 This command takes three parameters: @var{pointer} is the pointers
25124 whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
25125 for lower and upper bounds respectively.
25126 @end table
25127
25128 When you call an inferior function on an Intel MPX enabled program,
25129 GDB sets the inferior's bound registers to the init (disabled) state
25130 before calling the function. As a consequence, bounds checks for the
25131 pointer arguments passed to the function will always pass.
25132
25133 This is necessary because when you call an inferior function, the
25134 program is usually in the middle of the execution of other function.
25135 Since at that point bound registers are in an arbitrary state, not
25136 clearing them would lead to random bound violations in the called
25137 function.
25138
25139 You can still examine the influence of the bound registers on the
25140 execution of the called function by stopping the execution of the
25141 called function at its prologue, setting bound registers, and
25142 continuing the execution. For example:
25143
25144 @smallexample
25145 $ break *upper
25146 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
25147 $ print upper (a, b, c, d, 1)
25148 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
25149 $ print $bnd0
25150 @{lbound = 0x0, ubound = ffffffff@} : size -1
25151 @end smallexample
25152
25153 At this last step the value of bnd0 can be changed for investigation of bound
25154 violations caused along the execution of the call. In order to know how to
25155 set the bound registers or bound table for the call consult the ABI.
25156
25157 @node Alpha
25158 @subsection Alpha
25159
25160 See the following section.
25161
25162 @node MIPS
25163 @subsection @acronym{MIPS}
25164
25165 @cindex stack on Alpha
25166 @cindex stack on @acronym{MIPS}
25167 @cindex Alpha stack
25168 @cindex @acronym{MIPS} stack
25169 Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
25170 sometimes requires @value{GDBN} to search backward in the object code to
25171 find the beginning of a function.
25172
25173 @cindex response time, @acronym{MIPS} debugging
25174 To improve response time (especially for embedded applications, where
25175 @value{GDBN} may be restricted to a slow serial line for this search)
25176 you may want to limit the size of this search, using one of these
25177 commands:
25178
25179 @table @code
25180 @cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
25181 @item set heuristic-fence-post @var{limit}
25182 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
25183 search for the beginning of a function. A value of @var{0} (the
25184 default) means there is no limit. However, except for @var{0}, the
25185 larger the limit the more bytes @code{heuristic-fence-post} must search
25186 and therefore the longer it takes to run. You should only need to use
25187 this command when debugging a stripped executable.
25188
25189 @item show heuristic-fence-post
25190 Display the current limit.
25191 @end table
25192
25193 @noindent
25194 These commands are available @emph{only} when @value{GDBN} is configured
25195 for debugging programs on Alpha or @acronym{MIPS} processors.
25196
25197 Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
25198 programs:
25199
25200 @table @code
25201 @item set mips abi @var{arg}
25202 @kindex set mips abi
25203 @cindex set ABI for @acronym{MIPS}
25204 Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
25205 values of @var{arg} are:
25206
25207 @table @samp
25208 @item auto
25209 The default ABI associated with the current binary (this is the
25210 default).
25211 @item o32
25212 @item o64
25213 @item n32
25214 @item n64
25215 @item eabi32
25216 @item eabi64
25217 @end table
25218
25219 @item show mips abi
25220 @kindex show mips abi
25221 Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
25222
25223 @item set mips compression @var{arg}
25224 @kindex set mips compression
25225 @cindex code compression, @acronym{MIPS}
25226 Tell @value{GDBN} which @acronym{MIPS} compressed
25227 @acronym{ISA, Instruction Set Architecture} encoding is used by the
25228 inferior. @value{GDBN} uses this for code disassembly and other
25229 internal interpretation purposes. This setting is only referred to
25230 when no executable has been associated with the debugging session or
25231 the executable does not provide information about the encoding it uses.
25232 Otherwise this setting is automatically updated from information
25233 provided by the executable.
25234
25235 Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
25236 The default compressed @acronym{ISA} encoding is @samp{mips16}, as
25237 executables containing @acronym{MIPS16} code frequently are not
25238 identified as such.
25239
25240 This setting is ``sticky''; that is, it retains its value across
25241 debugging sessions until reset either explicitly with this command or
25242 implicitly from an executable.
25243
25244 The compiler and/or assembler typically add symbol table annotations to
25245 identify functions compiled for the @acronym{MIPS16} or
25246 @acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
25247 are present, @value{GDBN} uses them in preference to the global
25248 compressed @acronym{ISA} encoding setting.
25249
25250 @item show mips compression
25251 @kindex show mips compression
25252 Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
25253 @value{GDBN} to debug the inferior.
25254
25255 @item set mipsfpu
25256 @itemx show mipsfpu
25257 @xref{MIPS Embedded, set mipsfpu}.
25258
25259 @item set mips mask-address @var{arg}
25260 @kindex set mips mask-address
25261 @cindex @acronym{MIPS} addresses, masking
25262 This command determines whether the most-significant 32 bits of 64-bit
25263 @acronym{MIPS} addresses are masked off. The argument @var{arg} can be
25264 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
25265 setting, which lets @value{GDBN} determine the correct value.
25266
25267 @item show mips mask-address
25268 @kindex show mips mask-address
25269 Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
25270 not.
25271
25272 @item set remote-mips64-transfers-32bit-regs
25273 @kindex set remote-mips64-transfers-32bit-regs
25274 This command controls compatibility with 64-bit @acronym{MIPS} targets that
25275 transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
25276 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
25277 and 64 bits for other registers, set this option to @samp{on}.
25278
25279 @item show remote-mips64-transfers-32bit-regs
25280 @kindex show remote-mips64-transfers-32bit-regs
25281 Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
25282
25283 @item set debug mips
25284 @kindex set debug mips
25285 This command turns on and off debugging messages for the @acronym{MIPS}-specific
25286 target code in @value{GDBN}.
25287
25288 @item show debug mips
25289 @kindex show debug mips
25290 Show the current setting of @acronym{MIPS} debugging messages.
25291 @end table
25292
25293
25294 @node HPPA
25295 @subsection HPPA
25296 @cindex HPPA support
25297
25298 When @value{GDBN} is debugging the HP PA architecture, it provides the
25299 following special commands:
25300
25301 @table @code
25302 @item set debug hppa
25303 @kindex set debug hppa
25304 This command determines whether HPPA architecture-specific debugging
25305 messages are to be displayed.
25306
25307 @item show debug hppa
25308 Show whether HPPA debugging messages are displayed.
25309
25310 @item maint print unwind @var{address}
25311 @kindex maint print unwind@r{, HPPA}
25312 This command displays the contents of the unwind table entry at the
25313 given @var{address}.
25314
25315 @end table
25316
25317
25318 @node PowerPC
25319 @subsection PowerPC
25320 @cindex PowerPC architecture
25321
25322 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
25323 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
25324 numbers stored in the floating point registers. These values must be stored
25325 in two consecutive registers, always starting at an even register like
25326 @code{f0} or @code{f2}.
25327
25328 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
25329 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
25330 @code{f2} and @code{f3} for @code{$dl1} and so on.
25331
25332 For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
25333 wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
25334
25335 @node Nios II
25336 @subsection Nios II
25337 @cindex Nios II architecture
25338
25339 When @value{GDBN} is debugging the Nios II architecture,
25340 it provides the following special commands:
25341
25342 @table @code
25343
25344 @item set debug nios2
25345 @kindex set debug nios2
25346 This command turns on and off debugging messages for the Nios II
25347 target code in @value{GDBN}.
25348
25349 @item show debug nios2
25350 @kindex show debug nios2
25351 Show the current setting of Nios II debugging messages.
25352 @end table
25353
25354 @node Sparc64
25355 @subsection Sparc64
25356 @cindex Sparc64 support
25357 @cindex Application Data Integrity
25358 @subsubsection ADI Support
25359
25360 The M7 processor supports an Application Data Integrity (ADI) feature that
25361 detects invalid data accesses. When software allocates memory and enables
25362 ADI on the allocated memory, it chooses a 4-bit version number, sets the
25363 version in the upper 4 bits of the 64-bit pointer to that data, and stores
25364 the 4-bit version in every cacheline of that data. Hardware saves the latter
25365 in spare bits in the cache and memory hierarchy. On each load and store,
25366 the processor compares the upper 4 VA (virtual address) bits to the
25367 cacheline's version. If there is a mismatch, the processor generates a
25368 version mismatch trap which can be either precise or disrupting. The trap
25369 is an error condition which the kernel delivers to the process as a SIGSEGV
25370 signal.
25371
25372 Note that only 64-bit applications can use ADI and need to be built with
25373 ADI-enabled.
25374
25375 Values of the ADI version tags, which are in granularity of a
25376 cacheline (64 bytes), can be viewed or modified.
25377
25378
25379 @table @code
25380 @kindex adi examine
25381 @item adi (examine | x) [ / @var{n} ] @var{addr}
25382
25383 The @code{adi examine} command displays the value of one ADI version tag per
25384 cacheline.
25385
25386 @var{n} is a decimal integer specifying the number in bytes; the default
25387 is 1. It specifies how much ADI version information, at the ratio of 1:ADI
25388 block size, to display.
25389
25390 @var{addr} is the address in user address space where you want @value{GDBN}
25391 to begin displaying the ADI version tags.
25392
25393 Below is an example of displaying ADI versions of variable "shmaddr".
25394
25395 @smallexample
25396 (@value{GDBP}) adi x/100 shmaddr
25397 0xfff800010002c000: 0 0
25398 @end smallexample
25399
25400 @kindex adi assign
25401 @item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
25402
25403 The @code{adi assign} command is used to assign new ADI version tag
25404 to an address.
25405
25406 @var{n} is a decimal integer specifying the number in bytes;
25407 the default is 1. It specifies how much ADI version information, at the
25408 ratio of 1:ADI block size, to modify.
25409
25410 @var{addr} is the address in user address space where you want @value{GDBN}
25411 to begin modifying the ADI version tags.
25412
25413 @var{tag} is the new ADI version tag.
25414
25415 For example, do the following to modify then verify ADI versions of
25416 variable "shmaddr":
25417
25418 @smallexample
25419 (@value{GDBP}) adi a/100 shmaddr = 7
25420 (@value{GDBP}) adi x/100 shmaddr
25421 0xfff800010002c000: 7 7
25422 @end smallexample
25423
25424 @end table
25425
25426 @node S12Z
25427 @subsection S12Z
25428 @cindex S12Z support
25429
25430 When @value{GDBN} is debugging the S12Z architecture,
25431 it provides the following special command:
25432
25433 @table @code
25434 @item maint info bdccsr
25435 @kindex maint info bdccsr@r{, S12Z}
25436 This command displays the current value of the microprocessor's
25437 BDCCSR register.
25438 @end table
25439
25440
25441 @node Controlling GDB
25442 @chapter Controlling @value{GDBN}
25443
25444 You can alter the way @value{GDBN} interacts with you by using the
25445 @code{set} command. For commands controlling how @value{GDBN} displays
25446 data, see @ref{Print Settings, ,Print Settings}. Other settings are
25447 described here.
25448
25449 @menu
25450 * Prompt:: Prompt
25451 * Editing:: Command editing
25452 * Command History:: Command history
25453 * Screen Size:: Screen size
25454 * Output Styling:: Output styling
25455 * Numbers:: Numbers
25456 * ABI:: Configuring the current ABI
25457 * Auto-loading:: Automatically loading associated files
25458 * Messages/Warnings:: Optional warnings and messages
25459 * Debugging Output:: Optional messages about internal happenings
25460 * Other Misc Settings:: Other Miscellaneous Settings
25461 @end menu
25462
25463 @node Prompt
25464 @section Prompt
25465
25466 @cindex prompt
25467
25468 @value{GDBN} indicates its readiness to read a command by printing a string
25469 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
25470 can change the prompt string with the @code{set prompt} command. For
25471 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
25472 the prompt in one of the @value{GDBN} sessions so that you can always tell
25473 which one you are talking to.
25474
25475 @emph{Note:} @code{set prompt} does not add a space for you after the
25476 prompt you set. This allows you to set a prompt which ends in a space
25477 or a prompt that does not.
25478
25479 @table @code
25480 @kindex set prompt
25481 @item set prompt @var{newprompt}
25482 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
25483
25484 @kindex show prompt
25485 @item show prompt
25486 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
25487 @end table
25488
25489 Versions of @value{GDBN} that ship with Python scripting enabled have
25490 prompt extensions. The commands for interacting with these extensions
25491 are:
25492
25493 @table @code
25494 @kindex set extended-prompt
25495 @item set extended-prompt @var{prompt}
25496 Set an extended prompt that allows for substitutions.
25497 @xref{gdb.prompt}, for a list of escape sequences that can be used for
25498 substitution. Any escape sequences specified as part of the prompt
25499 string are replaced with the corresponding strings each time the prompt
25500 is displayed.
25501
25502 For example:
25503
25504 @smallexample
25505 set extended-prompt Current working directory: \w (gdb)
25506 @end smallexample
25507
25508 Note that when an extended-prompt is set, it takes control of the
25509 @var{prompt_hook} hook. @xref{prompt_hook}, for further information.
25510
25511 @kindex show extended-prompt
25512 @item show extended-prompt
25513 Prints the extended prompt. Any escape sequences specified as part of
25514 the prompt string with @code{set extended-prompt}, are replaced with the
25515 corresponding strings each time the prompt is displayed.
25516 @end table
25517
25518 @node Editing
25519 @section Command Editing
25520 @cindex readline
25521 @cindex command line editing
25522
25523 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
25524 @sc{gnu} library provides consistent behavior for programs which provide a
25525 command line interface to the user. Advantages are @sc{gnu} Emacs-style
25526 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
25527 substitution, and a storage and recall of command history across
25528 debugging sessions.
25529
25530 You may control the behavior of command line editing in @value{GDBN} with the
25531 command @code{set}.
25532
25533 @table @code
25534 @kindex set editing
25535 @cindex editing
25536 @item set editing
25537 @itemx set editing on
25538 Enable command line editing (enabled by default).
25539
25540 @item set editing off
25541 Disable command line editing.
25542
25543 @kindex show editing
25544 @item show editing
25545 Show whether command line editing is enabled.
25546 @end table
25547
25548 @ifset SYSTEM_READLINE
25549 @xref{Command Line Editing, , , rluserman, GNU Readline Library},
25550 @end ifset
25551 @ifclear SYSTEM_READLINE
25552 @xref{Command Line Editing},
25553 @end ifclear
25554 for more details about the Readline
25555 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
25556 encouraged to read that chapter.
25557
25558 @cindex Readline application name
25559 @value{GDBN} sets the Readline application name to @samp{gdb}. This
25560 is useful for conditions in @file{.inputrc}.
25561
25562 @cindex operate-and-get-next
25563 @value{GDBN} defines a bindable Readline command,
25564 @code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
25565 This command accepts the current line for execution and fetches the
25566 next line relative to the current line from the history for editing.
25567 Any argument is ignored.
25568
25569 @node Command History
25570 @section Command History
25571 @cindex command history
25572
25573 @value{GDBN} can keep track of the commands you type during your
25574 debugging sessions, so that you can be certain of precisely what
25575 happened. Use these commands to manage the @value{GDBN} command
25576 history facility.
25577
25578 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
25579 package, to provide the history facility.
25580 @ifset SYSTEM_READLINE
25581 @xref{Using History Interactively, , , history, GNU History Library},
25582 @end ifset
25583 @ifclear SYSTEM_READLINE
25584 @xref{Using History Interactively},
25585 @end ifclear
25586 for the detailed description of the History library.
25587
25588 To issue a command to @value{GDBN} without affecting certain aspects of
25589 the state which is seen by users, prefix it with @samp{server }
25590 (@pxref{Server Prefix}). This
25591 means that this command will not affect the command history, nor will it
25592 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
25593 pressed on a line by itself.
25594
25595 @cindex @code{server}, command prefix
25596 The server prefix does not affect the recording of values into the value
25597 history; to print a value without recording it into the value history,
25598 use the @code{output} command instead of the @code{print} command.
25599
25600 Here is the description of @value{GDBN} commands related to command
25601 history.
25602
25603 @table @code
25604 @cindex history substitution
25605 @cindex history file
25606 @kindex set history filename
25607 @cindex @env{GDBHISTFILE}, environment variable
25608 @item set history filename @r{[}@var{fname}@r{]}
25609 Set the name of the @value{GDBN} command history file to @var{fname}.
25610 This is the file where @value{GDBN} reads an initial command history
25611 list, and where it writes the command history from this session when it
25612 exits. You can access this list through history expansion or through
25613 the history command editing characters listed below. This file defaults
25614 to the value of the environment variable @code{GDBHISTFILE}, or to
25615 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
25616 is not set.
25617
25618 The @code{GDBHISTFILE} environment variable is read after processing
25619 any @value{GDBN} initialization files (@pxref{Startup}) and after
25620 processing any commands passed using command line options (for
25621 example, @code{-ex}).
25622
25623 If the @var{fname} argument is not given, or if the @code{GDBHISTFILE}
25624 is the empty string then @value{GDBN} will neither try to load an
25625 existing history file, nor will it try to save the history on exit.
25626
25627 @cindex save command history
25628 @kindex set history save
25629 @item set history save
25630 @itemx set history save on
25631 Record command history in a file, whose name may be specified with the
25632 @code{set history filename} command. By default, this option is
25633 disabled. The command history will be recorded when @value{GDBN}
25634 exits. If @code{set history filename} is set to the empty string then
25635 history saving is disabled, even when @code{set history save} is
25636 @code{on}.
25637
25638 @item set history save off
25639 Don't record the command history into the file specified by @code{set
25640 history filename} when @value{GDBN} exits.
25641
25642 @cindex history size
25643 @kindex set history size
25644 @cindex @env{GDBHISTSIZE}, environment variable
25645 @item set history size @var{size}
25646 @itemx set history size unlimited
25647 Set the number of commands which @value{GDBN} keeps in its history list.
25648 This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
25649 to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
25650 are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
25651 either a negative number or the empty string, then the number of commands
25652 @value{GDBN} keeps in the history list is unlimited.
25653
25654 The @code{GDBHISTSIZE} environment variable is read after processing
25655 any @value{GDBN} initialization files (@pxref{Startup}) and after
25656 processing any commands passed using command line options (for
25657 example, @code{-ex}).
25658
25659 @cindex remove duplicate history
25660 @kindex set history remove-duplicates
25661 @item set history remove-duplicates @var{count}
25662 @itemx set history remove-duplicates unlimited
25663 Control the removal of duplicate history entries in the command history list.
25664 If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
25665 history entries and remove the first entry that is a duplicate of the current
25666 entry being added to the command history list. If @var{count} is
25667 @code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
25668 removal of duplicate history entries is disabled.
25669
25670 Only history entries added during the current session are considered for
25671 removal. This option is set to 0 by default.
25672
25673 @end table
25674
25675 History expansion assigns special meaning to the character @kbd{!}.
25676 @ifset SYSTEM_READLINE
25677 @xref{Event Designators, , , history, GNU History Library},
25678 @end ifset
25679 @ifclear SYSTEM_READLINE
25680 @xref{Event Designators},
25681 @end ifclear
25682 for more details.
25683
25684 @cindex history expansion, turn on/off
25685 Since @kbd{!} is also the logical not operator in C, history expansion
25686 is off by default. If you decide to enable history expansion with the
25687 @code{set history expansion on} command, you may sometimes need to
25688 follow @kbd{!} (when it is used as logical not, in an expression) with
25689 a space or a tab to prevent it from being expanded. The readline
25690 history facilities do not attempt substitution on the strings
25691 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
25692
25693 The commands to control history expansion are:
25694
25695 @table @code
25696 @item set history expansion on
25697 @itemx set history expansion
25698 @kindex set history expansion
25699 Enable history expansion. History expansion is off by default.
25700
25701 @item set history expansion off
25702 Disable history expansion.
25703
25704 @c @group
25705 @kindex show history
25706 @item show history
25707 @itemx show history filename
25708 @itemx show history save
25709 @itemx show history size
25710 @itemx show history expansion
25711 These commands display the state of the @value{GDBN} history parameters.
25712 @code{show history} by itself displays all four states.
25713 @c @end group
25714 @end table
25715
25716 @table @code
25717 @kindex show commands
25718 @cindex show last commands
25719 @cindex display command history
25720 @item show commands
25721 Display the last ten commands in the command history.
25722
25723 @item show commands @var{n}
25724 Print ten commands centered on command number @var{n}.
25725
25726 @item show commands +
25727 Print ten commands just after the commands last printed.
25728 @end table
25729
25730 @node Screen Size
25731 @section Screen Size
25732 @cindex size of screen
25733 @cindex screen size
25734 @cindex pagination
25735 @cindex page size
25736 @cindex pauses in output
25737
25738 Certain commands to @value{GDBN} may produce large amounts of
25739 information output to the screen. To help you read all of it,
25740 @value{GDBN} pauses and asks you for input at the end of each page of
25741 output. Type @key{RET} when you want to see one more page of output,
25742 @kbd{q} to discard the remaining output, or @kbd{c} to continue
25743 without paging for the rest of the current command. Also, the screen
25744 width setting determines when to wrap lines of output. Depending on
25745 what is being printed, @value{GDBN} tries to break the line at a
25746 readable place, rather than simply letting it overflow onto the
25747 following line.
25748
25749 Normally @value{GDBN} knows the size of the screen from the terminal
25750 driver software. For example, on Unix @value{GDBN} uses the termcap data base
25751 together with the value of the @code{TERM} environment variable and the
25752 @code{stty rows} and @code{stty cols} settings. If this is not correct,
25753 you can override it with the @code{set height} and @code{set
25754 width} commands:
25755
25756 @table @code
25757 @kindex set height
25758 @kindex set width
25759 @kindex show width
25760 @kindex show height
25761 @item set height @var{lpp}
25762 @itemx set height unlimited
25763 @itemx show height
25764 @itemx set width @var{cpl}
25765 @itemx set width unlimited
25766 @itemx show width
25767 These @code{set} commands specify a screen height of @var{lpp} lines and
25768 a screen width of @var{cpl} characters. The associated @code{show}
25769 commands display the current settings.
25770
25771 If you specify a height of either @code{unlimited} or zero lines,
25772 @value{GDBN} does not pause during output no matter how long the
25773 output is. This is useful if output is to a file or to an editor
25774 buffer.
25775
25776 Likewise, you can specify @samp{set width unlimited} or @samp{set
25777 width 0} to prevent @value{GDBN} from wrapping its output.
25778
25779 @item set pagination on
25780 @itemx set pagination off
25781 @kindex set pagination
25782 Turn the output pagination on or off; the default is on. Turning
25783 pagination off is the alternative to @code{set height unlimited}. Note that
25784 running @value{GDBN} with the @option{--batch} option (@pxref{Mode
25785 Options, -batch}) also automatically disables pagination.
25786
25787 @item show pagination
25788 @kindex show pagination
25789 Show the current pagination mode.
25790 @end table
25791
25792 @node Output Styling
25793 @section Output Styling
25794 @cindex styling
25795 @cindex colors
25796
25797 @kindex set style
25798 @kindex show style
25799 @value{GDBN} can style its output on a capable terminal. This is
25800 enabled by default on most systems, but disabled by default when in
25801 batch mode (@pxref{Mode Options}). Various style settings are available;
25802 and styles can also be disabled entirely.
25803
25804 @table @code
25805 @item set style enabled @samp{on|off}
25806 Enable or disable all styling. The default is host-dependent, with
25807 most hosts defaulting to @samp{on}.
25808
25809 @item show style enabled
25810 Show the current state of styling.
25811
25812 @item set style sources @samp{on|off}
25813 Enable or disable source code styling. This affects whether source
25814 code, such as the output of the @code{list} command, is styled. Note
25815 that source styling only works if styling in general is enabled, and
25816 if @value{GDBN} was linked with the GNU Source Highlight library. The
25817 default is @samp{on}.
25818
25819 @item show style sources
25820 Show the current state of source code styling.
25821 @end table
25822
25823 Subcommands of @code{set style} control specific forms of styling.
25824 These subcommands all follow the same pattern: each style-able object
25825 can be styled with a foreground color, a background color, and an
25826 intensity.
25827
25828 For example, the style of file names can be controlled using the
25829 @code{set style filename} group of commands:
25830
25831 @table @code
25832 @item set style filename background @var{color}
25833 Set the background to @var{color}. Valid colors are @samp{none}
25834 (meaning the terminal's default color), @samp{black}, @samp{red},
25835 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
25836 and@samp{white}.
25837
25838 @item set style filename foreground @var{color}
25839 Set the foreground to @var{color}. Valid colors are @samp{none}
25840 (meaning the terminal's default color), @samp{black}, @samp{red},
25841 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
25842 and@samp{white}.
25843
25844 @item set style filename intensity @var{value}
25845 Set the intensity to @var{value}. Valid intensities are @samp{normal}
25846 (the default), @samp{bold}, and @samp{dim}.
25847 @end table
25848
25849 The @code{show style} command and its subcommands are styling
25850 a style name in their output using its own style.
25851 So, use @command{show style} to see the complete list of styles,
25852 their characteristics and the visual aspect of each style.
25853
25854 The style-able objects are:
25855 @table @code
25856 @item filename
25857 Control the styling of file names. By default, this style's
25858 foreground color is green.
25859
25860 @item function
25861 Control the styling of function names. These are managed with the
25862 @code{set style function} family of commands. By default, this
25863 style's foreground color is yellow.
25864
25865 @item variable
25866 Control the styling of variable names. These are managed with the
25867 @code{set style variable} family of commands. By default, this style's
25868 foreground color is cyan.
25869
25870 @item address
25871 Control the styling of addresses. These are managed with the
25872 @code{set style address} family of commands. By default, this style's
25873 foreground color is blue.
25874
25875 @item title
25876 Control the styling of titles. These are managed with the
25877 @code{set style title} family of commands. By default, this style's
25878 intensity is bold. Commands are using the title style to improve
25879 the readability of large output. For example, the commands
25880 @command{apropos} and @command{help} are using the title style
25881 for the command names.
25882
25883 @item highlight
25884 Control the styling of highlightings. These are managed with the
25885 @code{set style highlight} family of commands. By default, this style's
25886 foreground color is red. Commands are using the highlight style to draw
25887 the user attention to some specific parts of their output. For example,
25888 the command @command{apropos -v REGEXP} uses the highlight style to
25889 mark the documentation parts matching @var{regexp}.
25890
25891 @item tui-border
25892 Control the styling of the TUI border. Note that, unlike other
25893 styling options, only the color of the border can be controlled via
25894 @code{set style}. This was done for compatibility reasons, as TUI
25895 controls to set the border's intensity predated the addition of
25896 general styling to @value{GDBN}. @xref{TUI Configuration}.
25897
25898 @item tui-active-border
25899 Control the styling of the active TUI border; that is, the TUI window
25900 that has the focus.
25901
25902 @end table
25903
25904 @node Numbers
25905 @section Numbers
25906 @cindex number representation
25907 @cindex entering numbers
25908
25909 You can always enter numbers in octal, decimal, or hexadecimal in
25910 @value{GDBN} by the usual conventions: octal numbers begin with
25911 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
25912 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
25913 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
25914 10; likewise, the default display for numbers---when no particular
25915 format is specified---is base 10. You can change the default base for
25916 both input and output with the commands described below.
25917
25918 @table @code
25919 @kindex set input-radix
25920 @item set input-radix @var{base}
25921 Set the default base for numeric input. Supported choices
25922 for @var{base} are decimal 8, 10, or 16. The base must itself be
25923 specified either unambiguously or using the current input radix; for
25924 example, any of
25925
25926 @smallexample
25927 set input-radix 012
25928 set input-radix 10.
25929 set input-radix 0xa
25930 @end smallexample
25931
25932 @noindent
25933 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
25934 leaves the input radix unchanged, no matter what it was, since
25935 @samp{10}, being without any leading or trailing signs of its base, is
25936 interpreted in the current radix. Thus, if the current radix is 16,
25937 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
25938 change the radix.
25939
25940 @kindex set output-radix
25941 @item set output-radix @var{base}
25942 Set the default base for numeric display. Supported choices
25943 for @var{base} are decimal 8, 10, or 16. The base must itself be
25944 specified either unambiguously or using the current input radix.
25945
25946 @kindex show input-radix
25947 @item show input-radix
25948 Display the current default base for numeric input.
25949
25950 @kindex show output-radix
25951 @item show output-radix
25952 Display the current default base for numeric display.
25953
25954 @item set radix @r{[}@var{base}@r{]}
25955 @itemx show radix
25956 @kindex set radix
25957 @kindex show radix
25958 These commands set and show the default base for both input and output
25959 of numbers. @code{set radix} sets the radix of input and output to
25960 the same base; without an argument, it resets the radix back to its
25961 default value of 10.
25962
25963 @end table
25964
25965 @node ABI
25966 @section Configuring the Current ABI
25967
25968 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
25969 application automatically. However, sometimes you need to override its
25970 conclusions. Use these commands to manage @value{GDBN}'s view of the
25971 current ABI.
25972
25973 @cindex OS ABI
25974 @kindex set osabi
25975 @kindex show osabi
25976 @cindex Newlib OS ABI and its influence on the longjmp handling
25977
25978 One @value{GDBN} configuration can debug binaries for multiple operating
25979 system targets, either via remote debugging or native emulation.
25980 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
25981 but you can override its conclusion using the @code{set osabi} command.
25982 One example where this is useful is in debugging of binaries which use
25983 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
25984 not have the same identifying marks that the standard C library for your
25985 platform provides.
25986
25987 When @value{GDBN} is debugging the AArch64 architecture, it provides a
25988 ``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
25989 @code{longjmp} when debugging binaries that use the @sc{newlib} C library.
25990 The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
25991
25992 @table @code
25993 @item show osabi
25994 Show the OS ABI currently in use.
25995
25996 @item set osabi
25997 With no argument, show the list of registered available OS ABI's.
25998
25999 @item set osabi @var{abi}
26000 Set the current OS ABI to @var{abi}.
26001 @end table
26002
26003 @cindex float promotion
26004
26005 Generally, the way that an argument of type @code{float} is passed to a
26006 function depends on whether the function is prototyped. For a prototyped
26007 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
26008 according to the architecture's convention for @code{float}. For unprototyped
26009 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
26010 @code{double} and then passed.
26011
26012 Unfortunately, some forms of debug information do not reliably indicate whether
26013 a function is prototyped. If @value{GDBN} calls a function that is not marked
26014 as prototyped, it consults @kbd{set coerce-float-to-double}.
26015
26016 @table @code
26017 @kindex set coerce-float-to-double
26018 @item set coerce-float-to-double
26019 @itemx set coerce-float-to-double on
26020 Arguments of type @code{float} will be promoted to @code{double} when passed
26021 to an unprototyped function. This is the default setting.
26022
26023 @item set coerce-float-to-double off
26024 Arguments of type @code{float} will be passed directly to unprototyped
26025 functions.
26026
26027 @kindex show coerce-float-to-double
26028 @item show coerce-float-to-double
26029 Show the current setting of promoting @code{float} to @code{double}.
26030 @end table
26031
26032 @kindex set cp-abi
26033 @kindex show cp-abi
26034 @value{GDBN} needs to know the ABI used for your program's C@t{++}
26035 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
26036 used to build your application. @value{GDBN} only fully supports
26037 programs with a single C@t{++} ABI; if your program contains code using
26038 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
26039 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
26040 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
26041 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
26042 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
26043 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
26044 ``auto''.
26045
26046 @table @code
26047 @item show cp-abi
26048 Show the C@t{++} ABI currently in use.
26049
26050 @item set cp-abi
26051 With no argument, show the list of supported C@t{++} ABI's.
26052
26053 @item set cp-abi @var{abi}
26054 @itemx set cp-abi auto
26055 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
26056 @end table
26057
26058 @node Auto-loading
26059 @section Automatically loading associated files
26060 @cindex auto-loading
26061
26062 @value{GDBN} sometimes reads files with commands and settings automatically,
26063 without being explicitly told so by the user. We call this feature
26064 @dfn{auto-loading}. While auto-loading is useful for automatically adapting
26065 @value{GDBN} to the needs of your project, it can sometimes produce unexpected
26066 results or introduce security risks (e.g., if the file comes from untrusted
26067 sources).
26068
26069 @menu
26070 * Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
26071 * libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
26072
26073 * Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
26074 * Auto-loading verbose mode:: @samp{set/show debug auto-load}
26075 @end menu
26076
26077 There are various kinds of files @value{GDBN} can automatically load.
26078 In addition to these files, @value{GDBN} supports auto-loading code written
26079 in various extension languages. @xref{Auto-loading extensions}.
26080
26081 Note that loading of these associated files (including the local @file{.gdbinit}
26082 file) requires accordingly configured @code{auto-load safe-path}
26083 (@pxref{Auto-loading safe path}).
26084
26085 For these reasons, @value{GDBN} includes commands and options to let you
26086 control when to auto-load files and which files should be auto-loaded.
26087
26088 @table @code
26089 @anchor{set auto-load off}
26090 @kindex set auto-load off
26091 @item set auto-load off
26092 Globally disable loading of all auto-loaded files.
26093 You may want to use this command with the @samp{-iex} option
26094 (@pxref{Option -init-eval-command}) such as:
26095 @smallexample
26096 $ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
26097 @end smallexample
26098
26099 Be aware that system init file (@pxref{System-wide configuration})
26100 and init files from your home directory (@pxref{Home Directory Init File})
26101 still get read (as they come from generally trusted directories).
26102 To prevent @value{GDBN} from auto-loading even those init files, use the
26103 @option{-nx} option (@pxref{Mode Options}), in addition to
26104 @code{set auto-load no}.
26105
26106 @anchor{show auto-load}
26107 @kindex show auto-load
26108 @item show auto-load
26109 Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
26110 or disabled.
26111
26112 @smallexample
26113 (gdb) show auto-load
26114 gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
26115 libthread-db: Auto-loading of inferior specific libthread_db is on.
26116 local-gdbinit: Auto-loading of .gdbinit script from current directory
26117 is on.
26118 python-scripts: Auto-loading of Python scripts is on.
26119 safe-path: List of directories from which it is safe to auto-load files
26120 is $debugdir:$datadir/auto-load.
26121 scripts-directory: List of directories from which to load auto-loaded scripts
26122 is $debugdir:$datadir/auto-load.
26123 @end smallexample
26124
26125 @anchor{info auto-load}
26126 @kindex info auto-load
26127 @item info auto-load
26128 Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
26129 not.
26130
26131 @smallexample
26132 (gdb) info auto-load
26133 gdb-scripts:
26134 Loaded Script
26135 Yes /home/user/gdb/gdb-gdb.gdb
26136 libthread-db: No auto-loaded libthread-db.
26137 local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
26138 loaded.
26139 python-scripts:
26140 Loaded Script
26141 Yes /home/user/gdb/gdb-gdb.py
26142 @end smallexample
26143 @end table
26144
26145 These are @value{GDBN} control commands for the auto-loading:
26146
26147 @multitable @columnfractions .5 .5
26148 @item @xref{set auto-load off}.
26149 @tab Disable auto-loading globally.
26150 @item @xref{show auto-load}.
26151 @tab Show setting of all kinds of files.
26152 @item @xref{info auto-load}.
26153 @tab Show state of all kinds of files.
26154 @item @xref{set auto-load gdb-scripts}.
26155 @tab Control for @value{GDBN} command scripts.
26156 @item @xref{show auto-load gdb-scripts}.
26157 @tab Show setting of @value{GDBN} command scripts.
26158 @item @xref{info auto-load gdb-scripts}.
26159 @tab Show state of @value{GDBN} command scripts.
26160 @item @xref{set auto-load python-scripts}.
26161 @tab Control for @value{GDBN} Python scripts.
26162 @item @xref{show auto-load python-scripts}.
26163 @tab Show setting of @value{GDBN} Python scripts.
26164 @item @xref{info auto-load python-scripts}.
26165 @tab Show state of @value{GDBN} Python scripts.
26166 @item @xref{set auto-load guile-scripts}.
26167 @tab Control for @value{GDBN} Guile scripts.
26168 @item @xref{show auto-load guile-scripts}.
26169 @tab Show setting of @value{GDBN} Guile scripts.
26170 @item @xref{info auto-load guile-scripts}.
26171 @tab Show state of @value{GDBN} Guile scripts.
26172 @item @xref{set auto-load scripts-directory}.
26173 @tab Control for @value{GDBN} auto-loaded scripts location.
26174 @item @xref{show auto-load scripts-directory}.
26175 @tab Show @value{GDBN} auto-loaded scripts location.
26176 @item @xref{add-auto-load-scripts-directory}.
26177 @tab Add directory for auto-loaded scripts location list.
26178 @item @xref{set auto-load local-gdbinit}.
26179 @tab Control for init file in the current directory.
26180 @item @xref{show auto-load local-gdbinit}.
26181 @tab Show setting of init file in the current directory.
26182 @item @xref{info auto-load local-gdbinit}.
26183 @tab Show state of init file in the current directory.
26184 @item @xref{set auto-load libthread-db}.
26185 @tab Control for thread debugging library.
26186 @item @xref{show auto-load libthread-db}.
26187 @tab Show setting of thread debugging library.
26188 @item @xref{info auto-load libthread-db}.
26189 @tab Show state of thread debugging library.
26190 @item @xref{set auto-load safe-path}.
26191 @tab Control directories trusted for automatic loading.
26192 @item @xref{show auto-load safe-path}.
26193 @tab Show directories trusted for automatic loading.
26194 @item @xref{add-auto-load-safe-path}.
26195 @tab Add directory trusted for automatic loading.
26196 @end multitable
26197
26198 @node Init File in the Current Directory
26199 @subsection Automatically loading init file in the current directory
26200 @cindex auto-loading init file in the current directory
26201
26202 By default, @value{GDBN} reads and executes the canned sequences of commands
26203 from init file (if any) in the current working directory,
26204 see @ref{Init File in the Current Directory during Startup}.
26205
26206 Note that loading of this local @file{.gdbinit} file also requires accordingly
26207 configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26208
26209 @table @code
26210 @anchor{set auto-load local-gdbinit}
26211 @kindex set auto-load local-gdbinit
26212 @item set auto-load local-gdbinit [on|off]
26213 Enable or disable the auto-loading of canned sequences of commands
26214 (@pxref{Sequences}) found in init file in the current directory.
26215
26216 @anchor{show auto-load local-gdbinit}
26217 @kindex show auto-load local-gdbinit
26218 @item show auto-load local-gdbinit
26219 Show whether auto-loading of canned sequences of commands from init file in the
26220 current directory is enabled or disabled.
26221
26222 @anchor{info auto-load local-gdbinit}
26223 @kindex info auto-load local-gdbinit
26224 @item info auto-load local-gdbinit
26225 Print whether canned sequences of commands from init file in the
26226 current directory have been auto-loaded.
26227 @end table
26228
26229 @node libthread_db.so.1 file
26230 @subsection Automatically loading thread debugging library
26231 @cindex auto-loading libthread_db.so.1
26232
26233 This feature is currently present only on @sc{gnu}/Linux native hosts.
26234
26235 @value{GDBN} reads in some cases thread debugging library from places specific
26236 to the inferior (@pxref{set libthread-db-search-path}).
26237
26238 The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
26239 without checking this @samp{set auto-load libthread-db} switch as system
26240 libraries have to be trusted in general. In all other cases of
26241 @samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
26242 auto-load libthread-db} is enabled before trying to open such thread debugging
26243 library.
26244
26245 Note that loading of this debugging library also requires accordingly configured
26246 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26247
26248 @table @code
26249 @anchor{set auto-load libthread-db}
26250 @kindex set auto-load libthread-db
26251 @item set auto-load libthread-db [on|off]
26252 Enable or disable the auto-loading of inferior specific thread debugging library.
26253
26254 @anchor{show auto-load libthread-db}
26255 @kindex show auto-load libthread-db
26256 @item show auto-load libthread-db
26257 Show whether auto-loading of inferior specific thread debugging library is
26258 enabled or disabled.
26259
26260 @anchor{info auto-load libthread-db}
26261 @kindex info auto-load libthread-db
26262 @item info auto-load libthread-db
26263 Print the list of all loaded inferior specific thread debugging libraries and
26264 for each such library print list of inferior @var{pid}s using it.
26265 @end table
26266
26267 @node Auto-loading safe path
26268 @subsection Security restriction for auto-loading
26269 @cindex auto-loading safe-path
26270
26271 As the files of inferior can come from untrusted source (such as submitted by
26272 an application user) @value{GDBN} does not always load any files automatically.
26273 @value{GDBN} provides the @samp{set auto-load safe-path} setting to list
26274 directories trusted for loading files not explicitly requested by user.
26275 Each directory can also be a shell wildcard pattern.
26276
26277 If the path is not set properly you will see a warning and the file will not
26278 get loaded:
26279
26280 @smallexample
26281 $ ./gdb -q ./gdb
26282 Reading symbols from /home/user/gdb/gdb...
26283 warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
26284 declined by your `auto-load safe-path' set
26285 to "$debugdir:$datadir/auto-load".
26286 warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
26287 declined by your `auto-load safe-path' set
26288 to "$debugdir:$datadir/auto-load".
26289 @end smallexample
26290
26291 @noindent
26292 To instruct @value{GDBN} to go ahead and use the init files anyway,
26293 invoke @value{GDBN} like this:
26294
26295 @smallexample
26296 $ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
26297 @end smallexample
26298
26299 The list of trusted directories is controlled by the following commands:
26300
26301 @table @code
26302 @anchor{set auto-load safe-path}
26303 @kindex set auto-load safe-path
26304 @item set auto-load safe-path @r{[}@var{directories}@r{]}
26305 Set the list of directories (and their subdirectories) trusted for automatic
26306 loading and execution of scripts. You can also enter a specific trusted file.
26307 Each directory can also be a shell wildcard pattern; wildcards do not match
26308 directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
26309 (@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
26310 If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
26311 its default value as specified during @value{GDBN} compilation.
26312
26313 The list of directories uses path separator (@samp{:} on GNU and Unix
26314 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26315 to the @env{PATH} environment variable.
26316
26317 @anchor{show auto-load safe-path}
26318 @kindex show auto-load safe-path
26319 @item show auto-load safe-path
26320 Show the list of directories trusted for automatic loading and execution of
26321 scripts.
26322
26323 @anchor{add-auto-load-safe-path}
26324 @kindex add-auto-load-safe-path
26325 @item add-auto-load-safe-path
26326 Add an entry (or list of entries) to the list of directories trusted for
26327 automatic loading and execution of scripts. Multiple entries may be delimited
26328 by the host platform path separator in use.
26329 @end table
26330
26331 This variable defaults to what @code{--with-auto-load-dir} has been configured
26332 to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
26333 substitution applies the same as for @ref{set auto-load scripts-directory}.
26334 The default @code{set auto-load safe-path} value can be also overriden by
26335 @value{GDBN} configuration option @option{--with-auto-load-safe-path}.
26336
26337 Setting this variable to @file{/} disables this security protection,
26338 corresponding @value{GDBN} configuration option is
26339 @option{--without-auto-load-safe-path}.
26340 This variable is supposed to be set to the system directories writable by the
26341 system superuser only. Users can add their source directories in init files in
26342 their home directories (@pxref{Home Directory Init File}). See also deprecated
26343 init file in the current directory
26344 (@pxref{Init File in the Current Directory during Startup}).
26345
26346 To force @value{GDBN} to load the files it declined to load in the previous
26347 example, you could use one of the following ways:
26348
26349 @table @asis
26350 @item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
26351 Specify this trusted directory (or a file) as additional component of the list.
26352 You have to specify also any existing directories displayed by
26353 by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
26354
26355 @item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
26356 Specify this directory as in the previous case but just for a single
26357 @value{GDBN} session.
26358
26359 @item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
26360 Disable auto-loading safety for a single @value{GDBN} session.
26361 This assumes all the files you debug during this @value{GDBN} session will come
26362 from trusted sources.
26363
26364 @item @kbd{./configure --without-auto-load-safe-path}
26365 During compilation of @value{GDBN} you may disable any auto-loading safety.
26366 This assumes all the files you will ever debug with this @value{GDBN} come from
26367 trusted sources.
26368 @end table
26369
26370 On the other hand you can also explicitly forbid automatic files loading which
26371 also suppresses any such warning messages:
26372
26373 @table @asis
26374 @item @kbd{gdb -iex "set auto-load no" @dots{}}
26375 You can use @value{GDBN} command-line option for a single @value{GDBN} session.
26376
26377 @item @file{~/.gdbinit}: @samp{set auto-load no}
26378 Disable auto-loading globally for the user
26379 (@pxref{Home Directory Init File}). While it is improbable, you could also
26380 use system init file instead (@pxref{System-wide configuration}).
26381 @end table
26382
26383 This setting applies to the file names as entered by user. If no entry matches
26384 @value{GDBN} tries as a last resort to also resolve all the file names into
26385 their canonical form (typically resolving symbolic links) and compare the
26386 entries again. @value{GDBN} already canonicalizes most of the filenames on its
26387 own before starting the comparison so a canonical form of directories is
26388 recommended to be entered.
26389
26390 @node Auto-loading verbose mode
26391 @subsection Displaying files tried for auto-load
26392 @cindex auto-loading verbose mode
26393
26394 For better visibility of all the file locations where you can place scripts to
26395 be auto-loaded with inferior --- or to protect yourself against accidental
26396 execution of untrusted scripts --- @value{GDBN} provides a feature for printing
26397 all the files attempted to be loaded. Both existing and non-existing files may
26398 be printed.
26399
26400 For example the list of directories from which it is safe to auto-load files
26401 (@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
26402 may not be too obvious while setting it up.
26403
26404 @smallexample
26405 (gdb) set debug auto-load on
26406 (gdb) file ~/src/t/true
26407 auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
26408 for objfile "/tmp/true".
26409 auto-load: Updating directories of "/usr:/opt".
26410 auto-load: Using directory "/usr".
26411 auto-load: Using directory "/opt".
26412 warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
26413 by your `auto-load safe-path' set to "/usr:/opt".
26414 @end smallexample
26415
26416 @table @code
26417 @anchor{set debug auto-load}
26418 @kindex set debug auto-load
26419 @item set debug auto-load [on|off]
26420 Set whether to print the filenames attempted to be auto-loaded.
26421
26422 @anchor{show debug auto-load}
26423 @kindex show debug auto-load
26424 @item show debug auto-load
26425 Show whether printing of the filenames attempted to be auto-loaded is turned
26426 on or off.
26427 @end table
26428
26429 @node Messages/Warnings
26430 @section Optional Warnings and Messages
26431
26432 @cindex verbose operation
26433 @cindex optional warnings
26434 By default, @value{GDBN} is silent about its inner workings. If you are
26435 running on a slow machine, you may want to use the @code{set verbose}
26436 command. This makes @value{GDBN} tell you when it does a lengthy
26437 internal operation, so you will not think it has crashed.
26438
26439 Currently, the messages controlled by @code{set verbose} are those
26440 which announce that the symbol table for a source file is being read;
26441 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
26442
26443 @table @code
26444 @kindex set verbose
26445 @item set verbose on
26446 Enables @value{GDBN} output of certain informational messages.
26447
26448 @item set verbose off
26449 Disables @value{GDBN} output of certain informational messages.
26450
26451 @kindex show verbose
26452 @item show verbose
26453 Displays whether @code{set verbose} is on or off.
26454 @end table
26455
26456 By default, if @value{GDBN} encounters bugs in the symbol table of an
26457 object file, it is silent; but if you are debugging a compiler, you may
26458 find this information useful (@pxref{Symbol Errors, ,Errors Reading
26459 Symbol Files}).
26460
26461 @table @code
26462
26463 @kindex set complaints
26464 @item set complaints @var{limit}
26465 Permits @value{GDBN} to output @var{limit} complaints about each type of
26466 unusual symbols before becoming silent about the problem. Set
26467 @var{limit} to zero to suppress all complaints; set it to a large number
26468 to prevent complaints from being suppressed.
26469
26470 @kindex show complaints
26471 @item show complaints
26472 Displays how many symbol complaints @value{GDBN} is permitted to produce.
26473
26474 @end table
26475
26476 @anchor{confirmation requests}
26477 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
26478 lot of stupid questions to confirm certain commands. For example, if
26479 you try to run a program which is already running:
26480
26481 @smallexample
26482 (@value{GDBP}) run
26483 The program being debugged has been started already.
26484 Start it from the beginning? (y or n)
26485 @end smallexample
26486
26487 If you are willing to unflinchingly face the consequences of your own
26488 commands, you can disable this ``feature'':
26489
26490 @table @code
26491
26492 @kindex set confirm
26493 @cindex flinching
26494 @cindex confirmation
26495 @cindex stupid questions
26496 @item set confirm off
26497 Disables confirmation requests. Note that running @value{GDBN} with
26498 the @option{--batch} option (@pxref{Mode Options, -batch}) also
26499 automatically disables confirmation requests.
26500
26501 @item set confirm on
26502 Enables confirmation requests (the default).
26503
26504 @kindex show confirm
26505 @item show confirm
26506 Displays state of confirmation requests.
26507
26508 @end table
26509
26510 @cindex command tracing
26511 If you need to debug user-defined commands or sourced files you may find it
26512 useful to enable @dfn{command tracing}. In this mode each command will be
26513 printed as it is executed, prefixed with one or more @samp{+} symbols, the
26514 quantity denoting the call depth of each command.
26515
26516 @table @code
26517 @kindex set trace-commands
26518 @cindex command scripts, debugging
26519 @item set trace-commands on
26520 Enable command tracing.
26521 @item set trace-commands off
26522 Disable command tracing.
26523 @item show trace-commands
26524 Display the current state of command tracing.
26525 @end table
26526
26527 @node Debugging Output
26528 @section Optional Messages about Internal Happenings
26529 @cindex optional debugging messages
26530
26531 @value{GDBN} has commands that enable optional debugging messages from
26532 various @value{GDBN} subsystems; normally these commands are of
26533 interest to @value{GDBN} maintainers, or when reporting a bug. This
26534 section documents those commands.
26535
26536 @table @code
26537 @kindex set exec-done-display
26538 @item set exec-done-display
26539 Turns on or off the notification of asynchronous commands'
26540 completion. When on, @value{GDBN} will print a message when an
26541 asynchronous command finishes its execution. The default is off.
26542 @kindex show exec-done-display
26543 @item show exec-done-display
26544 Displays the current setting of asynchronous command completion
26545 notification.
26546
26547 @kindex set debug
26548 @cindex ARM AArch64
26549 @item set debug aarch64
26550 Turns on or off display of debugging messages related to ARM AArch64.
26551 The default is off.
26552 @kindex show debug
26553 @item show debug aarch64
26554 Displays the current state of displaying debugging messages related to
26555 ARM AArch64.
26556
26557 @cindex gdbarch debugging info
26558 @cindex architecture debugging info
26559 @item set debug arch
26560 Turns on or off display of gdbarch debugging info. The default is off
26561 @item show debug arch
26562 Displays the current state of displaying gdbarch debugging info.
26563
26564 @item set debug aix-solib
26565 @cindex AIX shared library debugging
26566 Control display of debugging messages from the AIX shared library
26567 support module. The default is off.
26568 @item show debug aix-solib
26569 Show the current state of displaying AIX shared library debugging messages.
26570
26571 @item set debug aix-thread
26572 @cindex AIX threads
26573 Display debugging messages about inner workings of the AIX thread
26574 module.
26575 @item show debug aix-thread
26576 Show the current state of AIX thread debugging info display.
26577
26578 @item set debug check-physname
26579 @cindex physname
26580 Check the results of the ``physname'' computation. When reading DWARF
26581 debugging information for C@t{++}, @value{GDBN} attempts to compute
26582 each entity's name. @value{GDBN} can do this computation in two
26583 different ways, depending on exactly what information is present.
26584 When enabled, this setting causes @value{GDBN} to compute the names
26585 both ways and display any discrepancies.
26586 @item show debug check-physname
26587 Show the current state of ``physname'' checking.
26588
26589 @item set debug coff-pe-read
26590 @cindex COFF/PE exported symbols
26591 Control display of debugging messages related to reading of COFF/PE
26592 exported symbols. The default is off.
26593 @item show debug coff-pe-read
26594 Displays the current state of displaying debugging messages related to
26595 reading of COFF/PE exported symbols.
26596
26597 @item set debug dwarf-die
26598 @cindex DWARF DIEs
26599 Dump DWARF DIEs after they are read in.
26600 The value is the number of nesting levels to print.
26601 A value of zero turns off the display.
26602 @item show debug dwarf-die
26603 Show the current state of DWARF DIE debugging.
26604
26605 @item set debug dwarf-line
26606 @cindex DWARF Line Tables
26607 Turns on or off display of debugging messages related to reading
26608 DWARF line tables. The default is 0 (off).
26609 A value of 1 provides basic information.
26610 A value greater than 1 provides more verbose information.
26611 @item show debug dwarf-line
26612 Show the current state of DWARF line table debugging.
26613
26614 @item set debug dwarf-read
26615 @cindex DWARF Reading
26616 Turns on or off display of debugging messages related to reading
26617 DWARF debug info. The default is 0 (off).
26618 A value of 1 provides basic information.
26619 A value greater than 1 provides more verbose information.
26620 @item show debug dwarf-read
26621 Show the current state of DWARF reader debugging.
26622
26623 @item set debug displaced
26624 @cindex displaced stepping debugging info
26625 Turns on or off display of @value{GDBN} debugging info for the
26626 displaced stepping support. The default is off.
26627 @item show debug displaced
26628 Displays the current state of displaying @value{GDBN} debugging info
26629 related to displaced stepping.
26630
26631 @item set debug event
26632 @cindex event debugging info
26633 Turns on or off display of @value{GDBN} event debugging info. The
26634 default is off.
26635 @item show debug event
26636 Displays the current state of displaying @value{GDBN} event debugging
26637 info.
26638
26639 @item set debug event-loop
26640 @cindex event-loop debugging
26641 Controls output of debugging info about the event loop. The possible
26642 values are @samp{off}, @samp{all} (shows all debugging info) and
26643 @samp{all-except-ui} (shows all debugging info except those about
26644 UI-related events).
26645 @item show debug event-loop
26646 Shows the current state of displaying debugging info about the event
26647 loop.
26648
26649 @item set debug expression
26650 @cindex expression debugging info
26651 Turns on or off display of debugging info about @value{GDBN}
26652 expression parsing. The default is off.
26653 @item show debug expression
26654 Displays the current state of displaying debugging info about
26655 @value{GDBN} expression parsing.
26656
26657 @item set debug fbsd-lwp
26658 @cindex FreeBSD LWP debug messages
26659 Turns on or off debugging messages from the FreeBSD LWP debug support.
26660 @item show debug fbsd-lwp
26661 Show the current state of FreeBSD LWP debugging messages.
26662
26663 @item set debug fbsd-nat
26664 @cindex FreeBSD native target debug messages
26665 Turns on or off debugging messages from the FreeBSD native target.
26666 @item show debug fbsd-nat
26667 Show the current state of FreeBSD native target debugging messages.
26668
26669 @item set debug fortran-array-slicing
26670 @cindex fortran array slicing debugging info
26671 Turns on or off display of @value{GDBN} Fortran array slicing
26672 debugging info. The default is off.
26673
26674 @item show debug fortran-array-slicing
26675 Displays the current state of displaying @value{GDBN} Fortran array
26676 slicing debugging info.
26677
26678 @item set debug frame
26679 @cindex frame debugging info
26680 Turns on or off display of @value{GDBN} frame debugging info. The
26681 default is off.
26682 @item show debug frame
26683 Displays the current state of displaying @value{GDBN} frame debugging
26684 info.
26685
26686 @item set debug gnu-nat
26687 @cindex @sc{gnu}/Hurd debug messages
26688 Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
26689 @item show debug gnu-nat
26690 Show the current state of @sc{gnu}/Hurd debugging messages.
26691
26692 @item set debug infrun
26693 @cindex inferior debugging info
26694 Turns on or off display of @value{GDBN} debugging info for running the inferior.
26695 The default is off. @file{infrun.c} contains GDB's runtime state machine used
26696 for implementing operations such as single-stepping the inferior.
26697 @item show debug infrun
26698 Displays the current state of @value{GDBN} inferior debugging.
26699
26700 @item set debug jit
26701 @cindex just-in-time compilation, debugging messages
26702 Turn on or off debugging messages from JIT debug support.
26703 @item show debug jit
26704 Displays the current state of @value{GDBN} JIT debugging.
26705
26706 @item set debug lin-lwp
26707 @cindex @sc{gnu}/Linux LWP debug messages
26708 @cindex Linux lightweight processes
26709 Turn on or off debugging messages from the Linux LWP debug support.
26710 @item show debug lin-lwp
26711 Show the current state of Linux LWP debugging messages.
26712
26713 @item set debug linux-namespaces
26714 @cindex @sc{gnu}/Linux namespaces debug messages
26715 Turn on or off debugging messages from the Linux namespaces debug support.
26716 @item show debug linux-namespaces
26717 Show the current state of Linux namespaces debugging messages.
26718
26719 @item set debug mach-o
26720 @cindex Mach-O symbols processing
26721 Control display of debugging messages related to Mach-O symbols
26722 processing. The default is off.
26723 @item show debug mach-o
26724 Displays the current state of displaying debugging messages related to
26725 reading of COFF/PE exported symbols.
26726
26727 @item set debug notification
26728 @cindex remote async notification debugging info
26729 Turn on or off debugging messages about remote async notification.
26730 The default is off.
26731 @item show debug notification
26732 Displays the current state of remote async notification debugging messages.
26733
26734 @item set debug observer
26735 @cindex observer debugging info
26736 Turns on or off display of @value{GDBN} observer debugging. This
26737 includes info such as the notification of observable events.
26738 @item show debug observer
26739 Displays the current state of observer debugging.
26740
26741 @item set debug overload
26742 @cindex C@t{++} overload debugging info
26743 Turns on or off display of @value{GDBN} C@t{++} overload debugging
26744 info. This includes info such as ranking of functions, etc. The default
26745 is off.
26746 @item show debug overload
26747 Displays the current state of displaying @value{GDBN} C@t{++} overload
26748 debugging info.
26749
26750 @cindex expression parser, debugging info
26751 @cindex debug expression parser
26752 @item set debug parser
26753 Turns on or off the display of expression parser debugging output.
26754 Internally, this sets the @code{yydebug} variable in the expression
26755 parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
26756 details. The default is off.
26757 @item show debug parser
26758 Show the current state of expression parser debugging.
26759
26760 @cindex packets, reporting on stdout
26761 @cindex serial connections, debugging
26762 @cindex debug remote protocol
26763 @cindex remote protocol debugging
26764 @cindex display remote packets
26765 @item set debug remote
26766 Turns on or off display of reports on all packets sent back and forth across
26767 the serial line to the remote machine. The info is printed on the
26768 @value{GDBN} standard output stream. The default is off.
26769 @item show debug remote
26770 Displays the state of display of remote packets.
26771
26772 @item set debug remote-packet-max-chars
26773 Sets the maximum number of characters to display for each remote packet when
26774 @code{set debug remote} is on. This is useful to prevent @value{GDBN} from
26775 displaying lengthy remote packets and polluting the console.
26776
26777 The default value is @code{512}, which means @value{GDBN} will truncate each
26778 remote packet after 512 bytes.
26779
26780 Setting this option to @code{unlimited} will disable truncation and will output
26781 the full length of the remote packets.
26782 @item show debug remote-packet-max-chars
26783 Displays the number of bytes to output for remote packet debugging.
26784
26785 @item set debug separate-debug-file
26786 Turns on or off display of debug output about separate debug file search.
26787 @item show debug separate-debug-file
26788 Displays the state of separate debug file search debug output.
26789
26790 @item set debug serial
26791 Turns on or off display of @value{GDBN} serial debugging info. The
26792 default is off.
26793 @item show debug serial
26794 Displays the current state of displaying @value{GDBN} serial debugging
26795 info.
26796
26797 @item set debug solib-frv
26798 @cindex FR-V shared-library debugging
26799 Turn on or off debugging messages for FR-V shared-library code.
26800 @item show debug solib-frv
26801 Display the current state of FR-V shared-library code debugging
26802 messages.
26803
26804 @item set debug symbol-lookup
26805 @cindex symbol lookup
26806 Turns on or off display of debugging messages related to symbol lookup.
26807 The default is 0 (off).
26808 A value of 1 provides basic information.
26809 A value greater than 1 provides more verbose information.
26810 @item show debug symbol-lookup
26811 Show the current state of symbol lookup debugging messages.
26812
26813 @item set debug symfile
26814 @cindex symbol file functions
26815 Turns on or off display of debugging messages related to symbol file functions.
26816 The default is off. @xref{Files}.
26817 @item show debug symfile
26818 Show the current state of symbol file debugging messages.
26819
26820 @item set debug symtab-create
26821 @cindex symbol table creation
26822 Turns on or off display of debugging messages related to symbol table creation.
26823 The default is 0 (off).
26824 A value of 1 provides basic information.
26825 A value greater than 1 provides more verbose information.
26826 @item show debug symtab-create
26827 Show the current state of symbol table creation debugging.
26828
26829 @item set debug target
26830 @cindex target debugging info
26831 Turns on or off display of @value{GDBN} target debugging info. This info
26832 includes what is going on at the target level of GDB, as it happens. The
26833 default is 0. Set it to 1 to track events, and to 2 to also track the
26834 value of large memory transfers.
26835 @item show debug target
26836 Displays the current state of displaying @value{GDBN} target debugging
26837 info.
26838
26839 @item set debug timestamp
26840 @cindex timestamping debugging info
26841 Turns on or off display of timestamps with @value{GDBN} debugging info.
26842 When enabled, seconds and microseconds are displayed before each debugging
26843 message.
26844 @item show debug timestamp
26845 Displays the current state of displaying timestamps with @value{GDBN}
26846 debugging info.
26847
26848 @item set debug varobj
26849 @cindex variable object debugging info
26850 Turns on or off display of @value{GDBN} variable object debugging
26851 info. The default is off.
26852 @item show debug varobj
26853 Displays the current state of displaying @value{GDBN} variable object
26854 debugging info.
26855
26856 @item set debug xml
26857 @cindex XML parser debugging
26858 Turn on or off debugging messages for built-in XML parsers.
26859 @item show debug xml
26860 Displays the current state of XML debugging messages.
26861 @end table
26862
26863 @node Other Misc Settings
26864 @section Other Miscellaneous Settings
26865 @cindex miscellaneous settings
26866
26867 @table @code
26868 @kindex set interactive-mode
26869 @item set interactive-mode
26870 If @code{on}, forces @value{GDBN} to assume that GDB was started
26871 in a terminal. In practice, this means that @value{GDBN} should wait
26872 for the user to answer queries generated by commands entered at
26873 the command prompt. If @code{off}, forces @value{GDBN} to operate
26874 in the opposite mode, and it uses the default answers to all queries.
26875 If @code{auto} (the default), @value{GDBN} tries to determine whether
26876 its standard input is a terminal, and works in interactive-mode if it
26877 is, non-interactively otherwise.
26878
26879 In the vast majority of cases, the debugger should be able to guess
26880 correctly which mode should be used. But this setting can be useful
26881 in certain specific cases, such as running a MinGW @value{GDBN}
26882 inside a cygwin window.
26883
26884 @kindex show interactive-mode
26885 @item show interactive-mode
26886 Displays whether the debugger is operating in interactive mode or not.
26887 @end table
26888
26889 @node Extending GDB
26890 @chapter Extending @value{GDBN}
26891 @cindex extending GDB
26892
26893 @value{GDBN} provides several mechanisms for extension.
26894 @value{GDBN} also provides the ability to automatically load
26895 extensions when it reads a file for debugging. This allows the
26896 user to automatically customize @value{GDBN} for the program
26897 being debugged.
26898
26899 @menu
26900 * Sequences:: Canned Sequences of @value{GDBN} Commands
26901 * Python:: Extending @value{GDBN} using Python
26902 * Guile:: Extending @value{GDBN} using Guile
26903 * Auto-loading extensions:: Automatically loading extensions
26904 * Multiple Extension Languages:: Working with multiple extension languages
26905 * Aliases:: Creating new spellings of existing commands
26906 @end menu
26907
26908 To facilitate the use of extension languages, @value{GDBN} is capable
26909 of evaluating the contents of a file. When doing so, @value{GDBN}
26910 can recognize which extension language is being used by looking at
26911 the filename extension. Files with an unrecognized filename extension
26912 are always treated as a @value{GDBN} Command Files.
26913 @xref{Command Files,, Command files}.
26914
26915 You can control how @value{GDBN} evaluates these files with the following
26916 setting:
26917
26918 @table @code
26919 @kindex set script-extension
26920 @kindex show script-extension
26921 @item set script-extension off
26922 All scripts are always evaluated as @value{GDBN} Command Files.
26923
26924 @item set script-extension soft
26925 The debugger determines the scripting language based on filename
26926 extension. If this scripting language is supported, @value{GDBN}
26927 evaluates the script using that language. Otherwise, it evaluates
26928 the file as a @value{GDBN} Command File.
26929
26930 @item set script-extension strict
26931 The debugger determines the scripting language based on filename
26932 extension, and evaluates the script using that language. If the
26933 language is not supported, then the evaluation fails.
26934
26935 @item show script-extension
26936 Display the current value of the @code{script-extension} option.
26937
26938 @end table
26939
26940 @ifset SYSTEM_GDBINIT_DIR
26941 This setting is not used for files in the system-wide gdbinit directory.
26942 Files in that directory must have an extension matching their language,
26943 or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
26944 commands. @xref{Startup}.
26945 @end ifset
26946
26947 @node Sequences
26948 @section Canned Sequences of Commands
26949
26950 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
26951 Command Lists}), @value{GDBN} provides two ways to store sequences of
26952 commands for execution as a unit: user-defined commands and command
26953 files.
26954
26955 @menu
26956 * Define:: How to define your own commands
26957 * Hooks:: Hooks for user-defined commands
26958 * Command Files:: How to write scripts of commands to be stored in a file
26959 * Output:: Commands for controlled output
26960 * Auto-loading sequences:: Controlling auto-loaded command files
26961 @end menu
26962
26963 @node Define
26964 @subsection User-defined Commands
26965
26966 @cindex user-defined command
26967 @cindex arguments, to user-defined commands
26968 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
26969 which you assign a new name as a command. This is done with the
26970 @code{define} command. User commands may accept an unlimited number of arguments
26971 separated by whitespace. Arguments are accessed within the user command
26972 via @code{$arg0@dots{}$argN}. A trivial example:
26973
26974 @smallexample
26975 define adder
26976 print $arg0 + $arg1 + $arg2
26977 end
26978 @end smallexample
26979
26980 @noindent
26981 To execute the command use:
26982
26983 @smallexample
26984 adder 1 2 3
26985 @end smallexample
26986
26987 @noindent
26988 This defines the command @code{adder}, which prints the sum of
26989 its three arguments. Note the arguments are text substitutions, so they may
26990 reference variables, use complex expressions, or even perform inferior
26991 functions calls.
26992
26993 @cindex argument count in user-defined commands
26994 @cindex how many arguments (user-defined commands)
26995 In addition, @code{$argc} may be used to find out how many arguments have
26996 been passed.
26997
26998 @smallexample
26999 define adder
27000 if $argc == 2
27001 print $arg0 + $arg1
27002 end
27003 if $argc == 3
27004 print $arg0 + $arg1 + $arg2
27005 end
27006 end
27007 @end smallexample
27008
27009 Combining with the @code{eval} command (@pxref{eval}) makes it easier
27010 to process a variable number of arguments:
27011
27012 @smallexample
27013 define adder
27014 set $i = 0
27015 set $sum = 0
27016 while $i < $argc
27017 eval "set $sum = $sum + $arg%d", $i
27018 set $i = $i + 1
27019 end
27020 print $sum
27021 end
27022 @end smallexample
27023
27024 @table @code
27025
27026 @kindex define
27027 @item define @var{commandname}
27028 Define a command named @var{commandname}. If there is already a command
27029 by that name, you are asked to confirm that you want to redefine it.
27030 The argument @var{commandname} may be a bare command name consisting of letters,
27031 numbers, dashes, dots, and underscores. It may also start with any
27032 predefined or user-defined prefix command.
27033 For example, @samp{define target my-target} creates
27034 a user-defined @samp{target my-target} command.
27035
27036 The definition of the command is made up of other @value{GDBN} command lines,
27037 which are given following the @code{define} command. The end of these
27038 commands is marked by a line containing @code{end}.
27039
27040 @kindex document
27041 @kindex end@r{ (user-defined commands)}
27042 @item document @var{commandname}
27043 Document the user-defined command @var{commandname}, so that it can be
27044 accessed by @code{help}. The command @var{commandname} must already be
27045 defined. This command reads lines of documentation just as @code{define}
27046 reads the lines of the command definition, ending with @code{end}.
27047 After the @code{document} command is finished, @code{help} on command
27048 @var{commandname} displays the documentation you have written.
27049
27050 You may use the @code{document} command again to change the
27051 documentation of a command. Redefining the command with @code{define}
27052 does not change the documentation.
27053
27054 @kindex define-prefix
27055 @item define-prefix @var{commandname}
27056 Define or mark the command @var{commandname} as a user-defined prefix
27057 command. Once marked, @var{commandname} can be used as prefix command
27058 by the @code{define} command.
27059 Note that @code{define-prefix} can be used with a not yet defined
27060 @var{commandname}. In such a case, @var{commandname} is defined as
27061 an empty user-defined command.
27062 In case you redefine a command that was marked as a user-defined
27063 prefix command, the subcommands of the redefined command are kept
27064 (and @value{GDBN} indicates so to the user).
27065
27066 Example:
27067 @example
27068 (gdb) define-prefix abc
27069 (gdb) define-prefix abc def
27070 (gdb) define abc def
27071 Type commands for definition of "abc def".
27072 End with a line saying just "end".
27073 >echo command initial def\n
27074 >end
27075 (gdb) define abc def ghi
27076 Type commands for definition of "abc def ghi".
27077 End with a line saying just "end".
27078 >echo command ghi\n
27079 >end
27080 (gdb) define abc def
27081 Keeping subcommands of prefix command "def".
27082 Redefine command "def"? (y or n) y
27083 Type commands for definition of "abc def".
27084 End with a line saying just "end".
27085 >echo command def\n
27086 >end
27087 (gdb) abc def ghi
27088 command ghi
27089 (gdb) abc def
27090 command def
27091 (gdb)
27092 @end example
27093
27094 @kindex dont-repeat
27095 @cindex don't repeat command
27096 @item dont-repeat
27097 Used inside a user-defined command, this tells @value{GDBN} that this
27098 command should not be repeated when the user hits @key{RET}
27099 (@pxref{Command Syntax, repeat last command}).
27100
27101 @kindex help user-defined
27102 @item help user-defined
27103 List all user-defined commands and all python commands defined in class
27104 COMMAND_USER. The first line of the documentation or docstring is
27105 included (if any).
27106
27107 @kindex show user
27108 @item show user
27109 @itemx show user @var{commandname}
27110 Display the @value{GDBN} commands used to define @var{commandname} (but
27111 not its documentation). If no @var{commandname} is given, display the
27112 definitions for all user-defined commands.
27113 This does not work for user-defined python commands.
27114
27115 @cindex infinite recursion in user-defined commands
27116 @kindex show max-user-call-depth
27117 @kindex set max-user-call-depth
27118 @item show max-user-call-depth
27119 @itemx set max-user-call-depth
27120 The value of @code{max-user-call-depth} controls how many recursion
27121 levels are allowed in user-defined commands before @value{GDBN} suspects an
27122 infinite recursion and aborts the command.
27123 This does not apply to user-defined python commands.
27124 @end table
27125
27126 In addition to the above commands, user-defined commands frequently
27127 use control flow commands, described in @ref{Command Files}.
27128
27129 When user-defined commands are executed, the
27130 commands of the definition are not printed. An error in any command
27131 stops execution of the user-defined command.
27132
27133 If used interactively, commands that would ask for confirmation proceed
27134 without asking when used inside a user-defined command. Many @value{GDBN}
27135 commands that normally print messages to say what they are doing omit the
27136 messages when used in a user-defined command.
27137
27138 @node Hooks
27139 @subsection User-defined Command Hooks
27140 @cindex command hooks
27141 @cindex hooks, for commands
27142 @cindex hooks, pre-command
27143
27144 @kindex hook
27145 You may define @dfn{hooks}, which are a special kind of user-defined
27146 command. Whenever you run the command @samp{foo}, if the user-defined
27147 command @samp{hook-foo} exists, it is executed (with no arguments)
27148 before that command.
27149
27150 @cindex hooks, post-command
27151 @kindex hookpost
27152 A hook may also be defined which is run after the command you executed.
27153 Whenever you run the command @samp{foo}, if the user-defined command
27154 @samp{hookpost-foo} exists, it is executed (with no arguments) after
27155 that command. Post-execution hooks may exist simultaneously with
27156 pre-execution hooks, for the same command.
27157
27158 It is valid for a hook to call the command which it hooks. If this
27159 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
27160
27161 @c It would be nice if hookpost could be passed a parameter indicating
27162 @c if the command it hooks executed properly or not. FIXME!
27163
27164 @kindex stop@r{, a pseudo-command}
27165 In addition, a pseudo-command, @samp{stop} exists. Defining
27166 (@samp{hook-stop}) makes the associated commands execute every time
27167 execution stops in your program: before breakpoint commands are run,
27168 displays are printed, or the stack frame is printed.
27169
27170 For example, to ignore @code{SIGALRM} signals while
27171 single-stepping, but treat them normally during normal execution,
27172 you could define:
27173
27174 @smallexample
27175 define hook-stop
27176 handle SIGALRM nopass
27177 end
27178
27179 define hook-run
27180 handle SIGALRM pass
27181 end
27182
27183 define hook-continue
27184 handle SIGALRM pass
27185 end
27186 @end smallexample
27187
27188 As a further example, to hook at the beginning and end of the @code{echo}
27189 command, and to add extra text to the beginning and end of the message,
27190 you could define:
27191
27192 @smallexample
27193 define hook-echo
27194 echo <<<---
27195 end
27196
27197 define hookpost-echo
27198 echo --->>>\n
27199 end
27200
27201 (@value{GDBP}) echo Hello World
27202 <<<---Hello World--->>>
27203 (@value{GDBP})
27204
27205 @end smallexample
27206
27207 You can define a hook for any single-word command in @value{GDBN}, but
27208 not for command aliases; you should define a hook for the basic command
27209 name, e.g.@: @code{backtrace} rather than @code{bt}.
27210 @c FIXME! So how does Joe User discover whether a command is an alias
27211 @c or not?
27212 You can hook a multi-word command by adding @code{hook-} or
27213 @code{hookpost-} to the last word of the command, e.g.@:
27214 @samp{define target hook-remote} to add a hook to @samp{target remote}.
27215
27216 If an error occurs during the execution of your hook, execution of
27217 @value{GDBN} commands stops and @value{GDBN} issues a prompt
27218 (before the command that you actually typed had a chance to run).
27219
27220 If you try to define a hook which does not match any known command, you
27221 get a warning from the @code{define} command.
27222
27223 @node Command Files
27224 @subsection Command Files
27225
27226 @cindex command files
27227 @cindex scripting commands
27228 A command file for @value{GDBN} is a text file made of lines that are
27229 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
27230 also be included. An empty line in a command file does nothing; it
27231 does not mean to repeat the last command, as it would from the
27232 terminal.
27233
27234 You can request the execution of a command file with the @code{source}
27235 command. Note that the @code{source} command is also used to evaluate
27236 scripts that are not Command Files. The exact behavior can be configured
27237 using the @code{script-extension} setting.
27238 @xref{Extending GDB,, Extending GDB}.
27239
27240 @table @code
27241 @kindex source
27242 @cindex execute commands from a file
27243 @item source [-s] [-v] @var{filename}
27244 Execute the command file @var{filename}.
27245 @end table
27246
27247 The lines in a command file are generally executed sequentially,
27248 unless the order of execution is changed by one of the
27249 @emph{flow-control commands} described below. The commands are not
27250 printed as they are executed. An error in any command terminates
27251 execution of the command file and control is returned to the console.
27252
27253 @value{GDBN} first searches for @var{filename} in the current directory.
27254 If the file is not found there, and @var{filename} does not specify a
27255 directory, then @value{GDBN} also looks for the file on the source search path
27256 (specified with the @samp{directory} command);
27257 except that @file{$cdir} is not searched because the compilation directory
27258 is not relevant to scripts.
27259
27260 If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
27261 on the search path even if @var{filename} specifies a directory.
27262 The search is done by appending @var{filename} to each element of the
27263 search path. So, for example, if @var{filename} is @file{mylib/myscript}
27264 and the search path contains @file{/home/user} then @value{GDBN} will
27265 look for the script @file{/home/user/mylib/myscript}.
27266 The search is also done if @var{filename} is an absolute path.
27267 For example, if @var{filename} is @file{/tmp/myscript} and
27268 the search path contains @file{/home/user} then @value{GDBN} will
27269 look for the script @file{/home/user/tmp/myscript}.
27270 For DOS-like systems, if @var{filename} contains a drive specification,
27271 it is stripped before concatenation. For example, if @var{filename} is
27272 @file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
27273 will look for the script @file{c:/tmp/myscript}.
27274
27275 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
27276 each command as it is executed. The option must be given before
27277 @var{filename}, and is interpreted as part of the filename anywhere else.
27278
27279 Commands that would ask for confirmation if used interactively proceed
27280 without asking when used in a command file. Many @value{GDBN} commands that
27281 normally print messages to say what they are doing omit the messages
27282 when called from command files.
27283
27284 @value{GDBN} also accepts command input from standard input. In this
27285 mode, normal output goes to standard output and error output goes to
27286 standard error. Errors in a command file supplied on standard input do
27287 not terminate execution of the command file---execution continues with
27288 the next command.
27289
27290 @smallexample
27291 gdb < cmds > log 2>&1
27292 @end smallexample
27293
27294 (The syntax above will vary depending on the shell used.) This example
27295 will execute commands from the file @file{cmds}. All output and errors
27296 would be directed to @file{log}.
27297
27298 Since commands stored on command files tend to be more general than
27299 commands typed interactively, they frequently need to deal with
27300 complicated situations, such as different or unexpected values of
27301 variables and symbols, changes in how the program being debugged is
27302 built, etc. @value{GDBN} provides a set of flow-control commands to
27303 deal with these complexities. Using these commands, you can write
27304 complex scripts that loop over data structures, execute commands
27305 conditionally, etc.
27306
27307 @table @code
27308 @kindex if
27309 @kindex else
27310 @item if
27311 @itemx else
27312 This command allows to include in your script conditionally executed
27313 commands. The @code{if} command takes a single argument, which is an
27314 expression to evaluate. It is followed by a series of commands that
27315 are executed only if the expression is true (its value is nonzero).
27316 There can then optionally be an @code{else} line, followed by a series
27317 of commands that are only executed if the expression was false. The
27318 end of the list is marked by a line containing @code{end}.
27319
27320 @kindex while
27321 @item while
27322 This command allows to write loops. Its syntax is similar to
27323 @code{if}: the command takes a single argument, which is an expression
27324 to evaluate, and must be followed by the commands to execute, one per
27325 line, terminated by an @code{end}. These commands are called the
27326 @dfn{body} of the loop. The commands in the body of @code{while} are
27327 executed repeatedly as long as the expression evaluates to true.
27328
27329 @kindex loop_break
27330 @item loop_break
27331 This command exits the @code{while} loop in whose body it is included.
27332 Execution of the script continues after that @code{while}s @code{end}
27333 line.
27334
27335 @kindex loop_continue
27336 @item loop_continue
27337 This command skips the execution of the rest of the body of commands
27338 in the @code{while} loop in whose body it is included. Execution
27339 branches to the beginning of the @code{while} loop, where it evaluates
27340 the controlling expression.
27341
27342 @kindex end@r{ (if/else/while commands)}
27343 @item end
27344 Terminate the block of commands that are the body of @code{if},
27345 @code{else}, or @code{while} flow-control commands.
27346 @end table
27347
27348
27349 @node Output
27350 @subsection Commands for Controlled Output
27351
27352 During the execution of a command file or a user-defined command, normal
27353 @value{GDBN} output is suppressed; the only output that appears is what is
27354 explicitly printed by the commands in the definition. This section
27355 describes three commands useful for generating exactly the output you
27356 want.
27357
27358 @table @code
27359 @kindex echo
27360 @item echo @var{text}
27361 @c I do not consider backslash-space a standard C escape sequence
27362 @c because it is not in ANSI.
27363 Print @var{text}. Nonprinting characters can be included in
27364 @var{text} using C escape sequences, such as @samp{\n} to print a
27365 newline. @strong{No newline is printed unless you specify one.}
27366 In addition to the standard C escape sequences, a backslash followed
27367 by a space stands for a space. This is useful for displaying a
27368 string with spaces at the beginning or the end, since leading and
27369 trailing spaces are otherwise trimmed from all arguments.
27370 To print @samp{@w{ }and foo =@w{ }}, use the command
27371 @samp{echo \@w{ }and foo = \@w{ }}.
27372
27373 A backslash at the end of @var{text} can be used, as in C, to continue
27374 the command onto subsequent lines. For example,
27375
27376 @smallexample
27377 echo This is some text\n\
27378 which is continued\n\
27379 onto several lines.\n
27380 @end smallexample
27381
27382 produces the same output as
27383
27384 @smallexample
27385 echo This is some text\n
27386 echo which is continued\n
27387 echo onto several lines.\n
27388 @end smallexample
27389
27390 @kindex output
27391 @item output @var{expression}
27392 Print the value of @var{expression} and nothing but that value: no
27393 newlines, no @samp{$@var{nn} = }. The value is not entered in the
27394 value history either. @xref{Expressions, ,Expressions}, for more information
27395 on expressions.
27396
27397 @item output/@var{fmt} @var{expression}
27398 Print the value of @var{expression} in format @var{fmt}. You can use
27399 the same formats as for @code{print}. @xref{Output Formats,,Output
27400 Formats}, for more information.
27401
27402 @kindex printf
27403 @item printf @var{template}, @var{expressions}@dots{}
27404 Print the values of one or more @var{expressions} under the control of
27405 the string @var{template}. To print several values, make
27406 @var{expressions} be a comma-separated list of individual expressions,
27407 which may be either numbers or pointers. Their values are printed as
27408 specified by @var{template}, exactly as a C program would do by
27409 executing the code below:
27410
27411 @smallexample
27412 printf (@var{template}, @var{expressions}@dots{});
27413 @end smallexample
27414
27415 As in @code{C} @code{printf}, ordinary characters in @var{template}
27416 are printed verbatim, while @dfn{conversion specification} introduced
27417 by the @samp{%} character cause subsequent @var{expressions} to be
27418 evaluated, their values converted and formatted according to type and
27419 style information encoded in the conversion specifications, and then
27420 printed.
27421
27422 For example, you can print two values in hex like this:
27423
27424 @smallexample
27425 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
27426 @end smallexample
27427
27428 @code{printf} supports all the standard @code{C} conversion
27429 specifications, including the flags and modifiers between the @samp{%}
27430 character and the conversion letter, with the following exceptions:
27431
27432 @itemize @bullet
27433 @item
27434 The argument-ordering modifiers, such as @samp{2$}, are not supported.
27435
27436 @item
27437 The modifier @samp{*} is not supported for specifying precision or
27438 width.
27439
27440 @item
27441 The @samp{'} flag (for separation of digits into groups according to
27442 @code{LC_NUMERIC'}) is not supported.
27443
27444 @item
27445 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
27446 supported.
27447
27448 @item
27449 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
27450
27451 @item
27452 The conversion letters @samp{a} and @samp{A} are not supported.
27453 @end itemize
27454
27455 @noindent
27456 Note that the @samp{ll} type modifier is supported only if the
27457 underlying @code{C} implementation used to build @value{GDBN} supports
27458 the @code{long long int} type, and the @samp{L} type modifier is
27459 supported only if @code{long double} type is available.
27460
27461 As in @code{C}, @code{printf} supports simple backslash-escape
27462 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
27463 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
27464 single character. Octal and hexadecimal escape sequences are not
27465 supported.
27466
27467 Additionally, @code{printf} supports conversion specifications for DFP
27468 (@dfn{Decimal Floating Point}) types using the following length modifiers
27469 together with a floating point specifier.
27470 letters:
27471
27472 @itemize @bullet
27473 @item
27474 @samp{H} for printing @code{Decimal32} types.
27475
27476 @item
27477 @samp{D} for printing @code{Decimal64} types.
27478
27479 @item
27480 @samp{DD} for printing @code{Decimal128} types.
27481 @end itemize
27482
27483 If the underlying @code{C} implementation used to build @value{GDBN} has
27484 support for the three length modifiers for DFP types, other modifiers
27485 such as width and precision will also be available for @value{GDBN} to use.
27486
27487 In case there is no such @code{C} support, no additional modifiers will be
27488 available and the value will be printed in the standard way.
27489
27490 Here's an example of printing DFP types using the above conversion letters:
27491 @smallexample
27492 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
27493 @end smallexample
27494
27495 @anchor{eval}
27496 @kindex eval
27497 @item eval @var{template}, @var{expressions}@dots{}
27498 Convert the values of one or more @var{expressions} under the control of
27499 the string @var{template} to a command line, and call it.
27500
27501 @end table
27502
27503 @node Auto-loading sequences
27504 @subsection Controlling auto-loading native @value{GDBN} scripts
27505 @cindex native script auto-loading
27506
27507 When a new object file is read (for example, due to the @code{file}
27508 command, or because the inferior has loaded a shared library),
27509 @value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
27510 @xref{Auto-loading extensions}.
27511
27512 Auto-loading can be enabled or disabled,
27513 and the list of auto-loaded scripts can be printed.
27514
27515 @table @code
27516 @anchor{set auto-load gdb-scripts}
27517 @kindex set auto-load gdb-scripts
27518 @item set auto-load gdb-scripts [on|off]
27519 Enable or disable the auto-loading of canned sequences of commands scripts.
27520
27521 @anchor{show auto-load gdb-scripts}
27522 @kindex show auto-load gdb-scripts
27523 @item show auto-load gdb-scripts
27524 Show whether auto-loading of canned sequences of commands scripts is enabled or
27525 disabled.
27526
27527 @anchor{info auto-load gdb-scripts}
27528 @kindex info auto-load gdb-scripts
27529 @cindex print list of auto-loaded canned sequences of commands scripts
27530 @item info auto-load gdb-scripts [@var{regexp}]
27531 Print the list of all canned sequences of commands scripts that @value{GDBN}
27532 auto-loaded.
27533 @end table
27534
27535 If @var{regexp} is supplied only canned sequences of commands scripts with
27536 matching names are printed.
27537
27538 @c Python docs live in a separate file.
27539 @include python.texi
27540
27541 @c Guile docs live in a separate file.
27542 @include guile.texi
27543
27544 @node Auto-loading extensions
27545 @section Auto-loading extensions
27546 @cindex auto-loading extensions
27547
27548 @value{GDBN} provides two mechanisms for automatically loading extensions
27549 when a new object file is read (for example, due to the @code{file}
27550 command, or because the inferior has loaded a shared library):
27551 @file{@var{objfile}-gdb.@var{ext}} and the @code{.debug_gdb_scripts}
27552 section of modern file formats like ELF.
27553
27554 @menu
27555 * objfile-gdb.ext file: objfile-gdbdotext file. The @file{@var{objfile}-gdb.@var{ext}} file
27556 * .debug_gdb_scripts section: dotdebug_gdb_scripts section. The @code{.debug_gdb_scripts} section
27557 * Which flavor to choose?::
27558 @end menu
27559
27560 The auto-loading feature is useful for supplying application-specific
27561 debugging commands and features.
27562
27563 Auto-loading can be enabled or disabled,
27564 and the list of auto-loaded scripts can be printed.
27565 See the @samp{auto-loading} section of each extension language
27566 for more information.
27567 For @value{GDBN} command files see @ref{Auto-loading sequences}.
27568 For Python files see @ref{Python Auto-loading}.
27569
27570 Note that loading of this script file also requires accordingly configured
27571 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27572
27573 @node objfile-gdbdotext file
27574 @subsection The @file{@var{objfile}-gdb.@var{ext}} file
27575 @cindex @file{@var{objfile}-gdb.gdb}
27576 @cindex @file{@var{objfile}-gdb.py}
27577 @cindex @file{@var{objfile}-gdb.scm}
27578
27579 When a new object file is read, @value{GDBN} looks for a file named
27580 @file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
27581 where @var{objfile} is the object file's name and
27582 where @var{ext} is the file extension for the extension language:
27583
27584 @table @code
27585 @item @file{@var{objfile}-gdb.gdb}
27586 GDB's own command language
27587 @item @file{@var{objfile}-gdb.py}
27588 Python
27589 @item @file{@var{objfile}-gdb.scm}
27590 Guile
27591 @end table
27592
27593 @var{script-name} is formed by ensuring that the file name of @var{objfile}
27594 is absolute, following all symlinks, and resolving @code{.} and @code{..}
27595 components, and appending the @file{-gdb.@var{ext}} suffix.
27596 If this file exists and is readable, @value{GDBN} will evaluate it as a
27597 script in the specified extension language.
27598
27599 If this file does not exist, then @value{GDBN} will look for
27600 @var{script-name} file in all of the directories as specified below.
27601 (On MS-Windows/MS-DOS, the drive letter of the executable's leading
27602 directories is converted to a one-letter subdirectory, i.e.@:
27603 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
27604 filesystems disallow colons in file names.)
27605
27606 Note that loading of these files requires an accordingly configured
27607 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27608
27609 For object files using @file{.exe} suffix @value{GDBN} tries to load first the
27610 scripts normally according to its @file{.exe} filename. But if no scripts are
27611 found @value{GDBN} also tries script filenames matching the object file without
27612 its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
27613 is attempted on any platform. This makes the script filenames compatible
27614 between Unix and MS-Windows hosts.
27615
27616 @table @code
27617 @anchor{set auto-load scripts-directory}
27618 @kindex set auto-load scripts-directory
27619 @item set auto-load scripts-directory @r{[}@var{directories}@r{]}
27620 Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
27621 may be delimited by the host platform path separator in use
27622 (@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
27623
27624 Each entry here needs to be covered also by the security setting
27625 @code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
27626
27627 @anchor{with-auto-load-dir}
27628 This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
27629 @code{set auto-load safe-path} value can be also overriden by @value{GDBN}
27630 configuration option @option{--with-auto-load-dir}.
27631
27632 Any reference to @file{$debugdir} will get replaced by
27633 @var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
27634 reference to @file{$datadir} will get replaced by @var{data-directory} which is
27635 determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
27636 @file{$datadir} must be placed as a directory component --- either alone or
27637 delimited by @file{/} or @file{\} directory separators, depending on the host
27638 platform.
27639
27640 The list of directories uses path separator (@samp{:} on GNU and Unix
27641 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
27642 to the @env{PATH} environment variable.
27643
27644 @anchor{show auto-load scripts-directory}
27645 @kindex show auto-load scripts-directory
27646 @item show auto-load scripts-directory
27647 Show @value{GDBN} auto-loaded scripts location.
27648
27649 @anchor{add-auto-load-scripts-directory}
27650 @kindex add-auto-load-scripts-directory
27651 @item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
27652 Add an entry (or list of entries) to the list of auto-loaded scripts locations.
27653 Multiple entries may be delimited by the host platform path separator in use.
27654 @end table
27655
27656 @value{GDBN} does not track which files it has already auto-loaded this way.
27657 @value{GDBN} will load the associated script every time the corresponding
27658 @var{objfile} is opened.
27659 So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
27660 is evaluated more than once.
27661
27662 @node dotdebug_gdb_scripts section
27663 @subsection The @code{.debug_gdb_scripts} section
27664 @cindex @code{.debug_gdb_scripts} section
27665
27666 For systems using file formats like ELF and COFF,
27667 when @value{GDBN} loads a new object file
27668 it will look for a special section named @code{.debug_gdb_scripts}.
27669 If this section exists, its contents is a list of null-terminated entries
27670 specifying scripts to load. Each entry begins with a non-null prefix byte that
27671 specifies the kind of entry, typically the extension language and whether the
27672 script is in a file or inlined in @code{.debug_gdb_scripts}.
27673
27674 The following entries are supported:
27675
27676 @table @code
27677 @item SECTION_SCRIPT_ID_PYTHON_FILE = 1
27678 @item SECTION_SCRIPT_ID_SCHEME_FILE = 3
27679 @item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
27680 @item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
27681 @end table
27682
27683 @subsubsection Script File Entries
27684
27685 If the entry specifies a file, @value{GDBN} will look for the file first
27686 in the current directory and then along the source search path
27687 (@pxref{Source Path, ,Specifying Source Directories}),
27688 except that @file{$cdir} is not searched, since the compilation
27689 directory is not relevant to scripts.
27690
27691 File entries can be placed in section @code{.debug_gdb_scripts} with,
27692 for example, this GCC macro for Python scripts.
27693
27694 @example
27695 /* Note: The "MS" section flags are to remove duplicates. */
27696 #define DEFINE_GDB_PY_SCRIPT(script_name) \
27697 asm("\
27698 .pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
27699 .byte 1 /* Python */\n\
27700 .asciz \"" script_name "\"\n\
27701 .popsection \n\
27702 ");
27703 @end example
27704
27705 @noindent
27706 For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
27707 Then one can reference the macro in a header or source file like this:
27708
27709 @example
27710 DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
27711 @end example
27712
27713 The script name may include directories if desired.
27714
27715 Note that loading of this script file also requires accordingly configured
27716 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27717
27718 If the macro invocation is put in a header, any application or library
27719 using this header will get a reference to the specified script,
27720 and with the use of @code{"MS"} attributes on the section, the linker
27721 will remove duplicates.
27722
27723 @subsubsection Script Text Entries
27724
27725 Script text entries allow to put the executable script in the entry
27726 itself instead of loading it from a file.
27727 The first line of the entry, everything after the prefix byte and up to
27728 the first newline (@code{0xa}) character, is the script name, and must not
27729 contain any kind of space character, e.g., spaces or tabs.
27730 The rest of the entry, up to the trailing null byte, is the script to
27731 execute in the specified language. The name needs to be unique among
27732 all script names, as @value{GDBN} executes each script only once based
27733 on its name.
27734
27735 Here is an example from file @file{py-section-script.c} in the @value{GDBN}
27736 testsuite.
27737
27738 @example
27739 #include "symcat.h"
27740 #include "gdb/section-scripts.h"
27741 asm(
27742 ".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
27743 ".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
27744 ".ascii \"gdb.inlined-script\\n\"\n"
27745 ".ascii \"class test_cmd (gdb.Command):\\n\"\n"
27746 ".ascii \" def __init__ (self):\\n\"\n"
27747 ".ascii \" super (test_cmd, self).__init__ ("
27748 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
27749 ".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
27750 ".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
27751 ".ascii \"test_cmd ()\\n\"\n"
27752 ".byte 0\n"
27753 ".popsection\n"
27754 );
27755 @end example
27756
27757 Loading of inlined scripts requires a properly configured
27758 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27759 The path to specify in @code{auto-load safe-path} is the path of the file
27760 containing the @code{.debug_gdb_scripts} section.
27761
27762 @node Which flavor to choose?
27763 @subsection Which flavor to choose?
27764
27765 Given the multiple ways of auto-loading extensions, it might not always
27766 be clear which one to choose. This section provides some guidance.
27767
27768 @noindent
27769 Benefits of the @file{-gdb.@var{ext}} way:
27770
27771 @itemize @bullet
27772 @item
27773 Can be used with file formats that don't support multiple sections.
27774
27775 @item
27776 Ease of finding scripts for public libraries.
27777
27778 Scripts specified in the @code{.debug_gdb_scripts} section are searched for
27779 in the source search path.
27780 For publicly installed libraries, e.g., @file{libstdc++}, there typically
27781 isn't a source directory in which to find the script.
27782
27783 @item
27784 Doesn't require source code additions.
27785 @end itemize
27786
27787 @noindent
27788 Benefits of the @code{.debug_gdb_scripts} way:
27789
27790 @itemize @bullet
27791 @item
27792 Works with static linking.
27793
27794 Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
27795 trigger their loading. When an application is statically linked the only
27796 objfile available is the executable, and it is cumbersome to attach all the
27797 scripts from all the input libraries to the executable's
27798 @file{-gdb.@var{ext}} script.
27799
27800 @item
27801 Works with classes that are entirely inlined.
27802
27803 Some classes can be entirely inlined, and thus there may not be an associated
27804 shared library to attach a @file{-gdb.@var{ext}} script to.
27805
27806 @item
27807 Scripts needn't be copied out of the source tree.
27808
27809 In some circumstances, apps can be built out of large collections of internal
27810 libraries, and the build infrastructure necessary to install the
27811 @file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
27812 cumbersome. It may be easier to specify the scripts in the
27813 @code{.debug_gdb_scripts} section as relative paths, and add a path to the
27814 top of the source tree to the source search path.
27815 @end itemize
27816
27817 @node Multiple Extension Languages
27818 @section Multiple Extension Languages
27819
27820 The Guile and Python extension languages do not share any state,
27821 and generally do not interfere with each other.
27822 There are some things to be aware of, however.
27823
27824 @subsection Python comes first
27825
27826 Python was @value{GDBN}'s first extension language, and to avoid breaking
27827 existing behaviour Python comes first. This is generally solved by the
27828 ``first one wins'' principle. @value{GDBN} maintains a list of enabled
27829 extension languages, and when it makes a call to an extension language,
27830 (say to pretty-print a value), it tries each in turn until an extension
27831 language indicates it has performed the request (e.g., has returned the
27832 pretty-printed form of a value).
27833 This extends to errors while performing such requests: If an error happens
27834 while, for example, trying to pretty-print an object then the error is
27835 reported and any following extension languages are not tried.
27836
27837 @node Aliases
27838 @section Creating new spellings of existing commands
27839 @cindex aliases for commands
27840
27841 It is often useful to define alternate spellings of existing commands.
27842 For example, if a new @value{GDBN} command defined in Python has
27843 a long name to type, it is handy to have an abbreviated version of it
27844 that involves less typing.
27845
27846 @value{GDBN} itself uses aliases. For example @samp{s} is an alias
27847 of the @samp{step} command even though it is otherwise an ambiguous
27848 abbreviation of other commands like @samp{set} and @samp{show}.
27849
27850 Aliases are also used to provide shortened or more common versions
27851 of multi-word commands. For example, @value{GDBN} provides the
27852 @samp{tty} alias of the @samp{set inferior-tty} command.
27853
27854 You can define a new alias with the @samp{alias} command.
27855
27856 @table @code
27857
27858 @kindex alias
27859 @item alias [-a] [--] @var{ALIAS} = @var{COMMAND} [DEFAULT-ARGS...]
27860
27861 @end table
27862
27863 @var{ALIAS} specifies the name of the new alias.
27864 Each word of @var{ALIAS} must consist of letters, numbers, dashes and
27865 underscores.
27866
27867 @var{COMMAND} specifies the name of an existing command
27868 that is being aliased.
27869
27870 @var{COMMAND} can also be the name of an existing alias. In this case,
27871 @var{COMMAND} cannot be an alias that has default arguments.
27872
27873 The @samp{-a} option specifies that the new alias is an abbreviation
27874 of the command. Abbreviations are not used in command completion.
27875
27876 The @samp{--} option specifies the end of options,
27877 and is useful when @var{ALIAS} begins with a dash.
27878
27879 You can specify @var{default-args} for your alias.
27880 These @var{default-args} will be automatically added before the alias
27881 arguments typed explicitly on the command line.
27882
27883 For example, the below defines an alias @code{btfullall} that shows all local
27884 variables and all frame arguments:
27885 @smallexample
27886 (@value{GDBP}) alias btfullall = backtrace -full -frame-arguments all
27887 @end smallexample
27888
27889 For more information about @var{default-args}, see @ref{Command aliases default args,
27890 ,Automatically prepend default arguments to user-defined aliases}.
27891
27892 Here is a simple example showing how to make an abbreviation
27893 of a command so that there is less to type.
27894 Suppose you were tired of typing @samp{disas}, the current
27895 shortest unambiguous abbreviation of the @samp{disassemble} command
27896 and you wanted an even shorter version named @samp{di}.
27897 The following will accomplish this.
27898
27899 @smallexample
27900 (gdb) alias -a di = disas
27901 @end smallexample
27902
27903 Note that aliases are different from user-defined commands.
27904 With a user-defined command, you also need to write documentation
27905 for it with the @samp{document} command.
27906 An alias automatically picks up the documentation of the existing command.
27907
27908 Here is an example where we make @samp{elms} an abbreviation of
27909 @samp{elements} in the @samp{set print elements} command.
27910 This is to show that you can make an abbreviation of any part
27911 of a command.
27912
27913 @smallexample
27914 (gdb) alias -a set print elms = set print elements
27915 (gdb) alias -a show print elms = show print elements
27916 (gdb) set p elms 20
27917 (gdb) show p elms
27918 Limit on string chars or array elements to print is 200.
27919 @end smallexample
27920
27921 Note that if you are defining an alias of a @samp{set} command,
27922 and you want to have an alias for the corresponding @samp{show}
27923 command, then you need to define the latter separately.
27924
27925 Unambiguously abbreviated commands are allowed in @var{COMMAND} and
27926 @var{ALIAS}, just as they are normally.
27927
27928 @smallexample
27929 (gdb) alias -a set pr elms = set p ele
27930 @end smallexample
27931
27932 Finally, here is an example showing the creation of a one word
27933 alias for a more complex command.
27934 This creates alias @samp{spe} of the command @samp{set print elements}.
27935
27936 @smallexample
27937 (gdb) alias spe = set print elements
27938 (gdb) spe 20
27939 @end smallexample
27940
27941 @node Interpreters
27942 @chapter Command Interpreters
27943 @cindex command interpreters
27944
27945 @value{GDBN} supports multiple command interpreters, and some command
27946 infrastructure to allow users or user interface writers to switch
27947 between interpreters or run commands in other interpreters.
27948
27949 @value{GDBN} currently supports two command interpreters, the console
27950 interpreter (sometimes called the command-line interpreter or @sc{cli})
27951 and the machine interface interpreter (or @sc{gdb/mi}). This manual
27952 describes both of these interfaces in great detail.
27953
27954 By default, @value{GDBN} will start with the console interpreter.
27955 However, the user may choose to start @value{GDBN} with another
27956 interpreter by specifying the @option{-i} or @option{--interpreter}
27957 startup options. Defined interpreters include:
27958
27959 @table @code
27960 @item console
27961 @cindex console interpreter
27962 The traditional console or command-line interpreter. This is the most often
27963 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
27964 @value{GDBN} will use this interpreter.
27965
27966 @item mi
27967 @cindex mi interpreter
27968 The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
27969 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
27970 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
27971 Interface}.
27972
27973 @item mi3
27974 @cindex mi3 interpreter
27975 The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
27976
27977 @item mi2
27978 @cindex mi2 interpreter
27979 The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
27980
27981 @item mi1
27982 @cindex mi1 interpreter
27983 The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
27984
27985 @end table
27986
27987 @cindex invoke another interpreter
27988
27989 @kindex interpreter-exec
27990 You may execute commands in any interpreter from the current
27991 interpreter using the appropriate command. If you are running the
27992 console interpreter, simply use the @code{interpreter-exec} command:
27993
27994 @smallexample
27995 interpreter-exec mi "-data-list-register-names"
27996 @end smallexample
27997
27998 @sc{gdb/mi} has a similar command, although it is only available in versions of
27999 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
28000
28001 Note that @code{interpreter-exec} only changes the interpreter for the
28002 duration of the specified command. It does not change the interpreter
28003 permanently.
28004
28005 @cindex start a new independent interpreter
28006
28007 Although you may only choose a single interpreter at startup, it is
28008 possible to run an independent interpreter on a specified input/output
28009 device (usually a tty).
28010
28011 For example, consider a debugger GUI or IDE that wants to provide a
28012 @value{GDBN} console view. It may do so by embedding a terminal
28013 emulator widget in its GUI, starting @value{GDBN} in the traditional
28014 command-line mode with stdin/stdout/stderr redirected to that
28015 terminal, and then creating an MI interpreter running on a specified
28016 input/output device. The console interpreter created by @value{GDBN}
28017 at startup handles commands the user types in the terminal widget,
28018 while the GUI controls and synchronizes state with @value{GDBN} using
28019 the separate MI interpreter.
28020
28021 To start a new secondary @dfn{user interface} running MI, use the
28022 @code{new-ui} command:
28023
28024 @kindex new-ui
28025 @cindex new user interface
28026 @smallexample
28027 new-ui @var{interpreter} @var{tty}
28028 @end smallexample
28029
28030 The @var{interpreter} parameter specifies the interpreter to run.
28031 This accepts the same values as the @code{interpreter-exec} command.
28032 For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
28033 @var{tty} parameter specifies the name of the bidirectional file the
28034 interpreter uses for input/output, usually the name of a
28035 pseudoterminal slave on Unix systems. For example:
28036
28037 @smallexample
28038 (@value{GDBP}) new-ui mi /dev/pts/9
28039 @end smallexample
28040
28041 @noindent
28042 runs an MI interpreter on @file{/dev/pts/9}.
28043
28044 @node TUI
28045 @chapter @value{GDBN} Text User Interface
28046 @cindex TUI
28047 @cindex Text User Interface
28048
28049 @menu
28050 * TUI Overview:: TUI overview
28051 * TUI Keys:: TUI key bindings
28052 * TUI Single Key Mode:: TUI single key mode
28053 * TUI Commands:: TUI-specific commands
28054 * TUI Configuration:: TUI configuration variables
28055 @end menu
28056
28057 The @value{GDBN} Text User Interface (TUI) is a terminal
28058 interface which uses the @code{curses} library to show the source
28059 file, the assembly output, the program registers and @value{GDBN}
28060 commands in separate text windows. The TUI mode is supported only
28061 on platforms where a suitable version of the @code{curses} library
28062 is available.
28063
28064 The TUI mode is enabled by default when you invoke @value{GDBN} as
28065 @samp{@value{GDBP} -tui}.
28066 You can also switch in and out of TUI mode while @value{GDBN} runs by
28067 using various TUI commands and key bindings, such as @command{tui
28068 enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
28069 @ref{TUI Keys, ,TUI Key Bindings}.
28070
28071 @node TUI Overview
28072 @section TUI Overview
28073
28074 In TUI mode, @value{GDBN} can display several text windows:
28075
28076 @table @emph
28077 @item command
28078 This window is the @value{GDBN} command window with the @value{GDBN}
28079 prompt and the @value{GDBN} output. The @value{GDBN} input is still
28080 managed using readline.
28081
28082 @item source
28083 The source window shows the source file of the program. The current
28084 line and active breakpoints are displayed in this window.
28085
28086 @item assembly
28087 The assembly window shows the disassembly output of the program.
28088
28089 @item register
28090 This window shows the processor registers. Registers are highlighted
28091 when their values change.
28092 @end table
28093
28094 The source and assembly windows show the current program position
28095 by highlighting the current line and marking it with a @samp{>} marker.
28096 Breakpoints are indicated with two markers. The first marker
28097 indicates the breakpoint type:
28098
28099 @table @code
28100 @item B
28101 Breakpoint which was hit at least once.
28102
28103 @item b
28104 Breakpoint which was never hit.
28105
28106 @item H
28107 Hardware breakpoint which was hit at least once.
28108
28109 @item h
28110 Hardware breakpoint which was never hit.
28111 @end table
28112
28113 The second marker indicates whether the breakpoint is enabled or not:
28114
28115 @table @code
28116 @item +
28117 Breakpoint is enabled.
28118
28119 @item -
28120 Breakpoint is disabled.
28121 @end table
28122
28123 The source, assembly and register windows are updated when the current
28124 thread changes, when the frame changes, or when the program counter
28125 changes.
28126
28127 These windows are not all visible at the same time. The command
28128 window is always visible. The others can be arranged in several
28129 layouts:
28130
28131 @itemize @bullet
28132 @item
28133 source only,
28134
28135 @item
28136 assembly only,
28137
28138 @item
28139 source and assembly,
28140
28141 @item
28142 source and registers, or
28143
28144 @item
28145 assembly and registers.
28146 @end itemize
28147
28148 These are the standard layouts, but other layouts can be defined.
28149
28150 A status line above the command window shows the following information:
28151
28152 @table @emph
28153 @item target
28154 Indicates the current @value{GDBN} target.
28155 (@pxref{Targets, ,Specifying a Debugging Target}).
28156
28157 @item process
28158 Gives the current process or thread number.
28159 When no process is being debugged, this field is set to @code{No process}.
28160
28161 @item function
28162 Gives the current function name for the selected frame.
28163 The name is demangled if demangling is turned on (@pxref{Print Settings}).
28164 When there is no symbol corresponding to the current program counter,
28165 the string @code{??} is displayed.
28166
28167 @item line
28168 Indicates the current line number for the selected frame.
28169 When the current line number is not known, the string @code{??} is displayed.
28170
28171 @item pc
28172 Indicates the current program counter address.
28173 @end table
28174
28175 @node TUI Keys
28176 @section TUI Key Bindings
28177 @cindex TUI key bindings
28178
28179 The TUI installs several key bindings in the readline keymaps
28180 @ifset SYSTEM_READLINE
28181 (@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
28182 @end ifset
28183 @ifclear SYSTEM_READLINE
28184 (@pxref{Command Line Editing}).
28185 @end ifclear
28186 The following key bindings are installed for both TUI mode and the
28187 @value{GDBN} standard mode.
28188
28189 @table @kbd
28190 @kindex C-x C-a
28191 @item C-x C-a
28192 @kindex C-x a
28193 @itemx C-x a
28194 @kindex C-x A
28195 @itemx C-x A
28196 Enter or leave the TUI mode. When leaving the TUI mode,
28197 the curses window management stops and @value{GDBN} operates using
28198 its standard mode, writing on the terminal directly. When reentering
28199 the TUI mode, control is given back to the curses windows.
28200 The screen is then refreshed.
28201
28202 This key binding uses the bindable Readline function
28203 @code{tui-switch-mode}.
28204
28205 @kindex C-x 1
28206 @item C-x 1
28207 Use a TUI layout with only one window. The layout will
28208 either be @samp{source} or @samp{assembly}. When the TUI mode
28209 is not active, it will switch to the TUI mode.
28210
28211 Think of this key binding as the Emacs @kbd{C-x 1} binding.
28212
28213 This key binding uses the bindable Readline function
28214 @code{tui-delete-other-windows}.
28215
28216 @kindex C-x 2
28217 @item C-x 2
28218 Use a TUI layout with at least two windows. When the current
28219 layout already has two windows, the next layout with two windows is used.
28220 When a new layout is chosen, one window will always be common to the
28221 previous layout and the new one.
28222
28223 Think of it as the Emacs @kbd{C-x 2} binding.
28224
28225 This key binding uses the bindable Readline function
28226 @code{tui-change-windows}.
28227
28228 @kindex C-x o
28229 @item C-x o
28230 Change the active window. The TUI associates several key bindings
28231 (like scrolling and arrow keys) with the active window. This command
28232 gives the focus to the next TUI window.
28233
28234 Think of it as the Emacs @kbd{C-x o} binding.
28235
28236 This key binding uses the bindable Readline function
28237 @code{tui-other-window}.
28238
28239 @kindex C-x s
28240 @item C-x s
28241 Switch in and out of the TUI SingleKey mode that binds single
28242 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
28243
28244 This key binding uses the bindable Readline function
28245 @code{next-keymap}.
28246 @end table
28247
28248 The following key bindings only work in the TUI mode:
28249
28250 @table @asis
28251 @kindex PgUp
28252 @item @key{PgUp}
28253 Scroll the active window one page up.
28254
28255 @kindex PgDn
28256 @item @key{PgDn}
28257 Scroll the active window one page down.
28258
28259 @kindex Up
28260 @item @key{Up}
28261 Scroll the active window one line up.
28262
28263 @kindex Down
28264 @item @key{Down}
28265 Scroll the active window one line down.
28266
28267 @kindex Left
28268 @item @key{Left}
28269 Scroll the active window one column left.
28270
28271 @kindex Right
28272 @item @key{Right}
28273 Scroll the active window one column right.
28274
28275 @kindex C-L
28276 @item @kbd{C-L}
28277 Refresh the screen.
28278 @end table
28279
28280 Because the arrow keys scroll the active window in the TUI mode, they
28281 are not available for their normal use by readline unless the command
28282 window has the focus. When another window is active, you must use
28283 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
28284 and @kbd{C-f} to control the command window.
28285
28286 @node TUI Single Key Mode
28287 @section TUI Single Key Mode
28288 @cindex TUI single key mode
28289
28290 The TUI also provides a @dfn{SingleKey} mode, which binds several
28291 frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
28292 switch into this mode, where the following key bindings are used:
28293
28294 @table @kbd
28295 @kindex c @r{(SingleKey TUI key)}
28296 @item c
28297 continue
28298
28299 @kindex d @r{(SingleKey TUI key)}
28300 @item d
28301 down
28302
28303 @kindex f @r{(SingleKey TUI key)}
28304 @item f
28305 finish
28306
28307 @kindex n @r{(SingleKey TUI key)}
28308 @item n
28309 next
28310
28311 @kindex o @r{(SingleKey TUI key)}
28312 @item o
28313 nexti. The shortcut letter @samp{o} stands for ``step Over''.
28314
28315 @kindex q @r{(SingleKey TUI key)}
28316 @item q
28317 exit the SingleKey mode.
28318
28319 @kindex r @r{(SingleKey TUI key)}
28320 @item r
28321 run
28322
28323 @kindex s @r{(SingleKey TUI key)}
28324 @item s
28325 step
28326
28327 @kindex i @r{(SingleKey TUI key)}
28328 @item i
28329 stepi. The shortcut letter @samp{i} stands for ``step Into''.
28330
28331 @kindex u @r{(SingleKey TUI key)}
28332 @item u
28333 up
28334
28335 @kindex v @r{(SingleKey TUI key)}
28336 @item v
28337 info locals
28338
28339 @kindex w @r{(SingleKey TUI key)}
28340 @item w
28341 where
28342 @end table
28343
28344 Other keys temporarily switch to the @value{GDBN} command prompt.
28345 The key that was pressed is inserted in the editing buffer so that
28346 it is possible to type most @value{GDBN} commands without interaction
28347 with the TUI SingleKey mode. Once the command is entered the TUI
28348 SingleKey mode is restored. The only way to permanently leave
28349 this mode is by typing @kbd{q} or @kbd{C-x s}.
28350
28351 @cindex SingleKey keymap name
28352 If @value{GDBN} was built with Readline 8.0 or later, the TUI
28353 SingleKey keymap will be named @samp{SingleKey}. This can be used in
28354 @file{.inputrc} to add additional bindings to this keymap.
28355
28356 @node TUI Commands
28357 @section TUI-specific Commands
28358 @cindex TUI commands
28359
28360 The TUI has specific commands to control the text windows.
28361 These commands are always available, even when @value{GDBN} is not in
28362 the TUI mode. When @value{GDBN} is in the standard mode, most
28363 of these commands will automatically switch to the TUI mode.
28364
28365 Note that if @value{GDBN}'s @code{stdout} is not connected to a
28366 terminal, or @value{GDBN} has been started with the machine interface
28367 interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
28368 these commands will fail with an error, because it would not be
28369 possible or desirable to enable curses window management.
28370
28371 @table @code
28372 @item tui enable
28373 @kindex tui enable
28374 Activate TUI mode. The last active TUI window layout will be used if
28375 TUI mode has previously been used in the current debugging session,
28376 otherwise a default layout is used.
28377
28378 @item tui disable
28379 @kindex tui disable
28380 Disable TUI mode, returning to the console interpreter.
28381
28382 @item info win
28383 @kindex info win
28384 List and give the size of all displayed windows.
28385
28386 @item tui new-layout @var{name} @var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}
28387 @kindex tui new-layout
28388 Create a new TUI layout. The new layout will be named @var{name}, and
28389 can be accessed using the @code{layout} command (see below).
28390
28391 Each @var{window} parameter is either the name of a window to display,
28392 or a window description. The windows will be displayed from top to
28393 bottom in the order listed.
28394
28395 The names of the windows are the same as the ones given to the
28396 @code{focus} command (see below); additional, the @code{status}
28397 window can be specified. Note that, because it is of fixed height,
28398 the weight assigned to the status window is of no importance. It is
28399 conventional to use @samp{0} here.
28400
28401 A window description looks a bit like an invocation of @code{tui
28402 new-layout}, and is of the form
28403 @{@r{[}@code{-horizontal}@r{]}@var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}@}.
28404
28405 This specifies a sub-layout. If @code{-horizontal} is given, the
28406 windows in this description will be arranged side-by-side, rather than
28407 top-to-bottom.
28408
28409 Each @var{weight} is an integer. It is the weight of this window
28410 relative to all the other windows in the layout. These numbers are
28411 used to calculate how much of the screen is given to each window.
28412
28413 For example:
28414
28415 @example
28416 (gdb) tui new-layout example src 1 regs 1 status 0 cmd 1
28417 @end example
28418
28419 Here, the new layout is called @samp{example}. It shows the source
28420 and register windows, followed by the status window, and then finally
28421 the command window. The non-status windows all have the same weight,
28422 so the terminal will be split into three roughly equal sections.
28423
28424 Here is a more complex example, showing a horizontal layout:
28425
28426 @example
28427 (gdb) tui new-layout example @{-horizontal src 1 asm 1@} 2 status 0 cmd 1
28428 @end example
28429
28430 This will result in side-by-side source and assembly windows; with the
28431 status and command window being beneath these, filling the entire
28432 width of the terminal. Because they have weight 2, the source and
28433 assembly windows will be twice the height of the command window.
28434
28435 @item layout @var{name}
28436 @kindex layout
28437 Changes which TUI windows are displayed. The @var{name} parameter
28438 controls which layout is shown. It can be either one of the built-in
28439 layout names, or the name of a layout defined by the user using
28440 @code{tui new-layout}.
28441
28442 The built-in layouts are as follows:
28443
28444 @table @code
28445 @item next
28446 Display the next layout.
28447
28448 @item prev
28449 Display the previous layout.
28450
28451 @item src
28452 Display the source and command windows.
28453
28454 @item asm
28455 Display the assembly and command windows.
28456
28457 @item split
28458 Display the source, assembly, and command windows.
28459
28460 @item regs
28461 When in @code{src} layout display the register, source, and command
28462 windows. When in @code{asm} or @code{split} layout display the
28463 register, assembler, and command windows.
28464 @end table
28465
28466 @item focus @var{name}
28467 @kindex focus
28468 Changes which TUI window is currently active for scrolling. The
28469 @var{name} parameter can be any of the following:
28470
28471 @table @code
28472 @item next
28473 Make the next window active for scrolling.
28474
28475 @item prev
28476 Make the previous window active for scrolling.
28477
28478 @item src
28479 Make the source window active for scrolling.
28480
28481 @item asm
28482 Make the assembly window active for scrolling.
28483
28484 @item regs
28485 Make the register window active for scrolling.
28486
28487 @item cmd
28488 Make the command window active for scrolling.
28489 @end table
28490
28491 @item refresh
28492 @kindex refresh
28493 Refresh the screen. This is similar to typing @kbd{C-L}.
28494
28495 @item tui reg @var{group}
28496 @kindex tui reg
28497 Changes the register group displayed in the tui register window to
28498 @var{group}. If the register window is not currently displayed this
28499 command will cause the register window to be displayed. The list of
28500 register groups, as well as their order is target specific. The
28501 following groups are available on most targets:
28502 @table @code
28503 @item next
28504 Repeatedly selecting this group will cause the display to cycle
28505 through all of the available register groups.
28506
28507 @item prev
28508 Repeatedly selecting this group will cause the display to cycle
28509 through all of the available register groups in the reverse order to
28510 @var{next}.
28511
28512 @item general
28513 Display the general registers.
28514 @item float
28515 Display the floating point registers.
28516 @item system
28517 Display the system registers.
28518 @item vector
28519 Display the vector registers.
28520 @item all
28521 Display all registers.
28522 @end table
28523
28524 @item update
28525 @kindex update
28526 Update the source window and the current execution point.
28527
28528 @item winheight @var{name} +@var{count}
28529 @itemx winheight @var{name} -@var{count}
28530 @kindex winheight
28531 Change the height of the window @var{name} by @var{count}
28532 lines. Positive counts increase the height, while negative counts
28533 decrease it. The @var{name} parameter can be one of @code{src} (the
28534 source window), @code{cmd} (the command window), @code{asm} (the
28535 disassembly window), or @code{regs} (the register display window).
28536 @end table
28537
28538 @node TUI Configuration
28539 @section TUI Configuration Variables
28540 @cindex TUI configuration variables
28541
28542 Several configuration variables control the appearance of TUI windows.
28543
28544 @table @code
28545 @item set tui border-kind @var{kind}
28546 @kindex set tui border-kind
28547 Select the border appearance for the source, assembly and register windows.
28548 The possible values are the following:
28549 @table @code
28550 @item space
28551 Use a space character to draw the border.
28552
28553 @item ascii
28554 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
28555
28556 @item acs
28557 Use the Alternate Character Set to draw the border. The border is
28558 drawn using character line graphics if the terminal supports them.
28559 @end table
28560
28561 @item set tui border-mode @var{mode}
28562 @kindex set tui border-mode
28563 @itemx set tui active-border-mode @var{mode}
28564 @kindex set tui active-border-mode
28565 Select the display attributes for the borders of the inactive windows
28566 or the active window. The @var{mode} can be one of the following:
28567 @table @code
28568 @item normal
28569 Use normal attributes to display the border.
28570
28571 @item standout
28572 Use standout mode.
28573
28574 @item reverse
28575 Use reverse video mode.
28576
28577 @item half
28578 Use half bright mode.
28579
28580 @item half-standout
28581 Use half bright and standout mode.
28582
28583 @item bold
28584 Use extra bright or bold mode.
28585
28586 @item bold-standout
28587 Use extra bright or bold and standout mode.
28588 @end table
28589
28590 @item set tui tab-width @var{nchars}
28591 @kindex set tui tab-width
28592 @kindex tabset
28593 Set the width of tab stops to be @var{nchars} characters. This
28594 setting affects the display of TAB characters in the source and
28595 assembly windows.
28596
28597 @item set tui compact-source @r{[}on@r{|}off@r{]}
28598 @kindex set tui compact-source
28599 Set whether the TUI source window is displayed in ``compact'' form.
28600 The default display uses more space for line numbers and starts the
28601 source text at the next tab stop; the compact display uses only as
28602 much space as is needed for the line numbers in the current file, and
28603 only a single space to separate the line numbers from the source.
28604 @end table
28605
28606 Note that the colors of the TUI borders can be controlled using the
28607 appropriate @code{set style} commands. @xref{Output Styling}.
28608
28609 @node Emacs
28610 @chapter Using @value{GDBN} under @sc{gnu} Emacs
28611
28612 @cindex Emacs
28613 @cindex @sc{gnu} Emacs
28614 A special interface allows you to use @sc{gnu} Emacs to view (and
28615 edit) the source files for the program you are debugging with
28616 @value{GDBN}.
28617
28618 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
28619 executable file you want to debug as an argument. This command starts
28620 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
28621 created Emacs buffer.
28622 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
28623
28624 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
28625 things:
28626
28627 @itemize @bullet
28628 @item
28629 All ``terminal'' input and output goes through an Emacs buffer, called
28630 the GUD buffer.
28631
28632 This applies both to @value{GDBN} commands and their output, and to the input
28633 and output done by the program you are debugging.
28634
28635 This is useful because it means that you can copy the text of previous
28636 commands and input them again; you can even use parts of the output
28637 in this way.
28638
28639 All the facilities of Emacs' Shell mode are available for interacting
28640 with your program. In particular, you can send signals the usual
28641 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
28642 stop.
28643
28644 @item
28645 @value{GDBN} displays source code through Emacs.
28646
28647 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
28648 source file for that frame and puts an arrow (@samp{=>}) at the
28649 left margin of the current line. Emacs uses a separate buffer for
28650 source display, and splits the screen to show both your @value{GDBN} session
28651 and the source.
28652
28653 Explicit @value{GDBN} @code{list} or search commands still produce output as
28654 usual, but you probably have no reason to use them from Emacs.
28655 @end itemize
28656
28657 We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
28658 a graphical mode, enabled by default, which provides further buffers
28659 that can control the execution and describe the state of your program.
28660 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
28661
28662 If you specify an absolute file name when prompted for the @kbd{M-x
28663 gdb} argument, then Emacs sets your current working directory to where
28664 your program resides. If you only specify the file name, then Emacs
28665 sets your current working directory to the directory associated
28666 with the previous buffer. In this case, @value{GDBN} may find your
28667 program by searching your environment's @code{PATH} variable, but on
28668 some operating systems it might not find the source. So, although the
28669 @value{GDBN} input and output session proceeds normally, the auxiliary
28670 buffer does not display the current source and line of execution.
28671
28672 The initial working directory of @value{GDBN} is printed on the top
28673 line of the GUD buffer and this serves as a default for the commands
28674 that specify files for @value{GDBN} to operate on. @xref{Files,
28675 ,Commands to Specify Files}.
28676
28677 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
28678 need to call @value{GDBN} by a different name (for example, if you
28679 keep several configurations around, with different names) you can
28680 customize the Emacs variable @code{gud-gdb-command-name} to run the
28681 one you want.
28682
28683 In the GUD buffer, you can use these special Emacs commands in
28684 addition to the standard Shell mode commands:
28685
28686 @table @kbd
28687 @item C-h m
28688 Describe the features of Emacs' GUD Mode.
28689
28690 @item C-c C-s
28691 Execute to another source line, like the @value{GDBN} @code{step} command; also
28692 update the display window to show the current file and location.
28693
28694 @item C-c C-n
28695 Execute to next source line in this function, skipping all function
28696 calls, like the @value{GDBN} @code{next} command. Then update the display window
28697 to show the current file and location.
28698
28699 @item C-c C-i
28700 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
28701 display window accordingly.
28702
28703 @item C-c C-f
28704 Execute until exit from the selected stack frame, like the @value{GDBN}
28705 @code{finish} command.
28706
28707 @item C-c C-r
28708 Continue execution of your program, like the @value{GDBN} @code{continue}
28709 command.
28710
28711 @item C-c <
28712 Go up the number of frames indicated by the numeric argument
28713 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
28714 like the @value{GDBN} @code{up} command.
28715
28716 @item C-c >
28717 Go down the number of frames indicated by the numeric argument, like the
28718 @value{GDBN} @code{down} command.
28719 @end table
28720
28721 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
28722 tells @value{GDBN} to set a breakpoint on the source line point is on.
28723
28724 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
28725 separate frame which shows a backtrace when the GUD buffer is current.
28726 Move point to any frame in the stack and type @key{RET} to make it
28727 become the current frame and display the associated source in the
28728 source buffer. Alternatively, click @kbd{Mouse-2} to make the
28729 selected frame become the current one. In graphical mode, the
28730 speedbar displays watch expressions.
28731
28732 If you accidentally delete the source-display buffer, an easy way to get
28733 it back is to type the command @code{f} in the @value{GDBN} buffer, to
28734 request a frame display; when you run under Emacs, this recreates
28735 the source buffer if necessary to show you the context of the current
28736 frame.
28737
28738 The source files displayed in Emacs are in ordinary Emacs buffers
28739 which are visiting the source files in the usual way. You can edit
28740 the files with these buffers if you wish; but keep in mind that @value{GDBN}
28741 communicates with Emacs in terms of line numbers. If you add or
28742 delete lines from the text, the line numbers that @value{GDBN} knows cease
28743 to correspond properly with the code.
28744
28745 A more detailed description of Emacs' interaction with @value{GDBN} is
28746 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
28747 Emacs Manual}).
28748
28749 @node GDB/MI
28750 @chapter The @sc{gdb/mi} Interface
28751
28752 @unnumberedsec Function and Purpose
28753
28754 @cindex @sc{gdb/mi}, its purpose
28755 @sc{gdb/mi} is a line based machine oriented text interface to
28756 @value{GDBN} and is activated by specifying using the
28757 @option{--interpreter} command line option (@pxref{Mode Options}). It
28758 is specifically intended to support the development of systems which
28759 use the debugger as just one small component of a larger system.
28760
28761 This chapter is a specification of the @sc{gdb/mi} interface. It is written
28762 in the form of a reference manual.
28763
28764 Note that @sc{gdb/mi} is still under construction, so some of the
28765 features described below are incomplete and subject to change
28766 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
28767
28768 @unnumberedsec Notation and Terminology
28769
28770 @cindex notational conventions, for @sc{gdb/mi}
28771 This chapter uses the following notation:
28772
28773 @itemize @bullet
28774 @item
28775 @code{|} separates two alternatives.
28776
28777 @item
28778 @code{[ @var{something} ]} indicates that @var{something} is optional:
28779 it may or may not be given.
28780
28781 @item
28782 @code{( @var{group} )*} means that @var{group} inside the parentheses
28783 may repeat zero or more times.
28784
28785 @item
28786 @code{( @var{group} )+} means that @var{group} inside the parentheses
28787 may repeat one or more times.
28788
28789 @item
28790 @code{"@var{string}"} means a literal @var{string}.
28791 @end itemize
28792
28793 @ignore
28794 @heading Dependencies
28795 @end ignore
28796
28797 @menu
28798 * GDB/MI General Design::
28799 * GDB/MI Command Syntax::
28800 * GDB/MI Compatibility with CLI::
28801 * GDB/MI Development and Front Ends::
28802 * GDB/MI Output Records::
28803 * GDB/MI Simple Examples::
28804 * GDB/MI Command Description Format::
28805 * GDB/MI Breakpoint Commands::
28806 * GDB/MI Catchpoint Commands::
28807 * GDB/MI Program Context::
28808 * GDB/MI Thread Commands::
28809 * GDB/MI Ada Tasking Commands::
28810 * GDB/MI Program Execution::
28811 * GDB/MI Stack Manipulation::
28812 * GDB/MI Variable Objects::
28813 * GDB/MI Data Manipulation::
28814 * GDB/MI Tracepoint Commands::
28815 * GDB/MI Symbol Query::
28816 * GDB/MI File Commands::
28817 @ignore
28818 * GDB/MI Kod Commands::
28819 * GDB/MI Memory Overlay Commands::
28820 * GDB/MI Signal Handling Commands::
28821 @end ignore
28822 * GDB/MI Target Manipulation::
28823 * GDB/MI File Transfer Commands::
28824 * GDB/MI Ada Exceptions Commands::
28825 * GDB/MI Support Commands::
28826 * GDB/MI Miscellaneous Commands::
28827 @end menu
28828
28829 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28830 @node GDB/MI General Design
28831 @section @sc{gdb/mi} General Design
28832 @cindex GDB/MI General Design
28833
28834 Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
28835 parts---commands sent to @value{GDBN}, responses to those commands
28836 and notifications. Each command results in exactly one response,
28837 indicating either successful completion of the command, or an error.
28838 For the commands that do not resume the target, the response contains the
28839 requested information. For the commands that resume the target, the
28840 response only indicates whether the target was successfully resumed.
28841 Notifications is the mechanism for reporting changes in the state of the
28842 target, or in @value{GDBN} state, that cannot conveniently be associated with
28843 a command and reported as part of that command response.
28844
28845 The important examples of notifications are:
28846 @itemize @bullet
28847
28848 @item
28849 Exec notifications. These are used to report changes in
28850 target state---when a target is resumed, or stopped. It would not
28851 be feasible to include this information in response of resuming
28852 commands, because one resume commands can result in multiple events in
28853 different threads. Also, quite some time may pass before any event
28854 happens in the target, while a frontend needs to know whether the resuming
28855 command itself was successfully executed.
28856
28857 @item
28858 Console output, and status notifications. Console output
28859 notifications are used to report output of CLI commands, as well as
28860 diagnostics for other commands. Status notifications are used to
28861 report the progress of a long-running operation. Naturally, including
28862 this information in command response would mean no output is produced
28863 until the command is finished, which is undesirable.
28864
28865 @item
28866 General notifications. Commands may have various side effects on
28867 the @value{GDBN} or target state beyond their official purpose. For example,
28868 a command may change the selected thread. Although such changes can
28869 be included in command response, using notification allows for more
28870 orthogonal frontend design.
28871
28872 @end itemize
28873
28874 There's no guarantee that whenever an MI command reports an error,
28875 @value{GDBN} or the target are in any specific state, and especially,
28876 the state is not reverted to the state before the MI command was
28877 processed. Therefore, whenever an MI command results in an error,
28878 we recommend that the frontend refreshes all the information shown in
28879 the user interface.
28880
28881
28882 @menu
28883 * Context management::
28884 * Asynchronous and non-stop modes::
28885 * Thread groups::
28886 @end menu
28887
28888 @node Context management
28889 @subsection Context management
28890
28891 @subsubsection Threads and Frames
28892
28893 In most cases when @value{GDBN} accesses the target, this access is
28894 done in context of a specific thread and frame (@pxref{Frames}).
28895 Often, even when accessing global data, the target requires that a thread
28896 be specified. The CLI interface maintains the selected thread and frame,
28897 and supplies them to target on each command. This is convenient,
28898 because a command line user would not want to specify that information
28899 explicitly on each command, and because user interacts with
28900 @value{GDBN} via a single terminal, so no confusion is possible as
28901 to what thread and frame are the current ones.
28902
28903 In the case of MI, the concept of selected thread and frame is less
28904 useful. First, a frontend can easily remember this information
28905 itself. Second, a graphical frontend can have more than one window,
28906 each one used for debugging a different thread, and the frontend might
28907 want to access additional threads for internal purposes. This
28908 increases the risk that by relying on implicitly selected thread, the
28909 frontend may be operating on a wrong one. Therefore, each MI command
28910 should explicitly specify which thread and frame to operate on. To
28911 make it possible, each MI command accepts the @samp{--thread} and
28912 @samp{--frame} options, the value to each is @value{GDBN} global
28913 identifier for thread and frame to operate on.
28914
28915 Usually, each top-level window in a frontend allows the user to select
28916 a thread and a frame, and remembers the user selection for further
28917 operations. However, in some cases @value{GDBN} may suggest that the
28918 current thread or frame be changed. For example, when stopping on a
28919 breakpoint it is reasonable to switch to the thread where breakpoint is
28920 hit. For another example, if the user issues the CLI @samp{thread} or
28921 @samp{frame} commands via the frontend, it is desirable to change the
28922 frontend's selection to the one specified by user. @value{GDBN}
28923 communicates the suggestion to change current thread and frame using the
28924 @samp{=thread-selected} notification.
28925
28926 Note that historically, MI shares the selected thread with CLI, so
28927 frontends used the @code{-thread-select} to execute commands in the
28928 right context. However, getting this to work right is cumbersome. The
28929 simplest way is for frontend to emit @code{-thread-select} command
28930 before every command. This doubles the number of commands that need
28931 to be sent. The alternative approach is to suppress @code{-thread-select}
28932 if the selected thread in @value{GDBN} is supposed to be identical to the
28933 thread the frontend wants to operate on. However, getting this
28934 optimization right can be tricky. In particular, if the frontend
28935 sends several commands to @value{GDBN}, and one of the commands changes the
28936 selected thread, then the behaviour of subsequent commands will
28937 change. So, a frontend should either wait for response from such
28938 problematic commands, or explicitly add @code{-thread-select} for
28939 all subsequent commands. No frontend is known to do this exactly
28940 right, so it is suggested to just always pass the @samp{--thread} and
28941 @samp{--frame} options.
28942
28943 @subsubsection Language
28944
28945 The execution of several commands depends on which language is selected.
28946 By default, the current language (@pxref{show language}) is used.
28947 But for commands known to be language-sensitive, it is recommended
28948 to use the @samp{--language} option. This option takes one argument,
28949 which is the name of the language to use while executing the command.
28950 For instance:
28951
28952 @smallexample
28953 -data-evaluate-expression --language c "sizeof (void*)"
28954 ^done,value="4"
28955 (gdb)
28956 @end smallexample
28957
28958 The valid language names are the same names accepted by the
28959 @samp{set language} command (@pxref{Manually}), excluding @samp{auto},
28960 @samp{local} or @samp{unknown}.
28961
28962 @node Asynchronous and non-stop modes
28963 @subsection Asynchronous command execution and non-stop mode
28964
28965 On some targets, @value{GDBN} is capable of processing MI commands
28966 even while the target is running. This is called @dfn{asynchronous
28967 command execution} (@pxref{Background Execution}). The frontend may
28968 specify a preference for asynchronous execution using the
28969 @code{-gdb-set mi-async 1} command, which should be emitted before
28970 either running the executable or attaching to the target. After the
28971 frontend has started the executable or attached to the target, it can
28972 find if asynchronous execution is enabled using the
28973 @code{-list-target-features} command.
28974
28975 @table @code
28976 @item -gdb-set mi-async on
28977 @item -gdb-set mi-async off
28978 Set whether MI is in asynchronous mode.
28979
28980 When @code{off}, which is the default, MI execution commands (e.g.,
28981 @code{-exec-continue}) are foreground commands, and @value{GDBN} waits
28982 for the program to stop before processing further commands.
28983
28984 When @code{on}, MI execution commands are background execution
28985 commands (e.g., @code{-exec-continue} becomes the equivalent of the
28986 @code{c&} CLI command), and so @value{GDBN} is capable of processing
28987 MI commands even while the target is running.
28988
28989 @item -gdb-show mi-async
28990 Show whether MI asynchronous mode is enabled.
28991 @end table
28992
28993 Note: In @value{GDBN} version 7.7 and earlier, this option was called
28994 @code{target-async} instead of @code{mi-async}, and it had the effect
28995 of both putting MI in asynchronous mode and making CLI background
28996 commands possible. CLI background commands are now always possible
28997 ``out of the box'' if the target supports them. The old spelling is
28998 kept as a deprecated alias for backwards compatibility.
28999
29000 Even if @value{GDBN} can accept a command while target is running,
29001 many commands that access the target do not work when the target is
29002 running. Therefore, asynchronous command execution is most useful
29003 when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
29004 it is possible to examine the state of one thread, while other threads
29005 are running.
29006
29007 When a given thread is running, MI commands that try to access the
29008 target in the context of that thread may not work, or may work only on
29009 some targets. In particular, commands that try to operate on thread's
29010 stack will not work, on any target. Commands that read memory, or
29011 modify breakpoints, may work or not work, depending on the target. Note
29012 that even commands that operate on global state, such as @code{print},
29013 @code{set}, and breakpoint commands, still access the target in the
29014 context of a specific thread, so frontend should try to find a
29015 stopped thread and perform the operation on that thread (using the
29016 @samp{--thread} option).
29017
29018 Which commands will work in the context of a running thread is
29019 highly target dependent. However, the two commands
29020 @code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
29021 to find the state of a thread, will always work.
29022
29023 @node Thread groups
29024 @subsection Thread groups
29025 @value{GDBN} may be used to debug several processes at the same time.
29026 On some platforms, @value{GDBN} may support debugging of several
29027 hardware systems, each one having several cores with several different
29028 processes running on each core. This section describes the MI
29029 mechanism to support such debugging scenarios.
29030
29031 The key observation is that regardless of the structure of the
29032 target, MI can have a global list of threads, because most commands that
29033 accept the @samp{--thread} option do not need to know what process that
29034 thread belongs to. Therefore, it is not necessary to introduce
29035 neither additional @samp{--process} option, nor an notion of the
29036 current process in the MI interface. The only strictly new feature
29037 that is required is the ability to find how the threads are grouped
29038 into processes.
29039
29040 To allow the user to discover such grouping, and to support arbitrary
29041 hierarchy of machines/cores/processes, MI introduces the concept of a
29042 @dfn{thread group}. Thread group is a collection of threads and other
29043 thread groups. A thread group always has a string identifier, a type,
29044 and may have additional attributes specific to the type. A new
29045 command, @code{-list-thread-groups}, returns the list of top-level
29046 thread groups, which correspond to processes that @value{GDBN} is
29047 debugging at the moment. By passing an identifier of a thread group
29048 to the @code{-list-thread-groups} command, it is possible to obtain
29049 the members of specific thread group.
29050
29051 To allow the user to easily discover processes, and other objects, he
29052 wishes to debug, a concept of @dfn{available thread group} is
29053 introduced. Available thread group is an thread group that
29054 @value{GDBN} is not debugging, but that can be attached to, using the
29055 @code{-target-attach} command. The list of available top-level thread
29056 groups can be obtained using @samp{-list-thread-groups --available}.
29057 In general, the content of a thread group may be only retrieved only
29058 after attaching to that thread group.
29059
29060 Thread groups are related to inferiors (@pxref{Inferiors Connections and
29061 Programs}). Each inferior corresponds to a thread group of a special
29062 type @samp{process}, and some additional operations are permitted on
29063 such thread groups.
29064
29065 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29066 @node GDB/MI Command Syntax
29067 @section @sc{gdb/mi} Command Syntax
29068
29069 @menu
29070 * GDB/MI Input Syntax::
29071 * GDB/MI Output Syntax::
29072 @end menu
29073
29074 @node GDB/MI Input Syntax
29075 @subsection @sc{gdb/mi} Input Syntax
29076
29077 @cindex input syntax for @sc{gdb/mi}
29078 @cindex @sc{gdb/mi}, input syntax
29079 @table @code
29080 @item @var{command} @expansion{}
29081 @code{@var{cli-command} | @var{mi-command}}
29082
29083 @item @var{cli-command} @expansion{}
29084 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
29085 @var{cli-command} is any existing @value{GDBN} CLI command.
29086
29087 @item @var{mi-command} @expansion{}
29088 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
29089 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
29090
29091 @item @var{token} @expansion{}
29092 "any sequence of digits"
29093
29094 @item @var{option} @expansion{}
29095 @code{"-" @var{parameter} [ " " @var{parameter} ]}
29096
29097 @item @var{parameter} @expansion{}
29098 @code{@var{non-blank-sequence} | @var{c-string}}
29099
29100 @item @var{operation} @expansion{}
29101 @emph{any of the operations described in this chapter}
29102
29103 @item @var{non-blank-sequence} @expansion{}
29104 @emph{anything, provided it doesn't contain special characters such as
29105 "-", @var{nl}, """ and of course " "}
29106
29107 @item @var{c-string} @expansion{}
29108 @code{""" @var{seven-bit-iso-c-string-content} """}
29109
29110 @item @var{nl} @expansion{}
29111 @code{CR | CR-LF}
29112 @end table
29113
29114 @noindent
29115 Notes:
29116
29117 @itemize @bullet
29118 @item
29119 The CLI commands are still handled by the @sc{mi} interpreter; their
29120 output is described below.
29121
29122 @item
29123 The @code{@var{token}}, when present, is passed back when the command
29124 finishes.
29125
29126 @item
29127 Some @sc{mi} commands accept optional arguments as part of the parameter
29128 list. Each option is identified by a leading @samp{-} (dash) and may be
29129 followed by an optional argument parameter. Options occur first in the
29130 parameter list and can be delimited from normal parameters using
29131 @samp{--} (this is useful when some parameters begin with a dash).
29132 @end itemize
29133
29134 Pragmatics:
29135
29136 @itemize @bullet
29137 @item
29138 We want easy access to the existing CLI syntax (for debugging).
29139
29140 @item
29141 We want it to be easy to spot a @sc{mi} operation.
29142 @end itemize
29143
29144 @node GDB/MI Output Syntax
29145 @subsection @sc{gdb/mi} Output Syntax
29146
29147 @cindex output syntax of @sc{gdb/mi}
29148 @cindex @sc{gdb/mi}, output syntax
29149 The output from @sc{gdb/mi} consists of zero or more out-of-band records
29150 followed, optionally, by a single result record. This result record
29151 is for the most recent command. The sequence of output records is
29152 terminated by @samp{(gdb)}.
29153
29154 If an input command was prefixed with a @code{@var{token}} then the
29155 corresponding output for that command will also be prefixed by that same
29156 @var{token}.
29157
29158 @table @code
29159 @item @var{output} @expansion{}
29160 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
29161
29162 @item @var{result-record} @expansion{}
29163 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
29164
29165 @item @var{out-of-band-record} @expansion{}
29166 @code{@var{async-record} | @var{stream-record}}
29167
29168 @item @var{async-record} @expansion{}
29169 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
29170
29171 @item @var{exec-async-output} @expansion{}
29172 @code{[ @var{token} ] "*" @var{async-output nl}}
29173
29174 @item @var{status-async-output} @expansion{}
29175 @code{[ @var{token} ] "+" @var{async-output nl}}
29176
29177 @item @var{notify-async-output} @expansion{}
29178 @code{[ @var{token} ] "=" @var{async-output nl}}
29179
29180 @item @var{async-output} @expansion{}
29181 @code{@var{async-class} ( "," @var{result} )*}
29182
29183 @item @var{result-class} @expansion{}
29184 @code{"done" | "running" | "connected" | "error" | "exit"}
29185
29186 @item @var{async-class} @expansion{}
29187 @code{"stopped" | @var{others}} (where @var{others} will be added
29188 depending on the needs---this is still in development).
29189
29190 @item @var{result} @expansion{}
29191 @code{ @var{variable} "=" @var{value}}
29192
29193 @item @var{variable} @expansion{}
29194 @code{ @var{string} }
29195
29196 @item @var{value} @expansion{}
29197 @code{ @var{const} | @var{tuple} | @var{list} }
29198
29199 @item @var{const} @expansion{}
29200 @code{@var{c-string}}
29201
29202 @item @var{tuple} @expansion{}
29203 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
29204
29205 @item @var{list} @expansion{}
29206 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
29207 @var{result} ( "," @var{result} )* "]" }
29208
29209 @item @var{stream-record} @expansion{}
29210 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
29211
29212 @item @var{console-stream-output} @expansion{}
29213 @code{"~" @var{c-string nl}}
29214
29215 @item @var{target-stream-output} @expansion{}
29216 @code{"@@" @var{c-string nl}}
29217
29218 @item @var{log-stream-output} @expansion{}
29219 @code{"&" @var{c-string nl}}
29220
29221 @item @var{nl} @expansion{}
29222 @code{CR | CR-LF}
29223
29224 @item @var{token} @expansion{}
29225 @emph{any sequence of digits}.
29226 @end table
29227
29228 @noindent
29229 Notes:
29230
29231 @itemize @bullet
29232 @item
29233 All output sequences end in a single line containing a period.
29234
29235 @item
29236 The @code{@var{token}} is from the corresponding request. Note that
29237 for all async output, while the token is allowed by the grammar and
29238 may be output by future versions of @value{GDBN} for select async
29239 output messages, it is generally omitted. Frontends should treat
29240 all async output as reporting general changes in the state of the
29241 target and there should be no need to associate async output to any
29242 prior command.
29243
29244 @item
29245 @cindex status output in @sc{gdb/mi}
29246 @var{status-async-output} contains on-going status information about the
29247 progress of a slow operation. It can be discarded. All status output is
29248 prefixed by @samp{+}.
29249
29250 @item
29251 @cindex async output in @sc{gdb/mi}
29252 @var{exec-async-output} contains asynchronous state change on the target
29253 (stopped, started, disappeared). All async output is prefixed by
29254 @samp{*}.
29255
29256 @item
29257 @cindex notify output in @sc{gdb/mi}
29258 @var{notify-async-output} contains supplementary information that the
29259 client should handle (e.g., a new breakpoint information). All notify
29260 output is prefixed by @samp{=}.
29261
29262 @item
29263 @cindex console output in @sc{gdb/mi}
29264 @var{console-stream-output} is output that should be displayed as is in the
29265 console. It is the textual response to a CLI command. All the console
29266 output is prefixed by @samp{~}.
29267
29268 @item
29269 @cindex target output in @sc{gdb/mi}
29270 @var{target-stream-output} is the output produced by the target program.
29271 All the target output is prefixed by @samp{@@}.
29272
29273 @item
29274 @cindex log output in @sc{gdb/mi}
29275 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
29276 instance messages that should be displayed as part of an error log. All
29277 the log output is prefixed by @samp{&}.
29278
29279 @item
29280 @cindex list output in @sc{gdb/mi}
29281 New @sc{gdb/mi} commands should only output @var{lists} containing
29282 @var{values}.
29283
29284
29285 @end itemize
29286
29287 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
29288 details about the various output records.
29289
29290 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29291 @node GDB/MI Compatibility with CLI
29292 @section @sc{gdb/mi} Compatibility with CLI
29293
29294 @cindex compatibility, @sc{gdb/mi} and CLI
29295 @cindex @sc{gdb/mi}, compatibility with CLI
29296
29297 For the developers convenience CLI commands can be entered directly,
29298 but there may be some unexpected behaviour. For example, commands
29299 that query the user will behave as if the user replied yes, breakpoint
29300 command lists are not executed and some CLI commands, such as
29301 @code{if}, @code{when} and @code{define}, prompt for further input with
29302 @samp{>}, which is not valid MI output.
29303
29304 This feature may be removed at some stage in the future and it is
29305 recommended that front ends use the @code{-interpreter-exec} command
29306 (@pxref{-interpreter-exec}).
29307
29308 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29309 @node GDB/MI Development and Front Ends
29310 @section @sc{gdb/mi} Development and Front Ends
29311 @cindex @sc{gdb/mi} development
29312
29313 The application which takes the MI output and presents the state of the
29314 program being debugged to the user is called a @dfn{front end}.
29315
29316 Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
29317 to the MI interface may break existing usage. This section describes how the
29318 protocol changes and how to request previous version of the protocol when it
29319 does.
29320
29321 Some changes in MI need not break a carefully designed front end, and
29322 for these the MI version will remain unchanged. The following is a
29323 list of changes that may occur within one level, so front ends should
29324 parse MI output in a way that can handle them:
29325
29326 @itemize @bullet
29327 @item
29328 New MI commands may be added.
29329
29330 @item
29331 New fields may be added to the output of any MI command.
29332
29333 @item
29334 The range of values for fields with specified values, e.g.,
29335 @code{in_scope} (@pxref{-var-update}) may be extended.
29336
29337 @c The format of field's content e.g type prefix, may change so parse it
29338 @c at your own risk. Yes, in general?
29339
29340 @c The order of fields may change? Shouldn't really matter but it might
29341 @c resolve inconsistencies.
29342 @end itemize
29343
29344 If the changes are likely to break front ends, the MI version level
29345 will be increased by one. The new versions of the MI protocol are not compatible
29346 with the old versions. Old versions of MI remain available, allowing front ends
29347 to keep using them until they are modified to use the latest MI version.
29348
29349 Since @code{--interpreter=mi} always points to the latest MI version, it is
29350 recommended that front ends request a specific version of MI when launching
29351 @value{GDBN} (e.g. @code{--interpreter=mi2}) to make sure they get an
29352 interpreter with the MI version they expect.
29353
29354 The following table gives a summary of the released versions of the MI
29355 interface: the version number, the version of GDB in which it first appeared
29356 and the breaking changes compared to the previous version.
29357
29358 @multitable @columnfractions .05 .05 .9
29359 @headitem MI version @tab GDB version @tab Breaking changes
29360
29361 @item
29362 @center 1
29363 @tab
29364 @center 5.1
29365 @tab
29366 None
29367
29368 @item
29369 @center 2
29370 @tab
29371 @center 6.0
29372 @tab
29373
29374 @itemize
29375 @item
29376 The @code{-environment-pwd}, @code{-environment-directory} and
29377 @code{-environment-path} commands now returns values using the MI output
29378 syntax, rather than CLI output syntax.
29379
29380 @item
29381 @code{-var-list-children}'s @code{children} result field is now a list, rather
29382 than a tuple.
29383
29384 @item
29385 @code{-var-update}'s @code{changelist} result field is now a list, rather than
29386 a tuple.
29387 @end itemize
29388
29389 @item
29390 @center 3
29391 @tab
29392 @center 9.1
29393 @tab
29394
29395 @itemize
29396 @item
29397 The output of information about multi-location breakpoints has changed in the
29398 responses to the @code{-break-insert} and @code{-break-info} commands, as well
29399 as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
29400 The multiple locations are now placed in a @code{locations} field, whose value
29401 is a list.
29402 @end itemize
29403
29404 @end multitable
29405
29406 If your front end cannot yet migrate to a more recent version of the
29407 MI protocol, you can nevertheless selectively enable specific features
29408 available in those recent MI versions, using the following commands:
29409
29410 @table @code
29411
29412 @item -fix-multi-location-breakpoint-output
29413 Use the output for multi-location breakpoints which was introduced by
29414 MI 3, even when using MI versions 2 or 1. This command has no
29415 effect when using MI version 3 or later.
29416
29417 @end table
29418
29419 The best way to avoid unexpected changes in MI that might break your front
29420 end is to make your project known to @value{GDBN} developers and
29421 follow development on @email{gdb@@sourceware.org} and
29422 @email{gdb-patches@@sourceware.org}.
29423 @cindex mailing lists
29424
29425 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29426 @node GDB/MI Output Records
29427 @section @sc{gdb/mi} Output Records
29428
29429 @menu
29430 * GDB/MI Result Records::
29431 * GDB/MI Stream Records::
29432 * GDB/MI Async Records::
29433 * GDB/MI Breakpoint Information::
29434 * GDB/MI Frame Information::
29435 * GDB/MI Thread Information::
29436 * GDB/MI Ada Exception Information::
29437 @end menu
29438
29439 @node GDB/MI Result Records
29440 @subsection @sc{gdb/mi} Result Records
29441
29442 @cindex result records in @sc{gdb/mi}
29443 @cindex @sc{gdb/mi}, result records
29444 In addition to a number of out-of-band notifications, the response to a
29445 @sc{gdb/mi} command includes one of the following result indications:
29446
29447 @table @code
29448 @findex ^done
29449 @item "^done" [ "," @var{results} ]
29450 The synchronous operation was successful, @code{@var{results}} are the return
29451 values.
29452
29453 @item "^running"
29454 @findex ^running
29455 This result record is equivalent to @samp{^done}. Historically, it
29456 was output instead of @samp{^done} if the command has resumed the
29457 target. This behaviour is maintained for backward compatibility, but
29458 all frontends should treat @samp{^done} and @samp{^running}
29459 identically and rely on the @samp{*running} output record to determine
29460 which threads are resumed.
29461
29462 @item "^connected"
29463 @findex ^connected
29464 @value{GDBN} has connected to a remote target.
29465
29466 @item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
29467 @findex ^error
29468 The operation failed. The @code{msg=@var{c-string}} variable contains
29469 the corresponding error message.
29470
29471 If present, the @code{code=@var{c-string}} variable provides an error
29472 code on which consumers can rely on to detect the corresponding
29473 error condition. At present, only one error code is defined:
29474
29475 @table @samp
29476 @item "undefined-command"
29477 Indicates that the command causing the error does not exist.
29478 @end table
29479
29480 @item "^exit"
29481 @findex ^exit
29482 @value{GDBN} has terminated.
29483
29484 @end table
29485
29486 @node GDB/MI Stream Records
29487 @subsection @sc{gdb/mi} Stream Records
29488
29489 @cindex @sc{gdb/mi}, stream records
29490 @cindex stream records in @sc{gdb/mi}
29491 @value{GDBN} internally maintains a number of output streams: the console, the
29492 target, and the log. The output intended for each of these streams is
29493 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
29494
29495 Each stream record begins with a unique @dfn{prefix character} which
29496 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
29497 Syntax}). In addition to the prefix, each stream record contains a
29498 @code{@var{string-output}}. This is either raw text (with an implicit new
29499 line) or a quoted C string (which does not contain an implicit newline).
29500
29501 @table @code
29502 @item "~" @var{string-output}
29503 The console output stream contains text that should be displayed in the
29504 CLI console window. It contains the textual responses to CLI commands.
29505
29506 @item "@@" @var{string-output}
29507 The target output stream contains any textual output from the running
29508 target. This is only present when GDB's event loop is truly
29509 asynchronous, which is currently only the case for remote targets.
29510
29511 @item "&" @var{string-output}
29512 The log stream contains debugging messages being produced by @value{GDBN}'s
29513 internals.
29514 @end table
29515
29516 @node GDB/MI Async Records
29517 @subsection @sc{gdb/mi} Async Records
29518
29519 @cindex async records in @sc{gdb/mi}
29520 @cindex @sc{gdb/mi}, async records
29521 @dfn{Async} records are used to notify the @sc{gdb/mi} client of
29522 additional changes that have occurred. Those changes can either be a
29523 consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
29524 target activity (e.g., target stopped).
29525
29526 The following is the list of possible async records:
29527
29528 @table @code
29529
29530 @item *running,thread-id="@var{thread}"
29531 The target is now running. The @var{thread} field can be the global
29532 thread ID of the thread that is now running, and it can be
29533 @samp{all} if all threads are running. The frontend should assume
29534 that no interaction with a running thread is possible after this
29535 notification is produced. The frontend should not assume that this
29536 notification is output only once for any command. @value{GDBN} may
29537 emit this notification several times, either for different threads,
29538 because it cannot resume all threads together, or even for a single
29539 thread, if the thread must be stepped though some code before letting
29540 it run freely.
29541
29542 @item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
29543 The target has stopped. The @var{reason} field can have one of the
29544 following values:
29545
29546 @table @code
29547 @item breakpoint-hit
29548 A breakpoint was reached.
29549 @item watchpoint-trigger
29550 A watchpoint was triggered.
29551 @item read-watchpoint-trigger
29552 A read watchpoint was triggered.
29553 @item access-watchpoint-trigger
29554 An access watchpoint was triggered.
29555 @item function-finished
29556 An -exec-finish or similar CLI command was accomplished.
29557 @item location-reached
29558 An -exec-until or similar CLI command was accomplished.
29559 @item watchpoint-scope
29560 A watchpoint has gone out of scope.
29561 @item end-stepping-range
29562 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
29563 similar CLI command was accomplished.
29564 @item exited-signalled
29565 The inferior exited because of a signal.
29566 @item exited
29567 The inferior exited.
29568 @item exited-normally
29569 The inferior exited normally.
29570 @item signal-received
29571 A signal was received by the inferior.
29572 @item solib-event
29573 The inferior has stopped due to a library being loaded or unloaded.
29574 This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
29575 set or when a @code{catch load} or @code{catch unload} catchpoint is
29576 in use (@pxref{Set Catchpoints}).
29577 @item fork
29578 The inferior has forked. This is reported when @code{catch fork}
29579 (@pxref{Set Catchpoints}) has been used.
29580 @item vfork
29581 The inferior has vforked. This is reported in when @code{catch vfork}
29582 (@pxref{Set Catchpoints}) has been used.
29583 @item syscall-entry
29584 The inferior entered a system call. This is reported when @code{catch
29585 syscall} (@pxref{Set Catchpoints}) has been used.
29586 @item syscall-return
29587 The inferior returned from a system call. This is reported when
29588 @code{catch syscall} (@pxref{Set Catchpoints}) has been used.
29589 @item exec
29590 The inferior called @code{exec}. This is reported when @code{catch exec}
29591 (@pxref{Set Catchpoints}) has been used.
29592 @end table
29593
29594 The @var{id} field identifies the global thread ID of the thread
29595 that directly caused the stop -- for example by hitting a breakpoint.
29596 Depending on whether all-stop
29597 mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
29598 stop all threads, or only the thread that directly triggered the stop.
29599 If all threads are stopped, the @var{stopped} field will have the
29600 value of @code{"all"}. Otherwise, the value of the @var{stopped}
29601 field will be a list of thread identifiers. Presently, this list will
29602 always include a single thread, but frontend should be prepared to see
29603 several threads in the list. The @var{core} field reports the
29604 processor core on which the stop event has happened. This field may be absent
29605 if such information is not available.
29606
29607 @item =thread-group-added,id="@var{id}"
29608 @itemx =thread-group-removed,id="@var{id}"
29609 A thread group was either added or removed. The @var{id} field
29610 contains the @value{GDBN} identifier of the thread group. When a thread
29611 group is added, it generally might not be associated with a running
29612 process. When a thread group is removed, its id becomes invalid and
29613 cannot be used in any way.
29614
29615 @item =thread-group-started,id="@var{id}",pid="@var{pid}"
29616 A thread group became associated with a running program,
29617 either because the program was just started or the thread group
29618 was attached to a program. The @var{id} field contains the
29619 @value{GDBN} identifier of the thread group. The @var{pid} field
29620 contains process identifier, specific to the operating system.
29621
29622 @item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
29623 A thread group is no longer associated with a running program,
29624 either because the program has exited, or because it was detached
29625 from. The @var{id} field contains the @value{GDBN} identifier of the
29626 thread group. The @var{code} field is the exit code of the inferior; it exists
29627 only when the inferior exited with some code.
29628
29629 @item =thread-created,id="@var{id}",group-id="@var{gid}"
29630 @itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
29631 A thread either was created, or has exited. The @var{id} field
29632 contains the global @value{GDBN} identifier of the thread. The @var{gid}
29633 field identifies the thread group this thread belongs to.
29634
29635 @item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
29636 Informs that the selected thread or frame were changed. This notification
29637 is not emitted as result of the @code{-thread-select} or
29638 @code{-stack-select-frame} commands, but is emitted whenever an MI command
29639 that is not documented to change the selected thread and frame actually
29640 changes them. In particular, invoking, directly or indirectly
29641 (via user-defined command), the CLI @code{thread} or @code{frame} commands,
29642 will generate this notification. Changing the thread or frame from another
29643 user interface (see @ref{Interpreters}) will also generate this notification.
29644
29645 The @var{frame} field is only present if the newly selected thread is
29646 stopped. See @ref{GDB/MI Frame Information} for the format of its value.
29647
29648 We suggest that in response to this notification, front ends
29649 highlight the selected thread and cause subsequent commands to apply to
29650 that thread.
29651
29652 @item =library-loaded,...
29653 Reports that a new library file was loaded by the program. This
29654 notification has 5 fields---@var{id}, @var{target-name},
29655 @var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
29656 opaque identifier of the library. For remote debugging case,
29657 @var{target-name} and @var{host-name} fields give the name of the
29658 library file on the target, and on the host respectively. For native
29659 debugging, both those fields have the same value. The
29660 @var{symbols-loaded} field is emitted only for backward compatibility
29661 and should not be relied on to convey any useful information. The
29662 @var{thread-group} field, if present, specifies the id of the thread
29663 group in whose context the library was loaded. If the field is
29664 absent, it means the library was loaded in the context of all present
29665 thread groups. The @var{ranges} field specifies the ranges of addresses belonging
29666 to this library.
29667
29668 @item =library-unloaded,...
29669 Reports that a library was unloaded by the program. This notification
29670 has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
29671 the same meaning as for the @code{=library-loaded} notification.
29672 The @var{thread-group} field, if present, specifies the id of the
29673 thread group in whose context the library was unloaded. If the field is
29674 absent, it means the library was unloaded in the context of all present
29675 thread groups.
29676
29677 @item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
29678 @itemx =traceframe-changed,end
29679 Reports that the trace frame was changed and its new number is
29680 @var{tfnum}. The number of the tracepoint associated with this trace
29681 frame is @var{tpnum}.
29682
29683 @item =tsv-created,name=@var{name},initial=@var{initial}
29684 Reports that the new trace state variable @var{name} is created with
29685 initial value @var{initial}.
29686
29687 @item =tsv-deleted,name=@var{name}
29688 @itemx =tsv-deleted
29689 Reports that the trace state variable @var{name} is deleted or all
29690 trace state variables are deleted.
29691
29692 @item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
29693 Reports that the trace state variable @var{name} is modified with
29694 the initial value @var{initial}. The current value @var{current} of
29695 trace state variable is optional and is reported if the current
29696 value of trace state variable is known.
29697
29698 @item =breakpoint-created,bkpt=@{...@}
29699 @itemx =breakpoint-modified,bkpt=@{...@}
29700 @itemx =breakpoint-deleted,id=@var{number}
29701 Reports that a breakpoint was created, modified, or deleted,
29702 respectively. Only user-visible breakpoints are reported to the MI
29703 user.
29704
29705 The @var{bkpt} argument is of the same form as returned by the various
29706 breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
29707 @var{number} is the ordinal number of the breakpoint.
29708
29709 Note that if a breakpoint is emitted in the result record of a
29710 command, then it will not also be emitted in an async record.
29711
29712 @item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
29713 @itemx =record-stopped,thread-group="@var{id}"
29714 Execution log recording was either started or stopped on an
29715 inferior. The @var{id} is the @value{GDBN} identifier of the thread
29716 group corresponding to the affected inferior.
29717
29718 The @var{method} field indicates the method used to record execution. If the
29719 method in use supports multiple recording formats, @var{format} will be present
29720 and contain the currently used format. @xref{Process Record and Replay},
29721 for existing method and format values.
29722
29723 @item =cmd-param-changed,param=@var{param},value=@var{value}
29724 Reports that a parameter of the command @code{set @var{param}} is
29725 changed to @var{value}. In the multi-word @code{set} command,
29726 the @var{param} is the whole parameter list to @code{set} command.
29727 For example, In command @code{set check type on}, @var{param}
29728 is @code{check type} and @var{value} is @code{on}.
29729
29730 @item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
29731 Reports that bytes from @var{addr} to @var{data} + @var{len} were
29732 written in an inferior. The @var{id} is the identifier of the
29733 thread group corresponding to the affected inferior. The optional
29734 @code{type="code"} part is reported if the memory written to holds
29735 executable code.
29736 @end table
29737
29738 @node GDB/MI Breakpoint Information
29739 @subsection @sc{gdb/mi} Breakpoint Information
29740
29741 When @value{GDBN} reports information about a breakpoint, a
29742 tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
29743 following fields:
29744
29745 @table @code
29746 @item number
29747 The breakpoint number.
29748
29749 @item type
29750 The type of the breakpoint. For ordinary breakpoints this will be
29751 @samp{breakpoint}, but many values are possible.
29752
29753 @item catch-type
29754 If the type of the breakpoint is @samp{catchpoint}, then this
29755 indicates the exact type of catchpoint.
29756
29757 @item disp
29758 This is the breakpoint disposition---either @samp{del}, meaning that
29759 the breakpoint will be deleted at the next stop, or @samp{keep},
29760 meaning that the breakpoint will not be deleted.
29761
29762 @item enabled
29763 This indicates whether the breakpoint is enabled, in which case the
29764 value is @samp{y}, or disabled, in which case the value is @samp{n}.
29765 Note that this is not the same as the field @code{enable}.
29766
29767 @item addr
29768 The address of the breakpoint. This may be a hexidecimal number,
29769 giving the address; or the string @samp{<PENDING>}, for a pending
29770 breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
29771 multiple locations. This field will not be present if no address can
29772 be determined. For example, a watchpoint does not have an address.
29773
29774 @item addr_flags
29775 Optional field containing any flags related to the address. These flags are
29776 architecture-dependent; see @ref{Architectures} for their meaning for a
29777 particular CPU.
29778
29779 @item func
29780 If known, the function in which the breakpoint appears.
29781 If not known, this field is not present.
29782
29783 @item filename
29784 The name of the source file which contains this function, if known.
29785 If not known, this field is not present.
29786
29787 @item fullname
29788 The full file name of the source file which contains this function, if
29789 known. If not known, this field is not present.
29790
29791 @item line
29792 The line number at which this breakpoint appears, if known.
29793 If not known, this field is not present.
29794
29795 @item at
29796 If the source file is not known, this field may be provided. If
29797 provided, this holds the address of the breakpoint, possibly followed
29798 by a symbol name.
29799
29800 @item pending
29801 If this breakpoint is pending, this field is present and holds the
29802 text used to set the breakpoint, as entered by the user.
29803
29804 @item evaluated-by
29805 Where this breakpoint's condition is evaluated, either @samp{host} or
29806 @samp{target}.
29807
29808 @item thread
29809 If this is a thread-specific breakpoint, then this identifies the
29810 thread in which the breakpoint can trigger.
29811
29812 @item task
29813 If this breakpoint is restricted to a particular Ada task, then this
29814 field will hold the task identifier.
29815
29816 @item cond
29817 If the breakpoint is conditional, this is the condition expression.
29818
29819 @item ignore
29820 The ignore count of the breakpoint.
29821
29822 @item enable
29823 The enable count of the breakpoint.
29824
29825 @item traceframe-usage
29826 FIXME.
29827
29828 @item static-tracepoint-marker-string-id
29829 For a static tracepoint, the name of the static tracepoint marker.
29830
29831 @item mask
29832 For a masked watchpoint, this is the mask.
29833
29834 @item pass
29835 A tracepoint's pass count.
29836
29837 @item original-location
29838 The location of the breakpoint as originally specified by the user.
29839 This field is optional.
29840
29841 @item times
29842 The number of times the breakpoint has been hit.
29843
29844 @item installed
29845 This field is only given for tracepoints. This is either @samp{y},
29846 meaning that the tracepoint is installed, or @samp{n}, meaning that it
29847 is not.
29848
29849 @item what
29850 Some extra data, the exact contents of which are type-dependent.
29851
29852 @item locations
29853 This field is present if the breakpoint has multiple locations. It is also
29854 exceptionally present if the breakpoint is enabled and has a single, disabled
29855 location.
29856
29857 The value is a list of locations. The format of a location is described below.
29858
29859 @end table
29860
29861 A location in a multi-location breakpoint is represented as a tuple with the
29862 following fields:
29863
29864 @table @code
29865
29866 @item number
29867 The location number as a dotted pair, like @samp{1.2}. The first digit is the
29868 number of the parent breakpoint. The second digit is the number of the
29869 location within that breakpoint.
29870
29871 @item enabled
29872 This indicates whether the location is enabled, in which case the
29873 value is @samp{y}, or disabled, in which case the value is @samp{n}.
29874 Note that this is not the same as the field @code{enable}.
29875
29876 @item addr
29877 The address of this location as an hexidecimal number.
29878
29879 @item addr_flags
29880 Optional field containing any flags related to the address. These flags are
29881 architecture-dependent; see @ref{Architectures} for their meaning for a
29882 particular CPU.
29883
29884 @item func
29885 If known, the function in which the location appears.
29886 If not known, this field is not present.
29887
29888 @item file
29889 The name of the source file which contains this location, if known.
29890 If not known, this field is not present.
29891
29892 @item fullname
29893 The full file name of the source file which contains this location, if
29894 known. If not known, this field is not present.
29895
29896 @item line
29897 The line number at which this location appears, if known.
29898 If not known, this field is not present.
29899
29900 @item thread-groups
29901 The thread groups this location is in.
29902
29903 @end table
29904
29905 For example, here is what the output of @code{-break-insert}
29906 (@pxref{GDB/MI Breakpoint Commands}) might be:
29907
29908 @smallexample
29909 -> -break-insert main
29910 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29911 enabled="y",addr="0x08048564",func="main",file="myprog.c",
29912 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29913 times="0"@}
29914 <- (gdb)
29915 @end smallexample
29916
29917 @node GDB/MI Frame Information
29918 @subsection @sc{gdb/mi} Frame Information
29919
29920 Response from many MI commands includes an information about stack
29921 frame. This information is a tuple that may have the following
29922 fields:
29923
29924 @table @code
29925 @item level
29926 The level of the stack frame. The innermost frame has the level of
29927 zero. This field is always present.
29928
29929 @item func
29930 The name of the function corresponding to the frame. This field may
29931 be absent if @value{GDBN} is unable to determine the function name.
29932
29933 @item addr
29934 The code address for the frame. This field is always present.
29935
29936 @item addr_flags
29937 Optional field containing any flags related to the address. These flags are
29938 architecture-dependent; see @ref{Architectures} for their meaning for a
29939 particular CPU.
29940
29941 @item file
29942 The name of the source files that correspond to the frame's code
29943 address. This field may be absent.
29944
29945 @item line
29946 The source line corresponding to the frames' code address. This field
29947 may be absent.
29948
29949 @item from
29950 The name of the binary file (either executable or shared library) the
29951 corresponds to the frame's code address. This field may be absent.
29952
29953 @end table
29954
29955 @node GDB/MI Thread Information
29956 @subsection @sc{gdb/mi} Thread Information
29957
29958 Whenever @value{GDBN} has to report an information about a thread, it
29959 uses a tuple with the following fields. The fields are always present unless
29960 stated otherwise.
29961
29962 @table @code
29963 @item id
29964 The global numeric id assigned to the thread by @value{GDBN}.
29965
29966 @item target-id
29967 The target-specific string identifying the thread.
29968
29969 @item details
29970 Additional information about the thread provided by the target.
29971 It is supposed to be human-readable and not interpreted by the
29972 frontend. This field is optional.
29973
29974 @item name
29975 The name of the thread. If the user specified a name using the
29976 @code{thread name} command, then this name is given. Otherwise, if
29977 @value{GDBN} can extract the thread name from the target, then that
29978 name is given. If @value{GDBN} cannot find the thread name, then this
29979 field is omitted.
29980
29981 @item state
29982 The execution state of the thread, either @samp{stopped} or @samp{running},
29983 depending on whether the thread is presently running.
29984
29985 @item frame
29986 The stack frame currently executing in the thread. This field is only present
29987 if the thread is stopped. Its format is documented in
29988 @ref{GDB/MI Frame Information}.
29989
29990 @item core
29991 The value of this field is an integer number of the processor core the
29992 thread was last seen on. This field is optional.
29993 @end table
29994
29995 @node GDB/MI Ada Exception Information
29996 @subsection @sc{gdb/mi} Ada Exception Information
29997
29998 Whenever a @code{*stopped} record is emitted because the program
29999 stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
30000 @value{GDBN} provides the name of the exception that was raised via
30001 the @code{exception-name} field. Also, for exceptions that were raised
30002 with an exception message, @value{GDBN} provides that message via
30003 the @code{exception-message} field.
30004
30005 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30006 @node GDB/MI Simple Examples
30007 @section Simple Examples of @sc{gdb/mi} Interaction
30008 @cindex @sc{gdb/mi}, simple examples
30009
30010 This subsection presents several simple examples of interaction using
30011 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
30012 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
30013 the output received from @sc{gdb/mi}.
30014
30015 Note the line breaks shown in the examples are here only for
30016 readability, they don't appear in the real output.
30017
30018 @subheading Setting a Breakpoint
30019
30020 Setting a breakpoint generates synchronous output which contains detailed
30021 information of the breakpoint.
30022
30023 @smallexample
30024 -> -break-insert main
30025 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30026 enabled="y",addr="0x08048564",func="main",file="myprog.c",
30027 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
30028 times="0"@}
30029 <- (gdb)
30030 @end smallexample
30031
30032 @subheading Program Execution
30033
30034 Program execution generates asynchronous records and MI gives the
30035 reason that execution stopped.
30036
30037 @smallexample
30038 -> -exec-run
30039 <- ^running
30040 <- (gdb)
30041 <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
30042 frame=@{addr="0x08048564",func="main",
30043 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
30044 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
30045 arch="i386:x86_64"@}
30046 <- (gdb)
30047 -> -exec-continue
30048 <- ^running
30049 <- (gdb)
30050 <- *stopped,reason="exited-normally"
30051 <- (gdb)
30052 @end smallexample
30053
30054 @subheading Quitting @value{GDBN}
30055
30056 Quitting @value{GDBN} just prints the result class @samp{^exit}.
30057
30058 @smallexample
30059 -> (gdb)
30060 <- -gdb-exit
30061 <- ^exit
30062 @end smallexample
30063
30064 Please note that @samp{^exit} is printed immediately, but it might
30065 take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
30066 performs necessary cleanups, including killing programs being debugged
30067 or disconnecting from debug hardware, so the frontend should wait till
30068 @value{GDBN} exits and should only forcibly kill @value{GDBN} if it
30069 fails to exit in reasonable time.
30070
30071 @subheading A Bad Command
30072
30073 Here's what happens if you pass a non-existent command:
30074
30075 @smallexample
30076 -> -rubbish
30077 <- ^error,msg="Undefined MI command: rubbish"
30078 <- (gdb)
30079 @end smallexample
30080
30081
30082 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30083 @node GDB/MI Command Description Format
30084 @section @sc{gdb/mi} Command Description Format
30085
30086 The remaining sections describe blocks of commands. Each block of
30087 commands is laid out in a fashion similar to this section.
30088
30089 @subheading Motivation
30090
30091 The motivation for this collection of commands.
30092
30093 @subheading Introduction
30094
30095 A brief introduction to this collection of commands as a whole.
30096
30097 @subheading Commands
30098
30099 For each command in the block, the following is described:
30100
30101 @subsubheading Synopsis
30102
30103 @smallexample
30104 -command @var{args}@dots{}
30105 @end smallexample
30106
30107 @subsubheading Result
30108
30109 @subsubheading @value{GDBN} Command
30110
30111 The corresponding @value{GDBN} CLI command(s), if any.
30112
30113 @subsubheading Example
30114
30115 Example(s) formatted for readability. Some of the described commands have
30116 not been implemented yet and these are labeled N.A.@: (not available).
30117
30118
30119 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30120 @node GDB/MI Breakpoint Commands
30121 @section @sc{gdb/mi} Breakpoint Commands
30122
30123 @cindex breakpoint commands for @sc{gdb/mi}
30124 @cindex @sc{gdb/mi}, breakpoint commands
30125 This section documents @sc{gdb/mi} commands for manipulating
30126 breakpoints.
30127
30128 @subheading The @code{-break-after} Command
30129 @findex -break-after
30130
30131 @subsubheading Synopsis
30132
30133 @smallexample
30134 -break-after @var{number} @var{count}
30135 @end smallexample
30136
30137 The breakpoint number @var{number} is not in effect until it has been
30138 hit @var{count} times. To see how this is reflected in the output of
30139 the @samp{-break-list} command, see the description of the
30140 @samp{-break-list} command below.
30141
30142 @subsubheading @value{GDBN} Command
30143
30144 The corresponding @value{GDBN} command is @samp{ignore}.
30145
30146 @subsubheading Example
30147
30148 @smallexample
30149 (gdb)
30150 -break-insert main
30151 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30152 enabled="y",addr="0x000100d0",func="main",file="hello.c",
30153 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
30154 times="0"@}
30155 (gdb)
30156 -break-after 1 3
30157 ~
30158 ^done
30159 (gdb)
30160 -break-list
30161 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30162 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30163 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30164 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30165 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30166 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30167 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30168 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30169 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30170 line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
30171 (gdb)
30172 @end smallexample
30173
30174 @ignore
30175 @subheading The @code{-break-catch} Command
30176 @findex -break-catch
30177 @end ignore
30178
30179 @subheading The @code{-break-commands} Command
30180 @findex -break-commands
30181
30182 @subsubheading Synopsis
30183
30184 @smallexample
30185 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
30186 @end smallexample
30187
30188 Specifies the CLI commands that should be executed when breakpoint
30189 @var{number} is hit. The parameters @var{command1} to @var{commandN}
30190 are the commands. If no command is specified, any previously-set
30191 commands are cleared. @xref{Break Commands}. Typical use of this
30192 functionality is tracing a program, that is, printing of values of
30193 some variables whenever breakpoint is hit and then continuing.
30194
30195 @subsubheading @value{GDBN} Command
30196
30197 The corresponding @value{GDBN} command is @samp{commands}.
30198
30199 @subsubheading Example
30200
30201 @smallexample
30202 (gdb)
30203 -break-insert main
30204 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30205 enabled="y",addr="0x000100d0",func="main",file="hello.c",
30206 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
30207 times="0"@}
30208 (gdb)
30209 -break-commands 1 "print v" "continue"
30210 ^done
30211 (gdb)
30212 @end smallexample
30213
30214 @subheading The @code{-break-condition} Command
30215 @findex -break-condition
30216
30217 @subsubheading Synopsis
30218
30219 @smallexample
30220 -break-condition @var{number} @var{expr}
30221 @end smallexample
30222
30223 Breakpoint @var{number} will stop the program only if the condition in
30224 @var{expr} is true. The condition becomes part of the
30225 @samp{-break-list} output (see the description of the @samp{-break-list}
30226 command below).
30227
30228 @subsubheading @value{GDBN} Command
30229
30230 The corresponding @value{GDBN} command is @samp{condition}.
30231
30232 @subsubheading Example
30233
30234 @smallexample
30235 (gdb)
30236 -break-condition 1 1
30237 ^done
30238 (gdb)
30239 -break-list
30240 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30241 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30242 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30243 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30244 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30245 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30246 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30247 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30248 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30249 line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
30250 (gdb)
30251 @end smallexample
30252
30253 @subheading The @code{-break-delete} Command
30254 @findex -break-delete
30255
30256 @subsubheading Synopsis
30257
30258 @smallexample
30259 -break-delete ( @var{breakpoint} )+
30260 @end smallexample
30261
30262 Delete the breakpoint(s) whose number(s) are specified in the argument
30263 list. This is obviously reflected in the breakpoint list.
30264
30265 @subsubheading @value{GDBN} Command
30266
30267 The corresponding @value{GDBN} command is @samp{delete}.
30268
30269 @subsubheading Example
30270
30271 @smallexample
30272 (gdb)
30273 -break-delete 1
30274 ^done
30275 (gdb)
30276 -break-list
30277 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30278 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30279 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30280 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30281 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30282 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30283 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30284 body=[]@}
30285 (gdb)
30286 @end smallexample
30287
30288 @subheading The @code{-break-disable} Command
30289 @findex -break-disable
30290
30291 @subsubheading Synopsis
30292
30293 @smallexample
30294 -break-disable ( @var{breakpoint} )+
30295 @end smallexample
30296
30297 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
30298 break list is now set to @samp{n} for the named @var{breakpoint}(s).
30299
30300 @subsubheading @value{GDBN} Command
30301
30302 The corresponding @value{GDBN} command is @samp{disable}.
30303
30304 @subsubheading Example
30305
30306 @smallexample
30307 (gdb)
30308 -break-disable 2
30309 ^done
30310 (gdb)
30311 -break-list
30312 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30313 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30314 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30315 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30316 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30317 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30318 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30319 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
30320 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30321 line="5",thread-groups=["i1"],times="0"@}]@}
30322 (gdb)
30323 @end smallexample
30324
30325 @subheading The @code{-break-enable} Command
30326 @findex -break-enable
30327
30328 @subsubheading Synopsis
30329
30330 @smallexample
30331 -break-enable ( @var{breakpoint} )+
30332 @end smallexample
30333
30334 Enable (previously disabled) @var{breakpoint}(s).
30335
30336 @subsubheading @value{GDBN} Command
30337
30338 The corresponding @value{GDBN} command is @samp{enable}.
30339
30340 @subsubheading Example
30341
30342 @smallexample
30343 (gdb)
30344 -break-enable 2
30345 ^done
30346 (gdb)
30347 -break-list
30348 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30349 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30350 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30351 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30352 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30353 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30354 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30355 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
30356 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30357 line="5",thread-groups=["i1"],times="0"@}]@}
30358 (gdb)
30359 @end smallexample
30360
30361 @subheading The @code{-break-info} Command
30362 @findex -break-info
30363
30364 @subsubheading Synopsis
30365
30366 @smallexample
30367 -break-info @var{breakpoint}
30368 @end smallexample
30369
30370 @c REDUNDANT???
30371 Get information about a single breakpoint.
30372
30373 The result is a table of breakpoints. @xref{GDB/MI Breakpoint
30374 Information}, for details on the format of each breakpoint in the
30375 table.
30376
30377 @subsubheading @value{GDBN} Command
30378
30379 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
30380
30381 @subsubheading Example
30382 N.A.
30383
30384 @subheading The @code{-break-insert} Command
30385 @findex -break-insert
30386 @anchor{-break-insert}
30387
30388 @subsubheading Synopsis
30389
30390 @smallexample
30391 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ] [ --qualified ]
30392 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30393 [ -p @var{thread-id} ] [ @var{location} ]
30394 @end smallexample
30395
30396 @noindent
30397 If specified, @var{location}, can be one of:
30398
30399 @table @var
30400 @item linespec location
30401 A linespec location. @xref{Linespec Locations}.
30402
30403 @item explicit location
30404 An explicit location. @sc{gdb/mi} explicit locations are
30405 analogous to the CLI's explicit locations using the option names
30406 listed below. @xref{Explicit Locations}.
30407
30408 @table @samp
30409 @item --source @var{filename}
30410 The source file name of the location. This option requires the use
30411 of either @samp{--function} or @samp{--line}.
30412
30413 @item --function @var{function}
30414 The name of a function or method.
30415
30416 @item --label @var{label}
30417 The name of a label.
30418
30419 @item --line @var{lineoffset}
30420 An absolute or relative line offset from the start of the location.
30421 @end table
30422
30423 @item address location
30424 An address location, *@var{address}. @xref{Address Locations}.
30425 @end table
30426
30427 @noindent
30428 The possible optional parameters of this command are:
30429
30430 @table @samp
30431 @item -t
30432 Insert a temporary breakpoint.
30433 @item -h
30434 Insert a hardware breakpoint.
30435 @item -f
30436 If @var{location} cannot be parsed (for example if it
30437 refers to unknown files or functions), create a pending
30438 breakpoint. Without this flag, @value{GDBN} will report
30439 an error, and won't create a breakpoint, if @var{location}
30440 cannot be parsed.
30441 @item -d
30442 Create a disabled breakpoint.
30443 @item -a
30444 Create a tracepoint. @xref{Tracepoints}. When this parameter
30445 is used together with @samp{-h}, a fast tracepoint is created.
30446 @item -c @var{condition}
30447 Make the breakpoint conditional on @var{condition}.
30448 @item -i @var{ignore-count}
30449 Initialize the @var{ignore-count}.
30450 @item -p @var{thread-id}
30451 Restrict the breakpoint to the thread with the specified global
30452 @var{thread-id}.
30453 @item --qualified
30454 This option makes @value{GDBN} interpret a function name specified as
30455 a complete fully-qualified name.
30456 @end table
30457
30458 @subsubheading Result
30459
30460 @xref{GDB/MI Breakpoint Information}, for details on the format of the
30461 resulting breakpoint.
30462
30463 Note: this format is open to change.
30464 @c An out-of-band breakpoint instead of part of the result?
30465
30466 @subsubheading @value{GDBN} Command
30467
30468 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
30469 @samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
30470
30471 @subsubheading Example
30472
30473 @smallexample
30474 (gdb)
30475 -break-insert main
30476 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
30477 fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
30478 times="0"@}
30479 (gdb)
30480 -break-insert -t foo
30481 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
30482 fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
30483 times="0"@}
30484 (gdb)
30485 -break-list
30486 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30487 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30488 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30489 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30490 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30491 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30492 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30493 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30494 addr="0x0001072c", func="main",file="recursive2.c",
30495 fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
30496 times="0"@},
30497 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
30498 addr="0x00010774",func="foo",file="recursive2.c",
30499 fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30500 times="0"@}]@}
30501 (gdb)
30502 @c -break-insert -r foo.*
30503 @c ~int foo(int, int);
30504 @c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
30505 @c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30506 @c times="0"@}
30507 @c (gdb)
30508 @end smallexample
30509
30510 @subheading The @code{-dprintf-insert} Command
30511 @findex -dprintf-insert
30512
30513 @subsubheading Synopsis
30514
30515 @smallexample
30516 -dprintf-insert [ -t ] [ -f ] [ -d ] [ --qualified ]
30517 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30518 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
30519 [ @var{argument} ]
30520 @end smallexample
30521
30522 @noindent
30523 If supplied, @var{location} and @code{--qualified} may be specified
30524 the same way as for the @code{-break-insert} command.
30525 @xref{-break-insert}.
30526
30527 The possible optional parameters of this command are:
30528
30529 @table @samp
30530 @item -t
30531 Insert a temporary breakpoint.
30532 @item -f
30533 If @var{location} cannot be parsed (for example, if it
30534 refers to unknown files or functions), create a pending
30535 breakpoint. Without this flag, @value{GDBN} will report
30536 an error, and won't create a breakpoint, if @var{location}
30537 cannot be parsed.
30538 @item -d
30539 Create a disabled breakpoint.
30540 @item -c @var{condition}
30541 Make the breakpoint conditional on @var{condition}.
30542 @item -i @var{ignore-count}
30543 Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
30544 to @var{ignore-count}.
30545 @item -p @var{thread-id}
30546 Restrict the breakpoint to the thread with the specified global
30547 @var{thread-id}.
30548 @end table
30549
30550 @subsubheading Result
30551
30552 @xref{GDB/MI Breakpoint Information}, for details on the format of the
30553 resulting breakpoint.
30554
30555 @c An out-of-band breakpoint instead of part of the result?
30556
30557 @subsubheading @value{GDBN} Command
30558
30559 The corresponding @value{GDBN} command is @samp{dprintf}.
30560
30561 @subsubheading Example
30562
30563 @smallexample
30564 (gdb)
30565 4-dprintf-insert foo "At foo entry\n"
30566 4^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
30567 addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
30568 fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
30569 times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
30570 original-location="foo"@}
30571 (gdb)
30572 5-dprintf-insert 26 "arg=%d, g=%d\n" arg g
30573 5^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
30574 addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
30575 fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
30576 times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
30577 original-location="mi-dprintf.c:26"@}
30578 (gdb)
30579 @end smallexample
30580
30581 @subheading The @code{-break-list} Command
30582 @findex -break-list
30583
30584 @subsubheading Synopsis
30585
30586 @smallexample
30587 -break-list
30588 @end smallexample
30589
30590 Displays the list of inserted breakpoints, showing the following fields:
30591
30592 @table @samp
30593 @item Number
30594 number of the breakpoint
30595 @item Type
30596 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
30597 @item Disposition
30598 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
30599 or @samp{nokeep}
30600 @item Enabled
30601 is the breakpoint enabled or no: @samp{y} or @samp{n}
30602 @item Address
30603 memory location at which the breakpoint is set
30604 @item What
30605 logical location of the breakpoint, expressed by function name, file
30606 name, line number
30607 @item Thread-groups
30608 list of thread groups to which this breakpoint applies
30609 @item Times
30610 number of times the breakpoint has been hit
30611 @end table
30612
30613 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
30614 @code{body} field is an empty list.
30615
30616 @subsubheading @value{GDBN} Command
30617
30618 The corresponding @value{GDBN} command is @samp{info break}.
30619
30620 @subsubheading Example
30621
30622 @smallexample
30623 (gdb)
30624 -break-list
30625 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30626 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30627 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30628 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30629 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30630 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30631 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30632 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30633 addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
30634 times="0"@},
30635 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
30636 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
30637 line="13",thread-groups=["i1"],times="0"@}]@}
30638 (gdb)
30639 @end smallexample
30640
30641 Here's an example of the result when there are no breakpoints:
30642
30643 @smallexample
30644 (gdb)
30645 -break-list
30646 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30647 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30648 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30649 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30650 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30651 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30652 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30653 body=[]@}
30654 (gdb)
30655 @end smallexample
30656
30657 @subheading The @code{-break-passcount} Command
30658 @findex -break-passcount
30659
30660 @subsubheading Synopsis
30661
30662 @smallexample
30663 -break-passcount @var{tracepoint-number} @var{passcount}
30664 @end smallexample
30665
30666 Set the passcount for tracepoint @var{tracepoint-number} to
30667 @var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
30668 is not a tracepoint, error is emitted. This corresponds to CLI
30669 command @samp{passcount}.
30670
30671 @subheading The @code{-break-watch} Command
30672 @findex -break-watch
30673
30674 @subsubheading Synopsis
30675
30676 @smallexample
30677 -break-watch [ -a | -r ]
30678 @end smallexample
30679
30680 Create a watchpoint. With the @samp{-a} option it will create an
30681 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
30682 read from or on a write to the memory location. With the @samp{-r}
30683 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
30684 trigger only when the memory location is accessed for reading. Without
30685 either of the options, the watchpoint created is a regular watchpoint,
30686 i.e., it will trigger when the memory location is accessed for writing.
30687 @xref{Set Watchpoints, , Setting Watchpoints}.
30688
30689 Note that @samp{-break-list} will report a single list of watchpoints and
30690 breakpoints inserted.
30691
30692 @subsubheading @value{GDBN} Command
30693
30694 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
30695 @samp{rwatch}.
30696
30697 @subsubheading Example
30698
30699 Setting a watchpoint on a variable in the @code{main} function:
30700
30701 @smallexample
30702 (gdb)
30703 -break-watch x
30704 ^done,wpt=@{number="2",exp="x"@}
30705 (gdb)
30706 -exec-continue
30707 ^running
30708 (gdb)
30709 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
30710 value=@{old="-268439212",new="55"@},
30711 frame=@{func="main",args=[],file="recursive2.c",
30712 fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
30713 (gdb)
30714 @end smallexample
30715
30716 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
30717 the program execution twice: first for the variable changing value, then
30718 for the watchpoint going out of scope.
30719
30720 @smallexample
30721 (gdb)
30722 -break-watch C
30723 ^done,wpt=@{number="5",exp="C"@}
30724 (gdb)
30725 -exec-continue
30726 ^running
30727 (gdb)
30728 *stopped,reason="watchpoint-trigger",
30729 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
30730 frame=@{func="callee4",args=[],
30731 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30732 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30733 arch="i386:x86_64"@}
30734 (gdb)
30735 -exec-continue
30736 ^running
30737 (gdb)
30738 *stopped,reason="watchpoint-scope",wpnum="5",
30739 frame=@{func="callee3",args=[@{name="strarg",
30740 value="0x11940 \"A string argument.\""@}],
30741 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30742 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30743 arch="i386:x86_64"@}
30744 (gdb)
30745 @end smallexample
30746
30747 Listing breakpoints and watchpoints, at different points in the program
30748 execution. Note that once the watchpoint goes out of scope, it is
30749 deleted.
30750
30751 @smallexample
30752 (gdb)
30753 -break-watch C
30754 ^done,wpt=@{number="2",exp="C"@}
30755 (gdb)
30756 -break-list
30757 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30758 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30759 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30760 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30761 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30762 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30763 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30764 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30765 addr="0x00010734",func="callee4",
30766 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30767 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
30768 times="1"@},
30769 bkpt=@{number="2",type="watchpoint",disp="keep",
30770 enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
30771 (gdb)
30772 -exec-continue
30773 ^running
30774 (gdb)
30775 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
30776 value=@{old="-276895068",new="3"@},
30777 frame=@{func="callee4",args=[],
30778 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30779 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30780 arch="i386:x86_64"@}
30781 (gdb)
30782 -break-list
30783 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30784 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30785 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30786 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30787 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30788 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30789 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30790 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30791 addr="0x00010734",func="callee4",
30792 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30793 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
30794 times="1"@},
30795 bkpt=@{number="2",type="watchpoint",disp="keep",
30796 enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
30797 (gdb)
30798 -exec-continue
30799 ^running
30800 ^done,reason="watchpoint-scope",wpnum="2",
30801 frame=@{func="callee3",args=[@{name="strarg",
30802 value="0x11940 \"A string argument.\""@}],
30803 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30804 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30805 arch="i386:x86_64"@}
30806 (gdb)
30807 -break-list
30808 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30809 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30810 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30811 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30812 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30813 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30814 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30815 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30816 addr="0x00010734",func="callee4",
30817 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30818 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
30819 thread-groups=["i1"],times="1"@}]@}
30820 (gdb)
30821 @end smallexample
30822
30823
30824 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30825 @node GDB/MI Catchpoint Commands
30826 @section @sc{gdb/mi} Catchpoint Commands
30827
30828 This section documents @sc{gdb/mi} commands for manipulating
30829 catchpoints.
30830
30831 @menu
30832 * Shared Library GDB/MI Catchpoint Commands::
30833 * Ada Exception GDB/MI Catchpoint Commands::
30834 * C++ Exception GDB/MI Catchpoint Commands::
30835 @end menu
30836
30837 @node Shared Library GDB/MI Catchpoint Commands
30838 @subsection Shared Library @sc{gdb/mi} Catchpoints
30839
30840 @subheading The @code{-catch-load} Command
30841 @findex -catch-load
30842
30843 @subsubheading Synopsis
30844
30845 @smallexample
30846 -catch-load [ -t ] [ -d ] @var{regexp}
30847 @end smallexample
30848
30849 Add a catchpoint for library load events. If the @samp{-t} option is used,
30850 the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30851 Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
30852 in a disabled state. The @samp{regexp} argument is a regular
30853 expression used to match the name of the loaded library.
30854
30855
30856 @subsubheading @value{GDBN} Command
30857
30858 The corresponding @value{GDBN} command is @samp{catch load}.
30859
30860 @subsubheading Example
30861
30862 @smallexample
30863 -catch-load -t foo.so
30864 ^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
30865 what="load of library matching foo.so",catch-type="load",times="0"@}
30866 (gdb)
30867 @end smallexample
30868
30869
30870 @subheading The @code{-catch-unload} Command
30871 @findex -catch-unload
30872
30873 @subsubheading Synopsis
30874
30875 @smallexample
30876 -catch-unload [ -t ] [ -d ] @var{regexp}
30877 @end smallexample
30878
30879 Add a catchpoint for library unload events. If the @samp{-t} option is
30880 used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30881 Breakpoints}). If the @samp{-d} option is used, the catchpoint is
30882 created in a disabled state. The @samp{regexp} argument is a regular
30883 expression used to match the name of the unloaded library.
30884
30885 @subsubheading @value{GDBN} Command
30886
30887 The corresponding @value{GDBN} command is @samp{catch unload}.
30888
30889 @subsubheading Example
30890
30891 @smallexample
30892 -catch-unload -d bar.so
30893 ^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
30894 what="load of library matching bar.so",catch-type="unload",times="0"@}
30895 (gdb)
30896 @end smallexample
30897
30898 @node Ada Exception GDB/MI Catchpoint Commands
30899 @subsection Ada Exception @sc{gdb/mi} Catchpoints
30900
30901 The following @sc{gdb/mi} commands can be used to create catchpoints
30902 that stop the execution when Ada exceptions are being raised.
30903
30904 @subheading The @code{-catch-assert} Command
30905 @findex -catch-assert
30906
30907 @subsubheading Synopsis
30908
30909 @smallexample
30910 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
30911 @end smallexample
30912
30913 Add a catchpoint for failed Ada assertions.
30914
30915 The possible optional parameters for this command are:
30916
30917 @table @samp
30918 @item -c @var{condition}
30919 Make the catchpoint conditional on @var{condition}.
30920 @item -d
30921 Create a disabled catchpoint.
30922 @item -t
30923 Create a temporary catchpoint.
30924 @end table
30925
30926 @subsubheading @value{GDBN} Command
30927
30928 The corresponding @value{GDBN} command is @samp{catch assert}.
30929
30930 @subsubheading Example
30931
30932 @smallexample
30933 -catch-assert
30934 ^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
30935 enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
30936 thread-groups=["i1"],times="0",
30937 original-location="__gnat_debug_raise_assert_failure"@}
30938 (gdb)
30939 @end smallexample
30940
30941 @subheading The @code{-catch-exception} Command
30942 @findex -catch-exception
30943
30944 @subsubheading Synopsis
30945
30946 @smallexample
30947 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30948 [ -t ] [ -u ]
30949 @end smallexample
30950
30951 Add a catchpoint stopping when Ada exceptions are raised.
30952 By default, the command stops the program when any Ada exception
30953 gets raised. But it is also possible, by using some of the
30954 optional parameters described below, to create more selective
30955 catchpoints.
30956
30957 The possible optional parameters for this command are:
30958
30959 @table @samp
30960 @item -c @var{condition}
30961 Make the catchpoint conditional on @var{condition}.
30962 @item -d
30963 Create a disabled catchpoint.
30964 @item -e @var{exception-name}
30965 Only stop when @var{exception-name} is raised. This option cannot
30966 be used combined with @samp{-u}.
30967 @item -t
30968 Create a temporary catchpoint.
30969 @item -u
30970 Stop only when an unhandled exception gets raised. This option
30971 cannot be used combined with @samp{-e}.
30972 @end table
30973
30974 @subsubheading @value{GDBN} Command
30975
30976 The corresponding @value{GDBN} commands are @samp{catch exception}
30977 and @samp{catch exception unhandled}.
30978
30979 @subsubheading Example
30980
30981 @smallexample
30982 -catch-exception -e Program_Error
30983 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30984 enabled="y",addr="0x0000000000404874",
30985 what="`Program_Error' Ada exception", thread-groups=["i1"],
30986 times="0",original-location="__gnat_debug_raise_exception"@}
30987 (gdb)
30988 @end smallexample
30989
30990 @subheading The @code{-catch-handlers} Command
30991 @findex -catch-handlers
30992
30993 @subsubheading Synopsis
30994
30995 @smallexample
30996 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30997 [ -t ]
30998 @end smallexample
30999
31000 Add a catchpoint stopping when Ada exceptions are handled.
31001 By default, the command stops the program when any Ada exception
31002 gets handled. But it is also possible, by using some of the
31003 optional parameters described below, to create more selective
31004 catchpoints.
31005
31006 The possible optional parameters for this command are:
31007
31008 @table @samp
31009 @item -c @var{condition}
31010 Make the catchpoint conditional on @var{condition}.
31011 @item -d
31012 Create a disabled catchpoint.
31013 @item -e @var{exception-name}
31014 Only stop when @var{exception-name} is handled.
31015 @item -t
31016 Create a temporary catchpoint.
31017 @end table
31018
31019 @subsubheading @value{GDBN} Command
31020
31021 The corresponding @value{GDBN} command is @samp{catch handlers}.
31022
31023 @subsubheading Example
31024
31025 @smallexample
31026 -catch-handlers -e Constraint_Error
31027 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
31028 enabled="y",addr="0x0000000000402f68",
31029 what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
31030 times="0",original-location="__gnat_begin_handler"@}
31031 (gdb)
31032 @end smallexample
31033
31034 @node C++ Exception GDB/MI Catchpoint Commands
31035 @subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
31036
31037 The following @sc{gdb/mi} commands can be used to create catchpoints
31038 that stop the execution when C@t{++} exceptions are being throw, rethrown,
31039 or caught.
31040
31041 @subheading The @code{-catch-throw} Command
31042 @findex -catch-throw
31043
31044 @subsubheading Synopsis
31045
31046 @smallexample
31047 -catch-throw [ -t ] [ -r @var{regexp}]
31048 @end smallexample
31049
31050 Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
31051 given, then only exceptions whose type matches the regular expression
31052 will be caught.
31053
31054 If @samp{-t} is given, then the catchpoint is enabled only for one
31055 stop, the catchpoint is automatically deleted after stopping once for
31056 the event.
31057
31058 @subsubheading @value{GDBN} Command
31059
31060 The corresponding @value{GDBN} commands are @samp{catch throw}
31061 and @samp{tcatch throw} (@pxref{Set Catchpoints}).
31062
31063 @subsubheading Example
31064
31065 @smallexample
31066 -catch-throw -r exception_type
31067 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31068 what="exception throw",catch-type="throw",
31069 thread-groups=["i1"],
31070 regexp="exception_type",times="0"@}
31071 (gdb)
31072 -exec-run
31073 ^running
31074 (gdb)
31075 ~"\n"
31076 ~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
31077 in __cxa_throw () from /lib64/libstdc++.so.6\n"
31078 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31079 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
31080 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31081 thread-id="1",stopped-threads="all",core="6"
31082 (gdb)
31083 @end smallexample
31084
31085 @subheading The @code{-catch-rethrow} Command
31086 @findex -catch-rethrow
31087
31088 @subsubheading Synopsis
31089
31090 @smallexample
31091 -catch-rethrow [ -t ] [ -r @var{regexp}]
31092 @end smallexample
31093
31094 Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
31095 then only exceptions whose type matches the regular expression will be
31096 caught.
31097
31098 If @samp{-t} is given, then the catchpoint is enabled only for one
31099 stop, the catchpoint is automatically deleted after the first event is
31100 caught.
31101
31102 @subsubheading @value{GDBN} Command
31103
31104 The corresponding @value{GDBN} commands are @samp{catch rethrow}
31105 and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
31106
31107 @subsubheading Example
31108
31109 @smallexample
31110 -catch-rethrow -r exception_type
31111 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31112 what="exception rethrow",catch-type="rethrow",
31113 thread-groups=["i1"],
31114 regexp="exception_type",times="0"@}
31115 (gdb)
31116 -exec-run
31117 ^running
31118 (gdb)
31119 ~"\n"
31120 ~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
31121 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
31122 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31123 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
31124 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31125 thread-id="1",stopped-threads="all",core="6"
31126 (gdb)
31127 @end smallexample
31128
31129 @subheading The @code{-catch-catch} Command
31130 @findex -catch-catch
31131
31132 @subsubheading Synopsis
31133
31134 @smallexample
31135 -catch-catch [ -t ] [ -r @var{regexp}]
31136 @end smallexample
31137
31138 Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
31139 is given, then only exceptions whose type matches the regular
31140 expression will be caught.
31141
31142 If @samp{-t} is given, then the catchpoint is enabled only for one
31143 stop, the catchpoint is automatically deleted after the first event is
31144 caught.
31145
31146 @subsubheading @value{GDBN} Command
31147
31148 The corresponding @value{GDBN} commands are @samp{catch catch}
31149 and @samp{tcatch catch} (@pxref{Set Catchpoints}).
31150
31151 @subsubheading Example
31152
31153 @smallexample
31154 -catch-catch -r exception_type
31155 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31156 what="exception catch",catch-type="catch",
31157 thread-groups=["i1"],
31158 regexp="exception_type",times="0"@}
31159 (gdb)
31160 -exec-run
31161 ^running
31162 (gdb)
31163 ~"\n"
31164 ~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
31165 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
31166 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31167 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
31168 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31169 thread-id="1",stopped-threads="all",core="6"
31170 (gdb)
31171 @end smallexample
31172
31173 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31174 @node GDB/MI Program Context
31175 @section @sc{gdb/mi} Program Context
31176
31177 @subheading The @code{-exec-arguments} Command
31178 @findex -exec-arguments
31179
31180
31181 @subsubheading Synopsis
31182
31183 @smallexample
31184 -exec-arguments @var{args}
31185 @end smallexample
31186
31187 Set the inferior program arguments, to be used in the next
31188 @samp{-exec-run}.
31189
31190 @subsubheading @value{GDBN} Command
31191
31192 The corresponding @value{GDBN} command is @samp{set args}.
31193
31194 @subsubheading Example
31195
31196 @smallexample
31197 (gdb)
31198 -exec-arguments -v word
31199 ^done
31200 (gdb)
31201 @end smallexample
31202
31203
31204 @ignore
31205 @subheading The @code{-exec-show-arguments} Command
31206 @findex -exec-show-arguments
31207
31208 @subsubheading Synopsis
31209
31210 @smallexample
31211 -exec-show-arguments
31212 @end smallexample
31213
31214 Print the arguments of the program.
31215
31216 @subsubheading @value{GDBN} Command
31217
31218 The corresponding @value{GDBN} command is @samp{show args}.
31219
31220 @subsubheading Example
31221 N.A.
31222 @end ignore
31223
31224
31225 @subheading The @code{-environment-cd} Command
31226 @findex -environment-cd
31227
31228 @subsubheading Synopsis
31229
31230 @smallexample
31231 -environment-cd @var{pathdir}
31232 @end smallexample
31233
31234 Set @value{GDBN}'s working directory.
31235
31236 @subsubheading @value{GDBN} Command
31237
31238 The corresponding @value{GDBN} command is @samp{cd}.
31239
31240 @subsubheading Example
31241
31242 @smallexample
31243 (gdb)
31244 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31245 ^done
31246 (gdb)
31247 @end smallexample
31248
31249
31250 @subheading The @code{-environment-directory} Command
31251 @findex -environment-directory
31252
31253 @subsubheading Synopsis
31254
31255 @smallexample
31256 -environment-directory [ -r ] [ @var{pathdir} ]+
31257 @end smallexample
31258
31259 Add directories @var{pathdir} to beginning of search path for source files.
31260 If the @samp{-r} option is used, the search path is reset to the default
31261 search path. If directories @var{pathdir} are supplied in addition to the
31262 @samp{-r} option, the search path is first reset and then addition
31263 occurs as normal.
31264 Multiple directories may be specified, separated by blanks. Specifying
31265 multiple directories in a single command
31266 results in the directories added to the beginning of the
31267 search path in the same order they were presented in the command.
31268 If blanks are needed as
31269 part of a directory name, double-quotes should be used around
31270 the name. In the command output, the path will show up separated
31271 by the system directory-separator character. The directory-separator
31272 character must not be used
31273 in any directory name.
31274 If no directories are specified, the current search path is displayed.
31275
31276 @subsubheading @value{GDBN} Command
31277
31278 The corresponding @value{GDBN} command is @samp{dir}.
31279
31280 @subsubheading Example
31281
31282 @smallexample
31283 (gdb)
31284 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31285 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
31286 (gdb)
31287 -environment-directory ""
31288 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
31289 (gdb)
31290 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
31291 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
31292 (gdb)
31293 -environment-directory -r
31294 ^done,source-path="$cdir:$cwd"
31295 (gdb)
31296 @end smallexample
31297
31298
31299 @subheading The @code{-environment-path} Command
31300 @findex -environment-path
31301
31302 @subsubheading Synopsis
31303
31304 @smallexample
31305 -environment-path [ -r ] [ @var{pathdir} ]+
31306 @end smallexample
31307
31308 Add directories @var{pathdir} to beginning of search path for object files.
31309 If the @samp{-r} option is used, the search path is reset to the original
31310 search path that existed at gdb start-up. If directories @var{pathdir} are
31311 supplied in addition to the
31312 @samp{-r} option, the search path is first reset and then addition
31313 occurs as normal.
31314 Multiple directories may be specified, separated by blanks. Specifying
31315 multiple directories in a single command
31316 results in the directories added to the beginning of the
31317 search path in the same order they were presented in the command.
31318 If blanks are needed as
31319 part of a directory name, double-quotes should be used around
31320 the name. In the command output, the path will show up separated
31321 by the system directory-separator character. The directory-separator
31322 character must not be used
31323 in any directory name.
31324 If no directories are specified, the current path is displayed.
31325
31326
31327 @subsubheading @value{GDBN} Command
31328
31329 The corresponding @value{GDBN} command is @samp{path}.
31330
31331 @subsubheading Example
31332
31333 @smallexample
31334 (gdb)
31335 -environment-path
31336 ^done,path="/usr/bin"
31337 (gdb)
31338 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
31339 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
31340 (gdb)
31341 -environment-path -r /usr/local/bin
31342 ^done,path="/usr/local/bin:/usr/bin"
31343 (gdb)
31344 @end smallexample
31345
31346
31347 @subheading The @code{-environment-pwd} Command
31348 @findex -environment-pwd
31349
31350 @subsubheading Synopsis
31351
31352 @smallexample
31353 -environment-pwd
31354 @end smallexample
31355
31356 Show the current working directory.
31357
31358 @subsubheading @value{GDBN} Command
31359
31360 The corresponding @value{GDBN} command is @samp{pwd}.
31361
31362 @subsubheading Example
31363
31364 @smallexample
31365 (gdb)
31366 -environment-pwd
31367 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
31368 (gdb)
31369 @end smallexample
31370
31371 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31372 @node GDB/MI Thread Commands
31373 @section @sc{gdb/mi} Thread Commands
31374
31375
31376 @subheading The @code{-thread-info} Command
31377 @findex -thread-info
31378
31379 @subsubheading Synopsis
31380
31381 @smallexample
31382 -thread-info [ @var{thread-id} ]
31383 @end smallexample
31384
31385 Reports information about either a specific thread, if the
31386 @var{thread-id} parameter is present, or about all threads.
31387 @var{thread-id} is the thread's global thread ID. When printing
31388 information about all threads, also reports the global ID of the
31389 current thread.
31390
31391 @subsubheading @value{GDBN} Command
31392
31393 The @samp{info thread} command prints the same information
31394 about all threads.
31395
31396 @subsubheading Result
31397
31398 The result contains the following attributes:
31399
31400 @table @samp
31401 @item threads
31402 A list of threads. The format of the elements of the list is described in
31403 @ref{GDB/MI Thread Information}.
31404
31405 @item current-thread-id
31406 The global id of the currently selected thread. This field is omitted if there
31407 is no selected thread (for example, when the selected inferior is not running,
31408 and therefore has no threads) or if a @var{thread-id} argument was passed to
31409 the command.
31410
31411 @end table
31412
31413 @subsubheading Example
31414
31415 @smallexample
31416 -thread-info
31417 ^done,threads=[
31418 @{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
31419 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
31420 args=[]@},state="running"@},
31421 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
31422 frame=@{level="0",addr="0x0804891f",func="foo",
31423 args=[@{name="i",value="10"@}],
31424 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
31425 state="running"@}],
31426 current-thread-id="1"
31427 (gdb)
31428 @end smallexample
31429
31430 @subheading The @code{-thread-list-ids} Command
31431 @findex -thread-list-ids
31432
31433 @subsubheading Synopsis
31434
31435 @smallexample
31436 -thread-list-ids
31437 @end smallexample
31438
31439 Produces a list of the currently known global @value{GDBN} thread ids.
31440 At the end of the list it also prints the total number of such
31441 threads.
31442
31443 This command is retained for historical reasons, the
31444 @code{-thread-info} command should be used instead.
31445
31446 @subsubheading @value{GDBN} Command
31447
31448 Part of @samp{info threads} supplies the same information.
31449
31450 @subsubheading Example
31451
31452 @smallexample
31453 (gdb)
31454 -thread-list-ids
31455 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31456 current-thread-id="1",number-of-threads="3"
31457 (gdb)
31458 @end smallexample
31459
31460
31461 @subheading The @code{-thread-select} Command
31462 @findex -thread-select
31463
31464 @subsubheading Synopsis
31465
31466 @smallexample
31467 -thread-select @var{thread-id}
31468 @end smallexample
31469
31470 Make thread with global thread number @var{thread-id} the current
31471 thread. It prints the number of the new current thread, and the
31472 topmost frame for that thread.
31473
31474 This command is deprecated in favor of explicitly using the
31475 @samp{--thread} option to each command.
31476
31477 @subsubheading @value{GDBN} Command
31478
31479 The corresponding @value{GDBN} command is @samp{thread}.
31480
31481 @subsubheading Example
31482
31483 @smallexample
31484 (gdb)
31485 -exec-next
31486 ^running
31487 (gdb)
31488 *stopped,reason="end-stepping-range",thread-id="2",line="187",
31489 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
31490 (gdb)
31491 -thread-list-ids
31492 ^done,
31493 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31494 number-of-threads="3"
31495 (gdb)
31496 -thread-select 3
31497 ^done,new-thread-id="3",
31498 frame=@{level="0",func="vprintf",
31499 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
31500 @{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
31501 (gdb)
31502 @end smallexample
31503
31504 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31505 @node GDB/MI Ada Tasking Commands
31506 @section @sc{gdb/mi} Ada Tasking Commands
31507
31508 @subheading The @code{-ada-task-info} Command
31509 @findex -ada-task-info
31510
31511 @subsubheading Synopsis
31512
31513 @smallexample
31514 -ada-task-info [ @var{task-id} ]
31515 @end smallexample
31516
31517 Reports information about either a specific Ada task, if the
31518 @var{task-id} parameter is present, or about all Ada tasks.
31519
31520 @subsubheading @value{GDBN} Command
31521
31522 The @samp{info tasks} command prints the same information
31523 about all Ada tasks (@pxref{Ada Tasks}).
31524
31525 @subsubheading Result
31526
31527 The result is a table of Ada tasks. The following columns are
31528 defined for each Ada task:
31529
31530 @table @samp
31531 @item current
31532 This field exists only for the current thread. It has the value @samp{*}.
31533
31534 @item id
31535 The identifier that @value{GDBN} uses to refer to the Ada task.
31536
31537 @item task-id
31538 The identifier that the target uses to refer to the Ada task.
31539
31540 @item thread-id
31541 The global thread identifier of the thread corresponding to the Ada
31542 task.
31543
31544 This field should always exist, as Ada tasks are always implemented
31545 on top of a thread. But if @value{GDBN} cannot find this corresponding
31546 thread for any reason, the field is omitted.
31547
31548 @item parent-id
31549 This field exists only when the task was created by another task.
31550 In this case, it provides the ID of the parent task.
31551
31552 @item priority
31553 The base priority of the task.
31554
31555 @item state
31556 The current state of the task. For a detailed description of the
31557 possible states, see @ref{Ada Tasks}.
31558
31559 @item name
31560 The name of the task.
31561
31562 @end table
31563
31564 @subsubheading Example
31565
31566 @smallexample
31567 -ada-task-info
31568 ^done,tasks=@{nr_rows="3",nr_cols="8",
31569 hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
31570 @{width="3",alignment="1",col_name="id",colhdr="ID"@},
31571 @{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
31572 @{width="4",alignment="1",col_name="thread-id",colhdr=""@},
31573 @{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
31574 @{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
31575 @{width="22",alignment="-1",col_name="state",colhdr="State"@},
31576 @{width="1",alignment="2",col_name="name",colhdr="Name"@}],
31577 body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
31578 state="Child Termination Wait",name="main_task"@}]@}
31579 (gdb)
31580 @end smallexample
31581
31582 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31583 @node GDB/MI Program Execution
31584 @section @sc{gdb/mi} Program Execution
31585
31586 These are the asynchronous commands which generate the out-of-band
31587 record @samp{*stopped}. Currently @value{GDBN} only really executes
31588 asynchronously with remote targets and this interaction is mimicked in
31589 other cases.
31590
31591 @subheading The @code{-exec-continue} Command
31592 @findex -exec-continue
31593
31594 @subsubheading Synopsis
31595
31596 @smallexample
31597 -exec-continue [--reverse] [--all|--thread-group N]
31598 @end smallexample
31599
31600 Resumes the execution of the inferior program, which will continue
31601 to execute until it reaches a debugger stop event. If the
31602 @samp{--reverse} option is specified, execution resumes in reverse until
31603 it reaches a stop event. Stop events may include
31604 @itemize @bullet
31605 @item
31606 breakpoints or watchpoints
31607 @item
31608 signals or exceptions
31609 @item
31610 the end of the process (or its beginning under @samp{--reverse})
31611 @item
31612 the end or beginning of a replay log if one is being used.
31613 @end itemize
31614 In all-stop mode (@pxref{All-Stop
31615 Mode}), may resume only one thread, or all threads, depending on the
31616 value of the @samp{scheduler-locking} variable. If @samp{--all} is
31617 specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
31618 ignored in all-stop mode. If the @samp{--thread-group} options is
31619 specified, then all threads in that thread group are resumed.
31620
31621 @subsubheading @value{GDBN} Command
31622
31623 The corresponding @value{GDBN} corresponding is @samp{continue}.
31624
31625 @subsubheading Example
31626
31627 @smallexample
31628 -exec-continue
31629 ^running
31630 (gdb)
31631 @@Hello world
31632 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
31633 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
31634 line="13",arch="i386:x86_64"@}
31635 (gdb)
31636 @end smallexample
31637
31638
31639 @subheading The @code{-exec-finish} Command
31640 @findex -exec-finish
31641
31642 @subsubheading Synopsis
31643
31644 @smallexample
31645 -exec-finish [--reverse]
31646 @end smallexample
31647
31648 Resumes the execution of the inferior program until the current
31649 function is exited. Displays the results returned by the function.
31650 If the @samp{--reverse} option is specified, resumes the reverse
31651 execution of the inferior program until the point where current
31652 function was called.
31653
31654 @subsubheading @value{GDBN} Command
31655
31656 The corresponding @value{GDBN} command is @samp{finish}.
31657
31658 @subsubheading Example
31659
31660 Function returning @code{void}.
31661
31662 @smallexample
31663 -exec-finish
31664 ^running
31665 (gdb)
31666 @@hello from foo
31667 *stopped,reason="function-finished",frame=@{func="main",args=[],
31668 file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
31669 (gdb)
31670 @end smallexample
31671
31672 Function returning other than @code{void}. The name of the internal
31673 @value{GDBN} variable storing the result is printed, together with the
31674 value itself.
31675
31676 @smallexample
31677 -exec-finish
31678 ^running
31679 (gdb)
31680 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
31681 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
31682 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31683 arch="i386:x86_64"@},
31684 gdb-result-var="$1",return-value="0"
31685 (gdb)
31686 @end smallexample
31687
31688
31689 @subheading The @code{-exec-interrupt} Command
31690 @findex -exec-interrupt
31691
31692 @subsubheading Synopsis
31693
31694 @smallexample
31695 -exec-interrupt [--all|--thread-group N]
31696 @end smallexample
31697
31698 Interrupts the background execution of the target. Note how the token
31699 associated with the stop message is the one for the execution command
31700 that has been interrupted. The token for the interrupt itself only
31701 appears in the @samp{^done} output. If the user is trying to
31702 interrupt a non-running program, an error message will be printed.
31703
31704 Note that when asynchronous execution is enabled, this command is
31705 asynchronous just like other execution commands. That is, first the
31706 @samp{^done} response will be printed, and the target stop will be
31707 reported after that using the @samp{*stopped} notification.
31708
31709 In non-stop mode, only the context thread is interrupted by default.
31710 All threads (in all inferiors) will be interrupted if the
31711 @samp{--all} option is specified. If the @samp{--thread-group}
31712 option is specified, all threads in that group will be interrupted.
31713
31714 @subsubheading @value{GDBN} Command
31715
31716 The corresponding @value{GDBN} command is @samp{interrupt}.
31717
31718 @subsubheading Example
31719
31720 @smallexample
31721 (gdb)
31722 111-exec-continue
31723 111^running
31724
31725 (gdb)
31726 222-exec-interrupt
31727 222^done
31728 (gdb)
31729 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
31730 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
31731 fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
31732 (gdb)
31733
31734 (gdb)
31735 -exec-interrupt
31736 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
31737 (gdb)
31738 @end smallexample
31739
31740 @subheading The @code{-exec-jump} Command
31741 @findex -exec-jump
31742
31743 @subsubheading Synopsis
31744
31745 @smallexample
31746 -exec-jump @var{location}
31747 @end smallexample
31748
31749 Resumes execution of the inferior program at the location specified by
31750 parameter. @xref{Specify Location}, for a description of the
31751 different forms of @var{location}.
31752
31753 @subsubheading @value{GDBN} Command
31754
31755 The corresponding @value{GDBN} command is @samp{jump}.
31756
31757 @subsubheading Example
31758
31759 @smallexample
31760 -exec-jump foo.c:10
31761 *running,thread-id="all"
31762 ^running
31763 @end smallexample
31764
31765
31766 @subheading The @code{-exec-next} Command
31767 @findex -exec-next
31768
31769 @subsubheading Synopsis
31770
31771 @smallexample
31772 -exec-next [--reverse]
31773 @end smallexample
31774
31775 Resumes execution of the inferior program, stopping when the beginning
31776 of the next source line is reached.
31777
31778 If the @samp{--reverse} option is specified, resumes reverse execution
31779 of the inferior program, stopping at the beginning of the previous
31780 source line. If you issue this command on the first line of a
31781 function, it will take you back to the caller of that function, to the
31782 source line where the function was called.
31783
31784
31785 @subsubheading @value{GDBN} Command
31786
31787 The corresponding @value{GDBN} command is @samp{next}.
31788
31789 @subsubheading Example
31790
31791 @smallexample
31792 -exec-next
31793 ^running
31794 (gdb)
31795 *stopped,reason="end-stepping-range",line="8",file="hello.c"
31796 (gdb)
31797 @end smallexample
31798
31799
31800 @subheading The @code{-exec-next-instruction} Command
31801 @findex -exec-next-instruction
31802
31803 @subsubheading Synopsis
31804
31805 @smallexample
31806 -exec-next-instruction [--reverse]
31807 @end smallexample
31808
31809 Executes one machine instruction. If the instruction is a function
31810 call, continues until the function returns. If the program stops at an
31811 instruction in the middle of a source line, the address will be
31812 printed as well.
31813
31814 If the @samp{--reverse} option is specified, resumes reverse execution
31815 of the inferior program, stopping at the previous instruction. If the
31816 previously executed instruction was a return from another function,
31817 it will continue to execute in reverse until the call to that function
31818 (from the current stack frame) is reached.
31819
31820 @subsubheading @value{GDBN} Command
31821
31822 The corresponding @value{GDBN} command is @samp{nexti}.
31823
31824 @subsubheading Example
31825
31826 @smallexample
31827 (gdb)
31828 -exec-next-instruction
31829 ^running
31830
31831 (gdb)
31832 *stopped,reason="end-stepping-range",
31833 addr="0x000100d4",line="5",file="hello.c"
31834 (gdb)
31835 @end smallexample
31836
31837
31838 @subheading The @code{-exec-return} Command
31839 @findex -exec-return
31840
31841 @subsubheading Synopsis
31842
31843 @smallexample
31844 -exec-return
31845 @end smallexample
31846
31847 Makes current function return immediately. Doesn't execute the inferior.
31848 Displays the new current frame.
31849
31850 @subsubheading @value{GDBN} Command
31851
31852 The corresponding @value{GDBN} command is @samp{return}.
31853
31854 @subsubheading Example
31855
31856 @smallexample
31857 (gdb)
31858 200-break-insert callee4
31859 200^done,bkpt=@{number="1",addr="0x00010734",
31860 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
31861 (gdb)
31862 000-exec-run
31863 000^running
31864 (gdb)
31865 000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
31866 frame=@{func="callee4",args=[],
31867 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31868 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31869 arch="i386:x86_64"@}
31870 (gdb)
31871 205-break-delete
31872 205^done
31873 (gdb)
31874 111-exec-return
31875 111^done,frame=@{level="0",func="callee3",
31876 args=[@{name="strarg",
31877 value="0x11940 \"A string argument.\""@}],
31878 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31879 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31880 arch="i386:x86_64"@}
31881 (gdb)
31882 @end smallexample
31883
31884
31885 @subheading The @code{-exec-run} Command
31886 @findex -exec-run
31887
31888 @subsubheading Synopsis
31889
31890 @smallexample
31891 -exec-run [ --all | --thread-group N ] [ --start ]
31892 @end smallexample
31893
31894 Starts execution of the inferior from the beginning. The inferior
31895 executes until either a breakpoint is encountered or the program
31896 exits. In the latter case the output will include an exit code, if
31897 the program has exited exceptionally.
31898
31899 When neither the @samp{--all} nor the @samp{--thread-group} option
31900 is specified, the current inferior is started. If the
31901 @samp{--thread-group} option is specified, it should refer to a thread
31902 group of type @samp{process}, and that thread group will be started.
31903 If the @samp{--all} option is specified, then all inferiors will be started.
31904
31905 Using the @samp{--start} option instructs the debugger to stop
31906 the execution at the start of the inferior's main subprogram,
31907 following the same behavior as the @code{start} command
31908 (@pxref{Starting}).
31909
31910 @subsubheading @value{GDBN} Command
31911
31912 The corresponding @value{GDBN} command is @samp{run}.
31913
31914 @subsubheading Examples
31915
31916 @smallexample
31917 (gdb)
31918 -break-insert main
31919 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
31920 (gdb)
31921 -exec-run
31922 ^running
31923 (gdb)
31924 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
31925 frame=@{func="main",args=[],file="recursive2.c",
31926 fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
31927 (gdb)
31928 @end smallexample
31929
31930 @noindent
31931 Program exited normally:
31932
31933 @smallexample
31934 (gdb)
31935 -exec-run
31936 ^running
31937 (gdb)
31938 x = 55
31939 *stopped,reason="exited-normally"
31940 (gdb)
31941 @end smallexample
31942
31943 @noindent
31944 Program exited exceptionally:
31945
31946 @smallexample
31947 (gdb)
31948 -exec-run
31949 ^running
31950 (gdb)
31951 x = 55
31952 *stopped,reason="exited",exit-code="01"
31953 (gdb)
31954 @end smallexample
31955
31956 Another way the program can terminate is if it receives a signal such as
31957 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
31958
31959 @smallexample
31960 (gdb)
31961 *stopped,reason="exited-signalled",signal-name="SIGINT",
31962 signal-meaning="Interrupt"
31963 @end smallexample
31964
31965
31966 @c @subheading -exec-signal
31967
31968
31969 @subheading The @code{-exec-step} Command
31970 @findex -exec-step
31971
31972 @subsubheading Synopsis
31973
31974 @smallexample
31975 -exec-step [--reverse]
31976 @end smallexample
31977
31978 Resumes execution of the inferior program, stopping when the beginning
31979 of the next source line is reached, if the next source line is not a
31980 function call. If it is, stop at the first instruction of the called
31981 function. If the @samp{--reverse} option is specified, resumes reverse
31982 execution of the inferior program, stopping at the beginning of the
31983 previously executed source line.
31984
31985 @subsubheading @value{GDBN} Command
31986
31987 The corresponding @value{GDBN} command is @samp{step}.
31988
31989 @subsubheading Example
31990
31991 Stepping into a function:
31992
31993 @smallexample
31994 -exec-step
31995 ^running
31996 (gdb)
31997 *stopped,reason="end-stepping-range",
31998 frame=@{func="foo",args=[@{name="a",value="10"@},
31999 @{name="b",value="0"@}],file="recursive2.c",
32000 fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
32001 (gdb)
32002 @end smallexample
32003
32004 Regular stepping:
32005
32006 @smallexample
32007 -exec-step
32008 ^running
32009 (gdb)
32010 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
32011 (gdb)
32012 @end smallexample
32013
32014
32015 @subheading The @code{-exec-step-instruction} Command
32016 @findex -exec-step-instruction
32017
32018 @subsubheading Synopsis
32019
32020 @smallexample
32021 -exec-step-instruction [--reverse]
32022 @end smallexample
32023
32024 Resumes the inferior which executes one machine instruction. If the
32025 @samp{--reverse} option is specified, resumes reverse execution of the
32026 inferior program, stopping at the previously executed instruction.
32027 The output, once @value{GDBN} has stopped, will vary depending on
32028 whether we have stopped in the middle of a source line or not. In the
32029 former case, the address at which the program stopped will be printed
32030 as well.
32031
32032 @subsubheading @value{GDBN} Command
32033
32034 The corresponding @value{GDBN} command is @samp{stepi}.
32035
32036 @subsubheading Example
32037
32038 @smallexample
32039 (gdb)
32040 -exec-step-instruction
32041 ^running
32042
32043 (gdb)
32044 *stopped,reason="end-stepping-range",
32045 frame=@{func="foo",args=[],file="try.c",
32046 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
32047 (gdb)
32048 -exec-step-instruction
32049 ^running
32050
32051 (gdb)
32052 *stopped,reason="end-stepping-range",
32053 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
32054 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
32055 (gdb)
32056 @end smallexample
32057
32058
32059 @subheading The @code{-exec-until} Command
32060 @findex -exec-until
32061
32062 @subsubheading Synopsis
32063
32064 @smallexample
32065 -exec-until [ @var{location} ]
32066 @end smallexample
32067
32068 Executes the inferior until the @var{location} specified in the
32069 argument is reached. If there is no argument, the inferior executes
32070 until a source line greater than the current one is reached. The
32071 reason for stopping in this case will be @samp{location-reached}.
32072
32073 @subsubheading @value{GDBN} Command
32074
32075 The corresponding @value{GDBN} command is @samp{until}.
32076
32077 @subsubheading Example
32078
32079 @smallexample
32080 (gdb)
32081 -exec-until recursive2.c:6
32082 ^running
32083 (gdb)
32084 x = 55
32085 *stopped,reason="location-reached",frame=@{func="main",args=[],
32086 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
32087 arch="i386:x86_64"@}
32088 (gdb)
32089 @end smallexample
32090
32091 @ignore
32092 @subheading -file-clear
32093 Is this going away????
32094 @end ignore
32095
32096 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32097 @node GDB/MI Stack Manipulation
32098 @section @sc{gdb/mi} Stack Manipulation Commands
32099
32100 @subheading The @code{-enable-frame-filters} Command
32101 @findex -enable-frame-filters
32102
32103 @smallexample
32104 -enable-frame-filters
32105 @end smallexample
32106
32107 @value{GDBN} allows Python-based frame filters to affect the output of
32108 the MI commands relating to stack traces. As there is no way to
32109 implement this in a fully backward-compatible way, a front end must
32110 request that this functionality be enabled.
32111
32112 Once enabled, this feature cannot be disabled.
32113
32114 Note that if Python support has not been compiled into @value{GDBN},
32115 this command will still succeed (and do nothing).
32116
32117 @subheading The @code{-stack-info-frame} Command
32118 @findex -stack-info-frame
32119
32120 @subsubheading Synopsis
32121
32122 @smallexample
32123 -stack-info-frame
32124 @end smallexample
32125
32126 Get info on the selected frame.
32127
32128 @subsubheading @value{GDBN} Command
32129
32130 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
32131 (without arguments).
32132
32133 @subsubheading Example
32134
32135 @smallexample
32136 (gdb)
32137 -stack-info-frame
32138 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
32139 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32140 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
32141 arch="i386:x86_64"@}
32142 (gdb)
32143 @end smallexample
32144
32145 @subheading The @code{-stack-info-depth} Command
32146 @findex -stack-info-depth
32147
32148 @subsubheading Synopsis
32149
32150 @smallexample
32151 -stack-info-depth [ @var{max-depth} ]
32152 @end smallexample
32153
32154 Return the depth of the stack. If the integer argument @var{max-depth}
32155 is specified, do not count beyond @var{max-depth} frames.
32156
32157 @subsubheading @value{GDBN} Command
32158
32159 There's no equivalent @value{GDBN} command.
32160
32161 @subsubheading Example
32162
32163 For a stack with frame levels 0 through 11:
32164
32165 @smallexample
32166 (gdb)
32167 -stack-info-depth
32168 ^done,depth="12"
32169 (gdb)
32170 -stack-info-depth 4
32171 ^done,depth="4"
32172 (gdb)
32173 -stack-info-depth 12
32174 ^done,depth="12"
32175 (gdb)
32176 -stack-info-depth 11
32177 ^done,depth="11"
32178 (gdb)
32179 -stack-info-depth 13
32180 ^done,depth="12"
32181 (gdb)
32182 @end smallexample
32183
32184 @anchor{-stack-list-arguments}
32185 @subheading The @code{-stack-list-arguments} Command
32186 @findex -stack-list-arguments
32187
32188 @subsubheading Synopsis
32189
32190 @smallexample
32191 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32192 [ @var{low-frame} @var{high-frame} ]
32193 @end smallexample
32194
32195 Display a list of the arguments for the frames between @var{low-frame}
32196 and @var{high-frame} (inclusive). If @var{low-frame} and
32197 @var{high-frame} are not provided, list the arguments for the whole
32198 call stack. If the two arguments are equal, show the single frame
32199 at the corresponding level. It is an error if @var{low-frame} is
32200 larger than the actual number of frames. On the other hand,
32201 @var{high-frame} may be larger than the actual number of frames, in
32202 which case only existing frames will be returned.
32203
32204 If @var{print-values} is 0 or @code{--no-values}, print only the names of
32205 the variables; if it is 1 or @code{--all-values}, print also their
32206 values; and if it is 2 or @code{--simple-values}, print the name,
32207 type and value for simple data types, and the name and type for arrays,
32208 structures and unions. If the option @code{--no-frame-filters} is
32209 supplied, then Python frame filters will not be executed.
32210
32211 If the @code{--skip-unavailable} option is specified, arguments that
32212 are not available are not listed. Partially available arguments
32213 are still displayed, however.
32214
32215 Use of this command to obtain arguments in a single frame is
32216 deprecated in favor of the @samp{-stack-list-variables} command.
32217
32218 @subsubheading @value{GDBN} Command
32219
32220 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
32221 @samp{gdb_get_args} command which partially overlaps with the
32222 functionality of @samp{-stack-list-arguments}.
32223
32224 @subsubheading Example
32225
32226 @smallexample
32227 (gdb)
32228 -stack-list-frames
32229 ^done,
32230 stack=[
32231 frame=@{level="0",addr="0x00010734",func="callee4",
32232 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32233 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
32234 arch="i386:x86_64"@},
32235 frame=@{level="1",addr="0x0001076c",func="callee3",
32236 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32237 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
32238 arch="i386:x86_64"@},
32239 frame=@{level="2",addr="0x0001078c",func="callee2",
32240 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32241 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
32242 arch="i386:x86_64"@},
32243 frame=@{level="3",addr="0x000107b4",func="callee1",
32244 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32245 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
32246 arch="i386:x86_64"@},
32247 frame=@{level="4",addr="0x000107e0",func="main",
32248 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32249 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
32250 arch="i386:x86_64"@}]
32251 (gdb)
32252 -stack-list-arguments 0
32253 ^done,
32254 stack-args=[
32255 frame=@{level="0",args=[]@},
32256 frame=@{level="1",args=[name="strarg"]@},
32257 frame=@{level="2",args=[name="intarg",name="strarg"]@},
32258 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
32259 frame=@{level="4",args=[]@}]
32260 (gdb)
32261 -stack-list-arguments 1
32262 ^done,
32263 stack-args=[
32264 frame=@{level="0",args=[]@},
32265 frame=@{level="1",
32266 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32267 frame=@{level="2",args=[
32268 @{name="intarg",value="2"@},
32269 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32270 @{frame=@{level="3",args=[
32271 @{name="intarg",value="2"@},
32272 @{name="strarg",value="0x11940 \"A string argument.\""@},
32273 @{name="fltarg",value="3.5"@}]@},
32274 frame=@{level="4",args=[]@}]
32275 (gdb)
32276 -stack-list-arguments 0 2 2
32277 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
32278 (gdb)
32279 -stack-list-arguments 1 2 2
32280 ^done,stack-args=[frame=@{level="2",
32281 args=[@{name="intarg",value="2"@},
32282 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
32283 (gdb)
32284 @end smallexample
32285
32286 @c @subheading -stack-list-exception-handlers
32287
32288
32289 @anchor{-stack-list-frames}
32290 @subheading The @code{-stack-list-frames} Command
32291 @findex -stack-list-frames
32292
32293 @subsubheading Synopsis
32294
32295 @smallexample
32296 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
32297 @end smallexample
32298
32299 List the frames currently on the stack. For each frame it displays the
32300 following info:
32301
32302 @table @samp
32303 @item @var{level}
32304 The frame number, 0 being the topmost frame, i.e., the innermost function.
32305 @item @var{addr}
32306 The @code{$pc} value for that frame.
32307 @item @var{func}
32308 Function name.
32309 @item @var{file}
32310 File name of the source file where the function lives.
32311 @item @var{fullname}
32312 The full file name of the source file where the function lives.
32313 @item @var{line}
32314 Line number corresponding to the @code{$pc}.
32315 @item @var{from}
32316 The shared library where this function is defined. This is only given
32317 if the frame's function is not known.
32318 @item @var{arch}
32319 Frame's architecture.
32320 @end table
32321
32322 If invoked without arguments, this command prints a backtrace for the
32323 whole stack. If given two integer arguments, it shows the frames whose
32324 levels are between the two arguments (inclusive). If the two arguments
32325 are equal, it shows the single frame at the corresponding level. It is
32326 an error if @var{low-frame} is larger than the actual number of
32327 frames. On the other hand, @var{high-frame} may be larger than the
32328 actual number of frames, in which case only existing frames will be
32329 returned. If the option @code{--no-frame-filters} is supplied, then
32330 Python frame filters will not be executed.
32331
32332 @subsubheading @value{GDBN} Command
32333
32334 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
32335
32336 @subsubheading Example
32337
32338 Full stack backtrace:
32339
32340 @smallexample
32341 (gdb)
32342 -stack-list-frames
32343 ^done,stack=
32344 [frame=@{level="0",addr="0x0001076c",func="foo",
32345 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
32346 arch="i386:x86_64"@},
32347 frame=@{level="1",addr="0x000107a4",func="foo",
32348 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32349 arch="i386:x86_64"@},
32350 frame=@{level="2",addr="0x000107a4",func="foo",
32351 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32352 arch="i386:x86_64"@},
32353 frame=@{level="3",addr="0x000107a4",func="foo",
32354 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32355 arch="i386:x86_64"@},
32356 frame=@{level="4",addr="0x000107a4",func="foo",
32357 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32358 arch="i386:x86_64"@},
32359 frame=@{level="5",addr="0x000107a4",func="foo",
32360 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32361 arch="i386:x86_64"@},
32362 frame=@{level="6",addr="0x000107a4",func="foo",
32363 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32364 arch="i386:x86_64"@},
32365 frame=@{level="7",addr="0x000107a4",func="foo",
32366 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32367 arch="i386:x86_64"@},
32368 frame=@{level="8",addr="0x000107a4",func="foo",
32369 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32370 arch="i386:x86_64"@},
32371 frame=@{level="9",addr="0x000107a4",func="foo",
32372 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32373 arch="i386:x86_64"@},
32374 frame=@{level="10",addr="0x000107a4",func="foo",
32375 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32376 arch="i386:x86_64"@},
32377 frame=@{level="11",addr="0x00010738",func="main",
32378 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
32379 arch="i386:x86_64"@}]
32380 (gdb)
32381 @end smallexample
32382
32383 Show frames between @var{low_frame} and @var{high_frame}:
32384
32385 @smallexample
32386 (gdb)
32387 -stack-list-frames 3 5
32388 ^done,stack=
32389 [frame=@{level="3",addr="0x000107a4",func="foo",
32390 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32391 arch="i386:x86_64"@},
32392 frame=@{level="4",addr="0x000107a4",func="foo",
32393 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32394 arch="i386:x86_64"@},
32395 frame=@{level="5",addr="0x000107a4",func="foo",
32396 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32397 arch="i386:x86_64"@}]
32398 (gdb)
32399 @end smallexample
32400
32401 Show a single frame:
32402
32403 @smallexample
32404 (gdb)
32405 -stack-list-frames 3 3
32406 ^done,stack=
32407 [frame=@{level="3",addr="0x000107a4",func="foo",
32408 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32409 arch="i386:x86_64"@}]
32410 (gdb)
32411 @end smallexample
32412
32413
32414 @subheading The @code{-stack-list-locals} Command
32415 @findex -stack-list-locals
32416 @anchor{-stack-list-locals}
32417
32418 @subsubheading Synopsis
32419
32420 @smallexample
32421 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32422 @end smallexample
32423
32424 Display the local variable names for the selected frame. If
32425 @var{print-values} is 0 or @code{--no-values}, print only the names of
32426 the variables; if it is 1 or @code{--all-values}, print also their
32427 values; and if it is 2 or @code{--simple-values}, print the name,
32428 type and value for simple data types, and the name and type for arrays,
32429 structures and unions. In this last case, a frontend can immediately
32430 display the value of simple data types and create variable objects for
32431 other data types when the user wishes to explore their values in
32432 more detail. If the option @code{--no-frame-filters} is supplied, then
32433 Python frame filters will not be executed.
32434
32435 If the @code{--skip-unavailable} option is specified, local variables
32436 that are not available are not listed. Partially available local
32437 variables are still displayed, however.
32438
32439 This command is deprecated in favor of the
32440 @samp{-stack-list-variables} command.
32441
32442 @subsubheading @value{GDBN} Command
32443
32444 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
32445
32446 @subsubheading Example
32447
32448 @smallexample
32449 (gdb)
32450 -stack-list-locals 0
32451 ^done,locals=[name="A",name="B",name="C"]
32452 (gdb)
32453 -stack-list-locals --all-values
32454 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
32455 @{name="C",value="@{1, 2, 3@}"@}]
32456 -stack-list-locals --simple-values
32457 ^done,locals=[@{name="A",type="int",value="1"@},
32458 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
32459 (gdb)
32460 @end smallexample
32461
32462 @anchor{-stack-list-variables}
32463 @subheading The @code{-stack-list-variables} Command
32464 @findex -stack-list-variables
32465
32466 @subsubheading Synopsis
32467
32468 @smallexample
32469 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32470 @end smallexample
32471
32472 Display the names of local variables and function arguments for the selected frame. If
32473 @var{print-values} is 0 or @code{--no-values}, print only the names of
32474 the variables; if it is 1 or @code{--all-values}, print also their
32475 values; and if it is 2 or @code{--simple-values}, print the name,
32476 type and value for simple data types, and the name and type for arrays,
32477 structures and unions. If the option @code{--no-frame-filters} is
32478 supplied, then Python frame filters will not be executed.
32479
32480 If the @code{--skip-unavailable} option is specified, local variables
32481 and arguments that are not available are not listed. Partially
32482 available arguments and local variables are still displayed, however.
32483
32484 @subsubheading Example
32485
32486 @smallexample
32487 (gdb)
32488 -stack-list-variables --thread 1 --frame 0 --all-values
32489 ^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
32490 (gdb)
32491 @end smallexample
32492
32493
32494 @subheading The @code{-stack-select-frame} Command
32495 @findex -stack-select-frame
32496
32497 @subsubheading Synopsis
32498
32499 @smallexample
32500 -stack-select-frame @var{framenum}
32501 @end smallexample
32502
32503 Change the selected frame. Select a different frame @var{framenum} on
32504 the stack.
32505
32506 This command in deprecated in favor of passing the @samp{--frame}
32507 option to every command.
32508
32509 @subsubheading @value{GDBN} Command
32510
32511 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
32512 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
32513
32514 @subsubheading Example
32515
32516 @smallexample
32517 (gdb)
32518 -stack-select-frame 2
32519 ^done
32520 (gdb)
32521 @end smallexample
32522
32523 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32524 @node GDB/MI Variable Objects
32525 @section @sc{gdb/mi} Variable Objects
32526
32527 @ignore
32528
32529 @subheading Motivation for Variable Objects in @sc{gdb/mi}
32530
32531 For the implementation of a variable debugger window (locals, watched
32532 expressions, etc.), we are proposing the adaptation of the existing code
32533 used by @code{Insight}.
32534
32535 The two main reasons for that are:
32536
32537 @enumerate 1
32538 @item
32539 It has been proven in practice (it is already on its second generation).
32540
32541 @item
32542 It will shorten development time (needless to say how important it is
32543 now).
32544 @end enumerate
32545
32546 The original interface was designed to be used by Tcl code, so it was
32547 slightly changed so it could be used through @sc{gdb/mi}. This section
32548 describes the @sc{gdb/mi} operations that will be available and gives some
32549 hints about their use.
32550
32551 @emph{Note}: In addition to the set of operations described here, we
32552 expect the @sc{gui} implementation of a variable window to require, at
32553 least, the following operations:
32554
32555 @itemize @bullet
32556 @item @code{-gdb-show} @code{output-radix}
32557 @item @code{-stack-list-arguments}
32558 @item @code{-stack-list-locals}
32559 @item @code{-stack-select-frame}
32560 @end itemize
32561
32562 @end ignore
32563
32564 @subheading Introduction to Variable Objects
32565
32566 @cindex variable objects in @sc{gdb/mi}
32567
32568 Variable objects are "object-oriented" MI interface for examining and
32569 changing values of expressions. Unlike some other MI interfaces that
32570 work with expressions, variable objects are specifically designed for
32571 simple and efficient presentation in the frontend. A variable object
32572 is identified by string name. When a variable object is created, the
32573 frontend specifies the expression for that variable object. The
32574 expression can be a simple variable, or it can be an arbitrary complex
32575 expression, and can even involve CPU registers. After creating a
32576 variable object, the frontend can invoke other variable object
32577 operations---for example to obtain or change the value of a variable
32578 object, or to change display format.
32579
32580 Variable objects have hierarchical tree structure. Any variable object
32581 that corresponds to a composite type, such as structure in C, has
32582 a number of child variable objects, for example corresponding to each
32583 element of a structure. A child variable object can itself have
32584 children, recursively. Recursion ends when we reach
32585 leaf variable objects, which always have built-in types. Child variable
32586 objects are created only by explicit request, so if a frontend
32587 is not interested in the children of a particular variable object, no
32588 child will be created.
32589
32590 For a leaf variable object it is possible to obtain its value as a
32591 string, or set the value from a string. String value can be also
32592 obtained for a non-leaf variable object, but it's generally a string
32593 that only indicates the type of the object, and does not list its
32594 contents. Assignment to a non-leaf variable object is not allowed.
32595
32596 A frontend does not need to read the values of all variable objects each time
32597 the program stops. Instead, MI provides an update command that lists all
32598 variable objects whose values has changed since the last update
32599 operation. This considerably reduces the amount of data that must
32600 be transferred to the frontend. As noted above, children variable
32601 objects are created on demand, and only leaf variable objects have a
32602 real value. As result, gdb will read target memory only for leaf
32603 variables that frontend has created.
32604
32605 The automatic update is not always desirable. For example, a frontend
32606 might want to keep a value of some expression for future reference,
32607 and never update it. For another example, fetching memory is
32608 relatively slow for embedded targets, so a frontend might want
32609 to disable automatic update for the variables that are either not
32610 visible on the screen, or ``closed''. This is possible using so
32611 called ``frozen variable objects''. Such variable objects are never
32612 implicitly updated.
32613
32614 Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
32615 fixed variable object, the expression is parsed when the variable
32616 object is created, including associating identifiers to specific
32617 variables. The meaning of expression never changes. For a floating
32618 variable object the values of variables whose names appear in the
32619 expressions are re-evaluated every time in the context of the current
32620 frame. Consider this example:
32621
32622 @smallexample
32623 void do_work(...)
32624 @{
32625 struct work_state state;
32626
32627 if (...)
32628 do_work(...);
32629 @}
32630 @end smallexample
32631
32632 If a fixed variable object for the @code{state} variable is created in
32633 this function, and we enter the recursive call, the variable
32634 object will report the value of @code{state} in the top-level
32635 @code{do_work} invocation. On the other hand, a floating variable
32636 object will report the value of @code{state} in the current frame.
32637
32638 If an expression specified when creating a fixed variable object
32639 refers to a local variable, the variable object becomes bound to the
32640 thread and frame in which the variable object is created. When such
32641 variable object is updated, @value{GDBN} makes sure that the
32642 thread/frame combination the variable object is bound to still exists,
32643 and re-evaluates the variable object in context of that thread/frame.
32644
32645 The following is the complete set of @sc{gdb/mi} operations defined to
32646 access this functionality:
32647
32648 @multitable @columnfractions .4 .6
32649 @item @strong{Operation}
32650 @tab @strong{Description}
32651
32652 @item @code{-enable-pretty-printing}
32653 @tab enable Python-based pretty-printing
32654 @item @code{-var-create}
32655 @tab create a variable object
32656 @item @code{-var-delete}
32657 @tab delete the variable object and/or its children
32658 @item @code{-var-set-format}
32659 @tab set the display format of this variable
32660 @item @code{-var-show-format}
32661 @tab show the display format of this variable
32662 @item @code{-var-info-num-children}
32663 @tab tells how many children this object has
32664 @item @code{-var-list-children}
32665 @tab return a list of the object's children
32666 @item @code{-var-info-type}
32667 @tab show the type of this variable object
32668 @item @code{-var-info-expression}
32669 @tab print parent-relative expression that this variable object represents
32670 @item @code{-var-info-path-expression}
32671 @tab print full expression that this variable object represents
32672 @item @code{-var-show-attributes}
32673 @tab is this variable editable? does it exist here?
32674 @item @code{-var-evaluate-expression}
32675 @tab get the value of this variable
32676 @item @code{-var-assign}
32677 @tab set the value of this variable
32678 @item @code{-var-update}
32679 @tab update the variable and its children
32680 @item @code{-var-set-frozen}
32681 @tab set frozenness attribute
32682 @item @code{-var-set-update-range}
32683 @tab set range of children to display on update
32684 @end multitable
32685
32686 In the next subsection we describe each operation in detail and suggest
32687 how it can be used.
32688
32689 @subheading Description And Use of Operations on Variable Objects
32690
32691 @subheading The @code{-enable-pretty-printing} Command
32692 @findex -enable-pretty-printing
32693
32694 @smallexample
32695 -enable-pretty-printing
32696 @end smallexample
32697
32698 @value{GDBN} allows Python-based visualizers to affect the output of the
32699 MI variable object commands. However, because there was no way to
32700 implement this in a fully backward-compatible way, a front end must
32701 request that this functionality be enabled.
32702
32703 Once enabled, this feature cannot be disabled.
32704
32705 Note that if Python support has not been compiled into @value{GDBN},
32706 this command will still succeed (and do nothing).
32707
32708 This feature is currently (as of @value{GDBN} 7.0) experimental, and
32709 may work differently in future versions of @value{GDBN}.
32710
32711 @subheading The @code{-var-create} Command
32712 @findex -var-create
32713
32714 @subsubheading Synopsis
32715
32716 @smallexample
32717 -var-create @{@var{name} | "-"@}
32718 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
32719 @end smallexample
32720
32721 This operation creates a variable object, which allows the monitoring of
32722 a variable, the result of an expression, a memory cell or a CPU
32723 register.
32724
32725 The @var{name} parameter is the string by which the object can be
32726 referenced. It must be unique. If @samp{-} is specified, the varobj
32727 system will generate a string ``varNNNNNN'' automatically. It will be
32728 unique provided that one does not specify @var{name} of that format.
32729 The command fails if a duplicate name is found.
32730
32731 The frame under which the expression should be evaluated can be
32732 specified by @var{frame-addr}. A @samp{*} indicates that the current
32733 frame should be used. A @samp{@@} indicates that a floating variable
32734 object must be created.
32735
32736 @var{expression} is any expression valid on the current language set (must not
32737 begin with a @samp{*}), or one of the following:
32738
32739 @itemize @bullet
32740 @item
32741 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
32742
32743 @item
32744 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
32745
32746 @item
32747 @samp{$@var{regname}} --- a CPU register name
32748 @end itemize
32749
32750 @cindex dynamic varobj
32751 A varobj's contents may be provided by a Python-based pretty-printer. In this
32752 case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
32753 have slightly different semantics in some cases. If the
32754 @code{-enable-pretty-printing} command is not sent, then @value{GDBN}
32755 will never create a dynamic varobj. This ensures backward
32756 compatibility for existing clients.
32757
32758 @subsubheading Result
32759
32760 This operation returns attributes of the newly-created varobj. These
32761 are:
32762
32763 @table @samp
32764 @item name
32765 The name of the varobj.
32766
32767 @item numchild
32768 The number of children of the varobj. This number is not necessarily
32769 reliable for a dynamic varobj. Instead, you must examine the
32770 @samp{has_more} attribute.
32771
32772 @item value
32773 The varobj's scalar value. For a varobj whose type is some sort of
32774 aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
32775 will not be interesting.
32776
32777 @item type
32778 The varobj's type. This is a string representation of the type, as
32779 would be printed by the @value{GDBN} CLI. If @samp{print object}
32780 (@pxref{Print Settings, set print object}) is set to @code{on}, the
32781 @emph{actual} (derived) type of the object is shown rather than the
32782 @emph{declared} one.
32783
32784 @item thread-id
32785 If a variable object is bound to a specific thread, then this is the
32786 thread's global identifier.
32787
32788 @item has_more
32789 For a dynamic varobj, this indicates whether there appear to be any
32790 children available. For a non-dynamic varobj, this will be 0.
32791
32792 @item dynamic
32793 This attribute will be present and have the value @samp{1} if the
32794 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32795 then this attribute will not be present.
32796
32797 @item displayhint
32798 A dynamic varobj can supply a display hint to the front end. The
32799 value comes directly from the Python pretty-printer object's
32800 @code{display_hint} method. @xref{Pretty Printing API}.
32801 @end table
32802
32803 Typical output will look like this:
32804
32805 @smallexample
32806 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
32807 has_more="@var{has_more}"
32808 @end smallexample
32809
32810
32811 @subheading The @code{-var-delete} Command
32812 @findex -var-delete
32813
32814 @subsubheading Synopsis
32815
32816 @smallexample
32817 -var-delete [ -c ] @var{name}
32818 @end smallexample
32819
32820 Deletes a previously created variable object and all of its children.
32821 With the @samp{-c} option, just deletes the children.
32822
32823 Returns an error if the object @var{name} is not found.
32824
32825
32826 @subheading The @code{-var-set-format} Command
32827 @findex -var-set-format
32828
32829 @subsubheading Synopsis
32830
32831 @smallexample
32832 -var-set-format @var{name} @var{format-spec}
32833 @end smallexample
32834
32835 Sets the output format for the value of the object @var{name} to be
32836 @var{format-spec}.
32837
32838 @anchor{-var-set-format}
32839 The syntax for the @var{format-spec} is as follows:
32840
32841 @smallexample
32842 @var{format-spec} @expansion{}
32843 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
32844 @end smallexample
32845
32846 The natural format is the default format choosen automatically
32847 based on the variable type (like decimal for an @code{int}, hex
32848 for pointers, etc.).
32849
32850 The zero-hexadecimal format has a representation similar to hexadecimal
32851 but with padding zeroes to the left of the value. For example, a 32-bit
32852 hexadecimal value of 0x1234 would be represented as 0x00001234 in the
32853 zero-hexadecimal format.
32854
32855 For a variable with children, the format is set only on the
32856 variable itself, and the children are not affected.
32857
32858 @subheading The @code{-var-show-format} Command
32859 @findex -var-show-format
32860
32861 @subsubheading Synopsis
32862
32863 @smallexample
32864 -var-show-format @var{name}
32865 @end smallexample
32866
32867 Returns the format used to display the value of the object @var{name}.
32868
32869 @smallexample
32870 @var{format} @expansion{}
32871 @var{format-spec}
32872 @end smallexample
32873
32874
32875 @subheading The @code{-var-info-num-children} Command
32876 @findex -var-info-num-children
32877
32878 @subsubheading Synopsis
32879
32880 @smallexample
32881 -var-info-num-children @var{name}
32882 @end smallexample
32883
32884 Returns the number of children of a variable object @var{name}:
32885
32886 @smallexample
32887 numchild=@var{n}
32888 @end smallexample
32889
32890 Note that this number is not completely reliable for a dynamic varobj.
32891 It will return the current number of children, but more children may
32892 be available.
32893
32894
32895 @subheading The @code{-var-list-children} Command
32896 @findex -var-list-children
32897
32898 @subsubheading Synopsis
32899
32900 @smallexample
32901 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
32902 @end smallexample
32903 @anchor{-var-list-children}
32904
32905 Return a list of the children of the specified variable object and
32906 create variable objects for them, if they do not already exist. With
32907 a single argument or if @var{print-values} has a value of 0 or
32908 @code{--no-values}, print only the names of the variables; if
32909 @var{print-values} is 1 or @code{--all-values}, also print their
32910 values; and if it is 2 or @code{--simple-values} print the name and
32911 value for simple data types and just the name for arrays, structures
32912 and unions.
32913
32914 @var{from} and @var{to}, if specified, indicate the range of children
32915 to report. If @var{from} or @var{to} is less than zero, the range is
32916 reset and all children will be reported. Otherwise, children starting
32917 at @var{from} (zero-based) and up to and excluding @var{to} will be
32918 reported.
32919
32920 If a child range is requested, it will only affect the current call to
32921 @code{-var-list-children}, but not future calls to @code{-var-update}.
32922 For this, you must instead use @code{-var-set-update-range}. The
32923 intent of this approach is to enable a front end to implement any
32924 update approach it likes; for example, scrolling a view may cause the
32925 front end to request more children with @code{-var-list-children}, and
32926 then the front end could call @code{-var-set-update-range} with a
32927 different range to ensure that future updates are restricted to just
32928 the visible items.
32929
32930 For each child the following results are returned:
32931
32932 @table @var
32933
32934 @item name
32935 Name of the variable object created for this child.
32936
32937 @item exp
32938 The expression to be shown to the user by the front end to designate this child.
32939 For example this may be the name of a structure member.
32940
32941 For a dynamic varobj, this value cannot be used to form an
32942 expression. There is no way to do this at all with a dynamic varobj.
32943
32944 For C/C@t{++} structures there are several pseudo children returned to
32945 designate access qualifiers. For these pseudo children @var{exp} is
32946 @samp{public}, @samp{private}, or @samp{protected}. In this case the
32947 type and value are not present.
32948
32949 A dynamic varobj will not report the access qualifying
32950 pseudo-children, regardless of the language. This information is not
32951 available at all with a dynamic varobj.
32952
32953 @item numchild
32954 Number of children this child has. For a dynamic varobj, this will be
32955 0.
32956
32957 @item type
32958 The type of the child. If @samp{print object}
32959 (@pxref{Print Settings, set print object}) is set to @code{on}, the
32960 @emph{actual} (derived) type of the object is shown rather than the
32961 @emph{declared} one.
32962
32963 @item value
32964 If values were requested, this is the value.
32965
32966 @item thread-id
32967 If this variable object is associated with a thread, this is the
32968 thread's global thread id. Otherwise this result is not present.
32969
32970 @item frozen
32971 If the variable object is frozen, this variable will be present with a value of 1.
32972
32973 @item displayhint
32974 A dynamic varobj can supply a display hint to the front end. The
32975 value comes directly from the Python pretty-printer object's
32976 @code{display_hint} method. @xref{Pretty Printing API}.
32977
32978 @item dynamic
32979 This attribute will be present and have the value @samp{1} if the
32980 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32981 then this attribute will not be present.
32982
32983 @end table
32984
32985 The result may have its own attributes:
32986
32987 @table @samp
32988 @item displayhint
32989 A dynamic varobj can supply a display hint to the front end. The
32990 value comes directly from the Python pretty-printer object's
32991 @code{display_hint} method. @xref{Pretty Printing API}.
32992
32993 @item has_more
32994 This is an integer attribute which is nonzero if there are children
32995 remaining after the end of the selected range.
32996 @end table
32997
32998 @subsubheading Example
32999
33000 @smallexample
33001 (gdb)
33002 -var-list-children n
33003 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
33004 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
33005 (gdb)
33006 -var-list-children --all-values n
33007 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
33008 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
33009 @end smallexample
33010
33011
33012 @subheading The @code{-var-info-type} Command
33013 @findex -var-info-type
33014
33015 @subsubheading Synopsis
33016
33017 @smallexample
33018 -var-info-type @var{name}
33019 @end smallexample
33020
33021 Returns the type of the specified variable @var{name}. The type is
33022 returned as a string in the same format as it is output by the
33023 @value{GDBN} CLI:
33024
33025 @smallexample
33026 type=@var{typename}
33027 @end smallexample
33028
33029
33030 @subheading The @code{-var-info-expression} Command
33031 @findex -var-info-expression
33032
33033 @subsubheading Synopsis
33034
33035 @smallexample
33036 -var-info-expression @var{name}
33037 @end smallexample
33038
33039 Returns a string that is suitable for presenting this
33040 variable object in user interface. The string is generally
33041 not valid expression in the current language, and cannot be evaluated.
33042
33043 For example, if @code{a} is an array, and variable object
33044 @code{A} was created for @code{a}, then we'll get this output:
33045
33046 @smallexample
33047 (gdb) -var-info-expression A.1
33048 ^done,lang="C",exp="1"
33049 @end smallexample
33050
33051 @noindent
33052 Here, the value of @code{lang} is the language name, which can be
33053 found in @ref{Supported Languages}.
33054
33055 Note that the output of the @code{-var-list-children} command also
33056 includes those expressions, so the @code{-var-info-expression} command
33057 is of limited use.
33058
33059 @subheading The @code{-var-info-path-expression} Command
33060 @findex -var-info-path-expression
33061
33062 @subsubheading Synopsis
33063
33064 @smallexample
33065 -var-info-path-expression @var{name}
33066 @end smallexample
33067
33068 Returns an expression that can be evaluated in the current
33069 context and will yield the same value that a variable object has.
33070 Compare this with the @code{-var-info-expression} command, which
33071 result can be used only for UI presentation. Typical use of
33072 the @code{-var-info-path-expression} command is creating a
33073 watchpoint from a variable object.
33074
33075 This command is currently not valid for children of a dynamic varobj,
33076 and will give an error when invoked on one.
33077
33078 For example, suppose @code{C} is a C@t{++} class, derived from class
33079 @code{Base}, and that the @code{Base} class has a member called
33080 @code{m_size}. Assume a variable @code{c} is has the type of
33081 @code{C} and a variable object @code{C} was created for variable
33082 @code{c}. Then, we'll get this output:
33083 @smallexample
33084 (gdb) -var-info-path-expression C.Base.public.m_size
33085 ^done,path_expr=((Base)c).m_size)
33086 @end smallexample
33087
33088 @subheading The @code{-var-show-attributes} Command
33089 @findex -var-show-attributes
33090
33091 @subsubheading Synopsis
33092
33093 @smallexample
33094 -var-show-attributes @var{name}
33095 @end smallexample
33096
33097 List attributes of the specified variable object @var{name}:
33098
33099 @smallexample
33100 status=@var{attr} [ ( ,@var{attr} )* ]
33101 @end smallexample
33102
33103 @noindent
33104 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
33105
33106 @subheading The @code{-var-evaluate-expression} Command
33107 @findex -var-evaluate-expression
33108
33109 @subsubheading Synopsis
33110
33111 @smallexample
33112 -var-evaluate-expression [-f @var{format-spec}] @var{name}
33113 @end smallexample
33114
33115 Evaluates the expression that is represented by the specified variable
33116 object and returns its value as a string. The format of the string
33117 can be specified with the @samp{-f} option. The possible values of
33118 this option are the same as for @code{-var-set-format}
33119 (@pxref{-var-set-format}). If the @samp{-f} option is not specified,
33120 the current display format will be used. The current display format
33121 can be changed using the @code{-var-set-format} command.
33122
33123 @smallexample
33124 value=@var{value}
33125 @end smallexample
33126
33127 Note that one must invoke @code{-var-list-children} for a variable
33128 before the value of a child variable can be evaluated.
33129
33130 @subheading The @code{-var-assign} Command
33131 @findex -var-assign
33132
33133 @subsubheading Synopsis
33134
33135 @smallexample
33136 -var-assign @var{name} @var{expression}
33137 @end smallexample
33138
33139 Assigns the value of @var{expression} to the variable object specified
33140 by @var{name}. The object must be @samp{editable}. If the variable's
33141 value is altered by the assign, the variable will show up in any
33142 subsequent @code{-var-update} list.
33143
33144 @subsubheading Example
33145
33146 @smallexample
33147 (gdb)
33148 -var-assign var1 3
33149 ^done,value="3"
33150 (gdb)
33151 -var-update *
33152 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
33153 (gdb)
33154 @end smallexample
33155
33156 @subheading The @code{-var-update} Command
33157 @findex -var-update
33158
33159 @subsubheading Synopsis
33160
33161 @smallexample
33162 -var-update [@var{print-values}] @{@var{name} | "*"@}
33163 @end smallexample
33164
33165 Reevaluate the expressions corresponding to the variable object
33166 @var{name} and all its direct and indirect children, and return the
33167 list of variable objects whose values have changed; @var{name} must
33168 be a root variable object. Here, ``changed'' means that the result of
33169 @code{-var-evaluate-expression} before and after the
33170 @code{-var-update} is different. If @samp{*} is used as the variable
33171 object names, all existing variable objects are updated, except
33172 for frozen ones (@pxref{-var-set-frozen}). The option
33173 @var{print-values} determines whether both names and values, or just
33174 names are printed. The possible values of this option are the same
33175 as for @code{-var-list-children} (@pxref{-var-list-children}). It is
33176 recommended to use the @samp{--all-values} option, to reduce the
33177 number of MI commands needed on each program stop.
33178
33179 With the @samp{*} parameter, if a variable object is bound to a
33180 currently running thread, it will not be updated, without any
33181 diagnostic.
33182
33183 If @code{-var-set-update-range} was previously used on a varobj, then
33184 only the selected range of children will be reported.
33185
33186 @code{-var-update} reports all the changed varobjs in a tuple named
33187 @samp{changelist}.
33188
33189 Each item in the change list is itself a tuple holding:
33190
33191 @table @samp
33192 @item name
33193 The name of the varobj.
33194
33195 @item value
33196 If values were requested for this update, then this field will be
33197 present and will hold the value of the varobj.
33198
33199 @item in_scope
33200 @anchor{-var-update}
33201 This field is a string which may take one of three values:
33202
33203 @table @code
33204 @item "true"
33205 The variable object's current value is valid.
33206
33207 @item "false"
33208 The variable object does not currently hold a valid value but it may
33209 hold one in the future if its associated expression comes back into
33210 scope.
33211
33212 @item "invalid"
33213 The variable object no longer holds a valid value.
33214 This can occur when the executable file being debugged has changed,
33215 either through recompilation or by using the @value{GDBN} @code{file}
33216 command. The front end should normally choose to delete these variable
33217 objects.
33218 @end table
33219
33220 In the future new values may be added to this list so the front should
33221 be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
33222
33223 @item type_changed
33224 This is only present if the varobj is still valid. If the type
33225 changed, then this will be the string @samp{true}; otherwise it will
33226 be @samp{false}.
33227
33228 When a varobj's type changes, its children are also likely to have
33229 become incorrect. Therefore, the varobj's children are automatically
33230 deleted when this attribute is @samp{true}. Also, the varobj's update
33231 range, when set using the @code{-var-set-update-range} command, is
33232 unset.
33233
33234 @item new_type
33235 If the varobj's type changed, then this field will be present and will
33236 hold the new type.
33237
33238 @item new_num_children
33239 For a dynamic varobj, if the number of children changed, or if the
33240 type changed, this will be the new number of children.
33241
33242 The @samp{numchild} field in other varobj responses is generally not
33243 valid for a dynamic varobj -- it will show the number of children that
33244 @value{GDBN} knows about, but because dynamic varobjs lazily
33245 instantiate their children, this will not reflect the number of
33246 children which may be available.
33247
33248 The @samp{new_num_children} attribute only reports changes to the
33249 number of children known by @value{GDBN}. This is the only way to
33250 detect whether an update has removed children (which necessarily can
33251 only happen at the end of the update range).
33252
33253 @item displayhint
33254 The display hint, if any.
33255
33256 @item has_more
33257 This is an integer value, which will be 1 if there are more children
33258 available outside the varobj's update range.
33259
33260 @item dynamic
33261 This attribute will be present and have the value @samp{1} if the
33262 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33263 then this attribute will not be present.
33264
33265 @item new_children
33266 If new children were added to a dynamic varobj within the selected
33267 update range (as set by @code{-var-set-update-range}), then they will
33268 be listed in this attribute.
33269 @end table
33270
33271 @subsubheading Example
33272
33273 @smallexample
33274 (gdb)
33275 -var-assign var1 3
33276 ^done,value="3"
33277 (gdb)
33278 -var-update --all-values var1
33279 ^done,changelist=[@{name="var1",value="3",in_scope="true",
33280 type_changed="false"@}]
33281 (gdb)
33282 @end smallexample
33283
33284 @subheading The @code{-var-set-frozen} Command
33285 @findex -var-set-frozen
33286 @anchor{-var-set-frozen}
33287
33288 @subsubheading Synopsis
33289
33290 @smallexample
33291 -var-set-frozen @var{name} @var{flag}
33292 @end smallexample
33293
33294 Set the frozenness flag on the variable object @var{name}. The
33295 @var{flag} parameter should be either @samp{1} to make the variable
33296 frozen or @samp{0} to make it unfrozen. If a variable object is
33297 frozen, then neither itself, nor any of its children, are
33298 implicitly updated by @code{-var-update} of
33299 a parent variable or by @code{-var-update *}. Only
33300 @code{-var-update} of the variable itself will update its value and
33301 values of its children. After a variable object is unfrozen, it is
33302 implicitly updated by all subsequent @code{-var-update} operations.
33303 Unfreezing a variable does not update it, only subsequent
33304 @code{-var-update} does.
33305
33306 @subsubheading Example
33307
33308 @smallexample
33309 (gdb)
33310 -var-set-frozen V 1
33311 ^done
33312 (gdb)
33313 @end smallexample
33314
33315 @subheading The @code{-var-set-update-range} command
33316 @findex -var-set-update-range
33317 @anchor{-var-set-update-range}
33318
33319 @subsubheading Synopsis
33320
33321 @smallexample
33322 -var-set-update-range @var{name} @var{from} @var{to}
33323 @end smallexample
33324
33325 Set the range of children to be returned by future invocations of
33326 @code{-var-update}.
33327
33328 @var{from} and @var{to} indicate the range of children to report. If
33329 @var{from} or @var{to} is less than zero, the range is reset and all
33330 children will be reported. Otherwise, children starting at @var{from}
33331 (zero-based) and up to and excluding @var{to} will be reported.
33332
33333 @subsubheading Example
33334
33335 @smallexample
33336 (gdb)
33337 -var-set-update-range V 1 2
33338 ^done
33339 @end smallexample
33340
33341 @subheading The @code{-var-set-visualizer} command
33342 @findex -var-set-visualizer
33343 @anchor{-var-set-visualizer}
33344
33345 @subsubheading Synopsis
33346
33347 @smallexample
33348 -var-set-visualizer @var{name} @var{visualizer}
33349 @end smallexample
33350
33351 Set a visualizer for the variable object @var{name}.
33352
33353 @var{visualizer} is the visualizer to use. The special value
33354 @samp{None} means to disable any visualizer in use.
33355
33356 If not @samp{None}, @var{visualizer} must be a Python expression.
33357 This expression must evaluate to a callable object which accepts a
33358 single argument. @value{GDBN} will call this object with the value of
33359 the varobj @var{name} as an argument (this is done so that the same
33360 Python pretty-printing code can be used for both the CLI and MI).
33361 When called, this object must return an object which conforms to the
33362 pretty-printing interface (@pxref{Pretty Printing API}).
33363
33364 The pre-defined function @code{gdb.default_visualizer} may be used to
33365 select a visualizer by following the built-in process
33366 (@pxref{Selecting Pretty-Printers}). This is done automatically when
33367 a varobj is created, and so ordinarily is not needed.
33368
33369 This feature is only available if Python support is enabled. The MI
33370 command @code{-list-features} (@pxref{GDB/MI Support Commands})
33371 can be used to check this.
33372
33373 @subsubheading Example
33374
33375 Resetting the visualizer:
33376
33377 @smallexample
33378 (gdb)
33379 -var-set-visualizer V None
33380 ^done
33381 @end smallexample
33382
33383 Reselecting the default (type-based) visualizer:
33384
33385 @smallexample
33386 (gdb)
33387 -var-set-visualizer V gdb.default_visualizer
33388 ^done
33389 @end smallexample
33390
33391 Suppose @code{SomeClass} is a visualizer class. A lambda expression
33392 can be used to instantiate this class for a varobj:
33393
33394 @smallexample
33395 (gdb)
33396 -var-set-visualizer V "lambda val: SomeClass()"
33397 ^done
33398 @end smallexample
33399
33400 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33401 @node GDB/MI Data Manipulation
33402 @section @sc{gdb/mi} Data Manipulation
33403
33404 @cindex data manipulation, in @sc{gdb/mi}
33405 @cindex @sc{gdb/mi}, data manipulation
33406 This section describes the @sc{gdb/mi} commands that manipulate data:
33407 examine memory and registers, evaluate expressions, etc.
33408
33409 For details about what an addressable memory unit is,
33410 @pxref{addressable memory unit}.
33411
33412 @c REMOVED FROM THE INTERFACE.
33413 @c @subheading -data-assign
33414 @c Change the value of a program variable. Plenty of side effects.
33415 @c @subsubheading GDB Command
33416 @c set variable
33417 @c @subsubheading Example
33418 @c N.A.
33419
33420 @subheading The @code{-data-disassemble} Command
33421 @findex -data-disassemble
33422
33423 @subsubheading Synopsis
33424
33425 @smallexample
33426 -data-disassemble
33427 [ -s @var{start-addr} -e @var{end-addr} ]
33428 | [ -a @var{addr} ]
33429 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
33430 -- @var{mode}
33431 @end smallexample
33432
33433 @noindent
33434 Where:
33435
33436 @table @samp
33437 @item @var{start-addr}
33438 is the beginning address (or @code{$pc})
33439 @item @var{end-addr}
33440 is the end address
33441 @item @var{addr}
33442 is an address anywhere within (or the name of) the function to
33443 disassemble. If an address is specified, the whole function
33444 surrounding that address will be disassembled. If a name is
33445 specified, the whole function with that name will be disassembled.
33446 @item @var{filename}
33447 is the name of the file to disassemble
33448 @item @var{linenum}
33449 is the line number to disassemble around
33450 @item @var{lines}
33451 is the number of disassembly lines to be produced. If it is -1,
33452 the whole function will be disassembled, in case no @var{end-addr} is
33453 specified. If @var{end-addr} is specified as a non-zero value, and
33454 @var{lines} is lower than the number of disassembly lines between
33455 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
33456 displayed; if @var{lines} is higher than the number of lines between
33457 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
33458 are displayed.
33459 @item @var{mode}
33460 is one of:
33461 @itemize @bullet
33462 @item 0 disassembly only
33463 @item 1 mixed source and disassembly (deprecated)
33464 @item 2 disassembly with raw opcodes
33465 @item 3 mixed source and disassembly with raw opcodes (deprecated)
33466 @item 4 mixed source and disassembly
33467 @item 5 mixed source and disassembly with raw opcodes
33468 @end itemize
33469
33470 Modes 1 and 3 are deprecated. The output is ``source centric''
33471 which hasn't proved useful in practice.
33472 @xref{Machine Code}, for a discussion of the difference between
33473 @code{/m} and @code{/s} output of the @code{disassemble} command.
33474 @end table
33475
33476 @subsubheading Result
33477
33478 The result of the @code{-data-disassemble} command will be a list named
33479 @samp{asm_insns}, the contents of this list depend on the @var{mode}
33480 used with the @code{-data-disassemble} command.
33481
33482 For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
33483 following fields:
33484
33485 @table @code
33486 @item address
33487 The address at which this instruction was disassembled.
33488
33489 @item func-name
33490 The name of the function this instruction is within.
33491
33492 @item offset
33493 The decimal offset in bytes from the start of @samp{func-name}.
33494
33495 @item inst
33496 The text disassembly for this @samp{address}.
33497
33498 @item opcodes
33499 This field is only present for modes 2, 3 and 5. This contains the raw opcode
33500 bytes for the @samp{inst} field.
33501
33502 @end table
33503
33504 For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
33505 @samp{src_and_asm_line}, each of which has the following fields:
33506
33507 @table @code
33508 @item line
33509 The line number within @samp{file}.
33510
33511 @item file
33512 The file name from the compilation unit. This might be an absolute
33513 file name or a relative file name depending on the compile command
33514 used.
33515
33516 @item fullname
33517 Absolute file name of @samp{file}. It is converted to a canonical form
33518 using the source file search path
33519 (@pxref{Source Path, ,Specifying Source Directories})
33520 and after resolving all the symbolic links.
33521
33522 If the source file is not found this field will contain the path as
33523 present in the debug information.
33524
33525 @item line_asm_insn
33526 This is a list of tuples containing the disassembly for @samp{line} in
33527 @samp{file}. The fields of each tuple are the same as for
33528 @code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
33529 @samp{func-name}, @samp{offset}, @samp{inst}, and optionally
33530 @samp{opcodes}.
33531
33532 @end table
33533
33534 Note that whatever included in the @samp{inst} field, is not
33535 manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
33536 adjust its format.
33537
33538 @subsubheading @value{GDBN} Command
33539
33540 The corresponding @value{GDBN} command is @samp{disassemble}.
33541
33542 @subsubheading Example
33543
33544 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
33545
33546 @smallexample
33547 (gdb)
33548 -data-disassemble -s $pc -e "$pc + 20" -- 0
33549 ^done,
33550 asm_insns=[
33551 @{address="0x000107c0",func-name="main",offset="4",
33552 inst="mov 2, %o0"@},
33553 @{address="0x000107c4",func-name="main",offset="8",
33554 inst="sethi %hi(0x11800), %o2"@},
33555 @{address="0x000107c8",func-name="main",offset="12",
33556 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
33557 @{address="0x000107cc",func-name="main",offset="16",
33558 inst="sethi %hi(0x11800), %o2"@},
33559 @{address="0x000107d0",func-name="main",offset="20",
33560 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
33561 (gdb)
33562 @end smallexample
33563
33564 Disassemble the whole @code{main} function. Line 32 is part of
33565 @code{main}.
33566
33567 @smallexample
33568 -data-disassemble -f basics.c -l 32 -- 0
33569 ^done,asm_insns=[
33570 @{address="0x000107bc",func-name="main",offset="0",
33571 inst="save %sp, -112, %sp"@},
33572 @{address="0x000107c0",func-name="main",offset="4",
33573 inst="mov 2, %o0"@},
33574 @{address="0x000107c4",func-name="main",offset="8",
33575 inst="sethi %hi(0x11800), %o2"@},
33576 [@dots{}]
33577 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
33578 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
33579 (gdb)
33580 @end smallexample
33581
33582 Disassemble 3 instructions from the start of @code{main}:
33583
33584 @smallexample
33585 (gdb)
33586 -data-disassemble -f basics.c -l 32 -n 3 -- 0
33587 ^done,asm_insns=[
33588 @{address="0x000107bc",func-name="main",offset="0",
33589 inst="save %sp, -112, %sp"@},
33590 @{address="0x000107c0",func-name="main",offset="4",
33591 inst="mov 2, %o0"@},
33592 @{address="0x000107c4",func-name="main",offset="8",
33593 inst="sethi %hi(0x11800), %o2"@}]
33594 (gdb)
33595 @end smallexample
33596
33597 Disassemble 3 instructions from the start of @code{main} in mixed mode:
33598
33599 @smallexample
33600 (gdb)
33601 -data-disassemble -f basics.c -l 32 -n 3 -- 1
33602 ^done,asm_insns=[
33603 src_and_asm_line=@{line="31",
33604 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33605 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33606 line_asm_insn=[@{address="0x000107bc",
33607 func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
33608 src_and_asm_line=@{line="32",
33609 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33610 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33611 line_asm_insn=[@{address="0x000107c0",
33612 func-name="main",offset="4",inst="mov 2, %o0"@},
33613 @{address="0x000107c4",func-name="main",offset="8",
33614 inst="sethi %hi(0x11800), %o2"@}]@}]
33615 (gdb)
33616 @end smallexample
33617
33618
33619 @subheading The @code{-data-evaluate-expression} Command
33620 @findex -data-evaluate-expression
33621
33622 @subsubheading Synopsis
33623
33624 @smallexample
33625 -data-evaluate-expression @var{expr}
33626 @end smallexample
33627
33628 Evaluate @var{expr} as an expression. The expression could contain an
33629 inferior function call. The function call will execute synchronously.
33630 If the expression contains spaces, it must be enclosed in double quotes.
33631
33632 @subsubheading @value{GDBN} Command
33633
33634 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
33635 @samp{call}. In @code{gdbtk} only, there's a corresponding
33636 @samp{gdb_eval} command.
33637
33638 @subsubheading Example
33639
33640 In the following example, the numbers that precede the commands are the
33641 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
33642 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
33643 output.
33644
33645 @smallexample
33646 211-data-evaluate-expression A
33647 211^done,value="1"
33648 (gdb)
33649 311-data-evaluate-expression &A
33650 311^done,value="0xefffeb7c"
33651 (gdb)
33652 411-data-evaluate-expression A+3
33653 411^done,value="4"
33654 (gdb)
33655 511-data-evaluate-expression "A + 3"
33656 511^done,value="4"
33657 (gdb)
33658 @end smallexample
33659
33660
33661 @subheading The @code{-data-list-changed-registers} Command
33662 @findex -data-list-changed-registers
33663
33664 @subsubheading Synopsis
33665
33666 @smallexample
33667 -data-list-changed-registers
33668 @end smallexample
33669
33670 Display a list of the registers that have changed.
33671
33672 @subsubheading @value{GDBN} Command
33673
33674 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
33675 has the corresponding command @samp{gdb_changed_register_list}.
33676
33677 @subsubheading Example
33678
33679 On a PPC MBX board:
33680
33681 @smallexample
33682 (gdb)
33683 -exec-continue
33684 ^running
33685
33686 (gdb)
33687 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
33688 func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
33689 line="5",arch="powerpc"@}
33690 (gdb)
33691 -data-list-changed-registers
33692 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
33693 "10","11","13","14","15","16","17","18","19","20","21","22","23",
33694 "24","25","26","27","28","30","31","64","65","66","67","69"]
33695 (gdb)
33696 @end smallexample
33697
33698
33699 @subheading The @code{-data-list-register-names} Command
33700 @findex -data-list-register-names
33701
33702 @subsubheading Synopsis
33703
33704 @smallexample
33705 -data-list-register-names [ ( @var{regno} )+ ]
33706 @end smallexample
33707
33708 Show a list of register names for the current target. If no arguments
33709 are given, it shows a list of the names of all the registers. If
33710 integer numbers are given as arguments, it will print a list of the
33711 names of the registers corresponding to the arguments. To ensure
33712 consistency between a register name and its number, the output list may
33713 include empty register names.
33714
33715 @subsubheading @value{GDBN} Command
33716
33717 @value{GDBN} does not have a command which corresponds to
33718 @samp{-data-list-register-names}. In @code{gdbtk} there is a
33719 corresponding command @samp{gdb_regnames}.
33720
33721 @subsubheading Example
33722
33723 For the PPC MBX board:
33724 @smallexample
33725 (gdb)
33726 -data-list-register-names
33727 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
33728 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
33729 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
33730 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
33731 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
33732 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
33733 "", "pc","ps","cr","lr","ctr","xer"]
33734 (gdb)
33735 -data-list-register-names 1 2 3
33736 ^done,register-names=["r1","r2","r3"]
33737 (gdb)
33738 @end smallexample
33739
33740 @subheading The @code{-data-list-register-values} Command
33741 @findex -data-list-register-values
33742
33743 @subsubheading Synopsis
33744
33745 @smallexample
33746 -data-list-register-values
33747 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
33748 @end smallexample
33749
33750 Display the registers' contents. The format according to which the
33751 registers' contents are to be returned is given by @var{fmt}, followed
33752 by an optional list of numbers specifying the registers to display. A
33753 missing list of numbers indicates that the contents of all the
33754 registers must be returned. The @code{--skip-unavailable} option
33755 indicates that only the available registers are to be returned.
33756
33757 Allowed formats for @var{fmt} are:
33758
33759 @table @code
33760 @item x
33761 Hexadecimal
33762 @item o
33763 Octal
33764 @item t
33765 Binary
33766 @item d
33767 Decimal
33768 @item r
33769 Raw
33770 @item N
33771 Natural
33772 @end table
33773
33774 @subsubheading @value{GDBN} Command
33775
33776 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
33777 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
33778
33779 @subsubheading Example
33780
33781 For a PPC MBX board (note: line breaks are for readability only, they
33782 don't appear in the actual output):
33783
33784 @smallexample
33785 (gdb)
33786 -data-list-register-values r 64 65
33787 ^done,register-values=[@{number="64",value="0xfe00a300"@},
33788 @{number="65",value="0x00029002"@}]
33789 (gdb)
33790 -data-list-register-values x
33791 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
33792 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
33793 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
33794 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
33795 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
33796 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
33797 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
33798 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
33799 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
33800 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
33801 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
33802 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
33803 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
33804 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
33805 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
33806 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
33807 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
33808 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
33809 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
33810 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
33811 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
33812 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
33813 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
33814 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
33815 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
33816 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
33817 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
33818 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
33819 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
33820 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
33821 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
33822 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
33823 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
33824 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
33825 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
33826 @{number="69",value="0x20002b03"@}]
33827 (gdb)
33828 @end smallexample
33829
33830
33831 @subheading The @code{-data-read-memory} Command
33832 @findex -data-read-memory
33833
33834 This command is deprecated, use @code{-data-read-memory-bytes} instead.
33835
33836 @subsubheading Synopsis
33837
33838 @smallexample
33839 -data-read-memory [ -o @var{byte-offset} ]
33840 @var{address} @var{word-format} @var{word-size}
33841 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
33842 @end smallexample
33843
33844 @noindent
33845 where:
33846
33847 @table @samp
33848 @item @var{address}
33849 An expression specifying the address of the first memory word to be
33850 read. Complex expressions containing embedded white space should be
33851 quoted using the C convention.
33852
33853 @item @var{word-format}
33854 The format to be used to print the memory words. The notation is the
33855 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
33856 ,Output Formats}).
33857
33858 @item @var{word-size}
33859 The size of each memory word in bytes.
33860
33861 @item @var{nr-rows}
33862 The number of rows in the output table.
33863
33864 @item @var{nr-cols}
33865 The number of columns in the output table.
33866
33867 @item @var{aschar}
33868 If present, indicates that each row should include an @sc{ascii} dump. The
33869 value of @var{aschar} is used as a padding character when a byte is not a
33870 member of the printable @sc{ascii} character set (printable @sc{ascii}
33871 characters are those whose code is between 32 and 126, inclusively).
33872
33873 @item @var{byte-offset}
33874 An offset to add to the @var{address} before fetching memory.
33875 @end table
33876
33877 This command displays memory contents as a table of @var{nr-rows} by
33878 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
33879 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
33880 (returned as @samp{total-bytes}). Should less than the requested number
33881 of bytes be returned by the target, the missing words are identified
33882 using @samp{N/A}. The number of bytes read from the target is returned
33883 in @samp{nr-bytes} and the starting address used to read memory in
33884 @samp{addr}.
33885
33886 The address of the next/previous row or page is available in
33887 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
33888 @samp{prev-page}.
33889
33890 @subsubheading @value{GDBN} Command
33891
33892 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
33893 @samp{gdb_get_mem} memory read command.
33894
33895 @subsubheading Example
33896
33897 Read six bytes of memory starting at @code{bytes+6} but then offset by
33898 @code{-6} bytes. Format as three rows of two columns. One byte per
33899 word. Display each word in hex.
33900
33901 @smallexample
33902 (gdb)
33903 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
33904 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
33905 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
33906 prev-page="0x0000138a",memory=[
33907 @{addr="0x00001390",data=["0x00","0x01"]@},
33908 @{addr="0x00001392",data=["0x02","0x03"]@},
33909 @{addr="0x00001394",data=["0x04","0x05"]@}]
33910 (gdb)
33911 @end smallexample
33912
33913 Read two bytes of memory starting at address @code{shorts + 64} and
33914 display as a single word formatted in decimal.
33915
33916 @smallexample
33917 (gdb)
33918 5-data-read-memory shorts+64 d 2 1 1
33919 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
33920 next-row="0x00001512",prev-row="0x0000150e",
33921 next-page="0x00001512",prev-page="0x0000150e",memory=[
33922 @{addr="0x00001510",data=["128"]@}]
33923 (gdb)
33924 @end smallexample
33925
33926 Read thirty two bytes of memory starting at @code{bytes+16} and format
33927 as eight rows of four columns. Include a string encoding with @samp{x}
33928 used as the non-printable character.
33929
33930 @smallexample
33931 (gdb)
33932 4-data-read-memory bytes+16 x 1 8 4 x
33933 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
33934 next-row="0x000013c0",prev-row="0x0000139c",
33935 next-page="0x000013c0",prev-page="0x00001380",memory=[
33936 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
33937 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
33938 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
33939 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
33940 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
33941 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
33942 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
33943 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
33944 (gdb)
33945 @end smallexample
33946
33947 @subheading The @code{-data-read-memory-bytes} Command
33948 @findex -data-read-memory-bytes
33949
33950 @subsubheading Synopsis
33951
33952 @smallexample
33953 -data-read-memory-bytes [ -o @var{offset} ]
33954 @var{address} @var{count}
33955 @end smallexample
33956
33957 @noindent
33958 where:
33959
33960 @table @samp
33961 @item @var{address}
33962 An expression specifying the address of the first addressable memory unit
33963 to be read. Complex expressions containing embedded white space should be
33964 quoted using the C convention.
33965
33966 @item @var{count}
33967 The number of addressable memory units to read. This should be an integer
33968 literal.
33969
33970 @item @var{offset}
33971 The offset relative to @var{address} at which to start reading. This
33972 should be an integer literal. This option is provided so that a frontend
33973 is not required to first evaluate address and then perform address
33974 arithmetics itself.
33975
33976 @end table
33977
33978 This command attempts to read all accessible memory regions in the
33979 specified range. First, all regions marked as unreadable in the memory
33980 map (if one is defined) will be skipped. @xref{Memory Region
33981 Attributes}. Second, @value{GDBN} will attempt to read the remaining
33982 regions. For each one, if reading full region results in an errors,
33983 @value{GDBN} will try to read a subset of the region.
33984
33985 In general, every single memory unit in the region may be readable or not,
33986 and the only way to read every readable unit is to try a read at
33987 every address, which is not practical. Therefore, @value{GDBN} will
33988 attempt to read all accessible memory units at either beginning or the end
33989 of the region, using a binary division scheme. This heuristic works
33990 well for reading across a memory map boundary. Note that if a region
33991 has a readable range that is neither at the beginning or the end,
33992 @value{GDBN} will not read it.
33993
33994 The result record (@pxref{GDB/MI Result Records}) that is output of
33995 the command includes a field named @samp{memory} whose content is a
33996 list of tuples. Each tuple represent a successfully read memory block
33997 and has the following fields:
33998
33999 @table @code
34000 @item begin
34001 The start address of the memory block, as hexadecimal literal.
34002
34003 @item end
34004 The end address of the memory block, as hexadecimal literal.
34005
34006 @item offset
34007 The offset of the memory block, as hexadecimal literal, relative to
34008 the start address passed to @code{-data-read-memory-bytes}.
34009
34010 @item contents
34011 The contents of the memory block, in hex.
34012
34013 @end table
34014
34015
34016
34017 @subsubheading @value{GDBN} Command
34018
34019 The corresponding @value{GDBN} command is @samp{x}.
34020
34021 @subsubheading Example
34022
34023 @smallexample
34024 (gdb)
34025 -data-read-memory-bytes &a 10
34026 ^done,memory=[@{begin="0xbffff154",offset="0x00000000",
34027 end="0xbffff15e",
34028 contents="01000000020000000300"@}]
34029 (gdb)
34030 @end smallexample
34031
34032
34033 @subheading The @code{-data-write-memory-bytes} Command
34034 @findex -data-write-memory-bytes
34035
34036 @subsubheading Synopsis
34037
34038 @smallexample
34039 -data-write-memory-bytes @var{address} @var{contents}
34040 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
34041 @end smallexample
34042
34043 @noindent
34044 where:
34045
34046 @table @samp
34047 @item @var{address}
34048 An expression specifying the address of the first addressable memory unit
34049 to be written. Complex expressions containing embedded white space should
34050 be quoted using the C convention.
34051
34052 @item @var{contents}
34053 The hex-encoded data to write. It is an error if @var{contents} does
34054 not represent an integral number of addressable memory units.
34055
34056 @item @var{count}
34057 Optional argument indicating the number of addressable memory units to be
34058 written. If @var{count} is greater than @var{contents}' length,
34059 @value{GDBN} will repeatedly write @var{contents} until it fills
34060 @var{count} memory units.
34061
34062 @end table
34063
34064 @subsubheading @value{GDBN} Command
34065
34066 There's no corresponding @value{GDBN} command.
34067
34068 @subsubheading Example
34069
34070 @smallexample
34071 (gdb)
34072 -data-write-memory-bytes &a "aabbccdd"
34073 ^done
34074 (gdb)
34075 @end smallexample
34076
34077 @smallexample
34078 (gdb)
34079 -data-write-memory-bytes &a "aabbccdd" 16e
34080 ^done
34081 (gdb)
34082 @end smallexample
34083
34084 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34085 @node GDB/MI Tracepoint Commands
34086 @section @sc{gdb/mi} Tracepoint Commands
34087
34088 The commands defined in this section implement MI support for
34089 tracepoints. For detailed introduction, see @ref{Tracepoints}.
34090
34091 @subheading The @code{-trace-find} Command
34092 @findex -trace-find
34093
34094 @subsubheading Synopsis
34095
34096 @smallexample
34097 -trace-find @var{mode} [@var{parameters}@dots{}]
34098 @end smallexample
34099
34100 Find a trace frame using criteria defined by @var{mode} and
34101 @var{parameters}. The following table lists permissible
34102 modes and their parameters. For details of operation, see @ref{tfind}.
34103
34104 @table @samp
34105
34106 @item none
34107 No parameters are required. Stops examining trace frames.
34108
34109 @item frame-number
34110 An integer is required as parameter. Selects tracepoint frame with
34111 that index.
34112
34113 @item tracepoint-number
34114 An integer is required as parameter. Finds next
34115 trace frame that corresponds to tracepoint with the specified number.
34116
34117 @item pc
34118 An address is required as parameter. Finds
34119 next trace frame that corresponds to any tracepoint at the specified
34120 address.
34121
34122 @item pc-inside-range
34123 Two addresses are required as parameters. Finds next trace
34124 frame that corresponds to a tracepoint at an address inside the
34125 specified range. Both bounds are considered to be inside the range.
34126
34127 @item pc-outside-range
34128 Two addresses are required as parameters. Finds
34129 next trace frame that corresponds to a tracepoint at an address outside
34130 the specified range. Both bounds are considered to be inside the range.
34131
34132 @item line
34133 Line specification is required as parameter. @xref{Specify Location}.
34134 Finds next trace frame that corresponds to a tracepoint at
34135 the specified location.
34136
34137 @end table
34138
34139 If @samp{none} was passed as @var{mode}, the response does not
34140 have fields. Otherwise, the response may have the following fields:
34141
34142 @table @samp
34143 @item found
34144 This field has either @samp{0} or @samp{1} as the value, depending
34145 on whether a matching tracepoint was found.
34146
34147 @item traceframe
34148 The index of the found traceframe. This field is present iff
34149 the @samp{found} field has value of @samp{1}.
34150
34151 @item tracepoint
34152 The index of the found tracepoint. This field is present iff
34153 the @samp{found} field has value of @samp{1}.
34154
34155 @item frame
34156 The information about the frame corresponding to the found trace
34157 frame. This field is present only if a trace frame was found.
34158 @xref{GDB/MI Frame Information}, for description of this field.
34159
34160 @end table
34161
34162 @subsubheading @value{GDBN} Command
34163
34164 The corresponding @value{GDBN} command is @samp{tfind}.
34165
34166 @subheading -trace-define-variable
34167 @findex -trace-define-variable
34168
34169 @subsubheading Synopsis
34170
34171 @smallexample
34172 -trace-define-variable @var{name} [ @var{value} ]
34173 @end smallexample
34174
34175 Create trace variable @var{name} if it does not exist. If
34176 @var{value} is specified, sets the initial value of the specified
34177 trace variable to that value. Note that the @var{name} should start
34178 with the @samp{$} character.
34179
34180 @subsubheading @value{GDBN} Command
34181
34182 The corresponding @value{GDBN} command is @samp{tvariable}.
34183
34184 @subheading The @code{-trace-frame-collected} Command
34185 @findex -trace-frame-collected
34186
34187 @subsubheading Synopsis
34188
34189 @smallexample
34190 -trace-frame-collected
34191 [--var-print-values @var{var_pval}]
34192 [--comp-print-values @var{comp_pval}]
34193 [--registers-format @var{regformat}]
34194 [--memory-contents]
34195 @end smallexample
34196
34197 This command returns the set of collected objects, register names,
34198 trace state variable names, memory ranges and computed expressions
34199 that have been collected at a particular trace frame. The optional
34200 parameters to the command affect the output format in different ways.
34201 See the output description table below for more details.
34202
34203 The reported names can be used in the normal manner to create
34204 varobjs and inspect the objects themselves. The items returned by
34205 this command are categorized so that it is clear which is a variable,
34206 which is a register, which is a trace state variable, which is a
34207 memory range and which is a computed expression.
34208
34209 For instance, if the actions were
34210 @smallexample
34211 collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
34212 collect *(int*)0xaf02bef0@@40
34213 @end smallexample
34214
34215 @noindent
34216 the object collected in its entirety would be @code{myVar}. The
34217 object @code{myArray} would be partially collected, because only the
34218 element at index @code{myIndex} would be collected. The remaining
34219 objects would be computed expressions.
34220
34221 An example output would be:
34222
34223 @smallexample
34224 (gdb)
34225 -trace-frame-collected
34226 ^done,
34227 explicit-variables=[@{name="myVar",value="1"@}],
34228 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
34229 @{name="myObj.field",value="0"@},
34230 @{name="myPtr->field",value="1"@},
34231 @{name="myCount + 2",value="3"@},
34232 @{name="$tvar1 + 1",value="43970027"@}],
34233 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
34234 @{number="1",value="0x0"@},
34235 @{number="2",value="0x4"@},
34236 ...
34237 @{number="125",value="0x0"@}],
34238 tvars=[@{name="$tvar1",current="43970026"@}],
34239 memory=[@{address="0x0000000000602264",length="4"@},
34240 @{address="0x0000000000615bc0",length="4"@}]
34241 (gdb)
34242 @end smallexample
34243
34244 Where:
34245
34246 @table @code
34247 @item explicit-variables
34248 The set of objects that have been collected in their entirety (as
34249 opposed to collecting just a few elements of an array or a few struct
34250 members). For each object, its name and value are printed.
34251 The @code{--var-print-values} option affects how or whether the value
34252 field is output. If @var{var_pval} is 0, then print only the names;
34253 if it is 1, print also their values; and if it is 2, print the name,
34254 type and value for simple data types, and the name and type for
34255 arrays, structures and unions.
34256
34257 @item computed-expressions
34258 The set of computed expressions that have been collected at the
34259 current trace frame. The @code{--comp-print-values} option affects
34260 this set like the @code{--var-print-values} option affects the
34261 @code{explicit-variables} set. See above.
34262
34263 @item registers
34264 The registers that have been collected at the current trace frame.
34265 For each register collected, the name and current value are returned.
34266 The value is formatted according to the @code{--registers-format}
34267 option. See the @command{-data-list-register-values} command for a
34268 list of the allowed formats. The default is @samp{x}.
34269
34270 @item tvars
34271 The trace state variables that have been collected at the current
34272 trace frame. For each trace state variable collected, the name and
34273 current value are returned.
34274
34275 @item memory
34276 The set of memory ranges that have been collected at the current trace
34277 frame. Its content is a list of tuples. Each tuple represents a
34278 collected memory range and has the following fields:
34279
34280 @table @code
34281 @item address
34282 The start address of the memory range, as hexadecimal literal.
34283
34284 @item length
34285 The length of the memory range, as decimal literal.
34286
34287 @item contents
34288 The contents of the memory block, in hex. This field is only present
34289 if the @code{--memory-contents} option is specified.
34290
34291 @end table
34292
34293 @end table
34294
34295 @subsubheading @value{GDBN} Command
34296
34297 There is no corresponding @value{GDBN} command.
34298
34299 @subsubheading Example
34300
34301 @subheading -trace-list-variables
34302 @findex -trace-list-variables
34303
34304 @subsubheading Synopsis
34305
34306 @smallexample
34307 -trace-list-variables
34308 @end smallexample
34309
34310 Return a table of all defined trace variables. Each element of the
34311 table has the following fields:
34312
34313 @table @samp
34314 @item name
34315 The name of the trace variable. This field is always present.
34316
34317 @item initial
34318 The initial value. This is a 64-bit signed integer. This
34319 field is always present.
34320
34321 @item current
34322 The value the trace variable has at the moment. This is a 64-bit
34323 signed integer. This field is absent iff current value is
34324 not defined, for example if the trace was never run, or is
34325 presently running.
34326
34327 @end table
34328
34329 @subsubheading @value{GDBN} Command
34330
34331 The corresponding @value{GDBN} command is @samp{tvariables}.
34332
34333 @subsubheading Example
34334
34335 @smallexample
34336 (gdb)
34337 -trace-list-variables
34338 ^done,trace-variables=@{nr_rows="1",nr_cols="3",
34339 hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
34340 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
34341 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
34342 body=[variable=@{name="$trace_timestamp",initial="0"@}
34343 variable=@{name="$foo",initial="10",current="15"@}]@}
34344 (gdb)
34345 @end smallexample
34346
34347 @subheading -trace-save
34348 @findex -trace-save
34349
34350 @subsubheading Synopsis
34351
34352 @smallexample
34353 -trace-save [ -r ] [ -ctf ] @var{filename}
34354 @end smallexample
34355
34356 Saves the collected trace data to @var{filename}. Without the
34357 @samp{-r} option, the data is downloaded from the target and saved
34358 in a local file. With the @samp{-r} option the target is asked
34359 to perform the save.
34360
34361 By default, this command will save the trace in the tfile format. You can
34362 supply the optional @samp{-ctf} argument to save it the CTF format. See
34363 @ref{Trace Files} for more information about CTF.
34364
34365 @subsubheading @value{GDBN} Command
34366
34367 The corresponding @value{GDBN} command is @samp{tsave}.
34368
34369
34370 @subheading -trace-start
34371 @findex -trace-start
34372
34373 @subsubheading Synopsis
34374
34375 @smallexample
34376 -trace-start
34377 @end smallexample
34378
34379 Starts a tracing experiment. The result of this command does not
34380 have any fields.
34381
34382 @subsubheading @value{GDBN} Command
34383
34384 The corresponding @value{GDBN} command is @samp{tstart}.
34385
34386 @subheading -trace-status
34387 @findex -trace-status
34388
34389 @subsubheading Synopsis
34390
34391 @smallexample
34392 -trace-status
34393 @end smallexample
34394
34395 Obtains the status of a tracing experiment. The result may include
34396 the following fields:
34397
34398 @table @samp
34399
34400 @item supported
34401 May have a value of either @samp{0}, when no tracing operations are
34402 supported, @samp{1}, when all tracing operations are supported, or
34403 @samp{file} when examining trace file. In the latter case, examining
34404 of trace frame is possible but new tracing experiement cannot be
34405 started. This field is always present.
34406
34407 @item running
34408 May have a value of either @samp{0} or @samp{1} depending on whether
34409 tracing experiement is in progress on target. This field is present
34410 if @samp{supported} field is not @samp{0}.
34411
34412 @item stop-reason
34413 Report the reason why the tracing was stopped last time. This field
34414 may be absent iff tracing was never stopped on target yet. The
34415 value of @samp{request} means the tracing was stopped as result of
34416 the @code{-trace-stop} command. The value of @samp{overflow} means
34417 the tracing buffer is full. The value of @samp{disconnection} means
34418 tracing was automatically stopped when @value{GDBN} has disconnected.
34419 The value of @samp{passcount} means tracing was stopped when a
34420 tracepoint was passed a maximal number of times for that tracepoint.
34421 This field is present if @samp{supported} field is not @samp{0}.
34422
34423 @item stopping-tracepoint
34424 The number of tracepoint whose passcount as exceeded. This field is
34425 present iff the @samp{stop-reason} field has the value of
34426 @samp{passcount}.
34427
34428 @item frames
34429 @itemx frames-created
34430 The @samp{frames} field is a count of the total number of trace frames
34431 in the trace buffer, while @samp{frames-created} is the total created
34432 during the run, including ones that were discarded, such as when a
34433 circular trace buffer filled up. Both fields are optional.
34434
34435 @item buffer-size
34436 @itemx buffer-free
34437 These fields tell the current size of the tracing buffer and the
34438 remaining space. These fields are optional.
34439
34440 @item circular
34441 The value of the circular trace buffer flag. @code{1} means that the
34442 trace buffer is circular and old trace frames will be discarded if
34443 necessary to make room, @code{0} means that the trace buffer is linear
34444 and may fill up.
34445
34446 @item disconnected
34447 The value of the disconnected tracing flag. @code{1} means that
34448 tracing will continue after @value{GDBN} disconnects, @code{0} means
34449 that the trace run will stop.
34450
34451 @item trace-file
34452 The filename of the trace file being examined. This field is
34453 optional, and only present when examining a trace file.
34454
34455 @end table
34456
34457 @subsubheading @value{GDBN} Command
34458
34459 The corresponding @value{GDBN} command is @samp{tstatus}.
34460
34461 @subheading -trace-stop
34462 @findex -trace-stop
34463
34464 @subsubheading Synopsis
34465
34466 @smallexample
34467 -trace-stop
34468 @end smallexample
34469
34470 Stops a tracing experiment. The result of this command has the same
34471 fields as @code{-trace-status}, except that the @samp{supported} and
34472 @samp{running} fields are not output.
34473
34474 @subsubheading @value{GDBN} Command
34475
34476 The corresponding @value{GDBN} command is @samp{tstop}.
34477
34478
34479 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34480 @node GDB/MI Symbol Query
34481 @section @sc{gdb/mi} Symbol Query Commands
34482
34483
34484 @ignore
34485 @subheading The @code{-symbol-info-address} Command
34486 @findex -symbol-info-address
34487
34488 @subsubheading Synopsis
34489
34490 @smallexample
34491 -symbol-info-address @var{symbol}
34492 @end smallexample
34493
34494 Describe where @var{symbol} is stored.
34495
34496 @subsubheading @value{GDBN} Command
34497
34498 The corresponding @value{GDBN} command is @samp{info address}.
34499
34500 @subsubheading Example
34501 N.A.
34502
34503
34504 @subheading The @code{-symbol-info-file} Command
34505 @findex -symbol-info-file
34506
34507 @subsubheading Synopsis
34508
34509 @smallexample
34510 -symbol-info-file
34511 @end smallexample
34512
34513 Show the file for the symbol.
34514
34515 @subsubheading @value{GDBN} Command
34516
34517 There's no equivalent @value{GDBN} command. @code{gdbtk} has
34518 @samp{gdb_find_file}.
34519
34520 @subsubheading Example
34521 N.A.
34522 @end ignore
34523
34524 @subheading The @code{-symbol-info-functions} Command
34525 @findex -symbol-info-functions
34526 @anchor{-symbol-info-functions}
34527
34528 @subsubheading Synopsis
34529
34530 @smallexample
34531 -symbol-info-functions [--include-nondebug]
34532 [--type @var{type_regexp}]
34533 [--name @var{name_regexp}]
34534 [--max-results @var{limit}]
34535 @end smallexample
34536
34537 @noindent
34538 Return a list containing the names and types for all global functions
34539 taken from the debug information. The functions are grouped by source
34540 file, and shown with the line number on which each function is
34541 defined.
34542
34543 The @code{--include-nondebug} option causes the output to include
34544 code symbols from the symbol table.
34545
34546 The options @code{--type} and @code{--name} allow the symbols returned
34547 to be filtered based on either the name of the function, or the type
34548 signature of the function.
34549
34550 The option @code{--max-results} restricts the command to return no
34551 more than @var{limit} results. If exactly @var{limit} results are
34552 returned then there might be additional results available if a higher
34553 limit is used.
34554
34555 @subsubheading @value{GDBN} Command
34556
34557 The corresponding @value{GDBN} command is @samp{info functions}.
34558
34559 @subsubheading Example
34560 @smallexample
34561 @group
34562 (gdb)
34563 -symbol-info-functions
34564 ^done,symbols=
34565 @{debug=
34566 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34567 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34568 symbols=[@{line="36", name="f4", type="void (int *)",
34569 description="void f4(int *);"@},
34570 @{line="42", name="main", type="int ()",
34571 description="int main();"@},
34572 @{line="30", name="f1", type="my_int_t (int, int)",
34573 description="static my_int_t f1(int, int);"@}]@},
34574 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34575 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34576 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34577 description="float f2(another_float_t);"@},
34578 @{line="39", name="f3", type="int (another_int_t)",
34579 description="int f3(another_int_t);"@},
34580 @{line="27", name="f1", type="another_float_t (int)",
34581 description="static another_float_t f1(int);"@}]@}]@}
34582 @end group
34583 @group
34584 (gdb)
34585 -symbol-info-functions --name f1
34586 ^done,symbols=
34587 @{debug=
34588 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34589 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34590 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
34591 description="static my_int_t f1(int, int);"@}]@},
34592 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34593 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34594 symbols=[@{line="27", name="f1", type="another_float_t (int)",
34595 description="static another_float_t f1(int);"@}]@}]@}
34596 @end group
34597 @group
34598 (gdb)
34599 -symbol-info-functions --type void
34600 ^done,symbols=
34601 @{debug=
34602 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34603 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34604 symbols=[@{line="36", name="f4", type="void (int *)",
34605 description="void f4(int *);"@}]@}]@}
34606 @end group
34607 @group
34608 (gdb)
34609 -symbol-info-functions --include-nondebug
34610 ^done,symbols=
34611 @{debug=
34612 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34613 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34614 symbols=[@{line="36", name="f4", type="void (int *)",
34615 description="void f4(int *);"@},
34616 @{line="42", name="main", type="int ()",
34617 description="int main();"@},
34618 @{line="30", name="f1", type="my_int_t (int, int)",
34619 description="static my_int_t f1(int, int);"@}]@},
34620 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34621 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34622 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34623 description="float f2(another_float_t);"@},
34624 @{line="39", name="f3", type="int (another_int_t)",
34625 description="int f3(another_int_t);"@},
34626 @{line="27", name="f1", type="another_float_t (int)",
34627 description="static another_float_t f1(int);"@}]@}],
34628 nondebug=
34629 [@{address="0x0000000000400398",name="_init"@},
34630 @{address="0x00000000004003b0",name="_start"@},
34631 ...
34632 ]@}
34633 @end group
34634 @end smallexample
34635
34636 @subheading The @code{-symbol-info-module-functions} Command
34637 @findex -symbol-info-module-functions
34638 @anchor{-symbol-info-module-functions}
34639
34640 @subsubheading Synopsis
34641
34642 @smallexample
34643 -symbol-info-module-functions [--module @var{module_regexp}]
34644 [--name @var{name_regexp}]
34645 [--type @var{type_regexp}]
34646 @end smallexample
34647
34648 @noindent
34649 Return a list containing the names of all known functions within all
34650 know Fortran modules. The functions are grouped by source file and
34651 containing module, and shown with the line number on which each
34652 function is defined.
34653
34654 The option @code{--module} only returns results for modules matching
34655 @var{module_regexp}. The option @code{--name} only returns functions
34656 whose name matches @var{name_regexp}, and @code{--type} only returns
34657 functions whose type matches @var{type_regexp}.
34658
34659 @subsubheading @value{GDBN} Command
34660
34661 The corresponding @value{GDBN} command is @samp{info module functions}.
34662
34663 @subsubheading Example
34664
34665 @smallexample
34666 @group
34667 (gdb)
34668 -symbol-info-module-functions
34669 ^done,symbols=
34670 [@{module="mod1",
34671 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34672 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34673 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
34674 description="void mod1::check_all(void);"@}]@}]@},
34675 @{module="mod2",
34676 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34677 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34678 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
34679 description="void mod2::check_var_i(void);"@}]@}]@},
34680 @{module="mod3",
34681 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34682 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34683 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
34684 description="void mod3::check_all(void);"@},
34685 @{line="27",name="mod3::check_mod2",type="void (void)",
34686 description="void mod3::check_mod2(void);"@}]@}]@},
34687 @{module="modmany",
34688 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34689 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34690 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
34691 description="void modmany::check_some(void);"@}]@}]@},
34692 @{module="moduse",
34693 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34694 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34695 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
34696 description="void moduse::check_all(void);"@},
34697 @{line="49",name="moduse::check_var_x",type="void (void)",
34698 description="void moduse::check_var_x(void);"@}]@}]@}]
34699 @end group
34700 @end smallexample
34701
34702 @subheading The @code{-symbol-info-module-variables} Command
34703 @findex -symbol-info-module-variables
34704 @anchor{-symbol-info-module-variables}
34705
34706 @subsubheading Synopsis
34707
34708 @smallexample
34709 -symbol-info-module-variables [--module @var{module_regexp}]
34710 [--name @var{name_regexp}]
34711 [--type @var{type_regexp}]
34712 @end smallexample
34713
34714 @noindent
34715 Return a list containing the names of all known variables within all
34716 know Fortran modules. The variables are grouped by source file and
34717 containing module, and shown with the line number on which each
34718 variable is defined.
34719
34720 The option @code{--module} only returns results for modules matching
34721 @var{module_regexp}. The option @code{--name} only returns variables
34722 whose name matches @var{name_regexp}, and @code{--type} only returns
34723 variables whose type matches @var{type_regexp}.
34724
34725 @subsubheading @value{GDBN} Command
34726
34727 The corresponding @value{GDBN} command is @samp{info module variables}.
34728
34729 @subsubheading Example
34730
34731 @smallexample
34732 @group
34733 (gdb)
34734 -symbol-info-module-variables
34735 ^done,symbols=
34736 [@{module="mod1",
34737 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34738 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34739 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
34740 description="integer(kind=4) mod1::var_const;"@},
34741 @{line="17",name="mod1::var_i",type="integer(kind=4)",
34742 description="integer(kind=4) mod1::var_i;"@}]@}]@},
34743 @{module="mod2",
34744 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34745 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34746 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
34747 description="integer(kind=4) mod2::var_i;"@}]@}]@},
34748 @{module="mod3",
34749 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34750 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34751 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
34752 description="integer(kind=4) mod3::mod1;"@},
34753 @{line="17",name="mod3::mod2",type="integer(kind=4)",
34754 description="integer(kind=4) mod3::mod2;"@},
34755 @{line="19",name="mod3::var_i",type="integer(kind=4)",
34756 description="integer(kind=4) mod3::var_i;"@}]@}]@},
34757 @{module="modmany",
34758 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34759 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34760 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
34761 description="integer(kind=4) modmany::var_a;"@},
34762 @{line="33",name="modmany::var_b",type="integer(kind=4)",
34763 description="integer(kind=4) modmany::var_b;"@},
34764 @{line="33",name="modmany::var_c",type="integer(kind=4)",
34765 description="integer(kind=4) modmany::var_c;"@},
34766 @{line="33",name="modmany::var_i",type="integer(kind=4)",
34767 description="integer(kind=4) modmany::var_i;"@}]@}]@},
34768 @{module="moduse",
34769 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34770 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34771 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
34772 description="integer(kind=4) moduse::var_x;"@},
34773 @{line="42",name="moduse::var_y",type="integer(kind=4)",
34774 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
34775 @end group
34776 @end smallexample
34777
34778 @subheading The @code{-symbol-info-modules} Command
34779 @findex -symbol-info-modules
34780 @anchor{-symbol-info-modules}
34781
34782 @subsubheading Synopsis
34783
34784 @smallexample
34785 -symbol-info-modules [--name @var{name_regexp}]
34786 [--max-results @var{limit}]
34787
34788 @end smallexample
34789
34790 @noindent
34791 Return a list containing the names of all known Fortran modules. The
34792 modules are grouped by source file, and shown with the line number on
34793 which each modules is defined.
34794
34795 The option @code{--name} allows the modules returned to be filtered
34796 based the name of the module.
34797
34798 The option @code{--max-results} restricts the command to return no
34799 more than @var{limit} results. If exactly @var{limit} results are
34800 returned then there might be additional results available if a higher
34801 limit is used.
34802
34803 @subsubheading @value{GDBN} Command
34804
34805 The corresponding @value{GDBN} command is @samp{info modules}.
34806
34807 @subsubheading Example
34808 @smallexample
34809 @group
34810 (gdb)
34811 -symbol-info-modules
34812 ^done,symbols=
34813 @{debug=
34814 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34815 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34816 symbols=[@{line="16",name="mod1"@},
34817 @{line="22",name="mod2"@}]@},
34818 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34819 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34820 symbols=[@{line="16",name="mod3"@},
34821 @{line="22",name="modmany"@},
34822 @{line="26",name="moduse"@}]@}]@}
34823 @end group
34824 @group
34825 (gdb)
34826 -symbol-info-modules --name mod[123]
34827 ^done,symbols=
34828 @{debug=
34829 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34830 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34831 symbols=[@{line="16",name="mod1"@},
34832 @{line="22",name="mod2"@}]@},
34833 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34834 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34835 symbols=[@{line="16",name="mod3"@}]@}]@}
34836 @end group
34837 @end smallexample
34838
34839 @subheading The @code{-symbol-info-types} Command
34840 @findex -symbol-info-types
34841 @anchor{-symbol-info-types}
34842
34843 @subsubheading Synopsis
34844
34845 @smallexample
34846 -symbol-info-types [--name @var{name_regexp}]
34847 [--max-results @var{limit}]
34848
34849 @end smallexample
34850
34851 @noindent
34852 Return a list of all defined types. The types are grouped by source
34853 file, and shown with the line number on which each user defined type
34854 is defined. Some base types are not defined in the source code but
34855 are added to the debug information by the compiler, for example
34856 @code{int}, @code{float}, etc.; these types do not have an associated
34857 line number.
34858
34859 The option @code{--name} allows the list of types returned to be
34860 filtered by name.
34861
34862 The option @code{--max-results} restricts the command to return no
34863 more than @var{limit} results. If exactly @var{limit} results are
34864 returned then there might be additional results available if a higher
34865 limit is used.
34866
34867 @subsubheading @value{GDBN} Command
34868
34869 The corresponding @value{GDBN} command is @samp{info types}.
34870
34871 @subsubheading Example
34872 @smallexample
34873 @group
34874 (gdb)
34875 -symbol-info-types
34876 ^done,symbols=
34877 @{debug=
34878 [@{filename="gdb.mi/mi-sym-info-1.c",
34879 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34880 symbols=[@{name="float"@},
34881 @{name="int"@},
34882 @{line="27",name="typedef int my_int_t;"@}]@},
34883 @{filename="gdb.mi/mi-sym-info-2.c",
34884 fullname="/project/gdb.mi/mi-sym-info-2.c",
34885 symbols=[@{line="24",name="typedef float another_float_t;"@},
34886 @{line="23",name="typedef int another_int_t;"@},
34887 @{name="float"@},
34888 @{name="int"@}]@}]@}
34889 @end group
34890 @group
34891 (gdb)
34892 -symbol-info-types --name _int_
34893 ^done,symbols=
34894 @{debug=
34895 [@{filename="gdb.mi/mi-sym-info-1.c",
34896 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34897 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
34898 @{filename="gdb.mi/mi-sym-info-2.c",
34899 fullname="/project/gdb.mi/mi-sym-info-2.c",
34900 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
34901 @end group
34902 @end smallexample
34903
34904 @subheading The @code{-symbol-info-variables} Command
34905 @findex -symbol-info-variables
34906 @anchor{-symbol-info-variables}
34907
34908 @subsubheading Synopsis
34909
34910 @smallexample
34911 -symbol-info-variables [--include-nondebug]
34912 [--type @var{type_regexp}]
34913 [--name @var{name_regexp}]
34914 [--max-results @var{limit}]
34915
34916 @end smallexample
34917
34918 @noindent
34919 Return a list containing the names and types for all global variables
34920 taken from the debug information. The variables are grouped by source
34921 file, and shown with the line number on which each variable is
34922 defined.
34923
34924 The @code{--include-nondebug} option causes the output to include
34925 data symbols from the symbol table.
34926
34927 The options @code{--type} and @code{--name} allow the symbols returned
34928 to be filtered based on either the name of the variable, or the type
34929 of the variable.
34930
34931 The option @code{--max-results} restricts the command to return no
34932 more than @var{limit} results. If exactly @var{limit} results are
34933 returned then there might be additional results available if a higher
34934 limit is used.
34935
34936 @subsubheading @value{GDBN} Command
34937
34938 The corresponding @value{GDBN} command is @samp{info variables}.
34939
34940 @subsubheading Example
34941 @smallexample
34942 @group
34943 (gdb)
34944 -symbol-info-variables
34945 ^done,symbols=
34946 @{debug=
34947 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34948 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34949 symbols=[@{line="25",name="global_f1",type="float",
34950 description="static float global_f1;"@},
34951 @{line="24",name="global_i1",type="int",
34952 description="static int global_i1;"@}]@},
34953 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34954 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34955 symbols=[@{line="21",name="global_f2",type="int",
34956 description="int global_f2;"@},
34957 @{line="20",name="global_i2",type="int",
34958 description="int global_i2;"@},
34959 @{line="19",name="global_f1",type="float",
34960 description="static float global_f1;"@},
34961 @{line="18",name="global_i1",type="int",
34962 description="static int global_i1;"@}]@}]@}
34963 @end group
34964 @group
34965 (gdb)
34966 -symbol-info-variables --name f1
34967 ^done,symbols=
34968 @{debug=
34969 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34970 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34971 symbols=[@{line="25",name="global_f1",type="float",
34972 description="static float global_f1;"@}]@},
34973 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34974 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34975 symbols=[@{line="19",name="global_f1",type="float",
34976 description="static float global_f1;"@}]@}]@}
34977 @end group
34978 @group
34979 (gdb)
34980 -symbol-info-variables --type float
34981 ^done,symbols=
34982 @{debug=
34983 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34984 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34985 symbols=[@{line="25",name="global_f1",type="float",
34986 description="static float global_f1;"@}]@},
34987 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34988 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34989 symbols=[@{line="19",name="global_f1",type="float",
34990 description="static float global_f1;"@}]@}]@}
34991 @end group
34992 @group
34993 (gdb)
34994 -symbol-info-variables --include-nondebug
34995 ^done,symbols=
34996 @{debug=
34997 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34998 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34999 symbols=[@{line="25",name="global_f1",type="float",
35000 description="static float global_f1;"@},
35001 @{line="24",name="global_i1",type="int",
35002 description="static int global_i1;"@}]@},
35003 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35004 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35005 symbols=[@{line="21",name="global_f2",type="int",
35006 description="int global_f2;"@},
35007 @{line="20",name="global_i2",type="int",
35008 description="int global_i2;"@},
35009 @{line="19",name="global_f1",type="float",
35010 description="static float global_f1;"@},
35011 @{line="18",name="global_i1",type="int",
35012 description="static int global_i1;"@}]@}],
35013 nondebug=
35014 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
35015 @{address="0x00000000004005d8",name="__dso_handle"@}
35016 ...
35017 ]@}
35018 @end group
35019 @end smallexample
35020
35021 @ignore
35022 @subheading The @code{-symbol-info-line} Command
35023 @findex -symbol-info-line
35024
35025 @subsubheading Synopsis
35026
35027 @smallexample
35028 -symbol-info-line
35029 @end smallexample
35030
35031 Show the core addresses of the code for a source line.
35032
35033 @subsubheading @value{GDBN} Command
35034
35035 The corresponding @value{GDBN} command is @samp{info line}.
35036 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
35037
35038 @subsubheading Example
35039 N.A.
35040
35041
35042 @subheading The @code{-symbol-info-symbol} Command
35043 @findex -symbol-info-symbol
35044
35045 @subsubheading Synopsis
35046
35047 @smallexample
35048 -symbol-info-symbol @var{addr}
35049 @end smallexample
35050
35051 Describe what symbol is at location @var{addr}.
35052
35053 @subsubheading @value{GDBN} Command
35054
35055 The corresponding @value{GDBN} command is @samp{info symbol}.
35056
35057 @subsubheading Example
35058 N.A.
35059
35060
35061 @subheading The @code{-symbol-list-functions} Command
35062 @findex -symbol-list-functions
35063
35064 @subsubheading Synopsis
35065
35066 @smallexample
35067 -symbol-list-functions
35068 @end smallexample
35069
35070 List the functions in the executable.
35071
35072 @subsubheading @value{GDBN} Command
35073
35074 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
35075 @samp{gdb_search} in @code{gdbtk}.
35076
35077 @subsubheading Example
35078 N.A.
35079 @end ignore
35080
35081
35082 @subheading The @code{-symbol-list-lines} Command
35083 @findex -symbol-list-lines
35084
35085 @subsubheading Synopsis
35086
35087 @smallexample
35088 -symbol-list-lines @var{filename}
35089 @end smallexample
35090
35091 Print the list of lines that contain code and their associated program
35092 addresses for the given source filename. The entries are sorted in
35093 ascending PC order.
35094
35095 @subsubheading @value{GDBN} Command
35096
35097 There is no corresponding @value{GDBN} command.
35098
35099 @subsubheading Example
35100 @smallexample
35101 (gdb)
35102 -symbol-list-lines basics.c
35103 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
35104 (gdb)
35105 @end smallexample
35106
35107
35108 @ignore
35109 @subheading The @code{-symbol-list-types} Command
35110 @findex -symbol-list-types
35111
35112 @subsubheading Synopsis
35113
35114 @smallexample
35115 -symbol-list-types
35116 @end smallexample
35117
35118 List all the type names.
35119
35120 @subsubheading @value{GDBN} Command
35121
35122 The corresponding commands are @samp{info types} in @value{GDBN},
35123 @samp{gdb_search} in @code{gdbtk}.
35124
35125 @subsubheading Example
35126 N.A.
35127
35128
35129 @subheading The @code{-symbol-list-variables} Command
35130 @findex -symbol-list-variables
35131
35132 @subsubheading Synopsis
35133
35134 @smallexample
35135 -symbol-list-variables
35136 @end smallexample
35137
35138 List all the global and static variable names.
35139
35140 @subsubheading @value{GDBN} Command
35141
35142 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
35143
35144 @subsubheading Example
35145 N.A.
35146
35147
35148 @subheading The @code{-symbol-locate} Command
35149 @findex -symbol-locate
35150
35151 @subsubheading Synopsis
35152
35153 @smallexample
35154 -symbol-locate
35155 @end smallexample
35156
35157 @subsubheading @value{GDBN} Command
35158
35159 @samp{gdb_loc} in @code{gdbtk}.
35160
35161 @subsubheading Example
35162 N.A.
35163
35164
35165 @subheading The @code{-symbol-type} Command
35166 @findex -symbol-type
35167
35168 @subsubheading Synopsis
35169
35170 @smallexample
35171 -symbol-type @var{variable}
35172 @end smallexample
35173
35174 Show type of @var{variable}.
35175
35176 @subsubheading @value{GDBN} Command
35177
35178 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
35179 @samp{gdb_obj_variable}.
35180
35181 @subsubheading Example
35182 N.A.
35183 @end ignore
35184
35185
35186 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35187 @node GDB/MI File Commands
35188 @section @sc{gdb/mi} File Commands
35189
35190 This section describes the GDB/MI commands to specify executable file names
35191 and to read in and obtain symbol table information.
35192
35193 @subheading The @code{-file-exec-and-symbols} Command
35194 @findex -file-exec-and-symbols
35195
35196 @subsubheading Synopsis
35197
35198 @smallexample
35199 -file-exec-and-symbols @var{file}
35200 @end smallexample
35201
35202 Specify the executable file to be debugged. This file is the one from
35203 which the symbol table is also read. If no file is specified, the
35204 command clears the executable and symbol information. If breakpoints
35205 are set when using this command with no arguments, @value{GDBN} will produce
35206 error messages. Otherwise, no output is produced, except a completion
35207 notification.
35208
35209 @subsubheading @value{GDBN} Command
35210
35211 The corresponding @value{GDBN} command is @samp{file}.
35212
35213 @subsubheading Example
35214
35215 @smallexample
35216 (gdb)
35217 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35218 ^done
35219 (gdb)
35220 @end smallexample
35221
35222
35223 @subheading The @code{-file-exec-file} Command
35224 @findex -file-exec-file
35225
35226 @subsubheading Synopsis
35227
35228 @smallexample
35229 -file-exec-file @var{file}
35230 @end smallexample
35231
35232 Specify the executable file to be debugged. Unlike
35233 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
35234 from this file. If used without argument, @value{GDBN} clears the information
35235 about the executable file. No output is produced, except a completion
35236 notification.
35237
35238 @subsubheading @value{GDBN} Command
35239
35240 The corresponding @value{GDBN} command is @samp{exec-file}.
35241
35242 @subsubheading Example
35243
35244 @smallexample
35245 (gdb)
35246 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35247 ^done
35248 (gdb)
35249 @end smallexample
35250
35251
35252 @ignore
35253 @subheading The @code{-file-list-exec-sections} Command
35254 @findex -file-list-exec-sections
35255
35256 @subsubheading Synopsis
35257
35258 @smallexample
35259 -file-list-exec-sections
35260 @end smallexample
35261
35262 List the sections of the current executable file.
35263
35264 @subsubheading @value{GDBN} Command
35265
35266 The @value{GDBN} command @samp{info file} shows, among the rest, the same
35267 information as this command. @code{gdbtk} has a corresponding command
35268 @samp{gdb_load_info}.
35269
35270 @subsubheading Example
35271 N.A.
35272 @end ignore
35273
35274
35275 @subheading The @code{-file-list-exec-source-file} Command
35276 @findex -file-list-exec-source-file
35277
35278 @subsubheading Synopsis
35279
35280 @smallexample
35281 -file-list-exec-source-file
35282 @end smallexample
35283
35284 List the line number, the current source file, and the absolute path
35285 to the current source file for the current executable. The macro
35286 information field has a value of @samp{1} or @samp{0} depending on
35287 whether or not the file includes preprocessor macro information.
35288
35289 @subsubheading @value{GDBN} Command
35290
35291 The @value{GDBN} equivalent is @samp{info source}
35292
35293 @subsubheading Example
35294
35295 @smallexample
35296 (gdb)
35297 123-file-list-exec-source-file
35298 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
35299 (gdb)
35300 @end smallexample
35301
35302
35303 @subheading The @code{-file-list-exec-source-files} Command
35304 @findex -file-list-exec-source-files
35305
35306 @subsubheading Synopsis
35307
35308 @smallexample
35309 -file-list-exec-source-files
35310 @end smallexample
35311
35312 List the source files for the current executable.
35313
35314 It will always output both the filename and fullname (absolute file
35315 name) of a source file.
35316
35317 @subsubheading @value{GDBN} Command
35318
35319 The @value{GDBN} equivalent is @samp{info sources}.
35320 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
35321
35322 @subsubheading Example
35323 @smallexample
35324 (gdb)
35325 -file-list-exec-source-files
35326 ^done,files=[
35327 @{file=foo.c,fullname=/home/foo.c@},
35328 @{file=/home/bar.c,fullname=/home/bar.c@},
35329 @{file=gdb_could_not_find_fullpath.c@}]
35330 (gdb)
35331 @end smallexample
35332
35333 @subheading The @code{-file-list-shared-libraries} Command
35334 @findex -file-list-shared-libraries
35335
35336 @subsubheading Synopsis
35337
35338 @smallexample
35339 -file-list-shared-libraries [ @var{regexp} ]
35340 @end smallexample
35341
35342 List the shared libraries in the program.
35343 With a regular expression @var{regexp}, only those libraries whose
35344 names match @var{regexp} are listed.
35345
35346 @subsubheading @value{GDBN} Command
35347
35348 The corresponding @value{GDBN} command is @samp{info shared}. The fields
35349 have a similar meaning to the @code{=library-loaded} notification.
35350 The @code{ranges} field specifies the multiple segments belonging to this
35351 library. Each range has the following fields:
35352
35353 @table @samp
35354 @item from
35355 The address defining the inclusive lower bound of the segment.
35356 @item to
35357 The address defining the exclusive upper bound of the segment.
35358 @end table
35359
35360 @subsubheading Example
35361 @smallexample
35362 (gdb)
35363 -file-list-exec-source-files
35364 ^done,shared-libraries=[
35365 @{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"@}]@},
35366 @{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"@}]@}]
35367 (gdb)
35368 @end smallexample
35369
35370
35371 @ignore
35372 @subheading The @code{-file-list-symbol-files} Command
35373 @findex -file-list-symbol-files
35374
35375 @subsubheading Synopsis
35376
35377 @smallexample
35378 -file-list-symbol-files
35379 @end smallexample
35380
35381 List symbol files.
35382
35383 @subsubheading @value{GDBN} Command
35384
35385 The corresponding @value{GDBN} command is @samp{info file} (part of it).
35386
35387 @subsubheading Example
35388 N.A.
35389 @end ignore
35390
35391
35392 @subheading The @code{-file-symbol-file} Command
35393 @findex -file-symbol-file
35394
35395 @subsubheading Synopsis
35396
35397 @smallexample
35398 -file-symbol-file @var{file}
35399 @end smallexample
35400
35401 Read symbol table info from the specified @var{file} argument. When
35402 used without arguments, clears @value{GDBN}'s symbol table info. No output is
35403 produced, except for a completion notification.
35404
35405 @subsubheading @value{GDBN} Command
35406
35407 The corresponding @value{GDBN} command is @samp{symbol-file}.
35408
35409 @subsubheading Example
35410
35411 @smallexample
35412 (gdb)
35413 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35414 ^done
35415 (gdb)
35416 @end smallexample
35417
35418 @ignore
35419 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35420 @node GDB/MI Memory Overlay Commands
35421 @section @sc{gdb/mi} Memory Overlay Commands
35422
35423 The memory overlay commands are not implemented.
35424
35425 @c @subheading -overlay-auto
35426
35427 @c @subheading -overlay-list-mapping-state
35428
35429 @c @subheading -overlay-list-overlays
35430
35431 @c @subheading -overlay-map
35432
35433 @c @subheading -overlay-off
35434
35435 @c @subheading -overlay-on
35436
35437 @c @subheading -overlay-unmap
35438
35439 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35440 @node GDB/MI Signal Handling Commands
35441 @section @sc{gdb/mi} Signal Handling Commands
35442
35443 Signal handling commands are not implemented.
35444
35445 @c @subheading -signal-handle
35446
35447 @c @subheading -signal-list-handle-actions
35448
35449 @c @subheading -signal-list-signal-types
35450 @end ignore
35451
35452
35453 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35454 @node GDB/MI Target Manipulation
35455 @section @sc{gdb/mi} Target Manipulation Commands
35456
35457
35458 @subheading The @code{-target-attach} Command
35459 @findex -target-attach
35460
35461 @subsubheading Synopsis
35462
35463 @smallexample
35464 -target-attach @var{pid} | @var{gid} | @var{file}
35465 @end smallexample
35466
35467 Attach to a process @var{pid} or a file @var{file} outside of
35468 @value{GDBN}, or a thread group @var{gid}. If attaching to a thread
35469 group, the id previously returned by
35470 @samp{-list-thread-groups --available} must be used.
35471
35472 @subsubheading @value{GDBN} Command
35473
35474 The corresponding @value{GDBN} command is @samp{attach}.
35475
35476 @subsubheading Example
35477 @smallexample
35478 (gdb)
35479 -target-attach 34
35480 =thread-created,id="1"
35481 *stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
35482 ^done
35483 (gdb)
35484 @end smallexample
35485
35486 @ignore
35487 @subheading The @code{-target-compare-sections} Command
35488 @findex -target-compare-sections
35489
35490 @subsubheading Synopsis
35491
35492 @smallexample
35493 -target-compare-sections [ @var{section} ]
35494 @end smallexample
35495
35496 Compare data of section @var{section} on target to the exec file.
35497 Without the argument, all sections are compared.
35498
35499 @subsubheading @value{GDBN} Command
35500
35501 The @value{GDBN} equivalent is @samp{compare-sections}.
35502
35503 @subsubheading Example
35504 N.A.
35505 @end ignore
35506
35507
35508 @subheading The @code{-target-detach} Command
35509 @findex -target-detach
35510
35511 @subsubheading Synopsis
35512
35513 @smallexample
35514 -target-detach [ @var{pid} | @var{gid} ]
35515 @end smallexample
35516
35517 Detach from the remote target which normally resumes its execution.
35518 If either @var{pid} or @var{gid} is specified, detaches from either
35519 the specified process, or specified thread group. There's no output.
35520
35521 @subsubheading @value{GDBN} Command
35522
35523 The corresponding @value{GDBN} command is @samp{detach}.
35524
35525 @subsubheading Example
35526
35527 @smallexample
35528 (gdb)
35529 -target-detach
35530 ^done
35531 (gdb)
35532 @end smallexample
35533
35534
35535 @subheading The @code{-target-disconnect} Command
35536 @findex -target-disconnect
35537
35538 @subsubheading Synopsis
35539
35540 @smallexample
35541 -target-disconnect
35542 @end smallexample
35543
35544 Disconnect from the remote target. There's no output and the target is
35545 generally not resumed.
35546
35547 @subsubheading @value{GDBN} Command
35548
35549 The corresponding @value{GDBN} command is @samp{disconnect}.
35550
35551 @subsubheading Example
35552
35553 @smallexample
35554 (gdb)
35555 -target-disconnect
35556 ^done
35557 (gdb)
35558 @end smallexample
35559
35560
35561 @subheading The @code{-target-download} Command
35562 @findex -target-download
35563
35564 @subsubheading Synopsis
35565
35566 @smallexample
35567 -target-download
35568 @end smallexample
35569
35570 Loads the executable onto the remote target.
35571 It prints out an update message every half second, which includes the fields:
35572
35573 @table @samp
35574 @item section
35575 The name of the section.
35576 @item section-sent
35577 The size of what has been sent so far for that section.
35578 @item section-size
35579 The size of the section.
35580 @item total-sent
35581 The total size of what was sent so far (the current and the previous sections).
35582 @item total-size
35583 The size of the overall executable to download.
35584 @end table
35585
35586 @noindent
35587 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
35588 @sc{gdb/mi} Output Syntax}).
35589
35590 In addition, it prints the name and size of the sections, as they are
35591 downloaded. These messages include the following fields:
35592
35593 @table @samp
35594 @item section
35595 The name of the section.
35596 @item section-size
35597 The size of the section.
35598 @item total-size
35599 The size of the overall executable to download.
35600 @end table
35601
35602 @noindent
35603 At the end, a summary is printed.
35604
35605 @subsubheading @value{GDBN} Command
35606
35607 The corresponding @value{GDBN} command is @samp{load}.
35608
35609 @subsubheading Example
35610
35611 Note: each status message appears on a single line. Here the messages
35612 have been broken down so that they can fit onto a page.
35613
35614 @smallexample
35615 (gdb)
35616 -target-download
35617 +download,@{section=".text",section-size="6668",total-size="9880"@}
35618 +download,@{section=".text",section-sent="512",section-size="6668",
35619 total-sent="512",total-size="9880"@}
35620 +download,@{section=".text",section-sent="1024",section-size="6668",
35621 total-sent="1024",total-size="9880"@}
35622 +download,@{section=".text",section-sent="1536",section-size="6668",
35623 total-sent="1536",total-size="9880"@}
35624 +download,@{section=".text",section-sent="2048",section-size="6668",
35625 total-sent="2048",total-size="9880"@}
35626 +download,@{section=".text",section-sent="2560",section-size="6668",
35627 total-sent="2560",total-size="9880"@}
35628 +download,@{section=".text",section-sent="3072",section-size="6668",
35629 total-sent="3072",total-size="9880"@}
35630 +download,@{section=".text",section-sent="3584",section-size="6668",
35631 total-sent="3584",total-size="9880"@}
35632 +download,@{section=".text",section-sent="4096",section-size="6668",
35633 total-sent="4096",total-size="9880"@}
35634 +download,@{section=".text",section-sent="4608",section-size="6668",
35635 total-sent="4608",total-size="9880"@}
35636 +download,@{section=".text",section-sent="5120",section-size="6668",
35637 total-sent="5120",total-size="9880"@}
35638 +download,@{section=".text",section-sent="5632",section-size="6668",
35639 total-sent="5632",total-size="9880"@}
35640 +download,@{section=".text",section-sent="6144",section-size="6668",
35641 total-sent="6144",total-size="9880"@}
35642 +download,@{section=".text",section-sent="6656",section-size="6668",
35643 total-sent="6656",total-size="9880"@}
35644 +download,@{section=".init",section-size="28",total-size="9880"@}
35645 +download,@{section=".fini",section-size="28",total-size="9880"@}
35646 +download,@{section=".data",section-size="3156",total-size="9880"@}
35647 +download,@{section=".data",section-sent="512",section-size="3156",
35648 total-sent="7236",total-size="9880"@}
35649 +download,@{section=".data",section-sent="1024",section-size="3156",
35650 total-sent="7748",total-size="9880"@}
35651 +download,@{section=".data",section-sent="1536",section-size="3156",
35652 total-sent="8260",total-size="9880"@}
35653 +download,@{section=".data",section-sent="2048",section-size="3156",
35654 total-sent="8772",total-size="9880"@}
35655 +download,@{section=".data",section-sent="2560",section-size="3156",
35656 total-sent="9284",total-size="9880"@}
35657 +download,@{section=".data",section-sent="3072",section-size="3156",
35658 total-sent="9796",total-size="9880"@}
35659 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
35660 write-rate="429"
35661 (gdb)
35662 @end smallexample
35663
35664
35665 @ignore
35666 @subheading The @code{-target-exec-status} Command
35667 @findex -target-exec-status
35668
35669 @subsubheading Synopsis
35670
35671 @smallexample
35672 -target-exec-status
35673 @end smallexample
35674
35675 Provide information on the state of the target (whether it is running or
35676 not, for instance).
35677
35678 @subsubheading @value{GDBN} Command
35679
35680 There's no equivalent @value{GDBN} command.
35681
35682 @subsubheading Example
35683 N.A.
35684
35685
35686 @subheading The @code{-target-list-available-targets} Command
35687 @findex -target-list-available-targets
35688
35689 @subsubheading Synopsis
35690
35691 @smallexample
35692 -target-list-available-targets
35693 @end smallexample
35694
35695 List the possible targets to connect to.
35696
35697 @subsubheading @value{GDBN} Command
35698
35699 The corresponding @value{GDBN} command is @samp{help target}.
35700
35701 @subsubheading Example
35702 N.A.
35703
35704
35705 @subheading The @code{-target-list-current-targets} Command
35706 @findex -target-list-current-targets
35707
35708 @subsubheading Synopsis
35709
35710 @smallexample
35711 -target-list-current-targets
35712 @end smallexample
35713
35714 Describe the current target.
35715
35716 @subsubheading @value{GDBN} Command
35717
35718 The corresponding information is printed by @samp{info file} (among
35719 other things).
35720
35721 @subsubheading Example
35722 N.A.
35723
35724
35725 @subheading The @code{-target-list-parameters} Command
35726 @findex -target-list-parameters
35727
35728 @subsubheading Synopsis
35729
35730 @smallexample
35731 -target-list-parameters
35732 @end smallexample
35733
35734 @c ????
35735 @end ignore
35736
35737 @subsubheading @value{GDBN} Command
35738
35739 No equivalent.
35740
35741 @subsubheading Example
35742 N.A.
35743
35744 @subheading The @code{-target-flash-erase} Command
35745 @findex -target-flash-erase
35746
35747 @subsubheading Synopsis
35748
35749 @smallexample
35750 -target-flash-erase
35751 @end smallexample
35752
35753 Erases all known flash memory regions on the target.
35754
35755 The corresponding @value{GDBN} command is @samp{flash-erase}.
35756
35757 The output is a list of flash regions that have been erased, with starting
35758 addresses and memory region sizes.
35759
35760 @smallexample
35761 (gdb)
35762 -target-flash-erase
35763 ^done,erased-regions=@{address="0x0",size="0x40000"@}
35764 (gdb)
35765 @end smallexample
35766
35767 @subheading The @code{-target-select} Command
35768 @findex -target-select
35769
35770 @subsubheading Synopsis
35771
35772 @smallexample
35773 -target-select @var{type} @var{parameters @dots{}}
35774 @end smallexample
35775
35776 Connect @value{GDBN} to the remote target. This command takes two args:
35777
35778 @table @samp
35779 @item @var{type}
35780 The type of target, for instance @samp{remote}, etc.
35781 @item @var{parameters}
35782 Device names, host names and the like. @xref{Target Commands, ,
35783 Commands for Managing Targets}, for more details.
35784 @end table
35785
35786 The output is a connection notification, followed by the address at
35787 which the target program is, in the following form:
35788
35789 @smallexample
35790 ^connected,addr="@var{address}",func="@var{function name}",
35791 args=[@var{arg list}]
35792 @end smallexample
35793
35794 @subsubheading @value{GDBN} Command
35795
35796 The corresponding @value{GDBN} command is @samp{target}.
35797
35798 @subsubheading Example
35799
35800 @smallexample
35801 (gdb)
35802 -target-select remote /dev/ttya
35803 ^connected,addr="0xfe00a300",func="??",args=[]
35804 (gdb)
35805 @end smallexample
35806
35807 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35808 @node GDB/MI File Transfer Commands
35809 @section @sc{gdb/mi} File Transfer Commands
35810
35811
35812 @subheading The @code{-target-file-put} Command
35813 @findex -target-file-put
35814
35815 @subsubheading Synopsis
35816
35817 @smallexample
35818 -target-file-put @var{hostfile} @var{targetfile}
35819 @end smallexample
35820
35821 Copy file @var{hostfile} from the host system (the machine running
35822 @value{GDBN}) to @var{targetfile} on the target system.
35823
35824 @subsubheading @value{GDBN} Command
35825
35826 The corresponding @value{GDBN} command is @samp{remote put}.
35827
35828 @subsubheading Example
35829
35830 @smallexample
35831 (gdb)
35832 -target-file-put localfile remotefile
35833 ^done
35834 (gdb)
35835 @end smallexample
35836
35837
35838 @subheading The @code{-target-file-get} Command
35839 @findex -target-file-get
35840
35841 @subsubheading Synopsis
35842
35843 @smallexample
35844 -target-file-get @var{targetfile} @var{hostfile}
35845 @end smallexample
35846
35847 Copy file @var{targetfile} from the target system to @var{hostfile}
35848 on the host system.
35849
35850 @subsubheading @value{GDBN} Command
35851
35852 The corresponding @value{GDBN} command is @samp{remote get}.
35853
35854 @subsubheading Example
35855
35856 @smallexample
35857 (gdb)
35858 -target-file-get remotefile localfile
35859 ^done
35860 (gdb)
35861 @end smallexample
35862
35863
35864 @subheading The @code{-target-file-delete} Command
35865 @findex -target-file-delete
35866
35867 @subsubheading Synopsis
35868
35869 @smallexample
35870 -target-file-delete @var{targetfile}
35871 @end smallexample
35872
35873 Delete @var{targetfile} from the target system.
35874
35875 @subsubheading @value{GDBN} Command
35876
35877 The corresponding @value{GDBN} command is @samp{remote delete}.
35878
35879 @subsubheading Example
35880
35881 @smallexample
35882 (gdb)
35883 -target-file-delete remotefile
35884 ^done
35885 (gdb)
35886 @end smallexample
35887
35888
35889 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35890 @node GDB/MI Ada Exceptions Commands
35891 @section Ada Exceptions @sc{gdb/mi} Commands
35892
35893 @subheading The @code{-info-ada-exceptions} Command
35894 @findex -info-ada-exceptions
35895
35896 @subsubheading Synopsis
35897
35898 @smallexample
35899 -info-ada-exceptions [ @var{regexp}]
35900 @end smallexample
35901
35902 List all Ada exceptions defined within the program being debugged.
35903 With a regular expression @var{regexp}, only those exceptions whose
35904 names match @var{regexp} are listed.
35905
35906 @subsubheading @value{GDBN} Command
35907
35908 The corresponding @value{GDBN} command is @samp{info exceptions}.
35909
35910 @subsubheading Result
35911
35912 The result is a table of Ada exceptions. The following columns are
35913 defined for each exception:
35914
35915 @table @samp
35916 @item name
35917 The name of the exception.
35918
35919 @item address
35920 The address of the exception.
35921
35922 @end table
35923
35924 @subsubheading Example
35925
35926 @smallexample
35927 -info-ada-exceptions aint
35928 ^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
35929 hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
35930 @{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
35931 body=[@{name="constraint_error",address="0x0000000000613da0"@},
35932 @{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
35933 @end smallexample
35934
35935 @subheading Catching Ada Exceptions
35936
35937 The commands describing how to ask @value{GDBN} to stop when a program
35938 raises an exception are described at @ref{Ada Exception GDB/MI
35939 Catchpoint Commands}.
35940
35941
35942 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35943 @node GDB/MI Support Commands
35944 @section @sc{gdb/mi} Support Commands
35945
35946 Since new commands and features get regularly added to @sc{gdb/mi},
35947 some commands are available to help front-ends query the debugger
35948 about support for these capabilities. Similarly, it is also possible
35949 to query @value{GDBN} about target support of certain features.
35950
35951 @subheading The @code{-info-gdb-mi-command} Command
35952 @cindex @code{-info-gdb-mi-command}
35953 @findex -info-gdb-mi-command
35954
35955 @subsubheading Synopsis
35956
35957 @smallexample
35958 -info-gdb-mi-command @var{cmd_name}
35959 @end smallexample
35960
35961 Query support for the @sc{gdb/mi} command named @var{cmd_name}.
35962
35963 Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
35964 is technically not part of the command name (@pxref{GDB/MI Input
35965 Syntax}), and thus should be omitted in @var{cmd_name}. However,
35966 for ease of use, this command also accepts the form with the leading
35967 dash.
35968
35969 @subsubheading @value{GDBN} Command
35970
35971 There is no corresponding @value{GDBN} command.
35972
35973 @subsubheading Result
35974
35975 The result is a tuple. There is currently only one field:
35976
35977 @table @samp
35978 @item exists
35979 This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
35980 @code{"false"} otherwise.
35981
35982 @end table
35983
35984 @subsubheading Example
35985
35986 Here is an example where the @sc{gdb/mi} command does not exist:
35987
35988 @smallexample
35989 -info-gdb-mi-command unsupported-command
35990 ^done,command=@{exists="false"@}
35991 @end smallexample
35992
35993 @noindent
35994 And here is an example where the @sc{gdb/mi} command is known
35995 to the debugger:
35996
35997 @smallexample
35998 -info-gdb-mi-command symbol-list-lines
35999 ^done,command=@{exists="true"@}
36000 @end smallexample
36001
36002 @subheading The @code{-list-features} Command
36003 @findex -list-features
36004 @cindex supported @sc{gdb/mi} features, list
36005
36006 Returns a list of particular features of the MI protocol that
36007 this version of gdb implements. A feature can be a command,
36008 or a new field in an output of some command, or even an
36009 important bugfix. While a frontend can sometimes detect presence
36010 of a feature at runtime, it is easier to perform detection at debugger
36011 startup.
36012
36013 The command returns a list of strings, with each string naming an
36014 available feature. Each returned string is just a name, it does not
36015 have any internal structure. The list of possible feature names
36016 is given below.
36017
36018 Example output:
36019
36020 @smallexample
36021 (gdb) -list-features
36022 ^done,result=["feature1","feature2"]
36023 @end smallexample
36024
36025 The current list of features is:
36026
36027 @ftable @samp
36028 @item frozen-varobjs
36029 Indicates support for the @code{-var-set-frozen} command, as well
36030 as possible presence of the @code{frozen} field in the output
36031 of @code{-varobj-create}.
36032 @item pending-breakpoints
36033 Indicates support for the @option{-f} option to the @code{-break-insert}
36034 command.
36035 @item python
36036 Indicates Python scripting support, Python-based
36037 pretty-printing commands, and possible presence of the
36038 @samp{display_hint} field in the output of @code{-var-list-children}
36039 @item thread-info
36040 Indicates support for the @code{-thread-info} command.
36041 @item data-read-memory-bytes
36042 Indicates support for the @code{-data-read-memory-bytes} and the
36043 @code{-data-write-memory-bytes} commands.
36044 @item breakpoint-notifications
36045 Indicates that changes to breakpoints and breakpoints created via the
36046 CLI will be announced via async records.
36047 @item ada-task-info
36048 Indicates support for the @code{-ada-task-info} command.
36049 @item language-option
36050 Indicates that all @sc{gdb/mi} commands accept the @option{--language}
36051 option (@pxref{Context management}).
36052 @item info-gdb-mi-command
36053 Indicates support for the @code{-info-gdb-mi-command} command.
36054 @item undefined-command-error-code
36055 Indicates support for the "undefined-command" error code in error result
36056 records, produced when trying to execute an undefined @sc{gdb/mi} command
36057 (@pxref{GDB/MI Result Records}).
36058 @item exec-run-start-option
36059 Indicates that the @code{-exec-run} command supports the @option{--start}
36060 option (@pxref{GDB/MI Program Execution}).
36061 @item data-disassemble-a-option
36062 Indicates that the @code{-data-disassemble} command supports the @option{-a}
36063 option (@pxref{GDB/MI Data Manipulation}).
36064 @end ftable
36065
36066 @subheading The @code{-list-target-features} Command
36067 @findex -list-target-features
36068
36069 Returns a list of particular features that are supported by the
36070 target. Those features affect the permitted MI commands, but
36071 unlike the features reported by the @code{-list-features} command, the
36072 features depend on which target GDB is using at the moment. Whenever
36073 a target can change, due to commands such as @code{-target-select},
36074 @code{-target-attach} or @code{-exec-run}, the list of target features
36075 may change, and the frontend should obtain it again.
36076 Example output:
36077
36078 @smallexample
36079 (gdb) -list-target-features
36080 ^done,result=["async"]
36081 @end smallexample
36082
36083 The current list of features is:
36084
36085 @table @samp
36086 @item async
36087 Indicates that the target is capable of asynchronous command
36088 execution, which means that @value{GDBN} will accept further commands
36089 while the target is running.
36090
36091 @item reverse
36092 Indicates that the target is capable of reverse execution.
36093 @xref{Reverse Execution}, for more information.
36094
36095 @end table
36096
36097 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36098 @node GDB/MI Miscellaneous Commands
36099 @section Miscellaneous @sc{gdb/mi} Commands
36100
36101 @c @subheading -gdb-complete
36102
36103 @subheading The @code{-gdb-exit} Command
36104 @findex -gdb-exit
36105
36106 @subsubheading Synopsis
36107
36108 @smallexample
36109 -gdb-exit
36110 @end smallexample
36111
36112 Exit @value{GDBN} immediately.
36113
36114 @subsubheading @value{GDBN} Command
36115
36116 Approximately corresponds to @samp{quit}.
36117
36118 @subsubheading Example
36119
36120 @smallexample
36121 (gdb)
36122 -gdb-exit
36123 ^exit
36124 @end smallexample
36125
36126
36127 @ignore
36128 @subheading The @code{-exec-abort} Command
36129 @findex -exec-abort
36130
36131 @subsubheading Synopsis
36132
36133 @smallexample
36134 -exec-abort
36135 @end smallexample
36136
36137 Kill the inferior running program.
36138
36139 @subsubheading @value{GDBN} Command
36140
36141 The corresponding @value{GDBN} command is @samp{kill}.
36142
36143 @subsubheading Example
36144 N.A.
36145 @end ignore
36146
36147
36148 @subheading The @code{-gdb-set} Command
36149 @findex -gdb-set
36150
36151 @subsubheading Synopsis
36152
36153 @smallexample
36154 -gdb-set
36155 @end smallexample
36156
36157 Set an internal @value{GDBN} variable.
36158 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
36159
36160 @subsubheading @value{GDBN} Command
36161
36162 The corresponding @value{GDBN} command is @samp{set}.
36163
36164 @subsubheading Example
36165
36166 @smallexample
36167 (gdb)
36168 -gdb-set $foo=3
36169 ^done
36170 (gdb)
36171 @end smallexample
36172
36173
36174 @subheading The @code{-gdb-show} Command
36175 @findex -gdb-show
36176
36177 @subsubheading Synopsis
36178
36179 @smallexample
36180 -gdb-show
36181 @end smallexample
36182
36183 Show the current value of a @value{GDBN} variable.
36184
36185 @subsubheading @value{GDBN} Command
36186
36187 The corresponding @value{GDBN} command is @samp{show}.
36188
36189 @subsubheading Example
36190
36191 @smallexample
36192 (gdb)
36193 -gdb-show annotate
36194 ^done,value="0"
36195 (gdb)
36196 @end smallexample
36197
36198 @c @subheading -gdb-source
36199
36200
36201 @subheading The @code{-gdb-version} Command
36202 @findex -gdb-version
36203
36204 @subsubheading Synopsis
36205
36206 @smallexample
36207 -gdb-version
36208 @end smallexample
36209
36210 Show version information for @value{GDBN}. Used mostly in testing.
36211
36212 @subsubheading @value{GDBN} Command
36213
36214 The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
36215 default shows this information when you start an interactive session.
36216
36217 @subsubheading Example
36218
36219 @c This example modifies the actual output from GDB to avoid overfull
36220 @c box in TeX.
36221 @smallexample
36222 (gdb)
36223 -gdb-version
36224 ~GNU gdb 5.2.1
36225 ~Copyright 2000 Free Software Foundation, Inc.
36226 ~GDB is free software, covered by the GNU General Public License, and
36227 ~you are welcome to change it and/or distribute copies of it under
36228 ~ certain conditions.
36229 ~Type "show copying" to see the conditions.
36230 ~There is absolutely no warranty for GDB. Type "show warranty" for
36231 ~ details.
36232 ~This GDB was configured as
36233 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
36234 ^done
36235 (gdb)
36236 @end smallexample
36237
36238 @subheading The @code{-list-thread-groups} Command
36239 @findex -list-thread-groups
36240
36241 @subheading Synopsis
36242
36243 @smallexample
36244 -list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
36245 @end smallexample
36246
36247 Lists thread groups (@pxref{Thread groups}). When a single thread
36248 group is passed as the argument, lists the children of that group.
36249 When several thread group are passed, lists information about those
36250 thread groups. Without any parameters, lists information about all
36251 top-level thread groups.
36252
36253 Normally, thread groups that are being debugged are reported.
36254 With the @samp{--available} option, @value{GDBN} reports thread groups
36255 available on the target.
36256
36257 The output of this command may have either a @samp{threads} result or
36258 a @samp{groups} result. The @samp{thread} result has a list of tuples
36259 as value, with each tuple describing a thread (@pxref{GDB/MI Thread
36260 Information}). The @samp{groups} result has a list of tuples as value,
36261 each tuple describing a thread group. If top-level groups are
36262 requested (that is, no parameter is passed), or when several groups
36263 are passed, the output always has a @samp{groups} result. The format
36264 of the @samp{group} result is described below.
36265
36266 To reduce the number of roundtrips it's possible to list thread groups
36267 together with their children, by passing the @samp{--recurse} option
36268 and the recursion depth. Presently, only recursion depth of 1 is
36269 permitted. If this option is present, then every reported thread group
36270 will also include its children, either as @samp{group} or
36271 @samp{threads} field.
36272
36273 In general, any combination of option and parameters is permitted, with
36274 the following caveats:
36275
36276 @itemize @bullet
36277 @item
36278 When a single thread group is passed, the output will typically
36279 be the @samp{threads} result. Because threads may not contain
36280 anything, the @samp{recurse} option will be ignored.
36281
36282 @item
36283 When the @samp{--available} option is passed, limited information may
36284 be available. In particular, the list of threads of a process might
36285 be inaccessible. Further, specifying specific thread groups might
36286 not give any performance advantage over listing all thread groups.
36287 The frontend should assume that @samp{-list-thread-groups --available}
36288 is always an expensive operation and cache the results.
36289
36290 @end itemize
36291
36292 The @samp{groups} result is a list of tuples, where each tuple may
36293 have the following fields:
36294
36295 @table @code
36296 @item id
36297 Identifier of the thread group. This field is always present.
36298 The identifier is an opaque string; frontends should not try to
36299 convert it to an integer, even though it might look like one.
36300
36301 @item type
36302 The type of the thread group. At present, only @samp{process} is a
36303 valid type.
36304
36305 @item pid
36306 The target-specific process identifier. This field is only present
36307 for thread groups of type @samp{process} and only if the process exists.
36308
36309 @item exit-code
36310 The exit code of this group's last exited thread, formatted in octal.
36311 This field is only present for thread groups of type @samp{process} and
36312 only if the process is not running.
36313
36314 @item num_children
36315 The number of children this thread group has. This field may be
36316 absent for an available thread group.
36317
36318 @item threads
36319 This field has a list of tuples as value, each tuple describing a
36320 thread. It may be present if the @samp{--recurse} option is
36321 specified, and it's actually possible to obtain the threads.
36322
36323 @item cores
36324 This field is a list of integers, each identifying a core that one
36325 thread of the group is running on. This field may be absent if
36326 such information is not available.
36327
36328 @item executable
36329 The name of the executable file that corresponds to this thread group.
36330 The field is only present for thread groups of type @samp{process},
36331 and only if there is a corresponding executable file.
36332
36333 @end table
36334
36335 @subheading Example
36336
36337 @smallexample
36338 @value{GDBP}
36339 -list-thread-groups
36340 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
36341 -list-thread-groups 17
36342 ^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
36343 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
36344 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
36345 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
36346 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
36347 -list-thread-groups --available
36348 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
36349 -list-thread-groups --available --recurse 1
36350 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36351 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36352 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
36353 -list-thread-groups --available --recurse 1 17 18
36354 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36355 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36356 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
36357 @end smallexample
36358
36359 @subheading The @code{-info-os} Command
36360 @findex -info-os
36361
36362 @subsubheading Synopsis
36363
36364 @smallexample
36365 -info-os [ @var{type} ]
36366 @end smallexample
36367
36368 If no argument is supplied, the command returns a table of available
36369 operating-system-specific information types. If one of these types is
36370 supplied as an argument @var{type}, then the command returns a table
36371 of data of that type.
36372
36373 The types of information available depend on the target operating
36374 system.
36375
36376 @subsubheading @value{GDBN} Command
36377
36378 The corresponding @value{GDBN} command is @samp{info os}.
36379
36380 @subsubheading Example
36381
36382 When run on a @sc{gnu}/Linux system, the output will look something
36383 like this:
36384
36385 @smallexample
36386 @value{GDBP}
36387 -info-os
36388 ^done,OSDataTable=@{nr_rows="10",nr_cols="3",
36389 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
36390 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
36391 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
36392 body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
36393 col2="CPUs"@},
36394 item=@{col0="files",col1="Listing of all file descriptors",
36395 col2="File descriptors"@},
36396 item=@{col0="modules",col1="Listing of all loaded kernel modules",
36397 col2="Kernel modules"@},
36398 item=@{col0="msg",col1="Listing of all message queues",
36399 col2="Message queues"@},
36400 item=@{col0="processes",col1="Listing of all processes",
36401 col2="Processes"@},
36402 item=@{col0="procgroups",col1="Listing of all process groups",
36403 col2="Process groups"@},
36404 item=@{col0="semaphores",col1="Listing of all semaphores",
36405 col2="Semaphores"@},
36406 item=@{col0="shm",col1="Listing of all shared-memory regions",
36407 col2="Shared-memory regions"@},
36408 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
36409 col2="Sockets"@},
36410 item=@{col0="threads",col1="Listing of all threads",
36411 col2="Threads"@}]
36412 @value{GDBP}
36413 -info-os processes
36414 ^done,OSDataTable=@{nr_rows="190",nr_cols="4",
36415 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
36416 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
36417 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
36418 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
36419 body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
36420 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
36421 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
36422 ...
36423 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
36424 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
36425 (gdb)
36426 @end smallexample
36427
36428 (Note that the MI output here includes a @code{"Title"} column that
36429 does not appear in command-line @code{info os}; this column is useful
36430 for MI clients that want to enumerate the types of data, such as in a
36431 popup menu, but is needless clutter on the command line, and
36432 @code{info os} omits it.)
36433
36434 @subheading The @code{-add-inferior} Command
36435 @findex -add-inferior
36436
36437 @subheading Synopsis
36438
36439 @smallexample
36440 -add-inferior
36441 @end smallexample
36442
36443 Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
36444 inferior is not associated with any executable. Such association may
36445 be established with the @samp{-file-exec-and-symbols} command
36446 (@pxref{GDB/MI File Commands}). The command response has a single
36447 field, @samp{inferior}, whose value is the identifier of the
36448 thread group corresponding to the new inferior.
36449
36450 @subheading Example
36451
36452 @smallexample
36453 @value{GDBP}
36454 -add-inferior
36455 ^done,inferior="i3"
36456 @end smallexample
36457
36458 @subheading The @code{-interpreter-exec} Command
36459 @findex -interpreter-exec
36460
36461 @subheading Synopsis
36462
36463 @smallexample
36464 -interpreter-exec @var{interpreter} @var{command}
36465 @end smallexample
36466 @anchor{-interpreter-exec}
36467
36468 Execute the specified @var{command} in the given @var{interpreter}.
36469
36470 @subheading @value{GDBN} Command
36471
36472 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
36473
36474 @subheading Example
36475
36476 @smallexample
36477 (gdb)
36478 -interpreter-exec console "break main"
36479 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
36480 &"During symbol reading, bad structure-type format.\n"
36481 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
36482 ^done
36483 (gdb)
36484 @end smallexample
36485
36486 @subheading The @code{-inferior-tty-set} Command
36487 @findex -inferior-tty-set
36488
36489 @subheading Synopsis
36490
36491 @smallexample
36492 -inferior-tty-set /dev/pts/1
36493 @end smallexample
36494
36495 Set terminal for future runs of the program being debugged.
36496
36497 @subheading @value{GDBN} Command
36498
36499 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
36500
36501 @subheading Example
36502
36503 @smallexample
36504 (gdb)
36505 -inferior-tty-set /dev/pts/1
36506 ^done
36507 (gdb)
36508 @end smallexample
36509
36510 @subheading The @code{-inferior-tty-show} Command
36511 @findex -inferior-tty-show
36512
36513 @subheading Synopsis
36514
36515 @smallexample
36516 -inferior-tty-show
36517 @end smallexample
36518
36519 Show terminal for future runs of program being debugged.
36520
36521 @subheading @value{GDBN} Command
36522
36523 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
36524
36525 @subheading Example
36526
36527 @smallexample
36528 (gdb)
36529 -inferior-tty-set /dev/pts/1
36530 ^done
36531 (gdb)
36532 -inferior-tty-show
36533 ^done,inferior_tty_terminal="/dev/pts/1"
36534 (gdb)
36535 @end smallexample
36536
36537 @subheading The @code{-enable-timings} Command
36538 @findex -enable-timings
36539
36540 @subheading Synopsis
36541
36542 @smallexample
36543 -enable-timings [yes | no]
36544 @end smallexample
36545
36546 Toggle the printing of the wallclock, user and system times for an MI
36547 command as a field in its output. This command is to help frontend
36548 developers optimize the performance of their code. No argument is
36549 equivalent to @samp{yes}.
36550
36551 @subheading @value{GDBN} Command
36552
36553 No equivalent.
36554
36555 @subheading Example
36556
36557 @smallexample
36558 (gdb)
36559 -enable-timings
36560 ^done
36561 (gdb)
36562 -break-insert main
36563 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
36564 addr="0x080484ed",func="main",file="myprog.c",
36565 fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
36566 times="0"@},
36567 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
36568 (gdb)
36569 -enable-timings no
36570 ^done
36571 (gdb)
36572 -exec-run
36573 ^running
36574 (gdb)
36575 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
36576 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
36577 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
36578 fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
36579 (gdb)
36580 @end smallexample
36581
36582 @subheading The @code{-complete} Command
36583 @findex -complete
36584
36585 @subheading Synopsis
36586
36587 @smallexample
36588 -complete @var{command}
36589 @end smallexample
36590
36591 Show a list of completions for partially typed CLI @var{command}.
36592
36593 This command is intended for @sc{gdb/mi} frontends that cannot use two separate
36594 CLI and MI channels --- for example: because of lack of PTYs like on Windows or
36595 because @value{GDBN} is used remotely via a SSH connection.
36596
36597 @subheading Result
36598
36599 The result consists of two or three fields:
36600
36601 @table @samp
36602 @item completion
36603 This field contains the completed @var{command}. If @var{command}
36604 has no known completions, this field is omitted.
36605
36606 @item matches
36607 This field contains a (possibly empty) array of matches. It is always present.
36608
36609 @item max_completions_reached
36610 This field contains @code{1} if number of known completions is above
36611 @code{max-completions} limit (@pxref{Completion}), otherwise it contains
36612 @code{0}. It is always present.
36613
36614 @end table
36615
36616 @subheading @value{GDBN} Command
36617
36618 The corresponding @value{GDBN} command is @samp{complete}.
36619
36620 @subheading Example
36621
36622 @smallexample
36623 (gdb)
36624 -complete br
36625 ^done,completion="break",
36626 matches=["break","break-range"],
36627 max_completions_reached="0"
36628 (gdb)
36629 -complete "b ma"
36630 ^done,completion="b ma",
36631 matches=["b madvise","b main"],max_completions_reached="0"
36632 (gdb)
36633 -complete "b push_b"
36634 ^done,completion="b push_back(",
36635 matches=[
36636 "b A::push_back(void*)",
36637 "b std::string::push_back(char)",
36638 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
36639 max_completions_reached="0"
36640 (gdb)
36641 -complete "nonexist"
36642 ^done,matches=[],max_completions_reached="0"
36643 (gdb)
36644
36645 @end smallexample
36646
36647 @node Annotations
36648 @chapter @value{GDBN} Annotations
36649
36650 This chapter describes annotations in @value{GDBN}. Annotations were
36651 designed to interface @value{GDBN} to graphical user interfaces or other
36652 similar programs which want to interact with @value{GDBN} at a
36653 relatively high level.
36654
36655 The annotation mechanism has largely been superseded by @sc{gdb/mi}
36656 (@pxref{GDB/MI}).
36657
36658 @ignore
36659 This is Edition @value{EDITION}, @value{DATE}.
36660 @end ignore
36661
36662 @menu
36663 * Annotations Overview:: What annotations are; the general syntax.
36664 * Server Prefix:: Issuing a command without affecting user state.
36665 * Prompting:: Annotations marking @value{GDBN}'s need for input.
36666 * Errors:: Annotations for error messages.
36667 * Invalidation:: Some annotations describe things now invalid.
36668 * Annotations for Running::
36669 Whether the program is running, how it stopped, etc.
36670 * Source Annotations:: Annotations describing source code.
36671 @end menu
36672
36673 @node Annotations Overview
36674 @section What is an Annotation?
36675 @cindex annotations
36676
36677 Annotations start with a newline character, two @samp{control-z}
36678 characters, and the name of the annotation. If there is no additional
36679 information associated with this annotation, the name of the annotation
36680 is followed immediately by a newline. If there is additional
36681 information, the name of the annotation is followed by a space, the
36682 additional information, and a newline. The additional information
36683 cannot contain newline characters.
36684
36685 Any output not beginning with a newline and two @samp{control-z}
36686 characters denotes literal output from @value{GDBN}. Currently there is
36687 no need for @value{GDBN} to output a newline followed by two
36688 @samp{control-z} characters, but if there was such a need, the
36689 annotations could be extended with an @samp{escape} annotation which
36690 means those three characters as output.
36691
36692 The annotation @var{level}, which is specified using the
36693 @option{--annotate} command line option (@pxref{Mode Options}), controls
36694 how much information @value{GDBN} prints together with its prompt,
36695 values of expressions, source lines, and other types of output. Level 0
36696 is for no annotations, level 1 is for use when @value{GDBN} is run as a
36697 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
36698 for programs that control @value{GDBN}, and level 2 annotations have
36699 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
36700 Interface, annotate, GDB's Obsolete Annotations}).
36701
36702 @table @code
36703 @kindex set annotate
36704 @item set annotate @var{level}
36705 The @value{GDBN} command @code{set annotate} sets the level of
36706 annotations to the specified @var{level}.
36707
36708 @item show annotate
36709 @kindex show annotate
36710 Show the current annotation level.
36711 @end table
36712
36713 This chapter describes level 3 annotations.
36714
36715 A simple example of starting up @value{GDBN} with annotations is:
36716
36717 @smallexample
36718 $ @kbd{gdb --annotate=3}
36719 GNU gdb 6.0
36720 Copyright 2003 Free Software Foundation, Inc.
36721 GDB is free software, covered by the GNU General Public License,
36722 and you are welcome to change it and/or distribute copies of it
36723 under certain conditions.
36724 Type "show copying" to see the conditions.
36725 There is absolutely no warranty for GDB. Type "show warranty"
36726 for details.
36727 This GDB was configured as "i386-pc-linux-gnu"
36728
36729 ^Z^Zpre-prompt
36730 (@value{GDBP})
36731 ^Z^Zprompt
36732 @kbd{quit}
36733
36734 ^Z^Zpost-prompt
36735 $
36736 @end smallexample
36737
36738 Here @samp{quit} is input to @value{GDBN}; the rest is output from
36739 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
36740 denotes a @samp{control-z} character) are annotations; the rest is
36741 output from @value{GDBN}.
36742
36743 @node Server Prefix
36744 @section The Server Prefix
36745 @cindex server prefix
36746
36747 If you prefix a command with @samp{server } then it will not affect
36748 the command history, nor will it affect @value{GDBN}'s notion of which
36749 command to repeat if @key{RET} is pressed on a line by itself. This
36750 means that commands can be run behind a user's back by a front-end in
36751 a transparent manner.
36752
36753 The @code{server } prefix does not affect the recording of values into
36754 the value history; to print a value without recording it into the
36755 value history, use the @code{output} command instead of the
36756 @code{print} command.
36757
36758 Using this prefix also disables confirmation requests
36759 (@pxref{confirmation requests}).
36760
36761 @node Prompting
36762 @section Annotation for @value{GDBN} Input
36763
36764 @cindex annotations for prompts
36765 When @value{GDBN} prompts for input, it annotates this fact so it is possible
36766 to know when to send output, when the output from a given command is
36767 over, etc.
36768
36769 Different kinds of input each have a different @dfn{input type}. Each
36770 input type has three annotations: a @code{pre-} annotation, which
36771 denotes the beginning of any prompt which is being output, a plain
36772 annotation, which denotes the end of the prompt, and then a @code{post-}
36773 annotation which denotes the end of any echo which may (or may not) be
36774 associated with the input. For example, the @code{prompt} input type
36775 features the following annotations:
36776
36777 @smallexample
36778 ^Z^Zpre-prompt
36779 ^Z^Zprompt
36780 ^Z^Zpost-prompt
36781 @end smallexample
36782
36783 The input types are
36784
36785 @table @code
36786 @findex pre-prompt annotation
36787 @findex prompt annotation
36788 @findex post-prompt annotation
36789 @item prompt
36790 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
36791
36792 @findex pre-commands annotation
36793 @findex commands annotation
36794 @findex post-commands annotation
36795 @item commands
36796 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
36797 command. The annotations are repeated for each command which is input.
36798
36799 @findex pre-overload-choice annotation
36800 @findex overload-choice annotation
36801 @findex post-overload-choice annotation
36802 @item overload-choice
36803 When @value{GDBN} wants the user to select between various overloaded functions.
36804
36805 @findex pre-query annotation
36806 @findex query annotation
36807 @findex post-query annotation
36808 @item query
36809 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
36810
36811 @findex pre-prompt-for-continue annotation
36812 @findex prompt-for-continue annotation
36813 @findex post-prompt-for-continue annotation
36814 @item prompt-for-continue
36815 When @value{GDBN} is asking the user to press return to continue. Note: Don't
36816 expect this to work well; instead use @code{set height 0} to disable
36817 prompting. This is because the counting of lines is buggy in the
36818 presence of annotations.
36819 @end table
36820
36821 @node Errors
36822 @section Errors
36823 @cindex annotations for errors, warnings and interrupts
36824
36825 @findex quit annotation
36826 @smallexample
36827 ^Z^Zquit
36828 @end smallexample
36829
36830 This annotation occurs right before @value{GDBN} responds to an interrupt.
36831
36832 @findex error annotation
36833 @smallexample
36834 ^Z^Zerror
36835 @end smallexample
36836
36837 This annotation occurs right before @value{GDBN} responds to an error.
36838
36839 Quit and error annotations indicate that any annotations which @value{GDBN} was
36840 in the middle of may end abruptly. For example, if a
36841 @code{value-history-begin} annotation is followed by a @code{error}, one
36842 cannot expect to receive the matching @code{value-history-end}. One
36843 cannot expect not to receive it either, however; an error annotation
36844 does not necessarily mean that @value{GDBN} is immediately returning all the way
36845 to the top level.
36846
36847 @findex error-begin annotation
36848 A quit or error annotation may be preceded by
36849
36850 @smallexample
36851 ^Z^Zerror-begin
36852 @end smallexample
36853
36854 Any output between that and the quit or error annotation is the error
36855 message.
36856
36857 Warning messages are not yet annotated.
36858 @c If we want to change that, need to fix warning(), type_error(),
36859 @c range_error(), and possibly other places.
36860
36861 @node Invalidation
36862 @section Invalidation Notices
36863
36864 @cindex annotations for invalidation messages
36865 The following annotations say that certain pieces of state may have
36866 changed.
36867
36868 @table @code
36869 @findex frames-invalid annotation
36870 @item ^Z^Zframes-invalid
36871
36872 The frames (for example, output from the @code{backtrace} command) may
36873 have changed.
36874
36875 @findex breakpoints-invalid annotation
36876 @item ^Z^Zbreakpoints-invalid
36877
36878 The breakpoints may have changed. For example, the user just added or
36879 deleted a breakpoint.
36880 @end table
36881
36882 @node Annotations for Running
36883 @section Running the Program
36884 @cindex annotations for running programs
36885
36886 @findex starting annotation
36887 @findex stopping annotation
36888 When the program starts executing due to a @value{GDBN} command such as
36889 @code{step} or @code{continue},
36890
36891 @smallexample
36892 ^Z^Zstarting
36893 @end smallexample
36894
36895 is output. When the program stops,
36896
36897 @smallexample
36898 ^Z^Zstopped
36899 @end smallexample
36900
36901 is output. Before the @code{stopped} annotation, a variety of
36902 annotations describe how the program stopped.
36903
36904 @table @code
36905 @findex exited annotation
36906 @item ^Z^Zexited @var{exit-status}
36907 The program exited, and @var{exit-status} is the exit status (zero for
36908 successful exit, otherwise nonzero).
36909
36910 @findex signalled annotation
36911 @findex signal-name annotation
36912 @findex signal-name-end annotation
36913 @findex signal-string annotation
36914 @findex signal-string-end annotation
36915 @item ^Z^Zsignalled
36916 The program exited with a signal. After the @code{^Z^Zsignalled}, the
36917 annotation continues:
36918
36919 @smallexample
36920 @var{intro-text}
36921 ^Z^Zsignal-name
36922 @var{name}
36923 ^Z^Zsignal-name-end
36924 @var{middle-text}
36925 ^Z^Zsignal-string
36926 @var{string}
36927 ^Z^Zsignal-string-end
36928 @var{end-text}
36929 @end smallexample
36930
36931 @noindent
36932 where @var{name} is the name of the signal, such as @code{SIGILL} or
36933 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
36934 as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
36935 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
36936 user's benefit and have no particular format.
36937
36938 @findex signal annotation
36939 @item ^Z^Zsignal
36940 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
36941 just saying that the program received the signal, not that it was
36942 terminated with it.
36943
36944 @findex breakpoint annotation
36945 @item ^Z^Zbreakpoint @var{number}
36946 The program hit breakpoint number @var{number}.
36947
36948 @findex watchpoint annotation
36949 @item ^Z^Zwatchpoint @var{number}
36950 The program hit watchpoint number @var{number}.
36951 @end table
36952
36953 @node Source Annotations
36954 @section Displaying Source
36955 @cindex annotations for source display
36956
36957 @findex source annotation
36958 The following annotation is used instead of displaying source code:
36959
36960 @smallexample
36961 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
36962 @end smallexample
36963
36964 where @var{filename} is an absolute file name indicating which source
36965 file, @var{line} is the line number within that file (where 1 is the
36966 first line in the file), @var{character} is the character position
36967 within the file (where 0 is the first character in the file) (for most
36968 debug formats this will necessarily point to the beginning of a line),
36969 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
36970 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
36971 @var{addr} is the address in the target program associated with the
36972 source which is being displayed. The @var{addr} is in the form @samp{0x}
36973 followed by one or more lowercase hex digits (note that this does not
36974 depend on the language).
36975
36976 @node JIT Interface
36977 @chapter JIT Compilation Interface
36978 @cindex just-in-time compilation
36979 @cindex JIT compilation interface
36980
36981 This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
36982 interface. A JIT compiler is a program or library that generates native
36983 executable code at runtime and executes it, usually in order to achieve good
36984 performance while maintaining platform independence.
36985
36986 Programs that use JIT compilation are normally difficult to debug because
36987 portions of their code are generated at runtime, instead of being loaded from
36988 object files, which is where @value{GDBN} normally finds the program's symbols
36989 and debug information. In order to debug programs that use JIT compilation,
36990 @value{GDBN} has an interface that allows the program to register in-memory
36991 symbol files with @value{GDBN} at runtime.
36992
36993 If you are using @value{GDBN} to debug a program that uses this interface, then
36994 it should work transparently so long as you have not stripped the binary. If
36995 you are developing a JIT compiler, then the interface is documented in the rest
36996 of this chapter. At this time, the only known client of this interface is the
36997 LLVM JIT.
36998
36999 Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
37000 JIT compiler communicates with @value{GDBN} by writing data into a global
37001 variable and calling a function at a well-known symbol. When @value{GDBN}
37002 attaches, it reads a linked list of symbol files from the global variable to
37003 find existing code, and puts a breakpoint in the function so that it can find
37004 out about additional code.
37005
37006 @menu
37007 * Declarations:: Relevant C struct declarations
37008 * Registering Code:: Steps to register code
37009 * Unregistering Code:: Steps to unregister code
37010 * Custom Debug Info:: Emit debug information in a custom format
37011 @end menu
37012
37013 @node Declarations
37014 @section JIT Declarations
37015
37016 These are the relevant struct declarations that a C program should include to
37017 implement the interface:
37018
37019 @smallexample
37020 typedef enum
37021 @{
37022 JIT_NOACTION = 0,
37023 JIT_REGISTER_FN,
37024 JIT_UNREGISTER_FN
37025 @} jit_actions_t;
37026
37027 struct jit_code_entry
37028 @{
37029 struct jit_code_entry *next_entry;
37030 struct jit_code_entry *prev_entry;
37031 const char *symfile_addr;
37032 uint64_t symfile_size;
37033 @};
37034
37035 struct jit_descriptor
37036 @{
37037 uint32_t version;
37038 /* This type should be jit_actions_t, but we use uint32_t
37039 to be explicit about the bitwidth. */
37040 uint32_t action_flag;
37041 struct jit_code_entry *relevant_entry;
37042 struct jit_code_entry *first_entry;
37043 @};
37044
37045 /* GDB puts a breakpoint in this function. */
37046 void __attribute__((noinline)) __jit_debug_register_code() @{ @};
37047
37048 /* Make sure to specify the version statically, because the
37049 debugger may check the version before we can set it. */
37050 struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
37051 @end smallexample
37052
37053 If the JIT is multi-threaded, then it is important that the JIT synchronize any
37054 modifications to this global data properly, which can easily be done by putting
37055 a global mutex around modifications to these structures.
37056
37057 @node Registering Code
37058 @section Registering Code
37059
37060 To register code with @value{GDBN}, the JIT should follow this protocol:
37061
37062 @itemize @bullet
37063 @item
37064 Generate an object file in memory with symbols and other desired debug
37065 information. The file must include the virtual addresses of the sections.
37066
37067 @item
37068 Create a code entry for the file, which gives the start and size of the symbol
37069 file.
37070
37071 @item
37072 Add it to the linked list in the JIT descriptor.
37073
37074 @item
37075 Point the relevant_entry field of the descriptor at the entry.
37076
37077 @item
37078 Set @code{action_flag} to @code{JIT_REGISTER} and call
37079 @code{__jit_debug_register_code}.
37080 @end itemize
37081
37082 When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
37083 @code{relevant_entry} pointer so it doesn't have to walk the list looking for
37084 new code. However, the linked list must still be maintained in order to allow
37085 @value{GDBN} to attach to a running process and still find the symbol files.
37086
37087 @node Unregistering Code
37088 @section Unregistering Code
37089
37090 If code is freed, then the JIT should use the following protocol:
37091
37092 @itemize @bullet
37093 @item
37094 Remove the code entry corresponding to the code from the linked list.
37095
37096 @item
37097 Point the @code{relevant_entry} field of the descriptor at the code entry.
37098
37099 @item
37100 Set @code{action_flag} to @code{JIT_UNREGISTER} and call
37101 @code{__jit_debug_register_code}.
37102 @end itemize
37103
37104 If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
37105 and the JIT will leak the memory used for the associated symbol files.
37106
37107 @node Custom Debug Info
37108 @section Custom Debug Info
37109 @cindex custom JIT debug info
37110 @cindex JIT debug info reader
37111
37112 Generating debug information in platform-native file formats (like ELF
37113 or COFF) may be an overkill for JIT compilers; especially if all the
37114 debug info is used for is displaying a meaningful backtrace. The
37115 issue can be resolved by having the JIT writers decide on a debug info
37116 format and also provide a reader that parses the debug info generated
37117 by the JIT compiler. This section gives a brief overview on writing
37118 such a parser. More specific details can be found in the source file
37119 @file{gdb/jit-reader.in}, which is also installed as a header at
37120 @file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
37121
37122 The reader is implemented as a shared object (so this functionality is
37123 not available on platforms which don't allow loading shared objects at
37124 runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
37125 @code{jit-reader-unload} are provided, to be used to load and unload
37126 the readers from a preconfigured directory. Once loaded, the shared
37127 object is used the parse the debug information emitted by the JIT
37128 compiler.
37129
37130 @menu
37131 * Using JIT Debug Info Readers:: How to use supplied readers correctly
37132 * Writing JIT Debug Info Readers:: Creating a debug-info reader
37133 @end menu
37134
37135 @node Using JIT Debug Info Readers
37136 @subsection Using JIT Debug Info Readers
37137 @kindex jit-reader-load
37138 @kindex jit-reader-unload
37139
37140 Readers can be loaded and unloaded using the @code{jit-reader-load}
37141 and @code{jit-reader-unload} commands.
37142
37143 @table @code
37144 @item jit-reader-load @var{reader}
37145 Load the JIT reader named @var{reader}, which is a shared
37146 object specified as either an absolute or a relative file name. In
37147 the latter case, @value{GDBN} will try to load the reader from a
37148 pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
37149 system (here @var{libdir} is the system library directory, often
37150 @file{/usr/local/lib}).
37151
37152 Only one reader can be active at a time; trying to load a second
37153 reader when one is already loaded will result in @value{GDBN}
37154 reporting an error. A new JIT reader can be loaded by first unloading
37155 the current one using @code{jit-reader-unload} and then invoking
37156 @code{jit-reader-load}.
37157
37158 @item jit-reader-unload
37159 Unload the currently loaded JIT reader.
37160
37161 @end table
37162
37163 @node Writing JIT Debug Info Readers
37164 @subsection Writing JIT Debug Info Readers
37165 @cindex writing JIT debug info readers
37166
37167 As mentioned, a reader is essentially a shared object conforming to a
37168 certain ABI. This ABI is described in @file{jit-reader.h}.
37169
37170 @file{jit-reader.h} defines the structures, macros and functions
37171 required to write a reader. It is installed (along with
37172 @value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
37173 the system include directory.
37174
37175 Readers need to be released under a GPL compatible license. A reader
37176 can be declared as released under such a license by placing the macro
37177 @code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
37178
37179 The entry point for readers is the symbol @code{gdb_init_reader},
37180 which is expected to be a function with the prototype
37181
37182 @findex gdb_init_reader
37183 @smallexample
37184 extern struct gdb_reader_funcs *gdb_init_reader (void);
37185 @end smallexample
37186
37187 @cindex @code{struct gdb_reader_funcs}
37188
37189 @code{struct gdb_reader_funcs} contains a set of pointers to callback
37190 functions. These functions are executed to read the debug info
37191 generated by the JIT compiler (@code{read}), to unwind stack frames
37192 (@code{unwind}) and to create canonical frame IDs
37193 (@code{get_frame_id}). It also has a callback that is called when the
37194 reader is being unloaded (@code{destroy}). The struct looks like this
37195
37196 @smallexample
37197 struct gdb_reader_funcs
37198 @{
37199 /* Must be set to GDB_READER_INTERFACE_VERSION. */
37200 int reader_version;
37201
37202 /* For use by the reader. */
37203 void *priv_data;
37204
37205 gdb_read_debug_info *read;
37206 gdb_unwind_frame *unwind;
37207 gdb_get_frame_id *get_frame_id;
37208 gdb_destroy_reader *destroy;
37209 @};
37210 @end smallexample
37211
37212 @cindex @code{struct gdb_symbol_callbacks}
37213 @cindex @code{struct gdb_unwind_callbacks}
37214
37215 The callbacks are provided with another set of callbacks by
37216 @value{GDBN} to do their job. For @code{read}, these callbacks are
37217 passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
37218 and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
37219 @code{struct gdb_symbol_callbacks} has callbacks to create new object
37220 files and new symbol tables inside those object files. @code{struct
37221 gdb_unwind_callbacks} has callbacks to read registers off the current
37222 frame and to write out the values of the registers in the previous
37223 frame. Both have a callback (@code{target_read}) to read bytes off the
37224 target's address space.
37225
37226 @node In-Process Agent
37227 @chapter In-Process Agent
37228 @cindex debugging agent
37229 The traditional debugging model is conceptually low-speed, but works fine,
37230 because most bugs can be reproduced in debugging-mode execution. However,
37231 as multi-core or many-core processors are becoming mainstream, and
37232 multi-threaded programs become more and more popular, there should be more
37233 and more bugs that only manifest themselves at normal-mode execution, for
37234 example, thread races, because debugger's interference with the program's
37235 timing may conceal the bugs. On the other hand, in some applications,
37236 it is not feasible for the debugger to interrupt the program's execution
37237 long enough for the developer to learn anything helpful about its behavior.
37238 If the program's correctness depends on its real-time behavior, delays
37239 introduced by a debugger might cause the program to fail, even when the
37240 code itself is correct. It is useful to be able to observe the program's
37241 behavior without interrupting it.
37242
37243 Therefore, traditional debugging model is too intrusive to reproduce
37244 some bugs. In order to reduce the interference with the program, we can
37245 reduce the number of operations performed by debugger. The
37246 @dfn{In-Process Agent}, a shared library, is running within the same
37247 process with inferior, and is able to perform some debugging operations
37248 itself. As a result, debugger is only involved when necessary, and
37249 performance of debugging can be improved accordingly. Note that
37250 interference with program can be reduced but can't be removed completely,
37251 because the in-process agent will still stop or slow down the program.
37252
37253 The in-process agent can interpret and execute Agent Expressions
37254 (@pxref{Agent Expressions}) during performing debugging operations. The
37255 agent expressions can be used for different purposes, such as collecting
37256 data in tracepoints, and condition evaluation in breakpoints.
37257
37258 @anchor{Control Agent}
37259 You can control whether the in-process agent is used as an aid for
37260 debugging with the following commands:
37261
37262 @table @code
37263 @kindex set agent on
37264 @item set agent on
37265 Causes the in-process agent to perform some operations on behalf of the
37266 debugger. Just which operations requested by the user will be done
37267 by the in-process agent depends on the its capabilities. For example,
37268 if you request to evaluate breakpoint conditions in the in-process agent,
37269 and the in-process agent has such capability as well, then breakpoint
37270 conditions will be evaluated in the in-process agent.
37271
37272 @kindex set agent off
37273 @item set agent off
37274 Disables execution of debugging operations by the in-process agent. All
37275 of the operations will be performed by @value{GDBN}.
37276
37277 @kindex show agent
37278 @item show agent
37279 Display the current setting of execution of debugging operations by
37280 the in-process agent.
37281 @end table
37282
37283 @menu
37284 * In-Process Agent Protocol::
37285 @end menu
37286
37287 @node In-Process Agent Protocol
37288 @section In-Process Agent Protocol
37289 @cindex in-process agent protocol
37290
37291 The in-process agent is able to communicate with both @value{GDBN} and
37292 GDBserver (@pxref{In-Process Agent}). This section documents the protocol
37293 used for communications between @value{GDBN} or GDBserver and the IPA.
37294 In general, @value{GDBN} or GDBserver sends commands
37295 (@pxref{IPA Protocol Commands}) and data to in-process agent, and then
37296 in-process agent replies back with the return result of the command, or
37297 some other information. The data sent to in-process agent is composed
37298 of primitive data types, such as 4-byte or 8-byte type, and composite
37299 types, which are called objects (@pxref{IPA Protocol Objects}).
37300
37301 @menu
37302 * IPA Protocol Objects::
37303 * IPA Protocol Commands::
37304 @end menu
37305
37306 @node IPA Protocol Objects
37307 @subsection IPA Protocol Objects
37308 @cindex ipa protocol objects
37309
37310 The commands sent to and results received from agent may contain some
37311 complex data types called @dfn{objects}.
37312
37313 The in-process agent is running on the same machine with @value{GDBN}
37314 or GDBserver, so it doesn't have to handle as much differences between
37315 two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
37316 However, there are still some differences of two ends in two processes:
37317
37318 @enumerate
37319 @item
37320 word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
37321 compiled as a 64-bit executable, while in-process agent is a 32-bit one.
37322 @item
37323 ABI. Some machines may have multiple types of ABI, @value{GDBN} or
37324 GDBserver is compiled with one, and in-process agent is compiled with
37325 the other one.
37326 @end enumerate
37327
37328 Here are the IPA Protocol Objects:
37329
37330 @enumerate
37331 @item
37332 agent expression object. It represents an agent expression
37333 (@pxref{Agent Expressions}).
37334 @anchor{agent expression object}
37335 @item
37336 tracepoint action object. It represents a tracepoint action
37337 (@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
37338 memory, static trace data and to evaluate expression.
37339 @anchor{tracepoint action object}
37340 @item
37341 tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
37342 @anchor{tracepoint object}
37343
37344 @end enumerate
37345
37346 The following table describes important attributes of each IPA protocol
37347 object:
37348
37349 @multitable @columnfractions .30 .20 .50
37350 @headitem Name @tab Size @tab Description
37351 @item @emph{agent expression object} @tab @tab
37352 @item length @tab 4 @tab length of bytes code
37353 @item byte code @tab @var{length} @tab contents of byte code
37354 @item @emph{tracepoint action for collecting memory} @tab @tab
37355 @item 'M' @tab 1 @tab type of tracepoint action
37356 @item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
37357 address of the lowest byte to collect, otherwise @var{addr} is the offset
37358 of @var{basereg} for memory collecting.
37359 @item len @tab 8 @tab length of memory for collecting
37360 @item basereg @tab 4 @tab the register number containing the starting
37361 memory address for collecting.
37362 @item @emph{tracepoint action for collecting registers} @tab @tab
37363 @item 'R' @tab 1 @tab type of tracepoint action
37364 @item @emph{tracepoint action for collecting static trace data} @tab @tab
37365 @item 'L' @tab 1 @tab type of tracepoint action
37366 @item @emph{tracepoint action for expression evaluation} @tab @tab
37367 @item 'X' @tab 1 @tab type of tracepoint action
37368 @item agent expression @tab length of @tab @ref{agent expression object}
37369 @item @emph{tracepoint object} @tab @tab
37370 @item number @tab 4 @tab number of tracepoint
37371 @item address @tab 8 @tab address of tracepoint inserted on
37372 @item type @tab 4 @tab type of tracepoint
37373 @item enabled @tab 1 @tab enable or disable of tracepoint
37374 @item step_count @tab 8 @tab step
37375 @item pass_count @tab 8 @tab pass
37376 @item numactions @tab 4 @tab number of tracepoint actions
37377 @item hit count @tab 8 @tab hit count
37378 @item trace frame usage @tab 8 @tab trace frame usage
37379 @item compiled_cond @tab 8 @tab compiled condition
37380 @item orig_size @tab 8 @tab orig size
37381 @item condition @tab 4 if condition is NULL otherwise length of
37382 @ref{agent expression object}
37383 @tab zero if condition is NULL, otherwise is
37384 @ref{agent expression object}
37385 @item actions @tab variable
37386 @tab numactions number of @ref{tracepoint action object}
37387 @end multitable
37388
37389 @node IPA Protocol Commands
37390 @subsection IPA Protocol Commands
37391 @cindex ipa protocol commands
37392
37393 The spaces in each command are delimiters to ease reading this commands
37394 specification. They don't exist in real commands.
37395
37396 @table @samp
37397
37398 @item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
37399 Installs a new fast tracepoint described by @var{tracepoint_object}
37400 (@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
37401 head of @dfn{jumppad}, which is used to jump to data collection routine
37402 in IPA finally.
37403
37404 Replies:
37405 @table @samp
37406 @item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
37407 @var{target_address} is address of tracepoint in the inferior.
37408 The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
37409 @var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
37410 The @var{fjump} contains a sequence of instructions jump to jumppad entry.
37411 The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
37412 @item E @var{NN}
37413 for an error
37414
37415 @end table
37416
37417 @item close
37418 Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
37419 is about to kill inferiors.
37420
37421 @item qTfSTM
37422 @xref{qTfSTM}.
37423 @item qTsSTM
37424 @xref{qTsSTM}.
37425 @item qTSTMat
37426 @xref{qTSTMat}.
37427 @item probe_marker_at:@var{address}
37428 Asks in-process agent to probe the marker at @var{address}.
37429
37430 Replies:
37431 @table @samp
37432 @item E @var{NN}
37433 for an error
37434 @end table
37435 @item unprobe_marker_at:@var{address}
37436 Asks in-process agent to unprobe the marker at @var{address}.
37437 @end table
37438
37439 @node GDB Bugs
37440 @chapter Reporting Bugs in @value{GDBN}
37441 @cindex bugs in @value{GDBN}
37442 @cindex reporting bugs in @value{GDBN}
37443
37444 Your bug reports play an essential role in making @value{GDBN} reliable.
37445
37446 Reporting a bug may help you by bringing a solution to your problem, or it
37447 may not. But in any case the principal function of a bug report is to help
37448 the entire community by making the next version of @value{GDBN} work better. Bug
37449 reports are your contribution to the maintenance of @value{GDBN}.
37450
37451 In order for a bug report to serve its purpose, you must include the
37452 information that enables us to fix the bug.
37453
37454 @menu
37455 * Bug Criteria:: Have you found a bug?
37456 * Bug Reporting:: How to report bugs
37457 @end menu
37458
37459 @node Bug Criteria
37460 @section Have You Found a Bug?
37461 @cindex bug criteria
37462
37463 If you are not sure whether you have found a bug, here are some guidelines:
37464
37465 @itemize @bullet
37466 @cindex fatal signal
37467 @cindex debugger crash
37468 @cindex crash of debugger
37469 @item
37470 If the debugger gets a fatal signal, for any input whatever, that is a
37471 @value{GDBN} bug. Reliable debuggers never crash.
37472
37473 @cindex error on valid input
37474 @item
37475 If @value{GDBN} produces an error message for valid input, that is a
37476 bug. (Note that if you're cross debugging, the problem may also be
37477 somewhere in the connection to the target.)
37478
37479 @cindex invalid input
37480 @item
37481 If @value{GDBN} does not produce an error message for invalid input,
37482 that is a bug. However, you should note that your idea of
37483 ``invalid input'' might be our idea of ``an extension'' or ``support
37484 for traditional practice''.
37485
37486 @item
37487 If you are an experienced user of debugging tools, your suggestions
37488 for improvement of @value{GDBN} are welcome in any case.
37489 @end itemize
37490
37491 @node Bug Reporting
37492 @section How to Report Bugs
37493 @cindex bug reports
37494 @cindex @value{GDBN} bugs, reporting
37495
37496 A number of companies and individuals offer support for @sc{gnu} products.
37497 If you obtained @value{GDBN} from a support organization, we recommend you
37498 contact that organization first.
37499
37500 You can find contact information for many support companies and
37501 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
37502 distribution.
37503 @c should add a web page ref...
37504
37505 @ifset BUGURL
37506 @ifset BUGURL_DEFAULT
37507 In any event, we also recommend that you submit bug reports for
37508 @value{GDBN}. The preferred method is to submit them directly using
37509 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
37510 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
37511 be used.
37512
37513 @strong{Do not send bug reports to @samp{info-gdb}, or to
37514 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
37515 not want to receive bug reports. Those that do have arranged to receive
37516 @samp{bug-gdb}.
37517
37518 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
37519 serves as a repeater. The mailing list and the newsgroup carry exactly
37520 the same messages. Often people think of posting bug reports to the
37521 newsgroup instead of mailing them. This appears to work, but it has one
37522 problem which can be crucial: a newsgroup posting often lacks a mail
37523 path back to the sender. Thus, if we need to ask for more information,
37524 we may be unable to reach you. For this reason, it is better to send
37525 bug reports to the mailing list.
37526 @end ifset
37527 @ifclear BUGURL_DEFAULT
37528 In any event, we also recommend that you submit bug reports for
37529 @value{GDBN} to @value{BUGURL}.
37530 @end ifclear
37531 @end ifset
37532
37533 The fundamental principle of reporting bugs usefully is this:
37534 @strong{report all the facts}. If you are not sure whether to state a
37535 fact or leave it out, state it!
37536
37537 Often people omit facts because they think they know what causes the
37538 problem and assume that some details do not matter. Thus, you might
37539 assume that the name of the variable you use in an example does not matter.
37540 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
37541 stray memory reference which happens to fetch from the location where that
37542 name is stored in memory; perhaps, if the name were different, the contents
37543 of that location would fool the debugger into doing the right thing despite
37544 the bug. Play it safe and give a specific, complete example. That is the
37545 easiest thing for you to do, and the most helpful.
37546
37547 Keep in mind that the purpose of a bug report is to enable us to fix the
37548 bug. It may be that the bug has been reported previously, but neither
37549 you nor we can know that unless your bug report is complete and
37550 self-contained.
37551
37552 Sometimes people give a few sketchy facts and ask, ``Does this ring a
37553 bell?'' Those bug reports are useless, and we urge everyone to
37554 @emph{refuse to respond to them} except to chide the sender to report
37555 bugs properly.
37556
37557 To enable us to fix the bug, you should include all these things:
37558
37559 @itemize @bullet
37560 @item
37561 The version of @value{GDBN}. @value{GDBN} announces it if you start
37562 with no arguments; you can also print it at any time using @code{show
37563 version}.
37564
37565 Without this, we will not know whether there is any point in looking for
37566 the bug in the current version of @value{GDBN}.
37567
37568 @item
37569 The type of machine you are using, and the operating system name and
37570 version number.
37571
37572 @item
37573 The details of the @value{GDBN} build-time configuration.
37574 @value{GDBN} shows these details if you invoke it with the
37575 @option{--configuration} command-line option, or if you type
37576 @code{show configuration} at @value{GDBN}'s prompt.
37577
37578 @item
37579 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
37580 ``@value{GCC}--2.8.1''.
37581
37582 @item
37583 What compiler (and its version) was used to compile the program you are
37584 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
37585 C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
37586 to get this information; for other compilers, see the documentation for
37587 those compilers.
37588
37589 @item
37590 The command arguments you gave the compiler to compile your example and
37591 observe the bug. For example, did you use @samp{-O}? To guarantee
37592 you will not omit something important, list them all. A copy of the
37593 Makefile (or the output from make) is sufficient.
37594
37595 If we were to try to guess the arguments, we would probably guess wrong
37596 and then we might not encounter the bug.
37597
37598 @item
37599 A complete input script, and all necessary source files, that will
37600 reproduce the bug.
37601
37602 @item
37603 A description of what behavior you observe that you believe is
37604 incorrect. For example, ``It gets a fatal signal.''
37605
37606 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
37607 will certainly notice it. But if the bug is incorrect output, we might
37608 not notice unless it is glaringly wrong. You might as well not give us
37609 a chance to make a mistake.
37610
37611 Even if the problem you experience is a fatal signal, you should still
37612 say so explicitly. Suppose something strange is going on, such as, your
37613 copy of @value{GDBN} is out of synch, or you have encountered a bug in
37614 the C library on your system. (This has happened!) Your copy might
37615 crash and ours would not. If you told us to expect a crash, then when
37616 ours fails to crash, we would know that the bug was not happening for
37617 us. If you had not told us to expect a crash, then we would not be able
37618 to draw any conclusion from our observations.
37619
37620 @pindex script
37621 @cindex recording a session script
37622 To collect all this information, you can use a session recording program
37623 such as @command{script}, which is available on many Unix systems.
37624 Just run your @value{GDBN} session inside @command{script} and then
37625 include the @file{typescript} file with your bug report.
37626
37627 Another way to record a @value{GDBN} session is to run @value{GDBN}
37628 inside Emacs and then save the entire buffer to a file.
37629
37630 @item
37631 If you wish to suggest changes to the @value{GDBN} source, send us context
37632 diffs. If you even discuss something in the @value{GDBN} source, refer to
37633 it by context, not by line number.
37634
37635 The line numbers in our development sources will not match those in your
37636 sources. Your line numbers would convey no useful information to us.
37637
37638 @end itemize
37639
37640 Here are some things that are not necessary:
37641
37642 @itemize @bullet
37643 @item
37644 A description of the envelope of the bug.
37645
37646 Often people who encounter a bug spend a lot of time investigating
37647 which changes to the input file will make the bug go away and which
37648 changes will not affect it.
37649
37650 This is often time consuming and not very useful, because the way we
37651 will find the bug is by running a single example under the debugger
37652 with breakpoints, not by pure deduction from a series of examples.
37653 We recommend that you save your time for something else.
37654
37655 Of course, if you can find a simpler example to report @emph{instead}
37656 of the original one, that is a convenience for us. Errors in the
37657 output will be easier to spot, running under the debugger will take
37658 less time, and so on.
37659
37660 However, simplification is not vital; if you do not want to do this,
37661 report the bug anyway and send us the entire test case you used.
37662
37663 @item
37664 A patch for the bug.
37665
37666 A patch for the bug does help us if it is a good one. But do not omit
37667 the necessary information, such as the test case, on the assumption that
37668 a patch is all we need. We might see problems with your patch and decide
37669 to fix the problem another way, or we might not understand it at all.
37670
37671 Sometimes with a program as complicated as @value{GDBN} it is very hard to
37672 construct an example that will make the program follow a certain path
37673 through the code. If you do not send us the example, we will not be able
37674 to construct one, so we will not be able to verify that the bug is fixed.
37675
37676 And if we cannot understand what bug you are trying to fix, or why your
37677 patch should be an improvement, we will not install it. A test case will
37678 help us to understand.
37679
37680 @item
37681 A guess about what the bug is or what it depends on.
37682
37683 Such guesses are usually wrong. Even we cannot guess right about such
37684 things without first using the debugger to find the facts.
37685 @end itemize
37686
37687 @c The readline documentation is distributed with the readline code
37688 @c and consists of the two following files:
37689 @c rluser.texi
37690 @c hsuser.texi
37691 @c Use -I with makeinfo to point to the appropriate directory,
37692 @c environment var TEXINPUTS with TeX.
37693 @ifclear SYSTEM_READLINE
37694 @include rluser.texi
37695 @include hsuser.texi
37696 @end ifclear
37697
37698 @node In Memoriam
37699 @appendix In Memoriam
37700
37701 The @value{GDBN} project mourns the loss of the following long-time
37702 contributors:
37703
37704 @table @code
37705 @item Fred Fish
37706 Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
37707 to Free Software in general. Outside of @value{GDBN}, he was known in
37708 the Amiga world for his series of Fish Disks, and the GeekGadget project.
37709
37710 @item Michael Snyder
37711 Michael was one of the Global Maintainers of the @value{GDBN} project,
37712 with contributions recorded as early as 1996, until 2011. In addition
37713 to his day to day participation, he was a large driving force behind
37714 adding Reverse Debugging to @value{GDBN}.
37715 @end table
37716
37717 Beyond their technical contributions to the project, they were also
37718 enjoyable members of the Free Software Community. We will miss them.
37719
37720 @node Formatting Documentation
37721 @appendix Formatting Documentation
37722
37723 @cindex @value{GDBN} reference card
37724 @cindex reference card
37725 The @value{GDBN} 4 release includes an already-formatted reference card, ready
37726 for printing with PostScript or Ghostscript, in the @file{gdb}
37727 subdirectory of the main source directory@footnote{In
37728 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
37729 release.}. If you can use PostScript or Ghostscript with your printer,
37730 you can print the reference card immediately with @file{refcard.ps}.
37731
37732 The release also includes the source for the reference card. You
37733 can format it, using @TeX{}, by typing:
37734
37735 @smallexample
37736 make refcard.dvi
37737 @end smallexample
37738
37739 The @value{GDBN} reference card is designed to print in @dfn{landscape}
37740 mode on US ``letter'' size paper;
37741 that is, on a sheet 11 inches wide by 8.5 inches
37742 high. You will need to specify this form of printing as an option to
37743 your @sc{dvi} output program.
37744
37745 @cindex documentation
37746
37747 All the documentation for @value{GDBN} comes as part of the machine-readable
37748 distribution. The documentation is written in Texinfo format, which is
37749 a documentation system that uses a single source file to produce both
37750 on-line information and a printed manual. You can use one of the Info
37751 formatting commands to create the on-line version of the documentation
37752 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
37753
37754 @value{GDBN} includes an already formatted copy of the on-line Info
37755 version of this manual in the @file{gdb} subdirectory. The main Info
37756 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
37757 subordinate files matching @samp{gdb.info*} in the same directory. If
37758 necessary, you can print out these files, or read them with any editor;
37759 but they are easier to read using the @code{info} subsystem in @sc{gnu}
37760 Emacs or the standalone @code{info} program, available as part of the
37761 @sc{gnu} Texinfo distribution.
37762
37763 If you want to format these Info files yourself, you need one of the
37764 Info formatting programs, such as @code{texinfo-format-buffer} or
37765 @code{makeinfo}.
37766
37767 If you have @code{makeinfo} installed, and are in the top level
37768 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
37769 version @value{GDBVN}), you can make the Info file by typing:
37770
37771 @smallexample
37772 cd gdb
37773 make gdb.info
37774 @end smallexample
37775
37776 If you want to typeset and print copies of this manual, you need @TeX{},
37777 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
37778 Texinfo definitions file.
37779
37780 @TeX{} is a typesetting program; it does not print files directly, but
37781 produces output files called @sc{dvi} files. To print a typeset
37782 document, you need a program to print @sc{dvi} files. If your system
37783 has @TeX{} installed, chances are it has such a program. The precise
37784 command to use depends on your system; @kbd{lpr -d} is common; another
37785 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
37786 require a file name without any extension or a @samp{.dvi} extension.
37787
37788 @TeX{} also requires a macro definitions file called
37789 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
37790 written in Texinfo format. On its own, @TeX{} cannot either read or
37791 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
37792 and is located in the @file{gdb-@var{version-number}/texinfo}
37793 directory.
37794
37795 If you have @TeX{} and a @sc{dvi} printer program installed, you can
37796 typeset and print this manual. First switch to the @file{gdb}
37797 subdirectory of the main source directory (for example, to
37798 @file{gdb-@value{GDBVN}/gdb}) and type:
37799
37800 @smallexample
37801 make gdb.dvi
37802 @end smallexample
37803
37804 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
37805
37806 @node Installing GDB
37807 @appendix Installing @value{GDBN}
37808 @cindex installation
37809
37810 @menu
37811 * Requirements:: Requirements for building @value{GDBN}
37812 * Running Configure:: Invoking the @value{GDBN} @file{configure} script
37813 * Separate Objdir:: Compiling @value{GDBN} in another directory
37814 * Config Names:: Specifying names for hosts and targets
37815 * Configure Options:: Summary of options for configure
37816 * System-wide configuration:: Having a system-wide init file
37817 @end menu
37818
37819 @node Requirements
37820 @section Requirements for Building @value{GDBN}
37821 @cindex building @value{GDBN}, requirements for
37822
37823 Building @value{GDBN} requires various tools and packages to be available.
37824 Other packages will be used only if they are found.
37825
37826 @heading Tools/Packages Necessary for Building @value{GDBN}
37827 @table @asis
37828 @item C@t{++}11 compiler
37829 @value{GDBN} is written in C@t{++}11. It should be buildable with any
37830 recent C@t{++}11 compiler, e.g.@: GCC.
37831
37832 @item GNU make
37833 @value{GDBN}'s build system relies on features only found in the GNU
37834 make program. Other variants of @code{make} will not work.
37835
37836 @item GMP (The GNU Multiple Precision Arithmetic Library)
37837 @value{GDBN} now uses GMP to perform some of its arithmetics.
37838 This library may be included with your operating system distribution;
37839 if it is not, you can get the latest version from
37840 @url{https://gmplib.org/}. If GMP is installed at an unusual path,
37841 you can use the @option{--with-libgmp-prefix} option to specify
37842 its location.
37843
37844 @end table
37845
37846 @heading Tools/Packages Optional for Building @value{GDBN}
37847 @table @asis
37848 @item Expat
37849 @anchor{Expat}
37850 @value{GDBN} can use the Expat XML parsing library. This library may be
37851 included with your operating system distribution; if it is not, you
37852 can get the latest version from @url{http://expat.sourceforge.net}.
37853 The @file{configure} script will search for this library in several
37854 standard locations; if it is installed in an unusual path, you can
37855 use the @option{--with-libexpat-prefix} option to specify its location.
37856
37857 Expat is used for:
37858
37859 @itemize @bullet
37860 @item
37861 Remote protocol memory maps (@pxref{Memory Map Format})
37862 @item
37863 Target descriptions (@pxref{Target Descriptions})
37864 @item
37865 Remote shared library lists (@xref{Library List Format},
37866 or alternatively @pxref{Library List Format for SVR4 Targets})
37867 @item
37868 MS-Windows shared libraries (@pxref{Shared Libraries})
37869 @item
37870 Traceframe info (@pxref{Traceframe Info Format})
37871 @item
37872 Branch trace (@pxref{Branch Trace Format},
37873 @pxref{Branch Trace Configuration Format})
37874 @end itemize
37875
37876 @item Guile
37877 @value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
37878 default, @value{GDBN} will be compiled if the Guile libraries are
37879 installed and are found by @file{configure}. You can use the
37880 @code{--with-guile} option to request Guile, and pass either the Guile
37881 version number or the file name of the relevant @code{pkg-config}
37882 program to choose a particular version of Guile.
37883
37884 @item iconv
37885 @value{GDBN}'s features related to character sets (@pxref{Character
37886 Sets}) require a functioning @code{iconv} implementation. If you are
37887 on a GNU system, then this is provided by the GNU C Library. Some
37888 other systems also provide a working @code{iconv}.
37889
37890 If @value{GDBN} is using the @code{iconv} program which is installed
37891 in a non-standard place, you will need to tell @value{GDBN} where to
37892 find it. This is done with @option{--with-iconv-bin} which specifies
37893 the directory that contains the @code{iconv} program. This program is
37894 run in order to make a list of the available character sets.
37895
37896 On systems without @code{iconv}, you can install GNU Libiconv. If
37897 Libiconv is installed in a standard place, @value{GDBN} will
37898 automatically use it if it is needed. If you have previously
37899 installed Libiconv in a non-standard place, you can use the
37900 @option{--with-libiconv-prefix} option to @file{configure}.
37901
37902 @value{GDBN}'s top-level @file{configure} and @file{Makefile} will
37903 arrange to build Libiconv if a directory named @file{libiconv} appears
37904 in the top-most source directory. If Libiconv is built this way, and
37905 if the operating system does not provide a suitable @code{iconv}
37906 implementation, then the just-built library will automatically be used
37907 by @value{GDBN}. One easy way to set this up is to download GNU
37908 Libiconv, unpack it inside the top-level directory of the @value{GDBN}
37909 source tree, and then rename the directory holding the Libiconv source
37910 code to @samp{libiconv}.
37911
37912 @item lzma
37913 @value{GDBN} can support debugging sections that are compressed with
37914 the LZMA library. @xref{MiniDebugInfo}. If this library is not
37915 included with your operating system, you can find it in the xz package
37916 at @url{http://tukaani.org/xz/}. If the LZMA library is available in
37917 the usual place, then the @file{configure} script will use it
37918 automatically. If it is installed in an unusual path, you can use the
37919 @option{--with-lzma-prefix} option to specify its location.
37920
37921 @item MPFR
37922 @anchor{MPFR}
37923 @value{GDBN} can use the GNU MPFR multiple-precision floating-point
37924 library. This library may be included with your operating system
37925 distribution; if it is not, you can get the latest version from
37926 @url{http://www.mpfr.org}. The @file{configure} script will search
37927 for this library in several standard locations; if it is installed
37928 in an unusual path, you can use the @option{--with-libmpfr-prefix}
37929 option to specify its location.
37930
37931 GNU MPFR is used to emulate target floating-point arithmetic during
37932 expression evaluation when the target uses different floating-point
37933 formats than the host. If GNU MPFR it is not available, @value{GDBN}
37934 will fall back to using host floating-point arithmetic.
37935
37936 @item Python
37937 @value{GDBN} can be scripted using Python language. @xref{Python}.
37938 By default, @value{GDBN} will be compiled if the Python libraries are
37939 installed and are found by @file{configure}. You can use the
37940 @code{--with-python} option to request Python, and pass either the
37941 file name of the relevant @code{python} executable, or the name of the
37942 directory in which Python is installed, to choose a particular
37943 installation of Python.
37944
37945 @item zlib
37946 @cindex compressed debug sections
37947 @value{GDBN} will use the @samp{zlib} library, if available, to read
37948 compressed debug sections. Some linkers, such as GNU gold, are capable
37949 of producing binaries with compressed debug sections. If @value{GDBN}
37950 is compiled with @samp{zlib}, it will be able to read the debug
37951 information in such binaries.
37952
37953 The @samp{zlib} library is likely included with your operating system
37954 distribution; if it is not, you can get the latest version from
37955 @url{http://zlib.net}.
37956 @end table
37957
37958 @node Running Configure
37959 @section Invoking the @value{GDBN} @file{configure} Script
37960 @cindex configuring @value{GDBN}
37961 @value{GDBN} comes with a @file{configure} script that automates the process
37962 of preparing @value{GDBN} for installation; you can then use @code{make} to
37963 build the @code{gdb} program.
37964 @iftex
37965 @c irrelevant in info file; it's as current as the code it lives with.
37966 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
37967 look at the @file{README} file in the sources; we may have improved the
37968 installation procedures since publishing this manual.}
37969 @end iftex
37970
37971 The @value{GDBN} distribution includes all the source code you need for
37972 @value{GDBN} in a single directory, whose name is usually composed by
37973 appending the version number to @samp{gdb}.
37974
37975 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
37976 @file{gdb-@value{GDBVN}} directory. That directory contains:
37977
37978 @table @code
37979 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
37980 script for configuring @value{GDBN} and all its supporting libraries
37981
37982 @item gdb-@value{GDBVN}/gdb
37983 the source specific to @value{GDBN} itself
37984
37985 @item gdb-@value{GDBVN}/bfd
37986 source for the Binary File Descriptor library
37987
37988 @item gdb-@value{GDBVN}/include
37989 @sc{gnu} include files
37990
37991 @item gdb-@value{GDBVN}/libiberty
37992 source for the @samp{-liberty} free software library
37993
37994 @item gdb-@value{GDBVN}/opcodes
37995 source for the library of opcode tables and disassemblers
37996
37997 @item gdb-@value{GDBVN}/readline
37998 source for the @sc{gnu} command-line interface
37999 @end table
38000
38001 There may be other subdirectories as well.
38002
38003 The simplest way to configure and build @value{GDBN} is to run @file{configure}
38004 from the @file{gdb-@var{version-number}} source directory, which in
38005 this example is the @file{gdb-@value{GDBVN}} directory.
38006
38007 First switch to the @file{gdb-@var{version-number}} source directory
38008 if you are not already in it; then run @file{configure}. Pass the
38009 identifier for the platform on which @value{GDBN} will run as an
38010 argument.
38011
38012 For example:
38013
38014 @smallexample
38015 cd gdb-@value{GDBVN}
38016 ./configure
38017 make
38018 @end smallexample
38019
38020 Running @samp{configure} and then running @code{make} builds the
38021 included supporting libraries, then @code{gdb} itself. The configured
38022 source files, and the binaries, are left in the corresponding source
38023 directories.
38024
38025 @need 750
38026 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
38027 system does not recognize this automatically when you run a different
38028 shell, you may need to run @code{sh} on it explicitly:
38029
38030 @smallexample
38031 sh configure
38032 @end smallexample
38033
38034 You should run the @file{configure} script from the top directory in the
38035 source tree, the @file{gdb-@var{version-number}} directory. If you run
38036 @file{configure} from one of the subdirectories, you will configure only
38037 that subdirectory. That is usually not what you want. In particular,
38038 if you run the first @file{configure} from the @file{gdb} subdirectory
38039 of the @file{gdb-@var{version-number}} directory, you will omit the
38040 configuration of @file{bfd}, @file{readline}, and other sibling
38041 directories of the @file{gdb} subdirectory. This leads to build errors
38042 about missing include files such as @file{bfd/bfd.h}.
38043
38044 You can install @code{@value{GDBN}} anywhere. The best way to do this
38045 is to pass the @code{--prefix} option to @code{configure}, and then
38046 install it with @code{make install}.
38047
38048 @node Separate Objdir
38049 @section Compiling @value{GDBN} in Another Directory
38050
38051 If you want to run @value{GDBN} versions for several host or target machines,
38052 you need a different @code{gdb} compiled for each combination of
38053 host and target. @file{configure} is designed to make this easy by
38054 allowing you to generate each configuration in a separate subdirectory,
38055 rather than in the source directory. If your @code{make} program
38056 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
38057 @code{make} in each of these directories builds the @code{gdb}
38058 program specified there.
38059
38060 To build @code{gdb} in a separate directory, run @file{configure}
38061 with the @samp{--srcdir} option to specify where to find the source.
38062 (You also need to specify a path to find @file{configure}
38063 itself from your working directory. If the path to @file{configure}
38064 would be the same as the argument to @samp{--srcdir}, you can leave out
38065 the @samp{--srcdir} option; it is assumed.)
38066
38067 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
38068 separate directory for a Sun 4 like this:
38069
38070 @smallexample
38071 @group
38072 cd gdb-@value{GDBVN}
38073 mkdir ../gdb-sun4
38074 cd ../gdb-sun4
38075 ../gdb-@value{GDBVN}/configure
38076 make
38077 @end group
38078 @end smallexample
38079
38080 When @file{configure} builds a configuration using a remote source
38081 directory, it creates a tree for the binaries with the same structure
38082 (and using the same names) as the tree under the source directory. In
38083 the example, you'd find the Sun 4 library @file{libiberty.a} in the
38084 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
38085 @file{gdb-sun4/gdb}.
38086
38087 Make sure that your path to the @file{configure} script has just one
38088 instance of @file{gdb} in it. If your path to @file{configure} looks
38089 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
38090 one subdirectory of @value{GDBN}, not the whole package. This leads to
38091 build errors about missing include files such as @file{bfd/bfd.h}.
38092
38093 One popular reason to build several @value{GDBN} configurations in separate
38094 directories is to configure @value{GDBN} for cross-compiling (where
38095 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
38096 programs that run on another machine---the @dfn{target}).
38097 You specify a cross-debugging target by
38098 giving the @samp{--target=@var{target}} option to @file{configure}.
38099
38100 When you run @code{make} to build a program or library, you must run
38101 it in a configured directory---whatever directory you were in when you
38102 called @file{configure} (or one of its subdirectories).
38103
38104 The @code{Makefile} that @file{configure} generates in each source
38105 directory also runs recursively. If you type @code{make} in a source
38106 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
38107 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
38108 will build all the required libraries, and then build GDB.
38109
38110 When you have multiple hosts or targets configured in separate
38111 directories, you can run @code{make} on them in parallel (for example,
38112 if they are NFS-mounted on each of the hosts); they will not interfere
38113 with each other.
38114
38115 @node Config Names
38116 @section Specifying Names for Hosts and Targets
38117
38118 The specifications used for hosts and targets in the @file{configure}
38119 script are based on a three-part naming scheme, but some short predefined
38120 aliases are also supported. The full naming scheme encodes three pieces
38121 of information in the following pattern:
38122
38123 @smallexample
38124 @var{architecture}-@var{vendor}-@var{os}
38125 @end smallexample
38126
38127 For example, you can use the alias @code{sun4} as a @var{host} argument,
38128 or as the value for @var{target} in a @code{--target=@var{target}}
38129 option. The equivalent full name is @samp{sparc-sun-sunos4}.
38130
38131 The @file{configure} script accompanying @value{GDBN} does not provide
38132 any query facility to list all supported host and target names or
38133 aliases. @file{configure} calls the Bourne shell script
38134 @code{config.sub} to map abbreviations to full names; you can read the
38135 script, if you wish, or you can use it to test your guesses on
38136 abbreviations---for example:
38137
38138 @smallexample
38139 % sh config.sub i386-linux
38140 i386-pc-linux-gnu
38141 % sh config.sub alpha-linux
38142 alpha-unknown-linux-gnu
38143 % sh config.sub hp9k700
38144 hppa1.1-hp-hpux
38145 % sh config.sub sun4
38146 sparc-sun-sunos4.1.1
38147 % sh config.sub sun3
38148 m68k-sun-sunos4.1.1
38149 % sh config.sub i986v
38150 Invalid configuration `i986v': machine `i986v' not recognized
38151 @end smallexample
38152
38153 @noindent
38154 @code{config.sub} is also distributed in the @value{GDBN} source
38155 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
38156
38157 @node Configure Options
38158 @section @file{configure} Options
38159
38160 Here is a summary of the @file{configure} options and arguments that
38161 are most often useful for building @value{GDBN}. @file{configure}
38162 also has several other options not listed here. @inforef{Running
38163 configure scripts,,autoconf.info}, for a full
38164 explanation of @file{configure}.
38165
38166 @smallexample
38167 configure @r{[}--help@r{]}
38168 @r{[}--prefix=@var{dir}@r{]}
38169 @r{[}--exec-prefix=@var{dir}@r{]}
38170 @r{[}--srcdir=@var{dirname}@r{]}
38171 @r{[}--target=@var{target}@r{]}
38172 @end smallexample
38173
38174 @noindent
38175 You may introduce options with a single @samp{-} rather than
38176 @samp{--} if you prefer; but you may abbreviate option names if you use
38177 @samp{--}.
38178
38179 @table @code
38180 @item --help
38181 Display a quick summary of how to invoke @file{configure}.
38182
38183 @item --prefix=@var{dir}
38184 Configure the source to install programs and files under directory
38185 @file{@var{dir}}.
38186
38187 @item --exec-prefix=@var{dir}
38188 Configure the source to install programs under directory
38189 @file{@var{dir}}.
38190
38191 @c avoid splitting the warning from the explanation:
38192 @need 2000
38193 @item --srcdir=@var{dirname}
38194 Use this option to make configurations in directories separate from the
38195 @value{GDBN} source directories. Among other things, you can use this to
38196 build (or maintain) several configurations simultaneously, in separate
38197 directories. @file{configure} writes configuration-specific files in
38198 the current directory, but arranges for them to use the source in the
38199 directory @var{dirname}. @file{configure} creates directories under
38200 the working directory in parallel to the source directories below
38201 @var{dirname}.
38202
38203 @item --target=@var{target}
38204 Configure @value{GDBN} for cross-debugging programs running on the specified
38205 @var{target}. Without this option, @value{GDBN} is configured to debug
38206 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
38207
38208 There is no convenient way to generate a list of all available
38209 targets. Also see the @code{--enable-targets} option, below.
38210 @end table
38211
38212 There are many other options that are specific to @value{GDBN}. This
38213 lists just the most common ones; there are some very specialized
38214 options not described here.
38215
38216 @table @code
38217 @item --enable-targets=@r{[}@var{target}@r{]}@dots{}
38218 @itemx --enable-targets=all
38219 Configure @value{GDBN} for cross-debugging programs running on the
38220 specified list of targets. The special value @samp{all} configures
38221 @value{GDBN} for debugging programs running on any target it supports.
38222
38223 @item --with-gdb-datadir=@var{path}
38224 Set the @value{GDBN}-specific data directory. @value{GDBN} will look
38225 here for certain supporting files or scripts. This defaults to the
38226 @file{gdb} subdirectory of @samp{datadir} (which can be set using
38227 @code{--datadir}).
38228
38229 @item --with-relocated-sources=@var{dir}
38230 Sets up the default source path substitution rule so that directory
38231 names recorded in debug information will be automatically adjusted for
38232 any directory under @var{dir}. @var{dir} should be a subdirectory of
38233 @value{GDBN}'s configured prefix, the one mentioned in the
38234 @code{--prefix} or @code{--exec-prefix} options to configure. This
38235 option is useful if GDB is supposed to be moved to a different place
38236 after it is built.
38237
38238 @item --enable-64-bit-bfd
38239 Enable 64-bit support in BFD on 32-bit hosts.
38240
38241 @item --disable-gdbmi
38242 Build @value{GDBN} without the GDB/MI machine interface
38243 (@pxref{GDB/MI}).
38244
38245 @item --enable-tui
38246 Build @value{GDBN} with the text-mode full-screen user interface
38247 (TUI). Requires a curses library (ncurses and cursesX are also
38248 supported).
38249
38250 @item --with-curses
38251 Use the curses library instead of the termcap library, for text-mode
38252 terminal operations.
38253
38254 @item --with-debuginfod
38255 Build @value{GDBN} with libdebuginfod, the debuginfod client library.
38256 Used to automatically fetch source files and separate debug files from
38257 debuginfod servers using the associated executable's build ID. Enabled
38258 by default if libdebuginfod is installed and found at configure time.
38259 debuginfod is packaged with elfutils, starting with version 0.178. You
38260 can get the latest version from `https://sourceware.org/elfutils/'.
38261
38262 @item --with-libunwind-ia64
38263 Use the libunwind library for unwinding function call stack on ia64
38264 target platforms. See http://www.nongnu.org/libunwind/index.html for
38265 details.
38266
38267 @item --with-system-readline
38268 Use the readline library installed on the host, rather than the
38269 library supplied as part of @value{GDBN}. Readline 7 or newer is
38270 required; this is enforced by the build system.
38271
38272 @item --with-system-zlib
38273 Use the zlib library installed on the host, rather than the library
38274 supplied as part of @value{GDBN}.
38275
38276 @item --with-expat
38277 Build @value{GDBN} with Expat, a library for XML parsing. (Done by
38278 default if libexpat is installed and found at configure time.) This
38279 library is used to read XML files supplied with @value{GDBN}. If it
38280 is unavailable, some features, such as remote protocol memory maps,
38281 target descriptions, and shared library lists, that are based on XML
38282 files, will not be available in @value{GDBN}. If your host does not
38283 have libexpat installed, you can get the latest version from
38284 `http://expat.sourceforge.net'.
38285
38286 @item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
38287
38288 Build @value{GDBN} with GNU libiconv, a character set encoding
38289 conversion library. This is not done by default, as on GNU systems
38290 the @code{iconv} that is built in to the C library is sufficient. If
38291 your host does not have a working @code{iconv}, you can get the latest
38292 version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
38293
38294 @value{GDBN}'s build system also supports building GNU libiconv as
38295 part of the overall build. @xref{Requirements}.
38296
38297 @item --with-lzma
38298 Build @value{GDBN} with LZMA, a compression library. (Done by default
38299 if liblzma is installed and found at configure time.) LZMA is used by
38300 @value{GDBN}'s "mini debuginfo" feature, which is only useful on
38301 platforms using the ELF object file format. If your host does not
38302 have liblzma installed, you can get the latest version from
38303 `https://tukaani.org/xz/'.
38304
38305 @item --with-mpfr
38306 Build @value{GDBN} with GNU MPFR, a library for multiple-precision
38307 floating-point computation with correct rounding. (Done by default if
38308 GNU MPFR is installed and found at configure time.) This library is
38309 used to emulate target floating-point arithmetic during expression
38310 evaluation when the target uses different floating-point formats than
38311 the host. If GNU MPFR is not available, @value{GDBN} will fall back
38312 to using host floating-point arithmetic. If your host does not have
38313 GNU MPFR installed, you can get the latest version from
38314 `http://www.mpfr.org'.
38315
38316 @item --with-python@r{[}=@var{python}@r{]}
38317 Build @value{GDBN} with Python scripting support. (Done by default if
38318 libpython is present and found at configure time.) Python makes
38319 @value{GDBN} scripting much more powerful than the restricted CLI
38320 scripting language. If your host does not have Python installed, you
38321 can find it on `http://www.python.org/download/'. The oldest version
38322 of Python supported by GDB is 2.6. The optional argument @var{python}
38323 is used to find the Python headers and libraries. It can be either
38324 the name of a Python executable, or the name of the directory in which
38325 Python is installed.
38326
38327 @item --with-guile[=GUILE]'
38328 Build @value{GDBN} with GNU Guile scripting support. (Done by default
38329 if libguile is present and found at configure time.) If your host
38330 does not have Guile installed, you can find it at
38331 `https://www.gnu.org/software/guile/'. The optional argument GUILE
38332 can be a version number, which will cause @code{configure} to try to
38333 use that version of Guile; or the file name of a @code{pkg-config}
38334 executable, which will be queried to find the information needed to
38335 compile and link against Guile.
38336
38337 @item --without-included-regex
38338 Don't use the regex library included with @value{GDBN} (as part of the
38339 libiberty library). This is the default on hosts with version 2 of
38340 the GNU C library.
38341
38342 @item --with-sysroot=@var{dir}
38343 Use @var{dir} as the default system root directory for libraries whose
38344 file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
38345 @var{dir} can be modified at run time by using the @command{set
38346 sysroot} command.) If @var{dir} is under the @value{GDBN} configured
38347 prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
38348 default system root will be automatically adjusted if and when
38349 @value{GDBN} is moved to a different location.
38350
38351 @item --with-system-gdbinit=@var{file}
38352 Configure @value{GDBN} to automatically load a system-wide init file.
38353 @var{file} should be an absolute file name. If @var{file} is in a
38354 directory under the configured prefix, and @value{GDBN} is moved to
38355 another location after being built, the location of the system-wide
38356 init file will be adjusted accordingly.
38357
38358 @item --with-system-gdbinit-dir=@var{directory}
38359 Configure @value{GDBN} to automatically load init files from a
38360 system-wide directory. @var{directory} should be an absolute directory
38361 name. If @var{directory} is in a directory under the configured
38362 prefix, and @value{GDBN} is moved to another location after being
38363 built, the location of the system-wide init directory will be
38364 adjusted accordingly.
38365
38366 @item --enable-build-warnings
38367 When building the @value{GDBN} sources, ask the compiler to warn about
38368 any code which looks even vaguely suspicious. It passes many
38369 different warning flags, depending on the exact version of the
38370 compiler you are using.
38371
38372 @item --enable-werror
38373 Treat compiler warnings as werrors. It adds the @code{-Werror} flag
38374 to the compiler, which will fail the compilation if the compiler
38375 outputs any warning messages.
38376
38377 @item --enable-ubsan
38378 Enable the GCC undefined behavior sanitizer. This is disabled by
38379 default, but passing @code{--enable-ubsan=yes} or
38380 @code{--enable-ubsan=auto} to @code{configure} will enable it. The
38381 undefined behavior sanitizer checks for C@t{++} undefined behavior.
38382 It has a performance cost, so if you are looking at @value{GDBN}'s
38383 performance, you should disable it. The undefined behavior sanitizer
38384 was first introduced in GCC 4.9.
38385 @end table
38386
38387 @node System-wide configuration
38388 @section System-wide configuration and settings
38389 @cindex system-wide init file
38390
38391 @value{GDBN} can be configured to have a system-wide init file and a
38392 system-wide init file directory; this file and files in that directory
38393 (if they have a recognized file extension) will be read and executed at
38394 startup (@pxref{Startup, , What @value{GDBN} does during startup}).
38395
38396 Here are the corresponding configure options:
38397
38398 @table @code
38399 @item --with-system-gdbinit=@var{file}
38400 Specify that the default location of the system-wide init file is
38401 @var{file}.
38402 @item --with-system-gdbinit-dir=@var{directory}
38403 Specify that the default location of the system-wide init file directory
38404 is @var{directory}.
38405 @end table
38406
38407 If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
38408 they may be subject to relocation. Two possible cases:
38409
38410 @itemize @bullet
38411 @item
38412 If the default location of this init file/directory contains @file{$prefix},
38413 it will be subject to relocation. Suppose that the configure options
38414 are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
38415 if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
38416 init file is looked for as @file{$install/etc/gdbinit} instead of
38417 @file{$prefix/etc/gdbinit}.
38418
38419 @item
38420 By contrast, if the default location does not contain the prefix,
38421 it will not be relocated. E.g.@: if @value{GDBN} has been configured with
38422 @option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
38423 then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
38424 wherever @value{GDBN} is installed.
38425 @end itemize
38426
38427 If the configured location of the system-wide init file (as given by the
38428 @option{--with-system-gdbinit} option at configure time) is in the
38429 data-directory (as specified by @option{--with-gdb-datadir} at configure
38430 time) or in one of its subdirectories, then @value{GDBN} will look for the
38431 system-wide init file in the directory specified by the
38432 @option{--data-directory} command-line option.
38433 Note that the system-wide init file is only read once, during @value{GDBN}
38434 initialization. If the data-directory is changed after @value{GDBN} has
38435 started with the @code{set data-directory} command, the file will not be
38436 reread.
38437
38438 This applies similarly to the system-wide directory specified in
38439 @option{--with-system-gdbinit-dir}.
38440
38441 Any supported scripting language can be used for these init files, as long
38442 as the file extension matches the scripting language. To be interpreted
38443 as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
38444 extension.
38445
38446 @menu
38447 * System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
38448 @end menu
38449
38450 @node System-wide Configuration Scripts
38451 @subsection Installed System-wide Configuration Scripts
38452 @cindex system-wide configuration scripts
38453
38454 The @file{system-gdbinit} directory, located inside the data-directory
38455 (as specified by @option{--with-gdb-datadir} at configure time) contains
38456 a number of scripts which can be used as system-wide init files. To
38457 automatically source those scripts at startup, @value{GDBN} should be
38458 configured with @option{--with-system-gdbinit}. Otherwise, any user
38459 should be able to source them by hand as needed.
38460
38461 The following scripts are currently available:
38462 @itemize @bullet
38463
38464 @item @file{elinos.py}
38465 @pindex elinos.py
38466 @cindex ELinOS system-wide configuration script
38467 This script is useful when debugging a program on an ELinOS target.
38468 It takes advantage of the environment variables defined in a standard
38469 ELinOS environment in order to determine the location of the system
38470 shared libraries, and then sets the @samp{solib-absolute-prefix}
38471 and @samp{solib-search-path} variables appropriately.
38472
38473 @item @file{wrs-linux.py}
38474 @pindex wrs-linux.py
38475 @cindex Wind River Linux system-wide configuration script
38476 This script is useful when debugging a program on a target running
38477 Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
38478 the host-side sysroot used by the target system.
38479
38480 @end itemize
38481
38482 @node Maintenance Commands
38483 @appendix Maintenance Commands
38484 @cindex maintenance commands
38485 @cindex internal commands
38486
38487 In addition to commands intended for @value{GDBN} users, @value{GDBN}
38488 includes a number of commands intended for @value{GDBN} developers,
38489 that are not documented elsewhere in this manual. These commands are
38490 provided here for reference. (For commands that turn on debugging
38491 messages, see @ref{Debugging Output}.)
38492
38493 @table @code
38494 @kindex maint agent
38495 @kindex maint agent-eval
38496 @item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38497 @itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38498 Translate the given @var{expression} into remote agent bytecodes.
38499 This command is useful for debugging the Agent Expression mechanism
38500 (@pxref{Agent Expressions}). The @samp{agent} version produces an
38501 expression useful for data collection, such as by tracepoints, while
38502 @samp{maint agent-eval} produces an expression that evaluates directly
38503 to a result. For instance, a collection expression for @code{globa +
38504 globb} will include bytecodes to record four bytes of memory at each
38505 of the addresses of @code{globa} and @code{globb}, while discarding
38506 the result of the addition, while an evaluation expression will do the
38507 addition and return the sum.
38508 If @code{-at} is given, generate remote agent bytecode for @var{location}.
38509 If not, generate remote agent bytecode for current frame PC address.
38510
38511 @kindex maint agent-printf
38512 @item maint agent-printf @var{format},@var{expr},...
38513 Translate the given format string and list of argument expressions
38514 into remote agent bytecodes and display them as a disassembled list.
38515 This command is useful for debugging the agent version of dynamic
38516 printf (@pxref{Dynamic Printf}).
38517
38518 @kindex maint info breakpoints
38519 @item @anchor{maint info breakpoints}maint info breakpoints
38520 Using the same format as @samp{info breakpoints}, display both the
38521 breakpoints you've set explicitly, and those @value{GDBN} is using for
38522 internal purposes. Internal breakpoints are shown with negative
38523 breakpoint numbers. The type column identifies what kind of breakpoint
38524 is shown:
38525
38526 @table @code
38527 @item breakpoint
38528 Normal, explicitly set breakpoint.
38529
38530 @item watchpoint
38531 Normal, explicitly set watchpoint.
38532
38533 @item longjmp
38534 Internal breakpoint, used to handle correctly stepping through
38535 @code{longjmp} calls.
38536
38537 @item longjmp resume
38538 Internal breakpoint at the target of a @code{longjmp}.
38539
38540 @item until
38541 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
38542
38543 @item finish
38544 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
38545
38546 @item shlib events
38547 Shared library events.
38548
38549 @end table
38550
38551 @kindex maint info btrace
38552 @item maint info btrace
38553 Pint information about raw branch tracing data.
38554
38555 @kindex maint btrace packet-history
38556 @item maint btrace packet-history
38557 Print the raw branch trace packets that are used to compute the
38558 execution history for the @samp{record btrace} command. Both the
38559 information and the format in which it is printed depend on the btrace
38560 recording format.
38561
38562 @table @code
38563 @item bts
38564 For the BTS recording format, print a list of blocks of sequential
38565 code. For each block, the following information is printed:
38566
38567 @table @asis
38568 @item Block number
38569 Newer blocks have higher numbers. The oldest block has number zero.
38570 @item Lowest @samp{PC}
38571 @item Highest @samp{PC}
38572 @end table
38573
38574 @item pt
38575 For the Intel Processor Trace recording format, print a list of
38576 Intel Processor Trace packets. For each packet, the following
38577 information is printed:
38578
38579 @table @asis
38580 @item Packet number
38581 Newer packets have higher numbers. The oldest packet has number zero.
38582 @item Trace offset
38583 The packet's offset in the trace stream.
38584 @item Packet opcode and payload
38585 @end table
38586 @end table
38587
38588 @kindex maint btrace clear-packet-history
38589 @item maint btrace clear-packet-history
38590 Discards the cached packet history printed by the @samp{maint btrace
38591 packet-history} command. The history will be computed again when
38592 needed.
38593
38594 @kindex maint btrace clear
38595 @item maint btrace clear
38596 Discard the branch trace data. The data will be fetched anew and the
38597 branch trace will be recomputed when needed.
38598
38599 This implicitly truncates the branch trace to a single branch trace
38600 buffer. When updating branch trace incrementally, the branch trace
38601 available to @value{GDBN} may be bigger than a single branch trace
38602 buffer.
38603
38604 @kindex maint set btrace pt skip-pad
38605 @item maint set btrace pt skip-pad
38606 @kindex maint show btrace pt skip-pad
38607 @item maint show btrace pt skip-pad
38608 Control whether @value{GDBN} will skip PAD packets when computing the
38609 packet history.
38610
38611 @kindex set displaced-stepping
38612 @kindex show displaced-stepping
38613 @cindex displaced stepping support
38614 @cindex out-of-line single-stepping
38615 @item set displaced-stepping
38616 @itemx show displaced-stepping
38617 Control whether or not @value{GDBN} will do @dfn{displaced stepping}
38618 if the target supports it. Displaced stepping is a way to single-step
38619 over breakpoints without removing them from the inferior, by executing
38620 an out-of-line copy of the instruction that was originally at the
38621 breakpoint location. It is also known as out-of-line single-stepping.
38622
38623 @table @code
38624 @item set displaced-stepping on
38625 If the target architecture supports it, @value{GDBN} will use
38626 displaced stepping to step over breakpoints.
38627
38628 @item set displaced-stepping off
38629 @value{GDBN} will not use displaced stepping to step over breakpoints,
38630 even if such is supported by the target architecture.
38631
38632 @cindex non-stop mode, and @samp{set displaced-stepping}
38633 @item set displaced-stepping auto
38634 This is the default mode. @value{GDBN} will use displaced stepping
38635 only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
38636 architecture supports displaced stepping.
38637 @end table
38638
38639 @kindex maint check-psymtabs
38640 @item maint check-psymtabs
38641 Check the consistency of currently expanded psymtabs versus symtabs.
38642 Use this to check, for example, whether a symbol is in one but not the other.
38643
38644 @kindex maint check-symtabs
38645 @item maint check-symtabs
38646 Check the consistency of currently expanded symtabs.
38647
38648 @kindex maint expand-symtabs
38649 @item maint expand-symtabs [@var{regexp}]
38650 Expand symbol tables.
38651 If @var{regexp} is specified, only expand symbol tables for file
38652 names matching @var{regexp}.
38653
38654 @kindex maint set catch-demangler-crashes
38655 @kindex maint show catch-demangler-crashes
38656 @cindex demangler crashes
38657 @item maint set catch-demangler-crashes [on|off]
38658 @itemx maint show catch-demangler-crashes
38659 Control whether @value{GDBN} should attempt to catch crashes in the
38660 symbol name demangler. The default is to attempt to catch crashes.
38661 If enabled, the first time a crash is caught, a core file is created,
38662 the offending symbol is displayed and the user is presented with the
38663 option to terminate the current session.
38664
38665 @kindex maint cplus first_component
38666 @item maint cplus first_component @var{name}
38667 Print the first C@t{++} class/namespace component of @var{name}.
38668
38669 @kindex maint cplus namespace
38670 @item maint cplus namespace
38671 Print the list of possible C@t{++} namespaces.
38672
38673 @kindex maint deprecate
38674 @kindex maint undeprecate
38675 @cindex deprecated commands
38676 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
38677 @itemx maint undeprecate @var{command}
38678 Deprecate or undeprecate the named @var{command}. Deprecated commands
38679 cause @value{GDBN} to issue a warning when you use them. The optional
38680 argument @var{replacement} says which newer command should be used in
38681 favor of the deprecated one; if it is given, @value{GDBN} will mention
38682 the replacement as part of the warning.
38683
38684 @kindex maint dump-me
38685 @item maint dump-me
38686 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
38687 Cause a fatal signal in the debugger and force it to dump its core.
38688 This is supported only on systems which support aborting a program
38689 with the @code{SIGQUIT} signal.
38690
38691 @kindex maint internal-error
38692 @kindex maint internal-warning
38693 @kindex maint demangler-warning
38694 @cindex demangler crashes
38695 @item maint internal-error @r{[}@var{message-text}@r{]}
38696 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
38697 @itemx maint demangler-warning @r{[}@var{message-text}@r{]}
38698
38699 Cause @value{GDBN} to call the internal function @code{internal_error},
38700 @code{internal_warning} or @code{demangler_warning} and hence behave
38701 as though an internal problem has been detected. In addition to
38702 reporting the internal problem, these functions give the user the
38703 opportunity to either quit @value{GDBN} or (for @code{internal_error}
38704 and @code{internal_warning}) create a core file of the current
38705 @value{GDBN} session.
38706
38707 These commands take an optional parameter @var{message-text} that is
38708 used as the text of the error or warning message.
38709
38710 Here's an example of using @code{internal-error}:
38711
38712 @smallexample
38713 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
38714 @dots{}/maint.c:121: internal-error: testing, 1, 2
38715 A problem internal to GDB has been detected. Further
38716 debugging may prove unreliable.
38717 Quit this debugging session? (y or n) @kbd{n}
38718 Create a core file? (y or n) @kbd{n}
38719 (@value{GDBP})
38720 @end smallexample
38721
38722 @cindex @value{GDBN} internal error
38723 @cindex internal errors, control of @value{GDBN} behavior
38724 @cindex demangler crashes
38725
38726 @kindex maint set internal-error
38727 @kindex maint show internal-error
38728 @kindex maint set internal-warning
38729 @kindex maint show internal-warning
38730 @kindex maint set demangler-warning
38731 @kindex maint show demangler-warning
38732 @item maint set internal-error @var{action} [ask|yes|no]
38733 @itemx maint show internal-error @var{action}
38734 @itemx maint set internal-warning @var{action} [ask|yes|no]
38735 @itemx maint show internal-warning @var{action}
38736 @itemx maint set demangler-warning @var{action} [ask|yes|no]
38737 @itemx maint show demangler-warning @var{action}
38738 When @value{GDBN} reports an internal problem (error or warning) it
38739 gives the user the opportunity to both quit @value{GDBN} and create a
38740 core file of the current @value{GDBN} session. These commands let you
38741 override the default behaviour for each particular @var{action},
38742 described in the table below.
38743
38744 @table @samp
38745 @item quit
38746 You can specify that @value{GDBN} should always (yes) or never (no)
38747 quit. The default is to ask the user what to do.
38748
38749 @item corefile
38750 You can specify that @value{GDBN} should always (yes) or never (no)
38751 create a core file. The default is to ask the user what to do. Note
38752 that there is no @code{corefile} option for @code{demangler-warning}:
38753 demangler warnings always create a core file and this cannot be
38754 disabled.
38755 @end table
38756
38757 @kindex maint packet
38758 @item maint packet @var{text}
38759 If @value{GDBN} is talking to an inferior via the serial protocol,
38760 then this command sends the string @var{text} to the inferior, and
38761 displays the response packet. @value{GDBN} supplies the initial
38762 @samp{$} character, the terminating @samp{#} character, and the
38763 checksum.
38764
38765 @kindex maint print architecture
38766 @item maint print architecture @r{[}@var{file}@r{]}
38767 Print the entire architecture configuration. The optional argument
38768 @var{file} names the file where the output goes.
38769
38770 @kindex maint print c-tdesc
38771 @item maint print c-tdesc @r{[}-single-feature@r{]} @r{[}@var{file}@r{]}
38772 Print the target description (@pxref{Target Descriptions}) as
38773 a C source file. By default, the target description is for the current
38774 target, but if the optional argument @var{file} is provided, that file
38775 is used to produce the description. The @var{file} should be an XML
38776 document, of the form described in @ref{Target Description Format}.
38777 The created source file is built into @value{GDBN} when @value{GDBN} is
38778 built again. This command is used by developers after they add or
38779 modify XML target descriptions.
38780
38781 When the optional flag @samp{-single-feature} is provided then the
38782 target description being processed (either the default, or from
38783 @var{file}) must only contain a single feature. The source file
38784 produced is different in this case.
38785
38786 @kindex maint print xml-tdesc
38787 @item maint print xml-tdesc @r{[}@var{file}@r{]}
38788 Print the target description (@pxref{Target Descriptions}) as an XML
38789 file. By default print the target description for the current target,
38790 but if the optional argument @var{file} is provided, then that file is
38791 read in by GDB and then used to produce the description. The
38792 @var{file} should be an XML document, of the form described in
38793 @ref{Target Description Format}.
38794
38795 @kindex maint check xml-descriptions
38796 @item maint check xml-descriptions @var{dir}
38797 Check that the target descriptions dynamically created by @value{GDBN}
38798 equal the descriptions created from XML files found in @var{dir}.
38799
38800 @anchor{maint check libthread-db}
38801 @kindex maint check libthread-db
38802 @item maint check libthread-db
38803 Run integrity checks on the current inferior's thread debugging
38804 library. This exercises all @code{libthread_db} functionality used by
38805 @value{GDBN} on GNU/Linux systems, and by extension also exercises the
38806 @code{proc_service} functions provided by @value{GDBN} that
38807 @code{libthread_db} uses. Note that parts of the test may be skipped
38808 on some platforms when debugging core files.
38809
38810 @kindex maint print core-file-backed-mappings
38811 @cindex memory address space mappings
38812 @item maint print core-file-backed-mappings
38813 Print the file-backed mappings which were loaded from a core file note.
38814 This output represents state internal to @value{GDBN} and should be
38815 similar to the mappings displayed by the @code{info proc mappings}
38816 command.
38817
38818 @kindex maint print dummy-frames
38819 @item maint print dummy-frames
38820 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
38821
38822 @smallexample
38823 (@value{GDBP}) @kbd{b add}
38824 @dots{}
38825 (@value{GDBP}) @kbd{print add(2,3)}
38826 Breakpoint 2, add (a=2, b=3) at @dots{}
38827 58 return (a + b);
38828 The program being debugged stopped while in a function called from GDB.
38829 @dots{}
38830 (@value{GDBP}) @kbd{maint print dummy-frames}
38831 0xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
38832 (@value{GDBP})
38833 @end smallexample
38834
38835 Takes an optional file parameter.
38836
38837 @kindex maint print registers
38838 @kindex maint print raw-registers
38839 @kindex maint print cooked-registers
38840 @kindex maint print register-groups
38841 @kindex maint print remote-registers
38842 @item maint print registers @r{[}@var{file}@r{]}
38843 @itemx maint print raw-registers @r{[}@var{file}@r{]}
38844 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
38845 @itemx maint print register-groups @r{[}@var{file}@r{]}
38846 @itemx maint print remote-registers @r{[}@var{file}@r{]}
38847 Print @value{GDBN}'s internal register data structures.
38848
38849 The command @code{maint print raw-registers} includes the contents of
38850 the raw register cache; the command @code{maint print
38851 cooked-registers} includes the (cooked) value of all registers,
38852 including registers which aren't available on the target nor visible
38853 to user; the command @code{maint print register-groups} includes the
38854 groups that each register is a member of; and the command @code{maint
38855 print remote-registers} includes the remote target's register numbers
38856 and offsets in the `G' packets.
38857
38858 These commands take an optional parameter, a file name to which to
38859 write the information.
38860
38861 @kindex maint print reggroups
38862 @item maint print reggroups @r{[}@var{file}@r{]}
38863 Print @value{GDBN}'s internal register group data structures. The
38864 optional argument @var{file} tells to what file to write the
38865 information.
38866
38867 The register groups info looks like this:
38868
38869 @smallexample
38870 (@value{GDBP}) @kbd{maint print reggroups}
38871 Group Type
38872 general user
38873 float user
38874 all user
38875 vector user
38876 system user
38877 save internal
38878 restore internal
38879 @end smallexample
38880
38881 @kindex maint flush register-cache
38882 @kindex flushregs
38883 @cindex register cache, flushing
38884 @item maint flush register-cache
38885 @itemx flushregs
38886 Flush the contents of the register cache and as a consequence the
38887 frame cache. This command is useful when debugging issues related to
38888 register fetching, or frame unwinding. The command @code{flushregs}
38889 is deprecated in favor of @code{maint flush register-cache}.
38890
38891 @kindex maint print objfiles
38892 @cindex info for known object files
38893 @item maint print objfiles @r{[}@var{regexp}@r{]}
38894 Print a dump of all known object files.
38895 If @var{regexp} is specified, only print object files whose names
38896 match @var{regexp}. For each object file, this command prints its name,
38897 address in memory, and all of its psymtabs and symtabs.
38898
38899 @kindex maint print user-registers
38900 @cindex user registers
38901 @item maint print user-registers
38902 List all currently available @dfn{user registers}. User registers
38903 typically provide alternate names for actual hardware registers. They
38904 include the four ``standard'' registers @code{$fp}, @code{$pc},
38905 @code{$sp}, and @code{$ps}. @xref{standard registers}. User
38906 registers can be used in expressions in the same way as the canonical
38907 register names, but only the latter are listed by the @code{info
38908 registers} and @code{maint print registers} commands.
38909
38910 @kindex maint print section-scripts
38911 @cindex info for known .debug_gdb_scripts-loaded scripts
38912 @item maint print section-scripts [@var{regexp}]
38913 Print a dump of scripts specified in the @code{.debug_gdb_section} section.
38914 If @var{regexp} is specified, only print scripts loaded by object files
38915 matching @var{regexp}.
38916 For each script, this command prints its name as specified in the objfile,
38917 and the full path if known.
38918 @xref{dotdebug_gdb_scripts section}.
38919
38920 @kindex maint print statistics
38921 @cindex bcache statistics
38922 @item maint print statistics
38923 This command prints, for each object file in the program, various data
38924 about that object file followed by the byte cache (@dfn{bcache})
38925 statistics for the object file. The objfile data includes the number
38926 of minimal, partial, full, and stabs symbols, the number of types
38927 defined by the objfile, the number of as yet unexpanded psym tables,
38928 the number of line tables and string tables, and the amount of memory
38929 used by the various tables. The bcache statistics include the counts,
38930 sizes, and counts of duplicates of all and unique objects, max,
38931 average, and median entry size, total memory used and its overhead and
38932 savings, and various measures of the hash table size and chain
38933 lengths.
38934
38935 @kindex maint print target-stack
38936 @cindex target stack description
38937 @item maint print target-stack
38938 A @dfn{target} is an interface between the debugger and a particular
38939 kind of file or process. Targets can be stacked in @dfn{strata},
38940 so that more than one target can potentially respond to a request.
38941 In particular, memory accesses will walk down the stack of targets
38942 until they find a target that is interested in handling that particular
38943 address.
38944
38945 This command prints a short description of each layer that was pushed on
38946 the @dfn{target stack}, starting from the top layer down to the bottom one.
38947
38948 @kindex maint print type
38949 @cindex type chain of a data type
38950 @item maint print type @var{expr}
38951 Print the type chain for a type specified by @var{expr}. The argument
38952 can be either a type name or a symbol. If it is a symbol, the type of
38953 that symbol is described. The type chain produced by this command is
38954 a recursive definition of the data type as stored in @value{GDBN}'s
38955 data structures, including its flags and contained types.
38956
38957 @kindex maint selftest
38958 @cindex self tests
38959 @item maint selftest @r{[}@var{filter}@r{]}
38960 Run any self tests that were compiled in to @value{GDBN}. This will
38961 print a message showing how many tests were run, and how many failed.
38962 If a @var{filter} is passed, only the tests with @var{filter} in their
38963 name will by ran.
38964
38965 @kindex maint info selftests
38966 @cindex self tests
38967 @item maint info selftests
38968 List the selftests compiled in to @value{GDBN}.
38969
38970 @kindex maint set dwarf always-disassemble
38971 @kindex maint show dwarf always-disassemble
38972 @item maint set dwarf always-disassemble
38973 @item maint show dwarf always-disassemble
38974 Control the behavior of @code{info address} when using DWARF debugging
38975 information.
38976
38977 The default is @code{off}, which means that @value{GDBN} should try to
38978 describe a variable's location in an easily readable format. When
38979 @code{on}, @value{GDBN} will instead display the DWARF location
38980 expression in an assembly-like format. Note that some locations are
38981 too complex for @value{GDBN} to describe simply; in this case you will
38982 always see the disassembly form.
38983
38984 Here is an example of the resulting disassembly:
38985
38986 @smallexample
38987 (gdb) info addr argc
38988 Symbol "argc" is a complex DWARF expression:
38989 1: DW_OP_fbreg 0
38990 @end smallexample
38991
38992 For more information on these expressions, see
38993 @uref{http://www.dwarfstd.org/, the DWARF standard}.
38994
38995 @kindex maint set dwarf max-cache-age
38996 @kindex maint show dwarf max-cache-age
38997 @item maint set dwarf max-cache-age
38998 @itemx maint show dwarf max-cache-age
38999 Control the DWARF compilation unit cache.
39000
39001 @cindex DWARF compilation units cache
39002 In object files with inter-compilation-unit references, such as those
39003 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
39004 reader needs to frequently refer to previously read compilation units.
39005 This setting controls how long a compilation unit will remain in the
39006 cache if it is not referenced. A higher limit means that cached
39007 compilation units will be stored in memory longer, and more total
39008 memory will be used. Setting it to zero disables caching, which will
39009 slow down @value{GDBN} startup, but reduce memory consumption.
39010
39011 @kindex maint set dwarf unwinders
39012 @kindex maint show dwarf unwinders
39013 @item maint set dwarf unwinders
39014 @itemx maint show dwarf unwinders
39015 Control use of the DWARF frame unwinders.
39016
39017 @cindex DWARF frame unwinders
39018 Many targets that support DWARF debugging use @value{GDBN}'s DWARF
39019 frame unwinders to build the backtrace. Many of these targets will
39020 also have a second mechanism for building the backtrace for use in
39021 cases where DWARF information is not available, this second mechanism
39022 is often an analysis of a function's prologue.
39023
39024 In order to extend testing coverage of the second level stack
39025 unwinding mechanisms it is helpful to be able to disable the DWARF
39026 stack unwinders, this can be done with this switch.
39027
39028 In normal use of @value{GDBN} disabling the DWARF unwinders is not
39029 advisable, there are cases that are better handled through DWARF than
39030 prologue analysis, and the debug experience is likely to be better
39031 with the DWARF frame unwinders enabled.
39032
39033 If DWARF frame unwinders are not supported for a particular target
39034 architecture, then enabling this flag does not cause them to be used.
39035
39036 @kindex maint set worker-threads
39037 @kindex maint show worker-threads
39038 @item maint set worker-threads
39039 @item maint show worker-threads
39040 Control the number of worker threads that may be used by @value{GDBN}.
39041 On capable hosts, @value{GDBN} may use multiple threads to speed up
39042 certain CPU-intensive operations, such as demangling symbol names.
39043 While the number of threads used by @value{GDBN} may vary, this
39044 command can be used to set an upper bound on this number. The default
39045 is @code{unlimited}, which lets @value{GDBN} choose a reasonable
39046 number. Note that this only controls worker threads started by
39047 @value{GDBN} itself; libraries used by @value{GDBN} may start threads
39048 of their own.
39049
39050 @kindex maint set profile
39051 @kindex maint show profile
39052 @cindex profiling GDB
39053 @item maint set profile
39054 @itemx maint show profile
39055 Control profiling of @value{GDBN}.
39056
39057 Profiling will be disabled until you use the @samp{maint set profile}
39058 command to enable it. When you enable profiling, the system will begin
39059 collecting timing and execution count data; when you disable profiling or
39060 exit @value{GDBN}, the results will be written to a log file. Remember that
39061 if you use profiling, @value{GDBN} will overwrite the profiling log file
39062 (often called @file{gmon.out}). If you have a record of important profiling
39063 data in a @file{gmon.out} file, be sure to move it to a safe location.
39064
39065 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
39066 compiled with the @samp{-pg} compiler option.
39067
39068 @kindex maint set show-debug-regs
39069 @kindex maint show show-debug-regs
39070 @cindex hardware debug registers
39071 @item maint set show-debug-regs
39072 @itemx maint show show-debug-regs
39073 Control whether to show variables that mirror the hardware debug
39074 registers. Use @code{on} to enable, @code{off} to disable. If
39075 enabled, the debug registers values are shown when @value{GDBN} inserts or
39076 removes a hardware breakpoint or watchpoint, and when the inferior
39077 triggers a hardware-assisted breakpoint or watchpoint.
39078
39079 @kindex maint set show-all-tib
39080 @kindex maint show show-all-tib
39081 @item maint set show-all-tib
39082 @itemx maint show show-all-tib
39083 Control whether to show all non zero areas within a 1k block starting
39084 at thread local base, when using the @samp{info w32 thread-information-block}
39085 command.
39086
39087 @kindex maint set target-async
39088 @kindex maint show target-async
39089 @item maint set target-async
39090 @itemx maint show target-async
39091 This controls whether @value{GDBN} targets operate in synchronous or
39092 asynchronous mode (@pxref{Background Execution}). Normally the
39093 default is asynchronous, if it is available; but this can be changed
39094 to more easily debug problems occurring only in synchronous mode.
39095
39096 @kindex maint set target-non-stop @var{mode} [on|off|auto]
39097 @kindex maint show target-non-stop
39098 @item maint set target-non-stop
39099 @itemx maint show target-non-stop
39100
39101 This controls whether @value{GDBN} targets always operate in non-stop
39102 mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
39103 Mode}). The default is @code{auto}, meaning non-stop mode is enabled
39104 if supported by the target.
39105
39106 @table @code
39107 @item maint set target-non-stop auto
39108 This is the default mode. @value{GDBN} controls the target in
39109 non-stop mode if the target supports it.
39110
39111 @item maint set target-non-stop on
39112 @value{GDBN} controls the target in non-stop mode even if the target
39113 does not indicate support.
39114
39115 @item maint set target-non-stop off
39116 @value{GDBN} does not control the target in non-stop mode even if the
39117 target supports it.
39118 @end table
39119
39120 @kindex maint set tui-resize-message
39121 @kindex maint show tui-resize-message
39122 @item maint set tui-resize-message
39123 @item maint show tui-resize-message
39124 Control whether @value{GDBN} displays a message each time the terminal
39125 is resized when in TUI mode. The default is @code{off}, which means
39126 that @value{GDBN} is silent during resizes. When @code{on},
39127 @value{GDBN} will display a message after a resize is completed; the
39128 message will include a number indicating how many times the terminal
39129 has been resized. This setting is intended for use by the test suite,
39130 where it would otherwise be difficult to determine when a resize and
39131 refresh has been completed.
39132
39133 @kindex maint set per-command
39134 @kindex maint show per-command
39135 @item maint set per-command
39136 @itemx maint show per-command
39137 @cindex resources used by commands
39138
39139 @value{GDBN} can display the resources used by each command.
39140 This is useful in debugging performance problems.
39141
39142 @table @code
39143 @item maint set per-command space [on|off]
39144 @itemx maint show per-command space
39145 Enable or disable the printing of the memory used by GDB for each command.
39146 If enabled, @value{GDBN} will display how much memory each command
39147 took, following the command's own output.
39148 This can also be requested by invoking @value{GDBN} with the
39149 @option{--statistics} command-line switch (@pxref{Mode Options}).
39150
39151 @item maint set per-command time [on|off]
39152 @itemx maint show per-command time
39153 Enable or disable the printing of the execution time of @value{GDBN}
39154 for each command.
39155 If enabled, @value{GDBN} will display how much time it
39156 took to execute each command, following the command's own output.
39157 Both CPU time and wallclock time are printed.
39158 Printing both is useful when trying to determine whether the cost is
39159 CPU or, e.g., disk/network latency.
39160 Note that the CPU time printed is for @value{GDBN} only, it does not include
39161 the execution time of the inferior because there's no mechanism currently
39162 to compute how much time was spent by @value{GDBN} and how much time was
39163 spent by the program been debugged.
39164 This can also be requested by invoking @value{GDBN} with the
39165 @option{--statistics} command-line switch (@pxref{Mode Options}).
39166
39167 @item maint set per-command symtab [on|off]
39168 @itemx maint show per-command symtab
39169 Enable or disable the printing of basic symbol table statistics
39170 for each command.
39171 If enabled, @value{GDBN} will display the following information:
39172
39173 @enumerate a
39174 @item
39175 number of symbol tables
39176 @item
39177 number of primary symbol tables
39178 @item
39179 number of blocks in the blockvector
39180 @end enumerate
39181 @end table
39182
39183 @kindex maint set check-libthread-db
39184 @kindex maint show check-libthread-db
39185 @item maint set check-libthread-db [on|off]
39186 @itemx maint show check-libthread-db
39187 Control whether @value{GDBN} should run integrity checks on inferior
39188 specific thread debugging libraries as they are loaded. The default
39189 is not to perform such checks. If any check fails @value{GDBN} will
39190 unload the library and continue searching for a suitable candidate as
39191 described in @ref{set libthread-db-search-path}. For more information
39192 about the tests, see @ref{maint check libthread-db}.
39193
39194 @kindex maint space
39195 @cindex memory used by commands
39196 @item maint space @var{value}
39197 An alias for @code{maint set per-command space}.
39198 A non-zero value enables it, zero disables it.
39199
39200 @kindex maint time
39201 @cindex time of command execution
39202 @item maint time @var{value}
39203 An alias for @code{maint set per-command time}.
39204 A non-zero value enables it, zero disables it.
39205
39206 @kindex maint translate-address
39207 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
39208 Find the symbol stored at the location specified by the address
39209 @var{addr} and an optional section name @var{section}. If found,
39210 @value{GDBN} prints the name of the closest symbol and an offset from
39211 the symbol's location to the specified address. This is similar to
39212 the @code{info address} command (@pxref{Symbols}), except that this
39213 command also allows to find symbols in other sections.
39214
39215 If section was not specified, the section in which the symbol was found
39216 is also printed. For dynamically linked executables, the name of
39217 executable or shared library containing the symbol is printed as well.
39218
39219 @kindex maint test-options
39220 @item maint test-options require-delimiter
39221 @itemx maint test-options unknown-is-error
39222 @itemx maint test-options unknown-is-operand
39223 These commands are used by the testsuite to validate the command
39224 options framework. The @code{require-delimiter} variant requires a
39225 double-dash delimiter to indicate end of options. The
39226 @code{unknown-is-error} and @code{unknown-is-operand} do not. The
39227 @code{unknown-is-error} variant throws an error on unknown option,
39228 while @code{unknown-is-operand} treats unknown options as the start of
39229 the command's operands. When run, the commands output the result of
39230 the processed options. When completed, the commands store the
39231 internal result of completion in a variable exposed by the @code{maint
39232 show test-options-completion-result} command.
39233
39234 @kindex maint show test-options-completion-result
39235 @item maint show test-options-completion-result
39236 Shows the result of completing the @code{maint test-options}
39237 subcommands. This is used by the testsuite to validate completion
39238 support in the command options framework.
39239
39240 @kindex maint set test-settings
39241 @kindex maint show test-settings
39242 @item maint set test-settings @var{kind}
39243 @itemx maint show test-settings @var{kind}
39244 These are representative commands for each @var{kind} of setting type
39245 @value{GDBN} supports. They are used by the testsuite for exercising
39246 the settings infrastructure.
39247
39248 @kindex maint with
39249 @item maint with @var{setting} [@var{value}] [-- @var{command}]
39250 Like the @code{with} command, but works with @code{maintenance set}
39251 variables. This is used by the testsuite to exercise the @code{with}
39252 command's infrastructure.
39253
39254 @end table
39255
39256 The following command is useful for non-interactive invocations of
39257 @value{GDBN}, such as in the test suite.
39258
39259 @table @code
39260 @item set watchdog @var{nsec}
39261 @kindex set watchdog
39262 @cindex watchdog timer
39263 @cindex timeout for commands
39264 Set the maximum number of seconds @value{GDBN} will wait for the
39265 target operation to finish. If this time expires, @value{GDBN}
39266 reports and error and the command is aborted.
39267
39268 @item show watchdog
39269 Show the current setting of the target wait timeout.
39270 @end table
39271
39272 @node Remote Protocol
39273 @appendix @value{GDBN} Remote Serial Protocol
39274
39275 @menu
39276 * Overview::
39277 * Packets::
39278 * Stop Reply Packets::
39279 * General Query Packets::
39280 * Architecture-Specific Protocol Details::
39281 * Tracepoint Packets::
39282 * Host I/O Packets::
39283 * Interrupts::
39284 * Notification Packets::
39285 * Remote Non-Stop::
39286 * Packet Acknowledgment::
39287 * Examples::
39288 * File-I/O Remote Protocol Extension::
39289 * Library List Format::
39290 * Library List Format for SVR4 Targets::
39291 * Memory Map Format::
39292 * Thread List Format::
39293 * Traceframe Info Format::
39294 * Branch Trace Format::
39295 * Branch Trace Configuration Format::
39296 @end menu
39297
39298 @node Overview
39299 @section Overview
39300
39301 There may be occasions when you need to know something about the
39302 protocol---for example, if there is only one serial port to your target
39303 machine, you might want your program to do something special if it
39304 recognizes a packet meant for @value{GDBN}.
39305
39306 In the examples below, @samp{->} and @samp{<-} are used to indicate
39307 transmitted and received data, respectively.
39308
39309 @cindex protocol, @value{GDBN} remote serial
39310 @cindex serial protocol, @value{GDBN} remote
39311 @cindex remote serial protocol
39312 All @value{GDBN} commands and responses (other than acknowledgments
39313 and notifications, see @ref{Notification Packets}) are sent as a
39314 @var{packet}. A @var{packet} is introduced with the character
39315 @samp{$}, the actual @var{packet-data}, and the terminating character
39316 @samp{#} followed by a two-digit @var{checksum}:
39317
39318 @smallexample
39319 @code{$}@var{packet-data}@code{#}@var{checksum}
39320 @end smallexample
39321 @noindent
39322
39323 @cindex checksum, for @value{GDBN} remote
39324 @noindent
39325 The two-digit @var{checksum} is computed as the modulo 256 sum of all
39326 characters between the leading @samp{$} and the trailing @samp{#} (an
39327 eight bit unsigned checksum).
39328
39329 Implementors should note that prior to @value{GDBN} 5.0 the protocol
39330 specification also included an optional two-digit @var{sequence-id}:
39331
39332 @smallexample
39333 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
39334 @end smallexample
39335
39336 @cindex sequence-id, for @value{GDBN} remote
39337 @noindent
39338 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
39339 has never output @var{sequence-id}s. Stubs that handle packets added
39340 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
39341
39342 When either the host or the target machine receives a packet, the first
39343 response expected is an acknowledgment: either @samp{+} (to indicate
39344 the package was received correctly) or @samp{-} (to request
39345 retransmission):
39346
39347 @smallexample
39348 -> @code{$}@var{packet-data}@code{#}@var{checksum}
39349 <- @code{+}
39350 @end smallexample
39351 @noindent
39352
39353 The @samp{+}/@samp{-} acknowledgments can be disabled
39354 once a connection is established.
39355 @xref{Packet Acknowledgment}, for details.
39356
39357 The host (@value{GDBN}) sends @var{command}s, and the target (the
39358 debugging stub incorporated in your program) sends a @var{response}. In
39359 the case of step and continue @var{command}s, the response is only sent
39360 when the operation has completed, and the target has again stopped all
39361 threads in all attached processes. This is the default all-stop mode
39362 behavior, but the remote protocol also supports @value{GDBN}'s non-stop
39363 execution mode; see @ref{Remote Non-Stop}, for details.
39364
39365 @var{packet-data} consists of a sequence of characters with the
39366 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
39367 exceptions).
39368
39369 @cindex remote protocol, field separator
39370 Fields within the packet should be separated using @samp{,} @samp{;} or
39371 @samp{:}. Except where otherwise noted all numbers are represented in
39372 @sc{hex} with leading zeros suppressed.
39373
39374 Implementors should note that prior to @value{GDBN} 5.0, the character
39375 @samp{:} could not appear as the third character in a packet (as it
39376 would potentially conflict with the @var{sequence-id}).
39377
39378 @cindex remote protocol, binary data
39379 @anchor{Binary Data}
39380 Binary data in most packets is encoded either as two hexadecimal
39381 digits per byte of binary data. This allowed the traditional remote
39382 protocol to work over connections which were only seven-bit clean.
39383 Some packets designed more recently assume an eight-bit clean
39384 connection, and use a more efficient encoding to send and receive
39385 binary data.
39386
39387 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
39388 as an escape character. Any escaped byte is transmitted as the escape
39389 character followed by the original character XORed with @code{0x20}.
39390 For example, the byte @code{0x7d} would be transmitted as the two
39391 bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
39392 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
39393 @samp{@}}) must always be escaped. Responses sent by the stub
39394 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
39395 is not interpreted as the start of a run-length encoded sequence
39396 (described next).
39397
39398 Response @var{data} can be run-length encoded to save space.
39399 Run-length encoding replaces runs of identical characters with one
39400 instance of the repeated character, followed by a @samp{*} and a
39401 repeat count. The repeat count is itself sent encoded, to avoid
39402 binary characters in @var{data}: a value of @var{n} is sent as
39403 @code{@var{n}+29}. For a repeat count greater or equal to 3, this
39404 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
39405 code 32) for a repeat count of 3. (This is because run-length
39406 encoding starts to win for counts 3 or more.) Thus, for example,
39407 @samp{0* } is a run-length encoding of ``0000'': the space character
39408 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
39409 3}} more times.
39410
39411 The printable characters @samp{#} and @samp{$} or with a numeric value
39412 greater than 126 must not be used. Runs of six repeats (@samp{#}) or
39413 seven repeats (@samp{$}) can be expanded using a repeat count of only
39414 five (@samp{"}). For example, @samp{00000000} can be encoded as
39415 @samp{0*"00}.
39416
39417 The error response returned for some packets includes a two character
39418 error number. That number is not well defined.
39419
39420 @cindex empty response, for unsupported packets
39421 For any @var{command} not supported by the stub, an empty response
39422 (@samp{$#00}) should be returned. That way it is possible to extend the
39423 protocol. A newer @value{GDBN} can tell if a packet is supported based
39424 on that response.
39425
39426 At a minimum, a stub is required to support the @samp{?} command to
39427 tell @value{GDBN} the reason for halting, @samp{g} and @samp{G}
39428 commands for register access, and the @samp{m} and @samp{M} commands
39429 for memory access. Stubs that only control single-threaded targets
39430 can implement run control with the @samp{c} (continue) command, and if
39431 the target architecture supports hardware-assisted single-stepping,
39432 the @samp{s} (step) command. Stubs that support multi-threading
39433 targets should support the @samp{vCont} command. All other commands
39434 are optional.
39435
39436 @node Packets
39437 @section Packets
39438
39439 The following table provides a complete list of all currently defined
39440 @var{command}s and their corresponding response @var{data}.
39441 @xref{File-I/O Remote Protocol Extension}, for details about the File
39442 I/O extension of the remote protocol.
39443
39444 Each packet's description has a template showing the packet's overall
39445 syntax, followed by an explanation of the packet's meaning. We
39446 include spaces in some of the templates for clarity; these are not
39447 part of the packet's syntax. No @value{GDBN} packet uses spaces to
39448 separate its components. For example, a template like @samp{foo
39449 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
39450 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
39451 @var{baz}. @value{GDBN} does not transmit a space character between the
39452 @samp{foo} and the @var{bar}, or between the @var{bar} and the
39453 @var{baz}.
39454
39455 @cindex @var{thread-id}, in remote protocol
39456 @anchor{thread-id syntax}
39457 Several packets and replies include a @var{thread-id} field to identify
39458 a thread. Normally these are positive numbers with a target-specific
39459 interpretation, formatted as big-endian hex strings. A @var{thread-id}
39460 can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
39461 pick any thread.
39462
39463 In addition, the remote protocol supports a multiprocess feature in
39464 which the @var{thread-id} syntax is extended to optionally include both
39465 process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
39466 The @var{pid} (process) and @var{tid} (thread) components each have the
39467 format described above: a positive number with target-specific
39468 interpretation formatted as a big-endian hex string, literal @samp{-1}
39469 to indicate all processes or threads (respectively), or @samp{0} to
39470 indicate an arbitrary process or thread. Specifying just a process, as
39471 @samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
39472 error to specify all processes but a specific thread, such as
39473 @samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
39474 for those packets and replies explicitly documented to include a process
39475 ID, rather than a @var{thread-id}.
39476
39477 The multiprocess @var{thread-id} syntax extensions are only used if both
39478 @value{GDBN} and the stub report support for the @samp{multiprocess}
39479 feature using @samp{qSupported}. @xref{multiprocess extensions}, for
39480 more information.
39481
39482 Note that all packet forms beginning with an upper- or lower-case
39483 letter, other than those described here, are reserved for future use.
39484
39485 Here are the packet descriptions.
39486
39487 @table @samp
39488
39489 @item !
39490 @cindex @samp{!} packet
39491 @anchor{extended mode}
39492 Enable extended mode. In extended mode, the remote server is made
39493 persistent. The @samp{R} packet is used to restart the program being
39494 debugged.
39495
39496 Reply:
39497 @table @samp
39498 @item OK
39499 The remote target both supports and has enabled extended mode.
39500 @end table
39501
39502 @item ?
39503 @cindex @samp{?} packet
39504 @anchor{? packet}
39505 This is sent when connection is first established to query the reason
39506 the target halted. The reply is the same as for step and continue.
39507 This packet has a special interpretation when the target is in
39508 non-stop mode; see @ref{Remote Non-Stop}.
39509
39510 Reply:
39511 @xref{Stop Reply Packets}, for the reply specifications.
39512
39513 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
39514 @cindex @samp{A} packet
39515 Initialized @code{argv[]} array passed into program. @var{arglen}
39516 specifies the number of bytes in the hex encoded byte stream
39517 @var{arg}. See @code{gdbserver} for more details.
39518
39519 Reply:
39520 @table @samp
39521 @item OK
39522 The arguments were set.
39523 @item E @var{NN}
39524 An error occurred.
39525 @end table
39526
39527 @item b @var{baud}
39528 @cindex @samp{b} packet
39529 (Don't use this packet; its behavior is not well-defined.)
39530 Change the serial line speed to @var{baud}.
39531
39532 JTC: @emph{When does the transport layer state change? When it's
39533 received, or after the ACK is transmitted. In either case, there are
39534 problems if the command or the acknowledgment packet is dropped.}
39535
39536 Stan: @emph{If people really wanted to add something like this, and get
39537 it working for the first time, they ought to modify ser-unix.c to send
39538 some kind of out-of-band message to a specially-setup stub and have the
39539 switch happen "in between" packets, so that from remote protocol's point
39540 of view, nothing actually happened.}
39541
39542 @item B @var{addr},@var{mode}
39543 @cindex @samp{B} packet
39544 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
39545 breakpoint at @var{addr}.
39546
39547 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
39548 (@pxref{insert breakpoint or watchpoint packet}).
39549
39550 @cindex @samp{bc} packet
39551 @anchor{bc}
39552 @item bc
39553 Backward continue. Execute the target system in reverse. No parameter.
39554 @xref{Reverse Execution}, for more information.
39555
39556 Reply:
39557 @xref{Stop Reply Packets}, for the reply specifications.
39558
39559 @cindex @samp{bs} packet
39560 @anchor{bs}
39561 @item bs
39562 Backward single step. Execute one instruction in reverse. No parameter.
39563 @xref{Reverse Execution}, for more information.
39564
39565 Reply:
39566 @xref{Stop Reply Packets}, for the reply specifications.
39567
39568 @item c @r{[}@var{addr}@r{]}
39569 @cindex @samp{c} packet
39570 Continue at @var{addr}, which is the address to resume. If @var{addr}
39571 is omitted, resume at current address.
39572
39573 This packet is deprecated for multi-threading support. @xref{vCont
39574 packet}.
39575
39576 Reply:
39577 @xref{Stop Reply Packets}, for the reply specifications.
39578
39579 @item C @var{sig}@r{[};@var{addr}@r{]}
39580 @cindex @samp{C} packet
39581 Continue with signal @var{sig} (hex signal number). If
39582 @samp{;@var{addr}} is omitted, resume at same address.
39583
39584 This packet is deprecated for multi-threading support. @xref{vCont
39585 packet}.
39586
39587 Reply:
39588 @xref{Stop Reply Packets}, for the reply specifications.
39589
39590 @item d
39591 @cindex @samp{d} packet
39592 Toggle debug flag.
39593
39594 Don't use this packet; instead, define a general set packet
39595 (@pxref{General Query Packets}).
39596
39597 @item D
39598 @itemx D;@var{pid}
39599 @cindex @samp{D} packet
39600 The first form of the packet is used to detach @value{GDBN} from the
39601 remote system. It is sent to the remote target
39602 before @value{GDBN} disconnects via the @code{detach} command.
39603
39604 The second form, including a process ID, is used when multiprocess
39605 protocol extensions are enabled (@pxref{multiprocess extensions}), to
39606 detach only a specific process. The @var{pid} is specified as a
39607 big-endian hex string.
39608
39609 Reply:
39610 @table @samp
39611 @item OK
39612 for success
39613 @item E @var{NN}
39614 for an error
39615 @end table
39616
39617 @item F @var{RC},@var{EE},@var{CF};@var{XX}
39618 @cindex @samp{F} packet
39619 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
39620 This is part of the File-I/O protocol extension. @xref{File-I/O
39621 Remote Protocol Extension}, for the specification.
39622
39623 @item g
39624 @anchor{read registers packet}
39625 @cindex @samp{g} packet
39626 Read general registers.
39627
39628 Reply:
39629 @table @samp
39630 @item @var{XX@dots{}}
39631 Each byte of register data is described by two hex digits. The bytes
39632 with the register are transmitted in target byte order. The size of
39633 each register and their position within the @samp{g} packet are
39634 determined by the @value{GDBN} internal gdbarch functions
39635 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
39636
39637 When reading registers from a trace frame (@pxref{Analyze Collected
39638 Data,,Using the Collected Data}), the stub may also return a string of
39639 literal @samp{x}'s in place of the register data digits, to indicate
39640 that the corresponding register has not been collected, thus its value
39641 is unavailable. For example, for an architecture with 4 registers of
39642 4 bytes each, the following reply indicates to @value{GDBN} that
39643 registers 0 and 2 have not been collected, while registers 1 and 3
39644 have been collected, and both have zero value:
39645
39646 @smallexample
39647 -> @code{g}
39648 <- @code{xxxxxxxx00000000xxxxxxxx00000000}
39649 @end smallexample
39650
39651 @item E @var{NN}
39652 for an error.
39653 @end table
39654
39655 @item G @var{XX@dots{}}
39656 @cindex @samp{G} packet
39657 Write general registers. @xref{read registers packet}, for a
39658 description of the @var{XX@dots{}} data.
39659
39660 Reply:
39661 @table @samp
39662 @item OK
39663 for success
39664 @item E @var{NN}
39665 for an error
39666 @end table
39667
39668 @item H @var{op} @var{thread-id}
39669 @cindex @samp{H} packet
39670 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
39671 @samp{G}, et.al.). Depending on the operation to be performed, @var{op}
39672 should be @samp{c} for step and continue operations (note that this
39673 is deprecated, supporting the @samp{vCont} command is a better
39674 option), and @samp{g} for other operations. The thread designator
39675 @var{thread-id} has the format and interpretation described in
39676 @ref{thread-id syntax}.
39677
39678 Reply:
39679 @table @samp
39680 @item OK
39681 for success
39682 @item E @var{NN}
39683 for an error
39684 @end table
39685
39686 @c FIXME: JTC:
39687 @c 'H': How restrictive (or permissive) is the thread model. If a
39688 @c thread is selected and stopped, are other threads allowed
39689 @c to continue to execute? As I mentioned above, I think the
39690 @c semantics of each command when a thread is selected must be
39691 @c described. For example:
39692 @c
39693 @c 'g': If the stub supports threads and a specific thread is
39694 @c selected, returns the register block from that thread;
39695 @c otherwise returns current registers.
39696 @c
39697 @c 'G' If the stub supports threads and a specific thread is
39698 @c selected, sets the registers of the register block of
39699 @c that thread; otherwise sets current registers.
39700
39701 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
39702 @anchor{cycle step packet}
39703 @cindex @samp{i} packet
39704 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
39705 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
39706 step starting at that address.
39707
39708 @item I
39709 @cindex @samp{I} packet
39710 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
39711 step packet}.
39712
39713 @item k
39714 @cindex @samp{k} packet
39715 Kill request.
39716
39717 The exact effect of this packet is not specified.
39718
39719 For a bare-metal target, it may power cycle or reset the target
39720 system. For that reason, the @samp{k} packet has no reply.
39721
39722 For a single-process target, it may kill that process if possible.
39723
39724 A multiple-process target may choose to kill just one process, or all
39725 that are under @value{GDBN}'s control. For more precise control, use
39726 the vKill packet (@pxref{vKill packet}).
39727
39728 If the target system immediately closes the connection in response to
39729 @samp{k}, @value{GDBN} does not consider the lack of packet
39730 acknowledgment to be an error, and assumes the kill was successful.
39731
39732 If connected using @kbd{target extended-remote}, and the target does
39733 not close the connection in response to a kill request, @value{GDBN}
39734 probes the target state as if a new connection was opened
39735 (@pxref{? packet}).
39736
39737 @item m @var{addr},@var{length}
39738 @cindex @samp{m} packet
39739 Read @var{length} addressable memory units starting at address @var{addr}
39740 (@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
39741 any particular boundary.
39742
39743 The stub need not use any particular size or alignment when gathering
39744 data from memory for the response; even if @var{addr} is word-aligned
39745 and @var{length} is a multiple of the word size, the stub is free to
39746 use byte accesses, or not. For this reason, this packet may not be
39747 suitable for accessing memory-mapped I/O devices.
39748 @cindex alignment of remote memory accesses
39749 @cindex size of remote memory accesses
39750 @cindex memory, alignment and size of remote accesses
39751
39752 Reply:
39753 @table @samp
39754 @item @var{XX@dots{}}
39755 Memory contents; each byte is transmitted as a two-digit hexadecimal number.
39756 The reply may contain fewer addressable memory units than requested if the
39757 server was able to read only part of the region of memory.
39758 @item E @var{NN}
39759 @var{NN} is errno
39760 @end table
39761
39762 @item M @var{addr},@var{length}:@var{XX@dots{}}
39763 @cindex @samp{M} packet
39764 Write @var{length} addressable memory units starting at address @var{addr}
39765 (@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
39766 byte is transmitted as a two-digit hexadecimal number.
39767
39768 Reply:
39769 @table @samp
39770 @item OK
39771 for success
39772 @item E @var{NN}
39773 for an error (this includes the case where only part of the data was
39774 written).
39775 @end table
39776
39777 @item p @var{n}
39778 @cindex @samp{p} packet
39779 Read the value of register @var{n}; @var{n} is in hex.
39780 @xref{read registers packet}, for a description of how the returned
39781 register value is encoded.
39782
39783 Reply:
39784 @table @samp
39785 @item @var{XX@dots{}}
39786 the register's value
39787 @item E @var{NN}
39788 for an error
39789 @item @w{}
39790 Indicating an unrecognized @var{query}.
39791 @end table
39792
39793 @item P @var{n@dots{}}=@var{r@dots{}}
39794 @anchor{write register packet}
39795 @cindex @samp{P} packet
39796 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
39797 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
39798 digits for each byte in the register (target byte order).
39799
39800 Reply:
39801 @table @samp
39802 @item OK
39803 for success
39804 @item E @var{NN}
39805 for an error
39806 @end table
39807
39808 @item q @var{name} @var{params}@dots{}
39809 @itemx Q @var{name} @var{params}@dots{}
39810 @cindex @samp{q} packet
39811 @cindex @samp{Q} packet
39812 General query (@samp{q}) and set (@samp{Q}). These packets are
39813 described fully in @ref{General Query Packets}.
39814
39815 @item r
39816 @cindex @samp{r} packet
39817 Reset the entire system.
39818
39819 Don't use this packet; use the @samp{R} packet instead.
39820
39821 @item R @var{XX}
39822 @cindex @samp{R} packet
39823 Restart the program being debugged. The @var{XX}, while needed, is ignored.
39824 This packet is only available in extended mode (@pxref{extended mode}).
39825
39826 The @samp{R} packet has no reply.
39827
39828 @item s @r{[}@var{addr}@r{]}
39829 @cindex @samp{s} packet
39830 Single step, resuming at @var{addr}. If
39831 @var{addr} is omitted, resume at same address.
39832
39833 This packet is deprecated for multi-threading support. @xref{vCont
39834 packet}.
39835
39836 Reply:
39837 @xref{Stop Reply Packets}, for the reply specifications.
39838
39839 @item S @var{sig}@r{[};@var{addr}@r{]}
39840 @anchor{step with signal packet}
39841 @cindex @samp{S} packet
39842 Step with signal. This is analogous to the @samp{C} packet, but
39843 requests a single-step, rather than a normal resumption of execution.
39844
39845 This packet is deprecated for multi-threading support. @xref{vCont
39846 packet}.
39847
39848 Reply:
39849 @xref{Stop Reply Packets}, for the reply specifications.
39850
39851 @item t @var{addr}:@var{PP},@var{MM}
39852 @cindex @samp{t} packet
39853 Search backwards starting at address @var{addr} for a match with pattern
39854 @var{PP} and mask @var{MM}, both of which are are 4 byte long.
39855 There must be at least 3 digits in @var{addr}.
39856
39857 @item T @var{thread-id}
39858 @cindex @samp{T} packet
39859 Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
39860
39861 Reply:
39862 @table @samp
39863 @item OK
39864 thread is still alive
39865 @item E @var{NN}
39866 thread is dead
39867 @end table
39868
39869 @item v
39870 Packets starting with @samp{v} are identified by a multi-letter name,
39871 up to the first @samp{;} or @samp{?} (or the end of the packet).
39872
39873 @item vAttach;@var{pid}
39874 @cindex @samp{vAttach} packet
39875 Attach to a new process with the specified process ID @var{pid}.
39876 The process ID is a
39877 hexadecimal integer identifying the process. In all-stop mode, all
39878 threads in the attached process are stopped; in non-stop mode, it may be
39879 attached without being stopped if that is supported by the target.
39880
39881 @c In non-stop mode, on a successful vAttach, the stub should set the
39882 @c current thread to a thread of the newly-attached process. After
39883 @c attaching, GDB queries for the attached process's thread ID with qC.
39884 @c Also note that, from a user perspective, whether or not the
39885 @c target is stopped on attach in non-stop mode depends on whether you
39886 @c use the foreground or background version of the attach command, not
39887 @c on what vAttach does; GDB does the right thing with respect to either
39888 @c stopping or restarting threads.
39889
39890 This packet is only available in extended mode (@pxref{extended mode}).
39891
39892 Reply:
39893 @table @samp
39894 @item E @var{nn}
39895 for an error
39896 @item @r{Any stop packet}
39897 for success in all-stop mode (@pxref{Stop Reply Packets})
39898 @item OK
39899 for success in non-stop mode (@pxref{Remote Non-Stop})
39900 @end table
39901
39902 @item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
39903 @cindex @samp{vCont} packet
39904 @anchor{vCont packet}
39905 Resume the inferior, specifying different actions for each thread.
39906
39907 For each inferior thread, the leftmost action with a matching
39908 @var{thread-id} is applied. Threads that don't match any action
39909 remain in their current state. Thread IDs are specified using the
39910 syntax described in @ref{thread-id syntax}. If multiprocess
39911 extensions (@pxref{multiprocess extensions}) are supported, actions
39912 can be specified to match all threads in a process by using the
39913 @samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
39914 @var{thread-id} matches all threads. Specifying no actions is an
39915 error.
39916
39917 Currently supported actions are:
39918
39919 @table @samp
39920 @item c
39921 Continue.
39922 @item C @var{sig}
39923 Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
39924 @item s
39925 Step.
39926 @item S @var{sig}
39927 Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
39928 @item t
39929 Stop.
39930 @item r @var{start},@var{end}
39931 Step once, and then keep stepping as long as the thread stops at
39932 addresses between @var{start} (inclusive) and @var{end} (exclusive).
39933 The remote stub reports a stop reply when either the thread goes out
39934 of the range or is stopped due to an unrelated reason, such as hitting
39935 a breakpoint. @xref{range stepping}.
39936
39937 If the range is empty (@var{start} == @var{end}), then the action
39938 becomes equivalent to the @samp{s} action. In other words,
39939 single-step once, and report the stop (even if the stepped instruction
39940 jumps to @var{start}).
39941
39942 (A stop reply may be sent at any point even if the PC is still within
39943 the stepping range; for example, it is valid to implement this packet
39944 in a degenerate way as a single instruction step operation.)
39945
39946 @end table
39947
39948 The optional argument @var{addr} normally associated with the
39949 @samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
39950 not supported in @samp{vCont}.
39951
39952 The @samp{t} action is only relevant in non-stop mode
39953 (@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
39954 A stop reply should be generated for any affected thread not already stopped.
39955 When a thread is stopped by means of a @samp{t} action,
39956 the corresponding stop reply should indicate that the thread has stopped with
39957 signal @samp{0}, regardless of whether the target uses some other signal
39958 as an implementation detail.
39959
39960 The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
39961 @samp{r} actions for threads that are already running. Conversely,
39962 the server must ignore @samp{t} actions for threads that are already
39963 stopped.
39964
39965 @emph{Note:} In non-stop mode, a thread is considered running until
39966 @value{GDBN} acknowledges an asynchronous stop notification for it with
39967 the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
39968
39969 The stub must support @samp{vCont} if it reports support for
39970 multiprocess extensions (@pxref{multiprocess extensions}).
39971
39972 Reply:
39973 @xref{Stop Reply Packets}, for the reply specifications.
39974
39975 @item vCont?
39976 @cindex @samp{vCont?} packet
39977 Request a list of actions supported by the @samp{vCont} packet.
39978
39979 Reply:
39980 @table @samp
39981 @item vCont@r{[};@var{action}@dots{}@r{]}
39982 The @samp{vCont} packet is supported. Each @var{action} is a supported
39983 command in the @samp{vCont} packet.
39984 @item @w{}
39985 The @samp{vCont} packet is not supported.
39986 @end table
39987
39988 @anchor{vCtrlC packet}
39989 @item vCtrlC
39990 @cindex @samp{vCtrlC} packet
39991 Interrupt remote target as if a control-C was pressed on the remote
39992 terminal. This is the equivalent to reacting to the @code{^C}
39993 (@samp{\003}, the control-C character) character in all-stop mode
39994 while the target is running, except this works in non-stop mode.
39995 @xref{interrupting remote targets}, for more info on the all-stop
39996 variant.
39997
39998 Reply:
39999 @table @samp
40000 @item E @var{nn}
40001 for an error
40002 @item OK
40003 for success
40004 @end table
40005
40006 @item vFile:@var{operation}:@var{parameter}@dots{}
40007 @cindex @samp{vFile} packet
40008 Perform a file operation on the target system. For details,
40009 see @ref{Host I/O Packets}.
40010
40011 @item vFlashErase:@var{addr},@var{length}
40012 @cindex @samp{vFlashErase} packet
40013 Direct the stub to erase @var{length} bytes of flash starting at
40014 @var{addr}. The region may enclose any number of flash blocks, but
40015 its start and end must fall on block boundaries, as indicated by the
40016 flash block size appearing in the memory map (@pxref{Memory Map
40017 Format}). @value{GDBN} groups flash memory programming operations
40018 together, and sends a @samp{vFlashDone} request after each group; the
40019 stub is allowed to delay erase operation until the @samp{vFlashDone}
40020 packet is received.
40021
40022 Reply:
40023 @table @samp
40024 @item OK
40025 for success
40026 @item E @var{NN}
40027 for an error
40028 @end table
40029
40030 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
40031 @cindex @samp{vFlashWrite} packet
40032 Direct the stub to write data to flash address @var{addr}. The data
40033 is passed in binary form using the same encoding as for the @samp{X}
40034 packet (@pxref{Binary Data}). The memory ranges specified by
40035 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
40036 not overlap, and must appear in order of increasing addresses
40037 (although @samp{vFlashErase} packets for higher addresses may already
40038 have been received; the ordering is guaranteed only between
40039 @samp{vFlashWrite} packets). If a packet writes to an address that was
40040 neither erased by a preceding @samp{vFlashErase} packet nor by some other
40041 target-specific method, the results are unpredictable.
40042
40043
40044 Reply:
40045 @table @samp
40046 @item OK
40047 for success
40048 @item E.memtype
40049 for vFlashWrite addressing non-flash memory
40050 @item E @var{NN}
40051 for an error
40052 @end table
40053
40054 @item vFlashDone
40055 @cindex @samp{vFlashDone} packet
40056 Indicate to the stub that flash programming operation is finished.
40057 The stub is permitted to delay or batch the effects of a group of
40058 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
40059 @samp{vFlashDone} packet is received. The contents of the affected
40060 regions of flash memory are unpredictable until the @samp{vFlashDone}
40061 request is completed.
40062
40063 @item vKill;@var{pid}
40064 @cindex @samp{vKill} packet
40065 @anchor{vKill packet}
40066 Kill the process with the specified process ID @var{pid}, which is a
40067 hexadecimal integer identifying the process. This packet is used in
40068 preference to @samp{k} when multiprocess protocol extensions are
40069 supported; see @ref{multiprocess extensions}.
40070
40071 Reply:
40072 @table @samp
40073 @item E @var{nn}
40074 for an error
40075 @item OK
40076 for success
40077 @end table
40078
40079 @item vMustReplyEmpty
40080 @cindex @samp{vMustReplyEmpty} packet
40081 The correct reply to an unknown @samp{v} packet is to return the empty
40082 string, however, some older versions of @command{gdbserver} would
40083 incorrectly return @samp{OK} for unknown @samp{v} packets.
40084
40085 The @samp{vMustReplyEmpty} is used as a feature test to check how
40086 @command{gdbserver} handles unknown packets, it is important that this
40087 packet be handled in the same way as other unknown @samp{v} packets.
40088 If this packet is handled differently to other unknown @samp{v}
40089 packets then it is possible that @value{GDBN} may run into problems in
40090 other areas, specifically around use of @samp{vFile:setfs:}.
40091
40092 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
40093 @cindex @samp{vRun} packet
40094 Run the program @var{filename}, passing it each @var{argument} on its
40095 command line. The file and arguments are hex-encoded strings. If
40096 @var{filename} is an empty string, the stub may use a default program
40097 (e.g.@: the last program run). The program is created in the stopped
40098 state.
40099
40100 @c FIXME: What about non-stop mode?
40101
40102 This packet is only available in extended mode (@pxref{extended mode}).
40103
40104 Reply:
40105 @table @samp
40106 @item E @var{nn}
40107 for an error
40108 @item @r{Any stop packet}
40109 for success (@pxref{Stop Reply Packets})
40110 @end table
40111
40112 @item vStopped
40113 @cindex @samp{vStopped} packet
40114 @xref{Notification Packets}.
40115
40116 @item X @var{addr},@var{length}:@var{XX@dots{}}
40117 @anchor{X packet}
40118 @cindex @samp{X} packet
40119 Write data to memory, where the data is transmitted in binary.
40120 Memory is specified by its address @var{addr} and number of addressable memory
40121 units @var{length} (@pxref{addressable memory unit});
40122 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
40123
40124 Reply:
40125 @table @samp
40126 @item OK
40127 for success
40128 @item E @var{NN}
40129 for an error
40130 @end table
40131
40132 @item z @var{type},@var{addr},@var{kind}
40133 @itemx Z @var{type},@var{addr},@var{kind}
40134 @anchor{insert breakpoint or watchpoint packet}
40135 @cindex @samp{z} packet
40136 @cindex @samp{Z} packets
40137 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
40138 watchpoint starting at address @var{address} of kind @var{kind}.
40139
40140 Each breakpoint and watchpoint packet @var{type} is documented
40141 separately.
40142
40143 @emph{Implementation notes: A remote target shall return an empty string
40144 for an unrecognized breakpoint or watchpoint packet @var{type}. A
40145 remote target shall support either both or neither of a given
40146 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
40147 avoid potential problems with duplicate packets, the operations should
40148 be implemented in an idempotent way.}
40149
40150 @item z0,@var{addr},@var{kind}
40151 @itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
40152 @cindex @samp{z0} packet
40153 @cindex @samp{Z0} packet
40154 Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
40155 @var{addr} of type @var{kind}.
40156
40157 A software breakpoint is implemented by replacing the instruction at
40158 @var{addr} with a software breakpoint or trap instruction. The
40159 @var{kind} is target-specific and typically indicates the size of the
40160 breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
40161 @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
40162 architectures have additional meanings for @var{kind}
40163 (@pxref{Architecture-Specific Protocol Details}); if no
40164 architecture-specific value is being used, it should be @samp{0}.
40165 @var{kind} is hex-encoded. @var{cond_list} is an optional list of
40166 conditional expressions in bytecode form that should be evaluated on
40167 the target's side. These are the conditions that should be taken into
40168 consideration when deciding if the breakpoint trigger should be
40169 reported back to @value{GDBN}.
40170
40171 See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
40172 for how to best report a software breakpoint event to @value{GDBN}.
40173
40174 The @var{cond_list} parameter is comprised of a series of expressions,
40175 concatenated without separators. Each expression has the following form:
40176
40177 @table @samp
40178
40179 @item X @var{len},@var{expr}
40180 @var{len} is the length of the bytecode expression and @var{expr} is the
40181 actual conditional expression in bytecode form.
40182
40183 @end table
40184
40185 The optional @var{cmd_list} parameter introduces commands that may be
40186 run on the target, rather than being reported back to @value{GDBN}.
40187 The parameter starts with a numeric flag @var{persist}; if the flag is
40188 nonzero, then the breakpoint may remain active and the commands
40189 continue to be run even when @value{GDBN} disconnects from the target.
40190 Following this flag is a series of expressions concatenated with no
40191 separators. Each expression has the following form:
40192
40193 @table @samp
40194
40195 @item X @var{len},@var{expr}
40196 @var{len} is the length of the bytecode expression and @var{expr} is the
40197 actual commands expression in bytecode form.
40198
40199 @end table
40200
40201 @emph{Implementation note: It is possible for a target to copy or move
40202 code that contains software breakpoints (e.g., when implementing
40203 overlays). The behavior of this packet, in the presence of such a
40204 target, is not defined.}
40205
40206 Reply:
40207 @table @samp
40208 @item OK
40209 success
40210 @item @w{}
40211 not supported
40212 @item E @var{NN}
40213 for an error
40214 @end table
40215
40216 @item z1,@var{addr},@var{kind}
40217 @itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
40218 @cindex @samp{z1} packet
40219 @cindex @samp{Z1} packet
40220 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
40221 address @var{addr}.
40222
40223 A hardware breakpoint is implemented using a mechanism that is not
40224 dependent on being able to modify the target's memory. The
40225 @var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
40226 same meaning as in @samp{Z0} packets.
40227
40228 @emph{Implementation note: A hardware breakpoint is not affected by code
40229 movement.}
40230
40231 Reply:
40232 @table @samp
40233 @item OK
40234 success
40235 @item @w{}
40236 not supported
40237 @item E @var{NN}
40238 for an error
40239 @end table
40240
40241 @item z2,@var{addr},@var{kind}
40242 @itemx Z2,@var{addr},@var{kind}
40243 @cindex @samp{z2} packet
40244 @cindex @samp{Z2} packet
40245 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
40246 The number of bytes to watch is specified by @var{kind}.
40247
40248 Reply:
40249 @table @samp
40250 @item OK
40251 success
40252 @item @w{}
40253 not supported
40254 @item E @var{NN}
40255 for an error
40256 @end table
40257
40258 @item z3,@var{addr},@var{kind}
40259 @itemx Z3,@var{addr},@var{kind}
40260 @cindex @samp{z3} packet
40261 @cindex @samp{Z3} packet
40262 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
40263 The number of bytes to watch is specified by @var{kind}.
40264
40265 Reply:
40266 @table @samp
40267 @item OK
40268 success
40269 @item @w{}
40270 not supported
40271 @item E @var{NN}
40272 for an error
40273 @end table
40274
40275 @item z4,@var{addr},@var{kind}
40276 @itemx Z4,@var{addr},@var{kind}
40277 @cindex @samp{z4} packet
40278 @cindex @samp{Z4} packet
40279 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
40280 The number of bytes to watch is specified by @var{kind}.
40281
40282 Reply:
40283 @table @samp
40284 @item OK
40285 success
40286 @item @w{}
40287 not supported
40288 @item E @var{NN}
40289 for an error
40290 @end table
40291
40292 @end table
40293
40294 @node Stop Reply Packets
40295 @section Stop Reply Packets
40296 @cindex stop reply packets
40297
40298 The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
40299 @samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
40300 receive any of the below as a reply. Except for @samp{?}
40301 and @samp{vStopped}, that reply is only returned
40302 when the target halts. In the below the exact meaning of @dfn{signal
40303 number} is defined by the header @file{include/gdb/signals.h} in the
40304 @value{GDBN} source code.
40305
40306 In non-stop mode, the server will simply reply @samp{OK} to commands
40307 such as @samp{vCont}; any stop will be the subject of a future
40308 notification. @xref{Remote Non-Stop}.
40309
40310 As in the description of request packets, we include spaces in the
40311 reply templates for clarity; these are not part of the reply packet's
40312 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
40313 components.
40314
40315 @table @samp
40316
40317 @item S @var{AA}
40318 The program received signal number @var{AA} (a two-digit hexadecimal
40319 number). This is equivalent to a @samp{T} response with no
40320 @var{n}:@var{r} pairs.
40321
40322 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
40323 @cindex @samp{T} packet reply
40324 The program received signal number @var{AA} (a two-digit hexadecimal
40325 number). This is equivalent to an @samp{S} response, except that the
40326 @samp{@var{n}:@var{r}} pairs can carry values of important registers
40327 and other information directly in the stop reply packet, reducing
40328 round-trip latency. Single-step and breakpoint traps are reported
40329 this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
40330
40331 @itemize @bullet
40332 @item
40333 If @var{n} is a hexadecimal number, it is a register number, and the
40334 corresponding @var{r} gives that register's value. The data @var{r} is a
40335 series of bytes in target byte order, with each byte given by a
40336 two-digit hex number.
40337
40338 @item
40339 If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
40340 the stopped thread, as specified in @ref{thread-id syntax}.
40341
40342 @item
40343 If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
40344 the core on which the stop event was detected.
40345
40346 @item
40347 If @var{n} is a recognized @dfn{stop reason}, it describes a more
40348 specific event that stopped the target. The currently defined stop
40349 reasons are listed below. The @var{aa} should be @samp{05}, the trap
40350 signal. At most one stop reason should be present.
40351
40352 @item
40353 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
40354 and go on to the next; this allows us to extend the protocol in the
40355 future.
40356 @end itemize
40357
40358 The currently defined stop reasons are:
40359
40360 @table @samp
40361 @item watch
40362 @itemx rwatch
40363 @itemx awatch
40364 The packet indicates a watchpoint hit, and @var{r} is the data address, in
40365 hex.
40366
40367 @item syscall_entry
40368 @itemx syscall_return
40369 The packet indicates a syscall entry or return, and @var{r} is the
40370 syscall number, in hex.
40371
40372 @cindex shared library events, remote reply
40373 @item library
40374 The packet indicates that the loaded libraries have changed.
40375 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
40376 list of loaded libraries. The @var{r} part is ignored.
40377
40378 @cindex replay log events, remote reply
40379 @item replaylog
40380 The packet indicates that the target cannot continue replaying
40381 logged execution events, because it has reached the end (or the
40382 beginning when executing backward) of the log. The value of @var{r}
40383 will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
40384 for more information.
40385
40386 @item swbreak
40387 @anchor{swbreak stop reason}
40388 The packet indicates a software breakpoint instruction was executed,
40389 irrespective of whether it was @value{GDBN} that planted the
40390 breakpoint or the breakpoint is hardcoded in the program. The @var{r}
40391 part must be left empty.
40392
40393 On some architectures, such as x86, at the architecture level, when a
40394 breakpoint instruction executes the program counter points at the
40395 breakpoint address plus an offset. On such targets, the stub is
40396 responsible for adjusting the PC to point back at the breakpoint
40397 address.
40398
40399 This packet should not be sent by default; older @value{GDBN} versions
40400 did not support it. @value{GDBN} requests it, by supplying an
40401 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40402 remote stub must also supply the appropriate @samp{qSupported} feature
40403 indicating support.
40404
40405 This packet is required for correct non-stop mode operation.
40406
40407 @item hwbreak
40408 The packet indicates the target stopped for a hardware breakpoint.
40409 The @var{r} part must be left empty.
40410
40411 The same remarks about @samp{qSupported} and non-stop mode above
40412 apply.
40413
40414 @cindex fork events, remote reply
40415 @item fork
40416 The packet indicates that @code{fork} was called, and @var{r}
40417 is the thread ID of the new child process. Refer to
40418 @ref{thread-id syntax} for the format of the @var{thread-id}
40419 field. This packet is only applicable to targets that support
40420 fork events.
40421
40422 This packet should not be sent by default; older @value{GDBN} versions
40423 did not support it. @value{GDBN} requests it, by supplying an
40424 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40425 remote stub must also supply the appropriate @samp{qSupported} feature
40426 indicating support.
40427
40428 @cindex vfork events, remote reply
40429 @item vfork
40430 The packet indicates that @code{vfork} was called, and @var{r}
40431 is the thread ID of the new child process. Refer to
40432 @ref{thread-id syntax} for the format of the @var{thread-id}
40433 field. This packet is only applicable to targets that support
40434 vfork events.
40435
40436 This packet should not be sent by default; older @value{GDBN} versions
40437 did not support it. @value{GDBN} requests it, by supplying an
40438 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40439 remote stub must also supply the appropriate @samp{qSupported} feature
40440 indicating support.
40441
40442 @cindex vforkdone events, remote reply
40443 @item vforkdone
40444 The packet indicates that a child process created by a vfork
40445 has either called @code{exec} or terminated, so that the
40446 address spaces of the parent and child process are no longer
40447 shared. The @var{r} part is ignored. This packet is only
40448 applicable to targets that support vforkdone events.
40449
40450 This packet should not be sent by default; older @value{GDBN} versions
40451 did not support it. @value{GDBN} requests it, by supplying an
40452 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40453 remote stub must also supply the appropriate @samp{qSupported} feature
40454 indicating support.
40455
40456 @cindex exec events, remote reply
40457 @item exec
40458 The packet indicates that @code{execve} was called, and @var{r}
40459 is the absolute pathname of the file that was executed, in hex.
40460 This packet is only applicable to targets that support exec events.
40461
40462 This packet should not be sent by default; older @value{GDBN} versions
40463 did not support it. @value{GDBN} requests it, by supplying an
40464 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40465 remote stub must also supply the appropriate @samp{qSupported} feature
40466 indicating support.
40467
40468 @cindex thread create event, remote reply
40469 @anchor{thread create event}
40470 @item create
40471 The packet indicates that the thread was just created. The new thread
40472 is stopped until @value{GDBN} sets it running with a resumption packet
40473 (@pxref{vCont packet}). This packet should not be sent by default;
40474 @value{GDBN} requests it with the @ref{QThreadEvents} packet. See
40475 also the @samp{w} (@pxref{thread exit event}) remote reply below. The
40476 @var{r} part is ignored.
40477
40478 @end table
40479
40480 @item W @var{AA}
40481 @itemx W @var{AA} ; process:@var{pid}
40482 The process exited, and @var{AA} is the exit status. This is only
40483 applicable to certain targets.
40484
40485 The second form of the response, including the process ID of the
40486 exited process, can be used only when @value{GDBN} has reported
40487 support for multiprocess protocol extensions; see @ref{multiprocess
40488 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40489 hex strings.
40490
40491 @item X @var{AA}
40492 @itemx X @var{AA} ; process:@var{pid}
40493 The process terminated with signal @var{AA}.
40494
40495 The second form of the response, including the process ID of the
40496 terminated process, can be used only when @value{GDBN} has reported
40497 support for multiprocess protocol extensions; see @ref{multiprocess
40498 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40499 hex strings.
40500
40501 @anchor{thread exit event}
40502 @cindex thread exit event, remote reply
40503 @item w @var{AA} ; @var{tid}
40504
40505 The thread exited, and @var{AA} is the exit status. This response
40506 should not be sent by default; @value{GDBN} requests it with the
40507 @ref{QThreadEvents} packet. See also @ref{thread create event} above.
40508 @var{AA} is formatted as a big-endian hex string.
40509
40510 @item N
40511 There are no resumed threads left in the target. In other words, even
40512 though the process is alive, the last resumed thread has exited. For
40513 example, say the target process has two threads: thread 1 and thread
40514 2. The client leaves thread 1 stopped, and resumes thread 2, which
40515 subsequently exits. At this point, even though the process is still
40516 alive, and thus no @samp{W} stop reply is sent, no thread is actually
40517 executing either. The @samp{N} stop reply thus informs the client
40518 that it can stop waiting for stop replies. This packet should not be
40519 sent by default; older @value{GDBN} versions did not support it.
40520 @value{GDBN} requests it, by supplying an appropriate
40521 @samp{qSupported} feature (@pxref{qSupported}). The remote stub must
40522 also supply the appropriate @samp{qSupported} feature indicating
40523 support.
40524
40525 @item O @var{XX}@dots{}
40526 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
40527 written as the program's console output. This can happen at any time
40528 while the program is running and the debugger should continue to wait
40529 for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
40530
40531 @item F @var{call-id},@var{parameter}@dots{}
40532 @var{call-id} is the identifier which says which host system call should
40533 be called. This is just the name of the function. Translation into the
40534 correct system call is only applicable as it's defined in @value{GDBN}.
40535 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
40536 system calls.
40537
40538 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
40539 this very system call.
40540
40541 The target replies with this packet when it expects @value{GDBN} to
40542 call a host system call on behalf of the target. @value{GDBN} replies
40543 with an appropriate @samp{F} packet and keeps up waiting for the next
40544 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
40545 or @samp{s} action is expected to be continued. @xref{File-I/O Remote
40546 Protocol Extension}, for more details.
40547
40548 @end table
40549
40550 @node General Query Packets
40551 @section General Query Packets
40552 @cindex remote query requests
40553
40554 Packets starting with @samp{q} are @dfn{general query packets};
40555 packets starting with @samp{Q} are @dfn{general set packets}. General
40556 query and set packets are a semi-unified form for retrieving and
40557 sending information to and from the stub.
40558
40559 The initial letter of a query or set packet is followed by a name
40560 indicating what sort of thing the packet applies to. For example,
40561 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
40562 definitions with the stub. These packet names follow some
40563 conventions:
40564
40565 @itemize @bullet
40566 @item
40567 The name must not contain commas, colons or semicolons.
40568 @item
40569 Most @value{GDBN} query and set packets have a leading upper case
40570 letter.
40571 @item
40572 The names of custom vendor packets should use a company prefix, in
40573 lower case, followed by a period. For example, packets designed at
40574 the Acme Corporation might begin with @samp{qacme.foo} (for querying
40575 foos) or @samp{Qacme.bar} (for setting bars).
40576 @end itemize
40577
40578 The name of a query or set packet should be separated from any
40579 parameters by a @samp{:}; the parameters themselves should be
40580 separated by @samp{,} or @samp{;}. Stubs must be careful to match the
40581 full packet name, and check for a separator or the end of the packet,
40582 in case two packet names share a common prefix. New packets should not begin
40583 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
40584 packets predate these conventions, and have arguments without any terminator
40585 for the packet name; we suspect they are in widespread use in places that
40586 are difficult to upgrade. The @samp{qC} packet has no arguments, but some
40587 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
40588 packet.}.
40589
40590 Like the descriptions of the other packets, each description here
40591 has a template showing the packet's overall syntax, followed by an
40592 explanation of the packet's meaning. We include spaces in some of the
40593 templates for clarity; these are not part of the packet's syntax. No
40594 @value{GDBN} packet uses spaces to separate its components.
40595
40596 Here are the currently defined query and set packets:
40597
40598 @table @samp
40599
40600 @item QAgent:1
40601 @itemx QAgent:0
40602 Turn on or off the agent as a helper to perform some debugging operations
40603 delegated from @value{GDBN} (@pxref{Control Agent}).
40604
40605 @item QAllow:@var{op}:@var{val}@dots{}
40606 @cindex @samp{QAllow} packet
40607 Specify which operations @value{GDBN} expects to request of the
40608 target, as a semicolon-separated list of operation name and value
40609 pairs. Possible values for @var{op} include @samp{WriteReg},
40610 @samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
40611 @samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
40612 indicating that @value{GDBN} will not request the operation, or 1,
40613 indicating that it may. (The target can then use this to set up its
40614 own internals optimally, for instance if the debugger never expects to
40615 insert breakpoints, it may not need to install its own trap handler.)
40616
40617 @item qC
40618 @cindex current thread, remote request
40619 @cindex @samp{qC} packet
40620 Return the current thread ID.
40621
40622 Reply:
40623 @table @samp
40624 @item QC @var{thread-id}
40625 Where @var{thread-id} is a thread ID as documented in
40626 @ref{thread-id syntax}.
40627 @item @r{(anything else)}
40628 Any other reply implies the old thread ID.
40629 @end table
40630
40631 @item qCRC:@var{addr},@var{length}
40632 @cindex CRC of memory block, remote request
40633 @cindex @samp{qCRC} packet
40634 @anchor{qCRC packet}
40635 Compute the CRC checksum of a block of memory using CRC-32 defined in
40636 IEEE 802.3. The CRC is computed byte at a time, taking the most
40637 significant bit of each byte first. The initial pattern code
40638 @code{0xffffffff} is used to ensure leading zeros affect the CRC.
40639
40640 @emph{Note:} This is the same CRC used in validating separate debug
40641 files (@pxref{Separate Debug Files, , Debugging Information in Separate
40642 Files}). However the algorithm is slightly different. When validating
40643 separate debug files, the CRC is computed taking the @emph{least}
40644 significant bit of each byte first, and the final result is inverted to
40645 detect trailing zeros.
40646
40647 Reply:
40648 @table @samp
40649 @item E @var{NN}
40650 An error (such as memory fault)
40651 @item C @var{crc32}
40652 The specified memory region's checksum is @var{crc32}.
40653 @end table
40654
40655 @item QDisableRandomization:@var{value}
40656 @cindex disable address space randomization, remote request
40657 @cindex @samp{QDisableRandomization} packet
40658 Some target operating systems will randomize the virtual address space
40659 of the inferior process as a security feature, but provide a feature
40660 to disable such randomization, e.g.@: to allow for a more deterministic
40661 debugging experience. On such systems, this packet with a @var{value}
40662 of 1 directs the target to disable address space randomization for
40663 processes subsequently started via @samp{vRun} packets, while a packet
40664 with a @var{value} of 0 tells the target to enable address space
40665 randomization.
40666
40667 This packet is only available in extended mode (@pxref{extended mode}).
40668
40669 Reply:
40670 @table @samp
40671 @item OK
40672 The request succeeded.
40673
40674 @item E @var{nn}
40675 An error occurred. The error number @var{nn} is given as hex digits.
40676
40677 @item @w{}
40678 An empty reply indicates that @samp{QDisableRandomization} is not supported
40679 by the stub.
40680 @end table
40681
40682 This packet is not probed by default; the remote stub must request it,
40683 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40684 This should only be done on targets that actually support disabling
40685 address space randomization.
40686
40687 @item QStartupWithShell:@var{value}
40688 @cindex startup with shell, remote request
40689 @cindex @samp{QStartupWithShell} packet
40690 On UNIX-like targets, it is possible to start the inferior using a
40691 shell program. This is the default behavior on both @value{GDBN} and
40692 @command{gdbserver} (@pxref{set startup-with-shell}). This packet is
40693 used to inform @command{gdbserver} whether it should start the
40694 inferior using a shell or not.
40695
40696 If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
40697 to start the inferior. If @var{value} is @samp{1},
40698 @command{gdbserver} will use a shell to start the inferior. All other
40699 values are considered an error.
40700
40701 This packet is only available in extended mode (@pxref{extended
40702 mode}).
40703
40704 Reply:
40705 @table @samp
40706 @item OK
40707 The request succeeded.
40708
40709 @item E @var{nn}
40710 An error occurred. The error number @var{nn} is given as hex digits.
40711 @end table
40712
40713 This packet is not probed by default; the remote stub must request it,
40714 by supplying an appropriate @samp{qSupported} response
40715 (@pxref{qSupported}). This should only be done on targets that
40716 actually support starting the inferior using a shell.
40717
40718 Use of this packet is controlled by the @code{set startup-with-shell}
40719 command; @pxref{set startup-with-shell}.
40720
40721 @item QEnvironmentHexEncoded:@var{hex-value}
40722 @anchor{QEnvironmentHexEncoded}
40723 @cindex set environment variable, remote request
40724 @cindex @samp{QEnvironmentHexEncoded} packet
40725 On UNIX-like targets, it is possible to set environment variables that
40726 will be passed to the inferior during the startup process. This
40727 packet is used to inform @command{gdbserver} of an environment
40728 variable that has been defined by the user on @value{GDBN} (@pxref{set
40729 environment}).
40730
40731 The packet is composed by @var{hex-value}, an hex encoded
40732 representation of the @var{name=value} format representing an
40733 environment variable. The name of the environment variable is
40734 represented by @var{name}, and the value to be assigned to the
40735 environment variable is represented by @var{value}. If the variable
40736 has no value (i.e., the value is @code{null}), then @var{value} will
40737 not be present.
40738
40739 This packet is only available in extended mode (@pxref{extended
40740 mode}).
40741
40742 Reply:
40743 @table @samp
40744 @item OK
40745 The request succeeded.
40746 @end table
40747
40748 This packet is not probed by default; the remote stub must request it,
40749 by supplying an appropriate @samp{qSupported} response
40750 (@pxref{qSupported}). This should only be done on targets that
40751 actually support passing environment variables to the starting
40752 inferior.
40753
40754 This packet is related to the @code{set environment} command;
40755 @pxref{set environment}.
40756
40757 @item QEnvironmentUnset:@var{hex-value}
40758 @anchor{QEnvironmentUnset}
40759 @cindex unset environment variable, remote request
40760 @cindex @samp{QEnvironmentUnset} packet
40761 On UNIX-like targets, it is possible to unset environment variables
40762 before starting the inferior in the remote target. This packet is
40763 used to inform @command{gdbserver} of an environment variable that has
40764 been unset by the user on @value{GDBN} (@pxref{unset environment}).
40765
40766 The packet is composed by @var{hex-value}, an hex encoded
40767 representation of the name of the environment variable to be unset.
40768
40769 This packet is only available in extended mode (@pxref{extended
40770 mode}).
40771
40772 Reply:
40773 @table @samp
40774 @item OK
40775 The request succeeded.
40776 @end table
40777
40778 This packet is not probed by default; the remote stub must request it,
40779 by supplying an appropriate @samp{qSupported} response
40780 (@pxref{qSupported}). This should only be done on targets that
40781 actually support passing environment variables to the starting
40782 inferior.
40783
40784 This packet is related to the @code{unset environment} command;
40785 @pxref{unset environment}.
40786
40787 @item QEnvironmentReset
40788 @anchor{QEnvironmentReset}
40789 @cindex reset environment, remote request
40790 @cindex @samp{QEnvironmentReset} packet
40791 On UNIX-like targets, this packet is used to reset the state of
40792 environment variables in the remote target before starting the
40793 inferior. In this context, reset means unsetting all environment
40794 variables that were previously set by the user (i.e., were not
40795 initially present in the environment). It is sent to
40796 @command{gdbserver} before the @samp{QEnvironmentHexEncoded}
40797 (@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
40798 (@pxref{QEnvironmentUnset}) packets.
40799
40800 This packet is only available in extended mode (@pxref{extended
40801 mode}).
40802
40803 Reply:
40804 @table @samp
40805 @item OK
40806 The request succeeded.
40807 @end table
40808
40809 This packet is not probed by default; the remote stub must request it,
40810 by supplying an appropriate @samp{qSupported} response
40811 (@pxref{qSupported}). This should only be done on targets that
40812 actually support passing environment variables to the starting
40813 inferior.
40814
40815 @item QSetWorkingDir:@r{[}@var{directory}@r{]}
40816 @anchor{QSetWorkingDir packet}
40817 @cindex set working directory, remote request
40818 @cindex @samp{QSetWorkingDir} packet
40819 This packet is used to inform the remote server of the intended
40820 current working directory for programs that are going to be executed.
40821
40822 The packet is composed by @var{directory}, an hex encoded
40823 representation of the directory that the remote inferior will use as
40824 its current working directory. If @var{directory} is an empty string,
40825 the remote server should reset the inferior's current working
40826 directory to its original, empty value.
40827
40828 This packet is only available in extended mode (@pxref{extended
40829 mode}).
40830
40831 Reply:
40832 @table @samp
40833 @item OK
40834 The request succeeded.
40835 @end table
40836
40837 @item qfThreadInfo
40838 @itemx qsThreadInfo
40839 @cindex list active threads, remote request
40840 @cindex @samp{qfThreadInfo} packet
40841 @cindex @samp{qsThreadInfo} packet
40842 Obtain a list of all active thread IDs from the target (OS). Since there
40843 may be too many active threads to fit into one reply packet, this query
40844 works iteratively: it may require more than one query/reply sequence to
40845 obtain the entire list of threads. The first query of the sequence will
40846 be the @samp{qfThreadInfo} query; subsequent queries in the
40847 sequence will be the @samp{qsThreadInfo} query.
40848
40849 NOTE: This packet replaces the @samp{qL} query (see below).
40850
40851 Reply:
40852 @table @samp
40853 @item m @var{thread-id}
40854 A single thread ID
40855 @item m @var{thread-id},@var{thread-id}@dots{}
40856 a comma-separated list of thread IDs
40857 @item l
40858 (lower case letter @samp{L}) denotes end of list.
40859 @end table
40860
40861 In response to each query, the target will reply with a list of one or
40862 more thread IDs, separated by commas.
40863 @value{GDBN} will respond to each reply with a request for more thread
40864 ids (using the @samp{qs} form of the query), until the target responds
40865 with @samp{l} (lower-case ell, for @dfn{last}).
40866 Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
40867 fields.
40868
40869 @emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
40870 initial connection with the remote target, and the very first thread ID
40871 mentioned in the reply will be stopped by @value{GDBN} in a subsequent
40872 message. Therefore, the stub should ensure that the first thread ID in
40873 the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
40874
40875 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
40876 @cindex get thread-local storage address, remote request
40877 @cindex @samp{qGetTLSAddr} packet
40878 Fetch the address associated with thread local storage specified
40879 by @var{thread-id}, @var{offset}, and @var{lm}.
40880
40881 @var{thread-id} is the thread ID associated with the
40882 thread for which to fetch the TLS address. @xref{thread-id syntax}.
40883
40884 @var{offset} is the (big endian, hex encoded) offset associated with the
40885 thread local variable. (This offset is obtained from the debug
40886 information associated with the variable.)
40887
40888 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
40889 load module associated with the thread local storage. For example,
40890 a @sc{gnu}/Linux system will pass the link map address of the shared
40891 object associated with the thread local storage under consideration.
40892 Other operating environments may choose to represent the load module
40893 differently, so the precise meaning of this parameter will vary.
40894
40895 Reply:
40896 @table @samp
40897 @item @var{XX}@dots{}
40898 Hex encoded (big endian) bytes representing the address of the thread
40899 local storage requested.
40900
40901 @item E @var{nn}
40902 An error occurred. The error number @var{nn} is given as hex digits.
40903
40904 @item @w{}
40905 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
40906 @end table
40907
40908 @item qGetTIBAddr:@var{thread-id}
40909 @cindex get thread information block address
40910 @cindex @samp{qGetTIBAddr} packet
40911 Fetch address of the Windows OS specific Thread Information Block.
40912
40913 @var{thread-id} is the thread ID associated with the thread.
40914
40915 Reply:
40916 @table @samp
40917 @item @var{XX}@dots{}
40918 Hex encoded (big endian) bytes representing the linear address of the
40919 thread information block.
40920
40921 @item E @var{nn}
40922 An error occured. This means that either the thread was not found, or the
40923 address could not be retrieved.
40924
40925 @item @w{}
40926 An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
40927 @end table
40928
40929 @item qL @var{startflag} @var{threadcount} @var{nextthread}
40930 Obtain thread information from RTOS. Where: @var{startflag} (one hex
40931 digit) is one to indicate the first query and zero to indicate a
40932 subsequent query; @var{threadcount} (two hex digits) is the maximum
40933 number of threads the response packet can contain; and @var{nextthread}
40934 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
40935 returned in the response as @var{argthread}.
40936
40937 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
40938
40939 Reply:
40940 @table @samp
40941 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
40942 Where: @var{count} (two hex digits) is the number of threads being
40943 returned; @var{done} (one hex digit) is zero to indicate more threads
40944 and one indicates no further threads; @var{argthreadid} (eight hex
40945 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
40946 is a sequence of thread IDs, @var{threadid} (eight hex
40947 digits), from the target. See @code{remote.c:parse_threadlist_response()}.
40948 @end table
40949
40950 @item qOffsets
40951 @cindex section offsets, remote request
40952 @cindex @samp{qOffsets} packet
40953 Get section offsets that the target used when relocating the downloaded
40954 image.
40955
40956 Reply:
40957 @table @samp
40958 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
40959 Relocate the @code{Text} section by @var{xxx} from its original address.
40960 Relocate the @code{Data} section by @var{yyy} from its original address.
40961 If the object file format provides segment information (e.g.@: @sc{elf}
40962 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
40963 segments by the supplied offsets.
40964
40965 @emph{Note: while a @code{Bss} offset may be included in the response,
40966 @value{GDBN} ignores this and instead applies the @code{Data} offset
40967 to the @code{Bss} section.}
40968
40969 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
40970 Relocate the first segment of the object file, which conventionally
40971 contains program code, to a starting address of @var{xxx}. If
40972 @samp{DataSeg} is specified, relocate the second segment, which
40973 conventionally contains modifiable data, to a starting address of
40974 @var{yyy}. @value{GDBN} will report an error if the object file
40975 does not contain segment information, or does not contain at least
40976 as many segments as mentioned in the reply. Extra segments are
40977 kept at fixed offsets relative to the last relocated segment.
40978 @end table
40979
40980 @item qP @var{mode} @var{thread-id}
40981 @cindex thread information, remote request
40982 @cindex @samp{qP} packet
40983 Returns information on @var{thread-id}. Where: @var{mode} is a hex
40984 encoded 32 bit mode; @var{thread-id} is a thread ID
40985 (@pxref{thread-id syntax}).
40986
40987 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
40988 (see below).
40989
40990 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
40991
40992 @item QNonStop:1
40993 @itemx QNonStop:0
40994 @cindex non-stop mode, remote request
40995 @cindex @samp{QNonStop} packet
40996 @anchor{QNonStop}
40997 Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
40998 @xref{Remote Non-Stop}, for more information.
40999
41000 Reply:
41001 @table @samp
41002 @item OK
41003 The request succeeded.
41004
41005 @item E @var{nn}
41006 An error occurred. The error number @var{nn} is given as hex digits.
41007
41008 @item @w{}
41009 An empty reply indicates that @samp{QNonStop} is not supported by
41010 the stub.
41011 @end table
41012
41013 This packet is not probed by default; the remote stub must request it,
41014 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41015 Use of this packet is controlled by the @code{set non-stop} command;
41016 @pxref{Non-Stop Mode}.
41017
41018 @item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
41019 @itemx QCatchSyscalls:0
41020 @cindex catch syscalls from inferior, remote request
41021 @cindex @samp{QCatchSyscalls} packet
41022 @anchor{QCatchSyscalls}
41023 Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
41024 catching syscalls from the inferior process.
41025
41026 For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
41027 in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
41028 is listed, every system call should be reported.
41029
41030 Note that if a syscall not in the list is reported, @value{GDBN} will
41031 still filter the event according to its own list from all corresponding
41032 @code{catch syscall} commands. However, it is more efficient to only
41033 report the requested syscalls.
41034
41035 Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
41036 @samp{QCatchSyscalls:1} list is completely replaced by the new list.
41037
41038 If the inferior process execs, the state of @samp{QCatchSyscalls} is
41039 kept for the new process too. On targets where exec may affect syscall
41040 numbers, for example with exec between 32 and 64-bit processes, the
41041 client should send a new packet with the new syscall list.
41042
41043 Reply:
41044 @table @samp
41045 @item OK
41046 The request succeeded.
41047
41048 @item E @var{nn}
41049 An error occurred. @var{nn} are hex digits.
41050
41051 @item @w{}
41052 An empty reply indicates that @samp{QCatchSyscalls} is not supported by
41053 the stub.
41054 @end table
41055
41056 Use of this packet is controlled by the @code{set remote catch-syscalls}
41057 command (@pxref{Remote Configuration, set remote catch-syscalls}).
41058 This packet is not probed by default; the remote stub must request it,
41059 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41060
41061 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
41062 @cindex pass signals to inferior, remote request
41063 @cindex @samp{QPassSignals} packet
41064 @anchor{QPassSignals}
41065 Each listed @var{signal} should be passed directly to the inferior process.
41066 Signals are numbered identically to continue packets and stop replies
41067 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
41068 strictly greater than the previous item. These signals do not need to stop
41069 the inferior, or be reported to @value{GDBN}. All other signals should be
41070 reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
41071 combine; any earlier @samp{QPassSignals} list is completely replaced by the
41072 new list. This packet improves performance when using @samp{handle
41073 @var{signal} nostop noprint pass}.
41074
41075 Reply:
41076 @table @samp
41077 @item OK
41078 The request succeeded.
41079
41080 @item E @var{nn}
41081 An error occurred. The error number @var{nn} is given as hex digits.
41082
41083 @item @w{}
41084 An empty reply indicates that @samp{QPassSignals} is not supported by
41085 the stub.
41086 @end table
41087
41088 Use of this packet is controlled by the @code{set remote pass-signals}
41089 command (@pxref{Remote Configuration, set remote pass-signals}).
41090 This packet is not probed by default; the remote stub must request it,
41091 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41092
41093 @item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
41094 @cindex signals the inferior may see, remote request
41095 @cindex @samp{QProgramSignals} packet
41096 @anchor{QProgramSignals}
41097 Each listed @var{signal} may be delivered to the inferior process.
41098 Others should be silently discarded.
41099
41100 In some cases, the remote stub may need to decide whether to deliver a
41101 signal to the program or not without @value{GDBN} involvement. One
41102 example of that is while detaching --- the program's threads may have
41103 stopped for signals that haven't yet had a chance of being reported to
41104 @value{GDBN}, and so the remote stub can use the signal list specified
41105 by this packet to know whether to deliver or ignore those pending
41106 signals.
41107
41108 This does not influence whether to deliver a signal as requested by a
41109 resumption packet (@pxref{vCont packet}).
41110
41111 Signals are numbered identically to continue packets and stop replies
41112 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
41113 strictly greater than the previous item. Multiple
41114 @samp{QProgramSignals} packets do not combine; any earlier
41115 @samp{QProgramSignals} list is completely replaced by the new list.
41116
41117 Reply:
41118 @table @samp
41119 @item OK
41120 The request succeeded.
41121
41122 @item E @var{nn}
41123 An error occurred. The error number @var{nn} is given as hex digits.
41124
41125 @item @w{}
41126 An empty reply indicates that @samp{QProgramSignals} is not supported
41127 by the stub.
41128 @end table
41129
41130 Use of this packet is controlled by the @code{set remote program-signals}
41131 command (@pxref{Remote Configuration, set remote program-signals}).
41132 This packet is not probed by default; the remote stub must request it,
41133 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41134
41135 @anchor{QThreadEvents}
41136 @item QThreadEvents:1
41137 @itemx QThreadEvents:0
41138 @cindex thread create/exit events, remote request
41139 @cindex @samp{QThreadEvents} packet
41140
41141 Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
41142 reporting of thread create and exit events. @xref{thread create
41143 event}, for the reply specifications. For example, this is used in
41144 non-stop mode when @value{GDBN} stops a set of threads and
41145 synchronously waits for the their corresponding stop replies. Without
41146 exit events, if one of the threads exits, @value{GDBN} would hang
41147 forever not knowing that it should no longer expect a stop for that
41148 same thread. @value{GDBN} does not enable this feature unless the
41149 stub reports that it supports it by including @samp{QThreadEvents+} in
41150 its @samp{qSupported} reply.
41151
41152 Reply:
41153 @table @samp
41154 @item OK
41155 The request succeeded.
41156
41157 @item E @var{nn}
41158 An error occurred. The error number @var{nn} is given as hex digits.
41159
41160 @item @w{}
41161 An empty reply indicates that @samp{QThreadEvents} is not supported by
41162 the stub.
41163 @end table
41164
41165 Use of this packet is controlled by the @code{set remote thread-events}
41166 command (@pxref{Remote Configuration, set remote thread-events}).
41167
41168 @item qRcmd,@var{command}
41169 @cindex execute remote command, remote request
41170 @cindex @samp{qRcmd} packet
41171 @var{command} (hex encoded) is passed to the local interpreter for
41172 execution. Invalid commands should be reported using the output
41173 string. Before the final result packet, the target may also respond
41174 with a number of intermediate @samp{O@var{output}} console output
41175 packets. @emph{Implementors should note that providing access to a
41176 stubs's interpreter may have security implications}.
41177
41178 Reply:
41179 @table @samp
41180 @item OK
41181 A command response with no output.
41182 @item @var{OUTPUT}
41183 A command response with the hex encoded output string @var{OUTPUT}.
41184 @item E @var{NN}
41185 Indicate a badly formed request.
41186 @item @w{}
41187 An empty reply indicates that @samp{qRcmd} is not recognized.
41188 @end table
41189
41190 (Note that the @code{qRcmd} packet's name is separated from the
41191 command by a @samp{,}, not a @samp{:}, contrary to the naming
41192 conventions above. Please don't use this packet as a model for new
41193 packets.)
41194
41195 @item qSearch:memory:@var{address};@var{length};@var{search-pattern}
41196 @cindex searching memory, in remote debugging
41197 @ifnotinfo
41198 @cindex @samp{qSearch:memory} packet
41199 @end ifnotinfo
41200 @cindex @samp{qSearch memory} packet
41201 @anchor{qSearch memory}
41202 Search @var{length} bytes at @var{address} for @var{search-pattern}.
41203 Both @var{address} and @var{length} are encoded in hex;
41204 @var{search-pattern} is a sequence of bytes, also hex encoded.
41205
41206 Reply:
41207 @table @samp
41208 @item 0
41209 The pattern was not found.
41210 @item 1,address
41211 The pattern was found at @var{address}.
41212 @item E @var{NN}
41213 A badly formed request or an error was encountered while searching memory.
41214 @item @w{}
41215 An empty reply indicates that @samp{qSearch:memory} is not recognized.
41216 @end table
41217
41218 @item QStartNoAckMode
41219 @cindex @samp{QStartNoAckMode} packet
41220 @anchor{QStartNoAckMode}
41221 Request that the remote stub disable the normal @samp{+}/@samp{-}
41222 protocol acknowledgments (@pxref{Packet Acknowledgment}).
41223
41224 Reply:
41225 @table @samp
41226 @item OK
41227 The stub has switched to no-acknowledgment mode.
41228 @value{GDBN} acknowledges this response,
41229 but neither the stub nor @value{GDBN} shall send or expect further
41230 @samp{+}/@samp{-} acknowledgments in the current connection.
41231 @item @w{}
41232 An empty reply indicates that the stub does not support no-acknowledgment mode.
41233 @end table
41234
41235 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
41236 @cindex supported packets, remote query
41237 @cindex features of the remote protocol
41238 @cindex @samp{qSupported} packet
41239 @anchor{qSupported}
41240 Tell the remote stub about features supported by @value{GDBN}, and
41241 query the stub for features it supports. This packet allows
41242 @value{GDBN} and the remote stub to take advantage of each others'
41243 features. @samp{qSupported} also consolidates multiple feature probes
41244 at startup, to improve @value{GDBN} performance---a single larger
41245 packet performs better than multiple smaller probe packets on
41246 high-latency links. Some features may enable behavior which must not
41247 be on by default, e.g.@: because it would confuse older clients or
41248 stubs. Other features may describe packets which could be
41249 automatically probed for, but are not. These features must be
41250 reported before @value{GDBN} will use them. This ``default
41251 unsupported'' behavior is not appropriate for all packets, but it
41252 helps to keep the initial connection time under control with new
41253 versions of @value{GDBN} which support increasing numbers of packets.
41254
41255 Reply:
41256 @table @samp
41257 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
41258 The stub supports or does not support each returned @var{stubfeature},
41259 depending on the form of each @var{stubfeature} (see below for the
41260 possible forms).
41261 @item @w{}
41262 An empty reply indicates that @samp{qSupported} is not recognized,
41263 or that no features needed to be reported to @value{GDBN}.
41264 @end table
41265
41266 The allowed forms for each feature (either a @var{gdbfeature} in the
41267 @samp{qSupported} packet, or a @var{stubfeature} in the response)
41268 are:
41269
41270 @table @samp
41271 @item @var{name}=@var{value}
41272 The remote protocol feature @var{name} is supported, and associated
41273 with the specified @var{value}. The format of @var{value} depends
41274 on the feature, but it must not include a semicolon.
41275 @item @var{name}+
41276 The remote protocol feature @var{name} is supported, and does not
41277 need an associated value.
41278 @item @var{name}-
41279 The remote protocol feature @var{name} is not supported.
41280 @item @var{name}?
41281 The remote protocol feature @var{name} may be supported, and
41282 @value{GDBN} should auto-detect support in some other way when it is
41283 needed. This form will not be used for @var{gdbfeature} notifications,
41284 but may be used for @var{stubfeature} responses.
41285 @end table
41286
41287 Whenever the stub receives a @samp{qSupported} request, the
41288 supplied set of @value{GDBN} features should override any previous
41289 request. This allows @value{GDBN} to put the stub in a known
41290 state, even if the stub had previously been communicating with
41291 a different version of @value{GDBN}.
41292
41293 The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
41294 are defined:
41295
41296 @table @samp
41297 @item multiprocess
41298 This feature indicates whether @value{GDBN} supports multiprocess
41299 extensions to the remote protocol. @value{GDBN} does not use such
41300 extensions unless the stub also reports that it supports them by
41301 including @samp{multiprocess+} in its @samp{qSupported} reply.
41302 @xref{multiprocess extensions}, for details.
41303
41304 @item xmlRegisters
41305 This feature indicates that @value{GDBN} supports the XML target
41306 description. If the stub sees @samp{xmlRegisters=} with target
41307 specific strings separated by a comma, it will report register
41308 description.
41309
41310 @item qRelocInsn
41311 This feature indicates whether @value{GDBN} supports the
41312 @samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
41313 instruction reply packet}).
41314
41315 @item swbreak
41316 This feature indicates whether @value{GDBN} supports the swbreak stop
41317 reason in stop replies. @xref{swbreak stop reason}, for details.
41318
41319 @item hwbreak
41320 This feature indicates whether @value{GDBN} supports the hwbreak stop
41321 reason in stop replies. @xref{swbreak stop reason}, for details.
41322
41323 @item fork-events
41324 This feature indicates whether @value{GDBN} supports fork event
41325 extensions to the remote protocol. @value{GDBN} does not use such
41326 extensions unless the stub also reports that it supports them by
41327 including @samp{fork-events+} in its @samp{qSupported} reply.
41328
41329 @item vfork-events
41330 This feature indicates whether @value{GDBN} supports vfork event
41331 extensions to the remote protocol. @value{GDBN} does not use such
41332 extensions unless the stub also reports that it supports them by
41333 including @samp{vfork-events+} in its @samp{qSupported} reply.
41334
41335 @item exec-events
41336 This feature indicates whether @value{GDBN} supports exec event
41337 extensions to the remote protocol. @value{GDBN} does not use such
41338 extensions unless the stub also reports that it supports them by
41339 including @samp{exec-events+} in its @samp{qSupported} reply.
41340
41341 @item vContSupported
41342 This feature indicates whether @value{GDBN} wants to know the
41343 supported actions in the reply to @samp{vCont?} packet.
41344 @end table
41345
41346 Stubs should ignore any unknown values for
41347 @var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
41348 packet supports receiving packets of unlimited length (earlier
41349 versions of @value{GDBN} may reject overly long responses). Additional values
41350 for @var{gdbfeature} may be defined in the future to let the stub take
41351 advantage of new features in @value{GDBN}, e.g.@: incompatible
41352 improvements in the remote protocol---the @samp{multiprocess} feature is
41353 an example of such a feature. The stub's reply should be independent
41354 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
41355 describes all the features it supports, and then the stub replies with
41356 all the features it supports.
41357
41358 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
41359 responses, as long as each response uses one of the standard forms.
41360
41361 Some features are flags. A stub which supports a flag feature
41362 should respond with a @samp{+} form response. Other features
41363 require values, and the stub should respond with an @samp{=}
41364 form response.
41365
41366 Each feature has a default value, which @value{GDBN} will use if
41367 @samp{qSupported} is not available or if the feature is not mentioned
41368 in the @samp{qSupported} response. The default values are fixed; a
41369 stub is free to omit any feature responses that match the defaults.
41370
41371 Not all features can be probed, but for those which can, the probing
41372 mechanism is useful: in some cases, a stub's internal
41373 architecture may not allow the protocol layer to know some information
41374 about the underlying target in advance. This is especially common in
41375 stubs which may be configured for multiple targets.
41376
41377 These are the currently defined stub features and their properties:
41378
41379 @multitable @columnfractions 0.35 0.2 0.12 0.2
41380 @c NOTE: The first row should be @headitem, but we do not yet require
41381 @c a new enough version of Texinfo (4.7) to use @headitem.
41382 @item Feature Name
41383 @tab Value Required
41384 @tab Default
41385 @tab Probe Allowed
41386
41387 @item @samp{PacketSize}
41388 @tab Yes
41389 @tab @samp{-}
41390 @tab No
41391
41392 @item @samp{qXfer:auxv:read}
41393 @tab No
41394 @tab @samp{-}
41395 @tab Yes
41396
41397 @item @samp{qXfer:btrace:read}
41398 @tab No
41399 @tab @samp{-}
41400 @tab Yes
41401
41402 @item @samp{qXfer:btrace-conf:read}
41403 @tab No
41404 @tab @samp{-}
41405 @tab Yes
41406
41407 @item @samp{qXfer:exec-file:read}
41408 @tab No
41409 @tab @samp{-}
41410 @tab Yes
41411
41412 @item @samp{qXfer:features:read}
41413 @tab No
41414 @tab @samp{-}
41415 @tab Yes
41416
41417 @item @samp{qXfer:libraries:read}
41418 @tab No
41419 @tab @samp{-}
41420 @tab Yes
41421
41422 @item @samp{qXfer:libraries-svr4:read}
41423 @tab No
41424 @tab @samp{-}
41425 @tab Yes
41426
41427 @item @samp{augmented-libraries-svr4-read}
41428 @tab No
41429 @tab @samp{-}
41430 @tab No
41431
41432 @item @samp{qXfer:memory-map:read}
41433 @tab No
41434 @tab @samp{-}
41435 @tab Yes
41436
41437 @item @samp{qXfer:sdata:read}
41438 @tab No
41439 @tab @samp{-}
41440 @tab Yes
41441
41442 @item @samp{qXfer:siginfo:read}
41443 @tab No
41444 @tab @samp{-}
41445 @tab Yes
41446
41447 @item @samp{qXfer:siginfo:write}
41448 @tab No
41449 @tab @samp{-}
41450 @tab Yes
41451
41452 @item @samp{qXfer:threads:read}
41453 @tab No
41454 @tab @samp{-}
41455 @tab Yes
41456
41457 @item @samp{qXfer:traceframe-info:read}
41458 @tab No
41459 @tab @samp{-}
41460 @tab Yes
41461
41462 @item @samp{qXfer:uib:read}
41463 @tab No
41464 @tab @samp{-}
41465 @tab Yes
41466
41467 @item @samp{qXfer:fdpic:read}
41468 @tab No
41469 @tab @samp{-}
41470 @tab Yes
41471
41472 @item @samp{Qbtrace:off}
41473 @tab Yes
41474 @tab @samp{-}
41475 @tab Yes
41476
41477 @item @samp{Qbtrace:bts}
41478 @tab Yes
41479 @tab @samp{-}
41480 @tab Yes
41481
41482 @item @samp{Qbtrace:pt}
41483 @tab Yes
41484 @tab @samp{-}
41485 @tab Yes
41486
41487 @item @samp{Qbtrace-conf:bts:size}
41488 @tab Yes
41489 @tab @samp{-}
41490 @tab Yes
41491
41492 @item @samp{Qbtrace-conf:pt:size}
41493 @tab Yes
41494 @tab @samp{-}
41495 @tab Yes
41496
41497 @item @samp{QNonStop}
41498 @tab No
41499 @tab @samp{-}
41500 @tab Yes
41501
41502 @item @samp{QCatchSyscalls}
41503 @tab No
41504 @tab @samp{-}
41505 @tab Yes
41506
41507 @item @samp{QPassSignals}
41508 @tab No
41509 @tab @samp{-}
41510 @tab Yes
41511
41512 @item @samp{QStartNoAckMode}
41513 @tab No
41514 @tab @samp{-}
41515 @tab Yes
41516
41517 @item @samp{multiprocess}
41518 @tab No
41519 @tab @samp{-}
41520 @tab No
41521
41522 @item @samp{ConditionalBreakpoints}
41523 @tab No
41524 @tab @samp{-}
41525 @tab No
41526
41527 @item @samp{ConditionalTracepoints}
41528 @tab No
41529 @tab @samp{-}
41530 @tab No
41531
41532 @item @samp{ReverseContinue}
41533 @tab No
41534 @tab @samp{-}
41535 @tab No
41536
41537 @item @samp{ReverseStep}
41538 @tab No
41539 @tab @samp{-}
41540 @tab No
41541
41542 @item @samp{TracepointSource}
41543 @tab No
41544 @tab @samp{-}
41545 @tab No
41546
41547 @item @samp{QAgent}
41548 @tab No
41549 @tab @samp{-}
41550 @tab No
41551
41552 @item @samp{QAllow}
41553 @tab No
41554 @tab @samp{-}
41555 @tab No
41556
41557 @item @samp{QDisableRandomization}
41558 @tab No
41559 @tab @samp{-}
41560 @tab No
41561
41562 @item @samp{EnableDisableTracepoints}
41563 @tab No
41564 @tab @samp{-}
41565 @tab No
41566
41567 @item @samp{QTBuffer:size}
41568 @tab No
41569 @tab @samp{-}
41570 @tab No
41571
41572 @item @samp{tracenz}
41573 @tab No
41574 @tab @samp{-}
41575 @tab No
41576
41577 @item @samp{BreakpointCommands}
41578 @tab No
41579 @tab @samp{-}
41580 @tab No
41581
41582 @item @samp{swbreak}
41583 @tab No
41584 @tab @samp{-}
41585 @tab No
41586
41587 @item @samp{hwbreak}
41588 @tab No
41589 @tab @samp{-}
41590 @tab No
41591
41592 @item @samp{fork-events}
41593 @tab No
41594 @tab @samp{-}
41595 @tab No
41596
41597 @item @samp{vfork-events}
41598 @tab No
41599 @tab @samp{-}
41600 @tab No
41601
41602 @item @samp{exec-events}
41603 @tab No
41604 @tab @samp{-}
41605 @tab No
41606
41607 @item @samp{QThreadEvents}
41608 @tab No
41609 @tab @samp{-}
41610 @tab No
41611
41612 @item @samp{no-resumed}
41613 @tab No
41614 @tab @samp{-}
41615 @tab No
41616
41617 @end multitable
41618
41619 These are the currently defined stub features, in more detail:
41620
41621 @table @samp
41622 @cindex packet size, remote protocol
41623 @item PacketSize=@var{bytes}
41624 The remote stub can accept packets up to at least @var{bytes} in
41625 length. @value{GDBN} will send packets up to this size for bulk
41626 transfers, and will never send larger packets. This is a limit on the
41627 data characters in the packet, including the frame and checksum.
41628 There is no trailing NUL byte in a remote protocol packet; if the stub
41629 stores packets in a NUL-terminated format, it should allow an extra
41630 byte in its buffer for the NUL. If this stub feature is not supported,
41631 @value{GDBN} guesses based on the size of the @samp{g} packet response.
41632
41633 @item qXfer:auxv:read
41634 The remote stub understands the @samp{qXfer:auxv:read} packet
41635 (@pxref{qXfer auxiliary vector read}).
41636
41637 @item qXfer:btrace:read
41638 The remote stub understands the @samp{qXfer:btrace:read}
41639 packet (@pxref{qXfer btrace read}).
41640
41641 @item qXfer:btrace-conf:read
41642 The remote stub understands the @samp{qXfer:btrace-conf:read}
41643 packet (@pxref{qXfer btrace-conf read}).
41644
41645 @item qXfer:exec-file:read
41646 The remote stub understands the @samp{qXfer:exec-file:read} packet
41647 (@pxref{qXfer executable filename read}).
41648
41649 @item qXfer:features:read
41650 The remote stub understands the @samp{qXfer:features:read} packet
41651 (@pxref{qXfer target description read}).
41652
41653 @item qXfer:libraries:read
41654 The remote stub understands the @samp{qXfer:libraries:read} packet
41655 (@pxref{qXfer library list read}).
41656
41657 @item qXfer:libraries-svr4:read
41658 The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
41659 (@pxref{qXfer svr4 library list read}).
41660
41661 @item augmented-libraries-svr4-read
41662 The remote stub understands the augmented form of the
41663 @samp{qXfer:libraries-svr4:read} packet
41664 (@pxref{qXfer svr4 library list read}).
41665
41666 @item qXfer:memory-map:read
41667 The remote stub understands the @samp{qXfer:memory-map:read} packet
41668 (@pxref{qXfer memory map read}).
41669
41670 @item qXfer:sdata:read
41671 The remote stub understands the @samp{qXfer:sdata:read} packet
41672 (@pxref{qXfer sdata read}).
41673
41674 @item qXfer:siginfo:read
41675 The remote stub understands the @samp{qXfer:siginfo:read} packet
41676 (@pxref{qXfer siginfo read}).
41677
41678 @item qXfer:siginfo:write
41679 The remote stub understands the @samp{qXfer:siginfo:write} packet
41680 (@pxref{qXfer siginfo write}).
41681
41682 @item qXfer:threads:read
41683 The remote stub understands the @samp{qXfer:threads:read} packet
41684 (@pxref{qXfer threads read}).
41685
41686 @item qXfer:traceframe-info:read
41687 The remote stub understands the @samp{qXfer:traceframe-info:read}
41688 packet (@pxref{qXfer traceframe info read}).
41689
41690 @item qXfer:uib:read
41691 The remote stub understands the @samp{qXfer:uib:read}
41692 packet (@pxref{qXfer unwind info block}).
41693
41694 @item qXfer:fdpic:read
41695 The remote stub understands the @samp{qXfer:fdpic:read}
41696 packet (@pxref{qXfer fdpic loadmap read}).
41697
41698 @item QNonStop
41699 The remote stub understands the @samp{QNonStop} packet
41700 (@pxref{QNonStop}).
41701
41702 @item QCatchSyscalls
41703 The remote stub understands the @samp{QCatchSyscalls} packet
41704 (@pxref{QCatchSyscalls}).
41705
41706 @item QPassSignals
41707 The remote stub understands the @samp{QPassSignals} packet
41708 (@pxref{QPassSignals}).
41709
41710 @item QStartNoAckMode
41711 The remote stub understands the @samp{QStartNoAckMode} packet and
41712 prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
41713
41714 @item multiprocess
41715 @anchor{multiprocess extensions}
41716 @cindex multiprocess extensions, in remote protocol
41717 The remote stub understands the multiprocess extensions to the remote
41718 protocol syntax. The multiprocess extensions affect the syntax of
41719 thread IDs in both packets and replies (@pxref{thread-id syntax}), and
41720 add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
41721 replies. Note that reporting this feature indicates support for the
41722 syntactic extensions only, not that the stub necessarily supports
41723 debugging of more than one process at a time. The stub must not use
41724 multiprocess extensions in packet replies unless @value{GDBN} has also
41725 indicated it supports them in its @samp{qSupported} request.
41726
41727 @item qXfer:osdata:read
41728 The remote stub understands the @samp{qXfer:osdata:read} packet
41729 ((@pxref{qXfer osdata read}).
41730
41731 @item ConditionalBreakpoints
41732 The target accepts and implements evaluation of conditional expressions
41733 defined for breakpoints. The target will only report breakpoint triggers
41734 when such conditions are true (@pxref{Conditions, ,Break Conditions}).
41735
41736 @item ConditionalTracepoints
41737 The remote stub accepts and implements conditional expressions defined
41738 for tracepoints (@pxref{Tracepoint Conditions}).
41739
41740 @item ReverseContinue
41741 The remote stub accepts and implements the reverse continue packet
41742 (@pxref{bc}).
41743
41744 @item ReverseStep
41745 The remote stub accepts and implements the reverse step packet
41746 (@pxref{bs}).
41747
41748 @item TracepointSource
41749 The remote stub understands the @samp{QTDPsrc} packet that supplies
41750 the source form of tracepoint definitions.
41751
41752 @item QAgent
41753 The remote stub understands the @samp{QAgent} packet.
41754
41755 @item QAllow
41756 The remote stub understands the @samp{QAllow} packet.
41757
41758 @item QDisableRandomization
41759 The remote stub understands the @samp{QDisableRandomization} packet.
41760
41761 @item StaticTracepoint
41762 @cindex static tracepoints, in remote protocol
41763 The remote stub supports static tracepoints.
41764
41765 @item InstallInTrace
41766 @anchor{install tracepoint in tracing}
41767 The remote stub supports installing tracepoint in tracing.
41768
41769 @item EnableDisableTracepoints
41770 The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
41771 @samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
41772 to be enabled and disabled while a trace experiment is running.
41773
41774 @item QTBuffer:size
41775 The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
41776 packet that allows to change the size of the trace buffer.
41777
41778 @item tracenz
41779 @cindex string tracing, in remote protocol
41780 The remote stub supports the @samp{tracenz} bytecode for collecting strings.
41781 See @ref{Bytecode Descriptions} for details about the bytecode.
41782
41783 @item BreakpointCommands
41784 @cindex breakpoint commands, in remote protocol
41785 The remote stub supports running a breakpoint's command list itself,
41786 rather than reporting the hit to @value{GDBN}.
41787
41788 @item Qbtrace:off
41789 The remote stub understands the @samp{Qbtrace:off} packet.
41790
41791 @item Qbtrace:bts
41792 The remote stub understands the @samp{Qbtrace:bts} packet.
41793
41794 @item Qbtrace:pt
41795 The remote stub understands the @samp{Qbtrace:pt} packet.
41796
41797 @item Qbtrace-conf:bts:size
41798 The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
41799
41800 @item Qbtrace-conf:pt:size
41801 The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
41802
41803 @item swbreak
41804 The remote stub reports the @samp{swbreak} stop reason for memory
41805 breakpoints.
41806
41807 @item hwbreak
41808 The remote stub reports the @samp{hwbreak} stop reason for hardware
41809 breakpoints.
41810
41811 @item fork-events
41812 The remote stub reports the @samp{fork} stop reason for fork events.
41813
41814 @item vfork-events
41815 The remote stub reports the @samp{vfork} stop reason for vfork events
41816 and vforkdone events.
41817
41818 @item exec-events
41819 The remote stub reports the @samp{exec} stop reason for exec events.
41820
41821 @item vContSupported
41822 The remote stub reports the supported actions in the reply to
41823 @samp{vCont?} packet.
41824
41825 @item QThreadEvents
41826 The remote stub understands the @samp{QThreadEvents} packet.
41827
41828 @item no-resumed
41829 The remote stub reports the @samp{N} stop reply.
41830
41831 @end table
41832
41833 @item qSymbol::
41834 @cindex symbol lookup, remote request
41835 @cindex @samp{qSymbol} packet
41836 Notify the target that @value{GDBN} is prepared to serve symbol lookup
41837 requests. Accept requests from the target for the values of symbols.
41838
41839 Reply:
41840 @table @samp
41841 @item OK
41842 The target does not need to look up any (more) symbols.
41843 @item qSymbol:@var{sym_name}
41844 The target requests the value of symbol @var{sym_name} (hex encoded).
41845 @value{GDBN} may provide the value by using the
41846 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
41847 below.
41848 @end table
41849
41850 @item qSymbol:@var{sym_value}:@var{sym_name}
41851 Set the value of @var{sym_name} to @var{sym_value}.
41852
41853 @var{sym_name} (hex encoded) is the name of a symbol whose value the
41854 target has previously requested.
41855
41856 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
41857 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
41858 will be empty.
41859
41860 Reply:
41861 @table @samp
41862 @item OK
41863 The target does not need to look up any (more) symbols.
41864 @item qSymbol:@var{sym_name}
41865 The target requests the value of a new symbol @var{sym_name} (hex
41866 encoded). @value{GDBN} will continue to supply the values of symbols
41867 (if available), until the target ceases to request them.
41868 @end table
41869
41870 @item qTBuffer
41871 @itemx QTBuffer
41872 @itemx QTDisconnected
41873 @itemx QTDP
41874 @itemx QTDPsrc
41875 @itemx QTDV
41876 @itemx qTfP
41877 @itemx qTfV
41878 @itemx QTFrame
41879 @itemx qTMinFTPILen
41880
41881 @xref{Tracepoint Packets}.
41882
41883 @item qThreadExtraInfo,@var{thread-id}
41884 @cindex thread attributes info, remote request
41885 @cindex @samp{qThreadExtraInfo} packet
41886 Obtain from the target OS a printable string description of thread
41887 attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
41888 for the forms of @var{thread-id}. This
41889 string may contain anything that the target OS thinks is interesting
41890 for @value{GDBN} to tell the user about the thread. The string is
41891 displayed in @value{GDBN}'s @code{info threads} display. Some
41892 examples of possible thread extra info strings are @samp{Runnable}, or
41893 @samp{Blocked on Mutex}.
41894
41895 Reply:
41896 @table @samp
41897 @item @var{XX}@dots{}
41898 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
41899 comprising the printable string containing the extra information about
41900 the thread's attributes.
41901 @end table
41902
41903 (Note that the @code{qThreadExtraInfo} packet's name is separated from
41904 the command by a @samp{,}, not a @samp{:}, contrary to the naming
41905 conventions above. Please don't use this packet as a model for new
41906 packets.)
41907
41908 @item QTNotes
41909 @itemx qTP
41910 @itemx QTSave
41911 @itemx qTsP
41912 @itemx qTsV
41913 @itemx QTStart
41914 @itemx QTStop
41915 @itemx QTEnable
41916 @itemx QTDisable
41917 @itemx QTinit
41918 @itemx QTro
41919 @itemx qTStatus
41920 @itemx qTV
41921 @itemx qTfSTM
41922 @itemx qTsSTM
41923 @itemx qTSTMat
41924 @xref{Tracepoint Packets}.
41925
41926 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
41927 @cindex read special object, remote request
41928 @cindex @samp{qXfer} packet
41929 @anchor{qXfer read}
41930 Read uninterpreted bytes from the target's special data area
41931 identified by the keyword @var{object}. Request @var{length} bytes
41932 starting at @var{offset} bytes into the data. The content and
41933 encoding of @var{annex} is specific to @var{object}; it can supply
41934 additional details about what data to access.
41935
41936 Reply:
41937 @table @samp
41938 @item m @var{data}
41939 Data @var{data} (@pxref{Binary Data}) has been read from the
41940 target. There may be more data at a higher address (although
41941 it is permitted to return @samp{m} even for the last valid
41942 block of data, as long as at least one byte of data was read).
41943 It is possible for @var{data} to have fewer bytes than the @var{length} in the
41944 request.
41945
41946 @item l @var{data}
41947 Data @var{data} (@pxref{Binary Data}) has been read from the target.
41948 There is no more data to be read. It is possible for @var{data} to
41949 have fewer bytes than the @var{length} in the request.
41950
41951 @item l
41952 The @var{offset} in the request is at the end of the data.
41953 There is no more data to be read.
41954
41955 @item E00
41956 The request was malformed, or @var{annex} was invalid.
41957
41958 @item E @var{nn}
41959 The offset was invalid, or there was an error encountered reading the data.
41960 The @var{nn} part is a hex-encoded @code{errno} value.
41961
41962 @item @w{}
41963 An empty reply indicates the @var{object} string was not recognized by
41964 the stub, or that the object does not support reading.
41965 @end table
41966
41967 Here are the specific requests of this form defined so far. All the
41968 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
41969 formats, listed above.
41970
41971 @table @samp
41972 @item qXfer:auxv:read::@var{offset},@var{length}
41973 @anchor{qXfer auxiliary vector read}
41974 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
41975 auxiliary vector}. Note @var{annex} must be empty.
41976
41977 This packet is not probed by default; the remote stub must request it,
41978 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41979
41980 @item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
41981 @anchor{qXfer btrace read}
41982
41983 Return a description of the current branch trace.
41984 @xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
41985 packet may have one of the following values:
41986
41987 @table @code
41988 @item all
41989 Returns all available branch trace.
41990
41991 @item new
41992 Returns all available branch trace if the branch trace changed since
41993 the last read request.
41994
41995 @item delta
41996 Returns the new branch trace since the last read request. Adds a new
41997 block to the end of the trace that begins at zero and ends at the source
41998 location of the first branch in the trace buffer. This extra block is
41999 used to stitch traces together.
42000
42001 If the trace buffer overflowed, returns an error indicating the overflow.
42002 @end table
42003
42004 This packet is not probed by default; the remote stub must request it
42005 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42006
42007 @item qXfer:btrace-conf:read::@var{offset},@var{length}
42008 @anchor{qXfer btrace-conf read}
42009
42010 Return a description of the current branch trace configuration.
42011 @xref{Branch Trace Configuration Format}.
42012
42013 This packet is not probed by default; the remote stub must request it
42014 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42015
42016 @item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
42017 @anchor{qXfer executable filename read}
42018 Return the full absolute name of the file that was executed to create
42019 a process running on the remote system. The annex specifies the
42020 numeric process ID of the process to query, encoded as a hexadecimal
42021 number. If the annex part is empty the remote stub should return the
42022 filename corresponding to the currently executing process.
42023
42024 This packet is not probed by default; the remote stub must request it,
42025 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42026
42027 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
42028 @anchor{qXfer target description read}
42029 Access the @dfn{target description}. @xref{Target Descriptions}. The
42030 annex specifies which XML document to access. The main description is
42031 always loaded from the @samp{target.xml} annex.
42032
42033 This packet is not probed by default; the remote stub must request it,
42034 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42035
42036 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
42037 @anchor{qXfer library list read}
42038 Access the target's list of loaded libraries. @xref{Library List Format}.
42039 The annex part of the generic @samp{qXfer} packet must be empty
42040 (@pxref{qXfer read}).
42041
42042 Targets which maintain a list of libraries in the program's memory do
42043 not need to implement this packet; it is designed for platforms where
42044 the operating system manages the list of loaded libraries.
42045
42046 This packet is not probed by default; the remote stub must request it,
42047 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42048
42049 @item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
42050 @anchor{qXfer svr4 library list read}
42051 Access the target's list of loaded libraries when the target is an SVR4
42052 platform. @xref{Library List Format for SVR4 Targets}. The annex part
42053 of the generic @samp{qXfer} packet must be empty unless the remote
42054 stub indicated it supports the augmented form of this packet
42055 by supplying an appropriate @samp{qSupported} response
42056 (@pxref{qXfer read}, @ref{qSupported}).
42057
42058 This packet is optional for better performance on SVR4 targets.
42059 @value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
42060
42061 This packet is not probed by default; the remote stub must request it,
42062 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42063
42064 If the remote stub indicates it supports the augmented form of this
42065 packet then the annex part of the generic @samp{qXfer} packet may
42066 contain a semicolon-separated list of @samp{@var{name}=@var{value}}
42067 arguments. The currently supported arguments are:
42068
42069 @table @code
42070 @item start=@var{address}
42071 A hexadecimal number specifying the address of the @samp{struct
42072 link_map} to start reading the library list from. If unset or zero
42073 then the first @samp{struct link_map} in the library list will be
42074 chosen as the starting point.
42075
42076 @item prev=@var{address}
42077 A hexadecimal number specifying the address of the @samp{struct
42078 link_map} immediately preceding the @samp{struct link_map}
42079 specified by the @samp{start} argument. If unset or zero then
42080 the remote stub will expect that no @samp{struct link_map}
42081 exists prior to the starting point.
42082
42083 @end table
42084
42085 Arguments that are not understood by the remote stub will be silently
42086 ignored.
42087
42088 @item qXfer:memory-map:read::@var{offset},@var{length}
42089 @anchor{qXfer memory map read}
42090 Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
42091 annex part of the generic @samp{qXfer} packet must be empty
42092 (@pxref{qXfer read}).
42093
42094 This packet is not probed by default; the remote stub must request it,
42095 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42096
42097 @item qXfer:sdata:read::@var{offset},@var{length}
42098 @anchor{qXfer sdata read}
42099
42100 Read contents of the extra collected static tracepoint marker
42101 information. The annex part of the generic @samp{qXfer} packet must
42102 be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
42103 Action Lists}.
42104
42105 This packet is not probed by default; the remote stub must request it,
42106 by supplying an appropriate @samp{qSupported} response
42107 (@pxref{qSupported}).
42108
42109 @item qXfer:siginfo:read::@var{offset},@var{length}
42110 @anchor{qXfer siginfo read}
42111 Read contents of the extra signal information on the target
42112 system. The annex part of the generic @samp{qXfer} packet must be
42113 empty (@pxref{qXfer read}).
42114
42115 This packet is not probed by default; the remote stub must request it,
42116 by supplying an appropriate @samp{qSupported} response
42117 (@pxref{qSupported}).
42118
42119 @item qXfer:threads:read::@var{offset},@var{length}
42120 @anchor{qXfer threads read}
42121 Access the list of threads on target. @xref{Thread List Format}. The
42122 annex part of the generic @samp{qXfer} packet must be empty
42123 (@pxref{qXfer read}).
42124
42125 This packet is not probed by default; the remote stub must request it,
42126 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42127
42128 @item qXfer:traceframe-info:read::@var{offset},@var{length}
42129 @anchor{qXfer traceframe info read}
42130
42131 Return a description of the current traceframe's contents.
42132 @xref{Traceframe Info Format}. The annex part of the generic
42133 @samp{qXfer} packet must be empty (@pxref{qXfer read}).
42134
42135 This packet is not probed by default; the remote stub must request it,
42136 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42137
42138 @item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
42139 @anchor{qXfer unwind info block}
42140
42141 Return the unwind information block for @var{pc}. This packet is used
42142 on OpenVMS/ia64 to ask the kernel unwind information.
42143
42144 This packet is not probed by default.
42145
42146 @item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
42147 @anchor{qXfer fdpic loadmap read}
42148 Read contents of @code{loadmap}s on the target system. The
42149 annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
42150 executable @code{loadmap} or interpreter @code{loadmap} to read.
42151
42152 This packet is not probed by default; the remote stub must request it,
42153 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42154
42155 @item qXfer:osdata:read::@var{offset},@var{length}
42156 @anchor{qXfer osdata read}
42157 Access the target's @dfn{operating system information}.
42158 @xref{Operating System Information}.
42159
42160 @end table
42161
42162 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
42163 @cindex write data into object, remote request
42164 @anchor{qXfer write}
42165 Write uninterpreted bytes into the target's special data area
42166 identified by the keyword @var{object}, starting at @var{offset} bytes
42167 into the data. The binary-encoded data (@pxref{Binary Data}) to be
42168 written is given by @var{data}@dots{}. The content and encoding of @var{annex}
42169 is specific to @var{object}; it can supply additional details about what data
42170 to access.
42171
42172 Reply:
42173 @table @samp
42174 @item @var{nn}
42175 @var{nn} (hex encoded) is the number of bytes written.
42176 This may be fewer bytes than supplied in the request.
42177
42178 @item E00
42179 The request was malformed, or @var{annex} was invalid.
42180
42181 @item E @var{nn}
42182 The offset was invalid, or there was an error encountered writing the data.
42183 The @var{nn} part is a hex-encoded @code{errno} value.
42184
42185 @item @w{}
42186 An empty reply indicates the @var{object} string was not
42187 recognized by the stub, or that the object does not support writing.
42188 @end table
42189
42190 Here are the specific requests of this form defined so far. All the
42191 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
42192 formats, listed above.
42193
42194 @table @samp
42195 @item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
42196 @anchor{qXfer siginfo write}
42197 Write @var{data} to the extra signal information on the target system.
42198 The annex part of the generic @samp{qXfer} packet must be
42199 empty (@pxref{qXfer write}).
42200
42201 This packet is not probed by default; the remote stub must request it,
42202 by supplying an appropriate @samp{qSupported} response
42203 (@pxref{qSupported}).
42204 @end table
42205
42206 @item qXfer:@var{object}:@var{operation}:@dots{}
42207 Requests of this form may be added in the future. When a stub does
42208 not recognize the @var{object} keyword, or its support for
42209 @var{object} does not recognize the @var{operation} keyword, the stub
42210 must respond with an empty packet.
42211
42212 @item qAttached:@var{pid}
42213 @cindex query attached, remote request
42214 @cindex @samp{qAttached} packet
42215 Return an indication of whether the remote server attached to an
42216 existing process or created a new process. When the multiprocess
42217 protocol extensions are supported (@pxref{multiprocess extensions}),
42218 @var{pid} is an integer in hexadecimal format identifying the target
42219 process. Otherwise, @value{GDBN} will omit the @var{pid} field and
42220 the query packet will be simplified as @samp{qAttached}.
42221
42222 This query is used, for example, to know whether the remote process
42223 should be detached or killed when a @value{GDBN} session is ended with
42224 the @code{quit} command.
42225
42226 Reply:
42227 @table @samp
42228 @item 1
42229 The remote server attached to an existing process.
42230 @item 0
42231 The remote server created a new process.
42232 @item E @var{NN}
42233 A badly formed request or an error was encountered.
42234 @end table
42235
42236 @item Qbtrace:bts
42237 Enable branch tracing for the current thread using Branch Trace Store.
42238
42239 Reply:
42240 @table @samp
42241 @item OK
42242 Branch tracing has been enabled.
42243 @item E.errtext
42244 A badly formed request or an error was encountered.
42245 @end table
42246
42247 @item Qbtrace:pt
42248 Enable branch tracing for the current thread using Intel Processor Trace.
42249
42250 Reply:
42251 @table @samp
42252 @item OK
42253 Branch tracing has been enabled.
42254 @item E.errtext
42255 A badly formed request or an error was encountered.
42256 @end table
42257
42258 @item Qbtrace:off
42259 Disable branch tracing for the current thread.
42260
42261 Reply:
42262 @table @samp
42263 @item OK
42264 Branch tracing has been disabled.
42265 @item E.errtext
42266 A badly formed request or an error was encountered.
42267 @end table
42268
42269 @item Qbtrace-conf:bts:size=@var{value}
42270 Set the requested ring buffer size for new threads that use the
42271 btrace recording method in bts format.
42272
42273 Reply:
42274 @table @samp
42275 @item OK
42276 The ring buffer size has been set.
42277 @item E.errtext
42278 A badly formed request or an error was encountered.
42279 @end table
42280
42281 @item Qbtrace-conf:pt:size=@var{value}
42282 Set the requested ring buffer size for new threads that use the
42283 btrace recording method in pt format.
42284
42285 Reply:
42286 @table @samp
42287 @item OK
42288 The ring buffer size has been set.
42289 @item E.errtext
42290 A badly formed request or an error was encountered.
42291 @end table
42292
42293 @end table
42294
42295 @node Architecture-Specific Protocol Details
42296 @section Architecture-Specific Protocol Details
42297
42298 This section describes how the remote protocol is applied to specific
42299 target architectures. Also see @ref{Standard Target Features}, for
42300 details of XML target descriptions for each architecture.
42301
42302 @menu
42303 * ARM-Specific Protocol Details::
42304 * MIPS-Specific Protocol Details::
42305 @end menu
42306
42307 @node ARM-Specific Protocol Details
42308 @subsection @acronym{ARM}-specific Protocol Details
42309
42310 @menu
42311 * ARM Breakpoint Kinds::
42312 @end menu
42313
42314 @node ARM Breakpoint Kinds
42315 @subsubsection @acronym{ARM} Breakpoint Kinds
42316 @cindex breakpoint kinds, @acronym{ARM}
42317
42318 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42319
42320 @table @r
42321
42322 @item 2
42323 16-bit Thumb mode breakpoint.
42324
42325 @item 3
42326 32-bit Thumb mode (Thumb-2) breakpoint.
42327
42328 @item 4
42329 32-bit @acronym{ARM} mode breakpoint.
42330
42331 @end table
42332
42333 @node MIPS-Specific Protocol Details
42334 @subsection @acronym{MIPS}-specific Protocol Details
42335
42336 @menu
42337 * MIPS Register packet Format::
42338 * MIPS Breakpoint Kinds::
42339 @end menu
42340
42341 @node MIPS Register packet Format
42342 @subsubsection @acronym{MIPS} Register Packet Format
42343 @cindex register packet format, @acronym{MIPS}
42344
42345 The following @code{g}/@code{G} packets have previously been defined.
42346 In the below, some thirty-two bit registers are transferred as
42347 sixty-four bits. Those registers should be zero/sign extended (which?)
42348 to fill the space allocated. Register bytes are transferred in target
42349 byte order. The two nibbles within a register byte are transferred
42350 most-significant -- least-significant.
42351
42352 @table @r
42353
42354 @item MIPS32
42355 All registers are transferred as thirty-two bit quantities in the order:
42356 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
42357 registers; fsr; fir; fp.
42358
42359 @item MIPS64
42360 All registers are transferred as sixty-four bit quantities (including
42361 thirty-two bit registers such as @code{sr}). The ordering is the same
42362 as @code{MIPS32}.
42363
42364 @end table
42365
42366 @node MIPS Breakpoint Kinds
42367 @subsubsection @acronym{MIPS} Breakpoint Kinds
42368 @cindex breakpoint kinds, @acronym{MIPS}
42369
42370 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42371
42372 @table @r
42373
42374 @item 2
42375 16-bit @acronym{MIPS16} mode breakpoint.
42376
42377 @item 3
42378 16-bit @acronym{microMIPS} mode breakpoint.
42379
42380 @item 4
42381 32-bit standard @acronym{MIPS} mode breakpoint.
42382
42383 @item 5
42384 32-bit @acronym{microMIPS} mode breakpoint.
42385
42386 @end table
42387
42388 @node Tracepoint Packets
42389 @section Tracepoint Packets
42390 @cindex tracepoint packets
42391 @cindex packets, tracepoint
42392
42393 Here we describe the packets @value{GDBN} uses to implement
42394 tracepoints (@pxref{Tracepoints}).
42395
42396 @table @samp
42397
42398 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
42399 @cindex @samp{QTDP} packet
42400 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
42401 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
42402 the tracepoint is disabled. The @var{step} gives the tracepoint's step
42403 count, and @var{pass} gives its pass count. If an @samp{F} is present,
42404 then the tracepoint is to be a fast tracepoint, and the @var{flen} is
42405 the number of bytes that the target should copy elsewhere to make room
42406 for the tracepoint. If an @samp{X} is present, it introduces a
42407 tracepoint condition, which consists of a hexadecimal length, followed
42408 by a comma and hex-encoded bytes, in a manner similar to action
42409 encodings as described below. If the trailing @samp{-} is present,
42410 further @samp{QTDP} packets will follow to specify this tracepoint's
42411 actions.
42412
42413 Replies:
42414 @table @samp
42415 @item OK
42416 The packet was understood and carried out.
42417 @item qRelocInsn
42418 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
42419 @item @w{}
42420 The packet was not recognized.
42421 @end table
42422
42423 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
42424 Define actions to be taken when a tracepoint is hit. The @var{n} and
42425 @var{addr} must be the same as in the initial @samp{QTDP} packet for
42426 this tracepoint. This packet may only be sent immediately after
42427 another @samp{QTDP} packet that ended with a @samp{-}. If the
42428 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
42429 specifying more actions for this tracepoint.
42430
42431 In the series of action packets for a given tracepoint, at most one
42432 can have an @samp{S} before its first @var{action}. If such a packet
42433 is sent, it and the following packets define ``while-stepping''
42434 actions. Any prior packets define ordinary actions --- that is, those
42435 taken when the tracepoint is first hit. If no action packet has an
42436 @samp{S}, then all the packets in the series specify ordinary
42437 tracepoint actions.
42438
42439 The @samp{@var{action}@dots{}} portion of the packet is a series of
42440 actions, concatenated without separators. Each action has one of the
42441 following forms:
42442
42443 @table @samp
42444
42445 @item R @var{mask}
42446 Collect the registers whose bits are set in @var{mask},
42447 a hexadecimal number whose @var{i}'th bit is set if register number
42448 @var{i} should be collected. (The least significant bit is numbered
42449 zero.) Note that @var{mask} may be any number of digits long; it may
42450 not fit in a 32-bit word.
42451
42452 @item M @var{basereg},@var{offset},@var{len}
42453 Collect @var{len} bytes of memory starting at the address in register
42454 number @var{basereg}, plus @var{offset}. If @var{basereg} is
42455 @samp{-1}, then the range has a fixed address: @var{offset} is the
42456 address of the lowest byte to collect. The @var{basereg},
42457 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
42458 values (the @samp{-1} value for @var{basereg} is a special case).
42459
42460 @item X @var{len},@var{expr}
42461 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
42462 it directs. The agent expression @var{expr} is as described in
42463 @ref{Agent Expressions}. Each byte of the expression is encoded as a
42464 two-digit hex number in the packet; @var{len} is the number of bytes
42465 in the expression (and thus one-half the number of hex digits in the
42466 packet).
42467
42468 @end table
42469
42470 Any number of actions may be packed together in a single @samp{QTDP}
42471 packet, as long as the packet does not exceed the maximum packet
42472 length (400 bytes, for many stubs). There may be only one @samp{R}
42473 action per tracepoint, and it must precede any @samp{M} or @samp{X}
42474 actions. Any registers referred to by @samp{M} and @samp{X} actions
42475 must be collected by a preceding @samp{R} action. (The
42476 ``while-stepping'' actions are treated as if they were attached to a
42477 separate tracepoint, as far as these restrictions are concerned.)
42478
42479 Replies:
42480 @table @samp
42481 @item OK
42482 The packet was understood and carried out.
42483 @item qRelocInsn
42484 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
42485 @item @w{}
42486 The packet was not recognized.
42487 @end table
42488
42489 @item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
42490 @cindex @samp{QTDPsrc} packet
42491 Specify a source string of tracepoint @var{n} at address @var{addr}.
42492 This is useful to get accurate reproduction of the tracepoints
42493 originally downloaded at the beginning of the trace run. The @var{type}
42494 is the name of the tracepoint part, such as @samp{cond} for the
42495 tracepoint's conditional expression (see below for a list of types), while
42496 @var{bytes} is the string, encoded in hexadecimal.
42497
42498 @var{start} is the offset of the @var{bytes} within the overall source
42499 string, while @var{slen} is the total length of the source string.
42500 This is intended for handling source strings that are longer than will
42501 fit in a single packet.
42502 @c Add detailed example when this info is moved into a dedicated
42503 @c tracepoint descriptions section.
42504
42505 The available string types are @samp{at} for the location,
42506 @samp{cond} for the conditional, and @samp{cmd} for an action command.
42507 @value{GDBN} sends a separate packet for each command in the action
42508 list, in the same order in which the commands are stored in the list.
42509
42510 The target does not need to do anything with source strings except
42511 report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
42512 query packets.
42513
42514 Although this packet is optional, and @value{GDBN} will only send it
42515 if the target replies with @samp{TracepointSource} @xref{General
42516 Query Packets}, it makes both disconnected tracing and trace files
42517 much easier to use. Otherwise the user must be careful that the
42518 tracepoints in effect while looking at trace frames are identical to
42519 the ones in effect during the trace run; even a small discrepancy
42520 could cause @samp{tdump} not to work, or a particular trace frame not
42521 be found.
42522
42523 @item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
42524 @cindex define trace state variable, remote request
42525 @cindex @samp{QTDV} packet
42526 Create a new trace state variable, number @var{n}, with an initial
42527 value of @var{value}, which is a 64-bit signed integer. Both @var{n}
42528 and @var{value} are encoded as hexadecimal values. @value{GDBN} has
42529 the option of not using this packet for initial values of zero; the
42530 target should simply create the trace state variables as they are
42531 mentioned in expressions. The value @var{builtin} should be 1 (one)
42532 if the trace state variable is builtin and 0 (zero) if it is not builtin.
42533 @value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
42534 @samp{qTsV} packet had it set. The contents of @var{name} is the
42535 hex-encoded name (without the leading @samp{$}) of the trace state
42536 variable.
42537
42538 @item QTFrame:@var{n}
42539 @cindex @samp{QTFrame} packet
42540 Select the @var{n}'th tracepoint frame from the buffer, and use the
42541 register and memory contents recorded there to answer subsequent
42542 request packets from @value{GDBN}.
42543
42544 A successful reply from the stub indicates that the stub has found the
42545 requested frame. The response is a series of parts, concatenated
42546 without separators, describing the frame we selected. Each part has
42547 one of the following forms:
42548
42549 @table @samp
42550 @item F @var{f}
42551 The selected frame is number @var{n} in the trace frame buffer;
42552 @var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
42553 was no frame matching the criteria in the request packet.
42554
42555 @item T @var{t}
42556 The selected trace frame records a hit of tracepoint number @var{t};
42557 @var{t} is a hexadecimal number.
42558
42559 @end table
42560
42561 @item QTFrame:pc:@var{addr}
42562 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42563 currently selected frame whose PC is @var{addr};
42564 @var{addr} is a hexadecimal number.
42565
42566 @item QTFrame:tdp:@var{t}
42567 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42568 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
42569 is a hexadecimal number.
42570
42571 @item QTFrame:range:@var{start}:@var{end}
42572 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42573 currently selected frame whose PC is between @var{start} (inclusive)
42574 and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
42575 numbers.
42576
42577 @item QTFrame:outside:@var{start}:@var{end}
42578 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
42579 frame @emph{outside} the given range of addresses (exclusive).
42580
42581 @item qTMinFTPILen
42582 @cindex @samp{qTMinFTPILen} packet
42583 This packet requests the minimum length of instruction at which a fast
42584 tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
42585 the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
42586 it depends on the target system being able to create trampolines in
42587 the first 64K of memory, which might or might not be possible for that
42588 system. So the reply to this packet will be 4 if it is able to
42589 arrange for that.
42590
42591 Replies:
42592
42593 @table @samp
42594 @item 0
42595 The minimum instruction length is currently unknown.
42596 @item @var{length}
42597 The minimum instruction length is @var{length}, where @var{length}
42598 is a hexadecimal number greater or equal to 1. A reply
42599 of 1 means that a fast tracepoint may be placed on any instruction
42600 regardless of size.
42601 @item E
42602 An error has occurred.
42603 @item @w{}
42604 An empty reply indicates that the request is not supported by the stub.
42605 @end table
42606
42607 @item QTStart
42608 @cindex @samp{QTStart} packet
42609 Begin the tracepoint experiment. Begin collecting data from
42610 tracepoint hits in the trace frame buffer. This packet supports the
42611 @samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
42612 instruction reply packet}).
42613
42614 @item QTStop
42615 @cindex @samp{QTStop} packet
42616 End the tracepoint experiment. Stop collecting trace frames.
42617
42618 @item QTEnable:@var{n}:@var{addr}
42619 @anchor{QTEnable}
42620 @cindex @samp{QTEnable} packet
42621 Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
42622 experiment. If the tracepoint was previously disabled, then collection
42623 of data from it will resume.
42624
42625 @item QTDisable:@var{n}:@var{addr}
42626 @anchor{QTDisable}
42627 @cindex @samp{QTDisable} packet
42628 Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
42629 experiment. No more data will be collected from the tracepoint unless
42630 @samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
42631
42632 @item QTinit
42633 @cindex @samp{QTinit} packet
42634 Clear the table of tracepoints, and empty the trace frame buffer.
42635
42636 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
42637 @cindex @samp{QTro} packet
42638 Establish the given ranges of memory as ``transparent''. The stub
42639 will answer requests for these ranges from memory's current contents,
42640 if they were not collected as part of the tracepoint hit.
42641
42642 @value{GDBN} uses this to mark read-only regions of memory, like those
42643 containing program code. Since these areas never change, they should
42644 still have the same contents they did when the tracepoint was hit, so
42645 there's no reason for the stub to refuse to provide their contents.
42646
42647 @item QTDisconnected:@var{value}
42648 @cindex @samp{QTDisconnected} packet
42649 Set the choice to what to do with the tracing run when @value{GDBN}
42650 disconnects from the target. A @var{value} of 1 directs the target to
42651 continue the tracing run, while 0 tells the target to stop tracing if
42652 @value{GDBN} is no longer in the picture.
42653
42654 @item qTStatus
42655 @cindex @samp{qTStatus} packet
42656 Ask the stub if there is a trace experiment running right now.
42657
42658 The reply has the form:
42659
42660 @table @samp
42661
42662 @item T@var{running}@r{[};@var{field}@r{]}@dots{}
42663 @var{running} is a single digit @code{1} if the trace is presently
42664 running, or @code{0} if not. It is followed by semicolon-separated
42665 optional fields that an agent may use to report additional status.
42666
42667 @end table
42668
42669 If the trace is not running, the agent may report any of several
42670 explanations as one of the optional fields:
42671
42672 @table @samp
42673
42674 @item tnotrun:0
42675 No trace has been run yet.
42676
42677 @item tstop[:@var{text}]:0
42678 The trace was stopped by a user-originated stop command. The optional
42679 @var{text} field is a user-supplied string supplied as part of the
42680 stop command (for instance, an explanation of why the trace was
42681 stopped manually). It is hex-encoded.
42682
42683 @item tfull:0
42684 The trace stopped because the trace buffer filled up.
42685
42686 @item tdisconnected:0
42687 The trace stopped because @value{GDBN} disconnected from the target.
42688
42689 @item tpasscount:@var{tpnum}
42690 The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
42691
42692 @item terror:@var{text}:@var{tpnum}
42693 The trace stopped because tracepoint @var{tpnum} had an error. The
42694 string @var{text} is available to describe the nature of the error
42695 (for instance, a divide by zero in the condition expression); it
42696 is hex encoded.
42697
42698 @item tunknown:0
42699 The trace stopped for some other reason.
42700
42701 @end table
42702
42703 Additional optional fields supply statistical and other information.
42704 Although not required, they are extremely useful for users monitoring
42705 the progress of a trace run. If a trace has stopped, and these
42706 numbers are reported, they must reflect the state of the just-stopped
42707 trace.
42708
42709 @table @samp
42710
42711 @item tframes:@var{n}
42712 The number of trace frames in the buffer.
42713
42714 @item tcreated:@var{n}
42715 The total number of trace frames created during the run. This may
42716 be larger than the trace frame count, if the buffer is circular.
42717
42718 @item tsize:@var{n}
42719 The total size of the trace buffer, in bytes.
42720
42721 @item tfree:@var{n}
42722 The number of bytes still unused in the buffer.
42723
42724 @item circular:@var{n}
42725 The value of the circular trace buffer flag. @code{1} means that the
42726 trace buffer is circular and old trace frames will be discarded if
42727 necessary to make room, @code{0} means that the trace buffer is linear
42728 and may fill up.
42729
42730 @item disconn:@var{n}
42731 The value of the disconnected tracing flag. @code{1} means that
42732 tracing will continue after @value{GDBN} disconnects, @code{0} means
42733 that the trace run will stop.
42734
42735 @end table
42736
42737 @item qTP:@var{tp}:@var{addr}
42738 @cindex tracepoint status, remote request
42739 @cindex @samp{qTP} packet
42740 Ask the stub for the current state of tracepoint number @var{tp} at
42741 address @var{addr}.
42742
42743 Replies:
42744 @table @samp
42745 @item V@var{hits}:@var{usage}
42746 The tracepoint has been hit @var{hits} times so far during the trace
42747 run, and accounts for @var{usage} in the trace buffer. Note that
42748 @code{while-stepping} steps are not counted as separate hits, but the
42749 steps' space consumption is added into the usage number.
42750
42751 @end table
42752
42753 @item qTV:@var{var}
42754 @cindex trace state variable value, remote request
42755 @cindex @samp{qTV} packet
42756 Ask the stub for the value of the trace state variable number @var{var}.
42757
42758 Replies:
42759 @table @samp
42760 @item V@var{value}
42761 The value of the variable is @var{value}. This will be the current
42762 value of the variable if the user is examining a running target, or a
42763 saved value if the variable was collected in the trace frame that the
42764 user is looking at. Note that multiple requests may result in
42765 different reply values, such as when requesting values while the
42766 program is running.
42767
42768 @item U
42769 The value of the variable is unknown. This would occur, for example,
42770 if the user is examining a trace frame in which the requested variable
42771 was not collected.
42772 @end table
42773
42774 @item qTfP
42775 @cindex @samp{qTfP} packet
42776 @itemx qTsP
42777 @cindex @samp{qTsP} packet
42778 These packets request data about tracepoints that are being used by
42779 the target. @value{GDBN} sends @code{qTfP} to get the first piece
42780 of data, and multiple @code{qTsP} to get additional pieces. Replies
42781 to these packets generally take the form of the @code{QTDP} packets
42782 that define tracepoints. (FIXME add detailed syntax)
42783
42784 @item qTfV
42785 @cindex @samp{qTfV} packet
42786 @itemx qTsV
42787 @cindex @samp{qTsV} packet
42788 These packets request data about trace state variables that are on the
42789 target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
42790 and multiple @code{qTsV} to get additional variables. Replies to
42791 these packets follow the syntax of the @code{QTDV} packets that define
42792 trace state variables.
42793
42794 @item qTfSTM
42795 @itemx qTsSTM
42796 @anchor{qTfSTM}
42797 @anchor{qTsSTM}
42798 @cindex @samp{qTfSTM} packet
42799 @cindex @samp{qTsSTM} packet
42800 These packets request data about static tracepoint markers that exist
42801 in the target program. @value{GDBN} sends @code{qTfSTM} to get the
42802 first piece of data, and multiple @code{qTsSTM} to get additional
42803 pieces. Replies to these packets take the following form:
42804
42805 Reply:
42806 @table @samp
42807 @item m @var{address}:@var{id}:@var{extra}
42808 A single marker
42809 @item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
42810 a comma-separated list of markers
42811 @item l
42812 (lower case letter @samp{L}) denotes end of list.
42813 @item E @var{nn}
42814 An error occurred. The error number @var{nn} is given as hex digits.
42815 @item @w{}
42816 An empty reply indicates that the request is not supported by the
42817 stub.
42818 @end table
42819
42820 The @var{address} is encoded in hex;
42821 @var{id} and @var{extra} are strings encoded in hex.
42822
42823 In response to each query, the target will reply with a list of one or
42824 more markers, separated by commas. @value{GDBN} will respond to each
42825 reply with a request for more markers (using the @samp{qs} form of the
42826 query), until the target responds with @samp{l} (lower-case ell, for
42827 @dfn{last}).
42828
42829 @item qTSTMat:@var{address}
42830 @anchor{qTSTMat}
42831 @cindex @samp{qTSTMat} packet
42832 This packets requests data about static tracepoint markers in the
42833 target program at @var{address}. Replies to this packet follow the
42834 syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
42835 tracepoint markers.
42836
42837 @item QTSave:@var{filename}
42838 @cindex @samp{QTSave} packet
42839 This packet directs the target to save trace data to the file name
42840 @var{filename} in the target's filesystem. The @var{filename} is encoded
42841 as a hex string; the interpretation of the file name (relative vs
42842 absolute, wild cards, etc) is up to the target.
42843
42844 @item qTBuffer:@var{offset},@var{len}
42845 @cindex @samp{qTBuffer} packet
42846 Return up to @var{len} bytes of the current contents of trace buffer,
42847 starting at @var{offset}. The trace buffer is treated as if it were
42848 a contiguous collection of traceframes, as per the trace file format.
42849 The reply consists as many hex-encoded bytes as the target can deliver
42850 in a packet; it is not an error to return fewer than were asked for.
42851 A reply consisting of just @code{l} indicates that no bytes are
42852 available.
42853
42854 @item QTBuffer:circular:@var{value}
42855 This packet directs the target to use a circular trace buffer if
42856 @var{value} is 1, or a linear buffer if the value is 0.
42857
42858 @item QTBuffer:size:@var{size}
42859 @anchor{QTBuffer-size}
42860 @cindex @samp{QTBuffer size} packet
42861 This packet directs the target to make the trace buffer be of size
42862 @var{size} if possible. A value of @code{-1} tells the target to
42863 use whatever size it prefers.
42864
42865 @item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
42866 @cindex @samp{QTNotes} packet
42867 This packet adds optional textual notes to the trace run. Allowable
42868 types include @code{user}, @code{notes}, and @code{tstop}, the
42869 @var{text} fields are arbitrary strings, hex-encoded.
42870
42871 @end table
42872
42873 @subsection Relocate instruction reply packet
42874 When installing fast tracepoints in memory, the target may need to
42875 relocate the instruction currently at the tracepoint address to a
42876 different address in memory. For most instructions, a simple copy is
42877 enough, but, for example, call instructions that implicitly push the
42878 return address on the stack, and relative branches or other
42879 PC-relative instructions require offset adjustment, so that the effect
42880 of executing the instruction at a different address is the same as if
42881 it had executed in the original location.
42882
42883 In response to several of the tracepoint packets, the target may also
42884 respond with a number of intermediate @samp{qRelocInsn} request
42885 packets before the final result packet, to have @value{GDBN} handle
42886 this relocation operation. If a packet supports this mechanism, its
42887 documentation will explicitly say so. See for example the above
42888 descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
42889 format of the request is:
42890
42891 @table @samp
42892 @item qRelocInsn:@var{from};@var{to}
42893
42894 This requests @value{GDBN} to copy instruction at address @var{from}
42895 to address @var{to}, possibly adjusted so that executing the
42896 instruction at @var{to} has the same effect as executing it at
42897 @var{from}. @value{GDBN} writes the adjusted instruction to target
42898 memory starting at @var{to}.
42899 @end table
42900
42901 Replies:
42902 @table @samp
42903 @item qRelocInsn:@var{adjusted_size}
42904 Informs the stub the relocation is complete. The @var{adjusted_size} is
42905 the length in bytes of resulting relocated instruction sequence.
42906 @item E @var{NN}
42907 A badly formed request was detected, or an error was encountered while
42908 relocating the instruction.
42909 @end table
42910
42911 @node Host I/O Packets
42912 @section Host I/O Packets
42913 @cindex Host I/O, remote protocol
42914 @cindex file transfer, remote protocol
42915
42916 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
42917 operations on the far side of a remote link. For example, Host I/O is
42918 used to upload and download files to a remote target with its own
42919 filesystem. Host I/O uses the same constant values and data structure
42920 layout as the target-initiated File-I/O protocol. However, the
42921 Host I/O packets are structured differently. The target-initiated
42922 protocol relies on target memory to store parameters and buffers.
42923 Host I/O requests are initiated by @value{GDBN}, and the
42924 target's memory is not involved. @xref{File-I/O Remote Protocol
42925 Extension}, for more details on the target-initiated protocol.
42926
42927 The Host I/O request packets all encode a single operation along with
42928 its arguments. They have this format:
42929
42930 @table @samp
42931
42932 @item vFile:@var{operation}: @var{parameter}@dots{}
42933 @var{operation} is the name of the particular request; the target
42934 should compare the entire packet name up to the second colon when checking
42935 for a supported operation. The format of @var{parameter} depends on
42936 the operation. Numbers are always passed in hexadecimal. Negative
42937 numbers have an explicit minus sign (i.e.@: two's complement is not
42938 used). Strings (e.g.@: filenames) are encoded as a series of
42939 hexadecimal bytes. The last argument to a system call may be a
42940 buffer of escaped binary data (@pxref{Binary Data}).
42941
42942 @end table
42943
42944 The valid responses to Host I/O packets are:
42945
42946 @table @samp
42947
42948 @item F @var{result} [, @var{errno}] [; @var{attachment}]
42949 @var{result} is the integer value returned by this operation, usually
42950 non-negative for success and -1 for errors. If an error has occured,
42951 @var{errno} will be included in the result specifying a
42952 value defined by the File-I/O protocol (@pxref{Errno Values}). For
42953 operations which return data, @var{attachment} supplies the data as a
42954 binary buffer. Binary buffers in response packets are escaped in the
42955 normal way (@pxref{Binary Data}). See the individual packet
42956 documentation for the interpretation of @var{result} and
42957 @var{attachment}.
42958
42959 @item @w{}
42960 An empty response indicates that this operation is not recognized.
42961
42962 @end table
42963
42964 These are the supported Host I/O operations:
42965
42966 @table @samp
42967 @item vFile:open: @var{filename}, @var{flags}, @var{mode}
42968 Open a file at @var{filename} and return a file descriptor for it, or
42969 return -1 if an error occurs. The @var{filename} is a string,
42970 @var{flags} is an integer indicating a mask of open flags
42971 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
42972 of mode bits to use if the file is created (@pxref{mode_t Values}).
42973 @xref{open}, for details of the open flags and mode values.
42974
42975 @item vFile:close: @var{fd}
42976 Close the open file corresponding to @var{fd} and return 0, or
42977 -1 if an error occurs.
42978
42979 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
42980 Read data from the open file corresponding to @var{fd}. Up to
42981 @var{count} bytes will be read from the file, starting at @var{offset}
42982 relative to the start of the file. The target may read fewer bytes;
42983 common reasons include packet size limits and an end-of-file
42984 condition. The number of bytes read is returned. Zero should only be
42985 returned for a successful read at the end of the file, or if
42986 @var{count} was zero.
42987
42988 The data read should be returned as a binary attachment on success.
42989 If zero bytes were read, the response should include an empty binary
42990 attachment (i.e.@: a trailing semicolon). The return value is the
42991 number of target bytes read; the binary attachment may be longer if
42992 some characters were escaped.
42993
42994 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
42995 Write @var{data} (a binary buffer) to the open file corresponding
42996 to @var{fd}. Start the write at @var{offset} from the start of the
42997 file. Unlike many @code{write} system calls, there is no
42998 separate @var{count} argument; the length of @var{data} in the
42999 packet is used. @samp{vFile:pwrite} returns the number of bytes written,
43000 which may be shorter than the length of @var{data}, or -1 if an
43001 error occurred.
43002
43003 @item vFile:fstat: @var{fd}
43004 Get information about the open file corresponding to @var{fd}.
43005 On success the information is returned as a binary attachment
43006 and the return value is the size of this attachment in bytes.
43007 If an error occurs the return value is -1. The format of the
43008 returned binary attachment is as described in @ref{struct stat}.
43009
43010 @item vFile:unlink: @var{filename}
43011 Delete the file at @var{filename} on the target. Return 0,
43012 or -1 if an error occurs. The @var{filename} is a string.
43013
43014 @item vFile:readlink: @var{filename}
43015 Read value of symbolic link @var{filename} on the target. Return
43016 the number of bytes read, or -1 if an error occurs.
43017
43018 The data read should be returned as a binary attachment on success.
43019 If zero bytes were read, the response should include an empty binary
43020 attachment (i.e.@: a trailing semicolon). The return value is the
43021 number of target bytes read; the binary attachment may be longer if
43022 some characters were escaped.
43023
43024 @item vFile:setfs: @var{pid}
43025 Select the filesystem on which @code{vFile} operations with
43026 @var{filename} arguments will operate. This is required for
43027 @value{GDBN} to be able to access files on remote targets where
43028 the remote stub does not share a common filesystem with the
43029 inferior(s).
43030
43031 If @var{pid} is nonzero, select the filesystem as seen by process
43032 @var{pid}. If @var{pid} is zero, select the filesystem as seen by
43033 the remote stub. Return 0 on success, or -1 if an error occurs.
43034 If @code{vFile:setfs:} indicates success, the selected filesystem
43035 remains selected until the next successful @code{vFile:setfs:}
43036 operation.
43037
43038 @end table
43039
43040 @node Interrupts
43041 @section Interrupts
43042 @cindex interrupts (remote protocol)
43043 @anchor{interrupting remote targets}
43044
43045 In all-stop mode, when a program on the remote target is running,
43046 @value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
43047 @code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
43048 is specified via @value{GDBN}'s @samp{interrupt-sequence}.
43049
43050 The precise meaning of @code{BREAK} is defined by the transport
43051 mechanism and may, in fact, be undefined. @value{GDBN} does not
43052 currently define a @code{BREAK} mechanism for any of the network
43053 interfaces except for TCP, in which case @value{GDBN} sends the
43054 @code{telnet} BREAK sequence.
43055
43056 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
43057 transport mechanisms. It is represented by sending the single byte
43058 @code{0x03} without any of the usual packet overhead described in
43059 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
43060 transmitted as part of a packet, it is considered to be packet data
43061 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
43062 (@pxref{X packet}), used for binary downloads, may include an unescaped
43063 @code{0x03} as part of its packet.
43064
43065 @code{BREAK} followed by @code{g} is also known as Magic SysRq g.
43066 When Linux kernel receives this sequence from serial port,
43067 it stops execution and connects to gdb.
43068
43069 In non-stop mode, because packet resumptions are asynchronous
43070 (@pxref{vCont packet}), @value{GDBN} is always free to send a remote
43071 command to the remote stub, even when the target is running. For that
43072 reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
43073 packet}) with the usual packet framing instead of the single byte
43074 @code{0x03}.
43075
43076 Stubs are not required to recognize these interrupt mechanisms and the
43077 precise meaning associated with receipt of the interrupt is
43078 implementation defined. If the target supports debugging of multiple
43079 threads and/or processes, it should attempt to interrupt all
43080 currently-executing threads and processes.
43081 If the stub is successful at interrupting the
43082 running program, it should send one of the stop
43083 reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
43084 of successfully stopping the program in all-stop mode, and a stop reply
43085 for each stopped thread in non-stop mode.
43086 Interrupts received while the
43087 program is stopped are queued and the program will be interrupted when
43088 it is resumed next time.
43089
43090 @node Notification Packets
43091 @section Notification Packets
43092 @cindex notification packets
43093 @cindex packets, notification
43094
43095 The @value{GDBN} remote serial protocol includes @dfn{notifications},
43096 packets that require no acknowledgment. Both the GDB and the stub
43097 may send notifications (although the only notifications defined at
43098 present are sent by the stub). Notifications carry information
43099 without incurring the round-trip latency of an acknowledgment, and so
43100 are useful for low-impact communications where occasional packet loss
43101 is not a problem.
43102
43103 A notification packet has the form @samp{% @var{data} #
43104 @var{checksum}}, where @var{data} is the content of the notification,
43105 and @var{checksum} is a checksum of @var{data}, computed and formatted
43106 as for ordinary @value{GDBN} packets. A notification's @var{data}
43107 never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
43108 receiving a notification, the recipient sends no @samp{+} or @samp{-}
43109 to acknowledge the notification's receipt or to report its corruption.
43110
43111 Every notification's @var{data} begins with a name, which contains no
43112 colon characters, followed by a colon character.
43113
43114 Recipients should silently ignore corrupted notifications and
43115 notifications they do not understand. Recipients should restart
43116 timeout periods on receipt of a well-formed notification, whether or
43117 not they understand it.
43118
43119 Senders should only send the notifications described here when this
43120 protocol description specifies that they are permitted. In the
43121 future, we may extend the protocol to permit existing notifications in
43122 new contexts; this rule helps older senders avoid confusing newer
43123 recipients.
43124
43125 (Older versions of @value{GDBN} ignore bytes received until they see
43126 the @samp{$} byte that begins an ordinary packet, so new stubs may
43127 transmit notifications without fear of confusing older clients. There
43128 are no notifications defined for @value{GDBN} to send at the moment, but we
43129 assume that most older stubs would ignore them, as well.)
43130
43131 Each notification is comprised of three parts:
43132 @table @samp
43133 @item @var{name}:@var{event}
43134 The notification packet is sent by the side that initiates the
43135 exchange (currently, only the stub does that), with @var{event}
43136 carrying the specific information about the notification, and
43137 @var{name} specifying the name of the notification.
43138 @item @var{ack}
43139 The acknowledge sent by the other side, usually @value{GDBN}, to
43140 acknowledge the exchange and request the event.
43141 @end table
43142
43143 The purpose of an asynchronous notification mechanism is to report to
43144 @value{GDBN} that something interesting happened in the remote stub.
43145
43146 The remote stub may send notification @var{name}:@var{event}
43147 at any time, but @value{GDBN} acknowledges the notification when
43148 appropriate. The notification event is pending before @value{GDBN}
43149 acknowledges. Only one notification at a time may be pending; if
43150 additional events occur before @value{GDBN} has acknowledged the
43151 previous notification, they must be queued by the stub for later
43152 synchronous transmission in response to @var{ack} packets from
43153 @value{GDBN}. Because the notification mechanism is unreliable,
43154 the stub is permitted to resend a notification if it believes
43155 @value{GDBN} may not have received it.
43156
43157 Specifically, notifications may appear when @value{GDBN} is not
43158 otherwise reading input from the stub, or when @value{GDBN} is
43159 expecting to read a normal synchronous response or a
43160 @samp{+}/@samp{-} acknowledgment to a packet it has sent.
43161 Notification packets are distinct from any other communication from
43162 the stub so there is no ambiguity.
43163
43164 After receiving a notification, @value{GDBN} shall acknowledge it by
43165 sending a @var{ack} packet as a regular, synchronous request to the
43166 stub. Such acknowledgment is not required to happen immediately, as
43167 @value{GDBN} is permitted to send other, unrelated packets to the
43168 stub first, which the stub should process normally.
43169
43170 Upon receiving a @var{ack} packet, if the stub has other queued
43171 events to report to @value{GDBN}, it shall respond by sending a
43172 normal @var{event}. @value{GDBN} shall then send another @var{ack}
43173 packet to solicit further responses; again, it is permitted to send
43174 other, unrelated packets as well which the stub should process
43175 normally.
43176
43177 If the stub receives a @var{ack} packet and there are no additional
43178 @var{event} to report, the stub shall return an @samp{OK} response.
43179 At this point, @value{GDBN} has finished processing a notification
43180 and the stub has completed sending any queued events. @value{GDBN}
43181 won't accept any new notifications until the final @samp{OK} is
43182 received . If further notification events occur, the stub shall send
43183 a new notification, @value{GDBN} shall accept the notification, and
43184 the process shall be repeated.
43185
43186 The process of asynchronous notification can be illustrated by the
43187 following example:
43188 @smallexample
43189 <- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
43190 @code{...}
43191 -> @code{vStopped}
43192 <- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
43193 -> @code{vStopped}
43194 <- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
43195 -> @code{vStopped}
43196 <- @code{OK}
43197 @end smallexample
43198
43199 The following notifications are defined:
43200 @multitable @columnfractions 0.12 0.12 0.38 0.38
43201
43202 @item Notification
43203 @tab Ack
43204 @tab Event
43205 @tab Description
43206
43207 @item Stop
43208 @tab vStopped
43209 @tab @var{reply}. The @var{reply} has the form of a stop reply, as
43210 described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
43211 for information on how these notifications are acknowledged by
43212 @value{GDBN}.
43213 @tab Report an asynchronous stop event in non-stop mode.
43214
43215 @end multitable
43216
43217 @node Remote Non-Stop
43218 @section Remote Protocol Support for Non-Stop Mode
43219
43220 @value{GDBN}'s remote protocol supports non-stop debugging of
43221 multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
43222 supports non-stop mode, it should report that to @value{GDBN} by including
43223 @samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
43224
43225 @value{GDBN} typically sends a @samp{QNonStop} packet only when
43226 establishing a new connection with the stub. Entering non-stop mode
43227 does not alter the state of any currently-running threads, but targets
43228 must stop all threads in any already-attached processes when entering
43229 all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
43230 probe the target state after a mode change.
43231
43232 In non-stop mode, when an attached process encounters an event that
43233 would otherwise be reported with a stop reply, it uses the
43234 asynchronous notification mechanism (@pxref{Notification Packets}) to
43235 inform @value{GDBN}. In contrast to all-stop mode, where all threads
43236 in all processes are stopped when a stop reply is sent, in non-stop
43237 mode only the thread reporting the stop event is stopped. That is,
43238 when reporting a @samp{S} or @samp{T} response to indicate completion
43239 of a step operation, hitting a breakpoint, or a fault, only the
43240 affected thread is stopped; any other still-running threads continue
43241 to run. When reporting a @samp{W} or @samp{X} response, all running
43242 threads belonging to other attached processes continue to run.
43243
43244 In non-stop mode, the target shall respond to the @samp{?} packet as
43245 follows. First, any incomplete stop reply notification/@samp{vStopped}
43246 sequence in progress is abandoned. The target must begin a new
43247 sequence reporting stop events for all stopped threads, whether or not
43248 it has previously reported those events to @value{GDBN}. The first
43249 stop reply is sent as a synchronous reply to the @samp{?} packet, and
43250 subsequent stop replies are sent as responses to @samp{vStopped} packets
43251 using the mechanism described above. The target must not send
43252 asynchronous stop reply notifications until the sequence is complete.
43253 If all threads are running when the target receives the @samp{?} packet,
43254 or if the target is not attached to any process, it shall respond
43255 @samp{OK}.
43256
43257 If the stub supports non-stop mode, it should also support the
43258 @samp{swbreak} stop reason if software breakpoints are supported, and
43259 the @samp{hwbreak} stop reason if hardware breakpoints are supported
43260 (@pxref{swbreak stop reason}). This is because given the asynchronous
43261 nature of non-stop mode, between the time a thread hits a breakpoint
43262 and the time the event is finally processed by @value{GDBN}, the
43263 breakpoint may have already been removed from the target. Due to
43264 this, @value{GDBN} needs to be able to tell whether a trap stop was
43265 caused by a delayed breakpoint event, which should be ignored, as
43266 opposed to a random trap signal, which should be reported to the user.
43267 Note the @samp{swbreak} feature implies that the target is responsible
43268 for adjusting the PC when a software breakpoint triggers, if
43269 necessary, such as on the x86 architecture.
43270
43271 @node Packet Acknowledgment
43272 @section Packet Acknowledgment
43273
43274 @cindex acknowledgment, for @value{GDBN} remote
43275 @cindex packet acknowledgment, for @value{GDBN} remote
43276 By default, when either the host or the target machine receives a packet,
43277 the first response expected is an acknowledgment: either @samp{+} (to indicate
43278 the package was received correctly) or @samp{-} (to request retransmission).
43279 This mechanism allows the @value{GDBN} remote protocol to operate over
43280 unreliable transport mechanisms, such as a serial line.
43281
43282 In cases where the transport mechanism is itself reliable (such as a pipe or
43283 TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
43284 It may be desirable to disable them in that case to reduce communication
43285 overhead, or for other reasons. This can be accomplished by means of the
43286 @samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
43287
43288 When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
43289 expect @samp{+}/@samp{-} protocol acknowledgments. The packet
43290 and response format still includes the normal checksum, as described in
43291 @ref{Overview}, but the checksum may be ignored by the receiver.
43292
43293 If the stub supports @samp{QStartNoAckMode} and prefers to operate in
43294 no-acknowledgment mode, it should report that to @value{GDBN}
43295 by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
43296 @pxref{qSupported}.
43297 If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
43298 disabled via the @code{set remote noack-packet off} command
43299 (@pxref{Remote Configuration}),
43300 @value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
43301 Only then may the stub actually turn off packet acknowledgments.
43302 @value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
43303 response, which can be safely ignored by the stub.
43304
43305 Note that @code{set remote noack-packet} command only affects negotiation
43306 between @value{GDBN} and the stub when subsequent connections are made;
43307 it does not affect the protocol acknowledgment state for any current
43308 connection.
43309 Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
43310 new connection is established,
43311 there is also no protocol request to re-enable the acknowledgments
43312 for the current connection, once disabled.
43313
43314 @node Examples
43315 @section Examples
43316
43317 Example sequence of a target being re-started. Notice how the restart
43318 does not get any direct output:
43319
43320 @smallexample
43321 -> @code{R00}
43322 <- @code{+}
43323 @emph{target restarts}
43324 -> @code{?}
43325 <- @code{+}
43326 <- @code{T001:1234123412341234}
43327 -> @code{+}
43328 @end smallexample
43329
43330 Example sequence of a target being stepped by a single instruction:
43331
43332 @smallexample
43333 -> @code{G1445@dots{}}
43334 <- @code{+}
43335 -> @code{s}
43336 <- @code{+}
43337 @emph{time passes}
43338 <- @code{T001:1234123412341234}
43339 -> @code{+}
43340 -> @code{g}
43341 <- @code{+}
43342 <- @code{1455@dots{}}
43343 -> @code{+}
43344 @end smallexample
43345
43346 @node File-I/O Remote Protocol Extension
43347 @section File-I/O Remote Protocol Extension
43348 @cindex File-I/O remote protocol extension
43349
43350 @menu
43351 * File-I/O Overview::
43352 * Protocol Basics::
43353 * The F Request Packet::
43354 * The F Reply Packet::
43355 * The Ctrl-C Message::
43356 * Console I/O::
43357 * List of Supported Calls::
43358 * Protocol-specific Representation of Datatypes::
43359 * Constants::
43360 * File-I/O Examples::
43361 @end menu
43362
43363 @node File-I/O Overview
43364 @subsection File-I/O Overview
43365 @cindex file-i/o overview
43366
43367 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
43368 target to use the host's file system and console I/O to perform various
43369 system calls. System calls on the target system are translated into a
43370 remote protocol packet to the host system, which then performs the needed
43371 actions and returns a response packet to the target system.
43372 This simulates file system operations even on targets that lack file systems.
43373
43374 The protocol is defined to be independent of both the host and target systems.
43375 It uses its own internal representation of datatypes and values. Both
43376 @value{GDBN} and the target's @value{GDBN} stub are responsible for
43377 translating the system-dependent value representations into the internal
43378 protocol representations when data is transmitted.
43379
43380 The communication is synchronous. A system call is possible only when
43381 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
43382 or @samp{s} packets. While @value{GDBN} handles the request for a system call,
43383 the target is stopped to allow deterministic access to the target's
43384 memory. Therefore File-I/O is not interruptible by target signals. On
43385 the other hand, it is possible to interrupt File-I/O by a user interrupt
43386 (@samp{Ctrl-C}) within @value{GDBN}.
43387
43388 The target's request to perform a host system call does not finish
43389 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
43390 after finishing the system call, the target returns to continuing the
43391 previous activity (continue, step). No additional continue or step
43392 request from @value{GDBN} is required.
43393
43394 @smallexample
43395 (@value{GDBP}) continue
43396 <- target requests 'system call X'
43397 target is stopped, @value{GDBN} executes system call
43398 -> @value{GDBN} returns result
43399 ... target continues, @value{GDBN} returns to wait for the target
43400 <- target hits breakpoint and sends a Txx packet
43401 @end smallexample
43402
43403 The protocol only supports I/O on the console and to regular files on
43404 the host file system. Character or block special devices, pipes,
43405 named pipes, sockets or any other communication method on the host
43406 system are not supported by this protocol.
43407
43408 File I/O is not supported in non-stop mode.
43409
43410 @node Protocol Basics
43411 @subsection Protocol Basics
43412 @cindex protocol basics, file-i/o
43413
43414 The File-I/O protocol uses the @code{F} packet as the request as well
43415 as reply packet. Since a File-I/O system call can only occur when
43416 @value{GDBN} is waiting for a response from the continuing or stepping target,
43417 the File-I/O request is a reply that @value{GDBN} has to expect as a result
43418 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
43419 This @code{F} packet contains all information needed to allow @value{GDBN}
43420 to call the appropriate host system call:
43421
43422 @itemize @bullet
43423 @item
43424 A unique identifier for the requested system call.
43425
43426 @item
43427 All parameters to the system call. Pointers are given as addresses
43428 in the target memory address space. Pointers to strings are given as
43429 pointer/length pair. Numerical values are given as they are.
43430 Numerical control flags are given in a protocol-specific representation.
43431
43432 @end itemize
43433
43434 At this point, @value{GDBN} has to perform the following actions.
43435
43436 @itemize @bullet
43437 @item
43438 If the parameters include pointer values to data needed as input to a
43439 system call, @value{GDBN} requests this data from the target with a
43440 standard @code{m} packet request. This additional communication has to be
43441 expected by the target implementation and is handled as any other @code{m}
43442 packet.
43443
43444 @item
43445 @value{GDBN} translates all value from protocol representation to host
43446 representation as needed. Datatypes are coerced into the host types.
43447
43448 @item
43449 @value{GDBN} calls the system call.
43450
43451 @item
43452 It then coerces datatypes back to protocol representation.
43453
43454 @item
43455 If the system call is expected to return data in buffer space specified
43456 by pointer parameters to the call, the data is transmitted to the
43457 target using a @code{M} or @code{X} packet. This packet has to be expected
43458 by the target implementation and is handled as any other @code{M} or @code{X}
43459 packet.
43460
43461 @end itemize
43462
43463 Eventually @value{GDBN} replies with another @code{F} packet which contains all
43464 necessary information for the target to continue. This at least contains
43465
43466 @itemize @bullet
43467 @item
43468 Return value.
43469
43470 @item
43471 @code{errno}, if has been changed by the system call.
43472
43473 @item
43474 ``Ctrl-C'' flag.
43475
43476 @end itemize
43477
43478 After having done the needed type and value coercion, the target continues
43479 the latest continue or step action.
43480
43481 @node The F Request Packet
43482 @subsection The @code{F} Request Packet
43483 @cindex file-i/o request packet
43484 @cindex @code{F} request packet
43485
43486 The @code{F} request packet has the following format:
43487
43488 @table @samp
43489 @item F@var{call-id},@var{parameter@dots{}}
43490
43491 @var{call-id} is the identifier to indicate the host system call to be called.
43492 This is just the name of the function.
43493
43494 @var{parameter@dots{}} are the parameters to the system call.
43495 Parameters are hexadecimal integer values, either the actual values in case
43496 of scalar datatypes, pointers to target buffer space in case of compound
43497 datatypes and unspecified memory areas, or pointer/length pairs in case
43498 of string parameters. These are appended to the @var{call-id} as a
43499 comma-delimited list. All values are transmitted in ASCII
43500 string representation, pointer/length pairs separated by a slash.
43501
43502 @end table
43503
43504
43505
43506 @node The F Reply Packet
43507 @subsection The @code{F} Reply Packet
43508 @cindex file-i/o reply packet
43509 @cindex @code{F} reply packet
43510
43511 The @code{F} reply packet has the following format:
43512
43513 @table @samp
43514
43515 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
43516
43517 @var{retcode} is the return code of the system call as hexadecimal value.
43518
43519 @var{errno} is the @code{errno} set by the call, in protocol-specific
43520 representation.
43521 This parameter can be omitted if the call was successful.
43522
43523 @var{Ctrl-C flag} is only sent if the user requested a break. In this
43524 case, @var{errno} must be sent as well, even if the call was successful.
43525 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
43526
43527 @smallexample
43528 F0,0,C
43529 @end smallexample
43530
43531 @noindent
43532 or, if the call was interrupted before the host call has been performed:
43533
43534 @smallexample
43535 F-1,4,C
43536 @end smallexample
43537
43538 @noindent
43539 assuming 4 is the protocol-specific representation of @code{EINTR}.
43540
43541 @end table
43542
43543
43544 @node The Ctrl-C Message
43545 @subsection The @samp{Ctrl-C} Message
43546 @cindex ctrl-c message, in file-i/o protocol
43547
43548 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
43549 reply packet (@pxref{The F Reply Packet}),
43550 the target should behave as if it had
43551 gotten a break message. The meaning for the target is ``system call
43552 interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
43553 (as with a break message) and return to @value{GDBN} with a @code{T02}
43554 packet.
43555
43556 It's important for the target to know in which
43557 state the system call was interrupted. There are two possible cases:
43558
43559 @itemize @bullet
43560 @item
43561 The system call hasn't been performed on the host yet.
43562
43563 @item
43564 The system call on the host has been finished.
43565
43566 @end itemize
43567
43568 These two states can be distinguished by the target by the value of the
43569 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
43570 call hasn't been performed. This is equivalent to the @code{EINTR} handling
43571 on POSIX systems. In any other case, the target may presume that the
43572 system call has been finished --- successfully or not --- and should behave
43573 as if the break message arrived right after the system call.
43574
43575 @value{GDBN} must behave reliably. If the system call has not been called
43576 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
43577 @code{errno} in the packet. If the system call on the host has been finished
43578 before the user requests a break, the full action must be finished by
43579 @value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
43580 The @code{F} packet may only be sent when either nothing has happened
43581 or the full action has been completed.
43582
43583 @node Console I/O
43584 @subsection Console I/O
43585 @cindex console i/o as part of file-i/o
43586
43587 By default and if not explicitly closed by the target system, the file
43588 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
43589 on the @value{GDBN} console is handled as any other file output operation
43590 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
43591 by @value{GDBN} so that after the target read request from file descriptor
43592 0 all following typing is buffered until either one of the following
43593 conditions is met:
43594
43595 @itemize @bullet
43596 @item
43597 The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
43598 @code{read}
43599 system call is treated as finished.
43600
43601 @item
43602 The user presses @key{RET}. This is treated as end of input with a trailing
43603 newline.
43604
43605 @item
43606 The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
43607 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
43608
43609 @end itemize
43610
43611 If the user has typed more characters than fit in the buffer given to
43612 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
43613 either another @code{read(0, @dots{})} is requested by the target, or debugging
43614 is stopped at the user's request.
43615
43616
43617 @node List of Supported Calls
43618 @subsection List of Supported Calls
43619 @cindex list of supported file-i/o calls
43620
43621 @menu
43622 * open::
43623 * close::
43624 * read::
43625 * write::
43626 * lseek::
43627 * rename::
43628 * unlink::
43629 * stat/fstat::
43630 * gettimeofday::
43631 * isatty::
43632 * system::
43633 @end menu
43634
43635 @node open
43636 @unnumberedsubsubsec open
43637 @cindex open, file-i/o system call
43638
43639 @table @asis
43640 @item Synopsis:
43641 @smallexample
43642 int open(const char *pathname, int flags);
43643 int open(const char *pathname, int flags, mode_t mode);
43644 @end smallexample
43645
43646 @item Request:
43647 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
43648
43649 @noindent
43650 @var{flags} is the bitwise @code{OR} of the following values:
43651
43652 @table @code
43653 @item O_CREAT
43654 If the file does not exist it will be created. The host
43655 rules apply as far as file ownership and time stamps
43656 are concerned.
43657
43658 @item O_EXCL
43659 When used with @code{O_CREAT}, if the file already exists it is
43660 an error and open() fails.
43661
43662 @item O_TRUNC
43663 If the file already exists and the open mode allows
43664 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
43665 truncated to zero length.
43666
43667 @item O_APPEND
43668 The file is opened in append mode.
43669
43670 @item O_RDONLY
43671 The file is opened for reading only.
43672
43673 @item O_WRONLY
43674 The file is opened for writing only.
43675
43676 @item O_RDWR
43677 The file is opened for reading and writing.
43678 @end table
43679
43680 @noindent
43681 Other bits are silently ignored.
43682
43683
43684 @noindent
43685 @var{mode} is the bitwise @code{OR} of the following values:
43686
43687 @table @code
43688 @item S_IRUSR
43689 User has read permission.
43690
43691 @item S_IWUSR
43692 User has write permission.
43693
43694 @item S_IRGRP
43695 Group has read permission.
43696
43697 @item S_IWGRP
43698 Group has write permission.
43699
43700 @item S_IROTH
43701 Others have read permission.
43702
43703 @item S_IWOTH
43704 Others have write permission.
43705 @end table
43706
43707 @noindent
43708 Other bits are silently ignored.
43709
43710
43711 @item Return value:
43712 @code{open} returns the new file descriptor or -1 if an error
43713 occurred.
43714
43715 @item Errors:
43716
43717 @table @code
43718 @item EEXIST
43719 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
43720
43721 @item EISDIR
43722 @var{pathname} refers to a directory.
43723
43724 @item EACCES
43725 The requested access is not allowed.
43726
43727 @item ENAMETOOLONG
43728 @var{pathname} was too long.
43729
43730 @item ENOENT
43731 A directory component in @var{pathname} does not exist.
43732
43733 @item ENODEV
43734 @var{pathname} refers to a device, pipe, named pipe or socket.
43735
43736 @item EROFS
43737 @var{pathname} refers to a file on a read-only filesystem and
43738 write access was requested.
43739
43740 @item EFAULT
43741 @var{pathname} is an invalid pointer value.
43742
43743 @item ENOSPC
43744 No space on device to create the file.
43745
43746 @item EMFILE
43747 The process already has the maximum number of files open.
43748
43749 @item ENFILE
43750 The limit on the total number of files open on the system
43751 has been reached.
43752
43753 @item EINTR
43754 The call was interrupted by the user.
43755 @end table
43756
43757 @end table
43758
43759 @node close
43760 @unnumberedsubsubsec close
43761 @cindex close, file-i/o system call
43762
43763 @table @asis
43764 @item Synopsis:
43765 @smallexample
43766 int close(int fd);
43767 @end smallexample
43768
43769 @item Request:
43770 @samp{Fclose,@var{fd}}
43771
43772 @item Return value:
43773 @code{close} returns zero on success, or -1 if an error occurred.
43774
43775 @item Errors:
43776
43777 @table @code
43778 @item EBADF
43779 @var{fd} isn't a valid open file descriptor.
43780
43781 @item EINTR
43782 The call was interrupted by the user.
43783 @end table
43784
43785 @end table
43786
43787 @node read
43788 @unnumberedsubsubsec read
43789 @cindex read, file-i/o system call
43790
43791 @table @asis
43792 @item Synopsis:
43793 @smallexample
43794 int read(int fd, void *buf, unsigned int count);
43795 @end smallexample
43796
43797 @item Request:
43798 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
43799
43800 @item Return value:
43801 On success, the number of bytes read is returned.
43802 Zero indicates end of file. If count is zero, read
43803 returns zero as well. On error, -1 is returned.
43804
43805 @item Errors:
43806
43807 @table @code
43808 @item EBADF
43809 @var{fd} is not a valid file descriptor or is not open for
43810 reading.
43811
43812 @item EFAULT
43813 @var{bufptr} is an invalid pointer value.
43814
43815 @item EINTR
43816 The call was interrupted by the user.
43817 @end table
43818
43819 @end table
43820
43821 @node write
43822 @unnumberedsubsubsec write
43823 @cindex write, file-i/o system call
43824
43825 @table @asis
43826 @item Synopsis:
43827 @smallexample
43828 int write(int fd, const void *buf, unsigned int count);
43829 @end smallexample
43830
43831 @item Request:
43832 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
43833
43834 @item Return value:
43835 On success, the number of bytes written are returned.
43836 Zero indicates nothing was written. On error, -1
43837 is returned.
43838
43839 @item Errors:
43840
43841 @table @code
43842 @item EBADF
43843 @var{fd} is not a valid file descriptor or is not open for
43844 writing.
43845
43846 @item EFAULT
43847 @var{bufptr} is an invalid pointer value.
43848
43849 @item EFBIG
43850 An attempt was made to write a file that exceeds the
43851 host-specific maximum file size allowed.
43852
43853 @item ENOSPC
43854 No space on device to write the data.
43855
43856 @item EINTR
43857 The call was interrupted by the user.
43858 @end table
43859
43860 @end table
43861
43862 @node lseek
43863 @unnumberedsubsubsec lseek
43864 @cindex lseek, file-i/o system call
43865
43866 @table @asis
43867 @item Synopsis:
43868 @smallexample
43869 long lseek (int fd, long offset, int flag);
43870 @end smallexample
43871
43872 @item Request:
43873 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
43874
43875 @var{flag} is one of:
43876
43877 @table @code
43878 @item SEEK_SET
43879 The offset is set to @var{offset} bytes.
43880
43881 @item SEEK_CUR
43882 The offset is set to its current location plus @var{offset}
43883 bytes.
43884
43885 @item SEEK_END
43886 The offset is set to the size of the file plus @var{offset}
43887 bytes.
43888 @end table
43889
43890 @item Return value:
43891 On success, the resulting unsigned offset in bytes from
43892 the beginning of the file is returned. Otherwise, a
43893 value of -1 is returned.
43894
43895 @item Errors:
43896
43897 @table @code
43898 @item EBADF
43899 @var{fd} is not a valid open file descriptor.
43900
43901 @item ESPIPE
43902 @var{fd} is associated with the @value{GDBN} console.
43903
43904 @item EINVAL
43905 @var{flag} is not a proper value.
43906
43907 @item EINTR
43908 The call was interrupted by the user.
43909 @end table
43910
43911 @end table
43912
43913 @node rename
43914 @unnumberedsubsubsec rename
43915 @cindex rename, file-i/o system call
43916
43917 @table @asis
43918 @item Synopsis:
43919 @smallexample
43920 int rename(const char *oldpath, const char *newpath);
43921 @end smallexample
43922
43923 @item Request:
43924 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
43925
43926 @item Return value:
43927 On success, zero is returned. On error, -1 is returned.
43928
43929 @item Errors:
43930
43931 @table @code
43932 @item EISDIR
43933 @var{newpath} is an existing directory, but @var{oldpath} is not a
43934 directory.
43935
43936 @item EEXIST
43937 @var{newpath} is a non-empty directory.
43938
43939 @item EBUSY
43940 @var{oldpath} or @var{newpath} is a directory that is in use by some
43941 process.
43942
43943 @item EINVAL
43944 An attempt was made to make a directory a subdirectory
43945 of itself.
43946
43947 @item ENOTDIR
43948 A component used as a directory in @var{oldpath} or new
43949 path is not a directory. Or @var{oldpath} is a directory
43950 and @var{newpath} exists but is not a directory.
43951
43952 @item EFAULT
43953 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
43954
43955 @item EACCES
43956 No access to the file or the path of the file.
43957
43958 @item ENAMETOOLONG
43959
43960 @var{oldpath} or @var{newpath} was too long.
43961
43962 @item ENOENT
43963 A directory component in @var{oldpath} or @var{newpath} does not exist.
43964
43965 @item EROFS
43966 The file is on a read-only filesystem.
43967
43968 @item ENOSPC
43969 The device containing the file has no room for the new
43970 directory entry.
43971
43972 @item EINTR
43973 The call was interrupted by the user.
43974 @end table
43975
43976 @end table
43977
43978 @node unlink
43979 @unnumberedsubsubsec unlink
43980 @cindex unlink, file-i/o system call
43981
43982 @table @asis
43983 @item Synopsis:
43984 @smallexample
43985 int unlink(const char *pathname);
43986 @end smallexample
43987
43988 @item Request:
43989 @samp{Funlink,@var{pathnameptr}/@var{len}}
43990
43991 @item Return value:
43992 On success, zero is returned. On error, -1 is returned.
43993
43994 @item Errors:
43995
43996 @table @code
43997 @item EACCES
43998 No access to the file or the path of the file.
43999
44000 @item EPERM
44001 The system does not allow unlinking of directories.
44002
44003 @item EBUSY
44004 The file @var{pathname} cannot be unlinked because it's
44005 being used by another process.
44006
44007 @item EFAULT
44008 @var{pathnameptr} is an invalid pointer value.
44009
44010 @item ENAMETOOLONG
44011 @var{pathname} was too long.
44012
44013 @item ENOENT
44014 A directory component in @var{pathname} does not exist.
44015
44016 @item ENOTDIR
44017 A component of the path is not a directory.
44018
44019 @item EROFS
44020 The file is on a read-only filesystem.
44021
44022 @item EINTR
44023 The call was interrupted by the user.
44024 @end table
44025
44026 @end table
44027
44028 @node stat/fstat
44029 @unnumberedsubsubsec stat/fstat
44030 @cindex fstat, file-i/o system call
44031 @cindex stat, file-i/o system call
44032
44033 @table @asis
44034 @item Synopsis:
44035 @smallexample
44036 int stat(const char *pathname, struct stat *buf);
44037 int fstat(int fd, struct stat *buf);
44038 @end smallexample
44039
44040 @item Request:
44041 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
44042 @samp{Ffstat,@var{fd},@var{bufptr}}
44043
44044 @item Return value:
44045 On success, zero is returned. On error, -1 is returned.
44046
44047 @item Errors:
44048
44049 @table @code
44050 @item EBADF
44051 @var{fd} is not a valid open file.
44052
44053 @item ENOENT
44054 A directory component in @var{pathname} does not exist or the
44055 path is an empty string.
44056
44057 @item ENOTDIR
44058 A component of the path is not a directory.
44059
44060 @item EFAULT
44061 @var{pathnameptr} is an invalid pointer value.
44062
44063 @item EACCES
44064 No access to the file or the path of the file.
44065
44066 @item ENAMETOOLONG
44067 @var{pathname} was too long.
44068
44069 @item EINTR
44070 The call was interrupted by the user.
44071 @end table
44072
44073 @end table
44074
44075 @node gettimeofday
44076 @unnumberedsubsubsec gettimeofday
44077 @cindex gettimeofday, file-i/o system call
44078
44079 @table @asis
44080 @item Synopsis:
44081 @smallexample
44082 int gettimeofday(struct timeval *tv, void *tz);
44083 @end smallexample
44084
44085 @item Request:
44086 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
44087
44088 @item Return value:
44089 On success, 0 is returned, -1 otherwise.
44090
44091 @item Errors:
44092
44093 @table @code
44094 @item EINVAL
44095 @var{tz} is a non-NULL pointer.
44096
44097 @item EFAULT
44098 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
44099 @end table
44100
44101 @end table
44102
44103 @node isatty
44104 @unnumberedsubsubsec isatty
44105 @cindex isatty, file-i/o system call
44106
44107 @table @asis
44108 @item Synopsis:
44109 @smallexample
44110 int isatty(int fd);
44111 @end smallexample
44112
44113 @item Request:
44114 @samp{Fisatty,@var{fd}}
44115
44116 @item Return value:
44117 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
44118
44119 @item Errors:
44120
44121 @table @code
44122 @item EINTR
44123 The call was interrupted by the user.
44124 @end table
44125
44126 @end table
44127
44128 Note that the @code{isatty} call is treated as a special case: it returns
44129 1 to the target if the file descriptor is attached
44130 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
44131 would require implementing @code{ioctl} and would be more complex than
44132 needed.
44133
44134
44135 @node system
44136 @unnumberedsubsubsec system
44137 @cindex system, file-i/o system call
44138
44139 @table @asis
44140 @item Synopsis:
44141 @smallexample
44142 int system(const char *command);
44143 @end smallexample
44144
44145 @item Request:
44146 @samp{Fsystem,@var{commandptr}/@var{len}}
44147
44148 @item Return value:
44149 If @var{len} is zero, the return value indicates whether a shell is
44150 available. A zero return value indicates a shell is not available.
44151 For non-zero @var{len}, the value returned is -1 on error and the
44152 return status of the command otherwise. Only the exit status of the
44153 command is returned, which is extracted from the host's @code{system}
44154 return value by calling @code{WEXITSTATUS(retval)}. In case
44155 @file{/bin/sh} could not be executed, 127 is returned.
44156
44157 @item Errors:
44158
44159 @table @code
44160 @item EINTR
44161 The call was interrupted by the user.
44162 @end table
44163
44164 @end table
44165
44166 @value{GDBN} takes over the full task of calling the necessary host calls
44167 to perform the @code{system} call. The return value of @code{system} on
44168 the host is simplified before it's returned
44169 to the target. Any termination signal information from the child process
44170 is discarded, and the return value consists
44171 entirely of the exit status of the called command.
44172
44173 Due to security concerns, the @code{system} call is by default refused
44174 by @value{GDBN}. The user has to allow this call explicitly with the
44175 @code{set remote system-call-allowed 1} command.
44176
44177 @table @code
44178 @item set remote system-call-allowed
44179 @kindex set remote system-call-allowed
44180 Control whether to allow the @code{system} calls in the File I/O
44181 protocol for the remote target. The default is zero (disabled).
44182
44183 @item show remote system-call-allowed
44184 @kindex show remote system-call-allowed
44185 Show whether the @code{system} calls are allowed in the File I/O
44186 protocol.
44187 @end table
44188
44189 @node Protocol-specific Representation of Datatypes
44190 @subsection Protocol-specific Representation of Datatypes
44191 @cindex protocol-specific representation of datatypes, in file-i/o protocol
44192
44193 @menu
44194 * Integral Datatypes::
44195 * Pointer Values::
44196 * Memory Transfer::
44197 * struct stat::
44198 * struct timeval::
44199 @end menu
44200
44201 @node Integral Datatypes
44202 @unnumberedsubsubsec Integral Datatypes
44203 @cindex integral datatypes, in file-i/o protocol
44204
44205 The integral datatypes used in the system calls are @code{int},
44206 @code{unsigned int}, @code{long}, @code{unsigned long},
44207 @code{mode_t}, and @code{time_t}.
44208
44209 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
44210 implemented as 32 bit values in this protocol.
44211
44212 @code{long} and @code{unsigned long} are implemented as 64 bit types.
44213
44214 @xref{Limits}, for corresponding MIN and MAX values (similar to those
44215 in @file{limits.h}) to allow range checking on host and target.
44216
44217 @code{time_t} datatypes are defined as seconds since the Epoch.
44218
44219 All integral datatypes transferred as part of a memory read or write of a
44220 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
44221 byte order.
44222
44223 @node Pointer Values
44224 @unnumberedsubsubsec Pointer Values
44225 @cindex pointer values, in file-i/o protocol
44226
44227 Pointers to target data are transmitted as they are. An exception
44228 is made for pointers to buffers for which the length isn't
44229 transmitted as part of the function call, namely strings. Strings
44230 are transmitted as a pointer/length pair, both as hex values, e.g.@:
44231
44232 @smallexample
44233 @code{1aaf/12}
44234 @end smallexample
44235
44236 @noindent
44237 which is a pointer to data of length 18 bytes at position 0x1aaf.
44238 The length is defined as the full string length in bytes, including
44239 the trailing null byte. For example, the string @code{"hello world"}
44240 at address 0x123456 is transmitted as
44241
44242 @smallexample
44243 @code{123456/d}
44244 @end smallexample
44245
44246 @node Memory Transfer
44247 @unnumberedsubsubsec Memory Transfer
44248 @cindex memory transfer, in file-i/o protocol
44249
44250 Structured data which is transferred using a memory read or write (for
44251 example, a @code{struct stat}) is expected to be in a protocol-specific format
44252 with all scalar multibyte datatypes being big endian. Translation to
44253 this representation needs to be done both by the target before the @code{F}
44254 packet is sent, and by @value{GDBN} before
44255 it transfers memory to the target. Transferred pointers to structured
44256 data should point to the already-coerced data at any time.
44257
44258
44259 @node struct stat
44260 @unnumberedsubsubsec struct stat
44261 @cindex struct stat, in file-i/o protocol
44262
44263 The buffer of type @code{struct stat} used by the target and @value{GDBN}
44264 is defined as follows:
44265
44266 @smallexample
44267 struct stat @{
44268 unsigned int st_dev; /* device */
44269 unsigned int st_ino; /* inode */
44270 mode_t st_mode; /* protection */
44271 unsigned int st_nlink; /* number of hard links */
44272 unsigned int st_uid; /* user ID of owner */
44273 unsigned int st_gid; /* group ID of owner */
44274 unsigned int st_rdev; /* device type (if inode device) */
44275 unsigned long st_size; /* total size, in bytes */
44276 unsigned long st_blksize; /* blocksize for filesystem I/O */
44277 unsigned long st_blocks; /* number of blocks allocated */
44278 time_t st_atime; /* time of last access */
44279 time_t st_mtime; /* time of last modification */
44280 time_t st_ctime; /* time of last change */
44281 @};
44282 @end smallexample
44283
44284 The integral datatypes conform to the definitions given in the
44285 appropriate section (see @ref{Integral Datatypes}, for details) so this
44286 structure is of size 64 bytes.
44287
44288 The values of several fields have a restricted meaning and/or
44289 range of values.
44290
44291 @table @code
44292
44293 @item st_dev
44294 A value of 0 represents a file, 1 the console.
44295
44296 @item st_ino
44297 No valid meaning for the target. Transmitted unchanged.
44298
44299 @item st_mode
44300 Valid mode bits are described in @ref{Constants}. Any other
44301 bits have currently no meaning for the target.
44302
44303 @item st_uid
44304 @itemx st_gid
44305 @itemx st_rdev
44306 No valid meaning for the target. Transmitted unchanged.
44307
44308 @item st_atime
44309 @itemx st_mtime
44310 @itemx st_ctime
44311 These values have a host and file system dependent
44312 accuracy. Especially on Windows hosts, the file system may not
44313 support exact timing values.
44314 @end table
44315
44316 The target gets a @code{struct stat} of the above representation and is
44317 responsible for coercing it to the target representation before
44318 continuing.
44319
44320 Note that due to size differences between the host, target, and protocol
44321 representations of @code{struct stat} members, these members could eventually
44322 get truncated on the target.
44323
44324 @node struct timeval
44325 @unnumberedsubsubsec struct timeval
44326 @cindex struct timeval, in file-i/o protocol
44327
44328 The buffer of type @code{struct timeval} used by the File-I/O protocol
44329 is defined as follows:
44330
44331 @smallexample
44332 struct timeval @{
44333 time_t tv_sec; /* second */
44334 long tv_usec; /* microsecond */
44335 @};
44336 @end smallexample
44337
44338 The integral datatypes conform to the definitions given in the
44339 appropriate section (see @ref{Integral Datatypes}, for details) so this
44340 structure is of size 8 bytes.
44341
44342 @node Constants
44343 @subsection Constants
44344 @cindex constants, in file-i/o protocol
44345
44346 The following values are used for the constants inside of the
44347 protocol. @value{GDBN} and target are responsible for translating these
44348 values before and after the call as needed.
44349
44350 @menu
44351 * Open Flags::
44352 * mode_t Values::
44353 * Errno Values::
44354 * Lseek Flags::
44355 * Limits::
44356 @end menu
44357
44358 @node Open Flags
44359 @unnumberedsubsubsec Open Flags
44360 @cindex open flags, in file-i/o protocol
44361
44362 All values are given in hexadecimal representation.
44363
44364 @smallexample
44365 O_RDONLY 0x0
44366 O_WRONLY 0x1
44367 O_RDWR 0x2
44368 O_APPEND 0x8
44369 O_CREAT 0x200
44370 O_TRUNC 0x400
44371 O_EXCL 0x800
44372 @end smallexample
44373
44374 @node mode_t Values
44375 @unnumberedsubsubsec mode_t Values
44376 @cindex mode_t values, in file-i/o protocol
44377
44378 All values are given in octal representation.
44379
44380 @smallexample
44381 S_IFREG 0100000
44382 S_IFDIR 040000
44383 S_IRUSR 0400
44384 S_IWUSR 0200
44385 S_IXUSR 0100
44386 S_IRGRP 040
44387 S_IWGRP 020
44388 S_IXGRP 010
44389 S_IROTH 04
44390 S_IWOTH 02
44391 S_IXOTH 01
44392 @end smallexample
44393
44394 @node Errno Values
44395 @unnumberedsubsubsec Errno Values
44396 @cindex errno values, in file-i/o protocol
44397
44398 All values are given in decimal representation.
44399
44400 @smallexample
44401 EPERM 1
44402 ENOENT 2
44403 EINTR 4
44404 EBADF 9
44405 EACCES 13
44406 EFAULT 14
44407 EBUSY 16
44408 EEXIST 17
44409 ENODEV 19
44410 ENOTDIR 20
44411 EISDIR 21
44412 EINVAL 22
44413 ENFILE 23
44414 EMFILE 24
44415 EFBIG 27
44416 ENOSPC 28
44417 ESPIPE 29
44418 EROFS 30
44419 ENAMETOOLONG 91
44420 EUNKNOWN 9999
44421 @end smallexample
44422
44423 @code{EUNKNOWN} is used as a fallback error value if a host system returns
44424 any error value not in the list of supported error numbers.
44425
44426 @node Lseek Flags
44427 @unnumberedsubsubsec Lseek Flags
44428 @cindex lseek flags, in file-i/o protocol
44429
44430 @smallexample
44431 SEEK_SET 0
44432 SEEK_CUR 1
44433 SEEK_END 2
44434 @end smallexample
44435
44436 @node Limits
44437 @unnumberedsubsubsec Limits
44438 @cindex limits, in file-i/o protocol
44439
44440 All values are given in decimal representation.
44441
44442 @smallexample
44443 INT_MIN -2147483648
44444 INT_MAX 2147483647
44445 UINT_MAX 4294967295
44446 LONG_MIN -9223372036854775808
44447 LONG_MAX 9223372036854775807
44448 ULONG_MAX 18446744073709551615
44449 @end smallexample
44450
44451 @node File-I/O Examples
44452 @subsection File-I/O Examples
44453 @cindex file-i/o examples
44454
44455 Example sequence of a write call, file descriptor 3, buffer is at target
44456 address 0x1234, 6 bytes should be written:
44457
44458 @smallexample
44459 <- @code{Fwrite,3,1234,6}
44460 @emph{request memory read from target}
44461 -> @code{m1234,6}
44462 <- XXXXXX
44463 @emph{return "6 bytes written"}
44464 -> @code{F6}
44465 @end smallexample
44466
44467 Example sequence of a read call, file descriptor 3, buffer is at target
44468 address 0x1234, 6 bytes should be read:
44469
44470 @smallexample
44471 <- @code{Fread,3,1234,6}
44472 @emph{request memory write to target}
44473 -> @code{X1234,6:XXXXXX}
44474 @emph{return "6 bytes read"}
44475 -> @code{F6}
44476 @end smallexample
44477
44478 Example sequence of a read call, call fails on the host due to invalid
44479 file descriptor (@code{EBADF}):
44480
44481 @smallexample
44482 <- @code{Fread,3,1234,6}
44483 -> @code{F-1,9}
44484 @end smallexample
44485
44486 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
44487 host is called:
44488
44489 @smallexample
44490 <- @code{Fread,3,1234,6}
44491 -> @code{F-1,4,C}
44492 <- @code{T02}
44493 @end smallexample
44494
44495 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
44496 host is called:
44497
44498 @smallexample
44499 <- @code{Fread,3,1234,6}
44500 -> @code{X1234,6:XXXXXX}
44501 <- @code{T02}
44502 @end smallexample
44503
44504 @node Library List Format
44505 @section Library List Format
44506 @cindex library list format, remote protocol
44507
44508 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
44509 same process as your application to manage libraries. In this case,
44510 @value{GDBN} can use the loader's symbol table and normal memory
44511 operations to maintain a list of shared libraries. On other
44512 platforms, the operating system manages loaded libraries.
44513 @value{GDBN} can not retrieve the list of currently loaded libraries
44514 through memory operations, so it uses the @samp{qXfer:libraries:read}
44515 packet (@pxref{qXfer library list read}) instead. The remote stub
44516 queries the target's operating system and reports which libraries
44517 are loaded.
44518
44519 The @samp{qXfer:libraries:read} packet returns an XML document which
44520 lists loaded libraries and their offsets. Each library has an
44521 associated name and one or more segment or section base addresses,
44522 which report where the library was loaded in memory.
44523
44524 For the common case of libraries that are fully linked binaries, the
44525 library should have a list of segments. If the target supports
44526 dynamic linking of a relocatable object file, its library XML element
44527 should instead include a list of allocated sections. The segment or
44528 section bases are start addresses, not relocation offsets; they do not
44529 depend on the library's link-time base addresses.
44530
44531 @value{GDBN} must be linked with the Expat library to support XML
44532 library lists. @xref{Expat}.
44533
44534 A simple memory map, with one loaded library relocated by a single
44535 offset, looks like this:
44536
44537 @smallexample
44538 <library-list>
44539 <library name="/lib/libc.so.6">
44540 <segment address="0x10000000"/>
44541 </library>
44542 </library-list>
44543 @end smallexample
44544
44545 Another simple memory map, with one loaded library with three
44546 allocated sections (.text, .data, .bss), looks like this:
44547
44548 @smallexample
44549 <library-list>
44550 <library name="sharedlib.o">
44551 <section address="0x10000000"/>
44552 <section address="0x20000000"/>
44553 <section address="0x30000000"/>
44554 </library>
44555 </library-list>
44556 @end smallexample
44557
44558 The format of a library list is described by this DTD:
44559
44560 @smallexample
44561 <!-- library-list: Root element with versioning -->
44562 <!ELEMENT library-list (library)*>
44563 <!ATTLIST library-list version CDATA #FIXED "1.0">
44564 <!ELEMENT library (segment*, section*)>
44565 <!ATTLIST library name CDATA #REQUIRED>
44566 <!ELEMENT segment EMPTY>
44567 <!ATTLIST segment address CDATA #REQUIRED>
44568 <!ELEMENT section EMPTY>
44569 <!ATTLIST section address CDATA #REQUIRED>
44570 @end smallexample
44571
44572 In addition, segments and section descriptors cannot be mixed within a
44573 single library element, and you must supply at least one segment or
44574 section for each library.
44575
44576 @node Library List Format for SVR4 Targets
44577 @section Library List Format for SVR4 Targets
44578 @cindex library list format, remote protocol
44579
44580 On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
44581 (e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
44582 shared libraries. Still a special library list provided by this packet is
44583 more efficient for the @value{GDBN} remote protocol.
44584
44585 The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
44586 loaded libraries and their SVR4 linker parameters. For each library on SVR4
44587 target, the following parameters are reported:
44588
44589 @itemize @minus
44590 @item
44591 @code{name}, the absolute file name from the @code{l_name} field of
44592 @code{struct link_map}.
44593 @item
44594 @code{lm} with address of @code{struct link_map} used for TLS
44595 (Thread Local Storage) access.
44596 @item
44597 @code{l_addr}, the displacement as read from the field @code{l_addr} of
44598 @code{struct link_map}. For prelinked libraries this is not an absolute
44599 memory address. It is a displacement of absolute memory address against
44600 address the file was prelinked to during the library load.
44601 @item
44602 @code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
44603 @end itemize
44604
44605 Additionally the single @code{main-lm} attribute specifies address of
44606 @code{struct link_map} used for the main executable. This parameter is used
44607 for TLS access and its presence is optional.
44608
44609 @value{GDBN} must be linked with the Expat library to support XML
44610 SVR4 library lists. @xref{Expat}.
44611
44612 A simple memory map, with two loaded libraries (which do not use prelink),
44613 looks like this:
44614
44615 @smallexample
44616 <library-list-svr4 version="1.0" main-lm="0xe4f8f8">
44617 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
44618 l_ld="0xe4eefc"/>
44619 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
44620 l_ld="0x152350"/>
44621 </library-list-svr>
44622 @end smallexample
44623
44624 The format of an SVR4 library list is described by this DTD:
44625
44626 @smallexample
44627 <!-- library-list-svr4: Root element with versioning -->
44628 <!ELEMENT library-list-svr4 (library)*>
44629 <!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
44630 <!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
44631 <!ELEMENT library EMPTY>
44632 <!ATTLIST library name CDATA #REQUIRED>
44633 <!ATTLIST library lm CDATA #REQUIRED>
44634 <!ATTLIST library l_addr CDATA #REQUIRED>
44635 <!ATTLIST library l_ld CDATA #REQUIRED>
44636 @end smallexample
44637
44638 @node Memory Map Format
44639 @section Memory Map Format
44640 @cindex memory map format
44641
44642 To be able to write into flash memory, @value{GDBN} needs to obtain a
44643 memory map from the target. This section describes the format of the
44644 memory map.
44645
44646 The memory map is obtained using the @samp{qXfer:memory-map:read}
44647 (@pxref{qXfer memory map read}) packet and is an XML document that
44648 lists memory regions.
44649
44650 @value{GDBN} must be linked with the Expat library to support XML
44651 memory maps. @xref{Expat}.
44652
44653 The top-level structure of the document is shown below:
44654
44655 @smallexample
44656 <?xml version="1.0"?>
44657 <!DOCTYPE memory-map
44658 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44659 "http://sourceware.org/gdb/gdb-memory-map.dtd">
44660 <memory-map>
44661 region...
44662 </memory-map>
44663 @end smallexample
44664
44665 Each region can be either:
44666
44667 @itemize
44668
44669 @item
44670 A region of RAM starting at @var{addr} and extending for @var{length}
44671 bytes from there:
44672
44673 @smallexample
44674 <memory type="ram" start="@var{addr}" length="@var{length}"/>
44675 @end smallexample
44676
44677
44678 @item
44679 A region of read-only memory:
44680
44681 @smallexample
44682 <memory type="rom" start="@var{addr}" length="@var{length}"/>
44683 @end smallexample
44684
44685
44686 @item
44687 A region of flash memory, with erasure blocks @var{blocksize}
44688 bytes in length:
44689
44690 @smallexample
44691 <memory type="flash" start="@var{addr}" length="@var{length}">
44692 <property name="blocksize">@var{blocksize}</property>
44693 </memory>
44694 @end smallexample
44695
44696 @end itemize
44697
44698 Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
44699 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
44700 packets to write to addresses in such ranges.
44701
44702 The formal DTD for memory map format is given below:
44703
44704 @smallexample
44705 <!-- ................................................... -->
44706 <!-- Memory Map XML DTD ................................ -->
44707 <!-- File: memory-map.dtd .............................. -->
44708 <!-- .................................... .............. -->
44709 <!-- memory-map.dtd -->
44710 <!-- memory-map: Root element with versioning -->
44711 <!ELEMENT memory-map (memory)*>
44712 <!ATTLIST memory-map version CDATA #FIXED "1.0.0">
44713 <!ELEMENT memory (property)*>
44714 <!-- memory: Specifies a memory region,
44715 and its type, or device. -->
44716 <!ATTLIST memory type (ram|rom|flash) #REQUIRED
44717 start CDATA #REQUIRED
44718 length CDATA #REQUIRED>
44719 <!-- property: Generic attribute tag -->
44720 <!ELEMENT property (#PCDATA | property)*>
44721 <!ATTLIST property name (blocksize) #REQUIRED>
44722 @end smallexample
44723
44724 @node Thread List Format
44725 @section Thread List Format
44726 @cindex thread list format
44727
44728 To efficiently update the list of threads and their attributes,
44729 @value{GDBN} issues the @samp{qXfer:threads:read} packet
44730 (@pxref{qXfer threads read}) and obtains the XML document with
44731 the following structure:
44732
44733 @smallexample
44734 <?xml version="1.0"?>
44735 <threads>
44736 <thread id="id" core="0" name="name">
44737 ... description ...
44738 </thread>
44739 </threads>
44740 @end smallexample
44741
44742 Each @samp{thread} element must have the @samp{id} attribute that
44743 identifies the thread (@pxref{thread-id syntax}). The
44744 @samp{core} attribute, if present, specifies which processor core
44745 the thread was last executing on. The @samp{name} attribute, if
44746 present, specifies the human-readable name of the thread. The content
44747 of the of @samp{thread} element is interpreted as human-readable
44748 auxiliary information. The @samp{handle} attribute, if present,
44749 is a hex encoded representation of the thread handle.
44750
44751
44752 @node Traceframe Info Format
44753 @section Traceframe Info Format
44754 @cindex traceframe info format
44755
44756 To be able to know which objects in the inferior can be examined when
44757 inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
44758 memory ranges, registers and trace state variables that have been
44759 collected in a traceframe.
44760
44761 This list is obtained using the @samp{qXfer:traceframe-info:read}
44762 (@pxref{qXfer traceframe info read}) packet and is an XML document.
44763
44764 @value{GDBN} must be linked with the Expat library to support XML
44765 traceframe info discovery. @xref{Expat}.
44766
44767 The top-level structure of the document is shown below:
44768
44769 @smallexample
44770 <?xml version="1.0"?>
44771 <!DOCTYPE traceframe-info
44772 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44773 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
44774 <traceframe-info>
44775 block...
44776 </traceframe-info>
44777 @end smallexample
44778
44779 Each traceframe block can be either:
44780
44781 @itemize
44782
44783 @item
44784 A region of collected memory starting at @var{addr} and extending for
44785 @var{length} bytes from there:
44786
44787 @smallexample
44788 <memory start="@var{addr}" length="@var{length}"/>
44789 @end smallexample
44790
44791 @item
44792 A block indicating trace state variable numbered @var{number} has been
44793 collected:
44794
44795 @smallexample
44796 <tvar id="@var{number}"/>
44797 @end smallexample
44798
44799 @end itemize
44800
44801 The formal DTD for the traceframe info format is given below:
44802
44803 @smallexample
44804 <!ELEMENT traceframe-info (memory | tvar)* >
44805 <!ATTLIST traceframe-info version CDATA #FIXED "1.0">
44806
44807 <!ELEMENT memory EMPTY>
44808 <!ATTLIST memory start CDATA #REQUIRED
44809 length CDATA #REQUIRED>
44810 <!ELEMENT tvar>
44811 <!ATTLIST tvar id CDATA #REQUIRED>
44812 @end smallexample
44813
44814 @node Branch Trace Format
44815 @section Branch Trace Format
44816 @cindex branch trace format
44817
44818 In order to display the branch trace of an inferior thread,
44819 @value{GDBN} needs to obtain the list of branches. This list is
44820 represented as list of sequential code blocks that are connected via
44821 branches. The code in each block has been executed sequentially.
44822
44823 This list is obtained using the @samp{qXfer:btrace:read}
44824 (@pxref{qXfer btrace read}) packet and is an XML document.
44825
44826 @value{GDBN} must be linked with the Expat library to support XML
44827 traceframe info discovery. @xref{Expat}.
44828
44829 The top-level structure of the document is shown below:
44830
44831 @smallexample
44832 <?xml version="1.0"?>
44833 <!DOCTYPE btrace
44834 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
44835 "http://sourceware.org/gdb/gdb-btrace.dtd">
44836 <btrace>
44837 block...
44838 </btrace>
44839 @end smallexample
44840
44841 @itemize
44842
44843 @item
44844 A block of sequentially executed instructions starting at @var{begin}
44845 and ending at @var{end}:
44846
44847 @smallexample
44848 <block begin="@var{begin}" end="@var{end}"/>
44849 @end smallexample
44850
44851 @end itemize
44852
44853 The formal DTD for the branch trace format is given below:
44854
44855 @smallexample
44856 <!ELEMENT btrace (block* | pt) >
44857 <!ATTLIST btrace version CDATA #FIXED "1.0">
44858
44859 <!ELEMENT block EMPTY>
44860 <!ATTLIST block begin CDATA #REQUIRED
44861 end CDATA #REQUIRED>
44862
44863 <!ELEMENT pt (pt-config?, raw?)>
44864
44865 <!ELEMENT pt-config (cpu?)>
44866
44867 <!ELEMENT cpu EMPTY>
44868 <!ATTLIST cpu vendor CDATA #REQUIRED
44869 family CDATA #REQUIRED
44870 model CDATA #REQUIRED
44871 stepping CDATA #REQUIRED>
44872
44873 <!ELEMENT raw (#PCDATA)>
44874 @end smallexample
44875
44876 @node Branch Trace Configuration Format
44877 @section Branch Trace Configuration Format
44878 @cindex branch trace configuration format
44879
44880 For each inferior thread, @value{GDBN} can obtain the branch trace
44881 configuration using the @samp{qXfer:btrace-conf:read}
44882 (@pxref{qXfer btrace-conf read}) packet.
44883
44884 The configuration describes the branch trace format and configuration
44885 settings for that format. The following information is described:
44886
44887 @table @code
44888 @item bts
44889 This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
44890 @table @code
44891 @item size
44892 The size of the @acronym{BTS} ring buffer in bytes.
44893 @end table
44894 @item pt
44895 This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
44896 PT}) format.
44897 @table @code
44898 @item size
44899 The size of the @acronym{Intel PT} ring buffer in bytes.
44900 @end table
44901 @end table
44902
44903 @value{GDBN} must be linked with the Expat library to support XML
44904 branch trace configuration discovery. @xref{Expat}.
44905
44906 The formal DTD for the branch trace configuration format is given below:
44907
44908 @smallexample
44909 <!ELEMENT btrace-conf (bts?, pt?)>
44910 <!ATTLIST btrace-conf version CDATA #FIXED "1.0">
44911
44912 <!ELEMENT bts EMPTY>
44913 <!ATTLIST bts size CDATA #IMPLIED>
44914
44915 <!ELEMENT pt EMPTY>
44916 <!ATTLIST pt size CDATA #IMPLIED>
44917 @end smallexample
44918
44919 @include agentexpr.texi
44920
44921 @node Target Descriptions
44922 @appendix Target Descriptions
44923 @cindex target descriptions
44924
44925 One of the challenges of using @value{GDBN} to debug embedded systems
44926 is that there are so many minor variants of each processor
44927 architecture in use. It is common practice for vendors to start with
44928 a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
44929 and then make changes to adapt it to a particular market niche. Some
44930 architectures have hundreds of variants, available from dozens of
44931 vendors. This leads to a number of problems:
44932
44933 @itemize @bullet
44934 @item
44935 With so many different customized processors, it is difficult for
44936 the @value{GDBN} maintainers to keep up with the changes.
44937 @item
44938 Since individual variants may have short lifetimes or limited
44939 audiences, it may not be worthwhile to carry information about every
44940 variant in the @value{GDBN} source tree.
44941 @item
44942 When @value{GDBN} does support the architecture of the embedded system
44943 at hand, the task of finding the correct architecture name to give the
44944 @command{set architecture} command can be error-prone.
44945 @end itemize
44946
44947 To address these problems, the @value{GDBN} remote protocol allows a
44948 target system to not only identify itself to @value{GDBN}, but to
44949 actually describe its own features. This lets @value{GDBN} support
44950 processor variants it has never seen before --- to the extent that the
44951 descriptions are accurate, and that @value{GDBN} understands them.
44952
44953 @value{GDBN} must be linked with the Expat library to support XML
44954 target descriptions. @xref{Expat}.
44955
44956 @menu
44957 * Retrieving Descriptions:: How descriptions are fetched from a target.
44958 * Target Description Format:: The contents of a target description.
44959 * Predefined Target Types:: Standard types available for target
44960 descriptions.
44961 * Enum Target Types:: How to define enum target types.
44962 * Standard Target Features:: Features @value{GDBN} knows about.
44963 @end menu
44964
44965 @node Retrieving Descriptions
44966 @section Retrieving Descriptions
44967
44968 Target descriptions can be read from the target automatically, or
44969 specified by the user manually. The default behavior is to read the
44970 description from the target. @value{GDBN} retrieves it via the remote
44971 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
44972 qXfer}). The @var{annex} in the @samp{qXfer} packet will be
44973 @samp{target.xml}. The contents of the @samp{target.xml} annex are an
44974 XML document, of the form described in @ref{Target Description
44975 Format}.
44976
44977 Alternatively, you can specify a file to read for the target description.
44978 If a file is set, the target will not be queried. The commands to
44979 specify a file are:
44980
44981 @table @code
44982 @cindex set tdesc filename
44983 @item set tdesc filename @var{path}
44984 Read the target description from @var{path}.
44985
44986 @cindex unset tdesc filename
44987 @item unset tdesc filename
44988 Do not read the XML target description from a file. @value{GDBN}
44989 will use the description supplied by the current target.
44990
44991 @cindex show tdesc filename
44992 @item show tdesc filename
44993 Show the filename to read for a target description, if any.
44994 @end table
44995
44996
44997 @node Target Description Format
44998 @section Target Description Format
44999 @cindex target descriptions, XML format
45000
45001 A target description annex is an @uref{http://www.w3.org/XML/, XML}
45002 document which complies with the Document Type Definition provided in
45003 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
45004 means you can use generally available tools like @command{xmllint} to
45005 check that your feature descriptions are well-formed and valid.
45006 However, to help people unfamiliar with XML write descriptions for
45007 their targets, we also describe the grammar here.
45008
45009 Target descriptions can identify the architecture of the remote target
45010 and (for some architectures) provide information about custom register
45011 sets. They can also identify the OS ABI of the remote target.
45012 @value{GDBN} can use this information to autoconfigure for your
45013 target, or to warn you if you connect to an unsupported target.
45014
45015 Here is a simple target description:
45016
45017 @smallexample
45018 <target version="1.0">
45019 <architecture>i386:x86-64</architecture>
45020 </target>
45021 @end smallexample
45022
45023 @noindent
45024 This minimal description only says that the target uses
45025 the x86-64 architecture.
45026
45027 A target description has the following overall form, with [ ] marking
45028 optional elements and @dots{} marking repeatable elements. The elements
45029 are explained further below.
45030
45031 @smallexample
45032 <?xml version="1.0"?>
45033 <!DOCTYPE target SYSTEM "gdb-target.dtd">
45034 <target version="1.0">
45035 @r{[}@var{architecture}@r{]}
45036 @r{[}@var{osabi}@r{]}
45037 @r{[}@var{compatible}@r{]}
45038 @r{[}@var{feature}@dots{}@r{]}
45039 </target>
45040 @end smallexample
45041
45042 @noindent
45043 The description is generally insensitive to whitespace and line
45044 breaks, under the usual common-sense rules. The XML version
45045 declaration and document type declaration can generally be omitted
45046 (@value{GDBN} does not require them), but specifying them may be
45047 useful for XML validation tools. The @samp{version} attribute for
45048 @samp{<target>} may also be omitted, but we recommend
45049 including it; if future versions of @value{GDBN} use an incompatible
45050 revision of @file{gdb-target.dtd}, they will detect and report
45051 the version mismatch.
45052
45053 @subsection Inclusion
45054 @cindex target descriptions, inclusion
45055 @cindex XInclude
45056 @ifnotinfo
45057 @cindex <xi:include>
45058 @end ifnotinfo
45059
45060 It can sometimes be valuable to split a target description up into
45061 several different annexes, either for organizational purposes, or to
45062 share files between different possible target descriptions. You can
45063 divide a description into multiple files by replacing any element of
45064 the target description with an inclusion directive of the form:
45065
45066 @smallexample
45067 <xi:include href="@var{document}"/>
45068 @end smallexample
45069
45070 @noindent
45071 When @value{GDBN} encounters an element of this form, it will retrieve
45072 the named XML @var{document}, and replace the inclusion directive with
45073 the contents of that document. If the current description was read
45074 using @samp{qXfer}, then so will be the included document;
45075 @var{document} will be interpreted as the name of an annex. If the
45076 current description was read from a file, @value{GDBN} will look for
45077 @var{document} as a file in the same directory where it found the
45078 original description.
45079
45080 @subsection Architecture
45081 @cindex <architecture>
45082
45083 An @samp{<architecture>} element has this form:
45084
45085 @smallexample
45086 <architecture>@var{arch}</architecture>
45087 @end smallexample
45088
45089 @var{arch} is one of the architectures from the set accepted by
45090 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
45091
45092 @subsection OS ABI
45093 @cindex @code{<osabi>}
45094
45095 This optional field was introduced in @value{GDBN} version 7.0.
45096 Previous versions of @value{GDBN} ignore it.
45097
45098 An @samp{<osabi>} element has this form:
45099
45100 @smallexample
45101 <osabi>@var{abi-name}</osabi>
45102 @end smallexample
45103
45104 @var{abi-name} is an OS ABI name from the same selection accepted by
45105 @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
45106
45107 @subsection Compatible Architecture
45108 @cindex @code{<compatible>}
45109
45110 This optional field was introduced in @value{GDBN} version 7.0.
45111 Previous versions of @value{GDBN} ignore it.
45112
45113 A @samp{<compatible>} element has this form:
45114
45115 @smallexample
45116 <compatible>@var{arch}</compatible>
45117 @end smallexample
45118
45119 @var{arch} is one of the architectures from the set accepted by
45120 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
45121
45122 A @samp{<compatible>} element is used to specify that the target
45123 is able to run binaries in some other than the main target architecture
45124 given by the @samp{<architecture>} element. For example, on the
45125 Cell Broadband Engine, the main architecture is @code{powerpc:common}
45126 or @code{powerpc:common64}, but the system is able to run binaries
45127 in the @code{spu} architecture as well. The way to describe this
45128 capability with @samp{<compatible>} is as follows:
45129
45130 @smallexample
45131 <architecture>powerpc:common</architecture>
45132 <compatible>spu</compatible>
45133 @end smallexample
45134
45135 @subsection Features
45136 @cindex <feature>
45137
45138 Each @samp{<feature>} describes some logical portion of the target
45139 system. Features are currently used to describe available CPU
45140 registers and the types of their contents. A @samp{<feature>} element
45141 has this form:
45142
45143 @smallexample
45144 <feature name="@var{name}">
45145 @r{[}@var{type}@dots{}@r{]}
45146 @var{reg}@dots{}
45147 </feature>
45148 @end smallexample
45149
45150 @noindent
45151 Each feature's name should be unique within the description. The name
45152 of a feature does not matter unless @value{GDBN} has some special
45153 knowledge of the contents of that feature; if it does, the feature
45154 should have its standard name. @xref{Standard Target Features}.
45155
45156 @subsection Types
45157
45158 Any register's value is a collection of bits which @value{GDBN} must
45159 interpret. The default interpretation is a two's complement integer,
45160 but other types can be requested by name in the register description.
45161 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
45162 Target Types}), and the description can define additional composite
45163 and enum types.
45164
45165 Each type element must have an @samp{id} attribute, which gives
45166 a unique (within the containing @samp{<feature>}) name to the type.
45167 Types must be defined before they are used.
45168
45169 @cindex <vector>
45170 Some targets offer vector registers, which can be treated as arrays
45171 of scalar elements. These types are written as @samp{<vector>} elements,
45172 specifying the array element type, @var{type}, and the number of elements,
45173 @var{count}:
45174
45175 @smallexample
45176 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
45177 @end smallexample
45178
45179 @cindex <union>
45180 If a register's value is usefully viewed in multiple ways, define it
45181 with a union type containing the useful representations. The
45182 @samp{<union>} element contains one or more @samp{<field>} elements,
45183 each of which has a @var{name} and a @var{type}:
45184
45185 @smallexample
45186 <union id="@var{id}">
45187 <field name="@var{name}" type="@var{type}"/>
45188 @dots{}
45189 </union>
45190 @end smallexample
45191
45192 @cindex <struct>
45193 @cindex <flags>
45194 If a register's value is composed from several separate values, define
45195 it with either a structure type or a flags type.
45196 A flags type may only contain bitfields.
45197 A structure type may either contain only bitfields or contain no bitfields.
45198 If the value contains only bitfields, its total size in bytes must be
45199 specified.
45200
45201 Non-bitfield values have a @var{name} and @var{type}.
45202
45203 @smallexample
45204 <struct id="@var{id}">
45205 <field name="@var{name}" type="@var{type}"/>
45206 @dots{}
45207 </struct>
45208 @end smallexample
45209
45210 Both @var{name} and @var{type} values are required.
45211 No implicit padding is added.
45212
45213 Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
45214
45215 @smallexample
45216 <struct id="@var{id}" size="@var{size}">
45217 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
45218 @dots{}
45219 </struct>
45220 @end smallexample
45221
45222 @smallexample
45223 <flags id="@var{id}" size="@var{size}">
45224 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
45225 @dots{}
45226 </flags>
45227 @end smallexample
45228
45229 The @var{name} value is required.
45230 Bitfield values may be named with the empty string, @samp{""},
45231 in which case the field is ``filler'' and its value is not printed.
45232 Not all bits need to be specified, so ``filler'' fields are optional.
45233
45234 The @var{start} and @var{end} values are required, and @var{type}
45235 is optional.
45236 The field's @var{start} must be less than or equal to its @var{end},
45237 and zero represents the least significant bit.
45238
45239 The default value of @var{type} is @code{bool} for single bit fields,
45240 and an unsigned integer otherwise.
45241
45242 Which to choose? Structures or flags?
45243
45244 Registers defined with @samp{flags} have these advantages over
45245 defining them with @samp{struct}:
45246
45247 @itemize @bullet
45248 @item
45249 Arithmetic may be performed on them as if they were integers.
45250 @item
45251 They are printed in a more readable fashion.
45252 @end itemize
45253
45254 Registers defined with @samp{struct} have one advantage over
45255 defining them with @samp{flags}:
45256
45257 @itemize @bullet
45258 @item
45259 One can fetch individual fields like in @samp{C}.
45260
45261 @smallexample
45262 (gdb) print $my_struct_reg.field3
45263 $1 = 42
45264 @end smallexample
45265
45266 @end itemize
45267
45268 @subsection Registers
45269 @cindex <reg>
45270
45271 Each register is represented as an element with this form:
45272
45273 @smallexample
45274 <reg name="@var{name}"
45275 bitsize="@var{size}"
45276 @r{[}regnum="@var{num}"@r{]}
45277 @r{[}save-restore="@var{save-restore}"@r{]}
45278 @r{[}type="@var{type}"@r{]}
45279 @r{[}group="@var{group}"@r{]}/>
45280 @end smallexample
45281
45282 @noindent
45283 The components are as follows:
45284
45285 @table @var
45286
45287 @item name
45288 The register's name; it must be unique within the target description.
45289
45290 @item bitsize
45291 The register's size, in bits.
45292
45293 @item regnum
45294 The register's number. If omitted, a register's number is one greater
45295 than that of the previous register (either in the current feature or in
45296 a preceding feature); the first register in the target description
45297 defaults to zero. This register number is used to read or write
45298 the register; e.g.@: it is used in the remote @code{p} and @code{P}
45299 packets, and registers appear in the @code{g} and @code{G} packets
45300 in order of increasing register number.
45301
45302 @item save-restore
45303 Whether the register should be preserved across inferior function
45304 calls; this must be either @code{yes} or @code{no}. The default is
45305 @code{yes}, which is appropriate for most registers except for
45306 some system control registers; this is not related to the target's
45307 ABI.
45308
45309 @item type
45310 The type of the register. It may be a predefined type, a type
45311 defined in the current feature, or one of the special types @code{int}
45312 and @code{float}. @code{int} is an integer type of the correct size
45313 for @var{bitsize}, and @code{float} is a floating point type (in the
45314 architecture's normal floating point format) of the correct size for
45315 @var{bitsize}. The default is @code{int}.
45316
45317 @item group
45318 The register group to which this register belongs. It can be one of the
45319 standard register groups @code{general}, @code{float}, @code{vector} or an
45320 arbitrary string. Group names should be limited to alphanumeric characters.
45321 If a group name is made up of multiple words the words may be separated by
45322 hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
45323 @var{group} is specified, @value{GDBN} will not display the register in
45324 @code{info registers}.
45325
45326 @end table
45327
45328 @node Predefined Target Types
45329 @section Predefined Target Types
45330 @cindex target descriptions, predefined types
45331
45332 Type definitions in the self-description can build up composite types
45333 from basic building blocks, but can not define fundamental types. Instead,
45334 standard identifiers are provided by @value{GDBN} for the fundamental
45335 types. The currently supported types are:
45336
45337 @table @code
45338
45339 @item bool
45340 Boolean type, occupying a single bit.
45341
45342 @item int8
45343 @itemx int16
45344 @itemx int24
45345 @itemx int32
45346 @itemx int64
45347 @itemx int128
45348 Signed integer types holding the specified number of bits.
45349
45350 @item uint8
45351 @itemx uint16
45352 @itemx uint24
45353 @itemx uint32
45354 @itemx uint64
45355 @itemx uint128
45356 Unsigned integer types holding the specified number of bits.
45357
45358 @item code_ptr
45359 @itemx data_ptr
45360 Pointers to unspecified code and data. The program counter and
45361 any dedicated return address register may be marked as code
45362 pointers; printing a code pointer converts it into a symbolic
45363 address. The stack pointer and any dedicated address registers
45364 may be marked as data pointers.
45365
45366 @item ieee_single
45367 Single precision IEEE floating point.
45368
45369 @item ieee_double
45370 Double precision IEEE floating point.
45371
45372 @item arm_fpa_ext
45373 The 12-byte extended precision format used by ARM FPA registers.
45374
45375 @item i387_ext
45376 The 10-byte extended precision format used by x87 registers.
45377
45378 @item i386_eflags
45379 32bit @sc{eflags} register used by x86.
45380
45381 @item i386_mxcsr
45382 32bit @sc{mxcsr} register used by x86.
45383
45384 @end table
45385
45386 @node Enum Target Types
45387 @section Enum Target Types
45388 @cindex target descriptions, enum types
45389
45390 Enum target types are useful in @samp{struct} and @samp{flags}
45391 register descriptions. @xref{Target Description Format}.
45392
45393 Enum types have a name, size and a list of name/value pairs.
45394
45395 @smallexample
45396 <enum id="@var{id}" size="@var{size}">
45397 <evalue name="@var{name}" value="@var{value}"/>
45398 @dots{}
45399 </enum>
45400 @end smallexample
45401
45402 Enums must be defined before they are used.
45403
45404 @smallexample
45405 <enum id="levels_type" size="4">
45406 <evalue name="low" value="0"/>
45407 <evalue name="high" value="1"/>
45408 </enum>
45409 <flags id="flags_type" size="4">
45410 <field name="X" start="0"/>
45411 <field name="LEVEL" start="1" end="1" type="levels_type"/>
45412 </flags>
45413 <reg name="flags" bitsize="32" type="flags_type"/>
45414 @end smallexample
45415
45416 Given that description, a value of 3 for the @samp{flags} register
45417 would be printed as:
45418
45419 @smallexample
45420 (gdb) info register flags
45421 flags 0x3 [ X LEVEL=high ]
45422 @end smallexample
45423
45424 @node Standard Target Features
45425 @section Standard Target Features
45426 @cindex target descriptions, standard features
45427
45428 A target description must contain either no registers or all the
45429 target's registers. If the description contains no registers, then
45430 @value{GDBN} will assume a default register layout, selected based on
45431 the architecture. If the description contains any registers, the
45432 default layout will not be used; the standard registers must be
45433 described in the target description, in such a way that @value{GDBN}
45434 can recognize them.
45435
45436 This is accomplished by giving specific names to feature elements
45437 which contain standard registers. @value{GDBN} will look for features
45438 with those names and verify that they contain the expected registers;
45439 if any known feature is missing required registers, or if any required
45440 feature is missing, @value{GDBN} will reject the target
45441 description. You can add additional registers to any of the
45442 standard features --- @value{GDBN} will display them just as if
45443 they were added to an unrecognized feature.
45444
45445 This section lists the known features and their expected contents.
45446 Sample XML documents for these features are included in the
45447 @value{GDBN} source tree, in the directory @file{gdb/features}.
45448
45449 Names recognized by @value{GDBN} should include the name of the
45450 company or organization which selected the name, and the overall
45451 architecture to which the feature applies; so e.g.@: the feature
45452 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
45453
45454 The names of registers are not case sensitive for the purpose
45455 of recognizing standard features, but @value{GDBN} will only display
45456 registers using the capitalization used in the description.
45457
45458 @menu
45459 * AArch64 Features::
45460 * ARC Features::
45461 * ARM Features::
45462 * i386 Features::
45463 * MicroBlaze Features::
45464 * MIPS Features::
45465 * M68K Features::
45466 * NDS32 Features::
45467 * Nios II Features::
45468 * OpenRISC 1000 Features::
45469 * PowerPC Features::
45470 * RISC-V Features::
45471 * RX Features::
45472 * S/390 and System z Features::
45473 * Sparc Features::
45474 * TIC6x Features::
45475 @end menu
45476
45477
45478 @node AArch64 Features
45479 @subsection AArch64 Features
45480 @cindex target descriptions, AArch64 features
45481
45482 The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
45483 targets. It should contain registers @samp{x0} through @samp{x30},
45484 @samp{sp}, @samp{pc}, and @samp{cpsr}.
45485
45486 The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
45487 it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
45488 and @samp{fpcr}.
45489
45490 The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
45491 it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
45492 through @samp{p15}, @samp{ffr} and @samp{vg}.
45493
45494 The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
45495 it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
45496
45497 @node ARC Features
45498 @subsection ARC Features
45499 @cindex target descriptions, ARC Features
45500
45501 ARC processors are so configurable that even core registers and their numbers
45502 are not predetermined completely. Moreover, @emph{flags} and @emph{PC}
45503 registers, which are important to @value{GDBN}, are not ``core'' registers in
45504 ARC. Therefore, there are two features that their presence is mandatory:
45505 @samp{org.gnu.gdb.arc.core} and @samp{org.gnu.gdb.arc.aux}.
45506
45507 The @samp{org.gnu.gdb.arc.core} feature is required for all targets. It must
45508 contain registers:
45509
45510 @itemize @minus
45511 @item
45512 @samp{r0} through @samp{r25} for normal register file targets.
45513 @item
45514 @samp{r0} through @samp{r3}, and @samp{r10} through @samp{r15} for reduced
45515 register file targets.
45516 @item
45517 @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}@footnote{Not necessary for ARCv1.},
45518 @samp{blink}, @samp{lp_count}, @samp{pcl}.
45519 @end itemize
45520
45521 In case of an ARCompact target (ARCv1 ISA), the @samp{org.gnu.gdb.arc.core}
45522 feature may contain registers @samp{ilink1} and @samp{ilink2}. While in case
45523 of ARC EM and ARC HS targets (ARCv2 ISA), register @samp{ilink} may be present.
45524 The difference between ARCv1 and ARCv2 is the naming of registers @emph{29th}
45525 and @emph{30th}. They are called @samp{ilink1} and @samp{ilink2} for ARCv1 and
45526 are optional. For ARCv2, they are called @samp{ilink} and @samp{r30} and only
45527 @samp{ilink} is optional. The optionality of @samp{ilink*} registers is
45528 because of their inaccessibility during user space debugging sessions.
45529
45530 Extension core registers @samp{r32} through @samp{r59} are optional and their
45531 existence depends on the configuration. When debugging GNU/Linux applications,
45532 i.e.@: user space debugging, these core registers are not available.
45533
45534 The @samp{org.gnu.gdb.arc.aux} feature is required for all ARC targets. Here
45535 is the list of registers pertinent to this feature:
45536
45537 @itemize @minus
45538 @item
45539 mandatory: @samp{pc} and @samp{status32}.
45540 @item
45541 optional: @samp{lp_start}, @samp{lp_end}, and @samp{bta}.
45542 @end itemize
45543
45544 @node ARM Features
45545 @subsection ARM Features
45546 @cindex target descriptions, ARM features
45547
45548 The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
45549 ARM targets.
45550 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
45551 @samp{lr}, @samp{pc}, and @samp{cpsr}.
45552
45553 For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
45554 feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
45555 registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
45556 and @samp{xpsr}.
45557
45558 The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
45559 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
45560
45561 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
45562 it should contain at least registers @samp{wR0} through @samp{wR15} and
45563 @samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
45564 @samp{wCSSF}, and @samp{wCASF} registers are optional.
45565
45566 The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
45567 should contain at least registers @samp{d0} through @samp{d15}. If
45568 they are present, @samp{d16} through @samp{d31} should also be included.
45569 @value{GDBN} will synthesize the single-precision registers from
45570 halves of the double-precision registers.
45571
45572 The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
45573 need to contain registers; it instructs @value{GDBN} to display the
45574 VFP double-precision registers as vectors and to synthesize the
45575 quad-precision registers from pairs of double-precision registers.
45576 If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
45577 be present and include 32 double-precision registers.
45578
45579 @node i386 Features
45580 @subsection i386 Features
45581 @cindex target descriptions, i386 features
45582
45583 The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
45584 targets. It should describe the following registers:
45585
45586 @itemize @minus
45587 @item
45588 @samp{eax} through @samp{edi} plus @samp{eip} for i386
45589 @item
45590 @samp{rax} through @samp{r15} plus @samp{rip} for amd64
45591 @item
45592 @samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
45593 @samp{fs}, @samp{gs}
45594 @item
45595 @samp{st0} through @samp{st7}
45596 @item
45597 @samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
45598 @samp{foseg}, @samp{fooff} and @samp{fop}
45599 @end itemize
45600
45601 The register sets may be different, depending on the target.
45602
45603 The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
45604 describe registers:
45605
45606 @itemize @minus
45607 @item
45608 @samp{xmm0} through @samp{xmm7} for i386
45609 @item
45610 @samp{xmm0} through @samp{xmm15} for amd64
45611 @item
45612 @samp{mxcsr}
45613 @end itemize
45614
45615 The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
45616 @samp{org.gnu.gdb.i386.sse} feature. It should
45617 describe the upper 128 bits of @sc{ymm} registers:
45618
45619 @itemize @minus
45620 @item
45621 @samp{ymm0h} through @samp{ymm7h} for i386
45622 @item
45623 @samp{ymm0h} through @samp{ymm15h} for amd64
45624 @end itemize
45625
45626 The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
45627 Memory Protection Extension (MPX). It should describe the following registers:
45628
45629 @itemize @minus
45630 @item
45631 @samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
45632 @item
45633 @samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
45634 @end itemize
45635
45636 The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
45637 describe a single register, @samp{orig_eax}.
45638
45639 The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
45640 describe two system registers: @samp{fs_base} and @samp{gs_base}.
45641
45642 The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
45643 @samp{org.gnu.gdb.i386.avx} feature. It should
45644 describe additional @sc{xmm} registers:
45645
45646 @itemize @minus
45647 @item
45648 @samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
45649 @end itemize
45650
45651 It should describe the upper 128 bits of additional @sc{ymm} registers:
45652
45653 @itemize @minus
45654 @item
45655 @samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
45656 @end itemize
45657
45658 It should
45659 describe the upper 256 bits of @sc{zmm} registers:
45660
45661 @itemize @minus
45662 @item
45663 @samp{zmm0h} through @samp{zmm7h} for i386.
45664 @item
45665 @samp{zmm0h} through @samp{zmm15h} for amd64.
45666 @end itemize
45667
45668 It should
45669 describe the additional @sc{zmm} registers:
45670
45671 @itemize @minus
45672 @item
45673 @samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
45674 @end itemize
45675
45676 The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
45677 describe a single register, @samp{pkru}. It is a 32-bit register
45678 valid for i386 and amd64.
45679
45680 @node MicroBlaze Features
45681 @subsection MicroBlaze Features
45682 @cindex target descriptions, MicroBlaze features
45683
45684 The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
45685 targets. It should contain registers @samp{r0} through @samp{r31},
45686 @samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
45687 @samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
45688 @samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
45689
45690 The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
45691 If present, it should contain registers @samp{rshr} and @samp{rslr}
45692
45693 @node MIPS Features
45694 @subsection @acronym{MIPS} Features
45695 @cindex target descriptions, @acronym{MIPS} features
45696
45697 The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
45698 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
45699 @samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
45700 on the target.
45701
45702 The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
45703 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
45704 registers. They may be 32-bit or 64-bit depending on the target.
45705
45706 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
45707 it may be optional in a future version of @value{GDBN}. It should
45708 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
45709 @samp{fir}. They may be 32-bit or 64-bit depending on the target.
45710
45711 The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
45712 contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
45713 @samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
45714 be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
45715
45716 The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
45717 contain a single register, @samp{restart}, which is used by the
45718 Linux kernel to control restartable syscalls.
45719
45720 @node M68K Features
45721 @subsection M68K Features
45722 @cindex target descriptions, M68K features
45723
45724 @table @code
45725 @item @samp{org.gnu.gdb.m68k.core}
45726 @itemx @samp{org.gnu.gdb.coldfire.core}
45727 @itemx @samp{org.gnu.gdb.fido.core}
45728 One of those features must be always present.
45729 The feature that is present determines which flavor of m68k is
45730 used. The feature that is present should contain registers
45731 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
45732 @samp{sp}, @samp{ps} and @samp{pc}.
45733
45734 @item @samp{org.gnu.gdb.coldfire.fp}
45735 This feature is optional. If present, it should contain registers
45736 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
45737 @samp{fpiaddr}.
45738
45739 Note that, despite the fact that this feature's name says
45740 @samp{coldfire}, it is used to describe any floating point registers.
45741 The size of the registers must match the main m68k flavor; so, for
45742 example, if the primary feature is reported as @samp{coldfire}, then
45743 64-bit floating point registers are required.
45744 @end table
45745
45746 @node NDS32 Features
45747 @subsection NDS32 Features
45748 @cindex target descriptions, NDS32 features
45749
45750 The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
45751 targets. It should contain at least registers @samp{r0} through
45752 @samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
45753 and @samp{pc}.
45754
45755 The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
45756 it should contain 64-bit double-precision floating-point registers
45757 @samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
45758 @samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
45759
45760 @emph{Note:} The first sixteen 64-bit double-precision floating-point
45761 registers are overlapped with the thirty-two 32-bit single-precision
45762 floating-point registers. The 32-bit single-precision registers, if
45763 not being listed explicitly, will be synthesized from halves of the
45764 overlapping 64-bit double-precision registers. Listing 32-bit
45765 single-precision registers explicitly is deprecated, and the
45766 support to it could be totally removed some day.
45767
45768 @node Nios II Features
45769 @subsection Nios II Features
45770 @cindex target descriptions, Nios II features
45771
45772 The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
45773 targets. It should contain the 32 core registers (@samp{zero},
45774 @samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
45775 @samp{pc}, and the 16 control registers (@samp{status} through
45776 @samp{mpuacc}).
45777
45778 @node OpenRISC 1000 Features
45779 @subsection Openrisc 1000 Features
45780 @cindex target descriptions, OpenRISC 1000 features
45781
45782 The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
45783 targets. It should contain the 32 general purpose registers (@samp{r0}
45784 through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
45785
45786 @node PowerPC Features
45787 @subsection PowerPC Features
45788 @cindex target descriptions, PowerPC features
45789
45790 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
45791 targets. It should contain registers @samp{r0} through @samp{r31},
45792 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
45793 @samp{xer}. They may be 32-bit or 64-bit depending on the target.
45794
45795 The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
45796 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
45797
45798 The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
45799 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
45800 @samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
45801 through @samp{v31} as aliases for the corresponding @samp{vrX}
45802 registers.
45803
45804 The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
45805 contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
45806 combine these registers with the floating point registers (@samp{f0}
45807 through @samp{f31}) and the altivec registers (@samp{vr0} through
45808 @samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
45809 @samp{vs63}, the set of vector-scalar registers for POWER7.
45810 Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
45811 @samp{org.gnu.gdb.power.altivec}.
45812
45813 The @samp{org.gnu.gdb.power.spe} feature is optional. It should
45814 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
45815 @samp{spefscr}. SPE targets should provide 32-bit registers in
45816 @samp{org.gnu.gdb.power.core} and provide the upper halves in
45817 @samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
45818 these to present registers @samp{ev0} through @samp{ev31} to the
45819 user.
45820
45821 The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
45822 contain the 64-bit register @samp{ppr}.
45823
45824 The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
45825 contain the 64-bit register @samp{dscr}.
45826
45827 The @samp{org.gnu.gdb.power.tar} feature is optional. It should
45828 contain the 64-bit register @samp{tar}.
45829
45830 The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
45831 contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
45832 64-bit wide.
45833
45834 The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
45835 contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
45836 and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
45837 server PMU registers provided by @sc{gnu}/Linux.
45838
45839 The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
45840 contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
45841 64-bit wide.
45842
45843 The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
45844 contain the checkpointed general-purpose registers @samp{cr0} through
45845 @samp{cr31}, as well as the checkpointed registers @samp{clr} and
45846 @samp{cctr}. These registers may all be either 32-bit or 64-bit
45847 depending on the target. It should also contain the checkpointed
45848 registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
45849 wide.
45850
45851 The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
45852 contain the checkpointed 64-bit floating-point registers @samp{cf0}
45853 through @samp{cf31}, as well as the checkpointed 64-bit register
45854 @samp{cfpscr}.
45855
45856 The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
45857 should contain the checkpointed altivec registers @samp{cvr0} through
45858 @samp{cvr31}, all 128-bit wide. It should also contain the
45859 checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
45860 wide.
45861
45862 The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
45863 contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
45864 will combine these registers with the checkpointed floating point
45865 registers (@samp{cf0} through @samp{cf31}) and the checkpointed
45866 altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
45867 128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
45868 @samp{cvs63}. Therefore, this feature requires both
45869 @samp{org.gnu.gdb.power.htm.altivec} and
45870 @samp{org.gnu.gdb.power.htm.fpu}.
45871
45872 The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
45873 contain the 64-bit checkpointed register @samp{cppr}.
45874
45875 The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
45876 contain the 64-bit checkpointed register @samp{cdscr}.
45877
45878 The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
45879 contain the 64-bit checkpointed register @samp{ctar}.
45880
45881
45882 @node RISC-V Features
45883 @subsection RISC-V Features
45884 @cindex target descriptions, RISC-V Features
45885
45886 The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
45887 targets. It should contain the registers @samp{x0} through
45888 @samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
45889 @samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
45890 etc).
45891
45892 The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
45893 should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
45894 @samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
45895 architectural register names, or the ABI names can be used.
45896
45897 The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
45898 it should contain registers that are not backed by real registers on
45899 the target, but are instead virtual, where the register value is
45900 derived from other target state. In many ways these are like
45901 @value{GDBN}s pseudo-registers, except implemented by the target.
45902 Currently the only register expected in this set is the one byte
45903 @samp{priv} register that contains the target's privilege level in the
45904 least significant two bits.
45905
45906 The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
45907 should contain all of the target's standard CSRs. Standard CSRs are
45908 those defined in the RISC-V specification documents. There is some
45909 overlap between this feature and the fpu feature; the @samp{fflags},
45910 @samp{frm}, and @samp{fcsr} registers could be in either feature. The
45911 expectation is that these registers will be in the fpu feature if the
45912 target has floating point hardware, but can be moved into the csr
45913 feature if the target has the floating point control registers, but no
45914 other floating point hardware.
45915
45916 @node RX Features
45917 @subsection RX Features
45918 @cindex target descriptions, RX Features
45919
45920 The @samp{org.gnu.gdb.rx.core} feature is required for RX
45921 targets. It should contain the registers @samp{r0} through
45922 @samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
45923 @samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
45924
45925 @node S/390 and System z Features
45926 @subsection S/390 and System z Features
45927 @cindex target descriptions, S/390 features
45928 @cindex target descriptions, System z features
45929
45930 The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
45931 System z targets. It should contain the PSW and the 16 general
45932 registers. In particular, System z targets should provide the 64-bit
45933 registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
45934 S/390 targets should provide the 32-bit versions of these registers.
45935 A System z target that runs in 31-bit addressing mode should provide
45936 32-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
45937 register's upper halves @samp{r0h} through @samp{r15h}, and their
45938 lower halves @samp{r0l} through @samp{r15l}.
45939
45940 The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
45941 contain the 64-bit registers @samp{f0} through @samp{f15}, and
45942 @samp{fpc}.
45943
45944 The @samp{org.gnu.gdb.s390.acr} feature is required. It should
45945 contain the 32-bit registers @samp{acr0} through @samp{acr15}.
45946
45947 The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
45948 contain the register @samp{orig_r2}, which is 64-bit wide on System z
45949 targets and 32-bit otherwise. In addition, the feature may contain
45950 the @samp{last_break} register, whose width depends on the addressing
45951 mode, as well as the @samp{system_call} register, which is always
45952 32-bit wide.
45953
45954 The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
45955 contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
45956 @samp{atia}, and @samp{tr0} through @samp{tr15}.
45957
45958 The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
45959 64-bit wide registers @samp{v0l} through @samp{v15l}, which will be
45960 combined by @value{GDBN} with the floating point registers @samp{f0}
45961 through @samp{f15} to present the 128-bit wide vector registers
45962 @samp{v0} through @samp{v15}. In addition, this feature should
45963 contain the 128-bit wide vector registers @samp{v16} through
45964 @samp{v31}.
45965
45966 The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
45967 the 64-bit wide guarded-storage-control registers @samp{gsd},
45968 @samp{gssm}, and @samp{gsepla}.
45969
45970 The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
45971 the 64-bit wide guarded-storage broadcast control registers
45972 @samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
45973
45974 @node Sparc Features
45975 @subsection Sparc Features
45976 @cindex target descriptions, sparc32 features
45977 @cindex target descriptions, sparc64 features
45978 The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
45979 targets. It should describe the following registers:
45980
45981 @itemize @minus
45982 @item
45983 @samp{g0} through @samp{g7}
45984 @item
45985 @samp{o0} through @samp{o7}
45986 @item
45987 @samp{l0} through @samp{l7}
45988 @item
45989 @samp{i0} through @samp{i7}
45990 @end itemize
45991
45992 They may be 32-bit or 64-bit depending on the target.
45993
45994 Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
45995 targets. It should describe the following registers:
45996
45997 @itemize @minus
45998 @item
45999 @samp{f0} through @samp{f31}
46000 @item
46001 @samp{f32} through @samp{f62} for sparc64
46002 @end itemize
46003
46004 The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
46005 targets. It should describe the following registers:
46006
46007 @itemize @minus
46008 @item
46009 @samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
46010 @samp{fsr}, and @samp{csr} for sparc32
46011 @item
46012 @samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
46013 for sparc64
46014 @end itemize
46015
46016 @node TIC6x Features
46017 @subsection TMS320C6x Features
46018 @cindex target descriptions, TIC6x features
46019 @cindex target descriptions, TMS320C6x features
46020 The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
46021 targets. It should contain registers @samp{A0} through @samp{A15},
46022 registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
46023
46024 The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
46025 contain registers @samp{A16} through @samp{A31} and @samp{B16}
46026 through @samp{B31}.
46027
46028 The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
46029 contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
46030
46031 @node Operating System Information
46032 @appendix Operating System Information
46033 @cindex operating system information
46034
46035 @menu
46036 * Process list::
46037 @end menu
46038
46039 Users of @value{GDBN} often wish to obtain information about the state of
46040 the operating system running on the target---for example the list of
46041 processes, or the list of open files. This section describes the
46042 mechanism that makes it possible. This mechanism is similar to the
46043 target features mechanism (@pxref{Target Descriptions}), but focuses
46044 on a different aspect of target.
46045
46046 Operating system information is retrieved from the target via the
46047 remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
46048 read}). The object name in the request should be @samp{osdata}, and
46049 the @var{annex} identifies the data to be fetched.
46050
46051 @node Process list
46052 @appendixsection Process list
46053 @cindex operating system information, process list
46054
46055 When requesting the process list, the @var{annex} field in the
46056 @samp{qXfer} request should be @samp{processes}. The returned data is
46057 an XML document. The formal syntax of this document is defined in
46058 @file{gdb/features/osdata.dtd}.
46059
46060 An example document is:
46061
46062 @smallexample
46063 <?xml version="1.0"?>
46064 <!DOCTYPE target SYSTEM "osdata.dtd">
46065 <osdata type="processes">
46066 <item>
46067 <column name="pid">1</column>
46068 <column name="user">root</column>
46069 <column name="command">/sbin/init</column>
46070 <column name="cores">1,2,3</column>
46071 </item>
46072 </osdata>
46073 @end smallexample
46074
46075 Each item should include a column whose name is @samp{pid}. The value
46076 of that column should identify the process on the target. The
46077 @samp{user} and @samp{command} columns are optional, and will be
46078 displayed by @value{GDBN}. The @samp{cores} column, if present,
46079 should contain a comma-separated list of cores that this process
46080 is running on. Target may provide additional columns,
46081 which @value{GDBN} currently ignores.
46082
46083 @node Trace File Format
46084 @appendix Trace File Format
46085 @cindex trace file format
46086
46087 The trace file comes in three parts: a header, a textual description
46088 section, and a trace frame section with binary data.
46089
46090 The header has the form @code{\x7fTRACE0\n}. The first byte is
46091 @code{0x7f} so as to indicate that the file contains binary data,
46092 while the @code{0} is a version number that may have different values
46093 in the future.
46094
46095 The description section consists of multiple lines of @sc{ascii} text
46096 separated by newline characters (@code{0xa}). The lines may include a
46097 variety of optional descriptive or context-setting information, such
46098 as tracepoint definitions or register set size. @value{GDBN} will
46099 ignore any line that it does not recognize. An empty line marks the end
46100 of this section.
46101
46102 @table @code
46103 @item R @var{size}
46104 Specifies the size of a register block in bytes. This is equal to the
46105 size of a @code{g} packet payload in the remote protocol. @var{size}
46106 is an ascii decimal number. There should be only one such line in
46107 a single trace file.
46108
46109 @item status @var{status}
46110 Trace status. @var{status} has the same format as a @code{qTStatus}
46111 remote packet reply. There should be only one such line in a single trace
46112 file.
46113
46114 @item tp @var{payload}
46115 Tracepoint definition. The @var{payload} has the same format as
46116 @code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
46117 may take multiple lines of definition, corresponding to the multiple
46118 reply packets.
46119
46120 @item tsv @var{payload}
46121 Trace state variable definition. The @var{payload} has the same format as
46122 @code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
46123 may take multiple lines of definition, corresponding to the multiple
46124 reply packets.
46125
46126 @item tdesc @var{payload}
46127 Target description in XML format. The @var{payload} is a single line of
46128 the XML file. All such lines should be concatenated together to get
46129 the original XML file. This file is in the same format as @code{qXfer}
46130 @code{features} payload, and corresponds to the main @code{target.xml}
46131 file. Includes are not allowed.
46132
46133 @end table
46134
46135 The trace frame section consists of a number of consecutive frames.
46136 Each frame begins with a two-byte tracepoint number, followed by a
46137 four-byte size giving the amount of data in the frame. The data in
46138 the frame consists of a number of blocks, each introduced by a
46139 character indicating its type (at least register, memory, and trace
46140 state variable). The data in this section is raw binary, not a
46141 hexadecimal or other encoding; its endianness matches the target's
46142 endianness.
46143
46144 @c FIXME bi-arch may require endianness/arch info in description section
46145
46146 @table @code
46147 @item R @var{bytes}
46148 Register block. The number and ordering of bytes matches that of a
46149 @code{g} packet in the remote protocol. Note that these are the
46150 actual bytes, in target order, not a hexadecimal encoding.
46151
46152 @item M @var{address} @var{length} @var{bytes}...
46153 Memory block. This is a contiguous block of memory, at the 8-byte
46154 address @var{address}, with a 2-byte length @var{length}, followed by
46155 @var{length} bytes.
46156
46157 @item V @var{number} @var{value}
46158 Trace state variable block. This records the 8-byte signed value
46159 @var{value} of trace state variable numbered @var{number}.
46160
46161 @end table
46162
46163 Future enhancements of the trace file format may include additional types
46164 of blocks.
46165
46166 @node Index Section Format
46167 @appendix @code{.gdb_index} section format
46168 @cindex .gdb_index section format
46169 @cindex index section format
46170
46171 This section documents the index section that is created by @code{save
46172 gdb-index} (@pxref{Index Files}). The index section is
46173 DWARF-specific; some knowledge of DWARF is assumed in this
46174 description.
46175
46176 The mapped index file format is designed to be directly
46177 @code{mmap}able on any architecture. In most cases, a datum is
46178 represented using a little-endian 32-bit integer value, called an
46179 @code{offset_type}. Big endian machines must byte-swap the values
46180 before using them. Exceptions to this rule are noted. The data is
46181 laid out such that alignment is always respected.
46182
46183 A mapped index consists of several areas, laid out in order.
46184
46185 @enumerate
46186 @item
46187 The file header. This is a sequence of values, of @code{offset_type}
46188 unless otherwise noted:
46189
46190 @enumerate
46191 @item
46192 The version number, currently 8. Versions 1, 2 and 3 are obsolete.
46193 Version 4 uses a different hashing function from versions 5 and 6.
46194 Version 6 includes symbols for inlined functions, whereas versions 4
46195 and 5 do not. Version 7 adds attributes to the CU indices in the
46196 symbol table. Version 8 specifies that symbols from DWARF type units
46197 (@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
46198 compilation unit (@samp{DW_TAG_comp_unit}) using the type.
46199
46200 @value{GDBN} will only read version 4, 5, or 6 indices
46201 by specifying @code{set use-deprecated-index-sections on}.
46202 GDB has a workaround for potentially broken version 7 indices so it is
46203 currently not flagged as deprecated.
46204
46205 @item
46206 The offset, from the start of the file, of the CU list.
46207
46208 @item
46209 The offset, from the start of the file, of the types CU list. Note
46210 that this area can be empty, in which case this offset will be equal
46211 to the next offset.
46212
46213 @item
46214 The offset, from the start of the file, of the address area.
46215
46216 @item
46217 The offset, from the start of the file, of the symbol table.
46218
46219 @item
46220 The offset, from the start of the file, of the constant pool.
46221 @end enumerate
46222
46223 @item
46224 The CU list. This is a sequence of pairs of 64-bit little-endian
46225 values, sorted by the CU offset. The first element in each pair is
46226 the offset of a CU in the @code{.debug_info} section. The second
46227 element in each pair is the length of that CU. References to a CU
46228 elsewhere in the map are done using a CU index, which is just the
46229 0-based index into this table. Note that if there are type CUs, then
46230 conceptually CUs and type CUs form a single list for the purposes of
46231 CU indices.
46232
46233 @item
46234 The types CU list. This is a sequence of triplets of 64-bit
46235 little-endian values. In a triplet, the first value is the CU offset,
46236 the second value is the type offset in the CU, and the third value is
46237 the type signature. The types CU list is not sorted.
46238
46239 @item
46240 The address area. The address area consists of a sequence of address
46241 entries. Each address entry has three elements:
46242
46243 @enumerate
46244 @item
46245 The low address. This is a 64-bit little-endian value.
46246
46247 @item
46248 The high address. This is a 64-bit little-endian value. Like
46249 @code{DW_AT_high_pc}, the value is one byte beyond the end.
46250
46251 @item
46252 The CU index. This is an @code{offset_type} value.
46253 @end enumerate
46254
46255 @item
46256 The symbol table. This is an open-addressed hash table. The size of
46257 the hash table is always a power of 2.
46258
46259 Each slot in the hash table consists of a pair of @code{offset_type}
46260 values. The first value is the offset of the symbol's name in the
46261 constant pool. The second value is the offset of the CU vector in the
46262 constant pool.
46263
46264 If both values are 0, then this slot in the hash table is empty. This
46265 is ok because while 0 is a valid constant pool index, it cannot be a
46266 valid index for both a string and a CU vector.
46267
46268 The hash value for a table entry is computed by applying an
46269 iterative hash function to the symbol's name. Starting with an
46270 initial value of @code{r = 0}, each (unsigned) character @samp{c} in
46271 the string is incorporated into the hash using the formula depending on the
46272 index version:
46273
46274 @table @asis
46275 @item Version 4
46276 The formula is @code{r = r * 67 + c - 113}.
46277
46278 @item Versions 5 to 7
46279 The formula is @code{r = r * 67 + tolower (c) - 113}.
46280 @end table
46281
46282 The terminating @samp{\0} is not incorporated into the hash.
46283
46284 The step size used in the hash table is computed via
46285 @code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
46286 value, and @samp{size} is the size of the hash table. The step size
46287 is used to find the next candidate slot when handling a hash
46288 collision.
46289
46290 The names of C@t{++} symbols in the hash table are canonicalized. We
46291 don't currently have a simple description of the canonicalization
46292 algorithm; if you intend to create new index sections, you must read
46293 the code.
46294
46295 @item
46296 The constant pool. This is simply a bunch of bytes. It is organized
46297 so that alignment is correct: CU vectors are stored first, followed by
46298 strings.
46299
46300 A CU vector in the constant pool is a sequence of @code{offset_type}
46301 values. The first value is the number of CU indices in the vector.
46302 Each subsequent value is the index and symbol attributes of a CU in
46303 the CU list. This element in the hash table is used to indicate which
46304 CUs define the symbol and how the symbol is used.
46305 See below for the format of each CU index+attributes entry.
46306
46307 A string in the constant pool is zero-terminated.
46308 @end enumerate
46309
46310 Attributes were added to CU index values in @code{.gdb_index} version 7.
46311 If a symbol has multiple uses within a CU then there is one
46312 CU index+attributes value for each use.
46313
46314 The format of each CU index+attributes entry is as follows
46315 (bit 0 = LSB):
46316
46317 @table @asis
46318
46319 @item Bits 0-23
46320 This is the index of the CU in the CU list.
46321 @item Bits 24-27
46322 These bits are reserved for future purposes and must be zero.
46323 @item Bits 28-30
46324 The kind of the symbol in the CU.
46325
46326 @table @asis
46327 @item 0
46328 This value is reserved and should not be used.
46329 By reserving zero the full @code{offset_type} value is backwards compatible
46330 with previous versions of the index.
46331 @item 1
46332 The symbol is a type.
46333 @item 2
46334 The symbol is a variable or an enum value.
46335 @item 3
46336 The symbol is a function.
46337 @item 4
46338 Any other kind of symbol.
46339 @item 5,6,7
46340 These values are reserved.
46341 @end table
46342
46343 @item Bit 31
46344 This bit is zero if the value is global and one if it is static.
46345
46346 The determination of whether a symbol is global or static is complicated.
46347 The authorative reference is the file @file{dwarf2read.c} in
46348 @value{GDBN} sources.
46349
46350 @end table
46351
46352 This pseudo-code describes the computation of a symbol's kind and
46353 global/static attributes in the index.
46354
46355 @smallexample
46356 is_external = get_attribute (die, DW_AT_external);
46357 language = get_attribute (cu_die, DW_AT_language);
46358 switch (die->tag)
46359 @{
46360 case DW_TAG_typedef:
46361 case DW_TAG_base_type:
46362 case DW_TAG_subrange_type:
46363 kind = TYPE;
46364 is_static = 1;
46365 break;
46366 case DW_TAG_enumerator:
46367 kind = VARIABLE;
46368 is_static = language != CPLUS;
46369 break;
46370 case DW_TAG_subprogram:
46371 kind = FUNCTION;
46372 is_static = ! (is_external || language == ADA);
46373 break;
46374 case DW_TAG_constant:
46375 kind = VARIABLE;
46376 is_static = ! is_external;
46377 break;
46378 case DW_TAG_variable:
46379 kind = VARIABLE;
46380 is_static = ! is_external;
46381 break;
46382 case DW_TAG_namespace:
46383 kind = TYPE;
46384 is_static = 0;
46385 break;
46386 case DW_TAG_class_type:
46387 case DW_TAG_interface_type:
46388 case DW_TAG_structure_type:
46389 case DW_TAG_union_type:
46390 case DW_TAG_enumeration_type:
46391 kind = TYPE;
46392 is_static = language != CPLUS;
46393 break;
46394 default:
46395 assert (0);
46396 @}
46397 @end smallexample
46398
46399 @node Man Pages
46400 @appendix Manual pages
46401 @cindex Man pages
46402
46403 @menu
46404 * gdb man:: The GNU Debugger man page
46405 * gdbserver man:: Remote Server for the GNU Debugger man page
46406 * gcore man:: Generate a core file of a running program
46407 * gdbinit man:: gdbinit scripts
46408 * gdb-add-index man:: Add index files to speed up GDB
46409 @end menu
46410
46411 @node gdb man
46412 @heading gdb man
46413
46414 @c man title gdb The GNU Debugger
46415
46416 @c man begin SYNOPSIS gdb
46417 gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
46418 [@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
46419 [@option{-b}@w{ }@var{bps}]
46420 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
46421 [@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
46422 [@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
46423 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
46424 [@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
46425 @c man end
46426
46427 @c man begin DESCRIPTION gdb
46428 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
46429 going on ``inside'' another program while it executes -- or what another
46430 program was doing at the moment it crashed.
46431
46432 @value{GDBN} can do four main kinds of things (plus other things in support of
46433 these) to help you catch bugs in the act:
46434
46435 @itemize @bullet
46436 @item
46437 Start your program, specifying anything that might affect its behavior.
46438
46439 @item
46440 Make your program stop on specified conditions.
46441
46442 @item
46443 Examine what has happened, when your program has stopped.
46444
46445 @item
46446 Change things in your program, so you can experiment with correcting the
46447 effects of one bug and go on to learn about another.
46448 @end itemize
46449
46450 You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
46451 Modula-2.
46452
46453 @value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
46454 commands from the terminal until you tell it to exit with the @value{GDBN}
46455 command @code{quit}. You can get online help from @value{GDBN} itself
46456 by using the command @code{help}.
46457
46458 You can run @code{gdb} with no arguments or options; but the most
46459 usual way to start @value{GDBN} is with one argument or two, specifying an
46460 executable program as the argument:
46461
46462 @smallexample
46463 gdb program
46464 @end smallexample
46465
46466 You can also start with both an executable program and a core file specified:
46467
46468 @smallexample
46469 gdb program core
46470 @end smallexample
46471
46472 You can, instead, specify a process ID as a second argument or use option
46473 @code{-p}, if you want to debug a running process:
46474
46475 @smallexample
46476 gdb program 1234
46477 gdb -p 1234
46478 @end smallexample
46479
46480 @noindent
46481 would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
46482 can omit the @var{program} filename.
46483
46484 Here are some of the most frequently needed @value{GDBN} commands:
46485
46486 @c pod2man highlights the right hand side of the @item lines.
46487 @table @env
46488 @item break [@var{file}:]@var{function}
46489 Set a breakpoint at @var{function} (in @var{file}).
46490
46491 @item run [@var{arglist}]
46492 Start your program (with @var{arglist}, if specified).
46493
46494 @item bt
46495 Backtrace: display the program stack.
46496
46497 @item print @var{expr}
46498 Display the value of an expression.
46499
46500 @item c
46501 Continue running your program (after stopping, e.g. at a breakpoint).
46502
46503 @item next
46504 Execute next program line (after stopping); step @emph{over} any
46505 function calls in the line.
46506
46507 @item edit [@var{file}:]@var{function}
46508 look at the program line where it is presently stopped.
46509
46510 @item list [@var{file}:]@var{function}
46511 type the text of the program in the vicinity of where it is presently stopped.
46512
46513 @item step
46514 Execute next program line (after stopping); step @emph{into} any
46515 function calls in the line.
46516
46517 @item help [@var{name}]
46518 Show information about @value{GDBN} command @var{name}, or general information
46519 about using @value{GDBN}.
46520
46521 @item quit
46522 Exit from @value{GDBN}.
46523 @end table
46524
46525 @ifset man
46526 For full details on @value{GDBN},
46527 see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46528 by Richard M. Stallman and Roland H. Pesch. The same text is available online
46529 as the @code{gdb} entry in the @code{info} program.
46530 @end ifset
46531 @c man end
46532
46533 @c man begin OPTIONS gdb
46534 Any arguments other than options specify an executable
46535 file and core file (or process ID); that is, the first argument
46536 encountered with no
46537 associated option flag is equivalent to a @option{-se} option, and the second,
46538 if any, is equivalent to a @option{-c} option if it's the name of a file.
46539 Many options have
46540 both long and short forms; both are shown here. The long forms are also
46541 recognized if you truncate them, so long as enough of the option is
46542 present to be unambiguous. (If you prefer, you can flag option
46543 arguments with @option{+} rather than @option{-}, though we illustrate the
46544 more usual convention.)
46545
46546 All the options and command line arguments you give are processed
46547 in sequential order. The order makes a difference when the @option{-x}
46548 option is used.
46549
46550 @table @env
46551 @item -help
46552 @itemx -h
46553 List all options, with brief explanations.
46554
46555 @item -symbols=@var{file}
46556 @itemx -s @var{file}
46557 Read symbol table from file @var{file}.
46558
46559 @item -write
46560 Enable writing into executable and core files.
46561
46562 @item -exec=@var{file}
46563 @itemx -e @var{file}
46564 Use file @var{file} as the executable file to execute when
46565 appropriate, and for examining pure data in conjunction with a core
46566 dump.
46567
46568 @item -se=@var{file}
46569 Read symbol table from file @var{file} and use it as the executable
46570 file.
46571
46572 @item -core=@var{file}
46573 @itemx -c @var{file}
46574 Use file @var{file} as a core dump to examine.
46575
46576 @item -command=@var{file}
46577 @itemx -x @var{file}
46578 Execute @value{GDBN} commands from file @var{file}.
46579
46580 @item -ex @var{command}
46581 Execute given @value{GDBN} @var{command}.
46582
46583 @item -directory=@var{directory}
46584 @itemx -d @var{directory}
46585 Add @var{directory} to the path to search for source files.
46586
46587 @item -nh
46588 Do not execute commands from @file{~/.config/gdb/gdbinit} or
46589 @file{~/.gdbinit}.
46590
46591 @item -nx
46592 @itemx -n
46593 Do not execute commands from any @file{.gdbinit} initialization files.
46594
46595 @item -quiet
46596 @itemx -q
46597 ``Quiet''. Do not print the introductory and copyright messages. These
46598 messages are also suppressed in batch mode.
46599
46600 @item -batch
46601 Run in batch mode. Exit with status @code{0} after processing all the command
46602 files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
46603 Exit with nonzero status if an error occurs in executing the @value{GDBN}
46604 commands in the command files.
46605
46606 Batch mode may be useful for running @value{GDBN} as a filter, for example to
46607 download and run a program on another computer; in order to make this
46608 more useful, the message
46609
46610 @smallexample
46611 Program exited normally.
46612 @end smallexample
46613
46614 @noindent
46615 (which is ordinarily issued whenever a program running under @value{GDBN} control
46616 terminates) is not issued when running in batch mode.
46617
46618 @item -cd=@var{directory}
46619 Run @value{GDBN} using @var{directory} as its working directory,
46620 instead of the current directory.
46621
46622 @item -fullname
46623 @itemx -f
46624 Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
46625 @value{GDBN} to output the full file name and line number in a standard,
46626 recognizable fashion each time a stack frame is displayed (which
46627 includes each time the program stops). This recognizable format looks
46628 like two @samp{\032} characters, followed by the file name, line number
46629 and character position separated by colons, and a newline. The
46630 Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
46631 characters as a signal to display the source code for the frame.
46632
46633 @item -b @var{bps}
46634 Set the line speed (baud rate or bits per second) of any serial
46635 interface used by @value{GDBN} for remote debugging.
46636
46637 @item -tty=@var{device}
46638 Run using @var{device} for your program's standard input and output.
46639 @end table
46640 @c man end
46641
46642 @c man begin SEEALSO gdb
46643 @ifset man
46644 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46645 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46646 documentation are properly installed at your site, the command
46647
46648 @smallexample
46649 info gdb
46650 @end smallexample
46651
46652 @noindent
46653 should give you access to the complete manual.
46654
46655 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46656 Richard M. Stallman and Roland H. Pesch, July 1991.
46657 @end ifset
46658 @c man end
46659
46660 @node gdbserver man
46661 @heading gdbserver man
46662
46663 @c man title gdbserver Remote Server for the GNU Debugger
46664 @format
46665 @c man begin SYNOPSIS gdbserver
46666 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46667
46668 gdbserver --attach @var{comm} @var{pid}
46669
46670 gdbserver --multi @var{comm}
46671 @c man end
46672 @end format
46673
46674 @c man begin DESCRIPTION gdbserver
46675 @command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
46676 than the one which is running the program being debugged.
46677
46678 @ifclear man
46679 @subheading Usage (server (target) side)
46680 @end ifclear
46681 @ifset man
46682 Usage (server (target) side):
46683 @end ifset
46684
46685 First, you need to have a copy of the program you want to debug put onto
46686 the target system. The program can be stripped to save space if needed, as
46687 @command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
46688 the @value{GDBN} running on the host system.
46689
46690 To use the server, you log on to the target system, and run the @command{gdbserver}
46691 program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
46692 your program, and (c) its arguments. The general syntax is:
46693
46694 @smallexample
46695 target> gdbserver @var{comm} @var{program} [@var{args} ...]
46696 @end smallexample
46697
46698 For example, using a serial port, you might say:
46699
46700 @smallexample
46701 @ifset man
46702 @c @file would wrap it as F</dev/com1>.
46703 target> gdbserver /dev/com1 emacs foo.txt
46704 @end ifset
46705 @ifclear man
46706 target> gdbserver @file{/dev/com1} emacs foo.txt
46707 @end ifclear
46708 @end smallexample
46709
46710 This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
46711 to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
46712 waits patiently for the host @value{GDBN} to communicate with it.
46713
46714 To use a TCP connection, you could say:
46715
46716 @smallexample
46717 target> gdbserver host:2345 emacs foo.txt
46718 @end smallexample
46719
46720 This says pretty much the same thing as the last example, except that we are
46721 going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
46722 that we are expecting to see a TCP connection from @code{host} to local TCP port
46723 2345. (Currently, the @code{host} part is ignored.) You can choose any number you
46724 want for the port number as long as it does not conflict with any existing TCP
46725 ports on the target system. This same port number must be used in the host
46726 @value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
46727 you chose a port number that conflicts with another service, @command{gdbserver} will
46728 print an error message and exit.
46729
46730 @command{gdbserver} can also attach to running programs.
46731 This is accomplished via the @option{--attach} argument. The syntax is:
46732
46733 @smallexample
46734 target> gdbserver --attach @var{comm} @var{pid}
46735 @end smallexample
46736
46737 @var{pid} is the process ID of a currently running process. It isn't
46738 necessary to point @command{gdbserver} at a binary for the running process.
46739
46740 To start @code{gdbserver} without supplying an initial command to run
46741 or process ID to attach, use the @option{--multi} command line option.
46742 In such case you should connect using @kbd{target extended-remote} to start
46743 the program you want to debug.
46744
46745 @smallexample
46746 target> gdbserver --multi @var{comm}
46747 @end smallexample
46748
46749 @ifclear man
46750 @subheading Usage (host side)
46751 @end ifclear
46752 @ifset man
46753 Usage (host side):
46754 @end ifset
46755
46756 You need an unstripped copy of the target program on your host system, since
46757 @value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
46758 would, with the target program as the first argument. (You may need to use the
46759 @option{--baud} option if the serial line is running at anything except 9600 baud.)
46760 That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
46761 new command you need to know about is @code{target remote}
46762 (or @code{target extended-remote}). Its argument is either
46763 a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
46764 descriptor. For example:
46765
46766 @smallexample
46767 @ifset man
46768 @c @file would wrap it as F</dev/ttyb>.
46769 (gdb) target remote /dev/ttyb
46770 @end ifset
46771 @ifclear man
46772 (gdb) target remote @file{/dev/ttyb}
46773 @end ifclear
46774 @end smallexample
46775
46776 @noindent
46777 communicates with the server via serial line @file{/dev/ttyb}, and:
46778
46779 @smallexample
46780 (gdb) target remote the-target:2345
46781 @end smallexample
46782
46783 @noindent
46784 communicates via a TCP connection to port 2345 on host `the-target', where
46785 you previously started up @command{gdbserver} with the same port number. Note that for
46786 TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
46787 command, otherwise you may get an error that looks something like
46788 `Connection refused'.
46789
46790 @command{gdbserver} can also debug multiple inferiors at once,
46791 described in
46792 @ifset man
46793 the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
46794 -- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
46795 @end ifset
46796 @ifclear man
46797 @ref{Inferiors Connections and Programs}.
46798 @end ifclear
46799 In such case use the @code{extended-remote} @value{GDBN} command variant:
46800
46801 @smallexample
46802 (gdb) target extended-remote the-target:2345
46803 @end smallexample
46804
46805 The @command{gdbserver} option @option{--multi} may or may not be used in such
46806 case.
46807 @c man end
46808
46809 @c man begin OPTIONS gdbserver
46810 There are three different modes for invoking @command{gdbserver}:
46811
46812 @itemize @bullet
46813
46814 @item
46815 Debug a specific program specified by its program name:
46816
46817 @smallexample
46818 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46819 @end smallexample
46820
46821 The @var{comm} parameter specifies how should the server communicate
46822 with @value{GDBN}; it is either a device name (to use a serial line),
46823 a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
46824 stdin/stdout of @code{gdbserver}. Specify the name of the program to
46825 debug in @var{prog}. Any remaining arguments will be passed to the
46826 program verbatim. When the program exits, @value{GDBN} will close the
46827 connection, and @code{gdbserver} will exit.
46828
46829 @item
46830 Debug a specific program by specifying the process ID of a running
46831 program:
46832
46833 @smallexample
46834 gdbserver --attach @var{comm} @var{pid}
46835 @end smallexample
46836
46837 The @var{comm} parameter is as described above. Supply the process ID
46838 of a running program in @var{pid}; @value{GDBN} will do everything
46839 else. Like with the previous mode, when the process @var{pid} exits,
46840 @value{GDBN} will close the connection, and @code{gdbserver} will exit.
46841
46842 @item
46843 Multi-process mode -- debug more than one program/process:
46844
46845 @smallexample
46846 gdbserver --multi @var{comm}
46847 @end smallexample
46848
46849 In this mode, @value{GDBN} can instruct @command{gdbserver} which
46850 command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
46851 close the connection when a process being debugged exits, so you can
46852 debug several processes in the same session.
46853 @end itemize
46854
46855 In each of the modes you may specify these options:
46856
46857 @table @env
46858
46859 @item --help
46860 List all options, with brief explanations.
46861
46862 @item --version
46863 This option causes @command{gdbserver} to print its version number and exit.
46864
46865 @item --attach
46866 @command{gdbserver} will attach to a running program. The syntax is:
46867
46868 @smallexample
46869 target> gdbserver --attach @var{comm} @var{pid}
46870 @end smallexample
46871
46872 @var{pid} is the process ID of a currently running process. It isn't
46873 necessary to point @command{gdbserver} at a binary for the running process.
46874
46875 @item --multi
46876 To start @code{gdbserver} without supplying an initial command to run
46877 or process ID to attach, use this command line option.
46878 Then you can connect using @kbd{target extended-remote} and start
46879 the program you want to debug. The syntax is:
46880
46881 @smallexample
46882 target> gdbserver --multi @var{comm}
46883 @end smallexample
46884
46885 @item --debug
46886 Instruct @code{gdbserver} to display extra status information about the debugging
46887 process.
46888 This option is intended for @code{gdbserver} development and for bug reports to
46889 the developers.
46890
46891 @item --remote-debug
46892 Instruct @code{gdbserver} to display remote protocol debug output.
46893 This option is intended for @code{gdbserver} development and for bug reports to
46894 the developers.
46895
46896 @item --debug-file=@var{filename}
46897 Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
46898 This option is intended for @code{gdbserver} development and for bug reports to
46899 the developers.
46900
46901 @item --debug-format=option1@r{[},option2,...@r{]}
46902 Instruct @code{gdbserver} to include extra information in each line
46903 of debugging output.
46904 @xref{Other Command-Line Arguments for gdbserver}.
46905
46906 @item --wrapper
46907 Specify a wrapper to launch programs
46908 for debugging. The option should be followed by the name of the
46909 wrapper, then any command-line arguments to pass to the wrapper, then
46910 @kbd{--} indicating the end of the wrapper arguments.
46911
46912 @item --once
46913 By default, @command{gdbserver} keeps the listening TCP port open, so that
46914 additional connections are possible. However, if you start @code{gdbserver}
46915 with the @option{--once} option, it will stop listening for any further
46916 connection attempts after connecting to the first @value{GDBN} session.
46917
46918 @c --disable-packet is not documented for users.
46919
46920 @c --disable-randomization and --no-disable-randomization are superseded by
46921 @c QDisableRandomization.
46922
46923 @end table
46924 @c man end
46925
46926 @c man begin SEEALSO gdbserver
46927 @ifset man
46928 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46929 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46930 documentation are properly installed at your site, the command
46931
46932 @smallexample
46933 info gdb
46934 @end smallexample
46935
46936 should give you access to the complete manual.
46937
46938 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46939 Richard M. Stallman and Roland H. Pesch, July 1991.
46940 @end ifset
46941 @c man end
46942
46943 @node gcore man
46944 @heading gcore
46945
46946 @c man title gcore Generate a core file of a running program
46947
46948 @format
46949 @c man begin SYNOPSIS gcore
46950 gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
46951 @c man end
46952 @end format
46953
46954 @c man begin DESCRIPTION gcore
46955 Generate core dumps of one or more running programs with process IDs
46956 @var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
46957 is equivalent to one produced by the kernel when the process crashes
46958 (and when @kbd{ulimit -c} was used to set up an appropriate core dump
46959 limit). However, unlike after a crash, after @command{gcore} finishes
46960 its job the program remains running without any change.
46961 @c man end
46962
46963 @c man begin OPTIONS gcore
46964 @table @env
46965 @item -a
46966 Dump all memory mappings. The actual effect of this option depends on
46967 the Operating System. On @sc{gnu}/Linux, it will disable
46968 @code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
46969 enable @code{dump-excluded-mappings} (@pxref{set
46970 dump-excluded-mappings}).
46971
46972 @item -o @var{prefix}
46973 The optional argument @var{prefix} specifies the prefix to be used
46974 when composing the file names of the core dumps. The file name is
46975 composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
46976 process ID of the running program being analyzed by @command{gcore}.
46977 If not specified, @var{prefix} defaults to @var{gcore}.
46978 @end table
46979 @c man end
46980
46981 @c man begin SEEALSO gcore
46982 @ifset man
46983 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46984 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46985 documentation are properly installed at your site, the command
46986
46987 @smallexample
46988 info gdb
46989 @end smallexample
46990
46991 @noindent
46992 should give you access to the complete manual.
46993
46994 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46995 Richard M. Stallman and Roland H. Pesch, July 1991.
46996 @end ifset
46997 @c man end
46998
46999 @node gdbinit man
47000 @heading gdbinit
47001
47002 @c man title gdbinit GDB initialization scripts
47003
47004 @format
47005 @c man begin SYNOPSIS gdbinit
47006 @ifset SYSTEM_GDBINIT
47007 @value{SYSTEM_GDBINIT}
47008 @end ifset
47009
47010 @ifset SYSTEM_GDBINIT_DIR
47011 @value{SYSTEM_GDBINIT_DIR}/*
47012 @end ifset
47013
47014 ~/.config/gdb/gdbinit
47015
47016 ~/.gdbinit
47017
47018 ./.gdbinit
47019 @c man end
47020 @end format
47021
47022 @c man begin DESCRIPTION gdbinit
47023 These files contain @value{GDBN} commands to automatically execute during
47024 @value{GDBN} startup. The lines of contents are canned sequences of commands,
47025 described in
47026 @ifset man
47027 the @value{GDBN} manual in node @code{Sequences}
47028 -- shell command @code{info -f gdb -n Sequences}.
47029 @end ifset
47030 @ifclear man
47031 @ref{Sequences}.
47032 @end ifclear
47033
47034 Please read more in
47035 @ifset man
47036 the @value{GDBN} manual in node @code{Startup}
47037 -- shell command @code{info -f gdb -n Startup}.
47038 @end ifset
47039 @ifclear man
47040 @ref{Startup}.
47041 @end ifclear
47042
47043 @table @env
47044 @ifset SYSTEM_GDBINIT
47045 @item @value{SYSTEM_GDBINIT}
47046 @end ifset
47047 @ifclear SYSTEM_GDBINIT
47048 @item (not enabled with @code{--with-system-gdbinit} during compilation)
47049 @end ifclear
47050 System-wide initialization file. It is executed unless user specified
47051 @value{GDBN} option @code{-nx} or @code{-n}.
47052 See more in
47053 @ifset man
47054 the @value{GDBN} manual in node @code{System-wide configuration}
47055 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
47056 @end ifset
47057 @ifset SYSTEM_GDBINIT_DIR
47058 @item @value{SYSTEM_GDBINIT_DIR}
47059 @end ifset
47060 @ifclear SYSTEM_GDBINIT_DIR
47061 @item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
47062 @end ifclear
47063 System-wide initialization directory. All files in this directory are
47064 executed on startup unless user specified @value{GDBN} option @code{-nx} or
47065 @code{-n}, as long as they have a recognized file extension.
47066 See more in
47067 @ifset man
47068 the @value{GDBN} manual in node @code{System-wide configuration}
47069 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
47070 @end ifset
47071 @ifclear man
47072 @ref{System-wide configuration}.
47073 @end ifclear
47074
47075 @item @file{~/.config/gdb/gdbinit} or @file{~/.gdbinit}
47076 User initialization file. It is executed unless user specified
47077 @value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
47078
47079 @item @file{.gdbinit}
47080 Initialization file for current directory. It may need to be enabled with
47081 @value{GDBN} security command @code{set auto-load local-gdbinit}.
47082 See more in
47083 @ifset man
47084 the @value{GDBN} manual in node @code{Init File in the Current Directory}
47085 -- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
47086 @end ifset
47087 @ifclear man
47088 @ref{Init File in the Current Directory}.
47089 @end ifclear
47090 @end table
47091 @c man end
47092
47093 @c man begin SEEALSO gdbinit
47094 @ifset man
47095 gdb(1), @code{info -f gdb -n Startup}
47096
47097 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47098 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47099 documentation are properly installed at your site, the command
47100
47101 @smallexample
47102 info gdb
47103 @end smallexample
47104
47105 should give you access to the complete manual.
47106
47107 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47108 Richard M. Stallman and Roland H. Pesch, July 1991.
47109 @end ifset
47110 @c man end
47111
47112 @node gdb-add-index man
47113 @heading gdb-add-index
47114 @pindex gdb-add-index
47115 @anchor{gdb-add-index}
47116
47117 @c man title gdb-add-index Add index files to speed up GDB
47118
47119 @c man begin SYNOPSIS gdb-add-index
47120 gdb-add-index @var{filename}
47121 @c man end
47122
47123 @c man begin DESCRIPTION gdb-add-index
47124 When @value{GDBN} finds a symbol file, it scans the symbols in the
47125 file in order to construct an internal symbol table. This lets most
47126 @value{GDBN} operations work quickly--at the cost of a delay early on.
47127 For large programs, this delay can be quite lengthy, so @value{GDBN}
47128 provides a way to build an index, which speeds up startup.
47129
47130 To determine whether a file contains such an index, use the command
47131 @kbd{readelf -S filename}: the index is stored in a section named
47132 @code{.gdb_index}. The index file can only be produced on systems
47133 which use ELF binaries and DWARF debug information (i.e., sections
47134 named @code{.debug_*}).
47135
47136 @command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
47137 in the @env{PATH} environment variable. If you want to use different
47138 versions of these programs, you can specify them through the
47139 @env{GDB} and @env{OBJDUMP} environment variables.
47140
47141 See more in
47142 @ifset man
47143 the @value{GDBN} manual in node @code{Index Files}
47144 -- shell command @kbd{info -f gdb -n "Index Files"}.
47145 @end ifset
47146 @ifclear man
47147 @ref{Index Files}.
47148 @end ifclear
47149 @c man end
47150
47151 @c man begin SEEALSO gdb-add-index
47152 @ifset man
47153 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47154 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47155 documentation are properly installed at your site, the command
47156
47157 @smallexample
47158 info gdb
47159 @end smallexample
47160
47161 should give you access to the complete manual.
47162
47163 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47164 Richard M. Stallman and Roland H. Pesch, July 1991.
47165 @end ifset
47166 @c man end
47167
47168 @include gpl.texi
47169
47170 @node GNU Free Documentation License
47171 @appendix GNU Free Documentation License
47172 @include fdl.texi
47173
47174 @node Concept Index
47175 @unnumbered Concept Index
47176
47177 @printindex cp
47178
47179 @node Command and Variable Index
47180 @unnumbered Command, Variable, and Function Index
47181
47182 @printindex fn
47183
47184 @tex
47185 % I think something like @@colophon should be in texinfo. In the
47186 % meantime:
47187 \long\def\colophon{\hbox to0pt{}\vfill
47188 \centerline{The body of this manual is set in}
47189 \centerline{\fontname\tenrm,}
47190 \centerline{with headings in {\bf\fontname\tenbf}}
47191 \centerline{and examples in {\tt\fontname\tentt}.}
47192 \centerline{{\it\fontname\tenit\/},}
47193 \centerline{{\bf\fontname\tenbf}, and}
47194 \centerline{{\sl\fontname\tensl\/}}
47195 \centerline{are used for emphasis.}\vfill}
47196 \page\colophon
47197 % Blame: doc@@cygnus.com, 1991.
47198 @end tex
47199
47200 @bye