4351378fd053f4019c122343d842ec95e847d3ae
[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-2021 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-2021 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 -early-init-command @var{file}
1044 @itemx -eix @var{file}
1045 @cindex @code{--early-init-command}
1046 @cindex @code{-eix}
1047 Execute commands from @var{file} very early in the initialization
1048 process, before any output is produced. @xref{Startup}.
1049
1050 @item -early-init-eval-command @var{command}
1051 @itemx -eiex @var{command}
1052 @cindex @code{--early-init-eval-command}
1053 @cindex @code{-eiex}
1054 Execute a single @value{GDBN} command very early in the initialization
1055 process, before any output is produced.
1056
1057 @item -directory @var{directory}
1058 @itemx -d @var{directory}
1059 @cindex @code{--directory}
1060 @cindex @code{-d}
1061 Add @var{directory} to the path to search for source and script files.
1062
1063 @item -r
1064 @itemx -readnow
1065 @cindex @code{--readnow}
1066 @cindex @code{-r}
1067 Read each symbol file's entire symbol table immediately, rather than
1068 the default, which is to read it incrementally as it is needed.
1069 This makes startup slower, but makes future operations faster.
1070
1071 @item --readnever
1072 @anchor{--readnever}
1073 @cindex @code{--readnever}, command-line option
1074 Do not read each symbol file's symbolic debug information. This makes
1075 startup faster but at the expense of not being able to perform
1076 symbolic debugging. DWARF unwind information is also not read,
1077 meaning backtraces may become incomplete or inaccurate. One use of
1078 this is when a user simply wants to do the following sequence: attach,
1079 dump core, detach. Loading the debugging information in this case is
1080 an unnecessary cause of delay.
1081 @end table
1082
1083 @node Mode Options
1084 @subsection Choosing Modes
1085
1086 You can run @value{GDBN} in various alternative modes---for example, in
1087 batch mode or quiet mode.
1088
1089 @table @code
1090 @anchor{-nx}
1091 @item -nx
1092 @itemx -n
1093 @cindex @code{--nx}
1094 @cindex @code{-n}
1095 Do not execute commands found in any initialization files
1096 (@pxref{Initialization Files}).
1097
1098 @anchor{-nh}
1099 @item -nh
1100 @cindex @code{--nh}
1101 Do not execute commands found in any home directory initialization
1102 file (@pxref{Initialization Files,,Home directory initialization
1103 file}). The system wide and current directory initialization files
1104 are still loaded.
1105
1106 @item -quiet
1107 @itemx -silent
1108 @itemx -q
1109 @cindex @code{--quiet}
1110 @cindex @code{--silent}
1111 @cindex @code{-q}
1112 ``Quiet''. Do not print the introductory and copyright messages. These
1113 messages are also suppressed in batch mode.
1114
1115 @item -batch
1116 @cindex @code{--batch}
1117 Run in batch mode. Exit with status @code{0} after processing all the
1118 command files specified with @samp{-x} (and all commands from
1119 initialization files, if not inhibited with @samp{-n}). Exit with
1120 nonzero status if an error occurs in executing the @value{GDBN} commands
1121 in the command files. Batch mode also disables pagination, sets unlimited
1122 terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1123 off} were in effect (@pxref{Messages/Warnings}).
1124
1125 Batch mode may be useful for running @value{GDBN} as a filter, for
1126 example to download and run a program on another computer; in order to
1127 make this more useful, the message
1128
1129 @smallexample
1130 Program exited normally.
1131 @end smallexample
1132
1133 @noindent
1134 (which is ordinarily issued whenever a program running under
1135 @value{GDBN} control terminates) is not issued when running in batch
1136 mode.
1137
1138 @item -batch-silent
1139 @cindex @code{--batch-silent}
1140 Run in batch mode exactly like @samp{-batch}, but totally silently. All
1141 @value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1142 unaffected). This is much quieter than @samp{-silent} and would be useless
1143 for an interactive session.
1144
1145 This is particularly useful when using targets that give @samp{Loading section}
1146 messages, for example.
1147
1148 Note that targets that give their output via @value{GDBN}, as opposed to
1149 writing directly to @code{stdout}, will also be made silent.
1150
1151 @item -return-child-result
1152 @cindex @code{--return-child-result}
1153 The return code from @value{GDBN} will be the return code from the child
1154 process (the process being debugged), with the following exceptions:
1155
1156 @itemize @bullet
1157 @item
1158 @value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1159 internal error. In this case the exit code is the same as it would have been
1160 without @samp{-return-child-result}.
1161 @item
1162 The user quits with an explicit value. E.g., @samp{quit 1}.
1163 @item
1164 The child process never runs, or is not allowed to terminate, in which case
1165 the exit code will be -1.
1166 @end itemize
1167
1168 This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1169 when @value{GDBN} is being used as a remote program loader or simulator
1170 interface.
1171
1172 @item -nowindows
1173 @itemx -nw
1174 @cindex @code{--nowindows}
1175 @cindex @code{-nw}
1176 ``No windows''. If @value{GDBN} comes with a graphical user interface
1177 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1178 interface. If no GUI is available, this option has no effect.
1179
1180 @item -windows
1181 @itemx -w
1182 @cindex @code{--windows}
1183 @cindex @code{-w}
1184 If @value{GDBN} includes a GUI, then this option requires it to be
1185 used if possible.
1186
1187 @item -cd @var{directory}
1188 @cindex @code{--cd}
1189 Run @value{GDBN} using @var{directory} as its working directory,
1190 instead of the current directory.
1191
1192 @item -data-directory @var{directory}
1193 @itemx -D @var{directory}
1194 @cindex @code{--data-directory}
1195 @cindex @code{-D}
1196 Run @value{GDBN} using @var{directory} as its data directory.
1197 The data directory is where @value{GDBN} searches for its
1198 auxiliary files. @xref{Data Files}.
1199
1200 @item -fullname
1201 @itemx -f
1202 @cindex @code{--fullname}
1203 @cindex @code{-f}
1204 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1205 subprocess. It tells @value{GDBN} to output the full file name and line
1206 number in a standard, recognizable fashion each time a stack frame is
1207 displayed (which includes each time your program stops). This
1208 recognizable format looks like two @samp{\032} characters, followed by
1209 the file name, line number and character position separated by colons,
1210 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1211 @samp{\032} characters as a signal to display the source code for the
1212 frame.
1213
1214 @item -annotate @var{level}
1215 @cindex @code{--annotate}
1216 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1217 effect is identical to using @samp{set annotate @var{level}}
1218 (@pxref{Annotations}). The annotation @var{level} controls how much
1219 information @value{GDBN} prints together with its prompt, values of
1220 expressions, source lines, and other types of output. Level 0 is the
1221 normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1222 @sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1223 that control @value{GDBN}, and level 2 has been deprecated.
1224
1225 The annotation mechanism has largely been superseded by @sc{gdb/mi}
1226 (@pxref{GDB/MI}).
1227
1228 @item --args
1229 @cindex @code{--args}
1230 Change interpretation of command line so that arguments following the
1231 executable file are passed as command line arguments to the inferior.
1232 This option stops option processing.
1233
1234 @item -baud @var{bps}
1235 @itemx -b @var{bps}
1236 @cindex @code{--baud}
1237 @cindex @code{-b}
1238 Set the line speed (baud rate or bits per second) of any serial
1239 interface used by @value{GDBN} for remote debugging.
1240
1241 @item -l @var{timeout}
1242 @cindex @code{-l}
1243 Set the timeout (in seconds) of any communication used by @value{GDBN}
1244 for remote debugging.
1245
1246 @item -tty @var{device}
1247 @itemx -t @var{device}
1248 @cindex @code{--tty}
1249 @cindex @code{-t}
1250 Run using @var{device} for your program's standard input and output.
1251 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1252
1253 @c resolve the situation of these eventually
1254 @item -tui
1255 @cindex @code{--tui}
1256 Activate the @dfn{Text User Interface} when starting. The Text User
1257 Interface manages several text windows on the terminal, showing
1258 source, assembly, registers and @value{GDBN} command outputs
1259 (@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1260 option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1261 Using @value{GDBN} under @sc{gnu} Emacs}).
1262
1263 @item -interpreter @var{interp}
1264 @cindex @code{--interpreter}
1265 Use the interpreter @var{interp} for interface with the controlling
1266 program or device. This option is meant to be set by programs which
1267 communicate with @value{GDBN} using it as a back end.
1268 @xref{Interpreters, , Command Interpreters}.
1269
1270 @samp{--interpreter=mi} (or @samp{--interpreter=mi3}) causes
1271 @value{GDBN} to use the @dfn{@sc{gdb/mi} interface} version 3 (@pxref{GDB/MI, ,
1272 The @sc{gdb/mi} Interface}) included since @value{GDBN} version 9.1. @sc{gdb/mi}
1273 version 2 (@code{mi2}), included in @value{GDBN} 6.0 and version 1 (@code{mi1}),
1274 included in @value{GDBN} 5.3, are also available. Earlier @sc{gdb/mi}
1275 interfaces are no longer supported.
1276
1277 @item -write
1278 @cindex @code{--write}
1279 Open the executable and core files for both reading and writing. This
1280 is equivalent to the @samp{set write on} command inside @value{GDBN}
1281 (@pxref{Patching}).
1282
1283 @item -statistics
1284 @cindex @code{--statistics}
1285 This option causes @value{GDBN} to print statistics about time and
1286 memory usage after it completes each command and returns to the prompt.
1287
1288 @item -version
1289 @cindex @code{--version}
1290 This option causes @value{GDBN} to print its version number and
1291 no-warranty blurb, and exit.
1292
1293 @item -configuration
1294 @cindex @code{--configuration}
1295 This option causes @value{GDBN} to print details about its build-time
1296 configuration parameters, and then exit. These details can be
1297 important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1298
1299 @end table
1300
1301 @node Startup
1302 @subsection What @value{GDBN} Does During Startup
1303 @cindex @value{GDBN} startup
1304
1305 Here's the description of what @value{GDBN} does during session startup:
1306
1307 @enumerate
1308
1309 @item
1310 Performs minimal setup required to initialize basic internal state.
1311
1312 @item
1313 @cindex early initialization file
1314 Reads commands from the early initialization file (if any) in your
1315 home directory. Only a restricted set of commands can be placed into
1316 an early initialization file, see @ref{Initialization Files}, for
1317 details.
1318
1319 @item
1320 Executes commands and command files specified by the @samp{-eiex} and
1321 @samp{-eix} command line options in their specified order. Only a
1322 restricted set of commands can be used with @samp{-eiex} and
1323 @samp{eix}, see @ref{Initialization Files}, for details.
1324
1325 @item
1326 Sets up the command interpreter as specified by the command line
1327 (@pxref{Mode Options, interpreter}).
1328
1329 @item
1330 @cindex init file
1331 Reads the system wide initialization file and the files from the
1332 system wide initialization directory, @pxref{System Wide Init Files}.
1333
1334 @item
1335 Reads the initialization file (if any) in your home directory and
1336 executes all the commands in that file, @pxref{Home Directory Init
1337 File}.
1338
1339 @anchor{Option -init-eval-command}
1340 @item
1341 Executes commands and command files specified by the @samp{-iex} and
1342 @samp{-ix} options in their specified order. Usually you should use the
1343 @samp{-ex} and @samp{-x} options instead, but this way you can apply
1344 settings before @value{GDBN} init files get executed and before inferior
1345 gets loaded.
1346
1347 @item
1348 Processes command line options and operands.
1349
1350 @item
1351 Reads and executes the commands from the initialization file (if any)
1352 in the current working directory as long as @samp{set auto-load
1353 local-gdbinit} is set to @samp{on} (@pxref{Init File in the Current
1354 Directory}). This is only done if the current directory is different
1355 from your home directory. Thus, you can have more than one init file,
1356 one generic in your home directory, and another, specific to the
1357 program you are debugging, in the directory where you invoke
1358 @value{GDBN}. @xref{Init File in the Current Directory during
1359 Startup}.
1360
1361 @item
1362 If the command line specified a program to debug, or a process to
1363 attach to, or a core file, @value{GDBN} loads any auto-loaded
1364 scripts provided for the program or for its loaded shared libraries.
1365 @xref{Auto-loading}.
1366
1367 If you wish to disable the auto-loading during startup,
1368 you must do something like the following:
1369
1370 @smallexample
1371 $ gdb -iex "set auto-load python-scripts off" myprogram
1372 @end smallexample
1373
1374 Option @samp{-ex} does not work because the auto-loading is then turned
1375 off too late.
1376
1377 @item
1378 Executes commands and command files specified by the @samp{-ex} and
1379 @samp{-x} options in their specified order. @xref{Command Files}, for
1380 more details about @value{GDBN} command files.
1381
1382 @item
1383 Reads the command history recorded in the @dfn{history file}.
1384 @xref{Command History}, for more details about the command history and the
1385 files where @value{GDBN} records it.
1386 @end enumerate
1387
1388 @node Initialization Files
1389 @subsection Initialization Files
1390 @cindex init file name
1391
1392 During startup (@pxref{Startup}) @value{GDBN} will execute commands
1393 from several initialization files. These initialization files use the
1394 same syntax as @dfn{command files} (@pxref{Command Files}) and are
1395 processed by @value{GDBN} in the same way.
1396
1397 To display the list of initialization files loaded by @value{GDBN} at
1398 startup, in the order they will be loaded, you can use @kbd{gdb
1399 --help}.
1400
1401 @cindex early initialization
1402 The @dfn{early initialization} file is loaded very early in
1403 @value{GDBN}'s initialization process, before the interpreter
1404 (@pxref{Interpreters}) has been initialized, and before the default
1405 target (@pxref{Targets}) is initialized. Only @code{set} or
1406 @code{source} commands should be placed into an early initialization
1407 file, and the only @code{set} commands that can be used are those that
1408 control how @value{GDBN} starts up.
1409
1410 Commands that can be placed into an early initialization file will be
1411 documented as such throughout this manual. Any command that is not
1412 documented as being suitable for an early initialization file should
1413 instead be placed into a general initialization file. Command files
1414 passed to @code{--early-init-command} or @code{-eix} are also early
1415 initialization files, with the same command restrictions. Only
1416 commands that can appear in an early initialization file should be
1417 passed to @code{--early-init-eval-command} or @code{-eiex}.
1418
1419 @cindex general initialization
1420 In contrast, the @dfn{general initialization} files are processed
1421 later, after @value{GDBN} has finished its own internal initialization
1422 process, any valid command can be used in these files.
1423
1424 @cindex initialization file
1425 Throughout the rest of this document the term @dfn{initialization
1426 file} refers to one of the general initialization files, not the early
1427 initialization file. Any discussion of the early initialization file
1428 will specifically mention that it is the early initialization file
1429 being discussed.
1430
1431 As the system wide and home directory initialization files are
1432 processed before most command line options, changes to settings
1433 (e.g. @samp{set complaints}) can affect subsequent processing of
1434 command line options and operands.
1435
1436 The following sections describe where @value{GDBN} looks for the early
1437 initialization and initialization files, and the order that the files
1438 are searched for.
1439
1440 @subsubsection Home directory early initialization files
1441
1442 @value{GDBN} initially looks for an early initialization file in the
1443 users home directory@footnote{On DOS/Windows systems, the home
1444 directory is the one pointed to by the @code{HOME} environment
1445 variable.}. There are a number of locations that @value{GDBN} will
1446 search in the home directory, these locations are searched in order
1447 and @value{GDBN} will load the first file that it finds, and
1448 subsequent locations will not be checked.
1449
1450 On non-macOS hosts the locations searched are:
1451 @itemize
1452 @item
1453 The file @file{gdb/gdbearlyinit} within the directory pointed to by the
1454 environment variable @env{XDG_CONFIG_HOME}, if it is defined.
1455 @item
1456 The file @file{.config/gdb/gdbearlyinit} within the directory pointed to
1457 by the environment variable @env{HOME}, if it is defined.
1458 @item
1459 The file @file{.gdbearlyinit} within the directory pointed to by the
1460 environment variable @env{HOME}, if it is defined.
1461 @end itemize
1462
1463 By contrast, on macOS hosts the locations searched are:
1464 @itemize
1465 @item
1466 The file @file{Library/Preferences/gdb/gdbearlyinit} within the
1467 directory pointed to by the environment variable @env{HOME}, if it is
1468 defined.
1469 @item
1470 The file @file{.gdbearlyinit} within the directory pointed to by the
1471 environment variable @env{HOME}, if it is defined.
1472 @end itemize
1473
1474 It is possible to prevent the home directory early initialization file
1475 from being loaded using the @samp{-nx} or @samp{-nh} command line
1476 options, @pxref{Mode Options,,Choosing Modes}.
1477
1478 @anchor{System Wide Init Files}
1479 @subsubsection System wide initialization files
1480
1481 There are two locations that are searched for system wide
1482 initialization files. Both of these locations are always checked:
1483
1484 @table @code
1485
1486 @item @file{system.gdbinit}
1487 This is a single system-wide initialization file. Its location is
1488 specified with the @code{--with-system-gdbinit} configure option
1489 (@pxref{System-wide configuration}). It is loaded first when
1490 @value{GDBN} starts, before command line options have been processed.
1491
1492 @item @file{system.gdbinit.d}
1493 This is the system-wide initialization directory. Its location is
1494 specified with the @code{--with-system-gdbinit-dir} configure option
1495 (@pxref{System-wide configuration}). Files in this directory are
1496 loaded in alphabetical order immediately after @file{system.gdbinit}
1497 (if enabled) when @value{GDBN} starts, before command line options
1498 have been processed. Files need to have a recognized scripting
1499 language extension (@file{.py}/@file{.scm}) or be named with a
1500 @file{.gdb} extension to be interpreted as regular @value{GDBN}
1501 commands. @value{GDBN} will not recurse into any subdirectories of
1502 this directory.
1503
1504 @end table
1505
1506 It is possible to prevent the system wide initialization files from
1507 being loaded using the @samp{-nx} command line option, @pxref{Mode
1508 Options,,Choosing Modes}.
1509
1510 @anchor{Home Directory Init File}
1511 @subsubsection Home directory initialization file
1512 @cindex @file{gdbinit}
1513 @cindex @file{.gdbinit}
1514 @cindex @file{gdb.ini}
1515
1516 After loading the system wide initialization files @value{GDBN} will
1517 look for an initialization file in the users home
1518 directory@footnote{On DOS/Windows systems, the home directory is the
1519 one pointed to by the @code{HOME} environment variable.}. There are a
1520 number of locations that @value{GDBN} will search in the home
1521 directory, these locations are searched in order and @value{GDBN} will
1522 load the first file that it finds, and subsequent locations will not
1523 be checked.
1524
1525 On non-Apple hosts the locations searched are:
1526 @table @file
1527 @item $XDG_CONFIG_HOME/gdb/gdbinit
1528 @item $HOME/.config/gdb/gdbinit
1529 @item $HOME/.gdbinit
1530 @end table
1531
1532 While on Apple hosts the locations searched are:
1533 @table @file
1534 @item $HOME/Library/Preferences/gdb/gdbinit
1535 @item $HOME/.gdbinit
1536 @end table
1537
1538 It is possible to prevent the home directory initialization file from
1539 being loaded using the @samp{-nx} or @samp{-nh} command line options,
1540 @pxref{Mode Options,,Choosing Modes}.
1541
1542 The DJGPP port of @value{GDBN} uses the name @file{gdb.ini} instead of
1543 @file{.gdbinit} or @file{gdbinit}, due to the limitations of file
1544 names imposed by DOS filesystems. The Windows port of @value{GDBN}
1545 uses the standard name, but if it finds a @file{gdb.ini} file in your
1546 home directory, it warns you about that and suggests to rename the
1547 file to the standard name.
1548
1549 @anchor{Init File in the Current Directory during Startup}
1550 @subsubsection Local directory initialization file
1551
1552 @value{GDBN} will check the current directory for a file called
1553 @file{.gdbinit}. It is loaded last, after command line options
1554 other than @samp{-x} and @samp{-ex} have been processed. The command
1555 line options @samp{-x} and @samp{-ex} are processed last, after
1556 @file{.gdbinit} has been loaded, @pxref{File Options,,Choosing
1557 Files}.
1558
1559 If the file in the current directory was already loaded as the home
1560 directory initialization file then it will not be loaded a second
1561 time.
1562
1563 It is possible to prevent the local directory initialization file from
1564 being loaded using the @samp{-nx} command line option, @pxref{Mode
1565 Options,,Choosing Modes}.
1566
1567 @node Quitting GDB
1568 @section Quitting @value{GDBN}
1569 @cindex exiting @value{GDBN}
1570 @cindex leaving @value{GDBN}
1571
1572 @table @code
1573 @kindex quit @r{[}@var{expression}@r{]}
1574 @kindex q @r{(@code{quit})}
1575 @item quit @r{[}@var{expression}@r{]}
1576 @itemx q
1577 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1578 @code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
1579 do not supply @var{expression}, @value{GDBN} will terminate normally;
1580 otherwise it will terminate using the result of @var{expression} as the
1581 error code.
1582 @end table
1583
1584 @cindex interrupt
1585 An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
1586 terminates the action of any @value{GDBN} command that is in progress and
1587 returns to @value{GDBN} command level. It is safe to type the interrupt
1588 character at any time because @value{GDBN} does not allow it to take effect
1589 until a time when it is safe.
1590
1591 If you have been using @value{GDBN} to control an attached process or
1592 device, you can release it with the @code{detach} command
1593 (@pxref{Attach, ,Debugging an Already-running Process}).
1594
1595 @node Shell Commands
1596 @section Shell Commands
1597
1598 If you need to execute occasional shell commands during your
1599 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1600 just use the @code{shell} command.
1601
1602 @table @code
1603 @kindex shell
1604 @kindex !
1605 @cindex shell escape
1606 @item shell @var{command-string}
1607 @itemx !@var{command-string}
1608 Invoke a standard shell to execute @var{command-string}.
1609 Note that no space is needed between @code{!} and @var{command-string}.
1610 On GNU and Unix systems, the environment variable @code{SHELL}, if it
1611 exists, determines which shell to run. Otherwise @value{GDBN} uses
1612 the default shell (@file{/bin/sh} on GNU and Unix systems,
1613 @file{cmd.exe} on MS-Windows, @file{COMMAND.COM} on MS-DOS, etc.).
1614 @end table
1615
1616 The utility @code{make} is often needed in development environments.
1617 You do not have to use the @code{shell} command for this purpose in
1618 @value{GDBN}:
1619
1620 @table @code
1621 @kindex make
1622 @cindex calling make
1623 @item make @var{make-args}
1624 Execute the @code{make} program with the specified
1625 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1626 @end table
1627
1628 @table @code
1629 @kindex pipe
1630 @kindex |
1631 @cindex send the output of a gdb command to a shell command
1632 @anchor{pipe}
1633 @item pipe [@var{command}] | @var{shell_command}
1634 @itemx | [@var{command}] | @var{shell_command}
1635 @itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1636 @itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1637 Executes @var{command} and sends its output to @var{shell_command}.
1638 Note that no space is needed around @code{|}.
1639 If no @var{command} is provided, the last command executed is repeated.
1640
1641 In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1642 can be used to specify an alternate delimiter string @var{delim} that separates
1643 the @var{command} from the @var{shell_command}.
1644
1645 Example:
1646 @smallexample
1647 @group
1648 (gdb) p var
1649 $1 = @{
1650 black = 144,
1651 red = 233,
1652 green = 377,
1653 blue = 610,
1654 white = 987
1655 @}
1656 @end group
1657 @group
1658 (gdb) pipe p var|wc
1659 7 19 80
1660 (gdb) |p var|wc -l
1661 7
1662 @end group
1663 @group
1664 (gdb) p /x var
1665 $4 = @{
1666 black = 0x90,
1667 red = 0xe9,
1668 green = 0x179,
1669 blue = 0x262,
1670 white = 0x3db
1671 @}
1672 (gdb) ||grep red
1673 red => 0xe9,
1674 @end group
1675 @group
1676 (gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1677 this contains a PIPE char
1678 (gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1679 this contains a PIPE char!
1680 (gdb)
1681 @end group
1682 @end smallexample
1683 @end table
1684
1685 The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1686 can be used to examine the exit status of the last shell command launched
1687 by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1688 @xref{Convenience Vars,, Convenience Variables}.
1689
1690 @node Logging Output
1691 @section Logging Output
1692 @cindex logging @value{GDBN} output
1693 @cindex save @value{GDBN} output to a file
1694
1695 You may want to save the output of @value{GDBN} commands to a file.
1696 There are several commands to control @value{GDBN}'s logging.
1697
1698 @table @code
1699 @kindex set logging
1700 @item set logging on
1701 Enable logging.
1702 @item set logging off
1703 Disable logging.
1704 @cindex logging file name
1705 @item set logging file @var{file}
1706 Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1707 @item set logging overwrite [on|off]
1708 By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1709 you want @code{set logging on} to overwrite the logfile instead.
1710 @item set logging redirect [on|off]
1711 By default, @value{GDBN} output will go to both the terminal and the logfile.
1712 Set @code{redirect} if you want output to go only to the log file.
1713 @item set logging debugredirect [on|off]
1714 By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1715 Set @code{debugredirect} if you want debug output to go only to the log file.
1716 @kindex show logging
1717 @item show logging
1718 Show the current values of the logging settings.
1719 @end table
1720
1721 You can also redirect the output of a @value{GDBN} command to a
1722 shell command. @xref{pipe}.
1723 @node Commands
1724 @chapter @value{GDBN} Commands
1725
1726 You can abbreviate a @value{GDBN} command to the first few letters of the command
1727 name, if that abbreviation is unambiguous; and you can repeat certain
1728 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1729 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1730 show you the alternatives available, if there is more than one possibility).
1731
1732 @menu
1733 * Command Syntax:: How to give commands to @value{GDBN}
1734 * Command Settings:: How to change default behavior of commands
1735 * Completion:: Command completion
1736 * Command Options:: Command options
1737 * Help:: How to ask @value{GDBN} for help
1738 @end menu
1739
1740 @node Command Syntax
1741 @section Command Syntax
1742
1743 A @value{GDBN} command is a single line of input. There is no limit on
1744 how long it can be. It starts with a command name, which is followed by
1745 arguments whose meaning depends on the command name. For example, the
1746 command @code{step} accepts an argument which is the number of times to
1747 step, as in @samp{step 5}. You can also use the @code{step} command
1748 with no arguments. Some commands do not allow any arguments.
1749
1750 @cindex abbreviation
1751 @value{GDBN} command names may always be truncated if that abbreviation is
1752 unambiguous. Other possible command abbreviations are listed in the
1753 documentation for individual commands. In some cases, even ambiguous
1754 abbreviations are allowed; for example, @code{s} is specially defined as
1755 equivalent to @code{step} even though there are other commands whose
1756 names start with @code{s}. You can test abbreviations by using them as
1757 arguments to the @code{help} command.
1758
1759 @cindex repeating commands
1760 @kindex RET @r{(repeat last command)}
1761 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1762 repeat the previous command. Certain commands (for example, @code{run})
1763 will not repeat this way; these are commands whose unintentional
1764 repetition might cause trouble and which you are unlikely to want to
1765 repeat. User-defined commands can disable this feature; see
1766 @ref{Define, dont-repeat}.
1767
1768 The @code{list} and @code{x} commands, when you repeat them with
1769 @key{RET}, construct new arguments rather than repeating
1770 exactly as typed. This permits easy scanning of source or memory.
1771
1772 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1773 output, in a way similar to the common utility @code{more}
1774 (@pxref{Screen Size,,Screen Size}). Since it is easy to press one
1775 @key{RET} too many in this situation, @value{GDBN} disables command
1776 repetition after any command that generates this sort of display.
1777
1778 @kindex # @r{(a comment)}
1779 @cindex comment
1780 Any text from a @kbd{#} to the end of the line is a comment; it does
1781 nothing. This is useful mainly in command files (@pxref{Command
1782 Files,,Command Files}).
1783
1784 @cindex repeating command sequences
1785 @kindex Ctrl-o @r{(operate-and-get-next)}
1786 The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1787 commands. This command accepts the current line, like @key{RET}, and
1788 then fetches the next line relative to the current line from the history
1789 for editing.
1790
1791
1792 @node Command Settings
1793 @section Command Settings
1794 @cindex default behavior of commands, changing
1795 @cindex default settings, changing
1796
1797 Many commands change their behavior according to command-specific
1798 variables or settings. These settings can be changed with the
1799 @code{set} subcommands. For example, the @code{print} command
1800 (@pxref{Data, ,Examining Data}) prints arrays differently depending on
1801 settings changeable with the commands @code{set print elements
1802 NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1803
1804 You can change these settings to your preference in the gdbinit files
1805 loaded at @value{GDBN} startup. @xref{Startup}.
1806
1807 The settings can also be changed interactively during the debugging
1808 session. For example, to change the limit of array elements to print,
1809 you can do the following:
1810 @smallexample
1811 (@value{GDBN}) set print elements 10
1812 (@value{GDBN}) print some_array
1813 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1814 @end smallexample
1815
1816 The above @code{set print elements 10} command changes the number of
1817 elements to print from the default of 200 to 10. If you only intend
1818 this limit of 10 to be used for printing @code{some_array}, then you
1819 must restore the limit back to 200, with @code{set print elements
1820 200}.
1821
1822 Some commands allow overriding settings with command options. For
1823 example, the @code{print} command supports a number of options that
1824 allow overriding relevant global print settings as set by @code{set
1825 print} subcommands. @xref{print options}. The example above could be
1826 rewritten as:
1827 @smallexample
1828 (@value{GDBN}) print -elements 10 -- some_array
1829 $1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1830 @end smallexample
1831
1832 Alternatively, you can use the @code{with} command to change a setting
1833 temporarily, for the duration of a command invocation.
1834
1835 @table @code
1836 @kindex with command
1837 @kindex w @r{(@code{with})}
1838 @cindex settings
1839 @cindex temporarily change settings
1840 @item with @var{setting} [@var{value}] [-- @var{command}]
1841 @itemx w @var{setting} [@var{value}] [-- @var{command}]
1842 Temporarily set @var{setting} to @var{value} for the duration of
1843 @var{command}.
1844
1845 @var{setting} is any setting you can change with the @code{set}
1846 subcommands. @var{value} is the value to assign to @code{setting}
1847 while running @code{command}.
1848
1849 If no @var{command} is provided, the last command executed is
1850 repeated.
1851
1852 If a @var{command} is provided, it must be preceded by a double dash
1853 (@code{--}) separator. This is required because some settings accept
1854 free-form arguments, such as expressions or filenames.
1855
1856 For example, the command
1857 @smallexample
1858 (@value{GDBN}) with print array on -- print some_array
1859 @end smallexample
1860 @noindent
1861 is equivalent to the following 3 commands:
1862 @smallexample
1863 (@value{GDBN}) set print array on
1864 (@value{GDBN}) print some_array
1865 (@value{GDBN}) set print array off
1866 @end smallexample
1867
1868 The @code{with} command is particularly useful when you want to
1869 override a setting while running user-defined commands, or commands
1870 defined in Python or Guile. @xref{Extending GDB,, Extending GDB}.
1871
1872 @smallexample
1873 (@value{GDBN}) with print pretty on -- my_complex_command
1874 @end smallexample
1875
1876 To change several settings for the same command, you can nest
1877 @code{with} commands. For example, @code{with language ada -- with
1878 print elements 10} temporarily changes the language to Ada and sets a
1879 limit of 10 elements to print for arrays and strings.
1880
1881 @end table
1882
1883 @node Completion
1884 @section Command Completion
1885
1886 @cindex completion
1887 @cindex word completion
1888 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1889 only one possibility; it can also show you what the valid possibilities
1890 are for the next word in a command, at any time. This works for @value{GDBN}
1891 commands, @value{GDBN} subcommands, command options, and the names of symbols
1892 in your program.
1893
1894 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1895 of a word. If there is only one possibility, @value{GDBN} fills in the
1896 word, and waits for you to finish the command (or press @key{RET} to
1897 enter it). For example, if you type
1898
1899 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1900 @c complete accuracy in these examples; space introduced for clarity.
1901 @c If texinfo enhancements make it unnecessary, it would be nice to
1902 @c replace " @key" by "@key" in the following...
1903 @smallexample
1904 (@value{GDBP}) info bre @key{TAB}
1905 @end smallexample
1906
1907 @noindent
1908 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1909 the only @code{info} subcommand beginning with @samp{bre}:
1910
1911 @smallexample
1912 (@value{GDBP}) info breakpoints
1913 @end smallexample
1914
1915 @noindent
1916 You can either press @key{RET} at this point, to run the @code{info
1917 breakpoints} command, or backspace and enter something else, if
1918 @samp{breakpoints} does not look like the command you expected. (If you
1919 were sure you wanted @code{info breakpoints} in the first place, you
1920 might as well just type @key{RET} immediately after @samp{info bre},
1921 to exploit command abbreviations rather than command completion).
1922
1923 If there is more than one possibility for the next word when you press
1924 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1925 characters and try again, or just press @key{TAB} a second time;
1926 @value{GDBN} displays all the possible completions for that word. For
1927 example, you might want to set a breakpoint on a subroutine whose name
1928 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1929 just sounds the bell. Typing @key{TAB} again displays all the
1930 function names in your program that begin with those characters, for
1931 example:
1932
1933 @smallexample
1934 (@value{GDBP}) b make_ @key{TAB}
1935 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1936 make_a_section_from_file make_environ
1937 make_abs_section make_function_type
1938 make_blockvector make_pointer_type
1939 make_cleanup make_reference_type
1940 make_command make_symbol_completion_list
1941 (@value{GDBP}) b make_
1942 @end smallexample
1943
1944 @noindent
1945 After displaying the available possibilities, @value{GDBN} copies your
1946 partial input (@samp{b make_} in the example) so you can finish the
1947 command.
1948
1949 If you just want to see the list of alternatives in the first place, you
1950 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1951 means @kbd{@key{META} ?}. You can type this either by holding down a
1952 key designated as the @key{META} shift on your keyboard (if there is
1953 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1954
1955 If the number of possible completions is large, @value{GDBN} will
1956 print as much of the list as it has collected, as well as a message
1957 indicating that the list may be truncated.
1958
1959 @smallexample
1960 (@value{GDBP}) b m@key{TAB}@key{TAB}
1961 main
1962 <... the rest of the possible completions ...>
1963 *** List may be truncated, max-completions reached. ***
1964 (@value{GDBP}) b m
1965 @end smallexample
1966
1967 @noindent
1968 This behavior can be controlled with the following commands:
1969
1970 @table @code
1971 @kindex set max-completions
1972 @item set max-completions @var{limit}
1973 @itemx set max-completions unlimited
1974 Set the maximum number of completion candidates. @value{GDBN} will
1975 stop looking for more completions once it collects this many candidates.
1976 This is useful when completing on things like function names as collecting
1977 all the possible candidates can be time consuming.
1978 The default value is 200. A value of zero disables tab-completion.
1979 Note that setting either no limit or a very large limit can make
1980 completion slow.
1981 @kindex show max-completions
1982 @item show max-completions
1983 Show the maximum number of candidates that @value{GDBN} will collect and show
1984 during completion.
1985 @end table
1986
1987 @cindex quotes in commands
1988 @cindex completion of quoted strings
1989 Sometimes the string you need, while logically a ``word'', may contain
1990 parentheses or other characters that @value{GDBN} normally excludes from
1991 its notion of a word. To permit word completion to work in this
1992 situation, you may enclose words in @code{'} (single quote marks) in
1993 @value{GDBN} commands.
1994
1995 A likely situation where you might need this is in typing an
1996 expression that involves a C@t{++} symbol name with template
1997 parameters. This is because when completing expressions, GDB treats
1998 the @samp{<} character as word delimiter, assuming that it's the
1999 less-than comparison operator (@pxref{C Operators, , C and C@t{++}
2000 Operators}).
2001
2002 For example, when you want to call a C@t{++} template function
2003 interactively using the @code{print} or @code{call} commands, you may
2004 need to distinguish whether you mean the version of @code{name} that
2005 was specialized for @code{int}, @code{name<int>()}, or the version
2006 that was specialized for @code{float}, @code{name<float>()}. To use
2007 the word-completion facilities in this situation, type a single quote
2008 @code{'} at the beginning of the function name. This alerts
2009 @value{GDBN} that it may need to consider more information than usual
2010 when you press @key{TAB} or @kbd{M-?} to request word completion:
2011
2012 @smallexample
2013 (@value{GDBP}) p 'func< @kbd{M-?}
2014 func<int>() func<float>()
2015 (@value{GDBP}) p 'func<
2016 @end smallexample
2017
2018 When setting breakpoints however (@pxref{Specify Location}), you don't
2019 usually need to type a quote before the function name, because
2020 @value{GDBN} understands that you want to set a breakpoint on a
2021 function:
2022
2023 @smallexample
2024 (@value{GDBP}) b func< @kbd{M-?}
2025 func<int>() func<float>()
2026 (@value{GDBP}) b func<
2027 @end smallexample
2028
2029 This is true even in the case of typing the name of C@t{++} overloaded
2030 functions (multiple definitions of the same function, distinguished by
2031 argument type). For example, when you want to set a breakpoint you
2032 don't need to distinguish whether you mean the version of @code{name}
2033 that takes an @code{int} parameter, @code{name(int)}, or the version
2034 that takes a @code{float} parameter, @code{name(float)}.
2035
2036 @smallexample
2037 (@value{GDBP}) b bubble( @kbd{M-?}
2038 bubble(int) bubble(double)
2039 (@value{GDBP}) b bubble(dou @kbd{M-?}
2040 bubble(double)
2041 @end smallexample
2042
2043 See @ref{quoting names} for a description of other scenarios that
2044 require quoting.
2045
2046 For more information about overloaded functions, see @ref{C Plus Plus
2047 Expressions, ,C@t{++} Expressions}. You can use the command @code{set
2048 overload-resolution off} to disable overload resolution;
2049 see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
2050
2051 @cindex completion of structure field names
2052 @cindex structure field name completion
2053 @cindex completion of union field names
2054 @cindex union field name completion
2055 When completing in an expression which looks up a field in a
2056 structure, @value{GDBN} also tries@footnote{The completer can be
2057 confused by certain kinds of invalid expressions. Also, it only
2058 examines the static type of the expression, not the dynamic type.} to
2059 limit completions to the field names available in the type of the
2060 left-hand-side:
2061
2062 @smallexample
2063 (@value{GDBP}) p gdb_stdout.@kbd{M-?}
2064 magic to_fputs to_rewind
2065 to_data to_isatty to_write
2066 to_delete to_put to_write_async_safe
2067 to_flush to_read
2068 @end smallexample
2069
2070 @noindent
2071 This is because the @code{gdb_stdout} is a variable of the type
2072 @code{struct ui_file} that is defined in @value{GDBN} sources as
2073 follows:
2074
2075 @smallexample
2076 struct ui_file
2077 @{
2078 int *magic;
2079 ui_file_flush_ftype *to_flush;
2080 ui_file_write_ftype *to_write;
2081 ui_file_write_async_safe_ftype *to_write_async_safe;
2082 ui_file_fputs_ftype *to_fputs;
2083 ui_file_read_ftype *to_read;
2084 ui_file_delete_ftype *to_delete;
2085 ui_file_isatty_ftype *to_isatty;
2086 ui_file_rewind_ftype *to_rewind;
2087 ui_file_put_ftype *to_put;
2088 void *to_data;
2089 @}
2090 @end smallexample
2091
2092 @node Command Options
2093 @section Command options
2094
2095 @cindex command options
2096 Some commands accept options starting with a leading dash. For
2097 example, @code{print -pretty}. Similarly to command names, you can
2098 abbreviate a @value{GDBN} option to the first few letters of the
2099 option name, if that abbreviation is unambiguous, and you can also use
2100 the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
2101 in an option (or to show you the alternatives available, if there is
2102 more than one possibility).
2103
2104 @cindex command options, raw input
2105 Some commands take raw input as argument. For example, the print
2106 command processes arbitrary expressions in any of the languages
2107 supported by @value{GDBN}. With such commands, because raw input may
2108 start with a leading dash that would be confused with an option or any
2109 of its abbreviations, e.g.@: @code{print -p} (short for @code{print
2110 -pretty} or printing negative @code{p}?), if you specify any command
2111 option, then you must use a double-dash (@code{--}) delimiter to
2112 indicate the end of options.
2113
2114 @cindex command options, boolean
2115
2116 Some options are described as accepting an argument which can be
2117 either @code{on} or @code{off}. These are known as @dfn{boolean
2118 options}. Similarly to boolean settings commands---@code{on} and
2119 @code{off} are the typical values, but any of @code{1}, @code{yes} and
2120 @code{enable} can also be used as ``true'' value, and any of @code{0},
2121 @code{no} and @code{disable} can also be used as ``false'' value. You
2122 can also omit a ``true'' value, as it is implied by default.
2123
2124 For example, these are equivalent:
2125
2126 @smallexample
2127 (@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
2128 (@value{GDBP}) p -o -p 0 -e u -- *myptr
2129 @end smallexample
2130
2131 You can discover the set of options some command accepts by completing
2132 on @code{-} after the command name. For example:
2133
2134 @smallexample
2135 (@value{GDBP}) print -@key{TAB}@key{TAB}
2136 -address -max-depth -raw-values -union
2137 -array -null-stop -repeats -vtbl
2138 -array-indexes -object -static-members
2139 -elements -pretty -symbol
2140 @end smallexample
2141
2142 Completion will in some cases guide you with a suggestion of what kind
2143 of argument an option expects. For example:
2144
2145 @smallexample
2146 (@value{GDBP}) print -elements @key{TAB}@key{TAB}
2147 NUMBER unlimited
2148 @end smallexample
2149
2150 Here, the option expects a number (e.g., @code{100}), not literal
2151 @code{NUMBER}. Such metasyntactical arguments are always presented in
2152 uppercase.
2153
2154 (For more on using the @code{print} command, see @ref{Data, ,Examining
2155 Data}.)
2156
2157 @node Help
2158 @section Getting Help
2159 @cindex online documentation
2160 @kindex help
2161
2162 You can always ask @value{GDBN} itself for information on its commands,
2163 using the command @code{help}.
2164
2165 @table @code
2166 @kindex h @r{(@code{help})}
2167 @item help
2168 @itemx h
2169 You can use @code{help} (abbreviated @code{h}) with no arguments to
2170 display a short list of named classes of commands:
2171
2172 @smallexample
2173 (@value{GDBP}) help
2174 List of classes of commands:
2175
2176 aliases -- User-defined aliases of other commands
2177 breakpoints -- Making program stop at certain points
2178 data -- Examining data
2179 files -- Specifying and examining files
2180 internals -- Maintenance commands
2181 obscure -- Obscure features
2182 running -- Running the program
2183 stack -- Examining the stack
2184 status -- Status inquiries
2185 support -- Support facilities
2186 tracepoints -- Tracing of program execution without
2187 stopping the program
2188 user-defined -- User-defined commands
2189
2190 Type "help" followed by a class name for a list of
2191 commands in that class.
2192 Type "help" followed by command name for full
2193 documentation.
2194 Command name abbreviations are allowed if unambiguous.
2195 (@value{GDBP})
2196 @end smallexample
2197 @c the above line break eliminates huge line overfull...
2198
2199 @item help @var{class}
2200 Using one of the general help classes as an argument, you can get a
2201 list of the individual commands in that class. If a command has
2202 aliases, the aliases are given after the command name, separated by
2203 commas. If an alias has default arguments, the full definition of
2204 the alias is given after the first line.
2205 For example, here is the help display for the class @code{status}:
2206
2207 @smallexample
2208 (@value{GDBP}) help status
2209 Status inquiries.
2210
2211 List of commands:
2212
2213 @c Line break in "show" line falsifies real output, but needed
2214 @c to fit in smallbook page size.
2215 info, inf, i -- Generic command for showing things
2216 about the program being debugged
2217 info address, iamain -- Describe where symbol SYM is stored.
2218 alias iamain = info address main
2219 info all-registers -- List of all registers and their contents,
2220 for selected stack frame.
2221 ...
2222 show, info set -- Generic command for showing things
2223 about the debugger
2224
2225 Type "help" followed by command name for full
2226 documentation.
2227 Command name abbreviations are allowed if unambiguous.
2228 (@value{GDBP})
2229 @end smallexample
2230
2231 @item help @var{command}
2232 With a command name as @code{help} argument, @value{GDBN} displays a
2233 short paragraph on how to use that command. If that command has
2234 one or more aliases, @value{GDBN} will display a first line with
2235 the command name and all its aliases separated by commas.
2236 This first line will be followed by the full definition of all aliases
2237 having default arguments.
2238
2239 @kindex apropos
2240 @item apropos [-v] @var{regexp}
2241 The @code{apropos} command searches through all of the @value{GDBN}
2242 commands, and their documentation, for the regular expression specified in
2243 @var{args}. It prints out all matches found. The optional flag @samp{-v},
2244 which stands for @samp{verbose}, indicates to output the full documentation
2245 of the matching commands and highlight the parts of the documentation
2246 matching @var{regexp}. For example:
2247
2248 @smallexample
2249 apropos alias
2250 @end smallexample
2251
2252 @noindent
2253 results in:
2254
2255 @smallexample
2256 @group
2257 alias -- Define a new command that is an alias of an existing command
2258 aliases -- User-defined aliases of other commands
2259 @end group
2260 @end smallexample
2261
2262 @noindent
2263 while
2264
2265 @smallexample
2266 apropos -v cut.*thread apply
2267 @end smallexample
2268
2269 @noindent
2270 results in the below output, where @samp{cut for 'thread apply}
2271 is highlighted if styling is enabled.
2272
2273 @smallexample
2274 @group
2275 taas -- Apply a command to all threads (ignoring errors
2276 and empty output).
2277 Usage: taas COMMAND
2278 shortcut for 'thread apply all -s COMMAND'
2279
2280 tfaas -- Apply a command to all frames of all threads
2281 (ignoring errors and empty output).
2282 Usage: tfaas COMMAND
2283 shortcut for 'thread apply all -s frame apply all -s COMMAND'
2284 @end group
2285 @end smallexample
2286
2287 @kindex complete
2288 @item complete @var{args}
2289 The @code{complete @var{args}} command lists all the possible completions
2290 for the beginning of a command. Use @var{args} to specify the beginning of the
2291 command you want completed. For example:
2292
2293 @smallexample
2294 complete i
2295 @end smallexample
2296
2297 @noindent results in:
2298
2299 @smallexample
2300 @group
2301 if
2302 ignore
2303 info
2304 inspect
2305 @end group
2306 @end smallexample
2307
2308 @noindent This is intended for use by @sc{gnu} Emacs.
2309 @end table
2310
2311 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2312 and @code{show} to inquire about the state of your program, or the state
2313 of @value{GDBN} itself. Each command supports many topics of inquiry; this
2314 manual introduces each of them in the appropriate context. The listings
2315 under @code{info} and under @code{show} in the Command, Variable, and
2316 Function Index point to all the sub-commands. @xref{Command and Variable
2317 Index}.
2318
2319 @c @group
2320 @table @code
2321 @kindex info
2322 @kindex i @r{(@code{info})}
2323 @item info
2324 This command (abbreviated @code{i}) is for describing the state of your
2325 program. For example, you can show the arguments passed to a function
2326 with @code{info args}, list the registers currently in use with @code{info
2327 registers}, or list the breakpoints you have set with @code{info breakpoints}.
2328 You can get a complete list of the @code{info} sub-commands with
2329 @w{@code{help info}}.
2330
2331 @kindex set
2332 @item set
2333 You can assign the result of an expression to an environment variable with
2334 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2335 @code{set prompt $}.
2336
2337 @kindex show
2338 @item show
2339 In contrast to @code{info}, @code{show} is for describing the state of
2340 @value{GDBN} itself.
2341 You can change most of the things you can @code{show}, by using the
2342 related command @code{set}; for example, you can control what number
2343 system is used for displays with @code{set radix}, or simply inquire
2344 which is currently in use with @code{show radix}.
2345
2346 @kindex info set
2347 To display all the settable parameters and their current
2348 values, you can use @code{show} with no arguments; you may also use
2349 @code{info set}. Both commands produce the same display.
2350 @c FIXME: "info set" violates the rule that "info" is for state of
2351 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2352 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2353 @end table
2354 @c @end group
2355
2356 Here are several miscellaneous @code{show} subcommands, all of which are
2357 exceptional in lacking corresponding @code{set} commands:
2358
2359 @table @code
2360 @kindex show version
2361 @cindex @value{GDBN} version number
2362 @item show version
2363 Show what version of @value{GDBN} is running. You should include this
2364 information in @value{GDBN} bug-reports. If multiple versions of
2365 @value{GDBN} are in use at your site, you may need to determine which
2366 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2367 commands are introduced, and old ones may wither away. Also, many
2368 system vendors ship variant versions of @value{GDBN}, and there are
2369 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2370 The version number is the same as the one announced when you start
2371 @value{GDBN}.
2372
2373 @kindex show copying
2374 @kindex info copying
2375 @cindex display @value{GDBN} copyright
2376 @item show copying
2377 @itemx info copying
2378 Display information about permission for copying @value{GDBN}.
2379
2380 @kindex show warranty
2381 @kindex info warranty
2382 @item show warranty
2383 @itemx info warranty
2384 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
2385 if your version of @value{GDBN} comes with one.
2386
2387 @kindex show configuration
2388 @item show configuration
2389 Display detailed information about the way @value{GDBN} was configured
2390 when it was built. This displays the optional arguments passed to the
2391 @file{configure} script and also configuration parameters detected
2392 automatically by @command{configure}. When reporting a @value{GDBN}
2393 bug (@pxref{GDB Bugs}), it is important to include this information in
2394 your report.
2395
2396 @end table
2397
2398 @node Running
2399 @chapter Running Programs Under @value{GDBN}
2400
2401 When you run a program under @value{GDBN}, you must first generate
2402 debugging information when you compile it.
2403
2404 You may start @value{GDBN} with its arguments, if any, in an environment
2405 of your choice. If you are doing native debugging, you may redirect
2406 your program's input and output, debug an already running process, or
2407 kill a child process.
2408
2409 @menu
2410 * Compilation:: Compiling for debugging
2411 * Starting:: Starting your program
2412 * Arguments:: Your program's arguments
2413 * Environment:: Your program's environment
2414
2415 * Working Directory:: Your program's working directory
2416 * Input/Output:: Your program's input and output
2417 * Attach:: Debugging an already-running process
2418 * Kill Process:: Killing the child process
2419 * Inferiors Connections and Programs:: Debugging multiple inferiors
2420 connections and programs
2421 * Threads:: Debugging programs with multiple threads
2422 * Forks:: Debugging forks
2423 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
2424 @end menu
2425
2426 @node Compilation
2427 @section Compiling for Debugging
2428
2429 In order to debug a program effectively, you need to generate
2430 debugging information when you compile it. This debugging information
2431 is stored in the object file; it describes the data type of each
2432 variable or function and the correspondence between source line numbers
2433 and addresses in the executable code.
2434
2435 To request debugging information, specify the @samp{-g} option when you run
2436 the compiler.
2437
2438 Programs that are to be shipped to your customers are compiled with
2439 optimizations, using the @samp{-O} compiler option. However, some
2440 compilers are unable to handle the @samp{-g} and @samp{-O} options
2441 together. Using those compilers, you cannot generate optimized
2442 executables containing debugging information.
2443
2444 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
2445 without @samp{-O}, making it possible to debug optimized code. We
2446 recommend that you @emph{always} use @samp{-g} whenever you compile a
2447 program. You may think your program is correct, but there is no sense
2448 in pushing your luck. For more information, see @ref{Optimized Code}.
2449
2450 Older versions of the @sc{gnu} C compiler permitted a variant option
2451 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2452 format; if your @sc{gnu} C compiler has this option, do not use it.
2453
2454 @value{GDBN} knows about preprocessor macros and can show you their
2455 expansion (@pxref{Macros}). Most compilers do not include information
2456 about preprocessor macros in the debugging information if you specify
2457 the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2458 the @sc{gnu} C compiler, provides macro information if you are using
2459 the DWARF debugging format, and specify the option @option{-g3}.
2460
2461 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
2462 gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
2463 information on @value{NGCC} options affecting debug information.
2464
2465 You will have the best debugging experience if you use the latest
2466 version of the DWARF debugging format that your compiler supports.
2467 DWARF is currently the most expressive and best supported debugging
2468 format in @value{GDBN}.
2469
2470 @need 2000
2471 @node Starting
2472 @section Starting your Program
2473 @cindex starting
2474 @cindex running
2475
2476 @table @code
2477 @kindex run
2478 @kindex r @r{(@code{run})}
2479 @item run
2480 @itemx r
2481 Use the @code{run} command to start your program under @value{GDBN}.
2482 You must first specify the program name with an argument to
2483 @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2484 @value{GDBN}}), or by using the @code{file} or @code{exec-file}
2485 command (@pxref{Files, ,Commands to Specify Files}).
2486
2487 @end table
2488
2489 If you are running your program in an execution environment that
2490 supports processes, @code{run} creates an inferior process and makes
2491 that process run your program. In some environments without processes,
2492 @code{run} jumps to the start of your program. Other targets,
2493 like @samp{remote}, are always running. If you get an error
2494 message like this one:
2495
2496 @smallexample
2497 The "remote" target does not support "run".
2498 Try "help target" or "continue".
2499 @end smallexample
2500
2501 @noindent
2502 then use @code{continue} to run your program. You may need @code{load}
2503 first (@pxref{load}).
2504
2505 The execution of a program is affected by certain information it
2506 receives from its superior. @value{GDBN} provides ways to specify this
2507 information, which you must do @emph{before} starting your program. (You
2508 can change it after starting your program, but such changes only affect
2509 your program the next time you start it.) This information may be
2510 divided into four categories:
2511
2512 @table @asis
2513 @item The @emph{arguments.}
2514 Specify the arguments to give your program as the arguments of the
2515 @code{run} command. If a shell is available on your target, the shell
2516 is used to pass the arguments, so that you may use normal conventions
2517 (such as wildcard expansion or variable substitution) in describing
2518 the arguments.
2519 In Unix systems, you can control which shell is used with the
2520 @code{SHELL} environment variable. If you do not define @code{SHELL},
2521 @value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2522 use of any shell with the @code{set startup-with-shell} command (see
2523 below for details).
2524
2525 @item The @emph{environment.}
2526 Your program normally inherits its environment from @value{GDBN}, but you can
2527 use the @value{GDBN} commands @code{set environment} and @code{unset
2528 environment} to change parts of the environment that affect
2529 your program. @xref{Environment, ,Your Program's Environment}.
2530
2531 @item The @emph{working directory.}
2532 You can set your program's working directory with the command
2533 @kbd{set cwd}. If you do not set any working directory with this
2534 command, your program will inherit @value{GDBN}'s working directory if
2535 native debugging, or the remote server's working directory if remote
2536 debugging. @xref{Working Directory, ,Your Program's Working
2537 Directory}.
2538
2539 @item The @emph{standard input and output.}
2540 Your program normally uses the same device for standard input and
2541 standard output as @value{GDBN} is using. You can redirect input and output
2542 in the @code{run} command line, or you can use the @code{tty} command to
2543 set a different device for your program.
2544 @xref{Input/Output, ,Your Program's Input and Output}.
2545
2546 @cindex pipes
2547 @emph{Warning:} While input and output redirection work, you cannot use
2548 pipes to pass the output of the program you are debugging to another
2549 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2550 wrong program.
2551 @end table
2552
2553 When you issue the @code{run} command, your program begins to execute
2554 immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
2555 of how to arrange for your program to stop. Once your program has
2556 stopped, you may call functions in your program, using the @code{print}
2557 or @code{call} commands. @xref{Data, ,Examining Data}.
2558
2559 If the modification time of your symbol file has changed since the last
2560 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2561 table, and reads it again. When it does this, @value{GDBN} tries to retain
2562 your current breakpoints.
2563
2564 @table @code
2565 @kindex start
2566 @item start
2567 @cindex run to main procedure
2568 The name of the main procedure can vary from language to language.
2569 With C or C@t{++}, the main procedure name is always @code{main}, but
2570 other languages such as Ada do not require a specific name for their
2571 main procedure. The debugger provides a convenient way to start the
2572 execution of the program and to stop at the beginning of the main
2573 procedure, depending on the language used.
2574
2575 The @samp{start} command does the equivalent of setting a temporary
2576 breakpoint at the beginning of the main procedure and then invoking
2577 the @samp{run} command.
2578
2579 @cindex elaboration phase
2580 Some programs contain an @dfn{elaboration} phase where some startup code is
2581 executed before the main procedure is called. This depends on the
2582 languages used to write your program. In C@t{++}, for instance,
2583 constructors for static and global objects are executed before
2584 @code{main} is called. It is therefore possible that the debugger stops
2585 before reaching the main procedure. However, the temporary breakpoint
2586 will remain to halt execution.
2587
2588 Specify the arguments to give to your program as arguments to the
2589 @samp{start} command. These arguments will be given verbatim to the
2590 underlying @samp{run} command. Note that the same arguments will be
2591 reused if no argument is provided during subsequent calls to
2592 @samp{start} or @samp{run}.
2593
2594 It is sometimes necessary to debug the program during elaboration. In
2595 these cases, using the @code{start} command would stop the execution
2596 of your program too late, as the program would have already completed
2597 the elaboration phase. Under these circumstances, either insert
2598 breakpoints in your elaboration code before running your program or
2599 use the @code{starti} command.
2600
2601 @kindex starti
2602 @item starti
2603 @cindex run to first instruction
2604 The @samp{starti} command does the equivalent of setting a temporary
2605 breakpoint at the first instruction of a program's execution and then
2606 invoking the @samp{run} command. For programs containing an
2607 elaboration phase, the @code{starti} command will stop execution at
2608 the start of the elaboration phase.
2609
2610 @anchor{set exec-wrapper}
2611 @kindex set exec-wrapper
2612 @item set exec-wrapper @var{wrapper}
2613 @itemx show exec-wrapper
2614 @itemx unset exec-wrapper
2615 When @samp{exec-wrapper} is set, the specified wrapper is used to
2616 launch programs for debugging. @value{GDBN} starts your program
2617 with a shell command of the form @kbd{exec @var{wrapper}
2618 @var{program}}. Quoting is added to @var{program} and its
2619 arguments, but not to @var{wrapper}, so you should add quotes if
2620 appropriate for your shell. The wrapper runs until it executes
2621 your program, and then @value{GDBN} takes control.
2622
2623 You can use any program that eventually calls @code{execve} with
2624 its arguments as a wrapper. Several standard Unix utilities do
2625 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2626 with @code{exec "$@@"} will also work.
2627
2628 For example, you can use @code{env} to pass an environment variable to
2629 the debugged program, without setting the variable in your shell's
2630 environment:
2631
2632 @smallexample
2633 (@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2634 (@value{GDBP}) run
2635 @end smallexample
2636
2637 This command is available when debugging locally on most targets, excluding
2638 @sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2639
2640 @kindex set startup-with-shell
2641 @anchor{set startup-with-shell}
2642 @item set startup-with-shell
2643 @itemx set startup-with-shell on
2644 @itemx set startup-with-shell off
2645 @itemx show startup-with-shell
2646 On Unix systems, by default, if a shell is available on your target,
2647 @value{GDBN}) uses it to start your program. Arguments of the
2648 @code{run} command are passed to the shell, which does variable
2649 substitution, expands wildcard characters and performs redirection of
2650 I/O. In some circumstances, it may be useful to disable such use of a
2651 shell, for example, when debugging the shell itself or diagnosing
2652 startup failures such as:
2653
2654 @smallexample
2655 (@value{GDBP}) run
2656 Starting program: ./a.out
2657 During startup program terminated with signal SIGSEGV, Segmentation fault.
2658 @end smallexample
2659
2660 @noindent
2661 which indicates the shell or the wrapper specified with
2662 @samp{exec-wrapper} crashed, not your program. Most often, this is
2663 caused by something odd in your shell's non-interactive mode
2664 initialization file---such as @file{.cshrc} for C-shell,
2665 $@file{.zshenv} for the Z shell, or the file specified in the
2666 @samp{BASH_ENV} environment variable for BASH.
2667
2668 @anchor{set auto-connect-native-target}
2669 @kindex set auto-connect-native-target
2670 @item set auto-connect-native-target
2671 @itemx set auto-connect-native-target on
2672 @itemx set auto-connect-native-target off
2673 @itemx show auto-connect-native-target
2674
2675 By default, if the current inferior is not connected to any target yet
2676 (e.g., with @code{target remote}), the @code{run} command starts your
2677 program as a native process under @value{GDBN}, on your local machine.
2678 If you're sure you don't want to debug programs on your local machine,
2679 you can tell @value{GDBN} to not connect to the native target
2680 automatically with the @code{set auto-connect-native-target off}
2681 command.
2682
2683 If @code{on}, which is the default, and if the current inferior is not
2684 connected to a target already, the @code{run} command automaticaly
2685 connects to the native target, if one is available.
2686
2687 If @code{off}, and if the current inferior is not connected to a
2688 target already, the @code{run} command fails with an error:
2689
2690 @smallexample
2691 (@value{GDBP}) run
2692 Don't know how to run. Try "help target".
2693 @end smallexample
2694
2695 If the current inferior is already connected to a target, @value{GDBN}
2696 always uses it with the @code{run} command.
2697
2698 In any case, you can explicitly connect to the native target with the
2699 @code{target native} command. For example,
2700
2701 @smallexample
2702 (@value{GDBP}) set auto-connect-native-target off
2703 (@value{GDBP}) run
2704 Don't know how to run. Try "help target".
2705 (@value{GDBP}) target native
2706 (@value{GDBP}) run
2707 Starting program: ./a.out
2708 [Inferior 1 (process 10421) exited normally]
2709 @end smallexample
2710
2711 In case you connected explicitly to the @code{native} target,
2712 @value{GDBN} remains connected even if all inferiors exit, ready for
2713 the next @code{run} command. Use the @code{disconnect} command to
2714 disconnect.
2715
2716 Examples of other commands that likewise respect the
2717 @code{auto-connect-native-target} setting: @code{attach}, @code{info
2718 proc}, @code{info os}.
2719
2720 @kindex set disable-randomization
2721 @item set disable-randomization
2722 @itemx set disable-randomization on
2723 This option (enabled by default in @value{GDBN}) will turn off the native
2724 randomization of the virtual address space of the started program. This option
2725 is useful for multiple debugging sessions to make the execution better
2726 reproducible and memory addresses reusable across debugging sessions.
2727
2728 This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2729 On @sc{gnu}/Linux you can get the same behavior using
2730
2731 @smallexample
2732 (@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2733 @end smallexample
2734
2735 @item set disable-randomization off
2736 Leave the behavior of the started executable unchanged. Some bugs rear their
2737 ugly heads only when the program is loaded at certain addresses. If your bug
2738 disappears when you run the program under @value{GDBN}, that might be because
2739 @value{GDBN} by default disables the address randomization on platforms, such
2740 as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2741 disable-randomization off} to try to reproduce such elusive bugs.
2742
2743 On targets where it is available, virtual address space randomization
2744 protects the programs against certain kinds of security attacks. In these
2745 cases the attacker needs to know the exact location of a concrete executable
2746 code. Randomizing its location makes it impossible to inject jumps misusing
2747 a code at its expected addresses.
2748
2749 Prelinking shared libraries provides a startup performance advantage but it
2750 makes addresses in these libraries predictable for privileged processes by
2751 having just unprivileged access at the target system. Reading the shared
2752 library binary gives enough information for assembling the malicious code
2753 misusing it. Still even a prelinked shared library can get loaded at a new
2754 random address just requiring the regular relocation process during the
2755 startup. Shared libraries not already prelinked are always loaded at
2756 a randomly chosen address.
2757
2758 Position independent executables (PIE) contain position independent code
2759 similar to the shared libraries and therefore such executables get loaded at
2760 a randomly chosen address upon startup. PIE executables always load even
2761 already prelinked shared libraries at a random address. You can build such
2762 executable using @command{gcc -fPIE -pie}.
2763
2764 Heap (malloc storage), stack and custom mmap areas are always placed randomly
2765 (as long as the randomization is enabled).
2766
2767 @item show disable-randomization
2768 Show the current setting of the explicit disable of the native randomization of
2769 the virtual address space of the started program.
2770
2771 @end table
2772
2773 @node Arguments
2774 @section Your Program's Arguments
2775
2776 @cindex arguments (to your program)
2777 The arguments to your program can be specified by the arguments of the
2778 @code{run} command.
2779 They are passed to a shell, which expands wildcard characters and
2780 performs redirection of I/O, and thence to your program. Your
2781 @code{SHELL} environment variable (if it exists) specifies what shell
2782 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
2783 the default shell (@file{/bin/sh} on Unix).
2784
2785 On non-Unix systems, the program is usually invoked directly by
2786 @value{GDBN}, which emulates I/O redirection via the appropriate system
2787 calls, and the wildcard characters are expanded by the startup code of
2788 the program, not by the shell.
2789
2790 @code{run} with no arguments uses the same arguments used by the previous
2791 @code{run}, or those set by the @code{set args} command.
2792
2793 @table @code
2794 @kindex set args
2795 @item set args
2796 Specify the arguments to be used the next time your program is run. If
2797 @code{set args} has no arguments, @code{run} executes your program
2798 with no arguments. Once you have run your program with arguments,
2799 using @code{set args} before the next @code{run} is the only way to run
2800 it again without arguments.
2801
2802 @kindex show args
2803 @item show args
2804 Show the arguments to give your program when it is started.
2805 @end table
2806
2807 @node Environment
2808 @section Your Program's Environment
2809
2810 @cindex environment (of your program)
2811 The @dfn{environment} consists of a set of environment variables and
2812 their values. Environment variables conventionally record such things as
2813 your user name, your home directory, your terminal type, and your search
2814 path for programs to run. Usually you set up environment variables with
2815 the shell and they are inherited by all the other programs you run. When
2816 debugging, it can be useful to try running your program with a modified
2817 environment without having to start @value{GDBN} over again.
2818
2819 @table @code
2820 @kindex path
2821 @item path @var{directory}
2822 Add @var{directory} to the front of the @code{PATH} environment variable
2823 (the search path for executables) that will be passed to your program.
2824 The value of @code{PATH} used by @value{GDBN} does not change.
2825 You may specify several directory names, separated by whitespace or by a
2826 system-dependent separator character (@samp{:} on Unix, @samp{;} on
2827 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2828 is moved to the front, so it is searched sooner.
2829
2830 You can use the string @samp{$cwd} to refer to whatever is the current
2831 working directory at the time @value{GDBN} searches the path. If you
2832 use @samp{.} instead, it refers to the directory where you executed the
2833 @code{path} command. @value{GDBN} replaces @samp{.} in the
2834 @var{directory} argument (with the current path) before adding
2835 @var{directory} to the search path.
2836 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2837 @c document that, since repeating it would be a no-op.
2838
2839 @kindex show paths
2840 @item show paths
2841 Display the list of search paths for executables (the @code{PATH}
2842 environment variable).
2843
2844 @kindex show environment
2845 @item show environment @r{[}@var{varname}@r{]}
2846 Print the value of environment variable @var{varname} to be given to
2847 your program when it starts. If you do not supply @var{varname},
2848 print the names and values of all environment variables to be given to
2849 your program. You can abbreviate @code{environment} as @code{env}.
2850
2851 @kindex set environment
2852 @anchor{set environment}
2853 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2854 Set environment variable @var{varname} to @var{value}. The value
2855 changes for your program (and the shell @value{GDBN} uses to launch
2856 it), not for @value{GDBN} itself. The @var{value} may be any string; the
2857 values of environment variables are just strings, and any
2858 interpretation is supplied by your program itself. The @var{value}
2859 parameter is optional; if it is eliminated, the variable is set to a
2860 null value.
2861 @c "any string" here does not include leading, trailing
2862 @c blanks. Gnu asks: does anyone care?
2863
2864 For example, this command:
2865
2866 @smallexample
2867 set env USER = foo
2868 @end smallexample
2869
2870 @noindent
2871 tells the debugged program, when subsequently run, that its user is named
2872 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2873 are not actually required.)
2874
2875 Note that on Unix systems, @value{GDBN} runs your program via a shell,
2876 which also inherits the environment set with @code{set environment}.
2877 If necessary, you can avoid that by using the @samp{env} program as a
2878 wrapper instead of using @code{set environment}. @xref{set
2879 exec-wrapper}, for an example doing just that.
2880
2881 Environment variables that are set by the user are also transmitted to
2882 @command{gdbserver} to be used when starting the remote inferior.
2883 @pxref{QEnvironmentHexEncoded}.
2884
2885 @kindex unset environment
2886 @anchor{unset environment}
2887 @item unset environment @var{varname}
2888 Remove variable @var{varname} from the environment to be passed to your
2889 program. This is different from @samp{set env @var{varname} =};
2890 @code{unset environment} removes the variable from the environment,
2891 rather than assigning it an empty value.
2892
2893 Environment variables that are unset by the user are also unset on
2894 @command{gdbserver} when starting the remote inferior.
2895 @pxref{QEnvironmentUnset}.
2896 @end table
2897
2898 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2899 the shell indicated by your @code{SHELL} environment variable if it
2900 exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2901 names a shell that runs an initialization file when started
2902 non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2903 for the Z shell, or the file specified in the @samp{BASH_ENV}
2904 environment variable for BASH---any variables you set in that file
2905 affect your program. You may wish to move setting of environment
2906 variables to files that are only run when you sign on, such as
2907 @file{.login} or @file{.profile}.
2908
2909 @node Working Directory
2910 @section Your Program's Working Directory
2911
2912 @cindex working directory (of your program)
2913 Each time you start your program with @code{run}, the inferior will be
2914 initialized with the current working directory specified by the
2915 @kbd{set cwd} command. If no directory has been specified by this
2916 command, then the inferior will inherit @value{GDBN}'s current working
2917 directory as its working directory if native debugging, or it will
2918 inherit the remote server's current working directory if remote
2919 debugging.
2920
2921 @table @code
2922 @kindex set cwd
2923 @cindex change inferior's working directory
2924 @anchor{set cwd command}
2925 @item set cwd @r{[}@var{directory}@r{]}
2926 Set the inferior's working directory to @var{directory}, which will be
2927 @code{glob}-expanded in order to resolve tildes (@file{~}). If no
2928 argument has been specified, the command clears the setting and resets
2929 it to an empty state. This setting has no effect on @value{GDBN}'s
2930 working directory, and it only takes effect the next time you start
2931 the inferior. The @file{~} in @var{directory} is a short for the
2932 @dfn{home directory}, usually pointed to by the @env{HOME} environment
2933 variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2934 uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2935 fallback.
2936
2937 You can also change @value{GDBN}'s current working directory by using
2938 the @code{cd} command.
2939 @xref{cd command}.
2940
2941 @kindex show cwd
2942 @cindex show inferior's working directory
2943 @item show cwd
2944 Show the inferior's working directory. If no directory has been
2945 specified by @kbd{set cwd}, then the default inferior's working
2946 directory is the same as @value{GDBN}'s working directory.
2947
2948 @kindex cd
2949 @cindex change @value{GDBN}'s working directory
2950 @anchor{cd command}
2951 @item cd @r{[}@var{directory}@r{]}
2952 Set the @value{GDBN} working directory to @var{directory}. If not
2953 given, @var{directory} uses @file{'~'}.
2954
2955 The @value{GDBN} working directory serves as a default for the
2956 commands that specify files for @value{GDBN} to operate on.
2957 @xref{Files, ,Commands to Specify Files}.
2958 @xref{set cwd command}.
2959
2960 @kindex pwd
2961 @item pwd
2962 Print the @value{GDBN} working directory.
2963 @end table
2964
2965 It is generally impossible to find the current working directory of
2966 the process being debugged (since a program can change its directory
2967 during its run). If you work on a system where @value{GDBN} supports
2968 the @code{info proc} command (@pxref{Process Information}), you can
2969 use the @code{info proc} command to find out the
2970 current working directory of the debuggee.
2971
2972 @node Input/Output
2973 @section Your Program's Input and Output
2974
2975 @cindex redirection
2976 @cindex i/o
2977 @cindex terminal
2978 By default, the program you run under @value{GDBN} does input and output to
2979 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
2980 to its own terminal modes to interact with you, but it records the terminal
2981 modes your program was using and switches back to them when you continue
2982 running your program.
2983
2984 @table @code
2985 @kindex info terminal
2986 @item info terminal
2987 Displays information recorded by @value{GDBN} about the terminal modes your
2988 program is using.
2989 @end table
2990
2991 You can redirect your program's input and/or output using shell
2992 redirection with the @code{run} command. For example,
2993
2994 @smallexample
2995 run > outfile
2996 @end smallexample
2997
2998 @noindent
2999 starts your program, diverting its output to the file @file{outfile}.
3000
3001 @kindex tty
3002 @cindex controlling terminal
3003 Another way to specify where your program should do input and output is
3004 with the @code{tty} command. This command accepts a file name as
3005 argument, and causes this file to be the default for future @code{run}
3006 commands. It also resets the controlling terminal for the child
3007 process, for future @code{run} commands. For example,
3008
3009 @smallexample
3010 tty /dev/ttyb
3011 @end smallexample
3012
3013 @noindent
3014 directs that processes started with subsequent @code{run} commands
3015 default to do input and output on the terminal @file{/dev/ttyb} and have
3016 that as their controlling terminal.
3017
3018 An explicit redirection in @code{run} overrides the @code{tty} command's
3019 effect on the input/output device, but not its effect on the controlling
3020 terminal.
3021
3022 When you use the @code{tty} command or redirect input in the @code{run}
3023 command, only the input @emph{for your program} is affected. The input
3024 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
3025 for @code{set inferior-tty}.
3026
3027 @cindex inferior tty
3028 @cindex set inferior controlling terminal
3029 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
3030 display the name of the terminal that will be used for future runs of your
3031 program.
3032
3033 @table @code
3034 @item set inferior-tty [ @var{tty} ]
3035 @kindex set inferior-tty
3036 Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
3037 restores the default behavior, which is to use the same terminal as
3038 @value{GDBN}.
3039
3040 @item show inferior-tty
3041 @kindex show inferior-tty
3042 Show the current tty for the program being debugged.
3043 @end table
3044
3045 @node Attach
3046 @section Debugging an Already-running Process
3047 @kindex attach
3048 @cindex attach
3049
3050 @table @code
3051 @item attach @var{process-id}
3052 This command attaches to a running process---one that was started
3053 outside @value{GDBN}. (@code{info files} shows your active
3054 targets.) The command takes as argument a process ID. The usual way to
3055 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
3056 or with the @samp{jobs -l} shell command.
3057
3058 @code{attach} does not repeat if you press @key{RET} a second time after
3059 executing the command.
3060 @end table
3061
3062 To use @code{attach}, your program must be running in an environment
3063 which supports processes; for example, @code{attach} does not work for
3064 programs on bare-board targets that lack an operating system. You must
3065 also have permission to send the process a signal.
3066
3067 When you use @code{attach}, the debugger finds the program running in
3068 the process first by looking in the current working directory, then (if
3069 the program is not found) by using the source file search path
3070 (@pxref{Source Path, ,Specifying Source Directories}). You can also use
3071 the @code{file} command to load the program. @xref{Files, ,Commands to
3072 Specify Files}.
3073
3074 @anchor{set exec-file-mismatch}
3075 If the debugger can determine that the executable file running in the
3076 process it is attaching to does not match the current exec-file loaded
3077 by @value{GDBN}, the option @code{exec-file-mismatch} specifies how to
3078 handle the mismatch. @value{GDBN} tries to compare the files by
3079 comparing their build IDs (@pxref{build ID}), if available.
3080
3081 @table @code
3082 @kindex exec-file-mismatch
3083 @cindex set exec-file-mismatch
3084 @item set exec-file-mismatch @samp{ask|warn|off}
3085
3086 Whether to detect mismatch between the current executable file loaded
3087 by @value{GDBN} and the executable file used to start the process. If
3088 @samp{ask}, the default, display a warning and ask the user whether to
3089 load the process executable file; if @samp{warn}, just display a
3090 warning; if @samp{off}, don't attempt to detect a mismatch.
3091 If the user confirms loading the process executable file, then its symbols
3092 will be loaded as well.
3093
3094 @cindex show exec-file-mismatch
3095 @item show exec-file-mismatch
3096 Show the current value of @code{exec-file-mismatch}.
3097
3098 @end table
3099
3100 The first thing @value{GDBN} does after arranging to debug the specified
3101 process is to stop it. You can examine and modify an attached process
3102 with all the @value{GDBN} commands that are ordinarily available when
3103 you start processes with @code{run}. You can insert breakpoints; you
3104 can step and continue; you can modify storage. If you would rather the
3105 process continue running, you may use the @code{continue} command after
3106 attaching @value{GDBN} to the process.
3107
3108 @table @code
3109 @kindex detach
3110 @item detach
3111 When you have finished debugging the attached process, you can use the
3112 @code{detach} command to release it from @value{GDBN} control. Detaching
3113 the process continues its execution. After the @code{detach} command,
3114 that process and @value{GDBN} become completely independent once more, and you
3115 are ready to @code{attach} another process or start one with @code{run}.
3116 @code{detach} does not repeat if you press @key{RET} again after
3117 executing the command.
3118 @end table
3119
3120 If you exit @value{GDBN} while you have an attached process, you detach
3121 that process. If you use the @code{run} command, you kill that process.
3122 By default, @value{GDBN} asks for confirmation if you try to do either of these
3123 things; you can control whether or not you need to confirm by using the
3124 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
3125 Messages}).
3126
3127 @node Kill Process
3128 @section Killing the Child Process
3129
3130 @table @code
3131 @kindex kill
3132 @item kill
3133 Kill the child process in which your program is running under @value{GDBN}.
3134 @end table
3135
3136 This command is useful if you wish to debug a core dump instead of a
3137 running process. @value{GDBN} ignores any core dump file while your program
3138 is running.
3139
3140 On some operating systems, a program cannot be executed outside @value{GDBN}
3141 while you have breakpoints set on it inside @value{GDBN}. You can use the
3142 @code{kill} command in this situation to permit running your program
3143 outside the debugger.
3144
3145 The @code{kill} command is also useful if you wish to recompile and
3146 relink your program, since on many systems it is impossible to modify an
3147 executable file while it is running in a process. In this case, when you
3148 next type @code{run}, @value{GDBN} notices that the file has changed, and
3149 reads the symbol table again (while trying to preserve your current
3150 breakpoint settings).
3151
3152 @node Inferiors Connections and Programs
3153 @section Debugging Multiple Inferiors Connections and Programs
3154
3155 @value{GDBN} lets you run and debug multiple programs in a single
3156 session. In addition, @value{GDBN} on some systems may let you run
3157 several programs simultaneously (otherwise you have to exit from one
3158 before starting another). On some systems @value{GDBN} may even let
3159 you debug several programs simultaneously on different remote systems.
3160 In the most general case, you can have multiple threads of execution
3161 in each of multiple processes, launched from multiple executables,
3162 running on different machines.
3163
3164 @cindex inferior
3165 @value{GDBN} represents the state of each program execution with an
3166 object called an @dfn{inferior}. An inferior typically corresponds to
3167 a process, but is more general and applies also to targets that do not
3168 have processes. Inferiors may be created before a process runs, and
3169 may be retained after a process exits. Inferiors have unique
3170 identifiers that are different from process ids. Usually each
3171 inferior will also have its own distinct address space, although some
3172 embedded targets may have several inferiors running in different parts
3173 of a single address space. Each inferior may in turn have multiple
3174 threads running in it.
3175
3176 To find out what inferiors exist at any moment, use @w{@code{info
3177 inferiors}}:
3178
3179 @table @code
3180 @kindex info inferiors [ @var{id}@dots{} ]
3181 @item info inferiors
3182 Print a list of all inferiors currently being managed by @value{GDBN}.
3183 By default all inferiors are printed, but the argument @var{id}@dots{}
3184 -- a space separated list of inferior numbers -- can be used to limit
3185 the display to just the requested inferiors.
3186
3187 @value{GDBN} displays for each inferior (in this order):
3188
3189 @enumerate
3190 @item
3191 the inferior number assigned by @value{GDBN}
3192
3193 @item
3194 the target system's inferior identifier
3195
3196 @item
3197 the target connection the inferior is bound to, including the unique
3198 connection number assigned by @value{GDBN}, and the protocol used by
3199 the connection.
3200
3201 @item
3202 the name of the executable the inferior is running.
3203
3204 @end enumerate
3205
3206 @noindent
3207 An asterisk @samp{*} preceding the @value{GDBN} inferior number
3208 indicates the current inferior.
3209
3210 For example,
3211 @end table
3212 @c end table here to get a little more width for example
3213
3214 @smallexample
3215 (@value{GDBP}) info inferiors
3216 Num Description Connection Executable
3217 * 1 process 3401 1 (native) goodbye
3218 2 process 2307 2 (extended-remote host:10000) hello
3219 @end smallexample
3220
3221 To get informations about the current inferior, use @code{inferior}:
3222
3223 @table @code
3224 @kindex inferior
3225 @item inferior
3226 Shows information about the current inferior.
3227
3228 For example,
3229 @end table
3230 @c end table here to get a little more width for example
3231
3232 @smallexample
3233 (@value{GDBP}) inferior
3234 [Current inferior is 1 [process 3401] (helloworld)]
3235 @end smallexample
3236
3237 To find out what open target connections exist at any moment, use
3238 @w{@code{info connections}}:
3239
3240 @table @code
3241 @kindex info connections [ @var{id}@dots{} ]
3242 @item info connections
3243 Print a list of all open target connections currently being managed by
3244 @value{GDBN}. By default all connections are printed, but the
3245 argument @var{id}@dots{} -- a space separated list of connections
3246 numbers -- can be used to limit the display to just the requested
3247 connections.
3248
3249 @value{GDBN} displays for each connection (in this order):
3250
3251 @enumerate
3252 @item
3253 the connection number assigned by @value{GDBN}.
3254
3255 @item
3256 the protocol used by the connection.
3257
3258 @item
3259 a textual description of the protocol used by the connection.
3260
3261 @end enumerate
3262
3263 @noindent
3264 An asterisk @samp{*} preceding the connection number indicates the
3265 connection of the current inferior.
3266
3267 For example,
3268 @end table
3269 @c end table here to get a little more width for example
3270
3271 @smallexample
3272 (@value{GDBP}) info connections
3273 Num What Description
3274 * 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3275 2 native Native process
3276 3 core Local core dump file
3277 @end smallexample
3278
3279 To switch focus between inferiors, use the @code{inferior} command:
3280
3281 @table @code
3282 @kindex inferior @var{infno}
3283 @item inferior @var{infno}
3284 Make inferior number @var{infno} the current inferior. The argument
3285 @var{infno} is the inferior number assigned by @value{GDBN}, as shown
3286 in the first field of the @samp{info inferiors} display.
3287 @end table
3288
3289 @vindex $_inferior@r{, convenience variable}
3290 The debugger convenience variable @samp{$_inferior} contains the
3291 number of the current inferior. You may find this useful in writing
3292 breakpoint conditional expressions, command scripts, and so forth.
3293 @xref{Convenience Vars,, Convenience Variables}, for general
3294 information on convenience variables.
3295
3296 You can get multiple executables into a debugging session via the
3297 @code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3298 systems @value{GDBN} can add inferiors to the debug session
3299 automatically by following calls to @code{fork} and @code{exec}. To
3300 remove inferiors from the debugging session use the
3301 @w{@code{remove-inferiors}} command.
3302
3303 @table @code
3304 @kindex add-inferior
3305 @item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
3306 Adds @var{n} inferiors to be run using @var{executable} as the
3307 executable; @var{n} defaults to 1. If no executable is specified,
3308 the inferiors begins empty, with no program. You can still assign or
3309 change the program assigned to the inferior at any time by using the
3310 @code{file} command with the executable name as its argument.
3311
3312 By default, the new inferior begins connected to the same target
3313 connection as the current inferior. For example, if the current
3314 inferior was connected to @code{gdbserver} with @code{target remote},
3315 then the new inferior will be connected to the same @code{gdbserver}
3316 instance. The @samp{-no-connection} option starts the new inferior
3317 with no connection yet. You can then for example use the @code{target
3318 remote} command to connect to some other @code{gdbserver} instance,
3319 use @code{run} to spawn a local program, etc.
3320
3321 @kindex clone-inferior
3322 @item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3323 Adds @var{n} inferiors ready to execute the same program as inferior
3324 @var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
3325 number of the current inferior. This is a convenient command when you
3326 want to run another instance of the inferior you are debugging.
3327
3328 @smallexample
3329 (@value{GDBP}) info inferiors
3330 Num Description Connection Executable
3331 * 1 process 29964 1 (native) helloworld
3332 (@value{GDBP}) clone-inferior
3333 Added inferior 2.
3334 1 inferiors added.
3335 (@value{GDBP}) info inferiors
3336 Num Description Connection Executable
3337 * 1 process 29964 1 (native) helloworld
3338 2 <null> 1 (native) helloworld
3339 @end smallexample
3340
3341 You can now simply switch focus to inferior 2 and run it.
3342
3343 @kindex remove-inferiors
3344 @item remove-inferiors @var{infno}@dots{}
3345 Removes the inferior or inferiors @var{infno}@dots{}. It is not
3346 possible to remove an inferior that is running with this command. For
3347 those, use the @code{kill} or @code{detach} command first.
3348
3349 @end table
3350
3351 To quit debugging one of the running inferiors that is not the current
3352 inferior, you can either detach from it by using the @w{@code{detach
3353 inferior}} command (allowing it to run independently), or kill it
3354 using the @w{@code{kill inferiors}} command:
3355
3356 @table @code
3357 @kindex detach inferiors @var{infno}@dots{}
3358 @item detach inferior @var{infno}@dots{}
3359 Detach from the inferior or inferiors identified by @value{GDBN}
3360 inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
3361 still stays on the list of inferiors shown by @code{info inferiors},
3362 but its Description will show @samp{<null>}.
3363
3364 @kindex kill inferiors @var{infno}@dots{}
3365 @item kill inferiors @var{infno}@dots{}
3366 Kill the inferior or inferiors identified by @value{GDBN} inferior
3367 number(s) @var{infno}@dots{}. Note that the inferior's entry still
3368 stays on the list of inferiors shown by @code{info inferiors}, but its
3369 Description will show @samp{<null>}.
3370 @end table
3371
3372 After the successful completion of a command such as @code{detach},
3373 @code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
3374 a normal process exit, the inferior is still valid and listed with
3375 @code{info inferiors}, ready to be restarted.
3376
3377
3378 To be notified when inferiors are started or exit under @value{GDBN}'s
3379 control use @w{@code{set print inferior-events}}:
3380
3381 @table @code
3382 @kindex set print inferior-events
3383 @cindex print messages on inferior start and exit
3384 @item set print inferior-events
3385 @itemx set print inferior-events on
3386 @itemx set print inferior-events off
3387 The @code{set print inferior-events} command allows you to enable or
3388 disable printing of messages when @value{GDBN} notices that new
3389 inferiors have started or that inferiors have exited or have been
3390 detached. By default, these messages will not be printed.
3391
3392 @kindex show print inferior-events
3393 @item show print inferior-events
3394 Show whether messages will be printed when @value{GDBN} detects that
3395 inferiors have started, exited or have been detached.
3396 @end table
3397
3398 Many commands will work the same with multiple programs as with a
3399 single program: e.g., @code{print myglobal} will simply display the
3400 value of @code{myglobal} in the current inferior.
3401
3402
3403 Occasionally, when debugging @value{GDBN} itself, it may be useful to
3404 get more info about the relationship of inferiors, programs, address
3405 spaces in a debug session. You can do that with the @w{@code{maint
3406 info program-spaces}} command.
3407
3408 @table @code
3409 @kindex maint info program-spaces
3410 @item maint info program-spaces
3411 Print a list of all program spaces currently being managed by
3412 @value{GDBN}.
3413
3414 @value{GDBN} displays for each program space (in this order):
3415
3416 @enumerate
3417 @item
3418 the program space number assigned by @value{GDBN}
3419
3420 @item
3421 the name of the executable loaded into the program space, with e.g.,
3422 the @code{file} command.
3423
3424 @end enumerate
3425
3426 @noindent
3427 An asterisk @samp{*} preceding the @value{GDBN} program space number
3428 indicates the current program space.
3429
3430 In addition, below each program space line, @value{GDBN} prints extra
3431 information that isn't suitable to display in tabular form. For
3432 example, the list of inferiors bound to the program space.
3433
3434 @smallexample
3435 (@value{GDBP}) maint info program-spaces
3436 Id Executable
3437 * 1 hello
3438 2 goodbye
3439 Bound inferiors: ID 1 (process 21561)
3440 @end smallexample
3441
3442 Here we can see that no inferior is running the program @code{hello},
3443 while @code{process 21561} is running the program @code{goodbye}. On
3444 some targets, it is possible that multiple inferiors are bound to the
3445 same program space. The most common example is that of debugging both
3446 the parent and child processes of a @code{vfork} call. For example,
3447
3448 @smallexample
3449 (@value{GDBP}) maint info program-spaces
3450 Id Executable
3451 * 1 vfork-test
3452 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3453 @end smallexample
3454
3455 Here, both inferior 2 and inferior 1 are running in the same program
3456 space as a result of inferior 1 having executed a @code{vfork} call.
3457 @end table
3458
3459 @node Threads
3460 @section Debugging Programs with Multiple Threads
3461
3462 @cindex threads of execution
3463 @cindex multiple threads
3464 @cindex switching threads
3465 In some operating systems, such as GNU/Linux and Solaris, a single program
3466 may have more than one @dfn{thread} of execution. The precise semantics
3467 of threads differ from one operating system to another, but in general
3468 the threads of a single program are akin to multiple processes---except
3469 that they share one address space (that is, they can all examine and
3470 modify the same variables). On the other hand, each thread has its own
3471 registers and execution stack, and perhaps private memory.
3472
3473 @value{GDBN} provides these facilities for debugging multi-thread
3474 programs:
3475
3476 @itemize @bullet
3477 @item automatic notification of new threads
3478 @item @samp{thread @var{thread-id}}, a command to switch among threads
3479 @item @samp{info threads}, a command to inquire about existing threads
3480 @item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
3481 a command to apply a command to a list of threads
3482 @item thread-specific breakpoints
3483 @item @samp{set print thread-events}, which controls printing of
3484 messages on thread start and exit.
3485 @item @samp{set libthread-db-search-path @var{path}}, which lets
3486 the user specify which @code{libthread_db} to use if the default choice
3487 isn't compatible with the program.
3488 @end itemize
3489
3490 @cindex focus of debugging
3491 @cindex current thread
3492 The @value{GDBN} thread debugging facility allows you to observe all
3493 threads while your program runs---but whenever @value{GDBN} takes
3494 control, one thread in particular is always the focus of debugging.
3495 This thread is called the @dfn{current thread}. Debugging commands show
3496 program information from the perspective of the current thread.
3497
3498 @cindex @code{New} @var{systag} message
3499 @cindex thread identifier (system)
3500 @c FIXME-implementors!! It would be more helpful if the [New...] message
3501 @c included GDB's numeric thread handle, so you could just go to that
3502 @c thread without first checking `info threads'.
3503 Whenever @value{GDBN} detects a new thread in your program, it displays
3504 the target system's identification for the thread with a message in the
3505 form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
3506 whose form varies depending on the particular system. For example, on
3507 @sc{gnu}/Linux, you might see
3508
3509 @smallexample
3510 [New Thread 0x41e02940 (LWP 25582)]
3511 @end smallexample
3512
3513 @noindent
3514 when @value{GDBN} notices a new thread. In contrast, on other systems,
3515 the @var{systag} is simply something like @samp{process 368}, with no
3516 further qualifier.
3517
3518 @c FIXME!! (1) Does the [New...] message appear even for the very first
3519 @c thread of a program, or does it only appear for the
3520 @c second---i.e.@: when it becomes obvious we have a multithread
3521 @c program?
3522 @c (2) *Is* there necessarily a first thread always? Or do some
3523 @c multithread systems permit starting a program with multiple
3524 @c threads ab initio?
3525
3526 @anchor{thread numbers}
3527 @cindex thread number, per inferior
3528 @cindex thread identifier (GDB)
3529 For debugging purposes, @value{GDBN} associates its own thread number
3530 ---always a single integer---with each thread of an inferior. This
3531 number is unique between all threads of an inferior, but not unique
3532 between threads of different inferiors.
3533
3534 @cindex qualified thread ID
3535 You can refer to a given thread in an inferior using the qualified
3536 @var{inferior-num}.@var{thread-num} syntax, also known as
3537 @dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3538 number and @var{thread-num} being the thread number of the given
3539 inferior. For example, thread @code{2.3} refers to thread number 3 of
3540 inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3541 then @value{GDBN} infers you're referring to a thread of the current
3542 inferior.
3543
3544 Until you create a second inferior, @value{GDBN} does not show the
3545 @var{inferior-num} part of thread IDs, even though you can always use
3546 the full @var{inferior-num}.@var{thread-num} form to refer to threads
3547 of inferior 1, the initial inferior.
3548
3549 @anchor{thread ID lists}
3550 @cindex thread ID lists
3551 Some commands accept a space-separated @dfn{thread ID list} as
3552 argument. A list element can be:
3553
3554 @enumerate
3555 @item
3556 A thread ID as shown in the first field of the @samp{info threads}
3557 display, with or without an inferior qualifier. E.g., @samp{2.1} or
3558 @samp{1}.
3559
3560 @item
3561 A range of thread numbers, again with or without an inferior
3562 qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3563 @var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3564
3565 @item
3566 All threads of an inferior, specified with a star wildcard, with or
3567 without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3568 @samp{1.*}) or @code{*}. The former refers to all threads of the
3569 given inferior, and the latter form without an inferior qualifier
3570 refers to all threads of the current inferior.
3571
3572 @end enumerate
3573
3574 For example, if the current inferior is 1, and inferior 7 has one
3575 thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3576 includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
3577 7 to 9 of inferior 6 and all threads of inferior 7. That is, in
3578 expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
3579 7.1}.
3580
3581
3582 @anchor{global thread numbers}
3583 @cindex global thread number
3584 @cindex global thread identifier (GDB)
3585 In addition to a @emph{per-inferior} number, each thread is also
3586 assigned a unique @emph{global} number, also known as @dfn{global
3587 thread ID}, a single integer. Unlike the thread number component of
3588 the thread ID, no two threads have the same global ID, even when
3589 you're debugging multiple inferiors.
3590
3591 From @value{GDBN}'s perspective, a process always has at least one
3592 thread. In other words, @value{GDBN} assigns a thread number to the
3593 program's ``main thread'' even if the program is not multi-threaded.
3594
3595 @vindex $_thread@r{, convenience variable}
3596 @vindex $_gthread@r{, convenience variable}
3597 The debugger convenience variables @samp{$_thread} and
3598 @samp{$_gthread} contain, respectively, the per-inferior thread number
3599 and the global thread number of the current thread. You may find this
3600 useful in writing breakpoint conditional expressions, command scripts,
3601 and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3602 general information on convenience variables.
3603
3604 If @value{GDBN} detects the program is multi-threaded, it augments the
3605 usual message about stopping at a breakpoint with the ID and name of
3606 the thread that hit the breakpoint.
3607
3608 @smallexample
3609 Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3610 @end smallexample
3611
3612 Likewise when the program receives a signal:
3613
3614 @smallexample
3615 Thread 1 "main" received signal SIGINT, Interrupt.
3616 @end smallexample
3617
3618 @table @code
3619 @kindex info threads
3620 @item info threads @r{[}@var{thread-id-list}@r{]}
3621
3622 Display information about one or more threads. With no arguments
3623 displays information about all threads. You can specify the list of
3624 threads that you want to display using the thread ID list syntax
3625 (@pxref{thread ID lists}).
3626
3627 @value{GDBN} displays for each thread (in this order):
3628
3629 @enumerate
3630 @item
3631 the per-inferior thread number assigned by @value{GDBN}
3632
3633 @item
3634 the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3635 option was specified
3636
3637 @item
3638 the target system's thread identifier (@var{systag})
3639
3640 @item
3641 the thread's name, if one is known. A thread can either be named by
3642 the user (see @code{thread name}, below), or, in some cases, by the
3643 program itself.
3644
3645 @item
3646 the current stack frame summary for that thread
3647 @end enumerate
3648
3649 @noindent
3650 An asterisk @samp{*} to the left of the @value{GDBN} thread number
3651 indicates the current thread.
3652
3653 For example,
3654 @end table
3655 @c end table here to get a little more width for example
3656
3657 @smallexample
3658 (@value{GDBP}) info threads
3659 Id Target Id Frame
3660 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3661 2 process 35 thread 23 0x34e5 in sigpause ()
3662 3 process 35 thread 27 0x34e5 in sigpause ()
3663 at threadtest.c:68
3664 @end smallexample
3665
3666 If you're debugging multiple inferiors, @value{GDBN} displays thread
3667 IDs using the qualified @var{inferior-num}.@var{thread-num} format.
3668 Otherwise, only @var{thread-num} is shown.
3669
3670 If you specify the @samp{-gid} option, @value{GDBN} displays a column
3671 indicating each thread's global thread ID:
3672
3673 @smallexample
3674 (@value{GDBP}) info threads
3675 Id GId Target Id Frame
3676 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3677 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3678 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3679 * 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
3680 @end smallexample
3681
3682 On Solaris, you can display more information about user threads with a
3683 Solaris-specific command:
3684
3685 @table @code
3686 @item maint info sol-threads
3687 @kindex maint info sol-threads
3688 @cindex thread info (Solaris)
3689 Display info on Solaris user threads.
3690 @end table
3691
3692 @table @code
3693 @kindex thread @var{thread-id}
3694 @item thread @var{thread-id}
3695 Make thread ID @var{thread-id} the current thread. The command
3696 argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3697 the first field of the @samp{info threads} display, with or without an
3698 inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3699
3700 @value{GDBN} responds by displaying the system identifier of the
3701 thread you selected, and its current stack frame summary:
3702
3703 @smallexample
3704 (@value{GDBP}) thread 2
3705 [Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3706 #0 some_function (ignore=0x0) at example.c:8
3707 8 printf ("hello\n");
3708 @end smallexample
3709
3710 @noindent
3711 As with the @samp{[New @dots{}]} message, the form of the text after
3712 @samp{Switching to} depends on your system's conventions for identifying
3713 threads.
3714
3715 @anchor{thread apply all}
3716 @kindex thread apply
3717 @cindex apply command to several threads
3718 @item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
3719 The @code{thread apply} command allows you to apply the named
3720 @var{command} to one or more threads. Specify the threads that you
3721 want affected using the thread ID list syntax (@pxref{thread ID
3722 lists}), or specify @code{all} to apply to all threads. To apply a
3723 command to all threads in descending order, type @kbd{thread apply all
3724 @var{command}}. To apply a command to all threads in ascending order,
3725 type @kbd{thread apply all -ascending @var{command}}.
3726
3727 The @var{flag} arguments control what output to produce and how to handle
3728 errors raised when applying @var{command} to a thread. @var{flag}
3729 must start with a @code{-} directly followed by one letter in
3730 @code{qcs}. If several flags are provided, they must be given
3731 individually, such as @code{-c -q}.
3732
3733 By default, @value{GDBN} displays some thread information before the
3734 output produced by @var{command}, and an error raised during the
3735 execution of a @var{command} will abort @code{thread apply}. The
3736 following flags can be used to fine-tune this behavior:
3737
3738 @table @code
3739 @item -c
3740 The flag @code{-c}, which stands for @samp{continue}, causes any
3741 errors in @var{command} to be displayed, and the execution of
3742 @code{thread apply} then continues.
3743 @item -s
3744 The flag @code{-s}, which stands for @samp{silent}, causes any errors
3745 or empty output produced by a @var{command} to be silently ignored.
3746 That is, the execution continues, but the thread information and errors
3747 are not printed.
3748 @item -q
3749 The flag @code{-q} (@samp{quiet}) disables printing the thread
3750 information.
3751 @end table
3752
3753 Flags @code{-c} and @code{-s} cannot be used together.
3754
3755 @kindex taas
3756 @cindex apply command to all threads (ignoring errors and empty output)
3757 @item taas [@var{option}]@dots{} @var{command}
3758 Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
3759 Applies @var{command} on all threads, ignoring errors and empty output.
3760
3761 The @code{taas} command accepts the same options as the @code{thread
3762 apply all} command. @xref{thread apply all}.
3763
3764 @kindex tfaas
3765 @cindex apply a command to all frames of all threads (ignoring errors and empty output)
3766 @item tfaas [@var{option}]@dots{} @var{command}
3767 Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
3768 Applies @var{command} on all frames of all threads, ignoring errors
3769 and empty output. Note that the flag @code{-s} is specified twice:
3770 The first @code{-s} ensures that @code{thread apply} only shows the thread
3771 information of the threads for which @code{frame apply} produces
3772 some output. The second @code{-s} is needed to ensure that @code{frame
3773 apply} shows the frame information of a frame only if the
3774 @var{command} successfully produced some output.
3775
3776 It can for example be used to print a local variable or a function
3777 argument without knowing the thread or frame where this variable or argument
3778 is, using:
3779 @smallexample
3780 (@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3781 @end smallexample
3782
3783 The @code{tfaas} command accepts the same options as the @code{frame
3784 apply} command. @xref{Frame Apply,,frame apply}.
3785
3786 @kindex thread name
3787 @cindex name a thread
3788 @item thread name [@var{name}]
3789 This command assigns a name to the current thread. If no argument is
3790 given, any existing user-specified name is removed. The thread name
3791 appears in the @samp{info threads} display.
3792
3793 On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3794 determine the name of the thread as given by the OS. On these
3795 systems, a name specified with @samp{thread name} will override the
3796 system-give name, and removing the user-specified name will cause
3797 @value{GDBN} to once again display the system-specified name.
3798
3799 @kindex thread find
3800 @cindex search for a thread
3801 @item thread find [@var{regexp}]
3802 Search for and display thread ids whose name or @var{systag}
3803 matches the supplied regular expression.
3804
3805 As well as being the complement to the @samp{thread name} command,
3806 this command also allows you to identify a thread by its target
3807 @var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3808 is the LWP id.
3809
3810 @smallexample
3811 (@value{GDBN}) thread find 26688
3812 Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3813 (@value{GDBN}) info thread 4
3814 Id Target Id Frame
3815 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3816 @end smallexample
3817
3818 @kindex set print thread-events
3819 @cindex print messages on thread start and exit
3820 @item set print thread-events
3821 @itemx set print thread-events on
3822 @itemx set print thread-events off
3823 The @code{set print thread-events} command allows you to enable or
3824 disable printing of messages when @value{GDBN} notices that new threads have
3825 started or that threads have exited. By default, these messages will
3826 be printed if detection of these events is supported by the target.
3827 Note that these messages cannot be disabled on all targets.
3828
3829 @kindex show print thread-events
3830 @item show print thread-events
3831 Show whether messages will be printed when @value{GDBN} detects that threads
3832 have started and exited.
3833 @end table
3834
3835 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
3836 more information about how @value{GDBN} behaves when you stop and start
3837 programs with multiple threads.
3838
3839 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
3840 watchpoints in programs with multiple threads.
3841
3842 @anchor{set libthread-db-search-path}
3843 @table @code
3844 @kindex set libthread-db-search-path
3845 @cindex search path for @code{libthread_db}
3846 @item set libthread-db-search-path @r{[}@var{path}@r{]}
3847 If this variable is set, @var{path} is a colon-separated list of
3848 directories @value{GDBN} will use to search for @code{libthread_db}.
3849 If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
3850 its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
3851 Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3852 macro.
3853
3854 On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3855 @code{libthread_db} library to obtain information about threads in the
3856 inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
3857 to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3858 specific thread debugging library loading is enabled
3859 by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
3860
3861 A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3862 refers to the default system directories that are
3863 normally searched for loading shared libraries. The @samp{$sdir} entry
3864 is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3865 (@pxref{libthread_db.so.1 file}).
3866
3867 A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3868 refers to the directory from which @code{libpthread}
3869 was loaded in the inferior process.
3870
3871 For any @code{libthread_db} library @value{GDBN} finds in above directories,
3872 @value{GDBN} attempts to initialize it with the current inferior process.
3873 If this initialization fails (which could happen because of a version
3874 mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3875 will unload @code{libthread_db}, and continue with the next directory.
3876 If none of @code{libthread_db} libraries initialize successfully,
3877 @value{GDBN} will issue a warning and thread debugging will be disabled.
3878
3879 Setting @code{libthread-db-search-path} is currently implemented
3880 only on some platforms.
3881
3882 @kindex show libthread-db-search-path
3883 @item show libthread-db-search-path
3884 Display current libthread_db search path.
3885
3886 @kindex set debug libthread-db
3887 @kindex show debug libthread-db
3888 @cindex debugging @code{libthread_db}
3889 @item set debug libthread-db
3890 @itemx show debug libthread-db
3891 Turns on or off display of @code{libthread_db}-related events.
3892 Use @code{1} to enable, @code{0} to disable.
3893 @end table
3894
3895 @node Forks
3896 @section Debugging Forks
3897
3898 @cindex fork, debugging programs which call
3899 @cindex multiple processes
3900 @cindex processes, multiple
3901 On most systems, @value{GDBN} has no special support for debugging
3902 programs which create additional processes using the @code{fork}
3903 function. When a program forks, @value{GDBN} will continue to debug the
3904 parent process and the child process will run unimpeded. If you have
3905 set a breakpoint in any code which the child then executes, the child
3906 will get a @code{SIGTRAP} signal which (unless it catches the signal)
3907 will cause it to terminate.
3908
3909 However, if you want to debug the child process there is a workaround
3910 which isn't too painful. Put a call to @code{sleep} in the code which
3911 the child process executes after the fork. It may be useful to sleep
3912 only if a certain environment variable is set, or a certain file exists,
3913 so that the delay need not occur when you don't want to run @value{GDBN}
3914 on the child. While the child is sleeping, use the @code{ps} program to
3915 get its process ID. Then tell @value{GDBN} (a new invocation of
3916 @value{GDBN} if you are also debugging the parent process) to attach to
3917 the child process (@pxref{Attach}). From that point on you can debug
3918 the child process just like any other process which you attached to.
3919
3920 On some systems, @value{GDBN} provides support for debugging programs
3921 that create additional processes using the @code{fork} or @code{vfork}
3922 functions. On @sc{gnu}/Linux platforms, this feature is supported
3923 with kernel version 2.5.46 and later.
3924
3925 The fork debugging commands are supported in native mode and when
3926 connected to @code{gdbserver} in either @code{target remote} mode or
3927 @code{target extended-remote} mode.
3928
3929 By default, when a program forks, @value{GDBN} will continue to debug
3930 the parent process and the child process will run unimpeded.
3931
3932 If you want to follow the child process instead of the parent process,
3933 use the command @w{@code{set follow-fork-mode}}.
3934
3935 @table @code
3936 @kindex set follow-fork-mode
3937 @item set follow-fork-mode @var{mode}
3938 Set the debugger response to a program call of @code{fork} or
3939 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
3940 process. The @var{mode} argument can be:
3941
3942 @table @code
3943 @item parent
3944 The original process is debugged after a fork. The child process runs
3945 unimpeded. This is the default.
3946
3947 @item child
3948 The new process is debugged after a fork. The parent process runs
3949 unimpeded.
3950
3951 @end table
3952
3953 @kindex show follow-fork-mode
3954 @item show follow-fork-mode
3955 Display the current debugger response to a @code{fork} or @code{vfork} call.
3956 @end table
3957
3958 @cindex debugging multiple processes
3959 On Linux, if you want to debug both the parent and child processes, use the
3960 command @w{@code{set detach-on-fork}}.
3961
3962 @table @code
3963 @kindex set detach-on-fork
3964 @item set detach-on-fork @var{mode}
3965 Tells gdb whether to detach one of the processes after a fork, or
3966 retain debugger control over them both.
3967
3968 @table @code
3969 @item on
3970 The child process (or parent process, depending on the value of
3971 @code{follow-fork-mode}) will be detached and allowed to run
3972 independently. This is the default.
3973
3974 @item off
3975 Both processes will be held under the control of @value{GDBN}.
3976 One process (child or parent, depending on the value of
3977 @code{follow-fork-mode}) is debugged as usual, while the other
3978 is held suspended.
3979
3980 @end table
3981
3982 @kindex show detach-on-fork
3983 @item show detach-on-fork
3984 Show whether detach-on-fork mode is on/off.
3985 @end table
3986
3987 If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3988 will retain control of all forked processes (including nested forks).
3989 You can list the forked processes under the control of @value{GDBN} by
3990 using the @w{@code{info inferiors}} command, and switch from one fork
3991 to another by using the @code{inferior} command (@pxref{Inferiors Connections and
3992 Programs, ,Debugging Multiple Inferiors Connections and Programs}).
3993
3994 To quit debugging one of the forked processes, you can either detach
3995 from it by using the @w{@code{detach inferiors}} command (allowing it
3996 to run independently), or kill it using the @w{@code{kill inferiors}}
3997 command. @xref{Inferiors Connections and Programs, ,Debugging
3998 Multiple Inferiors Connections and Programs}.
3999
4000 If you ask to debug a child process and a @code{vfork} is followed by an
4001 @code{exec}, @value{GDBN} executes the new target up to the first
4002 breakpoint in the new target. If you have a breakpoint set on
4003 @code{main} in your original program, the breakpoint will also be set on
4004 the child process's @code{main}.
4005
4006 On some systems, when a child process is spawned by @code{vfork}, you
4007 cannot debug the child or parent until an @code{exec} call completes.
4008
4009 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
4010 call executes, the new target restarts. To restart the parent
4011 process, use the @code{file} command with the parent executable name
4012 as its argument. By default, after an @code{exec} call executes,
4013 @value{GDBN} discards the symbols of the previous executable image.
4014 You can change this behaviour with the @w{@code{set follow-exec-mode}}
4015 command.
4016
4017 @table @code
4018 @kindex set follow-exec-mode
4019 @item set follow-exec-mode @var{mode}
4020
4021 Set debugger response to a program call of @code{exec}. An
4022 @code{exec} call replaces the program image of a process.
4023
4024 @code{follow-exec-mode} can be:
4025
4026 @table @code
4027 @item new
4028 @value{GDBN} creates a new inferior and rebinds the process to this
4029 new inferior. The program the process was running before the
4030 @code{exec} call can be restarted afterwards by restarting the
4031 original inferior.
4032
4033 For example:
4034
4035 @smallexample
4036 (@value{GDBP}) info inferiors
4037 (gdb) info inferior
4038 Id Description Executable
4039 * 1 <null> prog1
4040 (@value{GDBP}) run
4041 process 12020 is executing new program: prog2
4042 Program exited normally.
4043 (@value{GDBP}) info inferiors
4044 Id Description Executable
4045 1 <null> prog1
4046 * 2 <null> prog2
4047 @end smallexample
4048
4049 @item same
4050 @value{GDBN} keeps the process bound to the same inferior. The new
4051 executable image replaces the previous executable loaded in the
4052 inferior. Restarting the inferior after the @code{exec} call, with
4053 e.g., the @code{run} command, restarts the executable the process was
4054 running after the @code{exec} call. This is the default mode.
4055
4056 For example:
4057
4058 @smallexample
4059 (@value{GDBP}) info inferiors
4060 Id Description Executable
4061 * 1 <null> prog1
4062 (@value{GDBP}) run
4063 process 12020 is executing new program: prog2
4064 Program exited normally.
4065 (@value{GDBP}) info inferiors
4066 Id Description Executable
4067 * 1 <null> prog2
4068 @end smallexample
4069
4070 @end table
4071 @end table
4072
4073 @code{follow-exec-mode} is supported in native mode and
4074 @code{target extended-remote} mode.
4075
4076 You can use the @code{catch} command to make @value{GDBN} stop whenever
4077 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
4078 Catchpoints, ,Setting Catchpoints}.
4079
4080 @node Checkpoint/Restart
4081 @section Setting a @emph{Bookmark} to Return to Later
4082
4083 @cindex checkpoint
4084 @cindex restart
4085 @cindex bookmark
4086 @cindex snapshot of a process
4087 @cindex rewind program state
4088
4089 On certain operating systems@footnote{Currently, only
4090 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
4091 program's state, called a @dfn{checkpoint}, and come back to it
4092 later.
4093
4094 Returning to a checkpoint effectively undoes everything that has
4095 happened in the program since the @code{checkpoint} was saved. This
4096 includes changes in memory, registers, and even (within some limits)
4097 system state. Effectively, it is like going back in time to the
4098 moment when the checkpoint was saved.
4099
4100 Thus, if you're stepping thru a program and you think you're
4101 getting close to the point where things go wrong, you can save
4102 a checkpoint. Then, if you accidentally go too far and miss
4103 the critical statement, instead of having to restart your program
4104 from the beginning, you can just go back to the checkpoint and
4105 start again from there.
4106
4107 This can be especially useful if it takes a lot of time or
4108 steps to reach the point where you think the bug occurs.
4109
4110 To use the @code{checkpoint}/@code{restart} method of debugging:
4111
4112 @table @code
4113 @kindex checkpoint
4114 @item checkpoint
4115 Save a snapshot of the debugged program's current execution state.
4116 The @code{checkpoint} command takes no arguments, but each checkpoint
4117 is assigned a small integer id, similar to a breakpoint id.
4118
4119 @kindex info checkpoints
4120 @item info checkpoints
4121 List the checkpoints that have been saved in the current debugging
4122 session. For each checkpoint, the following information will be
4123 listed:
4124
4125 @table @code
4126 @item Checkpoint ID
4127 @item Process ID
4128 @item Code Address
4129 @item Source line, or label
4130 @end table
4131
4132 @kindex restart @var{checkpoint-id}
4133 @item restart @var{checkpoint-id}
4134 Restore the program state that was saved as checkpoint number
4135 @var{checkpoint-id}. All program variables, registers, stack frames
4136 etc.@: will be returned to the values that they had when the checkpoint
4137 was saved. In essence, gdb will ``wind back the clock'' to the point
4138 in time when the checkpoint was saved.
4139
4140 Note that breakpoints, @value{GDBN} variables, command history etc.
4141 are not affected by restoring a checkpoint. In general, a checkpoint
4142 only restores things that reside in the program being debugged, not in
4143 the debugger.
4144
4145 @kindex delete checkpoint @var{checkpoint-id}
4146 @item delete checkpoint @var{checkpoint-id}
4147 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
4148
4149 @end table
4150
4151 Returning to a previously saved checkpoint will restore the user state
4152 of the program being debugged, plus a significant subset of the system
4153 (OS) state, including file pointers. It won't ``un-write'' data from
4154 a file, but it will rewind the file pointer to the previous location,
4155 so that the previously written data can be overwritten. For files
4156 opened in read mode, the pointer will also be restored so that the
4157 previously read data can be read again.
4158
4159 Of course, characters that have been sent to a printer (or other
4160 external device) cannot be ``snatched back'', and characters received
4161 from eg.@: a serial device can be removed from internal program buffers,
4162 but they cannot be ``pushed back'' into the serial pipeline, ready to
4163 be received again. Similarly, the actual contents of files that have
4164 been changed cannot be restored (at this time).
4165
4166 However, within those constraints, you actually can ``rewind'' your
4167 program to a previously saved point in time, and begin debugging it
4168 again --- and you can change the course of events so as to debug a
4169 different execution path this time.
4170
4171 @cindex checkpoints and process id
4172 Finally, there is one bit of internal program state that will be
4173 different when you return to a checkpoint --- the program's process
4174 id. Each checkpoint will have a unique process id (or @var{pid}),
4175 and each will be different from the program's original @var{pid}.
4176 If your program has saved a local copy of its process id, this could
4177 potentially pose a problem.
4178
4179 @subsection A Non-obvious Benefit of Using Checkpoints
4180
4181 On some systems such as @sc{gnu}/Linux, address space randomization
4182 is performed on new processes for security reasons. This makes it
4183 difficult or impossible to set a breakpoint, or watchpoint, on an
4184 absolute address if you have to restart the program, since the
4185 absolute location of a symbol will change from one execution to the
4186 next.
4187
4188 A checkpoint, however, is an @emph{identical} copy of a process.
4189 Therefore if you create a checkpoint at (eg.@:) the start of main,
4190 and simply return to that checkpoint instead of restarting the
4191 process, you can avoid the effects of address randomization and
4192 your symbols will all stay in the same place.
4193
4194 @node Stopping
4195 @chapter Stopping and Continuing
4196
4197 The principal purposes of using a debugger are so that you can stop your
4198 program before it terminates; or so that, if your program runs into
4199 trouble, you can investigate and find out why.
4200
4201 Inside @value{GDBN}, your program may stop for any of several reasons,
4202 such as a signal, a breakpoint, or reaching a new line after a
4203 @value{GDBN} command such as @code{step}. You may then examine and
4204 change variables, set new breakpoints or remove old ones, and then
4205 continue execution. Usually, the messages shown by @value{GDBN} provide
4206 ample explanation of the status of your program---but you can also
4207 explicitly request this information at any time.
4208
4209 @table @code
4210 @kindex info program
4211 @item info program
4212 Display information about the status of your program: whether it is
4213 running or not, what process it is, and why it stopped.
4214 @end table
4215
4216 @menu
4217 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
4218 * Continuing and Stepping:: Resuming execution
4219 * Skipping Over Functions and Files::
4220 Skipping over functions and files
4221 * Signals:: Signals
4222 * Thread Stops:: Stopping and starting multi-thread programs
4223 @end menu
4224
4225 @node Breakpoints
4226 @section Breakpoints, Watchpoints, and Catchpoints
4227
4228 @cindex breakpoints
4229 A @dfn{breakpoint} makes your program stop whenever a certain point in
4230 the program is reached. For each breakpoint, you can add conditions to
4231 control in finer detail whether your program stops. You can set
4232 breakpoints with the @code{break} command and its variants (@pxref{Set
4233 Breaks, ,Setting Breakpoints}), to specify the place where your program
4234 should stop by line number, function name or exact address in the
4235 program.
4236
4237 On some systems, you can set breakpoints in shared libraries before
4238 the executable is run.
4239
4240 @cindex watchpoints
4241 @cindex data breakpoints
4242 @cindex memory tracing
4243 @cindex breakpoint on memory address
4244 @cindex breakpoint on variable modification
4245 A @dfn{watchpoint} is a special breakpoint that stops your program
4246 when the value of an expression changes. The expression may be a value
4247 of a variable, or it could involve values of one or more variables
4248 combined by operators, such as @samp{a + b}. This is sometimes called
4249 @dfn{data breakpoints}. You must use a different command to set
4250 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
4251 from that, you can manage a watchpoint like any other breakpoint: you
4252 enable, disable, and delete both breakpoints and watchpoints using the
4253 same commands.
4254
4255 You can arrange to have values from your program displayed automatically
4256 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
4257 Automatic Display}.
4258
4259 @cindex catchpoints
4260 @cindex breakpoint on events
4261 A @dfn{catchpoint} is another special breakpoint that stops your program
4262 when a certain kind of event occurs, such as the throwing of a C@t{++}
4263 exception or the loading of a library. As with watchpoints, you use a
4264 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
4265 Catchpoints}), but aside from that, you can manage a catchpoint like any
4266 other breakpoint. (To stop when your program receives a signal, use the
4267 @code{handle} command; see @ref{Signals, ,Signals}.)
4268
4269 @cindex breakpoint numbers
4270 @cindex numbers for breakpoints
4271 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
4272 catchpoint when you create it; these numbers are successive integers
4273 starting with one. In many of the commands for controlling various
4274 features of breakpoints you use the breakpoint number to say which
4275 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4276 @dfn{disabled}; if disabled, it has no effect on your program until you
4277 enable it again.
4278
4279 @cindex breakpoint ranges
4280 @cindex breakpoint lists
4281 @cindex ranges of breakpoints
4282 @cindex lists of breakpoints
4283 Some @value{GDBN} commands accept a space-separated list of breakpoints
4284 on which to operate. A list element can be either a single breakpoint number,
4285 like @samp{5}, or a range of such numbers, like @samp{5-7}.
4286 When a breakpoint list is given to a command, all breakpoints in that list
4287 are operated on.
4288
4289 @menu
4290 * Set Breaks:: Setting breakpoints
4291 * Set Watchpoints:: Setting watchpoints
4292 * Set Catchpoints:: Setting catchpoints
4293 * Delete Breaks:: Deleting breakpoints
4294 * Disabling:: Disabling breakpoints
4295 * Conditions:: Break conditions
4296 * Break Commands:: Breakpoint command lists
4297 * Dynamic Printf:: Dynamic printf
4298 * Save Breakpoints:: How to save breakpoints in a file
4299 * Static Probe Points:: Listing static probe points
4300 * Error in Breakpoints:: ``Cannot insert breakpoints''
4301 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
4302 @end menu
4303
4304 @node Set Breaks
4305 @subsection Setting Breakpoints
4306
4307 @c FIXME LMB what does GDB do if no code on line of breakpt?
4308 @c consider in particular declaration with/without initialization.
4309 @c
4310 @c FIXME 2 is there stuff on this already? break at fun start, already init?
4311
4312 @kindex break
4313 @kindex b @r{(@code{break})}
4314 @vindex $bpnum@r{, convenience variable}
4315 @cindex latest breakpoint
4316 Breakpoints are set with the @code{break} command (abbreviated
4317 @code{b}). The debugger convenience variable @samp{$bpnum} records the
4318 number of the breakpoint you've set most recently; see @ref{Convenience
4319 Vars,, Convenience Variables}, for a discussion of what you can do with
4320 convenience variables.
4321
4322 @table @code
4323 @item break @var{location}
4324 Set a breakpoint at the given @var{location}, which can specify a
4325 function name, a line number, or an address of an instruction.
4326 (@xref{Specify Location}, for a list of all the possible ways to
4327 specify a @var{location}.) The breakpoint will stop your program just
4328 before it executes any of the code in the specified @var{location}.
4329
4330 When using source languages that permit overloading of symbols, such as
4331 C@t{++}, a function name may refer to more than one possible place to break.
4332 @xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
4333 that situation.
4334
4335 It is also possible to insert a breakpoint that will stop the program
4336 only if a specific thread (@pxref{Thread-Specific Breakpoints})
4337 or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
4338
4339 @item break
4340 When called without any arguments, @code{break} sets a breakpoint at
4341 the next instruction to be executed in the selected stack frame
4342 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4343 innermost, this makes your program stop as soon as control
4344 returns to that frame. This is similar to the effect of a
4345 @code{finish} command in the frame inside the selected frame---except
4346 that @code{finish} does not leave an active breakpoint. If you use
4347 @code{break} without an argument in the innermost frame, @value{GDBN} stops
4348 the next time it reaches the current location; this may be useful
4349 inside loops.
4350
4351 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
4352 least one instruction has been executed. If it did not do this, you
4353 would be unable to proceed past a breakpoint without first disabling the
4354 breakpoint. This rule applies whether or not the breakpoint already
4355 existed when your program stopped.
4356
4357 @item break @dots{} if @var{cond}
4358 Set a breakpoint with condition @var{cond}; evaluate the expression
4359 @var{cond} each time the breakpoint is reached, and stop only if the
4360 value is nonzero---that is, if @var{cond} evaluates as true.
4361 @samp{@dots{}} stands for one of the possible arguments described
4362 above (or no argument) specifying where to break. @xref{Conditions,
4363 ,Break Conditions}, for more information on breakpoint conditions.
4364
4365 The breakpoint may be mapped to multiple locations. If the breakpoint
4366 condition @var{cond} is invalid at some but not all of the locations,
4367 the locations for which the condition is invalid are disabled. For
4368 example, @value{GDBN} reports below that two of the three locations
4369 are disabled.
4370
4371 @smallexample
4372 (@value{GDBP}) break func if a == 10
4373 warning: failed to validate condition at location 0x11ce, disabling:
4374 No symbol "a" in current context.
4375 warning: failed to validate condition at location 0x11b6, disabling:
4376 No symbol "a" in current context.
4377 Breakpoint 1 at 0x11b6: func. (3 locations)
4378 @end smallexample
4379
4380 Locations that are disabled because of the condition are denoted by an
4381 uppercase @code{N} in the output of the @code{info breakpoints}
4382 command:
4383
4384 @smallexample
4385 (@value{GDBP}) info breakpoints
4386 Num Type Disp Enb Address What
4387 1 breakpoint keep y <MULTIPLE>
4388 stop only if a == 10
4389 1.1 N* 0x00000000000011b6 in ...
4390 1.2 y 0x00000000000011c2 in ...
4391 1.3 N* 0x00000000000011ce in ...
4392 (*): Breakpoint condition is invalid at this location.
4393 @end smallexample
4394
4395 If the breakpoint condition @var{cond} is invalid in the context of
4396 @emph{all} the locations of the breakpoint, @value{GDBN} refuses to
4397 define the breakpoint. For example, if variable @code{foo} is an
4398 undefined variable:
4399
4400 @smallexample
4401 (@value{GDBP}) break func if foo
4402 No symbol "foo" in current context.
4403 @end smallexample
4404
4405 @item break @dots{} -force-condition if @var{cond}
4406 There may be cases where the condition @var{cond} is invalid at all
4407 the current locations, but the user knows that it will be valid at a
4408 future location; for example, because of a library load. In such
4409 cases, by using the @code{-force-condition} keyword before @samp{if},
4410 @value{GDBN} can be forced to define the breakpoint with the given
4411 condition expression instead of refusing it.
4412
4413 @smallexample
4414 (@value{GDBP}) break func -force-condition if foo
4415 warning: failed to validate condition at location 1, disabling:
4416 No symbol "foo" in current context.
4417 warning: failed to validate condition at location 2, disabling:
4418 No symbol "foo" in current context.
4419 warning: failed to validate condition at location 3, disabling:
4420 No symbol "foo" in current context.
4421 Breakpoint 1 at 0x1158: test.c:18. (3 locations)
4422 @end smallexample
4423
4424 This causes all the present locations where the breakpoint would
4425 otherwise be inserted, to be disabled, as seen in the example above.
4426 However, if there exist locations at which the condition is valid, the
4427 @code{-force-condition} keyword has no effect.
4428
4429 @kindex tbreak
4430 @item tbreak @var{args}
4431 Set a breakpoint enabled only for one stop. The @var{args} are the
4432 same as for the @code{break} command, and the breakpoint is set in the same
4433 way, but the breakpoint is automatically deleted after the first time your
4434 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
4435
4436 @kindex hbreak
4437 @cindex hardware breakpoints
4438 @item hbreak @var{args}
4439 Set a hardware-assisted breakpoint. The @var{args} are the same as for the
4440 @code{break} command and the breakpoint is set in the same way, but the
4441 breakpoint requires hardware support and some target hardware may not
4442 have this support. The main purpose of this is EPROM/ROM code
4443 debugging, so you can set a breakpoint at an instruction without
4444 changing the instruction. This can be used with the new trap-generation
4445 provided by SPARClite DSU and most x86-based targets. These targets
4446 will generate traps when a program accesses some data or instruction
4447 address that is assigned to the debug registers. However the hardware
4448 breakpoint registers can take a limited number of breakpoints. For
4449 example, on the DSU, only two data breakpoints can be set at a time, and
4450 @value{GDBN} will reject this command if more than two are used. Delete
4451 or disable unused hardware breakpoints before setting new ones
4452 (@pxref{Disabling, ,Disabling Breakpoints}).
4453 @xref{Conditions, ,Break Conditions}.
4454 For remote targets, you can restrict the number of hardware
4455 breakpoints @value{GDBN} will use, see @ref{set remote
4456 hardware-breakpoint-limit}.
4457
4458 @kindex thbreak
4459 @item thbreak @var{args}
4460 Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
4461 are the same as for the @code{hbreak} command and the breakpoint is set in
4462 the same way. However, like the @code{tbreak} command,
4463 the breakpoint is automatically deleted after the
4464 first time your program stops there. Also, like the @code{hbreak}
4465 command, the breakpoint requires hardware support and some target hardware
4466 may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4467 See also @ref{Conditions, ,Break Conditions}.
4468
4469 @kindex rbreak
4470 @cindex regular expression
4471 @cindex breakpoints at functions matching a regexp
4472 @cindex set breakpoints in many functions
4473 @item rbreak @var{regex}
4474 Set breakpoints on all functions matching the regular expression
4475 @var{regex}. This command sets an unconditional breakpoint on all
4476 matches, printing a list of all breakpoints it set. Once these
4477 breakpoints are set, they are treated just like the breakpoints set with
4478 the @code{break} command. You can delete them, disable them, or make
4479 them conditional the same way as any other breakpoint.
4480
4481 In programs using different languages, @value{GDBN} chooses the syntax
4482 to print the list of all breakpoints it sets according to the
4483 @samp{set language} value: using @samp{set language auto}
4484 (see @ref{Automatically, ,Set Language Automatically}) means to use the
4485 language of the breakpoint's function, other values mean to use
4486 the manually specified language (see @ref{Manually, ,Set Language Manually}).
4487
4488 The syntax of the regular expression is the standard one used with tools
4489 like @file{grep}. Note that this is different from the syntax used by
4490 shells, so for instance @code{foo*} matches all functions that include
4491 an @code{fo} followed by zero or more @code{o}s. There is an implicit
4492 @code{.*} leading and trailing the regular expression you supply, so to
4493 match only functions that begin with @code{foo}, use @code{^foo}.
4494
4495 @cindex non-member C@t{++} functions, set breakpoint in
4496 When debugging C@t{++} programs, @code{rbreak} is useful for setting
4497 breakpoints on overloaded functions that are not members of any special
4498 classes.
4499
4500 @cindex set breakpoints on all functions
4501 The @code{rbreak} command can be used to set breakpoints in
4502 @strong{all} the functions in a program, like this:
4503
4504 @smallexample
4505 (@value{GDBP}) rbreak .
4506 @end smallexample
4507
4508 @item rbreak @var{file}:@var{regex}
4509 If @code{rbreak} is called with a filename qualification, it limits
4510 the search for functions matching the given regular expression to the
4511 specified @var{file}. This can be used, for example, to set breakpoints on
4512 every function in a given file:
4513
4514 @smallexample
4515 (@value{GDBP}) rbreak file.c:.
4516 @end smallexample
4517
4518 The colon separating the filename qualifier from the regex may
4519 optionally be surrounded by spaces.
4520
4521 @kindex info breakpoints
4522 @cindex @code{$_} and @code{info breakpoints}
4523 @item info breakpoints @r{[}@var{list}@dots{}@r{]}
4524 @itemx info break @r{[}@var{list}@dots{}@r{]}
4525 Print a table of all breakpoints, watchpoints, and catchpoints set and
4526 not deleted. Optional argument @var{n} means print information only
4527 about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4528 For each breakpoint, following columns are printed:
4529
4530 @table @emph
4531 @item Breakpoint Numbers
4532 @item Type
4533 Breakpoint, watchpoint, or catchpoint.
4534 @item Disposition
4535 Whether the breakpoint is marked to be disabled or deleted when hit.
4536 @item Enabled or Disabled
4537 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
4538 that are not enabled.
4539 @item Address
4540 Where the breakpoint is in your program, as a memory address. For a
4541 pending breakpoint whose address is not yet known, this field will
4542 contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4543 library that has the symbol or line referred by breakpoint is loaded.
4544 See below for details. A breakpoint with several locations will
4545 have @samp{<MULTIPLE>} in this field---see below for details.
4546 @item What
4547 Where the breakpoint is in the source for your program, as a file and
4548 line number. For a pending breakpoint, the original string passed to
4549 the breakpoint command will be listed as it cannot be resolved until
4550 the appropriate shared library is loaded in the future.
4551 @end table
4552
4553 @noindent
4554 If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4555 ``target''. If mode is ``host'', breakpoint condition evaluation is done by
4556 @value{GDBN} on the host's side. If it is ``target'', then the condition
4557 is evaluated by the target. The @code{info break} command shows
4558 the condition on the line following the affected breakpoint, together with
4559 its condition evaluation mode in between parentheses.
4560
4561 Breakpoint commands, if any, are listed after that. A pending breakpoint is
4562 allowed to have a condition specified for it. The condition is not parsed for
4563 validity until a shared library is loaded that allows the pending
4564 breakpoint to resolve to a valid location.
4565
4566 @noindent
4567 @code{info break} with a breakpoint
4568 number @var{n} as argument lists only that breakpoint. The
4569 convenience variable @code{$_} and the default examining-address for
4570 the @code{x} command are set to the address of the last breakpoint
4571 listed (@pxref{Memory, ,Examining Memory}).
4572
4573 @noindent
4574 @code{info break} displays a count of the number of times the breakpoint
4575 has been hit. This is especially useful in conjunction with the
4576 @code{ignore} command. You can ignore a large number of breakpoint
4577 hits, look at the breakpoint info to see how many times the breakpoint
4578 was hit, and then run again, ignoring one less than that number. This
4579 will get you quickly to the last hit of that breakpoint.
4580
4581 @noindent
4582 For a breakpoints with an enable count (xref) greater than 1,
4583 @code{info break} also displays that count.
4584
4585 @end table
4586
4587 @value{GDBN} allows you to set any number of breakpoints at the same place in
4588 your program. There is nothing silly or meaningless about this. When
4589 the breakpoints are conditional, this is even useful
4590 (@pxref{Conditions, ,Break Conditions}).
4591
4592 @cindex multiple locations, breakpoints
4593 @cindex breakpoints, multiple locations
4594 It is possible that a breakpoint corresponds to several locations
4595 in your program. Examples of this situation are:
4596
4597 @itemize @bullet
4598 @item
4599 Multiple functions in the program may have the same name.
4600
4601 @item
4602 For a C@t{++} constructor, the @value{NGCC} compiler generates several
4603 instances of the function body, used in different cases.
4604
4605 @item
4606 For a C@t{++} template function, a given line in the function can
4607 correspond to any number of instantiations.
4608
4609 @item
4610 For an inlined function, a given source line can correspond to
4611 several places where that function is inlined.
4612 @end itemize
4613
4614 In all those cases, @value{GDBN} will insert a breakpoint at all
4615 the relevant locations.
4616
4617 A breakpoint with multiple locations is displayed in the breakpoint
4618 table using several rows---one header row, followed by one row for
4619 each breakpoint location. The header row has @samp{<MULTIPLE>} in the
4620 address column. The rows for individual locations contain the actual
4621 addresses for locations, and show the functions to which those
4622 locations belong. The number column for a location is of the form
4623 @var{breakpoint-number}.@var{location-number}.
4624
4625 For example:
4626
4627 @smallexample
4628 Num Type Disp Enb Address What
4629 1 breakpoint keep y <MULTIPLE>
4630 stop only if i==1
4631 breakpoint already hit 1 time
4632 1.1 y 0x080486a2 in void foo<int>() at t.cc:8
4633 1.2 y 0x080486ca in void foo<double>() at t.cc:8
4634 @end smallexample
4635
4636 You cannot delete the individual locations from a breakpoint. However,
4637 each location can be individually enabled or disabled by passing
4638 @var{breakpoint-number}.@var{location-number} as argument to the
4639 @code{enable} and @code{disable} commands. It's also possible to
4640 @code{enable} and @code{disable} a range of @var{location-number}
4641 locations using a @var{breakpoint-number} and two @var{location-number}s,
4642 in increasing order, separated by a hyphen, like
4643 @kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4644 in which case @value{GDBN} acts on all the locations in the range (inclusive).
4645 Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4646 all of the locations that belong to that breakpoint.
4647
4648 @cindex pending breakpoints
4649 It's quite common to have a breakpoint inside a shared library.
4650 Shared libraries can be loaded and unloaded explicitly,
4651 and possibly repeatedly, as the program is executed. To support
4652 this use case, @value{GDBN} updates breakpoint locations whenever
4653 any shared library is loaded or unloaded. Typically, you would
4654 set a breakpoint in a shared library at the beginning of your
4655 debugging session, when the library is not loaded, and when the
4656 symbols from the library are not available. When you try to set
4657 breakpoint, @value{GDBN} will ask you if you want to set
4658 a so called @dfn{pending breakpoint}---breakpoint whose address
4659 is not yet resolved.
4660
4661 After the program is run, whenever a new shared library is loaded,
4662 @value{GDBN} reevaluates all the breakpoints. When a newly loaded
4663 shared library contains the symbol or line referred to by some
4664 pending breakpoint, that breakpoint is resolved and becomes an
4665 ordinary breakpoint. When a library is unloaded, all breakpoints
4666 that refer to its symbols or source lines become pending again.
4667
4668 This logic works for breakpoints with multiple locations, too. For
4669 example, if you have a breakpoint in a C@t{++} template function, and
4670 a newly loaded shared library has an instantiation of that template,
4671 a new location is added to the list of locations for the breakpoint.
4672
4673 Except for having unresolved address, pending breakpoints do not
4674 differ from regular breakpoints. You can set conditions or commands,
4675 enable and disable them and perform other breakpoint operations.
4676
4677 @value{GDBN} provides some additional commands for controlling what
4678 happens when the @samp{break} command cannot resolve breakpoint
4679 address specification to an address:
4680
4681 @kindex set breakpoint pending
4682 @kindex show breakpoint pending
4683 @table @code
4684 @item set breakpoint pending auto
4685 This is the default behavior. When @value{GDBN} cannot find the breakpoint
4686 location, it queries you whether a pending breakpoint should be created.
4687
4688 @item set breakpoint pending on
4689 This indicates that an unrecognized breakpoint location should automatically
4690 result in a pending breakpoint being created.
4691
4692 @item set breakpoint pending off
4693 This indicates that pending breakpoints are not to be created. Any
4694 unrecognized breakpoint location results in an error. This setting does
4695 not affect any pending breakpoints previously created.
4696
4697 @item show breakpoint pending
4698 Show the current behavior setting for creating pending breakpoints.
4699 @end table
4700
4701 The settings above only affect the @code{break} command and its
4702 variants. Once breakpoint is set, it will be automatically updated
4703 as shared libraries are loaded and unloaded.
4704
4705 @cindex automatic hardware breakpoints
4706 For some targets, @value{GDBN} can automatically decide if hardware or
4707 software breakpoints should be used, depending on whether the
4708 breakpoint address is read-only or read-write. This applies to
4709 breakpoints set with the @code{break} command as well as to internal
4710 breakpoints set by commands like @code{next} and @code{finish}. For
4711 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
4712 breakpoints.
4713
4714 You can control this automatic behaviour with the following commands:
4715
4716 @kindex set breakpoint auto-hw
4717 @kindex show breakpoint auto-hw
4718 @table @code
4719 @item set breakpoint auto-hw on
4720 This is the default behavior. When @value{GDBN} sets a breakpoint, it
4721 will try to use the target memory map to decide if software or hardware
4722 breakpoint must be used.
4723
4724 @item set breakpoint auto-hw off
4725 This indicates @value{GDBN} should not automatically select breakpoint
4726 type. If the target provides a memory map, @value{GDBN} will warn when
4727 trying to set software breakpoint at a read-only address.
4728 @end table
4729
4730 @value{GDBN} normally implements breakpoints by replacing the program code
4731 at the breakpoint address with a special instruction, which, when
4732 executed, given control to the debugger. By default, the program
4733 code is so modified only when the program is resumed. As soon as
4734 the program stops, @value{GDBN} restores the original instructions. This
4735 behaviour guards against leaving breakpoints inserted in the
4736 target should gdb abrubptly disconnect. However, with slow remote
4737 targets, inserting and removing breakpoint can reduce the performance.
4738 This behavior can be controlled with the following commands::
4739
4740 @kindex set breakpoint always-inserted
4741 @kindex show breakpoint always-inserted
4742 @table @code
4743 @item set breakpoint always-inserted off
4744 All breakpoints, including newly added by the user, are inserted in
4745 the target only when the target is resumed. All breakpoints are
4746 removed from the target when it stops. This is the default mode.
4747
4748 @item set breakpoint always-inserted on
4749 Causes all breakpoints to be inserted in the target at all times. If
4750 the user adds a new breakpoint, or changes an existing breakpoint, the
4751 breakpoints in the target are updated immediately. A breakpoint is
4752 removed from the target only when breakpoint itself is deleted.
4753 @end table
4754
4755 @value{GDBN} handles conditional breakpoints by evaluating these conditions
4756 when a breakpoint breaks. If the condition is true, then the process being
4757 debugged stops, otherwise the process is resumed.
4758
4759 If the target supports evaluating conditions on its end, @value{GDBN} may
4760 download the breakpoint, together with its conditions, to it.
4761
4762 This feature can be controlled via the following commands:
4763
4764 @kindex set breakpoint condition-evaluation
4765 @kindex show breakpoint condition-evaluation
4766 @table @code
4767 @item set breakpoint condition-evaluation host
4768 This option commands @value{GDBN} to evaluate the breakpoint
4769 conditions on the host's side. Unconditional breakpoints are sent to
4770 the target which in turn receives the triggers and reports them back to GDB
4771 for condition evaluation. This is the standard evaluation mode.
4772
4773 @item set breakpoint condition-evaluation target
4774 This option commands @value{GDBN} to download breakpoint conditions
4775 to the target at the moment of their insertion. The target
4776 is responsible for evaluating the conditional expression and reporting
4777 breakpoint stop events back to @value{GDBN} whenever the condition
4778 is true. Due to limitations of target-side evaluation, some conditions
4779 cannot be evaluated there, e.g., conditions that depend on local data
4780 that is only known to the host. Examples include
4781 conditional expressions involving convenience variables, complex types
4782 that cannot be handled by the agent expression parser and expressions
4783 that are too long to be sent over to the target, specially when the
4784 target is a remote system. In these cases, the conditions will be
4785 evaluated by @value{GDBN}.
4786
4787 @item set breakpoint condition-evaluation auto
4788 This is the default mode. If the target supports evaluating breakpoint
4789 conditions on its end, @value{GDBN} will download breakpoint conditions to
4790 the target (limitations mentioned previously apply). If the target does
4791 not support breakpoint condition evaluation, then @value{GDBN} will fallback
4792 to evaluating all these conditions on the host's side.
4793 @end table
4794
4795
4796 @cindex negative breakpoint numbers
4797 @cindex internal @value{GDBN} breakpoints
4798 @value{GDBN} itself sometimes sets breakpoints in your program for
4799 special purposes, such as proper handling of @code{longjmp} (in C
4800 programs). These internal breakpoints are assigned negative numbers,
4801 starting with @code{-1}; @samp{info breakpoints} does not display them.
4802 You can see these breakpoints with the @value{GDBN} maintenance command
4803 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
4804
4805
4806 @node Set Watchpoints
4807 @subsection Setting Watchpoints
4808
4809 @cindex setting watchpoints
4810 You can use a watchpoint to stop execution whenever the value of an
4811 expression changes, without having to predict a particular place where
4812 this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4813 The expression may be as simple as the value of a single variable, or
4814 as complex as many variables combined by operators. Examples include:
4815
4816 @itemize @bullet
4817 @item
4818 A reference to the value of a single variable.
4819
4820 @item
4821 An address cast to an appropriate data type. For example,
4822 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4823 address (assuming an @code{int} occupies 4 bytes).
4824
4825 @item
4826 An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4827 expression can use any operators valid in the program's native
4828 language (@pxref{Languages}).
4829 @end itemize
4830
4831 You can set a watchpoint on an expression even if the expression can
4832 not be evaluated yet. For instance, you can set a watchpoint on
4833 @samp{*global_ptr} before @samp{global_ptr} is initialized.
4834 @value{GDBN} will stop when your program sets @samp{global_ptr} and
4835 the expression produces a valid value. If the expression becomes
4836 valid in some other way than changing a variable (e.g.@: if the memory
4837 pointed to by @samp{*global_ptr} becomes readable as the result of a
4838 @code{malloc} call), @value{GDBN} may not stop until the next time
4839 the expression changes.
4840
4841 @cindex software watchpoints
4842 @cindex hardware watchpoints
4843 Depending on your system, watchpoints may be implemented in software or
4844 hardware. @value{GDBN} does software watchpointing by single-stepping your
4845 program and testing the variable's value each time, which is hundreds of
4846 times slower than normal execution. (But this may still be worth it, to
4847 catch errors where you have no clue what part of your program is the
4848 culprit.)
4849
4850 On some systems, such as most PowerPC or x86-based targets,
4851 @value{GDBN} includes support for hardware watchpoints, which do not
4852 slow down the running of your program.
4853
4854 @table @code
4855 @kindex watch
4856 @item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4857 Set a watchpoint for an expression. @value{GDBN} will break when the
4858 expression @var{expr} is written into by the program and its value
4859 changes. The simplest (and the most popular) use of this command is
4860 to watch the value of a single variable:
4861
4862 @smallexample
4863 (@value{GDBP}) watch foo
4864 @end smallexample
4865
4866 If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
4867 argument, @value{GDBN} breaks only when the thread identified by
4868 @var{thread-id} changes the value of @var{expr}. If any other threads
4869 change the value of @var{expr}, @value{GDBN} will not break. Note
4870 that watchpoints restricted to a single thread in this way only work
4871 with Hardware Watchpoints.
4872
4873 Ordinarily a watchpoint respects the scope of variables in @var{expr}
4874 (see below). The @code{-location} argument tells @value{GDBN} to
4875 instead watch the memory referred to by @var{expr}. In this case,
4876 @value{GDBN} will evaluate @var{expr}, take the address of the result,
4877 and watch the memory at that address. The type of the result is used
4878 to determine the size of the watched memory. If the expression's
4879 result does not have an address, then @value{GDBN} will print an
4880 error.
4881
4882 The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4883 of masked watchpoints, if the current architecture supports this
4884 feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4885 Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4886 to an address to watch. The mask specifies that some bits of an address
4887 (the bits which are reset in the mask) should be ignored when matching
4888 the address accessed by the inferior against the watchpoint address.
4889 Thus, a masked watchpoint watches many addresses simultaneously---those
4890 addresses whose unmasked bits are identical to the unmasked bits in the
4891 watchpoint address. The @code{mask} argument implies @code{-location}.
4892 Examples:
4893
4894 @smallexample
4895 (@value{GDBP}) watch foo mask 0xffff00ff
4896 (@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4897 @end smallexample
4898
4899 @kindex rwatch
4900 @item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4901 Set a watchpoint that will break when the value of @var{expr} is read
4902 by the program.
4903
4904 @kindex awatch
4905 @item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4906 Set a watchpoint that will break when @var{expr} is either read from
4907 or written into by the program.
4908
4909 @kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4910 @item info watchpoints @r{[}@var{list}@dots{}@r{]}
4911 This command prints a list of watchpoints, using the same format as
4912 @code{info break} (@pxref{Set Breaks}).
4913 @end table
4914
4915 If you watch for a change in a numerically entered address you need to
4916 dereference it, as the address itself is just a constant number which will
4917 never change. @value{GDBN} refuses to create a watchpoint that watches
4918 a never-changing value:
4919
4920 @smallexample
4921 (@value{GDBP}) watch 0x600850
4922 Cannot watch constant value 0x600850.
4923 (@value{GDBP}) watch *(int *) 0x600850
4924 Watchpoint 1: *(int *) 6293584
4925 @end smallexample
4926
4927 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4928 watchpoints execute very quickly, and the debugger reports a change in
4929 value at the exact instruction where the change occurs. If @value{GDBN}
4930 cannot set a hardware watchpoint, it sets a software watchpoint, which
4931 executes more slowly and reports the change in value at the next
4932 @emph{statement}, not the instruction, after the change occurs.
4933
4934 @cindex use only software watchpoints
4935 You can force @value{GDBN} to use only software watchpoints with the
4936 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4937 zero, @value{GDBN} will never try to use hardware watchpoints, even if
4938 the underlying system supports them. (Note that hardware-assisted
4939 watchpoints that were set @emph{before} setting
4940 @code{can-use-hw-watchpoints} to zero will still use the hardware
4941 mechanism of watching expression values.)
4942
4943 @table @code
4944 @item set can-use-hw-watchpoints
4945 @kindex set can-use-hw-watchpoints
4946 Set whether or not to use hardware watchpoints.
4947
4948 @item show can-use-hw-watchpoints
4949 @kindex show can-use-hw-watchpoints
4950 Show the current mode of using hardware watchpoints.
4951 @end table
4952
4953 For remote targets, you can restrict the number of hardware
4954 watchpoints @value{GDBN} will use, see @ref{set remote
4955 hardware-breakpoint-limit}.
4956
4957 When you issue the @code{watch} command, @value{GDBN} reports
4958
4959 @smallexample
4960 Hardware watchpoint @var{num}: @var{expr}
4961 @end smallexample
4962
4963 @noindent
4964 if it was able to set a hardware watchpoint.
4965
4966 Currently, the @code{awatch} and @code{rwatch} commands can only set
4967 hardware watchpoints, because accesses to data that don't change the
4968 value of the watched expression cannot be detected without examining
4969 every instruction as it is being executed, and @value{GDBN} does not do
4970 that currently. If @value{GDBN} finds that it is unable to set a
4971 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4972 will print a message like this:
4973
4974 @smallexample
4975 Expression cannot be implemented with read/access watchpoint.
4976 @end smallexample
4977
4978 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4979 data type of the watched expression is wider than what a hardware
4980 watchpoint on the target machine can handle. For example, some systems
4981 can only watch regions that are up to 4 bytes wide; on such systems you
4982 cannot set hardware watchpoints for an expression that yields a
4983 double-precision floating-point number (which is typically 8 bytes
4984 wide). As a work-around, it might be possible to break the large region
4985 into a series of smaller ones and watch them with separate watchpoints.
4986
4987 If you set too many hardware watchpoints, @value{GDBN} might be unable
4988 to insert all of them when you resume the execution of your program.
4989 Since the precise number of active watchpoints is unknown until such
4990 time as the program is about to be resumed, @value{GDBN} might not be
4991 able to warn you about this when you set the watchpoints, and the
4992 warning will be printed only when the program is resumed:
4993
4994 @smallexample
4995 Hardware watchpoint @var{num}: Could not insert watchpoint
4996 @end smallexample
4997
4998 @noindent
4999 If this happens, delete or disable some of the watchpoints.
5000
5001 Watching complex expressions that reference many variables can also
5002 exhaust the resources available for hardware-assisted watchpoints.
5003 That's because @value{GDBN} needs to watch every variable in the
5004 expression with separately allocated resources.
5005
5006 If you call a function interactively using @code{print} or @code{call},
5007 any watchpoints you have set will be inactive until @value{GDBN} reaches another
5008 kind of breakpoint or the call completes.
5009
5010 @value{GDBN} automatically deletes watchpoints that watch local
5011 (automatic) variables, or expressions that involve such variables, when
5012 they go out of scope, that is, when the execution leaves the block in
5013 which these variables were defined. In particular, when the program
5014 being debugged terminates, @emph{all} local variables go out of scope,
5015 and so only watchpoints that watch global variables remain set. If you
5016 rerun the program, you will need to set all such watchpoints again. One
5017 way of doing that would be to set a code breakpoint at the entry to the
5018 @code{main} function and when it breaks, set all the watchpoints.
5019
5020 @cindex watchpoints and threads
5021 @cindex threads and watchpoints
5022 In multi-threaded programs, watchpoints will detect changes to the
5023 watched expression from every thread.
5024
5025 @quotation
5026 @emph{Warning:} In multi-threaded programs, software watchpoints
5027 have only limited usefulness. If @value{GDBN} creates a software
5028 watchpoint, it can only watch the value of an expression @emph{in a
5029 single thread}. If you are confident that the expression can only
5030 change due to the current thread's activity (and if you are also
5031 confident that no other thread can become current), then you can use
5032 software watchpoints as usual. However, @value{GDBN} may not notice
5033 when a non-current thread's activity changes the expression. (Hardware
5034 watchpoints, in contrast, watch an expression in all threads.)
5035 @end quotation
5036
5037 @xref{set remote hardware-watchpoint-limit}.
5038
5039 @node Set Catchpoints
5040 @subsection Setting Catchpoints
5041 @cindex catchpoints, setting
5042 @cindex exception handlers
5043 @cindex event handling
5044
5045 You can use @dfn{catchpoints} to cause the debugger to stop for certain
5046 kinds of program events, such as C@t{++} exceptions or the loading of a
5047 shared library. Use the @code{catch} command to set a catchpoint.
5048
5049 @table @code
5050 @kindex catch
5051 @item catch @var{event}
5052 Stop when @var{event} occurs. The @var{event} can be any of the following:
5053
5054 @table @code
5055 @item throw @r{[}@var{regexp}@r{]}
5056 @itemx rethrow @r{[}@var{regexp}@r{]}
5057 @itemx catch @r{[}@var{regexp}@r{]}
5058 @kindex catch throw
5059 @kindex catch rethrow
5060 @kindex catch catch
5061 @cindex stop on C@t{++} exceptions
5062 The throwing, re-throwing, or catching of a C@t{++} exception.
5063
5064 If @var{regexp} is given, then only exceptions whose type matches the
5065 regular expression will be caught.
5066
5067 @vindex $_exception@r{, convenience variable}
5068 The convenience variable @code{$_exception} is available at an
5069 exception-related catchpoint, on some systems. This holds the
5070 exception being thrown.
5071
5072 There are currently some limitations to C@t{++} exception handling in
5073 @value{GDBN}:
5074
5075 @itemize @bullet
5076 @item
5077 The support for these commands is system-dependent. Currently, only
5078 systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
5079 supported.
5080
5081 @item
5082 The regular expression feature and the @code{$_exception} convenience
5083 variable rely on the presence of some SDT probes in @code{libstdc++}.
5084 If these probes are not present, then these features cannot be used.
5085 These probes were first available in the GCC 4.8 release, but whether
5086 or not they are available in your GCC also depends on how it was
5087 built.
5088
5089 @item
5090 The @code{$_exception} convenience variable is only valid at the
5091 instruction at which an exception-related catchpoint is set.
5092
5093 @item
5094 When an exception-related catchpoint is hit, @value{GDBN} stops at a
5095 location in the system library which implements runtime exception
5096 support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
5097 (@pxref{Selection}) to get to your code.
5098
5099 @item
5100 If you call a function interactively, @value{GDBN} normally returns
5101 control to you when the function has finished executing. If the call
5102 raises an exception, however, the call may bypass the mechanism that
5103 returns control to you and cause your program either to abort or to
5104 simply continue running until it hits a breakpoint, catches a signal
5105 that @value{GDBN} is listening for, or exits. This is the case even if
5106 you set a catchpoint for the exception; catchpoints on exceptions are
5107 disabled within interactive calls. @xref{Calling}, for information on
5108 controlling this with @code{set unwind-on-terminating-exception}.
5109
5110 @item
5111 You cannot raise an exception interactively.
5112
5113 @item
5114 You cannot install an exception handler interactively.
5115 @end itemize
5116
5117 @item exception @r{[}@var{name}@r{]}
5118 @kindex catch exception
5119 @cindex Ada exception catching
5120 @cindex catch Ada exceptions
5121 An Ada exception being raised. If an exception name is specified
5122 at the end of the command (eg @code{catch exception Program_Error}),
5123 the debugger will stop only when this specific exception is raised.
5124 Otherwise, the debugger stops execution when any Ada exception is raised.
5125
5126 When inserting an exception catchpoint on a user-defined exception whose
5127 name is identical to one of the exceptions defined by the language, the
5128 fully qualified name must be used as the exception name. Otherwise,
5129 @value{GDBN} will assume that it should stop on the pre-defined exception
5130 rather than the user-defined one. For instance, assuming an exception
5131 called @code{Constraint_Error} is defined in package @code{Pck}, then
5132 the command to use to catch such exceptions is @kbd{catch exception
5133 Pck.Constraint_Error}.
5134
5135 @vindex $_ada_exception@r{, convenience variable}
5136 The convenience variable @code{$_ada_exception} holds the address of
5137 the exception being thrown. This can be useful when setting a
5138 condition for such a catchpoint.
5139
5140 @item exception unhandled
5141 @kindex catch exception unhandled
5142 An exception that was raised but is not handled by the program. The
5143 convenience variable @code{$_ada_exception} is set as for @code{catch
5144 exception}.
5145
5146 @item handlers @r{[}@var{name}@r{]}
5147 @kindex catch handlers
5148 @cindex Ada exception handlers catching
5149 @cindex catch Ada exceptions when handled
5150 An Ada exception being handled. If an exception name is
5151 specified at the end of the command
5152 (eg @kbd{catch handlers Program_Error}), the debugger will stop
5153 only when this specific exception is handled.
5154 Otherwise, the debugger stops execution when any Ada exception is handled.
5155
5156 When inserting a handlers catchpoint on a user-defined
5157 exception whose name is identical to one of the exceptions
5158 defined by the language, the fully qualified name must be used
5159 as the exception name. Otherwise, @value{GDBN} will assume that it
5160 should stop on the pre-defined exception rather than the
5161 user-defined one. For instance, assuming an exception called
5162 @code{Constraint_Error} is defined in package @code{Pck}, then the
5163 command to use to catch such exceptions handling is
5164 @kbd{catch handlers Pck.Constraint_Error}.
5165
5166 The convenience variable @code{$_ada_exception} is set as for
5167 @code{catch exception}.
5168
5169 @item assert
5170 @kindex catch assert
5171 A failed Ada assertion. Note that the convenience variable
5172 @code{$_ada_exception} is @emph{not} set by this catchpoint.
5173
5174 @item exec
5175 @kindex catch exec
5176 @cindex break on fork/exec
5177 A call to @code{exec}.
5178
5179 @anchor{catch syscall}
5180 @item syscall
5181 @itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
5182 @kindex catch syscall
5183 @cindex break on a system call.
5184 A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
5185 syscall is a mechanism for application programs to request a service
5186 from the operating system (OS) or one of the OS system services.
5187 @value{GDBN} can catch some or all of the syscalls issued by the
5188 debuggee, and show the related information for each syscall. If no
5189 argument is specified, calls to and returns from all system calls
5190 will be caught.
5191
5192 @var{name} can be any system call name that is valid for the
5193 underlying OS. Just what syscalls are valid depends on the OS. On
5194 GNU and Unix systems, you can find the full list of valid syscall
5195 names on @file{/usr/include/asm/unistd.h}.
5196
5197 @c For MS-Windows, the syscall names and the corresponding numbers
5198 @c can be found, e.g., on this URL:
5199 @c http://www.metasploit.com/users/opcode/syscalls.html
5200 @c but we don't support Windows syscalls yet.
5201
5202 Normally, @value{GDBN} knows in advance which syscalls are valid for
5203 each OS, so you can use the @value{GDBN} command-line completion
5204 facilities (@pxref{Completion,, command completion}) to list the
5205 available choices.
5206
5207 You may also specify the system call numerically. A syscall's
5208 number is the value passed to the OS's syscall dispatcher to
5209 identify the requested service. When you specify the syscall by its
5210 name, @value{GDBN} uses its database of syscalls to convert the name
5211 into the corresponding numeric code, but using the number directly
5212 may be useful if @value{GDBN}'s database does not have the complete
5213 list of syscalls on your system (e.g., because @value{GDBN} lags
5214 behind the OS upgrades).
5215
5216 You may specify a group of related syscalls to be caught at once using
5217 the @code{group:} syntax (@code{g:} is a shorter equivalent). For
5218 instance, on some platforms @value{GDBN} allows you to catch all
5219 network related syscalls, by passing the argument @code{group:network}
5220 to @code{catch syscall}. Note that not all syscall groups are
5221 available in every system. You can use the command completion
5222 facilities (@pxref{Completion,, command completion}) to list the
5223 syscall groups available on your environment.
5224
5225 The example below illustrates how this command works if you don't provide
5226 arguments to it:
5227
5228 @smallexample
5229 (@value{GDBP}) catch syscall
5230 Catchpoint 1 (syscall)
5231 (@value{GDBP}) r
5232 Starting program: /tmp/catch-syscall
5233
5234 Catchpoint 1 (call to syscall 'close'), \
5235 0xffffe424 in __kernel_vsyscall ()
5236 (@value{GDBP}) c
5237 Continuing.
5238
5239 Catchpoint 1 (returned from syscall 'close'), \
5240 0xffffe424 in __kernel_vsyscall ()
5241 (@value{GDBP})
5242 @end smallexample
5243
5244 Here is an example of catching a system call by name:
5245
5246 @smallexample
5247 (@value{GDBP}) catch syscall chroot
5248 Catchpoint 1 (syscall 'chroot' [61])
5249 (@value{GDBP}) r
5250 Starting program: /tmp/catch-syscall
5251
5252 Catchpoint 1 (call to syscall 'chroot'), \
5253 0xffffe424 in __kernel_vsyscall ()
5254 (@value{GDBP}) c
5255 Continuing.
5256
5257 Catchpoint 1 (returned from syscall 'chroot'), \
5258 0xffffe424 in __kernel_vsyscall ()
5259 (@value{GDBP})
5260 @end smallexample
5261
5262 An example of specifying a system call numerically. In the case
5263 below, the syscall number has a corresponding entry in the XML
5264 file, so @value{GDBN} finds its name and prints it:
5265
5266 @smallexample
5267 (@value{GDBP}) catch syscall 252
5268 Catchpoint 1 (syscall(s) 'exit_group')
5269 (@value{GDBP}) r
5270 Starting program: /tmp/catch-syscall
5271
5272 Catchpoint 1 (call to syscall 'exit_group'), \
5273 0xffffe424 in __kernel_vsyscall ()
5274 (@value{GDBP}) c
5275 Continuing.
5276
5277 Program exited normally.
5278 (@value{GDBP})
5279 @end smallexample
5280
5281 Here is an example of catching a syscall group:
5282
5283 @smallexample
5284 (@value{GDBP}) catch syscall group:process
5285 Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5286 'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5287 'exit_group' [252] 'waitid' [284] 'unshare' [310])
5288 (@value{GDBP}) r
5289 Starting program: /tmp/catch-syscall
5290
5291 Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5292 from /lib64/ld-linux-x86-64.so.2
5293
5294 (@value{GDBP}) c
5295 Continuing.
5296 @end smallexample
5297
5298 However, there can be situations when there is no corresponding name
5299 in XML file for that syscall number. In this case, @value{GDBN} prints
5300 a warning message saying that it was not able to find the syscall name,
5301 but the catchpoint will be set anyway. See the example below:
5302
5303 @smallexample
5304 (@value{GDBP}) catch syscall 764
5305 warning: The number '764' does not represent a known syscall.
5306 Catchpoint 2 (syscall 764)
5307 (@value{GDBP})
5308 @end smallexample
5309
5310 If you configure @value{GDBN} using the @samp{--without-expat} option,
5311 it will not be able to display syscall names. Also, if your
5312 architecture does not have an XML file describing its system calls,
5313 you will not be able to see the syscall names. It is important to
5314 notice that these two features are used for accessing the syscall
5315 name database. In either case, you will see a warning like this:
5316
5317 @smallexample
5318 (@value{GDBP}) catch syscall
5319 warning: Could not open "syscalls/i386-linux.xml"
5320 warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5321 GDB will not be able to display syscall names.
5322 Catchpoint 1 (syscall)
5323 (@value{GDBP})
5324 @end smallexample
5325
5326 Of course, the file name will change depending on your architecture and system.
5327
5328 Still using the example above, you can also try to catch a syscall by its
5329 number. In this case, you would see something like:
5330
5331 @smallexample
5332 (@value{GDBP}) catch syscall 252
5333 Catchpoint 1 (syscall(s) 252)
5334 @end smallexample
5335
5336 Again, in this case @value{GDBN} would not be able to display syscall's names.
5337
5338 @item fork
5339 @kindex catch fork
5340 A call to @code{fork}.
5341
5342 @item vfork
5343 @kindex catch vfork
5344 A call to @code{vfork}.
5345
5346 @item load @r{[}@var{regexp}@r{]}
5347 @itemx unload @r{[}@var{regexp}@r{]}
5348 @kindex catch load
5349 @kindex catch unload
5350 The loading or unloading of a shared library. If @var{regexp} is
5351 given, then the catchpoint will stop only if the regular expression
5352 matches one of the affected libraries.
5353
5354 @item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5355 @kindex catch signal
5356 The delivery of a signal.
5357
5358 With no arguments, this catchpoint will catch any signal that is not
5359 used internally by @value{GDBN}, specifically, all signals except
5360 @samp{SIGTRAP} and @samp{SIGINT}.
5361
5362 With the argument @samp{all}, all signals, including those used by
5363 @value{GDBN}, will be caught. This argument cannot be used with other
5364 signal names.
5365
5366 Otherwise, the arguments are a list of signal names as given to
5367 @code{handle} (@pxref{Signals}). Only signals specified in this list
5368 will be caught.
5369
5370 One reason that @code{catch signal} can be more useful than
5371 @code{handle} is that you can attach commands and conditions to the
5372 catchpoint.
5373
5374 When a signal is caught by a catchpoint, the signal's @code{stop} and
5375 @code{print} settings, as specified by @code{handle}, are ignored.
5376 However, whether the signal is still delivered to the inferior depends
5377 on the @code{pass} setting; this can be changed in the catchpoint's
5378 commands.
5379
5380 @end table
5381
5382 @item tcatch @var{event}
5383 @kindex tcatch
5384 Set a catchpoint that is enabled only for one stop. The catchpoint is
5385 automatically deleted after the first time the event is caught.
5386
5387 @end table
5388
5389 Use the @code{info break} command to list the current catchpoints.
5390
5391
5392 @node Delete Breaks
5393 @subsection Deleting Breakpoints
5394
5395 @cindex clearing breakpoints, watchpoints, catchpoints
5396 @cindex deleting breakpoints, watchpoints, catchpoints
5397 It is often necessary to eliminate a breakpoint, watchpoint, or
5398 catchpoint once it has done its job and you no longer want your program
5399 to stop there. This is called @dfn{deleting} the breakpoint. A
5400 breakpoint that has been deleted no longer exists; it is forgotten.
5401
5402 With the @code{clear} command you can delete breakpoints according to
5403 where they are in your program. With the @code{delete} command you can
5404 delete individual breakpoints, watchpoints, or catchpoints by specifying
5405 their breakpoint numbers.
5406
5407 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5408 automatically ignores breakpoints on the first instruction to be executed
5409 when you continue execution without changing the execution address.
5410
5411 @table @code
5412 @kindex clear
5413 @item clear
5414 Delete any breakpoints at the next instruction to be executed in the
5415 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
5416 the innermost frame is selected, this is a good way to delete a
5417 breakpoint where your program just stopped.
5418
5419 @item clear @var{location}
5420 Delete any breakpoints set at the specified @var{location}.
5421 @xref{Specify Location}, for the various forms of @var{location}; the
5422 most useful ones are listed below:
5423
5424 @table @code
5425 @item clear @var{function}
5426 @itemx clear @var{filename}:@var{function}
5427 Delete any breakpoints set at entry to the named @var{function}.
5428
5429 @item clear @var{linenum}
5430 @itemx clear @var{filename}:@var{linenum}
5431 Delete any breakpoints set at or within the code of the specified
5432 @var{linenum} of the specified @var{filename}.
5433 @end table
5434
5435 @cindex delete breakpoints
5436 @kindex delete
5437 @kindex d @r{(@code{delete})}
5438 @item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5439 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
5440 list specified as argument. If no argument is specified, delete all
5441 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5442 confirm off}). You can abbreviate this command as @code{d}.
5443 @end table
5444
5445 @node Disabling
5446 @subsection Disabling Breakpoints
5447
5448 @cindex enable/disable a breakpoint
5449 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5450 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5451 it had been deleted, but remembers the information on the breakpoint so
5452 that you can @dfn{enable} it again later.
5453
5454 You disable and enable breakpoints, watchpoints, and catchpoints with
5455 the @code{enable} and @code{disable} commands, optionally specifying
5456 one or more breakpoint numbers as arguments. Use @code{info break} to
5457 print a list of all breakpoints, watchpoints, and catchpoints if you
5458 do not know which numbers to use.
5459
5460 Disabling and enabling a breakpoint that has multiple locations
5461 affects all of its locations.
5462
5463 A breakpoint, watchpoint, or catchpoint can have any of several
5464 different states of enablement:
5465
5466 @itemize @bullet
5467 @item
5468 Enabled. The breakpoint stops your program. A breakpoint set
5469 with the @code{break} command starts out in this state.
5470 @item
5471 Disabled. The breakpoint has no effect on your program.
5472 @item
5473 Enabled once. The breakpoint stops your program, but then becomes
5474 disabled.
5475 @item
5476 Enabled for a count. The breakpoint stops your program for the next
5477 N times, then becomes disabled.
5478 @item
5479 Enabled for deletion. The breakpoint stops your program, but
5480 immediately after it does so it is deleted permanently. A breakpoint
5481 set with the @code{tbreak} command starts out in this state.
5482 @end itemize
5483
5484 You can use the following commands to enable or disable breakpoints,
5485 watchpoints, and catchpoints:
5486
5487 @table @code
5488 @kindex disable
5489 @kindex dis @r{(@code{disable})}
5490 @item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5491 Disable the specified breakpoints---or all breakpoints, if none are
5492 listed. A disabled breakpoint has no effect but is not forgotten. All
5493 options such as ignore-counts, conditions and commands are remembered in
5494 case the breakpoint is enabled again later. You may abbreviate
5495 @code{disable} as @code{dis}.
5496
5497 @kindex enable
5498 @item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5499 Enable the specified breakpoints (or all defined breakpoints). They
5500 become effective once again in stopping your program.
5501
5502 @item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
5503 Enable the specified breakpoints temporarily. @value{GDBN} disables any
5504 of these breakpoints immediately after stopping your program.
5505
5506 @item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
5507 Enable the specified breakpoints temporarily. @value{GDBN} records
5508 @var{count} with each of the specified breakpoints, and decrements a
5509 breakpoint's count when it is hit. When any count reaches 0,
5510 @value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5511 count (@pxref{Conditions, ,Break Conditions}), that will be
5512 decremented to 0 before @var{count} is affected.
5513
5514 @item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
5515 Enable the specified breakpoints to work once, then die. @value{GDBN}
5516 deletes any of these breakpoints as soon as your program stops there.
5517 Breakpoints set by the @code{tbreak} command start out in this state.
5518 @end table
5519
5520 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5521 @c confusing: tbreak is also initially enabled.
5522 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
5523 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
5524 subsequently, they become disabled or enabled only when you use one of
5525 the commands above. (The command @code{until} can set and delete a
5526 breakpoint of its own, but it does not change the state of your other
5527 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
5528 Stepping}.)
5529
5530 @node Conditions
5531 @subsection Break Conditions
5532 @cindex conditional breakpoints
5533 @cindex breakpoint conditions
5534
5535 @c FIXME what is scope of break condition expr? Context where wanted?
5536 @c in particular for a watchpoint?
5537 The simplest sort of breakpoint breaks every time your program reaches a
5538 specified place. You can also specify a @dfn{condition} for a
5539 breakpoint. A condition is just a Boolean expression in your
5540 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5541 a condition evaluates the expression each time your program reaches it,
5542 and your program stops only if the condition is @emph{true}.
5543
5544 This is the converse of using assertions for program validation; in that
5545 situation, you want to stop when the assertion is violated---that is,
5546 when the condition is false. In C, if you want to test an assertion expressed
5547 by the condition @var{assert}, you should set the condition
5548 @samp{! @var{assert}} on the appropriate breakpoint.
5549
5550 Conditions are also accepted for watchpoints; you may not need them,
5551 since a watchpoint is inspecting the value of an expression anyhow---but
5552 it might be simpler, say, to just set a watchpoint on a variable name,
5553 and specify a condition that tests whether the new value is an interesting
5554 one.
5555
5556 Break conditions can have side effects, and may even call functions in
5557 your program. This can be useful, for example, to activate functions
5558 that log program progress, or to use your own print functions to
5559 format special data structures. The effects are completely predictable
5560 unless there is another enabled breakpoint at the same address. (In
5561 that case, @value{GDBN} might see the other breakpoint first and stop your
5562 program without checking the condition of this one.) Note that
5563 breakpoint commands are usually more convenient and flexible than break
5564 conditions for the
5565 purpose of performing side effects when a breakpoint is reached
5566 (@pxref{Break Commands, ,Breakpoint Command Lists}).
5567
5568 Breakpoint conditions can also be evaluated on the target's side if
5569 the target supports it. Instead of evaluating the conditions locally,
5570 @value{GDBN} encodes the expression into an agent expression
5571 (@pxref{Agent Expressions}) suitable for execution on the target,
5572 independently of @value{GDBN}. Global variables become raw memory
5573 locations, locals become stack accesses, and so forth.
5574
5575 In this case, @value{GDBN} will only be notified of a breakpoint trigger
5576 when its condition evaluates to true. This mechanism may provide faster
5577 response times depending on the performance characteristics of the target
5578 since it does not need to keep @value{GDBN} informed about
5579 every breakpoint trigger, even those with false conditions.
5580
5581 Break conditions can be specified when a breakpoint is set, by using
5582 @samp{if} in the arguments to the @code{break} command. @xref{Set
5583 Breaks, ,Setting Breakpoints}. They can also be changed at any time
5584 with the @code{condition} command.
5585
5586 You can also use the @code{if} keyword with the @code{watch} command.
5587 The @code{catch} command does not recognize the @code{if} keyword;
5588 @code{condition} is the only way to impose a further condition on a
5589 catchpoint.
5590
5591 @table @code
5592 @kindex condition
5593 @item condition @var{bnum} @var{expression}
5594 Specify @var{expression} as the break condition for breakpoint,
5595 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5596 breakpoint @var{bnum} stops your program only if the value of
5597 @var{expression} is true (nonzero, in C). When you use
5598 @code{condition}, @value{GDBN} checks @var{expression} immediately for
5599 syntactic correctness, and to determine whether symbols in it have
5600 referents in the context of your breakpoint. If @var{expression} uses
5601 symbols not referenced in the context of the breakpoint, @value{GDBN}
5602 prints an error message:
5603
5604 @smallexample
5605 No symbol "foo" in current context.
5606 @end smallexample
5607
5608 @noindent
5609 @value{GDBN} does
5610 not actually evaluate @var{expression} at the time the @code{condition}
5611 command (or a command that sets a breakpoint with a condition, like
5612 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
5613
5614 @item condition -force @var{bnum} @var{expression}
5615 When the @code{-force} flag is used, define the condition even if
5616 @var{expression} is invalid at all the current locations of breakpoint
5617 @var{bnum}. This is similar to the @code{-force-condition} option
5618 of the @code{break} command.
5619
5620 @item condition @var{bnum}
5621 Remove the condition from breakpoint number @var{bnum}. It becomes
5622 an ordinary unconditional breakpoint.
5623 @end table
5624
5625 @cindex ignore count (of breakpoint)
5626 A special case of a breakpoint condition is to stop only when the
5627 breakpoint has been reached a certain number of times. This is so
5628 useful that there is a special way to do it, using the @dfn{ignore
5629 count} of the breakpoint. Every breakpoint has an ignore count, which
5630 is an integer. Most of the time, the ignore count is zero, and
5631 therefore has no effect. But if your program reaches a breakpoint whose
5632 ignore count is positive, then instead of stopping, it just decrements
5633 the ignore count by one and continues. As a result, if the ignore count
5634 value is @var{n}, the breakpoint does not stop the next @var{n} times
5635 your program reaches it.
5636
5637 @table @code
5638 @kindex ignore
5639 @item ignore @var{bnum} @var{count}
5640 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5641 The next @var{count} times the breakpoint is reached, your program's
5642 execution does not stop; other than to decrement the ignore count, @value{GDBN}
5643 takes no action.
5644
5645 To make the breakpoint stop the next time it is reached, specify
5646 a count of zero.
5647
5648 When you use @code{continue} to resume execution of your program from a
5649 breakpoint, you can specify an ignore count directly as an argument to
5650 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
5651 Stepping,,Continuing and Stepping}.
5652
5653 If a breakpoint has a positive ignore count and a condition, the
5654 condition is not checked. Once the ignore count reaches zero,
5655 @value{GDBN} resumes checking the condition.
5656
5657 You could achieve the effect of the ignore count with a condition such
5658 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5659 is decremented each time. @xref{Convenience Vars, ,Convenience
5660 Variables}.
5661 @end table
5662
5663 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5664
5665
5666 @node Break Commands
5667 @subsection Breakpoint Command Lists
5668
5669 @cindex breakpoint commands
5670 You can give any breakpoint (or watchpoint or catchpoint) a series of
5671 commands to execute when your program stops due to that breakpoint. For
5672 example, you might want to print the values of certain expressions, or
5673 enable other breakpoints.
5674
5675 @table @code
5676 @kindex commands
5677 @kindex end@r{ (breakpoint commands)}
5678 @item commands @r{[}@var{list}@dots{}@r{]}
5679 @itemx @dots{} @var{command-list} @dots{}
5680 @itemx end
5681 Specify a list of commands for the given breakpoints. The commands
5682 themselves appear on the following lines. Type a line containing just
5683 @code{end} to terminate the commands.
5684
5685 To remove all commands from a breakpoint, type @code{commands} and
5686 follow it immediately with @code{end}; that is, give no commands.
5687
5688 With no argument, @code{commands} refers to the last breakpoint,
5689 watchpoint, or catchpoint set (not to the breakpoint most recently
5690 encountered). If the most recent breakpoints were set with a single
5691 command, then the @code{commands} will apply to all the breakpoints
5692 set by that command. This applies to breakpoints set by
5693 @code{rbreak}, and also applies when a single @code{break} command
5694 creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5695 Expressions}).
5696 @end table
5697
5698 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5699 disabled within a @var{command-list}.
5700
5701 You can use breakpoint commands to start your program up again. Simply
5702 use the @code{continue} command, or @code{step}, or any other command
5703 that resumes execution.
5704
5705 Any other commands in the command list, after a command that resumes
5706 execution, are ignored. This is because any time you resume execution
5707 (even with a simple @code{next} or @code{step}), you may encounter
5708 another breakpoint---which could have its own command list, leading to
5709 ambiguities about which list to execute.
5710
5711 @kindex silent
5712 If the first command you specify in a command list is @code{silent}, the
5713 usual message about stopping at a breakpoint is not printed. This may
5714 be desirable for breakpoints that are to print a specific message and
5715 then continue. If none of the remaining commands print anything, you
5716 see no sign that the breakpoint was reached. @code{silent} is
5717 meaningful only at the beginning of a breakpoint command list.
5718
5719 The commands @code{echo}, @code{output}, and @code{printf} allow you to
5720 print precisely controlled output, and are often useful in silent
5721 breakpoints. @xref{Output, ,Commands for Controlled Output}.
5722
5723 For example, here is how you could use breakpoint commands to print the
5724 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5725
5726 @smallexample
5727 break foo if x>0
5728 commands
5729 silent
5730 printf "x is %d\n",x
5731 cont
5732 end
5733 @end smallexample
5734
5735 One application for breakpoint commands is to compensate for one bug so
5736 you can test for another. Put a breakpoint just after the erroneous line
5737 of code, give it a condition to detect the case in which something
5738 erroneous has been done, and give it commands to assign correct values
5739 to any variables that need them. End with the @code{continue} command
5740 so that your program does not stop, and start with the @code{silent}
5741 command so that no output is produced. Here is an example:
5742
5743 @smallexample
5744 break 403
5745 commands
5746 silent
5747 set x = y + 4
5748 cont
5749 end
5750 @end smallexample
5751
5752 @node Dynamic Printf
5753 @subsection Dynamic Printf
5754
5755 @cindex dynamic printf
5756 @cindex dprintf
5757 The dynamic printf command @code{dprintf} combines a breakpoint with
5758 formatted printing of your program's data to give you the effect of
5759 inserting @code{printf} calls into your program on-the-fly, without
5760 having to recompile it.
5761
5762 In its most basic form, the output goes to the GDB console. However,
5763 you can set the variable @code{dprintf-style} for alternate handling.
5764 For instance, you can ask to format the output by calling your
5765 program's @code{printf} function. This has the advantage that the
5766 characters go to the program's output device, so they can recorded in
5767 redirects to files and so forth.
5768
5769 If you are doing remote debugging with a stub or agent, you can also
5770 ask to have the printf handled by the remote agent. In addition to
5771 ensuring that the output goes to the remote program's device along
5772 with any other output the program might produce, you can also ask that
5773 the dprintf remain active even after disconnecting from the remote
5774 target. Using the stub/agent is also more efficient, as it can do
5775 everything without needing to communicate with @value{GDBN}.
5776
5777 @table @code
5778 @kindex dprintf
5779 @item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5780 Whenever execution reaches @var{location}, print the values of one or
5781 more @var{expressions} under the control of the string @var{template}.
5782 To print several values, separate them with commas.
5783
5784 @item set dprintf-style @var{style}
5785 Set the dprintf output to be handled in one of several different
5786 styles enumerated below. A change of style affects all existing
5787 dynamic printfs immediately. (If you need individual control over the
5788 print commands, simply define normal breakpoints with
5789 explicitly-supplied command lists.)
5790
5791 @table @code
5792 @item gdb
5793 @kindex dprintf-style gdb
5794 Handle the output using the @value{GDBN} @code{printf} command.
5795
5796 @item call
5797 @kindex dprintf-style call
5798 Handle the output by calling a function in your program (normally
5799 @code{printf}).
5800
5801 @item agent
5802 @kindex dprintf-style agent
5803 Have the remote debugging agent (such as @code{gdbserver}) handle
5804 the output itself. This style is only available for agents that
5805 support running commands on the target.
5806 @end table
5807
5808 @item set dprintf-function @var{function}
5809 Set the function to call if the dprintf style is @code{call}. By
5810 default its value is @code{printf}. You may set it to any expression.
5811 that @value{GDBN} can evaluate to a function, as per the @code{call}
5812 command.
5813
5814 @item set dprintf-channel @var{channel}
5815 Set a ``channel'' for dprintf. If set to a non-empty value,
5816 @value{GDBN} will evaluate it as an expression and pass the result as
5817 a first argument to the @code{dprintf-function}, in the manner of
5818 @code{fprintf} and similar functions. Otherwise, the dprintf format
5819 string will be the first argument, in the manner of @code{printf}.
5820
5821 As an example, if you wanted @code{dprintf} output to go to a logfile
5822 that is a standard I/O stream assigned to the variable @code{mylog},
5823 you could do the following:
5824
5825 @example
5826 (gdb) set dprintf-style call
5827 (gdb) set dprintf-function fprintf
5828 (gdb) set dprintf-channel mylog
5829 (gdb) dprintf 25,"at line 25, glob=%d\n",glob
5830 Dprintf 1 at 0x123456: file main.c, line 25.
5831 (gdb) info break
5832 1 dprintf keep y 0x00123456 in main at main.c:25
5833 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5834 continue
5835 (gdb)
5836 @end example
5837
5838 Note that the @code{info break} displays the dynamic printf commands
5839 as normal breakpoint commands; you can thus easily see the effect of
5840 the variable settings.
5841
5842 @item set disconnected-dprintf on
5843 @itemx set disconnected-dprintf off
5844 @kindex set disconnected-dprintf
5845 Choose whether @code{dprintf} commands should continue to run if
5846 @value{GDBN} has disconnected from the target. This only applies
5847 if the @code{dprintf-style} is @code{agent}.
5848
5849 @item show disconnected-dprintf off
5850 @kindex show disconnected-dprintf
5851 Show the current choice for disconnected @code{dprintf}.
5852
5853 @end table
5854
5855 @value{GDBN} does not check the validity of function and channel,
5856 relying on you to supply values that are meaningful for the contexts
5857 in which they are being used. For instance, the function and channel
5858 may be the values of local variables, but if that is the case, then
5859 all enabled dynamic prints must be at locations within the scope of
5860 those locals. If evaluation fails, @value{GDBN} will report an error.
5861
5862 @node Save Breakpoints
5863 @subsection How to save breakpoints to a file
5864
5865 To save breakpoint definitions to a file use the @w{@code{save
5866 breakpoints}} command.
5867
5868 @table @code
5869 @kindex save breakpoints
5870 @cindex save breakpoints to a file for future sessions
5871 @item save breakpoints [@var{filename}]
5872 This command saves all current breakpoint definitions together with
5873 their commands and ignore counts, into a file @file{@var{filename}}
5874 suitable for use in a later debugging session. This includes all
5875 types of breakpoints (breakpoints, watchpoints, catchpoints,
5876 tracepoints). To read the saved breakpoint definitions, use the
5877 @code{source} command (@pxref{Command Files}). Note that watchpoints
5878 with expressions involving local variables may fail to be recreated
5879 because it may not be possible to access the context where the
5880 watchpoint is valid anymore. Because the saved breakpoint definitions
5881 are simply a sequence of @value{GDBN} commands that recreate the
5882 breakpoints, you can edit the file in your favorite editing program,
5883 and remove the breakpoint definitions you're not interested in, or
5884 that can no longer be recreated.
5885 @end table
5886
5887 @node Static Probe Points
5888 @subsection Static Probe Points
5889
5890 @cindex static probe point, SystemTap
5891 @cindex static probe point, DTrace
5892 @value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5893 for Statically Defined Tracing, and the probes are designed to have a tiny
5894 runtime code and data footprint, and no dynamic relocations.
5895
5896 Currently, the following types of probes are supported on
5897 ELF-compatible systems:
5898
5899 @itemize @bullet
5900
5901 @item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5902 @acronym{SDT} probes@footnote{See
5903 @uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
5904 for more information on how to add @code{SystemTap} @acronym{SDT}
5905 probes in your applications.}. @code{SystemTap} probes are usable
5906 from assembly, C and C@t{++} languages@footnote{See
5907 @uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5908 for a good reference on how the @acronym{SDT} probes are implemented.}.
5909
5910 @item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5911 @acronym{USDT} probes. @code{DTrace} probes are usable from C and
5912 C@t{++} languages.
5913 @end itemize
5914
5915 @cindex semaphores on static probe points
5916 Some @code{SystemTap} probes have an associated semaphore variable;
5917 for instance, this happens automatically if you defined your probe
5918 using a DTrace-style @file{.d} file. If your probe has a semaphore,
5919 @value{GDBN} will automatically enable it when you specify a
5920 breakpoint using the @samp{-probe-stap} notation. But, if you put a
5921 breakpoint at a probe's location by some other method (e.g.,
5922 @code{break file:line}), then @value{GDBN} will not automatically set
5923 the semaphore. @code{DTrace} probes do not support semaphores.
5924
5925 You can examine the available static static probes using @code{info
5926 probes}, with optional arguments:
5927
5928 @table @code
5929 @kindex info probes
5930 @item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5931 If given, @var{type} is either @code{stap} for listing
5932 @code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5933 probes. If omitted all probes are listed regardless of their types.
5934
5935 If given, @var{provider} is a regular expression used to match against provider
5936 names when selecting which probes to list. If omitted, probes by all
5937 probes from all providers are listed.
5938
5939 If given, @var{name} is a regular expression to match against probe names
5940 when selecting which probes to list. If omitted, probe names are not
5941 considered when deciding whether to display them.
5942
5943 If given, @var{objfile} is a regular expression used to select which
5944 object files (executable or shared libraries) to examine. If not
5945 given, all object files are considered.
5946
5947 @item info probes all
5948 List the available static probes, from all types.
5949 @end table
5950
5951 @cindex enabling and disabling probes
5952 Some probe points can be enabled and/or disabled. The effect of
5953 enabling or disabling a probe depends on the type of probe being
5954 handled. Some @code{DTrace} probes can be enabled or
5955 disabled, but @code{SystemTap} probes cannot be disabled.
5956
5957 You can enable (or disable) one or more probes using the following
5958 commands, with optional arguments:
5959
5960 @table @code
5961 @kindex enable probes
5962 @item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5963 If given, @var{provider} is a regular expression used to match against
5964 provider names when selecting which probes to enable. If omitted,
5965 all probes from all providers are enabled.
5966
5967 If given, @var{name} is a regular expression to match against probe
5968 names when selecting which probes to enable. If omitted, probe names
5969 are not considered when deciding whether to enable them.
5970
5971 If given, @var{objfile} is a regular expression used to select which
5972 object files (executable or shared libraries) to examine. If not
5973 given, all object files are considered.
5974
5975 @kindex disable probes
5976 @item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5977 See the @code{enable probes} command above for a description of the
5978 optional arguments accepted by this command.
5979 @end table
5980
5981 @vindex $_probe_arg@r{, convenience variable}
5982 A probe may specify up to twelve arguments. These are available at the
5983 point at which the probe is defined---that is, when the current PC is
5984 at the probe's location. The arguments are available using the
5985 convenience variables (@pxref{Convenience Vars})
5986 @code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5987 probes each probe argument is an integer of the appropriate size;
5988 types are not preserved. In @code{DTrace} probes types are preserved
5989 provided that they are recognized as such by @value{GDBN}; otherwise
5990 the value of the probe argument will be a long integer. The
5991 convenience variable @code{$_probe_argc} holds the number of arguments
5992 at the current probe point.
5993
5994 These variables are always available, but attempts to access them at
5995 any location other than a probe point will cause @value{GDBN} to give
5996 an error message.
5997
5998
5999 @c @ifclear BARETARGET
6000 @node Error in Breakpoints
6001 @subsection ``Cannot insert breakpoints''
6002
6003 If you request too many active hardware-assisted breakpoints and
6004 watchpoints, you will see this error message:
6005
6006 @c FIXME: the precise wording of this message may change; the relevant
6007 @c source change is not committed yet (Sep 3, 1999).
6008 @smallexample
6009 Stopped; cannot insert breakpoints.
6010 You may have requested too many hardware breakpoints and watchpoints.
6011 @end smallexample
6012
6013 @noindent
6014 This message is printed when you attempt to resume the program, since
6015 only then @value{GDBN} knows exactly how many hardware breakpoints and
6016 watchpoints it needs to insert.
6017
6018 When this message is printed, you need to disable or remove some of the
6019 hardware-assisted breakpoints and watchpoints, and then continue.
6020
6021 @node Breakpoint-related Warnings
6022 @subsection ``Breakpoint address adjusted...''
6023 @cindex breakpoint address adjusted
6024
6025 Some processor architectures place constraints on the addresses at
6026 which breakpoints may be placed. For architectures thus constrained,
6027 @value{GDBN} will attempt to adjust the breakpoint's address to comply
6028 with the constraints dictated by the architecture.
6029
6030 One example of such an architecture is the Fujitsu FR-V. The FR-V is
6031 a VLIW architecture in which a number of RISC-like instructions may be
6032 bundled together for parallel execution. The FR-V architecture
6033 constrains the location of a breakpoint instruction within such a
6034 bundle to the instruction with the lowest address. @value{GDBN}
6035 honors this constraint by adjusting a breakpoint's address to the
6036 first in the bundle.
6037
6038 It is not uncommon for optimized code to have bundles which contain
6039 instructions from different source statements, thus it may happen that
6040 a breakpoint's address will be adjusted from one source statement to
6041 another. Since this adjustment may significantly alter @value{GDBN}'s
6042 breakpoint related behavior from what the user expects, a warning is
6043 printed when the breakpoint is first set and also when the breakpoint
6044 is hit.
6045
6046 A warning like the one below is printed when setting a breakpoint
6047 that's been subject to address adjustment:
6048
6049 @smallexample
6050 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
6051 @end smallexample
6052
6053 Such warnings are printed both for user settable and @value{GDBN}'s
6054 internal breakpoints. If you see one of these warnings, you should
6055 verify that a breakpoint set at the adjusted address will have the
6056 desired affect. If not, the breakpoint in question may be removed and
6057 other breakpoints may be set which will have the desired behavior.
6058 E.g., it may be sufficient to place the breakpoint at a later
6059 instruction. A conditional breakpoint may also be useful in some
6060 cases to prevent the breakpoint from triggering too often.
6061
6062 @value{GDBN} will also issue a warning when stopping at one of these
6063 adjusted breakpoints:
6064
6065 @smallexample
6066 warning: Breakpoint 1 address previously adjusted from 0x00010414
6067 to 0x00010410.
6068 @end smallexample
6069
6070 When this warning is encountered, it may be too late to take remedial
6071 action except in cases where the breakpoint is hit earlier or more
6072 frequently than expected.
6073
6074 @node Continuing and Stepping
6075 @section Continuing and Stepping
6076
6077 @cindex stepping
6078 @cindex continuing
6079 @cindex resuming execution
6080 @dfn{Continuing} means resuming program execution until your program
6081 completes normally. In contrast, @dfn{stepping} means executing just
6082 one more ``step'' of your program, where ``step'' may mean either one
6083 line of source code, or one machine instruction (depending on what
6084 particular command you use). Either when continuing or when stepping,
6085 your program may stop even sooner, due to a breakpoint or a signal. (If
6086 it stops due to a signal, you may want to use @code{handle}, or use
6087 @samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
6088 or you may step into the signal's handler (@pxref{stepping and signal
6089 handlers}).)
6090
6091 @table @code
6092 @kindex continue
6093 @kindex c @r{(@code{continue})}
6094 @kindex fg @r{(resume foreground execution)}
6095 @item continue @r{[}@var{ignore-count}@r{]}
6096 @itemx c @r{[}@var{ignore-count}@r{]}
6097 @itemx fg @r{[}@var{ignore-count}@r{]}
6098 Resume program execution, at the address where your program last stopped;
6099 any breakpoints set at that address are bypassed. The optional argument
6100 @var{ignore-count} allows you to specify a further number of times to
6101 ignore a breakpoint at this location; its effect is like that of
6102 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
6103
6104 The argument @var{ignore-count} is meaningful only when your program
6105 stopped due to a breakpoint. At other times, the argument to
6106 @code{continue} is ignored.
6107
6108 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
6109 debugged program is deemed to be the foreground program) are provided
6110 purely for convenience, and have exactly the same behavior as
6111 @code{continue}.
6112 @end table
6113
6114 To resume execution at a different place, you can use @code{return}
6115 (@pxref{Returning, ,Returning from a Function}) to go back to the
6116 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
6117 Different Address}) to go to an arbitrary location in your program.
6118
6119 A typical technique for using stepping is to set a breakpoint
6120 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
6121 beginning of the function or the section of your program where a problem
6122 is believed to lie, run your program until it stops at that breakpoint,
6123 and then step through the suspect area, examining the variables that are
6124 interesting, until you see the problem happen.
6125
6126 @table @code
6127 @kindex step
6128 @kindex s @r{(@code{step})}
6129 @item step
6130 Continue running your program until control reaches a different source
6131 line, then stop it and return control to @value{GDBN}. This command is
6132 abbreviated @code{s}.
6133
6134 @quotation
6135 @c "without debugging information" is imprecise; actually "without line
6136 @c numbers in the debugging information". (gcc -g1 has debugging info but
6137 @c not line numbers). But it seems complex to try to make that
6138 @c distinction here.
6139 @emph{Warning:} If you use the @code{step} command while control is
6140 within a function that was compiled without debugging information,
6141 execution proceeds until control reaches a function that does have
6142 debugging information. Likewise, it will not step into a function which
6143 is compiled without debugging information. To step through functions
6144 without debugging information, use the @code{stepi} command, described
6145 below.
6146 @end quotation
6147
6148 The @code{step} command only stops at the first instruction of a source
6149 line. This prevents the multiple stops that could otherwise occur in
6150 @code{switch} statements, @code{for} loops, etc. @code{step} continues
6151 to stop if a function that has debugging information is called within
6152 the line. In other words, @code{step} @emph{steps inside} any functions
6153 called within the line.
6154
6155 Also, the @code{step} command only enters a function if there is line
6156 number information for the function. Otherwise it acts like the
6157 @code{next} command. This avoids problems when using @code{cc -gl}
6158 on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
6159 was any debugging information about the routine.
6160
6161 @item step @var{count}
6162 Continue running as in @code{step}, but do so @var{count} times. If a
6163 breakpoint is reached, or a signal not related to stepping occurs before
6164 @var{count} steps, stepping stops right away.
6165
6166 @kindex next
6167 @kindex n @r{(@code{next})}
6168 @item next @r{[}@var{count}@r{]}
6169 Continue to the next source line in the current (innermost) stack frame.
6170 This is similar to @code{step}, but function calls that appear within
6171 the line of code are executed without stopping. Execution stops when
6172 control reaches a different line of code at the original stack level
6173 that was executing when you gave the @code{next} command. This command
6174 is abbreviated @code{n}.
6175
6176 An argument @var{count} is a repeat count, as for @code{step}.
6177
6178
6179 @c FIX ME!! Do we delete this, or is there a way it fits in with
6180 @c the following paragraph? --- Vctoria
6181 @c
6182 @c @code{next} within a function that lacks debugging information acts like
6183 @c @code{step}, but any function calls appearing within the code of the
6184 @c function are executed without stopping.
6185
6186 The @code{next} command only stops at the first instruction of a
6187 source line. This prevents multiple stops that could otherwise occur in
6188 @code{switch} statements, @code{for} loops, etc.
6189
6190 @kindex set step-mode
6191 @item set step-mode
6192 @cindex functions without line info, and stepping
6193 @cindex stepping into functions with no line info
6194 @itemx set step-mode on
6195 The @code{set step-mode on} command causes the @code{step} command to
6196 stop at the first instruction of a function which contains no debug line
6197 information rather than stepping over it.
6198
6199 This is useful in cases where you may be interested in inspecting the
6200 machine instructions of a function which has no symbolic info and do not
6201 want @value{GDBN} to automatically skip over this function.
6202
6203 @item set step-mode off
6204 Causes the @code{step} command to step over any functions which contains no
6205 debug information. This is the default.
6206
6207 @item show step-mode
6208 Show whether @value{GDBN} will stop in or step over functions without
6209 source line debug information.
6210
6211 @kindex finish
6212 @kindex fin @r{(@code{finish})}
6213 @item finish
6214 Continue running until just after function in the selected stack frame
6215 returns. Print the returned value (if any). This command can be
6216 abbreviated as @code{fin}.
6217
6218 Contrast this with the @code{return} command (@pxref{Returning,
6219 ,Returning from a Function}).
6220
6221 @kindex set print finish
6222 @kindex show print finish
6223 @item set print finish @r{[}on|off@r{]}
6224 @itemx show print finish
6225 By default the @code{finish} command will show the value that is
6226 returned by the function. This can be disabled using @code{set print
6227 finish off}. When disabled, the value is still entered into the value
6228 history (@pxref{Value History}), but not displayed.
6229
6230 @kindex until
6231 @kindex u @r{(@code{until})}
6232 @cindex run until specified location
6233 @item until
6234 @itemx u
6235 Continue running until a source line past the current line, in the
6236 current stack frame, is reached. This command is used to avoid single
6237 stepping through a loop more than once. It is like the @code{next}
6238 command, except that when @code{until} encounters a jump, it
6239 automatically continues execution until the program counter is greater
6240 than the address of the jump.
6241
6242 This means that when you reach the end of a loop after single stepping
6243 though it, @code{until} makes your program continue execution until it
6244 exits the loop. In contrast, a @code{next} command at the end of a loop
6245 simply steps back to the beginning of the loop, which forces you to step
6246 through the next iteration.
6247
6248 @code{until} always stops your program if it attempts to exit the current
6249 stack frame.
6250
6251 @code{until} may produce somewhat counterintuitive results if the order
6252 of machine code does not match the order of the source lines. For
6253 example, in the following excerpt from a debugging session, the @code{f}
6254 (@code{frame}) command shows that execution is stopped at line
6255 @code{206}; yet when we use @code{until}, we get to line @code{195}:
6256
6257 @smallexample
6258 (@value{GDBP}) f
6259 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
6260 206 expand_input();
6261 (@value{GDBP}) until
6262 195 for ( ; argc > 0; NEXTARG) @{
6263 @end smallexample
6264
6265 This happened because, for execution efficiency, the compiler had
6266 generated code for the loop closure test at the end, rather than the
6267 start, of the loop---even though the test in a C @code{for}-loop is
6268 written before the body of the loop. The @code{until} command appeared
6269 to step back to the beginning of the loop when it advanced to this
6270 expression; however, it has not really gone to an earlier
6271 statement---not in terms of the actual machine code.
6272
6273 @code{until} with no argument works by means of single
6274 instruction stepping, and hence is slower than @code{until} with an
6275 argument.
6276
6277 @item until @var{location}
6278 @itemx u @var{location}
6279 Continue running your program until either the specified @var{location} is
6280 reached, or the current stack frame returns. The location is any of
6281 the forms described in @ref{Specify Location}.
6282 This form of the command uses temporary breakpoints, and
6283 hence is quicker than @code{until} without an argument. The specified
6284 location is actually reached only if it is in the current frame. This
6285 implies that @code{until} can be used to skip over recursive function
6286 invocations. For instance in the code below, if the current location is
6287 line @code{96}, issuing @code{until 99} will execute the program up to
6288 line @code{99} in the same invocation of factorial, i.e., after the inner
6289 invocations have returned.
6290
6291 @smallexample
6292 94 int factorial (int value)
6293 95 @{
6294 96 if (value > 1) @{
6295 97 value *= factorial (value - 1);
6296 98 @}
6297 99 return (value);
6298 100 @}
6299 @end smallexample
6300
6301
6302 @kindex advance @var{location}
6303 @item advance @var{location}
6304 Continue running the program up to the given @var{location}. An argument is
6305 required, which should be of one of the forms described in
6306 @ref{Specify Location}.
6307 Execution will also stop upon exit from the current stack
6308 frame. This command is similar to @code{until}, but @code{advance} will
6309 not skip over recursive function calls, and the target location doesn't
6310 have to be in the same frame as the current one.
6311
6312
6313 @kindex stepi
6314 @kindex si @r{(@code{stepi})}
6315 @item stepi
6316 @itemx stepi @var{arg}
6317 @itemx si
6318 Execute one machine instruction, then stop and return to the debugger.
6319
6320 It is often useful to do @samp{display/i $pc} when stepping by machine
6321 instructions. This makes @value{GDBN} automatically display the next
6322 instruction to be executed, each time your program stops. @xref{Auto
6323 Display,, Automatic Display}.
6324
6325 An argument is a repeat count, as in @code{step}.
6326
6327 @need 750
6328 @kindex nexti
6329 @kindex ni @r{(@code{nexti})}
6330 @item nexti
6331 @itemx nexti @var{arg}
6332 @itemx ni
6333 Execute one machine instruction, but if it is a function call,
6334 proceed until the function returns.
6335
6336 An argument is a repeat count, as in @code{next}.
6337
6338 @end table
6339
6340 @anchor{range stepping}
6341 @cindex range stepping
6342 @cindex target-assisted range stepping
6343 By default, and if available, @value{GDBN} makes use of
6344 target-assisted @dfn{range stepping}. In other words, whenever you
6345 use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6346 tells the target to step the corresponding range of instruction
6347 addresses instead of issuing multiple single-steps. This speeds up
6348 line stepping, particularly for remote targets. Ideally, there should
6349 be no reason you would want to turn range stepping off. However, it's
6350 possible that a bug in the debug info, a bug in the remote stub (for
6351 remote targets), or even a bug in @value{GDBN} could make line
6352 stepping behave incorrectly when target-assisted range stepping is
6353 enabled. You can use the following command to turn off range stepping
6354 if necessary:
6355
6356 @table @code
6357 @kindex set range-stepping
6358 @kindex show range-stepping
6359 @item set range-stepping
6360 @itemx show range-stepping
6361 Control whether range stepping is enabled.
6362
6363 If @code{on}, and the target supports it, @value{GDBN} tells the
6364 target to step a range of addresses itself, instead of issuing
6365 multiple single-steps. If @code{off}, @value{GDBN} always issues
6366 single-steps, even if range stepping is supported by the target. The
6367 default is @code{on}.
6368
6369 @end table
6370
6371 @node Skipping Over Functions and Files
6372 @section Skipping Over Functions and Files
6373 @cindex skipping over functions and files
6374
6375 The program you are debugging may contain some functions which are
6376 uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
6377 skip a function, all functions in a file or a particular function in
6378 a particular file when stepping.
6379
6380 For example, consider the following C function:
6381
6382 @smallexample
6383 101 int func()
6384 102 @{
6385 103 foo(boring());
6386 104 bar(boring());
6387 105 @}
6388 @end smallexample
6389
6390 @noindent
6391 Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6392 are not interested in stepping through @code{boring}. If you run @code{step}
6393 at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6394 step over both @code{foo} and @code{boring}!
6395
6396 One solution is to @code{step} into @code{boring} and use the @code{finish}
6397 command to immediately exit it. But this can become tedious if @code{boring}
6398 is called from many places.
6399
6400 A more flexible solution is to execute @kbd{skip boring}. This instructs
6401 @value{GDBN} never to step into @code{boring}. Now when you execute
6402 @code{step} at line 103, you'll step over @code{boring} and directly into
6403 @code{foo}.
6404
6405 Functions may be skipped by providing either a function name, linespec
6406 (@pxref{Specify Location}), regular expression that matches the function's
6407 name, file name or a @code{glob}-style pattern that matches the file name.
6408
6409 On Posix systems the form of the regular expression is
6410 ``Extended Regular Expressions''. See for example @samp{man 7 regex}
6411 on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6412 expression is whatever is provided by the @code{regcomp} function of
6413 the underlying system.
6414 See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6415 description of @code{glob}-style patterns.
6416
6417 @table @code
6418 @kindex skip
6419 @item skip @r{[}@var{options}@r{]}
6420 The basic form of the @code{skip} command takes zero or more options
6421 that specify what to skip.
6422 The @var{options} argument is any useful combination of the following:
6423
6424 @table @code
6425 @item -file @var{file}
6426 @itemx -fi @var{file}
6427 Functions in @var{file} will be skipped over when stepping.
6428
6429 @item -gfile @var{file-glob-pattern}
6430 @itemx -gfi @var{file-glob-pattern}
6431 @cindex skipping over files via glob-style patterns
6432 Functions in files matching @var{file-glob-pattern} will be skipped
6433 over when stepping.
6434
6435 @smallexample
6436 (gdb) skip -gfi utils/*.c
6437 @end smallexample
6438
6439 @item -function @var{linespec}
6440 @itemx -fu @var{linespec}
6441 Functions named by @var{linespec} or the function containing the line
6442 named by @var{linespec} will be skipped over when stepping.
6443 @xref{Specify Location}.
6444
6445 @item -rfunction @var{regexp}
6446 @itemx -rfu @var{regexp}
6447 @cindex skipping over functions via regular expressions
6448 Functions whose name matches @var{regexp} will be skipped over when stepping.
6449
6450 This form is useful for complex function names.
6451 For example, there is generally no need to step into C@t{++} @code{std::string}
6452 constructors or destructors. Plus with C@t{++} templates it can be hard to
6453 write out the full name of the function, and often it doesn't matter what
6454 the template arguments are. Specifying the function to be skipped as a
6455 regular expression makes this easier.
6456
6457 @smallexample
6458 (gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6459 @end smallexample
6460
6461 If you want to skip every templated C@t{++} constructor and destructor
6462 in the @code{std} namespace you can do:
6463
6464 @smallexample
6465 (gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6466 @end smallexample
6467 @end table
6468
6469 If no options are specified, the function you're currently debugging
6470 will be skipped.
6471
6472 @kindex skip function
6473 @item skip function @r{[}@var{linespec}@r{]}
6474 After running this command, the function named by @var{linespec} or the
6475 function containing the line named by @var{linespec} will be skipped over when
6476 stepping. @xref{Specify Location}.
6477
6478 If you do not specify @var{linespec}, the function you're currently debugging
6479 will be skipped.
6480
6481 (If you have a function called @code{file} that you want to skip, use
6482 @kbd{skip function file}.)
6483
6484 @kindex skip file
6485 @item skip file @r{[}@var{filename}@r{]}
6486 After running this command, any function whose source lives in @var{filename}
6487 will be skipped over when stepping.
6488
6489 @smallexample
6490 (gdb) skip file boring.c
6491 File boring.c will be skipped when stepping.
6492 @end smallexample
6493
6494 If you do not specify @var{filename}, functions whose source lives in the file
6495 you're currently debugging will be skipped.
6496 @end table
6497
6498 Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6499 These are the commands for managing your list of skips:
6500
6501 @table @code
6502 @kindex info skip
6503 @item info skip @r{[}@var{range}@r{]}
6504 Print details about the specified skip(s). If @var{range} is not specified,
6505 print a table with details about all functions and files marked for skipping.
6506 @code{info skip} prints the following information about each skip:
6507
6508 @table @emph
6509 @item Identifier
6510 A number identifying this skip.
6511 @item Enabled or Disabled
6512 Enabled skips are marked with @samp{y}.
6513 Disabled skips are marked with @samp{n}.
6514 @item Glob
6515 If the file name is a @samp{glob} pattern this is @samp{y}.
6516 Otherwise it is @samp{n}.
6517 @item File
6518 The name or @samp{glob} pattern of the file to be skipped.
6519 If no file is specified this is @samp{<none>}.
6520 @item RE
6521 If the function name is a @samp{regular expression} this is @samp{y}.
6522 Otherwise it is @samp{n}.
6523 @item Function
6524 The name or regular expression of the function to skip.
6525 If no function is specified this is @samp{<none>}.
6526 @end table
6527
6528 @kindex skip delete
6529 @item skip delete @r{[}@var{range}@r{]}
6530 Delete the specified skip(s). If @var{range} is not specified, delete all
6531 skips.
6532
6533 @kindex skip enable
6534 @item skip enable @r{[}@var{range}@r{]}
6535 Enable the specified skip(s). If @var{range} is not specified, enable all
6536 skips.
6537
6538 @kindex skip disable
6539 @item skip disable @r{[}@var{range}@r{]}
6540 Disable the specified skip(s). If @var{range} is not specified, disable all
6541 skips.
6542
6543 @kindex set debug skip
6544 @item set debug skip @r{[}on|off@r{]}
6545 Set whether to print the debug output about skipping files and functions.
6546
6547 @kindex show debug skip
6548 @item show debug skip
6549 Show whether the debug output about skipping files and functions is printed.
6550
6551 @end table
6552
6553 @node Signals
6554 @section Signals
6555 @cindex signals
6556
6557 A signal is an asynchronous event that can happen in a program. The
6558 operating system defines the possible kinds of signals, and gives each
6559 kind a name and a number. For example, in Unix @code{SIGINT} is the
6560 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
6561 @code{SIGSEGV} is the signal a program gets from referencing a place in
6562 memory far away from all the areas in use; @code{SIGALRM} occurs when
6563 the alarm clock timer goes off (which happens only if your program has
6564 requested an alarm).
6565
6566 @cindex fatal signals
6567 Some signals, including @code{SIGALRM}, are a normal part of the
6568 functioning of your program. Others, such as @code{SIGSEGV}, indicate
6569 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
6570 program has not specified in advance some other way to handle the signal.
6571 @code{SIGINT} does not indicate an error in your program, but it is normally
6572 fatal so it can carry out the purpose of the interrupt: to kill the program.
6573
6574 @value{GDBN} has the ability to detect any occurrence of a signal in your
6575 program. You can tell @value{GDBN} in advance what to do for each kind of
6576 signal.
6577
6578 @cindex handling signals
6579 Normally, @value{GDBN} is set up to let the non-erroneous signals like
6580 @code{SIGALRM} be silently passed to your program
6581 (so as not to interfere with their role in the program's functioning)
6582 but to stop your program immediately whenever an error signal happens.
6583 You can change these settings with the @code{handle} command.
6584
6585 @table @code
6586 @kindex info signals
6587 @kindex info handle
6588 @item info signals
6589 @itemx info handle
6590 Print a table of all the kinds of signals and how @value{GDBN} has been told to
6591 handle each one. You can use this to see the signal numbers of all
6592 the defined types of signals.
6593
6594 @item info signals @var{sig}
6595 Similar, but print information only about the specified signal number.
6596
6597 @code{info handle} is an alias for @code{info signals}.
6598
6599 @item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6600 Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6601 for details about this command.
6602
6603 @kindex handle
6604 @item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
6605 Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
6606 can be the number of a signal or its name (with or without the
6607 @samp{SIG} at the beginning); a list of signal numbers of the form
6608 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
6609 known signals. Optional arguments @var{keywords}, described below,
6610 say what change to make.
6611 @end table
6612
6613 @c @group
6614 The keywords allowed by the @code{handle} command can be abbreviated.
6615 Their full names are:
6616
6617 @table @code
6618 @item nostop
6619 @value{GDBN} should not stop your program when this signal happens. It may
6620 still print a message telling you that the signal has come in.
6621
6622 @item stop
6623 @value{GDBN} should stop your program when this signal happens. This implies
6624 the @code{print} keyword as well.
6625
6626 @item print
6627 @value{GDBN} should print a message when this signal happens.
6628
6629 @item noprint
6630 @value{GDBN} should not mention the occurrence of the signal at all. This
6631 implies the @code{nostop} keyword as well.
6632
6633 @item pass
6634 @itemx noignore
6635 @value{GDBN} should allow your program to see this signal; your program
6636 can handle the signal, or else it may terminate if the signal is fatal
6637 and not handled. @code{pass} and @code{noignore} are synonyms.
6638
6639 @item nopass
6640 @itemx ignore
6641 @value{GDBN} should not allow your program to see this signal.
6642 @code{nopass} and @code{ignore} are synonyms.
6643 @end table
6644 @c @end group
6645
6646 When a signal stops your program, the signal is not visible to the
6647 program until you
6648 continue. Your program sees the signal then, if @code{pass} is in
6649 effect for the signal in question @emph{at that time}. In other words,
6650 after @value{GDBN} reports a signal, you can use the @code{handle}
6651 command with @code{pass} or @code{nopass} to control whether your
6652 program sees that signal when you continue.
6653
6654 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6655 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6656 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6657 erroneous signals.
6658
6659 You can also use the @code{signal} command to prevent your program from
6660 seeing a signal, or cause it to see a signal it normally would not see,
6661 or to give it any signal at any time. For example, if your program stopped
6662 due to some sort of memory reference error, you might store correct
6663 values into the erroneous variables and continue, hoping to see more
6664 execution; but your program would probably terminate immediately as
6665 a result of the fatal signal once it saw the signal. To prevent this,
6666 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
6667 Program a Signal}.
6668
6669 @cindex stepping and signal handlers
6670 @anchor{stepping and signal handlers}
6671
6672 @value{GDBN} optimizes for stepping the mainline code. If a signal
6673 that has @code{handle nostop} and @code{handle pass} set arrives while
6674 a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6675 in progress, @value{GDBN} lets the signal handler run and then resumes
6676 stepping the mainline code once the signal handler returns. In other
6677 words, @value{GDBN} steps over the signal handler. This prevents
6678 signals that you've specified as not interesting (with @code{handle
6679 nostop}) from changing the focus of debugging unexpectedly. Note that
6680 the signal handler itself may still hit a breakpoint, stop for another
6681 signal that has @code{handle stop} in effect, or for any other event
6682 that normally results in stopping the stepping command sooner. Also
6683 note that @value{GDBN} still informs you that the program received a
6684 signal if @code{handle print} is set.
6685
6686 @anchor{stepping into signal handlers}
6687
6688 If you set @code{handle pass} for a signal, and your program sets up a
6689 handler for it, then issuing a stepping command, such as @code{step}
6690 or @code{stepi}, when your program is stopped due to the signal will
6691 step @emph{into} the signal handler (if the target supports that).
6692
6693 Likewise, if you use the @code{queue-signal} command to queue a signal
6694 to be delivered to the current thread when execution of the thread
6695 resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6696 stepping command will step into the signal handler.
6697
6698 Here's an example, using @code{stepi} to step to the first instruction
6699 of @code{SIGUSR1}'s handler:
6700
6701 @smallexample
6702 (@value{GDBP}) handle SIGUSR1
6703 Signal Stop Print Pass to program Description
6704 SIGUSR1 Yes Yes Yes User defined signal 1
6705 (@value{GDBP}) c
6706 Continuing.
6707
6708 Program received signal SIGUSR1, User defined signal 1.
6709 main () sigusr1.c:28
6710 28 p = 0;
6711 (@value{GDBP}) si
6712 sigusr1_handler () at sigusr1.c:9
6713 9 @{
6714 @end smallexample
6715
6716 The same, but using @code{queue-signal} instead of waiting for the
6717 program to receive the signal first:
6718
6719 @smallexample
6720 (@value{GDBP}) n
6721 28 p = 0;
6722 (@value{GDBP}) queue-signal SIGUSR1
6723 (@value{GDBP}) si
6724 sigusr1_handler () at sigusr1.c:9
6725 9 @{
6726 (@value{GDBP})
6727 @end smallexample
6728
6729 @cindex extra signal information
6730 @anchor{extra signal information}
6731
6732 On some targets, @value{GDBN} can inspect extra signal information
6733 associated with the intercepted signal, before it is actually
6734 delivered to the program being debugged. This information is exported
6735 by the convenience variable @code{$_siginfo}, and consists of data
6736 that is passed by the kernel to the signal handler at the time of the
6737 receipt of a signal. The data type of the information itself is
6738 target dependent. You can see the data type using the @code{ptype
6739 $_siginfo} command. On Unix systems, it typically corresponds to the
6740 standard @code{siginfo_t} type, as defined in the @file{signal.h}
6741 system header.
6742
6743 Here's an example, on a @sc{gnu}/Linux system, printing the stray
6744 referenced address that raised a segmentation fault.
6745
6746 @smallexample
6747 @group
6748 (@value{GDBP}) continue
6749 Program received signal SIGSEGV, Segmentation fault.
6750 0x0000000000400766 in main ()
6751 69 *(int *)p = 0;
6752 (@value{GDBP}) ptype $_siginfo
6753 type = struct @{
6754 int si_signo;
6755 int si_errno;
6756 int si_code;
6757 union @{
6758 int _pad[28];
6759 struct @{...@} _kill;
6760 struct @{...@} _timer;
6761 struct @{...@} _rt;
6762 struct @{...@} _sigchld;
6763 struct @{...@} _sigfault;
6764 struct @{...@} _sigpoll;
6765 @} _sifields;
6766 @}
6767 (@value{GDBP}) ptype $_siginfo._sifields._sigfault
6768 type = struct @{
6769 void *si_addr;
6770 @}
6771 (@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6772 $1 = (void *) 0x7ffff7ff7000
6773 @end group
6774 @end smallexample
6775
6776 Depending on target support, @code{$_siginfo} may also be writable.
6777
6778 @cindex Intel MPX boundary violations
6779 @cindex boundary violations, Intel MPX
6780 On some targets, a @code{SIGSEGV} can be caused by a boundary
6781 violation, i.e., accessing an address outside of the allowed range.
6782 In those cases @value{GDBN} may displays additional information,
6783 depending on how @value{GDBN} has been told to handle the signal.
6784 With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6785 kind: "Upper" or "Lower", the memory address accessed and the
6786 bounds, while with @code{handle nostop SIGSEGV} no additional
6787 information is displayed.
6788
6789 The usual output of a segfault is:
6790 @smallexample
6791 Program received signal SIGSEGV, Segmentation fault
6792 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6793 68 value = *(p + len);
6794 @end smallexample
6795
6796 While a bound violation is presented as:
6797 @smallexample
6798 Program received signal SIGSEGV, Segmentation fault
6799 Upper bound violation while accessing address 0x7fffffffc3b3
6800 Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
6801 0x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
6802 68 value = *(p + len);
6803 @end smallexample
6804
6805 @node Thread Stops
6806 @section Stopping and Starting Multi-thread Programs
6807
6808 @cindex stopped threads
6809 @cindex threads, stopped
6810
6811 @cindex continuing threads
6812 @cindex threads, continuing
6813
6814 @value{GDBN} supports debugging programs with multiple threads
6815 (@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6816 are two modes of controlling execution of your program within the
6817 debugger. In the default mode, referred to as @dfn{all-stop mode},
6818 when any thread in your program stops (for example, at a breakpoint
6819 or while being stepped), all other threads in the program are also stopped by
6820 @value{GDBN}. On some targets, @value{GDBN} also supports
6821 @dfn{non-stop mode}, in which other threads can continue to run freely while
6822 you examine the stopped thread in the debugger.
6823
6824 @menu
6825 * All-Stop Mode:: All threads stop when GDB takes control
6826 * Non-Stop Mode:: Other threads continue to execute
6827 * Background Execution:: Running your program asynchronously
6828 * Thread-Specific Breakpoints:: Controlling breakpoints
6829 * Interrupted System Calls:: GDB may interfere with system calls
6830 * Observer Mode:: GDB does not alter program behavior
6831 @end menu
6832
6833 @node All-Stop Mode
6834 @subsection All-Stop Mode
6835
6836 @cindex all-stop mode
6837
6838 In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6839 @emph{all} threads of execution stop, not just the current thread. This
6840 allows you to examine the overall state of the program, including
6841 switching between threads, without worrying that things may change
6842 underfoot.
6843
6844 Conversely, whenever you restart the program, @emph{all} threads start
6845 executing. @emph{This is true even when single-stepping} with commands
6846 like @code{step} or @code{next}.
6847
6848 In particular, @value{GDBN} cannot single-step all threads in lockstep.
6849 Since thread scheduling is up to your debugging target's operating
6850 system (not controlled by @value{GDBN}), other threads may
6851 execute more than one statement while the current thread completes a
6852 single step. Moreover, in general other threads stop in the middle of a
6853 statement, rather than at a clean statement boundary, when the program
6854 stops.
6855
6856 You might even find your program stopped in another thread after
6857 continuing or even single-stepping. This happens whenever some other
6858 thread runs into a breakpoint, a signal, or an exception before the
6859 first thread completes whatever you requested.
6860
6861 @cindex automatic thread selection
6862 @cindex switching threads automatically
6863 @cindex threads, automatic switching
6864 Whenever @value{GDBN} stops your program, due to a breakpoint or a
6865 signal, it automatically selects the thread where that breakpoint or
6866 signal happened. @value{GDBN} alerts you to the context switch with a
6867 message such as @samp{[Switching to Thread @var{n}]} to identify the
6868 thread.
6869
6870 On some OSes, you can modify @value{GDBN}'s default behavior by
6871 locking the OS scheduler to allow only a single thread to run.
6872
6873 @table @code
6874 @item set scheduler-locking @var{mode}
6875 @cindex scheduler locking mode
6876 @cindex lock scheduler
6877 Set the scheduler locking mode. It applies to normal execution,
6878 record mode, and replay mode. If it is @code{off}, then there is no
6879 locking and any thread may run at any time. If @code{on}, then only
6880 the current thread may run when the inferior is resumed. The
6881 @code{step} mode optimizes for single-stepping; it prevents other
6882 threads from preempting the current thread while you are stepping, so
6883 that the focus of debugging does not change unexpectedly. Other
6884 threads never get a chance to run when you step, and they are
6885 completely free to run when you use commands like @samp{continue},
6886 @samp{until}, or @samp{finish}. However, unless another thread hits a
6887 breakpoint during its timeslice, @value{GDBN} does not change the
6888 current thread away from the thread that you are debugging. The
6889 @code{replay} mode behaves like @code{off} in record mode and like
6890 @code{on} in replay mode.
6891
6892 @item show scheduler-locking
6893 Display the current scheduler locking mode.
6894 @end table
6895
6896 @cindex resume threads of multiple processes simultaneously
6897 By default, when you issue one of the execution commands such as
6898 @code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6899 threads of the current inferior to run. For example, if @value{GDBN}
6900 is attached to two inferiors, each with two threads, the
6901 @code{continue} command resumes only the two threads of the current
6902 inferior. This is useful, for example, when you debug a program that
6903 forks and you want to hold the parent stopped (so that, for instance,
6904 it doesn't run to exit), while you debug the child. In other
6905 situations, you may not be interested in inspecting the current state
6906 of any of the processes @value{GDBN} is attached to, and you may want
6907 to resume them all until some breakpoint is hit. In the latter case,
6908 you can instruct @value{GDBN} to allow all threads of all the
6909 inferiors to run with the @w{@code{set schedule-multiple}} command.
6910
6911 @table @code
6912 @kindex set schedule-multiple
6913 @item set schedule-multiple
6914 Set the mode for allowing threads of multiple processes to be resumed
6915 when an execution command is issued. When @code{on}, all threads of
6916 all processes are allowed to run. When @code{off}, only the threads
6917 of the current process are resumed. The default is @code{off}. The
6918 @code{scheduler-locking} mode takes precedence when set to @code{on},
6919 or while you are stepping and set to @code{step}.
6920
6921 @item show schedule-multiple
6922 Display the current mode for resuming the execution of threads of
6923 multiple processes.
6924 @end table
6925
6926 @node Non-Stop Mode
6927 @subsection Non-Stop Mode
6928
6929 @cindex non-stop mode
6930
6931 @c This section is really only a place-holder, and needs to be expanded
6932 @c with more details.
6933
6934 For some multi-threaded targets, @value{GDBN} supports an optional
6935 mode of operation in which you can examine stopped program threads in
6936 the debugger while other threads continue to execute freely. This
6937 minimizes intrusion when debugging live systems, such as programs
6938 where some threads have real-time constraints or must continue to
6939 respond to external events. This is referred to as @dfn{non-stop} mode.
6940
6941 In non-stop mode, when a thread stops to report a debugging event,
6942 @emph{only} that thread is stopped; @value{GDBN} does not stop other
6943 threads as well, in contrast to the all-stop mode behavior. Additionally,
6944 execution commands such as @code{continue} and @code{step} apply by default
6945 only to the current thread in non-stop mode, rather than all threads as
6946 in all-stop mode. This allows you to control threads explicitly in
6947 ways that are not possible in all-stop mode --- for example, stepping
6948 one thread while allowing others to run freely, stepping
6949 one thread while holding all others stopped, or stepping several threads
6950 independently and simultaneously.
6951
6952 To enter non-stop mode, use this sequence of commands before you run
6953 or attach to your program:
6954
6955 @smallexample
6956 # If using the CLI, pagination breaks non-stop.
6957 set pagination off
6958
6959 # Finally, turn it on!
6960 set non-stop on
6961 @end smallexample
6962
6963 You can use these commands to manipulate the non-stop mode setting:
6964
6965 @table @code
6966 @kindex set non-stop
6967 @item set non-stop on
6968 Enable selection of non-stop mode.
6969 @item set non-stop off
6970 Disable selection of non-stop mode.
6971 @kindex show non-stop
6972 @item show non-stop
6973 Show the current non-stop enablement setting.
6974 @end table
6975
6976 Note these commands only reflect whether non-stop mode is enabled,
6977 not whether the currently-executing program is being run in non-stop mode.
6978 In particular, the @code{set non-stop} preference is only consulted when
6979 @value{GDBN} starts or connects to the target program, and it is generally
6980 not possible to switch modes once debugging has started. Furthermore,
6981 since not all targets support non-stop mode, even when you have enabled
6982 non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6983 default.
6984
6985 In non-stop mode, all execution commands apply only to the current thread
6986 by default. That is, @code{continue} only continues one thread.
6987 To continue all threads, issue @code{continue -a} or @code{c -a}.
6988
6989 You can use @value{GDBN}'s background execution commands
6990 (@pxref{Background Execution}) to run some threads in the background
6991 while you continue to examine or step others from @value{GDBN}.
6992 The MI execution commands (@pxref{GDB/MI Program Execution}) are
6993 always executed asynchronously in non-stop mode.
6994
6995 Suspending execution is done with the @code{interrupt} command when
6996 running in the background, or @kbd{Ctrl-c} during foreground execution.
6997 In all-stop mode, this stops the whole process;
6998 but in non-stop mode the interrupt applies only to the current thread.
6999 To stop the whole program, use @code{interrupt -a}.
7000
7001 Other execution commands do not currently support the @code{-a} option.
7002
7003 In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
7004 that thread current, as it does in all-stop mode. This is because the
7005 thread stop notifications are asynchronous with respect to @value{GDBN}'s
7006 command interpreter, and it would be confusing if @value{GDBN} unexpectedly
7007 changed to a different thread just as you entered a command to operate on the
7008 previously current thread.
7009
7010 @node Background Execution
7011 @subsection Background Execution
7012
7013 @cindex foreground execution
7014 @cindex background execution
7015 @cindex asynchronous execution
7016 @cindex execution, foreground, background and asynchronous
7017
7018 @value{GDBN}'s execution commands have two variants: the normal
7019 foreground (synchronous) behavior, and a background
7020 (asynchronous) behavior. In foreground execution, @value{GDBN} waits for
7021 the program to report that some thread has stopped before prompting for
7022 another command. In background execution, @value{GDBN} immediately gives
7023 a command prompt so that you can issue other commands while your program runs.
7024
7025 If the target doesn't support async mode, @value{GDBN} issues an error
7026 message if you attempt to use the background execution commands.
7027
7028 @cindex @code{&}, background execution of commands
7029 To specify background execution, add a @code{&} to the command. For example,
7030 the background form of the @code{continue} command is @code{continue&}, or
7031 just @code{c&}. The execution commands that accept background execution
7032 are:
7033
7034 @table @code
7035 @kindex run&
7036 @item run
7037 @xref{Starting, , Starting your Program}.
7038
7039 @item attach
7040 @kindex attach&
7041 @xref{Attach, , Debugging an Already-running Process}.
7042
7043 @item step
7044 @kindex step&
7045 @xref{Continuing and Stepping, step}.
7046
7047 @item stepi
7048 @kindex stepi&
7049 @xref{Continuing and Stepping, stepi}.
7050
7051 @item next
7052 @kindex next&
7053 @xref{Continuing and Stepping, next}.
7054
7055 @item nexti
7056 @kindex nexti&
7057 @xref{Continuing and Stepping, nexti}.
7058
7059 @item continue
7060 @kindex continue&
7061 @xref{Continuing and Stepping, continue}.
7062
7063 @item finish
7064 @kindex finish&
7065 @xref{Continuing and Stepping, finish}.
7066
7067 @item until
7068 @kindex until&
7069 @xref{Continuing and Stepping, until}.
7070
7071 @end table
7072
7073 Background execution is especially useful in conjunction with non-stop
7074 mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
7075 However, you can also use these commands in the normal all-stop mode with
7076 the restriction that you cannot issue another execution command until the
7077 previous one finishes. Examples of commands that are valid in all-stop
7078 mode while the program is running include @code{help} and @code{info break}.
7079
7080 You can interrupt your program while it is running in the background by
7081 using the @code{interrupt} command.
7082
7083 @table @code
7084 @kindex interrupt
7085 @item interrupt
7086 @itemx interrupt -a
7087
7088 Suspend execution of the running program. In all-stop mode,
7089 @code{interrupt} stops the whole process, but in non-stop mode, it stops
7090 only the current thread. To stop the whole program in non-stop mode,
7091 use @code{interrupt -a}.
7092 @end table
7093
7094 @node Thread-Specific Breakpoints
7095 @subsection Thread-Specific Breakpoints
7096
7097 When your program has multiple threads (@pxref{Threads,, Debugging
7098 Programs with Multiple Threads}), you can choose whether to set
7099 breakpoints on all threads, or on a particular thread.
7100
7101 @table @code
7102 @cindex breakpoints and threads
7103 @cindex thread breakpoints
7104 @kindex break @dots{} thread @var{thread-id}
7105 @item break @var{location} thread @var{thread-id}
7106 @itemx break @var{location} thread @var{thread-id} if @dots{}
7107 @var{location} specifies source lines; there are several ways of
7108 writing them (@pxref{Specify Location}), but the effect is always to
7109 specify some source line.
7110
7111 Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
7112 to specify that you only want @value{GDBN} to stop the program when a
7113 particular thread reaches this breakpoint. The @var{thread-id} specifier
7114 is one of the thread identifiers assigned by @value{GDBN}, shown
7115 in the first column of the @samp{info threads} display.
7116
7117 If you do not specify @samp{thread @var{thread-id}} when you set a
7118 breakpoint, the breakpoint applies to @emph{all} threads of your
7119 program.
7120
7121 You can use the @code{thread} qualifier on conditional breakpoints as
7122 well; in this case, place @samp{thread @var{thread-id}} before or
7123 after the breakpoint condition, like this:
7124
7125 @smallexample
7126 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
7127 @end smallexample
7128
7129 @end table
7130
7131 Thread-specific breakpoints are automatically deleted when
7132 @value{GDBN} detects the corresponding thread is no longer in the
7133 thread list. For example:
7134
7135 @smallexample
7136 (@value{GDBP}) c
7137 Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
7138 @end smallexample
7139
7140 There are several ways for a thread to disappear, such as a regular
7141 thread exit, but also when you detach from the process with the
7142 @code{detach} command (@pxref{Attach, ,Debugging an Already-running
7143 Process}), or if @value{GDBN} loses the remote connection
7144 (@pxref{Remote Debugging}), etc. Note that with some targets,
7145 @value{GDBN} is only able to detect a thread has exited when the user
7146 explictly asks for the thread list with the @code{info threads}
7147 command.
7148
7149 @node Interrupted System Calls
7150 @subsection Interrupted System Calls
7151
7152 @cindex thread breakpoints and system calls
7153 @cindex system calls and thread breakpoints
7154 @cindex premature return from system calls
7155 There is an unfortunate side effect when using @value{GDBN} to debug
7156 multi-threaded programs. If one thread stops for a
7157 breakpoint, or for some other reason, and another thread is blocked in a
7158 system call, then the system call may return prematurely. This is a
7159 consequence of the interaction between multiple threads and the signals
7160 that @value{GDBN} uses to implement breakpoints and other events that
7161 stop execution.
7162
7163 To handle this problem, your program should check the return value of
7164 each system call and react appropriately. This is good programming
7165 style anyways.
7166
7167 For example, do not write code like this:
7168
7169 @smallexample
7170 sleep (10);
7171 @end smallexample
7172
7173 The call to @code{sleep} will return early if a different thread stops
7174 at a breakpoint or for some other reason.
7175
7176 Instead, write this:
7177
7178 @smallexample
7179 int unslept = 10;
7180 while (unslept > 0)
7181 unslept = sleep (unslept);
7182 @end smallexample
7183
7184 A system call is allowed to return early, so the system is still
7185 conforming to its specification. But @value{GDBN} does cause your
7186 multi-threaded program to behave differently than it would without
7187 @value{GDBN}.
7188
7189 Also, @value{GDBN} uses internal breakpoints in the thread library to
7190 monitor certain events such as thread creation and thread destruction.
7191 When such an event happens, a system call in another thread may return
7192 prematurely, even though your program does not appear to stop.
7193
7194 @node Observer Mode
7195 @subsection Observer Mode
7196
7197 If you want to build on non-stop mode and observe program behavior
7198 without any chance of disruption by @value{GDBN}, you can set
7199 variables to disable all of the debugger's attempts to modify state,
7200 whether by writing memory, inserting breakpoints, etc. These operate
7201 at a low level, intercepting operations from all commands.
7202
7203 When all of these are set to @code{off}, then @value{GDBN} is said to
7204 be @dfn{observer mode}. As a convenience, the variable
7205 @code{observer} can be set to disable these, plus enable non-stop
7206 mode.
7207
7208 Note that @value{GDBN} will not prevent you from making nonsensical
7209 combinations of these settings. For instance, if you have enabled
7210 @code{may-insert-breakpoints} but disabled @code{may-write-memory},
7211 then breakpoints that work by writing trap instructions into the code
7212 stream will still not be able to be placed.
7213
7214 @table @code
7215
7216 @kindex observer
7217 @item set observer on
7218 @itemx set observer off
7219 When set to @code{on}, this disables all the permission variables
7220 below (except for @code{insert-fast-tracepoints}), plus enables
7221 non-stop debugging. Setting this to @code{off} switches back to
7222 normal debugging, though remaining in non-stop mode.
7223
7224 @item show observer
7225 Show whether observer mode is on or off.
7226
7227 @kindex may-write-registers
7228 @item set may-write-registers on
7229 @itemx set may-write-registers off
7230 This controls whether @value{GDBN} will attempt to alter the values of
7231 registers, such as with assignment expressions in @code{print}, or the
7232 @code{jump} command. It defaults to @code{on}.
7233
7234 @item show may-write-registers
7235 Show the current permission to write registers.
7236
7237 @kindex may-write-memory
7238 @item set may-write-memory on
7239 @itemx set may-write-memory off
7240 This controls whether @value{GDBN} will attempt to alter the contents
7241 of memory, such as with assignment expressions in @code{print}. It
7242 defaults to @code{on}.
7243
7244 @item show may-write-memory
7245 Show the current permission to write memory.
7246
7247 @kindex may-insert-breakpoints
7248 @item set may-insert-breakpoints on
7249 @itemx set may-insert-breakpoints off
7250 This controls whether @value{GDBN} will attempt to insert breakpoints.
7251 This affects all breakpoints, including internal breakpoints defined
7252 by @value{GDBN}. It defaults to @code{on}.
7253
7254 @item show may-insert-breakpoints
7255 Show the current permission to insert breakpoints.
7256
7257 @kindex may-insert-tracepoints
7258 @item set may-insert-tracepoints on
7259 @itemx set may-insert-tracepoints off
7260 This controls whether @value{GDBN} will attempt to insert (regular)
7261 tracepoints at the beginning of a tracing experiment. It affects only
7262 non-fast tracepoints, fast tracepoints being under the control of
7263 @code{may-insert-fast-tracepoints}. It defaults to @code{on}.
7264
7265 @item show may-insert-tracepoints
7266 Show the current permission to insert tracepoints.
7267
7268 @kindex may-insert-fast-tracepoints
7269 @item set may-insert-fast-tracepoints on
7270 @itemx set may-insert-fast-tracepoints off
7271 This controls whether @value{GDBN} will attempt to insert fast
7272 tracepoints at the beginning of a tracing experiment. It affects only
7273 fast tracepoints, regular (non-fast) tracepoints being under the
7274 control of @code{may-insert-tracepoints}. It defaults to @code{on}.
7275
7276 @item show may-insert-fast-tracepoints
7277 Show the current permission to insert fast tracepoints.
7278
7279 @kindex may-interrupt
7280 @item set may-interrupt on
7281 @itemx set may-interrupt off
7282 This controls whether @value{GDBN} will attempt to interrupt or stop
7283 program execution. When this variable is @code{off}, the
7284 @code{interrupt} command will have no effect, nor will
7285 @kbd{Ctrl-c}. It defaults to @code{on}.
7286
7287 @item show may-interrupt
7288 Show the current permission to interrupt or stop the program.
7289
7290 @end table
7291
7292 @node Reverse Execution
7293 @chapter Running programs backward
7294 @cindex reverse execution
7295 @cindex running programs backward
7296
7297 When you are debugging a program, it is not unusual to realize that
7298 you have gone too far, and some event of interest has already happened.
7299 If the target environment supports it, @value{GDBN} can allow you to
7300 ``rewind'' the program by running it backward.
7301
7302 A target environment that supports reverse execution should be able
7303 to ``undo'' the changes in machine state that have taken place as the
7304 program was executing normally. Variables, registers etc.@: should
7305 revert to their previous values. Obviously this requires a great
7306 deal of sophistication on the part of the target environment; not
7307 all target environments can support reverse execution.
7308
7309 When a program is executed in reverse, the instructions that
7310 have most recently been executed are ``un-executed'', in reverse
7311 order. The program counter runs backward, following the previous
7312 thread of execution in reverse. As each instruction is ``un-executed'',
7313 the values of memory and/or registers that were changed by that
7314 instruction are reverted to their previous states. After executing
7315 a piece of source code in reverse, all side effects of that code
7316 should be ``undone'', and all variables should be returned to their
7317 prior values@footnote{
7318 Note that some side effects are easier to undo than others. For instance,
7319 memory and registers are relatively easy, but device I/O is hard. Some
7320 targets may be able undo things like device I/O, and some may not.
7321
7322 The contract between @value{GDBN} and the reverse executing target
7323 requires only that the target do something reasonable when
7324 @value{GDBN} tells it to execute backwards, and then report the
7325 results back to @value{GDBN}. Whatever the target reports back to
7326 @value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7327 assumes that the memory and registers that the target reports are in a
7328 consistent state, but @value{GDBN} accepts whatever it is given.
7329 }.
7330
7331 On some platforms, @value{GDBN} has built-in support for reverse
7332 execution, activated with the @code{record} or @code{record btrace}
7333 commands. @xref{Process Record and Replay}. Some remote targets,
7334 typically full system emulators, support reverse execution directly
7335 without requiring any special command.
7336
7337 If you are debugging in a target environment that supports
7338 reverse execution, @value{GDBN} provides the following commands.
7339
7340 @table @code
7341 @kindex reverse-continue
7342 @kindex rc @r{(@code{reverse-continue})}
7343 @item reverse-continue @r{[}@var{ignore-count}@r{]}
7344 @itemx rc @r{[}@var{ignore-count}@r{]}
7345 Beginning at the point where your program last stopped, start executing
7346 in reverse. Reverse execution will stop for breakpoints and synchronous
7347 exceptions (signals), just like normal execution. Behavior of
7348 asynchronous signals depends on the target environment.
7349
7350 @kindex reverse-step
7351 @kindex rs @r{(@code{step})}
7352 @item reverse-step @r{[}@var{count}@r{]}
7353 Run the program backward until control reaches the start of a
7354 different source line; then stop it, and return control to @value{GDBN}.
7355
7356 Like the @code{step} command, @code{reverse-step} will only stop
7357 at the beginning of a source line. It ``un-executes'' the previously
7358 executed source line. If the previous source line included calls to
7359 debuggable functions, @code{reverse-step} will step (backward) into
7360 the called function, stopping at the beginning of the @emph{last}
7361 statement in the called function (typically a return statement).
7362
7363 Also, as with the @code{step} command, if non-debuggable functions are
7364 called, @code{reverse-step} will run thru them backward without stopping.
7365
7366 @kindex reverse-stepi
7367 @kindex rsi @r{(@code{reverse-stepi})}
7368 @item reverse-stepi @r{[}@var{count}@r{]}
7369 Reverse-execute one machine instruction. Note that the instruction
7370 to be reverse-executed is @emph{not} the one pointed to by the program
7371 counter, but the instruction executed prior to that one. For instance,
7372 if the last instruction was a jump, @code{reverse-stepi} will take you
7373 back from the destination of the jump to the jump instruction itself.
7374
7375 @kindex reverse-next
7376 @kindex rn @r{(@code{reverse-next})}
7377 @item reverse-next @r{[}@var{count}@r{]}
7378 Run backward to the beginning of the previous line executed in
7379 the current (innermost) stack frame. If the line contains function
7380 calls, they will be ``un-executed'' without stopping. Starting from
7381 the first line of a function, @code{reverse-next} will take you back
7382 to the caller of that function, @emph{before} the function was called,
7383 just as the normal @code{next} command would take you from the last
7384 line of a function back to its return to its caller
7385 @footnote{Unless the code is too heavily optimized.}.
7386
7387 @kindex reverse-nexti
7388 @kindex rni @r{(@code{reverse-nexti})}
7389 @item reverse-nexti @r{[}@var{count}@r{]}
7390 Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7391 in reverse, except that called functions are ``un-executed'' atomically.
7392 That is, if the previously executed instruction was a return from
7393 another function, @code{reverse-nexti} will continue to execute
7394 in reverse until the call to that function (from the current stack
7395 frame) is reached.
7396
7397 @kindex reverse-finish
7398 @item reverse-finish
7399 Just as the @code{finish} command takes you to the point where the
7400 current function returns, @code{reverse-finish} takes you to the point
7401 where it was called. Instead of ending up at the end of the current
7402 function invocation, you end up at the beginning.
7403
7404 @kindex set exec-direction
7405 @item set exec-direction
7406 Set the direction of target execution.
7407 @item set exec-direction reverse
7408 @cindex execute forward or backward in time
7409 @value{GDBN} will perform all execution commands in reverse, until the
7410 exec-direction mode is changed to ``forward''. Affected commands include
7411 @code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7412 command cannot be used in reverse mode.
7413 @item set exec-direction forward
7414 @value{GDBN} will perform all execution commands in the normal fashion.
7415 This is the default.
7416 @end table
7417
7418
7419 @node Process Record and Replay
7420 @chapter Recording Inferior's Execution and Replaying It
7421 @cindex process record and replay
7422 @cindex recording inferior's execution and replaying it
7423
7424 On some platforms, @value{GDBN} provides a special @dfn{process record
7425 and replay} target that can record a log of the process execution, and
7426 replay it later with both forward and reverse execution commands.
7427
7428 @cindex replay mode
7429 When this target is in use, if the execution log includes the record
7430 for the next instruction, @value{GDBN} will debug in @dfn{replay
7431 mode}. In the replay mode, the inferior does not really execute code
7432 instructions. Instead, all the events that normally happen during
7433 code execution are taken from the execution log. While code is not
7434 really executed in replay mode, the values of registers (including the
7435 program counter register) and the memory of the inferior are still
7436 changed as they normally would. Their contents are taken from the
7437 execution log.
7438
7439 @cindex record mode
7440 If the record for the next instruction is not in the execution log,
7441 @value{GDBN} will debug in @dfn{record mode}. In this mode, the
7442 inferior executes normally, and @value{GDBN} records the execution log
7443 for future replay.
7444
7445 The process record and replay target supports reverse execution
7446 (@pxref{Reverse Execution}), even if the platform on which the
7447 inferior runs does not. However, the reverse execution is limited in
7448 this case by the range of the instructions recorded in the execution
7449 log. In other words, reverse execution on platforms that don't
7450 support it directly can only be done in the replay mode.
7451
7452 When debugging in the reverse direction, @value{GDBN} will work in
7453 replay mode as long as the execution log includes the record for the
7454 previous instruction; otherwise, it will work in record mode, if the
7455 platform supports reverse execution, or stop if not.
7456
7457 Currently, process record and replay is supported on ARM, Aarch64,
7458 Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7459 GNU/Linux. Process record and replay can be used both when native
7460 debugging, and when remote debugging via @code{gdbserver}.
7461
7462 For architecture environments that support process record and replay,
7463 @value{GDBN} provides the following commands:
7464
7465 @table @code
7466 @kindex target record
7467 @kindex target record-full
7468 @kindex target record-btrace
7469 @kindex record
7470 @kindex record full
7471 @kindex record btrace
7472 @kindex record btrace bts
7473 @kindex record btrace pt
7474 @kindex record bts
7475 @kindex record pt
7476 @kindex rec
7477 @kindex rec full
7478 @kindex rec btrace
7479 @kindex rec btrace bts
7480 @kindex rec btrace pt
7481 @kindex rec bts
7482 @kindex rec pt
7483 @item record @var{method}
7484 This command starts the process record and replay target. The
7485 recording method can be specified as parameter. Without a parameter
7486 the command uses the @code{full} recording method. The following
7487 recording methods are available:
7488
7489 @table @code
7490 @item full
7491 Full record/replay recording using @value{GDBN}'s software record and
7492 replay implementation. This method allows replaying and reverse
7493 execution.
7494
7495 @item btrace @var{format}
7496 Hardware-supported instruction recording, supported on Intel
7497 processors. This method does not record data. Further, the data is
7498 collected in a ring buffer so old data will be overwritten when the
7499 buffer is full. It allows limited reverse execution. Variables and
7500 registers are not available during reverse execution. In remote
7501 debugging, recording continues on disconnect. Recorded data can be
7502 inspected after reconnecting. The recording may be stopped using
7503 @code{record stop}.
7504
7505 The recording format can be specified as parameter. Without a parameter
7506 the command chooses the recording format. The following recording
7507 formats are available:
7508
7509 @table @code
7510 @item bts
7511 @cindex branch trace store
7512 Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7513 this format, the processor stores a from/to record for each executed
7514 branch in the btrace ring buffer.
7515
7516 @item pt
7517 @cindex Intel Processor Trace
7518 Use the @dfn{Intel Processor Trace} recording format. In this
7519 format, the processor stores the execution trace in a compressed form
7520 that is afterwards decoded by @value{GDBN}.
7521
7522 The trace can be recorded with very low overhead. The compressed
7523 trace format also allows small trace buffers to already contain a big
7524 number of instructions compared to @acronym{BTS}.
7525
7526 Decoding the recorded execution trace, on the other hand, is more
7527 expensive than decoding @acronym{BTS} trace. This is mostly due to the
7528 increased number of instructions to process. You should increase the
7529 buffer-size with care.
7530 @end table
7531
7532 Not all recording formats may be available on all processors.
7533 @end table
7534
7535 The process record and replay target can only debug a process that is
7536 already running. Therefore, you need first to start the process with
7537 the @kbd{run} or @kbd{start} commands, and then start the recording
7538 with the @kbd{record @var{method}} command.
7539
7540 @cindex displaced stepping, and process record and replay
7541 Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7542 will be automatically disabled when process record and replay target
7543 is started. That's because the process record and replay target
7544 doesn't support displaced stepping.
7545
7546 @cindex non-stop mode, and process record and replay
7547 @cindex asynchronous execution, and process record and replay
7548 If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
7549 the asynchronous execution mode (@pxref{Background Execution}), not
7550 all recording methods are available. The @code{full} recording method
7551 does not support these two modes.
7552
7553 @kindex record stop
7554 @kindex rec s
7555 @item record stop
7556 Stop the process record and replay target. When process record and
7557 replay target stops, the entire execution log will be deleted and the
7558 inferior will either be terminated, or will remain in its final state.
7559
7560 When you stop the process record and replay target in record mode (at
7561 the end of the execution log), the inferior will be stopped at the
7562 next instruction that would have been recorded. In other words, if
7563 you record for a while and then stop recording, the inferior process
7564 will be left in the same state as if the recording never happened.
7565
7566 On the other hand, if the process record and replay target is stopped
7567 while in replay mode (that is, not at the end of the execution log,
7568 but at some earlier point), the inferior process will become ``live''
7569 at that earlier state, and it will then be possible to continue the
7570 usual ``live'' debugging of the process from that state.
7571
7572 When the inferior process exits, or @value{GDBN} detaches from it,
7573 process record and replay target will automatically stop itself.
7574
7575 @kindex record goto
7576 @item record goto
7577 Go to a specific location in the execution log. There are several
7578 ways to specify the location to go to:
7579
7580 @table @code
7581 @item record goto begin
7582 @itemx record goto start
7583 Go to the beginning of the execution log.
7584
7585 @item record goto end
7586 Go to the end of the execution log.
7587
7588 @item record goto @var{n}
7589 Go to instruction number @var{n} in the execution log.
7590 @end table
7591
7592 @kindex record save
7593 @item record save @var{filename}
7594 Save the execution log to a file @file{@var{filename}}.
7595 Default filename is @file{gdb_record.@var{process_id}}, where
7596 @var{process_id} is the process ID of the inferior.
7597
7598 This command may not be available for all recording methods.
7599
7600 @kindex record restore
7601 @item record restore @var{filename}
7602 Restore the execution log from a file @file{@var{filename}}.
7603 File must have been created with @code{record save}.
7604
7605 @kindex set record full
7606 @item set record full insn-number-max @var{limit}
7607 @itemx set record full insn-number-max unlimited
7608 Set the limit of instructions to be recorded for the @code{full}
7609 recording method. Default value is 200000.
7610
7611 If @var{limit} is a positive number, then @value{GDBN} will start
7612 deleting instructions from the log once the number of the record
7613 instructions becomes greater than @var{limit}. For every new recorded
7614 instruction, @value{GDBN} will delete the earliest recorded
7615 instruction to keep the number of recorded instructions at the limit.
7616 (Since deleting recorded instructions loses information, @value{GDBN}
7617 lets you control what happens when the limit is reached, by means of
7618 the @code{stop-at-limit} option, described below.)
7619
7620 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7621 delete recorded instructions from the execution log. The number of
7622 recorded instructions is limited only by the available memory.
7623
7624 @kindex show record full
7625 @item show record full insn-number-max
7626 Show the limit of instructions to be recorded with the @code{full}
7627 recording method.
7628
7629 @item set record full stop-at-limit
7630 Control the behavior of the @code{full} recording method when the
7631 number of recorded instructions reaches the limit. If ON (the
7632 default), @value{GDBN} will stop when the limit is reached for the
7633 first time and ask you whether you want to stop the inferior or
7634 continue running it and recording the execution log. If you decide
7635 to continue recording, each new recorded instruction will cause the
7636 oldest one to be deleted.
7637
7638 If this option is OFF, @value{GDBN} will automatically delete the
7639 oldest record to make room for each new one, without asking.
7640
7641 @item show record full stop-at-limit
7642 Show the current setting of @code{stop-at-limit}.
7643
7644 @item set record full memory-query
7645 Control the behavior when @value{GDBN} is unable to record memory
7646 changes caused by an instruction for the @code{full} recording method.
7647 If ON, @value{GDBN} will query whether to stop the inferior in that
7648 case.
7649
7650 If this option is OFF (the default), @value{GDBN} will automatically
7651 ignore the effect of such instructions on memory. Later, when
7652 @value{GDBN} replays this execution log, it will mark the log of this
7653 instruction as not accessible, and it will not affect the replay
7654 results.
7655
7656 @item show record full memory-query
7657 Show the current setting of @code{memory-query}.
7658
7659 @kindex set record btrace
7660 The @code{btrace} record target does not trace data. As a
7661 convenience, when replaying, @value{GDBN} reads read-only memory off
7662 the live program directly, assuming that the addresses of the
7663 read-only areas don't change. This for example makes it possible to
7664 disassemble code while replaying, but not to print variables.
7665 In some cases, being able to inspect variables might be useful.
7666 You can use the following command for that:
7667
7668 @item set record btrace replay-memory-access
7669 Control the behavior of the @code{btrace} recording method when
7670 accessing memory during replay. If @code{read-only} (the default),
7671 @value{GDBN} will only allow accesses to read-only memory.
7672 If @code{read-write}, @value{GDBN} will allow accesses to read-only
7673 and to read-write memory. Beware that the accessed memory corresponds
7674 to the live target and not necessarily to the current replay
7675 position.
7676
7677 @item set record btrace cpu @var{identifier}
7678 Set the processor to be used for enabling workarounds for processor
7679 errata when decoding the trace.
7680
7681 Processor errata are defects in processor operation, caused by its
7682 design or manufacture. They can cause a trace not to match the
7683 specification. This, in turn, may cause trace decode to fail.
7684 @value{GDBN} can detect erroneous trace packets and correct them, thus
7685 avoiding the decoding failures. These corrections are known as
7686 @dfn{errata workarounds}, and are enabled based on the processor on
7687 which the trace was recorded.
7688
7689 By default, @value{GDBN} attempts to detect the processor
7690 automatically, and apply the necessary workarounds for it. However,
7691 you may need to specify the processor if @value{GDBN} does not yet
7692 support it. This command allows you to do that, and also allows to
7693 disable the workarounds.
7694
7695 The argument @var{identifier} identifies the @sc{cpu} and is of the
7696 form: @code{@var{vendor}:@var{processor identifier}}. In addition,
7697 there are two special identifiers, @code{none} and @code{auto}
7698 (default).
7699
7700 The following vendor identifiers and corresponding processor
7701 identifiers are currently supported:
7702
7703 @multitable @columnfractions .1 .9
7704
7705 @item @code{intel}
7706 @tab @var{family}/@var{model}[/@var{stepping}]
7707
7708 @end multitable
7709
7710 On GNU/Linux systems, the processor @var{family}, @var{model}, and
7711 @var{stepping} can be obtained from @code{/proc/cpuinfo}.
7712
7713 If @var{identifier} is @code{auto}, enable errata workarounds for the
7714 processor on which the trace was recorded. If @var{identifier} is
7715 @code{none}, errata workarounds are disabled.
7716
7717 For example, when using an old @value{GDBN} on a new system, decode
7718 may fail because @value{GDBN} does not support the new processor. It
7719 often suffices to specify an older processor that @value{GDBN}
7720 supports.
7721
7722 @smallexample
7723 (gdb) info record
7724 Active record target: record-btrace
7725 Recording format: Intel Processor Trace.
7726 Buffer size: 16kB.
7727 Failed to configure the Intel Processor Trace decoder: unknown cpu.
7728 (gdb) set record btrace cpu intel:6/158
7729 (gdb) info record
7730 Active record target: record-btrace
7731 Recording format: Intel Processor Trace.
7732 Buffer size: 16kB.
7733 Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7734 @end smallexample
7735
7736 @kindex show record btrace
7737 @item show record btrace replay-memory-access
7738 Show the current setting of @code{replay-memory-access}.
7739
7740 @item show record btrace cpu
7741 Show the processor to be used for enabling trace decode errata
7742 workarounds.
7743
7744 @kindex set record btrace bts
7745 @item set record btrace bts buffer-size @var{size}
7746 @itemx set record btrace bts buffer-size unlimited
7747 Set the requested ring buffer size for branch tracing in @acronym{BTS}
7748 format. Default is 64KB.
7749
7750 If @var{size} is a positive number, then @value{GDBN} will try to
7751 allocate a buffer of at least @var{size} bytes for each new thread
7752 that uses the btrace recording method and the @acronym{BTS} format.
7753 The actually obtained buffer size may differ from the requested
7754 @var{size}. Use the @code{info record} command to see the actual
7755 buffer size for each thread that uses the btrace recording method and
7756 the @acronym{BTS} format.
7757
7758 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7759 allocate a buffer of 4MB.
7760
7761 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7762 also need longer to process the branch trace data before it can be used.
7763
7764 @item show record btrace bts buffer-size @var{size}
7765 Show the current setting of the requested ring buffer size for branch
7766 tracing in @acronym{BTS} format.
7767
7768 @kindex set record btrace pt
7769 @item set record btrace pt buffer-size @var{size}
7770 @itemx set record btrace pt buffer-size unlimited
7771 Set the requested ring buffer size for branch tracing in Intel
7772 Processor Trace format. Default is 16KB.
7773
7774 If @var{size} is a positive number, then @value{GDBN} will try to
7775 allocate a buffer of at least @var{size} bytes for each new thread
7776 that uses the btrace recording method and the Intel Processor Trace
7777 format. The actually obtained buffer size may differ from the
7778 requested @var{size}. Use the @code{info record} command to see the
7779 actual buffer size for each thread.
7780
7781 If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7782 allocate a buffer of 4MB.
7783
7784 Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7785 also need longer to process the branch trace data before it can be used.
7786
7787 @item show record btrace pt buffer-size @var{size}
7788 Show the current setting of the requested ring buffer size for branch
7789 tracing in Intel Processor Trace format.
7790
7791 @kindex info record
7792 @item info record
7793 Show various statistics about the recording depending on the recording
7794 method:
7795
7796 @table @code
7797 @item full
7798 For the @code{full} recording method, it shows the state of process
7799 record and its in-memory execution log buffer, including:
7800
7801 @itemize @bullet
7802 @item
7803 Whether in record mode or replay mode.
7804 @item
7805 Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7806 @item
7807 Highest recorded instruction number.
7808 @item
7809 Current instruction about to be replayed (if in replay mode).
7810 @item
7811 Number of instructions contained in the execution log.
7812 @item
7813 Maximum number of instructions that may be contained in the execution log.
7814 @end itemize
7815
7816 @item btrace
7817 For the @code{btrace} recording method, it shows:
7818
7819 @itemize @bullet
7820 @item
7821 Recording format.
7822 @item
7823 Number of instructions that have been recorded.
7824 @item
7825 Number of blocks of sequential control-flow formed by the recorded
7826 instructions.
7827 @item
7828 Whether in record mode or replay mode.
7829 @end itemize
7830
7831 For the @code{bts} recording format, it also shows:
7832 @itemize @bullet
7833 @item
7834 Size of the perf ring buffer.
7835 @end itemize
7836
7837 For the @code{pt} recording format, it also shows:
7838 @itemize @bullet
7839 @item
7840 Size of the perf ring buffer.
7841 @end itemize
7842 @end table
7843
7844 @kindex record delete
7845 @kindex rec del
7846 @item record delete
7847 When record target runs in replay mode (``in the past''), delete the
7848 subsequent execution log and begin to record a new execution log starting
7849 from the current address. This means you will abandon the previously
7850 recorded ``future'' and begin recording a new ``future''.
7851
7852 @kindex record instruction-history
7853 @kindex rec instruction-history
7854 @item record instruction-history
7855 Disassembles instructions from the recorded execution log. By
7856 default, ten instructions are disassembled. This can be changed using
7857 the @code{set record instruction-history-size} command. Instructions
7858 are printed in execution order.
7859
7860 It can also print mixed source+disassembly if you specify the the
7861 @code{/m} or @code{/s} modifier, and print the raw instructions in hex
7862 as well as in symbolic form by specifying the @code{/r} modifier.
7863
7864 The current position marker is printed for the instruction at the
7865 current program counter value. This instruction can appear multiple
7866 times in the trace and the current position marker will be printed
7867 every time. To omit the current position marker, specify the
7868 @code{/p} modifier.
7869
7870 To better align the printed instructions when the trace contains
7871 instructions from more than one function, the function name may be
7872 omitted by specifying the @code{/f} modifier.
7873
7874 Speculatively executed instructions are prefixed with @samp{?}. This
7875 feature is not available for all recording formats.
7876
7877 There are several ways to specify what part of the execution log to
7878 disassemble:
7879
7880 @table @code
7881 @item record instruction-history @var{insn}
7882 Disassembles ten instructions starting from instruction number
7883 @var{insn}.
7884
7885 @item record instruction-history @var{insn}, +/-@var{n}
7886 Disassembles @var{n} instructions around instruction number
7887 @var{insn}. If @var{n} is preceded with @code{+}, disassembles
7888 @var{n} instructions after instruction number @var{insn}. If
7889 @var{n} is preceded with @code{-}, disassembles @var{n}
7890 instructions before instruction number @var{insn}.
7891
7892 @item record instruction-history
7893 Disassembles ten more instructions after the last disassembly.
7894
7895 @item record instruction-history -
7896 Disassembles ten more instructions before the last disassembly.
7897
7898 @item record instruction-history @var{begin}, @var{end}
7899 Disassembles instructions beginning with instruction number
7900 @var{begin} until instruction number @var{end}. The instruction
7901 number @var{end} is included.
7902 @end table
7903
7904 This command may not be available for all recording methods.
7905
7906 @kindex set record
7907 @item set record instruction-history-size @var{size}
7908 @itemx set record instruction-history-size unlimited
7909 Define how many instructions to disassemble in the @code{record
7910 instruction-history} command. The default value is 10.
7911 A @var{size} of @code{unlimited} means unlimited instructions.
7912
7913 @kindex show record
7914 @item show record instruction-history-size
7915 Show how many instructions to disassemble in the @code{record
7916 instruction-history} command.
7917
7918 @kindex record function-call-history
7919 @kindex rec function-call-history
7920 @item record function-call-history
7921 Prints the execution history at function granularity. It prints one
7922 line for each sequence of instructions that belong to the same
7923 function giving the name of that function, the source lines
7924 for this instruction sequence (if the @code{/l} modifier is
7925 specified), and the instructions numbers that form the sequence (if
7926 the @code{/i} modifier is specified). The function names are indented
7927 to reflect the call stack depth if the @code{/c} modifier is
7928 specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7929 given together.
7930
7931 @smallexample
7932 (@value{GDBP}) @b{list 1, 10}
7933 1 void foo (void)
7934 2 @{
7935 3 @}
7936 4
7937 5 void bar (void)
7938 6 @{
7939 7 ...
7940 8 foo ();
7941 9 ...
7942 10 @}
7943 (@value{GDBP}) @b{record function-call-history /ilc}
7944 1 bar inst 1,4 at foo.c:6,8
7945 2 foo inst 5,10 at foo.c:2,3
7946 3 bar inst 11,13 at foo.c:9,10
7947 @end smallexample
7948
7949 By default, ten lines are printed. This can be changed using the
7950 @code{set record function-call-history-size} command. Functions are
7951 printed in execution order. There are several ways to specify what
7952 to print:
7953
7954 @table @code
7955 @item record function-call-history @var{func}
7956 Prints ten functions starting from function number @var{func}.
7957
7958 @item record function-call-history @var{func}, +/-@var{n}
7959 Prints @var{n} functions around function number @var{func}. If
7960 @var{n} is preceded with @code{+}, prints @var{n} functions after
7961 function number @var{func}. If @var{n} is preceded with @code{-},
7962 prints @var{n} functions before function number @var{func}.
7963
7964 @item record function-call-history
7965 Prints ten more functions after the last ten-line print.
7966
7967 @item record function-call-history -
7968 Prints ten more functions before the last ten-line print.
7969
7970 @item record function-call-history @var{begin}, @var{end}
7971 Prints functions beginning with function number @var{begin} until
7972 function number @var{end}. The function number @var{end} is included.
7973 @end table
7974
7975 This command may not be available for all recording methods.
7976
7977 @item set record function-call-history-size @var{size}
7978 @itemx set record function-call-history-size unlimited
7979 Define how many lines to print in the
7980 @code{record function-call-history} command. The default value is 10.
7981 A size of @code{unlimited} means unlimited lines.
7982
7983 @item show record function-call-history-size
7984 Show how many lines to print in the
7985 @code{record function-call-history} command.
7986 @end table
7987
7988
7989 @node Stack
7990 @chapter Examining the Stack
7991
7992 When your program has stopped, the first thing you need to know is where it
7993 stopped and how it got there.
7994
7995 @cindex call stack
7996 Each time your program performs a function call, information about the call
7997 is generated.
7998 That information includes the location of the call in your program,
7999 the arguments of the call,
8000 and the local variables of the function being called.
8001 The information is saved in a block of data called a @dfn{stack frame}.
8002 The stack frames are allocated in a region of memory called the @dfn{call
8003 stack}.
8004
8005 When your program stops, the @value{GDBN} commands for examining the
8006 stack allow you to see all of this information.
8007
8008 @cindex selected frame
8009 One of the stack frames is @dfn{selected} by @value{GDBN} and many
8010 @value{GDBN} commands refer implicitly to the selected frame. In
8011 particular, whenever you ask @value{GDBN} for the value of a variable in
8012 your program, the value is found in the selected frame. There are
8013 special @value{GDBN} commands to select whichever frame you are
8014 interested in. @xref{Selection, ,Selecting a Frame}.
8015
8016 When your program stops, @value{GDBN} automatically selects the
8017 currently executing frame and describes it briefly, similar to the
8018 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
8019
8020 @menu
8021 * Frames:: Stack frames
8022 * Backtrace:: Backtraces
8023 * Selection:: Selecting a frame
8024 * Frame Info:: Information on a frame
8025 * Frame Apply:: Applying a command to several frames
8026 * Frame Filter Management:: Managing frame filters
8027
8028 @end menu
8029
8030 @node Frames
8031 @section Stack Frames
8032
8033 @cindex frame, definition
8034 @cindex stack frame
8035 The call stack is divided up into contiguous pieces called @dfn{stack
8036 frames}, or @dfn{frames} for short; each frame is the data associated
8037 with one call to one function. The frame contains the arguments given
8038 to the function, the function's local variables, and the address at
8039 which the function is executing.
8040
8041 @cindex initial frame
8042 @cindex outermost frame
8043 @cindex innermost frame
8044 When your program is started, the stack has only one frame, that of the
8045 function @code{main}. This is called the @dfn{initial} frame or the
8046 @dfn{outermost} frame. Each time a function is called, a new frame is
8047 made. Each time a function returns, the frame for that function invocation
8048 is eliminated. If a function is recursive, there can be many frames for
8049 the same function. The frame for the function in which execution is
8050 actually occurring is called the @dfn{innermost} frame. This is the most
8051 recently created of all the stack frames that still exist.
8052
8053 @cindex frame pointer
8054 Inside your program, stack frames are identified by their addresses. A
8055 stack frame consists of many bytes, each of which has its own address; each
8056 kind of computer has a convention for choosing one byte whose
8057 address serves as the address of the frame. Usually this address is kept
8058 in a register called the @dfn{frame pointer register}
8059 (@pxref{Registers, $fp}) while execution is going on in that frame.
8060
8061 @cindex frame level
8062 @cindex frame number
8063 @value{GDBN} labels each existing stack frame with a @dfn{level}, a
8064 number that is zero for the innermost frame, one for the frame that
8065 called it, and so on upward. These level numbers give you a way of
8066 designating stack frames in @value{GDBN} commands. The terms
8067 @dfn{frame number} and @dfn{frame level} can be used interchangeably to
8068 describe this number.
8069
8070 @c The -fomit-frame-pointer below perennially causes hbox overflow
8071 @c underflow problems.
8072 @cindex frameless execution
8073 Some compilers provide a way to compile functions so that they operate
8074 without stack frames. (For example, the @value{NGCC} option
8075 @smallexample
8076 @samp{-fomit-frame-pointer}
8077 @end smallexample
8078 generates functions without a frame.)
8079 This is occasionally done with heavily used library functions to save
8080 the frame setup time. @value{GDBN} has limited facilities for dealing
8081 with these function invocations. If the innermost function invocation
8082 has no stack frame, @value{GDBN} nevertheless regards it as though
8083 it had a separate frame, which is numbered zero as usual, allowing
8084 correct tracing of the function call chain. However, @value{GDBN} has
8085 no provision for frameless functions elsewhere in the stack.
8086
8087 @node Backtrace
8088 @section Backtraces
8089
8090 @cindex traceback
8091 @cindex call stack traces
8092 A backtrace is a summary of how your program got where it is. It shows one
8093 line per frame, for many frames, starting with the currently executing
8094 frame (frame zero), followed by its caller (frame one), and on up the
8095 stack.
8096
8097 @anchor{backtrace-command}
8098 @kindex backtrace
8099 @kindex bt @r{(@code{backtrace})}
8100 To print a backtrace of the entire stack, use the @code{backtrace}
8101 command, or its alias @code{bt}. This command will print one line per
8102 frame for frames in the stack. By default, all stack frames are
8103 printed. You can stop the backtrace at any time by typing the system
8104 interrupt character, normally @kbd{Ctrl-c}.
8105
8106 @table @code
8107 @item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8108 @itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
8109 Print the backtrace of the entire stack.
8110
8111 The optional @var{count} can be one of the following:
8112
8113 @table @code
8114 @item @var{n}
8115 @itemx @var{n}
8116 Print only the innermost @var{n} frames, where @var{n} is a positive
8117 number.
8118
8119 @item -@var{n}
8120 @itemx -@var{n}
8121 Print only the outermost @var{n} frames, where @var{n} is a positive
8122 number.
8123 @end table
8124
8125 Options:
8126
8127 @table @code
8128 @item -full
8129 Print the values of the local variables also. This can be combined
8130 with the optional @var{count} to limit the number of frames shown.
8131
8132 @item -no-filters
8133 Do not run Python frame filters on this backtrace. @xref{Frame
8134 Filter API}, for more information. Additionally use @ref{disable
8135 frame-filter all} to turn off all frame filters. This is only
8136 relevant when @value{GDBN} has been configured with @code{Python}
8137 support.
8138
8139 @item -hide
8140 A Python frame filter might decide to ``elide'' some frames. Normally
8141 such elided frames are still printed, but they are indented relative
8142 to the filtered frames that cause them to be elided. The @code{-hide}
8143 option causes elided frames to not be printed at all.
8144 @end table
8145
8146 The @code{backtrace} command also supports a number of options that
8147 allow overriding relevant global print settings as set by @code{set
8148 backtrace} and @code{set print} subcommands:
8149
8150 @table @code
8151 @item -past-main [@code{on}|@code{off}]
8152 Set whether backtraces should continue past @code{main}. Related setting:
8153 @ref{set backtrace past-main}.
8154
8155 @item -past-entry [@code{on}|@code{off}]
8156 Set whether backtraces should continue past the entry point of a program.
8157 Related setting: @ref{set backtrace past-entry}.
8158
8159 @item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
8160 Set printing of function arguments at function entry.
8161 Related setting: @ref{set print entry-values}.
8162
8163 @item -frame-arguments @code{all}|@code{scalars}|@code{none}
8164 Set printing of non-scalar frame arguments.
8165 Related setting: @ref{set print frame-arguments}.
8166
8167 @item -raw-frame-arguments [@code{on}|@code{off}]
8168 Set whether to print frame arguments in raw form.
8169 Related setting: @ref{set print raw-frame-arguments}.
8170
8171 @item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
8172 Set printing of frame information.
8173 Related setting: @ref{set print frame-info}.
8174 @end table
8175
8176 The optional @var{qualifier} is maintained for backward compatibility.
8177 It can be one of the following:
8178
8179 @table @code
8180 @item full
8181 Equivalent to the @code{-full} option.
8182
8183 @item no-filters
8184 Equivalent to the @code{-no-filters} option.
8185
8186 @item hide
8187 Equivalent to the @code{-hide} option.
8188 @end table
8189
8190 @end table
8191
8192 @kindex where
8193 @kindex info stack
8194 The names @code{where} and @code{info stack} (abbreviated @code{info s})
8195 are additional aliases for @code{backtrace}.
8196
8197 @cindex multiple threads, backtrace
8198 In a multi-threaded program, @value{GDBN} by default shows the
8199 backtrace only for the current thread. To display the backtrace for
8200 several or all of the threads, use the command @code{thread apply}
8201 (@pxref{Threads, thread apply}). For example, if you type @kbd{thread
8202 apply all backtrace}, @value{GDBN} will display the backtrace for all
8203 the threads; this is handy when you debug a core dump of a
8204 multi-threaded program.
8205
8206 Each line in the backtrace shows the frame number and the function name.
8207 The program counter value is also shown---unless you use @code{set
8208 print address off}. The backtrace also shows the source file name and
8209 line number, as well as the arguments to the function. The program
8210 counter value is omitted if it is at the beginning of the code for that
8211 line number.
8212
8213 Here is an example of a backtrace. It was made with the command
8214 @samp{bt 3}, so it shows the innermost three frames.
8215
8216 @smallexample
8217 @group
8218 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8219 at builtin.c:993
8220 #1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
8221 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
8222 at macro.c:71
8223 (More stack frames follow...)
8224 @end group
8225 @end smallexample
8226
8227 @noindent
8228 The display for frame zero does not begin with a program counter
8229 value, indicating that your program has stopped at the beginning of the
8230 code for line @code{993} of @code{builtin.c}.
8231
8232 @noindent
8233 The value of parameter @code{data} in frame 1 has been replaced by
8234 @code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
8235 only if it is a scalar (integer, pointer, enumeration, etc). See command
8236 @kbd{set print frame-arguments} in @ref{Print Settings} for more details
8237 on how to configure the way function parameter values are printed.
8238 The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
8239 what frame information is printed.
8240
8241 @cindex optimized out, in backtrace
8242 @cindex function call arguments, optimized out
8243 If your program was compiled with optimizations, some compilers will
8244 optimize away arguments passed to functions if those arguments are
8245 never used after the call. Such optimizations generate code that
8246 passes arguments through registers, but doesn't store those arguments
8247 in the stack frame. @value{GDBN} has no way of displaying such
8248 arguments in stack frames other than the innermost one. Here's what
8249 such a backtrace might look like:
8250
8251 @smallexample
8252 @group
8253 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8254 at builtin.c:993
8255 #1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
8256 #2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
8257 at macro.c:71
8258 (More stack frames follow...)
8259 @end group
8260 @end smallexample
8261
8262 @noindent
8263 The values of arguments that were not saved in their stack frames are
8264 shown as @samp{<optimized out>}.
8265
8266 If you need to display the values of such optimized-out arguments,
8267 either deduce that from other variables whose values depend on the one
8268 you are interested in, or recompile without optimizations.
8269
8270 @cindex backtrace beyond @code{main} function
8271 @cindex program entry point
8272 @cindex startup code, and backtrace
8273 Most programs have a standard user entry point---a place where system
8274 libraries and startup code transition into user code. For C this is
8275 @code{main}@footnote{
8276 Note that embedded programs (the so-called ``free-standing''
8277 environment) are not required to have a @code{main} function as the
8278 entry point. They could even have multiple entry points.}.
8279 When @value{GDBN} finds the entry function in a backtrace
8280 it will terminate the backtrace, to avoid tracing into highly
8281 system-specific (and generally uninteresting) code.
8282
8283 If you need to examine the startup code, or limit the number of levels
8284 in a backtrace, you can change this behavior:
8285
8286 @table @code
8287 @item set backtrace past-main
8288 @itemx set backtrace past-main on
8289 @anchor{set backtrace past-main}
8290 @kindex set backtrace
8291 Backtraces will continue past the user entry point.
8292
8293 @item set backtrace past-main off
8294 Backtraces will stop when they encounter the user entry point. This is the
8295 default.
8296
8297 @item show backtrace past-main
8298 @kindex show backtrace
8299 Display the current user entry point backtrace policy.
8300
8301 @item set backtrace past-entry
8302 @itemx set backtrace past-entry on
8303 @anchor{set backtrace past-entry}
8304 Backtraces will continue past the internal entry point of an application.
8305 This entry point is encoded by the linker when the application is built,
8306 and is likely before the user entry point @code{main} (or equivalent) is called.
8307
8308 @item set backtrace past-entry off
8309 Backtraces will stop when they encounter the internal entry point of an
8310 application. This is the default.
8311
8312 @item show backtrace past-entry
8313 Display the current internal entry point backtrace policy.
8314
8315 @item set backtrace limit @var{n}
8316 @itemx set backtrace limit 0
8317 @itemx set backtrace limit unlimited
8318 @anchor{set backtrace limit}
8319 @cindex backtrace limit
8320 Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8321 or zero means unlimited levels.
8322
8323 @item show backtrace limit
8324 Display the current limit on backtrace levels.
8325 @end table
8326
8327 You can control how file names are displayed.
8328
8329 @table @code
8330 @item set filename-display
8331 @itemx set filename-display relative
8332 @cindex filename-display
8333 Display file names relative to the compilation directory. This is the default.
8334
8335 @item set filename-display basename
8336 Display only basename of a filename.
8337
8338 @item set filename-display absolute
8339 Display an absolute filename.
8340
8341 @item show filename-display
8342 Show the current way to display filenames.
8343 @end table
8344
8345 @node Selection
8346 @section Selecting a Frame
8347
8348 Most commands for examining the stack and other data in your program work on
8349 whichever stack frame is selected at the moment. Here are the commands for
8350 selecting a stack frame; all of them finish by printing a brief description
8351 of the stack frame just selected.
8352
8353 @table @code
8354 @kindex frame@r{, selecting}
8355 @kindex f @r{(@code{frame})}
8356 @item frame @r{[} @var{frame-selection-spec} @r{]}
8357 @item f @r{[} @var{frame-selection-spec} @r{]}
8358 The @command{frame} command allows different stack frames to be
8359 selected. The @var{frame-selection-spec} can be any of the following:
8360
8361 @table @code
8362 @kindex frame level
8363 @item @var{num}
8364 @item level @var{num}
8365 Select frame level @var{num}. Recall that frame zero is the innermost
8366 (currently executing) frame, frame one is the frame that called the
8367 innermost one, and so on. The highest level frame is usually the one
8368 for @code{main}.
8369
8370 As this is the most common method of navigating the frame stack, the
8371 string @command{level} can be omitted. For example, the following two
8372 commands are equivalent:
8373
8374 @smallexample
8375 (@value{GDBP}) frame 3
8376 (@value{GDBP}) frame level 3
8377 @end smallexample
8378
8379 @kindex frame address
8380 @item address @var{stack-address}
8381 Select the frame with stack address @var{stack-address}. The
8382 @var{stack-address} for a frame can be seen in the output of
8383 @command{info frame}, for example:
8384
8385 @smallexample
8386 (gdb) info frame
8387 Stack level 1, frame at 0x7fffffffda30:
8388 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8389 tail call frame, caller of frame at 0x7fffffffda30
8390 source language c++.
8391 Arglist at unknown address.
8392 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8393 @end smallexample
8394
8395 The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8396 indicated by the line:
8397
8398 @smallexample
8399 Stack level 1, frame at 0x7fffffffda30:
8400 @end smallexample
8401
8402 @kindex frame function
8403 @item function @var{function-name}
8404 Select the stack frame for function @var{function-name}. If there are
8405 multiple stack frames for function @var{function-name} then the inner
8406 most stack frame is selected.
8407
8408 @kindex frame view
8409 @item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8410 View a frame that is not part of @value{GDBN}'s backtrace. The frame
8411 viewed has stack address @var{stack-addr}, and optionally, a program
8412 counter address of @var{pc-addr}.
8413
8414 This is useful mainly if the chaining of stack frames has been
8415 damaged by a bug, making it impossible for @value{GDBN} to assign
8416 numbers properly to all frames. In addition, this can be useful
8417 when your program has multiple stacks and switches between them.
8418
8419 When viewing a frame outside the current backtrace using
8420 @command{frame view} then you can always return to the original
8421 stack using one of the previous stack frame selection instructions,
8422 for example @command{frame level 0}.
8423
8424 @end table
8425
8426 @kindex up
8427 @item up @var{n}
8428 Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8429 numbers @var{n}, this advances toward the outermost frame, to higher
8430 frame numbers, to frames that have existed longer.
8431
8432 @kindex down
8433 @kindex do @r{(@code{down})}
8434 @item down @var{n}
8435 Move @var{n} frames down the stack; @var{n} defaults to 1. For
8436 positive numbers @var{n}, this advances toward the innermost frame, to
8437 lower frame numbers, to frames that were created more recently.
8438 You may abbreviate @code{down} as @code{do}.
8439 @end table
8440
8441 All of these commands end by printing two lines of output describing the
8442 frame. The first line shows the frame number, the function name, the
8443 arguments, and the source file and line number of execution in that
8444 frame. The second line shows the text of that source line.
8445
8446 @need 1000
8447 For example:
8448
8449 @smallexample
8450 @group
8451 (@value{GDBP}) up
8452 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8453 at env.c:10
8454 10 read_input_file (argv[i]);
8455 @end group
8456 @end smallexample
8457
8458 After such a printout, the @code{list} command with no arguments
8459 prints ten lines centered on the point of execution in the frame.
8460 You can also edit the program at the point of execution with your favorite
8461 editing program by typing @code{edit}.
8462 @xref{List, ,Printing Source Lines},
8463 for details.
8464
8465 @table @code
8466 @kindex select-frame
8467 @item select-frame @r{[} @var{frame-selection-spec} @r{]}
8468 The @code{select-frame} command is a variant of @code{frame} that does
8469 not display the new frame after selecting it. This command is
8470 intended primarily for use in @value{GDBN} command scripts, where the
8471 output might be unnecessary and distracting. The
8472 @var{frame-selection-spec} is as for the @command{frame} command
8473 described in @ref{Selection, ,Selecting a Frame}.
8474
8475 @kindex down-silently
8476 @kindex up-silently
8477 @item up-silently @var{n}
8478 @itemx down-silently @var{n}
8479 These two commands are variants of @code{up} and @code{down},
8480 respectively; they differ in that they do their work silently, without
8481 causing display of the new frame. They are intended primarily for use
8482 in @value{GDBN} command scripts, where the output might be unnecessary and
8483 distracting.
8484 @end table
8485
8486 @node Frame Info
8487 @section Information About a Frame
8488
8489 There are several other commands to print information about the selected
8490 stack frame.
8491
8492 @table @code
8493 @item frame
8494 @itemx f
8495 When used without any argument, this command does not change which
8496 frame is selected, but prints a brief description of the currently
8497 selected stack frame. It can be abbreviated @code{f}. With an
8498 argument, this command is used to select a stack frame.
8499 @xref{Selection, ,Selecting a Frame}.
8500
8501 @kindex info frame
8502 @kindex info f @r{(@code{info frame})}
8503 @item info frame
8504 @itemx info f
8505 This command prints a verbose description of the selected stack frame,
8506 including:
8507
8508 @itemize @bullet
8509 @item
8510 the address of the frame
8511 @item
8512 the address of the next frame down (called by this frame)
8513 @item
8514 the address of the next frame up (caller of this frame)
8515 @item
8516 the language in which the source code corresponding to this frame is written
8517 @item
8518 the address of the frame's arguments
8519 @item
8520 the address of the frame's local variables
8521 @item
8522 the program counter saved in it (the address of execution in the caller frame)
8523 @item
8524 which registers were saved in the frame
8525 @end itemize
8526
8527 @noindent The verbose description is useful when
8528 something has gone wrong that has made the stack format fail to fit
8529 the usual conventions.
8530
8531 @item info frame @r{[} @var{frame-selection-spec} @r{]}
8532 @itemx info f @r{[} @var{frame-selection-spec} @r{]}
8533 Print a verbose description of the frame selected by
8534 @var{frame-selection-spec}. The @var{frame-selection-spec} is the
8535 same as for the @command{frame} command (@pxref{Selection, ,Selecting
8536 a Frame}). The selected frame remains unchanged by this command.
8537
8538 @kindex info args
8539 @item info args [-q]
8540 Print the arguments of the selected frame, each on a separate line.
8541
8542 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8543 printing header information and messages explaining why no argument
8544 have been printed.
8545
8546 @item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8547 Like @kbd{info args}, but only print the arguments selected
8548 with the provided regexp(s).
8549
8550 If @var{regexp} is provided, print only the arguments whose names
8551 match the regular expression @var{regexp}.
8552
8553 If @var{type_regexp} is provided, print only the arguments whose
8554 types, as printed by the @code{whatis} command, match
8555 the regular expression @var{type_regexp}.
8556 If @var{type_regexp} contains space(s), it should be enclosed in
8557 quote characters. If needed, use backslash to escape the meaning
8558 of special characters or quotes.
8559
8560 If both @var{regexp} and @var{type_regexp} are provided, an argument
8561 is printed only if its name matches @var{regexp} and its type matches
8562 @var{type_regexp}.
8563
8564 @item info locals [-q]
8565 @kindex info locals
8566 Print the local variables of the selected frame, each on a separate
8567 line. These are all variables (declared either static or automatic)
8568 accessible at the point of execution of the selected frame.
8569
8570 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8571 printing header information and messages explaining why no local variables
8572 have been printed.
8573
8574 @item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8575 Like @kbd{info locals}, but only print the local variables selected
8576 with the provided regexp(s).
8577
8578 If @var{regexp} is provided, print only the local variables whose names
8579 match the regular expression @var{regexp}.
8580
8581 If @var{type_regexp} is provided, print only the local variables whose
8582 types, as printed by the @code{whatis} command, match
8583 the regular expression @var{type_regexp}.
8584 If @var{type_regexp} contains space(s), it should be enclosed in
8585 quote characters. If needed, use backslash to escape the meaning
8586 of special characters or quotes.
8587
8588 If both @var{regexp} and @var{type_regexp} are provided, a local variable
8589 is printed only if its name matches @var{regexp} and its type matches
8590 @var{type_regexp}.
8591
8592 The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8593 combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8594 For example, your program might use Resource Acquisition Is
8595 Initialization types (RAII) such as @code{lock_something_t}: each
8596 local variable of type @code{lock_something_t} automatically places a
8597 lock that is destroyed when the variable goes out of scope. You can
8598 then list all acquired locks in your program by doing
8599 @smallexample
8600 thread apply all -s frame apply all -s info locals -q -t lock_something_t
8601 @end smallexample
8602 @noindent
8603 or the equivalent shorter form
8604 @smallexample
8605 tfaas i lo -q -t lock_something_t
8606 @end smallexample
8607
8608 @end table
8609
8610 @node Frame Apply
8611 @section Applying a Command to Several Frames.
8612 @kindex frame apply
8613 @cindex apply command to several frames
8614 @table @code
8615 @item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
8616 The @code{frame apply} command allows you to apply the named
8617 @var{command} to one or more frames.
8618
8619 @table @code
8620 @item @code{all}
8621 Specify @code{all} to apply @var{command} to all frames.
8622
8623 @item @var{count}
8624 Use @var{count} to apply @var{command} to the innermost @var{count}
8625 frames, where @var{count} is a positive number.
8626
8627 @item @var{-count}
8628 Use @var{-count} to apply @var{command} to the outermost @var{count}
8629 frames, where @var{count} is a positive number.
8630
8631 @item @code{level}
8632 Use @code{level} to apply @var{command} to the set of frames identified
8633 by the @var{level} list. @var{level} is a frame level or a range of frame
8634 levels as @var{level1}-@var{level2}. The frame level is the number shown
8635 in the first field of the @samp{backtrace} command output.
8636 E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8637 at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8638
8639 @end table
8640
8641 Note that the frames on which @code{frame apply} applies a command are
8642 also influenced by the @code{set backtrace} settings such as @code{set
8643 backtrace past-main} and @code{set backtrace limit N}.
8644 @xref{Backtrace,,Backtraces}.
8645
8646 The @code{frame apply} command also supports a number of options that
8647 allow overriding relevant @code{set backtrace} settings:
8648
8649 @table @code
8650 @item -past-main [@code{on}|@code{off}]
8651 Whether backtraces should continue past @code{main}.
8652 Related setting: @ref{set backtrace past-main}.
8653
8654 @item -past-entry [@code{on}|@code{off}]
8655 Whether backtraces should continue past the entry point of a program.
8656 Related setting: @ref{set backtrace past-entry}.
8657 @end table
8658
8659 By default, @value{GDBN} displays some frame information before the
8660 output produced by @var{command}, and an error raised during the
8661 execution of a @var{command} will abort @code{frame apply}. The
8662 following options can be used to fine-tune these behaviors:
8663
8664 @table @code
8665 @item -c
8666 The flag @code{-c}, which stands for @samp{continue}, causes any
8667 errors in @var{command} to be displayed, and the execution of
8668 @code{frame apply} then continues.
8669 @item -s
8670 The flag @code{-s}, which stands for @samp{silent}, causes any errors
8671 or empty output produced by a @var{command} to be silently ignored.
8672 That is, the execution continues, but the frame information and errors
8673 are not printed.
8674 @item -q
8675 The flag @code{-q} (@samp{quiet}) disables printing the frame
8676 information.
8677 @end table
8678
8679 The following example shows how the flags @code{-c} and @code{-s} are
8680 working when applying the command @code{p j} to all frames, where
8681 variable @code{j} can only be successfully printed in the outermost
8682 @code{#1 main} frame.
8683
8684 @smallexample
8685 @group
8686 (gdb) frame apply all p j
8687 #0 some_function (i=5) at fun.c:4
8688 No symbol "j" in current context.
8689 (gdb) frame apply all -c p j
8690 #0 some_function (i=5) at fun.c:4
8691 No symbol "j" in current context.
8692 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8693 $1 = 5
8694 (gdb) frame apply all -s p j
8695 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8696 $2 = 5
8697 (gdb)
8698 @end group
8699 @end smallexample
8700
8701 By default, @samp{frame apply}, prints the frame location
8702 information before the command output:
8703
8704 @smallexample
8705 @group
8706 (gdb) frame apply all p $sp
8707 #0 some_function (i=5) at fun.c:4
8708 $4 = (void *) 0xffffd1e0
8709 #1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8710 $5 = (void *) 0xffffd1f0
8711 (gdb)
8712 @end group
8713 @end smallexample
8714
8715 If the flag @code{-q} is given, no frame information is printed:
8716 @smallexample
8717 @group
8718 (gdb) frame apply all -q p $sp
8719 $12 = (void *) 0xffffd1e0
8720 $13 = (void *) 0xffffd1f0
8721 (gdb)
8722 @end group
8723 @end smallexample
8724
8725 @end table
8726
8727 @table @code
8728
8729 @kindex faas
8730 @cindex apply a command to all frames (ignoring errors and empty output)
8731 @item faas @var{command}
8732 Shortcut for @code{frame apply all -s @var{command}}.
8733 Applies @var{command} on all frames, ignoring errors and empty output.
8734
8735 It can for example be used to print a local variable or a function
8736 argument without knowing the frame where this variable or argument
8737 is, using:
8738 @smallexample
8739 (@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8740 @end smallexample
8741
8742 The @code{faas} command accepts the same options as the @code{frame
8743 apply} command. @xref{Frame Apply,,frame apply}.
8744
8745 Note that the command @code{tfaas @var{command}} applies @var{command}
8746 on all frames of all threads. See @xref{Threads,,Threads}.
8747 @end table
8748
8749
8750 @node Frame Filter Management
8751 @section Management of Frame Filters.
8752 @cindex managing frame filters
8753
8754 Frame filters are Python based utilities to manage and decorate the
8755 output of frames. @xref{Frame Filter API}, for further information.
8756
8757 Managing frame filters is performed by several commands available
8758 within @value{GDBN}, detailed here.
8759
8760 @table @code
8761 @kindex info frame-filter
8762 @item info frame-filter
8763 Print a list of installed frame filters from all dictionaries, showing
8764 their name, priority and enabled status.
8765
8766 @kindex disable frame-filter
8767 @anchor{disable frame-filter all}
8768 @item disable frame-filter @var{filter-dictionary} @var{filter-name}
8769 Disable a frame filter in the dictionary matching
8770 @var{filter-dictionary} and @var{filter-name}. The
8771 @var{filter-dictionary} may be @code{all}, @code{global},
8772 @code{progspace}, or the name of the object file where the frame filter
8773 dictionary resides. When @code{all} is specified, all frame filters
8774 across all dictionaries are disabled. The @var{filter-name} is the name
8775 of the frame filter and is used when @code{all} is not the option for
8776 @var{filter-dictionary}. A disabled frame-filter is not deleted, it
8777 may be enabled again later.
8778
8779 @kindex enable frame-filter
8780 @item enable frame-filter @var{filter-dictionary} @var{filter-name}
8781 Enable a frame filter in the dictionary matching
8782 @var{filter-dictionary} and @var{filter-name}. The
8783 @var{filter-dictionary} may be @code{all}, @code{global},
8784 @code{progspace} or the name of the object file where the frame filter
8785 dictionary resides. When @code{all} is specified, all frame filters across
8786 all dictionaries are enabled. The @var{filter-name} is the name of the frame
8787 filter and is used when @code{all} is not the option for
8788 @var{filter-dictionary}.
8789
8790 Example:
8791
8792 @smallexample
8793 (gdb) info frame-filter
8794
8795 global frame-filters:
8796 Priority Enabled Name
8797 1000 No 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 Yes BuildProgramFilter
8807
8808 (gdb) disable frame-filter /build/test BuildProgramFilter
8809 (gdb) info frame-filter
8810
8811 global frame-filters:
8812 Priority Enabled Name
8813 1000 No PrimaryFunctionFilter
8814 100 Yes Reverse
8815
8816 progspace /build/test frame-filters:
8817 Priority Enabled Name
8818 100 Yes ProgspaceFilter
8819
8820 objfile /build/test frame-filters:
8821 Priority Enabled Name
8822 999 No BuildProgramFilter
8823
8824 (gdb) enable frame-filter global PrimaryFunctionFilter
8825 (gdb) info frame-filter
8826
8827 global frame-filters:
8828 Priority Enabled Name
8829 1000 Yes PrimaryFunctionFilter
8830 100 Yes Reverse
8831
8832 progspace /build/test frame-filters:
8833 Priority Enabled Name
8834 100 Yes ProgspaceFilter
8835
8836 objfile /build/test frame-filters:
8837 Priority Enabled Name
8838 999 No BuildProgramFilter
8839 @end smallexample
8840
8841 @kindex set frame-filter priority
8842 @item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8843 Set the @var{priority} of a frame filter in the dictionary matching
8844 @var{filter-dictionary}, and the frame filter name matching
8845 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8846 @code{progspace} or the name of the object file where the frame filter
8847 dictionary resides. The @var{priority} is an integer.
8848
8849 @kindex show frame-filter priority
8850 @item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8851 Show the @var{priority} of a frame filter in the dictionary matching
8852 @var{filter-dictionary}, and the frame filter name matching
8853 @var{filter-name}. The @var{filter-dictionary} may be @code{global},
8854 @code{progspace} or the name of the object file where the frame filter
8855 dictionary resides.
8856
8857 Example:
8858
8859 @smallexample
8860 (gdb) info frame-filter
8861
8862 global frame-filters:
8863 Priority Enabled Name
8864 1000 Yes PrimaryFunctionFilter
8865 100 Yes Reverse
8866
8867 progspace /build/test frame-filters:
8868 Priority Enabled Name
8869 100 Yes ProgspaceFilter
8870
8871 objfile /build/test frame-filters:
8872 Priority Enabled Name
8873 999 No BuildProgramFilter
8874
8875 (gdb) set frame-filter priority global Reverse 50
8876 (gdb) info frame-filter
8877
8878 global frame-filters:
8879 Priority Enabled Name
8880 1000 Yes PrimaryFunctionFilter
8881 50 Yes Reverse
8882
8883 progspace /build/test frame-filters:
8884 Priority Enabled Name
8885 100 Yes ProgspaceFilter
8886
8887 objfile /build/test frame-filters:
8888 Priority Enabled Name
8889 999 No BuildProgramFilter
8890 @end smallexample
8891 @end table
8892
8893 @node Source
8894 @chapter Examining Source Files
8895
8896 @value{GDBN} can print parts of your program's source, since the debugging
8897 information recorded in the program tells @value{GDBN} what source files were
8898 used to build it. When your program stops, @value{GDBN} spontaneously prints
8899 the line where it stopped. Likewise, when you select a stack frame
8900 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
8901 execution in that frame has stopped. You can print other portions of
8902 source files by explicit command.
8903
8904 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
8905 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
8906 @value{GDBN} under @sc{gnu} Emacs}.
8907
8908 @menu
8909 * List:: Printing source lines
8910 * Specify Location:: How to specify code locations
8911 * Edit:: Editing source files
8912 * Search:: Searching source files
8913 * Source Path:: Specifying source directories
8914 * Machine Code:: Source and machine code
8915 @end menu
8916
8917 @node List
8918 @section Printing Source Lines
8919
8920 @kindex list
8921 @kindex l @r{(@code{list})}
8922 To print lines from a source file, use the @code{list} command
8923 (abbreviated @code{l}). By default, ten lines are printed.
8924 There are several ways to specify what part of the file you want to
8925 print; see @ref{Specify Location}, for the full list.
8926
8927 Here are the forms of the @code{list} command most commonly used:
8928
8929 @table @code
8930 @item list @var{linenum}
8931 Print lines centered around line number @var{linenum} in the
8932 current source file.
8933
8934 @item list @var{function}
8935 Print lines centered around the beginning of function
8936 @var{function}.
8937
8938 @item list
8939 Print more lines. If the last lines printed were printed with a
8940 @code{list} command, this prints lines following the last lines
8941 printed; however, if the last line printed was a solitary line printed
8942 as part of displaying a stack frame (@pxref{Stack, ,Examining the
8943 Stack}), this prints lines centered around that line.
8944
8945 @item list -
8946 Print lines just before the lines last printed.
8947 @end table
8948
8949 @cindex @code{list}, how many lines to display
8950 By default, @value{GDBN} prints ten source lines with any of these forms of
8951 the @code{list} command. You can change this using @code{set listsize}:
8952
8953 @table @code
8954 @kindex set listsize
8955 @item set listsize @var{count}
8956 @itemx set listsize unlimited
8957 Make the @code{list} command display @var{count} source lines (unless
8958 the @code{list} argument explicitly specifies some other number).
8959 Setting @var{count} to @code{unlimited} or 0 means there's no limit.
8960
8961 @kindex show listsize
8962 @item show listsize
8963 Display the number of lines that @code{list} prints.
8964 @end table
8965
8966 Repeating a @code{list} command with @key{RET} discards the argument,
8967 so it is equivalent to typing just @code{list}. This is more useful
8968 than listing the same lines again. An exception is made for an
8969 argument of @samp{-}; that argument is preserved in repetition so that
8970 each repetition moves up in the source file.
8971
8972 In general, the @code{list} command expects you to supply zero, one or two
8973 @dfn{locations}. Locations specify source lines; there are several ways
8974 of writing them (@pxref{Specify Location}), but the effect is always
8975 to specify some source line.
8976
8977 Here is a complete description of the possible arguments for @code{list}:
8978
8979 @table @code
8980 @item list @var{location}
8981 Print lines centered around the line specified by @var{location}.
8982
8983 @item list @var{first},@var{last}
8984 Print lines from @var{first} to @var{last}. Both arguments are
8985 locations. When a @code{list} command has two locations, and the
8986 source file of the second location is omitted, this refers to
8987 the same source file as the first location.
8988
8989 @item list ,@var{last}
8990 Print lines ending with @var{last}.
8991
8992 @item list @var{first},
8993 Print lines starting with @var{first}.
8994
8995 @item list +
8996 Print lines just after the lines last printed.
8997
8998 @item list -
8999 Print lines just before the lines last printed.
9000
9001 @item list
9002 As described in the preceding table.
9003 @end table
9004
9005 @node Specify Location
9006 @section Specifying a Location
9007 @cindex specifying location
9008 @cindex location
9009 @cindex source location
9010
9011 Several @value{GDBN} commands accept arguments that specify a location
9012 of your program's code. Since @value{GDBN} is a source-level
9013 debugger, a location usually specifies some line in the source code.
9014 Locations may be specified using three different formats:
9015 linespec locations, explicit locations, or address locations.
9016
9017 @menu
9018 * Linespec Locations:: Linespec locations
9019 * Explicit Locations:: Explicit locations
9020 * Address Locations:: Address locations
9021 @end menu
9022
9023 @node Linespec Locations
9024 @subsection Linespec Locations
9025 @cindex linespec locations
9026
9027 A @dfn{linespec} is a colon-separated list of source location parameters such
9028 as file name, function name, etc. Here are all the different ways of
9029 specifying a linespec:
9030
9031 @table @code
9032 @item @var{linenum}
9033 Specifies the line number @var{linenum} of the current source file.
9034
9035 @item -@var{offset}
9036 @itemx +@var{offset}
9037 Specifies the line @var{offset} lines before or after the @dfn{current
9038 line}. For the @code{list} command, the current line is the last one
9039 printed; for the breakpoint commands, this is the line at which
9040 execution stopped in the currently selected @dfn{stack frame}
9041 (@pxref{Frames, ,Frames}, for a description of stack frames.) When
9042 used as the second of the two linespecs in a @code{list} command,
9043 this specifies the line @var{offset} lines up or down from the first
9044 linespec.
9045
9046 @item @var{filename}:@var{linenum}
9047 Specifies the line @var{linenum} in the source file @var{filename}.
9048 If @var{filename} is a relative file name, then it will match any
9049 source file name with the same trailing components. For example, if
9050 @var{filename} is @samp{gcc/expr.c}, then it will match source file
9051 name of @file{/build/trunk/gcc/expr.c}, but not
9052 @file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
9053
9054 @item @var{function}
9055 Specifies the line that begins the body of the function @var{function}.
9056 For example, in C, this is the line with the open brace.
9057
9058 By default, in C@t{++} and Ada, @var{function} is interpreted as
9059 specifying all functions named @var{function} in all scopes. For
9060 C@t{++}, this means in all namespaces and classes. For Ada, this
9061 means in all packages.
9062
9063 For example, assuming a program with C@t{++} symbols named
9064 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9065 func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
9066
9067 Commands that accept a linespec let you override this with the
9068 @code{-qualified} option. For example, @w{@kbd{break -qualified
9069 func}} sets a breakpoint on a free-function named @code{func} ignoring
9070 any C@t{++} class methods and namespace functions called @code{func}.
9071
9072 @xref{Explicit Locations}.
9073
9074 @item @var{function}:@var{label}
9075 Specifies the line where @var{label} appears in @var{function}.
9076
9077 @item @var{filename}:@var{function}
9078 Specifies the line that begins the body of the function @var{function}
9079 in the file @var{filename}. You only need the file name with a
9080 function name to avoid ambiguity when there are identically named
9081 functions in different source files.
9082
9083 @item @var{label}
9084 Specifies the line at which the label named @var{label} appears
9085 in the function corresponding to the currently selected stack frame.
9086 If there is no current selected stack frame (for instance, if the inferior
9087 is not running), then @value{GDBN} will not search for a label.
9088
9089 @cindex breakpoint at static probe point
9090 @item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
9091 The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
9092 applications to embed static probes. @xref{Static Probe Points}, for more
9093 information on finding and using static probes. This form of linespec
9094 specifies the location of such a static probe.
9095
9096 If @var{objfile} is given, only probes coming from that shared library
9097 or executable matching @var{objfile} as a regular expression are considered.
9098 If @var{provider} is given, then only probes from that provider are considered.
9099 If several probes match the spec, @value{GDBN} will insert a breakpoint at
9100 each one of those probes.
9101 @end table
9102
9103 @node Explicit Locations
9104 @subsection Explicit Locations
9105 @cindex explicit locations
9106
9107 @dfn{Explicit locations} allow the user to directly specify the source
9108 location's parameters using option-value pairs.
9109
9110 Explicit locations are useful when several functions, labels, or
9111 file names have the same name (base name for files) in the program's
9112 sources. In these cases, explicit locations point to the source
9113 line you meant more accurately and unambiguously. Also, using
9114 explicit locations might be faster in large programs.
9115
9116 For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
9117 defined in the file named @file{foo} or the label @code{bar} in a function
9118 named @code{foo}. @value{GDBN} must search either the file system or
9119 the symbol table to know.
9120
9121 The list of valid explicit location options is summarized in the
9122 following table:
9123
9124 @table @code
9125 @item -source @var{filename}
9126 The value specifies the source file name. To differentiate between
9127 files with the same base name, prepend as many directories as is necessary
9128 to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
9129 @value{GDBN} will use the first file it finds with the given base
9130 name. This option requires the use of either @code{-function} or @code{-line}.
9131
9132 @item -function @var{function}
9133 The value specifies the name of a function. Operations
9134 on function locations unmodified by other options (such as @code{-label}
9135 or @code{-line}) refer to the line that begins the body of the function.
9136 In C, for example, this is the line with the open brace.
9137
9138 By default, in C@t{++} and Ada, @var{function} is interpreted as
9139 specifying all functions named @var{function} in all scopes. For
9140 C@t{++}, this means in all namespaces and classes. For Ada, this
9141 means in all packages.
9142
9143 For example, assuming a program with C@t{++} symbols named
9144 @code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
9145 -function func}} and @w{@kbd{break -function B::func}} set a
9146 breakpoint on both symbols.
9147
9148 You can use the @kbd{-qualified} flag to override this (see below).
9149
9150 @item -qualified
9151
9152 This flag makes @value{GDBN} interpret a function name specified with
9153 @kbd{-function} as a complete fully-qualified name.
9154
9155 For example, assuming a C@t{++} program with symbols named
9156 @code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
9157 -function B::func}} command sets a breakpoint on @code{B::func}, only.
9158
9159 (Note: the @kbd{-qualified} option can precede a linespec as well
9160 (@pxref{Linespec Locations}), so the particular example above could be
9161 simplified as @w{@kbd{break -qualified B::func}}.)
9162
9163 @item -label @var{label}
9164 The value specifies the name of a label. When the function
9165 name is not specified, the label is searched in the function of the currently
9166 selected stack frame.
9167
9168 @item -line @var{number}
9169 The value specifies a line offset for the location. The offset may either
9170 be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
9171 the command. When specified without any other options, the line offset is
9172 relative to the current line.
9173 @end table
9174
9175 Explicit location options may be abbreviated by omitting any non-unique
9176 trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
9177
9178 @node Address Locations
9179 @subsection Address Locations
9180 @cindex address locations
9181
9182 @dfn{Address locations} indicate a specific program address. They have
9183 the generalized form *@var{address}.
9184
9185 For line-oriented commands, such as @code{list} and @code{edit}, this
9186 specifies a source line that contains @var{address}. For @code{break} and
9187 other breakpoint-oriented commands, this can be used to set breakpoints in
9188 parts of your program which do not have debugging information or
9189 source files.
9190
9191 Here @var{address} may be any expression valid in the current working
9192 language (@pxref{Languages, working language}) that specifies a code
9193 address. In addition, as a convenience, @value{GDBN} extends the
9194 semantics of expressions used in locations to cover several situations
9195 that frequently occur during debugging. Here are the various forms
9196 of @var{address}:
9197
9198 @table @code
9199 @item @var{expression}
9200 Any expression valid in the current working language.
9201
9202 @item @var{funcaddr}
9203 An address of a function or procedure derived from its name. In C,
9204 C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
9205 simply the function's name @var{function} (and actually a special case
9206 of a valid expression). In Pascal and Modula-2, this is
9207 @code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
9208 (although the Pascal form also works).
9209
9210 This form specifies the address of the function's first instruction,
9211 before the stack frame and arguments have been set up.
9212
9213 @item '@var{filename}':@var{funcaddr}
9214 Like @var{funcaddr} above, but also specifies the name of the source
9215 file explicitly. This is useful if the name of the function does not
9216 specify the function unambiguously, e.g., if there are several
9217 functions with identical names in different source files.
9218 @end table
9219
9220 @node Edit
9221 @section Editing Source Files
9222 @cindex editing source files
9223
9224 @kindex edit
9225 @kindex e @r{(@code{edit})}
9226 To edit the lines in a source file, use the @code{edit} command.
9227 The editing program of your choice
9228 is invoked with the current line set to
9229 the active line in the program.
9230 Alternatively, there are several ways to specify what part of the file you
9231 want to print if you want to see other parts of the program:
9232
9233 @table @code
9234 @item edit @var{location}
9235 Edit the source file specified by @code{location}. Editing starts at
9236 that @var{location}, e.g., at the specified source line of the
9237 specified file. @xref{Specify Location}, for all the possible forms
9238 of the @var{location} argument; here are the forms of the @code{edit}
9239 command most commonly used:
9240
9241 @table @code
9242 @item edit @var{number}
9243 Edit the current source file with @var{number} as the active line number.
9244
9245 @item edit @var{function}
9246 Edit the file containing @var{function} at the beginning of its definition.
9247 @end table
9248
9249 @end table
9250
9251 @subsection Choosing your Editor
9252 You can customize @value{GDBN} to use any editor you want
9253 @footnote{
9254 The only restriction is that your editor (say @code{ex}), recognizes the
9255 following command-line syntax:
9256 @smallexample
9257 ex +@var{number} file
9258 @end smallexample
9259 The optional numeric value +@var{number} specifies the number of the line in
9260 the file where to start editing.}.
9261 By default, it is @file{@value{EDITOR}}, but you can change this
9262 by setting the environment variable @code{EDITOR} before using
9263 @value{GDBN}. For example, to configure @value{GDBN} to use the
9264 @code{vi} editor, you could use these commands with the @code{sh} shell:
9265 @smallexample
9266 EDITOR=/usr/bin/vi
9267 export EDITOR
9268 gdb @dots{}
9269 @end smallexample
9270 or in the @code{csh} shell,
9271 @smallexample
9272 setenv EDITOR /usr/bin/vi
9273 gdb @dots{}
9274 @end smallexample
9275
9276 @node Search
9277 @section Searching Source Files
9278 @cindex searching source files
9279
9280 There are two commands for searching through the current source file for a
9281 regular expression.
9282
9283 @table @code
9284 @kindex search
9285 @kindex forward-search
9286 @kindex fo @r{(@code{forward-search})}
9287 @item forward-search @var{regexp}
9288 @itemx search @var{regexp}
9289 The command @samp{forward-search @var{regexp}} checks each line,
9290 starting with the one following the last line listed, for a match for
9291 @var{regexp}. It lists the line that is found. You can use the
9292 synonym @samp{search @var{regexp}} or abbreviate the command name as
9293 @code{fo}.
9294
9295 @kindex reverse-search
9296 @item reverse-search @var{regexp}
9297 The command @samp{reverse-search @var{regexp}} checks each line, starting
9298 with the one before the last line listed and going backward, for a match
9299 for @var{regexp}. It lists the line that is found. You can abbreviate
9300 this command as @code{rev}.
9301 @end table
9302
9303 @node Source Path
9304 @section Specifying Source Directories
9305
9306 @cindex source path
9307 @cindex directories for source files
9308 Executable programs sometimes do not record the directories of the source
9309 files from which they were compiled, just the names. Even when they do,
9310 the directories could be moved between the compilation and your debugging
9311 session. @value{GDBN} has a list of directories to search for source files;
9312 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9313 it tries all the directories in the list, in the order they are present
9314 in the list, until it finds a file with the desired name.
9315
9316 For example, suppose an executable references the file
9317 @file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9318 directory, and the @dfn{source path} is @file{/mnt/cross}.
9319 @value{GDBN} would look for the source file in the following
9320 locations:
9321
9322 @enumerate
9323
9324 @item @file{/usr/src/foo-1.0/lib/foo.c}
9325 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9326 @item @file{/mnt/cross/foo.c}
9327
9328 @end enumerate
9329
9330 If the source file is not present at any of the above locations then
9331 an error is printed. @value{GDBN} does not look up the parts of the
9332 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9333 Likewise, the subdirectories of the source path are not searched: if
9334 the source path is @file{/mnt/cross}, and the binary refers to
9335 @file{foo.c}, @value{GDBN} would not find it under
9336 @file{/mnt/cross/usr/src/foo-1.0/lib}.
9337
9338 Plain file names, relative file names with leading directories, file
9339 names containing dots, etc.@: are all treated as described above,
9340 except that non-absolute file names are not looked up literally. If
9341 the @dfn{source path} is @file{/mnt/cross}, the source file is
9342 recorded as @file{../lib/foo.c}, and no compilation directory is
9343 recorded, then @value{GDBN} will search in the following locations:
9344
9345 @enumerate
9346
9347 @item @file{/mnt/cross/../lib/foo.c}
9348 @item @file{/mnt/cross/foo.c}
9349
9350 @end enumerate
9351
9352 @kindex cdir
9353 @kindex cwd
9354 @vindex $cdir@r{, convenience variable}
9355 @vindex $cwd@r{, convenience variable}
9356 @cindex compilation directory
9357 @cindex current directory
9358 @cindex working directory
9359 @cindex directory, current
9360 @cindex directory, compilation
9361 The @dfn{source path} will always include two special entries
9362 @samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9363 (if one is recorded) and the current working directory respectively.
9364
9365 @samp{$cdir} causes @value{GDBN} to search within the compilation
9366 directory, if one is recorded in the debug information. If no
9367 compilation directory is recorded in the debug information then
9368 @samp{$cdir} is ignored.
9369
9370 @samp{$cwd} is not the same as @samp{.}---the former tracks the
9371 current working directory as it changes during your @value{GDBN}
9372 session, while the latter is immediately expanded to the current
9373 directory at the time you add an entry to the source path.
9374
9375 If a compilation directory is recorded in the debug information, and
9376 @value{GDBN} has not found the source file after the first search
9377 using @dfn{source path}, then @value{GDBN} will combine the
9378 compilation directory and the filename, and then search for the source
9379 file again using the @dfn{source path}.
9380
9381 For example, if the executable records the source file as
9382 @file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9383 recorded as @file{/project/build}, and the @dfn{source path} is
9384 @file{/mnt/cross:$cdir:$cwd} while the current working directory of
9385 the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
9386 search for the source file in the following locations:
9387
9388 @enumerate
9389
9390 @item @file{/usr/src/foo-1.0/lib/foo.c}
9391 @item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9392 @item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9393 @item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9394 @item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9395 @item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9396 @item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9397 @item @file{/mnt/cross/foo.c}
9398 @item @file{/project/build/foo.c}
9399 @item @file{/home/user/foo.c}
9400
9401 @end enumerate
9402
9403 If the file name in the previous example had been recorded in the
9404 executable as a relative path rather than an absolute path, then the
9405 first look up would not have occurred, but all of the remaining steps
9406 would be similar.
9407
9408 When searching for source files on MS-DOS and MS-Windows, where
9409 absolute paths start with a drive letter (e.g.
9410 @file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9411 from the file name before appending it to a search directory from
9412 @dfn{source path}; for instance if the executable references the
9413 source file @file{C:/project/foo.c} and @dfn{source path} is set to
9414 @file{D:/mnt/cross}, then @value{GDBN} will search in the following
9415 locations for the source file:
9416
9417 @enumerate
9418
9419 @item @file{C:/project/foo.c}
9420 @item @file{D:/mnt/cross/project/foo.c}
9421 @item @file{D:/mnt/cross/foo.c}
9422
9423 @end enumerate
9424
9425 Note that the executable search path is @emph{not} used to locate the
9426 source files.
9427
9428 Whenever you reset or rearrange the source path, @value{GDBN} clears out
9429 any information it has cached about where source files are found and where
9430 each line is in the file.
9431
9432 @kindex directory
9433 @kindex dir
9434 When you start @value{GDBN}, its source path includes only @samp{$cdir}
9435 and @samp{$cwd}, in that order.
9436 To add other directories, use the @code{directory} command.
9437
9438 The search path is used to find both program source files and @value{GDBN}
9439 script files (read using the @samp{-command} option and @samp{source} command).
9440
9441 In addition to the source path, @value{GDBN} provides a set of commands
9442 that manage a list of source path substitution rules. A @dfn{substitution
9443 rule} specifies how to rewrite source directories stored in the program's
9444 debug information in case the sources were moved to a different
9445 directory between compilation and debugging. A rule is made of
9446 two strings, the first specifying what needs to be rewritten in
9447 the path, and the second specifying how it should be rewritten.
9448 In @ref{set substitute-path}, we name these two parts @var{from} and
9449 @var{to} respectively. @value{GDBN} does a simple string replacement
9450 of @var{from} with @var{to} at the start of the directory part of the
9451 source file name, and uses that result instead of the original file
9452 name to look up the sources.
9453
9454 Using the previous example, suppose the @file{foo-1.0} tree has been
9455 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
9456 @value{GDBN} to replace @file{/usr/src} in all source path names with
9457 @file{/mnt/cross}. The first lookup will then be
9458 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9459 of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9460 substitution rule, use the @code{set substitute-path} command
9461 (@pxref{set substitute-path}).
9462
9463 To avoid unexpected substitution results, a rule is applied only if the
9464 @var{from} part of the directory name ends at a directory separator.
9465 For instance, a rule substituting @file{/usr/source} into
9466 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9467 not to @file{/usr/sourceware/foo-2.0}. And because the substitution
9468 is applied only at the beginning of the directory name, this rule will
9469 not be applied to @file{/root/usr/source/baz.c} either.
9470
9471 In many cases, you can achieve the same result using the @code{directory}
9472 command. However, @code{set substitute-path} can be more efficient in
9473 the case where the sources are organized in a complex tree with multiple
9474 subdirectories. With the @code{directory} command, you need to add each
9475 subdirectory of your project. If you moved the entire tree while
9476 preserving its internal organization, then @code{set substitute-path}
9477 allows you to direct the debugger to all the sources with one single
9478 command.
9479
9480 @code{set substitute-path} is also more than just a shortcut command.
9481 The source path is only used if the file at the original location no
9482 longer exists. On the other hand, @code{set substitute-path} modifies
9483 the debugger behavior to look at the rewritten location instead. So, if
9484 for any reason a source file that is not relevant to your executable is
9485 located at the original location, a substitution rule is the only
9486 method available to point @value{GDBN} at the new location.
9487
9488 @cindex @samp{--with-relocated-sources}
9489 @cindex default source path substitution
9490 You can configure a default source path substitution rule by
9491 configuring @value{GDBN} with the
9492 @samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9493 should be the name of a directory under @value{GDBN}'s configured
9494 prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9495 directory names in debug information under @var{dir} will be adjusted
9496 automatically if the installed @value{GDBN} is moved to a new
9497 location. This is useful if @value{GDBN}, libraries or executables
9498 with debug information and corresponding source code are being moved
9499 together.
9500
9501 @table @code
9502 @item directory @var{dirname} @dots{}
9503 @item dir @var{dirname} @dots{}
9504 Add directory @var{dirname} to the front of the source path. Several
9505 directory names may be given to this command, separated by @samp{:}
9506 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9507 part of absolute file names) or
9508 whitespace. You may specify a directory that is already in the source
9509 path; this moves it forward, so @value{GDBN} searches it sooner.
9510
9511 The special strings @samp{$cdir} (to refer to the compilation
9512 directory, if one is recorded), and @samp{$cwd} (to refer to the
9513 current working directory) can also be included in the list of
9514 directories @var{dirname}. Though these will already be in the source
9515 path they will be moved forward in the list so @value{GDBN} searches
9516 them sooner.
9517
9518 @item directory
9519 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
9520
9521 @c RET-repeat for @code{directory} is explicitly disabled, but since
9522 @c repeating it would be a no-op we do not say that. (thanks to RMS)
9523
9524 @item set directories @var{path-list}
9525 @kindex set directories
9526 Set the source path to @var{path-list}.
9527 @samp{$cdir:$cwd} are added if missing.
9528
9529 @item show directories
9530 @kindex show directories
9531 Print the source path: show which directories it contains.
9532
9533 @anchor{set substitute-path}
9534 @item set substitute-path @var{from} @var{to}
9535 @kindex set substitute-path
9536 Define a source path substitution rule, and add it at the end of the
9537 current list of existing substitution rules. If a rule with the same
9538 @var{from} was already defined, then the old rule is also deleted.
9539
9540 For example, if the file @file{/foo/bar/baz.c} was moved to
9541 @file{/mnt/cross/baz.c}, then the command
9542
9543 @smallexample
9544 (@value{GDBP}) set substitute-path /foo/bar /mnt/cross
9545 @end smallexample
9546
9547 @noindent
9548 will tell @value{GDBN} to replace @samp{/foo/bar} with
9549 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9550 @file{baz.c} even though it was moved.
9551
9552 In the case when more than one substitution rule have been defined,
9553 the rules are evaluated one by one in the order where they have been
9554 defined. The first one matching, if any, is selected to perform
9555 the substitution.
9556
9557 For instance, if we had entered the following commands:
9558
9559 @smallexample
9560 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9561 (@value{GDBP}) set substitute-path /usr/src /mnt/src
9562 @end smallexample
9563
9564 @noindent
9565 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9566 @file{/mnt/include/defs.h} by using the first rule. However, it would
9567 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9568 @file{/mnt/src/lib/foo.c}.
9569
9570
9571 @item unset substitute-path [path]
9572 @kindex unset substitute-path
9573 If a path is specified, search the current list of substitution rules
9574 for a rule that would rewrite that path. Delete that rule if found.
9575 A warning is emitted by the debugger if no rule could be found.
9576
9577 If no path is specified, then all substitution rules are deleted.
9578
9579 @item show substitute-path [path]
9580 @kindex show substitute-path
9581 If a path is specified, then print the source path substitution rule
9582 which would rewrite that path, if any.
9583
9584 If no path is specified, then print all existing source path substitution
9585 rules.
9586
9587 @end table
9588
9589 If your source path is cluttered with directories that are no longer of
9590 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9591 versions of source. You can correct the situation as follows:
9592
9593 @enumerate
9594 @item
9595 Use @code{directory} with no argument to reset the source path to its default value.
9596
9597 @item
9598 Use @code{directory} with suitable arguments to reinstall the
9599 directories you want in the source path. You can add all the
9600 directories in one command.
9601 @end enumerate
9602
9603 @node Machine Code
9604 @section Source and Machine Code
9605 @cindex source line and its code address
9606
9607 You can use the command @code{info line} to map source lines to program
9608 addresses (and vice versa), and the command @code{disassemble} to display
9609 a range of addresses as machine instructions. You can use the command
9610 @code{set disassemble-next-line} to set whether to disassemble next
9611 source line when execution stops. When run under @sc{gnu} Emacs
9612 mode, the @code{info line} command causes the arrow to point to the
9613 line specified. Also, @code{info line} prints addresses in symbolic form as
9614 well as hex.
9615
9616 @table @code
9617 @kindex info line
9618 @item info line
9619 @itemx info line @var{location}
9620 Print the starting and ending addresses of the compiled code for
9621 source line @var{location}. You can specify source lines in any of
9622 the ways documented in @ref{Specify Location}. With no @var{location}
9623 information about the current source line is printed.
9624 @end table
9625
9626 For example, we can use @code{info line} to discover the location of
9627 the object code for the first line of function
9628 @code{m4_changequote}:
9629
9630 @smallexample
9631 (@value{GDBP}) info line m4_changequote
9632 Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9633 ends at 0x6350 <m4_changequote+4>.
9634 @end smallexample
9635
9636 @noindent
9637 @cindex code address and its source line
9638 We can also inquire (using @code{*@var{addr}} as the form for
9639 @var{location}) what source line covers a particular address:
9640 @smallexample
9641 (@value{GDBP}) info line *0x63ff
9642 Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9643 ends at 0x6404 <m4_changequote+184>.
9644 @end smallexample
9645
9646 @cindex @code{$_} and @code{info line}
9647 @cindex @code{x} command, default address
9648 @kindex x@r{(examine), and} info line
9649 After @code{info line}, the default address for the @code{x} command
9650 is changed to the starting address of the line, so that @samp{x/i} is
9651 sufficient to begin examining the machine code (@pxref{Memory,
9652 ,Examining Memory}). Also, this address is saved as the value of the
9653 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
9654 Variables}).
9655
9656 @cindex info line, repeated calls
9657 After @code{info line}, using @code{info line} again without
9658 specifying a location will display information about the next source
9659 line.
9660
9661 @table @code
9662 @kindex disassemble
9663 @cindex assembly instructions
9664 @cindex instructions, assembly
9665 @cindex machine instructions
9666 @cindex listing machine instructions
9667 @item disassemble
9668 @itemx disassemble /m
9669 @itemx disassemble /s
9670 @itemx disassemble /r
9671 This specialized command dumps a range of memory as machine
9672 instructions. It can also print mixed source+disassembly by specifying
9673 the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9674 as well as in symbolic form by specifying the @code{/r} modifier.
9675 The default memory range is the function surrounding the
9676 program counter of the selected frame. A single argument to this
9677 command is a program counter value; @value{GDBN} dumps the function
9678 surrounding this value. When two arguments are given, they should
9679 be separated by a comma, possibly surrounded by whitespace. The
9680 arguments specify a range of addresses to dump, in one of two forms:
9681
9682 @table @code
9683 @item @var{start},@var{end}
9684 the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9685 @item @var{start},+@var{length}
9686 the addresses from @var{start} (inclusive) to
9687 @code{@var{start}+@var{length}} (exclusive).
9688 @end table
9689
9690 @noindent
9691 When 2 arguments are specified, the name of the function is also
9692 printed (since there could be several functions in the given range).
9693
9694 The argument(s) can be any expression yielding a numeric value, such as
9695 @samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
9696
9697 If the range of memory being disassembled contains current program counter,
9698 the instruction at that location is shown with a @code{=>} marker.
9699 @end table
9700
9701 The following example shows the disassembly of a range of addresses of
9702 HP PA-RISC 2.0 code:
9703
9704 @smallexample
9705 (@value{GDBP}) disas 0x32c4, 0x32e4
9706 Dump of assembler code from 0x32c4 to 0x32e4:
9707 0x32c4 <main+204>: addil 0,dp
9708 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9709 0x32cc <main+212>: ldil 0x3000,r31
9710 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9711 0x32d4 <main+220>: ldo 0(r31),rp
9712 0x32d8 <main+224>: addil -0x800,dp
9713 0x32dc <main+228>: ldo 0x588(r1),r26
9714 0x32e0 <main+232>: ldil 0x3000,r31
9715 End of assembler dump.
9716 @end smallexample
9717
9718 Here is an example showing mixed source+assembly for Intel x86
9719 with @code{/m} or @code{/s}, when the program is stopped just after
9720 function prologue in a non-optimized function with no inline code.
9721
9722 @smallexample
9723 (@value{GDBP}) disas /m main
9724 Dump of assembler code for function main:
9725 5 @{
9726 0x08048330 <+0>: push %ebp
9727 0x08048331 <+1>: mov %esp,%ebp
9728 0x08048333 <+3>: sub $0x8,%esp
9729 0x08048336 <+6>: and $0xfffffff0,%esp
9730 0x08048339 <+9>: sub $0x10,%esp
9731
9732 6 printf ("Hello.\n");
9733 => 0x0804833c <+12>: movl $0x8048440,(%esp)
9734 0x08048343 <+19>: call 0x8048284 <puts@@plt>
9735
9736 7 return 0;
9737 8 @}
9738 0x08048348 <+24>: mov $0x0,%eax
9739 0x0804834d <+29>: leave
9740 0x0804834e <+30>: ret
9741
9742 End of assembler dump.
9743 @end smallexample
9744
9745 The @code{/m} option is deprecated as its output is not useful when
9746 there is either inlined code or re-ordered code.
9747 The @code{/s} option is the preferred choice.
9748 Here is an example for AMD x86-64 showing the difference between
9749 @code{/m} output and @code{/s} output.
9750 This example has one inline function defined in a header file,
9751 and the code is compiled with @samp{-O2} optimization.
9752 Note how the @code{/m} output is missing the disassembly of
9753 several instructions that are present in the @code{/s} output.
9754
9755 @file{foo.h}:
9756
9757 @smallexample
9758 int
9759 foo (int a)
9760 @{
9761 if (a < 0)
9762 return a * 2;
9763 if (a == 0)
9764 return 1;
9765 return a + 10;
9766 @}
9767 @end smallexample
9768
9769 @file{foo.c}:
9770
9771 @smallexample
9772 #include "foo.h"
9773 volatile int x, y;
9774 int
9775 main ()
9776 @{
9777 x = foo (y);
9778 return 0;
9779 @}
9780 @end smallexample
9781
9782 @smallexample
9783 (@value{GDBP}) disas /m main
9784 Dump of assembler code for function main:
9785 5 @{
9786
9787 6 x = foo (y);
9788 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <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 0x0000000000400420 <+32>: add %eax,%eax
9796 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9797
9798 End of assembler dump.
9799 (@value{GDBP}) disas /s main
9800 Dump of assembler code for function main:
9801 foo.c:
9802 5 @{
9803 6 x = foo (y);
9804 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9805
9806 foo.h:
9807 4 if (a < 0)
9808 0x0000000000400406 <+6>: test %eax,%eax
9809 0x0000000000400408 <+8>: js 0x400420 <main+32>
9810
9811 6 if (a == 0)
9812 7 return 1;
9813 8 return a + 10;
9814 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9815 0x000000000040040d <+13>: test %eax,%eax
9816 0x000000000040040f <+15>: mov $0x1,%eax
9817 0x0000000000400414 <+20>: cmovne %edx,%eax
9818
9819 foo.c:
9820 6 x = foo (y);
9821 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9822
9823 7 return 0;
9824 8 @}
9825 0x000000000040041d <+29>: xor %eax,%eax
9826 0x000000000040041f <+31>: retq
9827
9828 foo.h:
9829 5 return a * 2;
9830 0x0000000000400420 <+32>: add %eax,%eax
9831 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9832 End of assembler dump.
9833 @end smallexample
9834
9835 Here is another example showing raw instructions in hex for AMD x86-64,
9836
9837 @smallexample
9838 (gdb) disas /r 0x400281,+10
9839 Dump of assembler code from 0x400281 to 0x40028b:
9840 0x0000000000400281: 38 36 cmp %dh,(%rsi)
9841 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
9842 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
9843 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
9844 End of assembler dump.
9845 @end smallexample
9846
9847 Addresses cannot be specified as a location (@pxref{Specify Location}).
9848 So, for example, if you want to disassemble function @code{bar}
9849 in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9850 and not @samp{disassemble foo.c:bar}.
9851
9852 Some architectures have more than one commonly-used set of instruction
9853 mnemonics or other syntax.
9854
9855 For programs that were dynamically linked and use shared libraries,
9856 instructions that call functions or branch to locations in the shared
9857 libraries might show a seemingly bogus location---it's actually a
9858 location of the relocation table. On some architectures, @value{GDBN}
9859 might be able to resolve these to actual function names.
9860
9861 @table @code
9862 @kindex set disassembler-options
9863 @cindex disassembler options
9864 @item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9865 This command controls the passing of target specific information to
9866 the disassembler. For a list of valid options, please refer to the
9867 @code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9868 manual and/or the output of @kbd{objdump --help}
9869 (@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
9870 The default value is the empty string.
9871
9872 If it is necessary to specify more than one disassembler option, then
9873 multiple options can be placed together into a comma separated list.
9874 Currently this command is only supported on targets ARM, MIPS, PowerPC
9875 and S/390.
9876
9877 @kindex show disassembler-options
9878 @item show disassembler-options
9879 Show the current setting of the disassembler options.
9880 @end table
9881
9882 @table @code
9883 @kindex set disassembly-flavor
9884 @cindex Intel disassembly flavor
9885 @cindex AT&T disassembly flavor
9886 @item set disassembly-flavor @var{instruction-set}
9887 Select the instruction set to use when disassembling the
9888 program via the @code{disassemble} or @code{x/i} commands.
9889
9890 Currently this command is only defined for the Intel x86 family. You
9891 can set @var{instruction-set} to either @code{intel} or @code{att}.
9892 The default is @code{att}, the AT&T flavor used by default by Unix
9893 assemblers for x86-based targets.
9894
9895 @kindex show disassembly-flavor
9896 @item show disassembly-flavor
9897 Show the current setting of the disassembly flavor.
9898 @end table
9899
9900 @table @code
9901 @kindex set disassemble-next-line
9902 @kindex show disassemble-next-line
9903 @item set disassemble-next-line
9904 @itemx show disassemble-next-line
9905 Control whether or not @value{GDBN} will disassemble the next source
9906 line or instruction when execution stops. If ON, @value{GDBN} will
9907 display disassembly of the next source line when execution of the
9908 program being debugged stops. This is @emph{in addition} to
9909 displaying the source line itself, which @value{GDBN} always does if
9910 possible. If the next source line cannot be displayed for some reason
9911 (e.g., if @value{GDBN} cannot find the source file, or there's no line
9912 info in the debug info), @value{GDBN} will display disassembly of the
9913 next @emph{instruction} instead of showing the next source line. If
9914 AUTO, @value{GDBN} will display disassembly of next instruction only
9915 if the source line cannot be displayed. This setting causes
9916 @value{GDBN} to display some feedback when you step through a function
9917 with no line info or whose source file is unavailable. The default is
9918 OFF, which means never display the disassembly of the next line or
9919 instruction.
9920 @end table
9921
9922
9923 @node Data
9924 @chapter Examining Data
9925
9926 @cindex printing data
9927 @cindex examining data
9928 @kindex print
9929 @kindex inspect
9930 The usual way to examine data in your program is with the @code{print}
9931 command (abbreviated @code{p}), or its synonym @code{inspect}. It
9932 evaluates and prints the value of an expression of the language your
9933 program is written in (@pxref{Languages, ,Using @value{GDBN} with
9934 Different Languages}). It may also print the expression using a
9935 Python-based pretty-printer (@pxref{Pretty Printing}).
9936
9937 @table @code
9938 @item print [[@var{options}] --] @var{expr}
9939 @itemx print [[@var{options}] --] /@var{f} @var{expr}
9940 @var{expr} is an expression (in the source language). By default the
9941 value of @var{expr} is printed in a format appropriate to its data type;
9942 you can choose a different format by specifying @samp{/@var{f}}, where
9943 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
9944 Formats}.
9945
9946 @anchor{print options}
9947 The @code{print} command supports a number of options that allow
9948 overriding relevant global print settings as set by @code{set print}
9949 subcommands:
9950
9951 @table @code
9952 @item -address [@code{on}|@code{off}]
9953 Set printing of addresses.
9954 Related setting: @ref{set print address}.
9955
9956 @item -array [@code{on}|@code{off}]
9957 Pretty formatting of arrays.
9958 Related setting: @ref{set print array}.
9959
9960 @item -array-indexes [@code{on}|@code{off}]
9961 Set printing of array indexes.
9962 Related setting: @ref{set print array-indexes}.
9963
9964 @item -elements @var{number-of-elements}|@code{unlimited}
9965 Set limit on string chars or array elements to print. The value
9966 @code{unlimited} causes there to be no limit. Related setting:
9967 @ref{set print elements}.
9968
9969 @item -max-depth @var{depth}|@code{unlimited}
9970 Set the threshold after which nested structures are replaced with
9971 ellipsis. Related setting: @ref{set print max-depth}.
9972
9973 @item -null-stop [@code{on}|@code{off}]
9974 Set printing of char arrays to stop at first null char. Related
9975 setting: @ref{set print null-stop}.
9976
9977 @item -object [@code{on}|@code{off}]
9978 Set printing C@t{++} virtual function tables. Related setting:
9979 @ref{set print object}.
9980
9981 @item -pretty [@code{on}|@code{off}]
9982 Set pretty formatting of structures. Related setting: @ref{set print
9983 pretty}.
9984
9985 @item -raw-values [@code{on}|@code{off}]
9986 Set whether to print values in raw form, bypassing any
9987 pretty-printers for that value. Related setting: @ref{set print
9988 raw-values}.
9989
9990 @item -repeats @var{number-of-repeats}|@code{unlimited}
9991 Set threshold for repeated print elements. @code{unlimited} causes
9992 all elements to be individually printed. Related setting: @ref{set
9993 print repeats}.
9994
9995 @item -static-members [@code{on}|@code{off}]
9996 Set printing C@t{++} static members. Related setting: @ref{set print
9997 static-members}.
9998
9999 @item -symbol [@code{on}|@code{off}]
10000 Set printing of symbol names when printing pointers. Related setting:
10001 @ref{set print symbol}.
10002
10003 @item -union [@code{on}|@code{off}]
10004 Set printing of unions interior to structures. Related setting:
10005 @ref{set print union}.
10006
10007 @item -vtbl [@code{on}|@code{off}]
10008 Set printing of C++ virtual function tables. Related setting:
10009 @ref{set print vtbl}.
10010 @end table
10011
10012 Because the @code{print} command accepts arbitrary expressions which
10013 may look like options (including abbreviations), if you specify any
10014 command option, then you must use a double dash (@code{--}) to mark
10015 the end of option processing.
10016
10017 For example, this prints the value of the @code{-p} expression:
10018
10019 @smallexample
10020 (@value{GDBP}) print -p
10021 @end smallexample
10022
10023 While this repeats the last value in the value history (see below)
10024 with the @code{-pretty} option in effect:
10025
10026 @smallexample
10027 (@value{GDBP}) print -p --
10028 @end smallexample
10029
10030 Here is an example including both on option and an expression:
10031
10032 @smallexample
10033 @group
10034 (@value{GDBP}) print -pretty -- *myptr
10035 $1 = @{
10036 next = 0x0,
10037 flags = @{
10038 sweet = 1,
10039 sour = 1
10040 @},
10041 meat = 0x54 "Pork"
10042 @}
10043 @end group
10044 @end smallexample
10045
10046 @item print [@var{options}]
10047 @itemx print [@var{options}] /@var{f}
10048 @cindex reprint the last value
10049 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
10050 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
10051 conveniently inspect the same value in an alternative format.
10052 @end table
10053
10054 If the architecture supports memory tagging, the @code{print} command will
10055 display pointer/memory tag mismatches if what is being printed is a pointer
10056 or reference type. @xref{Memory Tagging}.
10057
10058 A more low-level way of examining data is with the @code{x} command.
10059 It examines data in memory at a specified address and prints it in a
10060 specified format. @xref{Memory, ,Examining Memory}.
10061
10062 If you are interested in information about types, or about how the
10063 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
10064 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
10065 Table}.
10066
10067 @cindex exploring hierarchical data structures
10068 @kindex explore
10069 Another way of examining values of expressions and type information is
10070 through the Python extension command @code{explore} (available only if
10071 the @value{GDBN} build is configured with @code{--with-python}). It
10072 offers an interactive way to start at the highest level (or, the most
10073 abstract level) of the data type of an expression (or, the data type
10074 itself) and explore all the way down to leaf scalar values/fields
10075 embedded in the higher level data types.
10076
10077 @table @code
10078 @item explore @var{arg}
10079 @var{arg} is either an expression (in the source language), or a type
10080 visible in the current context of the program being debugged.
10081 @end table
10082
10083 The working of the @code{explore} command can be illustrated with an
10084 example. If a data type @code{struct ComplexStruct} is defined in your
10085 C program as
10086
10087 @smallexample
10088 struct SimpleStruct
10089 @{
10090 int i;
10091 double d;
10092 @};
10093
10094 struct ComplexStruct
10095 @{
10096 struct SimpleStruct *ss_p;
10097 int arr[10];
10098 @};
10099 @end smallexample
10100
10101 @noindent
10102 followed by variable declarations as
10103
10104 @smallexample
10105 struct SimpleStruct ss = @{ 10, 1.11 @};
10106 struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
10107 @end smallexample
10108
10109 @noindent
10110 then, the value of the variable @code{cs} can be explored using the
10111 @code{explore} command as follows.
10112
10113 @smallexample
10114 (gdb) explore cs
10115 The value of `cs' is a struct/class of type `struct ComplexStruct' with
10116 the following fields:
10117
10118 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
10119 arr = <Enter 1 to explore this field of type `int [10]'>
10120
10121 Enter the field number of choice:
10122 @end smallexample
10123
10124 @noindent
10125 Since the fields of @code{cs} are not scalar values, you are being
10126 prompted to chose the field you want to explore. Let's say you choose
10127 the field @code{ss_p} by entering @code{0}. Then, since this field is a
10128 pointer, you will be asked if it is pointing to a single value. From
10129 the declaration of @code{cs} above, it is indeed pointing to a single
10130 value, hence you enter @code{y}. If you enter @code{n}, then you will
10131 be asked if it were pointing to an array of values, in which case this
10132 field will be explored as if it were an array.
10133
10134 @smallexample
10135 `cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
10136 Continue exploring it as a pointer to a single value [y/n]: y
10137 The value of `*(cs.ss_p)' is a struct/class of type `struct
10138 SimpleStruct' with the following fields:
10139
10140 i = 10 .. (Value of type `int')
10141 d = 1.1100000000000001 .. (Value of type `double')
10142
10143 Press enter to return to parent value:
10144 @end smallexample
10145
10146 @noindent
10147 If the field @code{arr} of @code{cs} was chosen for exploration by
10148 entering @code{1} earlier, then since it is as array, you will be
10149 prompted to enter the index of the element in the array that you want
10150 to explore.
10151
10152 @smallexample
10153 `cs.arr' is an array of `int'.
10154 Enter the index of the element you want to explore in `cs.arr': 5
10155
10156 `(cs.arr)[5]' is a scalar value of type `int'.
10157
10158 (cs.arr)[5] = 4
10159
10160 Press enter to return to parent value:
10161 @end smallexample
10162
10163 In general, at any stage of exploration, you can go deeper towards the
10164 leaf values by responding to the prompts appropriately, or hit the
10165 return key to return to the enclosing data structure (the @i{higher}
10166 level data structure).
10167
10168 Similar to exploring values, you can use the @code{explore} command to
10169 explore types. Instead of specifying a value (which is typically a
10170 variable name or an expression valid in the current context of the
10171 program being debugged), you specify a type name. If you consider the
10172 same example as above, your can explore the type
10173 @code{struct ComplexStruct} by passing the argument
10174 @code{struct ComplexStruct} to the @code{explore} command.
10175
10176 @smallexample
10177 (gdb) explore struct ComplexStruct
10178 @end smallexample
10179
10180 @noindent
10181 By responding to the prompts appropriately in the subsequent interactive
10182 session, you can explore the type @code{struct ComplexStruct} in a
10183 manner similar to how the value @code{cs} was explored in the above
10184 example.
10185
10186 The @code{explore} command also has two sub-commands,
10187 @code{explore value} and @code{explore type}. The former sub-command is
10188 a way to explicitly specify that value exploration of the argument is
10189 being invoked, while the latter is a way to explicitly specify that type
10190 exploration of the argument is being invoked.
10191
10192 @table @code
10193 @item explore value @var{expr}
10194 @cindex explore value
10195 This sub-command of @code{explore} explores the value of the
10196 expression @var{expr} (if @var{expr} is an expression valid in the
10197 current context of the program being debugged). The behavior of this
10198 command is identical to that of the behavior of the @code{explore}
10199 command being passed the argument @var{expr}.
10200
10201 @item explore type @var{arg}
10202 @cindex explore type
10203 This sub-command of @code{explore} explores the type of @var{arg} (if
10204 @var{arg} is a type visible in the current context of program being
10205 debugged), or the type of the value/expression @var{arg} (if @var{arg}
10206 is an expression valid in the current context of the program being
10207 debugged). If @var{arg} is a type, then the behavior of this command is
10208 identical to that of the @code{explore} command being passed the
10209 argument @var{arg}. If @var{arg} is an expression, then the behavior of
10210 this command will be identical to that of the @code{explore} command
10211 being passed the type of @var{arg} as the argument.
10212 @end table
10213
10214 @menu
10215 * Expressions:: Expressions
10216 * Ambiguous Expressions:: Ambiguous Expressions
10217 * Variables:: Program variables
10218 * Arrays:: Artificial arrays
10219 * Output Formats:: Output formats
10220 * Memory:: Examining memory
10221 * Memory Tagging:: Memory Tagging
10222 * Auto Display:: Automatic display
10223 * Print Settings:: Print settings
10224 * Pretty Printing:: Python pretty printing
10225 * Value History:: Value history
10226 * Convenience Vars:: Convenience variables
10227 * Convenience Funs:: Convenience functions
10228 * Registers:: Registers
10229 * Floating Point Hardware:: Floating point hardware
10230 * Vector Unit:: Vector Unit
10231 * OS Information:: Auxiliary data provided by operating system
10232 * Memory Region Attributes:: Memory region attributes
10233 * Dump/Restore Files:: Copy between memory and a file
10234 * Core File Generation:: Cause a program dump its core
10235 * Character Sets:: Debugging programs that use a different
10236 character set than GDB does
10237 * Caching Target Data:: Data caching for targets
10238 * Searching Memory:: Searching memory for a sequence of bytes
10239 * Value Sizes:: Managing memory allocated for values
10240 @end menu
10241
10242 @node Expressions
10243 @section Expressions
10244
10245 @cindex expressions
10246 @code{print} and many other @value{GDBN} commands accept an expression and
10247 compute its value. Any kind of constant, variable or operator defined
10248 by the programming language you are using is valid in an expression in
10249 @value{GDBN}. This includes conditional expressions, function calls,
10250 casts, and string constants. It also includes preprocessor macros, if
10251 you compiled your program to include this information; see
10252 @ref{Compilation}.
10253
10254 @cindex arrays in expressions
10255 @value{GDBN} supports array constants in expressions input by
10256 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
10257 you can use the command @code{print @{1, 2, 3@}} to create an array
10258 of three integers. If you pass an array to a function or assign it
10259 to a program variable, @value{GDBN} copies the array to memory that
10260 is @code{malloc}ed in the target program.
10261
10262 Because C is so widespread, most of the expressions shown in examples in
10263 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
10264 Languages}, for information on how to use expressions in other
10265 languages.
10266
10267 In this section, we discuss operators that you can use in @value{GDBN}
10268 expressions regardless of your programming language.
10269
10270 @cindex casts, in expressions
10271 Casts are supported in all languages, not just in C, because it is so
10272 useful to cast a number into a pointer in order to examine a structure
10273 at that address in memory.
10274 @c FIXME: casts supported---Mod2 true?
10275
10276 @value{GDBN} supports these operators, in addition to those common
10277 to programming languages:
10278
10279 @table @code
10280 @item @@
10281 @samp{@@} is a binary operator for treating parts of memory as arrays.
10282 @xref{Arrays, ,Artificial Arrays}, for more information.
10283
10284 @item ::
10285 @samp{::} allows you to specify a variable in terms of the file or
10286 function where it is defined. @xref{Variables, ,Program Variables}.
10287
10288 @cindex @{@var{type}@}
10289 @cindex type casting memory
10290 @cindex memory, viewing as typed object
10291 @cindex casts, to view memory
10292 @item @{@var{type}@} @var{addr}
10293 Refers to an object of type @var{type} stored at address @var{addr} in
10294 memory. The address @var{addr} may be any expression whose value is
10295 an integer or pointer (but parentheses are required around binary
10296 operators, just as in a cast). This construct is allowed regardless
10297 of what kind of data is normally supposed to reside at @var{addr}.
10298 @end table
10299
10300 @node Ambiguous Expressions
10301 @section Ambiguous Expressions
10302 @cindex ambiguous expressions
10303
10304 Expressions can sometimes contain some ambiguous elements. For instance,
10305 some programming languages (notably Ada, C@t{++} and Objective-C) permit
10306 a single function name to be defined several times, for application in
10307 different contexts. This is called @dfn{overloading}. Another example
10308 involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10309 templates and is typically instantiated several times, resulting in
10310 the same function name being defined in different contexts.
10311
10312 In some cases and depending on the language, it is possible to adjust
10313 the expression to remove the ambiguity. For instance in C@t{++}, you
10314 can specify the signature of the function you want to break on, as in
10315 @kbd{break @var{function}(@var{types})}. In Ada, using the fully
10316 qualified name of your function often makes the expression unambiguous
10317 as well.
10318
10319 When an ambiguity that needs to be resolved is detected, the debugger
10320 has the capability to display a menu of numbered choices for each
10321 possibility, and then waits for the selection with the prompt @samp{>}.
10322 The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10323 aborts the current command. If the command in which the expression was
10324 used allows more than one choice to be selected, the next option in the
10325 menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10326 choices.
10327
10328 For example, the following session excerpt shows an attempt to set a
10329 breakpoint at the overloaded symbol @code{String::after}.
10330 We choose three particular definitions of that function name:
10331
10332 @c FIXME! This is likely to change to show arg type lists, at least
10333 @smallexample
10334 @group
10335 (@value{GDBP}) b String::after
10336 [0] cancel
10337 [1] all
10338 [2] file:String.cc; line number:867
10339 [3] file:String.cc; line number:860
10340 [4] file:String.cc; line number:875
10341 [5] file:String.cc; line number:853
10342 [6] file:String.cc; line number:846
10343 [7] file:String.cc; line number:735
10344 > 2 4 6
10345 Breakpoint 1 at 0xb26c: file String.cc, line 867.
10346 Breakpoint 2 at 0xb344: file String.cc, line 875.
10347 Breakpoint 3 at 0xafcc: file String.cc, line 846.
10348 Multiple breakpoints were set.
10349 Use the "delete" command to delete unwanted
10350 breakpoints.
10351 (@value{GDBP})
10352 @end group
10353 @end smallexample
10354
10355 @table @code
10356 @kindex set multiple-symbols
10357 @item set multiple-symbols @var{mode}
10358 @cindex multiple-symbols menu
10359
10360 This option allows you to adjust the debugger behavior when an expression
10361 is ambiguous.
10362
10363 By default, @var{mode} is set to @code{all}. If the command with which
10364 the expression is used allows more than one choice, then @value{GDBN}
10365 automatically selects all possible choices. For instance, inserting
10366 a breakpoint on a function using an ambiguous name results in a breakpoint
10367 inserted on each possible match. However, if a unique choice must be made,
10368 then @value{GDBN} uses the menu to help you disambiguate the expression.
10369 For instance, printing the address of an overloaded function will result
10370 in the use of the menu.
10371
10372 When @var{mode} is set to @code{ask}, the debugger always uses the menu
10373 when an ambiguity is detected.
10374
10375 Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10376 an error due to the ambiguity and the command is aborted.
10377
10378 @kindex show multiple-symbols
10379 @item show multiple-symbols
10380 Show the current value of the @code{multiple-symbols} setting.
10381 @end table
10382
10383 @node Variables
10384 @section Program Variables
10385
10386 The most common kind of expression to use is the name of a variable
10387 in your program.
10388
10389 Variables in expressions are understood in the selected stack frame
10390 (@pxref{Selection, ,Selecting a Frame}); they must be either:
10391
10392 @itemize @bullet
10393 @item
10394 global (or file-static)
10395 @end itemize
10396
10397 @noindent or
10398
10399 @itemize @bullet
10400 @item
10401 visible according to the scope rules of the
10402 programming language from the point of execution in that frame
10403 @end itemize
10404
10405 @noindent This means that in the function
10406
10407 @smallexample
10408 foo (a)
10409 int a;
10410 @{
10411 bar (a);
10412 @{
10413 int b = test ();
10414 bar (b);
10415 @}
10416 @}
10417 @end smallexample
10418
10419 @noindent
10420 you can examine and use the variable @code{a} whenever your program is
10421 executing within the function @code{foo}, but you can only use or
10422 examine the variable @code{b} while your program is executing inside
10423 the block where @code{b} is declared.
10424
10425 @cindex variable name conflict
10426 There is an exception: you can refer to a variable or function whose
10427 scope is a single source file even if the current execution point is not
10428 in this file. But it is possible to have more than one such variable or
10429 function with the same name (in different source files). If that
10430 happens, referring to that name has unpredictable effects. If you wish,
10431 you can specify a static variable in a particular function or file by
10432 using the colon-colon (@code{::}) notation:
10433
10434 @cindex colon-colon, context for variables/functions
10435 @ifnotinfo
10436 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
10437 @cindex @code{::}, context for variables/functions
10438 @end ifnotinfo
10439 @smallexample
10440 @var{file}::@var{variable}
10441 @var{function}::@var{variable}
10442 @end smallexample
10443
10444 @noindent
10445 Here @var{file} or @var{function} is the name of the context for the
10446 static @var{variable}. In the case of file names, you can use quotes to
10447 make sure @value{GDBN} parses the file name as a single word---for example,
10448 to print a global value of @code{x} defined in @file{f2.c}:
10449
10450 @smallexample
10451 (@value{GDBP}) p 'f2.c'::x
10452 @end smallexample
10453
10454 The @code{::} notation is normally used for referring to
10455 static variables, since you typically disambiguate uses of local variables
10456 in functions by selecting the appropriate frame and using the
10457 simple name of the variable. However, you may also use this notation
10458 to refer to local variables in frames enclosing the selected frame:
10459
10460 @smallexample
10461 void
10462 foo (int a)
10463 @{
10464 if (a < 10)
10465 bar (a);
10466 else
10467 process (a); /* Stop here */
10468 @}
10469
10470 int
10471 bar (int a)
10472 @{
10473 foo (a + 5);
10474 @}
10475 @end smallexample
10476
10477 @noindent
10478 For example, if there is a breakpoint at the commented line,
10479 here is what you might see
10480 when the program stops after executing the call @code{bar(0)}:
10481
10482 @smallexample
10483 (@value{GDBP}) p a
10484 $1 = 10
10485 (@value{GDBP}) p bar::a
10486 $2 = 5
10487 (@value{GDBP}) up 2
10488 #2 0x080483d0 in foo (a=5) at foobar.c:12
10489 (@value{GDBP}) p a
10490 $3 = 5
10491 (@value{GDBP}) p bar::a
10492 $4 = 0
10493 @end smallexample
10494
10495 @cindex C@t{++} scope resolution
10496 These uses of @samp{::} are very rarely in conflict with the very
10497 similar use of the same notation in C@t{++}. When they are in
10498 conflict, the C@t{++} meaning takes precedence; however, this can be
10499 overridden by quoting the file or function name with single quotes.
10500
10501 For example, suppose the program is stopped in a method of a class
10502 that has a field named @code{includefile}, and there is also an
10503 include file named @file{includefile} that defines a variable,
10504 @code{some_global}.
10505
10506 @smallexample
10507 (@value{GDBP}) p includefile
10508 $1 = 23
10509 (@value{GDBP}) p includefile::some_global
10510 A syntax error in expression, near `'.
10511 (@value{GDBP}) p 'includefile'::some_global
10512 $2 = 27
10513 @end smallexample
10514
10515 @cindex wrong values
10516 @cindex variable values, wrong
10517 @cindex function entry/exit, wrong values of variables
10518 @cindex optimized code, wrong values of variables
10519 @quotation
10520 @emph{Warning:} Occasionally, a local variable may appear to have the
10521 wrong value at certain points in a function---just after entry to a new
10522 scope, and just before exit.
10523 @end quotation
10524 You may see this problem when you are stepping by machine instructions.
10525 This is because, on most machines, it takes more than one instruction to
10526 set up a stack frame (including local variable definitions); if you are
10527 stepping by machine instructions, variables may appear to have the wrong
10528 values until the stack frame is completely built. On exit, it usually
10529 also takes more than one machine instruction to destroy a stack frame;
10530 after you begin stepping through that group of instructions, local
10531 variable definitions may be gone.
10532
10533 This may also happen when the compiler does significant optimizations.
10534 To be sure of always seeing accurate values, turn off all optimization
10535 when compiling.
10536
10537 @cindex ``No symbol "foo" in current context''
10538 Another possible effect of compiler optimizations is to optimize
10539 unused variables out of existence, or assign variables to registers (as
10540 opposed to memory addresses). Depending on the support for such cases
10541 offered by the debug info format used by the compiler, @value{GDBN}
10542 might not be able to display values for such local variables. If that
10543 happens, @value{GDBN} will print a message like this:
10544
10545 @smallexample
10546 No symbol "foo" in current context.
10547 @end smallexample
10548
10549 To solve such problems, either recompile without optimizations, or use a
10550 different debug info format, if the compiler supports several such
10551 formats. @xref{Compilation}, for more information on choosing compiler
10552 options. @xref{C, ,C and C@t{++}}, for more information about debug
10553 info formats that are best suited to C@t{++} programs.
10554
10555 If you ask to print an object whose contents are unknown to
10556 @value{GDBN}, e.g., because its data type is not completely specified
10557 by the debug information, @value{GDBN} will say @samp{<incomplete
10558 type>}. @xref{Symbols, incomplete type}, for more about this.
10559
10560 @cindex no debug info variables
10561 If you try to examine or use the value of a (global) variable for
10562 which @value{GDBN} has no type information, e.g., because the program
10563 includes no debug information, @value{GDBN} displays an error message.
10564 @xref{Symbols, unknown type}, for more about unknown types. If you
10565 cast the variable to its declared type, @value{GDBN} gets the
10566 variable's value using the cast-to type as the variable's type. For
10567 example, in a C program:
10568
10569 @smallexample
10570 (@value{GDBP}) p var
10571 'var' has unknown type; cast it to its declared type
10572 (@value{GDBP}) p (float) var
10573 $1 = 3.14
10574 @end smallexample
10575
10576 If you append @kbd{@@entry} string to a function parameter name you get its
10577 value at the time the function got called. If the value is not available an
10578 error message is printed. Entry values are available only with some compilers.
10579 Entry values are normally also printed at the function parameter list according
10580 to @ref{set print entry-values}.
10581
10582 @smallexample
10583 Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
10584 29 i++;
10585 (gdb) next
10586 30 e (i);
10587 (gdb) print i
10588 $1 = 31
10589 (gdb) print i@@entry
10590 $2 = 30
10591 @end smallexample
10592
10593 Strings are identified as arrays of @code{char} values without specified
10594 signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10595 printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10596 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10597 defines literal string type @code{"char"} as @code{char} without a sign.
10598 For program code
10599
10600 @smallexample
10601 char var0[] = "A";
10602 signed char var1[] = "A";
10603 @end smallexample
10604
10605 You get during debugging
10606 @smallexample
10607 (gdb) print var0
10608 $1 = "A"
10609 (gdb) print var1
10610 $2 = @{65 'A', 0 '\0'@}
10611 @end smallexample
10612
10613 @node Arrays
10614 @section Artificial Arrays
10615
10616 @cindex artificial array
10617 @cindex arrays
10618 @kindex @@@r{, referencing memory as an array}
10619 It is often useful to print out several successive objects of the
10620 same type in memory; a section of an array, or an array of
10621 dynamically determined size for which only a pointer exists in the
10622 program.
10623
10624 You can do this by referring to a contiguous span of memory as an
10625 @dfn{artificial array}, using the binary operator @samp{@@}. The left
10626 operand of @samp{@@} should be the first element of the desired array
10627 and be an individual object. The right operand should be the desired length
10628 of the array. The result is an array value whose elements are all of
10629 the type of the left argument. The first element is actually the left
10630 argument; the second element comes from bytes of memory immediately
10631 following those that hold the first element, and so on. Here is an
10632 example. If a program says
10633
10634 @smallexample
10635 int *array = (int *) malloc (len * sizeof (int));
10636 @end smallexample
10637
10638 @noindent
10639 you can print the contents of @code{array} with
10640
10641 @smallexample
10642 p *array@@len
10643 @end smallexample
10644
10645 The left operand of @samp{@@} must reside in memory. Array values made
10646 with @samp{@@} in this way behave just like other arrays in terms of
10647 subscripting, and are coerced to pointers when used in expressions.
10648 Artificial arrays most often appear in expressions via the value history
10649 (@pxref{Value History, ,Value History}), after printing one out.
10650
10651 Another way to create an artificial array is to use a cast.
10652 This re-interprets a value as if it were an array.
10653 The value need not be in memory:
10654 @smallexample
10655 (@value{GDBP}) p/x (short[2])0x12345678
10656 $1 = @{0x1234, 0x5678@}
10657 @end smallexample
10658
10659 As a convenience, if you leave the array length out (as in
10660 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
10661 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
10662 @smallexample
10663 (@value{GDBP}) p/x (short[])0x12345678
10664 $2 = @{0x1234, 0x5678@}
10665 @end smallexample
10666
10667 Sometimes the artificial array mechanism is not quite enough; in
10668 moderately complex data structures, the elements of interest may not
10669 actually be adjacent---for example, if you are interested in the values
10670 of pointers in an array. One useful work-around in this situation is
10671 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
10672 Variables}) as a counter in an expression that prints the first
10673 interesting value, and then repeat that expression via @key{RET}. For
10674 instance, suppose you have an array @code{dtab} of pointers to
10675 structures, and you are interested in the values of a field @code{fv}
10676 in each structure. Here is an example of what you might type:
10677
10678 @smallexample
10679 set $i = 0
10680 p dtab[$i++]->fv
10681 @key{RET}
10682 @key{RET}
10683 @dots{}
10684 @end smallexample
10685
10686 @node Output Formats
10687 @section Output Formats
10688
10689 @cindex formatted output
10690 @cindex output formats
10691 By default, @value{GDBN} prints a value according to its data type. Sometimes
10692 this is not what you want. For example, you might want to print a number
10693 in hex, or a pointer in decimal. Or you might want to view data in memory
10694 at a certain address as a character string or as an instruction. To do
10695 these things, specify an @dfn{output format} when you print a value.
10696
10697 The simplest use of output formats is to say how to print a value
10698 already computed. This is done by starting the arguments of the
10699 @code{print} command with a slash and a format letter. The format
10700 letters supported are:
10701
10702 @table @code
10703 @item x
10704 Regard the bits of the value as an integer, and print the integer in
10705 hexadecimal.
10706
10707 @item d
10708 Print as integer in signed decimal.
10709
10710 @item u
10711 Print as integer in unsigned decimal.
10712
10713 @item o
10714 Print as integer in octal.
10715
10716 @item t
10717 Print as integer in binary. The letter @samp{t} stands for ``two''.
10718 @footnote{@samp{b} cannot be used because these format letters are also
10719 used with the @code{x} command, where @samp{b} stands for ``byte'';
10720 see @ref{Memory,,Examining Memory}.}
10721
10722 @item a
10723 @cindex unknown address, locating
10724 @cindex locate address
10725 Print as an address, both absolute in hexadecimal and as an offset from
10726 the nearest preceding symbol. You can use this format used to discover
10727 where (in what function) an unknown address is located:
10728
10729 @smallexample
10730 (@value{GDBP}) p/a 0x54320
10731 $3 = 0x54320 <_initialize_vx+396>
10732 @end smallexample
10733
10734 @noindent
10735 The command @code{info symbol 0x54320} yields similar results.
10736 @xref{Symbols, info symbol}.
10737
10738 @item c
10739 Regard as an integer and print it as a character constant. This
10740 prints both the numerical value and its character representation. The
10741 character representation is replaced with the octal escape @samp{\nnn}
10742 for characters outside the 7-bit @sc{ascii} range.
10743
10744 Without this format, @value{GDBN} displays @code{char},
10745 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10746 constants. Single-byte members of vectors are displayed as integer
10747 data.
10748
10749 @item f
10750 Regard the bits of the value as a floating point number and print
10751 using typical floating point syntax.
10752
10753 @item s
10754 @cindex printing strings
10755 @cindex printing byte arrays
10756 Regard as a string, if possible. With this format, pointers to single-byte
10757 data are displayed as null-terminated strings and arrays of single-byte data
10758 are displayed as fixed-length strings. Other values are displayed in their
10759 natural types.
10760
10761 Without this format, @value{GDBN} displays pointers to and arrays of
10762 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10763 strings. Single-byte members of a vector are displayed as an integer
10764 array.
10765
10766 @item z
10767 Like @samp{x} formatting, the value is treated as an integer and
10768 printed as hexadecimal, but leading zeros are printed to pad the value
10769 to the size of the integer type.
10770
10771 @item r
10772 @cindex raw printing
10773 Print using the @samp{raw} formatting. By default, @value{GDBN} will
10774 use a Python-based pretty-printer, if one is available (@pxref{Pretty
10775 Printing}). This typically results in a higher-level display of the
10776 value's contents. The @samp{r} format bypasses any Python
10777 pretty-printer which might exist.
10778 @end table
10779
10780 For example, to print the program counter in hex (@pxref{Registers}), type
10781
10782 @smallexample
10783 p/x $pc
10784 @end smallexample
10785
10786 @noindent
10787 Note that no space is required before the slash; this is because command
10788 names in @value{GDBN} cannot contain a slash.
10789
10790 To reprint the last value in the value history with a different format,
10791 you can use the @code{print} command with just a format and no
10792 expression. For example, @samp{p/x} reprints the last value in hex.
10793
10794 @node Memory
10795 @section Examining Memory
10796
10797 You can use the command @code{x} (for ``examine'') to examine memory in
10798 any of several formats, independently of your program's data types.
10799
10800 @cindex examining memory
10801 @table @code
10802 @kindex x @r{(examine memory)}
10803 @item x/@var{nfu} @var{addr}
10804 @itemx x @var{addr}
10805 @itemx x
10806 Use the @code{x} command to examine memory.
10807 @end table
10808
10809 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10810 much memory to display and how to format it; @var{addr} is an
10811 expression giving the address where you want to start displaying memory.
10812 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10813 Several commands set convenient defaults for @var{addr}.
10814
10815 @table @r
10816 @item @var{n}, the repeat count
10817 The repeat count is a decimal integer; the default is 1. It specifies
10818 how much memory (counting by units @var{u}) to display. If a negative
10819 number is specified, memory is examined backward from @var{addr}.
10820 @c This really is **decimal**; unaffected by 'set radix' as of GDB
10821 @c 4.1.2.
10822
10823 @item @var{f}, the display format
10824 The display format is one of the formats used by @code{print}
10825 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
10826 @samp{f}, @samp{s}), @samp{i} (for machine instructions) and
10827 @samp{m} (for displaying memory tags).
10828 The default is @samp{x} (hexadecimal) initially. The default changes
10829 each time you use either @code{x} or @code{print}.
10830
10831 @item @var{u}, the unit size
10832 The unit size is any of
10833
10834 @table @code
10835 @item b
10836 Bytes.
10837 @item h
10838 Halfwords (two bytes).
10839 @item w
10840 Words (four bytes). This is the initial default.
10841 @item g
10842 Giant words (eight bytes).
10843 @end table
10844
10845 Each time you specify a unit size with @code{x}, that size becomes the
10846 default unit the next time you use @code{x}. For the @samp{i} format,
10847 the unit size is ignored and is normally not written. For the @samp{s} format,
10848 the unit size defaults to @samp{b}, unless it is explicitly given.
10849 Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
10850 32-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
10851 Note that the results depend on the programming language of the
10852 current compilation unit. If the language is C, the @samp{s}
10853 modifier will use the UTF-16 encoding while @samp{w} will use
10854 UTF-32. The encoding is set by the programming language and cannot
10855 be altered.
10856
10857 @item @var{addr}, starting display address
10858 @var{addr} is the address where you want @value{GDBN} to begin displaying
10859 memory. The expression need not have a pointer value (though it may);
10860 it is always interpreted as an integer address of a byte of memory.
10861 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
10862 @var{addr} is usually just after the last address examined---but several
10863 other commands also set the default address: @code{info breakpoints} (to
10864 the address of the last breakpoint listed), @code{info line} (to the
10865 starting address of a line), and @code{print} (if you use it to display
10866 a value from memory).
10867 @end table
10868
10869 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10870 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10871 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
10872 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
10873 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
10874
10875 You can also specify a negative repeat count to examine memory backward
10876 from the given address. For example, @samp{x/-3uh 0x54320} prints three
10877 halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
10878
10879 Since the letters indicating unit sizes are all distinct from the
10880 letters specifying output formats, you do not have to remember whether
10881 unit size or format comes first; either order works. The output
10882 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10883 (However, the count @var{n} must come first; @samp{wx4} does not work.)
10884
10885 Even though the unit size @var{u} is ignored for the formats @samp{s}
10886 and @samp{i}, you might still want to use a count @var{n}; for example,
10887 @samp{3i} specifies that you want to see three machine instructions,
10888 including any operands. For convenience, especially when used with
10889 the @code{display} command, the @samp{i} format also prints branch delay
10890 slot instructions, if any, beyond the count specified, which immediately
10891 follow the last instruction that is within the count. The command
10892 @code{disassemble} gives an alternative way of inspecting machine
10893 instructions; see @ref{Machine Code,,Source and Machine Code}.
10894
10895 If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10896 the command displays null-terminated strings or instructions before the given
10897 address as many as the absolute value of the given number. For the @samp{i}
10898 format, we use line number information in the debug info to accurately locate
10899 instruction boundaries while disassembling backward. If line info is not
10900 available, the command stops examining memory with an error message.
10901
10902 All the defaults for the arguments to @code{x} are designed to make it
10903 easy to continue scanning memory with minimal specifications each time
10904 you use @code{x}. For example, after you have inspected three machine
10905 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10906 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
10907 the repeat count @var{n} is used again; the other arguments default as
10908 for successive uses of @code{x}.
10909
10910 When examining machine instructions, the instruction at current program
10911 counter is shown with a @code{=>} marker. For example:
10912
10913 @smallexample
10914 (@value{GDBP}) x/5i $pc-6
10915 0x804837f <main+11>: mov %esp,%ebp
10916 0x8048381 <main+13>: push %ecx
10917 0x8048382 <main+14>: sub $0x4,%esp
10918 => 0x8048385 <main+17>: movl $0x8048460,(%esp)
10919 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
10920 @end smallexample
10921
10922 If the architecture supports memory tagging, the tags can be displayed by
10923 using @samp{m}. @xref{Memory Tagging}.
10924
10925 The information will be displayed once per granule size
10926 (the amount of bytes a particular memory tag covers). For example, AArch64
10927 has a granule size of 16 bytes, so it will display a tag every 16 bytes.
10928
10929 Due to the way @value{GDBN} prints information with the @code{x} command (not
10930 aligned to a particular boundary), the tag information will refer to the
10931 initial address displayed on a particular line. If a memory tag boundary
10932 is crossed in the middle of a line displayed by the @code{x} command, it
10933 will be displayed on the next line.
10934
10935 The @samp{m} format doesn't affect any other specified formats that were
10936 passed to the @code{x} command.
10937
10938 @cindex @code{$_}, @code{$__}, and value history
10939 The addresses and contents printed by the @code{x} command are not saved
10940 in the value history because there is often too much of them and they
10941 would get in the way. Instead, @value{GDBN} makes these values available for
10942 subsequent use in expressions as values of the convenience variables
10943 @code{$_} and @code{$__}. After an @code{x} command, the last address
10944 examined is available for use in expressions in the convenience variable
10945 @code{$_}. The contents of that address, as examined, are available in
10946 the convenience variable @code{$__}.
10947
10948 If the @code{x} command has a repeat count, the address and contents saved
10949 are from the last memory unit printed; this is not the same as the last
10950 address printed if several units were printed on the last line of output.
10951
10952 @anchor{addressable memory unit}
10953 @cindex addressable memory unit
10954 Most targets have an addressable memory unit size of 8 bits. This means
10955 that to each memory address are associated 8 bits of data. Some
10956 targets, however, have other addressable memory unit sizes.
10957 Within @value{GDBN} and this document, the term
10958 @dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
10959 when explicitly referring to a chunk of data of that size. The word
10960 @dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
10961 the addressable memory unit size of the target. For most systems,
10962 addressable memory unit is a synonym of byte.
10963
10964 @cindex remote memory comparison
10965 @cindex target memory comparison
10966 @cindex verify remote memory image
10967 @cindex verify target memory image
10968 When you are debugging a program running on a remote target machine
10969 (@pxref{Remote Debugging}), you may wish to verify the program's image
10970 in the remote machine's memory against the executable file you
10971 downloaded to the target. Or, on any target, you may want to check
10972 whether the program has corrupted its own read-only sections. The
10973 @code{compare-sections} command is provided for such situations.
10974
10975 @table @code
10976 @kindex compare-sections
10977 @item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
10978 Compare the data of a loadable section @var{section-name} in the
10979 executable file of the program being debugged with the same section in
10980 the target machine's memory, and report any mismatches. With no
10981 arguments, compares all loadable sections. With an argument of
10982 @code{-r}, compares all loadable read-only sections.
10983
10984 Note: for remote targets, this command can be accelerated if the
10985 target supports computing the CRC checksum of a block of memory
10986 (@pxref{qCRC packet}).
10987 @end table
10988
10989 @node Memory Tagging
10990 @section Memory Tagging
10991
10992 Memory tagging is a memory protection technology that uses a pair of tags to
10993 validate memory accesses through pointers. The tags are integer values
10994 usually comprised of a few bits, depending on the architecture.
10995
10996 There are two types of tags that are used in this setup: logical and
10997 allocation. A logical tag is stored in the pointers themselves, usually at the
10998 higher bits of the pointers. An allocation tag is the tag associated
10999 with particular ranges of memory in the physical address space, against which
11000 the logical tags from pointers are compared.
11001
11002 The pointer tag (logical tag) must match the memory tag (allocation tag)
11003 for the memory access to be valid. If the logical tag does not match the
11004 allocation tag, that will raise a memory violation.
11005
11006 Allocation tags cover multiple contiguous bytes of physical memory. This
11007 range of bytes is called a memory tag granule and is architecture-specific.
11008 For example, AArch64 has a tag granule of 16 bytes, meaning each allocation
11009 tag spans 16 bytes of memory.
11010
11011 If the underlying architecture supports memory tagging, like AArch64 MTE
11012 or SPARC ADI do, @value{GDBN} can make use of it to validate pointers
11013 against memory allocation tags.
11014
11015 The @code{print} (@pxref{Data}) and @code{x} (@pxref{Memory}) commands will
11016 display tag information when appropriate, and a command prefix of
11017 @code{memory-tag} gives access to the various memory tagging commands.
11018
11019 The @code{memory-tag} commands are the following:
11020
11021 @table @code
11022 @kindex memory-tag print-logical-tag
11023 @item memory-tag print-logical-tag @var{pointer_expression}
11024 Print the logical tag stored in @var{pointer_expression}.
11025 @kindex memory-tag with-logical-tag
11026 @item memory-tag with-logical-tag @var{pointer_expression} @var{tag_bytes}
11027 Print the pointer given by @var{pointer_expression}, augmented with a logical
11028 tag of @var{tag_bytes}.
11029 @kindex memory-tag print-allocation-tag
11030 @item memory-tag print-allocation-tag @var{address_expression}
11031 Print the allocation tag associated with the memory address given by
11032 @var{address_expression}.
11033 @kindex memory-tag setatag
11034 @item memory-tag setatag @var{starting_address} @var{length} @var{tag_bytes}
11035 Set the allocation tag(s) for memory range @r{[}@var{starting_address},
11036 @var{starting_address} + @var{length}@r{)} to @var{tag_bytes}.
11037 @kindex memory-tag check
11038 @item memory-tag check @var{pointer_expression}
11039 Check if the logical tag in the pointer given by @var{pointer_expression}
11040 matches the allocation tag for the memory referenced by the pointer.
11041
11042 This essentially emulates the hardware validation that is done when tagged
11043 memory is accessed through a pointer, but does not cause a memory fault as
11044 it would during hardware validation.
11045
11046 It can be used to inspect potential memory tagging violations in the running
11047 process, before any faults get triggered.
11048 @end table
11049
11050 @node Auto Display
11051 @section Automatic Display
11052 @cindex automatic display
11053 @cindex display of expressions
11054
11055 If you find that you want to print the value of an expression frequently
11056 (to see how it changes), you might want to add it to the @dfn{automatic
11057 display list} so that @value{GDBN} prints its value each time your program stops.
11058 Each expression added to the list is given a number to identify it;
11059 to remove an expression from the list, you specify that number.
11060 The automatic display looks like this:
11061
11062 @smallexample
11063 2: foo = 38
11064 3: bar[5] = (struct hack *) 0x3804
11065 @end smallexample
11066
11067 @noindent
11068 This display shows item numbers, expressions and their current values. As with
11069 displays you request manually using @code{x} or @code{print}, you can
11070 specify the output format you prefer; in fact, @code{display} decides
11071 whether to use @code{print} or @code{x} depending your format
11072 specification---it uses @code{x} if you specify either the @samp{i}
11073 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
11074
11075 @table @code
11076 @kindex display
11077 @item display @var{expr}
11078 Add the expression @var{expr} to the list of expressions to display
11079 each time your program stops. @xref{Expressions, ,Expressions}.
11080
11081 @code{display} does not repeat if you press @key{RET} again after using it.
11082
11083 @item display/@var{fmt} @var{expr}
11084 For @var{fmt} specifying only a display format and not a size or
11085 count, add the expression @var{expr} to the auto-display list but
11086 arrange to display it each time in the specified format @var{fmt}.
11087 @xref{Output Formats,,Output Formats}.
11088
11089 @item display/@var{fmt} @var{addr}
11090 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
11091 number of units, add the expression @var{addr} as a memory address to
11092 be examined each time your program stops. Examining means in effect
11093 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
11094 @end table
11095
11096 For example, @samp{display/i $pc} can be helpful, to see the machine
11097 instruction about to be executed each time execution stops (@samp{$pc}
11098 is a common name for the program counter; @pxref{Registers, ,Registers}).
11099
11100 @table @code
11101 @kindex delete display
11102 @kindex undisplay
11103 @item undisplay @var{dnums}@dots{}
11104 @itemx delete display @var{dnums}@dots{}
11105 Remove items from the list of expressions to display. Specify the
11106 numbers of the displays that you want affected with the command
11107 argument @var{dnums}. It can be a single display number, one of the
11108 numbers shown in the first field of the @samp{info display} display;
11109 or it could be a range of display numbers, as in @code{2-4}.
11110
11111 @code{undisplay} does not repeat if you press @key{RET} after using it.
11112 (Otherwise you would just get the error @samp{No display number @dots{}}.)
11113
11114 @kindex disable display
11115 @item disable display @var{dnums}@dots{}
11116 Disable the display of item numbers @var{dnums}. A disabled display
11117 item is not printed automatically, but is not forgotten. It may be
11118 enabled again later. Specify the numbers of the displays that you
11119 want affected with the command argument @var{dnums}. It can be a
11120 single display number, one of the numbers shown in the first field of
11121 the @samp{info display} display; or it could be a range of display
11122 numbers, as in @code{2-4}.
11123
11124 @kindex enable display
11125 @item enable display @var{dnums}@dots{}
11126 Enable display of item numbers @var{dnums}. It becomes effective once
11127 again in auto display of its expression, until you specify otherwise.
11128 Specify the numbers of the displays that you want affected with the
11129 command argument @var{dnums}. It can be a single display number, one
11130 of the numbers shown in the first field of the @samp{info display}
11131 display; or it could be a range of display numbers, as in @code{2-4}.
11132
11133 @item display
11134 Display the current values of the expressions on the list, just as is
11135 done when your program stops.
11136
11137 @kindex info display
11138 @item info display
11139 Print the list of expressions previously set up to display
11140 automatically, each one with its item number, but without showing the
11141 values. This includes disabled expressions, which are marked as such.
11142 It also includes expressions which would not be displayed right now
11143 because they refer to automatic variables not currently available.
11144 @end table
11145
11146 @cindex display disabled out of scope
11147 If a display expression refers to local variables, then it does not make
11148 sense outside the lexical context for which it was set up. Such an
11149 expression is disabled when execution enters a context where one of its
11150 variables is not defined. For example, if you give the command
11151 @code{display last_char} while inside a function with an argument
11152 @code{last_char}, @value{GDBN} displays this argument while your program
11153 continues to stop inside that function. When it stops elsewhere---where
11154 there is no variable @code{last_char}---the display is disabled
11155 automatically. The next time your program stops where @code{last_char}
11156 is meaningful, you can enable the display expression once again.
11157
11158 @node Print Settings
11159 @section Print Settings
11160
11161 @cindex format options
11162 @cindex print settings
11163 @value{GDBN} provides the following ways to control how arrays, structures,
11164 and symbols are printed.
11165
11166 @noindent
11167 These settings are useful for debugging programs in any language:
11168
11169 @table @code
11170 @kindex set print
11171 @anchor{set print address}
11172 @item set print address
11173 @itemx set print address on
11174 @cindex print/don't print memory addresses
11175 @value{GDBN} prints memory addresses showing the location of stack
11176 traces, structure values, pointer values, breakpoints, and so forth,
11177 even when it also displays the contents of those addresses. The default
11178 is @code{on}. For example, this is what a stack frame display looks like with
11179 @code{set print address on}:
11180
11181 @smallexample
11182 @group
11183 (@value{GDBP}) f
11184 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
11185 at input.c:530
11186 530 if (lquote != def_lquote)
11187 @end group
11188 @end smallexample
11189
11190 @item set print address off
11191 Do not print addresses when displaying their contents. For example,
11192 this is the same stack frame displayed with @code{set print address off}:
11193
11194 @smallexample
11195 @group
11196 (@value{GDBP}) set print addr off
11197 (@value{GDBP}) f
11198 #0 set_quotes (lq="<<", rq=">>") at input.c:530
11199 530 if (lquote != def_lquote)
11200 @end group
11201 @end smallexample
11202
11203 You can use @samp{set print address off} to eliminate all machine
11204 dependent displays from the @value{GDBN} interface. For example, with
11205 @code{print address off}, you should get the same text for backtraces on
11206 all machines---whether or not they involve pointer arguments.
11207
11208 @kindex show print
11209 @item show print address
11210 Show whether or not addresses are to be printed.
11211 @end table
11212
11213 When @value{GDBN} prints a symbolic address, it normally prints the
11214 closest earlier symbol plus an offset. If that symbol does not uniquely
11215 identify the address (for example, it is a name whose scope is a single
11216 source file), you may need to clarify. One way to do this is with
11217 @code{info line}, for example @samp{info line *0x4537}. Alternately,
11218 you can set @value{GDBN} to print the source file and line number when
11219 it prints a symbolic address:
11220
11221 @table @code
11222 @item set print symbol-filename on
11223 @cindex source file and line of a symbol
11224 @cindex symbol, source file and line
11225 Tell @value{GDBN} to print the source file name and line number of a
11226 symbol in the symbolic form of an address.
11227
11228 @item set print symbol-filename off
11229 Do not print source file name and line number of a symbol. This is the
11230 default.
11231
11232 @item show print symbol-filename
11233 Show whether or not @value{GDBN} will print the source file name and
11234 line number of a symbol in the symbolic form of an address.
11235 @end table
11236
11237 Another situation where it is helpful to show symbol filenames and line
11238 numbers is when disassembling code; @value{GDBN} shows you the line
11239 number and source file that corresponds to each instruction.
11240
11241 Also, you may wish to see the symbolic form only if the address being
11242 printed is reasonably close to the closest earlier symbol:
11243
11244 @table @code
11245 @item set print max-symbolic-offset @var{max-offset}
11246 @itemx set print max-symbolic-offset unlimited
11247 @cindex maximum value for offset of closest symbol
11248 Tell @value{GDBN} to only display the symbolic form of an address if the
11249 offset between the closest earlier symbol and the address is less than
11250 @var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
11251 to always print the symbolic form of an address if any symbol precedes
11252 it. Zero is equivalent to @code{unlimited}.
11253
11254 @item show print max-symbolic-offset
11255 Ask how large the maximum offset is that @value{GDBN} prints in a
11256 symbolic address.
11257 @end table
11258
11259 @cindex wild pointer, interpreting
11260 @cindex pointer, finding referent
11261 If you have a pointer and you are not sure where it points, try
11262 @samp{set print symbol-filename on}. Then you can determine the name
11263 and source file location of the variable where it points, using
11264 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
11265 For example, here @value{GDBN} shows that a variable @code{ptt} points
11266 at another variable @code{t}, defined in @file{hi2.c}:
11267
11268 @smallexample
11269 (@value{GDBP}) set print symbol-filename on
11270 (@value{GDBP}) p/a ptt
11271 $4 = 0xe008 <t in hi2.c>
11272 @end smallexample
11273
11274 @quotation
11275 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
11276 does not show the symbol name and filename of the referent, even with
11277 the appropriate @code{set print} options turned on.
11278 @end quotation
11279
11280 You can also enable @samp{/a}-like formatting all the time using
11281 @samp{set print symbol on}:
11282
11283 @anchor{set print symbol}
11284 @table @code
11285 @item set print symbol on
11286 Tell @value{GDBN} to print the symbol corresponding to an address, if
11287 one exists.
11288
11289 @item set print symbol off
11290 Tell @value{GDBN} not to print the symbol corresponding to an
11291 address. In this mode, @value{GDBN} will still print the symbol
11292 corresponding to pointers to functions. This is the default.
11293
11294 @item show print symbol
11295 Show whether @value{GDBN} will display the symbol corresponding to an
11296 address.
11297 @end table
11298
11299 Other settings control how different kinds of objects are printed:
11300
11301 @table @code
11302 @anchor{set print array}
11303 @item set print array
11304 @itemx set print array on
11305 @cindex pretty print arrays
11306 Pretty print arrays. This format is more convenient to read,
11307 but uses more space. The default is off.
11308
11309 @item set print array off
11310 Return to compressed format for arrays.
11311
11312 @item show print array
11313 Show whether compressed or pretty format is selected for displaying
11314 arrays.
11315
11316 @cindex print array indexes
11317 @anchor{set print array-indexes}
11318 @item set print array-indexes
11319 @itemx set print array-indexes on
11320 Print the index of each element when displaying arrays. May be more
11321 convenient to locate a given element in the array or quickly find the
11322 index of a given element in that printed array. The default is off.
11323
11324 @item set print array-indexes off
11325 Stop printing element indexes when displaying arrays.
11326
11327 @item show print array-indexes
11328 Show whether the index of each element is printed when displaying
11329 arrays.
11330
11331 @anchor{set print elements}
11332 @item set print elements @var{number-of-elements}
11333 @itemx set print elements unlimited
11334 @cindex number of array elements to print
11335 @cindex limit on number of printed array elements
11336 Set a limit on how many elements of an array @value{GDBN} will print.
11337 If @value{GDBN} is printing a large array, it stops printing after it has
11338 printed the number of elements set by the @code{set print elements} command.
11339 This limit also applies to the display of strings.
11340 When @value{GDBN} starts, this limit is set to 200.
11341 Setting @var{number-of-elements} to @code{unlimited} or zero means
11342 that the number of elements to print is unlimited.
11343
11344 @item show print elements
11345 Display the number of elements of a large array that @value{GDBN} will print.
11346 If the number is 0, then the printing is unlimited.
11347
11348 @anchor{set print frame-arguments}
11349 @item set print frame-arguments @var{value}
11350 @kindex set print frame-arguments
11351 @cindex printing frame argument values
11352 @cindex print all frame argument values
11353 @cindex print frame argument values for scalars only
11354 @cindex do not print frame arguments
11355 This command allows to control how the values of arguments are printed
11356 when the debugger prints a frame (@pxref{Frames}). The possible
11357 values are:
11358
11359 @table @code
11360 @item all
11361 The values of all arguments are printed.
11362
11363 @item scalars
11364 Print the value of an argument only if it is a scalar. The value of more
11365 complex arguments such as arrays, structures, unions, etc, is replaced
11366 by @code{@dots{}}. This is the default. Here is an example where
11367 only scalar arguments are shown:
11368
11369 @smallexample
11370 #1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11371 at frame-args.c:23
11372 @end smallexample
11373
11374 @item none
11375 None of the argument values are printed. Instead, the value of each argument
11376 is replaced by @code{@dots{}}. In this case, the example above now becomes:
11377
11378 @smallexample
11379 #1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11380 at frame-args.c:23
11381 @end smallexample
11382
11383 @item presence
11384 Only the presence of arguments is indicated by @code{@dots{}}.
11385 The @code{@dots{}} are not printed for function without any arguments.
11386 None of the argument names and values are printed.
11387 In this case, the example above now becomes:
11388
11389 @smallexample
11390 #1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11391 @end smallexample
11392
11393 @end table
11394
11395 By default, only scalar arguments are printed. This command can be used
11396 to configure the debugger to print the value of all arguments, regardless
11397 of their type. However, it is often advantageous to not print the value
11398 of more complex parameters. For instance, it reduces the amount of
11399 information printed in each frame, making the backtrace more readable.
11400 Also, it improves performance when displaying Ada frames, because
11401 the computation of large arguments can sometimes be CPU-intensive,
11402 especially in large applications. Setting @code{print frame-arguments}
11403 to @code{scalars} (the default), @code{none} or @code{presence} avoids
11404 this computation, thus speeding up the display of each Ada frame.
11405
11406 @item show print frame-arguments
11407 Show how the value of arguments should be displayed when printing a frame.
11408
11409 @anchor{set print raw-frame-arguments}
11410 @item set print raw-frame-arguments on
11411 Print frame arguments in raw, non pretty-printed, form.
11412
11413 @item set print raw-frame-arguments off
11414 Print frame arguments in pretty-printed form, if there is a pretty-printer
11415 for the value (@pxref{Pretty Printing}),
11416 otherwise print the value in raw form.
11417 This is the default.
11418
11419 @item show print raw-frame-arguments
11420 Show whether to print frame arguments in raw form.
11421
11422 @anchor{set print entry-values}
11423 @item set print entry-values @var{value}
11424 @kindex set print entry-values
11425 Set printing of frame argument values at function entry. In some cases
11426 @value{GDBN} can determine the value of function argument which was passed by
11427 the function caller, even if the value was modified inside the called function
11428 and therefore is different. With optimized code, the current value could be
11429 unavailable, but the entry value may still be known.
11430
11431 The default value is @code{default} (see below for its description). Older
11432 @value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11433 this feature will behave in the @code{default} setting the same way as with the
11434 @code{no} setting.
11435
11436 This functionality is currently supported only by DWARF 2 debugging format and
11437 the compiler has to produce @samp{DW_TAG_call_site} tags. With
11438 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11439 this information.
11440
11441 The @var{value} parameter can be one of the following:
11442
11443 @table @code
11444 @item no
11445 Print only actual parameter values, never print values from function entry
11446 point.
11447 @smallexample
11448 #0 equal (val=5)
11449 #0 different (val=6)
11450 #0 lost (val=<optimized out>)
11451 #0 born (val=10)
11452 #0 invalid (val=<optimized out>)
11453 @end smallexample
11454
11455 @item only
11456 Print only parameter values from function entry point. The actual parameter
11457 values are never printed.
11458 @smallexample
11459 #0 equal (val@@entry=5)
11460 #0 different (val@@entry=5)
11461 #0 lost (val@@entry=5)
11462 #0 born (val@@entry=<optimized out>)
11463 #0 invalid (val@@entry=<optimized out>)
11464 @end smallexample
11465
11466 @item preferred
11467 Print only parameter values from function entry point. If value from function
11468 entry point is not known while the actual value is known, print the actual
11469 value for such parameter.
11470 @smallexample
11471 #0 equal (val@@entry=5)
11472 #0 different (val@@entry=5)
11473 #0 lost (val@@entry=5)
11474 #0 born (val=10)
11475 #0 invalid (val@@entry=<optimized out>)
11476 @end smallexample
11477
11478 @item if-needed
11479 Print actual parameter values. If actual parameter value is not known while
11480 value from function entry point is known, print the entry point value for such
11481 parameter.
11482 @smallexample
11483 #0 equal (val=5)
11484 #0 different (val=6)
11485 #0 lost (val@@entry=5)
11486 #0 born (val=10)
11487 #0 invalid (val=<optimized out>)
11488 @end smallexample
11489
11490 @item both
11491 Always print both the actual parameter value and its value from function entry
11492 point, even if values of one or both are not available due to compiler
11493 optimizations.
11494 @smallexample
11495 #0 equal (val=5, val@@entry=5)
11496 #0 different (val=6, val@@entry=5)
11497 #0 lost (val=<optimized out>, val@@entry=5)
11498 #0 born (val=10, val@@entry=<optimized out>)
11499 #0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11500 @end smallexample
11501
11502 @item compact
11503 Print the actual parameter value if it is known and also its value from
11504 function entry point if it is known. If neither is known, print for the actual
11505 value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11506 values are known and identical, print the shortened
11507 @code{param=param@@entry=VALUE} notation.
11508 @smallexample
11509 #0 equal (val=val@@entry=5)
11510 #0 different (val=6, val@@entry=5)
11511 #0 lost (val@@entry=5)
11512 #0 born (val=10)
11513 #0 invalid (val=<optimized out>)
11514 @end smallexample
11515
11516 @item default
11517 Always print the actual parameter value. Print also its value from function
11518 entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11519 if both values are known and identical, print the shortened
11520 @code{param=param@@entry=VALUE} notation.
11521 @smallexample
11522 #0 equal (val=val@@entry=5)
11523 #0 different (val=6, val@@entry=5)
11524 #0 lost (val=<optimized out>, val@@entry=5)
11525 #0 born (val=10)
11526 #0 invalid (val=<optimized out>)
11527 @end smallexample
11528 @end table
11529
11530 For analysis messages on possible failures of frame argument values at function
11531 entry resolution see @ref{set debug entry-values}.
11532
11533 @item show print entry-values
11534 Show the method being used for printing of frame argument values at function
11535 entry.
11536
11537 @anchor{set print frame-info}
11538 @item set print frame-info @var{value}
11539 @kindex set print frame-info
11540 @cindex printing frame information
11541 @cindex frame information, printing
11542 This command allows to control the information printed when
11543 the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11544 for a general explanation about frames and frame information.
11545 Note that some other settings (such as @code{set print frame-arguments}
11546 and @code{set print address}) are also influencing if and how some frame
11547 information is displayed. In particular, the frame program counter is never
11548 printed if @code{set print address} is off.
11549
11550 The possible values for @code{set print frame-info} are:
11551 @table @code
11552 @item short-location
11553 Print the frame level, the program counter (if not at the
11554 beginning of the location source line), the function, the function
11555 arguments.
11556 @item location
11557 Same as @code{short-location} but also print the source file and source line
11558 number.
11559 @item location-and-address
11560 Same as @code{location} but print the program counter even if located at the
11561 beginning of the location source line.
11562 @item source-line
11563 Print the program counter (if not at the beginning of the location
11564 source line), the line number and the source line.
11565 @item source-and-location
11566 Print what @code{location} and @code{source-line} are printing.
11567 @item auto
11568 The information printed for a frame is decided automatically
11569 by the @value{GDBN} command that prints a frame.
11570 For example, @code{frame} prints the information printed by
11571 @code{source-and-location} while @code{stepi} will switch between
11572 @code{source-line} and @code{source-and-location} depending on the program
11573 counter.
11574 The default value is @code{auto}.
11575 @end table
11576
11577 @anchor{set print repeats}
11578 @item set print repeats @var{number-of-repeats}
11579 @itemx set print repeats unlimited
11580 @cindex repeated array elements
11581 Set the threshold for suppressing display of repeated array
11582 elements. When the number of consecutive identical elements of an
11583 array exceeds the threshold, @value{GDBN} prints the string
11584 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
11585 identical repetitions, instead of displaying the identical elements
11586 themselves. Setting the threshold to @code{unlimited} or zero will
11587 cause all elements to be individually printed. The default threshold
11588 is 10.
11589
11590 @item show print repeats
11591 Display the current threshold for printing repeated identical
11592 elements.
11593
11594 @anchor{set print max-depth}
11595 @item set print max-depth @var{depth}
11596 @item set print max-depth unlimited
11597 @cindex printing nested structures
11598 Set the threshold after which nested structures are replaced with
11599 ellipsis, this can make visualising deeply nested structures easier.
11600
11601 For example, given this C code
11602
11603 @smallexample
11604 typedef struct s1 @{ int a; @} s1;
11605 typedef struct s2 @{ s1 b; @} s2;
11606 typedef struct s3 @{ s2 c; @} s3;
11607 typedef struct s4 @{ s3 d; @} s4;
11608
11609 s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11610 @end smallexample
11611
11612 The following table shows how different values of @var{depth} will
11613 effect how @code{var} is printed by @value{GDBN}:
11614
11615 @multitable @columnfractions .3 .7
11616 @headitem @var{depth} setting @tab Result of @samp{p var}
11617 @item unlimited
11618 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11619 @item @code{0}
11620 @tab @code{$1 = @{...@}}
11621 @item @code{1}
11622 @tab @code{$1 = @{d = @{...@}@}}
11623 @item @code{2}
11624 @tab @code{$1 = @{d = @{c = @{...@}@}@}}
11625 @item @code{3}
11626 @tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11627 @item @code{4}
11628 @tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11629 @end multitable
11630
11631 To see the contents of structures that have been hidden the user can
11632 either increase the print max-depth, or they can print the elements of
11633 the structure that are visible, for example
11634
11635 @smallexample
11636 (gdb) set print max-depth 2
11637 (gdb) p var
11638 $1 = @{d = @{c = @{...@}@}@}
11639 (gdb) p var.d
11640 $2 = @{c = @{b = @{...@}@}@}
11641 (gdb) p var.d.c
11642 $3 = @{b = @{a = 3@}@}
11643 @end smallexample
11644
11645 The pattern used to replace nested structures varies based on
11646 language, for most languages @code{@{...@}} is used, but Fortran uses
11647 @code{(...)}.
11648
11649 @item show print max-depth
11650 Display the current threshold after which nested structures are
11651 replaces with ellipsis.
11652
11653 @anchor{set print memory-tag-violations}
11654 @cindex printing memory tag violation information
11655 @item set print memory-tag-violations
11656 @itemx set print memory-tag-violations on
11657 Cause @value{GDBN} to display additional information about memory tag violations
11658 when printing pointers and addresses.
11659
11660 @item set print memory-tag-violations off
11661 Stop printing memory tag violation information.
11662
11663 @item show print memory-tag-violations
11664 Show whether memory tag violation information is displayed when printing
11665 pointers and addresses.
11666
11667 @anchor{set print null-stop}
11668 @item set print null-stop
11669 @cindex @sc{null} elements in arrays
11670 Cause @value{GDBN} to stop printing the characters of an array when the first
11671 @sc{null} is encountered. This is useful when large arrays actually
11672 contain only short strings.
11673 The default is off.
11674
11675 @item show print null-stop
11676 Show whether @value{GDBN} stops printing an array on the first
11677 @sc{null} character.
11678
11679 @anchor{set print pretty}
11680 @item set print pretty on
11681 @cindex print structures in indented form
11682 @cindex indentation in structure display
11683 Cause @value{GDBN} to print structures in an indented format with one member
11684 per line, like this:
11685
11686 @smallexample
11687 @group
11688 $1 = @{
11689 next = 0x0,
11690 flags = @{
11691 sweet = 1,
11692 sour = 1
11693 @},
11694 meat = 0x54 "Pork"
11695 @}
11696 @end group
11697 @end smallexample
11698
11699 @item set print pretty off
11700 Cause @value{GDBN} to print structures in a compact format, like this:
11701
11702 @smallexample
11703 @group
11704 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11705 meat = 0x54 "Pork"@}
11706 @end group
11707 @end smallexample
11708
11709 @noindent
11710 This is the default format.
11711
11712 @item show print pretty
11713 Show which format @value{GDBN} is using to print structures.
11714
11715 @anchor{set print raw-values}
11716 @item set print raw-values on
11717 Print values in raw form, without applying the pretty
11718 printers for the value.
11719
11720 @item set print raw-values off
11721 Print values in pretty-printed form, if there is a pretty-printer
11722 for the value (@pxref{Pretty Printing}),
11723 otherwise print the value in raw form.
11724
11725 The default setting is ``off''.
11726
11727 @item show print raw-values
11728 Show whether to print values in raw form.
11729
11730 @item set print sevenbit-strings on
11731 @cindex eight-bit characters in strings
11732 @cindex octal escapes in strings
11733 Print using only seven-bit characters; if this option is set,
11734 @value{GDBN} displays any eight-bit characters (in strings or
11735 character values) using the notation @code{\}@var{nnn}. This setting is
11736 best if you are working in English (@sc{ascii}) and you use the
11737 high-order bit of characters as a marker or ``meta'' bit.
11738
11739 @item set print sevenbit-strings off
11740 Print full eight-bit characters. This allows the use of more
11741 international character sets, and is the default.
11742
11743 @item show print sevenbit-strings
11744 Show whether or not @value{GDBN} is printing only seven-bit characters.
11745
11746 @anchor{set print union}
11747 @item set print union on
11748 @cindex unions in structures, printing
11749 Tell @value{GDBN} to print unions which are contained in structures
11750 and other unions. This is the default setting.
11751
11752 @item set print union off
11753 Tell @value{GDBN} not to print unions which are contained in
11754 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
11755 instead.
11756
11757 @item show print union
11758 Ask @value{GDBN} whether or not it will print unions which are contained in
11759 structures and other unions.
11760
11761 For example, given the declarations
11762
11763 @smallexample
11764 typedef enum @{Tree, Bug@} Species;
11765 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
11766 typedef enum @{Caterpillar, Cocoon, Butterfly@}
11767 Bug_forms;
11768
11769 struct thing @{
11770 Species it;
11771 union @{
11772 Tree_forms tree;
11773 Bug_forms bug;
11774 @} form;
11775 @};
11776
11777 struct thing foo = @{Tree, @{Acorn@}@};
11778 @end smallexample
11779
11780 @noindent
11781 with @code{set print union on} in effect @samp{p foo} would print
11782
11783 @smallexample
11784 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
11785 @end smallexample
11786
11787 @noindent
11788 and with @code{set print union off} in effect it would print
11789
11790 @smallexample
11791 $1 = @{it = Tree, form = @{...@}@}
11792 @end smallexample
11793
11794 @noindent
11795 @code{set print union} affects programs written in C-like languages
11796 and in Pascal.
11797 @end table
11798
11799 @need 1000
11800 @noindent
11801 These settings are of interest when debugging C@t{++} programs:
11802
11803 @table @code
11804 @cindex demangling C@t{++} names
11805 @item set print demangle
11806 @itemx set print demangle on
11807 Print C@t{++} names in their source form rather than in the encoded
11808 (``mangled'') form passed to the assembler and linker for type-safe
11809 linkage. The default is on.
11810
11811 @item show print demangle
11812 Show whether C@t{++} names are printed in mangled or demangled form.
11813
11814 @item set print asm-demangle
11815 @itemx set print asm-demangle on
11816 Print C@t{++} names in their source form rather than their mangled form, even
11817 in assembler code printouts such as instruction disassemblies.
11818 The default is off.
11819
11820 @item show print asm-demangle
11821 Show whether C@t{++} names in assembly listings are printed in mangled
11822 or demangled form.
11823
11824 @cindex C@t{++} symbol decoding style
11825 @cindex symbol decoding style, C@t{++}
11826 @kindex set demangle-style
11827 @item set demangle-style @var{style}
11828 Choose among several encoding schemes used by different compilers to represent
11829 C@t{++} names. If you omit @var{style}, you will see a list of possible
11830 formats. The default value is @var{auto}, which lets @value{GDBN} choose a
11831 decoding style by inspecting your program.
11832
11833 @item show demangle-style
11834 Display the encoding style currently in use for decoding C@t{++} symbols.
11835
11836 @anchor{set print object}
11837 @item set print object
11838 @itemx set print object on
11839 @cindex derived type of an object, printing
11840 @cindex display derived types
11841 When displaying a pointer to an object, identify the @emph{actual}
11842 (derived) type of the object rather than the @emph{declared} type, using
11843 the virtual function table. Note that the virtual function table is
11844 required---this feature can only work for objects that have run-time
11845 type identification; a single virtual method in the object's declared
11846 type is sufficient. Note that this setting is also taken into account when
11847 working with variable objects via MI (@pxref{GDB/MI}).
11848
11849 @item set print object off
11850 Display only the declared type of objects, without reference to the
11851 virtual function table. This is the default setting.
11852
11853 @item show print object
11854 Show whether actual, or declared, object types are displayed.
11855
11856 @anchor{set print static-members}
11857 @item set print static-members
11858 @itemx set print static-members on
11859 @cindex static members of C@t{++} objects
11860 Print static members when displaying a C@t{++} object. The default is on.
11861
11862 @item set print static-members off
11863 Do not print static members when displaying a C@t{++} object.
11864
11865 @item show print static-members
11866 Show whether C@t{++} static members are printed or not.
11867
11868 @item set print pascal_static-members
11869 @itemx set print pascal_static-members on
11870 @cindex static members of Pascal objects
11871 @cindex Pascal objects, static members display
11872 Print static members when displaying a Pascal object. The default is on.
11873
11874 @item set print pascal_static-members off
11875 Do not print static members when displaying a Pascal object.
11876
11877 @item show print pascal_static-members
11878 Show whether Pascal static members are printed or not.
11879
11880 @c These don't work with HP ANSI C++ yet.
11881 @anchor{set print vtbl}
11882 @item set print vtbl
11883 @itemx set print vtbl on
11884 @cindex pretty print C@t{++} virtual function tables
11885 @cindex virtual functions (C@t{++}) display
11886 @cindex VTBL display
11887 Pretty print C@t{++} virtual function tables. The default is off.
11888 (The @code{vtbl} commands do not work on programs compiled with the HP
11889 ANSI C@t{++} compiler (@code{aCC}).)
11890
11891 @item set print vtbl off
11892 Do not pretty print C@t{++} virtual function tables.
11893
11894 @item show print vtbl
11895 Show whether C@t{++} virtual function tables are pretty printed, or not.
11896 @end table
11897
11898 @node Pretty Printing
11899 @section Pretty Printing
11900
11901 @value{GDBN} provides a mechanism to allow pretty-printing of values using
11902 Python code. It greatly simplifies the display of complex objects. This
11903 mechanism works for both MI and the CLI.
11904
11905 @menu
11906 * Pretty-Printer Introduction:: Introduction to pretty-printers
11907 * Pretty-Printer Example:: An example pretty-printer
11908 * Pretty-Printer Commands:: Pretty-printer commands
11909 @end menu
11910
11911 @node Pretty-Printer Introduction
11912 @subsection Pretty-Printer Introduction
11913
11914 When @value{GDBN} prints a value, it first sees if there is a pretty-printer
11915 registered for the value. If there is then @value{GDBN} invokes the
11916 pretty-printer to print the value. Otherwise the value is printed normally.
11917
11918 Pretty-printers are normally named. This makes them easy to manage.
11919 The @samp{info pretty-printer} command will list all the installed
11920 pretty-printers with their names.
11921 If a pretty-printer can handle multiple data types, then its
11922 @dfn{subprinters} are the printers for the individual data types.
11923 Each such subprinter has its own name.
11924 The format of the name is @var{printer-name};@var{subprinter-name}.
11925
11926 Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
11927 Typically they are automatically loaded and registered when the corresponding
11928 debug information is loaded, thus making them available without having to
11929 do anything special.
11930
11931 There are three places where a pretty-printer can be registered.
11932
11933 @itemize @bullet
11934 @item
11935 Pretty-printers registered globally are available when debugging
11936 all inferiors.
11937
11938 @item
11939 Pretty-printers registered with a program space are available only
11940 when debugging that program.
11941 @xref{Progspaces In Python}, for more details on program spaces in Python.
11942
11943 @item
11944 Pretty-printers registered with an objfile are loaded and unloaded
11945 with the corresponding objfile (e.g., shared library).
11946 @xref{Objfiles In Python}, for more details on objfiles in Python.
11947 @end itemize
11948
11949 @xref{Selecting Pretty-Printers}, for further information on how
11950 pretty-printers are selected,
11951
11952 @xref{Writing a Pretty-Printer}, for implementing pretty printers
11953 for new types.
11954
11955 @node Pretty-Printer Example
11956 @subsection Pretty-Printer Example
11957
11958 Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
11959
11960 @smallexample
11961 (@value{GDBP}) print s
11962 $1 = @{
11963 static npos = 4294967295,
11964 _M_dataplus = @{
11965 <std::allocator<char>> = @{
11966 <__gnu_cxx::new_allocator<char>> = @{
11967 <No data fields>@}, <No data fields>
11968 @},
11969 members of std::basic_string<char, std::char_traits<char>,
11970 std::allocator<char> >::_Alloc_hider:
11971 _M_p = 0x804a014 "abcd"
11972 @}
11973 @}
11974 @end smallexample
11975
11976 With a pretty-printer for @code{std::string} only the contents are printed:
11977
11978 @smallexample
11979 (@value{GDBP}) print s
11980 $2 = "abcd"
11981 @end smallexample
11982
11983 @node Pretty-Printer Commands
11984 @subsection Pretty-Printer Commands
11985 @cindex pretty-printer commands
11986
11987 @table @code
11988 @kindex info pretty-printer
11989 @item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11990 Print the list of installed pretty-printers.
11991 This includes disabled pretty-printers, which are marked as such.
11992
11993 @var{object-regexp} is a regular expression matching the objects
11994 whose pretty-printers to list.
11995 Objects can be @code{global}, the program space's file
11996 (@pxref{Progspaces In Python}),
11997 and the object files within that program space (@pxref{Objfiles In Python}).
11998 @xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
11999 looks up a printer from these three objects.
12000
12001 @var{name-regexp} is a regular expression matching the name of the printers
12002 to list.
12003
12004 @kindex disable pretty-printer
12005 @item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
12006 Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
12007 A disabled pretty-printer is not forgotten, it may be enabled again later.
12008
12009 @kindex enable pretty-printer
12010 @item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
12011 Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
12012 @end table
12013
12014 Example:
12015
12016 Suppose we have three pretty-printers installed: one from library1.so
12017 named @code{foo} that prints objects of type @code{foo}, and
12018 another from library2.so named @code{bar} that prints two types of objects,
12019 @code{bar1} and @code{bar2}.
12020
12021 @smallexample
12022 (gdb) info pretty-printer
12023 library1.so:
12024 foo
12025 library2.so:
12026 bar
12027 bar1
12028 bar2
12029 (gdb) info pretty-printer library2
12030 library2.so:
12031 bar
12032 bar1
12033 bar2
12034 (gdb) disable pretty-printer library1
12035 1 printer disabled
12036 2 of 3 printers enabled
12037 (gdb) info pretty-printer
12038 library1.so:
12039 foo [disabled]
12040 library2.so:
12041 bar
12042 bar1
12043 bar2
12044 (gdb) disable pretty-printer library2 bar;bar1
12045 1 printer disabled
12046 1 of 3 printers enabled
12047 (gdb) info pretty-printer library2
12048 library1.so:
12049 foo [disabled]
12050 library2.so:
12051 bar
12052 bar1 [disabled]
12053 bar2
12054 (gdb) disable pretty-printer library2 bar
12055 1 printer disabled
12056 0 of 3 printers enabled
12057 (gdb) info pretty-printer library2
12058 library1.so:
12059 foo [disabled]
12060 library2.so:
12061 bar [disabled]
12062 bar1 [disabled]
12063 bar2
12064 @end smallexample
12065
12066 Note that for @code{bar} the entire printer can be disabled,
12067 as can each individual subprinter.
12068
12069 Printing values and frame arguments is done by default using
12070 the enabled pretty printers.
12071
12072 The print option @code{-raw-values} and @value{GDBN} setting
12073 @code{set print raw-values} (@pxref{set print raw-values}) can be
12074 used to print values without applying the enabled pretty printers.
12075
12076 Similarly, the backtrace option @code{-raw-frame-arguments} and
12077 @value{GDBN} setting @code{set print raw-frame-arguments}
12078 (@pxref{set print raw-frame-arguments}) can be used to ignore the
12079 enabled pretty printers when printing frame argument values.
12080
12081 @node Value History
12082 @section Value History
12083
12084 @cindex value history
12085 @cindex history of values printed by @value{GDBN}
12086 Values printed by the @code{print} command are saved in the @value{GDBN}
12087 @dfn{value history}. This allows you to refer to them in other expressions.
12088 Values are kept until the symbol table is re-read or discarded
12089 (for example with the @code{file} or @code{symbol-file} commands).
12090 When the symbol table changes, the value history is discarded,
12091 since the values may contain pointers back to the types defined in the
12092 symbol table.
12093
12094 @cindex @code{$}
12095 @cindex @code{$$}
12096 @cindex history number
12097 The values printed are given @dfn{history numbers} by which you can
12098 refer to them. These are successive integers starting with one.
12099 @code{print} shows you the history number assigned to a value by
12100 printing @samp{$@var{num} = } before the value; here @var{num} is the
12101 history number.
12102
12103 To refer to any previous value, use @samp{$} followed by the value's
12104 history number. The way @code{print} labels its output is designed to
12105 remind you of this. Just @code{$} refers to the most recent value in
12106 the history, and @code{$$} refers to the value before that.
12107 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
12108 is the value just prior to @code{$$}, @code{$$1} is equivalent to
12109 @code{$$}, and @code{$$0} is equivalent to @code{$}.
12110
12111 For example, suppose you have just printed a pointer to a structure and
12112 want to see the contents of the structure. It suffices to type
12113
12114 @smallexample
12115 p *$
12116 @end smallexample
12117
12118 If you have a chain of structures where the component @code{next} points
12119 to the next one, you can print the contents of the next one with this:
12120
12121 @smallexample
12122 p *$.next
12123 @end smallexample
12124
12125 @noindent
12126 You can print successive links in the chain by repeating this
12127 command---which you can do by just typing @key{RET}.
12128
12129 Note that the history records values, not expressions. If the value of
12130 @code{x} is 4 and you type these commands:
12131
12132 @smallexample
12133 print x
12134 set x=5
12135 @end smallexample
12136
12137 @noindent
12138 then the value recorded in the value history by the @code{print} command
12139 remains 4 even though the value of @code{x} has changed.
12140
12141 @table @code
12142 @kindex show values
12143 @item show values
12144 Print the last ten values in the value history, with their item numbers.
12145 This is like @samp{p@ $$9} repeated ten times, except that @code{show
12146 values} does not change the history.
12147
12148 @item show values @var{n}
12149 Print ten history values centered on history item number @var{n}.
12150
12151 @item show values +
12152 Print ten history values just after the values last printed. If no more
12153 values are available, @code{show values +} produces no display.
12154 @end table
12155
12156 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
12157 same effect as @samp{show values +}.
12158
12159 @node Convenience Vars
12160 @section Convenience Variables
12161
12162 @cindex convenience variables
12163 @cindex user-defined variables
12164 @value{GDBN} provides @dfn{convenience variables} that you can use within
12165 @value{GDBN} to hold on to a value and refer to it later. These variables
12166 exist entirely within @value{GDBN}; they are not part of your program, and
12167 setting a convenience variable has no direct effect on further execution
12168 of your program. That is why you can use them freely.
12169
12170 Convenience variables are prefixed with @samp{$}. Any name preceded by
12171 @samp{$} can be used for a convenience variable, unless it is one of
12172 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
12173 (Value history references, in contrast, are @emph{numbers} preceded
12174 by @samp{$}. @xref{Value History, ,Value History}.)
12175
12176 You can save a value in a convenience variable with an assignment
12177 expression, just as you would set a variable in your program.
12178 For example:
12179
12180 @smallexample
12181 set $foo = *object_ptr
12182 @end smallexample
12183
12184 @noindent
12185 would save in @code{$foo} the value contained in the object pointed to by
12186 @code{object_ptr}.
12187
12188 Using a convenience variable for the first time creates it, but its
12189 value is @code{void} until you assign a new value. You can alter the
12190 value with another assignment at any time.
12191
12192 Convenience variables have no fixed types. You can assign a convenience
12193 variable any type of value, including structures and arrays, even if
12194 that variable already has a value of a different type. The convenience
12195 variable, when used as an expression, has the type of its current value.
12196
12197 @table @code
12198 @kindex show convenience
12199 @cindex show all user variables and functions
12200 @item show convenience
12201 Print a list of convenience variables used so far, and their values,
12202 as well as a list of the convenience functions.
12203 Abbreviated @code{show conv}.
12204
12205 @kindex init-if-undefined
12206 @cindex convenience variables, initializing
12207 @item init-if-undefined $@var{variable} = @var{expression}
12208 Set a convenience variable if it has not already been set. This is useful
12209 for user-defined commands that keep some state. It is similar, in concept,
12210 to using local static variables with initializers in C (except that
12211 convenience variables are global). It can also be used to allow users to
12212 override default values used in a command script.
12213
12214 If the variable is already defined then the expression is not evaluated so
12215 any side-effects do not occur.
12216 @end table
12217
12218 One of the ways to use a convenience variable is as a counter to be
12219 incremented or a pointer to be advanced. For example, to print
12220 a field from successive elements of an array of structures:
12221
12222 @smallexample
12223 set $i = 0
12224 print bar[$i++]->contents
12225 @end smallexample
12226
12227 @noindent
12228 Repeat that command by typing @key{RET}.
12229
12230 Some convenience variables are created automatically by @value{GDBN} and given
12231 values likely to be useful.
12232
12233 @table @code
12234 @vindex $_@r{, convenience variable}
12235 @item $_
12236 The variable @code{$_} is automatically set by the @code{x} command to
12237 the last address examined (@pxref{Memory, ,Examining Memory}). Other
12238 commands which provide a default address for @code{x} to examine also
12239 set @code{$_} to that address; these commands include @code{info line}
12240 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
12241 except when set by the @code{x} command, in which case it is a pointer
12242 to the type of @code{$__}.
12243
12244 @vindex $__@r{, convenience variable}
12245 @item $__
12246 The variable @code{$__} is automatically set by the @code{x} command
12247 to the value found in the last address examined. Its type is chosen
12248 to match the format in which the data was printed.
12249
12250 @item $_exitcode
12251 @vindex $_exitcode@r{, convenience variable}
12252 When the program being debugged terminates normally, @value{GDBN}
12253 automatically sets this variable to the exit code of the program, and
12254 resets @code{$_exitsignal} to @code{void}.
12255
12256 @item $_exitsignal
12257 @vindex $_exitsignal@r{, convenience variable}
12258 When the program being debugged dies due to an uncaught signal,
12259 @value{GDBN} automatically sets this variable to that signal's number,
12260 and resets @code{$_exitcode} to @code{void}.
12261
12262 To distinguish between whether the program being debugged has exited
12263 (i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
12264 @code{$_exitsignal} is not @code{void}), the convenience function
12265 @code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
12266 Functions}). For example, considering the following source code:
12267
12268 @smallexample
12269 #include <signal.h>
12270
12271 int
12272 main (int argc, char *argv[])
12273 @{
12274 raise (SIGALRM);
12275 return 0;
12276 @}
12277 @end smallexample
12278
12279 A valid way of telling whether the program being debugged has exited
12280 or signalled would be:
12281
12282 @smallexample
12283 (@value{GDBP}) define has_exited_or_signalled
12284 Type commands for definition of ``has_exited_or_signalled''.
12285 End with a line saying just ``end''.
12286 >if $_isvoid ($_exitsignal)
12287 >echo The program has exited\n
12288 >else
12289 >echo The program has signalled\n
12290 >end
12291 >end
12292 (@value{GDBP}) run
12293 Starting program:
12294
12295 Program terminated with signal SIGALRM, Alarm clock.
12296 The program no longer exists.
12297 (@value{GDBP}) has_exited_or_signalled
12298 The program has signalled
12299 @end smallexample
12300
12301 As can be seen, @value{GDBN} correctly informs that the program being
12302 debugged has signalled, since it calls @code{raise} and raises a
12303 @code{SIGALRM} signal. If the program being debugged had not called
12304 @code{raise}, then @value{GDBN} would report a normal exit:
12305
12306 @smallexample
12307 (@value{GDBP}) has_exited_or_signalled
12308 The program has exited
12309 @end smallexample
12310
12311 @item $_exception
12312 The variable @code{$_exception} is set to the exception object being
12313 thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
12314
12315 @item $_ada_exception
12316 The variable @code{$_ada_exception} is set to the address of the
12317 exception being caught or thrown at an Ada exception-related
12318 catchpoint. @xref{Set Catchpoints}.
12319
12320 @item $_probe_argc
12321 @itemx $_probe_arg0@dots{}$_probe_arg11
12322 Arguments to a static probe. @xref{Static Probe Points}.
12323
12324 @item $_sdata
12325 @vindex $_sdata@r{, inspect, convenience variable}
12326 The variable @code{$_sdata} contains extra collected static tracepoint
12327 data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
12328 @code{$_sdata} could be empty, if not inspecting a trace buffer, or
12329 if extra static tracepoint data has not been collected.
12330
12331 @item $_siginfo
12332 @vindex $_siginfo@r{, convenience variable}
12333 The variable @code{$_siginfo} contains extra signal information
12334 (@pxref{extra signal information}). Note that @code{$_siginfo}
12335 could be empty, if the application has not yet received any signals.
12336 For example, it will be empty before you execute the @code{run} command.
12337
12338 @item $_tlb
12339 @vindex $_tlb@r{, convenience variable}
12340 The variable @code{$_tlb} is automatically set when debugging
12341 applications running on MS-Windows in native mode or connected to
12342 gdbserver that supports the @code{qGetTIBAddr} request.
12343 @xref{General Query Packets}.
12344 This variable contains the address of the thread information block.
12345
12346 @item $_inferior
12347 The number of the current inferior. @xref{Inferiors Connections and
12348 Programs, ,Debugging Multiple Inferiors Connections and Programs}.
12349
12350 @item $_thread
12351 The thread number of the current thread. @xref{thread numbers}.
12352
12353 @item $_gthread
12354 The global number of the current thread. @xref{global thread numbers}.
12355
12356 @item $_gdb_major
12357 @itemx $_gdb_minor
12358 @vindex $_gdb_major@r{, convenience variable}
12359 @vindex $_gdb_minor@r{, convenience variable}
12360 The major and minor version numbers of the running @value{GDBN}.
12361 Development snapshots and pretest versions have their minor version
12362 incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
12363 the value 12 for @code{$_gdb_minor}. These variables allow you to
12364 write scripts that work with different versions of @value{GDBN}
12365 without errors caused by features unavailable in some of those
12366 versions.
12367
12368 @item $_shell_exitcode
12369 @itemx $_shell_exitsignal
12370 @vindex $_shell_exitcode@r{, convenience variable}
12371 @vindex $_shell_exitsignal@r{, convenience variable}
12372 @cindex shell command, exit code
12373 @cindex shell command, exit signal
12374 @cindex exit status of shell commands
12375 @value{GDBN} commands such as @code{shell} and @code{|} are launching
12376 shell commands. When a launched command terminates, @value{GDBN}
12377 automatically maintains the variables @code{$_shell_exitcode}
12378 and @code{$_shell_exitsignal} according to the exit status of the last
12379 launched command. These variables are set and used similarly to
12380 the variables @code{$_exitcode} and @code{$_exitsignal}.
12381
12382 @end table
12383
12384 @node Convenience Funs
12385 @section Convenience Functions
12386
12387 @cindex convenience functions
12388 @value{GDBN} also supplies some @dfn{convenience functions}. These
12389 have a syntax similar to convenience variables. A convenience
12390 function can be used in an expression just like an ordinary function;
12391 however, a convenience function is implemented internally to
12392 @value{GDBN}.
12393
12394 These functions do not require @value{GDBN} to be configured with
12395 @code{Python} support, which means that they are always available.
12396
12397 @table @code
12398
12399 @item $_isvoid (@var{expr})
12400 @findex $_isvoid@r{, convenience function}
12401 Return one if the expression @var{expr} is @code{void}. Otherwise it
12402 returns zero.
12403
12404 A @code{void} expression is an expression where the type of the result
12405 is @code{void}. For example, you can examine a convenience variable
12406 (see @ref{Convenience Vars,, Convenience Variables}) to check whether
12407 it is @code{void}:
12408
12409 @smallexample
12410 (@value{GDBP}) print $_exitcode
12411 $1 = void
12412 (@value{GDBP}) print $_isvoid ($_exitcode)
12413 $2 = 1
12414 (@value{GDBP}) run
12415 Starting program: ./a.out
12416 [Inferior 1 (process 29572) exited normally]
12417 (@value{GDBP}) print $_exitcode
12418 $3 = 0
12419 (@value{GDBP}) print $_isvoid ($_exitcode)
12420 $4 = 0
12421 @end smallexample
12422
12423 In the example above, we used @code{$_isvoid} to check whether
12424 @code{$_exitcode} is @code{void} before and after the execution of the
12425 program being debugged. Before the execution there is no exit code to
12426 be examined, therefore @code{$_exitcode} is @code{void}. After the
12427 execution the program being debugged returned zero, therefore
12428 @code{$_exitcode} is zero, which means that it is not @code{void}
12429 anymore.
12430
12431 The @code{void} expression can also be a call of a function from the
12432 program being debugged. For example, given the following function:
12433
12434 @smallexample
12435 void
12436 foo (void)
12437 @{
12438 @}
12439 @end smallexample
12440
12441 The result of calling it inside @value{GDBN} is @code{void}:
12442
12443 @smallexample
12444 (@value{GDBP}) print foo ()
12445 $1 = void
12446 (@value{GDBP}) print $_isvoid (foo ())
12447 $2 = 1
12448 (@value{GDBP}) set $v = foo ()
12449 (@value{GDBP}) print $v
12450 $3 = void
12451 (@value{GDBP}) print $_isvoid ($v)
12452 $4 = 1
12453 @end smallexample
12454
12455 @item $_gdb_setting_str (@var{setting})
12456 @findex $_gdb_setting_str@r{, convenience function}
12457 Return the value of the @value{GDBN} @var{setting} as a string.
12458 @var{setting} is any setting that can be used in a @code{set} or
12459 @code{show} command (@pxref{Controlling GDB}).
12460
12461 @smallexample
12462 (@value{GDBP}) show print frame-arguments
12463 Printing of non-scalar frame arguments is "scalars".
12464 (@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12465 $1 = "scalars"
12466 (@value{GDBP}) p $_gdb_setting_str("height")
12467 $2 = "30"
12468 (@value{GDBP})
12469 @end smallexample
12470
12471 @item $_gdb_setting (@var{setting})
12472 @findex $_gdb_setting@r{, convenience function}
12473 Return the value of the @value{GDBN} @var{setting}.
12474 The type of the returned value depends on the setting.
12475
12476 The value type for boolean and auto boolean settings is @code{int}.
12477 The boolean values @code{off} and @code{on} are converted to
12478 the integer values @code{0} and @code{1}. The value @code{auto} is
12479 converted to the value @code{-1}.
12480
12481 The value type for integer settings is either @code{unsigned int}
12482 or @code{int}, depending on the setting.
12483
12484 Some integer settings accept an @code{unlimited} value.
12485 Depending on the setting, the @code{set} command also accepts
12486 the value @code{0} or the value @code{@minus{}1} as a synonym for
12487 @code{unlimited}.
12488 For example, @code{set height unlimited} is equivalent to
12489 @code{set height 0}.
12490
12491 Some other settings that accept the @code{unlimited} value
12492 use the value @code{0} to literally mean zero.
12493 For example, @code{set history size 0} indicates to not
12494 record any @value{GDBN} commands in the command history.
12495 For such settings, @code{@minus{}1} is the synonym
12496 for @code{unlimited}.
12497
12498 See the documentation of the corresponding @code{set} command for
12499 the numerical value equivalent to @code{unlimited}.
12500
12501 The @code{$_gdb_setting} function converts the unlimited value
12502 to a @code{0} or a @code{@minus{}1} value according to what the
12503 @code{set} command uses.
12504
12505 @smallexample
12506 @group
12507 (@value{GDBP}) p $_gdb_setting_str("height")
12508 $1 = "30"
12509 (@value{GDBP}) p $_gdb_setting("height")
12510 $2 = 30
12511 (@value{GDBP}) set height unlimited
12512 (@value{GDBP}) p $_gdb_setting_str("height")
12513 $3 = "unlimited"
12514 (@value{GDBP}) p $_gdb_setting("height")
12515 $4 = 0
12516 @end group
12517 @group
12518 (@value{GDBP}) p $_gdb_setting_str("history size")
12519 $5 = "unlimited"
12520 (@value{GDBP}) p $_gdb_setting("history size")
12521 $6 = -1
12522 (@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12523 $7 = "auto"
12524 (@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12525 $8 = -1
12526 (@value{GDBP})
12527 @end group
12528 @end smallexample
12529
12530 Other setting types (enum, filename, optional filename, string, string noescape)
12531 are returned as string values.
12532
12533
12534 @item $_gdb_maint_setting_str (@var{setting})
12535 @findex $_gdb_maint_setting_str@r{, convenience function}
12536 Like the @code{$_gdb_setting_str} function, but works with
12537 @code{maintenance set} variables.
12538
12539 @item $_gdb_maint_setting (@var{setting})
12540 @findex $_gdb_maint_setting@r{, convenience function}
12541 Like the @code{$_gdb_setting} function, but works with
12542 @code{maintenance set} variables.
12543
12544 @end table
12545
12546 The following functions require @value{GDBN} to be configured with
12547 @code{Python} support.
12548
12549 @table @code
12550
12551 @item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12552 @findex $_memeq@r{, convenience function}
12553 Returns one if the @var{length} bytes at the addresses given by
12554 @var{buf1} and @var{buf2} are equal.
12555 Otherwise it returns zero.
12556
12557 @item $_regex(@var{str}, @var{regex})
12558 @findex $_regex@r{, convenience function}
12559 Returns one if the string @var{str} matches the regular expression
12560 @var{regex}. Otherwise it returns zero.
12561 The syntax of the regular expression is that specified by @code{Python}'s
12562 regular expression support.
12563
12564 @item $_streq(@var{str1}, @var{str2})
12565 @findex $_streq@r{, convenience function}
12566 Returns one if the strings @var{str1} and @var{str2} are equal.
12567 Otherwise it returns zero.
12568
12569 @item $_strlen(@var{str})
12570 @findex $_strlen@r{, convenience function}
12571 Returns the length of string @var{str}.
12572
12573 @item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12574 @findex $_caller_is@r{, convenience function}
12575 Returns one if the calling function's name is equal to @var{name}.
12576 Otherwise it returns zero.
12577
12578 If the optional argument @var{number_of_frames} is provided,
12579 it is the number of frames up in the stack to look.
12580 The default is 1.
12581
12582 Example:
12583
12584 @smallexample
12585 (gdb) backtrace
12586 #0 bottom_func ()
12587 at testsuite/gdb.python/py-caller-is.c:21
12588 #1 0x00000000004005a0 in middle_func ()
12589 at testsuite/gdb.python/py-caller-is.c:27
12590 #2 0x00000000004005ab in top_func ()
12591 at testsuite/gdb.python/py-caller-is.c:33
12592 #3 0x00000000004005b6 in main ()
12593 at testsuite/gdb.python/py-caller-is.c:39
12594 (gdb) print $_caller_is ("middle_func")
12595 $1 = 1
12596 (gdb) print $_caller_is ("top_func", 2)
12597 $1 = 1
12598 @end smallexample
12599
12600 @item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12601 @findex $_caller_matches@r{, convenience function}
12602 Returns one if the calling function's name matches the regular expression
12603 @var{regexp}. Otherwise it returns zero.
12604
12605 If the optional argument @var{number_of_frames} is provided,
12606 it is the number of frames up in the stack to look.
12607 The default is 1.
12608
12609 @item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12610 @findex $_any_caller_is@r{, convenience function}
12611 Returns one if any calling function's name is equal to @var{name}.
12612 Otherwise it returns zero.
12613
12614 If the optional argument @var{number_of_frames} is provided,
12615 it is the number of frames up in the stack to look.
12616 The default is 1.
12617
12618 This function differs from @code{$_caller_is} in that this function
12619 checks all stack frames from the immediate caller to the frame specified
12620 by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12621 frame specified by @var{number_of_frames}.
12622
12623 @item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12624 @findex $_any_caller_matches@r{, convenience function}
12625 Returns one if any calling function's name matches the regular expression
12626 @var{regexp}. Otherwise it returns zero.
12627
12628 If the optional argument @var{number_of_frames} is provided,
12629 it is the number of frames up in the stack to look.
12630 The default is 1.
12631
12632 This function differs from @code{$_caller_matches} in that this function
12633 checks all stack frames from the immediate caller to the frame specified
12634 by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12635 frame specified by @var{number_of_frames}.
12636
12637 @item $_as_string(@var{value})
12638 @findex $_as_string@r{, convenience function}
12639 Return the string representation of @var{value}.
12640
12641 This function is useful to obtain the textual label (enumerator) of an
12642 enumeration value. For example, assuming the variable @var{node} is of
12643 an enumerated type:
12644
12645 @smallexample
12646 (gdb) printf "Visiting node of type %s\n", $_as_string(node)
12647 Visiting node of type NODE_INTEGER
12648 @end smallexample
12649
12650 @item $_cimag(@var{value})
12651 @itemx $_creal(@var{value})
12652 @findex $_cimag@r{, convenience function}
12653 @findex $_creal@r{, convenience function}
12654 Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12655 the complex number @var{value}.
12656
12657 The type of the imaginary or real part depends on the type of the
12658 complex number, e.g., using @code{$_cimag} on a @code{float complex}
12659 will return an imaginary part of type @code{float}.
12660
12661 @end table
12662
12663 @value{GDBN} provides the ability to list and get help on
12664 convenience functions.
12665
12666 @table @code
12667 @item help function
12668 @kindex help function
12669 @cindex show all convenience functions
12670 Print a list of all convenience functions.
12671 @end table
12672
12673 @node Registers
12674 @section Registers
12675
12676 @cindex registers
12677 You can refer to machine register contents, in expressions, as variables
12678 with names starting with @samp{$}. The names of registers are different
12679 for each machine; use @code{info registers} to see the names used on
12680 your machine.
12681
12682 @table @code
12683 @kindex info registers
12684 @item info registers
12685 Print the names and values of all registers except floating-point
12686 and vector registers (in the selected stack frame).
12687
12688 @kindex info all-registers
12689 @cindex floating point registers
12690 @item info all-registers
12691 Print the names and values of all registers, including floating-point
12692 and vector registers (in the selected stack frame).
12693
12694 @anchor{info_registers_reggroup}
12695 @item info registers @var{reggroup} @dots{}
12696 Print the name and value of the registers in each of the specified
12697 @var{reggroup}s. The @var{reggroup} can be any of those returned by
12698 @code{maint print reggroups} (@pxref{Maintenance Commands}).
12699
12700 @item info registers @var{regname} @dots{}
12701 Print the @dfn{relativized} value of each specified register @var{regname}.
12702 As discussed in detail below, register values are normally relative to
12703 the selected stack frame. The @var{regname} may be any register name valid on
12704 the machine you are using, with or without the initial @samp{$}.
12705 @end table
12706
12707 @anchor{standard registers}
12708 @cindex stack pointer register
12709 @cindex program counter register
12710 @cindex process status register
12711 @cindex frame pointer register
12712 @cindex standard registers
12713 @value{GDBN} has four ``standard'' register names that are available (in
12714 expressions) on most machines---whenever they do not conflict with an
12715 architecture's canonical mnemonics for registers. The register names
12716 @code{$pc} and @code{$sp} are used for the program counter register and
12717 the stack pointer. @code{$fp} is used for a register that contains a
12718 pointer to the current stack frame, and @code{$ps} is used for a
12719 register that contains the processor status. For example,
12720 you could print the program counter in hex with
12721
12722 @smallexample
12723 p/x $pc
12724 @end smallexample
12725
12726 @noindent
12727 or print the instruction to be executed next with
12728
12729 @smallexample
12730 x/i $pc
12731 @end smallexample
12732
12733 @noindent
12734 or add four to the stack pointer@footnote{This is a way of removing
12735 one word from the stack, on machines where stacks grow downward in
12736 memory (most machines, nowadays). This assumes that the innermost
12737 stack frame is selected; setting @code{$sp} is not allowed when other
12738 stack frames are selected. To pop entire frames off the stack,
12739 regardless of machine architecture, use @code{return};
12740 see @ref{Returning, ,Returning from a Function}.} with
12741
12742 @smallexample
12743 set $sp += 4
12744 @end smallexample
12745
12746 Whenever possible, these four standard register names are available on
12747 your machine even though the machine has different canonical mnemonics,
12748 so long as there is no conflict. The @code{info registers} command
12749 shows the canonical names. For example, on the SPARC, @code{info
12750 registers} displays the processor status register as @code{$psr} but you
12751 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12752 is an alias for the @sc{eflags} register.
12753
12754 @value{GDBN} always considers the contents of an ordinary register as an
12755 integer when the register is examined in this way. Some machines have
12756 special registers which can hold nothing but floating point; these
12757 registers are considered to have floating point values. There is no way
12758 to refer to the contents of an ordinary register as floating point value
12759 (although you can @emph{print} it as a floating point value with
12760 @samp{print/f $@var{regname}}).
12761
12762 Some registers have distinct ``raw'' and ``virtual'' data formats. This
12763 means that the data format in which the register contents are saved by
12764 the operating system is not the same one that your program normally
12765 sees. For example, the registers of the 68881 floating point
12766 coprocessor are always saved in ``extended'' (raw) format, but all C
12767 programs expect to work with ``double'' (virtual) format. In such
12768 cases, @value{GDBN} normally works with the virtual format only (the format
12769 that makes sense for your program), but the @code{info registers} command
12770 prints the data in both formats.
12771
12772 @cindex SSE registers (x86)
12773 @cindex MMX registers (x86)
12774 Some machines have special registers whose contents can be interpreted
12775 in several different ways. For example, modern x86-based machines
12776 have SSE and MMX registers that can hold several values packed
12777 together in several different formats. @value{GDBN} refers to such
12778 registers in @code{struct} notation:
12779
12780 @smallexample
12781 (@value{GDBP}) print $xmm1
12782 $1 = @{
12783 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
12784 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
12785 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
12786 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
12787 v4_int32 = @{0, 20657912, 11, 13@},
12788 v2_int64 = @{88725056443645952, 55834574859@},
12789 uint128 = 0x0000000d0000000b013b36f800000000
12790 @}
12791 @end smallexample
12792
12793 @noindent
12794 To set values of such registers, you need to tell @value{GDBN} which
12795 view of the register you wish to change, as if you were assigning
12796 value to a @code{struct} member:
12797
12798 @smallexample
12799 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
12800 @end smallexample
12801
12802 Normally, register values are relative to the selected stack frame
12803 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
12804 value that the register would contain if all stack frames farther in
12805 were exited and their saved registers restored. In order to see the
12806 true contents of hardware registers, you must select the innermost
12807 frame (with @samp{frame 0}).
12808
12809 @cindex caller-saved registers
12810 @cindex call-clobbered registers
12811 @cindex volatile registers
12812 @cindex <not saved> values
12813 Usually ABIs reserve some registers as not needed to be saved by the
12814 callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
12815 registers). It may therefore not be possible for @value{GDBN} to know
12816 the value a register had before the call (in other words, in the outer
12817 frame), if the register value has since been changed by the callee.
12818 @value{GDBN} tries to deduce where the inner frame saved
12819 (``callee-saved'') registers, from the debug info, unwind info, or the
12820 machine code generated by your compiler. If some register is not
12821 saved, and @value{GDBN} knows the register is ``caller-saved'' (via
12822 its own knowledge of the ABI, or because the debug/unwind info
12823 explicitly says the register's value is undefined), @value{GDBN}
12824 displays @w{@samp{<not saved>}} as the register's value. With targets
12825 that @value{GDBN} has no knowledge of the register saving convention,
12826 if a register was not saved by the callee, then its value and location
12827 in the outer frame are assumed to be the same of the inner frame.
12828 This is usually harmless, because if the register is call-clobbered,
12829 the caller either does not care what is in the register after the
12830 call, or has code to restore the value that it does care about. Note,
12831 however, that if you change such a register in the outer frame, you
12832 may also be affecting the inner frame. Also, the more ``outer'' the
12833 frame is you're looking at, the more likely a call-clobbered
12834 register's value is to be wrong, in the sense that it doesn't actually
12835 represent the value the register had just before the call.
12836
12837 @node Floating Point Hardware
12838 @section Floating Point Hardware
12839 @cindex floating point
12840
12841 Depending on the configuration, @value{GDBN} may be able to give
12842 you more information about the status of the floating point hardware.
12843
12844 @table @code
12845 @kindex info float
12846 @item info float
12847 Display hardware-dependent information about the floating
12848 point unit. The exact contents and layout vary depending on the
12849 floating point chip. Currently, @samp{info float} is supported on
12850 the ARM and x86 machines.
12851 @end table
12852
12853 @node Vector Unit
12854 @section Vector Unit
12855 @cindex vector unit
12856
12857 Depending on the configuration, @value{GDBN} may be able to give you
12858 more information about the status of the vector unit.
12859
12860 @table @code
12861 @kindex info vector
12862 @item info vector
12863 Display information about the vector unit. The exact contents and
12864 layout vary depending on the hardware.
12865 @end table
12866
12867 @node OS Information
12868 @section Operating System Auxiliary Information
12869 @cindex OS information
12870
12871 @value{GDBN} provides interfaces to useful OS facilities that can help
12872 you debug your program.
12873
12874 @cindex auxiliary vector
12875 @cindex vector, auxiliary
12876 Some operating systems supply an @dfn{auxiliary vector} to programs at
12877 startup. This is akin to the arguments and environment that you
12878 specify for a program, but contains a system-dependent variety of
12879 binary values that tell system libraries important details about the
12880 hardware, operating system, and process. Each value's purpose is
12881 identified by an integer tag; the meanings are well-known but system-specific.
12882 Depending on the configuration and operating system facilities,
12883 @value{GDBN} may be able to show you this information. For remote
12884 targets, this functionality may further depend on the remote stub's
12885 support of the @samp{qXfer:auxv:read} packet, see
12886 @ref{qXfer auxiliary vector read}.
12887
12888 @table @code
12889 @kindex info auxv
12890 @item info auxv
12891 Display the auxiliary vector of the inferior, which can be either a
12892 live process or a core dump file. @value{GDBN} prints each tag value
12893 numerically, and also shows names and text descriptions for recognized
12894 tags. Some values in the vector are numbers, some bit masks, and some
12895 pointers to strings or other data. @value{GDBN} displays each value in the
12896 most appropriate form for a recognized tag, and in hexadecimal for
12897 an unrecognized tag.
12898 @end table
12899
12900 On some targets, @value{GDBN} can access operating system-specific
12901 information and show it to you. The types of information available
12902 will differ depending on the type of operating system running on the
12903 target. The mechanism used to fetch the data is described in
12904 @ref{Operating System Information}. For remote targets, this
12905 functionality depends on the remote stub's support of the
12906 @samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
12907
12908 @table @code
12909 @kindex info os
12910 @item info os @var{infotype}
12911
12912 Display OS information of the requested type.
12913
12914 On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
12915
12916 @anchor{linux info os infotypes}
12917 @table @code
12918 @kindex info os cpus
12919 @item cpus
12920 Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
12921 the available fields from /proc/cpuinfo. For each supported architecture
12922 different fields are available. Two common entries are processor which gives
12923 CPU number and bogomips; a system constant that is calculated during
12924 kernel initialization.
12925
12926 @kindex info os files
12927 @item files
12928 Display the list of open file descriptors on the target. For each
12929 file descriptor, @value{GDBN} prints the identifier of the process
12930 owning the descriptor, the command of the owning process, the value
12931 of the descriptor, and the target of the descriptor.
12932
12933 @kindex info os modules
12934 @item modules
12935 Display the list of all loaded kernel modules on the target. For each
12936 module, @value{GDBN} prints the module name, the size of the module in
12937 bytes, the number of times the module is used, the dependencies of the
12938 module, the status of the module, and the address of the loaded module
12939 in memory.
12940
12941 @kindex info os msg
12942 @item msg
12943 Display the list of all System V message queues on the target. For each
12944 message queue, @value{GDBN} prints the message queue key, the message
12945 queue identifier, the access permissions, the current number of bytes
12946 on the queue, the current number of messages on the queue, the processes
12947 that last sent and received a message on the queue, the user and group
12948 of the owner and creator of the message queue, the times at which a
12949 message was last sent and received on the queue, and the time at which
12950 the message queue was last changed.
12951
12952 @kindex info os processes
12953 @item processes
12954 Display the list of processes on the target. For each process,
12955 @value{GDBN} prints the process identifier, the name of the user, the
12956 command corresponding to the process, and the list of processor cores
12957 that the process is currently running on. (To understand what these
12958 properties mean, for this and the following info types, please consult
12959 the general @sc{gnu}/Linux documentation.)
12960
12961 @kindex info os procgroups
12962 @item procgroups
12963 Display the list of process groups on the target. For each process,
12964 @value{GDBN} prints the identifier of the process group that it belongs
12965 to, the command corresponding to the process group leader, the process
12966 identifier, and the command line of the process. The list is sorted
12967 first by the process group identifier, then by the process identifier,
12968 so that processes belonging to the same process group are grouped together
12969 and the process group leader is listed first.
12970
12971 @kindex info os semaphores
12972 @item semaphores
12973 Display the list of all System V semaphore sets on the target. For each
12974 semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
12975 set identifier, the access permissions, the number of semaphores in the
12976 set, the user and group of the owner and creator of the semaphore set,
12977 and the times at which the semaphore set was operated upon and changed.
12978
12979 @kindex info os shm
12980 @item shm
12981 Display the list of all System V shared-memory regions on the target.
12982 For each shared-memory region, @value{GDBN} prints the region key,
12983 the shared-memory identifier, the access permissions, the size of the
12984 region, the process that created the region, the process that last
12985 attached to or detached from the region, the current number of live
12986 attaches to the region, and the times at which the region was last
12987 attached to, detach from, and changed.
12988
12989 @kindex info os sockets
12990 @item sockets
12991 Display the list of Internet-domain sockets on the target. For each
12992 socket, @value{GDBN} prints the address and port of the local and
12993 remote endpoints, the current state of the connection, the creator of
12994 the socket, the IP address family of the socket, and the type of the
12995 connection.
12996
12997 @kindex info os threads
12998 @item threads
12999 Display the list of threads running on the target. For each thread,
13000 @value{GDBN} prints the identifier of the process that the thread
13001 belongs to, the command of the process, the thread identifier, and the
13002 processor core that it is currently running on. The main thread of a
13003 process is not listed.
13004 @end table
13005
13006 @item info os
13007 If @var{infotype} is omitted, then list the possible values for
13008 @var{infotype} and the kind of OS information available for each
13009 @var{infotype}. If the target does not return a list of possible
13010 types, this command will report an error.
13011 @end table
13012
13013 @node Memory Region Attributes
13014 @section Memory Region Attributes
13015 @cindex memory region attributes
13016
13017 @dfn{Memory region attributes} allow you to describe special handling
13018 required by regions of your target's memory. @value{GDBN} uses
13019 attributes to determine whether to allow certain types of memory
13020 accesses; whether to use specific width accesses; and whether to cache
13021 target memory. By default the description of memory regions is
13022 fetched from the target (if the current target supports this), but the
13023 user can override the fetched regions.
13024
13025 Defined memory regions can be individually enabled and disabled. When a
13026 memory region is disabled, @value{GDBN} uses the default attributes when
13027 accessing memory in that region. Similarly, if no memory regions have
13028 been defined, @value{GDBN} uses the default attributes when accessing
13029 all memory.
13030
13031 When a memory region is defined, it is given a number to identify it;
13032 to enable, disable, or remove a memory region, you specify that number.
13033
13034 @table @code
13035 @kindex mem
13036 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
13037 Define a memory region bounded by @var{lower} and @var{upper} with
13038 attributes @var{attributes}@dots{}, and add it to the list of regions
13039 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
13040 case: it is treated as the target's maximum memory address.
13041 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
13042
13043 @item mem auto
13044 Discard any user changes to the memory regions and use target-supplied
13045 regions, if available, or no regions if the target does not support.
13046
13047 @kindex delete mem
13048 @item delete mem @var{nums}@dots{}
13049 Remove memory regions @var{nums}@dots{} from the list of regions
13050 monitored by @value{GDBN}.
13051
13052 @kindex disable mem
13053 @item disable mem @var{nums}@dots{}
13054 Disable monitoring of memory regions @var{nums}@dots{}.
13055 A disabled memory region is not forgotten.
13056 It may be enabled again later.
13057
13058 @kindex enable mem
13059 @item enable mem @var{nums}@dots{}
13060 Enable monitoring of memory regions @var{nums}@dots{}.
13061
13062 @kindex info mem
13063 @item info mem
13064 Print a table of all defined memory regions, with the following columns
13065 for each region:
13066
13067 @table @emph
13068 @item Memory Region Number
13069 @item Enabled or Disabled.
13070 Enabled memory regions are marked with @samp{y}.
13071 Disabled memory regions are marked with @samp{n}.
13072
13073 @item Lo Address
13074 The address defining the inclusive lower bound of the memory region.
13075
13076 @item Hi Address
13077 The address defining the exclusive upper bound of the memory region.
13078
13079 @item Attributes
13080 The list of attributes set for this memory region.
13081 @end table
13082 @end table
13083
13084
13085 @subsection Attributes
13086
13087 @subsubsection Memory Access Mode
13088 The access mode attributes set whether @value{GDBN} may make read or
13089 write accesses to a memory region.
13090
13091 While these attributes prevent @value{GDBN} from performing invalid
13092 memory accesses, they do nothing to prevent the target system, I/O DMA,
13093 etc.@: from accessing memory.
13094
13095 @table @code
13096 @item ro
13097 Memory is read only.
13098 @item wo
13099 Memory is write only.
13100 @item rw
13101 Memory is read/write. This is the default.
13102 @end table
13103
13104 @subsubsection Memory Access Size
13105 The access size attribute tells @value{GDBN} to use specific sized
13106 accesses in the memory region. Often memory mapped device registers
13107 require specific sized accesses. If no access size attribute is
13108 specified, @value{GDBN} may use accesses of any size.
13109
13110 @table @code
13111 @item 8
13112 Use 8 bit memory accesses.
13113 @item 16
13114 Use 16 bit memory accesses.
13115 @item 32
13116 Use 32 bit memory accesses.
13117 @item 64
13118 Use 64 bit memory accesses.
13119 @end table
13120
13121 @c @subsubsection Hardware/Software Breakpoints
13122 @c The hardware/software breakpoint attributes set whether @value{GDBN}
13123 @c will use hardware or software breakpoints for the internal breakpoints
13124 @c used by the step, next, finish, until, etc. commands.
13125 @c
13126 @c @table @code
13127 @c @item hwbreak
13128 @c Always use hardware breakpoints
13129 @c @item swbreak (default)
13130 @c @end table
13131
13132 @subsubsection Data Cache
13133 The data cache attributes set whether @value{GDBN} will cache target
13134 memory. While this generally improves performance by reducing debug
13135 protocol overhead, it can lead to incorrect results because @value{GDBN}
13136 does not know about volatile variables or memory mapped device
13137 registers.
13138
13139 @table @code
13140 @item cache
13141 Enable @value{GDBN} to cache target memory.
13142 @item nocache
13143 Disable @value{GDBN} from caching target memory. This is the default.
13144 @end table
13145
13146 @subsection Memory Access Checking
13147 @value{GDBN} can be instructed to refuse accesses to memory that is
13148 not explicitly described. This can be useful if accessing such
13149 regions has undesired effects for a specific target, or to provide
13150 better error checking. The following commands control this behaviour.
13151
13152 @table @code
13153 @kindex set mem inaccessible-by-default
13154 @item set mem inaccessible-by-default [on|off]
13155 If @code{on} is specified, make @value{GDBN} treat memory not
13156 explicitly described by the memory ranges as non-existent and refuse accesses
13157 to such memory. The checks are only performed if there's at least one
13158 memory range defined. If @code{off} is specified, make @value{GDBN}
13159 treat the memory not explicitly described by the memory ranges as RAM.
13160 The default value is @code{on}.
13161 @kindex show mem inaccessible-by-default
13162 @item show mem inaccessible-by-default
13163 Show the current handling of accesses to unknown memory.
13164 @end table
13165
13166
13167 @c @subsubsection Memory Write Verification
13168 @c The memory write verification attributes set whether @value{GDBN}
13169 @c will re-reads data after each write to verify the write was successful.
13170 @c
13171 @c @table @code
13172 @c @item verify
13173 @c @item noverify (default)
13174 @c @end table
13175
13176 @node Dump/Restore Files
13177 @section Copy Between Memory and a File
13178 @cindex dump/restore files
13179 @cindex append data to a file
13180 @cindex dump data to a file
13181 @cindex restore data from a file
13182
13183 You can use the commands @code{dump}, @code{append}, and
13184 @code{restore} to copy data between target memory and a file. The
13185 @code{dump} and @code{append} commands write data to a file, and the
13186 @code{restore} command reads data from a file back into the inferior's
13187 memory. Files may be in binary, Motorola S-record, Intel hex,
13188 Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
13189 append to binary files, and cannot read from Verilog Hex files.
13190
13191 @table @code
13192
13193 @kindex dump
13194 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13195 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
13196 Dump the contents of memory from @var{start_addr} to @var{end_addr},
13197 or the value of @var{expr}, to @var{filename} in the given format.
13198
13199 The @var{format} parameter may be any one of:
13200 @table @code
13201 @item binary
13202 Raw binary form.
13203 @item ihex
13204 Intel hex format.
13205 @item srec
13206 Motorola S-record format.
13207 @item tekhex
13208 Tektronix Hex format.
13209 @item verilog
13210 Verilog Hex format.
13211 @end table
13212
13213 @value{GDBN} uses the same definitions of these formats as the
13214 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
13215 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
13216 form.
13217
13218 @kindex append
13219 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
13220 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
13221 Append the contents of memory from @var{start_addr} to @var{end_addr},
13222 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
13223 (@value{GDBN} can only append data to files in raw binary form.)
13224
13225 @kindex restore
13226 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
13227 Restore the contents of file @var{filename} into memory. The
13228 @code{restore} command can automatically recognize any known @sc{bfd}
13229 file format, except for raw binary. To restore a raw binary file you
13230 must specify the optional keyword @code{binary} after the filename.
13231
13232 If @var{bias} is non-zero, its value will be added to the addresses
13233 contained in the file. Binary files always start at address zero, so
13234 they will be restored at address @var{bias}. Other bfd files have
13235 a built-in location; they will be restored at offset @var{bias}
13236 from that location.
13237
13238 If @var{start} and/or @var{end} are non-zero, then only data between
13239 file offset @var{start} and file offset @var{end} will be restored.
13240 These offsets are relative to the addresses in the file, before
13241 the @var{bias} argument is applied.
13242
13243 @end table
13244
13245 @node Core File Generation
13246 @section How to Produce a Core File from Your Program
13247 @cindex dump core from inferior
13248
13249 A @dfn{core file} or @dfn{core dump} is a file that records the memory
13250 image of a running process and its process status (register values
13251 etc.). Its primary use is post-mortem debugging of a program that
13252 crashed while it ran outside a debugger. A program that crashes
13253 automatically produces a core file, unless this feature is disabled by
13254 the user. @xref{Files}, for information on invoking @value{GDBN} in
13255 the post-mortem debugging mode.
13256
13257 Occasionally, you may wish to produce a core file of the program you
13258 are debugging in order to preserve a snapshot of its state.
13259 @value{GDBN} has a special command for that.
13260
13261 @table @code
13262 @kindex gcore
13263 @kindex generate-core-file
13264 @item generate-core-file [@var{file}]
13265 @itemx gcore [@var{file}]
13266 Produce a core dump of the inferior process. The optional argument
13267 @var{file} specifies the file name where to put the core dump. If not
13268 specified, the file name defaults to @file{core.@var{pid}}, where
13269 @var{pid} is the inferior process ID.
13270
13271 Note that this command is implemented only for some systems (as of
13272 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
13273
13274 On @sc{gnu}/Linux, this command can take into account the value of the
13275 file @file{/proc/@var{pid}/coredump_filter} when generating the core
13276 dump (@pxref{set use-coredump-filter}), and by default honors the
13277 @code{VM_DONTDUMP} flag for mappings where it is present in the file
13278 @file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
13279
13280 @kindex set use-coredump-filter
13281 @anchor{set use-coredump-filter}
13282 @item set use-coredump-filter on
13283 @itemx set use-coredump-filter off
13284 Enable or disable the use of the file
13285 @file{/proc/@var{pid}/coredump_filter} when generating core dump
13286 files. This file is used by the Linux kernel to decide what types of
13287 memory mappings will be dumped or ignored when generating a core dump
13288 file. @var{pid} is the process ID of a currently running process.
13289
13290 To make use of this feature, you have to write in the
13291 @file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
13292 which is a bit mask representing the memory mapping types. If a bit
13293 is set in the bit mask, then the memory mappings of the corresponding
13294 types will be dumped; otherwise, they will be ignored. This
13295 configuration is inherited by child processes. For more information
13296 about the bits that can be set in the
13297 @file{/proc/@var{pid}/coredump_filter} file, please refer to the
13298 manpage of @code{core(5)}.
13299
13300 By default, this option is @code{on}. If this option is turned
13301 @code{off}, @value{GDBN} does not read the @file{coredump_filter} file
13302 and instead uses the same default value as the Linux kernel in order
13303 to decide which pages will be dumped in the core dump file. This
13304 value is currently @code{0x33}, which means that bits @code{0}
13305 (anonymous private mappings), @code{1} (anonymous shared mappings),
13306 @code{4} (ELF headers) and @code{5} (private huge pages) are active.
13307 This will cause these memory mappings to be dumped automatically.
13308
13309 @kindex set dump-excluded-mappings
13310 @anchor{set dump-excluded-mappings}
13311 @item set dump-excluded-mappings on
13312 @itemx set dump-excluded-mappings off
13313 If @code{on} is specified, @value{GDBN} will dump memory mappings
13314 marked with the @code{VM_DONTDUMP} flag. This flag is represented in
13315 the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
13316
13317 The default value is @code{off}.
13318 @end table
13319
13320 @node Character Sets
13321 @section Character Sets
13322 @cindex character sets
13323 @cindex charset
13324 @cindex translating between character sets
13325 @cindex host character set
13326 @cindex target character set
13327
13328 If the program you are debugging uses a different character set to
13329 represent characters and strings than the one @value{GDBN} uses itself,
13330 @value{GDBN} can automatically translate between the character sets for
13331 you. The character set @value{GDBN} uses we call the @dfn{host
13332 character set}; the one the inferior program uses we call the
13333 @dfn{target character set}.
13334
13335 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
13336 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
13337 remote protocol (@pxref{Remote Debugging}) to debug a program
13338 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
13339 then the host character set is Latin-1, and the target character set is
13340 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
13341 target-charset EBCDIC-US}, then @value{GDBN} translates between
13342 @sc{ebcdic} and Latin 1 as you print character or string values, or use
13343 character and string literals in expressions.
13344
13345 @value{GDBN} has no way to automatically recognize which character set
13346 the inferior program uses; you must tell it, using the @code{set
13347 target-charset} command, described below.
13348
13349 Here are the commands for controlling @value{GDBN}'s character set
13350 support:
13351
13352 @table @code
13353 @item set target-charset @var{charset}
13354 @kindex set target-charset
13355 Set the current target character set to @var{charset}. To display the
13356 list of supported target character sets, type
13357 @kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
13358
13359 @item set host-charset @var{charset}
13360 @kindex set host-charset
13361 Set the current host character set to @var{charset}.
13362
13363 By default, @value{GDBN} uses a host character set appropriate to the
13364 system it is running on; you can override that default using the
13365 @code{set host-charset} command. On some systems, @value{GDBN} cannot
13366 automatically determine the appropriate host character set. In this
13367 case, @value{GDBN} uses @samp{UTF-8}.
13368
13369 @value{GDBN} can only use certain character sets as its host character
13370 set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
13371 @value{GDBN} will list the host character sets it supports.
13372
13373 @item set charset @var{charset}
13374 @kindex set charset
13375 Set the current host and target character sets to @var{charset}. As
13376 above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13377 @value{GDBN} will list the names of the character sets that can be used
13378 for both host and target.
13379
13380 @item show charset
13381 @kindex show charset
13382 Show the names of the current host and target character sets.
13383
13384 @item show host-charset
13385 @kindex show host-charset
13386 Show the name of the current host character set.
13387
13388 @item show target-charset
13389 @kindex show target-charset
13390 Show the name of the current target character set.
13391
13392 @item set target-wide-charset @var{charset}
13393 @kindex set target-wide-charset
13394 Set the current target's wide character set to @var{charset}. This is
13395 the character set used by the target's @code{wchar_t} type. To
13396 display the list of supported wide character sets, type
13397 @kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13398
13399 @item show target-wide-charset
13400 @kindex show target-wide-charset
13401 Show the name of the current target's wide character set.
13402 @end table
13403
13404 Here is an example of @value{GDBN}'s character set support in action.
13405 Assume that the following source code has been placed in the file
13406 @file{charset-test.c}:
13407
13408 @smallexample
13409 #include <stdio.h>
13410
13411 char ascii_hello[]
13412 = @{72, 101, 108, 108, 111, 44, 32, 119,
13413 111, 114, 108, 100, 33, 10, 0@};
13414 char ibm1047_hello[]
13415 = @{200, 133, 147, 147, 150, 107, 64, 166,
13416 150, 153, 147, 132, 90, 37, 0@};
13417
13418 main ()
13419 @{
13420 printf ("Hello, world!\n");
13421 @}
13422 @end smallexample
13423
13424 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13425 containing the string @samp{Hello, world!} followed by a newline,
13426 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13427
13428 We compile the program, and invoke the debugger on it:
13429
13430 @smallexample
13431 $ gcc -g charset-test.c -o charset-test
13432 $ gdb -nw charset-test
13433 GNU gdb 2001-12-19-cvs
13434 Copyright 2001 Free Software Foundation, Inc.
13435 @dots{}
13436 (@value{GDBP})
13437 @end smallexample
13438
13439 We can use the @code{show charset} command to see what character sets
13440 @value{GDBN} is currently using to interpret and display characters and
13441 strings:
13442
13443 @smallexample
13444 (@value{GDBP}) show charset
13445 The current host and target character set is `ISO-8859-1'.
13446 (@value{GDBP})
13447 @end smallexample
13448
13449 For the sake of printing this manual, let's use @sc{ascii} as our
13450 initial character set:
13451 @smallexample
13452 (@value{GDBP}) set charset ASCII
13453 (@value{GDBP}) show charset
13454 The current host and target character set is `ASCII'.
13455 (@value{GDBP})
13456 @end smallexample
13457
13458 Let's assume that @sc{ascii} is indeed the correct character set for our
13459 host system --- in other words, let's assume that if @value{GDBN} prints
13460 characters using the @sc{ascii} character set, our terminal will display
13461 them properly. Since our current target character set is also
13462 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
13463
13464 @smallexample
13465 (@value{GDBP}) print ascii_hello
13466 $1 = 0x401698 "Hello, world!\n"
13467 (@value{GDBP}) print ascii_hello[0]
13468 $2 = 72 'H'
13469 (@value{GDBP})
13470 @end smallexample
13471
13472 @value{GDBN} uses the target character set for character and string
13473 literals you use in expressions:
13474
13475 @smallexample
13476 (@value{GDBP}) print '+'
13477 $3 = 43 '+'
13478 (@value{GDBP})
13479 @end smallexample
13480
13481 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13482 character.
13483
13484 @value{GDBN} relies on the user to tell it which character set the
13485 target program uses. If we print @code{ibm1047_hello} while our target
13486 character set is still @sc{ascii}, we get jibberish:
13487
13488 @smallexample
13489 (@value{GDBP}) print ibm1047_hello
13490 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
13491 (@value{GDBP}) print ibm1047_hello[0]
13492 $5 = 200 '\310'
13493 (@value{GDBP})
13494 @end smallexample
13495
13496 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
13497 @value{GDBN} tells us the character sets it supports:
13498
13499 @smallexample
13500 (@value{GDBP}) set target-charset
13501 ASCII EBCDIC-US IBM1047 ISO-8859-1
13502 (@value{GDBP}) set target-charset
13503 @end smallexample
13504
13505 We can select @sc{ibm1047} as our target character set, and examine the
13506 program's strings again. Now the @sc{ascii} string is wrong, but
13507 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
13508 target character set, @sc{ibm1047}, to the host character set,
13509 @sc{ascii}, and they display correctly:
13510
13511 @smallexample
13512 (@value{GDBP}) set target-charset IBM1047
13513 (@value{GDBP}) show charset
13514 The current host character set is `ASCII'.
13515 The current target character set is `IBM1047'.
13516 (@value{GDBP}) print ascii_hello
13517 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
13518 (@value{GDBP}) print ascii_hello[0]
13519 $7 = 72 '\110'
13520 (@value{GDBP}) print ibm1047_hello
13521 $8 = 0x4016a8 "Hello, world!\n"
13522 (@value{GDBP}) print ibm1047_hello[0]
13523 $9 = 200 'H'
13524 (@value{GDBP})
13525 @end smallexample
13526
13527 As above, @value{GDBN} uses the target character set for character and
13528 string literals you use in expressions:
13529
13530 @smallexample
13531 (@value{GDBP}) print '+'
13532 $10 = 78 '+'
13533 (@value{GDBP})
13534 @end smallexample
13535
13536 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
13537 character.
13538
13539 @node Caching Target Data
13540 @section Caching Data of Targets
13541 @cindex caching data of targets
13542
13543 @value{GDBN} caches data exchanged between the debugger and a target.
13544 Each cache is associated with the address space of the inferior.
13545 @xref{Inferiors Connections and Programs}, about inferior and address space.
13546 Such caching generally improves performance in remote debugging
13547 (@pxref{Remote Debugging}), because it reduces the overhead of the
13548 remote protocol by bundling memory reads and writes into large chunks.
13549 Unfortunately, simply caching everything would lead to incorrect results,
13550 since @value{GDBN} does not necessarily know anything about volatile
13551 values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
13552 (@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13553 is executing.
13554 Therefore, by default, @value{GDBN} only caches data
13555 known to be on the stack@footnote{In non-stop mode, it is moderately
13556 rare for a running thread to modify the stack of a stopped thread
13557 in a way that would interfere with a backtrace, and caching of
13558 stack reads provides a significant speed up of remote backtraces.} or
13559 in the code segment.
13560 Other regions of memory can be explicitly marked as
13561 cacheable; @pxref{Memory Region Attributes}.
13562
13563 @table @code
13564 @kindex set remotecache
13565 @item set remotecache on
13566 @itemx set remotecache off
13567 This option no longer does anything; it exists for compatibility
13568 with old scripts.
13569
13570 @kindex show remotecache
13571 @item show remotecache
13572 Show the current state of the obsolete remotecache flag.
13573
13574 @kindex set stack-cache
13575 @item set stack-cache on
13576 @itemx set stack-cache off
13577 Enable or disable caching of stack accesses. When @code{on}, use
13578 caching. By default, this option is @code{on}.
13579
13580 @kindex show stack-cache
13581 @item show stack-cache
13582 Show the current state of data caching for memory accesses.
13583
13584 @kindex set code-cache
13585 @item set code-cache on
13586 @itemx set code-cache off
13587 Enable or disable caching of code segment accesses. When @code{on},
13588 use caching. By default, this option is @code{on}. This improves
13589 performance of disassembly in remote debugging.
13590
13591 @kindex show code-cache
13592 @item show code-cache
13593 Show the current state of target memory cache for code segment
13594 accesses.
13595
13596 @kindex info dcache
13597 @item info dcache @r{[}line@r{]}
13598 Print the information about the performance of data cache of the
13599 current inferior's address space. The information displayed
13600 includes the dcache width and depth, and for each cache line, its
13601 number, address, and how many times it was referenced. This
13602 command is useful for debugging the data cache operation.
13603
13604 If a line number is specified, the contents of that line will be
13605 printed in hex.
13606
13607 @item set dcache size @var{size}
13608 @cindex dcache size
13609 @kindex set dcache size
13610 Set maximum number of entries in dcache (dcache depth above).
13611
13612 @item set dcache line-size @var{line-size}
13613 @cindex dcache line-size
13614 @kindex set dcache line-size
13615 Set number of bytes each dcache entry caches (dcache width above).
13616 Must be a power of 2.
13617
13618 @item show dcache size
13619 @kindex show dcache size
13620 Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
13621
13622 @item show dcache line-size
13623 @kindex show dcache line-size
13624 Show default size of dcache lines.
13625
13626 @item maint flush dcache
13627 @cindex dcache, flushing
13628 @kindex maint flush dcache
13629 Flush the contents (if any) of the dcache. This maintainer command is
13630 useful when debugging the dcache implementation.
13631
13632 @end table
13633
13634 @node Searching Memory
13635 @section Search Memory
13636 @cindex searching memory
13637
13638 Memory can be searched for a particular sequence of bytes with the
13639 @code{find} command.
13640
13641 @table @code
13642 @kindex find
13643 @item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13644 @itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13645 Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13646 etc. The search begins at address @var{start_addr} and continues for either
13647 @var{len} bytes or through to @var{end_addr} inclusive.
13648 @end table
13649
13650 @var{s} and @var{n} are optional parameters.
13651 They may be specified in either order, apart or together.
13652
13653 @table @r
13654 @item @var{s}, search query size
13655 The size of each search query value.
13656
13657 @table @code
13658 @item b
13659 bytes
13660 @item h
13661 halfwords (two bytes)
13662 @item w
13663 words (four bytes)
13664 @item g
13665 giant words (eight bytes)
13666 @end table
13667
13668 All values are interpreted in the current language.
13669 This means, for example, that if the current source language is C/C@t{++}
13670 then searching for the string ``hello'' includes the trailing '\0'.
13671 The null terminator can be removed from searching by using casts,
13672 e.g.: @samp{@{char[5]@}"hello"}.
13673
13674 If the value size is not specified, it is taken from the
13675 value's type in the current language.
13676 This is useful when one wants to specify the search
13677 pattern as a mixture of types.
13678 Note that this means, for example, that in the case of C-like languages
13679 a search for an untyped 0x42 will search for @samp{(int) 0x42}
13680 which is typically four bytes.
13681
13682 @item @var{n}, maximum number of finds
13683 The maximum number of matches to print. The default is to print all finds.
13684 @end table
13685
13686 You can use strings as search values. Quote them with double-quotes
13687 (@code{"}).
13688 The string value is copied into the search pattern byte by byte,
13689 regardless of the endianness of the target and the size specification.
13690
13691 The address of each match found is printed as well as a count of the
13692 number of matches found.
13693
13694 The address of the last value found is stored in convenience variable
13695 @samp{$_}.
13696 A count of the number of matches is stored in @samp{$numfound}.
13697
13698 For example, if stopped at the @code{printf} in this function:
13699
13700 @smallexample
13701 void
13702 hello ()
13703 @{
13704 static char hello[] = "hello-hello";
13705 static struct @{ char c; short s; int i; @}
13706 __attribute__ ((packed)) mixed
13707 = @{ 'c', 0x1234, 0x87654321 @};
13708 printf ("%s\n", hello);
13709 @}
13710 @end smallexample
13711
13712 @noindent
13713 you get during debugging:
13714
13715 @smallexample
13716 (gdb) find &hello[0], +sizeof(hello), "hello"
13717 0x804956d <hello.1620+6>
13718 1 pattern found
13719 (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
13720 0x8049567 <hello.1620>
13721 0x804956d <hello.1620+6>
13722 2 patterns found.
13723 (gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
13724 0x8049567 <hello.1620>
13725 0x804956d <hello.1620+6>
13726 2 patterns found.
13727 (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
13728 0x8049567 <hello.1620>
13729 1 pattern found
13730 (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
13731 0x8049560 <mixed.1625>
13732 1 pattern found
13733 (gdb) print $numfound
13734 $1 = 1
13735 (gdb) print $_
13736 $2 = (void *) 0x8049560
13737 @end smallexample
13738
13739 @node Value Sizes
13740 @section Value Sizes
13741
13742 Whenever @value{GDBN} prints a value memory will be allocated within
13743 @value{GDBN} to hold the contents of the value. It is possible in
13744 some languages with dynamic typing systems, that an invalid program
13745 may indicate a value that is incorrectly large, this in turn may cause
13746 @value{GDBN} to try and allocate an overly large amount of memory.
13747
13748 @table @code
13749 @kindex set max-value-size
13750 @item set max-value-size @var{bytes}
13751 @itemx set max-value-size unlimited
13752 Set the maximum size of memory that @value{GDBN} will allocate for the
13753 contents of a value to @var{bytes}, trying to display a value that
13754 requires more memory than that will result in an error.
13755
13756 Setting this variable does not effect values that have already been
13757 allocated within @value{GDBN}, only future allocations.
13758
13759 There's a minimum size that @code{max-value-size} can be set to in
13760 order that @value{GDBN} can still operate correctly, this minimum is
13761 currently 16 bytes.
13762
13763 The limit applies to the results of some subexpressions as well as to
13764 complete expressions. For example, an expression denoting a simple
13765 integer component, such as @code{x.y.z}, may fail if the size of
13766 @var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
13767 @value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13768 @var{A} is an array variable with non-constant size, will generally
13769 succeed regardless of the bounds on @var{A}, as long as the component
13770 size is less than @var{bytes}.
13771
13772 The default value of @code{max-value-size} is currently 64k.
13773
13774 @kindex show max-value-size
13775 @item show max-value-size
13776 Show the maximum size of memory, in bytes, that @value{GDBN} will
13777 allocate for the contents of a value.
13778 @end table
13779
13780 @node Optimized Code
13781 @chapter Debugging Optimized Code
13782 @cindex optimized code, debugging
13783 @cindex debugging optimized code
13784
13785 Almost all compilers support optimization. With optimization
13786 disabled, the compiler generates assembly code that corresponds
13787 directly to your source code, in a simplistic way. As the compiler
13788 applies more powerful optimizations, the generated assembly code
13789 diverges from your original source code. With help from debugging
13790 information generated by the compiler, @value{GDBN} can map from
13791 the running program back to constructs from your original source.
13792
13793 @value{GDBN} is more accurate with optimization disabled. If you
13794 can recompile without optimization, it is easier to follow the
13795 progress of your program during debugging. But, there are many cases
13796 where you may need to debug an optimized version.
13797
13798 When you debug a program compiled with @samp{-g -O}, remember that the
13799 optimizer has rearranged your code; the debugger shows you what is
13800 really there. Do not be too surprised when the execution path does not
13801 exactly match your source file! An extreme example: if you define a
13802 variable, but never use it, @value{GDBN} never sees that
13803 variable---because the compiler optimizes it out of existence.
13804
13805 Some things do not work as well with @samp{-g -O} as with just
13806 @samp{-g}, particularly on machines with instruction scheduling. If in
13807 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
13808 please report it to us as a bug (including a test case!).
13809 @xref{Variables}, for more information about debugging optimized code.
13810
13811 @menu
13812 * Inline Functions:: How @value{GDBN} presents inlining
13813 * Tail Call Frames:: @value{GDBN} analysis of jumps to functions
13814 @end menu
13815
13816 @node Inline Functions
13817 @section Inline Functions
13818 @cindex inline functions, debugging
13819
13820 @dfn{Inlining} is an optimization that inserts a copy of the function
13821 body directly at each call site, instead of jumping to a shared
13822 routine. @value{GDBN} displays inlined functions just like
13823 non-inlined functions. They appear in backtraces. You can view their
13824 arguments and local variables, step into them with @code{step}, skip
13825 them with @code{next}, and escape from them with @code{finish}.
13826 You can check whether a function was inlined by using the
13827 @code{info frame} command.
13828
13829 For @value{GDBN} to support inlined functions, the compiler must
13830 record information about inlining in the debug information ---
13831 @value{NGCC} using the @sc{dwarf 2} format does this, and several
13832 other compilers do also. @value{GDBN} only supports inlined functions
13833 when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
13834 do not emit two required attributes (@samp{DW_AT_call_file} and
13835 @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
13836 function calls with earlier versions of @value{NGCC}. It instead
13837 displays the arguments and local variables of inlined functions as
13838 local variables in the caller.
13839
13840 The body of an inlined function is directly included at its call site;
13841 unlike a non-inlined function, there are no instructions devoted to
13842 the call. @value{GDBN} still pretends that the call site and the
13843 start of the inlined function are different instructions. Stepping to
13844 the call site shows the call site, and then stepping again shows
13845 the first line of the inlined function, even though no additional
13846 instructions are executed.
13847
13848 This makes source-level debugging much clearer; you can see both the
13849 context of the call and then the effect of the call. Only stepping by
13850 a single instruction using @code{stepi} or @code{nexti} does not do
13851 this; single instruction steps always show the inlined body.
13852
13853 There are some ways that @value{GDBN} does not pretend that inlined
13854 function calls are the same as normal calls:
13855
13856 @itemize @bullet
13857 @item
13858 Setting breakpoints at the call site of an inlined function may not
13859 work, because the call site does not contain any code. @value{GDBN}
13860 may incorrectly move the breakpoint to the next line of the enclosing
13861 function, after the call. This limitation will be removed in a future
13862 version of @value{GDBN}; until then, set a breakpoint on an earlier line
13863 or inside the inlined function instead.
13864
13865 @item
13866 @value{GDBN} cannot locate the return value of inlined calls after
13867 using the @code{finish} command. This is a limitation of compiler-generated
13868 debugging information; after @code{finish}, you can step to the next line
13869 and print a variable where your program stored the return value.
13870
13871 @end itemize
13872
13873 @node Tail Call Frames
13874 @section Tail Call Frames
13875 @cindex tail call frames, debugging
13876
13877 Function @code{B} can call function @code{C} in its very last statement. In
13878 unoptimized compilation the call of @code{C} is immediately followed by return
13879 instruction at the end of @code{B} code. Optimizing compiler may replace the
13880 call and return in function @code{B} into one jump to function @code{C}
13881 instead. Such use of a jump instruction is called @dfn{tail call}.
13882
13883 During execution of function @code{C}, there will be no indication in the
13884 function call stack frames that it was tail-called from @code{B}. If function
13885 @code{A} regularly calls function @code{B} which tail-calls function @code{C},
13886 then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
13887 some cases @value{GDBN} can determine that @code{C} was tail-called from
13888 @code{B}, and it will then create fictitious call frame for that, with the
13889 return address set up as if @code{B} called @code{C} normally.
13890
13891 This functionality is currently supported only by DWARF 2 debugging format and
13892 the compiler has to produce @samp{DW_TAG_call_site} tags. With
13893 @value{NGCC}, you need to specify @option{-O -g} during compilation, to get
13894 this information.
13895
13896 @kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
13897 kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
13898
13899 @smallexample
13900 (gdb) x/i $pc - 2
13901 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
13902 (gdb) info frame
13903 Stack level 1, frame at 0x7fffffffda30:
13904 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
13905 tail call frame, caller of frame at 0x7fffffffda30
13906 source language c++.
13907 Arglist at unknown address.
13908 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
13909 @end smallexample
13910
13911 The detection of all the possible code path executions can find them ambiguous.
13912 There is no execution history stored (possible @ref{Reverse Execution} is never
13913 used for this purpose) and the last known caller could have reached the known
13914 callee by multiple different jump sequences. In such case @value{GDBN} still
13915 tries to show at least all the unambiguous top tail callers and all the
13916 unambiguous bottom tail calees, if any.
13917
13918 @table @code
13919 @anchor{set debug entry-values}
13920 @item set debug entry-values
13921 @kindex set debug entry-values
13922 When set to on, enables printing of analysis messages for both frame argument
13923 values at function entry and tail calls. It will show all the possible valid
13924 tail calls code paths it has considered. It will also print the intersection
13925 of them with the final unambiguous (possibly partial or even empty) code path
13926 result.
13927
13928 @item show debug entry-values
13929 @kindex show debug entry-values
13930 Show the current state of analysis messages printing for both frame argument
13931 values at function entry and tail calls.
13932 @end table
13933
13934 The analysis messages for tail calls can for example show why the virtual tail
13935 call frame for function @code{c} has not been recognized (due to the indirect
13936 reference by variable @code{x}):
13937
13938 @smallexample
13939 static void __attribute__((noinline, noclone)) c (void);
13940 void (*x) (void) = c;
13941 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13942 static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
13943 int main (void) @{ x (); return 0; @}
13944
13945 Breakpoint 1, DW_OP_entry_value resolving cannot find
13946 DW_TAG_call_site 0x40039a in main
13947 a () at t.c:3
13948 3 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13949 (gdb) bt
13950 #0 a () at t.c:3
13951 #1 0x000000000040039a in main () at t.c:5
13952 @end smallexample
13953
13954 Another possibility is an ambiguous virtual tail call frames resolution:
13955
13956 @smallexample
13957 int i;
13958 static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
13959 static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
13960 static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
13961 static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
13962 static void __attribute__((noinline, noclone)) b (void)
13963 @{ if (i) c (); else e (); @}
13964 static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
13965 int main (void) @{ a (); return 0; @}
13966
13967 tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
13968 tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
13969 tailcall: reduced: 0x4004d2(a) |
13970 (gdb) bt
13971 #0 f () at t.c:2
13972 #1 0x00000000004004d2 in a () at t.c:8
13973 #2 0x0000000000400395 in main () at t.c:9
13974 @end smallexample
13975
13976 @set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
13977 @set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
13978
13979 @c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
13980 @ifset HAVE_MAKEINFO_CLICK
13981 @set ARROW @click{}
13982 @set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
13983 @set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
13984 @end ifset
13985 @ifclear HAVE_MAKEINFO_CLICK
13986 @set ARROW ->
13987 @set CALLSEQ1B @value{CALLSEQ1A}
13988 @set CALLSEQ2B @value{CALLSEQ2A}
13989 @end ifclear
13990
13991 Frames #0 and #2 are real, #1 is a virtual tail call frame.
13992 The code can have possible execution paths @value{CALLSEQ1B} or
13993 @value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
13994
13995 @code{initial:} state shows some random possible calling sequence @value{GDBN}
13996 has found. It then finds another possible calling sequence - that one is
13997 prefixed by @code{compare:}. The non-ambiguous intersection of these two is
13998 printed as the @code{reduced:} calling sequence. That one could have many
13999 further @code{compare:} and @code{reduced:} statements as long as there remain
14000 any non-ambiguous sequence entries.
14001
14002 For the frame of function @code{b} in both cases there are different possible
14003 @code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
14004 also ambiguous. The only non-ambiguous frame is the one for function @code{a},
14005 therefore this one is displayed to the user while the ambiguous frames are
14006 omitted.
14007
14008 There can be also reasons why printing of frame argument values at function
14009 entry may fail:
14010
14011 @smallexample
14012 int v;
14013 static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
14014 static void __attribute__((noinline, noclone)) a (int i);
14015 static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
14016 static void __attribute__((noinline, noclone)) a (int i)
14017 @{ if (i) b (i - 1); else c (0); @}
14018 int main (void) @{ a (5); return 0; @}
14019
14020 (gdb) bt
14021 #0 c (i=i@@entry=0) at t.c:2
14022 #1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
14023 function "a" at 0x400420 can call itself via tail calls
14024 i=<optimized out>) at t.c:6
14025 #2 0x000000000040036e in main () at t.c:7
14026 @end smallexample
14027
14028 @value{GDBN} cannot find out from the inferior state if and how many times did
14029 function @code{a} call itself (via function @code{b}) as these calls would be
14030 tail calls. Such tail calls would modify the @code{i} variable, therefore
14031 @value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
14032 prints @code{<optimized out>} instead.
14033
14034 @node Macros
14035 @chapter C Preprocessor Macros
14036
14037 Some languages, such as C and C@t{++}, provide a way to define and invoke
14038 ``preprocessor macros'' which expand into strings of tokens.
14039 @value{GDBN} can evaluate expressions containing macro invocations, show
14040 the result of macro expansion, and show a macro's definition, including
14041 where it was defined.
14042
14043 You may need to compile your program specially to provide @value{GDBN}
14044 with information about preprocessor macros. Most compilers do not
14045 include macros in their debugging information, even when you compile
14046 with the @option{-g} flag. @xref{Compilation}.
14047
14048 A program may define a macro at one point, remove that definition later,
14049 and then provide a different definition after that. Thus, at different
14050 points in the program, a macro may have different definitions, or have
14051 no definition at all. If there is a current stack frame, @value{GDBN}
14052 uses the macros in scope at that frame's source code line. Otherwise,
14053 @value{GDBN} uses the macros in scope at the current listing location;
14054 see @ref{List}.
14055
14056 Whenever @value{GDBN} evaluates an expression, it always expands any
14057 macro invocations present in the expression. @value{GDBN} also provides
14058 the following commands for working with macros explicitly.
14059
14060 @table @code
14061
14062 @kindex macro expand
14063 @cindex macro expansion, showing the results of preprocessor
14064 @cindex preprocessor macro expansion, showing the results of
14065 @cindex expanding preprocessor macros
14066 @item macro expand @var{expression}
14067 @itemx macro exp @var{expression}
14068 Show the results of expanding all preprocessor macro invocations in
14069 @var{expression}. Since @value{GDBN} simply expands macros, but does
14070 not parse the result, @var{expression} need not be a valid expression;
14071 it can be any string of tokens.
14072
14073 @kindex macro exp1
14074 @item macro expand-once @var{expression}
14075 @itemx macro exp1 @var{expression}
14076 @cindex expand macro once
14077 @i{(This command is not yet implemented.)} Show the results of
14078 expanding those preprocessor macro invocations that appear explicitly in
14079 @var{expression}. Macro invocations appearing in that expansion are
14080 left unchanged. This command allows you to see the effect of a
14081 particular macro more clearly, without being confused by further
14082 expansions. Since @value{GDBN} simply expands macros, but does not
14083 parse the result, @var{expression} need not be a valid expression; it
14084 can be any string of tokens.
14085
14086 @kindex info macro
14087 @cindex macro definition, showing
14088 @cindex definition of a macro, showing
14089 @cindex macros, from debug info
14090 @item info macro [-a|-all] [--] @var{macro}
14091 Show the current definition or all definitions of the named @var{macro},
14092 and describe the source location or compiler command-line where that
14093 definition was established. The optional double dash is to signify the end of
14094 argument processing and the beginning of @var{macro} for non C-like macros where
14095 the macro may begin with a hyphen.
14096
14097 @kindex info macros
14098 @item info macros @var{location}
14099 Show all macro definitions that are in effect at the location specified
14100 by @var{location}, and describe the source location or compiler
14101 command-line where those definitions were established.
14102
14103 @kindex macro define
14104 @cindex user-defined macros
14105 @cindex defining macros interactively
14106 @cindex macros, user-defined
14107 @item macro define @var{macro} @var{replacement-list}
14108 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
14109 Introduce a definition for a preprocessor macro named @var{macro},
14110 invocations of which are replaced by the tokens given in
14111 @var{replacement-list}. The first form of this command defines an
14112 ``object-like'' macro, which takes no arguments; the second form
14113 defines a ``function-like'' macro, which takes the arguments given in
14114 @var{arglist}.
14115
14116 A definition introduced by this command is in scope in every
14117 expression evaluated in @value{GDBN}, until it is removed with the
14118 @code{macro undef} command, described below. The definition overrides
14119 all definitions for @var{macro} present in the program being debugged,
14120 as well as any previous user-supplied definition.
14121
14122 @kindex macro undef
14123 @item macro undef @var{macro}
14124 Remove any user-supplied definition for the macro named @var{macro}.
14125 This command only affects definitions provided with the @code{macro
14126 define} command, described above; it cannot remove definitions present
14127 in the program being debugged.
14128
14129 @kindex macro list
14130 @item macro list
14131 List all the macros defined using the @code{macro define} command.
14132 @end table
14133
14134 @cindex macros, example of debugging with
14135 Here is a transcript showing the above commands in action. First, we
14136 show our source files:
14137
14138 @smallexample
14139 $ cat sample.c
14140 #include <stdio.h>
14141 #include "sample.h"
14142
14143 #define M 42
14144 #define ADD(x) (M + x)
14145
14146 main ()
14147 @{
14148 #define N 28
14149 printf ("Hello, world!\n");
14150 #undef N
14151 printf ("We're so creative.\n");
14152 #define N 1729
14153 printf ("Goodbye, world!\n");
14154 @}
14155 $ cat sample.h
14156 #define Q <
14157 $
14158 @end smallexample
14159
14160 Now, we compile the program using the @sc{gnu} C compiler,
14161 @value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
14162 minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
14163 and @option{-gdwarf-4}; we recommend always choosing the most recent
14164 version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
14165 includes information about preprocessor macros in the debugging
14166 information.
14167
14168 @smallexample
14169 $ gcc -gdwarf-2 -g3 sample.c -o sample
14170 $
14171 @end smallexample
14172
14173 Now, we start @value{GDBN} on our sample program:
14174
14175 @smallexample
14176 $ gdb -nw sample
14177 GNU gdb 2002-05-06-cvs
14178 Copyright 2002 Free Software Foundation, Inc.
14179 GDB is free software, @dots{}
14180 (@value{GDBP})
14181 @end smallexample
14182
14183 We can expand macros and examine their definitions, even when the
14184 program is not running. @value{GDBN} uses the current listing position
14185 to decide which macro definitions are in scope:
14186
14187 @smallexample
14188 (@value{GDBP}) list main
14189 3
14190 4 #define M 42
14191 5 #define ADD(x) (M + x)
14192 6
14193 7 main ()
14194 8 @{
14195 9 #define N 28
14196 10 printf ("Hello, world!\n");
14197 11 #undef N
14198 12 printf ("We're so creative.\n");
14199 (@value{GDBP}) info macro ADD
14200 Defined at /home/jimb/gdb/macros/play/sample.c:5
14201 #define ADD(x) (M + x)
14202 (@value{GDBP}) info macro Q
14203 Defined at /home/jimb/gdb/macros/play/sample.h:1
14204 included at /home/jimb/gdb/macros/play/sample.c:2
14205 #define Q <
14206 (@value{GDBP}) macro expand ADD(1)
14207 expands to: (42 + 1)
14208 (@value{GDBP}) macro expand-once ADD(1)
14209 expands to: once (M + 1)
14210 (@value{GDBP})
14211 @end smallexample
14212
14213 In the example above, note that @code{macro expand-once} expands only
14214 the macro invocation explicit in the original text --- the invocation of
14215 @code{ADD} --- but does not expand the invocation of the macro @code{M},
14216 which was introduced by @code{ADD}.
14217
14218 Once the program is running, @value{GDBN} uses the macro definitions in
14219 force at the source line of the current stack frame:
14220
14221 @smallexample
14222 (@value{GDBP}) break main
14223 Breakpoint 1 at 0x8048370: file sample.c, line 10.
14224 (@value{GDBP}) run
14225 Starting program: /home/jimb/gdb/macros/play/sample
14226
14227 Breakpoint 1, main () at sample.c:10
14228 10 printf ("Hello, world!\n");
14229 (@value{GDBP})
14230 @end smallexample
14231
14232 At line 10, the definition of the macro @code{N} at line 9 is in force:
14233
14234 @smallexample
14235 (@value{GDBP}) info macro N
14236 Defined at /home/jimb/gdb/macros/play/sample.c:9
14237 #define N 28
14238 (@value{GDBP}) macro expand N Q M
14239 expands to: 28 < 42
14240 (@value{GDBP}) print N Q M
14241 $1 = 1
14242 (@value{GDBP})
14243 @end smallexample
14244
14245 As we step over directives that remove @code{N}'s definition, and then
14246 give it a new definition, @value{GDBN} finds the definition (or lack
14247 thereof) in force at each point:
14248
14249 @smallexample
14250 (@value{GDBP}) next
14251 Hello, world!
14252 12 printf ("We're so creative.\n");
14253 (@value{GDBP}) info macro N
14254 The symbol `N' has no definition as a C/C++ preprocessor macro
14255 at /home/jimb/gdb/macros/play/sample.c:12
14256 (@value{GDBP}) next
14257 We're so creative.
14258 14 printf ("Goodbye, world!\n");
14259 (@value{GDBP}) info macro N
14260 Defined at /home/jimb/gdb/macros/play/sample.c:13
14261 #define N 1729
14262 (@value{GDBP}) macro expand N Q M
14263 expands to: 1729 < 42
14264 (@value{GDBP}) print N Q M
14265 $2 = 0
14266 (@value{GDBP})
14267 @end smallexample
14268
14269 In addition to source files, macros can be defined on the compilation command
14270 line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
14271 such a way, @value{GDBN} displays the location of their definition as line zero
14272 of the source file submitted to the compiler.
14273
14274 @smallexample
14275 (@value{GDBP}) info macro __STDC__
14276 Defined at /home/jimb/gdb/macros/play/sample.c:0
14277 -D__STDC__=1
14278 (@value{GDBP})
14279 @end smallexample
14280
14281
14282 @node Tracepoints
14283 @chapter Tracepoints
14284 @c This chapter is based on the documentation written by Michael
14285 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
14286
14287 @cindex tracepoints
14288 In some applications, it is not feasible for the debugger to interrupt
14289 the program's execution long enough for the developer to learn
14290 anything helpful about its behavior. If the program's correctness
14291 depends on its real-time behavior, delays introduced by a debugger
14292 might cause the program to change its behavior drastically, or perhaps
14293 fail, even when the code itself is correct. It is useful to be able
14294 to observe the program's behavior without interrupting it.
14295
14296 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
14297 specify locations in the program, called @dfn{tracepoints}, and
14298 arbitrary expressions to evaluate when those tracepoints are reached.
14299 Later, using the @code{tfind} command, you can examine the values
14300 those expressions had when the program hit the tracepoints. The
14301 expressions may also denote objects in memory---structures or arrays,
14302 for example---whose values @value{GDBN} should record; while visiting
14303 a particular tracepoint, you may inspect those objects as if they were
14304 in memory at that moment. However, because @value{GDBN} records these
14305 values without interacting with you, it can do so quickly and
14306 unobtrusively, hopefully not disturbing the program's behavior.
14307
14308 The tracepoint facility is currently available only for remote
14309 targets. @xref{Targets}. In addition, your remote target must know
14310 how to collect trace data. This functionality is implemented in the
14311 remote stub; however, none of the stubs distributed with @value{GDBN}
14312 support tracepoints as of this writing. The format of the remote
14313 packets used to implement tracepoints are described in @ref{Tracepoint
14314 Packets}.
14315
14316 It is also possible to get trace data from a file, in a manner reminiscent
14317 of corefiles; you specify the filename, and use @code{tfind} to search
14318 through the file. @xref{Trace Files}, for more details.
14319
14320 This chapter describes the tracepoint commands and features.
14321
14322 @menu
14323 * Set Tracepoints::
14324 * Analyze Collected Data::
14325 * Tracepoint Variables::
14326 * Trace Files::
14327 @end menu
14328
14329 @node Set Tracepoints
14330 @section Commands to Set Tracepoints
14331
14332 Before running such a @dfn{trace experiment}, an arbitrary number of
14333 tracepoints can be set. A tracepoint is actually a special type of
14334 breakpoint (@pxref{Set Breaks}), so you can manipulate it using
14335 standard breakpoint commands. For instance, as with breakpoints,
14336 tracepoint numbers are successive integers starting from one, and many
14337 of the commands associated with tracepoints take the tracepoint number
14338 as their argument, to identify which tracepoint to work on.
14339
14340 For each tracepoint, you can specify, in advance, some arbitrary set
14341 of data that you want the target to collect in the trace buffer when
14342 it hits that tracepoint. The collected data can include registers,
14343 local variables, or global data. Later, you can use @value{GDBN}
14344 commands to examine the values these data had at the time the
14345 tracepoint was hit.
14346
14347 Tracepoints do not support every breakpoint feature. Ignore counts on
14348 tracepoints have no effect, and tracepoints cannot run @value{GDBN}
14349 commands when they are hit. Tracepoints may not be thread-specific
14350 either.
14351
14352 @cindex fast tracepoints
14353 Some targets may support @dfn{fast tracepoints}, which are inserted in
14354 a different way (such as with a jump instead of a trap), that is
14355 faster but possibly restricted in where they may be installed.
14356
14357 @cindex static tracepoints
14358 @cindex markers, static tracepoints
14359 @cindex probing markers, static tracepoints
14360 Regular and fast tracepoints are dynamic tracing facilities, meaning
14361 that they can be used to insert tracepoints at (almost) any location
14362 in the target. Some targets may also support controlling @dfn{static
14363 tracepoints} from @value{GDBN}. With static tracing, a set of
14364 instrumentation points, also known as @dfn{markers}, are embedded in
14365 the target program, and can be activated or deactivated by name or
14366 address. These are usually placed at locations which facilitate
14367 investigating what the target is actually doing. @value{GDBN}'s
14368 support for static tracing includes being able to list instrumentation
14369 points, and attach them with @value{GDBN} defined high level
14370 tracepoints that expose the whole range of convenience of
14371 @value{GDBN}'s tracepoints support. Namely, support for collecting
14372 registers values and values of global or local (to the instrumentation
14373 point) variables; tracepoint conditions and trace state variables.
14374 The act of installing a @value{GDBN} static tracepoint on an
14375 instrumentation point, or marker, is referred to as @dfn{probing} a
14376 static tracepoint marker.
14377
14378 @code{gdbserver} supports tracepoints on some target systems.
14379 @xref{Server,,Tracepoints support in @code{gdbserver}}.
14380
14381 This section describes commands to set tracepoints and associated
14382 conditions and actions.
14383
14384 @menu
14385 * Create and Delete Tracepoints::
14386 * Enable and Disable Tracepoints::
14387 * Tracepoint Passcounts::
14388 * Tracepoint Conditions::
14389 * Trace State Variables::
14390 * Tracepoint Actions::
14391 * Listing Tracepoints::
14392 * Listing Static Tracepoint Markers::
14393 * Starting and Stopping Trace Experiments::
14394 * Tracepoint Restrictions::
14395 @end menu
14396
14397 @node Create and Delete Tracepoints
14398 @subsection Create and Delete Tracepoints
14399
14400 @table @code
14401 @cindex set tracepoint
14402 @kindex trace
14403 @item trace @var{location}
14404 The @code{trace} command is very similar to the @code{break} command.
14405 Its argument @var{location} can be any valid location.
14406 @xref{Specify Location}. The @code{trace} command defines a tracepoint,
14407 which is a point in the target program where the debugger will briefly stop,
14408 collect some data, and then allow the program to continue. Setting a tracepoint
14409 or changing its actions takes effect immediately if the remote stub
14410 supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14411 in tracing}).
14412 If remote stub doesn't support the @samp{InstallInTrace} feature, all
14413 these changes don't take effect until the next @code{tstart}
14414 command, and once a trace experiment is running, further changes will
14415 not have any effect until the next trace experiment starts. In addition,
14416 @value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14417 address is not yet resolved. (This is similar to pending breakpoints.)
14418 Pending tracepoints are not downloaded to the target and not installed
14419 until they are resolved. The resolution of pending tracepoints requires
14420 @value{GDBN} support---when debugging with the remote target, and
14421 @value{GDBN} disconnects from the remote stub (@pxref{disconnected
14422 tracing}), pending tracepoints can not be resolved (and downloaded to
14423 the remote stub) while @value{GDBN} is disconnected.
14424
14425 Here are some examples of using the @code{trace} command:
14426
14427 @smallexample
14428 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14429
14430 (@value{GDBP}) @b{trace +2} // 2 lines forward
14431
14432 (@value{GDBP}) @b{trace my_function} // first source line of function
14433
14434 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14435
14436 (@value{GDBP}) @b{trace *0x2117c4} // an address
14437 @end smallexample
14438
14439 @noindent
14440 You can abbreviate @code{trace} as @code{tr}.
14441
14442 @item trace @var{location} if @var{cond}
14443 Set a tracepoint with condition @var{cond}; evaluate the expression
14444 @var{cond} each time the tracepoint is reached, and collect data only
14445 if the value is nonzero---that is, if @var{cond} evaluates as true.
14446 @xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14447 information on tracepoint conditions.
14448
14449 @item ftrace @var{location} [ if @var{cond} ]
14450 @cindex set fast tracepoint
14451 @cindex fast tracepoints, setting
14452 @kindex ftrace
14453 The @code{ftrace} command sets a fast tracepoint. For targets that
14454 support them, fast tracepoints will use a more efficient but possibly
14455 less general technique to trigger data collection, such as a jump
14456 instruction instead of a trap, or some sort of hardware support. It
14457 may not be possible to create a fast tracepoint at the desired
14458 location, in which case the command will exit with an explanatory
14459 message.
14460
14461 @value{GDBN} handles arguments to @code{ftrace} exactly as for
14462 @code{trace}.
14463
14464 On 32-bit x86-architecture systems, fast tracepoints normally need to
14465 be placed at an instruction that is 5 bytes or longer, but can be
14466 placed at 4-byte instructions if the low 64K of memory of the target
14467 program is available to install trampolines. Some Unix-type systems,
14468 such as @sc{gnu}/Linux, exclude low addresses from the program's
14469 address space; but for instance with the Linux kernel it is possible
14470 to let @value{GDBN} use this area by doing a @command{sysctl} command
14471 to set the @code{mmap_min_addr} kernel parameter, as in
14472
14473 @example
14474 sudo sysctl -w vm.mmap_min_addr=32768
14475 @end example
14476
14477 @noindent
14478 which sets the low address to 32K, which leaves plenty of room for
14479 trampolines. The minimum address should be set to a page boundary.
14480
14481 @item strace @var{location} [ if @var{cond} ]
14482 @cindex set static tracepoint
14483 @cindex static tracepoints, setting
14484 @cindex probe static tracepoint marker
14485 @kindex strace
14486 The @code{strace} command sets a static tracepoint. For targets that
14487 support it, setting a static tracepoint probes a static
14488 instrumentation point, or marker, found at @var{location}. It may not
14489 be possible to set a static tracepoint at the desired location, in
14490 which case the command will exit with an explanatory message.
14491
14492 @value{GDBN} handles arguments to @code{strace} exactly as for
14493 @code{trace}, with the addition that the user can also specify
14494 @code{-m @var{marker}} as @var{location}. This probes the marker
14495 identified by the @var{marker} string identifier. This identifier
14496 depends on the static tracepoint backend library your program is
14497 using. You can find all the marker identifiers in the @samp{ID} field
14498 of the @code{info static-tracepoint-markers} command output.
14499 @xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14500 Markers}. For example, in the following small program using the UST
14501 tracing engine:
14502
14503 @smallexample
14504 main ()
14505 @{
14506 trace_mark(ust, bar33, "str %s", "FOOBAZ");
14507 @}
14508 @end smallexample
14509
14510 @noindent
14511 the marker id is composed of joining the first two arguments to the
14512 @code{trace_mark} call with a slash, which translates to:
14513
14514 @smallexample
14515 (@value{GDBP}) info static-tracepoint-markers
14516 Cnt Enb ID Address What
14517 1 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
14518 Data: "str %s"
14519 [etc...]
14520 @end smallexample
14521
14522 @noindent
14523 so you may probe the marker above with:
14524
14525 @smallexample
14526 (@value{GDBP}) strace -m ust/bar33
14527 @end smallexample
14528
14529 Static tracepoints accept an extra collect action --- @code{collect
14530 $_sdata}. This collects arbitrary user data passed in the probe point
14531 call to the tracing library. In the UST example above, you'll see
14532 that the third argument to @code{trace_mark} is a printf-like format
14533 string. The user data is then the result of running that formatting
14534 string against the following arguments. Note that @code{info
14535 static-tracepoint-markers} command output lists that format string in
14536 the @samp{Data:} field.
14537
14538 You can inspect this data when analyzing the trace buffer, by printing
14539 the $_sdata variable like any other variable available to
14540 @value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14541
14542 @vindex $tpnum
14543 @cindex last tracepoint number
14544 @cindex recent tracepoint number
14545 @cindex tracepoint number
14546 The convenience variable @code{$tpnum} records the tracepoint number
14547 of the most recently set tracepoint.
14548
14549 @kindex delete tracepoint
14550 @cindex tracepoint deletion
14551 @item delete tracepoint @r{[}@var{num}@r{]}
14552 Permanently delete one or more tracepoints. With no argument, the
14553 default is to delete all tracepoints. Note that the regular
14554 @code{delete} command can remove tracepoints also.
14555
14556 Examples:
14557
14558 @smallexample
14559 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14560
14561 (@value{GDBP}) @b{delete trace} // remove all tracepoints
14562 @end smallexample
14563
14564 @noindent
14565 You can abbreviate this command as @code{del tr}.
14566 @end table
14567
14568 @node Enable and Disable Tracepoints
14569 @subsection Enable and Disable Tracepoints
14570
14571 These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14572
14573 @table @code
14574 @kindex disable tracepoint
14575 @item disable tracepoint @r{[}@var{num}@r{]}
14576 Disable tracepoint @var{num}, or all tracepoints if no argument
14577 @var{num} is given. A disabled tracepoint will have no effect during
14578 a trace experiment, but it is not forgotten. You can re-enable
14579 a disabled tracepoint using the @code{enable tracepoint} command.
14580 If the command is issued during a trace experiment and the debug target
14581 has support for disabling tracepoints during a trace experiment, then the
14582 change will be effective immediately. Otherwise, it will be applied to the
14583 next trace experiment.
14584
14585 @kindex enable tracepoint
14586 @item enable tracepoint @r{[}@var{num}@r{]}
14587 Enable tracepoint @var{num}, or all tracepoints. If this command is
14588 issued during a trace experiment and the debug target supports enabling
14589 tracepoints during a trace experiment, then the enabled tracepoints will
14590 become effective immediately. Otherwise, they will become effective the
14591 next time a trace experiment is run.
14592 @end table
14593
14594 @node Tracepoint Passcounts
14595 @subsection Tracepoint Passcounts
14596
14597 @table @code
14598 @kindex passcount
14599 @cindex tracepoint pass count
14600 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14601 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
14602 automatically stop a trace experiment. If a tracepoint's passcount is
14603 @var{n}, then the trace experiment will be automatically stopped on
14604 the @var{n}'th time that tracepoint is hit. If the tracepoint number
14605 @var{num} is not specified, the @code{passcount} command sets the
14606 passcount of the most recently defined tracepoint. If no passcount is
14607 given, the trace experiment will run until stopped explicitly by the
14608 user.
14609
14610 Examples:
14611
14612 @smallexample
14613 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
14614 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
14615
14616 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
14617 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
14618 (@value{GDBP}) @b{trace foo}
14619 (@value{GDBP}) @b{pass 3}
14620 (@value{GDBP}) @b{trace bar}
14621 (@value{GDBP}) @b{pass 2}
14622 (@value{GDBP}) @b{trace baz}
14623 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
14624 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14625 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14626 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
14627 @end smallexample
14628 @end table
14629
14630 @node Tracepoint Conditions
14631 @subsection Tracepoint Conditions
14632 @cindex conditional tracepoints
14633 @cindex tracepoint conditions
14634
14635 The simplest sort of tracepoint collects data every time your program
14636 reaches a specified place. You can also specify a @dfn{condition} for
14637 a tracepoint. A condition is just a Boolean expression in your
14638 programming language (@pxref{Expressions, ,Expressions}). A
14639 tracepoint with a condition evaluates the expression each time your
14640 program reaches it, and data collection happens only if the condition
14641 is true.
14642
14643 Tracepoint conditions can be specified when a tracepoint is set, by
14644 using @samp{if} in the arguments to the @code{trace} command.
14645 @xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
14646 also be set or changed at any time with the @code{condition} command,
14647 just as with breakpoints.
14648
14649 Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14650 the conditional expression itself. Instead, @value{GDBN} encodes the
14651 expression into an agent expression (@pxref{Agent Expressions})
14652 suitable for execution on the target, independently of @value{GDBN}.
14653 Global variables become raw memory locations, locals become stack
14654 accesses, and so forth.
14655
14656 For instance, suppose you have a function that is usually called
14657 frequently, but should not be called after an error has occurred. You
14658 could use the following tracepoint command to collect data about calls
14659 of that function that happen while the error code is propagating
14660 through the program; an unconditional tracepoint could end up
14661 collecting thousands of useless trace frames that you would have to
14662 search through.
14663
14664 @smallexample
14665 (@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14666 @end smallexample
14667
14668 @node Trace State Variables
14669 @subsection Trace State Variables
14670 @cindex trace state variables
14671
14672 A @dfn{trace state variable} is a special type of variable that is
14673 created and managed by target-side code. The syntax is the same as
14674 that for GDB's convenience variables (a string prefixed with ``$''),
14675 but they are stored on the target. They must be created explicitly,
14676 using a @code{tvariable} command. They are always 64-bit signed
14677 integers.
14678
14679 Trace state variables are remembered by @value{GDBN}, and downloaded
14680 to the target along with tracepoint information when the trace
14681 experiment starts. There are no intrinsic limits on the number of
14682 trace state variables, beyond memory limitations of the target.
14683
14684 @cindex convenience variables, and trace state variables
14685 Although trace state variables are managed by the target, you can use
14686 them in print commands and expressions as if they were convenience
14687 variables; @value{GDBN} will get the current value from the target
14688 while the trace experiment is running. Trace state variables share
14689 the same namespace as other ``$'' variables, which means that you
14690 cannot have trace state variables with names like @code{$23} or
14691 @code{$pc}, nor can you have a trace state variable and a convenience
14692 variable with the same name.
14693
14694 @table @code
14695
14696 @item tvariable $@var{name} [ = @var{expression} ]
14697 @kindex tvariable
14698 The @code{tvariable} command creates a new trace state variable named
14699 @code{$@var{name}}, and optionally gives it an initial value of
14700 @var{expression}. The @var{expression} is evaluated when this command is
14701 entered; the result will be converted to an integer if possible,
14702 otherwise @value{GDBN} will report an error. A subsequent
14703 @code{tvariable} command specifying the same name does not create a
14704 variable, but instead assigns the supplied initial value to the
14705 existing variable of that name, overwriting any previous initial
14706 value. The default initial value is 0.
14707
14708 @item info tvariables
14709 @kindex info tvariables
14710 List all the trace state variables along with their initial values.
14711 Their current values may also be displayed, if the trace experiment is
14712 currently running.
14713
14714 @item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14715 @kindex delete tvariable
14716 Delete the given trace state variables, or all of them if no arguments
14717 are specified.
14718
14719 @end table
14720
14721 @node Tracepoint Actions
14722 @subsection Tracepoint Action Lists
14723
14724 @table @code
14725 @kindex actions
14726 @cindex tracepoint actions
14727 @item actions @r{[}@var{num}@r{]}
14728 This command will prompt for a list of actions to be taken when the
14729 tracepoint is hit. If the tracepoint number @var{num} is not
14730 specified, this command sets the actions for the one that was most
14731 recently defined (so that you can define a tracepoint and then say
14732 @code{actions} without bothering about its number). You specify the
14733 actions themselves on the following lines, one action at a time, and
14734 terminate the actions list with a line containing just @code{end}. So
14735 far, the only defined actions are @code{collect}, @code{teval}, and
14736 @code{while-stepping}.
14737
14738 @code{actions} is actually equivalent to @code{commands} (@pxref{Break
14739 Commands, ,Breakpoint Command Lists}), except that only the defined
14740 actions are allowed; any other @value{GDBN} command is rejected.
14741
14742 @cindex remove actions from a tracepoint
14743 To remove all actions from a tracepoint, type @samp{actions @var{num}}
14744 and follow it immediately with @samp{end}.
14745
14746 @smallexample
14747 (@value{GDBP}) @b{collect @var{data}} // collect some data
14748
14749 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
14750
14751 (@value{GDBP}) @b{end} // signals the end of actions.
14752 @end smallexample
14753
14754 In the following example, the action list begins with @code{collect}
14755 commands indicating the things to be collected when the tracepoint is
14756 hit. Then, in order to single-step and collect additional data
14757 following the tracepoint, a @code{while-stepping} command is used,
14758 followed by the list of things to be collected after each step in a
14759 sequence of single steps. The @code{while-stepping} command is
14760 terminated by its own separate @code{end} command. Lastly, the action
14761 list is terminated by an @code{end} command.
14762
14763 @smallexample
14764 (@value{GDBP}) @b{trace foo}
14765 (@value{GDBP}) @b{actions}
14766 Enter actions for tracepoint 1, one per line:
14767 > collect bar,baz
14768 > collect $regs
14769 > while-stepping 12
14770 > collect $pc, arr[i]
14771 > end
14772 end
14773 @end smallexample
14774
14775 @kindex collect @r{(tracepoints)}
14776 @item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
14777 Collect values of the given expressions when the tracepoint is hit.
14778 This command accepts a comma-separated list of any valid expressions.
14779 In addition to global, static, or local variables, the following
14780 special arguments are supported:
14781
14782 @table @code
14783 @item $regs
14784 Collect all registers.
14785
14786 @item $args
14787 Collect all function arguments.
14788
14789 @item $locals
14790 Collect all local variables.
14791
14792 @item $_ret
14793 Collect the return address. This is helpful if you want to see more
14794 of a backtrace.
14795
14796 @emph{Note:} The return address location can not always be reliably
14797 determined up front, and the wrong address / registers may end up
14798 collected instead. On some architectures the reliability is higher
14799 for tracepoints at function entry, while on others it's the opposite.
14800 When this happens, backtracing will stop because the return address is
14801 found unavailable (unless another collect rule happened to match it).
14802
14803 @item $_probe_argc
14804 Collects the number of arguments from the static probe at which the
14805 tracepoint is located.
14806 @xref{Static Probe Points}.
14807
14808 @item $_probe_arg@var{n}
14809 @var{n} is an integer between 0 and 11. Collects the @var{n}th argument
14810 from the static probe at which the tracepoint is located.
14811 @xref{Static Probe Points}.
14812
14813 @item $_sdata
14814 @vindex $_sdata@r{, collect}
14815 Collect static tracepoint marker specific data. Only available for
14816 static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
14817 Lists}. On the UST static tracepoints library backend, an
14818 instrumentation point resembles a @code{printf} function call. The
14819 tracing library is able to collect user specified data formatted to a
14820 character string using the format provided by the programmer that
14821 instrumented the program. Other backends have similar mechanisms.
14822 Here's an example of a UST marker call:
14823
14824 @smallexample
14825 const char master_name[] = "$your_name";
14826 trace_mark(channel1, marker1, "hello %s", master_name)
14827 @end smallexample
14828
14829 In this case, collecting @code{$_sdata} collects the string
14830 @samp{hello $yourname}. When analyzing the trace buffer, you can
14831 inspect @samp{$_sdata} like any other variable available to
14832 @value{GDBN}.
14833 @end table
14834
14835 You can give several consecutive @code{collect} commands, each one
14836 with a single argument, or one @code{collect} command with several
14837 arguments separated by commas; the effect is the same.
14838
14839 The optional @var{mods} changes the usual handling of the arguments.
14840 @code{s} requests that pointers to chars be handled as strings, in
14841 particular collecting the contents of the memory being pointed at, up
14842 to the first zero. The upper bound is by default the value of the
14843 @code{print elements} variable; if @code{s} is followed by a decimal
14844 number, that is the upper bound instead. So for instance
14845 @samp{collect/s25 mystr} collects as many as 25 characters at
14846 @samp{mystr}.
14847
14848 The command @code{info scope} (@pxref{Symbols, info scope}) is
14849 particularly useful for figuring out what data to collect.
14850
14851 @kindex teval @r{(tracepoints)}
14852 @item teval @var{expr1}, @var{expr2}, @dots{}
14853 Evaluate the given expressions when the tracepoint is hit. This
14854 command accepts a comma-separated list of expressions. The results
14855 are discarded, so this is mainly useful for assigning values to trace
14856 state variables (@pxref{Trace State Variables}) without adding those
14857 values to the trace buffer, as would be the case if the @code{collect}
14858 action were used.
14859
14860 @kindex while-stepping @r{(tracepoints)}
14861 @item while-stepping @var{n}
14862 Perform @var{n} single-step instruction traces after the tracepoint,
14863 collecting new data after each step. The @code{while-stepping}
14864 command is followed by the list of what to collect while stepping
14865 (followed by its own @code{end} command):
14866
14867 @smallexample
14868 > while-stepping 12
14869 > collect $regs, myglobal
14870 > end
14871 >
14872 @end smallexample
14873
14874 @noindent
14875 Note that @code{$pc} is not automatically collected by
14876 @code{while-stepping}; you need to explicitly collect that register if
14877 you need it. You may abbreviate @code{while-stepping} as @code{ws} or
14878 @code{stepping}.
14879
14880 @item set default-collect @var{expr1}, @var{expr2}, @dots{}
14881 @kindex set default-collect
14882 @cindex default collection action
14883 This variable is a list of expressions to collect at each tracepoint
14884 hit. It is effectively an additional @code{collect} action prepended
14885 to every tracepoint action list. The expressions are parsed
14886 individually for each tracepoint, so for instance a variable named
14887 @code{xyz} may be interpreted as a global for one tracepoint, and a
14888 local for another, as appropriate to the tracepoint's location.
14889
14890 @item show default-collect
14891 @kindex show default-collect
14892 Show the list of expressions that are collected by default at each
14893 tracepoint hit.
14894
14895 @end table
14896
14897 @node Listing Tracepoints
14898 @subsection Listing Tracepoints
14899
14900 @table @code
14901 @kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
14902 @kindex info tp @r{[}@var{n}@dots{}@r{]}
14903 @cindex information about tracepoints
14904 @item info tracepoints @r{[}@var{num}@dots{}@r{]}
14905 Display information about the tracepoint @var{num}. If you don't
14906 specify a tracepoint number, displays information about all the
14907 tracepoints defined so far. The format is similar to that used for
14908 @code{info breakpoints}; in fact, @code{info tracepoints} is the same
14909 command, simply restricting itself to tracepoints.
14910
14911 A tracepoint's listing may include additional information specific to
14912 tracing:
14913
14914 @itemize @bullet
14915 @item
14916 its passcount as given by the @code{passcount @var{n}} command
14917
14918 @item
14919 the state about installed on target of each location
14920 @end itemize
14921
14922 @smallexample
14923 (@value{GDBP}) @b{info trace}
14924 Num Type Disp Enb Address What
14925 1 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
14926 while-stepping 20
14927 collect globfoo, $regs
14928 end
14929 collect globfoo2
14930 end
14931 pass count 1200
14932 2 tracepoint keep y <MULTIPLE>
14933 collect $eip
14934 2.1 y 0x0804859c in func4 at change-loc.h:35
14935 installed on target
14936 2.2 y 0xb7ffc480 in func4 at change-loc.h:35
14937 installed on target
14938 2.3 y <PENDING> set_tracepoint
14939 3 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
14940 not installed on target
14941 (@value{GDBP})
14942 @end smallexample
14943
14944 @noindent
14945 This command can be abbreviated @code{info tp}.
14946 @end table
14947
14948 @node Listing Static Tracepoint Markers
14949 @subsection Listing Static Tracepoint Markers
14950
14951 @table @code
14952 @kindex info static-tracepoint-markers
14953 @cindex information about static tracepoint markers
14954 @item info static-tracepoint-markers
14955 Display information about all static tracepoint markers defined in the
14956 program.
14957
14958 For each marker, the following columns are printed:
14959
14960 @table @emph
14961 @item Count
14962 An incrementing counter, output to help readability. This is not a
14963 stable identifier.
14964 @item ID
14965 The marker ID, as reported by the target.
14966 @item Enabled or Disabled
14967 Probed markers are tagged with @samp{y}. @samp{n} identifies marks
14968 that are not enabled.
14969 @item Address
14970 Where the marker is in your program, as a memory address.
14971 @item What
14972 Where the marker is in the source for your program, as a file and line
14973 number. If the debug information included in the program does not
14974 allow @value{GDBN} to locate the source of the marker, this column
14975 will be left blank.
14976 @end table
14977
14978 @noindent
14979 In addition, the following information may be printed for each marker:
14980
14981 @table @emph
14982 @item Data
14983 User data passed to the tracing library by the marker call. In the
14984 UST backend, this is the format string passed as argument to the
14985 marker call.
14986 @item Static tracepoints probing the marker
14987 The list of static tracepoints attached to the marker.
14988 @end table
14989
14990 @smallexample
14991 (@value{GDBP}) info static-tracepoint-markers
14992 Cnt ID Enb Address What
14993 1 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
14994 Data: number1 %d number2 %d
14995 Probed by static tracepoints: #2
14996 2 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
14997 Data: str %s
14998 (@value{GDBP})
14999 @end smallexample
15000 @end table
15001
15002 @node Starting and Stopping Trace Experiments
15003 @subsection Starting and Stopping Trace Experiments
15004
15005 @table @code
15006 @kindex tstart [ @var{notes} ]
15007 @cindex start a new trace experiment
15008 @cindex collected data discarded
15009 @item tstart
15010 This command starts the trace experiment, and begins collecting data.
15011 It has the side effect of discarding all the data collected in the
15012 trace buffer during the previous trace experiment. If any arguments
15013 are supplied, they are taken as a note and stored with the trace
15014 experiment's state. The notes may be arbitrary text, and are
15015 especially useful with disconnected tracing in a multi-user context;
15016 the notes can explain what the trace is doing, supply user contact
15017 information, and so forth.
15018
15019 @kindex tstop [ @var{notes} ]
15020 @cindex stop a running trace experiment
15021 @item tstop
15022 This command stops the trace experiment. If any arguments are
15023 supplied, they are recorded with the experiment as a note. This is
15024 useful if you are stopping a trace started by someone else, for
15025 instance if the trace is interfering with the system's behavior and
15026 needs to be stopped quickly.
15027
15028 @strong{Note}: a trace experiment and data collection may stop
15029 automatically if any tracepoint's passcount is reached
15030 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
15031
15032 @kindex tstatus
15033 @cindex status of trace data collection
15034 @cindex trace experiment, status of
15035 @item tstatus
15036 This command displays the status of the current trace data
15037 collection.
15038 @end table
15039
15040 Here is an example of the commands we described so far:
15041
15042 @smallexample
15043 (@value{GDBP}) @b{trace gdb_c_test}
15044 (@value{GDBP}) @b{actions}
15045 Enter actions for tracepoint #1, one per line.
15046 > collect $regs,$locals,$args
15047 > while-stepping 11
15048 > collect $regs
15049 > end
15050 > end
15051 (@value{GDBP}) @b{tstart}
15052 [time passes @dots{}]
15053 (@value{GDBP}) @b{tstop}
15054 @end smallexample
15055
15056 @anchor{disconnected tracing}
15057 @cindex disconnected tracing
15058 You can choose to continue running the trace experiment even if
15059 @value{GDBN} disconnects from the target, voluntarily or
15060 involuntarily. For commands such as @code{detach}, the debugger will
15061 ask what you want to do with the trace. But for unexpected
15062 terminations (@value{GDBN} crash, network outage), it would be
15063 unfortunate to lose hard-won trace data, so the variable
15064 @code{disconnected-tracing} lets you decide whether the trace should
15065 continue running without @value{GDBN}.
15066
15067 @table @code
15068 @item set disconnected-tracing on
15069 @itemx set disconnected-tracing off
15070 @kindex set disconnected-tracing
15071 Choose whether a tracing run should continue to run if @value{GDBN}
15072 has disconnected from the target. Note that @code{detach} or
15073 @code{quit} will ask you directly what to do about a running trace no
15074 matter what this variable's setting, so the variable is mainly useful
15075 for handling unexpected situations, such as loss of the network.
15076
15077 @item show disconnected-tracing
15078 @kindex show disconnected-tracing
15079 Show the current choice for disconnected tracing.
15080
15081 @end table
15082
15083 When you reconnect to the target, the trace experiment may or may not
15084 still be running; it might have filled the trace buffer in the
15085 meantime, or stopped for one of the other reasons. If it is running,
15086 it will continue after reconnection.
15087
15088 Upon reconnection, the target will upload information about the
15089 tracepoints in effect. @value{GDBN} will then compare that
15090 information to the set of tracepoints currently defined, and attempt
15091 to match them up, allowing for the possibility that the numbers may
15092 have changed due to creation and deletion in the meantime. If one of
15093 the target's tracepoints does not match any in @value{GDBN}, the
15094 debugger will create a new tracepoint, so that you have a number with
15095 which to specify that tracepoint. This matching-up process is
15096 necessarily heuristic, and it may result in useless tracepoints being
15097 created; you may simply delete them if they are of no use.
15098
15099 @cindex circular trace buffer
15100 If your target agent supports a @dfn{circular trace buffer}, then you
15101 can run a trace experiment indefinitely without filling the trace
15102 buffer; when space runs out, the agent deletes already-collected trace
15103 frames, oldest first, until there is enough room to continue
15104 collecting. This is especially useful if your tracepoints are being
15105 hit too often, and your trace gets terminated prematurely because the
15106 buffer is full. To ask for a circular trace buffer, simply set
15107 @samp{circular-trace-buffer} to on. You can set this at any time,
15108 including during tracing; if the agent can do it, it will change
15109 buffer handling on the fly, otherwise it will not take effect until
15110 the next run.
15111
15112 @table @code
15113 @item set circular-trace-buffer on
15114 @itemx set circular-trace-buffer off
15115 @kindex set circular-trace-buffer
15116 Choose whether a tracing run should use a linear or circular buffer
15117 for trace data. A linear buffer will not lose any trace data, but may
15118 fill up prematurely, while a circular buffer will discard old trace
15119 data, but it will have always room for the latest tracepoint hits.
15120
15121 @item show circular-trace-buffer
15122 @kindex show circular-trace-buffer
15123 Show the current choice for the trace buffer. Note that this may not
15124 match the agent's current buffer handling, nor is it guaranteed to
15125 match the setting that might have been in effect during a past run,
15126 for instance if you are looking at frames from a trace file.
15127
15128 @end table
15129
15130 @table @code
15131 @item set trace-buffer-size @var{n}
15132 @itemx set trace-buffer-size unlimited
15133 @kindex set trace-buffer-size
15134 Request that the target use a trace buffer of @var{n} bytes. Not all
15135 targets will honor the request; they may have a compiled-in size for
15136 the trace buffer, or some other limitation. Set to a value of
15137 @code{unlimited} or @code{-1} to let the target use whatever size it
15138 likes. This is also the default.
15139
15140 @item show trace-buffer-size
15141 @kindex show trace-buffer-size
15142 Show the current requested size for the trace buffer. Note that this
15143 will only match the actual size if the target supports size-setting,
15144 and was able to handle the requested size. For instance, if the
15145 target can only change buffer size between runs, this variable will
15146 not reflect the change until the next run starts. Use @code{tstatus}
15147 to get a report of the actual buffer size.
15148 @end table
15149
15150 @table @code
15151 @item set trace-user @var{text}
15152 @kindex set trace-user
15153
15154 @item show trace-user
15155 @kindex show trace-user
15156
15157 @item set trace-notes @var{text}
15158 @kindex set trace-notes
15159 Set the trace run's notes.
15160
15161 @item show trace-notes
15162 @kindex show trace-notes
15163 Show the trace run's notes.
15164
15165 @item set trace-stop-notes @var{text}
15166 @kindex set trace-stop-notes
15167 Set the trace run's stop notes. The handling of the note is as for
15168 @code{tstop} arguments; the set command is convenient way to fix a
15169 stop note that is mistaken or incomplete.
15170
15171 @item show trace-stop-notes
15172 @kindex show trace-stop-notes
15173 Show the trace run's stop notes.
15174
15175 @end table
15176
15177 @node Tracepoint Restrictions
15178 @subsection Tracepoint Restrictions
15179
15180 @cindex tracepoint restrictions
15181 There are a number of restrictions on the use of tracepoints. As
15182 described above, tracepoint data gathering occurs on the target
15183 without interaction from @value{GDBN}. Thus the full capabilities of
15184 the debugger are not available during data gathering, and then at data
15185 examination time, you will be limited by only having what was
15186 collected. The following items describe some common problems, but it
15187 is not exhaustive, and you may run into additional difficulties not
15188 mentioned here.
15189
15190 @itemize @bullet
15191
15192 @item
15193 Tracepoint expressions are intended to gather objects (lvalues). Thus
15194 the full flexibility of GDB's expression evaluator is not available.
15195 You cannot call functions, cast objects to aggregate types, access
15196 convenience variables or modify values (except by assignment to trace
15197 state variables). Some language features may implicitly call
15198 functions (for instance Objective-C fields with accessors), and therefore
15199 cannot be collected either.
15200
15201 @item
15202 Collection of local variables, either individually or in bulk with
15203 @code{$locals} or @code{$args}, during @code{while-stepping} may
15204 behave erratically. The stepping action may enter a new scope (for
15205 instance by stepping into a function), or the location of the variable
15206 may change (for instance it is loaded into a register). The
15207 tracepoint data recorded uses the location information for the
15208 variables that is correct for the tracepoint location. When the
15209 tracepoint is created, it is not possible, in general, to determine
15210 where the steps of a @code{while-stepping} sequence will advance the
15211 program---particularly if a conditional branch is stepped.
15212
15213 @item
15214 Collection of an incompletely-initialized or partially-destroyed object
15215 may result in something that @value{GDBN} cannot display, or displays
15216 in a misleading way.
15217
15218 @item
15219 When @value{GDBN} displays a pointer to character it automatically
15220 dereferences the pointer to also display characters of the string
15221 being pointed to. However, collecting the pointer during tracing does
15222 not automatically collect the string. You need to explicitly
15223 dereference the pointer and provide size information if you want to
15224 collect not only the pointer, but the memory pointed to. For example,
15225 @code{*ptr@@50} can be used to collect the 50 element array pointed to
15226 by @code{ptr}.
15227
15228 @item
15229 It is not possible to collect a complete stack backtrace at a
15230 tracepoint. Instead, you may collect the registers and a few hundred
15231 bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
15232 (adjust to use the name of the actual stack pointer register on your
15233 target architecture, and the amount of stack you wish to capture).
15234 Then the @code{backtrace} command will show a partial backtrace when
15235 using a trace frame. The number of stack frames that can be examined
15236 depends on the sizes of the frames in the collected stack. Note that
15237 if you ask for a block so large that it goes past the bottom of the
15238 stack, the target agent may report an error trying to read from an
15239 invalid address.
15240
15241 @item
15242 If you do not collect registers at a tracepoint, @value{GDBN} can
15243 infer that the value of @code{$pc} must be the same as the address of
15244 the tracepoint and use that when you are looking at a trace frame
15245 for that tracepoint. However, this cannot work if the tracepoint has
15246 multiple locations (for instance if it was set in a function that was
15247 inlined), or if it has a @code{while-stepping} loop. In those cases
15248 @value{GDBN} will warn you that it can't infer @code{$pc}, and default
15249 it to zero.
15250
15251 @end itemize
15252
15253 @node Analyze Collected Data
15254 @section Using the Collected Data
15255
15256 After the tracepoint experiment ends, you use @value{GDBN} commands
15257 for examining the trace data. The basic idea is that each tracepoint
15258 collects a trace @dfn{snapshot} every time it is hit and another
15259 snapshot every time it single-steps. All these snapshots are
15260 consecutively numbered from zero and go into a buffer, and you can
15261 examine them later. The way you examine them is to @dfn{focus} on a
15262 specific trace snapshot. When the remote stub is focused on a trace
15263 snapshot, it will respond to all @value{GDBN} requests for memory and
15264 registers by reading from the buffer which belongs to that snapshot,
15265 rather than from @emph{real} memory or registers of the program being
15266 debugged. This means that @strong{all} @value{GDBN} commands
15267 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
15268 behave as if we were currently debugging the program state as it was
15269 when the tracepoint occurred. Any requests for data that are not in
15270 the buffer will fail.
15271
15272 @menu
15273 * tfind:: How to select a trace snapshot
15274 * tdump:: How to display all data for a snapshot
15275 * save tracepoints:: How to save tracepoints for a future run
15276 @end menu
15277
15278 @node tfind
15279 @subsection @code{tfind @var{n}}
15280
15281 @kindex tfind
15282 @cindex select trace snapshot
15283 @cindex find trace snapshot
15284 The basic command for selecting a trace snapshot from the buffer is
15285 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
15286 counting from zero. If no argument @var{n} is given, the next
15287 snapshot is selected.
15288
15289 Here are the various forms of using the @code{tfind} command.
15290
15291 @table @code
15292 @item tfind start
15293 Find the first snapshot in the buffer. This is a synonym for
15294 @code{tfind 0} (since 0 is the number of the first snapshot).
15295
15296 @item tfind none
15297 Stop debugging trace snapshots, resume @emph{live} debugging.
15298
15299 @item tfind end
15300 Same as @samp{tfind none}.
15301
15302 @item tfind
15303 No argument means find the next trace snapshot or find the first
15304 one if no trace snapshot is selected.
15305
15306 @item tfind -
15307 Find the previous trace snapshot before the current one. This permits
15308 retracing earlier steps.
15309
15310 @item tfind tracepoint @var{num}
15311 Find the next snapshot associated with tracepoint @var{num}. Search
15312 proceeds forward from the last examined trace snapshot. If no
15313 argument @var{num} is given, it means find the next snapshot collected
15314 for the same tracepoint as the current snapshot.
15315
15316 @item tfind pc @var{addr}
15317 Find the next snapshot associated with the value @var{addr} of the
15318 program counter. Search proceeds forward from the last examined trace
15319 snapshot. If no argument @var{addr} is given, it means find the next
15320 snapshot with the same value of PC as the current snapshot.
15321
15322 @item tfind outside @var{addr1}, @var{addr2}
15323 Find the next snapshot whose PC is outside the given range of
15324 addresses (exclusive).
15325
15326 @item tfind range @var{addr1}, @var{addr2}
15327 Find the next snapshot whose PC is between @var{addr1} and
15328 @var{addr2} (inclusive).
15329
15330 @item tfind line @r{[}@var{file}:@r{]}@var{n}
15331 Find the next snapshot associated with the source line @var{n}. If
15332 the optional argument @var{file} is given, refer to line @var{n} in
15333 that source file. Search proceeds forward from the last examined
15334 trace snapshot. If no argument @var{n} is given, it means find the
15335 next line other than the one currently being examined; thus saying
15336 @code{tfind line} repeatedly can appear to have the same effect as
15337 stepping from line to line in a @emph{live} debugging session.
15338 @end table
15339
15340 The default arguments for the @code{tfind} commands are specifically
15341 designed to make it easy to scan through the trace buffer. For
15342 instance, @code{tfind} with no argument selects the next trace
15343 snapshot, and @code{tfind -} with no argument selects the previous
15344 trace snapshot. So, by giving one @code{tfind} command, and then
15345 simply hitting @key{RET} repeatedly you can examine all the trace
15346 snapshots in order. Or, by saying @code{tfind -} and then hitting
15347 @key{RET} repeatedly you can examine the snapshots in reverse order.
15348 The @code{tfind line} command with no argument selects the snapshot
15349 for the next source line executed. The @code{tfind pc} command with
15350 no argument selects the next snapshot with the same program counter
15351 (PC) as the current frame. The @code{tfind tracepoint} command with
15352 no argument selects the next trace snapshot collected by the same
15353 tracepoint as the current one.
15354
15355 In addition to letting you scan through the trace buffer manually,
15356 these commands make it easy to construct @value{GDBN} scripts that
15357 scan through the trace buffer and print out whatever collected data
15358 you are interested in. Thus, if we want to examine the PC, FP, and SP
15359 registers from each trace frame in the buffer, we can say this:
15360
15361 @smallexample
15362 (@value{GDBP}) @b{tfind start}
15363 (@value{GDBP}) @b{while ($trace_frame != -1)}
15364 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
15365 $trace_frame, $pc, $sp, $fp
15366 > tfind
15367 > end
15368
15369 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
15370 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
15371 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
15372 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
15373 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
15374 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
15375 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
15376 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
15377 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
15378 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
15379 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
15380 @end smallexample
15381
15382 Or, if we want to examine the variable @code{X} at each source line in
15383 the buffer:
15384
15385 @smallexample
15386 (@value{GDBP}) @b{tfind start}
15387 (@value{GDBP}) @b{while ($trace_frame != -1)}
15388 > printf "Frame %d, X == %d\n", $trace_frame, X
15389 > tfind line
15390 > end
15391
15392 Frame 0, X = 1
15393 Frame 7, X = 2
15394 Frame 13, X = 255
15395 @end smallexample
15396
15397 @node tdump
15398 @subsection @code{tdump}
15399 @kindex tdump
15400 @cindex dump all data collected at tracepoint
15401 @cindex tracepoint data, display
15402
15403 This command takes no arguments. It prints all the data collected at
15404 the current trace snapshot.
15405
15406 @smallexample
15407 (@value{GDBP}) @b{trace 444}
15408 (@value{GDBP}) @b{actions}
15409 Enter actions for tracepoint #2, one per line:
15410 > collect $regs, $locals, $args, gdb_long_test
15411 > end
15412
15413 (@value{GDBP}) @b{tstart}
15414
15415 (@value{GDBP}) @b{tfind line 444}
15416 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15417 at gdb_test.c:444
15418 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15419
15420 (@value{GDBP}) @b{tdump}
15421 Data collected at tracepoint 2, trace frame 1:
15422 d0 0xc4aa0085 -995491707
15423 d1 0x18 24
15424 d2 0x80 128
15425 d3 0x33 51
15426 d4 0x71aea3d 119204413
15427 d5 0x22 34
15428 d6 0xe0 224
15429 d7 0x380035 3670069
15430 a0 0x19e24a 1696330
15431 a1 0x3000668 50333288
15432 a2 0x100 256
15433 a3 0x322000 3284992
15434 a4 0x3000698 50333336
15435 a5 0x1ad3cc 1758156
15436 fp 0x30bf3c 0x30bf3c
15437 sp 0x30bf34 0x30bf34
15438 ps 0x0 0
15439 pc 0x20b2c8 0x20b2c8
15440 fpcontrol 0x0 0
15441 fpstatus 0x0 0
15442 fpiaddr 0x0 0
15443 p = 0x20e5b4 "gdb-test"
15444 p1 = (void *) 0x11
15445 p2 = (void *) 0x22
15446 p3 = (void *) 0x33
15447 p4 = (void *) 0x44
15448 p5 = (void *) 0x55
15449 p6 = (void *) 0x66
15450 gdb_long_test = 17 '\021'
15451
15452 (@value{GDBP})
15453 @end smallexample
15454
15455 @code{tdump} works by scanning the tracepoint's current collection
15456 actions and printing the value of each expression listed. So
15457 @code{tdump} can fail, if after a run, you change the tracepoint's
15458 actions to mention variables that were not collected during the run.
15459
15460 Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15461 uses the collected value of @code{$pc} to distinguish between trace
15462 frames that were collected at the tracepoint hit, and frames that were
15463 collected while stepping. This allows it to correctly choose whether
15464 to display the basic list of collections, or the collections from the
15465 body of the while-stepping loop. However, if @code{$pc} was not collected,
15466 then @code{tdump} will always attempt to dump using the basic collection
15467 list, and may fail if a while-stepping frame does not include all the
15468 same data that is collected at the tracepoint hit.
15469 @c This is getting pretty arcane, example would be good.
15470
15471 @node save tracepoints
15472 @subsection @code{save tracepoints @var{filename}}
15473 @kindex save tracepoints
15474 @kindex save-tracepoints
15475 @cindex save tracepoints for future sessions
15476
15477 This command saves all current tracepoint definitions together with
15478 their actions and passcounts, into a file @file{@var{filename}}
15479 suitable for use in a later debugging session. To read the saved
15480 tracepoint definitions, use the @code{source} command (@pxref{Command
15481 Files}). The @w{@code{save-tracepoints}} command is a deprecated
15482 alias for @w{@code{save tracepoints}}
15483
15484 @node Tracepoint Variables
15485 @section Convenience Variables for Tracepoints
15486 @cindex tracepoint variables
15487 @cindex convenience variables for tracepoints
15488
15489 @table @code
15490 @vindex $trace_frame
15491 @item (int) $trace_frame
15492 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15493 snapshot is selected.
15494
15495 @vindex $tracepoint
15496 @item (int) $tracepoint
15497 The tracepoint for the current trace snapshot.
15498
15499 @vindex $trace_line
15500 @item (int) $trace_line
15501 The line number for the current trace snapshot.
15502
15503 @vindex $trace_file
15504 @item (char []) $trace_file
15505 The source file for the current trace snapshot.
15506
15507 @vindex $trace_func
15508 @item (char []) $trace_func
15509 The name of the function containing @code{$tracepoint}.
15510 @end table
15511
15512 Note: @code{$trace_file} is not suitable for use in @code{printf},
15513 use @code{output} instead.
15514
15515 Here's a simple example of using these convenience variables for
15516 stepping through all the trace snapshots and printing some of their
15517 data. Note that these are not the same as trace state variables,
15518 which are managed by the target.
15519
15520 @smallexample
15521 (@value{GDBP}) @b{tfind start}
15522
15523 (@value{GDBP}) @b{while $trace_frame != -1}
15524 > output $trace_file
15525 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15526 > tfind
15527 > end
15528 @end smallexample
15529
15530 @node Trace Files
15531 @section Using Trace Files
15532 @cindex trace files
15533
15534 In some situations, the target running a trace experiment may no
15535 longer be available; perhaps it crashed, or the hardware was needed
15536 for a different activity. To handle these cases, you can arrange to
15537 dump the trace data into a file, and later use that file as a source
15538 of trace data, via the @code{target tfile} command.
15539
15540 @table @code
15541
15542 @kindex tsave
15543 @item tsave [ -r ] @var{filename}
15544 @itemx tsave [-ctf] @var{dirname}
15545 Save the trace data to @var{filename}. By default, this command
15546 assumes that @var{filename} refers to the host filesystem, so if
15547 necessary @value{GDBN} will copy raw trace data up from the target and
15548 then save it. If the target supports it, you can also supply the
15549 optional argument @code{-r} (``remote'') to direct the target to save
15550 the data directly into @var{filename} in its own filesystem, which may be
15551 more efficient if the trace buffer is very large. (Note, however, that
15552 @code{target tfile} can only read from files accessible to the host.)
15553 By default, this command will save trace frame in tfile format.
15554 You can supply the optional argument @code{-ctf} to save data in CTF
15555 format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15556 that can be shared by multiple debugging and tracing tools. Please go to
15557 @indicateurl{http://www.efficios.com/ctf} to get more information.
15558
15559 @kindex target tfile
15560 @kindex tfile
15561 @kindex target ctf
15562 @kindex ctf
15563 @item target tfile @var{filename}
15564 @itemx target ctf @var{dirname}
15565 Use the file named @var{filename} or directory named @var{dirname} as
15566 a source of trace data. Commands that examine data work as they do with
15567 a live target, but it is not possible to run any new trace experiments.
15568 @code{tstatus} will report the state of the trace run at the moment
15569 the data was saved, as well as the current trace frame you are examining.
15570 Both @var{filename} and @var{dirname} must be on a filesystem accessible to
15571 the host.
15572
15573 @smallexample
15574 (@value{GDBP}) target ctf ctf.ctf
15575 (@value{GDBP}) tfind
15576 Found trace frame 0, tracepoint 2
15577 39 ++a; /* set tracepoint 1 here */
15578 (@value{GDBP}) tdump
15579 Data collected at tracepoint 2, trace frame 0:
15580 i = 0
15581 a = 0
15582 b = 1 '\001'
15583 c = @{"123", "456", "789", "123", "456", "789"@}
15584 d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15585 (@value{GDBP}) p b
15586 $1 = 1
15587 @end smallexample
15588
15589 @end table
15590
15591 @node Overlays
15592 @chapter Debugging Programs That Use Overlays
15593 @cindex overlays
15594
15595 If your program is too large to fit completely in your target system's
15596 memory, you can sometimes use @dfn{overlays} to work around this
15597 problem. @value{GDBN} provides some support for debugging programs that
15598 use overlays.
15599
15600 @menu
15601 * How Overlays Work:: A general explanation of overlays.
15602 * Overlay Commands:: Managing overlays in @value{GDBN}.
15603 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
15604 mapped by asking the inferior.
15605 * Overlay Sample Program:: A sample program using overlays.
15606 @end menu
15607
15608 @node How Overlays Work
15609 @section How Overlays Work
15610 @cindex mapped overlays
15611 @cindex unmapped overlays
15612 @cindex load address, overlay's
15613 @cindex mapped address
15614 @cindex overlay area
15615
15616 Suppose you have a computer whose instruction address space is only 64
15617 kilobytes long, but which has much more memory which can be accessed by
15618 other means: special instructions, segment registers, or memory
15619 management hardware, for example. Suppose further that you want to
15620 adapt a program which is larger than 64 kilobytes to run on this system.
15621
15622 One solution is to identify modules of your program which are relatively
15623 independent, and need not call each other directly; call these modules
15624 @dfn{overlays}. Separate the overlays from the main program, and place
15625 their machine code in the larger memory. Place your main program in
15626 instruction memory, but leave at least enough space there to hold the
15627 largest overlay as well.
15628
15629 Now, to call a function located in an overlay, you must first copy that
15630 overlay's machine code from the large memory into the space set aside
15631 for it in the instruction memory, and then jump to its entry point
15632 there.
15633
15634 @c NB: In the below the mapped area's size is greater or equal to the
15635 @c size of all overlays. This is intentional to remind the developer
15636 @c that overlays don't necessarily need to be the same size.
15637
15638 @smallexample
15639 @group
15640 Data Instruction Larger
15641 Address Space Address Space Address Space
15642 +-----------+ +-----------+ +-----------+
15643 | | | | | |
15644 +-----------+ +-----------+ +-----------+<-- overlay 1
15645 | program | | main | .----| overlay 1 | load address
15646 | variables | | program | | +-----------+
15647 | and heap | | | | | |
15648 +-----------+ | | | +-----------+<-- overlay 2
15649 | | +-----------+ | | | load address
15650 +-----------+ | | | .-| overlay 2 |
15651 | | | | | |
15652 mapped --->+-----------+ | | +-----------+
15653 address | | | | | |
15654 | overlay | <-' | | |
15655 | area | <---' +-----------+<-- overlay 3
15656 | | <---. | | load address
15657 +-----------+ `--| overlay 3 |
15658 | | | |
15659 +-----------+ | |
15660 +-----------+
15661 | |
15662 +-----------+
15663
15664 @anchor{A code overlay}A code overlay
15665 @end group
15666 @end smallexample
15667
15668 The diagram (@pxref{A code overlay}) shows a system with separate data
15669 and instruction address spaces. To map an overlay, the program copies
15670 its code from the larger address space to the instruction address space.
15671 Since the overlays shown here all use the same mapped address, only one
15672 may be mapped at a time. For a system with a single address space for
15673 data and instructions, the diagram would be similar, except that the
15674 program variables and heap would share an address space with the main
15675 program and the overlay area.
15676
15677 An overlay loaded into instruction memory and ready for use is called a
15678 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15679 instruction memory. An overlay not present (or only partially present)
15680 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15681 is its address in the larger memory. The mapped address is also called
15682 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15683 called the @dfn{load memory address}, or @dfn{LMA}.
15684
15685 Unfortunately, overlays are not a completely transparent way to adapt a
15686 program to limited instruction memory. They introduce a new set of
15687 global constraints you must keep in mind as you design your program:
15688
15689 @itemize @bullet
15690
15691 @item
15692 Before calling or returning to a function in an overlay, your program
15693 must make sure that overlay is actually mapped. Otherwise, the call or
15694 return will transfer control to the right address, but in the wrong
15695 overlay, and your program will probably crash.
15696
15697 @item
15698 If the process of mapping an overlay is expensive on your system, you
15699 will need to choose your overlays carefully to minimize their effect on
15700 your program's performance.
15701
15702 @item
15703 The executable file you load onto your system must contain each
15704 overlay's instructions, appearing at the overlay's load address, not its
15705 mapped address. However, each overlay's instructions must be relocated
15706 and its symbols defined as if the overlay were at its mapped address.
15707 You can use GNU linker scripts to specify different load and relocation
15708 addresses for pieces of your program; see @ref{Overlay Description,,,
15709 ld.info, Using ld: the GNU linker}.
15710
15711 @item
15712 The procedure for loading executable files onto your system must be able
15713 to load their contents into the larger address space as well as the
15714 instruction and data spaces.
15715
15716 @end itemize
15717
15718 The overlay system described above is rather simple, and could be
15719 improved in many ways:
15720
15721 @itemize @bullet
15722
15723 @item
15724 If your system has suitable bank switch registers or memory management
15725 hardware, you could use those facilities to make an overlay's load area
15726 contents simply appear at their mapped address in instruction space.
15727 This would probably be faster than copying the overlay to its mapped
15728 area in the usual way.
15729
15730 @item
15731 If your overlays are small enough, you could set aside more than one
15732 overlay area, and have more than one overlay mapped at a time.
15733
15734 @item
15735 You can use overlays to manage data, as well as instructions. In
15736 general, data overlays are even less transparent to your design than
15737 code overlays: whereas code overlays only require care when you call or
15738 return to functions, data overlays require care every time you access
15739 the data. Also, if you change the contents of a data overlay, you
15740 must copy its contents back out to its load address before you can copy a
15741 different data overlay into the same mapped area.
15742
15743 @end itemize
15744
15745
15746 @node Overlay Commands
15747 @section Overlay Commands
15748
15749 To use @value{GDBN}'s overlay support, each overlay in your program must
15750 correspond to a separate section of the executable file. The section's
15751 virtual memory address and load memory address must be the overlay's
15752 mapped and load addresses. Identifying overlays with sections allows
15753 @value{GDBN} to determine the appropriate address of a function or
15754 variable, depending on whether the overlay is mapped or not.
15755
15756 @value{GDBN}'s overlay commands all start with the word @code{overlay};
15757 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
15758
15759 @table @code
15760 @item overlay off
15761 @kindex overlay
15762 Disable @value{GDBN}'s overlay support. When overlay support is
15763 disabled, @value{GDBN} assumes that all functions and variables are
15764 always present at their mapped addresses. By default, @value{GDBN}'s
15765 overlay support is disabled.
15766
15767 @item overlay manual
15768 @cindex manual overlay debugging
15769 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
15770 relies on you to tell it which overlays are mapped, and which are not,
15771 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
15772 commands described below.
15773
15774 @item overlay map-overlay @var{overlay}
15775 @itemx overlay map @var{overlay}
15776 @cindex map an overlay
15777 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
15778 be the name of the object file section containing the overlay. When an
15779 overlay is mapped, @value{GDBN} assumes it can find the overlay's
15780 functions and variables at their mapped addresses. @value{GDBN} assumes
15781 that any other overlays whose mapped ranges overlap that of
15782 @var{overlay} are now unmapped.
15783
15784 @item overlay unmap-overlay @var{overlay}
15785 @itemx overlay unmap @var{overlay}
15786 @cindex unmap an overlay
15787 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
15788 must be the name of the object file section containing the overlay.
15789 When an overlay is unmapped, @value{GDBN} assumes it can find the
15790 overlay's functions and variables at their load addresses.
15791
15792 @item overlay auto
15793 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
15794 consults a data structure the overlay manager maintains in the inferior
15795 to see which overlays are mapped. For details, see @ref{Automatic
15796 Overlay Debugging}.
15797
15798 @item overlay load-target
15799 @itemx overlay load
15800 @cindex reloading the overlay table
15801 Re-read the overlay table from the inferior. Normally, @value{GDBN}
15802 re-reads the table @value{GDBN} automatically each time the inferior
15803 stops, so this command should only be necessary if you have changed the
15804 overlay mapping yourself using @value{GDBN}. This command is only
15805 useful when using automatic overlay debugging.
15806
15807 @item overlay list-overlays
15808 @itemx overlay list
15809 @cindex listing mapped overlays
15810 Display a list of the overlays currently mapped, along with their mapped
15811 addresses, load addresses, and sizes.
15812
15813 @end table
15814
15815 Normally, when @value{GDBN} prints a code address, it includes the name
15816 of the function the address falls in:
15817
15818 @smallexample
15819 (@value{GDBP}) print main
15820 $3 = @{int ()@} 0x11a0 <main>
15821 @end smallexample
15822 @noindent
15823 When overlay debugging is enabled, @value{GDBN} recognizes code in
15824 unmapped overlays, and prints the names of unmapped functions with
15825 asterisks around them. For example, if @code{foo} is a function in an
15826 unmapped overlay, @value{GDBN} prints it this way:
15827
15828 @smallexample
15829 (@value{GDBP}) overlay list
15830 No sections are mapped.
15831 (@value{GDBP}) print foo
15832 $5 = @{int (int)@} 0x100000 <*foo*>
15833 @end smallexample
15834 @noindent
15835 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
15836 name normally:
15837
15838 @smallexample
15839 (@value{GDBP}) overlay list
15840 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
15841 mapped at 0x1016 - 0x104a
15842 (@value{GDBP}) print foo
15843 $6 = @{int (int)@} 0x1016 <foo>
15844 @end smallexample
15845
15846 When overlay debugging is enabled, @value{GDBN} can find the correct
15847 address for functions and variables in an overlay, whether or not the
15848 overlay is mapped. This allows most @value{GDBN} commands, like
15849 @code{break} and @code{disassemble}, to work normally, even on unmapped
15850 code. However, @value{GDBN}'s breakpoint support has some limitations:
15851
15852 @itemize @bullet
15853 @item
15854 @cindex breakpoints in overlays
15855 @cindex overlays, setting breakpoints in
15856 You can set breakpoints in functions in unmapped overlays, as long as
15857 @value{GDBN} can write to the overlay at its load address.
15858 @item
15859 @value{GDBN} can not set hardware or simulator-based breakpoints in
15860 unmapped overlays. However, if you set a breakpoint at the end of your
15861 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
15862 you are using manual overlay management), @value{GDBN} will re-set its
15863 breakpoints properly.
15864 @end itemize
15865
15866
15867 @node Automatic Overlay Debugging
15868 @section Automatic Overlay Debugging
15869 @cindex automatic overlay debugging
15870
15871 @value{GDBN} can automatically track which overlays are mapped and which
15872 are not, given some simple co-operation from the overlay manager in the
15873 inferior. If you enable automatic overlay debugging with the
15874 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
15875 looks in the inferior's memory for certain variables describing the
15876 current state of the overlays.
15877
15878 Here are the variables your overlay manager must define to support
15879 @value{GDBN}'s automatic overlay debugging:
15880
15881 @table @asis
15882
15883 @item @code{_ovly_table}:
15884 This variable must be an array of the following structures:
15885
15886 @smallexample
15887 struct
15888 @{
15889 /* The overlay's mapped address. */
15890 unsigned long vma;
15891
15892 /* The size of the overlay, in bytes. */
15893 unsigned long size;
15894
15895 /* The overlay's load address. */
15896 unsigned long lma;
15897
15898 /* Non-zero if the overlay is currently mapped;
15899 zero otherwise. */
15900 unsigned long mapped;
15901 @}
15902 @end smallexample
15903
15904 @item @code{_novlys}:
15905 This variable must be a four-byte signed integer, holding the total
15906 number of elements in @code{_ovly_table}.
15907
15908 @end table
15909
15910 To decide whether a particular overlay is mapped or not, @value{GDBN}
15911 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
15912 @code{lma} members equal the VMA and LMA of the overlay's section in the
15913 executable file. When @value{GDBN} finds a matching entry, it consults
15914 the entry's @code{mapped} member to determine whether the overlay is
15915 currently mapped.
15916
15917 In addition, your overlay manager may define a function called
15918 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
15919 will silently set a breakpoint there. If the overlay manager then
15920 calls this function whenever it has changed the overlay table, this
15921 will enable @value{GDBN} to accurately keep track of which overlays
15922 are in program memory, and update any breakpoints that may be set
15923 in overlays. This will allow breakpoints to work even if the
15924 overlays are kept in ROM or other non-writable memory while they
15925 are not being executed.
15926
15927 @node Overlay Sample Program
15928 @section Overlay Sample Program
15929 @cindex overlay example program
15930
15931 When linking a program which uses overlays, you must place the overlays
15932 at their load addresses, while relocating them to run at their mapped
15933 addresses. To do this, you must write a linker script (@pxref{Overlay
15934 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
15935 since linker scripts are specific to a particular host system, target
15936 architecture, and target memory layout, this manual cannot provide
15937 portable sample code demonstrating @value{GDBN}'s overlay support.
15938
15939 However, the @value{GDBN} source distribution does contain an overlaid
15940 program, with linker scripts for a few systems, as part of its test
15941 suite. The program consists of the following files from
15942 @file{gdb/testsuite/gdb.base}:
15943
15944 @table @file
15945 @item overlays.c
15946 The main program file.
15947 @item ovlymgr.c
15948 A simple overlay manager, used by @file{overlays.c}.
15949 @item foo.c
15950 @itemx bar.c
15951 @itemx baz.c
15952 @itemx grbx.c
15953 Overlay modules, loaded and used by @file{overlays.c}.
15954 @item d10v.ld
15955 @itemx m32r.ld
15956 Linker scripts for linking the test program on the @code{d10v-elf}
15957 and @code{m32r-elf} targets.
15958 @end table
15959
15960 You can build the test program using the @code{d10v-elf} GCC
15961 cross-compiler like this:
15962
15963 @smallexample
15964 $ d10v-elf-gcc -g -c overlays.c
15965 $ d10v-elf-gcc -g -c ovlymgr.c
15966 $ d10v-elf-gcc -g -c foo.c
15967 $ d10v-elf-gcc -g -c bar.c
15968 $ d10v-elf-gcc -g -c baz.c
15969 $ d10v-elf-gcc -g -c grbx.c
15970 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
15971 baz.o grbx.o -Wl,-Td10v.ld -o overlays
15972 @end smallexample
15973
15974 The build process is identical for any other architecture, except that
15975 you must substitute the appropriate compiler and linker script for the
15976 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
15977
15978
15979 @node Languages
15980 @chapter Using @value{GDBN} with Different Languages
15981 @cindex languages
15982
15983 Although programming languages generally have common aspects, they are
15984 rarely expressed in the same manner. For instance, in ANSI C,
15985 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
15986 Modula-2, it is accomplished by @code{p^}. Values can also be
15987 represented (and displayed) differently. Hex numbers in C appear as
15988 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
15989
15990 @cindex working language
15991 Language-specific information is built into @value{GDBN} for some languages,
15992 allowing you to express operations like the above in your program's
15993 native language, and allowing @value{GDBN} to output values in a manner
15994 consistent with the syntax of your program's native language. The
15995 language you use to build expressions is called the @dfn{working
15996 language}.
15997
15998 @menu
15999 * Setting:: Switching between source languages
16000 * Show:: Displaying the language
16001 * Checks:: Type and range checks
16002 * Supported Languages:: Supported languages
16003 * Unsupported Languages:: Unsupported languages
16004 @end menu
16005
16006 @node Setting
16007 @section Switching Between Source Languages
16008
16009 There are two ways to control the working language---either have @value{GDBN}
16010 set it automatically, or select it manually yourself. You can use the
16011 @code{set language} command for either purpose. On startup, @value{GDBN}
16012 defaults to setting the language automatically. The working language is
16013 used to determine how expressions you type are interpreted, how values
16014 are printed, etc.
16015
16016 In addition to the working language, every source file that
16017 @value{GDBN} knows about has its own working language. For some object
16018 file formats, the compiler might indicate which language a particular
16019 source file is in. However, most of the time @value{GDBN} infers the
16020 language from the name of the file. The language of a source file
16021 controls whether C@t{++} names are demangled---this way @code{backtrace} can
16022 show each frame appropriately for its own language. There is no way to
16023 set the language of a source file from within @value{GDBN}, but you can
16024 set the language associated with a filename extension. @xref{Show, ,
16025 Displaying the Language}.
16026
16027 This is most commonly a problem when you use a program, such
16028 as @code{cfront} or @code{f2c}, that generates C but is written in
16029 another language. In that case, make the
16030 program use @code{#line} directives in its C output; that way
16031 @value{GDBN} will know the correct language of the source code of the original
16032 program, and will display that source code, not the generated C code.
16033
16034 @menu
16035 * Filenames:: Filename extensions and languages.
16036 * Manually:: Setting the working language manually
16037 * Automatically:: Having @value{GDBN} infer the source language
16038 @end menu
16039
16040 @node Filenames
16041 @subsection List of Filename Extensions and Languages
16042
16043 If a source file name ends in one of the following extensions, then
16044 @value{GDBN} infers that its language is the one indicated.
16045
16046 @table @file
16047 @item .ada
16048 @itemx .ads
16049 @itemx .adb
16050 @itemx .a
16051 Ada source file.
16052
16053 @item .c
16054 C source file
16055
16056 @item .C
16057 @itemx .cc
16058 @itemx .cp
16059 @itemx .cpp
16060 @itemx .cxx
16061 @itemx .c++
16062 C@t{++} source file
16063
16064 @item .d
16065 D source file
16066
16067 @item .m
16068 Objective-C source file
16069
16070 @item .f
16071 @itemx .F
16072 Fortran source file
16073
16074 @item .mod
16075 Modula-2 source file
16076
16077 @item .s
16078 @itemx .S
16079 Assembler source file. This actually behaves almost like C, but
16080 @value{GDBN} does not skip over function prologues when stepping.
16081 @end table
16082
16083 In addition, you may set the language associated with a filename
16084 extension. @xref{Show, , Displaying the Language}.
16085
16086 @node Manually
16087 @subsection Setting the Working Language
16088
16089 If you allow @value{GDBN} to set the language automatically,
16090 expressions are interpreted the same way in your debugging session and
16091 your program.
16092
16093 @kindex set language
16094 If you wish, you may set the language manually. To do this, issue the
16095 command @samp{set language @var{lang}}, where @var{lang} is the name of
16096 a language, such as
16097 @code{c} or @code{modula-2}.
16098 For a list of the supported languages, type @samp{set language}.
16099
16100 Setting the language manually prevents @value{GDBN} from updating the working
16101 language automatically. This can lead to confusion if you try
16102 to debug a program when the working language is not the same as the
16103 source language, when an expression is acceptable to both
16104 languages---but means different things. For instance, if the current
16105 source file were written in C, and @value{GDBN} was parsing Modula-2, a
16106 command such as:
16107
16108 @smallexample
16109 print a = b + c
16110 @end smallexample
16111
16112 @noindent
16113 might not have the effect you intended. In C, this means to add
16114 @code{b} and @code{c} and place the result in @code{a}. The result
16115 printed would be the value of @code{a}. In Modula-2, this means to compare
16116 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
16117
16118 @node Automatically
16119 @subsection Having @value{GDBN} Infer the Source Language
16120
16121 To have @value{GDBN} set the working language automatically, use
16122 @samp{set language local} or @samp{set language auto}. @value{GDBN}
16123 then infers the working language. That is, when your program stops in a
16124 frame (usually by encountering a breakpoint), @value{GDBN} sets the
16125 working language to the language recorded for the function in that
16126 frame. If the language for a frame is unknown (that is, if the function
16127 or block corresponding to the frame was defined in a source file that
16128 does not have a recognized extension), the current working language is
16129 not changed, and @value{GDBN} issues a warning.
16130
16131 This may not seem necessary for most programs, which are written
16132 entirely in one source language. However, program modules and libraries
16133 written in one source language can be used by a main program written in
16134 a different source language. Using @samp{set language auto} in this
16135 case frees you from having to set the working language manually.
16136
16137 @node Show
16138 @section Displaying the Language
16139
16140 The following commands help you find out which language is the
16141 working language, and also what language source files were written in.
16142
16143 @table @code
16144 @item show language
16145 @anchor{show language}
16146 @kindex show language
16147 Display the current working language. This is the
16148 language you can use with commands such as @code{print} to
16149 build and compute expressions that may involve variables in your program.
16150
16151 @item info frame
16152 @kindex info frame@r{, show the source language}
16153 Display the source language for this frame. This language becomes the
16154 working language if you use an identifier from this frame.
16155 @xref{Frame Info, ,Information about a Frame}, to identify the other
16156 information listed here.
16157
16158 @item info source
16159 @kindex info source@r{, show the source language}
16160 Display the source language of this source file.
16161 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
16162 information listed here.
16163 @end table
16164
16165 In unusual circumstances, you may have source files with extensions
16166 not in the standard list. You can then set the extension associated
16167 with a language explicitly:
16168
16169 @table @code
16170 @item set extension-language @var{ext} @var{language}
16171 @kindex set extension-language
16172 Tell @value{GDBN} that source files with extension @var{ext} are to be
16173 assumed as written in the source language @var{language}.
16174
16175 @item info extensions
16176 @kindex info extensions
16177 List all the filename extensions and the associated languages.
16178 @end table
16179
16180 @node Checks
16181 @section Type and Range Checking
16182
16183 Some languages are designed to guard you against making seemingly common
16184 errors through a series of compile- and run-time checks. These include
16185 checking the type of arguments to functions and operators and making
16186 sure mathematical overflows are caught at run time. Checks such as
16187 these help to ensure a program's correctness once it has been compiled
16188 by eliminating type mismatches and providing active checks for range
16189 errors when your program is running.
16190
16191 By default @value{GDBN} checks for these errors according to the
16192 rules of the current source language. Although @value{GDBN} does not check
16193 the statements in your program, it can check expressions entered directly
16194 into @value{GDBN} for evaluation via the @code{print} command, for example.
16195
16196 @menu
16197 * Type Checking:: An overview of type checking
16198 * Range Checking:: An overview of range checking
16199 @end menu
16200
16201 @cindex type checking
16202 @cindex checks, type
16203 @node Type Checking
16204 @subsection An Overview of Type Checking
16205
16206 Some languages, such as C and C@t{++}, are strongly typed, meaning that the
16207 arguments to operators and functions have to be of the correct type,
16208 otherwise an error occurs. These checks prevent type mismatch
16209 errors from ever causing any run-time problems. For example,
16210
16211 @smallexample
16212 int klass::my_method(char *b) @{ return b ? 1 : 2; @}
16213
16214 (@value{GDBP}) print obj.my_method (0)
16215 $1 = 2
16216 @exdent but
16217 (@value{GDBP}) print obj.my_method (0x1234)
16218 Cannot resolve method klass::my_method to any overloaded instance
16219 @end smallexample
16220
16221 The second example fails because in C@t{++} the integer constant
16222 @samp{0x1234} is not type-compatible with the pointer parameter type.
16223
16224 For the expressions you use in @value{GDBN} commands, you can tell
16225 @value{GDBN} to not enforce strict type checking or
16226 to treat any mismatches as errors and abandon the expression;
16227 When type checking is disabled, @value{GDBN} successfully evaluates
16228 expressions like the second example above.
16229
16230 Even if type checking is off, there may be other reasons
16231 related to type that prevent @value{GDBN} from evaluating an expression.
16232 For instance, @value{GDBN} does not know how to add an @code{int} and
16233 a @code{struct foo}. These particular type errors have nothing to do
16234 with the language in use and usually arise from expressions which make
16235 little sense to evaluate anyway.
16236
16237 @value{GDBN} provides some additional commands for controlling type checking:
16238
16239 @kindex set check type
16240 @kindex show check type
16241 @table @code
16242 @item set check type on
16243 @itemx set check type off
16244 Set strict type checking on or off. If any type mismatches occur in
16245 evaluating an expression while type checking is on, @value{GDBN} prints a
16246 message and aborts evaluation of the expression.
16247
16248 @item show check type
16249 Show the current setting of type checking and whether @value{GDBN}
16250 is enforcing strict type checking rules.
16251 @end table
16252
16253 @cindex range checking
16254 @cindex checks, range
16255 @node Range Checking
16256 @subsection An Overview of Range Checking
16257
16258 In some languages (such as Modula-2), it is an error to exceed the
16259 bounds of a type; this is enforced with run-time checks. Such range
16260 checking is meant to ensure program correctness by making sure
16261 computations do not overflow, or indices on an array element access do
16262 not exceed the bounds of the array.
16263
16264 For expressions you use in @value{GDBN} commands, you can tell
16265 @value{GDBN} to treat range errors in one of three ways: ignore them,
16266 always treat them as errors and abandon the expression, or issue
16267 warnings but evaluate the expression anyway.
16268
16269 A range error can result from numerical overflow, from exceeding an
16270 array index bound, or when you type a constant that is not a member
16271 of any type. Some languages, however, do not treat overflows as an
16272 error. In many implementations of C, mathematical overflow causes the
16273 result to ``wrap around'' to lower values---for example, if @var{m} is
16274 the largest integer value, and @var{s} is the smallest, then
16275
16276 @smallexample
16277 @var{m} + 1 @result{} @var{s}
16278 @end smallexample
16279
16280 This, too, is specific to individual languages, and in some cases
16281 specific to individual compilers or machines. @xref{Supported Languages, ,
16282 Supported Languages}, for further details on specific languages.
16283
16284 @value{GDBN} provides some additional commands for controlling the range checker:
16285
16286 @kindex set check range
16287 @kindex show check range
16288 @table @code
16289 @item set check range auto
16290 Set range checking on or off based on the current working language.
16291 @xref{Supported Languages, ,Supported Languages}, for the default settings for
16292 each language.
16293
16294 @item set check range on
16295 @itemx set check range off
16296 Set range checking on or off, overriding the default setting for the
16297 current working language. A warning is issued if the setting does not
16298 match the language default. If a range error occurs and range checking is on,
16299 then a message is printed and evaluation of the expression is aborted.
16300
16301 @item set check range warn
16302 Output messages when the @value{GDBN} range checker detects a range error,
16303 but attempt to evaluate the expression anyway. Evaluating the
16304 expression may still be impossible for other reasons, such as accessing
16305 memory that the process does not own (a typical example from many Unix
16306 systems).
16307
16308 @item show check range
16309 Show the current setting of the range checker, and whether or not it is
16310 being set automatically by @value{GDBN}.
16311 @end table
16312
16313 @node Supported Languages
16314 @section Supported Languages
16315
16316 @value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
16317 OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
16318 @c This is false ...
16319 Some @value{GDBN} features may be used in expressions regardless of the
16320 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
16321 and the @samp{@{type@}addr} construct (@pxref{Expressions,
16322 ,Expressions}) can be used with the constructs of any supported
16323 language.
16324
16325 The following sections detail to what degree each source language is
16326 supported by @value{GDBN}. These sections are not meant to be language
16327 tutorials or references, but serve only as a reference guide to what the
16328 @value{GDBN} expression parser accepts, and what input and output
16329 formats should look like for different languages. There are many good
16330 books written on each of these languages; please look to these for a
16331 language reference or tutorial.
16332
16333 @menu
16334 * C:: C and C@t{++}
16335 * D:: D
16336 * Go:: Go
16337 * Objective-C:: Objective-C
16338 * OpenCL C:: OpenCL C
16339 * Fortran:: Fortran
16340 * Pascal:: Pascal
16341 * Rust:: Rust
16342 * Modula-2:: Modula-2
16343 * Ada:: Ada
16344 @end menu
16345
16346 @node C
16347 @subsection C and C@t{++}
16348
16349 @cindex C and C@t{++}
16350 @cindex expressions in C or C@t{++}
16351
16352 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
16353 to both languages. Whenever this is the case, we discuss those languages
16354 together.
16355
16356 @cindex C@t{++}
16357 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
16358 @cindex @sc{gnu} C@t{++}
16359 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
16360 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
16361 effectively, you must compile your C@t{++} programs with a supported
16362 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
16363 compiler (@code{aCC}).
16364
16365 @menu
16366 * C Operators:: C and C@t{++} operators
16367 * C Constants:: C and C@t{++} constants
16368 * C Plus Plus Expressions:: C@t{++} expressions
16369 * C Defaults:: Default settings for C and C@t{++}
16370 * C Checks:: C and C@t{++} type and range checks
16371 * Debugging C:: @value{GDBN} and C
16372 * Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
16373 * Decimal Floating Point:: Numbers in Decimal Floating Point format
16374 @end menu
16375
16376 @node C Operators
16377 @subsubsection C and C@t{++} Operators
16378
16379 @cindex C and C@t{++} operators
16380
16381 Operators must be defined on values of specific types. For instance,
16382 @code{+} is defined on numbers, but not on structures. Operators are
16383 often defined on groups of types.
16384
16385 For the purposes of C and C@t{++}, the following definitions hold:
16386
16387 @itemize @bullet
16388
16389 @item
16390 @emph{Integral types} include @code{int} with any of its storage-class
16391 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
16392
16393 @item
16394 @emph{Floating-point types} include @code{float}, @code{double}, and
16395 @code{long double} (if supported by the target platform).
16396
16397 @item
16398 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
16399
16400 @item
16401 @emph{Scalar types} include all of the above.
16402
16403 @end itemize
16404
16405 @noindent
16406 The following operators are supported. They are listed here
16407 in order of increasing precedence:
16408
16409 @table @code
16410 @item ,
16411 The comma or sequencing operator. Expressions in a comma-separated list
16412 are evaluated from left to right, with the result of the entire
16413 expression being the last expression evaluated.
16414
16415 @item =
16416 Assignment. The value of an assignment expression is the value
16417 assigned. Defined on scalar types.
16418
16419 @item @var{op}=
16420 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16421 and translated to @w{@code{@var{a} = @var{a op b}}}.
16422 @w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
16423 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16424 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16425
16426 @item ?:
16427 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
16428 of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16429 should be of an integral type.
16430
16431 @item ||
16432 Logical @sc{or}. Defined on integral types.
16433
16434 @item &&
16435 Logical @sc{and}. Defined on integral types.
16436
16437 @item |
16438 Bitwise @sc{or}. Defined on integral types.
16439
16440 @item ^
16441 Bitwise exclusive-@sc{or}. Defined on integral types.
16442
16443 @item &
16444 Bitwise @sc{and}. Defined on integral types.
16445
16446 @item ==@r{, }!=
16447 Equality and inequality. Defined on scalar types. The value of these
16448 expressions is 0 for false and non-zero for true.
16449
16450 @item <@r{, }>@r{, }<=@r{, }>=
16451 Less than, greater than, less than or equal, greater than or equal.
16452 Defined on scalar types. The value of these expressions is 0 for false
16453 and non-zero for true.
16454
16455 @item <<@r{, }>>
16456 left shift, and right shift. Defined on integral types.
16457
16458 @item @@
16459 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16460
16461 @item +@r{, }-
16462 Addition and subtraction. Defined on integral types, floating-point types and
16463 pointer types.
16464
16465 @item *@r{, }/@r{, }%
16466 Multiplication, division, and modulus. Multiplication and division are
16467 defined on integral and floating-point types. Modulus is defined on
16468 integral types.
16469
16470 @item ++@r{, }--
16471 Increment and decrement. When appearing before a variable, the
16472 operation is performed before the variable is used in an expression;
16473 when appearing after it, the variable's value is used before the
16474 operation takes place.
16475
16476 @item *
16477 Pointer dereferencing. Defined on pointer types. Same precedence as
16478 @code{++}.
16479
16480 @item &
16481 Address operator. Defined on variables. Same precedence as @code{++}.
16482
16483 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16484 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
16485 to examine the address
16486 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
16487 stored.
16488
16489 @item -
16490 Negative. Defined on integral and floating-point types. Same
16491 precedence as @code{++}.
16492
16493 @item !
16494 Logical negation. Defined on integral types. Same precedence as
16495 @code{++}.
16496
16497 @item ~
16498 Bitwise complement operator. Defined on integral types. Same precedence as
16499 @code{++}.
16500
16501
16502 @item .@r{, }->
16503 Structure member, and pointer-to-structure member. For convenience,
16504 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
16505 pointer based on the stored type information.
16506 Defined on @code{struct} and @code{union} data.
16507
16508 @item .*@r{, }->*
16509 Dereferences of pointers to members.
16510
16511 @item []
16512 Array indexing. @code{@var{a}[@var{i}]} is defined as
16513 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
16514
16515 @item ()
16516 Function parameter list. Same precedence as @code{->}.
16517
16518 @item ::
16519 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
16520 and @code{class} types.
16521
16522 @item ::
16523 Doubled colons also represent the @value{GDBN} scope operator
16524 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
16525 above.
16526 @end table
16527
16528 If an operator is redefined in the user code, @value{GDBN} usually
16529 attempts to invoke the redefined version instead of using the operator's
16530 predefined meaning.
16531
16532 @node C Constants
16533 @subsubsection C and C@t{++} Constants
16534
16535 @cindex C and C@t{++} constants
16536
16537 @value{GDBN} allows you to express the constants of C and C@t{++} in the
16538 following ways:
16539
16540 @itemize @bullet
16541 @item
16542 Integer constants are a sequence of digits. Octal constants are
16543 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16544 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
16545 @samp{l}, specifying that the constant should be treated as a
16546 @code{long} value.
16547
16548 @item
16549 Floating point constants are a sequence of digits, followed by a decimal
16550 point, followed by a sequence of digits, and optionally followed by an
16551 exponent. An exponent is of the form:
16552 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16553 sequence of digits. The @samp{+} is optional for positive exponents.
16554 A floating-point constant may also end with a letter @samp{f} or
16555 @samp{F}, specifying that the constant should be treated as being of
16556 the @code{float} (as opposed to the default @code{double}) type; or with
16557 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16558 constant.
16559
16560 @item
16561 Enumerated constants consist of enumerated identifiers, or their
16562 integral equivalents.
16563
16564 @item
16565 Character constants are a single character surrounded by single quotes
16566 (@code{'}), or a number---the ordinal value of the corresponding character
16567 (usually its @sc{ascii} value). Within quotes, the single character may
16568 be represented by a letter or by @dfn{escape sequences}, which are of
16569 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16570 of the character's ordinal value; or of the form @samp{\@var{x}}, where
16571 @samp{@var{x}} is a predefined special character---for example,
16572 @samp{\n} for newline.
16573
16574 Wide character constants can be written by prefixing a character
16575 constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
16576 form of @samp{x}. The target wide character set is used when
16577 computing the value of this constant (@pxref{Character Sets}).
16578
16579 @item
16580 String constants are a sequence of character constants surrounded by
16581 double quotes (@code{"}). Any valid character constant (as described
16582 above) may appear. Double quotes within the string must be preceded by
16583 a backslash, so for instance @samp{"a\"b'c"} is a string of five
16584 characters.
16585
16586 Wide string constants can be written by prefixing a string constant
16587 with @samp{L}, as in C. The target wide character set is used when
16588 computing the value of this constant (@pxref{Character Sets}).
16589
16590 @item
16591 Pointer constants are an integral value. You can also write pointers
16592 to constants using the C operator @samp{&}.
16593
16594 @item
16595 Array constants are comma-separated lists surrounded by braces @samp{@{}
16596 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16597 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16598 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16599 @end itemize
16600
16601 @node C Plus Plus Expressions
16602 @subsubsection C@t{++} Expressions
16603
16604 @cindex expressions in C@t{++}
16605 @value{GDBN} expression handling can interpret most C@t{++} expressions.
16606
16607 @cindex debugging C@t{++} programs
16608 @cindex C@t{++} compilers
16609 @cindex debug formats and C@t{++}
16610 @cindex @value{NGCC} and C@t{++}
16611 @quotation
16612 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16613 the proper compiler and the proper debug format. Currently,
16614 @value{GDBN} works best when debugging C@t{++} code that is compiled
16615 with the most recent version of @value{NGCC} possible. The DWARF
16616 debugging format is preferred; @value{NGCC} defaults to this on most
16617 popular platforms. Other compilers and/or debug formats are likely to
16618 work badly or not at all when using @value{GDBN} to debug C@t{++}
16619 code. @xref{Compilation}.
16620 @end quotation
16621
16622 @enumerate
16623
16624 @cindex member functions
16625 @item
16626 Member function calls are allowed; you can use expressions like
16627
16628 @smallexample
16629 count = aml->GetOriginal(x, y)
16630 @end smallexample
16631
16632 @vindex this@r{, inside C@t{++} member functions}
16633 @cindex namespace in C@t{++}
16634 @item
16635 While a member function is active (in the selected stack frame), your
16636 expressions have the same namespace available as the member function;
16637 that is, @value{GDBN} allows implicit references to the class instance
16638 pointer @code{this} following the same rules as C@t{++}. @code{using}
16639 declarations in the current scope are also respected by @value{GDBN}.
16640
16641 @cindex call overloaded functions
16642 @cindex overloaded functions, calling
16643 @cindex type conversions in C@t{++}
16644 @item
16645 You can call overloaded functions; @value{GDBN} resolves the function
16646 call to the right definition, with some restrictions. @value{GDBN} does not
16647 perform overload resolution involving user-defined type conversions,
16648 calls to constructors, or instantiations of templates that do not exist
16649 in the program. It also cannot handle ellipsis argument lists or
16650 default arguments.
16651
16652 It does perform integral conversions and promotions, floating-point
16653 promotions, arithmetic conversions, pointer conversions, conversions of
16654 class objects to base classes, and standard conversions such as those of
16655 functions or arrays to pointers; it requires an exact match on the
16656 number of function arguments.
16657
16658 Overload resolution is always performed, unless you have specified
16659 @code{set overload-resolution off}. @xref{Debugging C Plus Plus,
16660 ,@value{GDBN} Features for C@t{++}}.
16661
16662 You must specify @code{set overload-resolution off} in order to use an
16663 explicit function signature to call an overloaded function, as in
16664 @smallexample
16665 p 'foo(char,int)'('x', 13)
16666 @end smallexample
16667
16668 The @value{GDBN} command-completion facility can simplify this;
16669 see @ref{Completion, ,Command Completion}.
16670
16671 @cindex reference declarations
16672 @item
16673 @value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16674 references; you can use them in expressions just as you do in C@t{++}
16675 source---they are automatically dereferenced.
16676
16677 In the parameter list shown when @value{GDBN} displays a frame, the values of
16678 reference variables are not displayed (unlike other variables); this
16679 avoids clutter, since references are often used for large structures.
16680 The @emph{address} of a reference variable is always shown, unless
16681 you have specified @samp{set print address off}.
16682
16683 @item
16684 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
16685 expressions can use it just as expressions in your program do. Since
16686 one scope may be defined in another, you can use @code{::} repeatedly if
16687 necessary, for example in an expression like
16688 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
16689 resolving name scope by reference to source files, in both C and C@t{++}
16690 debugging (@pxref{Variables, ,Program Variables}).
16691
16692 @item
16693 @value{GDBN} performs argument-dependent lookup, following the C@t{++}
16694 specification.
16695 @end enumerate
16696
16697 @node C Defaults
16698 @subsubsection C and C@t{++} Defaults
16699
16700 @cindex C and C@t{++} defaults
16701
16702 If you allow @value{GDBN} to set range checking automatically, it
16703 defaults to @code{off} whenever the working language changes to
16704 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
16705 selects the working language.
16706
16707 If you allow @value{GDBN} to set the language automatically, it
16708 recognizes source files whose names end with @file{.c}, @file{.C}, or
16709 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
16710 these files, it sets the working language to C or C@t{++}.
16711 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
16712 for further details.
16713
16714 @node C Checks
16715 @subsubsection C and C@t{++} Type and Range Checks
16716
16717 @cindex C and C@t{++} checks
16718
16719 By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16720 checking is used. However, if you turn type checking off, @value{GDBN}
16721 will allow certain non-standard conversions, such as promoting integer
16722 constants to pointers.
16723
16724 Range checking, if turned on, is done on mathematical operations. Array
16725 indices are not checked, since they are often used to index a pointer
16726 that is not itself an array.
16727
16728 @node Debugging C
16729 @subsubsection @value{GDBN} and C
16730
16731 The @code{set print union} and @code{show print union} commands apply to
16732 the @code{union} type. When set to @samp{on}, any @code{union} that is
16733 inside a @code{struct} or @code{class} is also printed. Otherwise, it
16734 appears as @samp{@{...@}}.
16735
16736 The @code{@@} operator aids in the debugging of dynamic arrays, formed
16737 with pointers and a memory allocation function. @xref{Expressions,
16738 ,Expressions}.
16739
16740 @node Debugging C Plus Plus
16741 @subsubsection @value{GDBN} Features for C@t{++}
16742
16743 @cindex commands for C@t{++}
16744
16745 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16746 designed specifically for use with C@t{++}. Here is a summary:
16747
16748 @table @code
16749 @cindex break in overloaded functions
16750 @item @r{breakpoint menus}
16751 When you want a breakpoint in a function whose name is overloaded,
16752 @value{GDBN} has the capability to display a menu of possible breakpoint
16753 locations to help you specify which function definition you want.
16754 @xref{Ambiguous Expressions,,Ambiguous Expressions}.
16755
16756 @cindex overloading in C@t{++}
16757 @item rbreak @var{regex}
16758 Setting breakpoints using regular expressions is helpful for setting
16759 breakpoints on overloaded functions that are not members of any special
16760 classes.
16761 @xref{Set Breaks, ,Setting Breakpoints}.
16762
16763 @cindex C@t{++} exception handling
16764 @item catch throw
16765 @itemx catch rethrow
16766 @itemx catch catch
16767 Debug C@t{++} exception handling using these commands. @xref{Set
16768 Catchpoints, , Setting Catchpoints}.
16769
16770 @cindex inheritance
16771 @item ptype @var{typename}
16772 Print inheritance relationships as well as other information for type
16773 @var{typename}.
16774 @xref{Symbols, ,Examining the Symbol Table}.
16775
16776 @item info vtbl @var{expression}.
16777 The @code{info vtbl} command can be used to display the virtual
16778 method tables of the object computed by @var{expression}. This shows
16779 one entry per virtual table; there may be multiple virtual tables when
16780 multiple inheritance is in use.
16781
16782 @cindex C@t{++} demangling
16783 @item demangle @var{name}
16784 Demangle @var{name}.
16785 @xref{Symbols}, for a more complete description of the @code{demangle} command.
16786
16787 @cindex C@t{++} symbol display
16788 @item set print demangle
16789 @itemx show print demangle
16790 @itemx set print asm-demangle
16791 @itemx show print asm-demangle
16792 Control whether C@t{++} symbols display in their source form, both when
16793 displaying code as C@t{++} source and when displaying disassemblies.
16794 @xref{Print Settings, ,Print Settings}.
16795
16796 @item set print object
16797 @itemx show print object
16798 Choose whether to print derived (actual) or declared types of objects.
16799 @xref{Print Settings, ,Print Settings}.
16800
16801 @item set print vtbl
16802 @itemx show print vtbl
16803 Control the format for printing virtual function tables.
16804 @xref{Print Settings, ,Print Settings}.
16805 (The @code{vtbl} commands do not work on programs compiled with the HP
16806 ANSI C@t{++} compiler (@code{aCC}).)
16807
16808 @kindex set overload-resolution
16809 @cindex overloaded functions, overload resolution
16810 @item set overload-resolution on
16811 Enable overload resolution for C@t{++} expression evaluation. The default
16812 is on. For overloaded functions, @value{GDBN} evaluates the arguments
16813 and searches for a function whose signature matches the argument types,
16814 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
16815 Expressions, ,C@t{++} Expressions}, for details).
16816 If it cannot find a match, it emits a message.
16817
16818 @item set overload-resolution off
16819 Disable overload resolution for C@t{++} expression evaluation. For
16820 overloaded functions that are not class member functions, @value{GDBN}
16821 chooses the first function of the specified name that it finds in the
16822 symbol table, whether or not its arguments are of the correct type. For
16823 overloaded functions that are class member functions, @value{GDBN}
16824 searches for a function whose signature @emph{exactly} matches the
16825 argument types.
16826
16827 @kindex show overload-resolution
16828 @item show overload-resolution
16829 Show the current setting of overload resolution.
16830
16831 @item @r{Overloaded symbol names}
16832 You can specify a particular definition of an overloaded symbol, using
16833 the same notation that is used to declare such symbols in C@t{++}: type
16834 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
16835 also use the @value{GDBN} command-line word completion facilities to list the
16836 available choices, or to finish the type list for you.
16837 @xref{Completion,, Command Completion}, for details on how to do this.
16838
16839 @item @r{Breakpoints in functions with ABI tags}
16840
16841 The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
16842 correspond to changes in the ABI of a type, function, or variable that
16843 would not otherwise be reflected in a mangled name. See
16844 @url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
16845 for more detail.
16846
16847 The ABI tags are visible in C@t{++} demangled names. For example, a
16848 function that returns a std::string:
16849
16850 @smallexample
16851 std::string function(int);
16852 @end smallexample
16853
16854 @noindent
16855 when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
16856 tag, and @value{GDBN} displays the symbol like this:
16857
16858 @smallexample
16859 function[abi:cxx11](int)
16860 @end smallexample
16861
16862 You can set a breakpoint on such functions simply as if they had no
16863 tag. For example:
16864
16865 @smallexample
16866 (gdb) b function(int)
16867 Breakpoint 2 at 0x40060d: file main.cc, line 10.
16868 (gdb) info breakpoints
16869 Num Type Disp Enb Address What
16870 1 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
16871 at main.cc:10
16872 @end smallexample
16873
16874 On the rare occasion you need to disambiguate between different ABI
16875 tags, you can do so by simply including the ABI tag in the function
16876 name, like:
16877
16878 @smallexample
16879 (@value{GDBP}) b ambiguous[abi:other_tag](int)
16880 @end smallexample
16881 @end table
16882
16883 @node Decimal Floating Point
16884 @subsubsection Decimal Floating Point format
16885 @cindex decimal floating point format
16886
16887 @value{GDBN} can examine, set and perform computations with numbers in
16888 decimal floating point format, which in the C language correspond to the
16889 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
16890 specified by the extension to support decimal floating-point arithmetic.
16891
16892 There are two encodings in use, depending on the architecture: BID (Binary
16893 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
16894 PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
16895 configured target.
16896
16897 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
16898 to manipulate decimal floating point numbers, it is not possible to convert
16899 (using a cast, for example) integers wider than 32-bit to decimal float.
16900
16901 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
16902 point computations, error checking in decimal float operations ignores
16903 underflow, overflow and divide by zero exceptions.
16904
16905 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
16906 to inspect @code{_Decimal128} values stored in floating point registers.
16907 See @ref{PowerPC,,PowerPC} for more details.
16908
16909 @node D
16910 @subsection D
16911
16912 @cindex D
16913 @value{GDBN} can be used to debug programs written in D and compiled with
16914 GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
16915 specific feature --- dynamic arrays.
16916
16917 @node Go
16918 @subsection Go
16919
16920 @cindex Go (programming language)
16921 @value{GDBN} can be used to debug programs written in Go and compiled with
16922 @file{gccgo} or @file{6g} compilers.
16923
16924 Here is a summary of the Go-specific features and restrictions:
16925
16926 @table @code
16927 @cindex current Go package
16928 @item The current Go package
16929 The name of the current package does not need to be specified when
16930 specifying global variables and functions.
16931
16932 For example, given the program:
16933
16934 @example
16935 package main
16936 var myglob = "Shall we?"
16937 func main () @{
16938 // ...
16939 @}
16940 @end example
16941
16942 When stopped inside @code{main} either of these work:
16943
16944 @example
16945 (gdb) p myglob
16946 (gdb) p main.myglob
16947 @end example
16948
16949 @cindex builtin Go types
16950 @item Builtin Go types
16951 The @code{string} type is recognized by @value{GDBN} and is printed
16952 as a string.
16953
16954 @cindex builtin Go functions
16955 @item Builtin Go functions
16956 The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
16957 function and handles it internally.
16958
16959 @cindex restrictions on Go expressions
16960 @item Restrictions on Go expressions
16961 All Go operators are supported except @code{&^}.
16962 The Go @code{_} ``blank identifier'' is not supported.
16963 Automatic dereferencing of pointers is not supported.
16964 @end table
16965
16966 @node Objective-C
16967 @subsection Objective-C
16968
16969 @cindex Objective-C
16970 This section provides information about some commands and command
16971 options that are useful for debugging Objective-C code. See also
16972 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
16973 few more commands specific to Objective-C support.
16974
16975 @menu
16976 * Method Names in Commands::
16977 * The Print Command with Objective-C::
16978 @end menu
16979
16980 @node Method Names in Commands
16981 @subsubsection Method Names in Commands
16982
16983 The following commands have been extended to accept Objective-C method
16984 names as line specifications:
16985
16986 @kindex clear@r{, and Objective-C}
16987 @kindex break@r{, and Objective-C}
16988 @kindex info line@r{, and Objective-C}
16989 @kindex jump@r{, and Objective-C}
16990 @kindex list@r{, and Objective-C}
16991 @itemize
16992 @item @code{clear}
16993 @item @code{break}
16994 @item @code{info line}
16995 @item @code{jump}
16996 @item @code{list}
16997 @end itemize
16998
16999 A fully qualified Objective-C method name is specified as
17000
17001 @smallexample
17002 -[@var{Class} @var{methodName}]
17003 @end smallexample
17004
17005 where the minus sign is used to indicate an instance method and a
17006 plus sign (not shown) is used to indicate a class method. The class
17007 name @var{Class} and method name @var{methodName} are enclosed in
17008 brackets, similar to the way messages are specified in Objective-C
17009 source code. For example, to set a breakpoint at the @code{create}
17010 instance method of class @code{Fruit} in the program currently being
17011 debugged, enter:
17012
17013 @smallexample
17014 break -[Fruit create]
17015 @end smallexample
17016
17017 To list ten program lines around the @code{initialize} class method,
17018 enter:
17019
17020 @smallexample
17021 list +[NSText initialize]
17022 @end smallexample
17023
17024 In the current version of @value{GDBN}, the plus or minus sign is
17025 required. In future versions of @value{GDBN}, the plus or minus
17026 sign will be optional, but you can use it to narrow the search. It
17027 is also possible to specify just a method name:
17028
17029 @smallexample
17030 break create
17031 @end smallexample
17032
17033 You must specify the complete method name, including any colons. If
17034 your program's source files contain more than one @code{create} method,
17035 you'll be presented with a numbered list of classes that implement that
17036 method. Indicate your choice by number, or type @samp{0} to exit if
17037 none apply.
17038
17039 As another example, to clear a breakpoint established at the
17040 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
17041
17042 @smallexample
17043 clear -[NSWindow makeKeyAndOrderFront:]
17044 @end smallexample
17045
17046 @node The Print Command with Objective-C
17047 @subsubsection The Print Command With Objective-C
17048 @cindex Objective-C, print objects
17049 @kindex print-object
17050 @kindex po @r{(@code{print-object})}
17051
17052 The print command has also been extended to accept methods. For example:
17053
17054 @smallexample
17055 print -[@var{object} hash]
17056 @end smallexample
17057
17058 @cindex print an Objective-C object description
17059 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
17060 @noindent
17061 will tell @value{GDBN} to send the @code{hash} message to @var{object}
17062 and print the result. Also, an additional command has been added,
17063 @code{print-object} or @code{po} for short, which is meant to print
17064 the description of an object. However, this command may only work
17065 with certain Objective-C libraries that have a particular hook
17066 function, @code{_NSPrintForDebugger}, defined.
17067
17068 @node OpenCL C
17069 @subsection OpenCL C
17070
17071 @cindex OpenCL C
17072 This section provides information about @value{GDBN}s OpenCL C support.
17073
17074 @menu
17075 * OpenCL C Datatypes::
17076 * OpenCL C Expressions::
17077 * OpenCL C Operators::
17078 @end menu
17079
17080 @node OpenCL C Datatypes
17081 @subsubsection OpenCL C Datatypes
17082
17083 @cindex OpenCL C Datatypes
17084 @value{GDBN} supports the builtin scalar and vector datatypes specified
17085 by OpenCL 1.1. In addition the half- and double-precision floating point
17086 data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
17087 extensions are also known to @value{GDBN}.
17088
17089 @node OpenCL C Expressions
17090 @subsubsection OpenCL C Expressions
17091
17092 @cindex OpenCL C Expressions
17093 @value{GDBN} supports accesses to vector components including the access as
17094 lvalue where possible. Since OpenCL C is based on C99 most C expressions
17095 supported by @value{GDBN} can be used as well.
17096
17097 @node OpenCL C Operators
17098 @subsubsection OpenCL C Operators
17099
17100 @cindex OpenCL C Operators
17101 @value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
17102 vector data types.
17103
17104 @node Fortran
17105 @subsection Fortran
17106 @cindex Fortran-specific support in @value{GDBN}
17107
17108 @value{GDBN} can be used to debug programs written in Fortran, but it
17109 currently supports only the features of Fortran 77 language.
17110
17111 @cindex trailing underscore, in Fortran symbols
17112 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
17113 among them) append an underscore to the names of variables and
17114 functions. When you debug programs compiled by those compilers, you
17115 will need to refer to variables and functions with a trailing
17116 underscore.
17117
17118 @menu
17119 * Fortran Operators:: Fortran operators and expressions
17120 * Fortran Defaults:: Default settings for Fortran
17121 * Special Fortran Commands:: Special @value{GDBN} commands for Fortran
17122 @end menu
17123
17124 @node Fortran Operators
17125 @subsubsection Fortran Operators and Expressions
17126
17127 @cindex Fortran operators and expressions
17128
17129 Operators must be defined on values of specific types. For instance,
17130 @code{+} is defined on numbers, but not on characters or other non-
17131 arithmetic types. Operators are often defined on groups of types.
17132
17133 @table @code
17134 @item **
17135 The exponentiation operator. It raises the first operand to the power
17136 of the second one.
17137
17138 @item :
17139 The range operator. Normally used in the form of array(low:high) to
17140 represent a section of array.
17141
17142 @item %
17143 The access component operator. Normally used to access elements in derived
17144 types. Also suitable for unions. As unions aren't part of regular Fortran,
17145 this can only happen when accessing a register that uses a gdbarch-defined
17146 union type.
17147 @item ::
17148 The scope operator. Normally used to access variables in modules or
17149 to set breakpoints on subroutines nested in modules or in other
17150 subroutines (internal subroutines).
17151 @end table
17152
17153 @node Fortran Defaults
17154 @subsubsection Fortran Defaults
17155
17156 @cindex Fortran Defaults
17157
17158 Fortran symbols are usually case-insensitive, so @value{GDBN} by
17159 default uses case-insensitive matches for Fortran symbols. You can
17160 change that with the @samp{set case-insensitive} command, see
17161 @ref{Symbols}, for the details.
17162
17163 @node Special Fortran Commands
17164 @subsubsection Special Fortran Commands
17165
17166 @cindex Special Fortran commands
17167
17168 @value{GDBN} has some commands to support Fortran-specific features,
17169 such as displaying common blocks.
17170
17171 @table @code
17172 @cindex @code{COMMON} blocks, Fortran
17173 @kindex info common
17174 @item info common @r{[}@var{common-name}@r{]}
17175 This command prints the values contained in the Fortran @code{COMMON}
17176 block whose name is @var{common-name}. With no argument, the names of
17177 all @code{COMMON} blocks visible at the current program location are
17178 printed.
17179 @cindex arrays slices (Fortran)
17180 @kindex set fortran repack-array-slices
17181 @kindex show fortran repack-array-slices
17182 @item set fortran repack-array-slices [on|off]
17183 @item show fortran repack-array-slices
17184 When taking a slice from an array, a Fortran compiler can choose to
17185 either produce an array descriptor that describes the slice in place,
17186 or it may repack the slice, copying the elements of the slice into a
17187 new region of memory.
17188
17189 When this setting is on, then @value{GDBN} will also repack array
17190 slices in some situations. When this setting is off, then
17191 @value{GDBN} will create array descriptors for slices that reference
17192 the original data in place.
17193
17194 @value{GDBN} will never repack an array slice if the data for the
17195 slice is contiguous within the original array.
17196
17197 @value{GDBN} will always repack string slices if the data for the
17198 slice is non-contiguous within the original string as @value{GDBN}
17199 does not support printing non-contiguous strings.
17200
17201 The default for this setting is @code{off}.
17202 @end table
17203
17204 @node Pascal
17205 @subsection Pascal
17206
17207 @cindex Pascal support in @value{GDBN}, limitations
17208 Debugging Pascal programs which use sets, subranges, file variables, or
17209 nested functions does not currently work. @value{GDBN} does not support
17210 entering expressions, printing values, or similar features using Pascal
17211 syntax.
17212
17213 The Pascal-specific command @code{set print pascal_static-members}
17214 controls whether static members of Pascal objects are displayed.
17215 @xref{Print Settings, pascal_static-members}.
17216
17217 @node Rust
17218 @subsection Rust
17219
17220 @value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
17221 Programming Language}. Type- and value-printing, and expression
17222 parsing, are reasonably complete. However, there are a few
17223 peculiarities and holes to be aware of.
17224
17225 @itemize @bullet
17226 @item
17227 Linespecs (@pxref{Specify Location}) are never relative to the current
17228 crate. Instead, they act as if there were a global namespace of
17229 crates, somewhat similar to the way @code{extern crate} behaves.
17230
17231 That is, if @value{GDBN} is stopped at a breakpoint in a function in
17232 crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
17233 to set a breakpoint in a function named @samp{f} in a crate named
17234 @samp{B}.
17235
17236 As a consequence of this approach, linespecs also cannot refer to
17237 items using @samp{self::} or @samp{super::}.
17238
17239 @item
17240 Because @value{GDBN} implements Rust name-lookup semantics in
17241 expressions, it will sometimes prepend the current crate to a name.
17242 For example, if @value{GDBN} is stopped at a breakpoint in the crate
17243 @samp{K}, then @code{print ::x::y} will try to find the symbol
17244 @samp{K::x::y}.
17245
17246 However, since it is useful to be able to refer to other crates when
17247 debugging, @value{GDBN} provides the @code{extern} extension to
17248 circumvent this. To use the extension, just put @code{extern} before
17249 a path expression to refer to the otherwise unavailable ``global''
17250 scope.
17251
17252 In the above example, if you wanted to refer to the symbol @samp{y} in
17253 the crate @samp{x}, you would use @code{print extern x::y}.
17254
17255 @item
17256 The Rust expression evaluator does not support ``statement-like''
17257 expressions such as @code{if} or @code{match}, or lambda expressions.
17258
17259 @item
17260 Tuple expressions are not implemented.
17261
17262 @item
17263 The Rust expression evaluator does not currently implement the
17264 @code{Drop} trait. Objects that may be created by the evaluator will
17265 never be destroyed.
17266
17267 @item
17268 @value{GDBN} does not implement type inference for generics. In order
17269 to call generic functions or otherwise refer to generic items, you
17270 will have to specify the type parameters manually.
17271
17272 @item
17273 @value{GDBN} currently uses the C@t{++} demangler for Rust. In most
17274 cases this does not cause any problems. However, in an expression
17275 context, completing a generic function name will give syntactically
17276 invalid results. This happens because Rust requires the @samp{::}
17277 operator between the function name and its generic arguments. For
17278 example, @value{GDBN} might provide a completion like
17279 @code{crate::f<u32>}, where the parser would require
17280 @code{crate::f::<u32>}.
17281
17282 @item
17283 As of this writing, the Rust compiler (version 1.8) has a few holes in
17284 the debugging information it generates. These holes prevent certain
17285 features from being implemented by @value{GDBN}:
17286 @itemize @bullet
17287
17288 @item
17289 Method calls cannot be made via traits.
17290
17291 @item
17292 Operator overloading is not implemented.
17293
17294 @item
17295 When debugging in a monomorphized function, you cannot use the generic
17296 type names.
17297
17298 @item
17299 The type @code{Self} is not available.
17300
17301 @item
17302 @code{use} statements are not available, so some names may not be
17303 available in the crate.
17304 @end itemize
17305 @end itemize
17306
17307 @node Modula-2
17308 @subsection Modula-2
17309
17310 @cindex Modula-2, @value{GDBN} support
17311
17312 The extensions made to @value{GDBN} to support Modula-2 only support
17313 output from the @sc{gnu} Modula-2 compiler (which is currently being
17314 developed). Other Modula-2 compilers are not currently supported, and
17315 attempting to debug executables produced by them is most likely
17316 to give an error as @value{GDBN} reads in the executable's symbol
17317 table.
17318
17319 @cindex expressions in Modula-2
17320 @menu
17321 * M2 Operators:: Built-in operators
17322 * Built-In Func/Proc:: Built-in functions and procedures
17323 * M2 Constants:: Modula-2 constants
17324 * M2 Types:: Modula-2 types
17325 * M2 Defaults:: Default settings for Modula-2
17326 * Deviations:: Deviations from standard Modula-2
17327 * M2 Checks:: Modula-2 type and range checks
17328 * M2 Scope:: The scope operators @code{::} and @code{.}
17329 * GDB/M2:: @value{GDBN} and Modula-2
17330 @end menu
17331
17332 @node M2 Operators
17333 @subsubsection Operators
17334 @cindex Modula-2 operators
17335
17336 Operators must be defined on values of specific types. For instance,
17337 @code{+} is defined on numbers, but not on structures. Operators are
17338 often defined on groups of types. For the purposes of Modula-2, the
17339 following definitions hold:
17340
17341 @itemize @bullet
17342
17343 @item
17344 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
17345 their subranges.
17346
17347 @item
17348 @emph{Character types} consist of @code{CHAR} and its subranges.
17349
17350 @item
17351 @emph{Floating-point types} consist of @code{REAL}.
17352
17353 @item
17354 @emph{Pointer types} consist of anything declared as @code{POINTER TO
17355 @var{type}}.
17356
17357 @item
17358 @emph{Scalar types} consist of all of the above.
17359
17360 @item
17361 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
17362
17363 @item
17364 @emph{Boolean types} consist of @code{BOOLEAN}.
17365 @end itemize
17366
17367 @noindent
17368 The following operators are supported, and appear in order of
17369 increasing precedence:
17370
17371 @table @code
17372 @item ,
17373 Function argument or array index separator.
17374
17375 @item :=
17376 Assignment. The value of @var{var} @code{:=} @var{value} is
17377 @var{value}.
17378
17379 @item <@r{, }>
17380 Less than, greater than on integral, floating-point, or enumerated
17381 types.
17382
17383 @item <=@r{, }>=
17384 Less than or equal to, greater than or equal to
17385 on integral, floating-point and enumerated types, or set inclusion on
17386 set types. Same precedence as @code{<}.
17387
17388 @item =@r{, }<>@r{, }#
17389 Equality and two ways of expressing inequality, valid on scalar types.
17390 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
17391 available for inequality, since @code{#} conflicts with the script
17392 comment character.
17393
17394 @item IN
17395 Set membership. Defined on set types and the types of their members.
17396 Same precedence as @code{<}.
17397
17398 @item OR
17399 Boolean disjunction. Defined on boolean types.
17400
17401 @item AND@r{, }&
17402 Boolean conjunction. Defined on boolean types.
17403
17404 @item @@
17405 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17406
17407 @item +@r{, }-
17408 Addition and subtraction on integral and floating-point types, or union
17409 and difference on set types.
17410
17411 @item *
17412 Multiplication on integral and floating-point types, or set intersection
17413 on set types.
17414
17415 @item /
17416 Division on floating-point types, or symmetric set difference on set
17417 types. Same precedence as @code{*}.
17418
17419 @item DIV@r{, }MOD
17420 Integer division and remainder. Defined on integral types. Same
17421 precedence as @code{*}.
17422
17423 @item -
17424 Negative. Defined on @code{INTEGER} and @code{REAL} data.
17425
17426 @item ^
17427 Pointer dereferencing. Defined on pointer types.
17428
17429 @item NOT
17430 Boolean negation. Defined on boolean types. Same precedence as
17431 @code{^}.
17432
17433 @item .
17434 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
17435 precedence as @code{^}.
17436
17437 @item []
17438 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
17439
17440 @item ()
17441 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
17442 as @code{^}.
17443
17444 @item ::@r{, }.
17445 @value{GDBN} and Modula-2 scope operators.
17446 @end table
17447
17448 @quotation
17449 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
17450 treats the use of the operator @code{IN}, or the use of operators
17451 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17452 @code{<=}, and @code{>=} on sets as an error.
17453 @end quotation
17454
17455
17456 @node Built-In Func/Proc
17457 @subsubsection Built-in Functions and Procedures
17458 @cindex Modula-2 built-ins
17459
17460 Modula-2 also makes available several built-in procedures and functions.
17461 In describing these, the following metavariables are used:
17462
17463 @table @var
17464
17465 @item a
17466 represents an @code{ARRAY} variable.
17467
17468 @item c
17469 represents a @code{CHAR} constant or variable.
17470
17471 @item i
17472 represents a variable or constant of integral type.
17473
17474 @item m
17475 represents an identifier that belongs to a set. Generally used in the
17476 same function with the metavariable @var{s}. The type of @var{s} should
17477 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17478
17479 @item n
17480 represents a variable or constant of integral or floating-point type.
17481
17482 @item r
17483 represents a variable or constant of floating-point type.
17484
17485 @item t
17486 represents a type.
17487
17488 @item v
17489 represents a variable.
17490
17491 @item x
17492 represents a variable or constant of one of many types. See the
17493 explanation of the function for details.
17494 @end table
17495
17496 All Modula-2 built-in procedures also return a result, described below.
17497
17498 @table @code
17499 @item ABS(@var{n})
17500 Returns the absolute value of @var{n}.
17501
17502 @item CAP(@var{c})
17503 If @var{c} is a lower case letter, it returns its upper case
17504 equivalent, otherwise it returns its argument.
17505
17506 @item CHR(@var{i})
17507 Returns the character whose ordinal value is @var{i}.
17508
17509 @item DEC(@var{v})
17510 Decrements the value in the variable @var{v} by one. Returns the new value.
17511
17512 @item DEC(@var{v},@var{i})
17513 Decrements the value in the variable @var{v} by @var{i}. Returns the
17514 new value.
17515
17516 @item EXCL(@var{m},@var{s})
17517 Removes the element @var{m} from the set @var{s}. Returns the new
17518 set.
17519
17520 @item FLOAT(@var{i})
17521 Returns the floating point equivalent of the integer @var{i}.
17522
17523 @item HIGH(@var{a})
17524 Returns the index of the last member of @var{a}.
17525
17526 @item INC(@var{v})
17527 Increments the value in the variable @var{v} by one. Returns the new value.
17528
17529 @item INC(@var{v},@var{i})
17530 Increments the value in the variable @var{v} by @var{i}. Returns the
17531 new value.
17532
17533 @item INCL(@var{m},@var{s})
17534 Adds the element @var{m} to the set @var{s} if it is not already
17535 there. Returns the new set.
17536
17537 @item MAX(@var{t})
17538 Returns the maximum value of the type @var{t}.
17539
17540 @item MIN(@var{t})
17541 Returns the minimum value of the type @var{t}.
17542
17543 @item ODD(@var{i})
17544 Returns boolean TRUE if @var{i} is an odd number.
17545
17546 @item ORD(@var{x})
17547 Returns the ordinal value of its argument. For example, the ordinal
17548 value of a character is its @sc{ascii} value (on machines supporting
17549 the @sc{ascii} character set). The argument @var{x} must be of an
17550 ordered type, which include integral, character and enumerated types.
17551
17552 @item SIZE(@var{x})
17553 Returns the size of its argument. The argument @var{x} can be a
17554 variable or a type.
17555
17556 @item TRUNC(@var{r})
17557 Returns the integral part of @var{r}.
17558
17559 @item TSIZE(@var{x})
17560 Returns the size of its argument. The argument @var{x} can be a
17561 variable or a type.
17562
17563 @item VAL(@var{t},@var{i})
17564 Returns the member of the type @var{t} whose ordinal value is @var{i}.
17565 @end table
17566
17567 @quotation
17568 @emph{Warning:} Sets and their operations are not yet supported, so
17569 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17570 an error.
17571 @end quotation
17572
17573 @cindex Modula-2 constants
17574 @node M2 Constants
17575 @subsubsection Constants
17576
17577 @value{GDBN} allows you to express the constants of Modula-2 in the following
17578 ways:
17579
17580 @itemize @bullet
17581
17582 @item
17583 Integer constants are simply a sequence of digits. When used in an
17584 expression, a constant is interpreted to be type-compatible with the
17585 rest of the expression. Hexadecimal integers are specified by a
17586 trailing @samp{H}, and octal integers by a trailing @samp{B}.
17587
17588 @item
17589 Floating point constants appear as a sequence of digits, followed by a
17590 decimal point and another sequence of digits. An optional exponent can
17591 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17592 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
17593 digits of the floating point constant must be valid decimal (base 10)
17594 digits.
17595
17596 @item
17597 Character constants consist of a single character enclosed by a pair of
17598 like quotes, either single (@code{'}) or double (@code{"}). They may
17599 also be expressed by their ordinal value (their @sc{ascii} value, usually)
17600 followed by a @samp{C}.
17601
17602 @item
17603 String constants consist of a sequence of characters enclosed by a
17604 pair of like quotes, either single (@code{'}) or double (@code{"}).
17605 Escape sequences in the style of C are also allowed. @xref{C
17606 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
17607 sequences.
17608
17609 @item
17610 Enumerated constants consist of an enumerated identifier.
17611
17612 @item
17613 Boolean constants consist of the identifiers @code{TRUE} and
17614 @code{FALSE}.
17615
17616 @item
17617 Pointer constants consist of integral values only.
17618
17619 @item
17620 Set constants are not yet supported.
17621 @end itemize
17622
17623 @node M2 Types
17624 @subsubsection Modula-2 Types
17625 @cindex Modula-2 types
17626
17627 Currently @value{GDBN} can print the following data types in Modula-2
17628 syntax: array types, record types, set types, pointer types, procedure
17629 types, enumerated types, subrange types and base types. You can also
17630 print the contents of variables declared using these type.
17631 This section gives a number of simple source code examples together with
17632 sample @value{GDBN} sessions.
17633
17634 The first example contains the following section of code:
17635
17636 @smallexample
17637 VAR
17638 s: SET OF CHAR ;
17639 r: [20..40] ;
17640 @end smallexample
17641
17642 @noindent
17643 and you can request @value{GDBN} to interrogate the type and value of
17644 @code{r} and @code{s}.
17645
17646 @smallexample
17647 (@value{GDBP}) print s
17648 @{'A'..'C', 'Z'@}
17649 (@value{GDBP}) ptype s
17650 SET OF CHAR
17651 (@value{GDBP}) print r
17652 21
17653 (@value{GDBP}) ptype r
17654 [20..40]
17655 @end smallexample
17656
17657 @noindent
17658 Likewise if your source code declares @code{s} as:
17659
17660 @smallexample
17661 VAR
17662 s: SET ['A'..'Z'] ;
17663 @end smallexample
17664
17665 @noindent
17666 then you may query the type of @code{s} by:
17667
17668 @smallexample
17669 (@value{GDBP}) ptype s
17670 type = SET ['A'..'Z']
17671 @end smallexample
17672
17673 @noindent
17674 Note that at present you cannot interactively manipulate set
17675 expressions using the debugger.
17676
17677 The following example shows how you might declare an array in Modula-2
17678 and how you can interact with @value{GDBN} to print its type and contents:
17679
17680 @smallexample
17681 VAR
17682 s: ARRAY [-10..10] OF CHAR ;
17683 @end smallexample
17684
17685 @smallexample
17686 (@value{GDBP}) ptype s
17687 ARRAY [-10..10] OF CHAR
17688 @end smallexample
17689
17690 Note that the array handling is not yet complete and although the type
17691 is printed correctly, expression handling still assumes that all
17692 arrays have a lower bound of zero and not @code{-10} as in the example
17693 above.
17694
17695 Here are some more type related Modula-2 examples:
17696
17697 @smallexample
17698 TYPE
17699 colour = (blue, red, yellow, green) ;
17700 t = [blue..yellow] ;
17701 VAR
17702 s: t ;
17703 BEGIN
17704 s := blue ;
17705 @end smallexample
17706
17707 @noindent
17708 The @value{GDBN} interaction shows how you can query the data type
17709 and value of a variable.
17710
17711 @smallexample
17712 (@value{GDBP}) print s
17713 $1 = blue
17714 (@value{GDBP}) ptype t
17715 type = [blue..yellow]
17716 @end smallexample
17717
17718 @noindent
17719 In this example a Modula-2 array is declared and its contents
17720 displayed. Observe that the contents are written in the same way as
17721 their @code{C} counterparts.
17722
17723 @smallexample
17724 VAR
17725 s: ARRAY [1..5] OF CARDINAL ;
17726 BEGIN
17727 s[1] := 1 ;
17728 @end smallexample
17729
17730 @smallexample
17731 (@value{GDBP}) print s
17732 $1 = @{1, 0, 0, 0, 0@}
17733 (@value{GDBP}) ptype s
17734 type = ARRAY [1..5] OF CARDINAL
17735 @end smallexample
17736
17737 The Modula-2 language interface to @value{GDBN} also understands
17738 pointer types as shown in this example:
17739
17740 @smallexample
17741 VAR
17742 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
17743 BEGIN
17744 NEW(s) ;
17745 s^[1] := 1 ;
17746 @end smallexample
17747
17748 @noindent
17749 and you can request that @value{GDBN} describes the type of @code{s}.
17750
17751 @smallexample
17752 (@value{GDBP}) ptype s
17753 type = POINTER TO ARRAY [1..5] OF CARDINAL
17754 @end smallexample
17755
17756 @value{GDBN} handles compound types as we can see in this example.
17757 Here we combine array types, record types, pointer types and subrange
17758 types:
17759
17760 @smallexample
17761 TYPE
17762 foo = RECORD
17763 f1: CARDINAL ;
17764 f2: CHAR ;
17765 f3: myarray ;
17766 END ;
17767
17768 myarray = ARRAY myrange OF CARDINAL ;
17769 myrange = [-2..2] ;
17770 VAR
17771 s: POINTER TO ARRAY myrange OF foo ;
17772 @end smallexample
17773
17774 @noindent
17775 and you can ask @value{GDBN} to describe the type of @code{s} as shown
17776 below.
17777
17778 @smallexample
17779 (@value{GDBP}) ptype s
17780 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
17781 f1 : CARDINAL;
17782 f2 : CHAR;
17783 f3 : ARRAY [-2..2] OF CARDINAL;
17784 END
17785 @end smallexample
17786
17787 @node M2 Defaults
17788 @subsubsection Modula-2 Defaults
17789 @cindex Modula-2 defaults
17790
17791 If type and range checking are set automatically by @value{GDBN}, they
17792 both default to @code{on} whenever the working language changes to
17793 Modula-2. This happens regardless of whether you or @value{GDBN}
17794 selected the working language.
17795
17796 If you allow @value{GDBN} to set the language automatically, then entering
17797 code compiled from a file whose name ends with @file{.mod} sets the
17798 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
17799 Infer the Source Language}, for further details.
17800
17801 @node Deviations
17802 @subsubsection Deviations from Standard Modula-2
17803 @cindex Modula-2, deviations from
17804
17805 A few changes have been made to make Modula-2 programs easier to debug.
17806 This is done primarily via loosening its type strictness:
17807
17808 @itemize @bullet
17809 @item
17810 Unlike in standard Modula-2, pointer constants can be formed by
17811 integers. This allows you to modify pointer variables during
17812 debugging. (In standard Modula-2, the actual address contained in a
17813 pointer variable is hidden from you; it can only be modified
17814 through direct assignment to another pointer variable or expression that
17815 returned a pointer.)
17816
17817 @item
17818 C escape sequences can be used in strings and characters to represent
17819 non-printable characters. @value{GDBN} prints out strings with these
17820 escape sequences embedded. Single non-printable characters are
17821 printed using the @samp{CHR(@var{nnn})} format.
17822
17823 @item
17824 The assignment operator (@code{:=}) returns the value of its right-hand
17825 argument.
17826
17827 @item
17828 All built-in procedures both modify @emph{and} return their argument.
17829 @end itemize
17830
17831 @node M2 Checks
17832 @subsubsection Modula-2 Type and Range Checks
17833 @cindex Modula-2 checks
17834
17835 @quotation
17836 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
17837 range checking.
17838 @end quotation
17839 @c FIXME remove warning when type/range checks added
17840
17841 @value{GDBN} considers two Modula-2 variables type equivalent if:
17842
17843 @itemize @bullet
17844 @item
17845 They are of types that have been declared equivalent via a @code{TYPE
17846 @var{t1} = @var{t2}} statement
17847
17848 @item
17849 They have been declared on the same line. (Note: This is true of the
17850 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
17851 @end itemize
17852
17853 As long as type checking is enabled, any attempt to combine variables
17854 whose types are not equivalent is an error.
17855
17856 Range checking is done on all mathematical operations, assignment, array
17857 index bounds, and all built-in functions and procedures.
17858
17859 @node M2 Scope
17860 @subsubsection The Scope Operators @code{::} and @code{.}
17861 @cindex scope
17862 @cindex @code{.}, Modula-2 scope operator
17863 @cindex colon, doubled as scope operator
17864 @ifinfo
17865 @vindex colon-colon@r{, in Modula-2}
17866 @c Info cannot handle :: but TeX can.
17867 @end ifinfo
17868 @ifnotinfo
17869 @vindex ::@r{, in Modula-2}
17870 @end ifnotinfo
17871
17872 There are a few subtle differences between the Modula-2 scope operator
17873 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
17874 similar syntax:
17875
17876 @smallexample
17877
17878 @var{module} . @var{id}
17879 @var{scope} :: @var{id}
17880 @end smallexample
17881
17882 @noindent
17883 where @var{scope} is the name of a module or a procedure,
17884 @var{module} the name of a module, and @var{id} is any declared
17885 identifier within your program, except another module.
17886
17887 Using the @code{::} operator makes @value{GDBN} search the scope
17888 specified by @var{scope} for the identifier @var{id}. If it is not
17889 found in the specified scope, then @value{GDBN} searches all scopes
17890 enclosing the one specified by @var{scope}.
17891
17892 Using the @code{.} operator makes @value{GDBN} search the current scope for
17893 the identifier specified by @var{id} that was imported from the
17894 definition module specified by @var{module}. With this operator, it is
17895 an error if the identifier @var{id} was not imported from definition
17896 module @var{module}, or if @var{id} is not an identifier in
17897 @var{module}.
17898
17899 @node GDB/M2
17900 @subsubsection @value{GDBN} and Modula-2
17901
17902 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
17903 Five subcommands of @code{set print} and @code{show print} apply
17904 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
17905 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
17906 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
17907 analogue in Modula-2.
17908
17909 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
17910 with any language, is not useful with Modula-2. Its
17911 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
17912 created in Modula-2 as they can in C or C@t{++}. However, because an
17913 address can be specified by an integral constant, the construct
17914 @samp{@{@var{type}@}@var{adrexp}} is still useful.
17915
17916 @cindex @code{#} in Modula-2
17917 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
17918 interpreted as the beginning of a comment. Use @code{<>} instead.
17919
17920 @node Ada
17921 @subsection Ada
17922 @cindex Ada
17923
17924 The extensions made to @value{GDBN} for Ada only support
17925 output from the @sc{gnu} Ada (GNAT) compiler.
17926 Other Ada compilers are not currently supported, and
17927 attempting to debug executables produced by them is most likely
17928 to be difficult.
17929
17930
17931 @cindex expressions in Ada
17932 @menu
17933 * Ada Mode Intro:: General remarks on the Ada syntax
17934 and semantics supported by Ada mode
17935 in @value{GDBN}.
17936 * Omissions from Ada:: Restrictions on the Ada expression syntax.
17937 * Additions to Ada:: Extensions of the Ada expression syntax.
17938 * Overloading support for Ada:: Support for expressions involving overloaded
17939 subprograms.
17940 * Stopping Before Main Program:: Debugging the program during elaboration.
17941 * Ada Exceptions:: Ada Exceptions
17942 * Ada Tasks:: Listing and setting breakpoints in tasks.
17943 * Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
17944 * Ravenscar Profile:: Tasking Support when using the Ravenscar
17945 Profile
17946 * Ada Settings:: New settable GDB parameters for Ada.
17947 * Ada Glitches:: Known peculiarities of Ada mode.
17948 @end menu
17949
17950 @node Ada Mode Intro
17951 @subsubsection Introduction
17952 @cindex Ada mode, general
17953
17954 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
17955 syntax, with some extensions.
17956 The philosophy behind the design of this subset is
17957
17958 @itemize @bullet
17959 @item
17960 That @value{GDBN} should provide basic literals and access to operations for
17961 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
17962 leaving more sophisticated computations to subprograms written into the
17963 program (which therefore may be called from @value{GDBN}).
17964
17965 @item
17966 That type safety and strict adherence to Ada language restrictions
17967 are not particularly important to the @value{GDBN} user.
17968
17969 @item
17970 That brevity is important to the @value{GDBN} user.
17971 @end itemize
17972
17973 Thus, for brevity, the debugger acts as if all names declared in
17974 user-written packages are directly visible, even if they are not visible
17975 according to Ada rules, thus making it unnecessary to fully qualify most
17976 names with their packages, regardless of context. Where this causes
17977 ambiguity, @value{GDBN} asks the user's intent.
17978
17979 The debugger will start in Ada mode if it detects an Ada main program.
17980 As for other languages, it will enter Ada mode when stopped in a program that
17981 was translated from an Ada source file.
17982
17983 While in Ada mode, you may use `@t{--}' for comments. This is useful
17984 mostly for documenting command files. The standard @value{GDBN} comment
17985 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
17986 middle (to allow based literals).
17987
17988 @node Omissions from Ada
17989 @subsubsection Omissions from Ada
17990 @cindex Ada, omissions from
17991
17992 Here are the notable omissions from the subset:
17993
17994 @itemize @bullet
17995 @item
17996 Only a subset of the attributes are supported:
17997
17998 @itemize @minus
17999 @item
18000 @t{'First}, @t{'Last}, and @t{'Length}
18001 on array objects (not on types and subtypes).
18002
18003 @item
18004 @t{'Min} and @t{'Max}.
18005
18006 @item
18007 @t{'Pos} and @t{'Val}.
18008
18009 @item
18010 @t{'Tag}.
18011
18012 @item
18013 @t{'Range} on array objects (not subtypes), but only as the right
18014 operand of the membership (@code{in}) operator.
18015
18016 @item
18017 @t{'Access}, @t{'Unchecked_Access}, and
18018 @t{'Unrestricted_Access} (a GNAT extension).
18019
18020 @item
18021 @t{'Address}.
18022 @end itemize
18023
18024 @item
18025 The names in
18026 @code{Characters.Latin_1} are not available and
18027 concatenation is not implemented. Thus, escape characters in strings are
18028 not currently available.
18029
18030 @item
18031 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
18032 equality of representations. They will generally work correctly
18033 for strings and arrays whose elements have integer or enumeration types.
18034 They may not work correctly for arrays whose element
18035 types have user-defined equality, for arrays of real values
18036 (in particular, IEEE-conformant floating point, because of negative
18037 zeroes and NaNs), and for arrays whose elements contain unused bits with
18038 indeterminate values.
18039
18040 @item
18041 The other component-by-component array operations (@code{and}, @code{or},
18042 @code{xor}, @code{not}, and relational tests other than equality)
18043 are not implemented.
18044
18045 @item
18046 @cindex array aggregates (Ada)
18047 @cindex record aggregates (Ada)
18048 @cindex aggregates (Ada)
18049 There is limited support for array and record aggregates. They are
18050 permitted only on the right sides of assignments, as in these examples:
18051
18052 @smallexample
18053 (@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
18054 (@value{GDBP}) set An_Array := (1, others => 0)
18055 (@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
18056 (@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
18057 (@value{GDBP}) set A_Record := (1, "Peter", True);
18058 (@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
18059 @end smallexample
18060
18061 Changing a
18062 discriminant's value by assigning an aggregate has an
18063 undefined effect if that discriminant is used within the record.
18064 However, you can first modify discriminants by directly assigning to
18065 them (which normally would not be allowed in Ada), and then performing an
18066 aggregate assignment. For example, given a variable @code{A_Rec}
18067 declared to have a type such as:
18068
18069 @smallexample
18070 type Rec (Len : Small_Integer := 0) is record
18071 Id : Integer;
18072 Vals : IntArray (1 .. Len);
18073 end record;
18074 @end smallexample
18075
18076 you can assign a value with a different size of @code{Vals} with two
18077 assignments:
18078
18079 @smallexample
18080 (@value{GDBP}) set A_Rec.Len := 4
18081 (@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
18082 @end smallexample
18083
18084 As this example also illustrates, @value{GDBN} is very loose about the usual
18085 rules concerning aggregates. You may leave out some of the
18086 components of an array or record aggregate (such as the @code{Len}
18087 component in the assignment to @code{A_Rec} above); they will retain their
18088 original values upon assignment. You may freely use dynamic values as
18089 indices in component associations. You may even use overlapping or
18090 redundant component associations, although which component values are
18091 assigned in such cases is not defined.
18092
18093 @item
18094 Calls to dispatching subprograms are not implemented.
18095
18096 @item
18097 The overloading algorithm is much more limited (i.e., less selective)
18098 than that of real Ada. It makes only limited use of the context in
18099 which a subexpression appears to resolve its meaning, and it is much
18100 looser in its rules for allowing type matches. As a result, some
18101 function calls will be ambiguous, and the user will be asked to choose
18102 the proper resolution.
18103
18104 @item
18105 The @code{new} operator is not implemented.
18106
18107 @item
18108 Entry calls are not implemented.
18109
18110 @item
18111 Aside from printing, arithmetic operations on the native VAX floating-point
18112 formats are not supported.
18113
18114 @item
18115 It is not possible to slice a packed array.
18116
18117 @item
18118 The names @code{True} and @code{False}, when not part of a qualified name,
18119 are interpreted as if implicitly prefixed by @code{Standard}, regardless of
18120 context.
18121 Should your program
18122 redefine these names in a package or procedure (at best a dubious practice),
18123 you will have to use fully qualified names to access their new definitions.
18124 @end itemize
18125
18126 @node Additions to Ada
18127 @subsubsection Additions to Ada
18128 @cindex Ada, deviations from
18129
18130 As it does for other languages, @value{GDBN} makes certain generic
18131 extensions to Ada (@pxref{Expressions}):
18132
18133 @itemize @bullet
18134 @item
18135 If the expression @var{E} is a variable residing in memory (typically
18136 a local variable or array element) and @var{N} is a positive integer,
18137 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
18138 @var{N}-1 adjacent variables following it in memory as an array. In
18139 Ada, this operator is generally not necessary, since its prime use is
18140 in displaying parts of an array, and slicing will usually do this in
18141 Ada. However, there are occasional uses when debugging programs in
18142 which certain debugging information has been optimized away.
18143
18144 @item
18145 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
18146 appears in function or file @var{B}.'' When @var{B} is a file name,
18147 you must typically surround it in single quotes.
18148
18149 @item
18150 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
18151 @var{type} that appears at address @var{addr}.''
18152
18153 @item
18154 A name starting with @samp{$} is a convenience variable
18155 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
18156 @end itemize
18157
18158 In addition, @value{GDBN} provides a few other shortcuts and outright
18159 additions specific to Ada:
18160
18161 @itemize @bullet
18162 @item
18163 The assignment statement is allowed as an expression, returning
18164 its right-hand operand as its value. Thus, you may enter
18165
18166 @smallexample
18167 (@value{GDBP}) set x := y + 3
18168 (@value{GDBP}) print A(tmp := y + 1)
18169 @end smallexample
18170
18171 @item
18172 The semicolon is allowed as an ``operator,'' returning as its value
18173 the value of its right-hand operand.
18174 This allows, for example,
18175 complex conditional breaks:
18176
18177 @smallexample
18178 (@value{GDBP}) break f
18179 (@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
18180 @end smallexample
18181
18182 @item
18183 Rather than use catenation and symbolic character names to introduce special
18184 characters into strings, one may instead use a special bracket notation,
18185 which is also used to print strings. A sequence of characters of the form
18186 @samp{["@var{XX}"]} within a string or character literal denotes the
18187 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
18188 sequence of characters @samp{["""]} also denotes a single quotation mark
18189 in strings. For example,
18190 @smallexample
18191 "One line.["0a"]Next line.["0a"]"
18192 @end smallexample
18193 @noindent
18194 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
18195 after each period.
18196
18197 @item
18198 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
18199 @t{'Max} is optional (and is ignored in any case). For example, it is valid
18200 to write
18201
18202 @smallexample
18203 (@value{GDBP}) print 'max(x, y)
18204 @end smallexample
18205
18206 @item
18207 When printing arrays, @value{GDBN} uses positional notation when the
18208 array has a lower bound of 1, and uses a modified named notation otherwise.
18209 For example, a one-dimensional array of three integers with a lower bound
18210 of 3 might print as
18211
18212 @smallexample
18213 (3 => 10, 17, 1)
18214 @end smallexample
18215
18216 @noindent
18217 That is, in contrast to valid Ada, only the first component has a @code{=>}
18218 clause.
18219
18220 @item
18221 You may abbreviate attributes in expressions with any unique,
18222 multi-character subsequence of
18223 their names (an exact match gets preference).
18224 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
18225 in place of @t{a'length}.
18226
18227 @item
18228 @cindex quoting Ada internal identifiers
18229 Since Ada is case-insensitive, the debugger normally maps identifiers you type
18230 to lower case. The GNAT compiler uses upper-case characters for
18231 some of its internal identifiers, which are normally of no interest to users.
18232 For the rare occasions when you actually have to look at them,
18233 enclose them in angle brackets to avoid the lower-case mapping.
18234 For example,
18235 @smallexample
18236 (@value{GDBP}) print <JMPBUF_SAVE>[0]
18237 @end smallexample
18238
18239 @item
18240 Printing an object of class-wide type or dereferencing an
18241 access-to-class-wide value will display all the components of the object's
18242 specific type (as indicated by its run-time tag). Likewise, component
18243 selection on such a value will operate on the specific type of the
18244 object.
18245
18246 @end itemize
18247
18248 @node Overloading support for Ada
18249 @subsubsection Overloading support for Ada
18250 @cindex overloading, Ada
18251
18252 The debugger supports limited overloading. Given a subprogram call in which
18253 the function symbol has multiple definitions, it will use the number of
18254 actual parameters and some information about their types to attempt to narrow
18255 the set of definitions. It also makes very limited use of context, preferring
18256 procedures to functions in the context of the @code{call} command, and
18257 functions to procedures elsewhere.
18258
18259 If, after narrowing, the set of matching definitions still contains more than
18260 one definition, @value{GDBN} will display a menu to query which one it should
18261 use, for instance:
18262
18263 @smallexample
18264 (@value{GDBP}) print f(1)
18265 Multiple matches for f
18266 [0] cancel
18267 [1] foo.f (integer) return boolean at foo.adb:23
18268 [2] foo.f (foo.new_integer) return boolean at foo.adb:28
18269 >
18270 @end smallexample
18271
18272 In this case, just select one menu entry either to cancel expression evaluation
18273 (type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
18274 instance (type the corresponding number and press @key{RET}).
18275
18276 Here are a couple of commands to customize @value{GDBN}'s behavior in this
18277 case:
18278
18279 @table @code
18280
18281 @kindex set ada print-signatures
18282 @item set ada print-signatures
18283 Control whether parameter types and return types are displayed in overloads
18284 selection menus. It is @code{on} by default.
18285 @xref{Overloading support for Ada}.
18286
18287 @kindex show ada print-signatures
18288 @item show ada print-signatures
18289 Show the current setting for displaying parameter types and return types in
18290 overloads selection menu.
18291 @xref{Overloading support for Ada}.
18292
18293 @end table
18294
18295 @node Stopping Before Main Program
18296 @subsubsection Stopping at the Very Beginning
18297
18298 @cindex breakpointing Ada elaboration code
18299 It is sometimes necessary to debug the program during elaboration, and
18300 before reaching the main procedure.
18301 As defined in the Ada Reference
18302 Manual, the elaboration code is invoked from a procedure called
18303 @code{adainit}. To run your program up to the beginning of
18304 elaboration, simply use the following two commands:
18305 @code{tbreak adainit} and @code{run}.
18306
18307 @node Ada Exceptions
18308 @subsubsection Ada Exceptions
18309
18310 A command is provided to list all Ada exceptions:
18311
18312 @table @code
18313 @kindex info exceptions
18314 @item info exceptions
18315 @itemx info exceptions @var{regexp}
18316 The @code{info exceptions} command allows you to list all Ada exceptions
18317 defined within the program being debugged, as well as their addresses.
18318 With a regular expression, @var{regexp}, as argument, only those exceptions
18319 whose names match @var{regexp} are listed.
18320 @end table
18321
18322 Below is a small example, showing how the command can be used, first
18323 without argument, and next with a regular expression passed as an
18324 argument.
18325
18326 @smallexample
18327 (@value{GDBP}) info exceptions
18328 All defined Ada exceptions:
18329 constraint_error: 0x613da0
18330 program_error: 0x613d20
18331 storage_error: 0x613ce0
18332 tasking_error: 0x613ca0
18333 const.aint_global_e: 0x613b00
18334 (@value{GDBP}) info exceptions const.aint
18335 All Ada exceptions matching regular expression "const.aint":
18336 constraint_error: 0x613da0
18337 const.aint_global_e: 0x613b00
18338 @end smallexample
18339
18340 It is also possible to ask @value{GDBN} to stop your program's execution
18341 when an exception is raised. For more details, see @ref{Set Catchpoints}.
18342
18343 @node Ada Tasks
18344 @subsubsection Extensions for Ada Tasks
18345 @cindex Ada, tasking
18346
18347 Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
18348 @value{GDBN} provides the following task-related commands:
18349
18350 @table @code
18351 @kindex info tasks
18352 @item info tasks
18353 This command shows a list of current Ada tasks, as in the following example:
18354
18355
18356 @smallexample
18357 @iftex
18358 @leftskip=0.5cm
18359 @end iftex
18360 (@value{GDBP}) info tasks
18361 ID TID P-ID Pri State Name
18362 1 8088000 0 15 Child Activation Wait main_task
18363 2 80a4000 1 15 Accept Statement b
18364 3 809a800 1 15 Child Activation Wait a
18365 * 4 80ae800 3 15 Runnable c
18366
18367 @end smallexample
18368
18369 @noindent
18370 In this listing, the asterisk before the last task indicates it to be the
18371 task currently being inspected.
18372
18373 @table @asis
18374 @item ID
18375 Represents @value{GDBN}'s internal task number.
18376
18377 @item TID
18378 The Ada task ID.
18379
18380 @item P-ID
18381 The parent's task ID (@value{GDBN}'s internal task number).
18382
18383 @item Pri
18384 The base priority of the task.
18385
18386 @item State
18387 Current state of the task.
18388
18389 @table @code
18390 @item Unactivated
18391 The task has been created but has not been activated. It cannot be
18392 executing.
18393
18394 @item Runnable
18395 The task is not blocked for any reason known to Ada. (It may be waiting
18396 for a mutex, though.) It is conceptually "executing" in normal mode.
18397
18398 @item Terminated
18399 The task is terminated, in the sense of ARM 9.3 (5). Any dependents
18400 that were waiting on terminate alternatives have been awakened and have
18401 terminated themselves.
18402
18403 @item Child Activation Wait
18404 The task is waiting for created tasks to complete activation.
18405
18406 @item Accept Statement
18407 The task is waiting on an accept or selective wait statement.
18408
18409 @item Waiting on entry call
18410 The task is waiting on an entry call.
18411
18412 @item Async Select Wait
18413 The task is waiting to start the abortable part of an asynchronous
18414 select statement.
18415
18416 @item Delay Sleep
18417 The task is waiting on a select statement with only a delay
18418 alternative open.
18419
18420 @item Child Termination Wait
18421 The task is sleeping having completed a master within itself, and is
18422 waiting for the tasks dependent on that master to become terminated or
18423 waiting on a terminate Phase.
18424
18425 @item Wait Child in Term Alt
18426 The task is sleeping waiting for tasks on terminate alternatives to
18427 finish terminating.
18428
18429 @item Accepting RV with @var{taskno}
18430 The task is accepting a rendez-vous with the task @var{taskno}.
18431 @end table
18432
18433 @item Name
18434 Name of the task in the program.
18435
18436 @end table
18437
18438 @kindex info task @var{taskno}
18439 @item info task @var{taskno}
18440 This command shows detailed informations on the specified task, as in
18441 the following example:
18442 @smallexample
18443 @iftex
18444 @leftskip=0.5cm
18445 @end iftex
18446 (@value{GDBP}) info tasks
18447 ID TID P-ID Pri State Name
18448 1 8077880 0 15 Child Activation Wait main_task
18449 * 2 807c468 1 15 Runnable task_1
18450 (@value{GDBP}) info task 2
18451 Ada Task: 0x807c468
18452 Name: "task_1"
18453 Thread: 0
18454 LWP: 0x1fac
18455 Parent: 1 ("main_task")
18456 Base Priority: 15
18457 State: Runnable
18458 @end smallexample
18459
18460 @item task
18461 @kindex task@r{ (Ada)}
18462 @cindex current Ada task ID
18463 This command prints the ID and name of the current task.
18464
18465 @smallexample
18466 @iftex
18467 @leftskip=0.5cm
18468 @end iftex
18469 (@value{GDBP}) info tasks
18470 ID TID P-ID Pri State Name
18471 1 8077870 0 15 Child Activation Wait main_task
18472 * 2 807c458 1 15 Runnable some_task
18473 (@value{GDBP}) task
18474 [Current task is 2 "some_task"]
18475 @end smallexample
18476
18477 @item task @var{taskno}
18478 @cindex Ada task switching
18479 This command is like the @code{thread @var{thread-id}}
18480 command (@pxref{Threads}). It switches the context of debugging
18481 from the current task to the given task.
18482
18483 @smallexample
18484 @iftex
18485 @leftskip=0.5cm
18486 @end iftex
18487 (@value{GDBP}) info tasks
18488 ID TID P-ID Pri State Name
18489 1 8077870 0 15 Child Activation Wait main_task
18490 * 2 807c458 1 15 Runnable some_task
18491 (@value{GDBP}) task 1
18492 [Switching to task 1 "main_task"]
18493 #0 0x8067726 in pthread_cond_wait ()
18494 (@value{GDBP}) bt
18495 #0 0x8067726 in pthread_cond_wait ()
18496 #1 0x8056714 in system.os_interface.pthread_cond_wait ()
18497 #2 0x805cb63 in system.task_primitives.operations.sleep ()
18498 #3 0x806153e in system.tasking.stages.activate_tasks ()
18499 #4 0x804aacc in un () at un.adb:5
18500 @end smallexample
18501
18502 @item break @var{location} task @var{taskno}
18503 @itemx break @var{location} task @var{taskno} if @dots{}
18504 @cindex breakpoints and tasks, in Ada
18505 @cindex task breakpoints, in Ada
18506 @kindex break @dots{} task @var{taskno}@r{ (Ada)}
18507 These commands are like the @code{break @dots{} thread @dots{}}
18508 command (@pxref{Thread Stops}). The
18509 @var{location} argument specifies source lines, as described
18510 in @ref{Specify Location}.
18511
18512 Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18513 to specify that you only want @value{GDBN} to stop the program when a
18514 particular Ada task reaches this breakpoint. The @var{taskno} is one of the
18515 numeric task identifiers assigned by @value{GDBN}, shown in the first
18516 column of the @samp{info tasks} display.
18517
18518 If you do not specify @samp{task @var{taskno}} when you set a
18519 breakpoint, the breakpoint applies to @emph{all} tasks of your
18520 program.
18521
18522 You can use the @code{task} qualifier on conditional breakpoints as
18523 well; in this case, place @samp{task @var{taskno}} before the
18524 breakpoint condition (before the @code{if}).
18525
18526 For example,
18527
18528 @smallexample
18529 @iftex
18530 @leftskip=0.5cm
18531 @end iftex
18532 (@value{GDBP}) info tasks
18533 ID TID P-ID Pri State Name
18534 1 140022020 0 15 Child Activation Wait main_task
18535 2 140045060 1 15 Accept/Select Wait t2
18536 3 140044840 1 15 Runnable t1
18537 * 4 140056040 1 15 Runnable t3
18538 (@value{GDBP}) b 15 task 2
18539 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18540 (@value{GDBP}) cont
18541 Continuing.
18542 task # 1 running
18543 task # 2 running
18544
18545 Breakpoint 5, test_task_debug () at test_task_debug.adb:15
18546 15 flush;
18547 (@value{GDBP}) info tasks
18548 ID TID P-ID Pri State Name
18549 1 140022020 0 15 Child Activation Wait main_task
18550 * 2 140045060 1 15 Runnable t2
18551 3 140044840 1 15 Runnable t1
18552 4 140056040 1 15 Delay Sleep t3
18553 @end smallexample
18554 @end table
18555
18556 @node Ada Tasks and Core Files
18557 @subsubsection Tasking Support when Debugging Core Files
18558 @cindex Ada tasking and core file debugging
18559
18560 When inspecting a core file, as opposed to debugging a live program,
18561 tasking support may be limited or even unavailable, depending on
18562 the platform being used.
18563 For instance, on x86-linux, the list of tasks is available, but task
18564 switching is not supported.
18565
18566 On certain platforms, the debugger needs to perform some
18567 memory writes in order to provide Ada tasking support. When inspecting
18568 a core file, this means that the core file must be opened with read-write
18569 privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18570 Under these circumstances, you should make a backup copy of the core
18571 file before inspecting it with @value{GDBN}.
18572
18573 @node Ravenscar Profile
18574 @subsubsection Tasking Support when using the Ravenscar Profile
18575 @cindex Ravenscar Profile
18576
18577 The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18578 specifically designed for systems with safety-critical real-time
18579 requirements.
18580
18581 @table @code
18582 @kindex set ravenscar task-switching on
18583 @cindex task switching with program using Ravenscar Profile
18584 @item set ravenscar task-switching on
18585 Allows task switching when debugging a program that uses the Ravenscar
18586 Profile. This is the default.
18587
18588 @kindex set ravenscar task-switching off
18589 @item set ravenscar task-switching off
18590 Turn off task switching when debugging a program that uses the Ravenscar
18591 Profile. This is mostly intended to disable the code that adds support
18592 for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
18593 the Ravenscar runtime is preventing @value{GDBN} from working properly.
18594 To be effective, this command should be run before the program is started.
18595
18596 @kindex show ravenscar task-switching
18597 @item show ravenscar task-switching
18598 Show whether it is possible to switch from task to task in a program
18599 using the Ravenscar Profile.
18600
18601 @end table
18602
18603 @cindex Ravenscar thread
18604 When Ravenscar task-switching is enabled, Ravenscar tasks are
18605 announced by @value{GDBN} as if they were threads:
18606
18607 @smallexample
18608 (gdb) continue
18609 [New Ravenscar Thread 0x2b8f0]
18610 @end smallexample
18611
18612 Both Ravenscar tasks and the underlying CPU threads will show up in
18613 the output of @code{info threads}:
18614
18615 @smallexample
18616 (gdb) info threads
18617 Id Target Id Frame
18618 1 Thread 1 (CPU#0 [running]) simple () at simple.adb:10
18619 2 Thread 2 (CPU#1 [running]) 0x0000000000003d34 in __gnat_initialize_cpu_devices ()
18620 3 Thread 3 (CPU#2 [running]) 0x0000000000003d28 in __gnat_initialize_cpu_devices ()
18621 4 Thread 4 (CPU#3 [halted ]) 0x000000000000c6ec in system.task_primitives.operations.idle ()
18622 * 5 Ravenscar Thread 0x2b8f0 simple () at simple.adb:10
18623 6 Ravenscar Thread 0x2f150 0x000000000000c6ec in system.task_primitives.operations.idle ()
18624 @end smallexample
18625
18626 One known limitation of the Ravenscar support in @value{GDBN} is that
18627 it isn't currently possible to single-step through the runtime
18628 initialization sequence. If you need to debug this code, you should
18629 use @code{set ravenscar task-switching off}.
18630
18631 @node Ada Settings
18632 @subsubsection Ada Settings
18633 @cindex Ada settings
18634
18635 @table @code
18636 @kindex set varsize-limit
18637 @item set varsize-limit @var{size}
18638 Prevent @value{GDBN} from attempting to evaluate objects whose size
18639 is above the given limit (@var{size}) when those sizes are computed
18640 from run-time quantities. This is typically the case when the object
18641 has a variable size, such as an array whose bounds are not known at
18642 compile time for example. Setting @var{size} to @code{unlimited}
18643 removes the size limitation. By default, the limit is about 65KB.
18644
18645 The purpose of having such a limit is to prevent @value{GDBN} from
18646 trying to grab enormous chunks of virtual memory when asked to evaluate
18647 a quantity whose bounds have been corrupted or have not yet been fully
18648 initialized. The limit applies to the results of some subexpressions
18649 as well as to complete expressions. For example, an expression denoting
18650 a simple integer component, such as @code{x.y.z}, may fail if the size of
18651 @code{x.y} is variable and exceeds @code{size}. On the other hand,
18652 @value{GDBN} is sometimes clever; the expression @code{A(i)}, where
18653 @code{A} is an array variable with non-constant size, will generally
18654 succeed regardless of the bounds on @code{A}, as long as the component
18655 size is less than @var{size}.
18656
18657 @kindex show varsize-limit
18658 @item show varsize-limit
18659 Show the limit on types whose size is determined by run-time quantities.
18660 @end table
18661
18662 @node Ada Glitches
18663 @subsubsection Known Peculiarities of Ada Mode
18664 @cindex Ada, problems
18665
18666 Besides the omissions listed previously (@pxref{Omissions from Ada}),
18667 we know of several problems with and limitations of Ada mode in
18668 @value{GDBN},
18669 some of which will be fixed with planned future releases of the debugger
18670 and the GNU Ada compiler.
18671
18672 @itemize @bullet
18673 @item
18674 Static constants that the compiler chooses not to materialize as objects in
18675 storage are invisible to the debugger.
18676
18677 @item
18678 Named parameter associations in function argument lists are ignored (the
18679 argument lists are treated as positional).
18680
18681 @item
18682 Many useful library packages are currently invisible to the debugger.
18683
18684 @item
18685 Fixed-point arithmetic, conversions, input, and output is carried out using
18686 floating-point arithmetic, and may give results that only approximate those on
18687 the host machine.
18688
18689 @item
18690 The GNAT compiler never generates the prefix @code{Standard} for any of
18691 the standard symbols defined by the Ada language. @value{GDBN} knows about
18692 this: it will strip the prefix from names when you use it, and will never
18693 look for a name you have so qualified among local symbols, nor match against
18694 symbols in other packages or subprograms. If you have
18695 defined entities anywhere in your program other than parameters and
18696 local variables whose simple names match names in @code{Standard},
18697 GNAT's lack of qualification here can cause confusion. When this happens,
18698 you can usually resolve the confusion
18699 by qualifying the problematic names with package
18700 @code{Standard} explicitly.
18701 @end itemize
18702
18703 Older versions of the compiler sometimes generate erroneous debugging
18704 information, resulting in the debugger incorrectly printing the value
18705 of affected entities. In some cases, the debugger is able to work
18706 around an issue automatically. In other cases, the debugger is able
18707 to work around the issue, but the work-around has to be specifically
18708 enabled.
18709
18710 @kindex set ada trust-PAD-over-XVS
18711 @kindex show ada trust-PAD-over-XVS
18712 @table @code
18713
18714 @item set ada trust-PAD-over-XVS on
18715 Configure GDB to strictly follow the GNAT encoding when computing the
18716 value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
18717 types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
18718 a complete description of the encoding used by the GNAT compiler).
18719 This is the default.
18720
18721 @item set ada trust-PAD-over-XVS off
18722 This is related to the encoding using by the GNAT compiler. If @value{GDBN}
18723 sometimes prints the wrong value for certain entities, changing @code{ada
18724 trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
18725 the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
18726 @code{off}, but this incurs a slight performance penalty, so it is
18727 recommended to leave this setting to @code{on} unless necessary.
18728
18729 @end table
18730
18731 @cindex GNAT descriptive types
18732 @cindex GNAT encoding
18733 Internally, the debugger also relies on the compiler following a number
18734 of conventions known as the @samp{GNAT Encoding}, all documented in
18735 @file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
18736 how the debugging information should be generated for certain types.
18737 In particular, this convention makes use of @dfn{descriptive types},
18738 which are artificial types generated purely to help the debugger.
18739
18740 These encodings were defined at a time when the debugging information
18741 format used was not powerful enough to describe some of the more complex
18742 types available in Ada. Since DWARF allows us to express nearly all
18743 Ada features, the long-term goal is to slowly replace these descriptive
18744 types by their pure DWARF equivalent. To facilitate that transition,
18745 a new maintenance option is available to force the debugger to ignore
18746 those descriptive types. It allows the user to quickly evaluate how
18747 well @value{GDBN} works without them.
18748
18749 @table @code
18750
18751 @kindex maint ada set ignore-descriptive-types
18752 @item maintenance ada set ignore-descriptive-types [on|off]
18753 Control whether the debugger should ignore descriptive types.
18754 The default is not to ignore descriptives types (@code{off}).
18755
18756 @kindex maint ada show ignore-descriptive-types
18757 @item maintenance ada show ignore-descriptive-types
18758 Show if descriptive types are ignored by @value{GDBN}.
18759
18760 @end table
18761
18762 @node Unsupported Languages
18763 @section Unsupported Languages
18764
18765 @cindex unsupported languages
18766 @cindex minimal language
18767 In addition to the other fully-supported programming languages,
18768 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
18769 It does not represent a real programming language, but provides a set
18770 of capabilities close to what the C or assembly languages provide.
18771 This should allow most simple operations to be performed while debugging
18772 an application that uses a language currently not supported by @value{GDBN}.
18773
18774 If the language is set to @code{auto}, @value{GDBN} will automatically
18775 select this language if the current frame corresponds to an unsupported
18776 language.
18777
18778 @node Symbols
18779 @chapter Examining the Symbol Table
18780
18781 The commands described in this chapter allow you to inquire about the
18782 symbols (names of variables, functions and types) defined in your
18783 program. This information is inherent in the text of your program and
18784 does not change as your program executes. @value{GDBN} finds it in your
18785 program's symbol table, in the file indicated when you started @value{GDBN}
18786 (@pxref{File Options, ,Choosing Files}), or by one of the
18787 file-management commands (@pxref{Files, ,Commands to Specify Files}).
18788
18789 @cindex symbol names
18790 @cindex names of symbols
18791 @cindex quoting names
18792 @anchor{quoting names}
18793 Occasionally, you may need to refer to symbols that contain unusual
18794 characters, which @value{GDBN} ordinarily treats as word delimiters. The
18795 most frequent case is in referring to static variables in other
18796 source files (@pxref{Variables,,Program Variables}). File names
18797 are recorded in object files as debugging symbols, but @value{GDBN} would
18798 ordinarily parse a typical file name, like @file{foo.c}, as the three words
18799 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
18800 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
18801
18802 @smallexample
18803 p 'foo.c'::x
18804 @end smallexample
18805
18806 @noindent
18807 looks up the value of @code{x} in the scope of the file @file{foo.c}.
18808
18809 @table @code
18810 @cindex case-insensitive symbol names
18811 @cindex case sensitivity in symbol names
18812 @kindex set case-sensitive
18813 @item set case-sensitive on
18814 @itemx set case-sensitive off
18815 @itemx set case-sensitive auto
18816 Normally, when @value{GDBN} looks up symbols, it matches their names
18817 with case sensitivity determined by the current source language.
18818 Occasionally, you may wish to control that. The command @code{set
18819 case-sensitive} lets you do that by specifying @code{on} for
18820 case-sensitive matches or @code{off} for case-insensitive ones. If
18821 you specify @code{auto}, case sensitivity is reset to the default
18822 suitable for the source language. The default is case-sensitive
18823 matches for all languages except for Fortran, for which the default is
18824 case-insensitive matches.
18825
18826 @kindex show case-sensitive
18827 @item show case-sensitive
18828 This command shows the current setting of case sensitivity for symbols
18829 lookups.
18830
18831 @kindex set print type methods
18832 @item set print type methods
18833 @itemx set print type methods on
18834 @itemx set print type methods off
18835 Normally, when @value{GDBN} prints a class, it displays any methods
18836 declared in that class. You can control this behavior either by
18837 passing the appropriate flag to @code{ptype}, or using @command{set
18838 print type methods}. Specifying @code{on} will cause @value{GDBN} to
18839 display the methods; this is the default. Specifying @code{off} will
18840 cause @value{GDBN} to omit the methods.
18841
18842 @kindex show print type methods
18843 @item show print type methods
18844 This command shows the current setting of method display when printing
18845 classes.
18846
18847 @kindex set print type nested-type-limit
18848 @item set print type nested-type-limit @var{limit}
18849 @itemx set print type nested-type-limit unlimited
18850 Set the limit of displayed nested types that the type printer will
18851 show. A @var{limit} of @code{unlimited} or @code{-1} will show all
18852 nested definitions. By default, the type printer will not show any nested
18853 types defined in classes.
18854
18855 @kindex show print type nested-type-limit
18856 @item show print type nested-type-limit
18857 This command shows the current display limit of nested types when
18858 printing classes.
18859
18860 @kindex set print type typedefs
18861 @item set print type typedefs
18862 @itemx set print type typedefs on
18863 @itemx set print type typedefs off
18864
18865 Normally, when @value{GDBN} prints a class, it displays any typedefs
18866 defined in that class. You can control this behavior either by
18867 passing the appropriate flag to @code{ptype}, or using @command{set
18868 print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
18869 display the typedef definitions; this is the default. Specifying
18870 @code{off} will cause @value{GDBN} to omit the typedef definitions.
18871 Note that this controls whether the typedef definition itself is
18872 printed, not whether typedef names are substituted when printing other
18873 types.
18874
18875 @kindex show print type typedefs
18876 @item show print type typedefs
18877 This command shows the current setting of typedef display when
18878 printing classes.
18879
18880 @kindex info address
18881 @cindex address of a symbol
18882 @item info address @var{symbol}
18883 Describe where the data for @var{symbol} is stored. For a register
18884 variable, this says which register it is kept in. For a non-register
18885 local variable, this prints the stack-frame offset at which the variable
18886 is always stored.
18887
18888 Note the contrast with @samp{print &@var{symbol}}, which does not work
18889 at all for a register variable, and for a stack local variable prints
18890 the exact address of the current instantiation of the variable.
18891
18892 @kindex info symbol
18893 @cindex symbol from address
18894 @cindex closest symbol and offset for an address
18895 @item info symbol @var{addr}
18896 Print the name of a symbol which is stored at the address @var{addr}.
18897 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
18898 nearest symbol and an offset from it:
18899
18900 @smallexample
18901 (@value{GDBP}) info symbol 0x54320
18902 _initialize_vx + 396 in section .text
18903 @end smallexample
18904
18905 @noindent
18906 This is the opposite of the @code{info address} command. You can use
18907 it to find out the name of a variable or a function given its address.
18908
18909 For dynamically linked executables, the name of executable or shared
18910 library containing the symbol is also printed:
18911
18912 @smallexample
18913 (@value{GDBP}) info symbol 0x400225
18914 _start + 5 in section .text of /tmp/a.out
18915 (@value{GDBP}) info symbol 0x2aaaac2811cf
18916 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
18917 @end smallexample
18918
18919 @kindex demangle
18920 @cindex demangle
18921 @item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
18922 Demangle @var{name}.
18923 If @var{language} is provided it is the name of the language to demangle
18924 @var{name} in. Otherwise @var{name} is demangled in the current language.
18925
18926 The @samp{--} option specifies the end of options,
18927 and is useful when @var{name} begins with a dash.
18928
18929 The parameter @code{demangle-style} specifies how to interpret the kind
18930 of mangling used. @xref{Print Settings}.
18931
18932 @kindex whatis
18933 @item whatis[/@var{flags}] [@var{arg}]
18934 Print the data type of @var{arg}, which can be either an expression
18935 or a name of a data type. With no argument, print the data type of
18936 @code{$}, the last value in the value history.
18937
18938 If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
18939 is not actually evaluated, and any side-effecting operations (such as
18940 assignments or function calls) inside it do not take place.
18941
18942 If @var{arg} is a variable or an expression, @code{whatis} prints its
18943 literal type as it is used in the source code. If the type was
18944 defined using a @code{typedef}, @code{whatis} will @emph{not} print
18945 the data type underlying the @code{typedef}. If the type of the
18946 variable or the expression is a compound data type, such as
18947 @code{struct} or @code{class}, @code{whatis} never prints their
18948 fields or methods. It just prints the @code{struct}/@code{class}
18949 name (a.k.a.@: its @dfn{tag}). If you want to see the members of
18950 such a compound data type, use @code{ptype}.
18951
18952 If @var{arg} is a type name that was defined using @code{typedef},
18953 @code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
18954 Unrolling means that @code{whatis} will show the underlying type used
18955 in the @code{typedef} declaration of @var{arg}. However, if that
18956 underlying type is also a @code{typedef}, @code{whatis} will not
18957 unroll it.
18958
18959 For C code, the type names may also have the form @samp{class
18960 @var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
18961 @var{union-tag}} or @samp{enum @var{enum-tag}}.
18962
18963 @var{flags} can be used to modify how the type is displayed.
18964 Available flags are:
18965
18966 @table @code
18967 @item r
18968 Display in ``raw'' form. Normally, @value{GDBN} substitutes template
18969 parameters and typedefs defined in a class when printing the class'
18970 members. The @code{/r} flag disables this.
18971
18972 @item m
18973 Do not print methods defined in the class.
18974
18975 @item M
18976 Print methods defined in the class. This is the default, but the flag
18977 exists in case you change the default with @command{set print type methods}.
18978
18979 @item t
18980 Do not print typedefs defined in the class. Note that this controls
18981 whether the typedef definition itself is printed, not whether typedef
18982 names are substituted when printing other types.
18983
18984 @item T
18985 Print typedefs defined in the class. This is the default, but the flag
18986 exists in case you change the default with @command{set print type typedefs}.
18987
18988 @item o
18989 Print the offsets and sizes of fields in a struct, similar to what the
18990 @command{pahole} tool does. This option implies the @code{/tm} flags.
18991
18992 For example, given the following declarations:
18993
18994 @smallexample
18995 struct tuv
18996 @{
18997 int a1;
18998 char *a2;
18999 int a3;
19000 @};
19001
19002 struct xyz
19003 @{
19004 int f1;
19005 char f2;
19006 void *f3;
19007 struct tuv f4;
19008 @};
19009
19010 union qwe
19011 @{
19012 struct tuv fff1;
19013 struct xyz fff2;
19014 @};
19015
19016 struct tyu
19017 @{
19018 int a1 : 1;
19019 int a2 : 3;
19020 int a3 : 23;
19021 char a4 : 2;
19022 int64_t a5;
19023 int a6 : 5;
19024 int64_t a7 : 3;
19025 @};
19026 @end smallexample
19027
19028 Issuing a @kbd{ptype /o struct tuv} command would print:
19029
19030 @smallexample
19031 (@value{GDBP}) ptype /o struct tuv
19032 /* offset | size */ type = struct tuv @{
19033 /* 0 | 4 */ int a1;
19034 /* XXX 4-byte hole */
19035 /* 8 | 8 */ char *a2;
19036 /* 16 | 4 */ int a3;
19037
19038 /* total size (bytes): 24 */
19039 @}
19040 @end smallexample
19041
19042 Notice the format of the first column of comments. There, you can
19043 find two parts separated by the @samp{|} character: the @emph{offset},
19044 which indicates where the field is located inside the struct, in
19045 bytes, and the @emph{size} of the field. Another interesting line is
19046 the marker of a @emph{hole} in the struct, indicating that it may be
19047 possible to pack the struct and make it use less space by reorganizing
19048 its fields.
19049
19050 It is also possible to print offsets inside an union:
19051
19052 @smallexample
19053 (@value{GDBP}) ptype /o union qwe
19054 /* offset | size */ type = union qwe @{
19055 /* 24 */ struct tuv @{
19056 /* 0 | 4 */ int a1;
19057 /* XXX 4-byte hole */
19058 /* 8 | 8 */ char *a2;
19059 /* 16 | 4 */ int a3;
19060
19061 /* total size (bytes): 24 */
19062 @} fff1;
19063 /* 40 */ struct xyz @{
19064 /* 0 | 4 */ int f1;
19065 /* 4 | 1 */ char f2;
19066 /* XXX 3-byte hole */
19067 /* 8 | 8 */ void *f3;
19068 /* 16 | 24 */ struct tuv @{
19069 /* 16 | 4 */ int a1;
19070 /* XXX 4-byte hole */
19071 /* 24 | 8 */ char *a2;
19072 /* 32 | 4 */ int a3;
19073
19074 /* total size (bytes): 24 */
19075 @} f4;
19076
19077 /* total size (bytes): 40 */
19078 @} fff2;
19079
19080 /* total size (bytes): 40 */
19081 @}
19082 @end smallexample
19083
19084 In this case, since @code{struct tuv} and @code{struct xyz} occupy the
19085 same space (because we are dealing with an union), the offset is not
19086 printed for them. However, you can still examine the offset of each
19087 of these structures' fields.
19088
19089 Another useful scenario is printing the offsets of a struct containing
19090 bitfields:
19091
19092 @smallexample
19093 (@value{GDBP}) ptype /o struct tyu
19094 /* offset | size */ type = struct tyu @{
19095 /* 0:31 | 4 */ int a1 : 1;
19096 /* 0:28 | 4 */ int a2 : 3;
19097 /* 0: 5 | 4 */ int a3 : 23;
19098 /* 3: 3 | 1 */ signed char a4 : 2;
19099 /* XXX 3-bit hole */
19100 /* XXX 4-byte hole */
19101 /* 8 | 8 */ int64_t a5;
19102 /* 16: 0 | 4 */ int a6 : 5;
19103 /* 16: 5 | 8 */ int64_t a7 : 3;
19104 "/* XXX 7-byte padding */
19105
19106 /* total size (bytes): 24 */
19107 @}
19108 @end smallexample
19109
19110 Note how the offset information is now extended to also include the
19111 first bit of the bitfield.
19112 @end table
19113
19114 @kindex ptype
19115 @item ptype[/@var{flags}] [@var{arg}]
19116 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
19117 detailed description of the type, instead of just the name of the type.
19118 @xref{Expressions, ,Expressions}.
19119
19120 Contrary to @code{whatis}, @code{ptype} always unrolls any
19121 @code{typedef}s in its argument declaration, whether the argument is
19122 a variable, expression, or a data type. This means that @code{ptype}
19123 of a variable or an expression will not print literally its type as
19124 present in the source code---use @code{whatis} for that. @code{typedef}s at
19125 the pointer or reference targets are also unrolled. Only @code{typedef}s of
19126 fields, methods and inner @code{class typedef}s of @code{struct}s,
19127 @code{class}es and @code{union}s are not unrolled even with @code{ptype}.
19128
19129 For example, for this variable declaration:
19130
19131 @smallexample
19132 typedef double real_t;
19133 struct complex @{ real_t real; double imag; @};
19134 typedef struct complex complex_t;
19135 complex_t var;
19136 real_t *real_pointer_var;
19137 @end smallexample
19138
19139 @noindent
19140 the two commands give this output:
19141
19142 @smallexample
19143 @group
19144 (@value{GDBP}) whatis var
19145 type = complex_t
19146 (@value{GDBP}) ptype var
19147 type = struct complex @{
19148 real_t real;
19149 double imag;
19150 @}
19151 (@value{GDBP}) whatis complex_t
19152 type = struct complex
19153 (@value{GDBP}) whatis struct complex
19154 type = struct complex
19155 (@value{GDBP}) ptype struct complex
19156 type = struct complex @{
19157 real_t real;
19158 double imag;
19159 @}
19160 (@value{GDBP}) whatis real_pointer_var
19161 type = real_t *
19162 (@value{GDBP}) ptype real_pointer_var
19163 type = double *
19164 @end group
19165 @end smallexample
19166
19167 @noindent
19168 As with @code{whatis}, using @code{ptype} without an argument refers to
19169 the type of @code{$}, the last value in the value history.
19170
19171 @cindex incomplete type
19172 Sometimes, programs use opaque data types or incomplete specifications
19173 of complex data structure. If the debug information included in the
19174 program does not allow @value{GDBN} to display a full declaration of
19175 the data type, it will say @samp{<incomplete type>}. For example,
19176 given these declarations:
19177
19178 @smallexample
19179 struct foo;
19180 struct foo *fooptr;
19181 @end smallexample
19182
19183 @noindent
19184 but no definition for @code{struct foo} itself, @value{GDBN} will say:
19185
19186 @smallexample
19187 (@value{GDBP}) ptype foo
19188 $1 = <incomplete type>
19189 @end smallexample
19190
19191 @noindent
19192 ``Incomplete type'' is C terminology for data types that are not
19193 completely specified.
19194
19195 @cindex unknown type
19196 Othertimes, information about a variable's type is completely absent
19197 from the debug information included in the program. This most often
19198 happens when the program or library where the variable is defined
19199 includes no debug information at all. @value{GDBN} knows the variable
19200 exists from inspecting the linker/loader symbol table (e.g., the ELF
19201 dynamic symbol table), but such symbols do not contain type
19202 information. Inspecting the type of a (global) variable for which
19203 @value{GDBN} has no type information shows:
19204
19205 @smallexample
19206 (@value{GDBP}) ptype var
19207 type = <data variable, no debug info>
19208 @end smallexample
19209
19210 @xref{Variables, no debug info variables}, for how to print the values
19211 of such variables.
19212
19213 @kindex info types
19214 @item info types [-q] [@var{regexp}]
19215 Print a brief description of all types whose names match the regular
19216 expression @var{regexp} (or all types in your program, if you supply
19217 no argument). Each complete typename is matched as though it were a
19218 complete line; thus, @samp{i type value} gives information on all
19219 types in your program whose names include the string @code{value}, but
19220 @samp{i type ^value$} gives information only on types whose complete
19221 name is @code{value}.
19222
19223 In programs using different languages, @value{GDBN} chooses the syntax
19224 to print the type description according to the
19225 @samp{set language} value: using @samp{set language auto}
19226 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19227 language of the type, other values mean to use
19228 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19229
19230 This command differs from @code{ptype} in two ways: first, like
19231 @code{whatis}, it does not print a detailed description; second, it
19232 lists all source files and line numbers where a type is defined.
19233
19234 The output from @samp{into types} is proceeded with a header line
19235 describing what types are being listed. The optional flag @samp{-q},
19236 which stands for @samp{quiet}, disables printing this header
19237 information.
19238
19239 @kindex info type-printers
19240 @item info type-printers
19241 Versions of @value{GDBN} that ship with Python scripting enabled may
19242 have ``type printers'' available. When using @command{ptype} or
19243 @command{whatis}, these printers are consulted when the name of a type
19244 is needed. @xref{Type Printing API}, for more information on writing
19245 type printers.
19246
19247 @code{info type-printers} displays all the available type printers.
19248
19249 @kindex enable type-printer
19250 @kindex disable type-printer
19251 @item enable type-printer @var{name}@dots{}
19252 @item disable type-printer @var{name}@dots{}
19253 These commands can be used to enable or disable type printers.
19254
19255 @kindex info scope
19256 @cindex local variables
19257 @item info scope @var{location}
19258 List all the variables local to a particular scope. This command
19259 accepts a @var{location} argument---a function name, a source line, or
19260 an address preceded by a @samp{*}, and prints all the variables local
19261 to the scope defined by that location. (@xref{Specify Location}, for
19262 details about supported forms of @var{location}.) For example:
19263
19264 @smallexample
19265 (@value{GDBP}) @b{info scope command_line_handler}
19266 Scope for command_line_handler:
19267 Symbol rl is an argument at stack/frame offset 8, length 4.
19268 Symbol linebuffer is in static storage at address 0x150a18, length 4.
19269 Symbol linelength is in static storage at address 0x150a1c, length 4.
19270 Symbol p is a local variable in register $esi, length 4.
19271 Symbol p1 is a local variable in register $ebx, length 4.
19272 Symbol nline is a local variable in register $edx, length 4.
19273 Symbol repeat is a local variable at frame offset -8, length 4.
19274 @end smallexample
19275
19276 @noindent
19277 This command is especially useful for determining what data to collect
19278 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
19279 collect}.
19280
19281 @kindex info source
19282 @item info source
19283 Show information about the current source file---that is, the source file for
19284 the function containing the current point of execution:
19285 @itemize @bullet
19286 @item
19287 the name of the source file, and the directory containing it,
19288 @item
19289 the directory it was compiled in,
19290 @item
19291 its length, in lines,
19292 @item
19293 which programming language it is written in,
19294 @item
19295 if the debug information provides it, the program that compiled the file
19296 (which may include, e.g., the compiler version and command line arguments),
19297 @item
19298 whether the executable includes debugging information for that file, and
19299 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
19300 @item
19301 whether the debugging information includes information about
19302 preprocessor macros.
19303 @end itemize
19304
19305
19306 @kindex info sources
19307 @item info sources
19308 Print the names of all source files in your program for which there is
19309 debugging information, organized into two lists: files whose symbols
19310 have already been read, and files whose symbols will be read when needed.
19311
19312 @item info sources [-dirname | -basename] [--] [@var{regexp}]
19313 Like @samp{info sources}, but only print the names of the files
19314 matching the provided @var{regexp}.
19315 By default, the @var{regexp} is used to match anywhere in the filename.
19316 If @code{-dirname}, only files having a dirname matching @var{regexp} are shown.
19317 If @code{-basename}, only files having a basename matching @var{regexp}
19318 are shown.
19319 The matching is case-sensitive, except on operating systems that
19320 have case-insensitive filesystem (e.g., MS-Windows).
19321
19322 @kindex info functions
19323 @item info functions [-q] [-n]
19324 Print the names and data types of all defined functions.
19325 Similarly to @samp{info types}, this command groups its output by source
19326 files and annotates each function definition with its source line
19327 number.
19328
19329 In programs using different languages, @value{GDBN} chooses the syntax
19330 to print the function name and type according to the
19331 @samp{set language} value: using @samp{set language auto}
19332 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19333 language of the function, other values mean to use
19334 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19335
19336 The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
19337 results. A non-debugging symbol is a symbol that comes from the
19338 executable's symbol table, not from the debug information (for
19339 example, DWARF) associated with the executable.
19340
19341 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19342 printing header information and messages explaining why no functions
19343 have been printed.
19344
19345 @item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
19346 Like @samp{info functions}, but only print the names and data types
19347 of the functions selected with the provided regexp(s).
19348
19349 If @var{regexp} is provided, print only the functions whose names
19350 match the regular expression @var{regexp}.
19351 Thus, @samp{info fun step} finds all functions whose
19352 names include @code{step}; @samp{info fun ^step} finds those whose names
19353 start with @code{step}. If a function name contains characters that
19354 conflict with the regular expression language (e.g.@:
19355 @samp{operator*()}), they may be quoted with a backslash.
19356
19357 If @var{type_regexp} is provided, print only the functions whose
19358 types, as printed by the @code{whatis} command, match
19359 the regular expression @var{type_regexp}.
19360 If @var{type_regexp} contains space(s), it should be enclosed in
19361 quote characters. If needed, use backslash to escape the meaning
19362 of special characters or quotes.
19363 Thus, @samp{info fun -t '^int ('} finds the functions that return
19364 an integer; @samp{info fun -t '(.*int.*'} finds the functions that
19365 have an argument type containing int; @samp{info fun -t '^int (' ^step}
19366 finds the functions whose names start with @code{step} and that return
19367 int.
19368
19369 If both @var{regexp} and @var{type_regexp} are provided, a function
19370 is printed only if its name matches @var{regexp} and its type matches
19371 @var{type_regexp}.
19372
19373
19374 @kindex info variables
19375 @item info variables [-q] [-n]
19376 Print the names and data types of all variables that are defined
19377 outside of functions (i.e.@: excluding local variables).
19378 The printed variables are grouped by source files and annotated with
19379 their respective source line numbers.
19380
19381 In programs using different languages, @value{GDBN} chooses the syntax
19382 to print the variable name and type according to the
19383 @samp{set language} value: using @samp{set language auto}
19384 (see @ref{Automatically, ,Set Language Automatically}) means to use the
19385 language of the variable, other values mean to use
19386 the manually specified language (see @ref{Manually, ,Set Language Manually}).
19387
19388 The @samp{-n} flag excludes non-debugging symbols from the results.
19389
19390 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19391 printing header information and messages explaining why no variables
19392 have been printed.
19393
19394 @item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
19395 Like @kbd{info variables}, but only print the variables selected
19396 with the provided regexp(s).
19397
19398 If @var{regexp} is provided, print only the variables whose names
19399 match the regular expression @var{regexp}.
19400
19401 If @var{type_regexp} is provided, print only the variables whose
19402 types, as printed by the @code{whatis} command, match
19403 the regular expression @var{type_regexp}.
19404 If @var{type_regexp} contains space(s), it should be enclosed in
19405 quote characters. If needed, use backslash to escape the meaning
19406 of special characters or quotes.
19407
19408 If both @var{regexp} and @var{type_regexp} are provided, an argument
19409 is printed only if its name matches @var{regexp} and its type matches
19410 @var{type_regexp}.
19411
19412 @kindex info modules
19413 @cindex modules
19414 @item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
19415 List all Fortran modules in the program, or all modules matching the
19416 optional regular expression @var{regexp}.
19417
19418 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19419 printing header information and messages explaining why no modules
19420 have been printed.
19421
19422 @kindex info module
19423 @cindex Fortran modules, information about
19424 @cindex functions and variables by Fortran module
19425 @cindex module functions and variables
19426 @item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19427 @itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19428 List all functions or variables within all Fortran modules. The set
19429 of functions or variables listed can be limited by providing some or
19430 all of the optional regular expressions. If @var{module-regexp} is
19431 provided, then only Fortran modules matching @var{module-regexp} will
19432 be searched. Only functions or variables whose type matches the
19433 optional regular expression @var{type-regexp} will be listed. And
19434 only functions or variables whose name matches the optional regular
19435 expression @var{regexp} will be listed.
19436
19437 The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19438 printing header information and messages explaining why no functions
19439 or variables have been printed.
19440
19441 @kindex info classes
19442 @cindex Objective-C, classes and selectors
19443 @item info classes
19444 @itemx info classes @var{regexp}
19445 Display all Objective-C classes in your program, or
19446 (with the @var{regexp} argument) all those matching a particular regular
19447 expression.
19448
19449 @kindex info selectors
19450 @item info selectors
19451 @itemx info selectors @var{regexp}
19452 Display all Objective-C selectors in your program, or
19453 (with the @var{regexp} argument) all those matching a particular regular
19454 expression.
19455
19456 @ignore
19457 This was never implemented.
19458 @kindex info methods
19459 @item info methods
19460 @itemx info methods @var{regexp}
19461 The @code{info methods} command permits the user to examine all defined
19462 methods within C@t{++} program, or (with the @var{regexp} argument) a
19463 specific set of methods found in the various C@t{++} classes. Many
19464 C@t{++} classes provide a large number of methods. Thus, the output
19465 from the @code{ptype} command can be overwhelming and hard to use. The
19466 @code{info-methods} command filters the methods, printing only those
19467 which match the regular-expression @var{regexp}.
19468 @end ignore
19469
19470 @cindex opaque data types
19471 @kindex set opaque-type-resolution
19472 @item set opaque-type-resolution on
19473 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
19474 declared as a pointer to a @code{struct}, @code{class}, or
19475 @code{union}---for example, @code{struct MyType *}---that is used in one
19476 source file although the full declaration of @code{struct MyType} is in
19477 another source file. The default is on.
19478
19479 A change in the setting of this subcommand will not take effect until
19480 the next time symbols for a file are loaded.
19481
19482 @item set opaque-type-resolution off
19483 Tell @value{GDBN} not to resolve opaque types. In this case, the type
19484 is printed as follows:
19485 @smallexample
19486 @{<no data fields>@}
19487 @end smallexample
19488
19489 @kindex show opaque-type-resolution
19490 @item show opaque-type-resolution
19491 Show whether opaque types are resolved or not.
19492
19493 @kindex set print symbol-loading
19494 @cindex print messages when symbols are loaded
19495 @item set print symbol-loading
19496 @itemx set print symbol-loading full
19497 @itemx set print symbol-loading brief
19498 @itemx set print symbol-loading off
19499 The @code{set print symbol-loading} command allows you to control the
19500 printing of messages when @value{GDBN} loads symbol information.
19501 By default a message is printed for the executable and one for each
19502 shared library, and normally this is what you want. However, when
19503 debugging apps with large numbers of shared libraries these messages
19504 can be annoying.
19505 When set to @code{brief} a message is printed for each executable,
19506 and when @value{GDBN} loads a collection of shared libraries at once
19507 it will only print one message regardless of the number of shared
19508 libraries. When set to @code{off} no messages are printed.
19509
19510 @kindex show print symbol-loading
19511 @item show print symbol-loading
19512 Show whether messages will be printed when a @value{GDBN} command
19513 entered from the keyboard causes symbol information to be loaded.
19514
19515 @kindex maint print symbols
19516 @cindex symbol dump
19517 @kindex maint print psymbols
19518 @cindex partial symbol dump
19519 @kindex maint print msymbols
19520 @cindex minimal symbol dump
19521 @item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19522 @itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19523 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19524 @itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19525 @itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19526 Write a dump of debugging symbol data into the file @var{filename} or
19527 the terminal if @var{filename} is unspecified.
19528 If @code{-objfile @var{objfile}} is specified, only dump symbols for
19529 that objfile.
19530 If @code{-pc @var{address}} is specified, only dump symbols for the file
19531 with code at that address. Note that @var{address} may be a symbol like
19532 @code{main}.
19533 If @code{-source @var{source}} is specified, only dump symbols for that
19534 source file.
19535
19536 These commands are used to debug the @value{GDBN} symbol-reading code.
19537 These commands do not modify internal @value{GDBN} state, therefore
19538 @samp{maint print symbols} will only print symbols for already expanded symbol
19539 tables.
19540 You can use the command @code{info sources} to find out which files these are.
19541 If you use @samp{maint print psymbols} instead, the dump shows information
19542 about symbols that @value{GDBN} only knows partially---that is, symbols
19543 defined in files that @value{GDBN} has skimmed, but not yet read completely.
19544 Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19545 ``ELF symbols''.
19546
19547 @xref{Files, ,Commands to Specify Files}, for a discussion of how
19548 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
19549
19550 @kindex maint info symtabs
19551 @kindex maint info psymtabs
19552 @cindex listing @value{GDBN}'s internal symbol tables
19553 @cindex symbol tables, listing @value{GDBN}'s internal
19554 @cindex full symbol tables, listing @value{GDBN}'s internal
19555 @cindex partial symbol tables, listing @value{GDBN}'s internal
19556 @item maint info symtabs @r{[} @var{regexp} @r{]}
19557 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
19558
19559 List the @code{struct symtab} or @code{struct partial_symtab}
19560 structures whose names match @var{regexp}. If @var{regexp} is not
19561 given, list them all. The output includes expressions which you can
19562 copy into a @value{GDBN} debugging this one to examine a particular
19563 structure in more detail. For example:
19564
19565 @smallexample
19566 (@value{GDBP}) maint info psymtabs dwarf2read
19567 @{ objfile /home/gnu/build/gdb/gdb
19568 ((struct objfile *) 0x82e69d0)
19569 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
19570 ((struct partial_symtab *) 0x8474b10)
19571 readin no
19572 fullname (null)
19573 text addresses 0x814d3c8 -- 0x8158074
19574 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
19575 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
19576 dependencies (none)
19577 @}
19578 @}
19579 (@value{GDBP}) maint info symtabs
19580 (@value{GDBP})
19581 @end smallexample
19582 @noindent
19583 We see that there is one partial symbol table whose filename contains
19584 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
19585 and we see that @value{GDBN} has not read in any symtabs yet at all.
19586 If we set a breakpoint on a function, that will cause @value{GDBN} to
19587 read the symtab for the compilation unit containing that function:
19588
19589 @smallexample
19590 (@value{GDBP}) break dwarf2_psymtab_to_symtab
19591 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
19592 line 1574.
19593 (@value{GDBP}) maint info symtabs
19594 @{ objfile /home/gnu/build/gdb/gdb
19595 ((struct objfile *) 0x82e69d0)
19596 @{ symtab /home/gnu/src/gdb/dwarf2read.c
19597 ((struct symtab *) 0x86c1f38)
19598 dirname (null)
19599 fullname (null)
19600 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
19601 linetable ((struct linetable *) 0x8370fa0)
19602 debugformat DWARF 2
19603 @}
19604 @}
19605 (@value{GDBP})
19606 @end smallexample
19607
19608 @kindex maint info line-table
19609 @cindex listing @value{GDBN}'s internal line tables
19610 @cindex line tables, listing @value{GDBN}'s internal
19611 @item maint info line-table @r{[} @var{regexp} @r{]}
19612
19613 List the @code{struct linetable} from all @code{struct symtab}
19614 instances whose name matches @var{regexp}. If @var{regexp} is not
19615 given, list the @code{struct linetable} from all @code{struct symtab}.
19616
19617 @kindex maint set symbol-cache-size
19618 @cindex symbol cache size
19619 @item maint set symbol-cache-size @var{size}
19620 Set the size of the symbol cache to @var{size}.
19621 The default size is intended to be good enough for debugging
19622 most applications. This option exists to allow for experimenting
19623 with different sizes.
19624
19625 @kindex maint show symbol-cache-size
19626 @item maint show symbol-cache-size
19627 Show the size of the symbol cache.
19628
19629 @kindex maint print symbol-cache
19630 @cindex symbol cache, printing its contents
19631 @item maint print symbol-cache
19632 Print the contents of the symbol cache.
19633 This is useful when debugging symbol cache issues.
19634
19635 @kindex maint print symbol-cache-statistics
19636 @cindex symbol cache, printing usage statistics
19637 @item maint print symbol-cache-statistics
19638 Print symbol cache usage statistics.
19639 This helps determine how well the cache is being utilized.
19640
19641 @kindex maint flush symbol-cache
19642 @kindex maint flush-symbol-cache
19643 @cindex symbol cache, flushing
19644 @item maint flush symbol-cache
19645 @itemx maint flush-symbol-cache
19646 Flush the contents of the symbol cache, all entries are removed. This
19647 command is useful when debugging the symbol cache. It is also useful
19648 when collecting performance data. The command @code{maint
19649 flush-symbol-cache} is deprecated in favor of @code{maint flush
19650 symbol-cache}..
19651
19652 @end table
19653
19654 @node Altering
19655 @chapter Altering Execution
19656
19657 Once you think you have found an error in your program, you might want to
19658 find out for certain whether correcting the apparent error would lead to
19659 correct results in the rest of the run. You can find the answer by
19660 experiment, using the @value{GDBN} features for altering execution of the
19661 program.
19662
19663 For example, you can store new values into variables or memory
19664 locations, give your program a signal, restart it at a different
19665 address, or even return prematurely from a function.
19666
19667 @menu
19668 * Assignment:: Assignment to variables
19669 * Jumping:: Continuing at a different address
19670 * Signaling:: Giving your program a signal
19671 * Returning:: Returning from a function
19672 * Calling:: Calling your program's functions
19673 * Patching:: Patching your program
19674 * Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
19675 @end menu
19676
19677 @node Assignment
19678 @section Assignment to Variables
19679
19680 @cindex assignment
19681 @cindex setting variables
19682 To alter the value of a variable, evaluate an assignment expression.
19683 @xref{Expressions, ,Expressions}. For example,
19684
19685 @smallexample
19686 print x=4
19687 @end smallexample
19688
19689 @noindent
19690 stores the value 4 into the variable @code{x}, and then prints the
19691 value of the assignment expression (which is 4).
19692 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
19693 information on operators in supported languages.
19694
19695 @kindex set variable
19696 @cindex variables, setting
19697 If you are not interested in seeing the value of the assignment, use the
19698 @code{set} command instead of the @code{print} command. @code{set} is
19699 really the same as @code{print} except that the expression's value is
19700 not printed and is not put in the value history (@pxref{Value History,
19701 ,Value History}). The expression is evaluated only for its effects.
19702
19703 If the beginning of the argument string of the @code{set} command
19704 appears identical to a @code{set} subcommand, use the @code{set
19705 variable} command instead of just @code{set}. This command is identical
19706 to @code{set} except for its lack of subcommands. For example, if your
19707 program has a variable @code{width}, you get an error if you try to set
19708 a new value with just @samp{set width=13}, because @value{GDBN} has the
19709 command @code{set width}:
19710
19711 @smallexample
19712 (@value{GDBP}) whatis width
19713 type = double
19714 (@value{GDBP}) p width
19715 $4 = 13
19716 (@value{GDBP}) set width=47
19717 Invalid syntax in expression.
19718 @end smallexample
19719
19720 @noindent
19721 The invalid expression, of course, is @samp{=47}. In
19722 order to actually set the program's variable @code{width}, use
19723
19724 @smallexample
19725 (@value{GDBP}) set var width=47
19726 @end smallexample
19727
19728 Because the @code{set} command has many subcommands that can conflict
19729 with the names of program variables, it is a good idea to use the
19730 @code{set variable} command instead of just @code{set}. For example, if
19731 your program has a variable @code{g}, you run into problems if you try
19732 to set a new value with just @samp{set g=4}, because @value{GDBN} has
19733 the command @code{set gnutarget}, abbreviated @code{set g}:
19734
19735 @smallexample
19736 @group
19737 (@value{GDBP}) whatis g
19738 type = double
19739 (@value{GDBP}) p g
19740 $1 = 1
19741 (@value{GDBP}) set g=4
19742 (@value{GDBP}) p g
19743 $2 = 1
19744 (@value{GDBP}) r
19745 The program being debugged has been started already.
19746 Start it from the beginning? (y or n) y
19747 Starting program: /home/smith/cc_progs/a.out
19748 "/home/smith/cc_progs/a.out": can't open to read symbols:
19749 Invalid bfd target.
19750 (@value{GDBP}) show g
19751 The current BFD target is "=4".
19752 @end group
19753 @end smallexample
19754
19755 @noindent
19756 The program variable @code{g} did not change, and you silently set the
19757 @code{gnutarget} to an invalid value. In order to set the variable
19758 @code{g}, use
19759
19760 @smallexample
19761 (@value{GDBP}) set var g=4
19762 @end smallexample
19763
19764 @value{GDBN} allows more implicit conversions in assignments than C; you can
19765 freely store an integer value into a pointer variable or vice versa,
19766 and you can convert any structure to any other structure that is the
19767 same length or shorter.
19768 @comment FIXME: how do structs align/pad in these conversions?
19769 @comment /doc@cygnus.com 18dec1990
19770
19771 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
19772 construct to generate a value of specified type at a specified address
19773 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
19774 to memory location @code{0x83040} as an integer (which implies a certain size
19775 and representation in memory), and
19776
19777 @smallexample
19778 set @{int@}0x83040 = 4
19779 @end smallexample
19780
19781 @noindent
19782 stores the value 4 into that memory location.
19783
19784 @node Jumping
19785 @section Continuing at a Different Address
19786
19787 Ordinarily, when you continue your program, you do so at the place where
19788 it stopped, with the @code{continue} command. You can instead continue at
19789 an address of your own choosing, with the following commands:
19790
19791 @table @code
19792 @kindex jump
19793 @kindex j @r{(@code{jump})}
19794 @item jump @var{location}
19795 @itemx j @var{location}
19796 Resume execution at @var{location}. Execution stops again immediately
19797 if there is a breakpoint there. @xref{Specify Location}, for a description
19798 of the different forms of @var{location}. It is common
19799 practice to use the @code{tbreak} command in conjunction with
19800 @code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
19801
19802 The @code{jump} command does not change the current stack frame, or
19803 the stack pointer, or the contents of any memory location or any
19804 register other than the program counter. If @var{location} is in
19805 a different function from the one currently executing, the results may
19806 be bizarre if the two functions expect different patterns of arguments or
19807 of local variables. For this reason, the @code{jump} command requests
19808 confirmation if the specified line is not in the function currently
19809 executing. However, even bizarre results are predictable if you are
19810 well acquainted with the machine-language code of your program.
19811 @end table
19812
19813 On many systems, you can get much the same effect as the @code{jump}
19814 command by storing a new value into the register @code{$pc}. The
19815 difference is that this does not start your program running; it only
19816 changes the address of where it @emph{will} run when you continue. For
19817 example,
19818
19819 @smallexample
19820 set $pc = 0x485
19821 @end smallexample
19822
19823 @noindent
19824 makes the next @code{continue} command or stepping command execute at
19825 address @code{0x485}, rather than at the address where your program stopped.
19826 @xref{Continuing and Stepping, ,Continuing and Stepping}.
19827
19828 The most common occasion to use the @code{jump} command is to back
19829 up---perhaps with more breakpoints set---over a portion of a program
19830 that has already executed, in order to examine its execution in more
19831 detail.
19832
19833 @c @group
19834 @node Signaling
19835 @section Giving your Program a Signal
19836 @cindex deliver a signal to a program
19837
19838 @table @code
19839 @kindex signal
19840 @item signal @var{signal}
19841 Resume execution where your program is stopped, but immediately give it the
19842 signal @var{signal}. The @var{signal} can be the name or the number of a
19843 signal. For example, on many systems @code{signal 2} and @code{signal
19844 SIGINT} are both ways of sending an interrupt signal.
19845
19846 Alternatively, if @var{signal} is zero, continue execution without
19847 giving a signal. This is useful when your program stopped on account of
19848 a signal and would ordinarily see the signal when resumed with the
19849 @code{continue} command; @samp{signal 0} causes it to resume without a
19850 signal.
19851
19852 @emph{Note:} When resuming a multi-threaded program, @var{signal} is
19853 delivered to the currently selected thread, not the thread that last
19854 reported a stop. This includes the situation where a thread was
19855 stopped due to a signal. So if you want to continue execution
19856 suppressing the signal that stopped a thread, you should select that
19857 same thread before issuing the @samp{signal 0} command. If you issue
19858 the @samp{signal 0} command with another thread as the selected one,
19859 @value{GDBN} detects that and asks for confirmation.
19860
19861 Invoking the @code{signal} command is not the same as invoking the
19862 @code{kill} utility from the shell. Sending a signal with @code{kill}
19863 causes @value{GDBN} to decide what to do with the signal depending on
19864 the signal handling tables (@pxref{Signals}). The @code{signal} command
19865 passes the signal directly to your program.
19866
19867 @code{signal} does not repeat when you press @key{RET} a second time
19868 after executing the command.
19869
19870 @kindex queue-signal
19871 @item queue-signal @var{signal}
19872 Queue @var{signal} to be delivered immediately to the current thread
19873 when execution of the thread resumes. The @var{signal} can be the name or
19874 the number of a signal. For example, on many systems @code{signal 2} and
19875 @code{signal SIGINT} are both ways of sending an interrupt signal.
19876 The handling of the signal must be set to pass the signal to the program,
19877 otherwise @value{GDBN} will report an error.
19878 You can control the handling of signals from @value{GDBN} with the
19879 @code{handle} command (@pxref{Signals}).
19880
19881 Alternatively, if @var{signal} is zero, any currently queued signal
19882 for the current thread is discarded and when execution resumes no signal
19883 will be delivered. This is useful when your program stopped on account
19884 of a signal and would ordinarily see the signal when resumed with the
19885 @code{continue} command.
19886
19887 This command differs from the @code{signal} command in that the signal
19888 is just queued, execution is not resumed. And @code{queue-signal} cannot
19889 be used to pass a signal whose handling state has been set to @code{nopass}
19890 (@pxref{Signals}).
19891 @end table
19892 @c @end group
19893
19894 @xref{stepping into signal handlers}, for information on how stepping
19895 commands behave when the thread has a signal queued.
19896
19897 @node Returning
19898 @section Returning from a Function
19899
19900 @table @code
19901 @cindex returning from a function
19902 @kindex return
19903 @item return
19904 @itemx return @var{expression}
19905 You can cancel execution of a function call with the @code{return}
19906 command. If you give an
19907 @var{expression} argument, its value is used as the function's return
19908 value.
19909 @end table
19910
19911 When you use @code{return}, @value{GDBN} discards the selected stack frame
19912 (and all frames within it). You can think of this as making the
19913 discarded frame return prematurely. If you wish to specify a value to
19914 be returned, give that value as the argument to @code{return}.
19915
19916 This pops the selected stack frame (@pxref{Selection, ,Selecting a
19917 Frame}), and any other frames inside of it, leaving its caller as the
19918 innermost remaining frame. That frame becomes selected. The
19919 specified value is stored in the registers used for returning values
19920 of functions.
19921
19922 The @code{return} command does not resume execution; it leaves the
19923 program stopped in the state that would exist if the function had just
19924 returned. In contrast, the @code{finish} command (@pxref{Continuing
19925 and Stepping, ,Continuing and Stepping}) resumes execution until the
19926 selected stack frame returns naturally.
19927
19928 @value{GDBN} needs to know how the @var{expression} argument should be set for
19929 the inferior. The concrete registers assignment depends on the OS ABI and the
19930 type being returned by the selected stack frame. For example it is common for
19931 OS ABI to return floating point values in FPU registers while integer values in
19932 CPU registers. Still some ABIs return even floating point values in CPU
19933 registers. Larger integer widths (such as @code{long long int}) also have
19934 specific placement rules. @value{GDBN} already knows the OS ABI from its
19935 current target so it needs to find out also the type being returned to make the
19936 assignment into the right register(s).
19937
19938 Normally, the selected stack frame has debug info. @value{GDBN} will always
19939 use the debug info instead of the implicit type of @var{expression} when the
19940 debug info is available. For example, if you type @kbd{return -1}, and the
19941 function in the current stack frame is declared to return a @code{long long
19942 int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
19943 into a @code{long long int}:
19944
19945 @smallexample
19946 Breakpoint 1, func () at gdb.base/return-nodebug.c:29
19947 29 return 31;
19948 (@value{GDBP}) return -1
19949 Make func return now? (y or n) y
19950 #0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
19951 43 printf ("result=%lld\n", func ());
19952 (@value{GDBP})
19953 @end smallexample
19954
19955 However, if the selected stack frame does not have a debug info, e.g., if the
19956 function was compiled without debug info, @value{GDBN} has to find out the type
19957 to return from user. Specifying a different type by mistake may set the value
19958 in different inferior registers than the caller code expects. For example,
19959 typing @kbd{return -1} with its implicit type @code{int} would set only a part
19960 of a @code{long long int} result for a debug info less function (on 32-bit
19961 architectures). Therefore the user is required to specify the return type by
19962 an appropriate cast explicitly:
19963
19964 @smallexample
19965 Breakpoint 2, 0x0040050b in func ()
19966 (@value{GDBP}) return -1
19967 Return value type not available for selected stack frame.
19968 Please use an explicit cast of the value to return.
19969 (@value{GDBP}) return (long long int) -1
19970 Make selected stack frame return now? (y or n) y
19971 #0 0x00400526 in main ()
19972 (@value{GDBP})
19973 @end smallexample
19974
19975 @node Calling
19976 @section Calling Program Functions
19977
19978 @table @code
19979 @cindex calling functions
19980 @cindex inferior functions, calling
19981 @item print @var{expr}
19982 Evaluate the expression @var{expr} and display the resulting value.
19983 The expression may include calls to functions in the program being
19984 debugged.
19985
19986 @kindex call
19987 @item call @var{expr}
19988 Evaluate the expression @var{expr} without displaying @code{void}
19989 returned values.
19990
19991 You can use this variant of the @code{print} command if you want to
19992 execute a function from your program that does not return anything
19993 (a.k.a.@: @dfn{a void function}), but without cluttering the output
19994 with @code{void} returned values that @value{GDBN} will otherwise
19995 print. If the result is not void, it is printed and saved in the
19996 value history.
19997 @end table
19998
19999 It is possible for the function you call via the @code{print} or
20000 @code{call} command to generate a signal (e.g., if there's a bug in
20001 the function, or if you passed it incorrect arguments). What happens
20002 in that case is controlled by the @code{set unwindonsignal} command.
20003
20004 Similarly, with a C@t{++} program it is possible for the function you
20005 call via the @code{print} or @code{call} command to generate an
20006 exception that is not handled due to the constraints of the dummy
20007 frame. In this case, any exception that is raised in the frame, but has
20008 an out-of-frame exception handler will not be found. GDB builds a
20009 dummy-frame for the inferior function call, and the unwinder cannot
20010 seek for exception handlers outside of this dummy-frame. What happens
20011 in that case is controlled by the
20012 @code{set unwind-on-terminating-exception} command.
20013
20014 @table @code
20015 @item set unwindonsignal
20016 @kindex set unwindonsignal
20017 @cindex unwind stack in called functions
20018 @cindex call dummy stack unwinding
20019 Set unwinding of the stack if a signal is received while in a function
20020 that @value{GDBN} called in the program being debugged. If set to on,
20021 @value{GDBN} unwinds the stack it created for the call and restores
20022 the context to what it was before the call. If set to off (the
20023 default), @value{GDBN} stops in the frame where the signal was
20024 received.
20025
20026 @item show unwindonsignal
20027 @kindex show unwindonsignal
20028 Show the current setting of stack unwinding in the functions called by
20029 @value{GDBN}.
20030
20031 @item set unwind-on-terminating-exception
20032 @kindex set unwind-on-terminating-exception
20033 @cindex unwind stack in called functions with unhandled exceptions
20034 @cindex call dummy stack unwinding on unhandled exception.
20035 Set unwinding of the stack if a C@t{++} exception is raised, but left
20036 unhandled while in a function that @value{GDBN} called in the program being
20037 debugged. If set to on (the default), @value{GDBN} unwinds the stack
20038 it created for the call and restores the context to what it was before
20039 the call. If set to off, @value{GDBN} the exception is delivered to
20040 the default C@t{++} exception handler and the inferior terminated.
20041
20042 @item show unwind-on-terminating-exception
20043 @kindex show unwind-on-terminating-exception
20044 Show the current setting of stack unwinding in the functions called by
20045 @value{GDBN}.
20046
20047 @item set may-call-functions
20048 @kindex set may-call-functions
20049 @cindex disabling calling functions in the program
20050 @cindex calling functions in the program, disabling
20051 Set permission to call functions in the program.
20052 This controls whether @value{GDBN} will attempt to call functions in
20053 the program, such as with expressions in the @code{print} command. It
20054 defaults to @code{on}.
20055
20056 To call a function in the program, @value{GDBN} has to temporarily
20057 modify the state of the inferior. This has potentially undesired side
20058 effects. Also, having @value{GDBN} call nested functions is likely to
20059 be erroneous and may even crash the program being debugged. You can
20060 avoid such hazards by forbidding @value{GDBN} from calling functions
20061 in the program being debugged. If calling functions in the program
20062 is forbidden, GDB will throw an error when a command (such as printing
20063 an expression) starts a function call in the program.
20064
20065 @item show may-call-functions
20066 @kindex show may-call-functions
20067 Show permission to call functions in the program.
20068
20069 @end table
20070
20071 @subsection Calling functions with no debug info
20072
20073 @cindex no debug info functions
20074 Sometimes, a function you wish to call is missing debug information.
20075 In such case, @value{GDBN} does not know the type of the function,
20076 including the types of the function's parameters. To avoid calling
20077 the inferior function incorrectly, which could result in the called
20078 function functioning erroneously and even crash, @value{GDBN} refuses
20079 to call the function unless you tell it the type of the function.
20080
20081 For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
20082 to do that. The simplest is to cast the call to the function's
20083 declared return type. For example:
20084
20085 @smallexample
20086 (@value{GDBP}) p getenv ("PATH")
20087 'getenv' has unknown return type; cast the call to its declared return type
20088 (@value{GDBP}) p (char *) getenv ("PATH")
20089 $1 = 0x7fffffffe7ba "/usr/local/bin:/"...
20090 @end smallexample
20091
20092 Casting the return type of a no-debug function is equivalent to
20093 casting the function to a pointer to a prototyped function that has a
20094 prototype that matches the types of the passed-in arguments, and
20095 calling that. I.e., the call above is equivalent to:
20096
20097 @smallexample
20098 (@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
20099 @end smallexample
20100
20101 @noindent
20102 and given this prototyped C or C++ function with float parameters:
20103
20104 @smallexample
20105 float multiply (float v1, float v2) @{ return v1 * v2; @}
20106 @end smallexample
20107
20108 @noindent
20109 these calls are equivalent:
20110
20111 @smallexample
20112 (@value{GDBP}) p (float) multiply (2.0f, 3.0f)
20113 (@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
20114 @end smallexample
20115
20116 If the function you wish to call is declared as unprototyped (i.e.@:
20117 old K&R style), you must use the cast-to-function-pointer syntax, so
20118 that @value{GDBN} knows that it needs to apply default argument
20119 promotions (promote float arguments to double). @xref{ABI, float
20120 promotion}. For example, given this unprototyped C function with
20121 float parameters, and no debug info:
20122
20123 @smallexample
20124 float
20125 multiply_noproto (v1, v2)
20126 float v1, v2;
20127 @{
20128 return v1 * v2;
20129 @}
20130 @end smallexample
20131
20132 @noindent
20133 you call it like this:
20134
20135 @smallexample
20136 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
20137 @end smallexample
20138
20139 @node Patching
20140 @section Patching Programs
20141
20142 @cindex patching binaries
20143 @cindex writing into executables
20144 @cindex writing into corefiles
20145
20146 By default, @value{GDBN} opens the file containing your program's
20147 executable code (or the corefile) read-only. This prevents accidental
20148 alterations to machine code; but it also prevents you from intentionally
20149 patching your program's binary.
20150
20151 If you'd like to be able to patch the binary, you can specify that
20152 explicitly with the @code{set write} command. For example, you might
20153 want to turn on internal debugging flags, or even to make emergency
20154 repairs.
20155
20156 @table @code
20157 @kindex set write
20158 @item set write on
20159 @itemx set write off
20160 If you specify @samp{set write on}, @value{GDBN} opens executable and
20161 core files for both reading and writing; if you specify @kbd{set write
20162 off} (the default), @value{GDBN} opens them read-only.
20163
20164 If you have already loaded a file, you must load it again (using the
20165 @code{exec-file} or @code{core-file} command) after changing @code{set
20166 write}, for your new setting to take effect.
20167
20168 @item show write
20169 @kindex show write
20170 Display whether executable files and core files are opened for writing
20171 as well as reading.
20172 @end table
20173
20174 @node Compiling and Injecting Code
20175 @section Compiling and injecting code in @value{GDBN}
20176 @cindex injecting code
20177 @cindex writing into executables
20178 @cindex compiling code
20179
20180 @value{GDBN} supports on-demand compilation and code injection into
20181 programs running under @value{GDBN}. GCC 5.0 or higher built with
20182 @file{libcc1.so} must be installed for this functionality to be enabled.
20183 This functionality is implemented with the following commands.
20184
20185 @table @code
20186 @kindex compile code
20187 @item compile code @var{source-code}
20188 @itemx compile code -raw @var{--} @var{source-code}
20189 Compile @var{source-code} with the compiler language found as the current
20190 language in @value{GDBN} (@pxref{Languages}). If compilation and
20191 injection is not supported with the current language specified in
20192 @value{GDBN}, or the compiler does not support this feature, an error
20193 message will be printed. If @var{source-code} compiles and links
20194 successfully, @value{GDBN} will load the object-code emitted,
20195 and execute it within the context of the currently selected inferior.
20196 It is important to note that the compiled code is executed immediately.
20197 After execution, the compiled code is removed from @value{GDBN} and any
20198 new types or variables you have defined will be deleted.
20199
20200 The command allows you to specify @var{source-code} in two ways.
20201 The simplest method is to provide a single line of code to the command.
20202 E.g.:
20203
20204 @smallexample
20205 compile code printf ("hello world\n");
20206 @end smallexample
20207
20208 If you specify options on the command line as well as source code, they
20209 may conflict. The @samp{--} delimiter can be used to separate options
20210 from actual source code. E.g.:
20211
20212 @smallexample
20213 compile code -r -- printf ("hello world\n");
20214 @end smallexample
20215
20216 Alternatively you can enter source code as multiple lines of text. To
20217 enter this mode, invoke the @samp{compile code} command without any text
20218 following the command. This will start the multiple-line editor and
20219 allow you to type as many lines of source code as required. When you
20220 have completed typing, enter @samp{end} on its own line to exit the
20221 editor.
20222
20223 @smallexample
20224 compile code
20225 >printf ("hello\n");
20226 >printf ("world\n");
20227 >end
20228 @end smallexample
20229
20230 Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
20231 provided @var{source-code} in a callable scope. In this case, you must
20232 specify the entry point of the code by defining a function named
20233 @code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
20234 inferior. Using @samp{-raw} option may be needed for example when
20235 @var{source-code} requires @samp{#include} lines which may conflict with
20236 inferior symbols otherwise.
20237
20238 @kindex compile file
20239 @item compile file @var{filename}
20240 @itemx compile file -raw @var{filename}
20241 Like @code{compile code}, but take the source code from @var{filename}.
20242
20243 @smallexample
20244 compile file /home/user/example.c
20245 @end smallexample
20246 @end table
20247
20248 @table @code
20249 @item compile print [[@var{options}] --] @var{expr}
20250 @itemx compile print [[@var{options}] --] /@var{f} @var{expr}
20251 Compile and execute @var{expr} with the compiler language found as the
20252 current language in @value{GDBN} (@pxref{Languages}). By default the
20253 value of @var{expr} is printed in a format appropriate to its data type;
20254 you can choose a different format by specifying @samp{/@var{f}}, where
20255 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
20256 Formats}. The @code{compile print} command accepts the same options
20257 as the @code{print} command; see @ref{print options}.
20258
20259 @item compile print [[@var{options}] --]
20260 @itemx compile print [[@var{options}] --] /@var{f}
20261 @cindex reprint the last value
20262 Alternatively you can enter the expression (source code producing it) as
20263 multiple lines of text. To enter this mode, invoke the @samp{compile print}
20264 command without any text following the command. This will start the
20265 multiple-line editor.
20266 @end table
20267
20268 @noindent
20269 The process of compiling and injecting the code can be inspected using:
20270
20271 @table @code
20272 @anchor{set debug compile}
20273 @item set debug compile
20274 @cindex compile command debugging info
20275 Turns on or off display of @value{GDBN} process of compiling and
20276 injecting the code. The default is off.
20277
20278 @item show debug compile
20279 Displays the current state of displaying @value{GDBN} process of
20280 compiling and injecting the code.
20281
20282 @anchor{set debug compile-cplus-types}
20283 @item set debug compile-cplus-types
20284 @cindex compile C@t{++} type conversion
20285 Turns on or off the display of C@t{++} type conversion debugging information.
20286 The default is off.
20287
20288 @item show debug compile-cplus-types
20289 Displays the current state of displaying debugging information for
20290 C@t{++} type conversion.
20291 @end table
20292
20293 @subsection Compilation options for the @code{compile} command
20294
20295 @value{GDBN} needs to specify the right compilation options for the code
20296 to be injected, in part to make its ABI compatible with the inferior
20297 and in part to make the injected code compatible with @value{GDBN}'s
20298 injecting process.
20299
20300 @noindent
20301 The options used, in increasing precedence:
20302
20303 @table @asis
20304 @item target architecture and OS options (@code{gdbarch})
20305 These options depend on target processor type and target operating
20306 system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
20307 (@code{-m64}) compilation option.
20308
20309 @item compilation options recorded in the target
20310 @value{NGCC} (since version 4.7) stores the options used for compilation
20311 into @code{DW_AT_producer} part of DWARF debugging information according
20312 to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
20313 explicitly specify @code{-g} during inferior compilation otherwise
20314 @value{NGCC} produces no DWARF. This feature is only relevant for
20315 platforms where @code{-g} produces DWARF by default, otherwise one may
20316 try to enforce DWARF by using @code{-gdwarf-4}.
20317
20318 @item compilation options set by @code{set compile-args}
20319 @end table
20320
20321 @noindent
20322 You can override compilation options using the following command:
20323
20324 @table @code
20325 @item set compile-args
20326 @cindex compile command options override
20327 Set compilation options used for compiling and injecting code with the
20328 @code{compile} commands. These options override any conflicting ones
20329 from the target architecture and/or options stored during inferior
20330 compilation.
20331
20332 @item show compile-args
20333 Displays the current state of compilation options override.
20334 This does not show all the options actually used during compilation,
20335 use @ref{set debug compile} for that.
20336 @end table
20337
20338 @subsection Caveats when using the @code{compile} command
20339
20340 There are a few caveats to keep in mind when using the @code{compile}
20341 command. As the caveats are different per language, the table below
20342 highlights specific issues on a per language basis.
20343
20344 @table @asis
20345 @item C code examples and caveats
20346 When the language in @value{GDBN} is set to @samp{C}, the compiler will
20347 attempt to compile the source code with a @samp{C} compiler. The source
20348 code provided to the @code{compile} command will have much the same
20349 access to variables and types as it normally would if it were part of
20350 the program currently being debugged in @value{GDBN}.
20351
20352 Below is a sample program that forms the basis of the examples that
20353 follow. This program has been compiled and loaded into @value{GDBN},
20354 much like any other normal debugging session.
20355
20356 @smallexample
20357 void function1 (void)
20358 @{
20359 int i = 42;
20360 printf ("function 1\n");
20361 @}
20362
20363 void function2 (void)
20364 @{
20365 int j = 12;
20366 function1 ();
20367 @}
20368
20369 int main(void)
20370 @{
20371 int k = 6;
20372 int *p;
20373 function2 ();
20374 return 0;
20375 @}
20376 @end smallexample
20377
20378 For the purposes of the examples in this section, the program above has
20379 been compiled, loaded into @value{GDBN}, stopped at the function
20380 @code{main}, and @value{GDBN} is awaiting input from the user.
20381
20382 To access variables and types for any program in @value{GDBN}, the
20383 program must be compiled and packaged with debug information. The
20384 @code{compile} command is not an exception to this rule. Without debug
20385 information, you can still use the @code{compile} command, but you will
20386 be very limited in what variables and types you can access.
20387
20388 So with that in mind, the example above has been compiled with debug
20389 information enabled. The @code{compile} command will have access to
20390 all variables and types (except those that may have been optimized
20391 out). Currently, as @value{GDBN} has stopped the program in the
20392 @code{main} function, the @code{compile} command would have access to
20393 the variable @code{k}. You could invoke the @code{compile} command
20394 and type some source code to set the value of @code{k}. You can also
20395 read it, or do anything with that variable you would normally do in
20396 @code{C}. Be aware that changes to inferior variables in the
20397 @code{compile} command are persistent. In the following example:
20398
20399 @smallexample
20400 compile code k = 3;
20401 @end smallexample
20402
20403 @noindent
20404 the variable @code{k} is now 3. It will retain that value until
20405 something else in the example program changes it, or another
20406 @code{compile} command changes it.
20407
20408 Normal scope and access rules apply to source code compiled and
20409 injected by the @code{compile} command. In the example, the variables
20410 @code{j} and @code{k} are not accessible yet, because the program is
20411 currently stopped in the @code{main} function, where these variables
20412 are not in scope. Therefore, the following command
20413
20414 @smallexample
20415 compile code j = 3;
20416 @end smallexample
20417
20418 @noindent
20419 will result in a compilation error message.
20420
20421 Once the program is continued, execution will bring these variables in
20422 scope, and they will become accessible; then the code you specify via
20423 the @code{compile} command will be able to access them.
20424
20425 You can create variables and types with the @code{compile} command as
20426 part of your source code. Variables and types that are created as part
20427 of the @code{compile} command are not visible to the rest of the program for
20428 the duration of its run. This example is valid:
20429
20430 @smallexample
20431 compile code int ff = 5; printf ("ff is %d\n", ff);
20432 @end smallexample
20433
20434 However, if you were to type the following into @value{GDBN} after that
20435 command has completed:
20436
20437 @smallexample
20438 compile code printf ("ff is %d\n'', ff);
20439 @end smallexample
20440
20441 @noindent
20442 a compiler error would be raised as the variable @code{ff} no longer
20443 exists. Object code generated and injected by the @code{compile}
20444 command is removed when its execution ends. Caution is advised
20445 when assigning to program variables values of variables created by the
20446 code submitted to the @code{compile} command. This example is valid:
20447
20448 @smallexample
20449 compile code int ff = 5; k = ff;
20450 @end smallexample
20451
20452 The value of the variable @code{ff} is assigned to @code{k}. The variable
20453 @code{k} does not require the existence of @code{ff} to maintain the value
20454 it has been assigned. However, pointers require particular care in
20455 assignment. If the source code compiled with the @code{compile} command
20456 changed the address of a pointer in the example program, perhaps to a
20457 variable created in the @code{compile} command, that pointer would point
20458 to an invalid location when the command exits. The following example
20459 would likely cause issues with your debugged program:
20460
20461 @smallexample
20462 compile code int ff = 5; p = &ff;
20463 @end smallexample
20464
20465 In this example, @code{p} would point to @code{ff} when the
20466 @code{compile} command is executing the source code provided to it.
20467 However, as variables in the (example) program persist with their
20468 assigned values, the variable @code{p} would point to an invalid
20469 location when the command exists. A general rule should be followed
20470 in that you should either assign @code{NULL} to any assigned pointers,
20471 or restore a valid location to the pointer before the command exits.
20472
20473 Similar caution must be exercised with any structs, unions, and typedefs
20474 defined in @code{compile} command. Types defined in the @code{compile}
20475 command will no longer be available in the next @code{compile} command.
20476 Therefore, if you cast a variable to a type defined in the
20477 @code{compile} command, care must be taken to ensure that any future
20478 need to resolve the type can be achieved.
20479
20480 @smallexample
20481 (gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20482 (gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20483 gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20484 Compilation failed.
20485 (gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
20486 42
20487 @end smallexample
20488
20489 Variables that have been optimized away by the compiler are not
20490 accessible to the code submitted to the @code{compile} command.
20491 Access to those variables will generate a compiler error which @value{GDBN}
20492 will print to the console.
20493 @end table
20494
20495 @subsection Compiler search for the @code{compile} command
20496
20497 @value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20498 which may not be obvious for remote targets of different architecture
20499 than where @value{GDBN} is running. Environment variable @code{PATH} on
20500 @value{GDBN} host is searched for @value{NGCC} binary matching the
20501 target architecture and operating system. This search can be overriden
20502 by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is
20503 taken from shell that executed @value{GDBN}, it is not the value set by
20504 @value{GDBN} command @code{set environment}). @xref{Environment}.
20505
20506
20507 Specifically @code{PATH} is searched for binaries matching regular expression
20508 @code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20509 debugged. @var{arch} is processor name --- multiarch is supported, so for
20510 example both @code{i386} and @code{x86_64} targets look for pattern
20511 @code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
20512 for pattern @code{s390x?}. @var{os} is currently supported only for
20513 pattern @code{linux(-gnu)?}.
20514
20515 On Posix hosts the compiler driver @value{GDBN} needs to find also
20516 shared library @file{libcc1.so} from the compiler. It is searched in
20517 default shared library search path (overridable with usual environment
20518 variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
20519 compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
20520 according to the installation of the found compiler --- as possibly
20521 specified by the @code{set compile-gcc} command.
20522
20523 @table @code
20524 @item set compile-gcc
20525 @cindex compile command driver filename override
20526 Set compilation command used for compiling and injecting code with the
20527 @code{compile} commands. If this option is not set (it is set to
20528 an empty string), the search described above will occur --- that is the
20529 default.
20530
20531 @item show compile-gcc
20532 Displays the current compile command @value{NGCC} driver filename.
20533 If set, it is the main command @command{gcc}, found usually for example
20534 under name @file{x86_64-linux-gnu-gcc}.
20535 @end table
20536
20537 @node GDB Files
20538 @chapter @value{GDBN} Files
20539
20540 @value{GDBN} needs to know the file name of the program to be debugged,
20541 both in order to read its symbol table and in order to start your
20542 program. To debug a core dump of a previous run, you must also tell
20543 @value{GDBN} the name of the core dump file.
20544
20545 @menu
20546 * Files:: Commands to specify files
20547 * File Caching:: Information about @value{GDBN}'s file caching
20548 * Separate Debug Files:: Debugging information in separate files
20549 * MiniDebugInfo:: Debugging information in a special section
20550 * Index Files:: Index files speed up GDB
20551 * Symbol Errors:: Errors reading symbol files
20552 * Data Files:: GDB data files
20553 @end menu
20554
20555 @node Files
20556 @section Commands to Specify Files
20557
20558 @cindex symbol table
20559 @cindex core dump file
20560
20561 You may want to specify executable and core dump file names. The usual
20562 way to do this is at start-up time, using the arguments to
20563 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
20564 Out of @value{GDBN}}).
20565
20566 Occasionally it is necessary to change to a different file during a
20567 @value{GDBN} session. Or you may run @value{GDBN} and forget to
20568 specify a file you want to use. Or you are debugging a remote target
20569 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
20570 Program}). In these situations the @value{GDBN} commands to specify
20571 new files are useful.
20572
20573 @table @code
20574 @cindex executable file
20575 @kindex file
20576 @item file @var{filename}
20577 Use @var{filename} as the program to be debugged. It is read for its
20578 symbols and for the contents of pure memory. It is also the program
20579 executed when you use the @code{run} command. If you do not specify a
20580 directory and the file is not found in the @value{GDBN} working directory,
20581 @value{GDBN} uses the environment variable @code{PATH} as a list of
20582 directories to search, just as the shell does when looking for a program
20583 to run. You can change the value of this variable, for both @value{GDBN}
20584 and your program, using the @code{path} command.
20585
20586 @cindex unlinked object files
20587 @cindex patching object files
20588 You can load unlinked object @file{.o} files into @value{GDBN} using
20589 the @code{file} command. You will not be able to ``run'' an object
20590 file, but you can disassemble functions and inspect variables. Also,
20591 if the underlying BFD functionality supports it, you could use
20592 @kbd{gdb -write} to patch object files using this technique. Note
20593 that @value{GDBN} can neither interpret nor modify relocations in this
20594 case, so branches and some initialized variables will appear to go to
20595 the wrong place. But this feature is still handy from time to time.
20596
20597 @item file
20598 @code{file} with no argument makes @value{GDBN} discard any information it
20599 has on both executable file and the symbol table.
20600
20601 @kindex exec-file
20602 @item exec-file @r{[} @var{filename} @r{]}
20603 Specify that the program to be run (but not the symbol table) is found
20604 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
20605 if necessary to locate your program. Omitting @var{filename} means to
20606 discard information on the executable file.
20607
20608 @kindex symbol-file
20609 @item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
20610 Read symbol table information from file @var{filename}. @code{PATH} is
20611 searched when necessary. Use the @code{file} command to get both symbol
20612 table and program to run from the same file.
20613
20614 If an optional @var{offset} is specified, it is added to the start
20615 address of each section in the symbol file. This is useful if the
20616 program is relocated at runtime, such as the Linux kernel with kASLR
20617 enabled.
20618
20619 @code{symbol-file} with no argument clears out @value{GDBN} information on your
20620 program's symbol table.
20621
20622 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
20623 some breakpoints and auto-display expressions. This is because they may
20624 contain pointers to the internal data recording symbols and data types,
20625 which are part of the old symbol table data being discarded inside
20626 @value{GDBN}.
20627
20628 @code{symbol-file} does not repeat if you press @key{RET} again after
20629 executing it once.
20630
20631 When @value{GDBN} is configured for a particular environment, it
20632 understands debugging information in whatever format is the standard
20633 generated for that environment; you may use either a @sc{gnu} compiler, or
20634 other compilers that adhere to the local conventions.
20635 Best results are usually obtained from @sc{gnu} compilers; for example,
20636 using @code{@value{NGCC}} you can generate debugging information for
20637 optimized code.
20638
20639 For most kinds of object files, with the exception of old SVR3 systems
20640 using COFF, the @code{symbol-file} command does not normally read the
20641 symbol table in full right away. Instead, it scans the symbol table
20642 quickly to find which source files and which symbols are present. The
20643 details are read later, one source file at a time, as they are needed.
20644
20645 The purpose of this two-stage reading strategy is to make @value{GDBN}
20646 start up faster. For the most part, it is invisible except for
20647 occasional pauses while the symbol table details for a particular source
20648 file are being read. (The @code{set verbose} command can turn these
20649 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
20650 Warnings and Messages}.)
20651
20652 We have not implemented the two-stage strategy for COFF yet. When the
20653 symbol table is stored in COFF format, @code{symbol-file} reads the
20654 symbol table data in full right away. Note that ``stabs-in-COFF''
20655 still does the two-stage strategy, since the debug info is actually
20656 in stabs format.
20657
20658 @kindex readnow
20659 @cindex reading symbols immediately
20660 @cindex symbols, reading immediately
20661 @item symbol-file @r{[} -readnow @r{]} @var{filename}
20662 @itemx file @r{[} -readnow @r{]} @var{filename}
20663 You can override the @value{GDBN} two-stage strategy for reading symbol
20664 tables by using the @samp{-readnow} option with any of the commands that
20665 load symbol table information, if you want to be sure @value{GDBN} has the
20666 entire symbol table available.
20667
20668 @cindex @code{-readnever}, option for symbol-file command
20669 @cindex never read symbols
20670 @cindex symbols, never read
20671 @item symbol-file @r{[} -readnever @r{]} @var{filename}
20672 @itemx file @r{[} -readnever @r{]} @var{filename}
20673 You can instruct @value{GDBN} to never read the symbolic information
20674 contained in @var{filename} by using the @samp{-readnever} option.
20675 @xref{--readnever}.
20676
20677 @c FIXME: for now no mention of directories, since this seems to be in
20678 @c flux. 13mar1992 status is that in theory GDB would look either in
20679 @c current dir or in same dir as myprog; but issues like competing
20680 @c GDB's, or clutter in system dirs, mean that in practice right now
20681 @c only current dir is used. FFish says maybe a special GDB hierarchy
20682 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
20683 @c files.
20684
20685 @kindex core-file
20686 @item core-file @r{[}@var{filename}@r{]}
20687 @itemx core
20688 Specify the whereabouts of a core dump file to be used as the ``contents
20689 of memory''. Traditionally, core files contain only some parts of the
20690 address space of the process that generated them; @value{GDBN} can access the
20691 executable file itself for other parts.
20692
20693 @code{core-file} with no argument specifies that no core file is
20694 to be used.
20695
20696 Note that the core file is ignored when your program is actually running
20697 under @value{GDBN}. So, if you have been running your program and you
20698 wish to debug a core file instead, you must kill the subprocess in which
20699 the program is running. To do this, use the @code{kill} command
20700 (@pxref{Kill Process, ,Killing the Child Process}).
20701
20702 @kindex add-symbol-file
20703 @cindex dynamic linking
20704 @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{]}
20705 The @code{add-symbol-file} command reads additional symbol table
20706 information from the file @var{filename}. You would use this command
20707 when @var{filename} has been dynamically loaded (by some other means)
20708 into the program that is running. The @var{textaddress} parameter gives
20709 the memory address at which the file's text section has been loaded.
20710 You can additionally specify the base address of other sections using
20711 an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
20712 If a section is omitted, @value{GDBN} will use its default addresses
20713 as found in @var{filename}. Any @var{address} or @var{textaddress}
20714 can be given as an expression.
20715
20716 If an optional @var{offset} is specified, it is added to the start
20717 address of each section, except those for which the address was
20718 specified explicitly.
20719
20720 The symbol table of the file @var{filename} is added to the symbol table
20721 originally read with the @code{symbol-file} command. You can use the
20722 @code{add-symbol-file} command any number of times; the new symbol data
20723 thus read is kept in addition to the old.
20724
20725 Changes can be reverted using the command @code{remove-symbol-file}.
20726
20727 @cindex relocatable object files, reading symbols from
20728 @cindex object files, relocatable, reading symbols from
20729 @cindex reading symbols from relocatable object files
20730 @cindex symbols, reading from relocatable object files
20731 @cindex @file{.o} files, reading symbols from
20732 Although @var{filename} is typically a shared library file, an
20733 executable file, or some other object file which has been fully
20734 relocated for loading into a process, you can also load symbolic
20735 information from relocatable @file{.o} files, as long as:
20736
20737 @itemize @bullet
20738 @item
20739 the file's symbolic information refers only to linker symbols defined in
20740 that file, not to symbols defined by other object files,
20741 @item
20742 every section the file's symbolic information refers to has actually
20743 been loaded into the inferior, as it appears in the file, and
20744 @item
20745 you can determine the address at which every section was loaded, and
20746 provide these to the @code{add-symbol-file} command.
20747 @end itemize
20748
20749 @noindent
20750 Some embedded operating systems, like Sun Chorus and VxWorks, can load
20751 relocatable files into an already running program; such systems
20752 typically make the requirements above easy to meet. However, it's
20753 important to recognize that many native systems use complex link
20754 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
20755 assembly, for example) that make the requirements difficult to meet. In
20756 general, one cannot assume that using @code{add-symbol-file} to read a
20757 relocatable object file's symbolic information will have the same effect
20758 as linking the relocatable object file into the program in the normal
20759 way.
20760
20761 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
20762
20763 @kindex remove-symbol-file
20764 @item remove-symbol-file @var{filename}
20765 @item remove-symbol-file -a @var{address}
20766 Remove a symbol file added via the @code{add-symbol-file} command. The
20767 file to remove can be identified by its @var{filename} or by an @var{address}
20768 that lies within the boundaries of this symbol file in memory. Example:
20769
20770 @smallexample
20771 (gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
20772 add symbol table from file "/home/user/gdb/mylib.so" at
20773 .text_addr = 0x7ffff7ff9480
20774 (y or n) y
20775 Reading symbols from /home/user/gdb/mylib.so...
20776 (gdb) remove-symbol-file -a 0x7ffff7ff9480
20777 Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
20778 (gdb)
20779 @end smallexample
20780
20781
20782 @code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
20783
20784 @kindex add-symbol-file-from-memory
20785 @cindex @code{syscall DSO}
20786 @cindex load symbols from memory
20787 @item add-symbol-file-from-memory @var{address}
20788 Load symbols from the given @var{address} in a dynamically loaded
20789 object file whose image is mapped directly into the inferior's memory.
20790 For example, the Linux kernel maps a @code{syscall DSO} into each
20791 process's address space; this DSO provides kernel-specific code for
20792 some system calls. The argument can be any expression whose
20793 evaluation yields the address of the file's shared object file header.
20794 For this command to work, you must have used @code{symbol-file} or
20795 @code{exec-file} commands in advance.
20796
20797 @kindex section
20798 @item section @var{section} @var{addr}
20799 The @code{section} command changes the base address of the named
20800 @var{section} of the exec file to @var{addr}. This can be used if the
20801 exec file does not contain section addresses, (such as in the
20802 @code{a.out} format), or when the addresses specified in the file
20803 itself are wrong. Each section must be changed separately. The
20804 @code{info files} command, described below, lists all the sections and
20805 their addresses.
20806
20807 @kindex info files
20808 @kindex info target
20809 @item info files
20810 @itemx info target
20811 @code{info files} and @code{info target} are synonymous; both print the
20812 current target (@pxref{Targets, ,Specifying a Debugging Target}),
20813 including the names of the executable and core dump files currently in
20814 use by @value{GDBN}, and the files from which symbols were loaded. The
20815 command @code{help target} lists all possible targets rather than
20816 current ones.
20817
20818 @kindex maint info sections
20819 @item maint info sections @r{[}-all-objects@r{]} @r{[}@var{filter-list}@r{]}
20820 Another command that can give you extra information about program sections
20821 is @code{maint info sections}. In addition to the section information
20822 displayed by @code{info files}, this command displays the flags and file
20823 offset of each section in the executable and core dump files.
20824
20825 When @samp{-all-objects} is passed then sections from all loaded object
20826 files, including shared libraries, are printed.
20827
20828 The optional @var{filter-list} is a space separated list of filter
20829 keywords. Sections that match any one of the filter criteria will be
20830 printed. There are two types of filter:
20831
20832 @table @code
20833 @item @var{section-name}
20834 Display information about any section named @var{section-name}.
20835 @item @var{section-flag}
20836 Display information for any section with @var{section-flag}. The
20837 section flags that @value{GDBN} currently knows about are:
20838 @table @code
20839 @item ALLOC
20840 Section will have space allocated in the process when loaded.
20841 Set for all sections except those containing debug information.
20842 @item LOAD
20843 Section will be loaded from the file into the child process memory.
20844 Set for pre-initialized code and data, clear for @code{.bss} sections.
20845 @item RELOC
20846 Section needs to be relocated before loading.
20847 @item READONLY
20848 Section cannot be modified by the child process.
20849 @item CODE
20850 Section contains executable code only.
20851 @item DATA
20852 Section contains data only (no executable code).
20853 @item ROM
20854 Section will reside in ROM.
20855 @item CONSTRUCTOR
20856 Section contains data for constructor/destructor lists.
20857 @item HAS_CONTENTS
20858 Section is not empty.
20859 @item NEVER_LOAD
20860 An instruction to the linker to not output the section.
20861 @item COFF_SHARED_LIBRARY
20862 A notification to the linker that the section contains
20863 COFF shared library information.
20864 @item IS_COMMON
20865 Section contains common symbols.
20866 @end table
20867 @end table
20868
20869 @kindex maint info target-sections
20870 @item maint info target-sections
20871 This command prints @value{GDBN}'s internal section table. For each
20872 target @value{GDBN} maintains a table containing the allocatable
20873 sections from all currently mapped objects, along with information
20874 about where the section is mapped.
20875
20876 @kindex set trust-readonly-sections
20877 @cindex read-only sections
20878 @item set trust-readonly-sections on
20879 Tell @value{GDBN} that readonly sections in your object file
20880 really are read-only (i.e.@: that their contents will not change).
20881 In that case, @value{GDBN} can fetch values from these sections
20882 out of the object file, rather than from the target program.
20883 For some targets (notably embedded ones), this can be a significant
20884 enhancement to debugging performance.
20885
20886 The default is off.
20887
20888 @item set trust-readonly-sections off
20889 Tell @value{GDBN} not to trust readonly sections. This means that
20890 the contents of the section might change while the program is running,
20891 and must therefore be fetched from the target when needed.
20892
20893 @item show trust-readonly-sections
20894 Show the current setting of trusting readonly sections.
20895 @end table
20896
20897 All file-specifying commands allow both absolute and relative file names
20898 as arguments. @value{GDBN} always converts the file name to an absolute file
20899 name and remembers it that way.
20900
20901 @cindex shared libraries
20902 @anchor{Shared Libraries}
20903 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
20904 Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
20905 DSBT (TIC6X) shared libraries.
20906
20907 On MS-Windows @value{GDBN} must be linked with the Expat library to support
20908 shared libraries. @xref{Expat}.
20909
20910 @value{GDBN} automatically loads symbol definitions from shared libraries
20911 when you use the @code{run} command, or when you examine a core file.
20912 (Before you issue the @code{run} command, @value{GDBN} does not understand
20913 references to a function in a shared library, however---unless you are
20914 debugging a core file).
20915
20916 @c FIXME: some @value{GDBN} release may permit some refs to undef
20917 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
20918 @c FIXME...lib; check this from time to time when updating manual
20919
20920 There are times, however, when you may wish to not automatically load
20921 symbol definitions from shared libraries, such as when they are
20922 particularly large or there are many of them.
20923
20924 To control the automatic loading of shared library symbols, use the
20925 commands:
20926
20927 @table @code
20928 @kindex set auto-solib-add
20929 @item set auto-solib-add @var{mode}
20930 If @var{mode} is @code{on}, symbols from all shared object libraries
20931 will be loaded automatically when the inferior begins execution, you
20932 attach to an independently started inferior, or when the dynamic linker
20933 informs @value{GDBN} that a new library has been loaded. If @var{mode}
20934 is @code{off}, symbols must be loaded manually, using the
20935 @code{sharedlibrary} command. The default value is @code{on}.
20936
20937 @cindex memory used for symbol tables
20938 If your program uses lots of shared libraries with debug info that
20939 takes large amounts of memory, you can decrease the @value{GDBN}
20940 memory footprint by preventing it from automatically loading the
20941 symbols from shared libraries. To that end, type @kbd{set
20942 auto-solib-add off} before running the inferior, then load each
20943 library whose debug symbols you do need with @kbd{sharedlibrary
20944 @var{regexp}}, where @var{regexp} is a regular expression that matches
20945 the libraries whose symbols you want to be loaded.
20946
20947 @kindex show auto-solib-add
20948 @item show auto-solib-add
20949 Display the current autoloading mode.
20950 @end table
20951
20952 @cindex load shared library
20953 To explicitly load shared library symbols, use the @code{sharedlibrary}
20954 command:
20955
20956 @table @code
20957 @kindex info sharedlibrary
20958 @kindex info share
20959 @item info share @var{regex}
20960 @itemx info sharedlibrary @var{regex}
20961 Print the names of the shared libraries which are currently loaded
20962 that match @var{regex}. If @var{regex} is omitted then print
20963 all shared libraries that are loaded.
20964
20965 @kindex info dll
20966 @item info dll @var{regex}
20967 This is an alias of @code{info sharedlibrary}.
20968
20969 @kindex sharedlibrary
20970 @kindex share
20971 @item sharedlibrary @var{regex}
20972 @itemx share @var{regex}
20973 Load shared object library symbols for files matching a
20974 Unix regular expression.
20975 As with files loaded automatically, it only loads shared libraries
20976 required by your program for a core file or after typing @code{run}. If
20977 @var{regex} is omitted all shared libraries required by your program are
20978 loaded.
20979
20980 @item nosharedlibrary
20981 @kindex nosharedlibrary
20982 @cindex unload symbols from shared libraries
20983 Unload all shared object library symbols. This discards all symbols
20984 that have been loaded from all shared libraries. Symbols from shared
20985 libraries that were loaded by explicit user requests are not
20986 discarded.
20987 @end table
20988
20989 Sometimes you may wish that @value{GDBN} stops and gives you control
20990 when any of shared library events happen. The best way to do this is
20991 to use @code{catch load} and @code{catch unload} (@pxref{Set
20992 Catchpoints}).
20993
20994 @value{GDBN} also supports the @code{set stop-on-solib-events}
20995 command for this. This command exists for historical reasons. It is
20996 less useful than setting a catchpoint, because it does not allow for
20997 conditions or commands as a catchpoint does.
20998
20999 @table @code
21000 @item set stop-on-solib-events
21001 @kindex set stop-on-solib-events
21002 This command controls whether @value{GDBN} should give you control
21003 when the dynamic linker notifies it about some shared library event.
21004 The most common event of interest is loading or unloading of a new
21005 shared library.
21006
21007 @item show stop-on-solib-events
21008 @kindex show stop-on-solib-events
21009 Show whether @value{GDBN} stops and gives you control when shared
21010 library events happen.
21011 @end table
21012
21013 Shared libraries are also supported in many cross or remote debugging
21014 configurations. @value{GDBN} needs to have access to the target's libraries;
21015 this can be accomplished either by providing copies of the libraries
21016 on the host system, or by asking @value{GDBN} to automatically retrieve the
21017 libraries from the target. If copies of the target libraries are
21018 provided, they need to be the same as the target libraries, although the
21019 copies on the target can be stripped as long as the copies on the host are
21020 not.
21021
21022 @cindex where to look for shared libraries
21023 For remote debugging, you need to tell @value{GDBN} where the target
21024 libraries are, so that it can load the correct copies---otherwise, it
21025 may try to load the host's libraries. @value{GDBN} has two variables
21026 to specify the search directories for target libraries.
21027
21028 @table @code
21029 @cindex prefix for executable and shared library file names
21030 @cindex system root, alternate
21031 @kindex set solib-absolute-prefix
21032 @kindex set sysroot
21033 @item set sysroot @var{path}
21034 Use @var{path} as the system root for the program being debugged. Any
21035 absolute shared library paths will be prefixed with @var{path}; many
21036 runtime loaders store the absolute paths to the shared library in the
21037 target program's memory. When starting processes remotely, and when
21038 attaching to already-running processes (local or remote), their
21039 executable filenames will be prefixed with @var{path} if reported to
21040 @value{GDBN} as absolute by the operating system. If you use
21041 @code{set sysroot} to find executables and shared libraries, they need
21042 to be laid out in the same way that they are on the target, with
21043 e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
21044 @var{path}.
21045
21046 If @var{path} starts with the sequence @file{target:} and the target
21047 system is remote then @value{GDBN} will retrieve the target binaries
21048 from the remote system. This is only supported when using a remote
21049 target that supports the @code{remote get} command (@pxref{File
21050 Transfer,,Sending files to a remote system}). The part of @var{path}
21051 following the initial @file{target:} (if present) is used as system
21052 root prefix on the remote file system. If @var{path} starts with the
21053 sequence @file{remote:} this is converted to the sequence
21054 @file{target:} by @code{set sysroot}@footnote{Historically the
21055 functionality to retrieve binaries from the remote system was
21056 provided by prefixing @var{path} with @file{remote:}}. If you want
21057 to specify a local system root using a directory that happens to be
21058 named @file{target:} or @file{remote:}, you need to use some
21059 equivalent variant of the name like @file{./target:}.
21060
21061 For targets with an MS-DOS based filesystem, such as MS-Windows,
21062 @value{GDBN} tries prefixing a few variants of the target
21063 absolute file name with @var{path}. But first, on Unix hosts,
21064 @value{GDBN} converts all backslash directory separators into forward
21065 slashes, because the backslash is not a directory separator on Unix:
21066
21067 @smallexample
21068 c:\foo\bar.dll @result{} c:/foo/bar.dll
21069 @end smallexample
21070
21071 Then, @value{GDBN} attempts prefixing the target file name with
21072 @var{path}, and looks for the resulting file name in the host file
21073 system:
21074
21075 @smallexample
21076 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
21077 @end smallexample
21078
21079 If that does not find the binary, @value{GDBN} tries removing
21080 the @samp{:} character from the drive spec, both for convenience, and,
21081 for the case of the host file system not supporting file names with
21082 colons:
21083
21084 @smallexample
21085 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
21086 @end smallexample
21087
21088 This makes it possible to have a system root that mirrors a target
21089 with more than one drive. E.g., you may want to setup your local
21090 copies of the target system shared libraries like so (note @samp{c} vs
21091 @samp{z}):
21092
21093 @smallexample
21094 @file{/path/to/sysroot/c/sys/bin/foo.dll}
21095 @file{/path/to/sysroot/c/sys/bin/bar.dll}
21096 @file{/path/to/sysroot/z/sys/bin/bar.dll}
21097 @end smallexample
21098
21099 @noindent
21100 and point the system root at @file{/path/to/sysroot}, so that
21101 @value{GDBN} can find the correct copies of both
21102 @file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
21103
21104 If that still does not find the binary, @value{GDBN} tries
21105 removing the whole drive spec from the target file name:
21106
21107 @smallexample
21108 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
21109 @end smallexample
21110
21111 This last lookup makes it possible to not care about the drive name,
21112 if you don't want or need to.
21113
21114 The @code{set solib-absolute-prefix} command is an alias for @code{set
21115 sysroot}.
21116
21117 @cindex default system root
21118 @cindex @samp{--with-sysroot}
21119 You can set the default system root by using the configure-time
21120 @samp{--with-sysroot} option. If the system root is inside
21121 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21122 @samp{--exec-prefix}), then the default system root will be updated
21123 automatically if the installed @value{GDBN} is moved to a new
21124 location.
21125
21126 @kindex show sysroot
21127 @item show sysroot
21128 Display the current executable and shared library prefix.
21129
21130 @kindex set solib-search-path
21131 @item set solib-search-path @var{path}
21132 If this variable is set, @var{path} is a colon-separated list of
21133 directories to search for shared libraries. @samp{solib-search-path}
21134 is used after @samp{sysroot} fails to locate the library, or if the
21135 path to the library is relative instead of absolute. If you want to
21136 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
21137 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
21138 finding your host's libraries. @samp{sysroot} is preferred; setting
21139 it to a nonexistent directory may interfere with automatic loading
21140 of shared library symbols.
21141
21142 @kindex show solib-search-path
21143 @item show solib-search-path
21144 Display the current shared library search path.
21145
21146 @cindex DOS file-name semantics of file names.
21147 @kindex set target-file-system-kind (unix|dos-based|auto)
21148 @kindex show target-file-system-kind
21149 @item set target-file-system-kind @var{kind}
21150 Set assumed file system kind for target reported file names.
21151
21152 Shared library file names as reported by the target system may not
21153 make sense as is on the system @value{GDBN} is running on. For
21154 example, when remote debugging a target that has MS-DOS based file
21155 system semantics, from a Unix host, the target may be reporting to
21156 @value{GDBN} a list of loaded shared libraries with file names such as
21157 @file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
21158 drive letters, so the @samp{c:\} prefix is not normally understood as
21159 indicating an absolute file name, and neither is the backslash
21160 normally considered a directory separator character. In that case,
21161 the native file system would interpret this whole absolute file name
21162 as a relative file name with no directory components. This would make
21163 it impossible to point @value{GDBN} at a copy of the remote target's
21164 shared libraries on the host using @code{set sysroot}, and impractical
21165 with @code{set solib-search-path}. Setting
21166 @code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
21167 to interpret such file names similarly to how the target would, and to
21168 map them to file names valid on @value{GDBN}'s native file system
21169 semantics. The value of @var{kind} can be @code{"auto"}, in addition
21170 to one of the supported file system kinds. In that case, @value{GDBN}
21171 tries to determine the appropriate file system variant based on the
21172 current target's operating system (@pxref{ABI, ,Configuring the
21173 Current ABI}). The supported file system settings are:
21174
21175 @table @code
21176 @item unix
21177 Instruct @value{GDBN} to assume the target file system is of Unix
21178 kind. Only file names starting the forward slash (@samp{/}) character
21179 are considered absolute, and the directory separator character is also
21180 the forward slash.
21181
21182 @item dos-based
21183 Instruct @value{GDBN} to assume the target file system is DOS based.
21184 File names starting with either a forward slash, or a drive letter
21185 followed by a colon (e.g., @samp{c:}), are considered absolute, and
21186 both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
21187 considered directory separators.
21188
21189 @item auto
21190 Instruct @value{GDBN} to use the file system kind associated with the
21191 target operating system (@pxref{ABI, ,Configuring the Current ABI}).
21192 This is the default.
21193 @end table
21194 @end table
21195
21196 @cindex file name canonicalization
21197 @cindex base name differences
21198 When processing file names provided by the user, @value{GDBN}
21199 frequently needs to compare them to the file names recorded in the
21200 program's debug info. Normally, @value{GDBN} compares just the
21201 @dfn{base names} of the files as strings, which is reasonably fast
21202 even for very large programs. (The base name of a file is the last
21203 portion of its name, after stripping all the leading directories.)
21204 This shortcut in comparison is based upon the assumption that files
21205 cannot have more than one base name. This is usually true, but
21206 references to files that use symlinks or similar filesystem
21207 facilities violate that assumption. If your program records files
21208 using such facilities, or if you provide file names to @value{GDBN}
21209 using symlinks etc., you can set @code{basenames-may-differ} to
21210 @code{true} to instruct @value{GDBN} to completely canonicalize each
21211 pair of file names it needs to compare. This will make file-name
21212 comparisons accurate, but at a price of a significant slowdown.
21213
21214 @table @code
21215 @item set basenames-may-differ
21216 @kindex set basenames-may-differ
21217 Set whether a source file may have multiple base names.
21218
21219 @item show basenames-may-differ
21220 @kindex show basenames-may-differ
21221 Show whether a source file may have multiple base names.
21222 @end table
21223
21224 @node File Caching
21225 @section File Caching
21226 @cindex caching of opened files
21227 @cindex caching of bfd objects
21228
21229 To speed up file loading, and reduce memory usage, @value{GDBN} will
21230 reuse the @code{bfd} objects used to track open files. @xref{Top, ,
21231 BFD, bfd, The Binary File Descriptor Library}. The following commands
21232 allow visibility and control of the caching behavior.
21233
21234 @table @code
21235 @kindex maint info bfds
21236 @item maint info bfds
21237 This prints information about each @code{bfd} object that is known to
21238 @value{GDBN}.
21239
21240 @kindex maint set bfd-sharing
21241 @kindex maint show bfd-sharing
21242 @kindex bfd caching
21243 @item maint set bfd-sharing
21244 @item maint show bfd-sharing
21245 Control whether @code{bfd} objects can be shared. When sharing is
21246 enabled @value{GDBN} reuses already open @code{bfd} objects rather
21247 than reopening the same file. Turning sharing off does not cause
21248 already shared @code{bfd} objects to be unshared, but all future files
21249 that are opened will create a new @code{bfd} object. Similarly,
21250 re-enabling sharing does not cause multiple existing @code{bfd}
21251 objects to be collapsed into a single shared @code{bfd} object.
21252
21253 @kindex set debug bfd-cache @var{level}
21254 @kindex bfd caching
21255 @item set debug bfd-cache @var{level}
21256 Turns on debugging of the bfd cache, setting the level to @var{level}.
21257
21258 @kindex show debug bfd-cache
21259 @kindex bfd caching
21260 @item show debug bfd-cache
21261 Show the current debugging level of the bfd cache.
21262 @end table
21263
21264 @node Separate Debug Files
21265 @section Debugging Information in Separate Files
21266 @cindex separate debugging information files
21267 @cindex debugging information in separate files
21268 @cindex @file{.debug} subdirectories
21269 @cindex debugging information directory, global
21270 @cindex global debugging information directories
21271 @cindex build ID, and separate debugging files
21272 @cindex @file{.build-id} directory
21273
21274 @value{GDBN} allows you to put a program's debugging information in a
21275 file separate from the executable itself, in a way that allows
21276 @value{GDBN} to find and load the debugging information automatically.
21277 Since debugging information can be very large---sometimes larger
21278 than the executable code itself---some systems distribute debugging
21279 information for their executables in separate files, which users can
21280 install only when they need to debug a problem.
21281
21282 @value{GDBN} supports two ways of specifying the separate debug info
21283 file:
21284
21285 @itemize @bullet
21286 @item
21287 The executable contains a @dfn{debug link} that specifies the name of
21288 the separate debug info file. The separate debug file's name is
21289 usually @file{@var{executable}.debug}, where @var{executable} is the
21290 name of the corresponding executable file without leading directories
21291 (e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
21292 debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
21293 checksum for the debug file, which @value{GDBN} uses to validate that
21294 the executable and the debug file came from the same build.
21295
21296 @item
21297 @anchor{build ID}
21298 The executable contains a @dfn{build ID}, a unique bit string that is
21299 also present in the corresponding debug info file. (This is supported
21300 only on some operating systems, when using the ELF or PE file formats
21301 for binary files and the @sc{gnu} Binutils.) For more details about
21302 this feature, see the description of the @option{--build-id}
21303 command-line option in @ref{Options, , Command Line Options, ld,
21304 The GNU Linker}. The debug info file's name is not specified
21305 explicitly by the build ID, but can be computed from the build ID, see
21306 below.
21307 @end itemize
21308
21309 Depending on the way the debug info file is specified, @value{GDBN}
21310 uses two different methods of looking for the debug file:
21311
21312 @itemize @bullet
21313 @item
21314 For the ``debug link'' method, @value{GDBN} looks up the named file in
21315 the directory of the executable file, then in a subdirectory of that
21316 directory named @file{.debug}, and finally under each one of the
21317 global debug directories, in a subdirectory whose name is identical to
21318 the leading directories of the executable's absolute file name. (On
21319 MS-Windows/MS-DOS, the drive letter of the executable's leading
21320 directories is converted to a one-letter subdirectory, i.e.@:
21321 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
21322 filesystems disallow colons in file names.)
21323
21324 @item
21325 For the ``build ID'' method, @value{GDBN} looks in the
21326 @file{.build-id} subdirectory of each one of the global debug directories for
21327 a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
21328 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
21329 are the rest of the bit string. (Real build ID strings are 32 or more
21330 hex characters, not 10.)
21331 @end itemize
21332
21333 So, for example, suppose you ask @value{GDBN} to debug
21334 @file{/usr/bin/ls}, which has a debug link that specifies the
21335 file @file{ls.debug}, and a build ID whose value in hex is
21336 @code{abcdef1234}. If the list of the global debug directories includes
21337 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
21338 debug information files, in the indicated order:
21339
21340 @itemize @minus
21341 @item
21342 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
21343 @item
21344 @file{/usr/bin/ls.debug}
21345 @item
21346 @file{/usr/bin/.debug/ls.debug}
21347 @item
21348 @file{/usr/lib/debug/usr/bin/ls.debug}.
21349 @end itemize
21350
21351 @anchor{debug-file-directory}
21352 Global debugging info directories default to what is set by @value{GDBN}
21353 configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
21354 you can also set the global debugging info directories, and view the list
21355 @value{GDBN} is currently using.
21356
21357 @table @code
21358
21359 @kindex set debug-file-directory
21360 @item set debug-file-directory @var{directories}
21361 Set the directories which @value{GDBN} searches for separate debugging
21362 information files to @var{directory}. Multiple path components can be set
21363 concatenating them by a path separator.
21364
21365 @kindex show debug-file-directory
21366 @item show debug-file-directory
21367 Show the directories @value{GDBN} searches for separate debugging
21368 information files.
21369
21370 @end table
21371
21372 @cindex @code{.gnu_debuglink} sections
21373 @cindex debug link sections
21374 A debug link is a special section of the executable file named
21375 @code{.gnu_debuglink}. The section must contain:
21376
21377 @itemize
21378 @item
21379 A filename, with any leading directory components removed, followed by
21380 a zero byte,
21381 @item
21382 zero to three bytes of padding, as needed to reach the next four-byte
21383 boundary within the section, and
21384 @item
21385 a four-byte CRC checksum, stored in the same endianness used for the
21386 executable file itself. The checksum is computed on the debugging
21387 information file's full contents by the function given below, passing
21388 zero as the @var{crc} argument.
21389 @end itemize
21390
21391 Any executable file format can carry a debug link, as long as it can
21392 contain a section named @code{.gnu_debuglink} with the contents
21393 described above.
21394
21395 @cindex @code{.note.gnu.build-id} sections
21396 @cindex build ID sections
21397 The build ID is a special section in the executable file (and in other
21398 ELF binary files that @value{GDBN} may consider). This section is
21399 often named @code{.note.gnu.build-id}, but that name is not mandatory.
21400 It contains unique identification for the built files---the ID remains
21401 the same across multiple builds of the same build tree. The default
21402 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
21403 content for the build ID string. The same section with an identical
21404 value is present in the original built binary with symbols, in its
21405 stripped variant, and in the separate debugging information file.
21406
21407 The debugging information file itself should be an ordinary
21408 executable, containing a full set of linker symbols, sections, and
21409 debugging information. The sections of the debugging information file
21410 should have the same names, addresses, and sizes as the original file,
21411 but they need not contain any data---much like a @code{.bss} section
21412 in an ordinary executable.
21413
21414 The @sc{gnu} binary utilities (Binutils) package includes the
21415 @samp{objcopy} utility that can produce
21416 the separated executable / debugging information file pairs using the
21417 following commands:
21418
21419 @smallexample
21420 @kbd{objcopy --only-keep-debug foo foo.debug}
21421 @kbd{strip -g foo}
21422 @end smallexample
21423
21424 @noindent
21425 These commands remove the debugging
21426 information from the executable file @file{foo} and place it in the file
21427 @file{foo.debug}. You can use the first, second or both methods to link the
21428 two files:
21429
21430 @itemize @bullet
21431 @item
21432 The debug link method needs the following additional command to also leave
21433 behind a debug link in @file{foo}:
21434
21435 @smallexample
21436 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
21437 @end smallexample
21438
21439 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
21440 a version of the @code{strip} command such that the command @kbd{strip foo -f
21441 foo.debug} has the same functionality as the two @code{objcopy} commands and
21442 the @code{ln -s} command above, together.
21443
21444 @item
21445 Build ID gets embedded into the main executable using @code{ld --build-id} or
21446 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
21447 compatibility fixes for debug files separation are present in @sc{gnu} binary
21448 utilities (Binutils) package since version 2.18.
21449 @end itemize
21450
21451 @noindent
21452
21453 @cindex CRC algorithm definition
21454 The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21455 IEEE 802.3 using the polynomial:
21456
21457 @c TexInfo requires naked braces for multi-digit exponents for Tex
21458 @c output, but this causes HTML output to barf. HTML has to be set using
21459 @c raw commands. So we end up having to specify this equation in 2
21460 @c different ways!
21461 @ifhtml
21462 @display
21463 @html
21464 <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>
21465 + <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
21466 @end html
21467 @end display
21468 @end ifhtml
21469 @ifnothtml
21470 @display
21471 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21472 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21473 @end display
21474 @end ifnothtml
21475
21476 The function is computed byte at a time, taking the least
21477 significant bit of each byte first. The initial pattern
21478 @code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21479 the final result is inverted to ensure trailing zeros also affect the
21480 CRC.
21481
21482 @emph{Note:} This is the same CRC polynomial as used in handling the
21483 @dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21484 However in the case of the Remote Serial Protocol, the CRC is computed
21485 @emph{most} significant bit first, and the result is not inverted, so
21486 trailing zeros have no effect on the CRC value.
21487
21488 To complete the description, we show below the code of the function
21489 which produces the CRC used in @code{.gnu_debuglink}. Inverting the
21490 initially supplied @code{crc} argument means that an initial call to
21491 this function passing in zero will start computing the CRC using
21492 @code{0xffffffff}.
21493
21494 @kindex gnu_debuglink_crc32
21495 @smallexample
21496 unsigned long
21497 gnu_debuglink_crc32 (unsigned long crc,
21498 unsigned char *buf, size_t len)
21499 @{
21500 static const unsigned long crc32_table[256] =
21501 @{
21502 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21503 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21504 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
21505 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
21506 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
21507 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
21508 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
21509 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
21510 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
21511 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
21512 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
21513 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
21514 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
21515 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
21516 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
21517 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
21518 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
21519 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
21520 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
21521 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
21522 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
21523 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
21524 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
21525 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
21526 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
21527 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
21528 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
21529 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
21530 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
21531 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
21532 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
21533 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
21534 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
21535 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
21536 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
21537 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
21538 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
21539 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
21540 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
21541 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
21542 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
21543 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
21544 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
21545 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
21546 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
21547 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
21548 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
21549 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
21550 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
21551 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
21552 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
21553 0x2d02ef8d
21554 @};
21555 unsigned char *end;
21556
21557 crc = ~crc & 0xffffffff;
21558 for (end = buf + len; buf < end; ++buf)
21559 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
21560 return ~crc & 0xffffffff;
21561 @}
21562 @end smallexample
21563
21564 @noindent
21565 This computation does not apply to the ``build ID'' method.
21566
21567 @node MiniDebugInfo
21568 @section Debugging information in a special section
21569 @cindex separate debug sections
21570 @cindex @samp{.gnu_debugdata} section
21571
21572 Some systems ship pre-built executables and libraries that have a
21573 special @samp{.gnu_debugdata} section. This feature is called
21574 @dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
21575 is used to supply extra symbols for backtraces.
21576
21577 The intent of this section is to provide extra minimal debugging
21578 information for use in simple backtraces. It is not intended to be a
21579 replacement for full separate debugging information (@pxref{Separate
21580 Debug Files}). The example below shows the intended use; however,
21581 @value{GDBN} does not currently put restrictions on what sort of
21582 debugging information might be included in the section.
21583
21584 @value{GDBN} has support for this extension. If the section exists,
21585 then it is used provided that no other source of debugging information
21586 can be found, and that @value{GDBN} was configured with LZMA support.
21587
21588 This section can be easily created using @command{objcopy} and other
21589 standard utilities:
21590
21591 @smallexample
21592 # Extract the dynamic symbols from the main binary, there is no need
21593 # to also have these in the normal symbol table.
21594 nm -D @var{binary} --format=posix --defined-only \
21595 | awk '@{ print $1 @}' | sort > dynsyms
21596
21597 # Extract all the text (i.e. function) symbols from the debuginfo.
21598 # (Note that we actually also accept "D" symbols, for the benefit
21599 # of platforms like PowerPC64 that use function descriptors.)
21600 nm @var{binary} --format=posix --defined-only \
21601 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
21602 | sort > funcsyms
21603
21604 # Keep all the function symbols not already in the dynamic symbol
21605 # table.
21606 comm -13 dynsyms funcsyms > keep_symbols
21607
21608 # Separate full debug info into debug binary.
21609 objcopy --only-keep-debug @var{binary} debug
21610
21611 # Copy the full debuginfo, keeping only a minimal set of symbols and
21612 # removing some unnecessary sections.
21613 objcopy -S --remove-section .gdb_index --remove-section .comment \
21614 --keep-symbols=keep_symbols debug mini_debuginfo
21615
21616 # Drop the full debug info from the original binary.
21617 strip --strip-all -R .comment @var{binary}
21618
21619 # Inject the compressed data into the .gnu_debugdata section of the
21620 # original binary.
21621 xz mini_debuginfo
21622 objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
21623 @end smallexample
21624
21625 @node Index Files
21626 @section Index Files Speed Up @value{GDBN}
21627 @cindex index files
21628 @cindex @samp{.gdb_index} section
21629
21630 When @value{GDBN} finds a symbol file, it scans the symbols in the
21631 file in order to construct an internal symbol table. This lets most
21632 @value{GDBN} operations work quickly---at the cost of a delay early
21633 on. For large programs, this delay can be quite lengthy, so
21634 @value{GDBN} provides a way to build an index, which speeds up
21635 startup.
21636
21637 For convenience, @value{GDBN} comes with a program,
21638 @command{gdb-add-index}, which can be used to add the index to a
21639 symbol file. It takes the symbol file as its only argument:
21640
21641 @smallexample
21642 $ gdb-add-index symfile
21643 @end smallexample
21644
21645 @xref{gdb-add-index}.
21646
21647 It is also possible to do the work manually. Here is what
21648 @command{gdb-add-index} does behind the curtains.
21649
21650 The index is stored as a section in the symbol file. @value{GDBN} can
21651 write the index to a file, then you can put it into the symbol file
21652 using @command{objcopy}.
21653
21654 To create an index file, use the @code{save gdb-index} command:
21655
21656 @table @code
21657 @item save gdb-index [-dwarf-5] @var{directory}
21658 @kindex save gdb-index
21659 Create index files for all symbol files currently known by
21660 @value{GDBN}. For each known @var{symbol-file}, this command by
21661 default creates it produces a single file
21662 @file{@var{symbol-file}.gdb-index}. If you invoke this command with
21663 the @option{-dwarf-5} option, it produces 2 files:
21664 @file{@var{symbol-file}.debug_names} and
21665 @file{@var{symbol-file}.debug_str}. The files are created in the
21666 given @var{directory}.
21667 @end table
21668
21669 Once you have created an index file you can merge it into your symbol
21670 file, here named @file{symfile}, using @command{objcopy}:
21671
21672 @smallexample
21673 $ objcopy --add-section .gdb_index=symfile.gdb-index \
21674 --set-section-flags .gdb_index=readonly symfile symfile
21675 @end smallexample
21676
21677 Or for @code{-dwarf-5}:
21678
21679 @smallexample
21680 $ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
21681 $ cat symfile.debug_str >>symfile.debug_str.new
21682 $ objcopy --add-section .debug_names=symfile.gdb-index \
21683 --set-section-flags .debug_names=readonly \
21684 --update-section .debug_str=symfile.debug_str.new symfile symfile
21685 @end smallexample
21686
21687 @value{GDBN} will normally ignore older versions of @file{.gdb_index}
21688 sections that have been deprecated. Usually they are deprecated because
21689 they are missing a new feature or have performance issues.
21690 To tell @value{GDBN} to use a deprecated index section anyway
21691 specify @code{set use-deprecated-index-sections on}.
21692 The default is @code{off}.
21693 This can speed up startup, but may result in some functionality being lost.
21694 @xref{Index Section Format}.
21695
21696 @emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
21697 must be done before gdb reads the file. The following will not work:
21698
21699 @smallexample
21700 $ gdb -ex "set use-deprecated-index-sections on" <program>
21701 @end smallexample
21702
21703 Instead you must do, for example,
21704
21705 @smallexample
21706 $ gdb -iex "set use-deprecated-index-sections on" <program>
21707 @end smallexample
21708
21709 Indices only work when using DWARF debugging information, not stabs.
21710
21711 @subsection Automatic symbol index cache
21712
21713 @cindex automatic symbol index cache
21714 It is possible for @value{GDBN} to automatically save a copy of this index in a
21715 cache on disk and retrieve it from there when loading the same binary in the
21716 future. This feature can be turned on with @kbd{set index-cache on}. The
21717 following commands can be used to tweak the behavior of the index cache.
21718
21719 @table @code
21720
21721 @kindex set index-cache
21722 @item set index-cache on
21723 @itemx set index-cache off
21724 Enable or disable the use of the symbol index cache.
21725
21726 @item set index-cache directory @var{directory}
21727 @kindex show index-cache
21728 @itemx show index-cache directory
21729 Set/show the directory where index files will be saved.
21730
21731 The default value for this directory depends on the host platform. On
21732 most systems, the index is cached in the @file{gdb} subdirectory of
21733 the directory pointed to by the @env{XDG_CACHE_HOME} environment
21734 variable, if it is defined, else in the @file{.cache/gdb} subdirectory
21735 of your home directory. However, on some systems, the default may
21736 differ according to local convention.
21737
21738 There is no limit on the disk space used by index cache. It is perfectly safe
21739 to delete the content of that directory to free up disk space.
21740
21741 @item show index-cache stats
21742 Print the number of cache hits and misses since the launch of @value{GDBN}.
21743
21744 @end table
21745
21746 @node Symbol Errors
21747 @section Errors Reading Symbol Files
21748
21749 While reading a symbol file, @value{GDBN} occasionally encounters problems,
21750 such as symbol types it does not recognize, or known bugs in compiler
21751 output. By default, @value{GDBN} does not notify you of such problems, since
21752 they are relatively common and primarily of interest to people
21753 debugging compilers. If you are interested in seeing information
21754 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
21755 only one message about each such type of problem, no matter how many
21756 times the problem occurs; or you can ask @value{GDBN} to print more messages,
21757 to see how many times the problems occur, with the @code{set
21758 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
21759 Messages}).
21760
21761 The messages currently printed, and their meanings, include:
21762
21763 @table @code
21764 @item inner block not inside outer block in @var{symbol}
21765
21766 The symbol information shows where symbol scopes begin and end
21767 (such as at the start of a function or a block of statements). This
21768 error indicates that an inner scope block is not fully contained
21769 in its outer scope blocks.
21770
21771 @value{GDBN} circumvents the problem by treating the inner block as if it had
21772 the same scope as the outer block. In the error message, @var{symbol}
21773 may be shown as ``@code{(don't know)}'' if the outer block is not a
21774 function.
21775
21776 @item block at @var{address} out of order
21777
21778 The symbol information for symbol scope blocks should occur in
21779 order of increasing addresses. This error indicates that it does not
21780 do so.
21781
21782 @value{GDBN} does not circumvent this problem, and has trouble
21783 locating symbols in the source file whose symbols it is reading. (You
21784 can often determine what source file is affected by specifying
21785 @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
21786 Messages}.)
21787
21788 @item bad block start address patched
21789
21790 The symbol information for a symbol scope block has a start address
21791 smaller than the address of the preceding source line. This is known
21792 to occur in the SunOS 4.1.1 (and earlier) C compiler.
21793
21794 @value{GDBN} circumvents the problem by treating the symbol scope block as
21795 starting on the previous source line.
21796
21797 @item bad string table offset in symbol @var{n}
21798
21799 @cindex foo
21800 Symbol number @var{n} contains a pointer into the string table which is
21801 larger than the size of the string table.
21802
21803 @value{GDBN} circumvents the problem by considering the symbol to have the
21804 name @code{foo}, which may cause other problems if many symbols end up
21805 with this name.
21806
21807 @item unknown symbol type @code{0x@var{nn}}
21808
21809 The symbol information contains new data types that @value{GDBN} does
21810 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
21811 uncomprehended information, in hexadecimal.
21812
21813 @value{GDBN} circumvents the error by ignoring this symbol information.
21814 This usually allows you to debug your program, though certain symbols
21815 are not accessible. If you encounter such a problem and feel like
21816 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
21817 on @code{complain}, then go up to the function @code{read_dbx_symtab}
21818 and examine @code{*bufp} to see the symbol.
21819
21820 @item stub type has NULL name
21821
21822 @value{GDBN} could not find the full definition for a struct or class.
21823
21824 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
21825 The symbol information for a C@t{++} member function is missing some
21826 information that recent versions of the compiler should have output for
21827 it.
21828
21829 @item info mismatch between compiler and debugger
21830
21831 @value{GDBN} could not parse a type specification output by the compiler.
21832
21833 @end table
21834
21835 @node Data Files
21836 @section GDB Data Files
21837
21838 @cindex prefix for data files
21839 @value{GDBN} will sometimes read an auxiliary data file. These files
21840 are kept in a directory known as the @dfn{data directory}.
21841
21842 You can set the data directory's name, and view the name @value{GDBN}
21843 is currently using.
21844
21845 @table @code
21846 @kindex set data-directory
21847 @item set data-directory @var{directory}
21848 Set the directory which @value{GDBN} searches for auxiliary data files
21849 to @var{directory}.
21850
21851 @kindex show data-directory
21852 @item show data-directory
21853 Show the directory @value{GDBN} searches for auxiliary data files.
21854 @end table
21855
21856 @cindex default data directory
21857 @cindex @samp{--with-gdb-datadir}
21858 You can set the default data directory by using the configure-time
21859 @samp{--with-gdb-datadir} option. If the data directory is inside
21860 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21861 @samp{--exec-prefix}), then the default data directory will be updated
21862 automatically if the installed @value{GDBN} is moved to a new
21863 location.
21864
21865 The data directory may also be specified with the
21866 @code{--data-directory} command line option.
21867 @xref{Mode Options}.
21868
21869 @node Targets
21870 @chapter Specifying a Debugging Target
21871
21872 @cindex debugging target
21873 A @dfn{target} is the execution environment occupied by your program.
21874
21875 Often, @value{GDBN} runs in the same host environment as your program;
21876 in that case, the debugging target is specified as a side effect when
21877 you use the @code{file} or @code{core} commands. When you need more
21878 flexibility---for example, running @value{GDBN} on a physically separate
21879 host, or controlling a standalone system over a serial port or a
21880 realtime system over a TCP/IP connection---you can use the @code{target}
21881 command to specify one of the target types configured for @value{GDBN}
21882 (@pxref{Target Commands, ,Commands for Managing Targets}).
21883
21884 @cindex target architecture
21885 It is possible to build @value{GDBN} for several different @dfn{target
21886 architectures}. When @value{GDBN} is built like that, you can choose
21887 one of the available architectures with the @kbd{set architecture}
21888 command.
21889
21890 @table @code
21891 @kindex set architecture
21892 @kindex show architecture
21893 @item set architecture @var{arch}
21894 This command sets the current target architecture to @var{arch}. The
21895 value of @var{arch} can be @code{"auto"}, in addition to one of the
21896 supported architectures.
21897
21898 @item show architecture
21899 Show the current target architecture.
21900
21901 @item set processor
21902 @itemx processor
21903 @kindex set processor
21904 @kindex show processor
21905 These are alias commands for, respectively, @code{set architecture}
21906 and @code{show architecture}.
21907 @end table
21908
21909 @menu
21910 * Active Targets:: Active targets
21911 * Target Commands:: Commands for managing targets
21912 * Byte Order:: Choosing target byte order
21913 @end menu
21914
21915 @node Active Targets
21916 @section Active Targets
21917
21918 @cindex stacking targets
21919 @cindex active targets
21920 @cindex multiple targets
21921
21922 There are multiple classes of targets such as: processes, executable files or
21923 recording sessions. Core files belong to the process class, making core file
21924 and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
21925 on multiple active targets, one in each class. This allows you to (for
21926 example) start a process and inspect its activity, while still having access to
21927 the executable file after the process finishes. Or if you start process
21928 recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
21929 presented a virtual layer of the recording target, while the process target
21930 remains stopped at the chronologically last point of the process execution.
21931
21932 Use the @code{core-file} and @code{exec-file} commands to select a new core
21933 file or executable target (@pxref{Files, ,Commands to Specify Files}). To
21934 specify as a target a process that is already running, use the @code{attach}
21935 command (@pxref{Attach, ,Debugging an Already-running Process}).
21936
21937 @node Target Commands
21938 @section Commands for Managing Targets
21939
21940 @table @code
21941 @item target @var{type} @var{parameters}
21942 Connects the @value{GDBN} host environment to a target machine or
21943 process. A target is typically a protocol for talking to debugging
21944 facilities. You use the argument @var{type} to specify the type or
21945 protocol of the target machine.
21946
21947 Further @var{parameters} are interpreted by the target protocol, but
21948 typically include things like device names or host names to connect
21949 with, process numbers, and baud rates.
21950
21951 The @code{target} command does not repeat if you press @key{RET} again
21952 after executing the command.
21953
21954 @kindex help target
21955 @item help target
21956 Displays the names of all targets available. To display targets
21957 currently selected, use either @code{info target} or @code{info files}
21958 (@pxref{Files, ,Commands to Specify Files}).
21959
21960 @item help target @var{name}
21961 Describe a particular target, including any parameters necessary to
21962 select it.
21963
21964 @kindex set gnutarget
21965 @item set gnutarget @var{args}
21966 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
21967 knows whether it is reading an @dfn{executable},
21968 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
21969 with the @code{set gnutarget} command. Unlike most @code{target} commands,
21970 with @code{gnutarget} the @code{target} refers to a program, not a machine.
21971
21972 @quotation
21973 @emph{Warning:} To specify a file format with @code{set gnutarget},
21974 you must know the actual BFD name.
21975 @end quotation
21976
21977 @noindent
21978 @xref{Files, , Commands to Specify Files}.
21979
21980 @kindex show gnutarget
21981 @item show gnutarget
21982 Use the @code{show gnutarget} command to display what file format
21983 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
21984 @value{GDBN} will determine the file format for each file automatically,
21985 and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
21986 @end table
21987
21988 @cindex common targets
21989 Here are some common targets (available, or not, depending on the GDB
21990 configuration):
21991
21992 @table @code
21993 @kindex target
21994 @item target exec @var{program}
21995 @cindex executable file target
21996 An executable file. @samp{target exec @var{program}} is the same as
21997 @samp{exec-file @var{program}}.
21998
21999 @item target core @var{filename}
22000 @cindex core dump file target
22001 A core dump file. @samp{target core @var{filename}} is the same as
22002 @samp{core-file @var{filename}}.
22003
22004 @item target remote @var{medium}
22005 @cindex remote target
22006 A remote system connected to @value{GDBN} via a serial line or network
22007 connection. This command tells @value{GDBN} to use its own remote
22008 protocol over @var{medium} for debugging. @xref{Remote Debugging}.
22009
22010 For example, if you have a board connected to @file{/dev/ttya} on the
22011 machine running @value{GDBN}, you could say:
22012
22013 @smallexample
22014 target remote /dev/ttya
22015 @end smallexample
22016
22017 @code{target remote} supports the @code{load} command. This is only
22018 useful if you have some other way of getting the stub to the target
22019 system, and you can put it somewhere in memory where it won't get
22020 clobbered by the download.
22021
22022 @item target sim @r{[}@var{simargs}@r{]} @dots{}
22023 @cindex built-in simulator target
22024 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
22025 In general,
22026 @smallexample
22027 target sim
22028 load
22029 run
22030 @end smallexample
22031 @noindent
22032 works; however, you cannot assume that a specific memory map, device
22033 drivers, or even basic I/O is available, although some simulators do
22034 provide these. For info about any processor-specific simulator details,
22035 see the appropriate section in @ref{Embedded Processors, ,Embedded
22036 Processors}.
22037
22038 @item target native
22039 @cindex native target
22040 Setup for local/native process debugging. Useful to make the
22041 @code{run} command spawn native processes (likewise @code{attach},
22042 etc.@:) even when @code{set auto-connect-native-target} is @code{off}
22043 (@pxref{set auto-connect-native-target}).
22044
22045 @end table
22046
22047 Different targets are available on different configurations of @value{GDBN};
22048 your configuration may have more or fewer targets.
22049
22050 Many remote targets require you to download the executable's code once
22051 you've successfully established a connection. You may wish to control
22052 various aspects of this process.
22053
22054 @table @code
22055
22056 @item set hash
22057 @kindex set hash@r{, for remote monitors}
22058 @cindex hash mark while downloading
22059 This command controls whether a hash mark @samp{#} is displayed while
22060 downloading a file to the remote monitor. If on, a hash mark is
22061 displayed after each S-record is successfully downloaded to the
22062 monitor.
22063
22064 @item show hash
22065 @kindex show hash@r{, for remote monitors}
22066 Show the current status of displaying the hash mark.
22067
22068 @item set debug monitor
22069 @kindex set debug monitor
22070 @cindex display remote monitor communications
22071 Enable or disable display of communications messages between
22072 @value{GDBN} and the remote monitor.
22073
22074 @item show debug monitor
22075 @kindex show debug monitor
22076 Show the current status of displaying communications between
22077 @value{GDBN} and the remote monitor.
22078 @end table
22079
22080 @table @code
22081
22082 @kindex load @var{filename} @var{offset}
22083 @item load @var{filename} @var{offset}
22084 @anchor{load}
22085 Depending on what remote debugging facilities are configured into
22086 @value{GDBN}, the @code{load} command may be available. Where it exists, it
22087 is meant to make @var{filename} (an executable) available for debugging
22088 on the remote system---by downloading, or dynamic linking, for example.
22089 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
22090 the @code{add-symbol-file} command.
22091
22092 If your @value{GDBN} does not have a @code{load} command, attempting to
22093 execute it gets the error message ``@code{You can't do that when your
22094 target is @dots{}}''
22095
22096 The file is loaded at whatever address is specified in the executable.
22097 For some object file formats, you can specify the load address when you
22098 link the program; for other formats, like a.out, the object file format
22099 specifies a fixed address.
22100 @c FIXME! This would be a good place for an xref to the GNU linker doc.
22101
22102 It is also possible to tell @value{GDBN} to load the executable file at a
22103 specific offset described by the optional argument @var{offset}. When
22104 @var{offset} is provided, @var{filename} must also be provided.
22105
22106 Depending on the remote side capabilities, @value{GDBN} may be able to
22107 load programs into flash memory.
22108
22109 @code{load} does not repeat if you press @key{RET} again after using it.
22110 @end table
22111
22112 @table @code
22113
22114 @kindex flash-erase
22115 @item flash-erase
22116 @anchor{flash-erase}
22117
22118 Erases all known flash memory regions on the target.
22119
22120 @end table
22121
22122 @node Byte Order
22123 @section Choosing Target Byte Order
22124
22125 @cindex choosing target byte order
22126 @cindex target byte order
22127
22128 Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
22129 offer the ability to run either big-endian or little-endian byte
22130 orders. Usually the executable or symbol will include a bit to
22131 designate the endian-ness, and you will not need to worry about
22132 which to use. However, you may still find it useful to adjust
22133 @value{GDBN}'s idea of processor endian-ness manually.
22134
22135 @table @code
22136 @kindex set endian
22137 @item set endian big
22138 Instruct @value{GDBN} to assume the target is big-endian.
22139
22140 @item set endian little
22141 Instruct @value{GDBN} to assume the target is little-endian.
22142
22143 @item set endian auto
22144 Instruct @value{GDBN} to use the byte order associated with the
22145 executable.
22146
22147 @item show endian
22148 Display @value{GDBN}'s current idea of the target byte order.
22149
22150 @end table
22151
22152 If the @code{set endian auto} mode is in effect and no executable has
22153 been selected, then the endianness used is the last one chosen either
22154 by one of the @code{set endian big} and @code{set endian little}
22155 commands or by inferring from the last executable used. If no
22156 endianness has been previously chosen, then the default for this mode
22157 is inferred from the target @value{GDBN} has been built for, and is
22158 @code{little} if the name of the target CPU has an @code{el} suffix
22159 and @code{big} otherwise.
22160
22161 Note that these commands merely adjust interpretation of symbolic
22162 data on the host, and that they have absolutely no effect on the
22163 target system.
22164
22165
22166 @node Remote Debugging
22167 @chapter Debugging Remote Programs
22168 @cindex remote debugging
22169
22170 If you are trying to debug a program running on a machine that cannot run
22171 @value{GDBN} in the usual way, it is often useful to use remote debugging.
22172 For example, you might use remote debugging on an operating system kernel,
22173 or on a small system which does not have a general purpose operating system
22174 powerful enough to run a full-featured debugger.
22175
22176 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
22177 to make this work with particular debugging targets. In addition,
22178 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
22179 but not specific to any particular target system) which you can use if you
22180 write the remote stubs---the code that runs on the remote system to
22181 communicate with @value{GDBN}.
22182
22183 Other remote targets may be available in your
22184 configuration of @value{GDBN}; use @code{help target} to list them.
22185
22186 @menu
22187 * Connecting:: Connecting to a remote target
22188 * File Transfer:: Sending files to a remote system
22189 * Server:: Using the gdbserver program
22190 * Remote Configuration:: Remote configuration
22191 * Remote Stub:: Implementing a remote stub
22192 @end menu
22193
22194 @node Connecting
22195 @section Connecting to a Remote Target
22196 @cindex remote debugging, connecting
22197 @cindex @code{gdbserver}, connecting
22198 @cindex remote debugging, types of connections
22199 @cindex @code{gdbserver}, types of connections
22200 @cindex @code{gdbserver}, @code{target remote} mode
22201 @cindex @code{gdbserver}, @code{target extended-remote} mode
22202
22203 This section describes how to connect to a remote target, including the
22204 types of connections and their differences, how to set up executable and
22205 symbol files on the host and target, and the commands used for
22206 connecting to and disconnecting from the remote target.
22207
22208 @subsection Types of Remote Connections
22209
22210 @value{GDBN} supports two types of remote connections, @code{target remote}
22211 mode and @code{target extended-remote} mode. Note that many remote targets
22212 support only @code{target remote} mode. There are several major
22213 differences between the two types of connections, enumerated here:
22214
22215 @table @asis
22216
22217 @cindex remote debugging, detach and program exit
22218 @item Result of detach or program exit
22219 @strong{With target remote mode:} When the debugged program exits or you
22220 detach from it, @value{GDBN} disconnects from the target. When using
22221 @code{gdbserver}, @code{gdbserver} will exit.
22222
22223 @strong{With target extended-remote mode:} When the debugged program exits or
22224 you detach from it, @value{GDBN} remains connected to the target, even
22225 though no program is running. You can rerun the program, attach to a
22226 running program, or use @code{monitor} commands specific to the target.
22227
22228 When using @code{gdbserver} in this case, it does not exit unless it was
22229 invoked using the @option{--once} option. If the @option{--once} option
22230 was not used, you can ask @code{gdbserver} to exit using the
22231 @code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
22232
22233 @item Specifying the program to debug
22234 For both connection types you use the @code{file} command to specify the
22235 program on the host system. If you are using @code{gdbserver} there are
22236 some differences in how to specify the location of the program on the
22237 target.
22238
22239 @strong{With target remote mode:} You must either specify the program to debug
22240 on the @code{gdbserver} command line or use the @option{--attach} option
22241 (@pxref{Attaching to a program,,Attaching to a Running Program}).
22242
22243 @cindex @option{--multi}, @code{gdbserver} option
22244 @strong{With target extended-remote mode:} You may specify the program to debug
22245 on the @code{gdbserver} command line, or you can load the program or attach
22246 to it using @value{GDBN} commands after connecting to @code{gdbserver}.
22247
22248 @anchor{--multi Option in Types of Remote Connnections}
22249 You can start @code{gdbserver} without supplying an initial command to run
22250 or process ID to attach. To do this, use the @option{--multi} command line
22251 option. Then you can connect using @code{target extended-remote} and start
22252 the program you want to debug (see below for details on using the
22253 @code{run} command in this scenario). Note that the conditions under which
22254 @code{gdbserver} terminates depend on how @value{GDBN} connects to it
22255 (@code{target remote} or @code{target extended-remote}). The
22256 @option{--multi} option to @code{gdbserver} has no influence on that.
22257
22258 @item The @code{run} command
22259 @strong{With target remote mode:} The @code{run} command is not
22260 supported. Once a connection has been established, you can use all
22261 the usual @value{GDBN} commands to examine and change data. The
22262 remote program is already running, so you can use commands like
22263 @kbd{step} and @kbd{continue}.
22264
22265 @strong{With target extended-remote mode:} The @code{run} command is
22266 supported. The @code{run} command uses the value set by
22267 @code{set remote exec-file} (@pxref{set remote exec-file}) to select
22268 the program to run. Command line arguments are supported, except for
22269 wildcard expansion and I/O redirection (@pxref{Arguments}).
22270
22271 If you specify the program to debug on the command line, then the
22272 @code{run} command is not required to start execution, and you can
22273 resume using commands like @kbd{step} and @kbd{continue} as with
22274 @code{target remote} mode.
22275
22276 @anchor{Attaching in Types of Remote Connections}
22277 @item Attaching
22278 @strong{With target remote mode:} The @value{GDBN} command @code{attach} is
22279 not supported. To attach to a running program using @code{gdbserver}, you
22280 must use the @option{--attach} option (@pxref{Running gdbserver}).
22281
22282 @strong{With target extended-remote mode:} To attach to a running program,
22283 you may use the @code{attach} command after the connection has been
22284 established. If you are using @code{gdbserver}, you may also invoke
22285 @code{gdbserver} using the @option{--attach} option
22286 (@pxref{Running gdbserver}).
22287
22288 Some remote targets allow @value{GDBN} to determine the executable file running
22289 in the process the debugger is attaching to. In such a case, @value{GDBN}
22290 uses the value of @code{exec-file-mismatch} to handle a possible mismatch
22291 between the executable file name running in the process and the name of the
22292 current exec-file loaded by @value{GDBN} (@pxref{set exec-file-mismatch}).
22293
22294 @end table
22295
22296 @anchor{Host and target files}
22297 @subsection Host and Target Files
22298 @cindex remote debugging, symbol files
22299 @cindex symbol files, remote debugging
22300
22301 @value{GDBN}, running on the host, needs access to symbol and debugging
22302 information for your program running on the target. This requires
22303 access to an unstripped copy of your program, and possibly any associated
22304 symbol files. Note that this section applies equally to both @code{target
22305 remote} mode and @code{target extended-remote} mode.
22306
22307 Some remote targets (@pxref{qXfer executable filename read}, and
22308 @pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
22309 the same connection used to communicate with @value{GDBN}. With such a
22310 target, if the remote program is unstripped, the only command you need is
22311 @code{target remote} (or @code{target extended-remote}).
22312
22313 If the remote program is stripped, or the target does not support remote
22314 program file access, start up @value{GDBN} using the name of the local
22315 unstripped copy of your program as the first argument, or use the
22316 @code{file} command. Use @code{set sysroot} to specify the location (on
22317 the host) of target libraries (unless your @value{GDBN} was compiled with
22318 the correct sysroot using @code{--with-sysroot}). Alternatively, you
22319 may use @code{set solib-search-path} to specify how @value{GDBN} locates
22320 target libraries.
22321
22322 The symbol file and target libraries must exactly match the executable
22323 and libraries on the target, with one exception: the files on the host
22324 system should not be stripped, even if the files on the target system
22325 are. Mismatched or missing files will lead to confusing results
22326 during debugging. On @sc{gnu}/Linux targets, mismatched or missing
22327 files may also prevent @code{gdbserver} from debugging multi-threaded
22328 programs.
22329
22330 @subsection Remote Connection Commands
22331 @cindex remote connection commands
22332 @value{GDBN} can communicate with the target over a serial line, a
22333 local Unix domain socket, or
22334 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
22335 each case, @value{GDBN} uses the same protocol for debugging your
22336 program; only the medium carrying the debugging packets varies. The
22337 @code{target remote} and @code{target extended-remote} commands
22338 establish a connection to the target. Both commands accept the same
22339 arguments, which indicate the medium to use:
22340
22341 @table @code
22342
22343 @item target remote @var{serial-device}
22344 @itemx target extended-remote @var{serial-device}
22345 @cindex serial line, @code{target remote}
22346 Use @var{serial-device} to communicate with the target. For example,
22347 to use a serial line connected to the device named @file{/dev/ttyb}:
22348
22349 @smallexample
22350 target remote /dev/ttyb
22351 @end smallexample
22352
22353 If you're using a serial line, you may want to give @value{GDBN} the
22354 @samp{--baud} option, or use the @code{set serial baud} command
22355 (@pxref{Remote Configuration, set serial baud}) before the
22356 @code{target} command.
22357
22358 @item target remote @var{local-socket}
22359 @itemx target extended-remote @var{local-socket}
22360 @cindex local socket, @code{target remote}
22361 @cindex Unix domain socket
22362 Use @var{local-socket} to communicate with the target. For example,
22363 to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
22364
22365 @smallexample
22366 target remote /tmp/gdb-socket0
22367 @end smallexample
22368
22369 Note that this command has the same form as the command to connect
22370 to a serial line. @value{GDBN} will automatically determine which
22371 kind of file you have specified and will make the appropriate kind
22372 of connection.
22373 This feature is not available if the host system does not support
22374 Unix domain sockets.
22375
22376 @item target remote @code{@var{host}:@var{port}}
22377 @itemx target remote @code{[@var{host}]:@var{port}}
22378 @itemx target remote @code{tcp:@var{host}:@var{port}}
22379 @itemx target remote @code{tcp:[@var{host}]:@var{port}}
22380 @itemx target remote @code{tcp4:@var{host}:@var{port}}
22381 @itemx target remote @code{tcp6:@var{host}:@var{port}}
22382 @itemx target remote @code{tcp6:[@var{host}]:@var{port}}
22383 @itemx target extended-remote @code{@var{host}:@var{port}}
22384 @itemx target extended-remote @code{[@var{host}]:@var{port}}
22385 @itemx target extended-remote @code{tcp:@var{host}:@var{port}}
22386 @itemx target extended-remote @code{tcp:[@var{host}]:@var{port}}
22387 @itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
22388 @itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
22389 @itemx target extended-remote @code{tcp6:[@var{host}]:@var{port}}
22390 @cindex @acronym{TCP} port, @code{target remote}
22391 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
22392 The @var{host} may be either a host name, a numeric @acronym{IPv4}
22393 address, or a numeric @acronym{IPv6} address (with or without the
22394 square brackets to separate the address from the port); @var{port}
22395 must be a decimal number. The @var{host} could be the target machine
22396 itself, if it is directly connected to the net, or it might be a
22397 terminal server which in turn has a serial line to the target.
22398
22399 For example, to connect to port 2828 on a terminal server named
22400 @code{manyfarms}:
22401
22402 @smallexample
22403 target remote manyfarms:2828
22404 @end smallexample
22405
22406 To connect to port 2828 on a terminal server whose address is
22407 @code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
22408 square bracket syntax:
22409
22410 @smallexample
22411 target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
22412 @end smallexample
22413
22414 @noindent
22415 or explicitly specify the @acronym{IPv6} protocol:
22416
22417 @smallexample
22418 target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
22419 @end smallexample
22420
22421 This last example may be confusing to the reader, because there is no
22422 visible separation between the hostname and the port number.
22423 Therefore, we recommend the user to provide @acronym{IPv6} addresses
22424 using square brackets for clarity. However, it is important to
22425 mention that for @value{GDBN} there is no ambiguity: the number after
22426 the last colon is considered to be the port number.
22427
22428 If your remote target is actually running on the same machine as your
22429 debugger session (e.g.@: a simulator for your target running on the
22430 same host), you can omit the hostname. For example, to connect to
22431 port 1234 on your local machine:
22432
22433 @smallexample
22434 target remote :1234
22435 @end smallexample
22436 @noindent
22437
22438 Note that the colon is still required here.
22439
22440 @item target remote @code{udp:@var{host}:@var{port}}
22441 @itemx target remote @code{udp:[@var{host}]:@var{port}}
22442 @itemx target remote @code{udp4:@var{host}:@var{port}}
22443 @itemx target remote @code{udp6:[@var{host}]:@var{port}}
22444 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
22445 @itemx target extended-remote @code{udp:@var{host}:@var{port}}
22446 @itemx target extended-remote @code{udp:[@var{host}]:@var{port}}
22447 @itemx target extended-remote @code{udp4:@var{host}:@var{port}}
22448 @itemx target extended-remote @code{udp6:@var{host}:@var{port}}
22449 @itemx target extended-remote @code{udp6:[@var{host}]:@var{port}}
22450 @cindex @acronym{UDP} port, @code{target remote}
22451 Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
22452 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
22453
22454 @smallexample
22455 target remote udp:manyfarms:2828
22456 @end smallexample
22457
22458 When using a @acronym{UDP} connection for remote debugging, you should
22459 keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
22460 can silently drop packets on busy or unreliable networks, which will
22461 cause havoc with your debugging session.
22462
22463 @item target remote | @var{command}
22464 @itemx target extended-remote | @var{command}
22465 @cindex pipe, @code{target remote} to
22466 Run @var{command} in the background and communicate with it using a
22467 pipe. The @var{command} is a shell command, to be parsed and expanded
22468 by the system's command shell, @code{/bin/sh}; it should expect remote
22469 protocol packets on its standard input, and send replies on its
22470 standard output. You could use this to run a stand-alone simulator
22471 that speaks the remote debugging protocol, to make net connections
22472 using programs like @code{ssh}, or for other similar tricks.
22473
22474 If @var{command} closes its standard output (perhaps by exiting),
22475 @value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
22476 program has already exited, this will have no effect.)
22477
22478 @end table
22479
22480 @cindex interrupting remote programs
22481 @cindex remote programs, interrupting
22482 Whenever @value{GDBN} is waiting for the remote program, if you type the
22483 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
22484 program. This may or may not succeed, depending in part on the hardware
22485 and the serial drivers the remote system uses. If you type the
22486 interrupt character once again, @value{GDBN} displays this prompt:
22487
22488 @smallexample
22489 Interrupted while waiting for the program.
22490 Give up (and stop debugging it)? (y or n)
22491 @end smallexample
22492
22493 In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22494 the remote debugging session. (If you decide you want to try again later,
22495 you can use @kbd{target remote} again to connect once more.) If you type
22496 @kbd{n}, @value{GDBN} goes back to waiting.
22497
22498 In @code{target extended-remote} mode, typing @kbd{n} will leave
22499 @value{GDBN} connected to the target.
22500
22501 @table @code
22502 @kindex detach (remote)
22503 @item detach
22504 When you have finished debugging the remote program, you can use the
22505 @code{detach} command to release it from @value{GDBN} control.
22506 Detaching from the target normally resumes its execution, but the results
22507 will depend on your particular remote stub. After the @code{detach}
22508 command in @code{target remote} mode, @value{GDBN} is free to connect to
22509 another target. In @code{target extended-remote} mode, @value{GDBN} is
22510 still connected to the target.
22511
22512 @kindex disconnect
22513 @item disconnect
22514 The @code{disconnect} command closes the connection to the target, and
22515 the target is generally not resumed. It will wait for @value{GDBN}
22516 (this instance or another one) to connect and continue debugging. After
22517 the @code{disconnect} command, @value{GDBN} is again free to connect to
22518 another target.
22519
22520 @cindex send command to remote monitor
22521 @cindex extend @value{GDBN} for remote targets
22522 @cindex add new commands for external monitor
22523 @kindex monitor
22524 @item monitor @var{cmd}
22525 This command allows you to send arbitrary commands directly to the
22526 remote monitor. Since @value{GDBN} doesn't care about the commands it
22527 sends like this, this command is the way to extend @value{GDBN}---you
22528 can add new commands that only the external monitor will understand
22529 and implement.
22530 @end table
22531
22532 @node File Transfer
22533 @section Sending files to a remote system
22534 @cindex remote target, file transfer
22535 @cindex file transfer
22536 @cindex sending files to remote systems
22537
22538 Some remote targets offer the ability to transfer files over the same
22539 connection used to communicate with @value{GDBN}. This is convenient
22540 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
22541 running @code{gdbserver} over a network interface. For other targets,
22542 e.g.@: embedded devices with only a single serial port, this may be
22543 the only way to upload or download files.
22544
22545 Not all remote targets support these commands.
22546
22547 @table @code
22548 @kindex remote put
22549 @item remote put @var{hostfile} @var{targetfile}
22550 Copy file @var{hostfile} from the host system (the machine running
22551 @value{GDBN}) to @var{targetfile} on the target system.
22552
22553 @kindex remote get
22554 @item remote get @var{targetfile} @var{hostfile}
22555 Copy file @var{targetfile} from the target system to @var{hostfile}
22556 on the host system.
22557
22558 @kindex remote delete
22559 @item remote delete @var{targetfile}
22560 Delete @var{targetfile} from the target system.
22561
22562 @end table
22563
22564 @node Server
22565 @section Using the @code{gdbserver} Program
22566
22567 @kindex gdbserver
22568 @cindex remote connection without stubs
22569 @code{gdbserver} is a control program for Unix-like systems, which
22570 allows you to connect your program with a remote @value{GDBN} via
22571 @code{target remote} or @code{target extended-remote}---but without
22572 linking in the usual debugging stub.
22573
22574 @code{gdbserver} is not a complete replacement for the debugging stubs,
22575 because it requires essentially the same operating-system facilities
22576 that @value{GDBN} itself does. In fact, a system that can run
22577 @code{gdbserver} to connect to a remote @value{GDBN} could also run
22578 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
22579 because it is a much smaller program than @value{GDBN} itself. It is
22580 also easier to port than all of @value{GDBN}, so you may be able to get
22581 started more quickly on a new system by using @code{gdbserver}.
22582 Finally, if you develop code for real-time systems, you may find that
22583 the tradeoffs involved in real-time operation make it more convenient to
22584 do as much development work as possible on another system, for example
22585 by cross-compiling. You can use @code{gdbserver} to make a similar
22586 choice for debugging.
22587
22588 @value{GDBN} and @code{gdbserver} communicate via either a serial line
22589 or a TCP connection, using the standard @value{GDBN} remote serial
22590 protocol.
22591
22592 @quotation
22593 @emph{Warning:} @code{gdbserver} does not have any built-in security.
22594 Do not run @code{gdbserver} connected to any public network; a
22595 @value{GDBN} connection to @code{gdbserver} provides access to the
22596 target system with the same privileges as the user running
22597 @code{gdbserver}.
22598 @end quotation
22599
22600 @anchor{Running gdbserver}
22601 @subsection Running @code{gdbserver}
22602 @cindex arguments, to @code{gdbserver}
22603 @cindex @code{gdbserver}, command-line arguments
22604
22605 Run @code{gdbserver} on the target system. You need a copy of the
22606 program you want to debug, including any libraries it requires.
22607 @code{gdbserver} does not need your program's symbol table, so you can
22608 strip the program if necessary to save space. @value{GDBN} on the host
22609 system does all the symbol handling.
22610
22611 To use the server, you must tell it how to communicate with @value{GDBN};
22612 the name of your program; and the arguments for your program. The usual
22613 syntax is:
22614
22615 @smallexample
22616 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
22617 @end smallexample
22618
22619 @var{comm} is either a device name (to use a serial line), or a TCP
22620 hostname and portnumber, or @code{-} or @code{stdio} to use
22621 stdin/stdout of @code{gdbserver}.
22622 For example, to debug Emacs with the argument
22623 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
22624 @file{/dev/com1}:
22625
22626 @smallexample
22627 target> gdbserver /dev/com1 emacs foo.txt
22628 @end smallexample
22629
22630 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
22631 with it.
22632
22633 To use a TCP connection instead of a serial line:
22634
22635 @smallexample
22636 target> gdbserver host:2345 emacs foo.txt
22637 @end smallexample
22638
22639 The only difference from the previous example is the first argument,
22640 specifying that you are communicating with the host @value{GDBN} via
22641 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
22642 expect a TCP connection from machine @samp{host} to local TCP port 2345.
22643 (Currently, the @samp{host} part is ignored.) You can choose any number
22644 you want for the port number as long as it does not conflict with any
22645 TCP ports already in use on the target system (for example, @code{23} is
22646 reserved for @code{telnet}).@footnote{If you choose a port number that
22647 conflicts with another service, @code{gdbserver} prints an error message
22648 and exits.} You must use the same port number with the host @value{GDBN}
22649 @code{target remote} command.
22650
22651 The @code{stdio} connection is useful when starting @code{gdbserver}
22652 with ssh:
22653
22654 @smallexample
22655 (gdb) target remote | ssh -T hostname gdbserver - hello
22656 @end smallexample
22657
22658 The @samp{-T} option to ssh is provided because we don't need a remote pty,
22659 and we don't want escape-character handling. Ssh does this by default when
22660 a command is provided, the flag is provided to make it explicit.
22661 You could elide it if you want to.
22662
22663 Programs started with stdio-connected gdbserver have @file{/dev/null} for
22664 @code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
22665 display through a pipe connected to gdbserver.
22666 Both @code{stdout} and @code{stderr} use the same pipe.
22667
22668 @anchor{Attaching to a program}
22669 @subsubsection Attaching to a Running Program
22670 @cindex attach to a program, @code{gdbserver}
22671 @cindex @option{--attach}, @code{gdbserver} option
22672
22673 On some targets, @code{gdbserver} can also attach to running programs.
22674 This is accomplished via the @code{--attach} argument. The syntax is:
22675
22676 @smallexample
22677 target> gdbserver --attach @var{comm} @var{pid}
22678 @end smallexample
22679
22680 @var{pid} is the process ID of a currently running process. It isn't
22681 necessary to point @code{gdbserver} at a binary for the running process.
22682
22683 In @code{target extended-remote} mode, you can also attach using the
22684 @value{GDBN} attach command
22685 (@pxref{Attaching in Types of Remote Connections}).
22686
22687 @pindex pidof
22688 You can debug processes by name instead of process ID if your target has the
22689 @code{pidof} utility:
22690
22691 @smallexample
22692 target> gdbserver --attach @var{comm} `pidof @var{program}`
22693 @end smallexample
22694
22695 In case more than one copy of @var{program} is running, or @var{program}
22696 has multiple threads, most versions of @code{pidof} support the
22697 @code{-s} option to only return the first process ID.
22698
22699 @subsubsection TCP port allocation lifecycle of @code{gdbserver}
22700
22701 This section applies only when @code{gdbserver} is run to listen on a TCP
22702 port.
22703
22704 @code{gdbserver} normally terminates after all of its debugged processes have
22705 terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
22706 extended-remote}, @code{gdbserver} stays running even with no processes left.
22707 @value{GDBN} normally terminates the spawned debugged process on its exit,
22708 which normally also terminates @code{gdbserver} in the @kbd{target remote}
22709 mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
22710 cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
22711 stays running even in the @kbd{target remote} mode.
22712
22713 When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
22714 Such reconnecting is useful for features like @ref{disconnected tracing}. For
22715 completeness, at most one @value{GDBN} can be connected at a time.
22716
22717 @cindex @option{--once}, @code{gdbserver} option
22718 By default, @code{gdbserver} keeps the listening TCP port open, so that
22719 subsequent connections are possible. However, if you start @code{gdbserver}
22720 with the @option{--once} option, it will stop listening for any further
22721 connection attempts after connecting to the first @value{GDBN} session. This
22722 means no further connections to @code{gdbserver} will be possible after the
22723 first one. It also means @code{gdbserver} will terminate after the first
22724 connection with remote @value{GDBN} has closed, even for unexpectedly closed
22725 connections and even in the @kbd{target extended-remote} mode. The
22726 @option{--once} option allows reusing the same port number for connecting to
22727 multiple instances of @code{gdbserver} running on the same host, since each
22728 instance closes its port after the first connection.
22729
22730 @anchor{Other Command-Line Arguments for gdbserver}
22731 @subsubsection Other Command-Line Arguments for @code{gdbserver}
22732
22733 You can use the @option{--multi} option to start @code{gdbserver} without
22734 specifying a program to debug or a process to attach to. Then you can
22735 attach in @code{target extended-remote} mode and run or attach to a
22736 program. For more information,
22737 @pxref{--multi Option in Types of Remote Connnections}.
22738
22739 @cindex @option{--debug}, @code{gdbserver} option
22740 The @option{--debug} option tells @code{gdbserver} to display extra
22741 status information about the debugging process.
22742 @cindex @option{--remote-debug}, @code{gdbserver} option
22743 The @option{--remote-debug} option tells @code{gdbserver} to display
22744 remote protocol debug output.
22745 @cindex @option{--debug-file}, @code{gdbserver} option
22746 @cindex @code{gdbserver}, send all debug output to a single file
22747 The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
22748 write any debug output to the given @var{filename}. These options are intended
22749 for @code{gdbserver} development and for bug reports to the developers.
22750
22751 @cindex @option{--debug-format}, @code{gdbserver} option
22752 The @option{--debug-format=option1[,option2,...]} option tells
22753 @code{gdbserver} to include additional information in each output.
22754 Possible options are:
22755
22756 @table @code
22757 @item none
22758 Turn off all extra information in debugging output.
22759 @item all
22760 Turn on all extra information in debugging output.
22761 @item timestamps
22762 Include a timestamp in each line of debugging output.
22763 @end table
22764
22765 Options are processed in order. Thus, for example, if @option{none}
22766 appears last then no additional information is added to debugging output.
22767
22768 @cindex @option{--wrapper}, @code{gdbserver} option
22769 The @option{--wrapper} option specifies a wrapper to launch programs
22770 for debugging. The option should be followed by the name of the
22771 wrapper, then any command-line arguments to pass to the wrapper, then
22772 @kbd{--} indicating the end of the wrapper arguments.
22773
22774 @code{gdbserver} runs the specified wrapper program with a combined
22775 command line including the wrapper arguments, then the name of the
22776 program to debug, then any arguments to the program. The wrapper
22777 runs until it executes your program, and then @value{GDBN} gains control.
22778
22779 You can use any program that eventually calls @code{execve} with
22780 its arguments as a wrapper. Several standard Unix utilities do
22781 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
22782 with @code{exec "$@@"} will also work.
22783
22784 For example, you can use @code{env} to pass an environment variable to
22785 the debugged program, without setting the variable in @code{gdbserver}'s
22786 environment:
22787
22788 @smallexample
22789 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
22790 @end smallexample
22791
22792 @cindex @option{--selftest}
22793 The @option{--selftest} option runs the self tests in @code{gdbserver}:
22794
22795 @smallexample
22796 $ gdbserver --selftest
22797 Ran 2 unit tests, 0 failed
22798 @end smallexample
22799
22800 These tests are disabled in release.
22801 @subsection Connecting to @code{gdbserver}
22802
22803 The basic procedure for connecting to the remote target is:
22804 @itemize
22805
22806 @item
22807 Run @value{GDBN} on the host system.
22808
22809 @item
22810 Make sure you have the necessary symbol files
22811 (@pxref{Host and target files}).
22812 Load symbols for your application using the @code{file} command before you
22813 connect. Use @code{set sysroot} to locate target libraries (unless your
22814 @value{GDBN} was compiled with the correct sysroot using
22815 @code{--with-sysroot}).
22816
22817 @item
22818 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
22819 For TCP connections, you must start up @code{gdbserver} prior to using
22820 the @code{target} command. Otherwise you may get an error whose
22821 text depends on the host system, but which usually looks something like
22822 @samp{Connection refused}. Don't use the @code{load}
22823 command in @value{GDBN} when using @code{target remote} mode, since the
22824 program is already on the target.
22825
22826 @end itemize
22827
22828 @anchor{Monitor Commands for gdbserver}
22829 @subsection Monitor Commands for @code{gdbserver}
22830 @cindex monitor commands, for @code{gdbserver}
22831
22832 During a @value{GDBN} session using @code{gdbserver}, you can use the
22833 @code{monitor} command to send special requests to @code{gdbserver}.
22834 Here are the available commands.
22835
22836 @table @code
22837 @item monitor help
22838 List the available monitor commands.
22839
22840 @item monitor set debug 0
22841 @itemx monitor set debug 1
22842 Disable or enable general debugging messages.
22843
22844 @item monitor set remote-debug 0
22845 @itemx monitor set remote-debug 1
22846 Disable or enable specific debugging messages associated with the remote
22847 protocol (@pxref{Remote Protocol}).
22848
22849 @item monitor set debug-file filename
22850 @itemx monitor set debug-file
22851 Send any debug output to the given file, or to stderr.
22852
22853 @item monitor set debug-format option1@r{[},option2,...@r{]}
22854 Specify additional text to add to debugging messages.
22855 Possible options are:
22856
22857 @table @code
22858 @item none
22859 Turn off all extra information in debugging output.
22860 @item all
22861 Turn on all extra information in debugging output.
22862 @item timestamps
22863 Include a timestamp in each line of debugging output.
22864 @end table
22865
22866 Options are processed in order. Thus, for example, if @option{none}
22867 appears last then no additional information is added to debugging output.
22868
22869 @item monitor set libthread-db-search-path [PATH]
22870 @cindex gdbserver, search path for @code{libthread_db}
22871 When this command is issued, @var{path} is a colon-separated list of
22872 directories to search for @code{libthread_db} (@pxref{Threads,,set
22873 libthread-db-search-path}). If you omit @var{path},
22874 @samp{libthread-db-search-path} will be reset to its default value.
22875
22876 The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
22877 not supported in @code{gdbserver}.
22878
22879 @item monitor exit
22880 Tell gdbserver to exit immediately. This command should be followed by
22881 @code{disconnect} to close the debugging session. @code{gdbserver} will
22882 detach from any attached processes and kill any processes it created.
22883 Use @code{monitor exit} to terminate @code{gdbserver} at the end
22884 of a multi-process mode debug session.
22885
22886 @end table
22887
22888 @subsection Tracepoints support in @code{gdbserver}
22889 @cindex tracepoints support in @code{gdbserver}
22890
22891 On some targets, @code{gdbserver} supports tracepoints, fast
22892 tracepoints and static tracepoints.
22893
22894 For fast or static tracepoints to work, a special library called the
22895 @dfn{in-process agent} (IPA), must be loaded in the inferior process.
22896 This library is built and distributed as an integral part of
22897 @code{gdbserver}. In addition, support for static tracepoints
22898 requires building the in-process agent library with static tracepoints
22899 support. At present, the UST (LTTng Userspace Tracer,
22900 @url{http://lttng.org/ust}) tracing engine is supported. This support
22901 is automatically available if UST development headers are found in the
22902 standard include path when @code{gdbserver} is built, or if
22903 @code{gdbserver} was explicitly configured using @option{--with-ust}
22904 to point at such headers. You can explicitly disable the support
22905 using @option{--with-ust=no}.
22906
22907 There are several ways to load the in-process agent in your program:
22908
22909 @table @code
22910 @item Specifying it as dependency at link time
22911
22912 You can link your program dynamically with the in-process agent
22913 library. On most systems, this is accomplished by adding
22914 @code{-linproctrace} to the link command.
22915
22916 @item Using the system's preloading mechanisms
22917
22918 You can force loading the in-process agent at startup time by using
22919 your system's support for preloading shared libraries. Many Unixes
22920 support the concept of preloading user defined libraries. In most
22921 cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
22922 in the environment. See also the description of @code{gdbserver}'s
22923 @option{--wrapper} command line option.
22924
22925 @item Using @value{GDBN} to force loading the agent at run time
22926
22927 On some systems, you can force the inferior to load a shared library,
22928 by calling a dynamic loader function in the inferior that takes care
22929 of dynamically looking up and loading a shared library. On most Unix
22930 systems, the function is @code{dlopen}. You'll use the @code{call}
22931 command for that. For example:
22932
22933 @smallexample
22934 (@value{GDBP}) call dlopen ("libinproctrace.so", ...)
22935 @end smallexample
22936
22937 Note that on most Unix systems, for the @code{dlopen} function to be
22938 available, the program needs to be linked with @code{-ldl}.
22939 @end table
22940
22941 On systems that have a userspace dynamic loader, like most Unix
22942 systems, when you connect to @code{gdbserver} using @code{target
22943 remote}, you'll find that the program is stopped at the dynamic
22944 loader's entry point, and no shared library has been loaded in the
22945 program's address space yet, including the in-process agent. In that
22946 case, before being able to use any of the fast or static tracepoints
22947 features, you need to let the loader run and load the shared
22948 libraries. The simplest way to do that is to run the program to the
22949 main procedure. E.g., if debugging a C or C@t{++} program, start
22950 @code{gdbserver} like so:
22951
22952 @smallexample
22953 $ gdbserver :9999 myprogram
22954 @end smallexample
22955
22956 Start GDB and connect to @code{gdbserver} like so, and run to main:
22957
22958 @smallexample
22959 $ gdb myprogram
22960 (@value{GDBP}) target remote myhost:9999
22961 0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
22962 (@value{GDBP}) b main
22963 (@value{GDBP}) continue
22964 @end smallexample
22965
22966 The in-process tracing agent library should now be loaded into the
22967 process; you can confirm it with the @code{info sharedlibrary}
22968 command, which will list @file{libinproctrace.so} as loaded in the
22969 process. You are now ready to install fast tracepoints, list static
22970 tracepoint markers, probe static tracepoints markers, and start
22971 tracing.
22972
22973 @node Remote Configuration
22974 @section Remote Configuration
22975
22976 @kindex set remote
22977 @kindex show remote
22978 This section documents the configuration options available when
22979 debugging remote programs. For the options related to the File I/O
22980 extensions of the remote protocol, see @ref{system,
22981 system-call-allowed}.
22982
22983 @table @code
22984 @item set remoteaddresssize @var{bits}
22985 @cindex address size for remote targets
22986 @cindex bits in remote address
22987 Set the maximum size of address in a memory packet to the specified
22988 number of bits. @value{GDBN} will mask off the address bits above
22989 that number, when it passes addresses to the remote target. The
22990 default value is the number of bits in the target's address.
22991
22992 @item show remoteaddresssize
22993 Show the current value of remote address size in bits.
22994
22995 @item set serial baud @var{n}
22996 @cindex baud rate for remote targets
22997 Set the baud rate for the remote serial I/O to @var{n} baud. The
22998 value is used to set the speed of the serial port used for debugging
22999 remote targets.
23000
23001 @item show serial baud
23002 Show the current speed of the remote connection.
23003
23004 @item set serial parity @var{parity}
23005 Set the parity for the remote serial I/O. Supported values of @var{parity} are:
23006 @code{even}, @code{none}, and @code{odd}. The default is @code{none}.
23007
23008 @item show serial parity
23009 Show the current parity of the serial port.
23010
23011 @item set remotebreak
23012 @cindex interrupt remote programs
23013 @cindex BREAK signal instead of Ctrl-C
23014 @anchor{set remotebreak}
23015 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
23016 when you type @kbd{Ctrl-c} to interrupt the program running
23017 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
23018 character instead. The default is off, since most remote systems
23019 expect to see @samp{Ctrl-C} as the interrupt signal.
23020
23021 @item show remotebreak
23022 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
23023 interrupt the remote program.
23024
23025 @item set remoteflow on
23026 @itemx set remoteflow off
23027 @kindex set remoteflow
23028 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
23029 on the serial port used to communicate to the remote target.
23030
23031 @item show remoteflow
23032 @kindex show remoteflow
23033 Show the current setting of hardware flow control.
23034
23035 @item set remotelogbase @var{base}
23036 Set the base (a.k.a.@: radix) of logging serial protocol
23037 communications to @var{base}. Supported values of @var{base} are:
23038 @code{ascii}, @code{octal}, and @code{hex}. The default is
23039 @code{ascii}.
23040
23041 @item show remotelogbase
23042 Show the current setting of the radix for logging remote serial
23043 protocol.
23044
23045 @item set remotelogfile @var{file}
23046 @cindex record serial communications on file
23047 Record remote serial communications on the named @var{file}. The
23048 default is not to record at all.
23049
23050 @item show remotelogfile
23051 Show the current setting of the file name on which to record the
23052 serial communications.
23053
23054 @item set remotetimeout @var{num}
23055 @cindex timeout for serial communications
23056 @cindex remote timeout
23057 Set the timeout limit to wait for the remote target to respond to
23058 @var{num} seconds. The default is 2 seconds.
23059
23060 @item show remotetimeout
23061 Show the current number of seconds to wait for the remote target
23062 responses.
23063
23064 @cindex limit hardware breakpoints and watchpoints
23065 @cindex remote target, limit break- and watchpoints
23066 @anchor{set remote hardware-watchpoint-limit}
23067 @anchor{set remote hardware-breakpoint-limit}
23068 @item set remote hardware-watchpoint-limit @var{limit}
23069 @itemx set remote hardware-breakpoint-limit @var{limit}
23070 Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
23071 or breakpoints. The @var{limit} can be set to 0 to disable hardware
23072 watchpoints or breakpoints, and @code{unlimited} for unlimited
23073 watchpoints or breakpoints.
23074
23075 @item show remote hardware-watchpoint-limit
23076 @itemx show remote hardware-breakpoint-limit
23077 Show the current limit for the number of hardware watchpoints or
23078 breakpoints that @value{GDBN} can use.
23079
23080 @cindex limit hardware watchpoints length
23081 @cindex remote target, limit watchpoints length
23082 @anchor{set remote hardware-watchpoint-length-limit}
23083 @item set remote hardware-watchpoint-length-limit @var{limit}
23084 Restrict @value{GDBN} to using @var{limit} bytes for the maximum
23085 length of a remote hardware watchpoint. A @var{limit} of 0 disables
23086 hardware watchpoints and @code{unlimited} allows watchpoints of any
23087 length.
23088
23089 @item show remote hardware-watchpoint-length-limit
23090 Show the current limit (in bytes) of the maximum length of
23091 a remote hardware watchpoint.
23092
23093 @item set remote exec-file @var{filename}
23094 @itemx show remote exec-file
23095 @anchor{set remote exec-file}
23096 @cindex executable file, for remote target
23097 Select the file used for @code{run} with @code{target
23098 extended-remote}. This should be set to a filename valid on the
23099 target system. If it is not set, the target will use a default
23100 filename (e.g.@: the last program run).
23101
23102 @item set remote interrupt-sequence
23103 @cindex interrupt remote programs
23104 @cindex select Ctrl-C, BREAK or BREAK-g
23105 Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
23106 @samp{BREAK-g} as the
23107 sequence to the remote target in order to interrupt the execution.
23108 @samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
23109 is high level of serial line for some certain time.
23110 Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
23111 It is @code{BREAK} signal followed by character @code{g}.
23112
23113 @item show remote interrupt-sequence
23114 Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
23115 is sent by @value{GDBN} to interrupt the remote program.
23116 @code{BREAK-g} is BREAK signal followed by @code{g} and
23117 also known as Magic SysRq g.
23118
23119 @item set remote interrupt-on-connect
23120 @cindex send interrupt-sequence on start
23121 Specify whether interrupt-sequence is sent to remote target when
23122 @value{GDBN} connects to it. This is mostly needed when you debug
23123 Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
23124 which is known as Magic SysRq g in order to connect @value{GDBN}.
23125
23126 @item show remote interrupt-on-connect
23127 Show whether interrupt-sequence is sent
23128 to remote target when @value{GDBN} connects to it.
23129
23130 @kindex set tcp
23131 @kindex show tcp
23132 @item set tcp auto-retry on
23133 @cindex auto-retry, for remote TCP target
23134 Enable auto-retry for remote TCP connections. This is useful if the remote
23135 debugging agent is launched in parallel with @value{GDBN}; there is a race
23136 condition because the agent may not become ready to accept the connection
23137 before @value{GDBN} attempts to connect. When auto-retry is
23138 enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
23139 to establish the connection using the timeout specified by
23140 @code{set tcp connect-timeout}.
23141
23142 @item set tcp auto-retry off
23143 Do not auto-retry failed TCP connections.
23144
23145 @item show tcp auto-retry
23146 Show the current auto-retry setting.
23147
23148 @item set tcp connect-timeout @var{seconds}
23149 @itemx set tcp connect-timeout unlimited
23150 @cindex connection timeout, for remote TCP target
23151 @cindex timeout, for remote target connection
23152 Set the timeout for establishing a TCP connection to the remote target to
23153 @var{seconds}. The timeout affects both polling to retry failed connections
23154 (enabled by @code{set tcp auto-retry on}) and waiting for connections
23155 that are merely slow to complete, and represents an approximate cumulative
23156 value. If @var{seconds} is @code{unlimited}, there is no timeout and
23157 @value{GDBN} will keep attempting to establish a connection forever,
23158 unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
23159
23160 @item show tcp connect-timeout
23161 Show the current connection timeout setting.
23162 @end table
23163
23164 @cindex remote packets, enabling and disabling
23165 The @value{GDBN} remote protocol autodetects the packets supported by
23166 your debugging stub. If you need to override the autodetection, you
23167 can use these commands to enable or disable individual packets. Each
23168 packet can be set to @samp{on} (the remote target supports this
23169 packet), @samp{off} (the remote target does not support this packet),
23170 or @samp{auto} (detect remote target support for this packet). They
23171 all default to @samp{auto}. For more information about each packet,
23172 see @ref{Remote Protocol}.
23173
23174 During normal use, you should not have to use any of these commands.
23175 If you do, that may be a bug in your remote debugging stub, or a bug
23176 in @value{GDBN}. You may want to report the problem to the
23177 @value{GDBN} developers.
23178
23179 For each packet @var{name}, the command to enable or disable the
23180 packet is @code{set remote @var{name}-packet}. The available settings
23181 are:
23182
23183 @multitable @columnfractions 0.28 0.32 0.25
23184 @item Command Name
23185 @tab Remote Packet
23186 @tab Related Features
23187
23188 @item @code{fetch-register}
23189 @tab @code{p}
23190 @tab @code{info registers}
23191
23192 @item @code{set-register}
23193 @tab @code{P}
23194 @tab @code{set}
23195
23196 @item @code{binary-download}
23197 @tab @code{X}
23198 @tab @code{load}, @code{set}
23199
23200 @item @code{read-aux-vector}
23201 @tab @code{qXfer:auxv:read}
23202 @tab @code{info auxv}
23203
23204 @item @code{symbol-lookup}
23205 @tab @code{qSymbol}
23206 @tab Detecting multiple threads
23207
23208 @item @code{attach}
23209 @tab @code{vAttach}
23210 @tab @code{attach}
23211
23212 @item @code{verbose-resume}
23213 @tab @code{vCont}
23214 @tab Stepping or resuming multiple threads
23215
23216 @item @code{run}
23217 @tab @code{vRun}
23218 @tab @code{run}
23219
23220 @item @code{software-breakpoint}
23221 @tab @code{Z0}
23222 @tab @code{break}
23223
23224 @item @code{hardware-breakpoint}
23225 @tab @code{Z1}
23226 @tab @code{hbreak}
23227
23228 @item @code{write-watchpoint}
23229 @tab @code{Z2}
23230 @tab @code{watch}
23231
23232 @item @code{read-watchpoint}
23233 @tab @code{Z3}
23234 @tab @code{rwatch}
23235
23236 @item @code{access-watchpoint}
23237 @tab @code{Z4}
23238 @tab @code{awatch}
23239
23240 @item @code{pid-to-exec-file}
23241 @tab @code{qXfer:exec-file:read}
23242 @tab @code{attach}, @code{run}
23243
23244 @item @code{target-features}
23245 @tab @code{qXfer:features:read}
23246 @tab @code{set architecture}
23247
23248 @item @code{library-info}
23249 @tab @code{qXfer:libraries:read}
23250 @tab @code{info sharedlibrary}
23251
23252 @item @code{memory-map}
23253 @tab @code{qXfer:memory-map:read}
23254 @tab @code{info mem}
23255
23256 @item @code{read-sdata-object}
23257 @tab @code{qXfer:sdata:read}
23258 @tab @code{print $_sdata}
23259
23260 @item @code{read-siginfo-object}
23261 @tab @code{qXfer:siginfo:read}
23262 @tab @code{print $_siginfo}
23263
23264 @item @code{write-siginfo-object}
23265 @tab @code{qXfer:siginfo:write}
23266 @tab @code{set $_siginfo}
23267
23268 @item @code{threads}
23269 @tab @code{qXfer:threads:read}
23270 @tab @code{info threads}
23271
23272 @item @code{get-thread-local-@*storage-address}
23273 @tab @code{qGetTLSAddr}
23274 @tab Displaying @code{__thread} variables
23275
23276 @item @code{get-thread-information-block-address}
23277 @tab @code{qGetTIBAddr}
23278 @tab Display MS-Windows Thread Information Block.
23279
23280 @item @code{search-memory}
23281 @tab @code{qSearch:memory}
23282 @tab @code{find}
23283
23284 @item @code{supported-packets}
23285 @tab @code{qSupported}
23286 @tab Remote communications parameters
23287
23288 @item @code{catch-syscalls}
23289 @tab @code{QCatchSyscalls}
23290 @tab @code{catch syscall}
23291
23292 @item @code{pass-signals}
23293 @tab @code{QPassSignals}
23294 @tab @code{handle @var{signal}}
23295
23296 @item @code{program-signals}
23297 @tab @code{QProgramSignals}
23298 @tab @code{handle @var{signal}}
23299
23300 @item @code{hostio-close-packet}
23301 @tab @code{vFile:close}
23302 @tab @code{remote get}, @code{remote put}
23303
23304 @item @code{hostio-open-packet}
23305 @tab @code{vFile:open}
23306 @tab @code{remote get}, @code{remote put}
23307
23308 @item @code{hostio-pread-packet}
23309 @tab @code{vFile:pread}
23310 @tab @code{remote get}, @code{remote put}
23311
23312 @item @code{hostio-pwrite-packet}
23313 @tab @code{vFile:pwrite}
23314 @tab @code{remote get}, @code{remote put}
23315
23316 @item @code{hostio-unlink-packet}
23317 @tab @code{vFile:unlink}
23318 @tab @code{remote delete}
23319
23320 @item @code{hostio-readlink-packet}
23321 @tab @code{vFile:readlink}
23322 @tab Host I/O
23323
23324 @item @code{hostio-fstat-packet}
23325 @tab @code{vFile:fstat}
23326 @tab Host I/O
23327
23328 @item @code{hostio-setfs-packet}
23329 @tab @code{vFile:setfs}
23330 @tab Host I/O
23331
23332 @item @code{noack-packet}
23333 @tab @code{QStartNoAckMode}
23334 @tab Packet acknowledgment
23335
23336 @item @code{osdata}
23337 @tab @code{qXfer:osdata:read}
23338 @tab @code{info os}
23339
23340 @item @code{query-attached}
23341 @tab @code{qAttached}
23342 @tab Querying remote process attach state.
23343
23344 @item @code{trace-buffer-size}
23345 @tab @code{QTBuffer:size}
23346 @tab @code{set trace-buffer-size}
23347
23348 @item @code{trace-status}
23349 @tab @code{qTStatus}
23350 @tab @code{tstatus}
23351
23352 @item @code{traceframe-info}
23353 @tab @code{qXfer:traceframe-info:read}
23354 @tab Traceframe info
23355
23356 @item @code{install-in-trace}
23357 @tab @code{InstallInTrace}
23358 @tab Install tracepoint in tracing
23359
23360 @item @code{disable-randomization}
23361 @tab @code{QDisableRandomization}
23362 @tab @code{set disable-randomization}
23363
23364 @item @code{startup-with-shell}
23365 @tab @code{QStartupWithShell}
23366 @tab @code{set startup-with-shell}
23367
23368 @item @code{environment-hex-encoded}
23369 @tab @code{QEnvironmentHexEncoded}
23370 @tab @code{set environment}
23371
23372 @item @code{environment-unset}
23373 @tab @code{QEnvironmentUnset}
23374 @tab @code{unset environment}
23375
23376 @item @code{environment-reset}
23377 @tab @code{QEnvironmentReset}
23378 @tab @code{Reset the inferior environment (i.e., unset user-set variables)}
23379
23380 @item @code{set-working-dir}
23381 @tab @code{QSetWorkingDir}
23382 @tab @code{set cwd}
23383
23384 @item @code{conditional-breakpoints-packet}
23385 @tab @code{Z0 and Z1}
23386 @tab @code{Support for target-side breakpoint condition evaluation}
23387
23388 @item @code{multiprocess-extensions}
23389 @tab @code{multiprocess extensions}
23390 @tab Debug multiple processes and remote process PID awareness
23391
23392 @item @code{swbreak-feature}
23393 @tab @code{swbreak stop reason}
23394 @tab @code{break}
23395
23396 @item @code{hwbreak-feature}
23397 @tab @code{hwbreak stop reason}
23398 @tab @code{hbreak}
23399
23400 @item @code{fork-event-feature}
23401 @tab @code{fork stop reason}
23402 @tab @code{fork}
23403
23404 @item @code{vfork-event-feature}
23405 @tab @code{vfork stop reason}
23406 @tab @code{vfork}
23407
23408 @item @code{exec-event-feature}
23409 @tab @code{exec stop reason}
23410 @tab @code{exec}
23411
23412 @item @code{thread-events}
23413 @tab @code{QThreadEvents}
23414 @tab Tracking thread lifetime.
23415
23416 @item @code{no-resumed-stop-reply}
23417 @tab @code{no resumed thread left stop reply}
23418 @tab Tracking thread lifetime.
23419
23420 @end multitable
23421
23422 @node Remote Stub
23423 @section Implementing a Remote Stub
23424
23425 @cindex debugging stub, example
23426 @cindex remote stub, example
23427 @cindex stub example, remote debugging
23428 The stub files provided with @value{GDBN} implement the target side of the
23429 communication protocol, and the @value{GDBN} side is implemented in the
23430 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
23431 these subroutines to communicate, and ignore the details. (If you're
23432 implementing your own stub file, you can still ignore the details: start
23433 with one of the existing stub files. @file{sparc-stub.c} is the best
23434 organized, and therefore the easiest to read.)
23435
23436 @cindex remote serial debugging, overview
23437 To debug a program running on another machine (the debugging
23438 @dfn{target} machine), you must first arrange for all the usual
23439 prerequisites for the program to run by itself. For example, for a C
23440 program, you need:
23441
23442 @enumerate
23443 @item
23444 A startup routine to set up the C runtime environment; these usually
23445 have a name like @file{crt0}. The startup routine may be supplied by
23446 your hardware supplier, or you may have to write your own.
23447
23448 @item
23449 A C subroutine library to support your program's
23450 subroutine calls, notably managing input and output.
23451
23452 @item
23453 A way of getting your program to the other machine---for example, a
23454 download program. These are often supplied by the hardware
23455 manufacturer, but you may have to write your own from hardware
23456 documentation.
23457 @end enumerate
23458
23459 The next step is to arrange for your program to use a serial port to
23460 communicate with the machine where @value{GDBN} is running (the @dfn{host}
23461 machine). In general terms, the scheme looks like this:
23462
23463 @table @emph
23464 @item On the host,
23465 @value{GDBN} already understands how to use this protocol; when everything
23466 else is set up, you can simply use the @samp{target remote} command
23467 (@pxref{Targets,,Specifying a Debugging Target}).
23468
23469 @item On the target,
23470 you must link with your program a few special-purpose subroutines that
23471 implement the @value{GDBN} remote serial protocol. The file containing these
23472 subroutines is called a @dfn{debugging stub}.
23473
23474 On certain remote targets, you can use an auxiliary program
23475 @code{gdbserver} instead of linking a stub into your program.
23476 @xref{Server,,Using the @code{gdbserver} Program}, for details.
23477 @end table
23478
23479 The debugging stub is specific to the architecture of the remote
23480 machine; for example, use @file{sparc-stub.c} to debug programs on
23481 @sc{sparc} boards.
23482
23483 @cindex remote serial stub list
23484 These working remote stubs are distributed with @value{GDBN}:
23485
23486 @table @code
23487
23488 @item i386-stub.c
23489 @cindex @file{i386-stub.c}
23490 @cindex Intel
23491 @cindex i386
23492 For Intel 386 and compatible architectures.
23493
23494 @item m68k-stub.c
23495 @cindex @file{m68k-stub.c}
23496 @cindex Motorola 680x0
23497 @cindex m680x0
23498 For Motorola 680x0 architectures.
23499
23500 @item sh-stub.c
23501 @cindex @file{sh-stub.c}
23502 @cindex Renesas
23503 @cindex SH
23504 For Renesas SH architectures.
23505
23506 @item sparc-stub.c
23507 @cindex @file{sparc-stub.c}
23508 @cindex Sparc
23509 For @sc{sparc} architectures.
23510
23511 @item sparcl-stub.c
23512 @cindex @file{sparcl-stub.c}
23513 @cindex Fujitsu
23514 @cindex SparcLite
23515 For Fujitsu @sc{sparclite} architectures.
23516
23517 @end table
23518
23519 The @file{README} file in the @value{GDBN} distribution may list other
23520 recently added stubs.
23521
23522 @menu
23523 * Stub Contents:: What the stub can do for you
23524 * Bootstrapping:: What you must do for the stub
23525 * Debug Session:: Putting it all together
23526 @end menu
23527
23528 @node Stub Contents
23529 @subsection What the Stub Can Do for You
23530
23531 @cindex remote serial stub
23532 The debugging stub for your architecture supplies these three
23533 subroutines:
23534
23535 @table @code
23536 @item set_debug_traps
23537 @findex set_debug_traps
23538 @cindex remote serial stub, initialization
23539 This routine arranges for @code{handle_exception} to run when your
23540 program stops. You must call this subroutine explicitly in your
23541 program's startup code.
23542
23543 @item handle_exception
23544 @findex handle_exception
23545 @cindex remote serial stub, main routine
23546 This is the central workhorse, but your program never calls it
23547 explicitly---the setup code arranges for @code{handle_exception} to
23548 run when a trap is triggered.
23549
23550 @code{handle_exception} takes control when your program stops during
23551 execution (for example, on a breakpoint), and mediates communications
23552 with @value{GDBN} on the host machine. This is where the communications
23553 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
23554 representative on the target machine. It begins by sending summary
23555 information on the state of your program, then continues to execute,
23556 retrieving and transmitting any information @value{GDBN} needs, until you
23557 execute a @value{GDBN} command that makes your program resume; at that point,
23558 @code{handle_exception} returns control to your own code on the target
23559 machine.
23560
23561 @item breakpoint
23562 @cindex @code{breakpoint} subroutine, remote
23563 Use this auxiliary subroutine to make your program contain a
23564 breakpoint. Depending on the particular situation, this may be the only
23565 way for @value{GDBN} to get control. For instance, if your target
23566 machine has some sort of interrupt button, you won't need to call this;
23567 pressing the interrupt button transfers control to
23568 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
23569 simply receiving characters on the serial port may also trigger a trap;
23570 again, in that situation, you don't need to call @code{breakpoint} from
23571 your own program---simply running @samp{target remote} from the host
23572 @value{GDBN} session gets control.
23573
23574 Call @code{breakpoint} if none of these is true, or if you simply want
23575 to make certain your program stops at a predetermined point for the
23576 start of your debugging session.
23577 @end table
23578
23579 @node Bootstrapping
23580 @subsection What You Must Do for the Stub
23581
23582 @cindex remote stub, support routines
23583 The debugging stubs that come with @value{GDBN} are set up for a particular
23584 chip architecture, but they have no information about the rest of your
23585 debugging target machine.
23586
23587 First of all you need to tell the stub how to communicate with the
23588 serial port.
23589
23590 @table @code
23591 @item int getDebugChar()
23592 @findex getDebugChar
23593 Write this subroutine to read a single character from the serial port.
23594 It may be identical to @code{getchar} for your target system; a
23595 different name is used to allow you to distinguish the two if you wish.
23596
23597 @item void putDebugChar(int)
23598 @findex putDebugChar
23599 Write this subroutine to write a single character to the serial port.
23600 It may be identical to @code{putchar} for your target system; a
23601 different name is used to allow you to distinguish the two if you wish.
23602 @end table
23603
23604 @cindex control C, and remote debugging
23605 @cindex interrupting remote targets
23606 If you want @value{GDBN} to be able to stop your program while it is
23607 running, you need to use an interrupt-driven serial driver, and arrange
23608 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
23609 character). That is the character which @value{GDBN} uses to tell the
23610 remote system to stop.
23611
23612 Getting the debugging target to return the proper status to @value{GDBN}
23613 probably requires changes to the standard stub; one quick and dirty way
23614 is to just execute a breakpoint instruction (the ``dirty'' part is that
23615 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
23616
23617 Other routines you need to supply are:
23618
23619 @table @code
23620 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
23621 @findex exceptionHandler
23622 Write this function to install @var{exception_address} in the exception
23623 handling tables. You need to do this because the stub does not have any
23624 way of knowing what the exception handling tables on your target system
23625 are like (for example, the processor's table might be in @sc{rom},
23626 containing entries which point to a table in @sc{ram}).
23627 The @var{exception_number} specifies the exception which should be changed;
23628 its meaning is architecture-dependent (for example, different numbers
23629 might represent divide by zero, misaligned access, etc). When this
23630 exception occurs, control should be transferred directly to
23631 @var{exception_address}, and the processor state (stack, registers,
23632 and so on) should be just as it is when a processor exception occurs. So if
23633 you want to use a jump instruction to reach @var{exception_address}, it
23634 should be a simple jump, not a jump to subroutine.
23635
23636 For the 386, @var{exception_address} should be installed as an interrupt
23637 gate so that interrupts are masked while the handler runs. The gate
23638 should be at privilege level 0 (the most privileged level). The
23639 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
23640 help from @code{exceptionHandler}.
23641
23642 @item void flush_i_cache()
23643 @findex flush_i_cache
23644 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
23645 instruction cache, if any, on your target machine. If there is no
23646 instruction cache, this subroutine may be a no-op.
23647
23648 On target machines that have instruction caches, @value{GDBN} requires this
23649 function to make certain that the state of your program is stable.
23650 @end table
23651
23652 @noindent
23653 You must also make sure this library routine is available:
23654
23655 @table @code
23656 @item void *memset(void *, int, int)
23657 @findex memset
23658 This is the standard library function @code{memset} that sets an area of
23659 memory to a known value. If you have one of the free versions of
23660 @code{libc.a}, @code{memset} can be found there; otherwise, you must
23661 either obtain it from your hardware manufacturer, or write your own.
23662 @end table
23663
23664 If you do not use the GNU C compiler, you may need other standard
23665 library subroutines as well; this varies from one stub to another,
23666 but in general the stubs are likely to use any of the common library
23667 subroutines which @code{@value{NGCC}} generates as inline code.
23668
23669
23670 @node Debug Session
23671 @subsection Putting it All Together
23672
23673 @cindex remote serial debugging summary
23674 In summary, when your program is ready to debug, you must follow these
23675 steps.
23676
23677 @enumerate
23678 @item
23679 Make sure you have defined the supporting low-level routines
23680 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
23681 @display
23682 @code{getDebugChar}, @code{putDebugChar},
23683 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
23684 @end display
23685
23686 @item
23687 Insert these lines in your program's startup code, before the main
23688 procedure is called:
23689
23690 @smallexample
23691 set_debug_traps();
23692 breakpoint();
23693 @end smallexample
23694
23695 On some machines, when a breakpoint trap is raised, the hardware
23696 automatically makes the PC point to the instruction after the
23697 breakpoint. If your machine doesn't do that, you may need to adjust
23698 @code{handle_exception} to arrange for it to return to the instruction
23699 after the breakpoint on this first invocation, so that your program
23700 doesn't keep hitting the initial breakpoint instead of making
23701 progress.
23702
23703 @item
23704 For the 680x0 stub only, you need to provide a variable called
23705 @code{exceptionHook}. Normally you just use:
23706
23707 @smallexample
23708 void (*exceptionHook)() = 0;
23709 @end smallexample
23710
23711 @noindent
23712 but if before calling @code{set_debug_traps}, you set it to point to a
23713 function in your program, that function is called when
23714 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
23715 error). The function indicated by @code{exceptionHook} is called with
23716 one parameter: an @code{int} which is the exception number.
23717
23718 @item
23719 Compile and link together: your program, the @value{GDBN} debugging stub for
23720 your target architecture, and the supporting subroutines.
23721
23722 @item
23723 Make sure you have a serial connection between your target machine and
23724 the @value{GDBN} host, and identify the serial port on the host.
23725
23726 @item
23727 @c The "remote" target now provides a `load' command, so we should
23728 @c document that. FIXME.
23729 Download your program to your target machine (or get it there by
23730 whatever means the manufacturer provides), and start it.
23731
23732 @item
23733 Start @value{GDBN} on the host, and connect to the target
23734 (@pxref{Connecting,,Connecting to a Remote Target}).
23735
23736 @end enumerate
23737
23738 @node Configurations
23739 @chapter Configuration-Specific Information
23740
23741 While nearly all @value{GDBN} commands are available for all native and
23742 cross versions of the debugger, there are some exceptions. This chapter
23743 describes things that are only available in certain configurations.
23744
23745 There are three major categories of configurations: native
23746 configurations, where the host and target are the same, embedded
23747 operating system configurations, which are usually the same for several
23748 different processor architectures, and bare embedded processors, which
23749 are quite different from each other.
23750
23751 @menu
23752 * Native::
23753 * Embedded OS::
23754 * Embedded Processors::
23755 * Architectures::
23756 @end menu
23757
23758 @node Native
23759 @section Native
23760
23761 This section describes details specific to particular native
23762 configurations.
23763
23764 @menu
23765 * BSD libkvm Interface:: Debugging BSD kernel memory images
23766 * Process Information:: Process information
23767 * DJGPP Native:: Features specific to the DJGPP port
23768 * Cygwin Native:: Features specific to the Cygwin port
23769 * Hurd Native:: Features specific to @sc{gnu} Hurd
23770 * Darwin:: Features specific to Darwin
23771 * FreeBSD:: Features specific to FreeBSD
23772 @end menu
23773
23774 @node BSD libkvm Interface
23775 @subsection BSD libkvm Interface
23776
23777 @cindex libkvm
23778 @cindex kernel memory image
23779 @cindex kernel crash dump
23780
23781 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
23782 interface that provides a uniform interface for accessing kernel virtual
23783 memory images, including live systems and crash dumps. @value{GDBN}
23784 uses this interface to allow you to debug live kernels and kernel crash
23785 dumps on many native BSD configurations. This is implemented as a
23786 special @code{kvm} debugging target. For debugging a live system, load
23787 the currently running kernel into @value{GDBN} and connect to the
23788 @code{kvm} target:
23789
23790 @smallexample
23791 (@value{GDBP}) @b{target kvm}
23792 @end smallexample
23793
23794 For debugging crash dumps, provide the file name of the crash dump as an
23795 argument:
23796
23797 @smallexample
23798 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
23799 @end smallexample
23800
23801 Once connected to the @code{kvm} target, the following commands are
23802 available:
23803
23804 @table @code
23805 @kindex kvm
23806 @item kvm pcb
23807 Set current context from the @dfn{Process Control Block} (PCB) address.
23808
23809 @item kvm proc
23810 Set current context from proc address. This command isn't available on
23811 modern FreeBSD systems.
23812 @end table
23813
23814 @node Process Information
23815 @subsection Process Information
23816 @cindex /proc
23817 @cindex examine process image
23818 @cindex process info via @file{/proc}
23819
23820 Some operating systems provide interfaces to fetch additional
23821 information about running processes beyond memory and per-thread
23822 register state. If @value{GDBN} is configured for an operating system
23823 with a supported interface, the command @code{info proc} is available
23824 to report information about the process running your program, or about
23825 any process running on your system.
23826
23827 One supported interface is a facility called @samp{/proc} that can be
23828 used to examine the image of a running process using file-system
23829 subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
23830 systems.
23831
23832 On FreeBSD and NetBSD systems, system control nodes are used to query
23833 process information.
23834
23835 In addition, some systems may provide additional process information
23836 in core files. Note that a core file may include a subset of the
23837 information available from a live process. Process information is
23838 currently available from cores created on @sc{gnu}/Linux and FreeBSD
23839 systems.
23840
23841 @table @code
23842 @kindex info proc
23843 @cindex process ID
23844 @item info proc
23845 @itemx info proc @var{process-id}
23846 Summarize available information about a process. If a
23847 process ID is specified by @var{process-id}, display information about
23848 that process; otherwise display information about the program being
23849 debugged. The summary includes the debugged process ID, the command
23850 line used to invoke it, its current working directory, and its
23851 executable file's absolute file name.
23852
23853 On some systems, @var{process-id} can be of the form
23854 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
23855 within a process. If the optional @var{pid} part is missing, it means
23856 a thread from the process being debugged (the leading @samp{/} still
23857 needs to be present, or else @value{GDBN} will interpret the number as
23858 a process ID rather than a thread ID).
23859
23860 @item info proc cmdline
23861 @cindex info proc cmdline
23862 Show the original command line of the process. This command is
23863 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
23864
23865 @item info proc cwd
23866 @cindex info proc cwd
23867 Show the current working directory of the process. This command is
23868 supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
23869
23870 @item info proc exe
23871 @cindex info proc exe
23872 Show the name of executable of the process. This command is supported
23873 on @sc{gnu}/Linux, FreeBSD and NetBSD.
23874
23875 @item info proc files
23876 @cindex info proc files
23877 Show the file descriptors open by the process. For each open file
23878 descriptor, @value{GDBN} shows its number, type (file, directory,
23879 character device, socket), file pointer offset, and the name of the
23880 resource open on the descriptor. The resource name can be a file name
23881 (for files, directories, and devices) or a protocol followed by socket
23882 address (for network connections). This command is supported on
23883 FreeBSD.
23884
23885 This example shows the open file descriptors for a process using a
23886 tty for standard input and output as well as two network sockets:
23887
23888 @smallexample
23889 (gdb) info proc files 22136
23890 process 22136
23891 Open files:
23892
23893 FD Type Offset Flags Name
23894 text file - r-------- /usr/bin/ssh
23895 ctty chr - rw------- /dev/pts/20
23896 cwd dir - r-------- /usr/home/john
23897 root dir - r-------- /
23898 0 chr 0x32933a4 rw------- /dev/pts/20
23899 1 chr 0x32933a4 rw------- /dev/pts/20
23900 2 chr 0x32933a4 rw------- /dev/pts/20
23901 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
23902 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
23903 @end smallexample
23904
23905 @item info proc mappings
23906 @cindex memory address space mappings
23907 Report the memory address space ranges accessible in a process. On
23908 Solaris, FreeBSD and NetBSD systems, each memory range includes information
23909 on whether the process has read, write, or execute access rights to each
23910 range. On @sc{gnu}/Linux, FreeBSD and NetBSD systems, each memory range
23911 includes the object file which is mapped to that range.
23912
23913 @item info proc stat
23914 @itemx info proc status
23915 @cindex process detailed status information
23916 Show additional process-related information, including the user ID and
23917 group ID; virtual memory usage; the signals that are pending, blocked,
23918 and ignored; its TTY; its consumption of system and user time; its
23919 stack size; its @samp{nice} value; etc. These commands are supported
23920 on @sc{gnu}/Linux, FreeBSD and NetBSD.
23921
23922 For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
23923 information (type @kbd{man 5 proc} from your shell prompt).
23924
23925 For FreeBSD and NetBSD systems, @code{info proc stat} is an alias for
23926 @code{info proc status}.
23927
23928 @item info proc all
23929 Show all the information about the process described under all of the
23930 above @code{info proc} subcommands.
23931
23932 @ignore
23933 @comment These sub-options of 'info proc' were not included when
23934 @comment procfs.c was re-written. Keep their descriptions around
23935 @comment against the day when someone finds the time to put them back in.
23936 @kindex info proc times
23937 @item info proc times
23938 Starting time, user CPU time, and system CPU time for your program and
23939 its children.
23940
23941 @kindex info proc id
23942 @item info proc id
23943 Report on the process IDs related to your program: its own process ID,
23944 the ID of its parent, the process group ID, and the session ID.
23945 @end ignore
23946
23947 @item set procfs-trace
23948 @kindex set procfs-trace
23949 @cindex @code{procfs} API calls
23950 This command enables and disables tracing of @code{procfs} API calls.
23951
23952 @item show procfs-trace
23953 @kindex show procfs-trace
23954 Show the current state of @code{procfs} API call tracing.
23955
23956 @item set procfs-file @var{file}
23957 @kindex set procfs-file
23958 Tell @value{GDBN} to write @code{procfs} API trace to the named
23959 @var{file}. @value{GDBN} appends the trace info to the previous
23960 contents of the file. The default is to display the trace on the
23961 standard output.
23962
23963 @item show procfs-file
23964 @kindex show procfs-file
23965 Show the file to which @code{procfs} API trace is written.
23966
23967 @item proc-trace-entry
23968 @itemx proc-trace-exit
23969 @itemx proc-untrace-entry
23970 @itemx proc-untrace-exit
23971 @kindex proc-trace-entry
23972 @kindex proc-trace-exit
23973 @kindex proc-untrace-entry
23974 @kindex proc-untrace-exit
23975 These commands enable and disable tracing of entries into and exits
23976 from the @code{syscall} interface.
23977
23978 @item info pidlist
23979 @kindex info pidlist
23980 @cindex process list, QNX Neutrino
23981 For QNX Neutrino only, this command displays the list of all the
23982 processes and all the threads within each process.
23983
23984 @item info meminfo
23985 @kindex info meminfo
23986 @cindex mapinfo list, QNX Neutrino
23987 For QNX Neutrino only, this command displays the list of all mapinfos.
23988 @end table
23989
23990 @node DJGPP Native
23991 @subsection Features for Debugging @sc{djgpp} Programs
23992 @cindex @sc{djgpp} debugging
23993 @cindex native @sc{djgpp} debugging
23994 @cindex MS-DOS-specific commands
23995
23996 @cindex DPMI
23997 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
23998 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
23999 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
24000 top of real-mode DOS systems and their emulations.
24001
24002 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
24003 defines a few commands specific to the @sc{djgpp} port. This
24004 subsection describes those commands.
24005
24006 @table @code
24007 @kindex info dos
24008 @item info dos
24009 This is a prefix of @sc{djgpp}-specific commands which print
24010 information about the target system and important OS structures.
24011
24012 @kindex sysinfo
24013 @cindex MS-DOS system info
24014 @cindex free memory information (MS-DOS)
24015 @item info dos sysinfo
24016 This command displays assorted information about the underlying
24017 platform: the CPU type and features, the OS version and flavor, the
24018 DPMI version, and the available conventional and DPMI memory.
24019
24020 @cindex GDT
24021 @cindex LDT
24022 @cindex IDT
24023 @cindex segment descriptor tables
24024 @cindex descriptor tables display
24025 @item info dos gdt
24026 @itemx info dos ldt
24027 @itemx info dos idt
24028 These 3 commands display entries from, respectively, Global, Local,
24029 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
24030 tables are data structures which store a descriptor for each segment
24031 that is currently in use. The segment's selector is an index into a
24032 descriptor table; the table entry for that index holds the
24033 descriptor's base address and limit, and its attributes and access
24034 rights.
24035
24036 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
24037 segment (used for both data and the stack), and a DOS segment (which
24038 allows access to DOS/BIOS data structures and absolute addresses in
24039 conventional memory). However, the DPMI host will usually define
24040 additional segments in order to support the DPMI environment.
24041
24042 @cindex garbled pointers
24043 These commands allow to display entries from the descriptor tables.
24044 Without an argument, all entries from the specified table are
24045 displayed. An argument, which should be an integer expression, means
24046 display a single entry whose index is given by the argument. For
24047 example, here's a convenient way to display information about the
24048 debugged program's data segment:
24049
24050 @smallexample
24051 @exdent @code{(@value{GDBP}) info dos ldt $ds}
24052 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
24053 @end smallexample
24054
24055 @noindent
24056 This comes in handy when you want to see whether a pointer is outside
24057 the data segment's limit (i.e.@: @dfn{garbled}).
24058
24059 @cindex page tables display (MS-DOS)
24060 @item info dos pde
24061 @itemx info dos pte
24062 These two commands display entries from, respectively, the Page
24063 Directory and the Page Tables. Page Directories and Page Tables are
24064 data structures which control how virtual memory addresses are mapped
24065 into physical addresses. A Page Table includes an entry for every
24066 page of memory that is mapped into the program's address space; there
24067 may be several Page Tables, each one holding up to 4096 entries. A
24068 Page Directory has up to 4096 entries, one each for every Page Table
24069 that is currently in use.
24070
24071 Without an argument, @kbd{info dos pde} displays the entire Page
24072 Directory, and @kbd{info dos pte} displays all the entries in all of
24073 the Page Tables. An argument, an integer expression, given to the
24074 @kbd{info dos pde} command means display only that entry from the Page
24075 Directory table. An argument given to the @kbd{info dos pte} command
24076 means display entries from a single Page Table, the one pointed to by
24077 the specified entry in the Page Directory.
24078
24079 @cindex direct memory access (DMA) on MS-DOS
24080 These commands are useful when your program uses @dfn{DMA} (Direct
24081 Memory Access), which needs physical addresses to program the DMA
24082 controller.
24083
24084 These commands are supported only with some DPMI servers.
24085
24086 @cindex physical address from linear address
24087 @item info dos address-pte @var{addr}
24088 This command displays the Page Table entry for a specified linear
24089 address. The argument @var{addr} is a linear address which should
24090 already have the appropriate segment's base address added to it,
24091 because this command accepts addresses which may belong to @emph{any}
24092 segment. For example, here's how to display the Page Table entry for
24093 the page where a variable @code{i} is stored:
24094
24095 @smallexample
24096 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
24097 @exdent @code{Page Table entry for address 0x11a00d30:}
24098 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
24099 @end smallexample
24100
24101 @noindent
24102 This says that @code{i} is stored at offset @code{0xd30} from the page
24103 whose physical base address is @code{0x02698000}, and shows all the
24104 attributes of that page.
24105
24106 Note that you must cast the addresses of variables to a @code{char *},
24107 since otherwise the value of @code{__djgpp_base_address}, the base
24108 address of all variables and functions in a @sc{djgpp} program, will
24109 be added using the rules of C pointer arithmetics: if @code{i} is
24110 declared an @code{int}, @value{GDBN} will add 4 times the value of
24111 @code{__djgpp_base_address} to the address of @code{i}.
24112
24113 Here's another example, it displays the Page Table entry for the
24114 transfer buffer:
24115
24116 @smallexample
24117 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
24118 @exdent @code{Page Table entry for address 0x29110:}
24119 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
24120 @end smallexample
24121
24122 @noindent
24123 (The @code{+ 3} offset is because the transfer buffer's address is the
24124 3rd member of the @code{_go32_info_block} structure.) The output
24125 clearly shows that this DPMI server maps the addresses in conventional
24126 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
24127 linear (@code{0x29110}) addresses are identical.
24128
24129 This command is supported only with some DPMI servers.
24130 @end table
24131
24132 @cindex DOS serial data link, remote debugging
24133 In addition to native debugging, the DJGPP port supports remote
24134 debugging via a serial data link. The following commands are specific
24135 to remote serial debugging in the DJGPP port of @value{GDBN}.
24136
24137 @table @code
24138 @kindex set com1base
24139 @kindex set com1irq
24140 @kindex set com2base
24141 @kindex set com2irq
24142 @kindex set com3base
24143 @kindex set com3irq
24144 @kindex set com4base
24145 @kindex set com4irq
24146 @item set com1base @var{addr}
24147 This command sets the base I/O port address of the @file{COM1} serial
24148 port.
24149
24150 @item set com1irq @var{irq}
24151 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
24152 for the @file{COM1} serial port.
24153
24154 There are similar commands @samp{set com2base}, @samp{set com3irq},
24155 etc.@: for setting the port address and the @code{IRQ} lines for the
24156 other 3 COM ports.
24157
24158 @kindex show com1base
24159 @kindex show com1irq
24160 @kindex show com2base
24161 @kindex show com2irq
24162 @kindex show com3base
24163 @kindex show com3irq
24164 @kindex show com4base
24165 @kindex show com4irq
24166 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
24167 display the current settings of the base address and the @code{IRQ}
24168 lines used by the COM ports.
24169
24170 @item info serial
24171 @kindex info serial
24172 @cindex DOS serial port status
24173 This command prints the status of the 4 DOS serial ports. For each
24174 port, it prints whether it's active or not, its I/O base address and
24175 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
24176 counts of various errors encountered so far.
24177 @end table
24178
24179
24180 @node Cygwin Native
24181 @subsection Features for Debugging MS Windows PE Executables
24182 @cindex MS Windows debugging
24183 @cindex native Cygwin debugging
24184 @cindex Cygwin-specific commands
24185
24186 @value{GDBN} supports native debugging of MS Windows programs, including
24187 DLLs with and without symbolic debugging information.
24188
24189 @cindex Ctrl-BREAK, MS-Windows
24190 @cindex interrupt debuggee on MS-Windows
24191 MS-Windows programs that call @code{SetConsoleMode} to switch off the
24192 special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
24193 by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
24194 supports @kbd{C-@key{BREAK}} as an alternative interrupt key
24195 sequence, which can be used to interrupt the debuggee even if it
24196 ignores @kbd{C-c}.
24197
24198 There are various additional Cygwin-specific commands, described in
24199 this section. Working with DLLs that have no debugging symbols is
24200 described in @ref{Non-debug DLL Symbols}.
24201
24202 @table @code
24203 @kindex info w32
24204 @item info w32
24205 This is a prefix of MS Windows-specific commands which print
24206 information about the target system and important OS structures.
24207
24208 @item info w32 selector
24209 This command displays information returned by
24210 the Win32 API @code{GetThreadSelectorEntry} function.
24211 It takes an optional argument that is evaluated to
24212 a long value to give the information about this given selector.
24213 Without argument, this command displays information
24214 about the six segment registers.
24215
24216 @item info w32 thread-information-block
24217 This command displays thread specific information stored in the
24218 Thread Information Block (readable on the X86 CPU family using @code{$fs}
24219 selector for 32-bit programs and @code{$gs} for 64-bit programs).
24220
24221 @kindex signal-event
24222 @item signal-event @var{id}
24223 This command signals an event with user-provided @var{id}. Used to resume
24224 crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
24225
24226 To use it, create or edit the following keys in
24227 @code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
24228 @code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
24229 (for x86_64 versions):
24230
24231 @itemize @minus
24232 @item
24233 @code{Debugger} (REG_SZ) --- a command to launch the debugger.
24234 Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
24235 "attach %ld" -ex "signal-event %ld" -ex "continue"}.
24236
24237 The first @code{%ld} will be replaced by the process ID of the
24238 crashing process, the second @code{%ld} will be replaced by the ID of
24239 the event that blocks the crashing process, waiting for @value{GDBN}
24240 to attach.
24241
24242 @item
24243 @code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
24244 make the system run debugger specified by the Debugger key
24245 automatically, @code{0} will cause a dialog box with ``OK'' and
24246 ``Cancel'' buttons to appear, which allows the user to either
24247 terminate the crashing process (OK) or debug it (Cancel).
24248 @end itemize
24249
24250 @kindex set cygwin-exceptions
24251 @cindex debugging the Cygwin DLL
24252 @cindex Cygwin DLL, debugging
24253 @item set cygwin-exceptions @var{mode}
24254 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
24255 happen inside the Cygwin DLL. If @var{mode} is @code{off},
24256 @value{GDBN} will delay recognition of exceptions, and may ignore some
24257 exceptions which seem to be caused by internal Cygwin DLL
24258 ``bookkeeping''. This option is meant primarily for debugging the
24259 Cygwin DLL itself; the default value is @code{off} to avoid annoying
24260 @value{GDBN} users with false @code{SIGSEGV} signals.
24261
24262 @kindex show cygwin-exceptions
24263 @item show cygwin-exceptions
24264 Displays whether @value{GDBN} will break on exceptions that happen
24265 inside the Cygwin DLL itself.
24266
24267 @kindex set new-console
24268 @item set new-console @var{mode}
24269 If @var{mode} is @code{on} the debuggee will
24270 be started in a new console on next start.
24271 If @var{mode} is @code{off}, the debuggee will
24272 be started in the same console as the debugger.
24273
24274 @kindex show new-console
24275 @item show new-console
24276 Displays whether a new console is used
24277 when the debuggee is started.
24278
24279 @kindex set new-group
24280 @item set new-group @var{mode}
24281 This boolean value controls whether the debuggee should
24282 start a new group or stay in the same group as the debugger.
24283 This affects the way the Windows OS handles
24284 @samp{Ctrl-C}.
24285
24286 @kindex show new-group
24287 @item show new-group
24288 Displays current value of new-group boolean.
24289
24290 @kindex set debugevents
24291 @item set debugevents
24292 This boolean value adds debug output concerning kernel events related
24293 to the debuggee seen by the debugger. This includes events that
24294 signal thread and process creation and exit, DLL loading and
24295 unloading, console interrupts, and debugging messages produced by the
24296 Windows @code{OutputDebugString} API call.
24297
24298 @kindex set debugexec
24299 @item set debugexec
24300 This boolean value adds debug output concerning execute events
24301 (such as resume thread) seen by the debugger.
24302
24303 @kindex set debugexceptions
24304 @item set debugexceptions
24305 This boolean value adds debug output concerning exceptions in the
24306 debuggee seen by the debugger.
24307
24308 @kindex set debugmemory
24309 @item set debugmemory
24310 This boolean value adds debug output concerning debuggee memory reads
24311 and writes by the debugger.
24312
24313 @kindex set shell
24314 @item set shell
24315 This boolean values specifies whether the debuggee is called
24316 via a shell or directly (default value is on).
24317
24318 @kindex show shell
24319 @item show shell
24320 Displays if the debuggee will be started with a shell.
24321
24322 @end table
24323
24324 @menu
24325 * Non-debug DLL Symbols:: Support for DLLs without debugging symbols
24326 @end menu
24327
24328 @node Non-debug DLL Symbols
24329 @subsubsection Support for DLLs without Debugging Symbols
24330 @cindex DLLs with no debugging symbols
24331 @cindex Minimal symbols and DLLs
24332
24333 Very often on windows, some of the DLLs that your program relies on do
24334 not include symbolic debugging information (for example,
24335 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
24336 symbols in a DLL, it relies on the minimal amount of symbolic
24337 information contained in the DLL's export table. This section
24338 describes working with such symbols, known internally to @value{GDBN} as
24339 ``minimal symbols''.
24340
24341 Note that before the debugged program has started execution, no DLLs
24342 will have been loaded. The easiest way around this problem is simply to
24343 start the program --- either by setting a breakpoint or letting the
24344 program run once to completion.
24345
24346 @subsubsection DLL Name Prefixes
24347
24348 In keeping with the naming conventions used by the Microsoft debugging
24349 tools, DLL export symbols are made available with a prefix based on the
24350 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
24351 also entered into the symbol table, so @code{CreateFileA} is often
24352 sufficient. In some cases there will be name clashes within a program
24353 (particularly if the executable itself includes full debugging symbols)
24354 necessitating the use of the fully qualified name when referring to the
24355 contents of the DLL. Use single-quotes around the name to avoid the
24356 exclamation mark (``!'') being interpreted as a language operator.
24357
24358 Note that the internal name of the DLL may be all upper-case, even
24359 though the file name of the DLL is lower-case, or vice-versa. Since
24360 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
24361 some confusion. If in doubt, try the @code{info functions} and
24362 @code{info variables} commands or even @code{maint print msymbols}
24363 (@pxref{Symbols}). Here's an example:
24364
24365 @smallexample
24366 (@value{GDBP}) info function CreateFileA
24367 All functions matching regular expression "CreateFileA":
24368
24369 Non-debugging symbols:
24370 0x77e885f4 CreateFileA
24371 0x77e885f4 KERNEL32!CreateFileA
24372 @end smallexample
24373
24374 @smallexample
24375 (@value{GDBP}) info function !
24376 All functions matching regular expression "!":
24377
24378 Non-debugging symbols:
24379 0x6100114c cygwin1!__assert
24380 0x61004034 cygwin1!_dll_crt0@@0
24381 0x61004240 cygwin1!dll_crt0(per_process *)
24382 [etc...]
24383 @end smallexample
24384
24385 @subsubsection Working with Minimal Symbols
24386
24387 Symbols extracted from a DLL's export table do not contain very much
24388 type information. All that @value{GDBN} can do is guess whether a symbol
24389 refers to a function or variable depending on the linker section that
24390 contains the symbol. Also note that the actual contents of the memory
24391 contained in a DLL are not available unless the program is running. This
24392 means that you cannot examine the contents of a variable or disassemble
24393 a function within a DLL without a running program.
24394
24395 Variables are generally treated as pointers and dereferenced
24396 automatically. For this reason, it is often necessary to prefix a
24397 variable name with the address-of operator (``&'') and provide explicit
24398 type information in the command. Here's an example of the type of
24399 problem:
24400
24401 @smallexample
24402 (@value{GDBP}) print 'cygwin1!__argv'
24403 'cygwin1!__argv' has unknown type; cast it to its declared type
24404 @end smallexample
24405
24406 @smallexample
24407 (@value{GDBP}) x 'cygwin1!__argv'
24408 'cygwin1!__argv' has unknown type; cast it to its declared type
24409 @end smallexample
24410
24411 And two possible solutions:
24412
24413 @smallexample
24414 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
24415 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
24416 @end smallexample
24417
24418 @smallexample
24419 (@value{GDBP}) x/2x &'cygwin1!__argv'
24420 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
24421 (@value{GDBP}) x/x 0x10021608
24422 0x10021608: 0x0022fd98
24423 (@value{GDBP}) x/s 0x0022fd98
24424 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
24425 @end smallexample
24426
24427 Setting a break point within a DLL is possible even before the program
24428 starts execution. However, under these circumstances, @value{GDBN} can't
24429 examine the initial instructions of the function in order to skip the
24430 function's frame set-up code. You can work around this by using ``*&''
24431 to set the breakpoint at a raw memory address:
24432
24433 @smallexample
24434 (@value{GDBP}) break *&'python22!PyOS_Readline'
24435 Breakpoint 1 at 0x1e04eff0
24436 @end smallexample
24437
24438 The author of these extensions is not entirely convinced that setting a
24439 break point within a shared DLL like @file{kernel32.dll} is completely
24440 safe.
24441
24442 @node Hurd Native
24443 @subsection Commands Specific to @sc{gnu} Hurd Systems
24444 @cindex @sc{gnu} Hurd debugging
24445
24446 This subsection describes @value{GDBN} commands specific to the
24447 @sc{gnu} Hurd native debugging.
24448
24449 @table @code
24450 @item set signals
24451 @itemx set sigs
24452 @kindex set signals@r{, Hurd command}
24453 @kindex set sigs@r{, Hurd command}
24454 This command toggles the state of inferior signal interception by
24455 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
24456 affected by this command. @code{sigs} is a shorthand alias for
24457 @code{signals}.
24458
24459 @item show signals
24460 @itemx show sigs
24461 @kindex show signals@r{, Hurd command}
24462 @kindex show sigs@r{, Hurd command}
24463 Show the current state of intercepting inferior's signals.
24464
24465 @item set signal-thread
24466 @itemx set sigthread
24467 @kindex set signal-thread
24468 @kindex set sigthread
24469 This command tells @value{GDBN} which thread is the @code{libc} signal
24470 thread. That thread is run when a signal is delivered to a running
24471 process. @code{set sigthread} is the shorthand alias of @code{set
24472 signal-thread}.
24473
24474 @item show signal-thread
24475 @itemx show sigthread
24476 @kindex show signal-thread
24477 @kindex show sigthread
24478 These two commands show which thread will run when the inferior is
24479 delivered a signal.
24480
24481 @item set stopped
24482 @kindex set stopped@r{, Hurd command}
24483 This commands tells @value{GDBN} that the inferior process is stopped,
24484 as with the @code{SIGSTOP} signal. The stopped process can be
24485 continued by delivering a signal to it.
24486
24487 @item show stopped
24488 @kindex show stopped@r{, Hurd command}
24489 This command shows whether @value{GDBN} thinks the debuggee is
24490 stopped.
24491
24492 @item set exceptions
24493 @kindex set exceptions@r{, Hurd command}
24494 Use this command to turn off trapping of exceptions in the inferior.
24495 When exception trapping is off, neither breakpoints nor
24496 single-stepping will work. To restore the default, set exception
24497 trapping on.
24498
24499 @item show exceptions
24500 @kindex show exceptions@r{, Hurd command}
24501 Show the current state of trapping exceptions in the inferior.
24502
24503 @item set task pause
24504 @kindex set task@r{, Hurd commands}
24505 @cindex task attributes (@sc{gnu} Hurd)
24506 @cindex pause current task (@sc{gnu} Hurd)
24507 This command toggles task suspension when @value{GDBN} has control.
24508 Setting it to on takes effect immediately, and the task is suspended
24509 whenever @value{GDBN} gets control. Setting it to off will take
24510 effect the next time the inferior is continued. If this option is set
24511 to off, you can use @code{set thread default pause on} or @code{set
24512 thread pause on} (see below) to pause individual threads.
24513
24514 @item show task pause
24515 @kindex show task@r{, Hurd commands}
24516 Show the current state of task suspension.
24517
24518 @item set task detach-suspend-count
24519 @cindex task suspend count
24520 @cindex detach from task, @sc{gnu} Hurd
24521 This command sets the suspend count the task will be left with when
24522 @value{GDBN} detaches from it.
24523
24524 @item show task detach-suspend-count
24525 Show the suspend count the task will be left with when detaching.
24526
24527 @item set task exception-port
24528 @itemx set task excp
24529 @cindex task exception port, @sc{gnu} Hurd
24530 This command sets the task exception port to which @value{GDBN} will
24531 forward exceptions. The argument should be the value of the @dfn{send
24532 rights} of the task. @code{set task excp} is a shorthand alias.
24533
24534 @item set noninvasive
24535 @cindex noninvasive task options
24536 This command switches @value{GDBN} to a mode that is the least
24537 invasive as far as interfering with the inferior is concerned. This
24538 is the same as using @code{set task pause}, @code{set exceptions}, and
24539 @code{set signals} to values opposite to the defaults.
24540
24541 @item info send-rights
24542 @itemx info receive-rights
24543 @itemx info port-rights
24544 @itemx info port-sets
24545 @itemx info dead-names
24546 @itemx info ports
24547 @itemx info psets
24548 @cindex send rights, @sc{gnu} Hurd
24549 @cindex receive rights, @sc{gnu} Hurd
24550 @cindex port rights, @sc{gnu} Hurd
24551 @cindex port sets, @sc{gnu} Hurd
24552 @cindex dead names, @sc{gnu} Hurd
24553 These commands display information about, respectively, send rights,
24554 receive rights, port rights, port sets, and dead names of a task.
24555 There are also shorthand aliases: @code{info ports} for @code{info
24556 port-rights} and @code{info psets} for @code{info port-sets}.
24557
24558 @item set thread pause
24559 @kindex set thread@r{, Hurd command}
24560 @cindex thread properties, @sc{gnu} Hurd
24561 @cindex pause current thread (@sc{gnu} Hurd)
24562 This command toggles current thread suspension when @value{GDBN} has
24563 control. Setting it to on takes effect immediately, and the current
24564 thread is suspended whenever @value{GDBN} gets control. Setting it to
24565 off will take effect the next time the inferior is continued.
24566 Normally, this command has no effect, since when @value{GDBN} has
24567 control, the whole task is suspended. However, if you used @code{set
24568 task pause off} (see above), this command comes in handy to suspend
24569 only the current thread.
24570
24571 @item show thread pause
24572 @kindex show thread@r{, Hurd command}
24573 This command shows the state of current thread suspension.
24574
24575 @item set thread run
24576 This command sets whether the current thread is allowed to run.
24577
24578 @item show thread run
24579 Show whether the current thread is allowed to run.
24580
24581 @item set thread detach-suspend-count
24582 @cindex thread suspend count, @sc{gnu} Hurd
24583 @cindex detach from thread, @sc{gnu} Hurd
24584 This command sets the suspend count @value{GDBN} will leave on a
24585 thread when detaching. This number is relative to the suspend count
24586 found by @value{GDBN} when it notices the thread; use @code{set thread
24587 takeover-suspend-count} to force it to an absolute value.
24588
24589 @item show thread detach-suspend-count
24590 Show the suspend count @value{GDBN} will leave on the thread when
24591 detaching.
24592
24593 @item set thread exception-port
24594 @itemx set thread excp
24595 Set the thread exception port to which to forward exceptions. This
24596 overrides the port set by @code{set task exception-port} (see above).
24597 @code{set thread excp} is the shorthand alias.
24598
24599 @item set thread takeover-suspend-count
24600 Normally, @value{GDBN}'s thread suspend counts are relative to the
24601 value @value{GDBN} finds when it notices each thread. This command
24602 changes the suspend counts to be absolute instead.
24603
24604 @item set thread default
24605 @itemx show thread default
24606 @cindex thread default settings, @sc{gnu} Hurd
24607 Each of the above @code{set thread} commands has a @code{set thread
24608 default} counterpart (e.g., @code{set thread default pause}, @code{set
24609 thread default exception-port}, etc.). The @code{thread default}
24610 variety of commands sets the default thread properties for all
24611 threads; you can then change the properties of individual threads with
24612 the non-default commands.
24613 @end table
24614
24615 @node Darwin
24616 @subsection Darwin
24617 @cindex Darwin
24618
24619 @value{GDBN} provides the following commands specific to the Darwin target:
24620
24621 @table @code
24622 @item set debug darwin @var{num}
24623 @kindex set debug darwin
24624 When set to a non zero value, enables debugging messages specific to
24625 the Darwin support. Higher values produce more verbose output.
24626
24627 @item show debug darwin
24628 @kindex show debug darwin
24629 Show the current state of Darwin messages.
24630
24631 @item set debug mach-o @var{num}
24632 @kindex set debug mach-o
24633 When set to a non zero value, enables debugging messages while
24634 @value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
24635 file format used on Darwin for object and executable files.) Higher
24636 values produce more verbose output. This is a command to diagnose
24637 problems internal to @value{GDBN} and should not be needed in normal
24638 usage.
24639
24640 @item show debug mach-o
24641 @kindex show debug mach-o
24642 Show the current state of Mach-O file messages.
24643
24644 @item set mach-exceptions on
24645 @itemx set mach-exceptions off
24646 @kindex set mach-exceptions
24647 On Darwin, faults are first reported as a Mach exception and are then
24648 mapped to a Posix signal. Use this command to turn on trapping of
24649 Mach exceptions in the inferior. This might be sometimes useful to
24650 better understand the cause of a fault. The default is off.
24651
24652 @item show mach-exceptions
24653 @kindex show mach-exceptions
24654 Show the current state of exceptions trapping.
24655 @end table
24656
24657 @node FreeBSD
24658 @subsection FreeBSD
24659 @cindex FreeBSD
24660
24661 When the ABI of a system call is changed in the FreeBSD kernel, this
24662 is implemented by leaving a compatibility system call using the old
24663 ABI at the existing number and allocating a new system call number for
24664 the version using the new ABI. As a convenience, when a system call
24665 is caught by name (@pxref{catch syscall}), compatibility system calls
24666 are also caught.
24667
24668 For example, FreeBSD 12 introduced a new variant of the @code{kevent}
24669 system call and catching the @code{kevent} system call by name catches
24670 both variants:
24671
24672 @smallexample
24673 (@value{GDBP}) catch syscall kevent
24674 Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
24675 (@value{GDBP})
24676 @end smallexample
24677
24678
24679 @node Embedded OS
24680 @section Embedded Operating Systems
24681
24682 This section describes configurations involving the debugging of
24683 embedded operating systems that are available for several different
24684 architectures.
24685
24686 @value{GDBN} includes the ability to debug programs running on
24687 various real-time operating systems.
24688
24689 @node Embedded Processors
24690 @section Embedded Processors
24691
24692 This section goes into details specific to particular embedded
24693 configurations.
24694
24695 @cindex send command to simulator
24696 Whenever a specific embedded processor has a simulator, @value{GDBN}
24697 allows to send an arbitrary command to the simulator.
24698
24699 @table @code
24700 @item sim @var{command}
24701 @kindex sim@r{, a command}
24702 Send an arbitrary @var{command} string to the simulator. Consult the
24703 documentation for the specific simulator in use for information about
24704 acceptable commands.
24705 @end table
24706
24707
24708 @menu
24709 * ARC:: Synopsys ARC
24710 * ARM:: ARM
24711 * BPF:: eBPF
24712 * M68K:: Motorola M68K
24713 * MicroBlaze:: Xilinx MicroBlaze
24714 * MIPS Embedded:: MIPS Embedded
24715 * OpenRISC 1000:: OpenRISC 1000 (or1k)
24716 * PowerPC Embedded:: PowerPC Embedded
24717 * AVR:: Atmel AVR
24718 * CRIS:: CRIS
24719 * Super-H:: Renesas Super-H
24720 @end menu
24721
24722 @node ARC
24723 @subsection Synopsys ARC
24724 @cindex Synopsys ARC
24725 @cindex ARC specific commands
24726 @cindex ARC600
24727 @cindex ARC700
24728 @cindex ARC EM
24729 @cindex ARC HS
24730
24731 @value{GDBN} provides the following ARC-specific commands:
24732
24733 @table @code
24734 @item set debug arc
24735 @kindex set debug arc
24736 Control the level of ARC specific debug messages. Use 0 for no messages (the
24737 default), 1 for debug messages, and 2 for even more debug messages.
24738
24739 @item show debug arc
24740 @kindex show debug arc
24741 Show the level of ARC specific debugging in operation.
24742
24743 @item maint print arc arc-instruction @var{address}
24744 @kindex maint print arc arc-instruction
24745 Print internal disassembler information about instruction at a given address.
24746
24747 @end table
24748
24749 @node ARM
24750 @subsection ARM
24751
24752 @value{GDBN} provides the following ARM-specific commands:
24753
24754 @table @code
24755 @item set arm disassembler
24756 @kindex set arm
24757 This commands selects from a list of disassembly styles. The
24758 @code{"std"} style is the standard style.
24759
24760 @item show arm disassembler
24761 @kindex show arm
24762 Show the current disassembly style.
24763
24764 @item set arm apcs32
24765 @cindex ARM 32-bit mode
24766 This command toggles ARM operation mode between 32-bit and 26-bit.
24767
24768 @item show arm apcs32
24769 Display the current usage of the ARM 32-bit mode.
24770
24771 @item set arm fpu @var{fputype}
24772 This command sets the ARM floating-point unit (FPU) type. The
24773 argument @var{fputype} can be one of these:
24774
24775 @table @code
24776 @item auto
24777 Determine the FPU type by querying the OS ABI.
24778 @item softfpa
24779 Software FPU, with mixed-endian doubles on little-endian ARM
24780 processors.
24781 @item fpa
24782 GCC-compiled FPA co-processor.
24783 @item softvfp
24784 Software FPU with pure-endian doubles.
24785 @item vfp
24786 VFP co-processor.
24787 @end table
24788
24789 @item show arm fpu
24790 Show the current type of the FPU.
24791
24792 @item set arm abi
24793 This command forces @value{GDBN} to use the specified ABI.
24794
24795 @item show arm abi
24796 Show the currently used ABI.
24797
24798 @item set arm fallback-mode (arm|thumb|auto)
24799 @value{GDBN} uses the symbol table, when available, to determine
24800 whether instructions are ARM or Thumb. This command controls
24801 @value{GDBN}'s default behavior when the symbol table is not
24802 available. The default is @samp{auto}, which causes @value{GDBN} to
24803 use the current execution mode (from the @code{T} bit in the @code{CPSR}
24804 register).
24805
24806 @item show arm fallback-mode
24807 Show the current fallback instruction mode.
24808
24809 @item set arm force-mode (arm|thumb|auto)
24810 This command overrides use of the symbol table to determine whether
24811 instructions are ARM or Thumb. The default is @samp{auto}, which
24812 causes @value{GDBN} to use the symbol table and then the setting
24813 of @samp{set arm fallback-mode}.
24814
24815 @item show arm force-mode
24816 Show the current forced instruction mode.
24817
24818 @item set debug arm
24819 Toggle whether to display ARM-specific debugging messages from the ARM
24820 target support subsystem.
24821
24822 @item show debug arm
24823 Show whether ARM-specific debugging messages are enabled.
24824 @end table
24825
24826 @table @code
24827 @item target sim @r{[}@var{simargs}@r{]} @dots{}
24828 The @value{GDBN} ARM simulator accepts the following optional arguments.
24829
24830 @table @code
24831 @item --swi-support=@var{type}
24832 Tell the simulator which SWI interfaces to support. The argument
24833 @var{type} may be a comma separated list of the following values.
24834 The default value is @code{all}.
24835
24836 @table @code
24837 @item none
24838 @item demon
24839 @item angel
24840 @item redboot
24841 @item all
24842 @end table
24843 @end table
24844 @end table
24845
24846 @node BPF
24847 @subsection BPF
24848
24849 @table @code
24850 @item target sim @r{[}@var{simargs}@r{]} @dots{}
24851 The @value{GDBN} BPF simulator accepts the following optional arguments.
24852
24853 @table @code
24854 @item --skb-data-offset=@var{offset}
24855 Tell the simulator the offset, measured in bytes, of the
24856 @code{skb_data} field in the kernel @code{struct sk_buff} structure.
24857 This offset is used by some BPF specific-purpose load/store
24858 instructions. Defaults to 0.
24859 @end table
24860 @end table
24861
24862 @node M68K
24863 @subsection M68k
24864
24865 The Motorola m68k configuration includes ColdFire support.
24866
24867 @node MicroBlaze
24868 @subsection MicroBlaze
24869 @cindex Xilinx MicroBlaze
24870 @cindex XMD, Xilinx Microprocessor Debugger
24871
24872 The MicroBlaze is a soft-core processor supported on various Xilinx
24873 FPGAs, such as Spartan or Virtex series. Boards with these processors
24874 usually have JTAG ports which connect to a host system running the Xilinx
24875 Embedded Development Kit (EDK) or Software Development Kit (SDK).
24876 This host system is used to download the configuration bitstream to
24877 the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
24878 communicates with the target board using the JTAG interface and
24879 presents a @code{gdbserver} interface to the board. By default
24880 @code{xmd} uses port @code{1234}. (While it is possible to change
24881 this default port, it requires the use of undocumented @code{xmd}
24882 commands. Contact Xilinx support if you need to do this.)
24883
24884 Use these GDB commands to connect to the MicroBlaze target processor.
24885
24886 @table @code
24887 @item target remote :1234
24888 Use this command to connect to the target if you are running @value{GDBN}
24889 on the same system as @code{xmd}.
24890
24891 @item target remote @var{xmd-host}:1234
24892 Use this command to connect to the target if it is connected to @code{xmd}
24893 running on a different system named @var{xmd-host}.
24894
24895 @item load
24896 Use this command to download a program to the MicroBlaze target.
24897
24898 @item set debug microblaze @var{n}
24899 Enable MicroBlaze-specific debugging messages if non-zero.
24900
24901 @item show debug microblaze @var{n}
24902 Show MicroBlaze-specific debugging level.
24903 @end table
24904
24905 @node MIPS Embedded
24906 @subsection @acronym{MIPS} Embedded
24907
24908 @noindent
24909 @value{GDBN} supports these special commands for @acronym{MIPS} targets:
24910
24911 @table @code
24912 @item set mipsfpu double
24913 @itemx set mipsfpu single
24914 @itemx set mipsfpu none
24915 @itemx set mipsfpu auto
24916 @itemx show mipsfpu
24917 @kindex set mipsfpu
24918 @kindex show mipsfpu
24919 @cindex @acronym{MIPS} remote floating point
24920 @cindex floating point, @acronym{MIPS} remote
24921 If your target board does not support the @acronym{MIPS} floating point
24922 coprocessor, you should use the command @samp{set mipsfpu none} (if you
24923 need this, you may wish to put the command in your @value{GDBN} init
24924 file). This tells @value{GDBN} how to find the return value of
24925 functions which return floating point values. It also allows
24926 @value{GDBN} to avoid saving the floating point registers when calling
24927 functions on the board. If you are using a floating point coprocessor
24928 with only single precision floating point support, as on the @sc{r4650}
24929 processor, use the command @samp{set mipsfpu single}. The default
24930 double precision floating point coprocessor may be selected using
24931 @samp{set mipsfpu double}.
24932
24933 In previous versions the only choices were double precision or no
24934 floating point, so @samp{set mipsfpu on} will select double precision
24935 and @samp{set mipsfpu off} will select no floating point.
24936
24937 As usual, you can inquire about the @code{mipsfpu} variable with
24938 @samp{show mipsfpu}.
24939 @end table
24940
24941 @node OpenRISC 1000
24942 @subsection OpenRISC 1000
24943 @cindex OpenRISC 1000
24944
24945 @noindent
24946 The OpenRISC 1000 provides a free RISC instruction set architecture. It is
24947 mainly provided as a soft-core which can run on Xilinx, Altera and other
24948 FPGA's.
24949
24950 @value{GDBN} for OpenRISC supports the below commands when connecting to
24951 a target:
24952
24953 @table @code
24954
24955 @kindex target sim
24956 @item target sim
24957
24958 Runs the builtin CPU simulator which can run very basic
24959 programs but does not support most hardware functions like MMU.
24960 For more complex use cases the user is advised to run an external
24961 target, and connect using @samp{target remote}.
24962
24963 Example: @code{target sim}
24964
24965 @item set debug or1k
24966 Toggle whether to display OpenRISC-specific debugging messages from the
24967 OpenRISC target support subsystem.
24968
24969 @item show debug or1k
24970 Show whether OpenRISC-specific debugging messages are enabled.
24971 @end table
24972
24973 @node PowerPC Embedded
24974 @subsection PowerPC Embedded
24975
24976 @cindex DVC register
24977 @value{GDBN} supports using the DVC (Data Value Compare) register to
24978 implement in hardware simple hardware watchpoint conditions of the form:
24979
24980 @smallexample
24981 (@value{GDBP}) watch @var{address|variable} \
24982 if @var{address|variable} == @var{constant expression}
24983 @end smallexample
24984
24985 The DVC register will be automatically used when @value{GDBN} detects
24986 such pattern in a condition expression, and the created watchpoint uses one
24987 debug register (either the @code{exact-watchpoints} option is on and the
24988 variable is scalar, or the variable has a length of one byte). This feature
24989 is available in native @value{GDBN} running on a Linux kernel version 2.6.34
24990 or newer.
24991
24992 When running on PowerPC embedded processors, @value{GDBN} automatically uses
24993 ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
24994 in which case watchpoints using only one debug register are created when
24995 watching variables of scalar types.
24996
24997 You can create an artificial array to watch an arbitrary memory
24998 region using one of the following commands (@pxref{Expressions}):
24999
25000 @smallexample
25001 (@value{GDBP}) watch *((char *) @var{address})@@@var{length}
25002 (@value{GDBP}) watch @{char[@var{length}]@} @var{address}
25003 @end smallexample
25004
25005 PowerPC embedded processors support masked watchpoints. See the discussion
25006 about the @code{mask} argument in @ref{Set Watchpoints}.
25007
25008 @cindex ranged breakpoint
25009 PowerPC embedded processors support hardware accelerated
25010 @dfn{ranged breakpoints}. A ranged breakpoint stops execution of
25011 the inferior whenever it executes an instruction at any address within
25012 the range it specifies. To set a ranged breakpoint in @value{GDBN},
25013 use the @code{break-range} command.
25014
25015 @value{GDBN} provides the following PowerPC-specific commands:
25016
25017 @table @code
25018 @kindex break-range
25019 @item break-range @var{start-location}, @var{end-location}
25020 Set a breakpoint for an address range given by
25021 @var{start-location} and @var{end-location}, which can specify a function name,
25022 a line number, an offset of lines from the current line or from the start
25023 location, or an address of an instruction (see @ref{Specify Location},
25024 for a list of all the possible ways to specify a @var{location}.)
25025 The breakpoint will stop execution of the inferior whenever it
25026 executes an instruction at any address within the specified range,
25027 (including @var{start-location} and @var{end-location}.)
25028
25029 @kindex set powerpc
25030 @item set powerpc soft-float
25031 @itemx show powerpc soft-float
25032 Force @value{GDBN} to use (or not use) a software floating point calling
25033 convention. By default, @value{GDBN} selects the calling convention based
25034 on the selected architecture and the provided executable file.
25035
25036 @item set powerpc vector-abi
25037 @itemx show powerpc vector-abi
25038 Force @value{GDBN} to use the specified calling convention for vector
25039 arguments and return values. The valid options are @samp{auto};
25040 @samp{generic}, to avoid vector registers even if they are present;
25041 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
25042 registers. By default, @value{GDBN} selects the calling convention
25043 based on the selected architecture and the provided executable file.
25044
25045 @item set powerpc exact-watchpoints
25046 @itemx show powerpc exact-watchpoints
25047 Allow @value{GDBN} to use only one debug register when watching a variable
25048 of scalar type, thus assuming that the variable is accessed through the
25049 address of its first byte.
25050
25051 @end table
25052
25053 @node AVR
25054 @subsection Atmel AVR
25055 @cindex AVR
25056
25057 When configured for debugging the Atmel AVR, @value{GDBN} supports the
25058 following AVR-specific commands:
25059
25060 @table @code
25061 @item info io_registers
25062 @kindex info io_registers@r{, AVR}
25063 @cindex I/O registers (Atmel AVR)
25064 This command displays information about the AVR I/O registers. For
25065 each register, @value{GDBN} prints its number and value.
25066 @end table
25067
25068 @node CRIS
25069 @subsection CRIS
25070 @cindex CRIS
25071
25072 When configured for debugging CRIS, @value{GDBN} provides the
25073 following CRIS-specific commands:
25074
25075 @table @code
25076 @item set cris-version @var{ver}
25077 @cindex CRIS version
25078 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
25079 The CRIS version affects register names and sizes. This command is useful in
25080 case autodetection of the CRIS version fails.
25081
25082 @item show cris-version
25083 Show the current CRIS version.
25084
25085 @item set cris-dwarf2-cfi
25086 @cindex DWARF-2 CFI and CRIS
25087 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
25088 Change to @samp{off} when using @code{gcc-cris} whose version is below
25089 @code{R59}.
25090
25091 @item show cris-dwarf2-cfi
25092 Show the current state of using DWARF-2 CFI.
25093
25094 @item set cris-mode @var{mode}
25095 @cindex CRIS mode
25096 Set the current CRIS mode to @var{mode}. It should only be changed when
25097 debugging in guru mode, in which case it should be set to
25098 @samp{guru} (the default is @samp{normal}).
25099
25100 @item show cris-mode
25101 Show the current CRIS mode.
25102 @end table
25103
25104 @node Super-H
25105 @subsection Renesas Super-H
25106 @cindex Super-H
25107
25108 For the Renesas Super-H processor, @value{GDBN} provides these
25109 commands:
25110
25111 @table @code
25112 @item set sh calling-convention @var{convention}
25113 @kindex set sh calling-convention
25114 Set the calling-convention used when calling functions from @value{GDBN}.
25115 Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
25116 With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
25117 convention. If the DWARF-2 information of the called function specifies
25118 that the function follows the Renesas calling convention, the function
25119 is called using the Renesas calling convention. If the calling convention
25120 is set to @samp{renesas}, the Renesas calling convention is always used,
25121 regardless of the DWARF-2 information. This can be used to override the
25122 default of @samp{gcc} if debug information is missing, or the compiler
25123 does not emit the DWARF-2 calling convention entry for a function.
25124
25125 @item show sh calling-convention
25126 @kindex show sh calling-convention
25127 Show the current calling convention setting.
25128
25129 @end table
25130
25131
25132 @node Architectures
25133 @section Architectures
25134
25135 This section describes characteristics of architectures that affect
25136 all uses of @value{GDBN} with the architecture, both native and cross.
25137
25138 @menu
25139 * AArch64::
25140 * i386::
25141 * Alpha::
25142 * MIPS::
25143 * HPPA:: HP PA architecture
25144 * PowerPC::
25145 * Nios II::
25146 * Sparc64::
25147 * S12Z::
25148 @end menu
25149
25150 @node AArch64
25151 @subsection AArch64
25152 @cindex AArch64 support
25153
25154 When @value{GDBN} is debugging the AArch64 architecture, it provides the
25155 following special commands:
25156
25157 @table @code
25158 @item set debug aarch64
25159 @kindex set debug aarch64
25160 This command determines whether AArch64 architecture-specific debugging
25161 messages are to be displayed.
25162
25163 @item show debug aarch64
25164 Show whether AArch64 debugging messages are displayed.
25165
25166 @end table
25167
25168 @subsubsection AArch64 SVE.
25169 @cindex AArch64 SVE.
25170
25171 When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
25172 Extension (SVE) is present, then @value{GDBN} will provide the vector registers
25173 @code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
25174 @code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
25175 @code{$vg} will be provided. This is the vector granule for the current thread
25176 and represents the number of 64-bit chunks in an SVE @code{z} register.
25177
25178 If the vector length changes, then the @code{$vg} register will be updated,
25179 but the lengths of the @code{z} and @code{p} registers will not change. This
25180 is a known limitation of @value{GDBN} and does not affect the execution of the
25181 target process.
25182
25183 @subsubsection AArch64 Pointer Authentication.
25184 @cindex AArch64 Pointer Authentication.
25185
25186 When @value{GDBN} is debugging the AArch64 architecture, and the program is
25187 using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
25188 register @code{$lr} is pointing to an PAC function its value will be masked.
25189 When GDB prints a backtrace, any addresses that required unmasking will be
25190 postfixed with the marker [PAC]. When using the MI, this is printed as part
25191 of the @code{addr_flags} field.
25192
25193 @subsubsection AArch64 Memory Tagging Extension.
25194 @cindex AArch64 Memory Tagging Extension.
25195
25196 When @value{GDBN} is debugging the AArch64 architecture, the program is
25197 using the v8.5-A feature Memory Tagging Extension (MTE) and there is support
25198 in the kernel for MTE, @value{GDBN} will make memory tagging functionality
25199 available for inspection and editing of logical and allocation tags.
25200 @xref{Memory Tagging}.
25201
25202 To aid debugging, @value{GDBN} will output additional information when SIGSEGV
25203 signals are generated as a result of memory tag failures.
25204
25205 If the tag violation is synchronous, the following will be shown:
25206
25207 @smallexample
25208 Program received signal SIGSEGV, Segmentation fault
25209 Memory tag violation while accessing address 0x0500fffff7ff8000
25210 Allocation tag 0x1
25211 Logical tag 0x5.
25212 @end smallexample
25213
25214 If the tag violation is asynchronous, the fault address is not available.
25215 In this case @value{GDBN} will show the following:
25216
25217 @smallexample
25218 Program received signal SIGSEGV, Segmentation fault
25219 Memory tag violation
25220 Fault address unavailable.
25221 @end smallexample
25222
25223 A special register, @code{tag_ctl}, is made available through the
25224 @code{org.gnu.gdb.aarch64.mte} feature. This register exposes some
25225 options that can be controlled at runtime and emulates the @code{prctl}
25226 option @code{PR_SET_TAGGED_ADDR_CTRL}. For further information, see the
25227 documentation in the Linux kernel.
25228
25229 @node i386
25230 @subsection x86 Architecture-specific Issues
25231
25232 @table @code
25233 @item set struct-convention @var{mode}
25234 @kindex set struct-convention
25235 @cindex struct return convention
25236 @cindex struct/union returned in registers
25237 Set the convention used by the inferior to return @code{struct}s and
25238 @code{union}s from functions to @var{mode}. Possible values of
25239 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
25240 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
25241 are returned on the stack, while @code{"reg"} means that a
25242 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
25243 be returned in a register.
25244
25245 @item show struct-convention
25246 @kindex show struct-convention
25247 Show the current setting of the convention to return @code{struct}s
25248 from functions.
25249 @end table
25250
25251
25252 @subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
25253 @cindex Intel Memory Protection Extensions (MPX).
25254
25255 Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
25256 @footnote{The register named with capital letters represent the architecture
25257 registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
25258 which are the lower bound and upper bound. Bounds are effective addresses or
25259 memory locations. The upper bounds are architecturally represented in 1's
25260 complement form. A bound having lower bound = 0, and upper bound = 0
25261 (1's complement of all bits set) will allow access to the entire address space.
25262
25263 @samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
25264 through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
25265 display the upper bound performing the complement of one operation on the
25266 upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
25267 @value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
25268 can also be noted that the upper bounds are inclusive.
25269
25270 As an example, assume that the register BND0 holds bounds for a pointer having
25271 access allowed for the range between 0x32 and 0x71. The values present on
25272 bnd0raw and bnd registers are presented as follows:
25273
25274 @smallexample
25275 bnd0raw = @{0x32, 0xffffffff8e@}
25276 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
25277 @end smallexample
25278
25279 This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
25280 change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
25281 counterpart. When the bnd0@dots{}bnd3 registers are displayed via
25282 Python, the display includes the memory size, in bits, accessible to
25283 the pointer.
25284
25285 Bounds can also be stored in bounds tables, which are stored in
25286 application memory. These tables store bounds for pointers by specifying
25287 the bounds pointer's value along with its bounds. Evaluating and changing
25288 bounds located in bound tables is therefore interesting while investigating
25289 bugs on MPX context. @value{GDBN} provides commands for this purpose:
25290
25291 @table @code
25292 @item show mpx bound @var{pointer}
25293 @kindex show mpx bound
25294 Display bounds of the given @var{pointer}.
25295
25296 @item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
25297 @kindex set mpx bound
25298 Set the bounds of a pointer in the bound table.
25299 This command takes three parameters: @var{pointer} is the pointers
25300 whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
25301 for lower and upper bounds respectively.
25302 @end table
25303
25304 When you call an inferior function on an Intel MPX enabled program,
25305 GDB sets the inferior's bound registers to the init (disabled) state
25306 before calling the function. As a consequence, bounds checks for the
25307 pointer arguments passed to the function will always pass.
25308
25309 This is necessary because when you call an inferior function, the
25310 program is usually in the middle of the execution of other function.
25311 Since at that point bound registers are in an arbitrary state, not
25312 clearing them would lead to random bound violations in the called
25313 function.
25314
25315 You can still examine the influence of the bound registers on the
25316 execution of the called function by stopping the execution of the
25317 called function at its prologue, setting bound registers, and
25318 continuing the execution. For example:
25319
25320 @smallexample
25321 $ break *upper
25322 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
25323 $ print upper (a, b, c, d, 1)
25324 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
25325 $ print $bnd0
25326 @{lbound = 0x0, ubound = ffffffff@} : size -1
25327 @end smallexample
25328
25329 At this last step the value of bnd0 can be changed for investigation of bound
25330 violations caused along the execution of the call. In order to know how to
25331 set the bound registers or bound table for the call consult the ABI.
25332
25333 @node Alpha
25334 @subsection Alpha
25335
25336 See the following section.
25337
25338 @node MIPS
25339 @subsection @acronym{MIPS}
25340
25341 @cindex stack on Alpha
25342 @cindex stack on @acronym{MIPS}
25343 @cindex Alpha stack
25344 @cindex @acronym{MIPS} stack
25345 Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
25346 sometimes requires @value{GDBN} to search backward in the object code to
25347 find the beginning of a function.
25348
25349 @cindex response time, @acronym{MIPS} debugging
25350 To improve response time (especially for embedded applications, where
25351 @value{GDBN} may be restricted to a slow serial line for this search)
25352 you may want to limit the size of this search, using one of these
25353 commands:
25354
25355 @table @code
25356 @cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
25357 @item set heuristic-fence-post @var{limit}
25358 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
25359 search for the beginning of a function. A value of @var{0} (the
25360 default) means there is no limit. However, except for @var{0}, the
25361 larger the limit the more bytes @code{heuristic-fence-post} must search
25362 and therefore the longer it takes to run. You should only need to use
25363 this command when debugging a stripped executable.
25364
25365 @item show heuristic-fence-post
25366 Display the current limit.
25367 @end table
25368
25369 @noindent
25370 These commands are available @emph{only} when @value{GDBN} is configured
25371 for debugging programs on Alpha or @acronym{MIPS} processors.
25372
25373 Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
25374 programs:
25375
25376 @table @code
25377 @item set mips abi @var{arg}
25378 @kindex set mips abi
25379 @cindex set ABI for @acronym{MIPS}
25380 Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
25381 values of @var{arg} are:
25382
25383 @table @samp
25384 @item auto
25385 The default ABI associated with the current binary (this is the
25386 default).
25387 @item o32
25388 @item o64
25389 @item n32
25390 @item n64
25391 @item eabi32
25392 @item eabi64
25393 @end table
25394
25395 @item show mips abi
25396 @kindex show mips abi
25397 Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
25398
25399 @item set mips compression @var{arg}
25400 @kindex set mips compression
25401 @cindex code compression, @acronym{MIPS}
25402 Tell @value{GDBN} which @acronym{MIPS} compressed
25403 @acronym{ISA, Instruction Set Architecture} encoding is used by the
25404 inferior. @value{GDBN} uses this for code disassembly and other
25405 internal interpretation purposes. This setting is only referred to
25406 when no executable has been associated with the debugging session or
25407 the executable does not provide information about the encoding it uses.
25408 Otherwise this setting is automatically updated from information
25409 provided by the executable.
25410
25411 Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
25412 The default compressed @acronym{ISA} encoding is @samp{mips16}, as
25413 executables containing @acronym{MIPS16} code frequently are not
25414 identified as such.
25415
25416 This setting is ``sticky''; that is, it retains its value across
25417 debugging sessions until reset either explicitly with this command or
25418 implicitly from an executable.
25419
25420 The compiler and/or assembler typically add symbol table annotations to
25421 identify functions compiled for the @acronym{MIPS16} or
25422 @acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
25423 are present, @value{GDBN} uses them in preference to the global
25424 compressed @acronym{ISA} encoding setting.
25425
25426 @item show mips compression
25427 @kindex show mips compression
25428 Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
25429 @value{GDBN} to debug the inferior.
25430
25431 @item set mipsfpu
25432 @itemx show mipsfpu
25433 @xref{MIPS Embedded, set mipsfpu}.
25434
25435 @item set mips mask-address @var{arg}
25436 @kindex set mips mask-address
25437 @cindex @acronym{MIPS} addresses, masking
25438 This command determines whether the most-significant 32 bits of 64-bit
25439 @acronym{MIPS} addresses are masked off. The argument @var{arg} can be
25440 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
25441 setting, which lets @value{GDBN} determine the correct value.
25442
25443 @item show mips mask-address
25444 @kindex show mips mask-address
25445 Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
25446 not.
25447
25448 @item set remote-mips64-transfers-32bit-regs
25449 @kindex set remote-mips64-transfers-32bit-regs
25450 This command controls compatibility with 64-bit @acronym{MIPS} targets that
25451 transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
25452 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
25453 and 64 bits for other registers, set this option to @samp{on}.
25454
25455 @item show remote-mips64-transfers-32bit-regs
25456 @kindex show remote-mips64-transfers-32bit-regs
25457 Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
25458
25459 @item set debug mips
25460 @kindex set debug mips
25461 This command turns on and off debugging messages for the @acronym{MIPS}-specific
25462 target code in @value{GDBN}.
25463
25464 @item show debug mips
25465 @kindex show debug mips
25466 Show the current setting of @acronym{MIPS} debugging messages.
25467 @end table
25468
25469
25470 @node HPPA
25471 @subsection HPPA
25472 @cindex HPPA support
25473
25474 When @value{GDBN} is debugging the HP PA architecture, it provides the
25475 following special commands:
25476
25477 @table @code
25478 @item set debug hppa
25479 @kindex set debug hppa
25480 This command determines whether HPPA architecture-specific debugging
25481 messages are to be displayed.
25482
25483 @item show debug hppa
25484 Show whether HPPA debugging messages are displayed.
25485
25486 @item maint print unwind @var{address}
25487 @kindex maint print unwind@r{, HPPA}
25488 This command displays the contents of the unwind table entry at the
25489 given @var{address}.
25490
25491 @end table
25492
25493
25494 @node PowerPC
25495 @subsection PowerPC
25496 @cindex PowerPC architecture
25497
25498 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
25499 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
25500 numbers stored in the floating point registers. These values must be stored
25501 in two consecutive registers, always starting at an even register like
25502 @code{f0} or @code{f2}.
25503
25504 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
25505 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
25506 @code{f2} and @code{f3} for @code{$dl1} and so on.
25507
25508 For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
25509 wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
25510
25511 @node Nios II
25512 @subsection Nios II
25513 @cindex Nios II architecture
25514
25515 When @value{GDBN} is debugging the Nios II architecture,
25516 it provides the following special commands:
25517
25518 @table @code
25519
25520 @item set debug nios2
25521 @kindex set debug nios2
25522 This command turns on and off debugging messages for the Nios II
25523 target code in @value{GDBN}.
25524
25525 @item show debug nios2
25526 @kindex show debug nios2
25527 Show the current setting of Nios II debugging messages.
25528 @end table
25529
25530 @node Sparc64
25531 @subsection Sparc64
25532 @cindex Sparc64 support
25533 @cindex Application Data Integrity
25534 @subsubsection ADI Support
25535
25536 The M7 processor supports an Application Data Integrity (ADI) feature that
25537 detects invalid data accesses. When software allocates memory and enables
25538 ADI on the allocated memory, it chooses a 4-bit version number, sets the
25539 version in the upper 4 bits of the 64-bit pointer to that data, and stores
25540 the 4-bit version in every cacheline of that data. Hardware saves the latter
25541 in spare bits in the cache and memory hierarchy. On each load and store,
25542 the processor compares the upper 4 VA (virtual address) bits to the
25543 cacheline's version. If there is a mismatch, the processor generates a
25544 version mismatch trap which can be either precise or disrupting. The trap
25545 is an error condition which the kernel delivers to the process as a SIGSEGV
25546 signal.
25547
25548 Note that only 64-bit applications can use ADI and need to be built with
25549 ADI-enabled.
25550
25551 Values of the ADI version tags, which are in granularity of a
25552 cacheline (64 bytes), can be viewed or modified.
25553
25554
25555 @table @code
25556 @kindex adi examine
25557 @item adi (examine | x) [ / @var{n} ] @var{addr}
25558
25559 The @code{adi examine} command displays the value of one ADI version tag per
25560 cacheline.
25561
25562 @var{n} is a decimal integer specifying the number in bytes; the default
25563 is 1. It specifies how much ADI version information, at the ratio of 1:ADI
25564 block size, to display.
25565
25566 @var{addr} is the address in user address space where you want @value{GDBN}
25567 to begin displaying the ADI version tags.
25568
25569 Below is an example of displaying ADI versions of variable "shmaddr".
25570
25571 @smallexample
25572 (@value{GDBP}) adi x/100 shmaddr
25573 0xfff800010002c000: 0 0
25574 @end smallexample
25575
25576 @kindex adi assign
25577 @item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
25578
25579 The @code{adi assign} command is used to assign new ADI version tag
25580 to an address.
25581
25582 @var{n} is a decimal integer specifying the number in bytes;
25583 the default is 1. It specifies how much ADI version information, at the
25584 ratio of 1:ADI block size, to modify.
25585
25586 @var{addr} is the address in user address space where you want @value{GDBN}
25587 to begin modifying the ADI version tags.
25588
25589 @var{tag} is the new ADI version tag.
25590
25591 For example, do the following to modify then verify ADI versions of
25592 variable "shmaddr":
25593
25594 @smallexample
25595 (@value{GDBP}) adi a/100 shmaddr = 7
25596 (@value{GDBP}) adi x/100 shmaddr
25597 0xfff800010002c000: 7 7
25598 @end smallexample
25599
25600 @end table
25601
25602 @node S12Z
25603 @subsection S12Z
25604 @cindex S12Z support
25605
25606 When @value{GDBN} is debugging the S12Z architecture,
25607 it provides the following special command:
25608
25609 @table @code
25610 @item maint info bdccsr
25611 @kindex maint info bdccsr@r{, S12Z}
25612 This command displays the current value of the microprocessor's
25613 BDCCSR register.
25614 @end table
25615
25616
25617 @node Controlling GDB
25618 @chapter Controlling @value{GDBN}
25619
25620 You can alter the way @value{GDBN} interacts with you by using the
25621 @code{set} command. For commands controlling how @value{GDBN} displays
25622 data, see @ref{Print Settings, ,Print Settings}. Other settings are
25623 described here.
25624
25625 @menu
25626 * Prompt:: Prompt
25627 * Editing:: Command editing
25628 * Command History:: Command history
25629 * Screen Size:: Screen size
25630 * Output Styling:: Output styling
25631 * Numbers:: Numbers
25632 * ABI:: Configuring the current ABI
25633 * Auto-loading:: Automatically loading associated files
25634 * Messages/Warnings:: Optional warnings and messages
25635 * Debugging Output:: Optional messages about internal happenings
25636 * Other Misc Settings:: Other Miscellaneous Settings
25637 @end menu
25638
25639 @node Prompt
25640 @section Prompt
25641
25642 @cindex prompt
25643
25644 @value{GDBN} indicates its readiness to read a command by printing a string
25645 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
25646 can change the prompt string with the @code{set prompt} command. For
25647 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
25648 the prompt in one of the @value{GDBN} sessions so that you can always tell
25649 which one you are talking to.
25650
25651 @emph{Note:} @code{set prompt} does not add a space for you after the
25652 prompt you set. This allows you to set a prompt which ends in a space
25653 or a prompt that does not.
25654
25655 @table @code
25656 @kindex set prompt
25657 @item set prompt @var{newprompt}
25658 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
25659
25660 @kindex show prompt
25661 @item show prompt
25662 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
25663 @end table
25664
25665 Versions of @value{GDBN} that ship with Python scripting enabled have
25666 prompt extensions. The commands for interacting with these extensions
25667 are:
25668
25669 @table @code
25670 @kindex set extended-prompt
25671 @item set extended-prompt @var{prompt}
25672 Set an extended prompt that allows for substitutions.
25673 @xref{gdb.prompt}, for a list of escape sequences that can be used for
25674 substitution. Any escape sequences specified as part of the prompt
25675 string are replaced with the corresponding strings each time the prompt
25676 is displayed.
25677
25678 For example:
25679
25680 @smallexample
25681 set extended-prompt Current working directory: \w (gdb)
25682 @end smallexample
25683
25684 Note that when an extended-prompt is set, it takes control of the
25685 @var{prompt_hook} hook. @xref{prompt_hook}, for further information.
25686
25687 @kindex show extended-prompt
25688 @item show extended-prompt
25689 Prints the extended prompt. Any escape sequences specified as part of
25690 the prompt string with @code{set extended-prompt}, are replaced with the
25691 corresponding strings each time the prompt is displayed.
25692 @end table
25693
25694 @node Editing
25695 @section Command Editing
25696 @cindex readline
25697 @cindex command line editing
25698
25699 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
25700 @sc{gnu} library provides consistent behavior for programs which provide a
25701 command line interface to the user. Advantages are @sc{gnu} Emacs-style
25702 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
25703 substitution, and a storage and recall of command history across
25704 debugging sessions.
25705
25706 You may control the behavior of command line editing in @value{GDBN} with the
25707 command @code{set}.
25708
25709 @table @code
25710 @kindex set editing
25711 @cindex editing
25712 @item set editing
25713 @itemx set editing on
25714 Enable command line editing (enabled by default).
25715
25716 @item set editing off
25717 Disable command line editing.
25718
25719 @kindex show editing
25720 @item show editing
25721 Show whether command line editing is enabled.
25722 @end table
25723
25724 @ifset SYSTEM_READLINE
25725 @xref{Command Line Editing, , , rluserman, GNU Readline Library},
25726 @end ifset
25727 @ifclear SYSTEM_READLINE
25728 @xref{Command Line Editing},
25729 @end ifclear
25730 for more details about the Readline
25731 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
25732 encouraged to read that chapter.
25733
25734 @cindex Readline application name
25735 @value{GDBN} sets the Readline application name to @samp{gdb}. This
25736 is useful for conditions in @file{.inputrc}.
25737
25738 @cindex operate-and-get-next
25739 @value{GDBN} defines a bindable Readline command,
25740 @code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
25741 This command accepts the current line for execution and fetches the
25742 next line relative to the current line from the history for editing.
25743 Any argument is ignored.
25744
25745 @node Command History
25746 @section Command History
25747 @cindex command history
25748
25749 @value{GDBN} can keep track of the commands you type during your
25750 debugging sessions, so that you can be certain of precisely what
25751 happened. Use these commands to manage the @value{GDBN} command
25752 history facility.
25753
25754 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
25755 package, to provide the history facility.
25756 @ifset SYSTEM_READLINE
25757 @xref{Using History Interactively, , , history, GNU History Library},
25758 @end ifset
25759 @ifclear SYSTEM_READLINE
25760 @xref{Using History Interactively},
25761 @end ifclear
25762 for the detailed description of the History library.
25763
25764 To issue a command to @value{GDBN} without affecting certain aspects of
25765 the state which is seen by users, prefix it with @samp{server }
25766 (@pxref{Server Prefix}). This
25767 means that this command will not affect the command history, nor will it
25768 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
25769 pressed on a line by itself.
25770
25771 @cindex @code{server}, command prefix
25772 The server prefix does not affect the recording of values into the value
25773 history; to print a value without recording it into the value history,
25774 use the @code{output} command instead of the @code{print} command.
25775
25776 Here is the description of @value{GDBN} commands related to command
25777 history.
25778
25779 @table @code
25780 @cindex history substitution
25781 @cindex history file
25782 @kindex set history filename
25783 @cindex @env{GDBHISTFILE}, environment variable
25784 @item set history filename @r{[}@var{fname}@r{]}
25785 Set the name of the @value{GDBN} command history file to @var{fname}.
25786 This is the file where @value{GDBN} reads an initial command history
25787 list, and where it writes the command history from this session when it
25788 exits. You can access this list through history expansion or through
25789 the history command editing characters listed below. This file defaults
25790 to the value of the environment variable @code{GDBHISTFILE}, or to
25791 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
25792 is not set.
25793
25794 The @code{GDBHISTFILE} environment variable is read after processing
25795 any @value{GDBN} initialization files (@pxref{Startup}) and after
25796 processing any commands passed using command line options (for
25797 example, @code{-ex}).
25798
25799 If the @var{fname} argument is not given, or if the @code{GDBHISTFILE}
25800 is the empty string then @value{GDBN} will neither try to load an
25801 existing history file, nor will it try to save the history on exit.
25802
25803 @cindex save command history
25804 @kindex set history save
25805 @item set history save
25806 @itemx set history save on
25807 Record command history in a file, whose name may be specified with the
25808 @code{set history filename} command. By default, this option is
25809 disabled. The command history will be recorded when @value{GDBN}
25810 exits. If @code{set history filename} is set to the empty string then
25811 history saving is disabled, even when @code{set history save} is
25812 @code{on}.
25813
25814 @item set history save off
25815 Don't record the command history into the file specified by @code{set
25816 history filename} when @value{GDBN} exits.
25817
25818 @cindex history size
25819 @kindex set history size
25820 @cindex @env{GDBHISTSIZE}, environment variable
25821 @item set history size @var{size}
25822 @itemx set history size unlimited
25823 Set the number of commands which @value{GDBN} keeps in its history list.
25824 This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
25825 to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
25826 are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
25827 either a negative number or the empty string, then the number of commands
25828 @value{GDBN} keeps in the history list is unlimited.
25829
25830 The @code{GDBHISTSIZE} environment variable is read after processing
25831 any @value{GDBN} initialization files (@pxref{Startup}) and after
25832 processing any commands passed using command line options (for
25833 example, @code{-ex}).
25834
25835 @cindex remove duplicate history
25836 @kindex set history remove-duplicates
25837 @item set history remove-duplicates @var{count}
25838 @itemx set history remove-duplicates unlimited
25839 Control the removal of duplicate history entries in the command history list.
25840 If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
25841 history entries and remove the first entry that is a duplicate of the current
25842 entry being added to the command history list. If @var{count} is
25843 @code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
25844 removal of duplicate history entries is disabled.
25845
25846 Only history entries added during the current session are considered for
25847 removal. This option is set to 0 by default.
25848
25849 @end table
25850
25851 History expansion assigns special meaning to the character @kbd{!}.
25852 @ifset SYSTEM_READLINE
25853 @xref{Event Designators, , , history, GNU History Library},
25854 @end ifset
25855 @ifclear SYSTEM_READLINE
25856 @xref{Event Designators},
25857 @end ifclear
25858 for more details.
25859
25860 @cindex history expansion, turn on/off
25861 Since @kbd{!} is also the logical not operator in C, history expansion
25862 is off by default. If you decide to enable history expansion with the
25863 @code{set history expansion on} command, you may sometimes need to
25864 follow @kbd{!} (when it is used as logical not, in an expression) with
25865 a space or a tab to prevent it from being expanded. The readline
25866 history facilities do not attempt substitution on the strings
25867 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
25868
25869 The commands to control history expansion are:
25870
25871 @table @code
25872 @item set history expansion on
25873 @itemx set history expansion
25874 @kindex set history expansion
25875 Enable history expansion. History expansion is off by default.
25876
25877 @item set history expansion off
25878 Disable history expansion.
25879
25880 @c @group
25881 @kindex show history
25882 @item show history
25883 @itemx show history filename
25884 @itemx show history save
25885 @itemx show history size
25886 @itemx show history expansion
25887 These commands display the state of the @value{GDBN} history parameters.
25888 @code{show history} by itself displays all four states.
25889 @c @end group
25890 @end table
25891
25892 @table @code
25893 @kindex show commands
25894 @cindex show last commands
25895 @cindex display command history
25896 @item show commands
25897 Display the last ten commands in the command history.
25898
25899 @item show commands @var{n}
25900 Print ten commands centered on command number @var{n}.
25901
25902 @item show commands +
25903 Print ten commands just after the commands last printed.
25904 @end table
25905
25906 @node Screen Size
25907 @section Screen Size
25908 @cindex size of screen
25909 @cindex screen size
25910 @cindex pagination
25911 @cindex page size
25912 @cindex pauses in output
25913
25914 Certain commands to @value{GDBN} may produce large amounts of
25915 information output to the screen. To help you read all of it,
25916 @value{GDBN} pauses and asks you for input at the end of each page of
25917 output. Type @key{RET} when you want to see one more page of output,
25918 @kbd{q} to discard the remaining output, or @kbd{c} to continue
25919 without paging for the rest of the current command. Also, the screen
25920 width setting determines when to wrap lines of output. Depending on
25921 what is being printed, @value{GDBN} tries to break the line at a
25922 readable place, rather than simply letting it overflow onto the
25923 following line.
25924
25925 Normally @value{GDBN} knows the size of the screen from the terminal
25926 driver software. For example, on Unix @value{GDBN} uses the termcap data base
25927 together with the value of the @code{TERM} environment variable and the
25928 @code{stty rows} and @code{stty cols} settings. If this is not correct,
25929 you can override it with the @code{set height} and @code{set
25930 width} commands:
25931
25932 @table @code
25933 @kindex set height
25934 @kindex set width
25935 @kindex show width
25936 @kindex show height
25937 @item set height @var{lpp}
25938 @itemx set height unlimited
25939 @itemx show height
25940 @itemx set width @var{cpl}
25941 @itemx set width unlimited
25942 @itemx show width
25943 These @code{set} commands specify a screen height of @var{lpp} lines and
25944 a screen width of @var{cpl} characters. The associated @code{show}
25945 commands display the current settings.
25946
25947 If you specify a height of either @code{unlimited} or zero lines,
25948 @value{GDBN} does not pause during output no matter how long the
25949 output is. This is useful if output is to a file or to an editor
25950 buffer.
25951
25952 Likewise, you can specify @samp{set width unlimited} or @samp{set
25953 width 0} to prevent @value{GDBN} from wrapping its output.
25954
25955 @item set pagination on
25956 @itemx set pagination off
25957 @kindex set pagination
25958 Turn the output pagination on or off; the default is on. Turning
25959 pagination off is the alternative to @code{set height unlimited}. Note that
25960 running @value{GDBN} with the @option{--batch} option (@pxref{Mode
25961 Options, -batch}) also automatically disables pagination.
25962
25963 @item show pagination
25964 @kindex show pagination
25965 Show the current pagination mode.
25966 @end table
25967
25968 @node Output Styling
25969 @section Output Styling
25970 @cindex styling
25971 @cindex colors
25972
25973 @kindex set style
25974 @kindex show style
25975 @value{GDBN} can style its output on a capable terminal. This is
25976 enabled by default on most systems, but disabled by default when in
25977 batch mode (@pxref{Mode Options}). Various style settings are available;
25978 and styles can also be disabled entirely.
25979
25980 @table @code
25981 @item set style enabled @samp{on|off}
25982 Enable or disable all styling. The default is host-dependent, with
25983 most hosts defaulting to @samp{on}.
25984
25985 @item show style enabled
25986 Show the current state of styling.
25987
25988 @item set style sources @samp{on|off}
25989 Enable or disable source code styling. This affects whether source
25990 code, such as the output of the @code{list} command, is styled. Note
25991 that source styling only works if styling in general is enabled, and
25992 if @value{GDBN} was linked with the GNU Source Highlight library. The
25993 default is @samp{on}.
25994
25995 @item show style sources
25996 Show the current state of source code styling.
25997 @end table
25998
25999 Subcommands of @code{set style} control specific forms of styling.
26000 These subcommands all follow the same pattern: each style-able object
26001 can be styled with a foreground color, a background color, and an
26002 intensity.
26003
26004 For example, the style of file names can be controlled using the
26005 @code{set style filename} group of commands:
26006
26007 @table @code
26008 @item set style filename background @var{color}
26009 Set the background to @var{color}. Valid colors are @samp{none}
26010 (meaning the terminal's default color), @samp{black}, @samp{red},
26011 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
26012 and@samp{white}.
26013
26014 @item set style filename foreground @var{color}
26015 Set the foreground to @var{color}. Valid colors are @samp{none}
26016 (meaning the terminal's default color), @samp{black}, @samp{red},
26017 @samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
26018 and@samp{white}.
26019
26020 @item set style filename intensity @var{value}
26021 Set the intensity to @var{value}. Valid intensities are @samp{normal}
26022 (the default), @samp{bold}, and @samp{dim}.
26023 @end table
26024
26025 The @code{show style} command and its subcommands are styling
26026 a style name in their output using its own style.
26027 So, use @command{show style} to see the complete list of styles,
26028 their characteristics and the visual aspect of each style.
26029
26030 The style-able objects are:
26031 @table @code
26032 @item filename
26033 Control the styling of file names. By default, this style's
26034 foreground color is green.
26035
26036 @item function
26037 Control the styling of function names. These are managed with the
26038 @code{set style function} family of commands. By default, this
26039 style's foreground color is yellow.
26040
26041 @item variable
26042 Control the styling of variable names. These are managed with the
26043 @code{set style variable} family of commands. By default, this style's
26044 foreground color is cyan.
26045
26046 @item address
26047 Control the styling of addresses. These are managed with the
26048 @code{set style address} family of commands. By default, this style's
26049 foreground color is blue.
26050
26051 @item version
26052 Control the styling of @value{GDBN}'s version number text. By
26053 default, this style's foreground color is magenta and it has bold
26054 intensity. The version number is displayed in two places, the output
26055 of @command{show version}, and when @value{GDBN} starts up.
26056
26057 In order to control how @value{GDBN} styles the version number at
26058 startup, add the @code{set style version} family of commands to the
26059 early initialization command file (@pxref{Initialization
26060 Files}).
26061
26062 @item title
26063 Control the styling of titles. These are managed with the
26064 @code{set style title} family of commands. By default, this style's
26065 intensity is bold. Commands are using the title style to improve
26066 the readability of large output. For example, the commands
26067 @command{apropos} and @command{help} are using the title style
26068 for the command names.
26069
26070 @item highlight
26071 Control the styling of highlightings. These are managed with the
26072 @code{set style highlight} family of commands. By default, this style's
26073 foreground color is red. Commands are using the highlight style to draw
26074 the user attention to some specific parts of their output. For example,
26075 the command @command{apropos -v REGEXP} uses the highlight style to
26076 mark the documentation parts matching @var{regexp}.
26077
26078 @item tui-border
26079 Control the styling of the TUI border. Note that, unlike other
26080 styling options, only the color of the border can be controlled via
26081 @code{set style}. This was done for compatibility reasons, as TUI
26082 controls to set the border's intensity predated the addition of
26083 general styling to @value{GDBN}. @xref{TUI Configuration}.
26084
26085 @item tui-active-border
26086 Control the styling of the active TUI border; that is, the TUI window
26087 that has the focus.
26088
26089 @end table
26090
26091 @node Numbers
26092 @section Numbers
26093 @cindex number representation
26094 @cindex entering numbers
26095
26096 You can always enter numbers in octal, decimal, or hexadecimal in
26097 @value{GDBN} by the usual conventions: octal numbers begin with
26098 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
26099 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
26100 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
26101 10; likewise, the default display for numbers---when no particular
26102 format is specified---is base 10. You can change the default base for
26103 both input and output with the commands described below.
26104
26105 @table @code
26106 @kindex set input-radix
26107 @item set input-radix @var{base}
26108 Set the default base for numeric input. Supported choices
26109 for @var{base} are decimal 8, 10, or 16. The base must itself be
26110 specified either unambiguously or using the current input radix; for
26111 example, any of
26112
26113 @smallexample
26114 set input-radix 012
26115 set input-radix 10.
26116 set input-radix 0xa
26117 @end smallexample
26118
26119 @noindent
26120 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
26121 leaves the input radix unchanged, no matter what it was, since
26122 @samp{10}, being without any leading or trailing signs of its base, is
26123 interpreted in the current radix. Thus, if the current radix is 16,
26124 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
26125 change the radix.
26126
26127 @kindex set output-radix
26128 @item set output-radix @var{base}
26129 Set the default base for numeric display. Supported choices
26130 for @var{base} are decimal 8, 10, or 16. The base must itself be
26131 specified either unambiguously or using the current input radix.
26132
26133 @kindex show input-radix
26134 @item show input-radix
26135 Display the current default base for numeric input.
26136
26137 @kindex show output-radix
26138 @item show output-radix
26139 Display the current default base for numeric display.
26140
26141 @item set radix @r{[}@var{base}@r{]}
26142 @itemx show radix
26143 @kindex set radix
26144 @kindex show radix
26145 These commands set and show the default base for both input and output
26146 of numbers. @code{set radix} sets the radix of input and output to
26147 the same base; without an argument, it resets the radix back to its
26148 default value of 10.
26149
26150 @end table
26151
26152 @node ABI
26153 @section Configuring the Current ABI
26154
26155 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
26156 application automatically. However, sometimes you need to override its
26157 conclusions. Use these commands to manage @value{GDBN}'s view of the
26158 current ABI.
26159
26160 @cindex OS ABI
26161 @kindex set osabi
26162 @kindex show osabi
26163 @cindex Newlib OS ABI and its influence on the longjmp handling
26164
26165 One @value{GDBN} configuration can debug binaries for multiple operating
26166 system targets, either via remote debugging or native emulation.
26167 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
26168 but you can override its conclusion using the @code{set osabi} command.
26169 One example where this is useful is in debugging of binaries which use
26170 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
26171 not have the same identifying marks that the standard C library for your
26172 platform provides.
26173
26174 When @value{GDBN} is debugging the AArch64 architecture, it provides a
26175 ``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
26176 @code{longjmp} when debugging binaries that use the @sc{newlib} C library.
26177 The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
26178
26179 @table @code
26180 @item show osabi
26181 Show the OS ABI currently in use.
26182
26183 @item set osabi
26184 With no argument, show the list of registered available OS ABI's.
26185
26186 @item set osabi @var{abi}
26187 Set the current OS ABI to @var{abi}.
26188 @end table
26189
26190 @cindex float promotion
26191
26192 Generally, the way that an argument of type @code{float} is passed to a
26193 function depends on whether the function is prototyped. For a prototyped
26194 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
26195 according to the architecture's convention for @code{float}. For unprototyped
26196 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
26197 @code{double} and then passed.
26198
26199 Unfortunately, some forms of debug information do not reliably indicate whether
26200 a function is prototyped. If @value{GDBN} calls a function that is not marked
26201 as prototyped, it consults @kbd{set coerce-float-to-double}.
26202
26203 @table @code
26204 @kindex set coerce-float-to-double
26205 @item set coerce-float-to-double
26206 @itemx set coerce-float-to-double on
26207 Arguments of type @code{float} will be promoted to @code{double} when passed
26208 to an unprototyped function. This is the default setting.
26209
26210 @item set coerce-float-to-double off
26211 Arguments of type @code{float} will be passed directly to unprototyped
26212 functions.
26213
26214 @kindex show coerce-float-to-double
26215 @item show coerce-float-to-double
26216 Show the current setting of promoting @code{float} to @code{double}.
26217 @end table
26218
26219 @kindex set cp-abi
26220 @kindex show cp-abi
26221 @value{GDBN} needs to know the ABI used for your program's C@t{++}
26222 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
26223 used to build your application. @value{GDBN} only fully supports
26224 programs with a single C@t{++} ABI; if your program contains code using
26225 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
26226 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
26227 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
26228 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
26229 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
26230 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
26231 ``auto''.
26232
26233 @table @code
26234 @item show cp-abi
26235 Show the C@t{++} ABI currently in use.
26236
26237 @item set cp-abi
26238 With no argument, show the list of supported C@t{++} ABI's.
26239
26240 @item set cp-abi @var{abi}
26241 @itemx set cp-abi auto
26242 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
26243 @end table
26244
26245 @node Auto-loading
26246 @section Automatically loading associated files
26247 @cindex auto-loading
26248
26249 @value{GDBN} sometimes reads files with commands and settings automatically,
26250 without being explicitly told so by the user. We call this feature
26251 @dfn{auto-loading}. While auto-loading is useful for automatically adapting
26252 @value{GDBN} to the needs of your project, it can sometimes produce unexpected
26253 results or introduce security risks (e.g., if the file comes from untrusted
26254 sources).
26255
26256 There are various kinds of files @value{GDBN} can automatically load.
26257 In addition to these files, @value{GDBN} supports auto-loading code written
26258 in various extension languages. @xref{Auto-loading extensions}.
26259
26260 Note that loading of these associated files (including the local @file{.gdbinit}
26261 file) requires accordingly configured @code{auto-load safe-path}
26262 (@pxref{Auto-loading safe path}).
26263
26264 For these reasons, @value{GDBN} includes commands and options to let you
26265 control when to auto-load files and which files should be auto-loaded.
26266
26267 @table @code
26268 @anchor{set auto-load off}
26269 @kindex set auto-load off
26270 @item set auto-load off
26271 Globally disable loading of all auto-loaded files.
26272 You may want to use this command with the @samp{-iex} option
26273 (@pxref{Option -init-eval-command}) such as:
26274 @smallexample
26275 $ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
26276 @end smallexample
26277
26278 Be aware that system init file (@pxref{System-wide configuration})
26279 and init files from your home directory (@pxref{Home Directory Init File})
26280 still get read (as they come from generally trusted directories).
26281 To prevent @value{GDBN} from auto-loading even those init files, use the
26282 @option{-nx} option (@pxref{Mode Options}), in addition to
26283 @code{set auto-load no}.
26284
26285 @anchor{show auto-load}
26286 @kindex show auto-load
26287 @item show auto-load
26288 Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
26289 or disabled.
26290
26291 @smallexample
26292 (gdb) show auto-load
26293 gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
26294 libthread-db: Auto-loading of inferior specific libthread_db is on.
26295 local-gdbinit: Auto-loading of .gdbinit script from current directory
26296 is on.
26297 python-scripts: Auto-loading of Python scripts is on.
26298 safe-path: List of directories from which it is safe to auto-load files
26299 is $debugdir:$datadir/auto-load.
26300 scripts-directory: List of directories from which to load auto-loaded scripts
26301 is $debugdir:$datadir/auto-load.
26302 @end smallexample
26303
26304 @anchor{info auto-load}
26305 @kindex info auto-load
26306 @item info auto-load
26307 Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
26308 not.
26309
26310 @smallexample
26311 (gdb) info auto-load
26312 gdb-scripts:
26313 Loaded Script
26314 Yes /home/user/gdb/gdb-gdb.gdb
26315 libthread-db: No auto-loaded libthread-db.
26316 local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
26317 loaded.
26318 python-scripts:
26319 Loaded Script
26320 Yes /home/user/gdb/gdb-gdb.py
26321 @end smallexample
26322 @end table
26323
26324 These are @value{GDBN} control commands for the auto-loading:
26325
26326 @multitable @columnfractions .5 .5
26327 @item @xref{set auto-load off}.
26328 @tab Disable auto-loading globally.
26329 @item @xref{show auto-load}.
26330 @tab Show setting of all kinds of files.
26331 @item @xref{info auto-load}.
26332 @tab Show state of all kinds of files.
26333 @item @xref{set auto-load gdb-scripts}.
26334 @tab Control for @value{GDBN} command scripts.
26335 @item @xref{show auto-load gdb-scripts}.
26336 @tab Show setting of @value{GDBN} command scripts.
26337 @item @xref{info auto-load gdb-scripts}.
26338 @tab Show state of @value{GDBN} command scripts.
26339 @item @xref{set auto-load python-scripts}.
26340 @tab Control for @value{GDBN} Python scripts.
26341 @item @xref{show auto-load python-scripts}.
26342 @tab Show setting of @value{GDBN} Python scripts.
26343 @item @xref{info auto-load python-scripts}.
26344 @tab Show state of @value{GDBN} Python scripts.
26345 @item @xref{set auto-load guile-scripts}.
26346 @tab Control for @value{GDBN} Guile scripts.
26347 @item @xref{show auto-load guile-scripts}.
26348 @tab Show setting of @value{GDBN} Guile scripts.
26349 @item @xref{info auto-load guile-scripts}.
26350 @tab Show state of @value{GDBN} Guile scripts.
26351 @item @xref{set auto-load scripts-directory}.
26352 @tab Control for @value{GDBN} auto-loaded scripts location.
26353 @item @xref{show auto-load scripts-directory}.
26354 @tab Show @value{GDBN} auto-loaded scripts location.
26355 @item @xref{add-auto-load-scripts-directory}.
26356 @tab Add directory for auto-loaded scripts location list.
26357 @item @xref{set auto-load local-gdbinit}.
26358 @tab Control for init file in the current directory.
26359 @item @xref{show auto-load local-gdbinit}.
26360 @tab Show setting of init file in the current directory.
26361 @item @xref{info auto-load local-gdbinit}.
26362 @tab Show state of init file in the current directory.
26363 @item @xref{set auto-load libthread-db}.
26364 @tab Control for thread debugging library.
26365 @item @xref{show auto-load libthread-db}.
26366 @tab Show setting of thread debugging library.
26367 @item @xref{info auto-load libthread-db}.
26368 @tab Show state of thread debugging library.
26369 @item @xref{set auto-load safe-path}.
26370 @tab Control directories trusted for automatic loading.
26371 @item @xref{show auto-load safe-path}.
26372 @tab Show directories trusted for automatic loading.
26373 @item @xref{add-auto-load-safe-path}.
26374 @tab Add directory trusted for automatic loading.
26375 @end multitable
26376
26377 @menu
26378 * Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
26379 * libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
26380
26381 * Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
26382 * Auto-loading verbose mode:: @samp{set/show debug auto-load}
26383 @end menu
26384
26385 @node Init File in the Current Directory
26386 @subsection Automatically loading init file in the current directory
26387 @cindex auto-loading init file in the current directory
26388
26389 By default, @value{GDBN} reads and executes the canned sequences of commands
26390 from init file (if any) in the current working directory,
26391 see @ref{Init File in the Current Directory during Startup}.
26392
26393 Note that loading of this local @file{.gdbinit} file also requires accordingly
26394 configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26395
26396 @table @code
26397 @anchor{set auto-load local-gdbinit}
26398 @kindex set auto-load local-gdbinit
26399 @item set auto-load local-gdbinit [on|off]
26400 Enable or disable the auto-loading of canned sequences of commands
26401 (@pxref{Sequences}) found in init file in the current directory.
26402
26403 @anchor{show auto-load local-gdbinit}
26404 @kindex show auto-load local-gdbinit
26405 @item show auto-load local-gdbinit
26406 Show whether auto-loading of canned sequences of commands from init file in the
26407 current directory is enabled or disabled.
26408
26409 @anchor{info auto-load local-gdbinit}
26410 @kindex info auto-load local-gdbinit
26411 @item info auto-load local-gdbinit
26412 Print whether canned sequences of commands from init file in the
26413 current directory have been auto-loaded.
26414 @end table
26415
26416 @node libthread_db.so.1 file
26417 @subsection Automatically loading thread debugging library
26418 @cindex auto-loading libthread_db.so.1
26419
26420 This feature is currently present only on @sc{gnu}/Linux native hosts.
26421
26422 @value{GDBN} reads in some cases thread debugging library from places specific
26423 to the inferior (@pxref{set libthread-db-search-path}).
26424
26425 The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
26426 without checking this @samp{set auto-load libthread-db} switch as system
26427 libraries have to be trusted in general. In all other cases of
26428 @samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
26429 auto-load libthread-db} is enabled before trying to open such thread debugging
26430 library.
26431
26432 Note that loading of this debugging library also requires accordingly configured
26433 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26434
26435 @table @code
26436 @anchor{set auto-load libthread-db}
26437 @kindex set auto-load libthread-db
26438 @item set auto-load libthread-db [on|off]
26439 Enable or disable the auto-loading of inferior specific thread debugging library.
26440
26441 @anchor{show auto-load libthread-db}
26442 @kindex show auto-load libthread-db
26443 @item show auto-load libthread-db
26444 Show whether auto-loading of inferior specific thread debugging library is
26445 enabled or disabled.
26446
26447 @anchor{info auto-load libthread-db}
26448 @kindex info auto-load libthread-db
26449 @item info auto-load libthread-db
26450 Print the list of all loaded inferior specific thread debugging libraries and
26451 for each such library print list of inferior @var{pid}s using it.
26452 @end table
26453
26454 @node Auto-loading safe path
26455 @subsection Security restriction for auto-loading
26456 @cindex auto-loading safe-path
26457
26458 As the files of inferior can come from untrusted source (such as submitted by
26459 an application user) @value{GDBN} does not always load any files automatically.
26460 @value{GDBN} provides the @samp{set auto-load safe-path} setting to list
26461 directories trusted for loading files not explicitly requested by user.
26462 Each directory can also be a shell wildcard pattern.
26463
26464 If the path is not set properly you will see a warning and the file will not
26465 get loaded:
26466
26467 @smallexample
26468 $ ./gdb -q ./gdb
26469 Reading symbols from /home/user/gdb/gdb...
26470 warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
26471 declined by your `auto-load safe-path' set
26472 to "$debugdir:$datadir/auto-load".
26473 warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
26474 declined by your `auto-load safe-path' set
26475 to "$debugdir:$datadir/auto-load".
26476 @end smallexample
26477
26478 @noindent
26479 To instruct @value{GDBN} to go ahead and use the init files anyway,
26480 invoke @value{GDBN} like this:
26481
26482 @smallexample
26483 $ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
26484 @end smallexample
26485
26486 The list of trusted directories is controlled by the following commands:
26487
26488 @table @code
26489 @anchor{set auto-load safe-path}
26490 @kindex set auto-load safe-path
26491 @item set auto-load safe-path @r{[}@var{directories}@r{]}
26492 Set the list of directories (and their subdirectories) trusted for automatic
26493 loading and execution of scripts. You can also enter a specific trusted file.
26494 Each directory can also be a shell wildcard pattern; wildcards do not match
26495 directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
26496 (@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
26497 If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
26498 its default value as specified during @value{GDBN} compilation.
26499
26500 The list of directories uses path separator (@samp{:} on GNU and Unix
26501 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26502 to the @env{PATH} environment variable.
26503
26504 @anchor{show auto-load safe-path}
26505 @kindex show auto-load safe-path
26506 @item show auto-load safe-path
26507 Show the list of directories trusted for automatic loading and execution of
26508 scripts.
26509
26510 @anchor{add-auto-load-safe-path}
26511 @kindex add-auto-load-safe-path
26512 @item add-auto-load-safe-path
26513 Add an entry (or list of entries) to the list of directories trusted for
26514 automatic loading and execution of scripts. Multiple entries may be delimited
26515 by the host platform path separator in use.
26516 @end table
26517
26518 This variable defaults to what @code{--with-auto-load-dir} has been configured
26519 to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
26520 substitution applies the same as for @ref{set auto-load scripts-directory}.
26521 The default @code{set auto-load safe-path} value can be also overriden by
26522 @value{GDBN} configuration option @option{--with-auto-load-safe-path}.
26523
26524 Setting this variable to @file{/} disables this security protection,
26525 corresponding @value{GDBN} configuration option is
26526 @option{--without-auto-load-safe-path}.
26527 This variable is supposed to be set to the system directories writable by the
26528 system superuser only. Users can add their source directories in init files in
26529 their home directories (@pxref{Home Directory Init File}). See also deprecated
26530 init file in the current directory
26531 (@pxref{Init File in the Current Directory during Startup}).
26532
26533 To force @value{GDBN} to load the files it declined to load in the previous
26534 example, you could use one of the following ways:
26535
26536 @table @asis
26537 @item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
26538 Specify this trusted directory (or a file) as additional component of the list.
26539 You have to specify also any existing directories displayed by
26540 by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
26541
26542 @item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
26543 Specify this directory as in the previous case but just for a single
26544 @value{GDBN} session.
26545
26546 @item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
26547 Disable auto-loading safety for a single @value{GDBN} session.
26548 This assumes all the files you debug during this @value{GDBN} session will come
26549 from trusted sources.
26550
26551 @item @kbd{./configure --without-auto-load-safe-path}
26552 During compilation of @value{GDBN} you may disable any auto-loading safety.
26553 This assumes all the files you will ever debug with this @value{GDBN} come from
26554 trusted sources.
26555 @end table
26556
26557 On the other hand you can also explicitly forbid automatic files loading which
26558 also suppresses any such warning messages:
26559
26560 @table @asis
26561 @item @kbd{gdb -iex "set auto-load no" @dots{}}
26562 You can use @value{GDBN} command-line option for a single @value{GDBN} session.
26563
26564 @item @file{~/.gdbinit}: @samp{set auto-load no}
26565 Disable auto-loading globally for the user
26566 (@pxref{Home Directory Init File}). While it is improbable, you could also
26567 use system init file instead (@pxref{System-wide configuration}).
26568 @end table
26569
26570 This setting applies to the file names as entered by user. If no entry matches
26571 @value{GDBN} tries as a last resort to also resolve all the file names into
26572 their canonical form (typically resolving symbolic links) and compare the
26573 entries again. @value{GDBN} already canonicalizes most of the filenames on its
26574 own before starting the comparison so a canonical form of directories is
26575 recommended to be entered.
26576
26577 @node Auto-loading verbose mode
26578 @subsection Displaying files tried for auto-load
26579 @cindex auto-loading verbose mode
26580
26581 For better visibility of all the file locations where you can place scripts to
26582 be auto-loaded with inferior --- or to protect yourself against accidental
26583 execution of untrusted scripts --- @value{GDBN} provides a feature for printing
26584 all the files attempted to be loaded. Both existing and non-existing files may
26585 be printed.
26586
26587 For example the list of directories from which it is safe to auto-load files
26588 (@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
26589 may not be too obvious while setting it up.
26590
26591 @smallexample
26592 (gdb) set debug auto-load on
26593 (gdb) file ~/src/t/true
26594 auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
26595 for objfile "/tmp/true".
26596 auto-load: Updating directories of "/usr:/opt".
26597 auto-load: Using directory "/usr".
26598 auto-load: Using directory "/opt".
26599 warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
26600 by your `auto-load safe-path' set to "/usr:/opt".
26601 @end smallexample
26602
26603 @table @code
26604 @anchor{set debug auto-load}
26605 @kindex set debug auto-load
26606 @item set debug auto-load [on|off]
26607 Set whether to print the filenames attempted to be auto-loaded.
26608
26609 @anchor{show debug auto-load}
26610 @kindex show debug auto-load
26611 @item show debug auto-load
26612 Show whether printing of the filenames attempted to be auto-loaded is turned
26613 on or off.
26614 @end table
26615
26616 @node Messages/Warnings
26617 @section Optional Warnings and Messages
26618
26619 @cindex verbose operation
26620 @cindex optional warnings
26621 By default, @value{GDBN} is silent about its inner workings. If you are
26622 running on a slow machine, you may want to use the @code{set verbose}
26623 command. This makes @value{GDBN} tell you when it does a lengthy
26624 internal operation, so you will not think it has crashed.
26625
26626 Currently, the messages controlled by @code{set verbose} are those
26627 which announce that the symbol table for a source file is being read;
26628 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
26629
26630 @table @code
26631 @kindex set verbose
26632 @item set verbose on
26633 Enables @value{GDBN} output of certain informational messages.
26634
26635 @item set verbose off
26636 Disables @value{GDBN} output of certain informational messages.
26637
26638 @kindex show verbose
26639 @item show verbose
26640 Displays whether @code{set verbose} is on or off.
26641 @end table
26642
26643 By default, if @value{GDBN} encounters bugs in the symbol table of an
26644 object file, it is silent; but if you are debugging a compiler, you may
26645 find this information useful (@pxref{Symbol Errors, ,Errors Reading
26646 Symbol Files}).
26647
26648 @table @code
26649
26650 @kindex set complaints
26651 @item set complaints @var{limit}
26652 Permits @value{GDBN} to output @var{limit} complaints about each type of
26653 unusual symbols before becoming silent about the problem. Set
26654 @var{limit} to zero to suppress all complaints; set it to a large number
26655 to prevent complaints from being suppressed.
26656
26657 @kindex show complaints
26658 @item show complaints
26659 Displays how many symbol complaints @value{GDBN} is permitted to produce.
26660
26661 @end table
26662
26663 @anchor{confirmation requests}
26664 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
26665 lot of stupid questions to confirm certain commands. For example, if
26666 you try to run a program which is already running:
26667
26668 @smallexample
26669 (@value{GDBP}) run
26670 The program being debugged has been started already.
26671 Start it from the beginning? (y or n)
26672 @end smallexample
26673
26674 If you are willing to unflinchingly face the consequences of your own
26675 commands, you can disable this ``feature'':
26676
26677 @table @code
26678
26679 @kindex set confirm
26680 @cindex flinching
26681 @cindex confirmation
26682 @cindex stupid questions
26683 @item set confirm off
26684 Disables confirmation requests. Note that running @value{GDBN} with
26685 the @option{--batch} option (@pxref{Mode Options, -batch}) also
26686 automatically disables confirmation requests.
26687
26688 @item set confirm on
26689 Enables confirmation requests (the default).
26690
26691 @kindex show confirm
26692 @item show confirm
26693 Displays state of confirmation requests.
26694
26695 @end table
26696
26697 @cindex command tracing
26698 If you need to debug user-defined commands or sourced files you may find it
26699 useful to enable @dfn{command tracing}. In this mode each command will be
26700 printed as it is executed, prefixed with one or more @samp{+} symbols, the
26701 quantity denoting the call depth of each command.
26702
26703 @table @code
26704 @kindex set trace-commands
26705 @cindex command scripts, debugging
26706 @item set trace-commands on
26707 Enable command tracing.
26708 @item set trace-commands off
26709 Disable command tracing.
26710 @item show trace-commands
26711 Display the current state of command tracing.
26712 @end table
26713
26714 @node Debugging Output
26715 @section Optional Messages about Internal Happenings
26716 @cindex optional debugging messages
26717
26718 @value{GDBN} has commands that enable optional debugging messages from
26719 various @value{GDBN} subsystems; normally these commands are of
26720 interest to @value{GDBN} maintainers, or when reporting a bug. This
26721 section documents those commands.
26722
26723 @table @code
26724 @kindex set exec-done-display
26725 @item set exec-done-display
26726 Turns on or off the notification of asynchronous commands'
26727 completion. When on, @value{GDBN} will print a message when an
26728 asynchronous command finishes its execution. The default is off.
26729 @kindex show exec-done-display
26730 @item show exec-done-display
26731 Displays the current setting of asynchronous command completion
26732 notification.
26733
26734 @kindex set debug
26735 @cindex ARM AArch64
26736 @item set debug aarch64
26737 Turns on or off display of debugging messages related to ARM AArch64.
26738 The default is off.
26739 @kindex show debug
26740 @item show debug aarch64
26741 Displays the current state of displaying debugging messages related to
26742 ARM AArch64.
26743
26744 @cindex gdbarch debugging info
26745 @cindex architecture debugging info
26746 @item set debug arch
26747 Turns on or off display of gdbarch debugging info. The default is off
26748 @item show debug arch
26749 Displays the current state of displaying gdbarch debugging info.
26750
26751 @item set debug aix-solib
26752 @cindex AIX shared library debugging
26753 Control display of debugging messages from the AIX shared library
26754 support module. The default is off.
26755 @item show debug aix-solib
26756 Show the current state of displaying AIX shared library debugging messages.
26757
26758 @item set debug aix-thread
26759 @cindex AIX threads
26760 Display debugging messages about inner workings of the AIX thread
26761 module.
26762 @item show debug aix-thread
26763 Show the current state of AIX thread debugging info display.
26764
26765 @item set debug check-physname
26766 @cindex physname
26767 Check the results of the ``physname'' computation. When reading DWARF
26768 debugging information for C@t{++}, @value{GDBN} attempts to compute
26769 each entity's name. @value{GDBN} can do this computation in two
26770 different ways, depending on exactly what information is present.
26771 When enabled, this setting causes @value{GDBN} to compute the names
26772 both ways and display any discrepancies.
26773 @item show debug check-physname
26774 Show the current state of ``physname'' checking.
26775
26776 @item set debug coff-pe-read
26777 @cindex COFF/PE exported symbols
26778 Control display of debugging messages related to reading of COFF/PE
26779 exported symbols. The default is off.
26780 @item show debug coff-pe-read
26781 Displays the current state of displaying debugging messages related to
26782 reading of COFF/PE exported symbols.
26783
26784 @item set debug dwarf-die
26785 @cindex DWARF DIEs
26786 Dump DWARF DIEs after they are read in.
26787 The value is the number of nesting levels to print.
26788 A value of zero turns off the display.
26789 @item show debug dwarf-die
26790 Show the current state of DWARF DIE debugging.
26791
26792 @item set debug dwarf-line
26793 @cindex DWARF Line Tables
26794 Turns on or off display of debugging messages related to reading
26795 DWARF line tables. The default is 0 (off).
26796 A value of 1 provides basic information.
26797 A value greater than 1 provides more verbose information.
26798 @item show debug dwarf-line
26799 Show the current state of DWARF line table debugging.
26800
26801 @item set debug dwarf-read
26802 @cindex DWARF Reading
26803 Turns on or off display of debugging messages related to reading
26804 DWARF debug info. The default is 0 (off).
26805 A value of 1 provides basic information.
26806 A value greater than 1 provides more verbose information.
26807 @item show debug dwarf-read
26808 Show the current state of DWARF reader debugging.
26809
26810 @item set debug displaced
26811 @cindex displaced stepping debugging info
26812 Turns on or off display of @value{GDBN} debugging info for the
26813 displaced stepping support. The default is off.
26814 @item show debug displaced
26815 Displays the current state of displaying @value{GDBN} debugging info
26816 related to displaced stepping.
26817
26818 @item set debug event
26819 @cindex event debugging info
26820 Turns on or off display of @value{GDBN} event debugging info. The
26821 default is off.
26822 @item show debug event
26823 Displays the current state of displaying @value{GDBN} event debugging
26824 info.
26825
26826 @item set debug event-loop
26827 @cindex event-loop debugging
26828 Controls output of debugging info about the event loop. The possible
26829 values are @samp{off}, @samp{all} (shows all debugging info) and
26830 @samp{all-except-ui} (shows all debugging info except those about
26831 UI-related events).
26832 @item show debug event-loop
26833 Shows the current state of displaying debugging info about the event
26834 loop.
26835
26836 @item set debug expression
26837 @cindex expression debugging info
26838 Turns on or off display of debugging info about @value{GDBN}
26839 expression parsing. The default is off.
26840 @item show debug expression
26841 Displays the current state of displaying debugging info about
26842 @value{GDBN} expression parsing.
26843
26844 @item set debug fbsd-lwp
26845 @cindex FreeBSD LWP debug messages
26846 Turns on or off debugging messages from the FreeBSD LWP debug support.
26847 @item show debug fbsd-lwp
26848 Show the current state of FreeBSD LWP debugging messages.
26849
26850 @item set debug fbsd-nat
26851 @cindex FreeBSD native target debug messages
26852 Turns on or off debugging messages from the FreeBSD native target.
26853 @item show debug fbsd-nat
26854 Show the current state of FreeBSD native target debugging messages.
26855
26856 @item set debug fortran-array-slicing
26857 @cindex fortran array slicing debugging info
26858 Turns on or off display of @value{GDBN} Fortran array slicing
26859 debugging info. The default is off.
26860
26861 @item show debug fortran-array-slicing
26862 Displays the current state of displaying @value{GDBN} Fortran array
26863 slicing debugging info.
26864
26865 @item set debug frame
26866 @cindex frame debugging info
26867 Turns on or off display of @value{GDBN} frame debugging info. The
26868 default is off.
26869 @item show debug frame
26870 Displays the current state of displaying @value{GDBN} frame debugging
26871 info.
26872
26873 @item set debug gnu-nat
26874 @cindex @sc{gnu}/Hurd debug messages
26875 Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
26876 @item show debug gnu-nat
26877 Show the current state of @sc{gnu}/Hurd debugging messages.
26878
26879 @item set debug infrun
26880 @cindex inferior debugging info
26881 Turns on or off display of @value{GDBN} debugging info for running the inferior.
26882 The default is off. @file{infrun.c} contains GDB's runtime state machine used
26883 for implementing operations such as single-stepping the inferior.
26884 @item show debug infrun
26885 Displays the current state of @value{GDBN} inferior debugging.
26886
26887 @item set debug jit
26888 @cindex just-in-time compilation, debugging messages
26889 Turn on or off debugging messages from JIT debug support.
26890 @item show debug jit
26891 Displays the current state of @value{GDBN} JIT debugging.
26892
26893 @item set debug lin-lwp
26894 @cindex @sc{gnu}/Linux LWP debug messages
26895 @cindex Linux lightweight processes
26896 Turn on or off debugging messages from the Linux LWP debug support.
26897 @item show debug lin-lwp
26898 Show the current state of Linux LWP debugging messages.
26899
26900 @item set debug linux-namespaces
26901 @cindex @sc{gnu}/Linux namespaces debug messages
26902 Turn on or off debugging messages from the Linux namespaces debug support.
26903 @item show debug linux-namespaces
26904 Show the current state of Linux namespaces debugging messages.
26905
26906 @item set debug mach-o
26907 @cindex Mach-O symbols processing
26908 Control display of debugging messages related to Mach-O symbols
26909 processing. The default is off.
26910 @item show debug mach-o
26911 Displays the current state of displaying debugging messages related to
26912 reading of COFF/PE exported symbols.
26913
26914 @item set debug notification
26915 @cindex remote async notification debugging info
26916 Turn on or off debugging messages about remote async notification.
26917 The default is off.
26918 @item show debug notification
26919 Displays the current state of remote async notification debugging messages.
26920
26921 @item set debug observer
26922 @cindex observer debugging info
26923 Turns on or off display of @value{GDBN} observer debugging. This
26924 includes info such as the notification of observable events.
26925 @item show debug observer
26926 Displays the current state of observer debugging.
26927
26928 @item set debug overload
26929 @cindex C@t{++} overload debugging info
26930 Turns on or off display of @value{GDBN} C@t{++} overload debugging
26931 info. This includes info such as ranking of functions, etc. The default
26932 is off.
26933 @item show debug overload
26934 Displays the current state of displaying @value{GDBN} C@t{++} overload
26935 debugging info.
26936
26937 @cindex expression parser, debugging info
26938 @cindex debug expression parser
26939 @item set debug parser
26940 Turns on or off the display of expression parser debugging output.
26941 Internally, this sets the @code{yydebug} variable in the expression
26942 parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
26943 details. The default is off.
26944 @item show debug parser
26945 Show the current state of expression parser debugging.
26946
26947 @cindex packets, reporting on stdout
26948 @cindex serial connections, debugging
26949 @cindex debug remote protocol
26950 @cindex remote protocol debugging
26951 @cindex display remote packets
26952 @item set debug remote
26953 Turns on or off display of reports on all packets sent back and forth across
26954 the serial line to the remote machine. The info is printed on the
26955 @value{GDBN} standard output stream. The default is off.
26956 @item show debug remote
26957 Displays the state of display of remote packets.
26958
26959 @item set debug remote-packet-max-chars
26960 Sets the maximum number of characters to display for each remote packet when
26961 @code{set debug remote} is on. This is useful to prevent @value{GDBN} from
26962 displaying lengthy remote packets and polluting the console.
26963
26964 The default value is @code{512}, which means @value{GDBN} will truncate each
26965 remote packet after 512 bytes.
26966
26967 Setting this option to @code{unlimited} will disable truncation and will output
26968 the full length of the remote packets.
26969 @item show debug remote-packet-max-chars
26970 Displays the number of bytes to output for remote packet debugging.
26971
26972 @item set debug separate-debug-file
26973 Turns on or off display of debug output about separate debug file search.
26974 @item show debug separate-debug-file
26975 Displays the state of separate debug file search debug output.
26976
26977 @item set debug serial
26978 Turns on or off display of @value{GDBN} serial debugging info. The
26979 default is off.
26980 @item show debug serial
26981 Displays the current state of displaying @value{GDBN} serial debugging
26982 info.
26983
26984 @item set debug solib-frv
26985 @cindex FR-V shared-library debugging
26986 Turn on or off debugging messages for FR-V shared-library code.
26987 @item show debug solib-frv
26988 Display the current state of FR-V shared-library code debugging
26989 messages.
26990
26991 @item set debug symbol-lookup
26992 @cindex symbol lookup
26993 Turns on or off display of debugging messages related to symbol lookup.
26994 The default is 0 (off).
26995 A value of 1 provides basic information.
26996 A value greater than 1 provides more verbose information.
26997 @item show debug symbol-lookup
26998 Show the current state of symbol lookup debugging messages.
26999
27000 @item set debug symfile
27001 @cindex symbol file functions
27002 Turns on or off display of debugging messages related to symbol file functions.
27003 The default is off. @xref{Files}.
27004 @item show debug symfile
27005 Show the current state of symbol file debugging messages.
27006
27007 @item set debug symtab-create
27008 @cindex symbol table creation
27009 Turns on or off display of debugging messages related to symbol table creation.
27010 The default is 0 (off).
27011 A value of 1 provides basic information.
27012 A value greater than 1 provides more verbose information.
27013 @item show debug symtab-create
27014 Show the current state of symbol table creation debugging.
27015
27016 @item set debug target
27017 @cindex target debugging info
27018 Turns on or off display of @value{GDBN} target debugging info. This info
27019 includes what is going on at the target level of GDB, as it happens. The
27020 default is 0. Set it to 1 to track events, and to 2 to also track the
27021 value of large memory transfers.
27022 @item show debug target
27023 Displays the current state of displaying @value{GDBN} target debugging
27024 info.
27025
27026 @item set debug timestamp
27027 @cindex timestamping debugging info
27028 Turns on or off display of timestamps with @value{GDBN} debugging info.
27029 When enabled, seconds and microseconds are displayed before each debugging
27030 message.
27031 @item show debug timestamp
27032 Displays the current state of displaying timestamps with @value{GDBN}
27033 debugging info.
27034
27035 @item set debug varobj
27036 @cindex variable object debugging info
27037 Turns on or off display of @value{GDBN} variable object debugging
27038 info. The default is off.
27039 @item show debug varobj
27040 Displays the current state of displaying @value{GDBN} variable object
27041 debugging info.
27042
27043 @item set debug xml
27044 @cindex XML parser debugging
27045 Turn on or off debugging messages for built-in XML parsers.
27046 @item show debug xml
27047 Displays the current state of XML debugging messages.
27048 @end table
27049
27050 @node Other Misc Settings
27051 @section Other Miscellaneous Settings
27052 @cindex miscellaneous settings
27053
27054 @table @code
27055 @kindex set interactive-mode
27056 @item set interactive-mode
27057 If @code{on}, forces @value{GDBN} to assume that GDB was started
27058 in a terminal. In practice, this means that @value{GDBN} should wait
27059 for the user to answer queries generated by commands entered at
27060 the command prompt. If @code{off}, forces @value{GDBN} to operate
27061 in the opposite mode, and it uses the default answers to all queries.
27062 If @code{auto} (the default), @value{GDBN} tries to determine whether
27063 its standard input is a terminal, and works in interactive-mode if it
27064 is, non-interactively otherwise.
27065
27066 In the vast majority of cases, the debugger should be able to guess
27067 correctly which mode should be used. But this setting can be useful
27068 in certain specific cases, such as running a MinGW @value{GDBN}
27069 inside a cygwin window.
27070
27071 @kindex show interactive-mode
27072 @item show interactive-mode
27073 Displays whether the debugger is operating in interactive mode or not.
27074 @end table
27075
27076 @node Extending GDB
27077 @chapter Extending @value{GDBN}
27078 @cindex extending GDB
27079
27080 @value{GDBN} provides several mechanisms for extension.
27081 @value{GDBN} also provides the ability to automatically load
27082 extensions when it reads a file for debugging. This allows the
27083 user to automatically customize @value{GDBN} for the program
27084 being debugged.
27085
27086 To facilitate the use of extension languages, @value{GDBN} is capable
27087 of evaluating the contents of a file. When doing so, @value{GDBN}
27088 can recognize which extension language is being used by looking at
27089 the filename extension. Files with an unrecognized filename extension
27090 are always treated as a @value{GDBN} Command Files.
27091 @xref{Command Files,, Command files}.
27092
27093 You can control how @value{GDBN} evaluates these files with the following
27094 setting:
27095
27096 @table @code
27097 @kindex set script-extension
27098 @kindex show script-extension
27099 @item set script-extension off
27100 All scripts are always evaluated as @value{GDBN} Command Files.
27101
27102 @item set script-extension soft
27103 The debugger determines the scripting language based on filename
27104 extension. If this scripting language is supported, @value{GDBN}
27105 evaluates the script using that language. Otherwise, it evaluates
27106 the file as a @value{GDBN} Command File.
27107
27108 @item set script-extension strict
27109 The debugger determines the scripting language based on filename
27110 extension, and evaluates the script using that language. If the
27111 language is not supported, then the evaluation fails.
27112
27113 @item show script-extension
27114 Display the current value of the @code{script-extension} option.
27115
27116 @end table
27117
27118 @ifset SYSTEM_GDBINIT_DIR
27119 This setting is not used for files in the system-wide gdbinit directory.
27120 Files in that directory must have an extension matching their language,
27121 or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
27122 commands. @xref{Startup}.
27123 @end ifset
27124
27125 @menu
27126 * Sequences:: Canned Sequences of @value{GDBN} Commands
27127 * Aliases:: Command Aliases
27128 * Python:: Extending @value{GDBN} using Python
27129 * Guile:: Extending @value{GDBN} using Guile
27130 * Auto-loading extensions:: Automatically loading extensions
27131 * Multiple Extension Languages:: Working with multiple extension languages
27132 @end menu
27133
27134 @node Sequences
27135 @section Canned Sequences of Commands
27136
27137 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
27138 Command Lists}), @value{GDBN} provides two ways to store sequences of
27139 commands for execution as a unit: user-defined commands and command
27140 files.
27141
27142 @menu
27143 * Define:: How to define your own commands
27144 * Hooks:: Hooks for user-defined commands
27145 * Command Files:: How to write scripts of commands to be stored in a file
27146 * Output:: Commands for controlled output
27147 * Auto-loading sequences:: Controlling auto-loaded command files
27148 @end menu
27149
27150 @node Define
27151 @subsection User-defined Commands
27152
27153 @cindex user-defined command
27154 @cindex arguments, to user-defined commands
27155 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
27156 which you assign a new name as a command. This is done with the
27157 @code{define} command. User commands may accept an unlimited number of arguments
27158 separated by whitespace. Arguments are accessed within the user command
27159 via @code{$arg0@dots{}$argN}. A trivial example:
27160
27161 @smallexample
27162 define adder
27163 print $arg0 + $arg1 + $arg2
27164 end
27165 @end smallexample
27166
27167 @noindent
27168 To execute the command use:
27169
27170 @smallexample
27171 adder 1 2 3
27172 @end smallexample
27173
27174 @noindent
27175 This defines the command @code{adder}, which prints the sum of
27176 its three arguments. Note the arguments are text substitutions, so they may
27177 reference variables, use complex expressions, or even perform inferior
27178 functions calls.
27179
27180 @cindex argument count in user-defined commands
27181 @cindex how many arguments (user-defined commands)
27182 In addition, @code{$argc} may be used to find out how many arguments have
27183 been passed.
27184
27185 @smallexample
27186 define adder
27187 if $argc == 2
27188 print $arg0 + $arg1
27189 end
27190 if $argc == 3
27191 print $arg0 + $arg1 + $arg2
27192 end
27193 end
27194 @end smallexample
27195
27196 Combining with the @code{eval} command (@pxref{eval}) makes it easier
27197 to process a variable number of arguments:
27198
27199 @smallexample
27200 define adder
27201 set $i = 0
27202 set $sum = 0
27203 while $i < $argc
27204 eval "set $sum = $sum + $arg%d", $i
27205 set $i = $i + 1
27206 end
27207 print $sum
27208 end
27209 @end smallexample
27210
27211 @table @code
27212
27213 @kindex define
27214 @item define @var{commandname}
27215 Define a command named @var{commandname}. If there is already a command
27216 by that name, you are asked to confirm that you want to redefine it.
27217 The argument @var{commandname} may be a bare command name consisting of letters,
27218 numbers, dashes, dots, and underscores. It may also start with any
27219 predefined or user-defined prefix command.
27220 For example, @samp{define target my-target} creates
27221 a user-defined @samp{target my-target} command.
27222
27223 The definition of the command is made up of other @value{GDBN} command lines,
27224 which are given following the @code{define} command. The end of these
27225 commands is marked by a line containing @code{end}.
27226
27227 @kindex document
27228 @kindex end@r{ (user-defined commands)}
27229 @item document @var{commandname}
27230 Document the user-defined command @var{commandname}, so that it can be
27231 accessed by @code{help}. The command @var{commandname} must already be
27232 defined. This command reads lines of documentation just as @code{define}
27233 reads the lines of the command definition, ending with @code{end}.
27234 After the @code{document} command is finished, @code{help} on command
27235 @var{commandname} displays the documentation you have written.
27236
27237 You may use the @code{document} command again to change the
27238 documentation of a command. Redefining the command with @code{define}
27239 does not change the documentation.
27240
27241 @kindex define-prefix
27242 @item define-prefix @var{commandname}
27243 Define or mark the command @var{commandname} as a user-defined prefix
27244 command. Once marked, @var{commandname} can be used as prefix command
27245 by the @code{define} command.
27246 Note that @code{define-prefix} can be used with a not yet defined
27247 @var{commandname}. In such a case, @var{commandname} is defined as
27248 an empty user-defined command.
27249 In case you redefine a command that was marked as a user-defined
27250 prefix command, the subcommands of the redefined command are kept
27251 (and @value{GDBN} indicates so to the user).
27252
27253 Example:
27254 @example
27255 (gdb) define-prefix abc
27256 (gdb) define-prefix abc def
27257 (gdb) define abc def
27258 Type commands for definition of "abc def".
27259 End with a line saying just "end".
27260 >echo command initial def\n
27261 >end
27262 (gdb) define abc def ghi
27263 Type commands for definition of "abc def ghi".
27264 End with a line saying just "end".
27265 >echo command ghi\n
27266 >end
27267 (gdb) define abc def
27268 Keeping subcommands of prefix command "def".
27269 Redefine command "def"? (y or n) y
27270 Type commands for definition of "abc def".
27271 End with a line saying just "end".
27272 >echo command def\n
27273 >end
27274 (gdb) abc def ghi
27275 command ghi
27276 (gdb) abc def
27277 command def
27278 (gdb)
27279 @end example
27280
27281 @kindex dont-repeat
27282 @cindex don't repeat command
27283 @item dont-repeat
27284 Used inside a user-defined command, this tells @value{GDBN} that this
27285 command should not be repeated when the user hits @key{RET}
27286 (@pxref{Command Syntax, repeat last command}).
27287
27288 @kindex help user-defined
27289 @item help user-defined
27290 List all user-defined commands and all python commands defined in class
27291 COMMAND_USER. The first line of the documentation or docstring is
27292 included (if any).
27293
27294 @kindex show user
27295 @item show user
27296 @itemx show user @var{commandname}
27297 Display the @value{GDBN} commands used to define @var{commandname} (but
27298 not its documentation). If no @var{commandname} is given, display the
27299 definitions for all user-defined commands.
27300 This does not work for user-defined python commands.
27301
27302 @cindex infinite recursion in user-defined commands
27303 @kindex show max-user-call-depth
27304 @kindex set max-user-call-depth
27305 @item show max-user-call-depth
27306 @itemx set max-user-call-depth
27307 The value of @code{max-user-call-depth} controls how many recursion
27308 levels are allowed in user-defined commands before @value{GDBN} suspects an
27309 infinite recursion and aborts the command.
27310 This does not apply to user-defined python commands.
27311 @end table
27312
27313 In addition to the above commands, user-defined commands frequently
27314 use control flow commands, described in @ref{Command Files}.
27315
27316 When user-defined commands are executed, the
27317 commands of the definition are not printed. An error in any command
27318 stops execution of the user-defined command.
27319
27320 If used interactively, commands that would ask for confirmation proceed
27321 without asking when used inside a user-defined command. Many @value{GDBN}
27322 commands that normally print messages to say what they are doing omit the
27323 messages when used in a user-defined command.
27324
27325 @node Hooks
27326 @subsection User-defined Command Hooks
27327 @cindex command hooks
27328 @cindex hooks, for commands
27329 @cindex hooks, pre-command
27330
27331 @kindex hook
27332 You may define @dfn{hooks}, which are a special kind of user-defined
27333 command. Whenever you run the command @samp{foo}, if the user-defined
27334 command @samp{hook-foo} exists, it is executed (with no arguments)
27335 before that command.
27336
27337 @cindex hooks, post-command
27338 @kindex hookpost
27339 A hook may also be defined which is run after the command you executed.
27340 Whenever you run the command @samp{foo}, if the user-defined command
27341 @samp{hookpost-foo} exists, it is executed (with no arguments) after
27342 that command. Post-execution hooks may exist simultaneously with
27343 pre-execution hooks, for the same command.
27344
27345 It is valid for a hook to call the command which it hooks. If this
27346 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
27347
27348 @c It would be nice if hookpost could be passed a parameter indicating
27349 @c if the command it hooks executed properly or not. FIXME!
27350
27351 @kindex stop@r{, a pseudo-command}
27352 In addition, a pseudo-command, @samp{stop} exists. Defining
27353 (@samp{hook-stop}) makes the associated commands execute every time
27354 execution stops in your program: before breakpoint commands are run,
27355 displays are printed, or the stack frame is printed.
27356
27357 For example, to ignore @code{SIGALRM} signals while
27358 single-stepping, but treat them normally during normal execution,
27359 you could define:
27360
27361 @smallexample
27362 define hook-stop
27363 handle SIGALRM nopass
27364 end
27365
27366 define hook-run
27367 handle SIGALRM pass
27368 end
27369
27370 define hook-continue
27371 handle SIGALRM pass
27372 end
27373 @end smallexample
27374
27375 As a further example, to hook at the beginning and end of the @code{echo}
27376 command, and to add extra text to the beginning and end of the message,
27377 you could define:
27378
27379 @smallexample
27380 define hook-echo
27381 echo <<<---
27382 end
27383
27384 define hookpost-echo
27385 echo --->>>\n
27386 end
27387
27388 (@value{GDBP}) echo Hello World
27389 <<<---Hello World--->>>
27390 (@value{GDBP})
27391
27392 @end smallexample
27393
27394 You can define a hook for any single-word command in @value{GDBN}, but
27395 not for command aliases; you should define a hook for the basic command
27396 name, e.g.@: @code{backtrace} rather than @code{bt}.
27397 @c FIXME! So how does Joe User discover whether a command is an alias
27398 @c or not?
27399 You can hook a multi-word command by adding @code{hook-} or
27400 @code{hookpost-} to the last word of the command, e.g.@:
27401 @samp{define target hook-remote} to add a hook to @samp{target remote}.
27402
27403 If an error occurs during the execution of your hook, execution of
27404 @value{GDBN} commands stops and @value{GDBN} issues a prompt
27405 (before the command that you actually typed had a chance to run).
27406
27407 If you try to define a hook which does not match any known command, you
27408 get a warning from the @code{define} command.
27409
27410 @node Command Files
27411 @subsection Command Files
27412
27413 @cindex command files
27414 @cindex scripting commands
27415 A command file for @value{GDBN} is a text file made of lines that are
27416 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
27417 also be included. An empty line in a command file does nothing; it
27418 does not mean to repeat the last command, as it would from the
27419 terminal.
27420
27421 You can request the execution of a command file with the @code{source}
27422 command. Note that the @code{source} command is also used to evaluate
27423 scripts that are not Command Files. The exact behavior can be configured
27424 using the @code{script-extension} setting.
27425 @xref{Extending GDB,, Extending GDB}.
27426
27427 @table @code
27428 @kindex source
27429 @cindex execute commands from a file
27430 @item source [-s] [-v] @var{filename}
27431 Execute the command file @var{filename}.
27432 @end table
27433
27434 The lines in a command file are generally executed sequentially,
27435 unless the order of execution is changed by one of the
27436 @emph{flow-control commands} described below. The commands are not
27437 printed as they are executed. An error in any command terminates
27438 execution of the command file and control is returned to the console.
27439
27440 @value{GDBN} first searches for @var{filename} in the current directory.
27441 If the file is not found there, and @var{filename} does not specify a
27442 directory, then @value{GDBN} also looks for the file on the source search path
27443 (specified with the @samp{directory} command);
27444 except that @file{$cdir} is not searched because the compilation directory
27445 is not relevant to scripts.
27446
27447 If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
27448 on the search path even if @var{filename} specifies a directory.
27449 The search is done by appending @var{filename} to each element of the
27450 search path. So, for example, if @var{filename} is @file{mylib/myscript}
27451 and the search path contains @file{/home/user} then @value{GDBN} will
27452 look for the script @file{/home/user/mylib/myscript}.
27453 The search is also done if @var{filename} is an absolute path.
27454 For example, if @var{filename} is @file{/tmp/myscript} and
27455 the search path contains @file{/home/user} then @value{GDBN} will
27456 look for the script @file{/home/user/tmp/myscript}.
27457 For DOS-like systems, if @var{filename} contains a drive specification,
27458 it is stripped before concatenation. For example, if @var{filename} is
27459 @file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
27460 will look for the script @file{c:/tmp/myscript}.
27461
27462 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
27463 each command as it is executed. The option must be given before
27464 @var{filename}, and is interpreted as part of the filename anywhere else.
27465
27466 Commands that would ask for confirmation if used interactively proceed
27467 without asking when used in a command file. Many @value{GDBN} commands that
27468 normally print messages to say what they are doing omit the messages
27469 when called from command files.
27470
27471 @value{GDBN} also accepts command input from standard input. In this
27472 mode, normal output goes to standard output and error output goes to
27473 standard error. Errors in a command file supplied on standard input do
27474 not terminate execution of the command file---execution continues with
27475 the next command.
27476
27477 @smallexample
27478 gdb < cmds > log 2>&1
27479 @end smallexample
27480
27481 (The syntax above will vary depending on the shell used.) This example
27482 will execute commands from the file @file{cmds}. All output and errors
27483 would be directed to @file{log}.
27484
27485 Since commands stored on command files tend to be more general than
27486 commands typed interactively, they frequently need to deal with
27487 complicated situations, such as different or unexpected values of
27488 variables and symbols, changes in how the program being debugged is
27489 built, etc. @value{GDBN} provides a set of flow-control commands to
27490 deal with these complexities. Using these commands, you can write
27491 complex scripts that loop over data structures, execute commands
27492 conditionally, etc.
27493
27494 @table @code
27495 @kindex if
27496 @kindex else
27497 @item if
27498 @itemx else
27499 This command allows to include in your script conditionally executed
27500 commands. The @code{if} command takes a single argument, which is an
27501 expression to evaluate. It is followed by a series of commands that
27502 are executed only if the expression is true (its value is nonzero).
27503 There can then optionally be an @code{else} line, followed by a series
27504 of commands that are only executed if the expression was false. The
27505 end of the list is marked by a line containing @code{end}.
27506
27507 @kindex while
27508 @item while
27509 This command allows to write loops. Its syntax is similar to
27510 @code{if}: the command takes a single argument, which is an expression
27511 to evaluate, and must be followed by the commands to execute, one per
27512 line, terminated by an @code{end}. These commands are called the
27513 @dfn{body} of the loop. The commands in the body of @code{while} are
27514 executed repeatedly as long as the expression evaluates to true.
27515
27516 @kindex loop_break
27517 @item loop_break
27518 This command exits the @code{while} loop in whose body it is included.
27519 Execution of the script continues after that @code{while}s @code{end}
27520 line.
27521
27522 @kindex loop_continue
27523 @item loop_continue
27524 This command skips the execution of the rest of the body of commands
27525 in the @code{while} loop in whose body it is included. Execution
27526 branches to the beginning of the @code{while} loop, where it evaluates
27527 the controlling expression.
27528
27529 @kindex end@r{ (if/else/while commands)}
27530 @item end
27531 Terminate the block of commands that are the body of @code{if},
27532 @code{else}, or @code{while} flow-control commands.
27533 @end table
27534
27535
27536 @node Output
27537 @subsection Commands for Controlled Output
27538
27539 During the execution of a command file or a user-defined command, normal
27540 @value{GDBN} output is suppressed; the only output that appears is what is
27541 explicitly printed by the commands in the definition. This section
27542 describes three commands useful for generating exactly the output you
27543 want.
27544
27545 @table @code
27546 @kindex echo
27547 @item echo @var{text}
27548 @c I do not consider backslash-space a standard C escape sequence
27549 @c because it is not in ANSI.
27550 Print @var{text}. Nonprinting characters can be included in
27551 @var{text} using C escape sequences, such as @samp{\n} to print a
27552 newline. @strong{No newline is printed unless you specify one.}
27553 In addition to the standard C escape sequences, a backslash followed
27554 by a space stands for a space. This is useful for displaying a
27555 string with spaces at the beginning or the end, since leading and
27556 trailing spaces are otherwise trimmed from all arguments.
27557 To print @samp{@w{ }and foo =@w{ }}, use the command
27558 @samp{echo \@w{ }and foo = \@w{ }}.
27559
27560 A backslash at the end of @var{text} can be used, as in C, to continue
27561 the command onto subsequent lines. For example,
27562
27563 @smallexample
27564 echo This is some text\n\
27565 which is continued\n\
27566 onto several lines.\n
27567 @end smallexample
27568
27569 produces the same output as
27570
27571 @smallexample
27572 echo This is some text\n
27573 echo which is continued\n
27574 echo onto several lines.\n
27575 @end smallexample
27576
27577 @kindex output
27578 @item output @var{expression}
27579 Print the value of @var{expression} and nothing but that value: no
27580 newlines, no @samp{$@var{nn} = }. The value is not entered in the
27581 value history either. @xref{Expressions, ,Expressions}, for more information
27582 on expressions.
27583
27584 @item output/@var{fmt} @var{expression}
27585 Print the value of @var{expression} in format @var{fmt}. You can use
27586 the same formats as for @code{print}. @xref{Output Formats,,Output
27587 Formats}, for more information.
27588
27589 @kindex printf
27590 @item printf @var{template}, @var{expressions}@dots{}
27591 Print the values of one or more @var{expressions} under the control of
27592 the string @var{template}. To print several values, make
27593 @var{expressions} be a comma-separated list of individual expressions,
27594 which may be either numbers or pointers. Their values are printed as
27595 specified by @var{template}, exactly as a C program would do by
27596 executing the code below:
27597
27598 @smallexample
27599 printf (@var{template}, @var{expressions}@dots{});
27600 @end smallexample
27601
27602 As in @code{C} @code{printf}, ordinary characters in @var{template}
27603 are printed verbatim, while @dfn{conversion specification} introduced
27604 by the @samp{%} character cause subsequent @var{expressions} to be
27605 evaluated, their values converted and formatted according to type and
27606 style information encoded in the conversion specifications, and then
27607 printed.
27608
27609 For example, you can print two values in hex like this:
27610
27611 @smallexample
27612 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
27613 @end smallexample
27614
27615 @code{printf} supports all the standard @code{C} conversion
27616 specifications, including the flags and modifiers between the @samp{%}
27617 character and the conversion letter, with the following exceptions:
27618
27619 @itemize @bullet
27620 @item
27621 The argument-ordering modifiers, such as @samp{2$}, are not supported.
27622
27623 @item
27624 The modifier @samp{*} is not supported for specifying precision or
27625 width.
27626
27627 @item
27628 The @samp{'} flag (for separation of digits into groups according to
27629 @code{LC_NUMERIC'}) is not supported.
27630
27631 @item
27632 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
27633 supported.
27634
27635 @item
27636 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
27637
27638 @item
27639 The conversion letters @samp{a} and @samp{A} are not supported.
27640 @end itemize
27641
27642 @noindent
27643 Note that the @samp{ll} type modifier is supported only if the
27644 underlying @code{C} implementation used to build @value{GDBN} supports
27645 the @code{long long int} type, and the @samp{L} type modifier is
27646 supported only if @code{long double} type is available.
27647
27648 As in @code{C}, @code{printf} supports simple backslash-escape
27649 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
27650 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
27651 single character. Octal and hexadecimal escape sequences are not
27652 supported.
27653
27654 Additionally, @code{printf} supports conversion specifications for DFP
27655 (@dfn{Decimal Floating Point}) types using the following length modifiers
27656 together with a floating point specifier.
27657 letters:
27658
27659 @itemize @bullet
27660 @item
27661 @samp{H} for printing @code{Decimal32} types.
27662
27663 @item
27664 @samp{D} for printing @code{Decimal64} types.
27665
27666 @item
27667 @samp{DD} for printing @code{Decimal128} types.
27668 @end itemize
27669
27670 If the underlying @code{C} implementation used to build @value{GDBN} has
27671 support for the three length modifiers for DFP types, other modifiers
27672 such as width and precision will also be available for @value{GDBN} to use.
27673
27674 In case there is no such @code{C} support, no additional modifiers will be
27675 available and the value will be printed in the standard way.
27676
27677 Here's an example of printing DFP types using the above conversion letters:
27678 @smallexample
27679 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
27680 @end smallexample
27681
27682 @anchor{eval}
27683 @kindex eval
27684 @item eval @var{template}, @var{expressions}@dots{}
27685 Convert the values of one or more @var{expressions} under the control of
27686 the string @var{template} to a command line, and call it.
27687
27688 @end table
27689
27690 @node Auto-loading sequences
27691 @subsection Controlling auto-loading native @value{GDBN} scripts
27692 @cindex native script auto-loading
27693
27694 When a new object file is read (for example, due to the @code{file}
27695 command, or because the inferior has loaded a shared library),
27696 @value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
27697 @xref{Auto-loading extensions}.
27698
27699 Auto-loading can be enabled or disabled,
27700 and the list of auto-loaded scripts can be printed.
27701
27702 @table @code
27703 @anchor{set auto-load gdb-scripts}
27704 @kindex set auto-load gdb-scripts
27705 @item set auto-load gdb-scripts [on|off]
27706 Enable or disable the auto-loading of canned sequences of commands scripts.
27707
27708 @anchor{show auto-load gdb-scripts}
27709 @kindex show auto-load gdb-scripts
27710 @item show auto-load gdb-scripts
27711 Show whether auto-loading of canned sequences of commands scripts is enabled or
27712 disabled.
27713
27714 @anchor{info auto-load gdb-scripts}
27715 @kindex info auto-load gdb-scripts
27716 @cindex print list of auto-loaded canned sequences of commands scripts
27717 @item info auto-load gdb-scripts [@var{regexp}]
27718 Print the list of all canned sequences of commands scripts that @value{GDBN}
27719 auto-loaded.
27720 @end table
27721
27722 If @var{regexp} is supplied only canned sequences of commands scripts with
27723 matching names are printed.
27724
27725 @node Aliases
27726 @section Command Aliases
27727 @cindex aliases for commands
27728
27729 Aliases allow you to define alternate spellings for existing commands.
27730 For example, if a new @value{GDBN} command defined in Python
27731 (@pxref{Python}) has a long name, it is handy to have an abbreviated
27732 version of it that involves less typing.
27733
27734 @value{GDBN} itself uses aliases. For example @samp{s} is an alias
27735 of the @samp{step} command even though it is otherwise an ambiguous
27736 abbreviation of other commands like @samp{set} and @samp{show}.
27737
27738 Aliases are also used to provide shortened or more common versions
27739 of multi-word commands. For example, @value{GDBN} provides the
27740 @samp{tty} alias of the @samp{set inferior-tty} command.
27741
27742 You can define a new alias with the @samp{alias} command.
27743
27744 @table @code
27745
27746 @kindex alias
27747 @item alias [-a] [--] @var{alias} = @var{command} [@var{default-args}]
27748
27749 @end table
27750
27751 @var{alias} specifies the name of the new alias. Each word of
27752 @var{alias} must consist of letters, numbers, dashes and underscores.
27753
27754 @var{command} specifies the name of an existing command
27755 that is being aliased.
27756
27757 @var{command} can also be the name of an existing alias. In this
27758 case, @var{command} cannot be an alias that has default arguments.
27759
27760 The @samp{-a} option specifies that the new alias is an abbreviation
27761 of the command. Abbreviations are not used in command completion.
27762
27763 The @samp{--} option specifies the end of options,
27764 and is useful when @var{alias} begins with a dash.
27765
27766 You can specify @var{default-args} for your alias. These
27767 @var{default-args} will be automatically added before the alias
27768 arguments typed explicitly on the command line.
27769
27770 For example, the below defines an alias @code{btfullall} that shows all local
27771 variables and all frame arguments:
27772 @smallexample
27773 (@value{GDBP}) alias btfullall = backtrace -full -frame-arguments all
27774 @end smallexample
27775
27776 For more information about @var{default-args}, see @ref{Command
27777 aliases default args, ,Default Arguments}.
27778
27779 Here is a simple example showing how to make an abbreviation of a
27780 command so that there is less to type. Suppose you were tired of
27781 typing @samp{disas}, the current shortest unambiguous abbreviation of
27782 the @samp{disassemble} command and you wanted an even shorter version
27783 named @samp{di}. The following will accomplish this.
27784
27785 @smallexample
27786 (gdb) alias -a di = disas
27787 @end smallexample
27788
27789 Note that aliases are different from user-defined commands. With a
27790 user-defined command, you also need to write documentation for it with
27791 the @samp{document} command. An alias automatically picks up the
27792 documentation of the existing command.
27793
27794 Here is an example where we make @samp{elms} an abbreviation of
27795 @samp{elements} in the @samp{set print elements} command.
27796 This is to show that you can make an abbreviation of any part
27797 of a command.
27798
27799 @smallexample
27800 (gdb) alias -a set print elms = set print elements
27801 (gdb) alias -a show print elms = show print elements
27802 (gdb) set p elms 20
27803 (gdb) show p elms
27804 Limit on string chars or array elements to print is 200.
27805 @end smallexample
27806
27807 Note that if you are defining an alias of a @samp{set} command,
27808 and you want to have an alias for the corresponding @samp{show}
27809 command, then you need to define the latter separately.
27810
27811 Unambiguously abbreviated commands are allowed in @var{command} and
27812 @var{alias}, just as they are normally.
27813
27814 @smallexample
27815 (gdb) alias -a set pr elms = set p ele
27816 @end smallexample
27817
27818 Finally, here is an example showing the creation of a one word
27819 alias for a more complex command.
27820 This creates alias @samp{spe} of the command @samp{set print elements}.
27821
27822 @smallexample
27823 (gdb) alias spe = set print elements
27824 (gdb) spe 20
27825 @end smallexample
27826
27827 @menu
27828 * Command aliases default args:: Default arguments for aliases
27829 @end menu
27830
27831 @node Command aliases default args
27832 @subsection Default Arguments
27833 @cindex aliases for commands, default arguments
27834
27835 You can tell @value{GDBN} to always prepend some default arguments to
27836 the list of arguments provided explicitly by the user when using a
27837 user-defined alias.
27838
27839 If you repeatedly use the same arguments or options for a command, you
27840 can define an alias for this command and tell @value{GDBN} to
27841 automatically prepend these arguments or options to the list of
27842 arguments you type explicitly when using the alias@footnote{@value{GDBN}
27843 could easily accept default arguments for pre-defined commands and aliases,
27844 but it was deemed this would be confusing, and so is not allowed.}.
27845
27846 For example, if you often use the command @code{thread apply all}
27847 specifying to work on the threads in ascending order and to continue in case it
27848 encounters an error, you can tell @value{GDBN} to automatically preprend
27849 the @code{-ascending} and @code{-c} options by using:
27850
27851 @smallexample
27852 (@value{GDBP}) alias thread apply asc-all = thread apply all -ascending -c
27853 @end smallexample
27854
27855 Once you have defined this alias with its default args, any time you type
27856 the @code{thread apply asc-all} followed by @code{some arguments},
27857 @value{GDBN} will execute @code{thread apply all -ascending -c some arguments}.
27858
27859 To have even less to type, you can also define a one word alias:
27860 @smallexample
27861 (@value{GDBP}) alias t_a_c = thread apply all -ascending -c
27862 @end smallexample
27863
27864 As usual, unambiguous abbreviations can be used for @var{alias}
27865 and @var{default-args}.
27866
27867 The different aliases of a command do not share their default args.
27868 For example, you define a new alias @code{bt_ALL} showing all possible
27869 information and another alias @code{bt_SMALL} showing very limited information
27870 using:
27871 @smallexample
27872 (@value{GDBP}) alias bt_ALL = backtrace -entry-values both -frame-arg all \
27873 -past-main -past-entry -full
27874 (@value{GDBP}) alias bt_SMALL = backtrace -entry-values no -frame-arg none \
27875 -past-main off -past-entry off
27876 @end smallexample
27877
27878 (For more on using the @code{alias} command, see @ref{Aliases}.)
27879
27880 Default args are not limited to the arguments and options of @var{command},
27881 but can specify nested commands if @var{command} accepts such a nested command
27882 as argument.
27883 For example, the below defines @code{faalocalsoftype} that lists the
27884 frames having locals of a certain type, together with the matching
27885 local vars:
27886 @smallexample
27887 (@value{GDBP}) alias faalocalsoftype = frame apply all info locals -q -t
27888 (@value{GDBP}) faalocalsoftype int
27889 #1 0x55554f5e in sleeper_or_burner (v=0xdf50) at sleepers.c:86
27890 i = 0
27891 ret = 21845
27892 @end smallexample
27893
27894 This is also very useful to define an alias for a set of nested @code{with}
27895 commands to have a particular combination of temporary settings. For example,
27896 the below defines the alias @code{pp10} that pretty prints an expression
27897 argument, with a maximum of 10 elements if the expression is a string or
27898 an array:
27899 @smallexample
27900 (@value{GDBP}) alias pp10 = with print pretty -- with print elements 10 -- print
27901 @end smallexample
27902 This defines the alias @code{pp10} as being a sequence of 3 commands.
27903 The first part @code{with print pretty --} temporarily activates the setting
27904 @code{set print pretty}, then launches the command that follows the separator
27905 @code{--}.
27906 The command following the first part is also a @code{with} command that
27907 temporarily changes the setting @code{set print elements} to 10, then
27908 launches the command that follows the second separator @code{--}.
27909 The third part @code{print} is the command the @code{pp10} alias will launch,
27910 using the temporary values of the settings and the arguments explicitly given
27911 by the user.
27912 For more information about the @code{with} command usage,
27913 see @ref{Command Settings}.
27914
27915 @c Python docs live in a separate file.
27916 @include python.texi
27917
27918 @c Guile docs live in a separate file.
27919 @include guile.texi
27920
27921 @node Auto-loading extensions
27922 @section Auto-loading extensions
27923 @cindex auto-loading extensions
27924
27925 @value{GDBN} provides two mechanisms for automatically loading
27926 extensions when a new object file is read (for example, due to the
27927 @code{file} command, or because the inferior has loaded a shared
27928 library): @file{@var{objfile}-gdb.@var{ext}} (@pxref{objfile-gdbdotext
27929 file,,The @file{@var{objfile}-gdb.@var{ext}} file}) and the
27930 @code{.debug_gdb_scripts} section of modern file formats like ELF
27931 (@pxref{dotdebug_gdb_scripts section,,The @code{.debug_gdb_scripts}
27932 section}). For a discussion of the differences between these two
27933 approaches see @ref{Which flavor to choose?}.
27934
27935 The auto-loading feature is useful for supplying application-specific
27936 debugging commands and features.
27937
27938 Auto-loading can be enabled or disabled,
27939 and the list of auto-loaded scripts can be printed.
27940 See the @samp{auto-loading} section of each extension language
27941 for more information.
27942 For @value{GDBN} command files see @ref{Auto-loading sequences}.
27943 For Python files see @ref{Python Auto-loading}.
27944
27945 Note that loading of this script file also requires accordingly configured
27946 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27947
27948 @menu
27949 * objfile-gdbdotext file:: The @file{@var{objfile}-gdb.@var{ext}} file
27950 * dotdebug_gdb_scripts section:: The @code{.debug_gdb_scripts} section
27951 * Which flavor to choose?:: Choosing between these approaches
27952 @end menu
27953
27954 @node objfile-gdbdotext file
27955 @subsection The @file{@var{objfile}-gdb.@var{ext}} file
27956 @cindex @file{@var{objfile}-gdb.gdb}
27957 @cindex @file{@var{objfile}-gdb.py}
27958 @cindex @file{@var{objfile}-gdb.scm}
27959
27960 When a new object file is read, @value{GDBN} looks for a file named
27961 @file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
27962 where @var{objfile} is the object file's name and
27963 where @var{ext} is the file extension for the extension language:
27964
27965 @table @code
27966 @item @file{@var{objfile}-gdb.gdb}
27967 GDB's own command language
27968 @item @file{@var{objfile}-gdb.py}
27969 Python
27970 @item @file{@var{objfile}-gdb.scm}
27971 Guile
27972 @end table
27973
27974 @var{script-name} is formed by ensuring that the file name of @var{objfile}
27975 is absolute, following all symlinks, and resolving @code{.} and @code{..}
27976 components, and appending the @file{-gdb.@var{ext}} suffix.
27977 If this file exists and is readable, @value{GDBN} will evaluate it as a
27978 script in the specified extension language.
27979
27980 If this file does not exist, then @value{GDBN} will look for
27981 @var{script-name} file in all of the directories as specified below.
27982 (On MS-Windows/MS-DOS, the drive letter of the executable's leading
27983 directories is converted to a one-letter subdirectory, i.e.@:
27984 @file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
27985 filesystems disallow colons in file names.)
27986
27987 Note that loading of these files requires an accordingly configured
27988 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27989
27990 For object files using @file{.exe} suffix @value{GDBN} tries to load first the
27991 scripts normally according to its @file{.exe} filename. But if no scripts are
27992 found @value{GDBN} also tries script filenames matching the object file without
27993 its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
27994 is attempted on any platform. This makes the script filenames compatible
27995 between Unix and MS-Windows hosts.
27996
27997 @table @code
27998 @anchor{set auto-load scripts-directory}
27999 @kindex set auto-load scripts-directory
28000 @item set auto-load scripts-directory @r{[}@var{directories}@r{]}
28001 Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
28002 may be delimited by the host platform path separator in use
28003 (@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
28004
28005 Each entry here needs to be covered also by the security setting
28006 @code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
28007
28008 @anchor{with-auto-load-dir}
28009 This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
28010 @code{set auto-load safe-path} value can be also overriden by @value{GDBN}
28011 configuration option @option{--with-auto-load-dir}.
28012
28013 Any reference to @file{$debugdir} will get replaced by
28014 @var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
28015 reference to @file{$datadir} will get replaced by @var{data-directory} which is
28016 determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
28017 @file{$datadir} must be placed as a directory component --- either alone or
28018 delimited by @file{/} or @file{\} directory separators, depending on the host
28019 platform.
28020
28021 The list of directories uses path separator (@samp{:} on GNU and Unix
28022 systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
28023 to the @env{PATH} environment variable.
28024
28025 @anchor{show auto-load scripts-directory}
28026 @kindex show auto-load scripts-directory
28027 @item show auto-load scripts-directory
28028 Show @value{GDBN} auto-loaded scripts location.
28029
28030 @anchor{add-auto-load-scripts-directory}
28031 @kindex add-auto-load-scripts-directory
28032 @item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
28033 Add an entry (or list of entries) to the list of auto-loaded scripts locations.
28034 Multiple entries may be delimited by the host platform path separator in use.
28035 @end table
28036
28037 @value{GDBN} does not track which files it has already auto-loaded this way.
28038 @value{GDBN} will load the associated script every time the corresponding
28039 @var{objfile} is opened.
28040 So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
28041 is evaluated more than once.
28042
28043 @node dotdebug_gdb_scripts section
28044 @subsection The @code{.debug_gdb_scripts} section
28045 @cindex @code{.debug_gdb_scripts} section
28046
28047 For systems using file formats like ELF and COFF,
28048 when @value{GDBN} loads a new object file
28049 it will look for a special section named @code{.debug_gdb_scripts}.
28050 If this section exists, its contents is a list of null-terminated entries
28051 specifying scripts to load. Each entry begins with a non-null prefix byte that
28052 specifies the kind of entry, typically the extension language and whether the
28053 script is in a file or inlined in @code{.debug_gdb_scripts}.
28054
28055 The following entries are supported:
28056
28057 @table @code
28058 @item SECTION_SCRIPT_ID_PYTHON_FILE = 1
28059 @item SECTION_SCRIPT_ID_SCHEME_FILE = 3
28060 @item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
28061 @item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
28062 @end table
28063
28064 @subsubsection Script File Entries
28065
28066 If the entry specifies a file, @value{GDBN} will look for the file first
28067 in the current directory and then along the source search path
28068 (@pxref{Source Path, ,Specifying Source Directories}),
28069 except that @file{$cdir} is not searched, since the compilation
28070 directory is not relevant to scripts.
28071
28072 File entries can be placed in section @code{.debug_gdb_scripts} with,
28073 for example, this GCC macro for Python scripts.
28074
28075 @example
28076 /* Note: The "MS" section flags are to remove duplicates. */
28077 #define DEFINE_GDB_PY_SCRIPT(script_name) \
28078 asm("\
28079 .pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
28080 .byte 1 /* Python */\n\
28081 .asciz \"" script_name "\"\n\
28082 .popsection \n\
28083 ");
28084 @end example
28085
28086 @noindent
28087 For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
28088 Then one can reference the macro in a header or source file like this:
28089
28090 @example
28091 DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
28092 @end example
28093
28094 The script name may include directories if desired.
28095
28096 Note that loading of this script file also requires accordingly configured
28097 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
28098
28099 If the macro invocation is put in a header, any application or library
28100 using this header will get a reference to the specified script,
28101 and with the use of @code{"MS"} attributes on the section, the linker
28102 will remove duplicates.
28103
28104 @subsubsection Script Text Entries
28105
28106 Script text entries allow to put the executable script in the entry
28107 itself instead of loading it from a file.
28108 The first line of the entry, everything after the prefix byte and up to
28109 the first newline (@code{0xa}) character, is the script name, and must not
28110 contain any kind of space character, e.g., spaces or tabs.
28111 The rest of the entry, up to the trailing null byte, is the script to
28112 execute in the specified language. The name needs to be unique among
28113 all script names, as @value{GDBN} executes each script only once based
28114 on its name.
28115
28116 Here is an example from file @file{py-section-script.c} in the @value{GDBN}
28117 testsuite.
28118
28119 @example
28120 #include "symcat.h"
28121 #include "gdb/section-scripts.h"
28122 asm(
28123 ".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
28124 ".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
28125 ".ascii \"gdb.inlined-script\\n\"\n"
28126 ".ascii \"class test_cmd (gdb.Command):\\n\"\n"
28127 ".ascii \" def __init__ (self):\\n\"\n"
28128 ".ascii \" super (test_cmd, self).__init__ ("
28129 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
28130 ".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
28131 ".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
28132 ".ascii \"test_cmd ()\\n\"\n"
28133 ".byte 0\n"
28134 ".popsection\n"
28135 );
28136 @end example
28137
28138 Loading of inlined scripts requires a properly configured
28139 @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
28140 The path to specify in @code{auto-load safe-path} is the path of the file
28141 containing the @code{.debug_gdb_scripts} section.
28142
28143 @node Which flavor to choose?
28144 @subsection Which flavor to choose?
28145
28146 Given the multiple ways of auto-loading extensions, it might not always
28147 be clear which one to choose. This section provides some guidance.
28148
28149 @noindent
28150 Benefits of the @file{-gdb.@var{ext}} way:
28151
28152 @itemize @bullet
28153 @item
28154 Can be used with file formats that don't support multiple sections.
28155
28156 @item
28157 Ease of finding scripts for public libraries.
28158
28159 Scripts specified in the @code{.debug_gdb_scripts} section are searched for
28160 in the source search path.
28161 For publicly installed libraries, e.g., @file{libstdc++}, there typically
28162 isn't a source directory in which to find the script.
28163
28164 @item
28165 Doesn't require source code additions.
28166 @end itemize
28167
28168 @noindent
28169 Benefits of the @code{.debug_gdb_scripts} way:
28170
28171 @itemize @bullet
28172 @item
28173 Works with static linking.
28174
28175 Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
28176 trigger their loading. When an application is statically linked the only
28177 objfile available is the executable, and it is cumbersome to attach all the
28178 scripts from all the input libraries to the executable's
28179 @file{-gdb.@var{ext}} script.
28180
28181 @item
28182 Works with classes that are entirely inlined.
28183
28184 Some classes can be entirely inlined, and thus there may not be an associated
28185 shared library to attach a @file{-gdb.@var{ext}} script to.
28186
28187 @item
28188 Scripts needn't be copied out of the source tree.
28189
28190 In some circumstances, apps can be built out of large collections of internal
28191 libraries, and the build infrastructure necessary to install the
28192 @file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
28193 cumbersome. It may be easier to specify the scripts in the
28194 @code{.debug_gdb_scripts} section as relative paths, and add a path to the
28195 top of the source tree to the source search path.
28196 @end itemize
28197
28198 @node Multiple Extension Languages
28199 @section Multiple Extension Languages
28200
28201 The Guile and Python extension languages do not share any state,
28202 and generally do not interfere with each other.
28203 There are some things to be aware of, however.
28204
28205 @subsection Python comes first
28206
28207 Python was @value{GDBN}'s first extension language, and to avoid breaking
28208 existing behaviour Python comes first. This is generally solved by the
28209 ``first one wins'' principle. @value{GDBN} maintains a list of enabled
28210 extension languages, and when it makes a call to an extension language,
28211 (say to pretty-print a value), it tries each in turn until an extension
28212 language indicates it has performed the request (e.g., has returned the
28213 pretty-printed form of a value).
28214 This extends to errors while performing such requests: If an error happens
28215 while, for example, trying to pretty-print an object then the error is
28216 reported and any following extension languages are not tried.
28217
28218 @node Interpreters
28219 @chapter Command Interpreters
28220 @cindex command interpreters
28221
28222 @value{GDBN} supports multiple command interpreters, and some command
28223 infrastructure to allow users or user interface writers to switch
28224 between interpreters or run commands in other interpreters.
28225
28226 @value{GDBN} currently supports two command interpreters, the console
28227 interpreter (sometimes called the command-line interpreter or @sc{cli})
28228 and the machine interface interpreter (or @sc{gdb/mi}). This manual
28229 describes both of these interfaces in great detail.
28230
28231 By default, @value{GDBN} will start with the console interpreter.
28232 However, the user may choose to start @value{GDBN} with another
28233 interpreter by specifying the @option{-i} or @option{--interpreter}
28234 startup options. Defined interpreters include:
28235
28236 @table @code
28237 @item console
28238 @cindex console interpreter
28239 The traditional console or command-line interpreter. This is the most often
28240 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
28241 @value{GDBN} will use this interpreter.
28242
28243 @item mi
28244 @cindex mi interpreter
28245 The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
28246 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
28247 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
28248 Interface}.
28249
28250 @item mi3
28251 @cindex mi3 interpreter
28252 The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
28253
28254 @item mi2
28255 @cindex mi2 interpreter
28256 The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
28257
28258 @item mi1
28259 @cindex mi1 interpreter
28260 The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
28261
28262 @end table
28263
28264 @cindex invoke another interpreter
28265
28266 @kindex interpreter-exec
28267 You may execute commands in any interpreter from the current
28268 interpreter using the appropriate command. If you are running the
28269 console interpreter, simply use the @code{interpreter-exec} command:
28270
28271 @smallexample
28272 interpreter-exec mi "-data-list-register-names"
28273 @end smallexample
28274
28275 @sc{gdb/mi} has a similar command, although it is only available in versions of
28276 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
28277
28278 Note that @code{interpreter-exec} only changes the interpreter for the
28279 duration of the specified command. It does not change the interpreter
28280 permanently.
28281
28282 @cindex start a new independent interpreter
28283
28284 Although you may only choose a single interpreter at startup, it is
28285 possible to run an independent interpreter on a specified input/output
28286 device (usually a tty).
28287
28288 For example, consider a debugger GUI or IDE that wants to provide a
28289 @value{GDBN} console view. It may do so by embedding a terminal
28290 emulator widget in its GUI, starting @value{GDBN} in the traditional
28291 command-line mode with stdin/stdout/stderr redirected to that
28292 terminal, and then creating an MI interpreter running on a specified
28293 input/output device. The console interpreter created by @value{GDBN}
28294 at startup handles commands the user types in the terminal widget,
28295 while the GUI controls and synchronizes state with @value{GDBN} using
28296 the separate MI interpreter.
28297
28298 To start a new secondary @dfn{user interface} running MI, use the
28299 @code{new-ui} command:
28300
28301 @kindex new-ui
28302 @cindex new user interface
28303 @smallexample
28304 new-ui @var{interpreter} @var{tty}
28305 @end smallexample
28306
28307 The @var{interpreter} parameter specifies the interpreter to run.
28308 This accepts the same values as the @code{interpreter-exec} command.
28309 For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
28310 @var{tty} parameter specifies the name of the bidirectional file the
28311 interpreter uses for input/output, usually the name of a
28312 pseudoterminal slave on Unix systems. For example:
28313
28314 @smallexample
28315 (@value{GDBP}) new-ui mi /dev/pts/9
28316 @end smallexample
28317
28318 @noindent
28319 runs an MI interpreter on @file{/dev/pts/9}.
28320
28321 @node TUI
28322 @chapter @value{GDBN} Text User Interface
28323 @cindex TUI
28324 @cindex Text User Interface
28325
28326 The @value{GDBN} Text User Interface (TUI) is a terminal
28327 interface which uses the @code{curses} library to show the source
28328 file, the assembly output, the program registers and @value{GDBN}
28329 commands in separate text windows. The TUI mode is supported only
28330 on platforms where a suitable version of the @code{curses} library
28331 is available.
28332
28333 The TUI mode is enabled by default when you invoke @value{GDBN} as
28334 @samp{@value{GDBP} -tui}.
28335 You can also switch in and out of TUI mode while @value{GDBN} runs by
28336 using various TUI commands and key bindings, such as @command{tui
28337 enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
28338 @ref{TUI Keys, ,TUI Key Bindings}.
28339
28340 @menu
28341 * TUI Overview:: TUI overview
28342 * TUI Keys:: TUI key bindings
28343 * TUI Single Key Mode:: TUI single key mode
28344 * TUI Commands:: TUI-specific commands
28345 * TUI Configuration:: TUI configuration variables
28346 @end menu
28347
28348 @node TUI Overview
28349 @section TUI Overview
28350
28351 In TUI mode, @value{GDBN} can display several text windows:
28352
28353 @table @emph
28354 @item command
28355 This window is the @value{GDBN} command window with the @value{GDBN}
28356 prompt and the @value{GDBN} output. The @value{GDBN} input is still
28357 managed using readline.
28358
28359 @item source
28360 The source window shows the source file of the program. The current
28361 line and active breakpoints are displayed in this window.
28362
28363 @item assembly
28364 The assembly window shows the disassembly output of the program.
28365
28366 @item register
28367 This window shows the processor registers. Registers are highlighted
28368 when their values change.
28369 @end table
28370
28371 The source and assembly windows show the current program position
28372 by highlighting the current line and marking it with a @samp{>} marker.
28373 Breakpoints are indicated with two markers. The first marker
28374 indicates the breakpoint type:
28375
28376 @table @code
28377 @item B
28378 Breakpoint which was hit at least once.
28379
28380 @item b
28381 Breakpoint which was never hit.
28382
28383 @item H
28384 Hardware breakpoint which was hit at least once.
28385
28386 @item h
28387 Hardware breakpoint which was never hit.
28388 @end table
28389
28390 The second marker indicates whether the breakpoint is enabled or not:
28391
28392 @table @code
28393 @item +
28394 Breakpoint is enabled.
28395
28396 @item -
28397 Breakpoint is disabled.
28398 @end table
28399
28400 The source, assembly and register windows are updated when the current
28401 thread changes, when the frame changes, or when the program counter
28402 changes.
28403
28404 These windows are not all visible at the same time. The command
28405 window is always visible. The others can be arranged in several
28406 layouts:
28407
28408 @itemize @bullet
28409 @item
28410 source only,
28411
28412 @item
28413 assembly only,
28414
28415 @item
28416 source and assembly,
28417
28418 @item
28419 source and registers, or
28420
28421 @item
28422 assembly and registers.
28423 @end itemize
28424
28425 These are the standard layouts, but other layouts can be defined.
28426
28427 A status line above the command window shows the following information:
28428
28429 @table @emph
28430 @item target
28431 Indicates the current @value{GDBN} target.
28432 (@pxref{Targets, ,Specifying a Debugging Target}).
28433
28434 @item process
28435 Gives the current process or thread number.
28436 When no process is being debugged, this field is set to @code{No process}.
28437
28438 @item function
28439 Gives the current function name for the selected frame.
28440 The name is demangled if demangling is turned on (@pxref{Print Settings}).
28441 When there is no symbol corresponding to the current program counter,
28442 the string @code{??} is displayed.
28443
28444 @item line
28445 Indicates the current line number for the selected frame.
28446 When the current line number is not known, the string @code{??} is displayed.
28447
28448 @item pc
28449 Indicates the current program counter address.
28450 @end table
28451
28452 @node TUI Keys
28453 @section TUI Key Bindings
28454 @cindex TUI key bindings
28455
28456 The TUI installs several key bindings in the readline keymaps
28457 @ifset SYSTEM_READLINE
28458 (@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
28459 @end ifset
28460 @ifclear SYSTEM_READLINE
28461 (@pxref{Command Line Editing}).
28462 @end ifclear
28463 The following key bindings are installed for both TUI mode and the
28464 @value{GDBN} standard mode.
28465
28466 @table @kbd
28467 @kindex C-x C-a
28468 @item C-x C-a
28469 @kindex C-x a
28470 @itemx C-x a
28471 @kindex C-x A
28472 @itemx C-x A
28473 Enter or leave the TUI mode. When leaving the TUI mode,
28474 the curses window management stops and @value{GDBN} operates using
28475 its standard mode, writing on the terminal directly. When reentering
28476 the TUI mode, control is given back to the curses windows.
28477 The screen is then refreshed.
28478
28479 This key binding uses the bindable Readline function
28480 @code{tui-switch-mode}.
28481
28482 @kindex C-x 1
28483 @item C-x 1
28484 Use a TUI layout with only one window. The layout will
28485 either be @samp{source} or @samp{assembly}. When the TUI mode
28486 is not active, it will switch to the TUI mode.
28487
28488 Think of this key binding as the Emacs @kbd{C-x 1} binding.
28489
28490 This key binding uses the bindable Readline function
28491 @code{tui-delete-other-windows}.
28492
28493 @kindex C-x 2
28494 @item C-x 2
28495 Use a TUI layout with at least two windows. When the current
28496 layout already has two windows, the next layout with two windows is used.
28497 When a new layout is chosen, one window will always be common to the
28498 previous layout and the new one.
28499
28500 Think of it as the Emacs @kbd{C-x 2} binding.
28501
28502 This key binding uses the bindable Readline function
28503 @code{tui-change-windows}.
28504
28505 @kindex C-x o
28506 @item C-x o
28507 Change the active window. The TUI associates several key bindings
28508 (like scrolling and arrow keys) with the active window. This command
28509 gives the focus to the next TUI window.
28510
28511 Think of it as the Emacs @kbd{C-x o} binding.
28512
28513 This key binding uses the bindable Readline function
28514 @code{tui-other-window}.
28515
28516 @kindex C-x s
28517 @item C-x s
28518 Switch in and out of the TUI SingleKey mode that binds single
28519 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
28520
28521 This key binding uses the bindable Readline function
28522 @code{next-keymap}.
28523 @end table
28524
28525 The following key bindings only work in the TUI mode:
28526
28527 @table @asis
28528 @kindex PgUp
28529 @item @key{PgUp}
28530 Scroll the active window one page up.
28531
28532 @kindex PgDn
28533 @item @key{PgDn}
28534 Scroll the active window one page down.
28535
28536 @kindex Up
28537 @item @key{Up}
28538 Scroll the active window one line up.
28539
28540 @kindex Down
28541 @item @key{Down}
28542 Scroll the active window one line down.
28543
28544 @kindex Left
28545 @item @key{Left}
28546 Scroll the active window one column left.
28547
28548 @kindex Right
28549 @item @key{Right}
28550 Scroll the active window one column right.
28551
28552 @kindex C-L
28553 @item @kbd{C-L}
28554 Refresh the screen.
28555 @end table
28556
28557 Because the arrow keys scroll the active window in the TUI mode, they
28558 are not available for their normal use by readline unless the command
28559 window has the focus. When another window is active, you must use
28560 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
28561 and @kbd{C-f} to control the command window.
28562
28563 @node TUI Single Key Mode
28564 @section TUI Single Key Mode
28565 @cindex TUI single key mode
28566
28567 The TUI also provides a @dfn{SingleKey} mode, which binds several
28568 frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
28569 switch into this mode, where the following key bindings are used:
28570
28571 @table @kbd
28572 @kindex c @r{(SingleKey TUI key)}
28573 @item c
28574 continue
28575
28576 @kindex d @r{(SingleKey TUI key)}
28577 @item d
28578 down
28579
28580 @kindex f @r{(SingleKey TUI key)}
28581 @item f
28582 finish
28583
28584 @kindex n @r{(SingleKey TUI key)}
28585 @item n
28586 next
28587
28588 @kindex o @r{(SingleKey TUI key)}
28589 @item o
28590 nexti. The shortcut letter @samp{o} stands for ``step Over''.
28591
28592 @kindex q @r{(SingleKey TUI key)}
28593 @item q
28594 exit the SingleKey mode.
28595
28596 @kindex r @r{(SingleKey TUI key)}
28597 @item r
28598 run
28599
28600 @kindex s @r{(SingleKey TUI key)}
28601 @item s
28602 step
28603
28604 @kindex i @r{(SingleKey TUI key)}
28605 @item i
28606 stepi. The shortcut letter @samp{i} stands for ``step Into''.
28607
28608 @kindex u @r{(SingleKey TUI key)}
28609 @item u
28610 up
28611
28612 @kindex v @r{(SingleKey TUI key)}
28613 @item v
28614 info locals
28615
28616 @kindex w @r{(SingleKey TUI key)}
28617 @item w
28618 where
28619 @end table
28620
28621 Other keys temporarily switch to the @value{GDBN} command prompt.
28622 The key that was pressed is inserted in the editing buffer so that
28623 it is possible to type most @value{GDBN} commands without interaction
28624 with the TUI SingleKey mode. Once the command is entered the TUI
28625 SingleKey mode is restored. The only way to permanently leave
28626 this mode is by typing @kbd{q} or @kbd{C-x s}.
28627
28628 @cindex SingleKey keymap name
28629 If @value{GDBN} was built with Readline 8.0 or later, the TUI
28630 SingleKey keymap will be named @samp{SingleKey}. This can be used in
28631 @file{.inputrc} to add additional bindings to this keymap.
28632
28633 @node TUI Commands
28634 @section TUI-specific Commands
28635 @cindex TUI commands
28636
28637 The TUI has specific commands to control the text windows.
28638 These commands are always available, even when @value{GDBN} is not in
28639 the TUI mode. When @value{GDBN} is in the standard mode, most
28640 of these commands will automatically switch to the TUI mode.
28641
28642 Note that if @value{GDBN}'s @code{stdout} is not connected to a
28643 terminal, or @value{GDBN} has been started with the machine interface
28644 interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
28645 these commands will fail with an error, because it would not be
28646 possible or desirable to enable curses window management.
28647
28648 @table @code
28649 @item tui enable
28650 @kindex tui enable
28651 Activate TUI mode. The last active TUI window layout will be used if
28652 TUI mode has previously been used in the current debugging session,
28653 otherwise a default layout is used.
28654
28655 @item tui disable
28656 @kindex tui disable
28657 Disable TUI mode, returning to the console interpreter.
28658
28659 @item info win
28660 @kindex info win
28661 List and give the size of all displayed windows.
28662
28663 @item tui new-layout @var{name} @var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}
28664 @kindex tui new-layout
28665 Create a new TUI layout. The new layout will be named @var{name}, and
28666 can be accessed using the @code{layout} command (see below).
28667
28668 Each @var{window} parameter is either the name of a window to display,
28669 or a window description. The windows will be displayed from top to
28670 bottom in the order listed.
28671
28672 The names of the windows are the same as the ones given to the
28673 @code{focus} command (see below); additional, the @code{status}
28674 window can be specified. Note that, because it is of fixed height,
28675 the weight assigned to the status window is of no importance. It is
28676 conventional to use @samp{0} here.
28677
28678 A window description looks a bit like an invocation of @code{tui
28679 new-layout}, and is of the form
28680 @{@r{[}@code{-horizontal}@r{]}@var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}@}.
28681
28682 This specifies a sub-layout. If @code{-horizontal} is given, the
28683 windows in this description will be arranged side-by-side, rather than
28684 top-to-bottom.
28685
28686 Each @var{weight} is an integer. It is the weight of this window
28687 relative to all the other windows in the layout. These numbers are
28688 used to calculate how much of the screen is given to each window.
28689
28690 For example:
28691
28692 @example
28693 (gdb) tui new-layout example src 1 regs 1 status 0 cmd 1
28694 @end example
28695
28696 Here, the new layout is called @samp{example}. It shows the source
28697 and register windows, followed by the status window, and then finally
28698 the command window. The non-status windows all have the same weight,
28699 so the terminal will be split into three roughly equal sections.
28700
28701 Here is a more complex example, showing a horizontal layout:
28702
28703 @example
28704 (gdb) tui new-layout example @{-horizontal src 1 asm 1@} 2 status 0 cmd 1
28705 @end example
28706
28707 This will result in side-by-side source and assembly windows; with the
28708 status and command window being beneath these, filling the entire
28709 width of the terminal. Because they have weight 2, the source and
28710 assembly windows will be twice the height of the command window.
28711
28712 @item layout @var{name}
28713 @kindex layout
28714 Changes which TUI windows are displayed. The @var{name} parameter
28715 controls which layout is shown. It can be either one of the built-in
28716 layout names, or the name of a layout defined by the user using
28717 @code{tui new-layout}.
28718
28719 The built-in layouts are as follows:
28720
28721 @table @code
28722 @item next
28723 Display the next layout.
28724
28725 @item prev
28726 Display the previous layout.
28727
28728 @item src
28729 Display the source and command windows.
28730
28731 @item asm
28732 Display the assembly and command windows.
28733
28734 @item split
28735 Display the source, assembly, and command windows.
28736
28737 @item regs
28738 When in @code{src} layout display the register, source, and command
28739 windows. When in @code{asm} or @code{split} layout display the
28740 register, assembler, and command windows.
28741 @end table
28742
28743 @item focus @var{name}
28744 @kindex focus
28745 Changes which TUI window is currently active for scrolling. The
28746 @var{name} parameter can be any of the following:
28747
28748 @table @code
28749 @item next
28750 Make the next window active for scrolling.
28751
28752 @item prev
28753 Make the previous window active for scrolling.
28754
28755 @item src
28756 Make the source window active for scrolling.
28757
28758 @item asm
28759 Make the assembly window active for scrolling.
28760
28761 @item regs
28762 Make the register window active for scrolling.
28763
28764 @item cmd
28765 Make the command window active for scrolling.
28766 @end table
28767
28768 @item refresh
28769 @kindex refresh
28770 Refresh the screen. This is similar to typing @kbd{C-L}.
28771
28772 @item tui reg @var{group}
28773 @kindex tui reg
28774 Changes the register group displayed in the tui register window to
28775 @var{group}. If the register window is not currently displayed this
28776 command will cause the register window to be displayed. The list of
28777 register groups, as well as their order is target specific. The
28778 following groups are available on most targets:
28779 @table @code
28780 @item next
28781 Repeatedly selecting this group will cause the display to cycle
28782 through all of the available register groups.
28783
28784 @item prev
28785 Repeatedly selecting this group will cause the display to cycle
28786 through all of the available register groups in the reverse order to
28787 @var{next}.
28788
28789 @item general
28790 Display the general registers.
28791 @item float
28792 Display the floating point registers.
28793 @item system
28794 Display the system registers.
28795 @item vector
28796 Display the vector registers.
28797 @item all
28798 Display all registers.
28799 @end table
28800
28801 @item update
28802 @kindex update
28803 Update the source window and the current execution point.
28804
28805 @item winheight @var{name} +@var{count}
28806 @itemx winheight @var{name} -@var{count}
28807 @kindex winheight
28808 Change the height of the window @var{name} by @var{count}
28809 lines. Positive counts increase the height, while negative counts
28810 decrease it. The @var{name} parameter can be one of @code{src} (the
28811 source window), @code{cmd} (the command window), @code{asm} (the
28812 disassembly window), or @code{regs} (the register display window).
28813 @end table
28814
28815 @node TUI Configuration
28816 @section TUI Configuration Variables
28817 @cindex TUI configuration variables
28818
28819 Several configuration variables control the appearance of TUI windows.
28820
28821 @table @code
28822 @item set tui border-kind @var{kind}
28823 @kindex set tui border-kind
28824 Select the border appearance for the source, assembly and register windows.
28825 The possible values are the following:
28826 @table @code
28827 @item space
28828 Use a space character to draw the border.
28829
28830 @item ascii
28831 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
28832
28833 @item acs
28834 Use the Alternate Character Set to draw the border. The border is
28835 drawn using character line graphics if the terminal supports them.
28836 @end table
28837
28838 @item set tui border-mode @var{mode}
28839 @kindex set tui border-mode
28840 @itemx set tui active-border-mode @var{mode}
28841 @kindex set tui active-border-mode
28842 Select the display attributes for the borders of the inactive windows
28843 or the active window. The @var{mode} can be one of the following:
28844 @table @code
28845 @item normal
28846 Use normal attributes to display the border.
28847
28848 @item standout
28849 Use standout mode.
28850
28851 @item reverse
28852 Use reverse video mode.
28853
28854 @item half
28855 Use half bright mode.
28856
28857 @item half-standout
28858 Use half bright and standout mode.
28859
28860 @item bold
28861 Use extra bright or bold mode.
28862
28863 @item bold-standout
28864 Use extra bright or bold and standout mode.
28865 @end table
28866
28867 @item set tui tab-width @var{nchars}
28868 @kindex set tui tab-width
28869 @kindex tabset
28870 Set the width of tab stops to be @var{nchars} characters. This
28871 setting affects the display of TAB characters in the source and
28872 assembly windows.
28873
28874 @item set tui compact-source @r{[}on@r{|}off@r{]}
28875 @kindex set tui compact-source
28876 Set whether the TUI source window is displayed in ``compact'' form.
28877 The default display uses more space for line numbers and starts the
28878 source text at the next tab stop; the compact display uses only as
28879 much space as is needed for the line numbers in the current file, and
28880 only a single space to separate the line numbers from the source.
28881 @end table
28882
28883 Note that the colors of the TUI borders can be controlled using the
28884 appropriate @code{set style} commands. @xref{Output Styling}.
28885
28886 @node Emacs
28887 @chapter Using @value{GDBN} under @sc{gnu} Emacs
28888
28889 @cindex Emacs
28890 @cindex @sc{gnu} Emacs
28891 A special interface allows you to use @sc{gnu} Emacs to view (and
28892 edit) the source files for the program you are debugging with
28893 @value{GDBN}.
28894
28895 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
28896 executable file you want to debug as an argument. This command starts
28897 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
28898 created Emacs buffer.
28899 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
28900
28901 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
28902 things:
28903
28904 @itemize @bullet
28905 @item
28906 All ``terminal'' input and output goes through an Emacs buffer, called
28907 the GUD buffer.
28908
28909 This applies both to @value{GDBN} commands and their output, and to the input
28910 and output done by the program you are debugging.
28911
28912 This is useful because it means that you can copy the text of previous
28913 commands and input them again; you can even use parts of the output
28914 in this way.
28915
28916 All the facilities of Emacs' Shell mode are available for interacting
28917 with your program. In particular, you can send signals the usual
28918 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
28919 stop.
28920
28921 @item
28922 @value{GDBN} displays source code through Emacs.
28923
28924 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
28925 source file for that frame and puts an arrow (@samp{=>}) at the
28926 left margin of the current line. Emacs uses a separate buffer for
28927 source display, and splits the screen to show both your @value{GDBN} session
28928 and the source.
28929
28930 Explicit @value{GDBN} @code{list} or search commands still produce output as
28931 usual, but you probably have no reason to use them from Emacs.
28932 @end itemize
28933
28934 We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
28935 a graphical mode, enabled by default, which provides further buffers
28936 that can control the execution and describe the state of your program.
28937 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
28938
28939 If you specify an absolute file name when prompted for the @kbd{M-x
28940 gdb} argument, then Emacs sets your current working directory to where
28941 your program resides. If you only specify the file name, then Emacs
28942 sets your current working directory to the directory associated
28943 with the previous buffer. In this case, @value{GDBN} may find your
28944 program by searching your environment's @code{PATH} variable, but on
28945 some operating systems it might not find the source. So, although the
28946 @value{GDBN} input and output session proceeds normally, the auxiliary
28947 buffer does not display the current source and line of execution.
28948
28949 The initial working directory of @value{GDBN} is printed on the top
28950 line of the GUD buffer and this serves as a default for the commands
28951 that specify files for @value{GDBN} to operate on. @xref{Files,
28952 ,Commands to Specify Files}.
28953
28954 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
28955 need to call @value{GDBN} by a different name (for example, if you
28956 keep several configurations around, with different names) you can
28957 customize the Emacs variable @code{gud-gdb-command-name} to run the
28958 one you want.
28959
28960 In the GUD buffer, you can use these special Emacs commands in
28961 addition to the standard Shell mode commands:
28962
28963 @table @kbd
28964 @item C-h m
28965 Describe the features of Emacs' GUD Mode.
28966
28967 @item C-c C-s
28968 Execute to another source line, like the @value{GDBN} @code{step} command; also
28969 update the display window to show the current file and location.
28970
28971 @item C-c C-n
28972 Execute to next source line in this function, skipping all function
28973 calls, like the @value{GDBN} @code{next} command. Then update the display window
28974 to show the current file and location.
28975
28976 @item C-c C-i
28977 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
28978 display window accordingly.
28979
28980 @item C-c C-f
28981 Execute until exit from the selected stack frame, like the @value{GDBN}
28982 @code{finish} command.
28983
28984 @item C-c C-r
28985 Continue execution of your program, like the @value{GDBN} @code{continue}
28986 command.
28987
28988 @item C-c <
28989 Go up the number of frames indicated by the numeric argument
28990 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
28991 like the @value{GDBN} @code{up} command.
28992
28993 @item C-c >
28994 Go down the number of frames indicated by the numeric argument, like the
28995 @value{GDBN} @code{down} command.
28996 @end table
28997
28998 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
28999 tells @value{GDBN} to set a breakpoint on the source line point is on.
29000
29001 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
29002 separate frame which shows a backtrace when the GUD buffer is current.
29003 Move point to any frame in the stack and type @key{RET} to make it
29004 become the current frame and display the associated source in the
29005 source buffer. Alternatively, click @kbd{Mouse-2} to make the
29006 selected frame become the current one. In graphical mode, the
29007 speedbar displays watch expressions.
29008
29009 If you accidentally delete the source-display buffer, an easy way to get
29010 it back is to type the command @code{f} in the @value{GDBN} buffer, to
29011 request a frame display; when you run under Emacs, this recreates
29012 the source buffer if necessary to show you the context of the current
29013 frame.
29014
29015 The source files displayed in Emacs are in ordinary Emacs buffers
29016 which are visiting the source files in the usual way. You can edit
29017 the files with these buffers if you wish; but keep in mind that @value{GDBN}
29018 communicates with Emacs in terms of line numbers. If you add or
29019 delete lines from the text, the line numbers that @value{GDBN} knows cease
29020 to correspond properly with the code.
29021
29022 A more detailed description of Emacs' interaction with @value{GDBN} is
29023 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
29024 Emacs Manual}).
29025
29026 @node GDB/MI
29027 @chapter The @sc{gdb/mi} Interface
29028
29029 @unnumberedsec Function and Purpose
29030
29031 @cindex @sc{gdb/mi}, its purpose
29032 @sc{gdb/mi} is a line based machine oriented text interface to
29033 @value{GDBN} and is activated by specifying using the
29034 @option{--interpreter} command line option (@pxref{Mode Options}). It
29035 is specifically intended to support the development of systems which
29036 use the debugger as just one small component of a larger system.
29037
29038 This chapter is a specification of the @sc{gdb/mi} interface. It is written
29039 in the form of a reference manual.
29040
29041 Note that @sc{gdb/mi} is still under construction, so some of the
29042 features described below are incomplete and subject to change
29043 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
29044
29045 @unnumberedsec Notation and Terminology
29046
29047 @cindex notational conventions, for @sc{gdb/mi}
29048 This chapter uses the following notation:
29049
29050 @itemize @bullet
29051 @item
29052 @code{|} separates two alternatives.
29053
29054 @item
29055 @code{[ @var{something} ]} indicates that @var{something} is optional:
29056 it may or may not be given.
29057
29058 @item
29059 @code{( @var{group} )*} means that @var{group} inside the parentheses
29060 may repeat zero or more times.
29061
29062 @item
29063 @code{( @var{group} )+} means that @var{group} inside the parentheses
29064 may repeat one or more times.
29065
29066 @item
29067 @code{"@var{string}"} means a literal @var{string}.
29068 @end itemize
29069
29070 @ignore
29071 @heading Dependencies
29072 @end ignore
29073
29074 @menu
29075 * GDB/MI General Design::
29076 * GDB/MI Command Syntax::
29077 * GDB/MI Compatibility with CLI::
29078 * GDB/MI Development and Front Ends::
29079 * GDB/MI Output Records::
29080 * GDB/MI Simple Examples::
29081 * GDB/MI Command Description Format::
29082 * GDB/MI Breakpoint Commands::
29083 * GDB/MI Catchpoint Commands::
29084 * GDB/MI Program Context::
29085 * GDB/MI Thread Commands::
29086 * GDB/MI Ada Tasking Commands::
29087 * GDB/MI Program Execution::
29088 * GDB/MI Stack Manipulation::
29089 * GDB/MI Variable Objects::
29090 * GDB/MI Data Manipulation::
29091 * GDB/MI Tracepoint Commands::
29092 * GDB/MI Symbol Query::
29093 * GDB/MI File Commands::
29094 @ignore
29095 * GDB/MI Kod Commands::
29096 * GDB/MI Memory Overlay Commands::
29097 * GDB/MI Signal Handling Commands::
29098 @end ignore
29099 * GDB/MI Target Manipulation::
29100 * GDB/MI File Transfer Commands::
29101 * GDB/MI Ada Exceptions Commands::
29102 * GDB/MI Support Commands::
29103 * GDB/MI Miscellaneous Commands::
29104 @end menu
29105
29106 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29107 @node GDB/MI General Design
29108 @section @sc{gdb/mi} General Design
29109 @cindex GDB/MI General Design
29110
29111 Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
29112 parts---commands sent to @value{GDBN}, responses to those commands
29113 and notifications. Each command results in exactly one response,
29114 indicating either successful completion of the command, or an error.
29115 For the commands that do not resume the target, the response contains the
29116 requested information. For the commands that resume the target, the
29117 response only indicates whether the target was successfully resumed.
29118 Notifications is the mechanism for reporting changes in the state of the
29119 target, or in @value{GDBN} state, that cannot conveniently be associated with
29120 a command and reported as part of that command response.
29121
29122 The important examples of notifications are:
29123 @itemize @bullet
29124
29125 @item
29126 Exec notifications. These are used to report changes in
29127 target state---when a target is resumed, or stopped. It would not
29128 be feasible to include this information in response of resuming
29129 commands, because one resume commands can result in multiple events in
29130 different threads. Also, quite some time may pass before any event
29131 happens in the target, while a frontend needs to know whether the resuming
29132 command itself was successfully executed.
29133
29134 @item
29135 Console output, and status notifications. Console output
29136 notifications are used to report output of CLI commands, as well as
29137 diagnostics for other commands. Status notifications are used to
29138 report the progress of a long-running operation. Naturally, including
29139 this information in command response would mean no output is produced
29140 until the command is finished, which is undesirable.
29141
29142 @item
29143 General notifications. Commands may have various side effects on
29144 the @value{GDBN} or target state beyond their official purpose. For example,
29145 a command may change the selected thread. Although such changes can
29146 be included in command response, using notification allows for more
29147 orthogonal frontend design.
29148
29149 @end itemize
29150
29151 There's no guarantee that whenever an MI command reports an error,
29152 @value{GDBN} or the target are in any specific state, and especially,
29153 the state is not reverted to the state before the MI command was
29154 processed. Therefore, whenever an MI command results in an error,
29155 we recommend that the frontend refreshes all the information shown in
29156 the user interface.
29157
29158
29159 @menu
29160 * Context management::
29161 * Asynchronous and non-stop modes::
29162 * Thread groups::
29163 @end menu
29164
29165 @node Context management
29166 @subsection Context management
29167
29168 @subsubsection Threads and Frames
29169
29170 In most cases when @value{GDBN} accesses the target, this access is
29171 done in context of a specific thread and frame (@pxref{Frames}).
29172 Often, even when accessing global data, the target requires that a thread
29173 be specified. The CLI interface maintains the selected thread and frame,
29174 and supplies them to target on each command. This is convenient,
29175 because a command line user would not want to specify that information
29176 explicitly on each command, and because user interacts with
29177 @value{GDBN} via a single terminal, so no confusion is possible as
29178 to what thread and frame are the current ones.
29179
29180 In the case of MI, the concept of selected thread and frame is less
29181 useful. First, a frontend can easily remember this information
29182 itself. Second, a graphical frontend can have more than one window,
29183 each one used for debugging a different thread, and the frontend might
29184 want to access additional threads for internal purposes. This
29185 increases the risk that by relying on implicitly selected thread, the
29186 frontend may be operating on a wrong one. Therefore, each MI command
29187 should explicitly specify which thread and frame to operate on. To
29188 make it possible, each MI command accepts the @samp{--thread} and
29189 @samp{--frame} options, the value to each is @value{GDBN} global
29190 identifier for thread and frame to operate on.
29191
29192 Usually, each top-level window in a frontend allows the user to select
29193 a thread and a frame, and remembers the user selection for further
29194 operations. However, in some cases @value{GDBN} may suggest that the
29195 current thread or frame be changed. For example, when stopping on a
29196 breakpoint it is reasonable to switch to the thread where breakpoint is
29197 hit. For another example, if the user issues the CLI @samp{thread} or
29198 @samp{frame} commands via the frontend, it is desirable to change the
29199 frontend's selection to the one specified by user. @value{GDBN}
29200 communicates the suggestion to change current thread and frame using the
29201 @samp{=thread-selected} notification.
29202
29203 Note that historically, MI shares the selected thread with CLI, so
29204 frontends used the @code{-thread-select} to execute commands in the
29205 right context. However, getting this to work right is cumbersome. The
29206 simplest way is for frontend to emit @code{-thread-select} command
29207 before every command. This doubles the number of commands that need
29208 to be sent. The alternative approach is to suppress @code{-thread-select}
29209 if the selected thread in @value{GDBN} is supposed to be identical to the
29210 thread the frontend wants to operate on. However, getting this
29211 optimization right can be tricky. In particular, if the frontend
29212 sends several commands to @value{GDBN}, and one of the commands changes the
29213 selected thread, then the behaviour of subsequent commands will
29214 change. So, a frontend should either wait for response from such
29215 problematic commands, or explicitly add @code{-thread-select} for
29216 all subsequent commands. No frontend is known to do this exactly
29217 right, so it is suggested to just always pass the @samp{--thread} and
29218 @samp{--frame} options.
29219
29220 @subsubsection Language
29221
29222 The execution of several commands depends on which language is selected.
29223 By default, the current language (@pxref{show language}) is used.
29224 But for commands known to be language-sensitive, it is recommended
29225 to use the @samp{--language} option. This option takes one argument,
29226 which is the name of the language to use while executing the command.
29227 For instance:
29228
29229 @smallexample
29230 -data-evaluate-expression --language c "sizeof (void*)"
29231 ^done,value="4"
29232 (gdb)
29233 @end smallexample
29234
29235 The valid language names are the same names accepted by the
29236 @samp{set language} command (@pxref{Manually}), excluding @samp{auto},
29237 @samp{local} or @samp{unknown}.
29238
29239 @node Asynchronous and non-stop modes
29240 @subsection Asynchronous command execution and non-stop mode
29241
29242 On some targets, @value{GDBN} is capable of processing MI commands
29243 even while the target is running. This is called @dfn{asynchronous
29244 command execution} (@pxref{Background Execution}). The frontend may
29245 specify a preference for asynchronous execution using the
29246 @code{-gdb-set mi-async 1} command, which should be emitted before
29247 either running the executable or attaching to the target. After the
29248 frontend has started the executable or attached to the target, it can
29249 find if asynchronous execution is enabled using the
29250 @code{-list-target-features} command.
29251
29252 @table @code
29253 @item -gdb-set mi-async on
29254 @item -gdb-set mi-async off
29255 Set whether MI is in asynchronous mode.
29256
29257 When @code{off}, which is the default, MI execution commands (e.g.,
29258 @code{-exec-continue}) are foreground commands, and @value{GDBN} waits
29259 for the program to stop before processing further commands.
29260
29261 When @code{on}, MI execution commands are background execution
29262 commands (e.g., @code{-exec-continue} becomes the equivalent of the
29263 @code{c&} CLI command), and so @value{GDBN} is capable of processing
29264 MI commands even while the target is running.
29265
29266 @item -gdb-show mi-async
29267 Show whether MI asynchronous mode is enabled.
29268 @end table
29269
29270 Note: In @value{GDBN} version 7.7 and earlier, this option was called
29271 @code{target-async} instead of @code{mi-async}, and it had the effect
29272 of both putting MI in asynchronous mode and making CLI background
29273 commands possible. CLI background commands are now always possible
29274 ``out of the box'' if the target supports them. The old spelling is
29275 kept as a deprecated alias for backwards compatibility.
29276
29277 Even if @value{GDBN} can accept a command while target is running,
29278 many commands that access the target do not work when the target is
29279 running. Therefore, asynchronous command execution is most useful
29280 when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
29281 it is possible to examine the state of one thread, while other threads
29282 are running.
29283
29284 When a given thread is running, MI commands that try to access the
29285 target in the context of that thread may not work, or may work only on
29286 some targets. In particular, commands that try to operate on thread's
29287 stack will not work, on any target. Commands that read memory, or
29288 modify breakpoints, may work or not work, depending on the target. Note
29289 that even commands that operate on global state, such as @code{print},
29290 @code{set}, and breakpoint commands, still access the target in the
29291 context of a specific thread, so frontend should try to find a
29292 stopped thread and perform the operation on that thread (using the
29293 @samp{--thread} option).
29294
29295 Which commands will work in the context of a running thread is
29296 highly target dependent. However, the two commands
29297 @code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
29298 to find the state of a thread, will always work.
29299
29300 @node Thread groups
29301 @subsection Thread groups
29302 @value{GDBN} may be used to debug several processes at the same time.
29303 On some platforms, @value{GDBN} may support debugging of several
29304 hardware systems, each one having several cores with several different
29305 processes running on each core. This section describes the MI
29306 mechanism to support such debugging scenarios.
29307
29308 The key observation is that regardless of the structure of the
29309 target, MI can have a global list of threads, because most commands that
29310 accept the @samp{--thread} option do not need to know what process that
29311 thread belongs to. Therefore, it is not necessary to introduce
29312 neither additional @samp{--process} option, nor an notion of the
29313 current process in the MI interface. The only strictly new feature
29314 that is required is the ability to find how the threads are grouped
29315 into processes.
29316
29317 To allow the user to discover such grouping, and to support arbitrary
29318 hierarchy of machines/cores/processes, MI introduces the concept of a
29319 @dfn{thread group}. Thread group is a collection of threads and other
29320 thread groups. A thread group always has a string identifier, a type,
29321 and may have additional attributes specific to the type. A new
29322 command, @code{-list-thread-groups}, returns the list of top-level
29323 thread groups, which correspond to processes that @value{GDBN} is
29324 debugging at the moment. By passing an identifier of a thread group
29325 to the @code{-list-thread-groups} command, it is possible to obtain
29326 the members of specific thread group.
29327
29328 To allow the user to easily discover processes, and other objects, he
29329 wishes to debug, a concept of @dfn{available thread group} is
29330 introduced. Available thread group is an thread group that
29331 @value{GDBN} is not debugging, but that can be attached to, using the
29332 @code{-target-attach} command. The list of available top-level thread
29333 groups can be obtained using @samp{-list-thread-groups --available}.
29334 In general, the content of a thread group may be only retrieved only
29335 after attaching to that thread group.
29336
29337 Thread groups are related to inferiors (@pxref{Inferiors Connections and
29338 Programs}). Each inferior corresponds to a thread group of a special
29339 type @samp{process}, and some additional operations are permitted on
29340 such thread groups.
29341
29342 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29343 @node GDB/MI Command Syntax
29344 @section @sc{gdb/mi} Command Syntax
29345
29346 @menu
29347 * GDB/MI Input Syntax::
29348 * GDB/MI Output Syntax::
29349 @end menu
29350
29351 @node GDB/MI Input Syntax
29352 @subsection @sc{gdb/mi} Input Syntax
29353
29354 @cindex input syntax for @sc{gdb/mi}
29355 @cindex @sc{gdb/mi}, input syntax
29356 @table @code
29357 @item @var{command} @expansion{}
29358 @code{@var{cli-command} | @var{mi-command}}
29359
29360 @item @var{cli-command} @expansion{}
29361 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
29362 @var{cli-command} is any existing @value{GDBN} CLI command.
29363
29364 @item @var{mi-command} @expansion{}
29365 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
29366 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
29367
29368 @item @var{token} @expansion{}
29369 "any sequence of digits"
29370
29371 @item @var{option} @expansion{}
29372 @code{"-" @var{parameter} [ " " @var{parameter} ]}
29373
29374 @item @var{parameter} @expansion{}
29375 @code{@var{non-blank-sequence} | @var{c-string}}
29376
29377 @item @var{operation} @expansion{}
29378 @emph{any of the operations described in this chapter}
29379
29380 @item @var{non-blank-sequence} @expansion{}
29381 @emph{anything, provided it doesn't contain special characters such as
29382 "-", @var{nl}, """ and of course " "}
29383
29384 @item @var{c-string} @expansion{}
29385 @code{""" @var{seven-bit-iso-c-string-content} """}
29386
29387 @item @var{nl} @expansion{}
29388 @code{CR | CR-LF}
29389 @end table
29390
29391 @noindent
29392 Notes:
29393
29394 @itemize @bullet
29395 @item
29396 The CLI commands are still handled by the @sc{mi} interpreter; their
29397 output is described below.
29398
29399 @item
29400 The @code{@var{token}}, when present, is passed back when the command
29401 finishes.
29402
29403 @item
29404 Some @sc{mi} commands accept optional arguments as part of the parameter
29405 list. Each option is identified by a leading @samp{-} (dash) and may be
29406 followed by an optional argument parameter. Options occur first in the
29407 parameter list and can be delimited from normal parameters using
29408 @samp{--} (this is useful when some parameters begin with a dash).
29409 @end itemize
29410
29411 Pragmatics:
29412
29413 @itemize @bullet
29414 @item
29415 We want easy access to the existing CLI syntax (for debugging).
29416
29417 @item
29418 We want it to be easy to spot a @sc{mi} operation.
29419 @end itemize
29420
29421 @node GDB/MI Output Syntax
29422 @subsection @sc{gdb/mi} Output Syntax
29423
29424 @cindex output syntax of @sc{gdb/mi}
29425 @cindex @sc{gdb/mi}, output syntax
29426 The output from @sc{gdb/mi} consists of zero or more out-of-band records
29427 followed, optionally, by a single result record. This result record
29428 is for the most recent command. The sequence of output records is
29429 terminated by @samp{(gdb)}.
29430
29431 If an input command was prefixed with a @code{@var{token}} then the
29432 corresponding output for that command will also be prefixed by that same
29433 @var{token}.
29434
29435 @table @code
29436 @item @var{output} @expansion{}
29437 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
29438
29439 @item @var{result-record} @expansion{}
29440 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
29441
29442 @item @var{out-of-band-record} @expansion{}
29443 @code{@var{async-record} | @var{stream-record}}
29444
29445 @item @var{async-record} @expansion{}
29446 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
29447
29448 @item @var{exec-async-output} @expansion{}
29449 @code{[ @var{token} ] "*" @var{async-output nl}}
29450
29451 @item @var{status-async-output} @expansion{}
29452 @code{[ @var{token} ] "+" @var{async-output nl}}
29453
29454 @item @var{notify-async-output} @expansion{}
29455 @code{[ @var{token} ] "=" @var{async-output nl}}
29456
29457 @item @var{async-output} @expansion{}
29458 @code{@var{async-class} ( "," @var{result} )*}
29459
29460 @item @var{result-class} @expansion{}
29461 @code{"done" | "running" | "connected" | "error" | "exit"}
29462
29463 @item @var{async-class} @expansion{}
29464 @code{"stopped" | @var{others}} (where @var{others} will be added
29465 depending on the needs---this is still in development).
29466
29467 @item @var{result} @expansion{}
29468 @code{ @var{variable} "=" @var{value}}
29469
29470 @item @var{variable} @expansion{}
29471 @code{ @var{string} }
29472
29473 @item @var{value} @expansion{}
29474 @code{ @var{const} | @var{tuple} | @var{list} }
29475
29476 @item @var{const} @expansion{}
29477 @code{@var{c-string}}
29478
29479 @item @var{tuple} @expansion{}
29480 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
29481
29482 @item @var{list} @expansion{}
29483 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
29484 @var{result} ( "," @var{result} )* "]" }
29485
29486 @item @var{stream-record} @expansion{}
29487 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
29488
29489 @item @var{console-stream-output} @expansion{}
29490 @code{"~" @var{c-string nl}}
29491
29492 @item @var{target-stream-output} @expansion{}
29493 @code{"@@" @var{c-string nl}}
29494
29495 @item @var{log-stream-output} @expansion{}
29496 @code{"&" @var{c-string nl}}
29497
29498 @item @var{nl} @expansion{}
29499 @code{CR | CR-LF}
29500
29501 @item @var{token} @expansion{}
29502 @emph{any sequence of digits}.
29503 @end table
29504
29505 @noindent
29506 Notes:
29507
29508 @itemize @bullet
29509 @item
29510 All output sequences end in a single line containing a period.
29511
29512 @item
29513 The @code{@var{token}} is from the corresponding request. Note that
29514 for all async output, while the token is allowed by the grammar and
29515 may be output by future versions of @value{GDBN} for select async
29516 output messages, it is generally omitted. Frontends should treat
29517 all async output as reporting general changes in the state of the
29518 target and there should be no need to associate async output to any
29519 prior command.
29520
29521 @item
29522 @cindex status output in @sc{gdb/mi}
29523 @var{status-async-output} contains on-going status information about the
29524 progress of a slow operation. It can be discarded. All status output is
29525 prefixed by @samp{+}.
29526
29527 @item
29528 @cindex async output in @sc{gdb/mi}
29529 @var{exec-async-output} contains asynchronous state change on the target
29530 (stopped, started, disappeared). All async output is prefixed by
29531 @samp{*}.
29532
29533 @item
29534 @cindex notify output in @sc{gdb/mi}
29535 @var{notify-async-output} contains supplementary information that the
29536 client should handle (e.g., a new breakpoint information). All notify
29537 output is prefixed by @samp{=}.
29538
29539 @item
29540 @cindex console output in @sc{gdb/mi}
29541 @var{console-stream-output} is output that should be displayed as is in the
29542 console. It is the textual response to a CLI command. All the console
29543 output is prefixed by @samp{~}.
29544
29545 @item
29546 @cindex target output in @sc{gdb/mi}
29547 @var{target-stream-output} is the output produced by the target program.
29548 All the target output is prefixed by @samp{@@}.
29549
29550 @item
29551 @cindex log output in @sc{gdb/mi}
29552 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
29553 instance messages that should be displayed as part of an error log. All
29554 the log output is prefixed by @samp{&}.
29555
29556 @item
29557 @cindex list output in @sc{gdb/mi}
29558 New @sc{gdb/mi} commands should only output @var{lists} containing
29559 @var{values}.
29560
29561
29562 @end itemize
29563
29564 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
29565 details about the various output records.
29566
29567 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29568 @node GDB/MI Compatibility with CLI
29569 @section @sc{gdb/mi} Compatibility with CLI
29570
29571 @cindex compatibility, @sc{gdb/mi} and CLI
29572 @cindex @sc{gdb/mi}, compatibility with CLI
29573
29574 For the developers convenience CLI commands can be entered directly,
29575 but there may be some unexpected behaviour. For example, commands
29576 that query the user will behave as if the user replied yes, breakpoint
29577 command lists are not executed and some CLI commands, such as
29578 @code{if}, @code{when} and @code{define}, prompt for further input with
29579 @samp{>}, which is not valid MI output.
29580
29581 This feature may be removed at some stage in the future and it is
29582 recommended that front ends use the @code{-interpreter-exec} command
29583 (@pxref{-interpreter-exec}).
29584
29585 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29586 @node GDB/MI Development and Front Ends
29587 @section @sc{gdb/mi} Development and Front Ends
29588 @cindex @sc{gdb/mi} development
29589
29590 The application which takes the MI output and presents the state of the
29591 program being debugged to the user is called a @dfn{front end}.
29592
29593 Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
29594 to the MI interface may break existing usage. This section describes how the
29595 protocol changes and how to request previous version of the protocol when it
29596 does.
29597
29598 Some changes in MI need not break a carefully designed front end, and
29599 for these the MI version will remain unchanged. The following is a
29600 list of changes that may occur within one level, so front ends should
29601 parse MI output in a way that can handle them:
29602
29603 @itemize @bullet
29604 @item
29605 New MI commands may be added.
29606
29607 @item
29608 New fields may be added to the output of any MI command.
29609
29610 @item
29611 The range of values for fields with specified values, e.g.,
29612 @code{in_scope} (@pxref{-var-update}) may be extended.
29613
29614 @c The format of field's content e.g type prefix, may change so parse it
29615 @c at your own risk. Yes, in general?
29616
29617 @c The order of fields may change? Shouldn't really matter but it might
29618 @c resolve inconsistencies.
29619 @end itemize
29620
29621 If the changes are likely to break front ends, the MI version level
29622 will be increased by one. The new versions of the MI protocol are not compatible
29623 with the old versions. Old versions of MI remain available, allowing front ends
29624 to keep using them until they are modified to use the latest MI version.
29625
29626 Since @code{--interpreter=mi} always points to the latest MI version, it is
29627 recommended that front ends request a specific version of MI when launching
29628 @value{GDBN} (e.g. @code{--interpreter=mi2}) to make sure they get an
29629 interpreter with the MI version they expect.
29630
29631 The following table gives a summary of the released versions of the MI
29632 interface: the version number, the version of GDB in which it first appeared
29633 and the breaking changes compared to the previous version.
29634
29635 @multitable @columnfractions .05 .05 .9
29636 @headitem MI version @tab GDB version @tab Breaking changes
29637
29638 @item
29639 @center 1
29640 @tab
29641 @center 5.1
29642 @tab
29643 None
29644
29645 @item
29646 @center 2
29647 @tab
29648 @center 6.0
29649 @tab
29650
29651 @itemize
29652 @item
29653 The @code{-environment-pwd}, @code{-environment-directory} and
29654 @code{-environment-path} commands now returns values using the MI output
29655 syntax, rather than CLI output syntax.
29656
29657 @item
29658 @code{-var-list-children}'s @code{children} result field is now a list, rather
29659 than a tuple.
29660
29661 @item
29662 @code{-var-update}'s @code{changelist} result field is now a list, rather than
29663 a tuple.
29664 @end itemize
29665
29666 @item
29667 @center 3
29668 @tab
29669 @center 9.1
29670 @tab
29671
29672 @itemize
29673 @item
29674 The output of information about multi-location breakpoints has changed in the
29675 responses to the @code{-break-insert} and @code{-break-info} commands, as well
29676 as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
29677 The multiple locations are now placed in a @code{locations} field, whose value
29678 is a list.
29679 @end itemize
29680
29681 @end multitable
29682
29683 If your front end cannot yet migrate to a more recent version of the
29684 MI protocol, you can nevertheless selectively enable specific features
29685 available in those recent MI versions, using the following commands:
29686
29687 @table @code
29688
29689 @item -fix-multi-location-breakpoint-output
29690 Use the output for multi-location breakpoints which was introduced by
29691 MI 3, even when using MI versions 2 or 1. This command has no
29692 effect when using MI version 3 or later.
29693
29694 @end table
29695
29696 The best way to avoid unexpected changes in MI that might break your front
29697 end is to make your project known to @value{GDBN} developers and
29698 follow development on @email{gdb@@sourceware.org} and
29699 @email{gdb-patches@@sourceware.org}.
29700 @cindex mailing lists
29701
29702 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29703 @node GDB/MI Output Records
29704 @section @sc{gdb/mi} Output Records
29705
29706 @menu
29707 * GDB/MI Result Records::
29708 * GDB/MI Stream Records::
29709 * GDB/MI Async Records::
29710 * GDB/MI Breakpoint Information::
29711 * GDB/MI Frame Information::
29712 * GDB/MI Thread Information::
29713 * GDB/MI Ada Exception Information::
29714 @end menu
29715
29716 @node GDB/MI Result Records
29717 @subsection @sc{gdb/mi} Result Records
29718
29719 @cindex result records in @sc{gdb/mi}
29720 @cindex @sc{gdb/mi}, result records
29721 In addition to a number of out-of-band notifications, the response to a
29722 @sc{gdb/mi} command includes one of the following result indications:
29723
29724 @table @code
29725 @findex ^done
29726 @item "^done" [ "," @var{results} ]
29727 The synchronous operation was successful, @code{@var{results}} are the return
29728 values.
29729
29730 @item "^running"
29731 @findex ^running
29732 This result record is equivalent to @samp{^done}. Historically, it
29733 was output instead of @samp{^done} if the command has resumed the
29734 target. This behaviour is maintained for backward compatibility, but
29735 all frontends should treat @samp{^done} and @samp{^running}
29736 identically and rely on the @samp{*running} output record to determine
29737 which threads are resumed.
29738
29739 @item "^connected"
29740 @findex ^connected
29741 @value{GDBN} has connected to a remote target.
29742
29743 @item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
29744 @findex ^error
29745 The operation failed. The @code{msg=@var{c-string}} variable contains
29746 the corresponding error message.
29747
29748 If present, the @code{code=@var{c-string}} variable provides an error
29749 code on which consumers can rely on to detect the corresponding
29750 error condition. At present, only one error code is defined:
29751
29752 @table @samp
29753 @item "undefined-command"
29754 Indicates that the command causing the error does not exist.
29755 @end table
29756
29757 @item "^exit"
29758 @findex ^exit
29759 @value{GDBN} has terminated.
29760
29761 @end table
29762
29763 @node GDB/MI Stream Records
29764 @subsection @sc{gdb/mi} Stream Records
29765
29766 @cindex @sc{gdb/mi}, stream records
29767 @cindex stream records in @sc{gdb/mi}
29768 @value{GDBN} internally maintains a number of output streams: the console, the
29769 target, and the log. The output intended for each of these streams is
29770 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
29771
29772 Each stream record begins with a unique @dfn{prefix character} which
29773 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
29774 Syntax}). In addition to the prefix, each stream record contains a
29775 @code{@var{string-output}}. This is either raw text (with an implicit new
29776 line) or a quoted C string (which does not contain an implicit newline).
29777
29778 @table @code
29779 @item "~" @var{string-output}
29780 The console output stream contains text that should be displayed in the
29781 CLI console window. It contains the textual responses to CLI commands.
29782
29783 @item "@@" @var{string-output}
29784 The target output stream contains any textual output from the running
29785 target. This is only present when GDB's event loop is truly
29786 asynchronous, which is currently only the case for remote targets.
29787
29788 @item "&" @var{string-output}
29789 The log stream contains debugging messages being produced by @value{GDBN}'s
29790 internals.
29791 @end table
29792
29793 @node GDB/MI Async Records
29794 @subsection @sc{gdb/mi} Async Records
29795
29796 @cindex async records in @sc{gdb/mi}
29797 @cindex @sc{gdb/mi}, async records
29798 @dfn{Async} records are used to notify the @sc{gdb/mi} client of
29799 additional changes that have occurred. Those changes can either be a
29800 consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
29801 target activity (e.g., target stopped).
29802
29803 The following is the list of possible async records:
29804
29805 @table @code
29806
29807 @item *running,thread-id="@var{thread}"
29808 The target is now running. The @var{thread} field can be the global
29809 thread ID of the thread that is now running, and it can be
29810 @samp{all} if all threads are running. The frontend should assume
29811 that no interaction with a running thread is possible after this
29812 notification is produced. The frontend should not assume that this
29813 notification is output only once for any command. @value{GDBN} may
29814 emit this notification several times, either for different threads,
29815 because it cannot resume all threads together, or even for a single
29816 thread, if the thread must be stepped though some code before letting
29817 it run freely.
29818
29819 @item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
29820 The target has stopped. The @var{reason} field can have one of the
29821 following values:
29822
29823 @table @code
29824 @item breakpoint-hit
29825 A breakpoint was reached.
29826 @item watchpoint-trigger
29827 A watchpoint was triggered.
29828 @item read-watchpoint-trigger
29829 A read watchpoint was triggered.
29830 @item access-watchpoint-trigger
29831 An access watchpoint was triggered.
29832 @item function-finished
29833 An -exec-finish or similar CLI command was accomplished.
29834 @item location-reached
29835 An -exec-until or similar CLI command was accomplished.
29836 @item watchpoint-scope
29837 A watchpoint has gone out of scope.
29838 @item end-stepping-range
29839 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
29840 similar CLI command was accomplished.
29841 @item exited-signalled
29842 The inferior exited because of a signal.
29843 @item exited
29844 The inferior exited.
29845 @item exited-normally
29846 The inferior exited normally.
29847 @item signal-received
29848 A signal was received by the inferior.
29849 @item solib-event
29850 The inferior has stopped due to a library being loaded or unloaded.
29851 This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
29852 set or when a @code{catch load} or @code{catch unload} catchpoint is
29853 in use (@pxref{Set Catchpoints}).
29854 @item fork
29855 The inferior has forked. This is reported when @code{catch fork}
29856 (@pxref{Set Catchpoints}) has been used.
29857 @item vfork
29858 The inferior has vforked. This is reported in when @code{catch vfork}
29859 (@pxref{Set Catchpoints}) has been used.
29860 @item syscall-entry
29861 The inferior entered a system call. This is reported when @code{catch
29862 syscall} (@pxref{Set Catchpoints}) has been used.
29863 @item syscall-return
29864 The inferior returned from a system call. This is reported when
29865 @code{catch syscall} (@pxref{Set Catchpoints}) has been used.
29866 @item exec
29867 The inferior called @code{exec}. This is reported when @code{catch exec}
29868 (@pxref{Set Catchpoints}) has been used.
29869 @end table
29870
29871 The @var{id} field identifies the global thread ID of the thread
29872 that directly caused the stop -- for example by hitting a breakpoint.
29873 Depending on whether all-stop
29874 mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
29875 stop all threads, or only the thread that directly triggered the stop.
29876 If all threads are stopped, the @var{stopped} field will have the
29877 value of @code{"all"}. Otherwise, the value of the @var{stopped}
29878 field will be a list of thread identifiers. Presently, this list will
29879 always include a single thread, but frontend should be prepared to see
29880 several threads in the list. The @var{core} field reports the
29881 processor core on which the stop event has happened. This field may be absent
29882 if such information is not available.
29883
29884 @item =thread-group-added,id="@var{id}"
29885 @itemx =thread-group-removed,id="@var{id}"
29886 A thread group was either added or removed. The @var{id} field
29887 contains the @value{GDBN} identifier of the thread group. When a thread
29888 group is added, it generally might not be associated with a running
29889 process. When a thread group is removed, its id becomes invalid and
29890 cannot be used in any way.
29891
29892 @item =thread-group-started,id="@var{id}",pid="@var{pid}"
29893 A thread group became associated with a running program,
29894 either because the program was just started or the thread group
29895 was attached to a program. The @var{id} field contains the
29896 @value{GDBN} identifier of the thread group. The @var{pid} field
29897 contains process identifier, specific to the operating system.
29898
29899 @item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
29900 A thread group is no longer associated with a running program,
29901 either because the program has exited, or because it was detached
29902 from. The @var{id} field contains the @value{GDBN} identifier of the
29903 thread group. The @var{code} field is the exit code of the inferior; it exists
29904 only when the inferior exited with some code.
29905
29906 @item =thread-created,id="@var{id}",group-id="@var{gid}"
29907 @itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
29908 A thread either was created, or has exited. The @var{id} field
29909 contains the global @value{GDBN} identifier of the thread. The @var{gid}
29910 field identifies the thread group this thread belongs to.
29911
29912 @item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
29913 Informs that the selected thread or frame were changed. This notification
29914 is not emitted as result of the @code{-thread-select} or
29915 @code{-stack-select-frame} commands, but is emitted whenever an MI command
29916 that is not documented to change the selected thread and frame actually
29917 changes them. In particular, invoking, directly or indirectly
29918 (via user-defined command), the CLI @code{thread} or @code{frame} commands,
29919 will generate this notification. Changing the thread or frame from another
29920 user interface (see @ref{Interpreters}) will also generate this notification.
29921
29922 The @var{frame} field is only present if the newly selected thread is
29923 stopped. See @ref{GDB/MI Frame Information} for the format of its value.
29924
29925 We suggest that in response to this notification, front ends
29926 highlight the selected thread and cause subsequent commands to apply to
29927 that thread.
29928
29929 @item =library-loaded,...
29930 Reports that a new library file was loaded by the program. This
29931 notification has 5 fields---@var{id}, @var{target-name},
29932 @var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
29933 opaque identifier of the library. For remote debugging case,
29934 @var{target-name} and @var{host-name} fields give the name of the
29935 library file on the target, and on the host respectively. For native
29936 debugging, both those fields have the same value. The
29937 @var{symbols-loaded} field is emitted only for backward compatibility
29938 and should not be relied on to convey any useful information. The
29939 @var{thread-group} field, if present, specifies the id of the thread
29940 group in whose context the library was loaded. If the field is
29941 absent, it means the library was loaded in the context of all present
29942 thread groups. The @var{ranges} field specifies the ranges of addresses belonging
29943 to this library.
29944
29945 @item =library-unloaded,...
29946 Reports that a library was unloaded by the program. This notification
29947 has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
29948 the same meaning as for the @code{=library-loaded} notification.
29949 The @var{thread-group} field, if present, specifies the id of the
29950 thread group in whose context the library was unloaded. If the field is
29951 absent, it means the library was unloaded in the context of all present
29952 thread groups.
29953
29954 @item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
29955 @itemx =traceframe-changed,end
29956 Reports that the trace frame was changed and its new number is
29957 @var{tfnum}. The number of the tracepoint associated with this trace
29958 frame is @var{tpnum}.
29959
29960 @item =tsv-created,name=@var{name},initial=@var{initial}
29961 Reports that the new trace state variable @var{name} is created with
29962 initial value @var{initial}.
29963
29964 @item =tsv-deleted,name=@var{name}
29965 @itemx =tsv-deleted
29966 Reports that the trace state variable @var{name} is deleted or all
29967 trace state variables are deleted.
29968
29969 @item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
29970 Reports that the trace state variable @var{name} is modified with
29971 the initial value @var{initial}. The current value @var{current} of
29972 trace state variable is optional and is reported if the current
29973 value of trace state variable is known.
29974
29975 @item =breakpoint-created,bkpt=@{...@}
29976 @itemx =breakpoint-modified,bkpt=@{...@}
29977 @itemx =breakpoint-deleted,id=@var{number}
29978 Reports that a breakpoint was created, modified, or deleted,
29979 respectively. Only user-visible breakpoints are reported to the MI
29980 user.
29981
29982 The @var{bkpt} argument is of the same form as returned by the various
29983 breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
29984 @var{number} is the ordinal number of the breakpoint.
29985
29986 Note that if a breakpoint is emitted in the result record of a
29987 command, then it will not also be emitted in an async record.
29988
29989 @item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
29990 @itemx =record-stopped,thread-group="@var{id}"
29991 Execution log recording was either started or stopped on an
29992 inferior. The @var{id} is the @value{GDBN} identifier of the thread
29993 group corresponding to the affected inferior.
29994
29995 The @var{method} field indicates the method used to record execution. If the
29996 method in use supports multiple recording formats, @var{format} will be present
29997 and contain the currently used format. @xref{Process Record and Replay},
29998 for existing method and format values.
29999
30000 @item =cmd-param-changed,param=@var{param},value=@var{value}
30001 Reports that a parameter of the command @code{set @var{param}} is
30002 changed to @var{value}. In the multi-word @code{set} command,
30003 the @var{param} is the whole parameter list to @code{set} command.
30004 For example, In command @code{set check type on}, @var{param}
30005 is @code{check type} and @var{value} is @code{on}.
30006
30007 @item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
30008 Reports that bytes from @var{addr} to @var{data} + @var{len} were
30009 written in an inferior. The @var{id} is the identifier of the
30010 thread group corresponding to the affected inferior. The optional
30011 @code{type="code"} part is reported if the memory written to holds
30012 executable code.
30013 @end table
30014
30015 @node GDB/MI Breakpoint Information
30016 @subsection @sc{gdb/mi} Breakpoint Information
30017
30018 When @value{GDBN} reports information about a breakpoint, a
30019 tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
30020 following fields:
30021
30022 @table @code
30023 @item number
30024 The breakpoint number.
30025
30026 @item type
30027 The type of the breakpoint. For ordinary breakpoints this will be
30028 @samp{breakpoint}, but many values are possible.
30029
30030 @item catch-type
30031 If the type of the breakpoint is @samp{catchpoint}, then this
30032 indicates the exact type of catchpoint.
30033
30034 @item disp
30035 This is the breakpoint disposition---either @samp{del}, meaning that
30036 the breakpoint will be deleted at the next stop, or @samp{keep},
30037 meaning that the breakpoint will not be deleted.
30038
30039 @item enabled
30040 This indicates whether the breakpoint is enabled, in which case the
30041 value is @samp{y}, or disabled, in which case the value is @samp{n}.
30042 Note that this is not the same as the field @code{enable}.
30043
30044 @item addr
30045 The address of the breakpoint. This may be a hexidecimal number,
30046 giving the address; or the string @samp{<PENDING>}, for a pending
30047 breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
30048 multiple locations. This field will not be present if no address can
30049 be determined. For example, a watchpoint does not have an address.
30050
30051 @item addr_flags
30052 Optional field containing any flags related to the address. These flags are
30053 architecture-dependent; see @ref{Architectures} for their meaning for a
30054 particular CPU.
30055
30056 @item func
30057 If known, the function in which the breakpoint appears.
30058 If not known, this field is not present.
30059
30060 @item filename
30061 The name of the source file which contains this function, if known.
30062 If not known, this field is not present.
30063
30064 @item fullname
30065 The full file name of the source file which contains this function, if
30066 known. If not known, this field is not present.
30067
30068 @item line
30069 The line number at which this breakpoint appears, if known.
30070 If not known, this field is not present.
30071
30072 @item at
30073 If the source file is not known, this field may be provided. If
30074 provided, this holds the address of the breakpoint, possibly followed
30075 by a symbol name.
30076
30077 @item pending
30078 If this breakpoint is pending, this field is present and holds the
30079 text used to set the breakpoint, as entered by the user.
30080
30081 @item evaluated-by
30082 Where this breakpoint's condition is evaluated, either @samp{host} or
30083 @samp{target}.
30084
30085 @item thread
30086 If this is a thread-specific breakpoint, then this identifies the
30087 thread in which the breakpoint can trigger.
30088
30089 @item task
30090 If this breakpoint is restricted to a particular Ada task, then this
30091 field will hold the task identifier.
30092
30093 @item cond
30094 If the breakpoint is conditional, this is the condition expression.
30095
30096 @item ignore
30097 The ignore count of the breakpoint.
30098
30099 @item enable
30100 The enable count of the breakpoint.
30101
30102 @item traceframe-usage
30103 FIXME.
30104
30105 @item static-tracepoint-marker-string-id
30106 For a static tracepoint, the name of the static tracepoint marker.
30107
30108 @item mask
30109 For a masked watchpoint, this is the mask.
30110
30111 @item pass
30112 A tracepoint's pass count.
30113
30114 @item original-location
30115 The location of the breakpoint as originally specified by the user.
30116 This field is optional.
30117
30118 @item times
30119 The number of times the breakpoint has been hit.
30120
30121 @item installed
30122 This field is only given for tracepoints. This is either @samp{y},
30123 meaning that the tracepoint is installed, or @samp{n}, meaning that it
30124 is not.
30125
30126 @item what
30127 Some extra data, the exact contents of which are type-dependent.
30128
30129 @item locations
30130 This field is present if the breakpoint has multiple locations. It is also
30131 exceptionally present if the breakpoint is enabled and has a single, disabled
30132 location.
30133
30134 The value is a list of locations. The format of a location is described below.
30135
30136 @end table
30137
30138 A location in a multi-location breakpoint is represented as a tuple with the
30139 following fields:
30140
30141 @table @code
30142
30143 @item number
30144 The location number as a dotted pair, like @samp{1.2}. The first digit is the
30145 number of the parent breakpoint. The second digit is the number of the
30146 location within that breakpoint.
30147
30148 @item enabled
30149 This indicates whether the location is enabled, in which case the
30150 value is @samp{y}, or disabled, in which case the value is @samp{n}.
30151 Note that this is not the same as the field @code{enable}.
30152
30153 @item addr
30154 The address of this location as an hexidecimal number.
30155
30156 @item addr_flags
30157 Optional field containing any flags related to the address. These flags are
30158 architecture-dependent; see @ref{Architectures} for their meaning for a
30159 particular CPU.
30160
30161 @item func
30162 If known, the function in which the location appears.
30163 If not known, this field is not present.
30164
30165 @item file
30166 The name of the source file which contains this location, if known.
30167 If not known, this field is not present.
30168
30169 @item fullname
30170 The full file name of the source file which contains this location, if
30171 known. If not known, this field is not present.
30172
30173 @item line
30174 The line number at which this location appears, if known.
30175 If not known, this field is not present.
30176
30177 @item thread-groups
30178 The thread groups this location is in.
30179
30180 @end table
30181
30182 For example, here is what the output of @code{-break-insert}
30183 (@pxref{GDB/MI Breakpoint Commands}) might be:
30184
30185 @smallexample
30186 -> -break-insert main
30187 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30188 enabled="y",addr="0x08048564",func="main",file="myprog.c",
30189 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
30190 times="0"@}
30191 <- (gdb)
30192 @end smallexample
30193
30194 @node GDB/MI Frame Information
30195 @subsection @sc{gdb/mi} Frame Information
30196
30197 Response from many MI commands includes an information about stack
30198 frame. This information is a tuple that may have the following
30199 fields:
30200
30201 @table @code
30202 @item level
30203 The level of the stack frame. The innermost frame has the level of
30204 zero. This field is always present.
30205
30206 @item func
30207 The name of the function corresponding to the frame. This field may
30208 be absent if @value{GDBN} is unable to determine the function name.
30209
30210 @item addr
30211 The code address for the frame. This field is always present.
30212
30213 @item addr_flags
30214 Optional field containing any flags related to the address. These flags are
30215 architecture-dependent; see @ref{Architectures} for their meaning for a
30216 particular CPU.
30217
30218 @item file
30219 The name of the source files that correspond to the frame's code
30220 address. This field may be absent.
30221
30222 @item line
30223 The source line corresponding to the frames' code address. This field
30224 may be absent.
30225
30226 @item from
30227 The name of the binary file (either executable or shared library) the
30228 corresponds to the frame's code address. This field may be absent.
30229
30230 @end table
30231
30232 @node GDB/MI Thread Information
30233 @subsection @sc{gdb/mi} Thread Information
30234
30235 Whenever @value{GDBN} has to report an information about a thread, it
30236 uses a tuple with the following fields. The fields are always present unless
30237 stated otherwise.
30238
30239 @table @code
30240 @item id
30241 The global numeric id assigned to the thread by @value{GDBN}.
30242
30243 @item target-id
30244 The target-specific string identifying the thread.
30245
30246 @item details
30247 Additional information about the thread provided by the target.
30248 It is supposed to be human-readable and not interpreted by the
30249 frontend. This field is optional.
30250
30251 @item name
30252 The name of the thread. If the user specified a name using the
30253 @code{thread name} command, then this name is given. Otherwise, if
30254 @value{GDBN} can extract the thread name from the target, then that
30255 name is given. If @value{GDBN} cannot find the thread name, then this
30256 field is omitted.
30257
30258 @item state
30259 The execution state of the thread, either @samp{stopped} or @samp{running},
30260 depending on whether the thread is presently running.
30261
30262 @item frame
30263 The stack frame currently executing in the thread. This field is only present
30264 if the thread is stopped. Its format is documented in
30265 @ref{GDB/MI Frame Information}.
30266
30267 @item core
30268 The value of this field is an integer number of the processor core the
30269 thread was last seen on. This field is optional.
30270 @end table
30271
30272 @node GDB/MI Ada Exception Information
30273 @subsection @sc{gdb/mi} Ada Exception Information
30274
30275 Whenever a @code{*stopped} record is emitted because the program
30276 stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
30277 @value{GDBN} provides the name of the exception that was raised via
30278 the @code{exception-name} field. Also, for exceptions that were raised
30279 with an exception message, @value{GDBN} provides that message via
30280 the @code{exception-message} field.
30281
30282 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30283 @node GDB/MI Simple Examples
30284 @section Simple Examples of @sc{gdb/mi} Interaction
30285 @cindex @sc{gdb/mi}, simple examples
30286
30287 This subsection presents several simple examples of interaction using
30288 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
30289 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
30290 the output received from @sc{gdb/mi}.
30291
30292 Note the line breaks shown in the examples are here only for
30293 readability, they don't appear in the real output.
30294
30295 @subheading Setting a Breakpoint
30296
30297 Setting a breakpoint generates synchronous output which contains detailed
30298 information of the breakpoint.
30299
30300 @smallexample
30301 -> -break-insert main
30302 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30303 enabled="y",addr="0x08048564",func="main",file="myprog.c",
30304 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
30305 times="0"@}
30306 <- (gdb)
30307 @end smallexample
30308
30309 @subheading Program Execution
30310
30311 Program execution generates asynchronous records and MI gives the
30312 reason that execution stopped.
30313
30314 @smallexample
30315 -> -exec-run
30316 <- ^running
30317 <- (gdb)
30318 <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
30319 frame=@{addr="0x08048564",func="main",
30320 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
30321 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
30322 arch="i386:x86_64"@}
30323 <- (gdb)
30324 -> -exec-continue
30325 <- ^running
30326 <- (gdb)
30327 <- *stopped,reason="exited-normally"
30328 <- (gdb)
30329 @end smallexample
30330
30331 @subheading Quitting @value{GDBN}
30332
30333 Quitting @value{GDBN} just prints the result class @samp{^exit}.
30334
30335 @smallexample
30336 -> (gdb)
30337 <- -gdb-exit
30338 <- ^exit
30339 @end smallexample
30340
30341 Please note that @samp{^exit} is printed immediately, but it might
30342 take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
30343 performs necessary cleanups, including killing programs being debugged
30344 or disconnecting from debug hardware, so the frontend should wait till
30345 @value{GDBN} exits and should only forcibly kill @value{GDBN} if it
30346 fails to exit in reasonable time.
30347
30348 @subheading A Bad Command
30349
30350 Here's what happens if you pass a non-existent command:
30351
30352 @smallexample
30353 -> -rubbish
30354 <- ^error,msg="Undefined MI command: rubbish"
30355 <- (gdb)
30356 @end smallexample
30357
30358
30359 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30360 @node GDB/MI Command Description Format
30361 @section @sc{gdb/mi} Command Description Format
30362
30363 The remaining sections describe blocks of commands. Each block of
30364 commands is laid out in a fashion similar to this section.
30365
30366 @subheading Motivation
30367
30368 The motivation for this collection of commands.
30369
30370 @subheading Introduction
30371
30372 A brief introduction to this collection of commands as a whole.
30373
30374 @subheading Commands
30375
30376 For each command in the block, the following is described:
30377
30378 @subsubheading Synopsis
30379
30380 @smallexample
30381 -command @var{args}@dots{}
30382 @end smallexample
30383
30384 @subsubheading Result
30385
30386 @subsubheading @value{GDBN} Command
30387
30388 The corresponding @value{GDBN} CLI command(s), if any.
30389
30390 @subsubheading Example
30391
30392 Example(s) formatted for readability. Some of the described commands have
30393 not been implemented yet and these are labeled N.A.@: (not available).
30394
30395
30396 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30397 @node GDB/MI Breakpoint Commands
30398 @section @sc{gdb/mi} Breakpoint Commands
30399
30400 @cindex breakpoint commands for @sc{gdb/mi}
30401 @cindex @sc{gdb/mi}, breakpoint commands
30402 This section documents @sc{gdb/mi} commands for manipulating
30403 breakpoints.
30404
30405 @subheading The @code{-break-after} Command
30406 @findex -break-after
30407
30408 @subsubheading Synopsis
30409
30410 @smallexample
30411 -break-after @var{number} @var{count}
30412 @end smallexample
30413
30414 The breakpoint number @var{number} is not in effect until it has been
30415 hit @var{count} times. To see how this is reflected in the output of
30416 the @samp{-break-list} command, see the description of the
30417 @samp{-break-list} command below.
30418
30419 @subsubheading @value{GDBN} Command
30420
30421 The corresponding @value{GDBN} command is @samp{ignore}.
30422
30423 @subsubheading Example
30424
30425 @smallexample
30426 (gdb)
30427 -break-insert main
30428 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30429 enabled="y",addr="0x000100d0",func="main",file="hello.c",
30430 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
30431 times="0"@}
30432 (gdb)
30433 -break-after 1 3
30434 ~
30435 ^done
30436 (gdb)
30437 -break-list
30438 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30439 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30440 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30441 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30442 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30443 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30444 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30445 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30446 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30447 line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
30448 (gdb)
30449 @end smallexample
30450
30451 @ignore
30452 @subheading The @code{-break-catch} Command
30453 @findex -break-catch
30454 @end ignore
30455
30456 @subheading The @code{-break-commands} Command
30457 @findex -break-commands
30458
30459 @subsubheading Synopsis
30460
30461 @smallexample
30462 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
30463 @end smallexample
30464
30465 Specifies the CLI commands that should be executed when breakpoint
30466 @var{number} is hit. The parameters @var{command1} to @var{commandN}
30467 are the commands. If no command is specified, any previously-set
30468 commands are cleared. @xref{Break Commands}. Typical use of this
30469 functionality is tracing a program, that is, printing of values of
30470 some variables whenever breakpoint is hit and then continuing.
30471
30472 @subsubheading @value{GDBN} Command
30473
30474 The corresponding @value{GDBN} command is @samp{commands}.
30475
30476 @subsubheading Example
30477
30478 @smallexample
30479 (gdb)
30480 -break-insert main
30481 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
30482 enabled="y",addr="0x000100d0",func="main",file="hello.c",
30483 fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
30484 times="0"@}
30485 (gdb)
30486 -break-commands 1 "print v" "continue"
30487 ^done
30488 (gdb)
30489 @end smallexample
30490
30491 @subheading The @code{-break-condition} Command
30492 @findex -break-condition
30493
30494 @subsubheading Synopsis
30495
30496 @smallexample
30497 -break-condition @var{number} @var{expr}
30498 @end smallexample
30499
30500 Breakpoint @var{number} will stop the program only if the condition in
30501 @var{expr} is true. The condition becomes part of the
30502 @samp{-break-list} output (see the description of the @samp{-break-list}
30503 command below).
30504
30505 @subsubheading @value{GDBN} Command
30506
30507 The corresponding @value{GDBN} command is @samp{condition}.
30508
30509 @subsubheading Example
30510
30511 @smallexample
30512 (gdb)
30513 -break-condition 1 1
30514 ^done
30515 (gdb)
30516 -break-list
30517 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30518 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30519 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30520 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30521 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30522 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30523 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30524 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30525 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30526 line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
30527 (gdb)
30528 @end smallexample
30529
30530 @subheading The @code{-break-delete} Command
30531 @findex -break-delete
30532
30533 @subsubheading Synopsis
30534
30535 @smallexample
30536 -break-delete ( @var{breakpoint} )+
30537 @end smallexample
30538
30539 Delete the breakpoint(s) whose number(s) are specified in the argument
30540 list. This is obviously reflected in the breakpoint list.
30541
30542 @subsubheading @value{GDBN} Command
30543
30544 The corresponding @value{GDBN} command is @samp{delete}.
30545
30546 @subsubheading Example
30547
30548 @smallexample
30549 (gdb)
30550 -break-delete 1
30551 ^done
30552 (gdb)
30553 -break-list
30554 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30555 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30556 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30557 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30558 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30559 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30560 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30561 body=[]@}
30562 (gdb)
30563 @end smallexample
30564
30565 @subheading The @code{-break-disable} Command
30566 @findex -break-disable
30567
30568 @subsubheading Synopsis
30569
30570 @smallexample
30571 -break-disable ( @var{breakpoint} )+
30572 @end smallexample
30573
30574 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
30575 break list is now set to @samp{n} for the named @var{breakpoint}(s).
30576
30577 @subsubheading @value{GDBN} Command
30578
30579 The corresponding @value{GDBN} command is @samp{disable}.
30580
30581 @subsubheading Example
30582
30583 @smallexample
30584 (gdb)
30585 -break-disable 2
30586 ^done
30587 (gdb)
30588 -break-list
30589 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30590 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30591 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30592 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30593 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30594 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30595 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30596 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
30597 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30598 line="5",thread-groups=["i1"],times="0"@}]@}
30599 (gdb)
30600 @end smallexample
30601
30602 @subheading The @code{-break-enable} Command
30603 @findex -break-enable
30604
30605 @subsubheading Synopsis
30606
30607 @smallexample
30608 -break-enable ( @var{breakpoint} )+
30609 @end smallexample
30610
30611 Enable (previously disabled) @var{breakpoint}(s).
30612
30613 @subsubheading @value{GDBN} Command
30614
30615 The corresponding @value{GDBN} command is @samp{enable}.
30616
30617 @subsubheading Example
30618
30619 @smallexample
30620 (gdb)
30621 -break-enable 2
30622 ^done
30623 (gdb)
30624 -break-list
30625 ^done,BreakpointTable=@{nr_rows="1",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="2",type="breakpoint",disp="keep",enabled="y",
30633 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30634 line="5",thread-groups=["i1"],times="0"@}]@}
30635 (gdb)
30636 @end smallexample
30637
30638 @subheading The @code{-break-info} Command
30639 @findex -break-info
30640
30641 @subsubheading Synopsis
30642
30643 @smallexample
30644 -break-info @var{breakpoint}
30645 @end smallexample
30646
30647 @c REDUNDANT???
30648 Get information about a single breakpoint.
30649
30650 The result is a table of breakpoints. @xref{GDB/MI Breakpoint
30651 Information}, for details on the format of each breakpoint in the
30652 table.
30653
30654 @subsubheading @value{GDBN} Command
30655
30656 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
30657
30658 @subsubheading Example
30659 N.A.
30660
30661 @subheading The @code{-break-insert} Command
30662 @findex -break-insert
30663 @anchor{-break-insert}
30664
30665 @subsubheading Synopsis
30666
30667 @smallexample
30668 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ] [ --qualified ]
30669 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30670 [ -p @var{thread-id} ] [ @var{location} ]
30671 @end smallexample
30672
30673 @noindent
30674 If specified, @var{location}, can be one of:
30675
30676 @table @var
30677 @item linespec location
30678 A linespec location. @xref{Linespec Locations}.
30679
30680 @item explicit location
30681 An explicit location. @sc{gdb/mi} explicit locations are
30682 analogous to the CLI's explicit locations using the option names
30683 listed below. @xref{Explicit Locations}.
30684
30685 @table @samp
30686 @item --source @var{filename}
30687 The source file name of the location. This option requires the use
30688 of either @samp{--function} or @samp{--line}.
30689
30690 @item --function @var{function}
30691 The name of a function or method.
30692
30693 @item --label @var{label}
30694 The name of a label.
30695
30696 @item --line @var{lineoffset}
30697 An absolute or relative line offset from the start of the location.
30698 @end table
30699
30700 @item address location
30701 An address location, *@var{address}. @xref{Address Locations}.
30702 @end table
30703
30704 @noindent
30705 The possible optional parameters of this command are:
30706
30707 @table @samp
30708 @item -t
30709 Insert a temporary breakpoint.
30710 @item -h
30711 Insert a hardware breakpoint.
30712 @item -f
30713 If @var{location} cannot be parsed (for example if it
30714 refers to unknown files or functions), create a pending
30715 breakpoint. Without this flag, @value{GDBN} will report
30716 an error, and won't create a breakpoint, if @var{location}
30717 cannot be parsed.
30718 @item -d
30719 Create a disabled breakpoint.
30720 @item -a
30721 Create a tracepoint. @xref{Tracepoints}. When this parameter
30722 is used together with @samp{-h}, a fast tracepoint is created.
30723 @item -c @var{condition}
30724 Make the breakpoint conditional on @var{condition}.
30725 @item -i @var{ignore-count}
30726 Initialize the @var{ignore-count}.
30727 @item -p @var{thread-id}
30728 Restrict the breakpoint to the thread with the specified global
30729 @var{thread-id}.
30730 @item --qualified
30731 This option makes @value{GDBN} interpret a function name specified as
30732 a complete fully-qualified name.
30733 @end table
30734
30735 @subsubheading Result
30736
30737 @xref{GDB/MI Breakpoint Information}, for details on the format of the
30738 resulting breakpoint.
30739
30740 Note: this format is open to change.
30741 @c An out-of-band breakpoint instead of part of the result?
30742
30743 @subsubheading @value{GDBN} Command
30744
30745 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
30746 @samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
30747
30748 @subsubheading Example
30749
30750 @smallexample
30751 (gdb)
30752 -break-insert main
30753 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
30754 fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
30755 times="0"@}
30756 (gdb)
30757 -break-insert -t foo
30758 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
30759 fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
30760 times="0"@}
30761 (gdb)
30762 -break-list
30763 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30764 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30765 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30766 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30767 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30768 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30769 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30770 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30771 addr="0x0001072c", func="main",file="recursive2.c",
30772 fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
30773 times="0"@},
30774 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
30775 addr="0x00010774",func="foo",file="recursive2.c",
30776 fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30777 times="0"@}]@}
30778 (gdb)
30779 @c -break-insert -r foo.*
30780 @c ~int foo(int, int);
30781 @c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
30782 @c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30783 @c times="0"@}
30784 @c (gdb)
30785 @end smallexample
30786
30787 @subheading The @code{-dprintf-insert} Command
30788 @findex -dprintf-insert
30789
30790 @subsubheading Synopsis
30791
30792 @smallexample
30793 -dprintf-insert [ -t ] [ -f ] [ -d ] [ --qualified ]
30794 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30795 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
30796 [ @var{argument} ]
30797 @end smallexample
30798
30799 @noindent
30800 If supplied, @var{location} and @code{--qualified} may be specified
30801 the same way as for the @code{-break-insert} command.
30802 @xref{-break-insert}.
30803
30804 The possible optional parameters of this command are:
30805
30806 @table @samp
30807 @item -t
30808 Insert a temporary breakpoint.
30809 @item -f
30810 If @var{location} cannot be parsed (for example, if it
30811 refers to unknown files or functions), create a pending
30812 breakpoint. Without this flag, @value{GDBN} will report
30813 an error, and won't create a breakpoint, if @var{location}
30814 cannot be parsed.
30815 @item -d
30816 Create a disabled breakpoint.
30817 @item -c @var{condition}
30818 Make the breakpoint conditional on @var{condition}.
30819 @item -i @var{ignore-count}
30820 Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
30821 to @var{ignore-count}.
30822 @item -p @var{thread-id}
30823 Restrict the breakpoint to the thread with the specified global
30824 @var{thread-id}.
30825 @end table
30826
30827 @subsubheading Result
30828
30829 @xref{GDB/MI Breakpoint Information}, for details on the format of the
30830 resulting breakpoint.
30831
30832 @c An out-of-band breakpoint instead of part of the result?
30833
30834 @subsubheading @value{GDBN} Command
30835
30836 The corresponding @value{GDBN} command is @samp{dprintf}.
30837
30838 @subsubheading Example
30839
30840 @smallexample
30841 (gdb)
30842 4-dprintf-insert foo "At foo entry\n"
30843 4^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
30844 addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
30845 fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
30846 times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
30847 original-location="foo"@}
30848 (gdb)
30849 5-dprintf-insert 26 "arg=%d, g=%d\n" arg g
30850 5^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
30851 addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
30852 fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
30853 times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
30854 original-location="mi-dprintf.c:26"@}
30855 (gdb)
30856 @end smallexample
30857
30858 @subheading The @code{-break-list} Command
30859 @findex -break-list
30860
30861 @subsubheading Synopsis
30862
30863 @smallexample
30864 -break-list
30865 @end smallexample
30866
30867 Displays the list of inserted breakpoints, showing the following fields:
30868
30869 @table @samp
30870 @item Number
30871 number of the breakpoint
30872 @item Type
30873 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
30874 @item Disposition
30875 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
30876 or @samp{nokeep}
30877 @item Enabled
30878 is the breakpoint enabled or no: @samp{y} or @samp{n}
30879 @item Address
30880 memory location at which the breakpoint is set
30881 @item What
30882 logical location of the breakpoint, expressed by function name, file
30883 name, line number
30884 @item Thread-groups
30885 list of thread groups to which this breakpoint applies
30886 @item Times
30887 number of times the breakpoint has been hit
30888 @end table
30889
30890 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
30891 @code{body} field is an empty list.
30892
30893 @subsubheading @value{GDBN} Command
30894
30895 The corresponding @value{GDBN} command is @samp{info break}.
30896
30897 @subsubheading Example
30898
30899 @smallexample
30900 (gdb)
30901 -break-list
30902 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30903 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30904 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30905 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30906 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30907 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30908 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30909 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30910 addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
30911 times="0"@},
30912 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
30913 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
30914 line="13",thread-groups=["i1"],times="0"@}]@}
30915 (gdb)
30916 @end smallexample
30917
30918 Here's an example of the result when there are no breakpoints:
30919
30920 @smallexample
30921 (gdb)
30922 -break-list
30923 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30924 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30925 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30926 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30927 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30928 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30929 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
30930 body=[]@}
30931 (gdb)
30932 @end smallexample
30933
30934 @subheading The @code{-break-passcount} Command
30935 @findex -break-passcount
30936
30937 @subsubheading Synopsis
30938
30939 @smallexample
30940 -break-passcount @var{tracepoint-number} @var{passcount}
30941 @end smallexample
30942
30943 Set the passcount for tracepoint @var{tracepoint-number} to
30944 @var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
30945 is not a tracepoint, error is emitted. This corresponds to CLI
30946 command @samp{passcount}.
30947
30948 @subheading The @code{-break-watch} Command
30949 @findex -break-watch
30950
30951 @subsubheading Synopsis
30952
30953 @smallexample
30954 -break-watch [ -a | -r ]
30955 @end smallexample
30956
30957 Create a watchpoint. With the @samp{-a} option it will create an
30958 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
30959 read from or on a write to the memory location. With the @samp{-r}
30960 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
30961 trigger only when the memory location is accessed for reading. Without
30962 either of the options, the watchpoint created is a regular watchpoint,
30963 i.e., it will trigger when the memory location is accessed for writing.
30964 @xref{Set Watchpoints, , Setting Watchpoints}.
30965
30966 Note that @samp{-break-list} will report a single list of watchpoints and
30967 breakpoints inserted.
30968
30969 @subsubheading @value{GDBN} Command
30970
30971 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
30972 @samp{rwatch}.
30973
30974 @subsubheading Example
30975
30976 Setting a watchpoint on a variable in the @code{main} function:
30977
30978 @smallexample
30979 (gdb)
30980 -break-watch x
30981 ^done,wpt=@{number="2",exp="x"@}
30982 (gdb)
30983 -exec-continue
30984 ^running
30985 (gdb)
30986 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
30987 value=@{old="-268439212",new="55"@},
30988 frame=@{func="main",args=[],file="recursive2.c",
30989 fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
30990 (gdb)
30991 @end smallexample
30992
30993 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
30994 the program execution twice: first for the variable changing value, then
30995 for the watchpoint going out of scope.
30996
30997 @smallexample
30998 (gdb)
30999 -break-watch C
31000 ^done,wpt=@{number="5",exp="C"@}
31001 (gdb)
31002 -exec-continue
31003 ^running
31004 (gdb)
31005 *stopped,reason="watchpoint-trigger",
31006 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
31007 frame=@{func="callee4",args=[],
31008 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31009 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
31010 arch="i386:x86_64"@}
31011 (gdb)
31012 -exec-continue
31013 ^running
31014 (gdb)
31015 *stopped,reason="watchpoint-scope",wpnum="5",
31016 frame=@{func="callee3",args=[@{name="strarg",
31017 value="0x11940 \"A string argument.\""@}],
31018 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31019 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31020 arch="i386:x86_64"@}
31021 (gdb)
31022 @end smallexample
31023
31024 Listing breakpoints and watchpoints, at different points in the program
31025 execution. Note that once the watchpoint goes out of scope, it is
31026 deleted.
31027
31028 @smallexample
31029 (gdb)
31030 -break-watch C
31031 ^done,wpt=@{number="2",exp="C"@}
31032 (gdb)
31033 -break-list
31034 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
31035 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31036 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31037 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31038 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31039 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31040 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31041 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31042 addr="0x00010734",func="callee4",
31043 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31044 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
31045 times="1"@},
31046 bkpt=@{number="2",type="watchpoint",disp="keep",
31047 enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
31048 (gdb)
31049 -exec-continue
31050 ^running
31051 (gdb)
31052 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
31053 value=@{old="-276895068",new="3"@},
31054 frame=@{func="callee4",args=[],
31055 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31056 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
31057 arch="i386:x86_64"@}
31058 (gdb)
31059 -break-list
31060 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
31061 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31062 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31063 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31064 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31065 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31066 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31067 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31068 addr="0x00010734",func="callee4",
31069 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31070 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
31071 times="1"@},
31072 bkpt=@{number="2",type="watchpoint",disp="keep",
31073 enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
31074 (gdb)
31075 -exec-continue
31076 ^running
31077 ^done,reason="watchpoint-scope",wpnum="2",
31078 frame=@{func="callee3",args=[@{name="strarg",
31079 value="0x11940 \"A string argument.\""@}],
31080 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31081 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31082 arch="i386:x86_64"@}
31083 (gdb)
31084 -break-list
31085 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
31086 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
31087 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
31088 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
31089 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
31090 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
31091 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
31092 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
31093 addr="0x00010734",func="callee4",
31094 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31095 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31096 thread-groups=["i1"],times="1"@}]@}
31097 (gdb)
31098 @end smallexample
31099
31100
31101 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31102 @node GDB/MI Catchpoint Commands
31103 @section @sc{gdb/mi} Catchpoint Commands
31104
31105 This section documents @sc{gdb/mi} commands for manipulating
31106 catchpoints.
31107
31108 @menu
31109 * Shared Library GDB/MI Catchpoint Commands::
31110 * Ada Exception GDB/MI Catchpoint Commands::
31111 * C++ Exception GDB/MI Catchpoint Commands::
31112 @end menu
31113
31114 @node Shared Library GDB/MI Catchpoint Commands
31115 @subsection Shared Library @sc{gdb/mi} Catchpoints
31116
31117 @subheading The @code{-catch-load} Command
31118 @findex -catch-load
31119
31120 @subsubheading Synopsis
31121
31122 @smallexample
31123 -catch-load [ -t ] [ -d ] @var{regexp}
31124 @end smallexample
31125
31126 Add a catchpoint for library load events. If the @samp{-t} option is used,
31127 the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
31128 Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
31129 in a disabled state. The @samp{regexp} argument is a regular
31130 expression used to match the name of the loaded library.
31131
31132
31133 @subsubheading @value{GDBN} Command
31134
31135 The corresponding @value{GDBN} command is @samp{catch load}.
31136
31137 @subsubheading Example
31138
31139 @smallexample
31140 -catch-load -t foo.so
31141 ^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
31142 what="load of library matching foo.so",catch-type="load",times="0"@}
31143 (gdb)
31144 @end smallexample
31145
31146
31147 @subheading The @code{-catch-unload} Command
31148 @findex -catch-unload
31149
31150 @subsubheading Synopsis
31151
31152 @smallexample
31153 -catch-unload [ -t ] [ -d ] @var{regexp}
31154 @end smallexample
31155
31156 Add a catchpoint for library unload events. If the @samp{-t} option is
31157 used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
31158 Breakpoints}). If the @samp{-d} option is used, the catchpoint is
31159 created in a disabled state. The @samp{regexp} argument is a regular
31160 expression used to match the name of the unloaded library.
31161
31162 @subsubheading @value{GDBN} Command
31163
31164 The corresponding @value{GDBN} command is @samp{catch unload}.
31165
31166 @subsubheading Example
31167
31168 @smallexample
31169 -catch-unload -d bar.so
31170 ^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
31171 what="load of library matching bar.so",catch-type="unload",times="0"@}
31172 (gdb)
31173 @end smallexample
31174
31175 @node Ada Exception GDB/MI Catchpoint Commands
31176 @subsection Ada Exception @sc{gdb/mi} Catchpoints
31177
31178 The following @sc{gdb/mi} commands can be used to create catchpoints
31179 that stop the execution when Ada exceptions are being raised.
31180
31181 @subheading The @code{-catch-assert} Command
31182 @findex -catch-assert
31183
31184 @subsubheading Synopsis
31185
31186 @smallexample
31187 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
31188 @end smallexample
31189
31190 Add a catchpoint for failed Ada assertions.
31191
31192 The possible optional parameters for this command are:
31193
31194 @table @samp
31195 @item -c @var{condition}
31196 Make the catchpoint conditional on @var{condition}.
31197 @item -d
31198 Create a disabled catchpoint.
31199 @item -t
31200 Create a temporary catchpoint.
31201 @end table
31202
31203 @subsubheading @value{GDBN} Command
31204
31205 The corresponding @value{GDBN} command is @samp{catch assert}.
31206
31207 @subsubheading Example
31208
31209 @smallexample
31210 -catch-assert
31211 ^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
31212 enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
31213 thread-groups=["i1"],times="0",
31214 original-location="__gnat_debug_raise_assert_failure"@}
31215 (gdb)
31216 @end smallexample
31217
31218 @subheading The @code{-catch-exception} Command
31219 @findex -catch-exception
31220
31221 @subsubheading Synopsis
31222
31223 @smallexample
31224 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
31225 [ -t ] [ -u ]
31226 @end smallexample
31227
31228 Add a catchpoint stopping when Ada exceptions are raised.
31229 By default, the command stops the program when any Ada exception
31230 gets raised. But it is also possible, by using some of the
31231 optional parameters described below, to create more selective
31232 catchpoints.
31233
31234 The possible optional parameters for this command are:
31235
31236 @table @samp
31237 @item -c @var{condition}
31238 Make the catchpoint conditional on @var{condition}.
31239 @item -d
31240 Create a disabled catchpoint.
31241 @item -e @var{exception-name}
31242 Only stop when @var{exception-name} is raised. This option cannot
31243 be used combined with @samp{-u}.
31244 @item -t
31245 Create a temporary catchpoint.
31246 @item -u
31247 Stop only when an unhandled exception gets raised. This option
31248 cannot be used combined with @samp{-e}.
31249 @end table
31250
31251 @subsubheading @value{GDBN} Command
31252
31253 The corresponding @value{GDBN} commands are @samp{catch exception}
31254 and @samp{catch exception unhandled}.
31255
31256 @subsubheading Example
31257
31258 @smallexample
31259 -catch-exception -e Program_Error
31260 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
31261 enabled="y",addr="0x0000000000404874",
31262 what="`Program_Error' Ada exception", thread-groups=["i1"],
31263 times="0",original-location="__gnat_debug_raise_exception"@}
31264 (gdb)
31265 @end smallexample
31266
31267 @subheading The @code{-catch-handlers} Command
31268 @findex -catch-handlers
31269
31270 @subsubheading Synopsis
31271
31272 @smallexample
31273 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
31274 [ -t ]
31275 @end smallexample
31276
31277 Add a catchpoint stopping when Ada exceptions are handled.
31278 By default, the command stops the program when any Ada exception
31279 gets handled. But it is also possible, by using some of the
31280 optional parameters described below, to create more selective
31281 catchpoints.
31282
31283 The possible optional parameters for this command are:
31284
31285 @table @samp
31286 @item -c @var{condition}
31287 Make the catchpoint conditional on @var{condition}.
31288 @item -d
31289 Create a disabled catchpoint.
31290 @item -e @var{exception-name}
31291 Only stop when @var{exception-name} is handled.
31292 @item -t
31293 Create a temporary catchpoint.
31294 @end table
31295
31296 @subsubheading @value{GDBN} Command
31297
31298 The corresponding @value{GDBN} command is @samp{catch handlers}.
31299
31300 @subsubheading Example
31301
31302 @smallexample
31303 -catch-handlers -e Constraint_Error
31304 ^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
31305 enabled="y",addr="0x0000000000402f68",
31306 what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
31307 times="0",original-location="__gnat_begin_handler"@}
31308 (gdb)
31309 @end smallexample
31310
31311 @node C++ Exception GDB/MI Catchpoint Commands
31312 @subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
31313
31314 The following @sc{gdb/mi} commands can be used to create catchpoints
31315 that stop the execution when C@t{++} exceptions are being throw, rethrown,
31316 or caught.
31317
31318 @subheading The @code{-catch-throw} Command
31319 @findex -catch-throw
31320
31321 @subsubheading Synopsis
31322
31323 @smallexample
31324 -catch-throw [ -t ] [ -r @var{regexp}]
31325 @end smallexample
31326
31327 Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
31328 given, then only exceptions whose type matches the regular expression
31329 will be caught.
31330
31331 If @samp{-t} is given, then the catchpoint is enabled only for one
31332 stop, the catchpoint is automatically deleted after stopping once for
31333 the event.
31334
31335 @subsubheading @value{GDBN} Command
31336
31337 The corresponding @value{GDBN} commands are @samp{catch throw}
31338 and @samp{tcatch throw} (@pxref{Set Catchpoints}).
31339
31340 @subsubheading Example
31341
31342 @smallexample
31343 -catch-throw -r exception_type
31344 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31345 what="exception throw",catch-type="throw",
31346 thread-groups=["i1"],
31347 regexp="exception_type",times="0"@}
31348 (gdb)
31349 -exec-run
31350 ^running
31351 (gdb)
31352 ~"\n"
31353 ~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
31354 in __cxa_throw () from /lib64/libstdc++.so.6\n"
31355 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31356 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
31357 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31358 thread-id="1",stopped-threads="all",core="6"
31359 (gdb)
31360 @end smallexample
31361
31362 @subheading The @code{-catch-rethrow} Command
31363 @findex -catch-rethrow
31364
31365 @subsubheading Synopsis
31366
31367 @smallexample
31368 -catch-rethrow [ -t ] [ -r @var{regexp}]
31369 @end smallexample
31370
31371 Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
31372 then only exceptions whose type matches the regular expression will be
31373 caught.
31374
31375 If @samp{-t} is given, then the catchpoint is enabled only for one
31376 stop, the catchpoint is automatically deleted after the first event is
31377 caught.
31378
31379 @subsubheading @value{GDBN} Command
31380
31381 The corresponding @value{GDBN} commands are @samp{catch rethrow}
31382 and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
31383
31384 @subsubheading Example
31385
31386 @smallexample
31387 -catch-rethrow -r exception_type
31388 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31389 what="exception rethrow",catch-type="rethrow",
31390 thread-groups=["i1"],
31391 regexp="exception_type",times="0"@}
31392 (gdb)
31393 -exec-run
31394 ^running
31395 (gdb)
31396 ~"\n"
31397 ~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
31398 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
31399 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31400 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
31401 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31402 thread-id="1",stopped-threads="all",core="6"
31403 (gdb)
31404 @end smallexample
31405
31406 @subheading The @code{-catch-catch} Command
31407 @findex -catch-catch
31408
31409 @subsubheading Synopsis
31410
31411 @smallexample
31412 -catch-catch [ -t ] [ -r @var{regexp}]
31413 @end smallexample
31414
31415 Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
31416 is given, then only exceptions whose type matches the regular
31417 expression will be caught.
31418
31419 If @samp{-t} is given, then the catchpoint is enabled only for one
31420 stop, the catchpoint is automatically deleted after the first event is
31421 caught.
31422
31423 @subsubheading @value{GDBN} Command
31424
31425 The corresponding @value{GDBN} commands are @samp{catch catch}
31426 and @samp{tcatch catch} (@pxref{Set Catchpoints}).
31427
31428 @subsubheading Example
31429
31430 @smallexample
31431 -catch-catch -r exception_type
31432 ^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
31433 what="exception catch",catch-type="catch",
31434 thread-groups=["i1"],
31435 regexp="exception_type",times="0"@}
31436 (gdb)
31437 -exec-run
31438 ^running
31439 (gdb)
31440 ~"\n"
31441 ~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
31442 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
31443 *stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
31444 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
31445 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
31446 thread-id="1",stopped-threads="all",core="6"
31447 (gdb)
31448 @end smallexample
31449
31450 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31451 @node GDB/MI Program Context
31452 @section @sc{gdb/mi} Program Context
31453
31454 @subheading The @code{-exec-arguments} Command
31455 @findex -exec-arguments
31456
31457
31458 @subsubheading Synopsis
31459
31460 @smallexample
31461 -exec-arguments @var{args}
31462 @end smallexample
31463
31464 Set the inferior program arguments, to be used in the next
31465 @samp{-exec-run}.
31466
31467 @subsubheading @value{GDBN} Command
31468
31469 The corresponding @value{GDBN} command is @samp{set args}.
31470
31471 @subsubheading Example
31472
31473 @smallexample
31474 (gdb)
31475 -exec-arguments -v word
31476 ^done
31477 (gdb)
31478 @end smallexample
31479
31480
31481 @ignore
31482 @subheading The @code{-exec-show-arguments} Command
31483 @findex -exec-show-arguments
31484
31485 @subsubheading Synopsis
31486
31487 @smallexample
31488 -exec-show-arguments
31489 @end smallexample
31490
31491 Print the arguments of the program.
31492
31493 @subsubheading @value{GDBN} Command
31494
31495 The corresponding @value{GDBN} command is @samp{show args}.
31496
31497 @subsubheading Example
31498 N.A.
31499 @end ignore
31500
31501
31502 @subheading The @code{-environment-cd} Command
31503 @findex -environment-cd
31504
31505 @subsubheading Synopsis
31506
31507 @smallexample
31508 -environment-cd @var{pathdir}
31509 @end smallexample
31510
31511 Set @value{GDBN}'s working directory.
31512
31513 @subsubheading @value{GDBN} Command
31514
31515 The corresponding @value{GDBN} command is @samp{cd}.
31516
31517 @subsubheading Example
31518
31519 @smallexample
31520 (gdb)
31521 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31522 ^done
31523 (gdb)
31524 @end smallexample
31525
31526
31527 @subheading The @code{-environment-directory} Command
31528 @findex -environment-directory
31529
31530 @subsubheading Synopsis
31531
31532 @smallexample
31533 -environment-directory [ -r ] [ @var{pathdir} ]+
31534 @end smallexample
31535
31536 Add directories @var{pathdir} to beginning of search path for source files.
31537 If the @samp{-r} option is used, the search path is reset to the default
31538 search path. If directories @var{pathdir} are supplied in addition to the
31539 @samp{-r} option, the search path is first reset and then addition
31540 occurs as normal.
31541 Multiple directories may be specified, separated by blanks. Specifying
31542 multiple directories in a single command
31543 results in the directories added to the beginning of the
31544 search path in the same order they were presented in the command.
31545 If blanks are needed as
31546 part of a directory name, double-quotes should be used around
31547 the name. In the command output, the path will show up separated
31548 by the system directory-separator character. The directory-separator
31549 character must not be used
31550 in any directory name.
31551 If no directories are specified, the current search path is displayed.
31552
31553 @subsubheading @value{GDBN} Command
31554
31555 The corresponding @value{GDBN} command is @samp{dir}.
31556
31557 @subsubheading Example
31558
31559 @smallexample
31560 (gdb)
31561 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31562 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
31563 (gdb)
31564 -environment-directory ""
31565 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
31566 (gdb)
31567 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
31568 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
31569 (gdb)
31570 -environment-directory -r
31571 ^done,source-path="$cdir:$cwd"
31572 (gdb)
31573 @end smallexample
31574
31575
31576 @subheading The @code{-environment-path} Command
31577 @findex -environment-path
31578
31579 @subsubheading Synopsis
31580
31581 @smallexample
31582 -environment-path [ -r ] [ @var{pathdir} ]+
31583 @end smallexample
31584
31585 Add directories @var{pathdir} to beginning of search path for object files.
31586 If the @samp{-r} option is used, the search path is reset to the original
31587 search path that existed at gdb start-up. If directories @var{pathdir} are
31588 supplied in addition to the
31589 @samp{-r} option, the search path is first reset and then addition
31590 occurs as normal.
31591 Multiple directories may be specified, separated by blanks. Specifying
31592 multiple directories in a single command
31593 results in the directories added to the beginning of the
31594 search path in the same order they were presented in the command.
31595 If blanks are needed as
31596 part of a directory name, double-quotes should be used around
31597 the name. In the command output, the path will show up separated
31598 by the system directory-separator character. The directory-separator
31599 character must not be used
31600 in any directory name.
31601 If no directories are specified, the current path is displayed.
31602
31603
31604 @subsubheading @value{GDBN} Command
31605
31606 The corresponding @value{GDBN} command is @samp{path}.
31607
31608 @subsubheading Example
31609
31610 @smallexample
31611 (gdb)
31612 -environment-path
31613 ^done,path="/usr/bin"
31614 (gdb)
31615 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
31616 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
31617 (gdb)
31618 -environment-path -r /usr/local/bin
31619 ^done,path="/usr/local/bin:/usr/bin"
31620 (gdb)
31621 @end smallexample
31622
31623
31624 @subheading The @code{-environment-pwd} Command
31625 @findex -environment-pwd
31626
31627 @subsubheading Synopsis
31628
31629 @smallexample
31630 -environment-pwd
31631 @end smallexample
31632
31633 Show the current working directory.
31634
31635 @subsubheading @value{GDBN} Command
31636
31637 The corresponding @value{GDBN} command is @samp{pwd}.
31638
31639 @subsubheading Example
31640
31641 @smallexample
31642 (gdb)
31643 -environment-pwd
31644 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
31645 (gdb)
31646 @end smallexample
31647
31648 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31649 @node GDB/MI Thread Commands
31650 @section @sc{gdb/mi} Thread Commands
31651
31652
31653 @subheading The @code{-thread-info} Command
31654 @findex -thread-info
31655
31656 @subsubheading Synopsis
31657
31658 @smallexample
31659 -thread-info [ @var{thread-id} ]
31660 @end smallexample
31661
31662 Reports information about either a specific thread, if the
31663 @var{thread-id} parameter is present, or about all threads.
31664 @var{thread-id} is the thread's global thread ID. When printing
31665 information about all threads, also reports the global ID of the
31666 current thread.
31667
31668 @subsubheading @value{GDBN} Command
31669
31670 The @samp{info thread} command prints the same information
31671 about all threads.
31672
31673 @subsubheading Result
31674
31675 The result contains the following attributes:
31676
31677 @table @samp
31678 @item threads
31679 A list of threads. The format of the elements of the list is described in
31680 @ref{GDB/MI Thread Information}.
31681
31682 @item current-thread-id
31683 The global id of the currently selected thread. This field is omitted if there
31684 is no selected thread (for example, when the selected inferior is not running,
31685 and therefore has no threads) or if a @var{thread-id} argument was passed to
31686 the command.
31687
31688 @end table
31689
31690 @subsubheading Example
31691
31692 @smallexample
31693 -thread-info
31694 ^done,threads=[
31695 @{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
31696 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
31697 args=[]@},state="running"@},
31698 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
31699 frame=@{level="0",addr="0x0804891f",func="foo",
31700 args=[@{name="i",value="10"@}],
31701 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
31702 state="running"@}],
31703 current-thread-id="1"
31704 (gdb)
31705 @end smallexample
31706
31707 @subheading The @code{-thread-list-ids} Command
31708 @findex -thread-list-ids
31709
31710 @subsubheading Synopsis
31711
31712 @smallexample
31713 -thread-list-ids
31714 @end smallexample
31715
31716 Produces a list of the currently known global @value{GDBN} thread ids.
31717 At the end of the list it also prints the total number of such
31718 threads.
31719
31720 This command is retained for historical reasons, the
31721 @code{-thread-info} command should be used instead.
31722
31723 @subsubheading @value{GDBN} Command
31724
31725 Part of @samp{info threads} supplies the same information.
31726
31727 @subsubheading Example
31728
31729 @smallexample
31730 (gdb)
31731 -thread-list-ids
31732 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31733 current-thread-id="1",number-of-threads="3"
31734 (gdb)
31735 @end smallexample
31736
31737
31738 @subheading The @code{-thread-select} Command
31739 @findex -thread-select
31740
31741 @subsubheading Synopsis
31742
31743 @smallexample
31744 -thread-select @var{thread-id}
31745 @end smallexample
31746
31747 Make thread with global thread number @var{thread-id} the current
31748 thread. It prints the number of the new current thread, and the
31749 topmost frame for that thread.
31750
31751 This command is deprecated in favor of explicitly using the
31752 @samp{--thread} option to each command.
31753
31754 @subsubheading @value{GDBN} Command
31755
31756 The corresponding @value{GDBN} command is @samp{thread}.
31757
31758 @subsubheading Example
31759
31760 @smallexample
31761 (gdb)
31762 -exec-next
31763 ^running
31764 (gdb)
31765 *stopped,reason="end-stepping-range",thread-id="2",line="187",
31766 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
31767 (gdb)
31768 -thread-list-ids
31769 ^done,
31770 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31771 number-of-threads="3"
31772 (gdb)
31773 -thread-select 3
31774 ^done,new-thread-id="3",
31775 frame=@{level="0",func="vprintf",
31776 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
31777 @{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
31778 (gdb)
31779 @end smallexample
31780
31781 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31782 @node GDB/MI Ada Tasking Commands
31783 @section @sc{gdb/mi} Ada Tasking Commands
31784
31785 @subheading The @code{-ada-task-info} Command
31786 @findex -ada-task-info
31787
31788 @subsubheading Synopsis
31789
31790 @smallexample
31791 -ada-task-info [ @var{task-id} ]
31792 @end smallexample
31793
31794 Reports information about either a specific Ada task, if the
31795 @var{task-id} parameter is present, or about all Ada tasks.
31796
31797 @subsubheading @value{GDBN} Command
31798
31799 The @samp{info tasks} command prints the same information
31800 about all Ada tasks (@pxref{Ada Tasks}).
31801
31802 @subsubheading Result
31803
31804 The result is a table of Ada tasks. The following columns are
31805 defined for each Ada task:
31806
31807 @table @samp
31808 @item current
31809 This field exists only for the current thread. It has the value @samp{*}.
31810
31811 @item id
31812 The identifier that @value{GDBN} uses to refer to the Ada task.
31813
31814 @item task-id
31815 The identifier that the target uses to refer to the Ada task.
31816
31817 @item thread-id
31818 The global thread identifier of the thread corresponding to the Ada
31819 task.
31820
31821 This field should always exist, as Ada tasks are always implemented
31822 on top of a thread. But if @value{GDBN} cannot find this corresponding
31823 thread for any reason, the field is omitted.
31824
31825 @item parent-id
31826 This field exists only when the task was created by another task.
31827 In this case, it provides the ID of the parent task.
31828
31829 @item priority
31830 The base priority of the task.
31831
31832 @item state
31833 The current state of the task. For a detailed description of the
31834 possible states, see @ref{Ada Tasks}.
31835
31836 @item name
31837 The name of the task.
31838
31839 @end table
31840
31841 @subsubheading Example
31842
31843 @smallexample
31844 -ada-task-info
31845 ^done,tasks=@{nr_rows="3",nr_cols="8",
31846 hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
31847 @{width="3",alignment="1",col_name="id",colhdr="ID"@},
31848 @{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
31849 @{width="4",alignment="1",col_name="thread-id",colhdr=""@},
31850 @{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
31851 @{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
31852 @{width="22",alignment="-1",col_name="state",colhdr="State"@},
31853 @{width="1",alignment="2",col_name="name",colhdr="Name"@}],
31854 body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
31855 state="Child Termination Wait",name="main_task"@}]@}
31856 (gdb)
31857 @end smallexample
31858
31859 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31860 @node GDB/MI Program Execution
31861 @section @sc{gdb/mi} Program Execution
31862
31863 These are the asynchronous commands which generate the out-of-band
31864 record @samp{*stopped}. Currently @value{GDBN} only really executes
31865 asynchronously with remote targets and this interaction is mimicked in
31866 other cases.
31867
31868 @subheading The @code{-exec-continue} Command
31869 @findex -exec-continue
31870
31871 @subsubheading Synopsis
31872
31873 @smallexample
31874 -exec-continue [--reverse] [--all|--thread-group N]
31875 @end smallexample
31876
31877 Resumes the execution of the inferior program, which will continue
31878 to execute until it reaches a debugger stop event. If the
31879 @samp{--reverse} option is specified, execution resumes in reverse until
31880 it reaches a stop event. Stop events may include
31881 @itemize @bullet
31882 @item
31883 breakpoints or watchpoints
31884 @item
31885 signals or exceptions
31886 @item
31887 the end of the process (or its beginning under @samp{--reverse})
31888 @item
31889 the end or beginning of a replay log if one is being used.
31890 @end itemize
31891 In all-stop mode (@pxref{All-Stop
31892 Mode}), may resume only one thread, or all threads, depending on the
31893 value of the @samp{scheduler-locking} variable. If @samp{--all} is
31894 specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
31895 ignored in all-stop mode. If the @samp{--thread-group} options is
31896 specified, then all threads in that thread group are resumed.
31897
31898 @subsubheading @value{GDBN} Command
31899
31900 The corresponding @value{GDBN} corresponding is @samp{continue}.
31901
31902 @subsubheading Example
31903
31904 @smallexample
31905 -exec-continue
31906 ^running
31907 (gdb)
31908 @@Hello world
31909 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
31910 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
31911 line="13",arch="i386:x86_64"@}
31912 (gdb)
31913 @end smallexample
31914
31915
31916 @subheading The @code{-exec-finish} Command
31917 @findex -exec-finish
31918
31919 @subsubheading Synopsis
31920
31921 @smallexample
31922 -exec-finish [--reverse]
31923 @end smallexample
31924
31925 Resumes the execution of the inferior program until the current
31926 function is exited. Displays the results returned by the function.
31927 If the @samp{--reverse} option is specified, resumes the reverse
31928 execution of the inferior program until the point where current
31929 function was called.
31930
31931 @subsubheading @value{GDBN} Command
31932
31933 The corresponding @value{GDBN} command is @samp{finish}.
31934
31935 @subsubheading Example
31936
31937 Function returning @code{void}.
31938
31939 @smallexample
31940 -exec-finish
31941 ^running
31942 (gdb)
31943 @@hello from foo
31944 *stopped,reason="function-finished",frame=@{func="main",args=[],
31945 file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
31946 (gdb)
31947 @end smallexample
31948
31949 Function returning other than @code{void}. The name of the internal
31950 @value{GDBN} variable storing the result is printed, together with the
31951 value itself.
31952
31953 @smallexample
31954 -exec-finish
31955 ^running
31956 (gdb)
31957 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
31958 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
31959 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31960 arch="i386:x86_64"@},
31961 gdb-result-var="$1",return-value="0"
31962 (gdb)
31963 @end smallexample
31964
31965
31966 @subheading The @code{-exec-interrupt} Command
31967 @findex -exec-interrupt
31968
31969 @subsubheading Synopsis
31970
31971 @smallexample
31972 -exec-interrupt [--all|--thread-group N]
31973 @end smallexample
31974
31975 Interrupts the background execution of the target. Note how the token
31976 associated with the stop message is the one for the execution command
31977 that has been interrupted. The token for the interrupt itself only
31978 appears in the @samp{^done} output. If the user is trying to
31979 interrupt a non-running program, an error message will be printed.
31980
31981 Note that when asynchronous execution is enabled, this command is
31982 asynchronous just like other execution commands. That is, first the
31983 @samp{^done} response will be printed, and the target stop will be
31984 reported after that using the @samp{*stopped} notification.
31985
31986 In non-stop mode, only the context thread is interrupted by default.
31987 All threads (in all inferiors) will be interrupted if the
31988 @samp{--all} option is specified. If the @samp{--thread-group}
31989 option is specified, all threads in that group will be interrupted.
31990
31991 @subsubheading @value{GDBN} Command
31992
31993 The corresponding @value{GDBN} command is @samp{interrupt}.
31994
31995 @subsubheading Example
31996
31997 @smallexample
31998 (gdb)
31999 111-exec-continue
32000 111^running
32001
32002 (gdb)
32003 222-exec-interrupt
32004 222^done
32005 (gdb)
32006 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
32007 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
32008 fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
32009 (gdb)
32010
32011 (gdb)
32012 -exec-interrupt
32013 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
32014 (gdb)
32015 @end smallexample
32016
32017 @subheading The @code{-exec-jump} Command
32018 @findex -exec-jump
32019
32020 @subsubheading Synopsis
32021
32022 @smallexample
32023 -exec-jump @var{location}
32024 @end smallexample
32025
32026 Resumes execution of the inferior program at the location specified by
32027 parameter. @xref{Specify Location}, for a description of the
32028 different forms of @var{location}.
32029
32030 @subsubheading @value{GDBN} Command
32031
32032 The corresponding @value{GDBN} command is @samp{jump}.
32033
32034 @subsubheading Example
32035
32036 @smallexample
32037 -exec-jump foo.c:10
32038 *running,thread-id="all"
32039 ^running
32040 @end smallexample
32041
32042
32043 @subheading The @code{-exec-next} Command
32044 @findex -exec-next
32045
32046 @subsubheading Synopsis
32047
32048 @smallexample
32049 -exec-next [--reverse]
32050 @end smallexample
32051
32052 Resumes execution of the inferior program, stopping when the beginning
32053 of the next source line is reached.
32054
32055 If the @samp{--reverse} option is specified, resumes reverse execution
32056 of the inferior program, stopping at the beginning of the previous
32057 source line. If you issue this command on the first line of a
32058 function, it will take you back to the caller of that function, to the
32059 source line where the function was called.
32060
32061
32062 @subsubheading @value{GDBN} Command
32063
32064 The corresponding @value{GDBN} command is @samp{next}.
32065
32066 @subsubheading Example
32067
32068 @smallexample
32069 -exec-next
32070 ^running
32071 (gdb)
32072 *stopped,reason="end-stepping-range",line="8",file="hello.c"
32073 (gdb)
32074 @end smallexample
32075
32076
32077 @subheading The @code{-exec-next-instruction} Command
32078 @findex -exec-next-instruction
32079
32080 @subsubheading Synopsis
32081
32082 @smallexample
32083 -exec-next-instruction [--reverse]
32084 @end smallexample
32085
32086 Executes one machine instruction. If the instruction is a function
32087 call, continues until the function returns. If the program stops at an
32088 instruction in the middle of a source line, the address will be
32089 printed as well.
32090
32091 If the @samp{--reverse} option is specified, resumes reverse execution
32092 of the inferior program, stopping at the previous instruction. If the
32093 previously executed instruction was a return from another function,
32094 it will continue to execute in reverse until the call to that function
32095 (from the current stack frame) is reached.
32096
32097 @subsubheading @value{GDBN} Command
32098
32099 The corresponding @value{GDBN} command is @samp{nexti}.
32100
32101 @subsubheading Example
32102
32103 @smallexample
32104 (gdb)
32105 -exec-next-instruction
32106 ^running
32107
32108 (gdb)
32109 *stopped,reason="end-stepping-range",
32110 addr="0x000100d4",line="5",file="hello.c"
32111 (gdb)
32112 @end smallexample
32113
32114
32115 @subheading The @code{-exec-return} Command
32116 @findex -exec-return
32117
32118 @subsubheading Synopsis
32119
32120 @smallexample
32121 -exec-return
32122 @end smallexample
32123
32124 Makes current function return immediately. Doesn't execute the inferior.
32125 Displays the new current frame.
32126
32127 @subsubheading @value{GDBN} Command
32128
32129 The corresponding @value{GDBN} command is @samp{return}.
32130
32131 @subsubheading Example
32132
32133 @smallexample
32134 (gdb)
32135 200-break-insert callee4
32136 200^done,bkpt=@{number="1",addr="0x00010734",
32137 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
32138 (gdb)
32139 000-exec-run
32140 000^running
32141 (gdb)
32142 000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
32143 frame=@{func="callee4",args=[],
32144 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32145 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
32146 arch="i386:x86_64"@}
32147 (gdb)
32148 205-break-delete
32149 205^done
32150 (gdb)
32151 111-exec-return
32152 111^done,frame=@{level="0",func="callee3",
32153 args=[@{name="strarg",
32154 value="0x11940 \"A string argument.\""@}],
32155 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32156 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
32157 arch="i386:x86_64"@}
32158 (gdb)
32159 @end smallexample
32160
32161
32162 @subheading The @code{-exec-run} Command
32163 @findex -exec-run
32164
32165 @subsubheading Synopsis
32166
32167 @smallexample
32168 -exec-run [ --all | --thread-group N ] [ --start ]
32169 @end smallexample
32170
32171 Starts execution of the inferior from the beginning. The inferior
32172 executes until either a breakpoint is encountered or the program
32173 exits. In the latter case the output will include an exit code, if
32174 the program has exited exceptionally.
32175
32176 When neither the @samp{--all} nor the @samp{--thread-group} option
32177 is specified, the current inferior is started. If the
32178 @samp{--thread-group} option is specified, it should refer to a thread
32179 group of type @samp{process}, and that thread group will be started.
32180 If the @samp{--all} option is specified, then all inferiors will be started.
32181
32182 Using the @samp{--start} option instructs the debugger to stop
32183 the execution at the start of the inferior's main subprogram,
32184 following the same behavior as the @code{start} command
32185 (@pxref{Starting}).
32186
32187 @subsubheading @value{GDBN} Command
32188
32189 The corresponding @value{GDBN} command is @samp{run}.
32190
32191 @subsubheading Examples
32192
32193 @smallexample
32194 (gdb)
32195 -break-insert main
32196 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
32197 (gdb)
32198 -exec-run
32199 ^running
32200 (gdb)
32201 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
32202 frame=@{func="main",args=[],file="recursive2.c",
32203 fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
32204 (gdb)
32205 @end smallexample
32206
32207 @noindent
32208 Program exited normally:
32209
32210 @smallexample
32211 (gdb)
32212 -exec-run
32213 ^running
32214 (gdb)
32215 x = 55
32216 *stopped,reason="exited-normally"
32217 (gdb)
32218 @end smallexample
32219
32220 @noindent
32221 Program exited exceptionally:
32222
32223 @smallexample
32224 (gdb)
32225 -exec-run
32226 ^running
32227 (gdb)
32228 x = 55
32229 *stopped,reason="exited",exit-code="01"
32230 (gdb)
32231 @end smallexample
32232
32233 Another way the program can terminate is if it receives a signal such as
32234 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
32235
32236 @smallexample
32237 (gdb)
32238 *stopped,reason="exited-signalled",signal-name="SIGINT",
32239 signal-meaning="Interrupt"
32240 @end smallexample
32241
32242
32243 @c @subheading -exec-signal
32244
32245
32246 @subheading The @code{-exec-step} Command
32247 @findex -exec-step
32248
32249 @subsubheading Synopsis
32250
32251 @smallexample
32252 -exec-step [--reverse]
32253 @end smallexample
32254
32255 Resumes execution of the inferior program, stopping when the beginning
32256 of the next source line is reached, if the next source line is not a
32257 function call. If it is, stop at the first instruction of the called
32258 function. If the @samp{--reverse} option is specified, resumes reverse
32259 execution of the inferior program, stopping at the beginning of the
32260 previously executed source line.
32261
32262 @subsubheading @value{GDBN} Command
32263
32264 The corresponding @value{GDBN} command is @samp{step}.
32265
32266 @subsubheading Example
32267
32268 Stepping into a function:
32269
32270 @smallexample
32271 -exec-step
32272 ^running
32273 (gdb)
32274 *stopped,reason="end-stepping-range",
32275 frame=@{func="foo",args=[@{name="a",value="10"@},
32276 @{name="b",value="0"@}],file="recursive2.c",
32277 fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
32278 (gdb)
32279 @end smallexample
32280
32281 Regular stepping:
32282
32283 @smallexample
32284 -exec-step
32285 ^running
32286 (gdb)
32287 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
32288 (gdb)
32289 @end smallexample
32290
32291
32292 @subheading The @code{-exec-step-instruction} Command
32293 @findex -exec-step-instruction
32294
32295 @subsubheading Synopsis
32296
32297 @smallexample
32298 -exec-step-instruction [--reverse]
32299 @end smallexample
32300
32301 Resumes the inferior which executes one machine instruction. If the
32302 @samp{--reverse} option is specified, resumes reverse execution of the
32303 inferior program, stopping at the previously executed instruction.
32304 The output, once @value{GDBN} has stopped, will vary depending on
32305 whether we have stopped in the middle of a source line or not. In the
32306 former case, the address at which the program stopped will be printed
32307 as well.
32308
32309 @subsubheading @value{GDBN} Command
32310
32311 The corresponding @value{GDBN} command is @samp{stepi}.
32312
32313 @subsubheading Example
32314
32315 @smallexample
32316 (gdb)
32317 -exec-step-instruction
32318 ^running
32319
32320 (gdb)
32321 *stopped,reason="end-stepping-range",
32322 frame=@{func="foo",args=[],file="try.c",
32323 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
32324 (gdb)
32325 -exec-step-instruction
32326 ^running
32327
32328 (gdb)
32329 *stopped,reason="end-stepping-range",
32330 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
32331 fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
32332 (gdb)
32333 @end smallexample
32334
32335
32336 @subheading The @code{-exec-until} Command
32337 @findex -exec-until
32338
32339 @subsubheading Synopsis
32340
32341 @smallexample
32342 -exec-until [ @var{location} ]
32343 @end smallexample
32344
32345 Executes the inferior until the @var{location} specified in the
32346 argument is reached. If there is no argument, the inferior executes
32347 until a source line greater than the current one is reached. The
32348 reason for stopping in this case will be @samp{location-reached}.
32349
32350 @subsubheading @value{GDBN} Command
32351
32352 The corresponding @value{GDBN} command is @samp{until}.
32353
32354 @subsubheading Example
32355
32356 @smallexample
32357 (gdb)
32358 -exec-until recursive2.c:6
32359 ^running
32360 (gdb)
32361 x = 55
32362 *stopped,reason="location-reached",frame=@{func="main",args=[],
32363 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
32364 arch="i386:x86_64"@}
32365 (gdb)
32366 @end smallexample
32367
32368 @ignore
32369 @subheading -file-clear
32370 Is this going away????
32371 @end ignore
32372
32373 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32374 @node GDB/MI Stack Manipulation
32375 @section @sc{gdb/mi} Stack Manipulation Commands
32376
32377 @subheading The @code{-enable-frame-filters} Command
32378 @findex -enable-frame-filters
32379
32380 @smallexample
32381 -enable-frame-filters
32382 @end smallexample
32383
32384 @value{GDBN} allows Python-based frame filters to affect the output of
32385 the MI commands relating to stack traces. As there is no way to
32386 implement this in a fully backward-compatible way, a front end must
32387 request that this functionality be enabled.
32388
32389 Once enabled, this feature cannot be disabled.
32390
32391 Note that if Python support has not been compiled into @value{GDBN},
32392 this command will still succeed (and do nothing).
32393
32394 @subheading The @code{-stack-info-frame} Command
32395 @findex -stack-info-frame
32396
32397 @subsubheading Synopsis
32398
32399 @smallexample
32400 -stack-info-frame
32401 @end smallexample
32402
32403 Get info on the selected frame.
32404
32405 @subsubheading @value{GDBN} Command
32406
32407 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
32408 (without arguments).
32409
32410 @subsubheading Example
32411
32412 @smallexample
32413 (gdb)
32414 -stack-info-frame
32415 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
32416 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32417 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
32418 arch="i386:x86_64"@}
32419 (gdb)
32420 @end smallexample
32421
32422 @subheading The @code{-stack-info-depth} Command
32423 @findex -stack-info-depth
32424
32425 @subsubheading Synopsis
32426
32427 @smallexample
32428 -stack-info-depth [ @var{max-depth} ]
32429 @end smallexample
32430
32431 Return the depth of the stack. If the integer argument @var{max-depth}
32432 is specified, do not count beyond @var{max-depth} frames.
32433
32434 @subsubheading @value{GDBN} Command
32435
32436 There's no equivalent @value{GDBN} command.
32437
32438 @subsubheading Example
32439
32440 For a stack with frame levels 0 through 11:
32441
32442 @smallexample
32443 (gdb)
32444 -stack-info-depth
32445 ^done,depth="12"
32446 (gdb)
32447 -stack-info-depth 4
32448 ^done,depth="4"
32449 (gdb)
32450 -stack-info-depth 12
32451 ^done,depth="12"
32452 (gdb)
32453 -stack-info-depth 11
32454 ^done,depth="11"
32455 (gdb)
32456 -stack-info-depth 13
32457 ^done,depth="12"
32458 (gdb)
32459 @end smallexample
32460
32461 @anchor{-stack-list-arguments}
32462 @subheading The @code{-stack-list-arguments} Command
32463 @findex -stack-list-arguments
32464
32465 @subsubheading Synopsis
32466
32467 @smallexample
32468 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32469 [ @var{low-frame} @var{high-frame} ]
32470 @end smallexample
32471
32472 Display a list of the arguments for the frames between @var{low-frame}
32473 and @var{high-frame} (inclusive). If @var{low-frame} and
32474 @var{high-frame} are not provided, list the arguments for the whole
32475 call stack. If the two arguments are equal, show the single frame
32476 at the corresponding level. It is an error if @var{low-frame} is
32477 larger than the actual number of frames. On the other hand,
32478 @var{high-frame} may be larger than the actual number of frames, in
32479 which case only existing frames will be returned.
32480
32481 If @var{print-values} is 0 or @code{--no-values}, print only the names of
32482 the variables; if it is 1 or @code{--all-values}, print also their
32483 values; and if it is 2 or @code{--simple-values}, print the name,
32484 type and value for simple data types, and the name and type for arrays,
32485 structures and unions. If the option @code{--no-frame-filters} is
32486 supplied, then Python frame filters will not be executed.
32487
32488 If the @code{--skip-unavailable} option is specified, arguments that
32489 are not available are not listed. Partially available arguments
32490 are still displayed, however.
32491
32492 Use of this command to obtain arguments in a single frame is
32493 deprecated in favor of the @samp{-stack-list-variables} command.
32494
32495 @subsubheading @value{GDBN} Command
32496
32497 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
32498 @samp{gdb_get_args} command which partially overlaps with the
32499 functionality of @samp{-stack-list-arguments}.
32500
32501 @subsubheading Example
32502
32503 @smallexample
32504 (gdb)
32505 -stack-list-frames
32506 ^done,
32507 stack=[
32508 frame=@{level="0",addr="0x00010734",func="callee4",
32509 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32510 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
32511 arch="i386:x86_64"@},
32512 frame=@{level="1",addr="0x0001076c",func="callee3",
32513 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32514 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
32515 arch="i386:x86_64"@},
32516 frame=@{level="2",addr="0x0001078c",func="callee2",
32517 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32518 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
32519 arch="i386:x86_64"@},
32520 frame=@{level="3",addr="0x000107b4",func="callee1",
32521 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32522 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
32523 arch="i386:x86_64"@},
32524 frame=@{level="4",addr="0x000107e0",func="main",
32525 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32526 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
32527 arch="i386:x86_64"@}]
32528 (gdb)
32529 -stack-list-arguments 0
32530 ^done,
32531 stack-args=[
32532 frame=@{level="0",args=[]@},
32533 frame=@{level="1",args=[name="strarg"]@},
32534 frame=@{level="2",args=[name="intarg",name="strarg"]@},
32535 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
32536 frame=@{level="4",args=[]@}]
32537 (gdb)
32538 -stack-list-arguments 1
32539 ^done,
32540 stack-args=[
32541 frame=@{level="0",args=[]@},
32542 frame=@{level="1",
32543 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32544 frame=@{level="2",args=[
32545 @{name="intarg",value="2"@},
32546 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32547 @{frame=@{level="3",args=[
32548 @{name="intarg",value="2"@},
32549 @{name="strarg",value="0x11940 \"A string argument.\""@},
32550 @{name="fltarg",value="3.5"@}]@},
32551 frame=@{level="4",args=[]@}]
32552 (gdb)
32553 -stack-list-arguments 0 2 2
32554 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
32555 (gdb)
32556 -stack-list-arguments 1 2 2
32557 ^done,stack-args=[frame=@{level="2",
32558 args=[@{name="intarg",value="2"@},
32559 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
32560 (gdb)
32561 @end smallexample
32562
32563 @c @subheading -stack-list-exception-handlers
32564
32565
32566 @anchor{-stack-list-frames}
32567 @subheading The @code{-stack-list-frames} Command
32568 @findex -stack-list-frames
32569
32570 @subsubheading Synopsis
32571
32572 @smallexample
32573 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
32574 @end smallexample
32575
32576 List the frames currently on the stack. For each frame it displays the
32577 following info:
32578
32579 @table @samp
32580 @item @var{level}
32581 The frame number, 0 being the topmost frame, i.e., the innermost function.
32582 @item @var{addr}
32583 The @code{$pc} value for that frame.
32584 @item @var{func}
32585 Function name.
32586 @item @var{file}
32587 File name of the source file where the function lives.
32588 @item @var{fullname}
32589 The full file name of the source file where the function lives.
32590 @item @var{line}
32591 Line number corresponding to the @code{$pc}.
32592 @item @var{from}
32593 The shared library where this function is defined. This is only given
32594 if the frame's function is not known.
32595 @item @var{arch}
32596 Frame's architecture.
32597 @end table
32598
32599 If invoked without arguments, this command prints a backtrace for the
32600 whole stack. If given two integer arguments, it shows the frames whose
32601 levels are between the two arguments (inclusive). If the two arguments
32602 are equal, it shows the single frame at the corresponding level. It is
32603 an error if @var{low-frame} is larger than the actual number of
32604 frames. On the other hand, @var{high-frame} may be larger than the
32605 actual number of frames, in which case only existing frames will be
32606 returned. If the option @code{--no-frame-filters} is supplied, then
32607 Python frame filters will not be executed.
32608
32609 @subsubheading @value{GDBN} Command
32610
32611 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
32612
32613 @subsubheading Example
32614
32615 Full stack backtrace:
32616
32617 @smallexample
32618 (gdb)
32619 -stack-list-frames
32620 ^done,stack=
32621 [frame=@{level="0",addr="0x0001076c",func="foo",
32622 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
32623 arch="i386:x86_64"@},
32624 frame=@{level="1",addr="0x000107a4",func="foo",
32625 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32626 arch="i386:x86_64"@},
32627 frame=@{level="2",addr="0x000107a4",func="foo",
32628 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32629 arch="i386:x86_64"@},
32630 frame=@{level="3",addr="0x000107a4",func="foo",
32631 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32632 arch="i386:x86_64"@},
32633 frame=@{level="4",addr="0x000107a4",func="foo",
32634 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32635 arch="i386:x86_64"@},
32636 frame=@{level="5",addr="0x000107a4",func="foo",
32637 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32638 arch="i386:x86_64"@},
32639 frame=@{level="6",addr="0x000107a4",func="foo",
32640 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32641 arch="i386:x86_64"@},
32642 frame=@{level="7",addr="0x000107a4",func="foo",
32643 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32644 arch="i386:x86_64"@},
32645 frame=@{level="8",addr="0x000107a4",func="foo",
32646 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32647 arch="i386:x86_64"@},
32648 frame=@{level="9",addr="0x000107a4",func="foo",
32649 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32650 arch="i386:x86_64"@},
32651 frame=@{level="10",addr="0x000107a4",func="foo",
32652 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32653 arch="i386:x86_64"@},
32654 frame=@{level="11",addr="0x00010738",func="main",
32655 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
32656 arch="i386:x86_64"@}]
32657 (gdb)
32658 @end smallexample
32659
32660 Show frames between @var{low_frame} and @var{high_frame}:
32661
32662 @smallexample
32663 (gdb)
32664 -stack-list-frames 3 5
32665 ^done,stack=
32666 [frame=@{level="3",addr="0x000107a4",func="foo",
32667 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32668 arch="i386:x86_64"@},
32669 frame=@{level="4",addr="0x000107a4",func="foo",
32670 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32671 arch="i386:x86_64"@},
32672 frame=@{level="5",addr="0x000107a4",func="foo",
32673 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32674 arch="i386:x86_64"@}]
32675 (gdb)
32676 @end smallexample
32677
32678 Show a single frame:
32679
32680 @smallexample
32681 (gdb)
32682 -stack-list-frames 3 3
32683 ^done,stack=
32684 [frame=@{level="3",addr="0x000107a4",func="foo",
32685 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32686 arch="i386:x86_64"@}]
32687 (gdb)
32688 @end smallexample
32689
32690
32691 @subheading The @code{-stack-list-locals} Command
32692 @findex -stack-list-locals
32693 @anchor{-stack-list-locals}
32694
32695 @subsubheading Synopsis
32696
32697 @smallexample
32698 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32699 @end smallexample
32700
32701 Display the local variable names for the selected frame. If
32702 @var{print-values} is 0 or @code{--no-values}, print only the names of
32703 the variables; if it is 1 or @code{--all-values}, print also their
32704 values; and if it is 2 or @code{--simple-values}, print the name,
32705 type and value for simple data types, and the name and type for arrays,
32706 structures and unions. In this last case, a frontend can immediately
32707 display the value of simple data types and create variable objects for
32708 other data types when the user wishes to explore their values in
32709 more detail. If the option @code{--no-frame-filters} is supplied, then
32710 Python frame filters will not be executed.
32711
32712 If the @code{--skip-unavailable} option is specified, local variables
32713 that are not available are not listed. Partially available local
32714 variables are still displayed, however.
32715
32716 This command is deprecated in favor of the
32717 @samp{-stack-list-variables} command.
32718
32719 @subsubheading @value{GDBN} Command
32720
32721 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
32722
32723 @subsubheading Example
32724
32725 @smallexample
32726 (gdb)
32727 -stack-list-locals 0
32728 ^done,locals=[name="A",name="B",name="C"]
32729 (gdb)
32730 -stack-list-locals --all-values
32731 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
32732 @{name="C",value="@{1, 2, 3@}"@}]
32733 -stack-list-locals --simple-values
32734 ^done,locals=[@{name="A",type="int",value="1"@},
32735 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
32736 (gdb)
32737 @end smallexample
32738
32739 @anchor{-stack-list-variables}
32740 @subheading The @code{-stack-list-variables} Command
32741 @findex -stack-list-variables
32742
32743 @subsubheading Synopsis
32744
32745 @smallexample
32746 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32747 @end smallexample
32748
32749 Display the names of local variables and function arguments for the selected frame. If
32750 @var{print-values} is 0 or @code{--no-values}, print only the names of
32751 the variables; if it is 1 or @code{--all-values}, print also their
32752 values; and if it is 2 or @code{--simple-values}, print the name,
32753 type and value for simple data types, and the name and type for arrays,
32754 structures and unions. If the option @code{--no-frame-filters} is
32755 supplied, then Python frame filters will not be executed.
32756
32757 If the @code{--skip-unavailable} option is specified, local variables
32758 and arguments that are not available are not listed. Partially
32759 available arguments and local variables are still displayed, however.
32760
32761 @subsubheading Example
32762
32763 @smallexample
32764 (gdb)
32765 -stack-list-variables --thread 1 --frame 0 --all-values
32766 ^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
32767 (gdb)
32768 @end smallexample
32769
32770
32771 @subheading The @code{-stack-select-frame} Command
32772 @findex -stack-select-frame
32773
32774 @subsubheading Synopsis
32775
32776 @smallexample
32777 -stack-select-frame @var{framenum}
32778 @end smallexample
32779
32780 Change the selected frame. Select a different frame @var{framenum} on
32781 the stack.
32782
32783 This command in deprecated in favor of passing the @samp{--frame}
32784 option to every command.
32785
32786 @subsubheading @value{GDBN} Command
32787
32788 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
32789 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
32790
32791 @subsubheading Example
32792
32793 @smallexample
32794 (gdb)
32795 -stack-select-frame 2
32796 ^done
32797 (gdb)
32798 @end smallexample
32799
32800 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32801 @node GDB/MI Variable Objects
32802 @section @sc{gdb/mi} Variable Objects
32803
32804 @ignore
32805
32806 @subheading Motivation for Variable Objects in @sc{gdb/mi}
32807
32808 For the implementation of a variable debugger window (locals, watched
32809 expressions, etc.), we are proposing the adaptation of the existing code
32810 used by @code{Insight}.
32811
32812 The two main reasons for that are:
32813
32814 @enumerate 1
32815 @item
32816 It has been proven in practice (it is already on its second generation).
32817
32818 @item
32819 It will shorten development time (needless to say how important it is
32820 now).
32821 @end enumerate
32822
32823 The original interface was designed to be used by Tcl code, so it was
32824 slightly changed so it could be used through @sc{gdb/mi}. This section
32825 describes the @sc{gdb/mi} operations that will be available and gives some
32826 hints about their use.
32827
32828 @emph{Note}: In addition to the set of operations described here, we
32829 expect the @sc{gui} implementation of a variable window to require, at
32830 least, the following operations:
32831
32832 @itemize @bullet
32833 @item @code{-gdb-show} @code{output-radix}
32834 @item @code{-stack-list-arguments}
32835 @item @code{-stack-list-locals}
32836 @item @code{-stack-select-frame}
32837 @end itemize
32838
32839 @end ignore
32840
32841 @subheading Introduction to Variable Objects
32842
32843 @cindex variable objects in @sc{gdb/mi}
32844
32845 Variable objects are "object-oriented" MI interface for examining and
32846 changing values of expressions. Unlike some other MI interfaces that
32847 work with expressions, variable objects are specifically designed for
32848 simple and efficient presentation in the frontend. A variable object
32849 is identified by string name. When a variable object is created, the
32850 frontend specifies the expression for that variable object. The
32851 expression can be a simple variable, or it can be an arbitrary complex
32852 expression, and can even involve CPU registers. After creating a
32853 variable object, the frontend can invoke other variable object
32854 operations---for example to obtain or change the value of a variable
32855 object, or to change display format.
32856
32857 Variable objects have hierarchical tree structure. Any variable object
32858 that corresponds to a composite type, such as structure in C, has
32859 a number of child variable objects, for example corresponding to each
32860 element of a structure. A child variable object can itself have
32861 children, recursively. Recursion ends when we reach
32862 leaf variable objects, which always have built-in types. Child variable
32863 objects are created only by explicit request, so if a frontend
32864 is not interested in the children of a particular variable object, no
32865 child will be created.
32866
32867 For a leaf variable object it is possible to obtain its value as a
32868 string, or set the value from a string. String value can be also
32869 obtained for a non-leaf variable object, but it's generally a string
32870 that only indicates the type of the object, and does not list its
32871 contents. Assignment to a non-leaf variable object is not allowed.
32872
32873 A frontend does not need to read the values of all variable objects each time
32874 the program stops. Instead, MI provides an update command that lists all
32875 variable objects whose values has changed since the last update
32876 operation. This considerably reduces the amount of data that must
32877 be transferred to the frontend. As noted above, children variable
32878 objects are created on demand, and only leaf variable objects have a
32879 real value. As result, gdb will read target memory only for leaf
32880 variables that frontend has created.
32881
32882 The automatic update is not always desirable. For example, a frontend
32883 might want to keep a value of some expression for future reference,
32884 and never update it. For another example, fetching memory is
32885 relatively slow for embedded targets, so a frontend might want
32886 to disable automatic update for the variables that are either not
32887 visible on the screen, or ``closed''. This is possible using so
32888 called ``frozen variable objects''. Such variable objects are never
32889 implicitly updated.
32890
32891 Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
32892 fixed variable object, the expression is parsed when the variable
32893 object is created, including associating identifiers to specific
32894 variables. The meaning of expression never changes. For a floating
32895 variable object the values of variables whose names appear in the
32896 expressions are re-evaluated every time in the context of the current
32897 frame. Consider this example:
32898
32899 @smallexample
32900 void do_work(...)
32901 @{
32902 struct work_state state;
32903
32904 if (...)
32905 do_work(...);
32906 @}
32907 @end smallexample
32908
32909 If a fixed variable object for the @code{state} variable is created in
32910 this function, and we enter the recursive call, the variable
32911 object will report the value of @code{state} in the top-level
32912 @code{do_work} invocation. On the other hand, a floating variable
32913 object will report the value of @code{state} in the current frame.
32914
32915 If an expression specified when creating a fixed variable object
32916 refers to a local variable, the variable object becomes bound to the
32917 thread and frame in which the variable object is created. When such
32918 variable object is updated, @value{GDBN} makes sure that the
32919 thread/frame combination the variable object is bound to still exists,
32920 and re-evaluates the variable object in context of that thread/frame.
32921
32922 The following is the complete set of @sc{gdb/mi} operations defined to
32923 access this functionality:
32924
32925 @multitable @columnfractions .4 .6
32926 @item @strong{Operation}
32927 @tab @strong{Description}
32928
32929 @item @code{-enable-pretty-printing}
32930 @tab enable Python-based pretty-printing
32931 @item @code{-var-create}
32932 @tab create a variable object
32933 @item @code{-var-delete}
32934 @tab delete the variable object and/or its children
32935 @item @code{-var-set-format}
32936 @tab set the display format of this variable
32937 @item @code{-var-show-format}
32938 @tab show the display format of this variable
32939 @item @code{-var-info-num-children}
32940 @tab tells how many children this object has
32941 @item @code{-var-list-children}
32942 @tab return a list of the object's children
32943 @item @code{-var-info-type}
32944 @tab show the type of this variable object
32945 @item @code{-var-info-expression}
32946 @tab print parent-relative expression that this variable object represents
32947 @item @code{-var-info-path-expression}
32948 @tab print full expression that this variable object represents
32949 @item @code{-var-show-attributes}
32950 @tab is this variable editable? does it exist here?
32951 @item @code{-var-evaluate-expression}
32952 @tab get the value of this variable
32953 @item @code{-var-assign}
32954 @tab set the value of this variable
32955 @item @code{-var-update}
32956 @tab update the variable and its children
32957 @item @code{-var-set-frozen}
32958 @tab set frozenness attribute
32959 @item @code{-var-set-update-range}
32960 @tab set range of children to display on update
32961 @end multitable
32962
32963 In the next subsection we describe each operation in detail and suggest
32964 how it can be used.
32965
32966 @subheading Description And Use of Operations on Variable Objects
32967
32968 @subheading The @code{-enable-pretty-printing} Command
32969 @findex -enable-pretty-printing
32970
32971 @smallexample
32972 -enable-pretty-printing
32973 @end smallexample
32974
32975 @value{GDBN} allows Python-based visualizers to affect the output of the
32976 MI variable object commands. However, because there was no way to
32977 implement this in a fully backward-compatible way, a front end must
32978 request that this functionality be enabled.
32979
32980 Once enabled, this feature cannot be disabled.
32981
32982 Note that if Python support has not been compiled into @value{GDBN},
32983 this command will still succeed (and do nothing).
32984
32985 This feature is currently (as of @value{GDBN} 7.0) experimental, and
32986 may work differently in future versions of @value{GDBN}.
32987
32988 @subheading The @code{-var-create} Command
32989 @findex -var-create
32990
32991 @subsubheading Synopsis
32992
32993 @smallexample
32994 -var-create @{@var{name} | "-"@}
32995 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
32996 @end smallexample
32997
32998 This operation creates a variable object, which allows the monitoring of
32999 a variable, the result of an expression, a memory cell or a CPU
33000 register.
33001
33002 The @var{name} parameter is the string by which the object can be
33003 referenced. It must be unique. If @samp{-} is specified, the varobj
33004 system will generate a string ``varNNNNNN'' automatically. It will be
33005 unique provided that one does not specify @var{name} of that format.
33006 The command fails if a duplicate name is found.
33007
33008 The frame under which the expression should be evaluated can be
33009 specified by @var{frame-addr}. A @samp{*} indicates that the current
33010 frame should be used. A @samp{@@} indicates that a floating variable
33011 object must be created.
33012
33013 @var{expression} is any expression valid on the current language set (must not
33014 begin with a @samp{*}), or one of the following:
33015
33016 @itemize @bullet
33017 @item
33018 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
33019
33020 @item
33021 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
33022
33023 @item
33024 @samp{$@var{regname}} --- a CPU register name
33025 @end itemize
33026
33027 @cindex dynamic varobj
33028 A varobj's contents may be provided by a Python-based pretty-printer. In this
33029 case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
33030 have slightly different semantics in some cases. If the
33031 @code{-enable-pretty-printing} command is not sent, then @value{GDBN}
33032 will never create a dynamic varobj. This ensures backward
33033 compatibility for existing clients.
33034
33035 @subsubheading Result
33036
33037 This operation returns attributes of the newly-created varobj. These
33038 are:
33039
33040 @table @samp
33041 @item name
33042 The name of the varobj.
33043
33044 @item numchild
33045 The number of children of the varobj. This number is not necessarily
33046 reliable for a dynamic varobj. Instead, you must examine the
33047 @samp{has_more} attribute.
33048
33049 @item value
33050 The varobj's scalar value. For a varobj whose type is some sort of
33051 aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
33052 will not be interesting.
33053
33054 @item type
33055 The varobj's type. This is a string representation of the type, as
33056 would be printed by the @value{GDBN} CLI. If @samp{print object}
33057 (@pxref{Print Settings, set print object}) is set to @code{on}, the
33058 @emph{actual} (derived) type of the object is shown rather than the
33059 @emph{declared} one.
33060
33061 @item thread-id
33062 If a variable object is bound to a specific thread, then this is the
33063 thread's global identifier.
33064
33065 @item has_more
33066 For a dynamic varobj, this indicates whether there appear to be any
33067 children available. For a non-dynamic varobj, this will be 0.
33068
33069 @item dynamic
33070 This attribute will be present and have the value @samp{1} if the
33071 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33072 then this attribute will not be present.
33073
33074 @item displayhint
33075 A dynamic varobj can supply a display hint to the front end. The
33076 value comes directly from the Python pretty-printer object's
33077 @code{display_hint} method. @xref{Pretty Printing API}.
33078 @end table
33079
33080 Typical output will look like this:
33081
33082 @smallexample
33083 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
33084 has_more="@var{has_more}"
33085 @end smallexample
33086
33087
33088 @subheading The @code{-var-delete} Command
33089 @findex -var-delete
33090
33091 @subsubheading Synopsis
33092
33093 @smallexample
33094 -var-delete [ -c ] @var{name}
33095 @end smallexample
33096
33097 Deletes a previously created variable object and all of its children.
33098 With the @samp{-c} option, just deletes the children.
33099
33100 Returns an error if the object @var{name} is not found.
33101
33102
33103 @subheading The @code{-var-set-format} Command
33104 @findex -var-set-format
33105
33106 @subsubheading Synopsis
33107
33108 @smallexample
33109 -var-set-format @var{name} @var{format-spec}
33110 @end smallexample
33111
33112 Sets the output format for the value of the object @var{name} to be
33113 @var{format-spec}.
33114
33115 @anchor{-var-set-format}
33116 The syntax for the @var{format-spec} is as follows:
33117
33118 @smallexample
33119 @var{format-spec} @expansion{}
33120 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
33121 @end smallexample
33122
33123 The natural format is the default format choosen automatically
33124 based on the variable type (like decimal for an @code{int}, hex
33125 for pointers, etc.).
33126
33127 The zero-hexadecimal format has a representation similar to hexadecimal
33128 but with padding zeroes to the left of the value. For example, a 32-bit
33129 hexadecimal value of 0x1234 would be represented as 0x00001234 in the
33130 zero-hexadecimal format.
33131
33132 For a variable with children, the format is set only on the
33133 variable itself, and the children are not affected.
33134
33135 @subheading The @code{-var-show-format} Command
33136 @findex -var-show-format
33137
33138 @subsubheading Synopsis
33139
33140 @smallexample
33141 -var-show-format @var{name}
33142 @end smallexample
33143
33144 Returns the format used to display the value of the object @var{name}.
33145
33146 @smallexample
33147 @var{format} @expansion{}
33148 @var{format-spec}
33149 @end smallexample
33150
33151
33152 @subheading The @code{-var-info-num-children} Command
33153 @findex -var-info-num-children
33154
33155 @subsubheading Synopsis
33156
33157 @smallexample
33158 -var-info-num-children @var{name}
33159 @end smallexample
33160
33161 Returns the number of children of a variable object @var{name}:
33162
33163 @smallexample
33164 numchild=@var{n}
33165 @end smallexample
33166
33167 Note that this number is not completely reliable for a dynamic varobj.
33168 It will return the current number of children, but more children may
33169 be available.
33170
33171
33172 @subheading The @code{-var-list-children} Command
33173 @findex -var-list-children
33174
33175 @subsubheading Synopsis
33176
33177 @smallexample
33178 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
33179 @end smallexample
33180 @anchor{-var-list-children}
33181
33182 Return a list of the children of the specified variable object and
33183 create variable objects for them, if they do not already exist. With
33184 a single argument or if @var{print-values} has a value of 0 or
33185 @code{--no-values}, print only the names of the variables; if
33186 @var{print-values} is 1 or @code{--all-values}, also print their
33187 values; and if it is 2 or @code{--simple-values} print the name and
33188 value for simple data types and just the name for arrays, structures
33189 and unions.
33190
33191 @var{from} and @var{to}, if specified, indicate the range of children
33192 to report. If @var{from} or @var{to} is less than zero, the range is
33193 reset and all children will be reported. Otherwise, children starting
33194 at @var{from} (zero-based) and up to and excluding @var{to} will be
33195 reported.
33196
33197 If a child range is requested, it will only affect the current call to
33198 @code{-var-list-children}, but not future calls to @code{-var-update}.
33199 For this, you must instead use @code{-var-set-update-range}. The
33200 intent of this approach is to enable a front end to implement any
33201 update approach it likes; for example, scrolling a view may cause the
33202 front end to request more children with @code{-var-list-children}, and
33203 then the front end could call @code{-var-set-update-range} with a
33204 different range to ensure that future updates are restricted to just
33205 the visible items.
33206
33207 For each child the following results are returned:
33208
33209 @table @var
33210
33211 @item name
33212 Name of the variable object created for this child.
33213
33214 @item exp
33215 The expression to be shown to the user by the front end to designate this child.
33216 For example this may be the name of a structure member.
33217
33218 For a dynamic varobj, this value cannot be used to form an
33219 expression. There is no way to do this at all with a dynamic varobj.
33220
33221 For C/C@t{++} structures there are several pseudo children returned to
33222 designate access qualifiers. For these pseudo children @var{exp} is
33223 @samp{public}, @samp{private}, or @samp{protected}. In this case the
33224 type and value are not present.
33225
33226 A dynamic varobj will not report the access qualifying
33227 pseudo-children, regardless of the language. This information is not
33228 available at all with a dynamic varobj.
33229
33230 @item numchild
33231 Number of children this child has. For a dynamic varobj, this will be
33232 0.
33233
33234 @item type
33235 The type of the child. If @samp{print object}
33236 (@pxref{Print Settings, set print object}) is set to @code{on}, the
33237 @emph{actual} (derived) type of the object is shown rather than the
33238 @emph{declared} one.
33239
33240 @item value
33241 If values were requested, this is the value.
33242
33243 @item thread-id
33244 If this variable object is associated with a thread, this is the
33245 thread's global thread id. Otherwise this result is not present.
33246
33247 @item frozen
33248 If the variable object is frozen, this variable will be present with a value of 1.
33249
33250 @item displayhint
33251 A dynamic varobj can supply a display hint to the front end. The
33252 value comes directly from the Python pretty-printer object's
33253 @code{display_hint} method. @xref{Pretty Printing API}.
33254
33255 @item dynamic
33256 This attribute will be present and have the value @samp{1} if the
33257 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33258 then this attribute will not be present.
33259
33260 @end table
33261
33262 The result may have its own attributes:
33263
33264 @table @samp
33265 @item displayhint
33266 A dynamic varobj can supply a display hint to the front end. The
33267 value comes directly from the Python pretty-printer object's
33268 @code{display_hint} method. @xref{Pretty Printing API}.
33269
33270 @item has_more
33271 This is an integer attribute which is nonzero if there are children
33272 remaining after the end of the selected range.
33273 @end table
33274
33275 @subsubheading Example
33276
33277 @smallexample
33278 (gdb)
33279 -var-list-children n
33280 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
33281 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
33282 (gdb)
33283 -var-list-children --all-values n
33284 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
33285 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
33286 @end smallexample
33287
33288
33289 @subheading The @code{-var-info-type} Command
33290 @findex -var-info-type
33291
33292 @subsubheading Synopsis
33293
33294 @smallexample
33295 -var-info-type @var{name}
33296 @end smallexample
33297
33298 Returns the type of the specified variable @var{name}. The type is
33299 returned as a string in the same format as it is output by the
33300 @value{GDBN} CLI:
33301
33302 @smallexample
33303 type=@var{typename}
33304 @end smallexample
33305
33306
33307 @subheading The @code{-var-info-expression} Command
33308 @findex -var-info-expression
33309
33310 @subsubheading Synopsis
33311
33312 @smallexample
33313 -var-info-expression @var{name}
33314 @end smallexample
33315
33316 Returns a string that is suitable for presenting this
33317 variable object in user interface. The string is generally
33318 not valid expression in the current language, and cannot be evaluated.
33319
33320 For example, if @code{a} is an array, and variable object
33321 @code{A} was created for @code{a}, then we'll get this output:
33322
33323 @smallexample
33324 (gdb) -var-info-expression A.1
33325 ^done,lang="C",exp="1"
33326 @end smallexample
33327
33328 @noindent
33329 Here, the value of @code{lang} is the language name, which can be
33330 found in @ref{Supported Languages}.
33331
33332 Note that the output of the @code{-var-list-children} command also
33333 includes those expressions, so the @code{-var-info-expression} command
33334 is of limited use.
33335
33336 @subheading The @code{-var-info-path-expression} Command
33337 @findex -var-info-path-expression
33338
33339 @subsubheading Synopsis
33340
33341 @smallexample
33342 -var-info-path-expression @var{name}
33343 @end smallexample
33344
33345 Returns an expression that can be evaluated in the current
33346 context and will yield the same value that a variable object has.
33347 Compare this with the @code{-var-info-expression} command, which
33348 result can be used only for UI presentation. Typical use of
33349 the @code{-var-info-path-expression} command is creating a
33350 watchpoint from a variable object.
33351
33352 This command is currently not valid for children of a dynamic varobj,
33353 and will give an error when invoked on one.
33354
33355 For example, suppose @code{C} is a C@t{++} class, derived from class
33356 @code{Base}, and that the @code{Base} class has a member called
33357 @code{m_size}. Assume a variable @code{c} is has the type of
33358 @code{C} and a variable object @code{C} was created for variable
33359 @code{c}. Then, we'll get this output:
33360 @smallexample
33361 (gdb) -var-info-path-expression C.Base.public.m_size
33362 ^done,path_expr=((Base)c).m_size)
33363 @end smallexample
33364
33365 @subheading The @code{-var-show-attributes} Command
33366 @findex -var-show-attributes
33367
33368 @subsubheading Synopsis
33369
33370 @smallexample
33371 -var-show-attributes @var{name}
33372 @end smallexample
33373
33374 List attributes of the specified variable object @var{name}:
33375
33376 @smallexample
33377 status=@var{attr} [ ( ,@var{attr} )* ]
33378 @end smallexample
33379
33380 @noindent
33381 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
33382
33383 @subheading The @code{-var-evaluate-expression} Command
33384 @findex -var-evaluate-expression
33385
33386 @subsubheading Synopsis
33387
33388 @smallexample
33389 -var-evaluate-expression [-f @var{format-spec}] @var{name}
33390 @end smallexample
33391
33392 Evaluates the expression that is represented by the specified variable
33393 object and returns its value as a string. The format of the string
33394 can be specified with the @samp{-f} option. The possible values of
33395 this option are the same as for @code{-var-set-format}
33396 (@pxref{-var-set-format}). If the @samp{-f} option is not specified,
33397 the current display format will be used. The current display format
33398 can be changed using the @code{-var-set-format} command.
33399
33400 @smallexample
33401 value=@var{value}
33402 @end smallexample
33403
33404 Note that one must invoke @code{-var-list-children} for a variable
33405 before the value of a child variable can be evaluated.
33406
33407 @subheading The @code{-var-assign} Command
33408 @findex -var-assign
33409
33410 @subsubheading Synopsis
33411
33412 @smallexample
33413 -var-assign @var{name} @var{expression}
33414 @end smallexample
33415
33416 Assigns the value of @var{expression} to the variable object specified
33417 by @var{name}. The object must be @samp{editable}. If the variable's
33418 value is altered by the assign, the variable will show up in any
33419 subsequent @code{-var-update} list.
33420
33421 @subsubheading Example
33422
33423 @smallexample
33424 (gdb)
33425 -var-assign var1 3
33426 ^done,value="3"
33427 (gdb)
33428 -var-update *
33429 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
33430 (gdb)
33431 @end smallexample
33432
33433 @subheading The @code{-var-update} Command
33434 @findex -var-update
33435
33436 @subsubheading Synopsis
33437
33438 @smallexample
33439 -var-update [@var{print-values}] @{@var{name} | "*"@}
33440 @end smallexample
33441
33442 Reevaluate the expressions corresponding to the variable object
33443 @var{name} and all its direct and indirect children, and return the
33444 list of variable objects whose values have changed; @var{name} must
33445 be a root variable object. Here, ``changed'' means that the result of
33446 @code{-var-evaluate-expression} before and after the
33447 @code{-var-update} is different. If @samp{*} is used as the variable
33448 object names, all existing variable objects are updated, except
33449 for frozen ones (@pxref{-var-set-frozen}). The option
33450 @var{print-values} determines whether both names and values, or just
33451 names are printed. The possible values of this option are the same
33452 as for @code{-var-list-children} (@pxref{-var-list-children}). It is
33453 recommended to use the @samp{--all-values} option, to reduce the
33454 number of MI commands needed on each program stop.
33455
33456 With the @samp{*} parameter, if a variable object is bound to a
33457 currently running thread, it will not be updated, without any
33458 diagnostic.
33459
33460 If @code{-var-set-update-range} was previously used on a varobj, then
33461 only the selected range of children will be reported.
33462
33463 @code{-var-update} reports all the changed varobjs in a tuple named
33464 @samp{changelist}.
33465
33466 Each item in the change list is itself a tuple holding:
33467
33468 @table @samp
33469 @item name
33470 The name of the varobj.
33471
33472 @item value
33473 If values were requested for this update, then this field will be
33474 present and will hold the value of the varobj.
33475
33476 @item in_scope
33477 @anchor{-var-update}
33478 This field is a string which may take one of three values:
33479
33480 @table @code
33481 @item "true"
33482 The variable object's current value is valid.
33483
33484 @item "false"
33485 The variable object does not currently hold a valid value but it may
33486 hold one in the future if its associated expression comes back into
33487 scope.
33488
33489 @item "invalid"
33490 The variable object no longer holds a valid value.
33491 This can occur when the executable file being debugged has changed,
33492 either through recompilation or by using the @value{GDBN} @code{file}
33493 command. The front end should normally choose to delete these variable
33494 objects.
33495 @end table
33496
33497 In the future new values may be added to this list so the front should
33498 be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
33499
33500 @item type_changed
33501 This is only present if the varobj is still valid. If the type
33502 changed, then this will be the string @samp{true}; otherwise it will
33503 be @samp{false}.
33504
33505 When a varobj's type changes, its children are also likely to have
33506 become incorrect. Therefore, the varobj's children are automatically
33507 deleted when this attribute is @samp{true}. Also, the varobj's update
33508 range, when set using the @code{-var-set-update-range} command, is
33509 unset.
33510
33511 @item new_type
33512 If the varobj's type changed, then this field will be present and will
33513 hold the new type.
33514
33515 @item new_num_children
33516 For a dynamic varobj, if the number of children changed, or if the
33517 type changed, this will be the new number of children.
33518
33519 The @samp{numchild} field in other varobj responses is generally not
33520 valid for a dynamic varobj -- it will show the number of children that
33521 @value{GDBN} knows about, but because dynamic varobjs lazily
33522 instantiate their children, this will not reflect the number of
33523 children which may be available.
33524
33525 The @samp{new_num_children} attribute only reports changes to the
33526 number of children known by @value{GDBN}. This is the only way to
33527 detect whether an update has removed children (which necessarily can
33528 only happen at the end of the update range).
33529
33530 @item displayhint
33531 The display hint, if any.
33532
33533 @item has_more
33534 This is an integer value, which will be 1 if there are more children
33535 available outside the varobj's update range.
33536
33537 @item dynamic
33538 This attribute will be present and have the value @samp{1} if the
33539 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
33540 then this attribute will not be present.
33541
33542 @item new_children
33543 If new children were added to a dynamic varobj within the selected
33544 update range (as set by @code{-var-set-update-range}), then they will
33545 be listed in this attribute.
33546 @end table
33547
33548 @subsubheading Example
33549
33550 @smallexample
33551 (gdb)
33552 -var-assign var1 3
33553 ^done,value="3"
33554 (gdb)
33555 -var-update --all-values var1
33556 ^done,changelist=[@{name="var1",value="3",in_scope="true",
33557 type_changed="false"@}]
33558 (gdb)
33559 @end smallexample
33560
33561 @subheading The @code{-var-set-frozen} Command
33562 @findex -var-set-frozen
33563 @anchor{-var-set-frozen}
33564
33565 @subsubheading Synopsis
33566
33567 @smallexample
33568 -var-set-frozen @var{name} @var{flag}
33569 @end smallexample
33570
33571 Set the frozenness flag on the variable object @var{name}. The
33572 @var{flag} parameter should be either @samp{1} to make the variable
33573 frozen or @samp{0} to make it unfrozen. If a variable object is
33574 frozen, then neither itself, nor any of its children, are
33575 implicitly updated by @code{-var-update} of
33576 a parent variable or by @code{-var-update *}. Only
33577 @code{-var-update} of the variable itself will update its value and
33578 values of its children. After a variable object is unfrozen, it is
33579 implicitly updated by all subsequent @code{-var-update} operations.
33580 Unfreezing a variable does not update it, only subsequent
33581 @code{-var-update} does.
33582
33583 @subsubheading Example
33584
33585 @smallexample
33586 (gdb)
33587 -var-set-frozen V 1
33588 ^done
33589 (gdb)
33590 @end smallexample
33591
33592 @subheading The @code{-var-set-update-range} command
33593 @findex -var-set-update-range
33594 @anchor{-var-set-update-range}
33595
33596 @subsubheading Synopsis
33597
33598 @smallexample
33599 -var-set-update-range @var{name} @var{from} @var{to}
33600 @end smallexample
33601
33602 Set the range of children to be returned by future invocations of
33603 @code{-var-update}.
33604
33605 @var{from} and @var{to} indicate the range of children to report. If
33606 @var{from} or @var{to} is less than zero, the range is reset and all
33607 children will be reported. Otherwise, children starting at @var{from}
33608 (zero-based) and up to and excluding @var{to} will be reported.
33609
33610 @subsubheading Example
33611
33612 @smallexample
33613 (gdb)
33614 -var-set-update-range V 1 2
33615 ^done
33616 @end smallexample
33617
33618 @subheading The @code{-var-set-visualizer} command
33619 @findex -var-set-visualizer
33620 @anchor{-var-set-visualizer}
33621
33622 @subsubheading Synopsis
33623
33624 @smallexample
33625 -var-set-visualizer @var{name} @var{visualizer}
33626 @end smallexample
33627
33628 Set a visualizer for the variable object @var{name}.
33629
33630 @var{visualizer} is the visualizer to use. The special value
33631 @samp{None} means to disable any visualizer in use.
33632
33633 If not @samp{None}, @var{visualizer} must be a Python expression.
33634 This expression must evaluate to a callable object which accepts a
33635 single argument. @value{GDBN} will call this object with the value of
33636 the varobj @var{name} as an argument (this is done so that the same
33637 Python pretty-printing code can be used for both the CLI and MI).
33638 When called, this object must return an object which conforms to the
33639 pretty-printing interface (@pxref{Pretty Printing API}).
33640
33641 The pre-defined function @code{gdb.default_visualizer} may be used to
33642 select a visualizer by following the built-in process
33643 (@pxref{Selecting Pretty-Printers}). This is done automatically when
33644 a varobj is created, and so ordinarily is not needed.
33645
33646 This feature is only available if Python support is enabled. The MI
33647 command @code{-list-features} (@pxref{GDB/MI Support Commands})
33648 can be used to check this.
33649
33650 @subsubheading Example
33651
33652 Resetting the visualizer:
33653
33654 @smallexample
33655 (gdb)
33656 -var-set-visualizer V None
33657 ^done
33658 @end smallexample
33659
33660 Reselecting the default (type-based) visualizer:
33661
33662 @smallexample
33663 (gdb)
33664 -var-set-visualizer V gdb.default_visualizer
33665 ^done
33666 @end smallexample
33667
33668 Suppose @code{SomeClass} is a visualizer class. A lambda expression
33669 can be used to instantiate this class for a varobj:
33670
33671 @smallexample
33672 (gdb)
33673 -var-set-visualizer V "lambda val: SomeClass()"
33674 ^done
33675 @end smallexample
33676
33677 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33678 @node GDB/MI Data Manipulation
33679 @section @sc{gdb/mi} Data Manipulation
33680
33681 @cindex data manipulation, in @sc{gdb/mi}
33682 @cindex @sc{gdb/mi}, data manipulation
33683 This section describes the @sc{gdb/mi} commands that manipulate data:
33684 examine memory and registers, evaluate expressions, etc.
33685
33686 For details about what an addressable memory unit is,
33687 @pxref{addressable memory unit}.
33688
33689 @c REMOVED FROM THE INTERFACE.
33690 @c @subheading -data-assign
33691 @c Change the value of a program variable. Plenty of side effects.
33692 @c @subsubheading GDB Command
33693 @c set variable
33694 @c @subsubheading Example
33695 @c N.A.
33696
33697 @subheading The @code{-data-disassemble} Command
33698 @findex -data-disassemble
33699
33700 @subsubheading Synopsis
33701
33702 @smallexample
33703 -data-disassemble
33704 [ -s @var{start-addr} -e @var{end-addr} ]
33705 | [ -a @var{addr} ]
33706 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
33707 -- @var{mode}
33708 @end smallexample
33709
33710 @noindent
33711 Where:
33712
33713 @table @samp
33714 @item @var{start-addr}
33715 is the beginning address (or @code{$pc})
33716 @item @var{end-addr}
33717 is the end address
33718 @item @var{addr}
33719 is an address anywhere within (or the name of) the function to
33720 disassemble. If an address is specified, the whole function
33721 surrounding that address will be disassembled. If a name is
33722 specified, the whole function with that name will be disassembled.
33723 @item @var{filename}
33724 is the name of the file to disassemble
33725 @item @var{linenum}
33726 is the line number to disassemble around
33727 @item @var{lines}
33728 is the number of disassembly lines to be produced. If it is -1,
33729 the whole function will be disassembled, in case no @var{end-addr} is
33730 specified. If @var{end-addr} is specified as a non-zero value, and
33731 @var{lines} is lower than the number of disassembly lines between
33732 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
33733 displayed; if @var{lines} is higher than the number of lines between
33734 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
33735 are displayed.
33736 @item @var{mode}
33737 is one of:
33738 @itemize @bullet
33739 @item 0 disassembly only
33740 @item 1 mixed source and disassembly (deprecated)
33741 @item 2 disassembly with raw opcodes
33742 @item 3 mixed source and disassembly with raw opcodes (deprecated)
33743 @item 4 mixed source and disassembly
33744 @item 5 mixed source and disassembly with raw opcodes
33745 @end itemize
33746
33747 Modes 1 and 3 are deprecated. The output is ``source centric''
33748 which hasn't proved useful in practice.
33749 @xref{Machine Code}, for a discussion of the difference between
33750 @code{/m} and @code{/s} output of the @code{disassemble} command.
33751 @end table
33752
33753 @subsubheading Result
33754
33755 The result of the @code{-data-disassemble} command will be a list named
33756 @samp{asm_insns}, the contents of this list depend on the @var{mode}
33757 used with the @code{-data-disassemble} command.
33758
33759 For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
33760 following fields:
33761
33762 @table @code
33763 @item address
33764 The address at which this instruction was disassembled.
33765
33766 @item func-name
33767 The name of the function this instruction is within.
33768
33769 @item offset
33770 The decimal offset in bytes from the start of @samp{func-name}.
33771
33772 @item inst
33773 The text disassembly for this @samp{address}.
33774
33775 @item opcodes
33776 This field is only present for modes 2, 3 and 5. This contains the raw opcode
33777 bytes for the @samp{inst} field.
33778
33779 @end table
33780
33781 For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
33782 @samp{src_and_asm_line}, each of which has the following fields:
33783
33784 @table @code
33785 @item line
33786 The line number within @samp{file}.
33787
33788 @item file
33789 The file name from the compilation unit. This might be an absolute
33790 file name or a relative file name depending on the compile command
33791 used.
33792
33793 @item fullname
33794 Absolute file name of @samp{file}. It is converted to a canonical form
33795 using the source file search path
33796 (@pxref{Source Path, ,Specifying Source Directories})
33797 and after resolving all the symbolic links.
33798
33799 If the source file is not found this field will contain the path as
33800 present in the debug information.
33801
33802 @item line_asm_insn
33803 This is a list of tuples containing the disassembly for @samp{line} in
33804 @samp{file}. The fields of each tuple are the same as for
33805 @code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
33806 @samp{func-name}, @samp{offset}, @samp{inst}, and optionally
33807 @samp{opcodes}.
33808
33809 @end table
33810
33811 Note that whatever included in the @samp{inst} field, is not
33812 manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
33813 adjust its format.
33814
33815 @subsubheading @value{GDBN} Command
33816
33817 The corresponding @value{GDBN} command is @samp{disassemble}.
33818
33819 @subsubheading Example
33820
33821 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
33822
33823 @smallexample
33824 (gdb)
33825 -data-disassemble -s $pc -e "$pc + 20" -- 0
33826 ^done,
33827 asm_insns=[
33828 @{address="0x000107c0",func-name="main",offset="4",
33829 inst="mov 2, %o0"@},
33830 @{address="0x000107c4",func-name="main",offset="8",
33831 inst="sethi %hi(0x11800), %o2"@},
33832 @{address="0x000107c8",func-name="main",offset="12",
33833 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
33834 @{address="0x000107cc",func-name="main",offset="16",
33835 inst="sethi %hi(0x11800), %o2"@},
33836 @{address="0x000107d0",func-name="main",offset="20",
33837 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
33838 (gdb)
33839 @end smallexample
33840
33841 Disassemble the whole @code{main} function. Line 32 is part of
33842 @code{main}.
33843
33844 @smallexample
33845 -data-disassemble -f basics.c -l 32 -- 0
33846 ^done,asm_insns=[
33847 @{address="0x000107bc",func-name="main",offset="0",
33848 inst="save %sp, -112, %sp"@},
33849 @{address="0x000107c0",func-name="main",offset="4",
33850 inst="mov 2, %o0"@},
33851 @{address="0x000107c4",func-name="main",offset="8",
33852 inst="sethi %hi(0x11800), %o2"@},
33853 [@dots{}]
33854 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
33855 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
33856 (gdb)
33857 @end smallexample
33858
33859 Disassemble 3 instructions from the start of @code{main}:
33860
33861 @smallexample
33862 (gdb)
33863 -data-disassemble -f basics.c -l 32 -n 3 -- 0
33864 ^done,asm_insns=[
33865 @{address="0x000107bc",func-name="main",offset="0",
33866 inst="save %sp, -112, %sp"@},
33867 @{address="0x000107c0",func-name="main",offset="4",
33868 inst="mov 2, %o0"@},
33869 @{address="0x000107c4",func-name="main",offset="8",
33870 inst="sethi %hi(0x11800), %o2"@}]
33871 (gdb)
33872 @end smallexample
33873
33874 Disassemble 3 instructions from the start of @code{main} in mixed mode:
33875
33876 @smallexample
33877 (gdb)
33878 -data-disassemble -f basics.c -l 32 -n 3 -- 1
33879 ^done,asm_insns=[
33880 src_and_asm_line=@{line="31",
33881 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33882 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33883 line_asm_insn=[@{address="0x000107bc",
33884 func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
33885 src_and_asm_line=@{line="32",
33886 file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33887 fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33888 line_asm_insn=[@{address="0x000107c0",
33889 func-name="main",offset="4",inst="mov 2, %o0"@},
33890 @{address="0x000107c4",func-name="main",offset="8",
33891 inst="sethi %hi(0x11800), %o2"@}]@}]
33892 (gdb)
33893 @end smallexample
33894
33895
33896 @subheading The @code{-data-evaluate-expression} Command
33897 @findex -data-evaluate-expression
33898
33899 @subsubheading Synopsis
33900
33901 @smallexample
33902 -data-evaluate-expression @var{expr}
33903 @end smallexample
33904
33905 Evaluate @var{expr} as an expression. The expression could contain an
33906 inferior function call. The function call will execute synchronously.
33907 If the expression contains spaces, it must be enclosed in double quotes.
33908
33909 @subsubheading @value{GDBN} Command
33910
33911 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
33912 @samp{call}. In @code{gdbtk} only, there's a corresponding
33913 @samp{gdb_eval} command.
33914
33915 @subsubheading Example
33916
33917 In the following example, the numbers that precede the commands are the
33918 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
33919 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
33920 output.
33921
33922 @smallexample
33923 211-data-evaluate-expression A
33924 211^done,value="1"
33925 (gdb)
33926 311-data-evaluate-expression &A
33927 311^done,value="0xefffeb7c"
33928 (gdb)
33929 411-data-evaluate-expression A+3
33930 411^done,value="4"
33931 (gdb)
33932 511-data-evaluate-expression "A + 3"
33933 511^done,value="4"
33934 (gdb)
33935 @end smallexample
33936
33937
33938 @subheading The @code{-data-list-changed-registers} Command
33939 @findex -data-list-changed-registers
33940
33941 @subsubheading Synopsis
33942
33943 @smallexample
33944 -data-list-changed-registers
33945 @end smallexample
33946
33947 Display a list of the registers that have changed.
33948
33949 @subsubheading @value{GDBN} Command
33950
33951 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
33952 has the corresponding command @samp{gdb_changed_register_list}.
33953
33954 @subsubheading Example
33955
33956 On a PPC MBX board:
33957
33958 @smallexample
33959 (gdb)
33960 -exec-continue
33961 ^running
33962
33963 (gdb)
33964 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
33965 func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
33966 line="5",arch="powerpc"@}
33967 (gdb)
33968 -data-list-changed-registers
33969 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
33970 "10","11","13","14","15","16","17","18","19","20","21","22","23",
33971 "24","25","26","27","28","30","31","64","65","66","67","69"]
33972 (gdb)
33973 @end smallexample
33974
33975
33976 @subheading The @code{-data-list-register-names} Command
33977 @findex -data-list-register-names
33978
33979 @subsubheading Synopsis
33980
33981 @smallexample
33982 -data-list-register-names [ ( @var{regno} )+ ]
33983 @end smallexample
33984
33985 Show a list of register names for the current target. If no arguments
33986 are given, it shows a list of the names of all the registers. If
33987 integer numbers are given as arguments, it will print a list of the
33988 names of the registers corresponding to the arguments. To ensure
33989 consistency between a register name and its number, the output list may
33990 include empty register names.
33991
33992 @subsubheading @value{GDBN} Command
33993
33994 @value{GDBN} does not have a command which corresponds to
33995 @samp{-data-list-register-names}. In @code{gdbtk} there is a
33996 corresponding command @samp{gdb_regnames}.
33997
33998 @subsubheading Example
33999
34000 For the PPC MBX board:
34001 @smallexample
34002 (gdb)
34003 -data-list-register-names
34004 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
34005 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
34006 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
34007 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
34008 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
34009 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
34010 "", "pc","ps","cr","lr","ctr","xer"]
34011 (gdb)
34012 -data-list-register-names 1 2 3
34013 ^done,register-names=["r1","r2","r3"]
34014 (gdb)
34015 @end smallexample
34016
34017 @subheading The @code{-data-list-register-values} Command
34018 @findex -data-list-register-values
34019
34020 @subsubheading Synopsis
34021
34022 @smallexample
34023 -data-list-register-values
34024 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
34025 @end smallexample
34026
34027 Display the registers' contents. The format according to which the
34028 registers' contents are to be returned is given by @var{fmt}, followed
34029 by an optional list of numbers specifying the registers to display. A
34030 missing list of numbers indicates that the contents of all the
34031 registers must be returned. The @code{--skip-unavailable} option
34032 indicates that only the available registers are to be returned.
34033
34034 Allowed formats for @var{fmt} are:
34035
34036 @table @code
34037 @item x
34038 Hexadecimal
34039 @item o
34040 Octal
34041 @item t
34042 Binary
34043 @item d
34044 Decimal
34045 @item r
34046 Raw
34047 @item N
34048 Natural
34049 @end table
34050
34051 @subsubheading @value{GDBN} Command
34052
34053 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
34054 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
34055
34056 @subsubheading Example
34057
34058 For a PPC MBX board (note: line breaks are for readability only, they
34059 don't appear in the actual output):
34060
34061 @smallexample
34062 (gdb)
34063 -data-list-register-values r 64 65
34064 ^done,register-values=[@{number="64",value="0xfe00a300"@},
34065 @{number="65",value="0x00029002"@}]
34066 (gdb)
34067 -data-list-register-values x
34068 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
34069 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
34070 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
34071 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
34072 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
34073 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
34074 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
34075 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
34076 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
34077 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
34078 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
34079 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
34080 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
34081 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
34082 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
34083 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
34084 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
34085 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
34086 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
34087 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
34088 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
34089 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
34090 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
34091 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
34092 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
34093 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
34094 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
34095 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
34096 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
34097 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
34098 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
34099 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
34100 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
34101 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
34102 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
34103 @{number="69",value="0x20002b03"@}]
34104 (gdb)
34105 @end smallexample
34106
34107
34108 @subheading The @code{-data-read-memory} Command
34109 @findex -data-read-memory
34110
34111 This command is deprecated, use @code{-data-read-memory-bytes} instead.
34112
34113 @subsubheading Synopsis
34114
34115 @smallexample
34116 -data-read-memory [ -o @var{byte-offset} ]
34117 @var{address} @var{word-format} @var{word-size}
34118 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
34119 @end smallexample
34120
34121 @noindent
34122 where:
34123
34124 @table @samp
34125 @item @var{address}
34126 An expression specifying the address of the first memory word to be
34127 read. Complex expressions containing embedded white space should be
34128 quoted using the C convention.
34129
34130 @item @var{word-format}
34131 The format to be used to print the memory words. The notation is the
34132 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
34133 ,Output Formats}).
34134
34135 @item @var{word-size}
34136 The size of each memory word in bytes.
34137
34138 @item @var{nr-rows}
34139 The number of rows in the output table.
34140
34141 @item @var{nr-cols}
34142 The number of columns in the output table.
34143
34144 @item @var{aschar}
34145 If present, indicates that each row should include an @sc{ascii} dump. The
34146 value of @var{aschar} is used as a padding character when a byte is not a
34147 member of the printable @sc{ascii} character set (printable @sc{ascii}
34148 characters are those whose code is between 32 and 126, inclusively).
34149
34150 @item @var{byte-offset}
34151 An offset to add to the @var{address} before fetching memory.
34152 @end table
34153
34154 This command displays memory contents as a table of @var{nr-rows} by
34155 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
34156 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
34157 (returned as @samp{total-bytes}). Should less than the requested number
34158 of bytes be returned by the target, the missing words are identified
34159 using @samp{N/A}. The number of bytes read from the target is returned
34160 in @samp{nr-bytes} and the starting address used to read memory in
34161 @samp{addr}.
34162
34163 The address of the next/previous row or page is available in
34164 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
34165 @samp{prev-page}.
34166
34167 @subsubheading @value{GDBN} Command
34168
34169 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
34170 @samp{gdb_get_mem} memory read command.
34171
34172 @subsubheading Example
34173
34174 Read six bytes of memory starting at @code{bytes+6} but then offset by
34175 @code{-6} bytes. Format as three rows of two columns. One byte per
34176 word. Display each word in hex.
34177
34178 @smallexample
34179 (gdb)
34180 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
34181 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
34182 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
34183 prev-page="0x0000138a",memory=[
34184 @{addr="0x00001390",data=["0x00","0x01"]@},
34185 @{addr="0x00001392",data=["0x02","0x03"]@},
34186 @{addr="0x00001394",data=["0x04","0x05"]@}]
34187 (gdb)
34188 @end smallexample
34189
34190 Read two bytes of memory starting at address @code{shorts + 64} and
34191 display as a single word formatted in decimal.
34192
34193 @smallexample
34194 (gdb)
34195 5-data-read-memory shorts+64 d 2 1 1
34196 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
34197 next-row="0x00001512",prev-row="0x0000150e",
34198 next-page="0x00001512",prev-page="0x0000150e",memory=[
34199 @{addr="0x00001510",data=["128"]@}]
34200 (gdb)
34201 @end smallexample
34202
34203 Read thirty two bytes of memory starting at @code{bytes+16} and format
34204 as eight rows of four columns. Include a string encoding with @samp{x}
34205 used as the non-printable character.
34206
34207 @smallexample
34208 (gdb)
34209 4-data-read-memory bytes+16 x 1 8 4 x
34210 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
34211 next-row="0x000013c0",prev-row="0x0000139c",
34212 next-page="0x000013c0",prev-page="0x00001380",memory=[
34213 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
34214 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
34215 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
34216 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
34217 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
34218 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
34219 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
34220 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
34221 (gdb)
34222 @end smallexample
34223
34224 @subheading The @code{-data-read-memory-bytes} Command
34225 @findex -data-read-memory-bytes
34226
34227 @subsubheading Synopsis
34228
34229 @smallexample
34230 -data-read-memory-bytes [ -o @var{offset} ]
34231 @var{address} @var{count}
34232 @end smallexample
34233
34234 @noindent
34235 where:
34236
34237 @table @samp
34238 @item @var{address}
34239 An expression specifying the address of the first addressable memory unit
34240 to be read. Complex expressions containing embedded white space should be
34241 quoted using the C convention.
34242
34243 @item @var{count}
34244 The number of addressable memory units to read. This should be an integer
34245 literal.
34246
34247 @item @var{offset}
34248 The offset relative to @var{address} at which to start reading. This
34249 should be an integer literal. This option is provided so that a frontend
34250 is not required to first evaluate address and then perform address
34251 arithmetics itself.
34252
34253 @end table
34254
34255 This command attempts to read all accessible memory regions in the
34256 specified range. First, all regions marked as unreadable in the memory
34257 map (if one is defined) will be skipped. @xref{Memory Region
34258 Attributes}. Second, @value{GDBN} will attempt to read the remaining
34259 regions. For each one, if reading full region results in an errors,
34260 @value{GDBN} will try to read a subset of the region.
34261
34262 In general, every single memory unit in the region may be readable or not,
34263 and the only way to read every readable unit is to try a read at
34264 every address, which is not practical. Therefore, @value{GDBN} will
34265 attempt to read all accessible memory units at either beginning or the end
34266 of the region, using a binary division scheme. This heuristic works
34267 well for reading across a memory map boundary. Note that if a region
34268 has a readable range that is neither at the beginning or the end,
34269 @value{GDBN} will not read it.
34270
34271 The result record (@pxref{GDB/MI Result Records}) that is output of
34272 the command includes a field named @samp{memory} whose content is a
34273 list of tuples. Each tuple represent a successfully read memory block
34274 and has the following fields:
34275
34276 @table @code
34277 @item begin
34278 The start address of the memory block, as hexadecimal literal.
34279
34280 @item end
34281 The end address of the memory block, as hexadecimal literal.
34282
34283 @item offset
34284 The offset of the memory block, as hexadecimal literal, relative to
34285 the start address passed to @code{-data-read-memory-bytes}.
34286
34287 @item contents
34288 The contents of the memory block, in hex.
34289
34290 @end table
34291
34292
34293
34294 @subsubheading @value{GDBN} Command
34295
34296 The corresponding @value{GDBN} command is @samp{x}.
34297
34298 @subsubheading Example
34299
34300 @smallexample
34301 (gdb)
34302 -data-read-memory-bytes &a 10
34303 ^done,memory=[@{begin="0xbffff154",offset="0x00000000",
34304 end="0xbffff15e",
34305 contents="01000000020000000300"@}]
34306 (gdb)
34307 @end smallexample
34308
34309
34310 @subheading The @code{-data-write-memory-bytes} Command
34311 @findex -data-write-memory-bytes
34312
34313 @subsubheading Synopsis
34314
34315 @smallexample
34316 -data-write-memory-bytes @var{address} @var{contents}
34317 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
34318 @end smallexample
34319
34320 @noindent
34321 where:
34322
34323 @table @samp
34324 @item @var{address}
34325 An expression specifying the address of the first addressable memory unit
34326 to be written. Complex expressions containing embedded white space should
34327 be quoted using the C convention.
34328
34329 @item @var{contents}
34330 The hex-encoded data to write. It is an error if @var{contents} does
34331 not represent an integral number of addressable memory units.
34332
34333 @item @var{count}
34334 Optional argument indicating the number of addressable memory units to be
34335 written. If @var{count} is greater than @var{contents}' length,
34336 @value{GDBN} will repeatedly write @var{contents} until it fills
34337 @var{count} memory units.
34338
34339 @end table
34340
34341 @subsubheading @value{GDBN} Command
34342
34343 There's no corresponding @value{GDBN} command.
34344
34345 @subsubheading Example
34346
34347 @smallexample
34348 (gdb)
34349 -data-write-memory-bytes &a "aabbccdd"
34350 ^done
34351 (gdb)
34352 @end smallexample
34353
34354 @smallexample
34355 (gdb)
34356 -data-write-memory-bytes &a "aabbccdd" 16e
34357 ^done
34358 (gdb)
34359 @end smallexample
34360
34361 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34362 @node GDB/MI Tracepoint Commands
34363 @section @sc{gdb/mi} Tracepoint Commands
34364
34365 The commands defined in this section implement MI support for
34366 tracepoints. For detailed introduction, see @ref{Tracepoints}.
34367
34368 @subheading The @code{-trace-find} Command
34369 @findex -trace-find
34370
34371 @subsubheading Synopsis
34372
34373 @smallexample
34374 -trace-find @var{mode} [@var{parameters}@dots{}]
34375 @end smallexample
34376
34377 Find a trace frame using criteria defined by @var{mode} and
34378 @var{parameters}. The following table lists permissible
34379 modes and their parameters. For details of operation, see @ref{tfind}.
34380
34381 @table @samp
34382
34383 @item none
34384 No parameters are required. Stops examining trace frames.
34385
34386 @item frame-number
34387 An integer is required as parameter. Selects tracepoint frame with
34388 that index.
34389
34390 @item tracepoint-number
34391 An integer is required as parameter. Finds next
34392 trace frame that corresponds to tracepoint with the specified number.
34393
34394 @item pc
34395 An address is required as parameter. Finds
34396 next trace frame that corresponds to any tracepoint at the specified
34397 address.
34398
34399 @item pc-inside-range
34400 Two addresses are required as parameters. Finds next trace
34401 frame that corresponds to a tracepoint at an address inside the
34402 specified range. Both bounds are considered to be inside the range.
34403
34404 @item pc-outside-range
34405 Two addresses are required as parameters. Finds
34406 next trace frame that corresponds to a tracepoint at an address outside
34407 the specified range. Both bounds are considered to be inside the range.
34408
34409 @item line
34410 Line specification is required as parameter. @xref{Specify Location}.
34411 Finds next trace frame that corresponds to a tracepoint at
34412 the specified location.
34413
34414 @end table
34415
34416 If @samp{none} was passed as @var{mode}, the response does not
34417 have fields. Otherwise, the response may have the following fields:
34418
34419 @table @samp
34420 @item found
34421 This field has either @samp{0} or @samp{1} as the value, depending
34422 on whether a matching tracepoint was found.
34423
34424 @item traceframe
34425 The index of the found traceframe. This field is present iff
34426 the @samp{found} field has value of @samp{1}.
34427
34428 @item tracepoint
34429 The index of the found tracepoint. This field is present iff
34430 the @samp{found} field has value of @samp{1}.
34431
34432 @item frame
34433 The information about the frame corresponding to the found trace
34434 frame. This field is present only if a trace frame was found.
34435 @xref{GDB/MI Frame Information}, for description of this field.
34436
34437 @end table
34438
34439 @subsubheading @value{GDBN} Command
34440
34441 The corresponding @value{GDBN} command is @samp{tfind}.
34442
34443 @subheading -trace-define-variable
34444 @findex -trace-define-variable
34445
34446 @subsubheading Synopsis
34447
34448 @smallexample
34449 -trace-define-variable @var{name} [ @var{value} ]
34450 @end smallexample
34451
34452 Create trace variable @var{name} if it does not exist. If
34453 @var{value} is specified, sets the initial value of the specified
34454 trace variable to that value. Note that the @var{name} should start
34455 with the @samp{$} character.
34456
34457 @subsubheading @value{GDBN} Command
34458
34459 The corresponding @value{GDBN} command is @samp{tvariable}.
34460
34461 @subheading The @code{-trace-frame-collected} Command
34462 @findex -trace-frame-collected
34463
34464 @subsubheading Synopsis
34465
34466 @smallexample
34467 -trace-frame-collected
34468 [--var-print-values @var{var_pval}]
34469 [--comp-print-values @var{comp_pval}]
34470 [--registers-format @var{regformat}]
34471 [--memory-contents]
34472 @end smallexample
34473
34474 This command returns the set of collected objects, register names,
34475 trace state variable names, memory ranges and computed expressions
34476 that have been collected at a particular trace frame. The optional
34477 parameters to the command affect the output format in different ways.
34478 See the output description table below for more details.
34479
34480 The reported names can be used in the normal manner to create
34481 varobjs and inspect the objects themselves. The items returned by
34482 this command are categorized so that it is clear which is a variable,
34483 which is a register, which is a trace state variable, which is a
34484 memory range and which is a computed expression.
34485
34486 For instance, if the actions were
34487 @smallexample
34488 collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
34489 collect *(int*)0xaf02bef0@@40
34490 @end smallexample
34491
34492 @noindent
34493 the object collected in its entirety would be @code{myVar}. The
34494 object @code{myArray} would be partially collected, because only the
34495 element at index @code{myIndex} would be collected. The remaining
34496 objects would be computed expressions.
34497
34498 An example output would be:
34499
34500 @smallexample
34501 (gdb)
34502 -trace-frame-collected
34503 ^done,
34504 explicit-variables=[@{name="myVar",value="1"@}],
34505 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
34506 @{name="myObj.field",value="0"@},
34507 @{name="myPtr->field",value="1"@},
34508 @{name="myCount + 2",value="3"@},
34509 @{name="$tvar1 + 1",value="43970027"@}],
34510 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
34511 @{number="1",value="0x0"@},
34512 @{number="2",value="0x4"@},
34513 ...
34514 @{number="125",value="0x0"@}],
34515 tvars=[@{name="$tvar1",current="43970026"@}],
34516 memory=[@{address="0x0000000000602264",length="4"@},
34517 @{address="0x0000000000615bc0",length="4"@}]
34518 (gdb)
34519 @end smallexample
34520
34521 Where:
34522
34523 @table @code
34524 @item explicit-variables
34525 The set of objects that have been collected in their entirety (as
34526 opposed to collecting just a few elements of an array or a few struct
34527 members). For each object, its name and value are printed.
34528 The @code{--var-print-values} option affects how or whether the value
34529 field is output. If @var{var_pval} is 0, then print only the names;
34530 if it is 1, print also their values; and if it is 2, print the name,
34531 type and value for simple data types, and the name and type for
34532 arrays, structures and unions.
34533
34534 @item computed-expressions
34535 The set of computed expressions that have been collected at the
34536 current trace frame. The @code{--comp-print-values} option affects
34537 this set like the @code{--var-print-values} option affects the
34538 @code{explicit-variables} set. See above.
34539
34540 @item registers
34541 The registers that have been collected at the current trace frame.
34542 For each register collected, the name and current value are returned.
34543 The value is formatted according to the @code{--registers-format}
34544 option. See the @command{-data-list-register-values} command for a
34545 list of the allowed formats. The default is @samp{x}.
34546
34547 @item tvars
34548 The trace state variables that have been collected at the current
34549 trace frame. For each trace state variable collected, the name and
34550 current value are returned.
34551
34552 @item memory
34553 The set of memory ranges that have been collected at the current trace
34554 frame. Its content is a list of tuples. Each tuple represents a
34555 collected memory range and has the following fields:
34556
34557 @table @code
34558 @item address
34559 The start address of the memory range, as hexadecimal literal.
34560
34561 @item length
34562 The length of the memory range, as decimal literal.
34563
34564 @item contents
34565 The contents of the memory block, in hex. This field is only present
34566 if the @code{--memory-contents} option is specified.
34567
34568 @end table
34569
34570 @end table
34571
34572 @subsubheading @value{GDBN} Command
34573
34574 There is no corresponding @value{GDBN} command.
34575
34576 @subsubheading Example
34577
34578 @subheading -trace-list-variables
34579 @findex -trace-list-variables
34580
34581 @subsubheading Synopsis
34582
34583 @smallexample
34584 -trace-list-variables
34585 @end smallexample
34586
34587 Return a table of all defined trace variables. Each element of the
34588 table has the following fields:
34589
34590 @table @samp
34591 @item name
34592 The name of the trace variable. This field is always present.
34593
34594 @item initial
34595 The initial value. This is a 64-bit signed integer. This
34596 field is always present.
34597
34598 @item current
34599 The value the trace variable has at the moment. This is a 64-bit
34600 signed integer. This field is absent iff current value is
34601 not defined, for example if the trace was never run, or is
34602 presently running.
34603
34604 @end table
34605
34606 @subsubheading @value{GDBN} Command
34607
34608 The corresponding @value{GDBN} command is @samp{tvariables}.
34609
34610 @subsubheading Example
34611
34612 @smallexample
34613 (gdb)
34614 -trace-list-variables
34615 ^done,trace-variables=@{nr_rows="1",nr_cols="3",
34616 hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
34617 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
34618 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
34619 body=[variable=@{name="$trace_timestamp",initial="0"@}
34620 variable=@{name="$foo",initial="10",current="15"@}]@}
34621 (gdb)
34622 @end smallexample
34623
34624 @subheading -trace-save
34625 @findex -trace-save
34626
34627 @subsubheading Synopsis
34628
34629 @smallexample
34630 -trace-save [ -r ] [ -ctf ] @var{filename}
34631 @end smallexample
34632
34633 Saves the collected trace data to @var{filename}. Without the
34634 @samp{-r} option, the data is downloaded from the target and saved
34635 in a local file. With the @samp{-r} option the target is asked
34636 to perform the save.
34637
34638 By default, this command will save the trace in the tfile format. You can
34639 supply the optional @samp{-ctf} argument to save it the CTF format. See
34640 @ref{Trace Files} for more information about CTF.
34641
34642 @subsubheading @value{GDBN} Command
34643
34644 The corresponding @value{GDBN} command is @samp{tsave}.
34645
34646
34647 @subheading -trace-start
34648 @findex -trace-start
34649
34650 @subsubheading Synopsis
34651
34652 @smallexample
34653 -trace-start
34654 @end smallexample
34655
34656 Starts a tracing experiment. The result of this command does not
34657 have any fields.
34658
34659 @subsubheading @value{GDBN} Command
34660
34661 The corresponding @value{GDBN} command is @samp{tstart}.
34662
34663 @subheading -trace-status
34664 @findex -trace-status
34665
34666 @subsubheading Synopsis
34667
34668 @smallexample
34669 -trace-status
34670 @end smallexample
34671
34672 Obtains the status of a tracing experiment. The result may include
34673 the following fields:
34674
34675 @table @samp
34676
34677 @item supported
34678 May have a value of either @samp{0}, when no tracing operations are
34679 supported, @samp{1}, when all tracing operations are supported, or
34680 @samp{file} when examining trace file. In the latter case, examining
34681 of trace frame is possible but new tracing experiement cannot be
34682 started. This field is always present.
34683
34684 @item running
34685 May have a value of either @samp{0} or @samp{1} depending on whether
34686 tracing experiement is in progress on target. This field is present
34687 if @samp{supported} field is not @samp{0}.
34688
34689 @item stop-reason
34690 Report the reason why the tracing was stopped last time. This field
34691 may be absent iff tracing was never stopped on target yet. The
34692 value of @samp{request} means the tracing was stopped as result of
34693 the @code{-trace-stop} command. The value of @samp{overflow} means
34694 the tracing buffer is full. The value of @samp{disconnection} means
34695 tracing was automatically stopped when @value{GDBN} has disconnected.
34696 The value of @samp{passcount} means tracing was stopped when a
34697 tracepoint was passed a maximal number of times for that tracepoint.
34698 This field is present if @samp{supported} field is not @samp{0}.
34699
34700 @item stopping-tracepoint
34701 The number of tracepoint whose passcount as exceeded. This field is
34702 present iff the @samp{stop-reason} field has the value of
34703 @samp{passcount}.
34704
34705 @item frames
34706 @itemx frames-created
34707 The @samp{frames} field is a count of the total number of trace frames
34708 in the trace buffer, while @samp{frames-created} is the total created
34709 during the run, including ones that were discarded, such as when a
34710 circular trace buffer filled up. Both fields are optional.
34711
34712 @item buffer-size
34713 @itemx buffer-free
34714 These fields tell the current size of the tracing buffer and the
34715 remaining space. These fields are optional.
34716
34717 @item circular
34718 The value of the circular trace buffer flag. @code{1} means that the
34719 trace buffer is circular and old trace frames will be discarded if
34720 necessary to make room, @code{0} means that the trace buffer is linear
34721 and may fill up.
34722
34723 @item disconnected
34724 The value of the disconnected tracing flag. @code{1} means that
34725 tracing will continue after @value{GDBN} disconnects, @code{0} means
34726 that the trace run will stop.
34727
34728 @item trace-file
34729 The filename of the trace file being examined. This field is
34730 optional, and only present when examining a trace file.
34731
34732 @end table
34733
34734 @subsubheading @value{GDBN} Command
34735
34736 The corresponding @value{GDBN} command is @samp{tstatus}.
34737
34738 @subheading -trace-stop
34739 @findex -trace-stop
34740
34741 @subsubheading Synopsis
34742
34743 @smallexample
34744 -trace-stop
34745 @end smallexample
34746
34747 Stops a tracing experiment. The result of this command has the same
34748 fields as @code{-trace-status}, except that the @samp{supported} and
34749 @samp{running} fields are not output.
34750
34751 @subsubheading @value{GDBN} Command
34752
34753 The corresponding @value{GDBN} command is @samp{tstop}.
34754
34755
34756 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34757 @node GDB/MI Symbol Query
34758 @section @sc{gdb/mi} Symbol Query Commands
34759
34760
34761 @ignore
34762 @subheading The @code{-symbol-info-address} Command
34763 @findex -symbol-info-address
34764
34765 @subsubheading Synopsis
34766
34767 @smallexample
34768 -symbol-info-address @var{symbol}
34769 @end smallexample
34770
34771 Describe where @var{symbol} is stored.
34772
34773 @subsubheading @value{GDBN} Command
34774
34775 The corresponding @value{GDBN} command is @samp{info address}.
34776
34777 @subsubheading Example
34778 N.A.
34779
34780
34781 @subheading The @code{-symbol-info-file} Command
34782 @findex -symbol-info-file
34783
34784 @subsubheading Synopsis
34785
34786 @smallexample
34787 -symbol-info-file
34788 @end smallexample
34789
34790 Show the file for the symbol.
34791
34792 @subsubheading @value{GDBN} Command
34793
34794 There's no equivalent @value{GDBN} command. @code{gdbtk} has
34795 @samp{gdb_find_file}.
34796
34797 @subsubheading Example
34798 N.A.
34799 @end ignore
34800
34801 @subheading The @code{-symbol-info-functions} Command
34802 @findex -symbol-info-functions
34803 @anchor{-symbol-info-functions}
34804
34805 @subsubheading Synopsis
34806
34807 @smallexample
34808 -symbol-info-functions [--include-nondebug]
34809 [--type @var{type_regexp}]
34810 [--name @var{name_regexp}]
34811 [--max-results @var{limit}]
34812 @end smallexample
34813
34814 @noindent
34815 Return a list containing the names and types for all global functions
34816 taken from the debug information. The functions are grouped by source
34817 file, and shown with the line number on which each function is
34818 defined.
34819
34820 The @code{--include-nondebug} option causes the output to include
34821 code symbols from the symbol table.
34822
34823 The options @code{--type} and @code{--name} allow the symbols returned
34824 to be filtered based on either the name of the function, or the type
34825 signature of the function.
34826
34827 The option @code{--max-results} restricts the command to return no
34828 more than @var{limit} results. If exactly @var{limit} results are
34829 returned then there might be additional results available if a higher
34830 limit is used.
34831
34832 @subsubheading @value{GDBN} Command
34833
34834 The corresponding @value{GDBN} command is @samp{info functions}.
34835
34836 @subsubheading Example
34837 @smallexample
34838 @group
34839 (gdb)
34840 -symbol-info-functions
34841 ^done,symbols=
34842 @{debug=
34843 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34844 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34845 symbols=[@{line="36", name="f4", type="void (int *)",
34846 description="void f4(int *);"@},
34847 @{line="42", name="main", type="int ()",
34848 description="int main();"@},
34849 @{line="30", name="f1", type="my_int_t (int, int)",
34850 description="static my_int_t f1(int, int);"@}]@},
34851 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34852 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34853 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34854 description="float f2(another_float_t);"@},
34855 @{line="39", name="f3", type="int (another_int_t)",
34856 description="int f3(another_int_t);"@},
34857 @{line="27", name="f1", type="another_float_t (int)",
34858 description="static another_float_t f1(int);"@}]@}]@}
34859 @end group
34860 @group
34861 (gdb)
34862 -symbol-info-functions --name f1
34863 ^done,symbols=
34864 @{debug=
34865 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34866 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34867 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
34868 description="static my_int_t f1(int, int);"@}]@},
34869 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34870 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34871 symbols=[@{line="27", name="f1", type="another_float_t (int)",
34872 description="static another_float_t f1(int);"@}]@}]@}
34873 @end group
34874 @group
34875 (gdb)
34876 -symbol-info-functions --type void
34877 ^done,symbols=
34878 @{debug=
34879 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34880 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34881 symbols=[@{line="36", name="f4", type="void (int *)",
34882 description="void f4(int *);"@}]@}]@}
34883 @end group
34884 @group
34885 (gdb)
34886 -symbol-info-functions --include-nondebug
34887 ^done,symbols=
34888 @{debug=
34889 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34890 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34891 symbols=[@{line="36", name="f4", type="void (int *)",
34892 description="void f4(int *);"@},
34893 @{line="42", name="main", type="int ()",
34894 description="int main();"@},
34895 @{line="30", name="f1", type="my_int_t (int, int)",
34896 description="static my_int_t f1(int, int);"@}]@},
34897 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34898 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34899 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34900 description="float f2(another_float_t);"@},
34901 @{line="39", name="f3", type="int (another_int_t)",
34902 description="int f3(another_int_t);"@},
34903 @{line="27", name="f1", type="another_float_t (int)",
34904 description="static another_float_t f1(int);"@}]@}],
34905 nondebug=
34906 [@{address="0x0000000000400398",name="_init"@},
34907 @{address="0x00000000004003b0",name="_start"@},
34908 ...
34909 ]@}
34910 @end group
34911 @end smallexample
34912
34913 @subheading The @code{-symbol-info-module-functions} Command
34914 @findex -symbol-info-module-functions
34915 @anchor{-symbol-info-module-functions}
34916
34917 @subsubheading Synopsis
34918
34919 @smallexample
34920 -symbol-info-module-functions [--module @var{module_regexp}]
34921 [--name @var{name_regexp}]
34922 [--type @var{type_regexp}]
34923 @end smallexample
34924
34925 @noindent
34926 Return a list containing the names of all known functions within all
34927 know Fortran modules. The functions are grouped by source file and
34928 containing module, and shown with the line number on which each
34929 function is defined.
34930
34931 The option @code{--module} only returns results for modules matching
34932 @var{module_regexp}. The option @code{--name} only returns functions
34933 whose name matches @var{name_regexp}, and @code{--type} only returns
34934 functions whose type matches @var{type_regexp}.
34935
34936 @subsubheading @value{GDBN} Command
34937
34938 The corresponding @value{GDBN} command is @samp{info module functions}.
34939
34940 @subsubheading Example
34941
34942 @smallexample
34943 @group
34944 (gdb)
34945 -symbol-info-module-functions
34946 ^done,symbols=
34947 [@{module="mod1",
34948 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34949 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34950 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
34951 description="void mod1::check_all(void);"@}]@}]@},
34952 @{module="mod2",
34953 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34954 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34955 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
34956 description="void mod2::check_var_i(void);"@}]@}]@},
34957 @{module="mod3",
34958 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34959 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34960 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
34961 description="void mod3::check_all(void);"@},
34962 @{line="27",name="mod3::check_mod2",type="void (void)",
34963 description="void mod3::check_mod2(void);"@}]@}]@},
34964 @{module="modmany",
34965 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34966 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34967 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
34968 description="void modmany::check_some(void);"@}]@}]@},
34969 @{module="moduse",
34970 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34971 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34972 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
34973 description="void moduse::check_all(void);"@},
34974 @{line="49",name="moduse::check_var_x",type="void (void)",
34975 description="void moduse::check_var_x(void);"@}]@}]@}]
34976 @end group
34977 @end smallexample
34978
34979 @subheading The @code{-symbol-info-module-variables} Command
34980 @findex -symbol-info-module-variables
34981 @anchor{-symbol-info-module-variables}
34982
34983 @subsubheading Synopsis
34984
34985 @smallexample
34986 -symbol-info-module-variables [--module @var{module_regexp}]
34987 [--name @var{name_regexp}]
34988 [--type @var{type_regexp}]
34989 @end smallexample
34990
34991 @noindent
34992 Return a list containing the names of all known variables within all
34993 know Fortran modules. The variables are grouped by source file and
34994 containing module, and shown with the line number on which each
34995 variable is defined.
34996
34997 The option @code{--module} only returns results for modules matching
34998 @var{module_regexp}. The option @code{--name} only returns variables
34999 whose name matches @var{name_regexp}, and @code{--type} only returns
35000 variables whose type matches @var{type_regexp}.
35001
35002 @subsubheading @value{GDBN} Command
35003
35004 The corresponding @value{GDBN} command is @samp{info module variables}.
35005
35006 @subsubheading Example
35007
35008 @smallexample
35009 @group
35010 (gdb)
35011 -symbol-info-module-variables
35012 ^done,symbols=
35013 [@{module="mod1",
35014 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35015 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35016 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
35017 description="integer(kind=4) mod1::var_const;"@},
35018 @{line="17",name="mod1::var_i",type="integer(kind=4)",
35019 description="integer(kind=4) mod1::var_i;"@}]@}]@},
35020 @{module="mod2",
35021 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35022 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35023 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
35024 description="integer(kind=4) mod2::var_i;"@}]@}]@},
35025 @{module="mod3",
35026 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35027 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35028 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
35029 description="integer(kind=4) mod3::mod1;"@},
35030 @{line="17",name="mod3::mod2",type="integer(kind=4)",
35031 description="integer(kind=4) mod3::mod2;"@},
35032 @{line="19",name="mod3::var_i",type="integer(kind=4)",
35033 description="integer(kind=4) mod3::var_i;"@}]@}]@},
35034 @{module="modmany",
35035 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35036 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35037 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
35038 description="integer(kind=4) modmany::var_a;"@},
35039 @{line="33",name="modmany::var_b",type="integer(kind=4)",
35040 description="integer(kind=4) modmany::var_b;"@},
35041 @{line="33",name="modmany::var_c",type="integer(kind=4)",
35042 description="integer(kind=4) modmany::var_c;"@},
35043 @{line="33",name="modmany::var_i",type="integer(kind=4)",
35044 description="integer(kind=4) modmany::var_i;"@}]@}]@},
35045 @{module="moduse",
35046 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35047 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35048 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
35049 description="integer(kind=4) moduse::var_x;"@},
35050 @{line="42",name="moduse::var_y",type="integer(kind=4)",
35051 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
35052 @end group
35053 @end smallexample
35054
35055 @subheading The @code{-symbol-info-modules} Command
35056 @findex -symbol-info-modules
35057 @anchor{-symbol-info-modules}
35058
35059 @subsubheading Synopsis
35060
35061 @smallexample
35062 -symbol-info-modules [--name @var{name_regexp}]
35063 [--max-results @var{limit}]
35064
35065 @end smallexample
35066
35067 @noindent
35068 Return a list containing the names of all known Fortran modules. The
35069 modules are grouped by source file, and shown with the line number on
35070 which each modules is defined.
35071
35072 The option @code{--name} allows the modules returned to be filtered
35073 based the name of the module.
35074
35075 The option @code{--max-results} restricts the command to return no
35076 more than @var{limit} results. If exactly @var{limit} results are
35077 returned then there might be additional results available if a higher
35078 limit is used.
35079
35080 @subsubheading @value{GDBN} Command
35081
35082 The corresponding @value{GDBN} command is @samp{info modules}.
35083
35084 @subsubheading Example
35085 @smallexample
35086 @group
35087 (gdb)
35088 -symbol-info-modules
35089 ^done,symbols=
35090 @{debug=
35091 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35092 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35093 symbols=[@{line="16",name="mod1"@},
35094 @{line="22",name="mod2"@}]@},
35095 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35096 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35097 symbols=[@{line="16",name="mod3"@},
35098 @{line="22",name="modmany"@},
35099 @{line="26",name="moduse"@}]@}]@}
35100 @end group
35101 @group
35102 (gdb)
35103 -symbol-info-modules --name mod[123]
35104 ^done,symbols=
35105 @{debug=
35106 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35107 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
35108 symbols=[@{line="16",name="mod1"@},
35109 @{line="22",name="mod2"@}]@},
35110 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35111 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
35112 symbols=[@{line="16",name="mod3"@}]@}]@}
35113 @end group
35114 @end smallexample
35115
35116 @subheading The @code{-symbol-info-types} Command
35117 @findex -symbol-info-types
35118 @anchor{-symbol-info-types}
35119
35120 @subsubheading Synopsis
35121
35122 @smallexample
35123 -symbol-info-types [--name @var{name_regexp}]
35124 [--max-results @var{limit}]
35125
35126 @end smallexample
35127
35128 @noindent
35129 Return a list of all defined types. The types are grouped by source
35130 file, and shown with the line number on which each user defined type
35131 is defined. Some base types are not defined in the source code but
35132 are added to the debug information by the compiler, for example
35133 @code{int}, @code{float}, etc.; these types do not have an associated
35134 line number.
35135
35136 The option @code{--name} allows the list of types returned to be
35137 filtered by name.
35138
35139 The option @code{--max-results} restricts the command to return no
35140 more than @var{limit} results. If exactly @var{limit} results are
35141 returned then there might be additional results available if a higher
35142 limit is used.
35143
35144 @subsubheading @value{GDBN} Command
35145
35146 The corresponding @value{GDBN} command is @samp{info types}.
35147
35148 @subsubheading Example
35149 @smallexample
35150 @group
35151 (gdb)
35152 -symbol-info-types
35153 ^done,symbols=
35154 @{debug=
35155 [@{filename="gdb.mi/mi-sym-info-1.c",
35156 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35157 symbols=[@{name="float"@},
35158 @{name="int"@},
35159 @{line="27",name="typedef int my_int_t;"@}]@},
35160 @{filename="gdb.mi/mi-sym-info-2.c",
35161 fullname="/project/gdb.mi/mi-sym-info-2.c",
35162 symbols=[@{line="24",name="typedef float another_float_t;"@},
35163 @{line="23",name="typedef int another_int_t;"@},
35164 @{name="float"@},
35165 @{name="int"@}]@}]@}
35166 @end group
35167 @group
35168 (gdb)
35169 -symbol-info-types --name _int_
35170 ^done,symbols=
35171 @{debug=
35172 [@{filename="gdb.mi/mi-sym-info-1.c",
35173 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35174 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
35175 @{filename="gdb.mi/mi-sym-info-2.c",
35176 fullname="/project/gdb.mi/mi-sym-info-2.c",
35177 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
35178 @end group
35179 @end smallexample
35180
35181 @subheading The @code{-symbol-info-variables} Command
35182 @findex -symbol-info-variables
35183 @anchor{-symbol-info-variables}
35184
35185 @subsubheading Synopsis
35186
35187 @smallexample
35188 -symbol-info-variables [--include-nondebug]
35189 [--type @var{type_regexp}]
35190 [--name @var{name_regexp}]
35191 [--max-results @var{limit}]
35192
35193 @end smallexample
35194
35195 @noindent
35196 Return a list containing the names and types for all global variables
35197 taken from the debug information. The variables are grouped by source
35198 file, and shown with the line number on which each variable is
35199 defined.
35200
35201 The @code{--include-nondebug} option causes the output to include
35202 data symbols from the symbol table.
35203
35204 The options @code{--type} and @code{--name} allow the symbols returned
35205 to be filtered based on either the name of the variable, or the type
35206 of the variable.
35207
35208 The option @code{--max-results} restricts the command to return no
35209 more than @var{limit} results. If exactly @var{limit} results are
35210 returned then there might be additional results available if a higher
35211 limit is used.
35212
35213 @subsubheading @value{GDBN} Command
35214
35215 The corresponding @value{GDBN} command is @samp{info variables}.
35216
35217 @subsubheading Example
35218 @smallexample
35219 @group
35220 (gdb)
35221 -symbol-info-variables
35222 ^done,symbols=
35223 @{debug=
35224 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35225 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35226 symbols=[@{line="25",name="global_f1",type="float",
35227 description="static float global_f1;"@},
35228 @{line="24",name="global_i1",type="int",
35229 description="static int global_i1;"@}]@},
35230 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35231 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35232 symbols=[@{line="21",name="global_f2",type="int",
35233 description="int global_f2;"@},
35234 @{line="20",name="global_i2",type="int",
35235 description="int global_i2;"@},
35236 @{line="19",name="global_f1",type="float",
35237 description="static float global_f1;"@},
35238 @{line="18",name="global_i1",type="int",
35239 description="static int global_i1;"@}]@}]@}
35240 @end group
35241 @group
35242 (gdb)
35243 -symbol-info-variables --name f1
35244 ^done,symbols=
35245 @{debug=
35246 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35247 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35248 symbols=[@{line="25",name="global_f1",type="float",
35249 description="static float global_f1;"@}]@},
35250 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35251 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35252 symbols=[@{line="19",name="global_f1",type="float",
35253 description="static float global_f1;"@}]@}]@}
35254 @end group
35255 @group
35256 (gdb)
35257 -symbol-info-variables --type float
35258 ^done,symbols=
35259 @{debug=
35260 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35261 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35262 symbols=[@{line="25",name="global_f1",type="float",
35263 description="static float global_f1;"@}]@},
35264 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35265 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35266 symbols=[@{line="19",name="global_f1",type="float",
35267 description="static float global_f1;"@}]@}]@}
35268 @end group
35269 @group
35270 (gdb)
35271 -symbol-info-variables --include-nondebug
35272 ^done,symbols=
35273 @{debug=
35274 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35275 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
35276 symbols=[@{line="25",name="global_f1",type="float",
35277 description="static float global_f1;"@},
35278 @{line="24",name="global_i1",type="int",
35279 description="static int global_i1;"@}]@},
35280 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35281 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
35282 symbols=[@{line="21",name="global_f2",type="int",
35283 description="int global_f2;"@},
35284 @{line="20",name="global_i2",type="int",
35285 description="int global_i2;"@},
35286 @{line="19",name="global_f1",type="float",
35287 description="static float global_f1;"@},
35288 @{line="18",name="global_i1",type="int",
35289 description="static int global_i1;"@}]@}],
35290 nondebug=
35291 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
35292 @{address="0x00000000004005d8",name="__dso_handle"@}
35293 ...
35294 ]@}
35295 @end group
35296 @end smallexample
35297
35298 @ignore
35299 @subheading The @code{-symbol-info-line} Command
35300 @findex -symbol-info-line
35301
35302 @subsubheading Synopsis
35303
35304 @smallexample
35305 -symbol-info-line
35306 @end smallexample
35307
35308 Show the core addresses of the code for a source line.
35309
35310 @subsubheading @value{GDBN} Command
35311
35312 The corresponding @value{GDBN} command is @samp{info line}.
35313 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
35314
35315 @subsubheading Example
35316 N.A.
35317
35318
35319 @subheading The @code{-symbol-info-symbol} Command
35320 @findex -symbol-info-symbol
35321
35322 @subsubheading Synopsis
35323
35324 @smallexample
35325 -symbol-info-symbol @var{addr}
35326 @end smallexample
35327
35328 Describe what symbol is at location @var{addr}.
35329
35330 @subsubheading @value{GDBN} Command
35331
35332 The corresponding @value{GDBN} command is @samp{info symbol}.
35333
35334 @subsubheading Example
35335 N.A.
35336
35337
35338 @subheading The @code{-symbol-list-functions} Command
35339 @findex -symbol-list-functions
35340
35341 @subsubheading Synopsis
35342
35343 @smallexample
35344 -symbol-list-functions
35345 @end smallexample
35346
35347 List the functions in the executable.
35348
35349 @subsubheading @value{GDBN} Command
35350
35351 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
35352 @samp{gdb_search} in @code{gdbtk}.
35353
35354 @subsubheading Example
35355 N.A.
35356 @end ignore
35357
35358
35359 @subheading The @code{-symbol-list-lines} Command
35360 @findex -symbol-list-lines
35361
35362 @subsubheading Synopsis
35363
35364 @smallexample
35365 -symbol-list-lines @var{filename}
35366 @end smallexample
35367
35368 Print the list of lines that contain code and their associated program
35369 addresses for the given source filename. The entries are sorted in
35370 ascending PC order.
35371
35372 @subsubheading @value{GDBN} Command
35373
35374 There is no corresponding @value{GDBN} command.
35375
35376 @subsubheading Example
35377 @smallexample
35378 (gdb)
35379 -symbol-list-lines basics.c
35380 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
35381 (gdb)
35382 @end smallexample
35383
35384
35385 @ignore
35386 @subheading The @code{-symbol-list-types} Command
35387 @findex -symbol-list-types
35388
35389 @subsubheading Synopsis
35390
35391 @smallexample
35392 -symbol-list-types
35393 @end smallexample
35394
35395 List all the type names.
35396
35397 @subsubheading @value{GDBN} Command
35398
35399 The corresponding commands are @samp{info types} in @value{GDBN},
35400 @samp{gdb_search} in @code{gdbtk}.
35401
35402 @subsubheading Example
35403 N.A.
35404
35405
35406 @subheading The @code{-symbol-list-variables} Command
35407 @findex -symbol-list-variables
35408
35409 @subsubheading Synopsis
35410
35411 @smallexample
35412 -symbol-list-variables
35413 @end smallexample
35414
35415 List all the global and static variable names.
35416
35417 @subsubheading @value{GDBN} Command
35418
35419 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
35420
35421 @subsubheading Example
35422 N.A.
35423
35424
35425 @subheading The @code{-symbol-locate} Command
35426 @findex -symbol-locate
35427
35428 @subsubheading Synopsis
35429
35430 @smallexample
35431 -symbol-locate
35432 @end smallexample
35433
35434 @subsubheading @value{GDBN} Command
35435
35436 @samp{gdb_loc} in @code{gdbtk}.
35437
35438 @subsubheading Example
35439 N.A.
35440
35441
35442 @subheading The @code{-symbol-type} Command
35443 @findex -symbol-type
35444
35445 @subsubheading Synopsis
35446
35447 @smallexample
35448 -symbol-type @var{variable}
35449 @end smallexample
35450
35451 Show type of @var{variable}.
35452
35453 @subsubheading @value{GDBN} Command
35454
35455 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
35456 @samp{gdb_obj_variable}.
35457
35458 @subsubheading Example
35459 N.A.
35460 @end ignore
35461
35462
35463 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35464 @node GDB/MI File Commands
35465 @section @sc{gdb/mi} File Commands
35466
35467 This section describes the GDB/MI commands to specify executable file names
35468 and to read in and obtain symbol table information.
35469
35470 @subheading The @code{-file-exec-and-symbols} Command
35471 @findex -file-exec-and-symbols
35472
35473 @subsubheading Synopsis
35474
35475 @smallexample
35476 -file-exec-and-symbols @var{file}
35477 @end smallexample
35478
35479 Specify the executable file to be debugged. This file is the one from
35480 which the symbol table is also read. If no file is specified, the
35481 command clears the executable and symbol information. If breakpoints
35482 are set when using this command with no arguments, @value{GDBN} will produce
35483 error messages. Otherwise, no output is produced, except a completion
35484 notification.
35485
35486 @subsubheading @value{GDBN} Command
35487
35488 The corresponding @value{GDBN} command is @samp{file}.
35489
35490 @subsubheading Example
35491
35492 @smallexample
35493 (gdb)
35494 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35495 ^done
35496 (gdb)
35497 @end smallexample
35498
35499
35500 @subheading The @code{-file-exec-file} Command
35501 @findex -file-exec-file
35502
35503 @subsubheading Synopsis
35504
35505 @smallexample
35506 -file-exec-file @var{file}
35507 @end smallexample
35508
35509 Specify the executable file to be debugged. Unlike
35510 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
35511 from this file. If used without argument, @value{GDBN} clears the information
35512 about the executable file. No output is produced, except a completion
35513 notification.
35514
35515 @subsubheading @value{GDBN} Command
35516
35517 The corresponding @value{GDBN} command is @samp{exec-file}.
35518
35519 @subsubheading Example
35520
35521 @smallexample
35522 (gdb)
35523 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35524 ^done
35525 (gdb)
35526 @end smallexample
35527
35528
35529 @ignore
35530 @subheading The @code{-file-list-exec-sections} Command
35531 @findex -file-list-exec-sections
35532
35533 @subsubheading Synopsis
35534
35535 @smallexample
35536 -file-list-exec-sections
35537 @end smallexample
35538
35539 List the sections of the current executable file.
35540
35541 @subsubheading @value{GDBN} Command
35542
35543 The @value{GDBN} command @samp{info file} shows, among the rest, the same
35544 information as this command. @code{gdbtk} has a corresponding command
35545 @samp{gdb_load_info}.
35546
35547 @subsubheading Example
35548 N.A.
35549 @end ignore
35550
35551
35552 @subheading The @code{-file-list-exec-source-file} Command
35553 @findex -file-list-exec-source-file
35554
35555 @subsubheading Synopsis
35556
35557 @smallexample
35558 -file-list-exec-source-file
35559 @end smallexample
35560
35561 List the line number, the current source file, and the absolute path
35562 to the current source file for the current executable. The macro
35563 information field has a value of @samp{1} or @samp{0} depending on
35564 whether or not the file includes preprocessor macro information.
35565
35566 @subsubheading @value{GDBN} Command
35567
35568 The @value{GDBN} equivalent is @samp{info source}
35569
35570 @subsubheading Example
35571
35572 @smallexample
35573 (gdb)
35574 123-file-list-exec-source-file
35575 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
35576 (gdb)
35577 @end smallexample
35578
35579
35580 @subheading The @code{-file-list-exec-source-files} Command
35581 @findex -file-list-exec-source-files
35582
35583 @subsubheading Synopsis
35584
35585 @smallexample
35586 -file-list-exec-source-files
35587 @end smallexample
35588
35589 List the source files for the current executable.
35590
35591 It will always output both the filename and fullname (absolute file
35592 name) of a source file.
35593
35594 @subsubheading @value{GDBN} Command
35595
35596 The @value{GDBN} equivalent is @samp{info sources}.
35597 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
35598
35599 @subsubheading Example
35600 @smallexample
35601 (gdb)
35602 -file-list-exec-source-files
35603 ^done,files=[
35604 @{file=foo.c,fullname=/home/foo.c@},
35605 @{file=/home/bar.c,fullname=/home/bar.c@},
35606 @{file=gdb_could_not_find_fullpath.c@}]
35607 (gdb)
35608 @end smallexample
35609
35610 @subheading The @code{-file-list-shared-libraries} Command
35611 @findex -file-list-shared-libraries
35612
35613 @subsubheading Synopsis
35614
35615 @smallexample
35616 -file-list-shared-libraries [ @var{regexp} ]
35617 @end smallexample
35618
35619 List the shared libraries in the program.
35620 With a regular expression @var{regexp}, only those libraries whose
35621 names match @var{regexp} are listed.
35622
35623 @subsubheading @value{GDBN} Command
35624
35625 The corresponding @value{GDBN} command is @samp{info shared}. The fields
35626 have a similar meaning to the @code{=library-loaded} notification.
35627 The @code{ranges} field specifies the multiple segments belonging to this
35628 library. Each range has the following fields:
35629
35630 @table @samp
35631 @item from
35632 The address defining the inclusive lower bound of the segment.
35633 @item to
35634 The address defining the exclusive upper bound of the segment.
35635 @end table
35636
35637 @subsubheading Example
35638 @smallexample
35639 (gdb)
35640 -file-list-exec-source-files
35641 ^done,shared-libraries=[
35642 @{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"@}]@},
35643 @{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"@}]@}]
35644 (gdb)
35645 @end smallexample
35646
35647
35648 @ignore
35649 @subheading The @code{-file-list-symbol-files} Command
35650 @findex -file-list-symbol-files
35651
35652 @subsubheading Synopsis
35653
35654 @smallexample
35655 -file-list-symbol-files
35656 @end smallexample
35657
35658 List symbol files.
35659
35660 @subsubheading @value{GDBN} Command
35661
35662 The corresponding @value{GDBN} command is @samp{info file} (part of it).
35663
35664 @subsubheading Example
35665 N.A.
35666 @end ignore
35667
35668
35669 @subheading The @code{-file-symbol-file} Command
35670 @findex -file-symbol-file
35671
35672 @subsubheading Synopsis
35673
35674 @smallexample
35675 -file-symbol-file @var{file}
35676 @end smallexample
35677
35678 Read symbol table info from the specified @var{file} argument. When
35679 used without arguments, clears @value{GDBN}'s symbol table info. No output is
35680 produced, except for a completion notification.
35681
35682 @subsubheading @value{GDBN} Command
35683
35684 The corresponding @value{GDBN} command is @samp{symbol-file}.
35685
35686 @subsubheading Example
35687
35688 @smallexample
35689 (gdb)
35690 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35691 ^done
35692 (gdb)
35693 @end smallexample
35694
35695 @ignore
35696 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35697 @node GDB/MI Memory Overlay Commands
35698 @section @sc{gdb/mi} Memory Overlay Commands
35699
35700 The memory overlay commands are not implemented.
35701
35702 @c @subheading -overlay-auto
35703
35704 @c @subheading -overlay-list-mapping-state
35705
35706 @c @subheading -overlay-list-overlays
35707
35708 @c @subheading -overlay-map
35709
35710 @c @subheading -overlay-off
35711
35712 @c @subheading -overlay-on
35713
35714 @c @subheading -overlay-unmap
35715
35716 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35717 @node GDB/MI Signal Handling Commands
35718 @section @sc{gdb/mi} Signal Handling Commands
35719
35720 Signal handling commands are not implemented.
35721
35722 @c @subheading -signal-handle
35723
35724 @c @subheading -signal-list-handle-actions
35725
35726 @c @subheading -signal-list-signal-types
35727 @end ignore
35728
35729
35730 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35731 @node GDB/MI Target Manipulation
35732 @section @sc{gdb/mi} Target Manipulation Commands
35733
35734
35735 @subheading The @code{-target-attach} Command
35736 @findex -target-attach
35737
35738 @subsubheading Synopsis
35739
35740 @smallexample
35741 -target-attach @var{pid} | @var{gid} | @var{file}
35742 @end smallexample
35743
35744 Attach to a process @var{pid} or a file @var{file} outside of
35745 @value{GDBN}, or a thread group @var{gid}. If attaching to a thread
35746 group, the id previously returned by
35747 @samp{-list-thread-groups --available} must be used.
35748
35749 @subsubheading @value{GDBN} Command
35750
35751 The corresponding @value{GDBN} command is @samp{attach}.
35752
35753 @subsubheading Example
35754 @smallexample
35755 (gdb)
35756 -target-attach 34
35757 =thread-created,id="1"
35758 *stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
35759 ^done
35760 (gdb)
35761 @end smallexample
35762
35763 @ignore
35764 @subheading The @code{-target-compare-sections} Command
35765 @findex -target-compare-sections
35766
35767 @subsubheading Synopsis
35768
35769 @smallexample
35770 -target-compare-sections [ @var{section} ]
35771 @end smallexample
35772
35773 Compare data of section @var{section} on target to the exec file.
35774 Without the argument, all sections are compared.
35775
35776 @subsubheading @value{GDBN} Command
35777
35778 The @value{GDBN} equivalent is @samp{compare-sections}.
35779
35780 @subsubheading Example
35781 N.A.
35782 @end ignore
35783
35784
35785 @subheading The @code{-target-detach} Command
35786 @findex -target-detach
35787
35788 @subsubheading Synopsis
35789
35790 @smallexample
35791 -target-detach [ @var{pid} | @var{gid} ]
35792 @end smallexample
35793
35794 Detach from the remote target which normally resumes its execution.
35795 If either @var{pid} or @var{gid} is specified, detaches from either
35796 the specified process, or specified thread group. There's no output.
35797
35798 @subsubheading @value{GDBN} Command
35799
35800 The corresponding @value{GDBN} command is @samp{detach}.
35801
35802 @subsubheading Example
35803
35804 @smallexample
35805 (gdb)
35806 -target-detach
35807 ^done
35808 (gdb)
35809 @end smallexample
35810
35811
35812 @subheading The @code{-target-disconnect} Command
35813 @findex -target-disconnect
35814
35815 @subsubheading Synopsis
35816
35817 @smallexample
35818 -target-disconnect
35819 @end smallexample
35820
35821 Disconnect from the remote target. There's no output and the target is
35822 generally not resumed.
35823
35824 @subsubheading @value{GDBN} Command
35825
35826 The corresponding @value{GDBN} command is @samp{disconnect}.
35827
35828 @subsubheading Example
35829
35830 @smallexample
35831 (gdb)
35832 -target-disconnect
35833 ^done
35834 (gdb)
35835 @end smallexample
35836
35837
35838 @subheading The @code{-target-download} Command
35839 @findex -target-download
35840
35841 @subsubheading Synopsis
35842
35843 @smallexample
35844 -target-download
35845 @end smallexample
35846
35847 Loads the executable onto the remote target.
35848 It prints out an update message every half second, which includes the fields:
35849
35850 @table @samp
35851 @item section
35852 The name of the section.
35853 @item section-sent
35854 The size of what has been sent so far for that section.
35855 @item section-size
35856 The size of the section.
35857 @item total-sent
35858 The total size of what was sent so far (the current and the previous sections).
35859 @item total-size
35860 The size of the overall executable to download.
35861 @end table
35862
35863 @noindent
35864 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
35865 @sc{gdb/mi} Output Syntax}).
35866
35867 In addition, it prints the name and size of the sections, as they are
35868 downloaded. These messages include the following fields:
35869
35870 @table @samp
35871 @item section
35872 The name of the section.
35873 @item section-size
35874 The size of the section.
35875 @item total-size
35876 The size of the overall executable to download.
35877 @end table
35878
35879 @noindent
35880 At the end, a summary is printed.
35881
35882 @subsubheading @value{GDBN} Command
35883
35884 The corresponding @value{GDBN} command is @samp{load}.
35885
35886 @subsubheading Example
35887
35888 Note: each status message appears on a single line. Here the messages
35889 have been broken down so that they can fit onto a page.
35890
35891 @smallexample
35892 (gdb)
35893 -target-download
35894 +download,@{section=".text",section-size="6668",total-size="9880"@}
35895 +download,@{section=".text",section-sent="512",section-size="6668",
35896 total-sent="512",total-size="9880"@}
35897 +download,@{section=".text",section-sent="1024",section-size="6668",
35898 total-sent="1024",total-size="9880"@}
35899 +download,@{section=".text",section-sent="1536",section-size="6668",
35900 total-sent="1536",total-size="9880"@}
35901 +download,@{section=".text",section-sent="2048",section-size="6668",
35902 total-sent="2048",total-size="9880"@}
35903 +download,@{section=".text",section-sent="2560",section-size="6668",
35904 total-sent="2560",total-size="9880"@}
35905 +download,@{section=".text",section-sent="3072",section-size="6668",
35906 total-sent="3072",total-size="9880"@}
35907 +download,@{section=".text",section-sent="3584",section-size="6668",
35908 total-sent="3584",total-size="9880"@}
35909 +download,@{section=".text",section-sent="4096",section-size="6668",
35910 total-sent="4096",total-size="9880"@}
35911 +download,@{section=".text",section-sent="4608",section-size="6668",
35912 total-sent="4608",total-size="9880"@}
35913 +download,@{section=".text",section-sent="5120",section-size="6668",
35914 total-sent="5120",total-size="9880"@}
35915 +download,@{section=".text",section-sent="5632",section-size="6668",
35916 total-sent="5632",total-size="9880"@}
35917 +download,@{section=".text",section-sent="6144",section-size="6668",
35918 total-sent="6144",total-size="9880"@}
35919 +download,@{section=".text",section-sent="6656",section-size="6668",
35920 total-sent="6656",total-size="9880"@}
35921 +download,@{section=".init",section-size="28",total-size="9880"@}
35922 +download,@{section=".fini",section-size="28",total-size="9880"@}
35923 +download,@{section=".data",section-size="3156",total-size="9880"@}
35924 +download,@{section=".data",section-sent="512",section-size="3156",
35925 total-sent="7236",total-size="9880"@}
35926 +download,@{section=".data",section-sent="1024",section-size="3156",
35927 total-sent="7748",total-size="9880"@}
35928 +download,@{section=".data",section-sent="1536",section-size="3156",
35929 total-sent="8260",total-size="9880"@}
35930 +download,@{section=".data",section-sent="2048",section-size="3156",
35931 total-sent="8772",total-size="9880"@}
35932 +download,@{section=".data",section-sent="2560",section-size="3156",
35933 total-sent="9284",total-size="9880"@}
35934 +download,@{section=".data",section-sent="3072",section-size="3156",
35935 total-sent="9796",total-size="9880"@}
35936 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
35937 write-rate="429"
35938 (gdb)
35939 @end smallexample
35940
35941
35942 @ignore
35943 @subheading The @code{-target-exec-status} Command
35944 @findex -target-exec-status
35945
35946 @subsubheading Synopsis
35947
35948 @smallexample
35949 -target-exec-status
35950 @end smallexample
35951
35952 Provide information on the state of the target (whether it is running or
35953 not, for instance).
35954
35955 @subsubheading @value{GDBN} Command
35956
35957 There's no equivalent @value{GDBN} command.
35958
35959 @subsubheading Example
35960 N.A.
35961
35962
35963 @subheading The @code{-target-list-available-targets} Command
35964 @findex -target-list-available-targets
35965
35966 @subsubheading Synopsis
35967
35968 @smallexample
35969 -target-list-available-targets
35970 @end smallexample
35971
35972 List the possible targets to connect to.
35973
35974 @subsubheading @value{GDBN} Command
35975
35976 The corresponding @value{GDBN} command is @samp{help target}.
35977
35978 @subsubheading Example
35979 N.A.
35980
35981
35982 @subheading The @code{-target-list-current-targets} Command
35983 @findex -target-list-current-targets
35984
35985 @subsubheading Synopsis
35986
35987 @smallexample
35988 -target-list-current-targets
35989 @end smallexample
35990
35991 Describe the current target.
35992
35993 @subsubheading @value{GDBN} Command
35994
35995 The corresponding information is printed by @samp{info file} (among
35996 other things).
35997
35998 @subsubheading Example
35999 N.A.
36000
36001
36002 @subheading The @code{-target-list-parameters} Command
36003 @findex -target-list-parameters
36004
36005 @subsubheading Synopsis
36006
36007 @smallexample
36008 -target-list-parameters
36009 @end smallexample
36010
36011 @c ????
36012 @end ignore
36013
36014 @subsubheading @value{GDBN} Command
36015
36016 No equivalent.
36017
36018 @subsubheading Example
36019 N.A.
36020
36021 @subheading The @code{-target-flash-erase} Command
36022 @findex -target-flash-erase
36023
36024 @subsubheading Synopsis
36025
36026 @smallexample
36027 -target-flash-erase
36028 @end smallexample
36029
36030 Erases all known flash memory regions on the target.
36031
36032 The corresponding @value{GDBN} command is @samp{flash-erase}.
36033
36034 The output is a list of flash regions that have been erased, with starting
36035 addresses and memory region sizes.
36036
36037 @smallexample
36038 (gdb)
36039 -target-flash-erase
36040 ^done,erased-regions=@{address="0x0",size="0x40000"@}
36041 (gdb)
36042 @end smallexample
36043
36044 @subheading The @code{-target-select} Command
36045 @findex -target-select
36046
36047 @subsubheading Synopsis
36048
36049 @smallexample
36050 -target-select @var{type} @var{parameters @dots{}}
36051 @end smallexample
36052
36053 Connect @value{GDBN} to the remote target. This command takes two args:
36054
36055 @table @samp
36056 @item @var{type}
36057 The type of target, for instance @samp{remote}, etc.
36058 @item @var{parameters}
36059 Device names, host names and the like. @xref{Target Commands, ,
36060 Commands for Managing Targets}, for more details.
36061 @end table
36062
36063 The output is a connection notification, followed by the address at
36064 which the target program is, in the following form:
36065
36066 @smallexample
36067 ^connected,addr="@var{address}",func="@var{function name}",
36068 args=[@var{arg list}]
36069 @end smallexample
36070
36071 @subsubheading @value{GDBN} Command
36072
36073 The corresponding @value{GDBN} command is @samp{target}.
36074
36075 @subsubheading Example
36076
36077 @smallexample
36078 (gdb)
36079 -target-select remote /dev/ttya
36080 ^connected,addr="0xfe00a300",func="??",args=[]
36081 (gdb)
36082 @end smallexample
36083
36084 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36085 @node GDB/MI File Transfer Commands
36086 @section @sc{gdb/mi} File Transfer Commands
36087
36088
36089 @subheading The @code{-target-file-put} Command
36090 @findex -target-file-put
36091
36092 @subsubheading Synopsis
36093
36094 @smallexample
36095 -target-file-put @var{hostfile} @var{targetfile}
36096 @end smallexample
36097
36098 Copy file @var{hostfile} from the host system (the machine running
36099 @value{GDBN}) to @var{targetfile} on the target system.
36100
36101 @subsubheading @value{GDBN} Command
36102
36103 The corresponding @value{GDBN} command is @samp{remote put}.
36104
36105 @subsubheading Example
36106
36107 @smallexample
36108 (gdb)
36109 -target-file-put localfile remotefile
36110 ^done
36111 (gdb)
36112 @end smallexample
36113
36114
36115 @subheading The @code{-target-file-get} Command
36116 @findex -target-file-get
36117
36118 @subsubheading Synopsis
36119
36120 @smallexample
36121 -target-file-get @var{targetfile} @var{hostfile}
36122 @end smallexample
36123
36124 Copy file @var{targetfile} from the target system to @var{hostfile}
36125 on the host system.
36126
36127 @subsubheading @value{GDBN} Command
36128
36129 The corresponding @value{GDBN} command is @samp{remote get}.
36130
36131 @subsubheading Example
36132
36133 @smallexample
36134 (gdb)
36135 -target-file-get remotefile localfile
36136 ^done
36137 (gdb)
36138 @end smallexample
36139
36140
36141 @subheading The @code{-target-file-delete} Command
36142 @findex -target-file-delete
36143
36144 @subsubheading Synopsis
36145
36146 @smallexample
36147 -target-file-delete @var{targetfile}
36148 @end smallexample
36149
36150 Delete @var{targetfile} from the target system.
36151
36152 @subsubheading @value{GDBN} Command
36153
36154 The corresponding @value{GDBN} command is @samp{remote delete}.
36155
36156 @subsubheading Example
36157
36158 @smallexample
36159 (gdb)
36160 -target-file-delete remotefile
36161 ^done
36162 (gdb)
36163 @end smallexample
36164
36165
36166 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36167 @node GDB/MI Ada Exceptions Commands
36168 @section Ada Exceptions @sc{gdb/mi} Commands
36169
36170 @subheading The @code{-info-ada-exceptions} Command
36171 @findex -info-ada-exceptions
36172
36173 @subsubheading Synopsis
36174
36175 @smallexample
36176 -info-ada-exceptions [ @var{regexp}]
36177 @end smallexample
36178
36179 List all Ada exceptions defined within the program being debugged.
36180 With a regular expression @var{regexp}, only those exceptions whose
36181 names match @var{regexp} are listed.
36182
36183 @subsubheading @value{GDBN} Command
36184
36185 The corresponding @value{GDBN} command is @samp{info exceptions}.
36186
36187 @subsubheading Result
36188
36189 The result is a table of Ada exceptions. The following columns are
36190 defined for each exception:
36191
36192 @table @samp
36193 @item name
36194 The name of the exception.
36195
36196 @item address
36197 The address of the exception.
36198
36199 @end table
36200
36201 @subsubheading Example
36202
36203 @smallexample
36204 -info-ada-exceptions aint
36205 ^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
36206 hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
36207 @{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
36208 body=[@{name="constraint_error",address="0x0000000000613da0"@},
36209 @{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
36210 @end smallexample
36211
36212 @subheading Catching Ada Exceptions
36213
36214 The commands describing how to ask @value{GDBN} to stop when a program
36215 raises an exception are described at @ref{Ada Exception GDB/MI
36216 Catchpoint Commands}.
36217
36218
36219 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36220 @node GDB/MI Support Commands
36221 @section @sc{gdb/mi} Support Commands
36222
36223 Since new commands and features get regularly added to @sc{gdb/mi},
36224 some commands are available to help front-ends query the debugger
36225 about support for these capabilities. Similarly, it is also possible
36226 to query @value{GDBN} about target support of certain features.
36227
36228 @subheading The @code{-info-gdb-mi-command} Command
36229 @cindex @code{-info-gdb-mi-command}
36230 @findex -info-gdb-mi-command
36231
36232 @subsubheading Synopsis
36233
36234 @smallexample
36235 -info-gdb-mi-command @var{cmd_name}
36236 @end smallexample
36237
36238 Query support for the @sc{gdb/mi} command named @var{cmd_name}.
36239
36240 Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
36241 is technically not part of the command name (@pxref{GDB/MI Input
36242 Syntax}), and thus should be omitted in @var{cmd_name}. However,
36243 for ease of use, this command also accepts the form with the leading
36244 dash.
36245
36246 @subsubheading @value{GDBN} Command
36247
36248 There is no corresponding @value{GDBN} command.
36249
36250 @subsubheading Result
36251
36252 The result is a tuple. There is currently only one field:
36253
36254 @table @samp
36255 @item exists
36256 This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
36257 @code{"false"} otherwise.
36258
36259 @end table
36260
36261 @subsubheading Example
36262
36263 Here is an example where the @sc{gdb/mi} command does not exist:
36264
36265 @smallexample
36266 -info-gdb-mi-command unsupported-command
36267 ^done,command=@{exists="false"@}
36268 @end smallexample
36269
36270 @noindent
36271 And here is an example where the @sc{gdb/mi} command is known
36272 to the debugger:
36273
36274 @smallexample
36275 -info-gdb-mi-command symbol-list-lines
36276 ^done,command=@{exists="true"@}
36277 @end smallexample
36278
36279 @subheading The @code{-list-features} Command
36280 @findex -list-features
36281 @cindex supported @sc{gdb/mi} features, list
36282
36283 Returns a list of particular features of the MI protocol that
36284 this version of gdb implements. A feature can be a command,
36285 or a new field in an output of some command, or even an
36286 important bugfix. While a frontend can sometimes detect presence
36287 of a feature at runtime, it is easier to perform detection at debugger
36288 startup.
36289
36290 The command returns a list of strings, with each string naming an
36291 available feature. Each returned string is just a name, it does not
36292 have any internal structure. The list of possible feature names
36293 is given below.
36294
36295 Example output:
36296
36297 @smallexample
36298 (gdb) -list-features
36299 ^done,result=["feature1","feature2"]
36300 @end smallexample
36301
36302 The current list of features is:
36303
36304 @ftable @samp
36305 @item frozen-varobjs
36306 Indicates support for the @code{-var-set-frozen} command, as well
36307 as possible presence of the @code{frozen} field in the output
36308 of @code{-varobj-create}.
36309 @item pending-breakpoints
36310 Indicates support for the @option{-f} option to the @code{-break-insert}
36311 command.
36312 @item python
36313 Indicates Python scripting support, Python-based
36314 pretty-printing commands, and possible presence of the
36315 @samp{display_hint} field in the output of @code{-var-list-children}
36316 @item thread-info
36317 Indicates support for the @code{-thread-info} command.
36318 @item data-read-memory-bytes
36319 Indicates support for the @code{-data-read-memory-bytes} and the
36320 @code{-data-write-memory-bytes} commands.
36321 @item breakpoint-notifications
36322 Indicates that changes to breakpoints and breakpoints created via the
36323 CLI will be announced via async records.
36324 @item ada-task-info
36325 Indicates support for the @code{-ada-task-info} command.
36326 @item language-option
36327 Indicates that all @sc{gdb/mi} commands accept the @option{--language}
36328 option (@pxref{Context management}).
36329 @item info-gdb-mi-command
36330 Indicates support for the @code{-info-gdb-mi-command} command.
36331 @item undefined-command-error-code
36332 Indicates support for the "undefined-command" error code in error result
36333 records, produced when trying to execute an undefined @sc{gdb/mi} command
36334 (@pxref{GDB/MI Result Records}).
36335 @item exec-run-start-option
36336 Indicates that the @code{-exec-run} command supports the @option{--start}
36337 option (@pxref{GDB/MI Program Execution}).
36338 @item data-disassemble-a-option
36339 Indicates that the @code{-data-disassemble} command supports the @option{-a}
36340 option (@pxref{GDB/MI Data Manipulation}).
36341 @end ftable
36342
36343 @subheading The @code{-list-target-features} Command
36344 @findex -list-target-features
36345
36346 Returns a list of particular features that are supported by the
36347 target. Those features affect the permitted MI commands, but
36348 unlike the features reported by the @code{-list-features} command, the
36349 features depend on which target GDB is using at the moment. Whenever
36350 a target can change, due to commands such as @code{-target-select},
36351 @code{-target-attach} or @code{-exec-run}, the list of target features
36352 may change, and the frontend should obtain it again.
36353 Example output:
36354
36355 @smallexample
36356 (gdb) -list-target-features
36357 ^done,result=["async"]
36358 @end smallexample
36359
36360 The current list of features is:
36361
36362 @table @samp
36363 @item async
36364 Indicates that the target is capable of asynchronous command
36365 execution, which means that @value{GDBN} will accept further commands
36366 while the target is running.
36367
36368 @item reverse
36369 Indicates that the target is capable of reverse execution.
36370 @xref{Reverse Execution}, for more information.
36371
36372 @end table
36373
36374 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36375 @node GDB/MI Miscellaneous Commands
36376 @section Miscellaneous @sc{gdb/mi} Commands
36377
36378 @c @subheading -gdb-complete
36379
36380 @subheading The @code{-gdb-exit} Command
36381 @findex -gdb-exit
36382
36383 @subsubheading Synopsis
36384
36385 @smallexample
36386 -gdb-exit
36387 @end smallexample
36388
36389 Exit @value{GDBN} immediately.
36390
36391 @subsubheading @value{GDBN} Command
36392
36393 Approximately corresponds to @samp{quit}.
36394
36395 @subsubheading Example
36396
36397 @smallexample
36398 (gdb)
36399 -gdb-exit
36400 ^exit
36401 @end smallexample
36402
36403
36404 @ignore
36405 @subheading The @code{-exec-abort} Command
36406 @findex -exec-abort
36407
36408 @subsubheading Synopsis
36409
36410 @smallexample
36411 -exec-abort
36412 @end smallexample
36413
36414 Kill the inferior running program.
36415
36416 @subsubheading @value{GDBN} Command
36417
36418 The corresponding @value{GDBN} command is @samp{kill}.
36419
36420 @subsubheading Example
36421 N.A.
36422 @end ignore
36423
36424
36425 @subheading The @code{-gdb-set} Command
36426 @findex -gdb-set
36427
36428 @subsubheading Synopsis
36429
36430 @smallexample
36431 -gdb-set
36432 @end smallexample
36433
36434 Set an internal @value{GDBN} variable.
36435 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
36436
36437 @subsubheading @value{GDBN} Command
36438
36439 The corresponding @value{GDBN} command is @samp{set}.
36440
36441 @subsubheading Example
36442
36443 @smallexample
36444 (gdb)
36445 -gdb-set $foo=3
36446 ^done
36447 (gdb)
36448 @end smallexample
36449
36450
36451 @subheading The @code{-gdb-show} Command
36452 @findex -gdb-show
36453
36454 @subsubheading Synopsis
36455
36456 @smallexample
36457 -gdb-show
36458 @end smallexample
36459
36460 Show the current value of a @value{GDBN} variable.
36461
36462 @subsubheading @value{GDBN} Command
36463
36464 The corresponding @value{GDBN} command is @samp{show}.
36465
36466 @subsubheading Example
36467
36468 @smallexample
36469 (gdb)
36470 -gdb-show annotate
36471 ^done,value="0"
36472 (gdb)
36473 @end smallexample
36474
36475 @c @subheading -gdb-source
36476
36477
36478 @subheading The @code{-gdb-version} Command
36479 @findex -gdb-version
36480
36481 @subsubheading Synopsis
36482
36483 @smallexample
36484 -gdb-version
36485 @end smallexample
36486
36487 Show version information for @value{GDBN}. Used mostly in testing.
36488
36489 @subsubheading @value{GDBN} Command
36490
36491 The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
36492 default shows this information when you start an interactive session.
36493
36494 @subsubheading Example
36495
36496 @c This example modifies the actual output from GDB to avoid overfull
36497 @c box in TeX.
36498 @smallexample
36499 (gdb)
36500 -gdb-version
36501 ~GNU gdb 5.2.1
36502 ~Copyright 2000 Free Software Foundation, Inc.
36503 ~GDB is free software, covered by the GNU General Public License, and
36504 ~you are welcome to change it and/or distribute copies of it under
36505 ~ certain conditions.
36506 ~Type "show copying" to see the conditions.
36507 ~There is absolutely no warranty for GDB. Type "show warranty" for
36508 ~ details.
36509 ~This GDB was configured as
36510 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
36511 ^done
36512 (gdb)
36513 @end smallexample
36514
36515 @subheading The @code{-list-thread-groups} Command
36516 @findex -list-thread-groups
36517
36518 @subheading Synopsis
36519
36520 @smallexample
36521 -list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
36522 @end smallexample
36523
36524 Lists thread groups (@pxref{Thread groups}). When a single thread
36525 group is passed as the argument, lists the children of that group.
36526 When several thread group are passed, lists information about those
36527 thread groups. Without any parameters, lists information about all
36528 top-level thread groups.
36529
36530 Normally, thread groups that are being debugged are reported.
36531 With the @samp{--available} option, @value{GDBN} reports thread groups
36532 available on the target.
36533
36534 The output of this command may have either a @samp{threads} result or
36535 a @samp{groups} result. The @samp{thread} result has a list of tuples
36536 as value, with each tuple describing a thread (@pxref{GDB/MI Thread
36537 Information}). The @samp{groups} result has a list of tuples as value,
36538 each tuple describing a thread group. If top-level groups are
36539 requested (that is, no parameter is passed), or when several groups
36540 are passed, the output always has a @samp{groups} result. The format
36541 of the @samp{group} result is described below.
36542
36543 To reduce the number of roundtrips it's possible to list thread groups
36544 together with their children, by passing the @samp{--recurse} option
36545 and the recursion depth. Presently, only recursion depth of 1 is
36546 permitted. If this option is present, then every reported thread group
36547 will also include its children, either as @samp{group} or
36548 @samp{threads} field.
36549
36550 In general, any combination of option and parameters is permitted, with
36551 the following caveats:
36552
36553 @itemize @bullet
36554 @item
36555 When a single thread group is passed, the output will typically
36556 be the @samp{threads} result. Because threads may not contain
36557 anything, the @samp{recurse} option will be ignored.
36558
36559 @item
36560 When the @samp{--available} option is passed, limited information may
36561 be available. In particular, the list of threads of a process might
36562 be inaccessible. Further, specifying specific thread groups might
36563 not give any performance advantage over listing all thread groups.
36564 The frontend should assume that @samp{-list-thread-groups --available}
36565 is always an expensive operation and cache the results.
36566
36567 @end itemize
36568
36569 The @samp{groups} result is a list of tuples, where each tuple may
36570 have the following fields:
36571
36572 @table @code
36573 @item id
36574 Identifier of the thread group. This field is always present.
36575 The identifier is an opaque string; frontends should not try to
36576 convert it to an integer, even though it might look like one.
36577
36578 @item type
36579 The type of the thread group. At present, only @samp{process} is a
36580 valid type.
36581
36582 @item pid
36583 The target-specific process identifier. This field is only present
36584 for thread groups of type @samp{process} and only if the process exists.
36585
36586 @item exit-code
36587 The exit code of this group's last exited thread, formatted in octal.
36588 This field is only present for thread groups of type @samp{process} and
36589 only if the process is not running.
36590
36591 @item num_children
36592 The number of children this thread group has. This field may be
36593 absent for an available thread group.
36594
36595 @item threads
36596 This field has a list of tuples as value, each tuple describing a
36597 thread. It may be present if the @samp{--recurse} option is
36598 specified, and it's actually possible to obtain the threads.
36599
36600 @item cores
36601 This field is a list of integers, each identifying a core that one
36602 thread of the group is running on. This field may be absent if
36603 such information is not available.
36604
36605 @item executable
36606 The name of the executable file that corresponds to this thread group.
36607 The field is only present for thread groups of type @samp{process},
36608 and only if there is a corresponding executable file.
36609
36610 @end table
36611
36612 @subheading Example
36613
36614 @smallexample
36615 (@value{GDBP})
36616 -list-thread-groups
36617 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
36618 -list-thread-groups 17
36619 ^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
36620 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
36621 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
36622 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
36623 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
36624 -list-thread-groups --available
36625 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
36626 -list-thread-groups --available --recurse 1
36627 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36628 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36629 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
36630 -list-thread-groups --available --recurse 1 17 18
36631 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36632 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36633 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
36634 @end smallexample
36635
36636 @subheading The @code{-info-os} Command
36637 @findex -info-os
36638
36639 @subsubheading Synopsis
36640
36641 @smallexample
36642 -info-os [ @var{type} ]
36643 @end smallexample
36644
36645 If no argument is supplied, the command returns a table of available
36646 operating-system-specific information types. If one of these types is
36647 supplied as an argument @var{type}, then the command returns a table
36648 of data of that type.
36649
36650 The types of information available depend on the target operating
36651 system.
36652
36653 @subsubheading @value{GDBN} Command
36654
36655 The corresponding @value{GDBN} command is @samp{info os}.
36656
36657 @subsubheading Example
36658
36659 When run on a @sc{gnu}/Linux system, the output will look something
36660 like this:
36661
36662 @smallexample
36663 (@value{GDBP})
36664 -info-os
36665 ^done,OSDataTable=@{nr_rows="10",nr_cols="3",
36666 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
36667 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
36668 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
36669 body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
36670 col2="CPUs"@},
36671 item=@{col0="files",col1="Listing of all file descriptors",
36672 col2="File descriptors"@},
36673 item=@{col0="modules",col1="Listing of all loaded kernel modules",
36674 col2="Kernel modules"@},
36675 item=@{col0="msg",col1="Listing of all message queues",
36676 col2="Message queues"@},
36677 item=@{col0="processes",col1="Listing of all processes",
36678 col2="Processes"@},
36679 item=@{col0="procgroups",col1="Listing of all process groups",
36680 col2="Process groups"@},
36681 item=@{col0="semaphores",col1="Listing of all semaphores",
36682 col2="Semaphores"@},
36683 item=@{col0="shm",col1="Listing of all shared-memory regions",
36684 col2="Shared-memory regions"@},
36685 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
36686 col2="Sockets"@},
36687 item=@{col0="threads",col1="Listing of all threads",
36688 col2="Threads"@}]
36689 (@value{GDBP})
36690 -info-os processes
36691 ^done,OSDataTable=@{nr_rows="190",nr_cols="4",
36692 hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
36693 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
36694 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
36695 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
36696 body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
36697 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
36698 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
36699 ...
36700 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
36701 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
36702 (@value{GDBP})
36703 @end smallexample
36704
36705 (Note that the MI output here includes a @code{"Title"} column that
36706 does not appear in command-line @code{info os}; this column is useful
36707 for MI clients that want to enumerate the types of data, such as in a
36708 popup menu, but is needless clutter on the command line, and
36709 @code{info os} omits it.)
36710
36711 @subheading The @code{-add-inferior} Command
36712 @findex -add-inferior
36713
36714 @subheading Synopsis
36715
36716 @smallexample
36717 -add-inferior
36718 @end smallexample
36719
36720 Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
36721 inferior is not associated with any executable. Such association may
36722 be established with the @samp{-file-exec-and-symbols} command
36723 (@pxref{GDB/MI File Commands}). The command response has a single
36724 field, @samp{inferior}, whose value is the identifier of the
36725 thread group corresponding to the new inferior.
36726
36727 @subheading Example
36728
36729 @smallexample
36730 (@value{GDBP})
36731 -add-inferior
36732 ^done,inferior="i3"
36733 @end smallexample
36734
36735 @subheading The @code{-interpreter-exec} Command
36736 @findex -interpreter-exec
36737
36738 @subheading Synopsis
36739
36740 @smallexample
36741 -interpreter-exec @var{interpreter} @var{command}
36742 @end smallexample
36743 @anchor{-interpreter-exec}
36744
36745 Execute the specified @var{command} in the given @var{interpreter}.
36746
36747 @subheading @value{GDBN} Command
36748
36749 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
36750
36751 @subheading Example
36752
36753 @smallexample
36754 (gdb)
36755 -interpreter-exec console "break main"
36756 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
36757 &"During symbol reading, bad structure-type format.\n"
36758 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
36759 ^done
36760 (gdb)
36761 @end smallexample
36762
36763 @subheading The @code{-inferior-tty-set} Command
36764 @findex -inferior-tty-set
36765
36766 @subheading Synopsis
36767
36768 @smallexample
36769 -inferior-tty-set /dev/pts/1
36770 @end smallexample
36771
36772 Set terminal for future runs of the program being debugged.
36773
36774 @subheading @value{GDBN} Command
36775
36776 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
36777
36778 @subheading Example
36779
36780 @smallexample
36781 (gdb)
36782 -inferior-tty-set /dev/pts/1
36783 ^done
36784 (gdb)
36785 @end smallexample
36786
36787 @subheading The @code{-inferior-tty-show} Command
36788 @findex -inferior-tty-show
36789
36790 @subheading Synopsis
36791
36792 @smallexample
36793 -inferior-tty-show
36794 @end smallexample
36795
36796 Show terminal for future runs of program being debugged.
36797
36798 @subheading @value{GDBN} Command
36799
36800 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
36801
36802 @subheading Example
36803
36804 @smallexample
36805 (gdb)
36806 -inferior-tty-set /dev/pts/1
36807 ^done
36808 (gdb)
36809 -inferior-tty-show
36810 ^done,inferior_tty_terminal="/dev/pts/1"
36811 (gdb)
36812 @end smallexample
36813
36814 @subheading The @code{-enable-timings} Command
36815 @findex -enable-timings
36816
36817 @subheading Synopsis
36818
36819 @smallexample
36820 -enable-timings [yes | no]
36821 @end smallexample
36822
36823 Toggle the printing of the wallclock, user and system times for an MI
36824 command as a field in its output. This command is to help frontend
36825 developers optimize the performance of their code. No argument is
36826 equivalent to @samp{yes}.
36827
36828 @subheading @value{GDBN} Command
36829
36830 No equivalent.
36831
36832 @subheading Example
36833
36834 @smallexample
36835 (gdb)
36836 -enable-timings
36837 ^done
36838 (gdb)
36839 -break-insert main
36840 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
36841 addr="0x080484ed",func="main",file="myprog.c",
36842 fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
36843 times="0"@},
36844 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
36845 (gdb)
36846 -enable-timings no
36847 ^done
36848 (gdb)
36849 -exec-run
36850 ^running
36851 (gdb)
36852 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
36853 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
36854 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
36855 fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
36856 (gdb)
36857 @end smallexample
36858
36859 @subheading The @code{-complete} Command
36860 @findex -complete
36861
36862 @subheading Synopsis
36863
36864 @smallexample
36865 -complete @var{command}
36866 @end smallexample
36867
36868 Show a list of completions for partially typed CLI @var{command}.
36869
36870 This command is intended for @sc{gdb/mi} frontends that cannot use two separate
36871 CLI and MI channels --- for example: because of lack of PTYs like on Windows or
36872 because @value{GDBN} is used remotely via a SSH connection.
36873
36874 @subheading Result
36875
36876 The result consists of two or three fields:
36877
36878 @table @samp
36879 @item completion
36880 This field contains the completed @var{command}. If @var{command}
36881 has no known completions, this field is omitted.
36882
36883 @item matches
36884 This field contains a (possibly empty) array of matches. It is always present.
36885
36886 @item max_completions_reached
36887 This field contains @code{1} if number of known completions is above
36888 @code{max-completions} limit (@pxref{Completion}), otherwise it contains
36889 @code{0}. It is always present.
36890
36891 @end table
36892
36893 @subheading @value{GDBN} Command
36894
36895 The corresponding @value{GDBN} command is @samp{complete}.
36896
36897 @subheading Example
36898
36899 @smallexample
36900 (gdb)
36901 -complete br
36902 ^done,completion="break",
36903 matches=["break","break-range"],
36904 max_completions_reached="0"
36905 (gdb)
36906 -complete "b ma"
36907 ^done,completion="b ma",
36908 matches=["b madvise","b main"],max_completions_reached="0"
36909 (gdb)
36910 -complete "b push_b"
36911 ^done,completion="b push_back(",
36912 matches=[
36913 "b A::push_back(void*)",
36914 "b std::string::push_back(char)",
36915 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
36916 max_completions_reached="0"
36917 (gdb)
36918 -complete "nonexist"
36919 ^done,matches=[],max_completions_reached="0"
36920 (gdb)
36921
36922 @end smallexample
36923
36924 @node Annotations
36925 @chapter @value{GDBN} Annotations
36926
36927 This chapter describes annotations in @value{GDBN}. Annotations were
36928 designed to interface @value{GDBN} to graphical user interfaces or other
36929 similar programs which want to interact with @value{GDBN} at a
36930 relatively high level.
36931
36932 The annotation mechanism has largely been superseded by @sc{gdb/mi}
36933 (@pxref{GDB/MI}).
36934
36935 @ignore
36936 This is Edition @value{EDITION}, @value{DATE}.
36937 @end ignore
36938
36939 @menu
36940 * Annotations Overview:: What annotations are; the general syntax.
36941 * Server Prefix:: Issuing a command without affecting user state.
36942 * Prompting:: Annotations marking @value{GDBN}'s need for input.
36943 * Errors:: Annotations for error messages.
36944 * Invalidation:: Some annotations describe things now invalid.
36945 * Annotations for Running::
36946 Whether the program is running, how it stopped, etc.
36947 * Source Annotations:: Annotations describing source code.
36948 @end menu
36949
36950 @node Annotations Overview
36951 @section What is an Annotation?
36952 @cindex annotations
36953
36954 Annotations start with a newline character, two @samp{control-z}
36955 characters, and the name of the annotation. If there is no additional
36956 information associated with this annotation, the name of the annotation
36957 is followed immediately by a newline. If there is additional
36958 information, the name of the annotation is followed by a space, the
36959 additional information, and a newline. The additional information
36960 cannot contain newline characters.
36961
36962 Any output not beginning with a newline and two @samp{control-z}
36963 characters denotes literal output from @value{GDBN}. Currently there is
36964 no need for @value{GDBN} to output a newline followed by two
36965 @samp{control-z} characters, but if there was such a need, the
36966 annotations could be extended with an @samp{escape} annotation which
36967 means those three characters as output.
36968
36969 The annotation @var{level}, which is specified using the
36970 @option{--annotate} command line option (@pxref{Mode Options}), controls
36971 how much information @value{GDBN} prints together with its prompt,
36972 values of expressions, source lines, and other types of output. Level 0
36973 is for no annotations, level 1 is for use when @value{GDBN} is run as a
36974 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
36975 for programs that control @value{GDBN}, and level 2 annotations have
36976 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
36977 Interface, annotate, GDB's Obsolete Annotations}).
36978
36979 @table @code
36980 @kindex set annotate
36981 @item set annotate @var{level}
36982 The @value{GDBN} command @code{set annotate} sets the level of
36983 annotations to the specified @var{level}.
36984
36985 @item show annotate
36986 @kindex show annotate
36987 Show the current annotation level.
36988 @end table
36989
36990 This chapter describes level 3 annotations.
36991
36992 A simple example of starting up @value{GDBN} with annotations is:
36993
36994 @smallexample
36995 $ @kbd{gdb --annotate=3}
36996 GNU gdb 6.0
36997 Copyright 2003 Free Software Foundation, Inc.
36998 GDB is free software, covered by the GNU General Public License,
36999 and you are welcome to change it and/or distribute copies of it
37000 under certain conditions.
37001 Type "show copying" to see the conditions.
37002 There is absolutely no warranty for GDB. Type "show warranty"
37003 for details.
37004 This GDB was configured as "i386-pc-linux-gnu"
37005
37006 ^Z^Zpre-prompt
37007 (@value{GDBP})
37008 ^Z^Zprompt
37009 @kbd{quit}
37010
37011 ^Z^Zpost-prompt
37012 $
37013 @end smallexample
37014
37015 Here @samp{quit} is input to @value{GDBN}; the rest is output from
37016 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
37017 denotes a @samp{control-z} character) are annotations; the rest is
37018 output from @value{GDBN}.
37019
37020 @node Server Prefix
37021 @section The Server Prefix
37022 @cindex server prefix
37023
37024 If you prefix a command with @samp{server } then it will not affect
37025 the command history, nor will it affect @value{GDBN}'s notion of which
37026 command to repeat if @key{RET} is pressed on a line by itself. This
37027 means that commands can be run behind a user's back by a front-end in
37028 a transparent manner.
37029
37030 The @code{server } prefix does not affect the recording of values into
37031 the value history; to print a value without recording it into the
37032 value history, use the @code{output} command instead of the
37033 @code{print} command.
37034
37035 Using this prefix also disables confirmation requests
37036 (@pxref{confirmation requests}).
37037
37038 @node Prompting
37039 @section Annotation for @value{GDBN} Input
37040
37041 @cindex annotations for prompts
37042 When @value{GDBN} prompts for input, it annotates this fact so it is possible
37043 to know when to send output, when the output from a given command is
37044 over, etc.
37045
37046 Different kinds of input each have a different @dfn{input type}. Each
37047 input type has three annotations: a @code{pre-} annotation, which
37048 denotes the beginning of any prompt which is being output, a plain
37049 annotation, which denotes the end of the prompt, and then a @code{post-}
37050 annotation which denotes the end of any echo which may (or may not) be
37051 associated with the input. For example, the @code{prompt} input type
37052 features the following annotations:
37053
37054 @smallexample
37055 ^Z^Zpre-prompt
37056 ^Z^Zprompt
37057 ^Z^Zpost-prompt
37058 @end smallexample
37059
37060 The input types are
37061
37062 @table @code
37063 @findex pre-prompt annotation
37064 @findex prompt annotation
37065 @findex post-prompt annotation
37066 @item prompt
37067 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
37068
37069 @findex pre-commands annotation
37070 @findex commands annotation
37071 @findex post-commands annotation
37072 @item commands
37073 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
37074 command. The annotations are repeated for each command which is input.
37075
37076 @findex pre-overload-choice annotation
37077 @findex overload-choice annotation
37078 @findex post-overload-choice annotation
37079 @item overload-choice
37080 When @value{GDBN} wants the user to select between various overloaded functions.
37081
37082 @findex pre-query annotation
37083 @findex query annotation
37084 @findex post-query annotation
37085 @item query
37086 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
37087
37088 @findex pre-prompt-for-continue annotation
37089 @findex prompt-for-continue annotation
37090 @findex post-prompt-for-continue annotation
37091 @item prompt-for-continue
37092 When @value{GDBN} is asking the user to press return to continue. Note: Don't
37093 expect this to work well; instead use @code{set height 0} to disable
37094 prompting. This is because the counting of lines is buggy in the
37095 presence of annotations.
37096 @end table
37097
37098 @node Errors
37099 @section Errors
37100 @cindex annotations for errors, warnings and interrupts
37101
37102 @findex quit annotation
37103 @smallexample
37104 ^Z^Zquit
37105 @end smallexample
37106
37107 This annotation occurs right before @value{GDBN} responds to an interrupt.
37108
37109 @findex error annotation
37110 @smallexample
37111 ^Z^Zerror
37112 @end smallexample
37113
37114 This annotation occurs right before @value{GDBN} responds to an error.
37115
37116 Quit and error annotations indicate that any annotations which @value{GDBN} was
37117 in the middle of may end abruptly. For example, if a
37118 @code{value-history-begin} annotation is followed by a @code{error}, one
37119 cannot expect to receive the matching @code{value-history-end}. One
37120 cannot expect not to receive it either, however; an error annotation
37121 does not necessarily mean that @value{GDBN} is immediately returning all the way
37122 to the top level.
37123
37124 @findex error-begin annotation
37125 A quit or error annotation may be preceded by
37126
37127 @smallexample
37128 ^Z^Zerror-begin
37129 @end smallexample
37130
37131 Any output between that and the quit or error annotation is the error
37132 message.
37133
37134 Warning messages are not yet annotated.
37135 @c If we want to change that, need to fix warning(), type_error(),
37136 @c range_error(), and possibly other places.
37137
37138 @node Invalidation
37139 @section Invalidation Notices
37140
37141 @cindex annotations for invalidation messages
37142 The following annotations say that certain pieces of state may have
37143 changed.
37144
37145 @table @code
37146 @findex frames-invalid annotation
37147 @item ^Z^Zframes-invalid
37148
37149 The frames (for example, output from the @code{backtrace} command) may
37150 have changed.
37151
37152 @findex breakpoints-invalid annotation
37153 @item ^Z^Zbreakpoints-invalid
37154
37155 The breakpoints may have changed. For example, the user just added or
37156 deleted a breakpoint.
37157 @end table
37158
37159 @node Annotations for Running
37160 @section Running the Program
37161 @cindex annotations for running programs
37162
37163 @findex starting annotation
37164 @findex stopping annotation
37165 When the program starts executing due to a @value{GDBN} command such as
37166 @code{step} or @code{continue},
37167
37168 @smallexample
37169 ^Z^Zstarting
37170 @end smallexample
37171
37172 is output. When the program stops,
37173
37174 @smallexample
37175 ^Z^Zstopped
37176 @end smallexample
37177
37178 is output. Before the @code{stopped} annotation, a variety of
37179 annotations describe how the program stopped.
37180
37181 @table @code
37182 @findex exited annotation
37183 @item ^Z^Zexited @var{exit-status}
37184 The program exited, and @var{exit-status} is the exit status (zero for
37185 successful exit, otherwise nonzero).
37186
37187 @findex signalled annotation
37188 @findex signal-name annotation
37189 @findex signal-name-end annotation
37190 @findex signal-string annotation
37191 @findex signal-string-end annotation
37192 @item ^Z^Zsignalled
37193 The program exited with a signal. After the @code{^Z^Zsignalled}, the
37194 annotation continues:
37195
37196 @smallexample
37197 @var{intro-text}
37198 ^Z^Zsignal-name
37199 @var{name}
37200 ^Z^Zsignal-name-end
37201 @var{middle-text}
37202 ^Z^Zsignal-string
37203 @var{string}
37204 ^Z^Zsignal-string-end
37205 @var{end-text}
37206 @end smallexample
37207
37208 @noindent
37209 where @var{name} is the name of the signal, such as @code{SIGILL} or
37210 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
37211 as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
37212 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
37213 user's benefit and have no particular format.
37214
37215 @findex signal annotation
37216 @item ^Z^Zsignal
37217 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
37218 just saying that the program received the signal, not that it was
37219 terminated with it.
37220
37221 @findex breakpoint annotation
37222 @item ^Z^Zbreakpoint @var{number}
37223 The program hit breakpoint number @var{number}.
37224
37225 @findex watchpoint annotation
37226 @item ^Z^Zwatchpoint @var{number}
37227 The program hit watchpoint number @var{number}.
37228 @end table
37229
37230 @node Source Annotations
37231 @section Displaying Source
37232 @cindex annotations for source display
37233
37234 @findex source annotation
37235 The following annotation is used instead of displaying source code:
37236
37237 @smallexample
37238 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
37239 @end smallexample
37240
37241 where @var{filename} is an absolute file name indicating which source
37242 file, @var{line} is the line number within that file (where 1 is the
37243 first line in the file), @var{character} is the character position
37244 within the file (where 0 is the first character in the file) (for most
37245 debug formats this will necessarily point to the beginning of a line),
37246 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
37247 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
37248 @var{addr} is the address in the target program associated with the
37249 source which is being displayed. The @var{addr} is in the form @samp{0x}
37250 followed by one or more lowercase hex digits (note that this does not
37251 depend on the language).
37252
37253 @node JIT Interface
37254 @chapter JIT Compilation Interface
37255 @cindex just-in-time compilation
37256 @cindex JIT compilation interface
37257
37258 This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
37259 interface. A JIT compiler is a program or library that generates native
37260 executable code at runtime and executes it, usually in order to achieve good
37261 performance while maintaining platform independence.
37262
37263 Programs that use JIT compilation are normally difficult to debug because
37264 portions of their code are generated at runtime, instead of being loaded from
37265 object files, which is where @value{GDBN} normally finds the program's symbols
37266 and debug information. In order to debug programs that use JIT compilation,
37267 @value{GDBN} has an interface that allows the program to register in-memory
37268 symbol files with @value{GDBN} at runtime.
37269
37270 If you are using @value{GDBN} to debug a program that uses this interface, then
37271 it should work transparently so long as you have not stripped the binary. If
37272 you are developing a JIT compiler, then the interface is documented in the rest
37273 of this chapter. At this time, the only known client of this interface is the
37274 LLVM JIT.
37275
37276 Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
37277 JIT compiler communicates with @value{GDBN} by writing data into a global
37278 variable and calling a function at a well-known symbol. When @value{GDBN}
37279 attaches, it reads a linked list of symbol files from the global variable to
37280 find existing code, and puts a breakpoint in the function so that it can find
37281 out about additional code.
37282
37283 @menu
37284 * Declarations:: Relevant C struct declarations
37285 * Registering Code:: Steps to register code
37286 * Unregistering Code:: Steps to unregister code
37287 * Custom Debug Info:: Emit debug information in a custom format
37288 @end menu
37289
37290 @node Declarations
37291 @section JIT Declarations
37292
37293 These are the relevant struct declarations that a C program should include to
37294 implement the interface:
37295
37296 @smallexample
37297 typedef enum
37298 @{
37299 JIT_NOACTION = 0,
37300 JIT_REGISTER_FN,
37301 JIT_UNREGISTER_FN
37302 @} jit_actions_t;
37303
37304 struct jit_code_entry
37305 @{
37306 struct jit_code_entry *next_entry;
37307 struct jit_code_entry *prev_entry;
37308 const char *symfile_addr;
37309 uint64_t symfile_size;
37310 @};
37311
37312 struct jit_descriptor
37313 @{
37314 uint32_t version;
37315 /* This type should be jit_actions_t, but we use uint32_t
37316 to be explicit about the bitwidth. */
37317 uint32_t action_flag;
37318 struct jit_code_entry *relevant_entry;
37319 struct jit_code_entry *first_entry;
37320 @};
37321
37322 /* GDB puts a breakpoint in this function. */
37323 void __attribute__((noinline)) __jit_debug_register_code() @{ @};
37324
37325 /* Make sure to specify the version statically, because the
37326 debugger may check the version before we can set it. */
37327 struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
37328 @end smallexample
37329
37330 If the JIT is multi-threaded, then it is important that the JIT synchronize any
37331 modifications to this global data properly, which can easily be done by putting
37332 a global mutex around modifications to these structures.
37333
37334 @node Registering Code
37335 @section Registering Code
37336
37337 To register code with @value{GDBN}, the JIT should follow this protocol:
37338
37339 @itemize @bullet
37340 @item
37341 Generate an object file in memory with symbols and other desired debug
37342 information. The file must include the virtual addresses of the sections.
37343
37344 @item
37345 Create a code entry for the file, which gives the start and size of the symbol
37346 file.
37347
37348 @item
37349 Add it to the linked list in the JIT descriptor.
37350
37351 @item
37352 Point the relevant_entry field of the descriptor at the entry.
37353
37354 @item
37355 Set @code{action_flag} to @code{JIT_REGISTER} and call
37356 @code{__jit_debug_register_code}.
37357 @end itemize
37358
37359 When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
37360 @code{relevant_entry} pointer so it doesn't have to walk the list looking for
37361 new code. However, the linked list must still be maintained in order to allow
37362 @value{GDBN} to attach to a running process and still find the symbol files.
37363
37364 @node Unregistering Code
37365 @section Unregistering Code
37366
37367 If code is freed, then the JIT should use the following protocol:
37368
37369 @itemize @bullet
37370 @item
37371 Remove the code entry corresponding to the code from the linked list.
37372
37373 @item
37374 Point the @code{relevant_entry} field of the descriptor at the code entry.
37375
37376 @item
37377 Set @code{action_flag} to @code{JIT_UNREGISTER} and call
37378 @code{__jit_debug_register_code}.
37379 @end itemize
37380
37381 If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
37382 and the JIT will leak the memory used for the associated symbol files.
37383
37384 @node Custom Debug Info
37385 @section Custom Debug Info
37386 @cindex custom JIT debug info
37387 @cindex JIT debug info reader
37388
37389 Generating debug information in platform-native file formats (like ELF
37390 or COFF) may be an overkill for JIT compilers; especially if all the
37391 debug info is used for is displaying a meaningful backtrace. The
37392 issue can be resolved by having the JIT writers decide on a debug info
37393 format and also provide a reader that parses the debug info generated
37394 by the JIT compiler. This section gives a brief overview on writing
37395 such a parser. More specific details can be found in the source file
37396 @file{gdb/jit-reader.in}, which is also installed as a header at
37397 @file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
37398
37399 The reader is implemented as a shared object (so this functionality is
37400 not available on platforms which don't allow loading shared objects at
37401 runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
37402 @code{jit-reader-unload} are provided, to be used to load and unload
37403 the readers from a preconfigured directory. Once loaded, the shared
37404 object is used the parse the debug information emitted by the JIT
37405 compiler.
37406
37407 @menu
37408 * Using JIT Debug Info Readers:: How to use supplied readers correctly
37409 * Writing JIT Debug Info Readers:: Creating a debug-info reader
37410 @end menu
37411
37412 @node Using JIT Debug Info Readers
37413 @subsection Using JIT Debug Info Readers
37414 @kindex jit-reader-load
37415 @kindex jit-reader-unload
37416
37417 Readers can be loaded and unloaded using the @code{jit-reader-load}
37418 and @code{jit-reader-unload} commands.
37419
37420 @table @code
37421 @item jit-reader-load @var{reader}
37422 Load the JIT reader named @var{reader}, which is a shared
37423 object specified as either an absolute or a relative file name. In
37424 the latter case, @value{GDBN} will try to load the reader from a
37425 pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
37426 system (here @var{libdir} is the system library directory, often
37427 @file{/usr/local/lib}).
37428
37429 Only one reader can be active at a time; trying to load a second
37430 reader when one is already loaded will result in @value{GDBN}
37431 reporting an error. A new JIT reader can be loaded by first unloading
37432 the current one using @code{jit-reader-unload} and then invoking
37433 @code{jit-reader-load}.
37434
37435 @item jit-reader-unload
37436 Unload the currently loaded JIT reader.
37437
37438 @end table
37439
37440 @node Writing JIT Debug Info Readers
37441 @subsection Writing JIT Debug Info Readers
37442 @cindex writing JIT debug info readers
37443
37444 As mentioned, a reader is essentially a shared object conforming to a
37445 certain ABI. This ABI is described in @file{jit-reader.h}.
37446
37447 @file{jit-reader.h} defines the structures, macros and functions
37448 required to write a reader. It is installed (along with
37449 @value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
37450 the system include directory.
37451
37452 Readers need to be released under a GPL compatible license. A reader
37453 can be declared as released under such a license by placing the macro
37454 @code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
37455
37456 The entry point for readers is the symbol @code{gdb_init_reader},
37457 which is expected to be a function with the prototype
37458
37459 @findex gdb_init_reader
37460 @smallexample
37461 extern struct gdb_reader_funcs *gdb_init_reader (void);
37462 @end smallexample
37463
37464 @cindex @code{struct gdb_reader_funcs}
37465
37466 @code{struct gdb_reader_funcs} contains a set of pointers to callback
37467 functions. These functions are executed to read the debug info
37468 generated by the JIT compiler (@code{read}), to unwind stack frames
37469 (@code{unwind}) and to create canonical frame IDs
37470 (@code{get_frame_id}). It also has a callback that is called when the
37471 reader is being unloaded (@code{destroy}). The struct looks like this
37472
37473 @smallexample
37474 struct gdb_reader_funcs
37475 @{
37476 /* Must be set to GDB_READER_INTERFACE_VERSION. */
37477 int reader_version;
37478
37479 /* For use by the reader. */
37480 void *priv_data;
37481
37482 gdb_read_debug_info *read;
37483 gdb_unwind_frame *unwind;
37484 gdb_get_frame_id *get_frame_id;
37485 gdb_destroy_reader *destroy;
37486 @};
37487 @end smallexample
37488
37489 @cindex @code{struct gdb_symbol_callbacks}
37490 @cindex @code{struct gdb_unwind_callbacks}
37491
37492 The callbacks are provided with another set of callbacks by
37493 @value{GDBN} to do their job. For @code{read}, these callbacks are
37494 passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
37495 and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
37496 @code{struct gdb_symbol_callbacks} has callbacks to create new object
37497 files and new symbol tables inside those object files. @code{struct
37498 gdb_unwind_callbacks} has callbacks to read registers off the current
37499 frame and to write out the values of the registers in the previous
37500 frame. Both have a callback (@code{target_read}) to read bytes off the
37501 target's address space.
37502
37503 @node In-Process Agent
37504 @chapter In-Process Agent
37505 @cindex debugging agent
37506 The traditional debugging model is conceptually low-speed, but works fine,
37507 because most bugs can be reproduced in debugging-mode execution. However,
37508 as multi-core or many-core processors are becoming mainstream, and
37509 multi-threaded programs become more and more popular, there should be more
37510 and more bugs that only manifest themselves at normal-mode execution, for
37511 example, thread races, because debugger's interference with the program's
37512 timing may conceal the bugs. On the other hand, in some applications,
37513 it is not feasible for the debugger to interrupt the program's execution
37514 long enough for the developer to learn anything helpful about its behavior.
37515 If the program's correctness depends on its real-time behavior, delays
37516 introduced by a debugger might cause the program to fail, even when the
37517 code itself is correct. It is useful to be able to observe the program's
37518 behavior without interrupting it.
37519
37520 Therefore, traditional debugging model is too intrusive to reproduce
37521 some bugs. In order to reduce the interference with the program, we can
37522 reduce the number of operations performed by debugger. The
37523 @dfn{In-Process Agent}, a shared library, is running within the same
37524 process with inferior, and is able to perform some debugging operations
37525 itself. As a result, debugger is only involved when necessary, and
37526 performance of debugging can be improved accordingly. Note that
37527 interference with program can be reduced but can't be removed completely,
37528 because the in-process agent will still stop or slow down the program.
37529
37530 The in-process agent can interpret and execute Agent Expressions
37531 (@pxref{Agent Expressions}) during performing debugging operations. The
37532 agent expressions can be used for different purposes, such as collecting
37533 data in tracepoints, and condition evaluation in breakpoints.
37534
37535 @anchor{Control Agent}
37536 You can control whether the in-process agent is used as an aid for
37537 debugging with the following commands:
37538
37539 @table @code
37540 @kindex set agent on
37541 @item set agent on
37542 Causes the in-process agent to perform some operations on behalf of the
37543 debugger. Just which operations requested by the user will be done
37544 by the in-process agent depends on the its capabilities. For example,
37545 if you request to evaluate breakpoint conditions in the in-process agent,
37546 and the in-process agent has such capability as well, then breakpoint
37547 conditions will be evaluated in the in-process agent.
37548
37549 @kindex set agent off
37550 @item set agent off
37551 Disables execution of debugging operations by the in-process agent. All
37552 of the operations will be performed by @value{GDBN}.
37553
37554 @kindex show agent
37555 @item show agent
37556 Display the current setting of execution of debugging operations by
37557 the in-process agent.
37558 @end table
37559
37560 @menu
37561 * In-Process Agent Protocol::
37562 @end menu
37563
37564 @node In-Process Agent Protocol
37565 @section In-Process Agent Protocol
37566 @cindex in-process agent protocol
37567
37568 The in-process agent is able to communicate with both @value{GDBN} and
37569 GDBserver (@pxref{In-Process Agent}). This section documents the protocol
37570 used for communications between @value{GDBN} or GDBserver and the IPA.
37571 In general, @value{GDBN} or GDBserver sends commands
37572 (@pxref{IPA Protocol Commands}) and data to in-process agent, and then
37573 in-process agent replies back with the return result of the command, or
37574 some other information. The data sent to in-process agent is composed
37575 of primitive data types, such as 4-byte or 8-byte type, and composite
37576 types, which are called objects (@pxref{IPA Protocol Objects}).
37577
37578 @menu
37579 * IPA Protocol Objects::
37580 * IPA Protocol Commands::
37581 @end menu
37582
37583 @node IPA Protocol Objects
37584 @subsection IPA Protocol Objects
37585 @cindex ipa protocol objects
37586
37587 The commands sent to and results received from agent may contain some
37588 complex data types called @dfn{objects}.
37589
37590 The in-process agent is running on the same machine with @value{GDBN}
37591 or GDBserver, so it doesn't have to handle as much differences between
37592 two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
37593 However, there are still some differences of two ends in two processes:
37594
37595 @enumerate
37596 @item
37597 word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
37598 compiled as a 64-bit executable, while in-process agent is a 32-bit one.
37599 @item
37600 ABI. Some machines may have multiple types of ABI, @value{GDBN} or
37601 GDBserver is compiled with one, and in-process agent is compiled with
37602 the other one.
37603 @end enumerate
37604
37605 Here are the IPA Protocol Objects:
37606
37607 @enumerate
37608 @item
37609 agent expression object. It represents an agent expression
37610 (@pxref{Agent Expressions}).
37611 @anchor{agent expression object}
37612 @item
37613 tracepoint action object. It represents a tracepoint action
37614 (@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
37615 memory, static trace data and to evaluate expression.
37616 @anchor{tracepoint action object}
37617 @item
37618 tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
37619 @anchor{tracepoint object}
37620
37621 @end enumerate
37622
37623 The following table describes important attributes of each IPA protocol
37624 object:
37625
37626 @multitable @columnfractions .30 .20 .50
37627 @headitem Name @tab Size @tab Description
37628 @item @emph{agent expression object} @tab @tab
37629 @item length @tab 4 @tab length of bytes code
37630 @item byte code @tab @var{length} @tab contents of byte code
37631 @item @emph{tracepoint action for collecting memory} @tab @tab
37632 @item 'M' @tab 1 @tab type of tracepoint action
37633 @item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
37634 address of the lowest byte to collect, otherwise @var{addr} is the offset
37635 of @var{basereg} for memory collecting.
37636 @item len @tab 8 @tab length of memory for collecting
37637 @item basereg @tab 4 @tab the register number containing the starting
37638 memory address for collecting.
37639 @item @emph{tracepoint action for collecting registers} @tab @tab
37640 @item 'R' @tab 1 @tab type of tracepoint action
37641 @item @emph{tracepoint action for collecting static trace data} @tab @tab
37642 @item 'L' @tab 1 @tab type of tracepoint action
37643 @item @emph{tracepoint action for expression evaluation} @tab @tab
37644 @item 'X' @tab 1 @tab type of tracepoint action
37645 @item agent expression @tab length of @tab @ref{agent expression object}
37646 @item @emph{tracepoint object} @tab @tab
37647 @item number @tab 4 @tab number of tracepoint
37648 @item address @tab 8 @tab address of tracepoint inserted on
37649 @item type @tab 4 @tab type of tracepoint
37650 @item enabled @tab 1 @tab enable or disable of tracepoint
37651 @item step_count @tab 8 @tab step
37652 @item pass_count @tab 8 @tab pass
37653 @item numactions @tab 4 @tab number of tracepoint actions
37654 @item hit count @tab 8 @tab hit count
37655 @item trace frame usage @tab 8 @tab trace frame usage
37656 @item compiled_cond @tab 8 @tab compiled condition
37657 @item orig_size @tab 8 @tab orig size
37658 @item condition @tab 4 if condition is NULL otherwise length of
37659 @ref{agent expression object}
37660 @tab zero if condition is NULL, otherwise is
37661 @ref{agent expression object}
37662 @item actions @tab variable
37663 @tab numactions number of @ref{tracepoint action object}
37664 @end multitable
37665
37666 @node IPA Protocol Commands
37667 @subsection IPA Protocol Commands
37668 @cindex ipa protocol commands
37669
37670 The spaces in each command are delimiters to ease reading this commands
37671 specification. They don't exist in real commands.
37672
37673 @table @samp
37674
37675 @item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
37676 Installs a new fast tracepoint described by @var{tracepoint_object}
37677 (@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
37678 head of @dfn{jumppad}, which is used to jump to data collection routine
37679 in IPA finally.
37680
37681 Replies:
37682 @table @samp
37683 @item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
37684 @var{target_address} is address of tracepoint in the inferior.
37685 The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
37686 @var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
37687 The @var{fjump} contains a sequence of instructions jump to jumppad entry.
37688 The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
37689 @item E @var{NN}
37690 for an error
37691
37692 @end table
37693
37694 @item close
37695 Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
37696 is about to kill inferiors.
37697
37698 @item qTfSTM
37699 @xref{qTfSTM}.
37700 @item qTsSTM
37701 @xref{qTsSTM}.
37702 @item qTSTMat
37703 @xref{qTSTMat}.
37704 @item probe_marker_at:@var{address}
37705 Asks in-process agent to probe the marker at @var{address}.
37706
37707 Replies:
37708 @table @samp
37709 @item E @var{NN}
37710 for an error
37711 @end table
37712 @item unprobe_marker_at:@var{address}
37713 Asks in-process agent to unprobe the marker at @var{address}.
37714 @end table
37715
37716 @node GDB Bugs
37717 @chapter Reporting Bugs in @value{GDBN}
37718 @cindex bugs in @value{GDBN}
37719 @cindex reporting bugs in @value{GDBN}
37720
37721 Your bug reports play an essential role in making @value{GDBN} reliable.
37722
37723 Reporting a bug may help you by bringing a solution to your problem, or it
37724 may not. But in any case the principal function of a bug report is to help
37725 the entire community by making the next version of @value{GDBN} work better. Bug
37726 reports are your contribution to the maintenance of @value{GDBN}.
37727
37728 In order for a bug report to serve its purpose, you must include the
37729 information that enables us to fix the bug.
37730
37731 @menu
37732 * Bug Criteria:: Have you found a bug?
37733 * Bug Reporting:: How to report bugs
37734 @end menu
37735
37736 @node Bug Criteria
37737 @section Have You Found a Bug?
37738 @cindex bug criteria
37739
37740 If you are not sure whether you have found a bug, here are some guidelines:
37741
37742 @itemize @bullet
37743 @cindex fatal signal
37744 @cindex debugger crash
37745 @cindex crash of debugger
37746 @item
37747 If the debugger gets a fatal signal, for any input whatever, that is a
37748 @value{GDBN} bug. Reliable debuggers never crash.
37749
37750 @cindex error on valid input
37751 @item
37752 If @value{GDBN} produces an error message for valid input, that is a
37753 bug. (Note that if you're cross debugging, the problem may also be
37754 somewhere in the connection to the target.)
37755
37756 @cindex invalid input
37757 @item
37758 If @value{GDBN} does not produce an error message for invalid input,
37759 that is a bug. However, you should note that your idea of
37760 ``invalid input'' might be our idea of ``an extension'' or ``support
37761 for traditional practice''.
37762
37763 @item
37764 If you are an experienced user of debugging tools, your suggestions
37765 for improvement of @value{GDBN} are welcome in any case.
37766 @end itemize
37767
37768 @node Bug Reporting
37769 @section How to Report Bugs
37770 @cindex bug reports
37771 @cindex @value{GDBN} bugs, reporting
37772
37773 A number of companies and individuals offer support for @sc{gnu} products.
37774 If you obtained @value{GDBN} from a support organization, we recommend you
37775 contact that organization first.
37776
37777 You can find contact information for many support companies and
37778 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
37779 distribution.
37780 @c should add a web page ref...
37781
37782 @ifset BUGURL
37783 @ifset BUGURL_DEFAULT
37784 In any event, we also recommend that you submit bug reports for
37785 @value{GDBN}. The preferred method is to submit them directly using
37786 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
37787 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
37788 be used.
37789
37790 @strong{Do not send bug reports to @samp{info-gdb}, or to
37791 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
37792 not want to receive bug reports. Those that do have arranged to receive
37793 @samp{bug-gdb}.
37794
37795 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
37796 serves as a repeater. The mailing list and the newsgroup carry exactly
37797 the same messages. Often people think of posting bug reports to the
37798 newsgroup instead of mailing them. This appears to work, but it has one
37799 problem which can be crucial: a newsgroup posting often lacks a mail
37800 path back to the sender. Thus, if we need to ask for more information,
37801 we may be unable to reach you. For this reason, it is better to send
37802 bug reports to the mailing list.
37803 @end ifset
37804 @ifclear BUGURL_DEFAULT
37805 In any event, we also recommend that you submit bug reports for
37806 @value{GDBN} to @value{BUGURL}.
37807 @end ifclear
37808 @end ifset
37809
37810 The fundamental principle of reporting bugs usefully is this:
37811 @strong{report all the facts}. If you are not sure whether to state a
37812 fact or leave it out, state it!
37813
37814 Often people omit facts because they think they know what causes the
37815 problem and assume that some details do not matter. Thus, you might
37816 assume that the name of the variable you use in an example does not matter.
37817 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
37818 stray memory reference which happens to fetch from the location where that
37819 name is stored in memory; perhaps, if the name were different, the contents
37820 of that location would fool the debugger into doing the right thing despite
37821 the bug. Play it safe and give a specific, complete example. That is the
37822 easiest thing for you to do, and the most helpful.
37823
37824 Keep in mind that the purpose of a bug report is to enable us to fix the
37825 bug. It may be that the bug has been reported previously, but neither
37826 you nor we can know that unless your bug report is complete and
37827 self-contained.
37828
37829 Sometimes people give a few sketchy facts and ask, ``Does this ring a
37830 bell?'' Those bug reports are useless, and we urge everyone to
37831 @emph{refuse to respond to them} except to chide the sender to report
37832 bugs properly.
37833
37834 To enable us to fix the bug, you should include all these things:
37835
37836 @itemize @bullet
37837 @item
37838 The version of @value{GDBN}. @value{GDBN} announces it if you start
37839 with no arguments; you can also print it at any time using @code{show
37840 version}.
37841
37842 Without this, we will not know whether there is any point in looking for
37843 the bug in the current version of @value{GDBN}.
37844
37845 @item
37846 The type of machine you are using, and the operating system name and
37847 version number.
37848
37849 @item
37850 The details of the @value{GDBN} build-time configuration.
37851 @value{GDBN} shows these details if you invoke it with the
37852 @option{--configuration} command-line option, or if you type
37853 @code{show configuration} at @value{GDBN}'s prompt.
37854
37855 @item
37856 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
37857 ``@value{GCC}--2.8.1''.
37858
37859 @item
37860 What compiler (and its version) was used to compile the program you are
37861 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
37862 C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
37863 to get this information; for other compilers, see the documentation for
37864 those compilers.
37865
37866 @item
37867 The command arguments you gave the compiler to compile your example and
37868 observe the bug. For example, did you use @samp{-O}? To guarantee
37869 you will not omit something important, list them all. A copy of the
37870 Makefile (or the output from make) is sufficient.
37871
37872 If we were to try to guess the arguments, we would probably guess wrong
37873 and then we might not encounter the bug.
37874
37875 @item
37876 A complete input script, and all necessary source files, that will
37877 reproduce the bug.
37878
37879 @item
37880 A description of what behavior you observe that you believe is
37881 incorrect. For example, ``It gets a fatal signal.''
37882
37883 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
37884 will certainly notice it. But if the bug is incorrect output, we might
37885 not notice unless it is glaringly wrong. You might as well not give us
37886 a chance to make a mistake.
37887
37888 Even if the problem you experience is a fatal signal, you should still
37889 say so explicitly. Suppose something strange is going on, such as, your
37890 copy of @value{GDBN} is out of synch, or you have encountered a bug in
37891 the C library on your system. (This has happened!) Your copy might
37892 crash and ours would not. If you told us to expect a crash, then when
37893 ours fails to crash, we would know that the bug was not happening for
37894 us. If you had not told us to expect a crash, then we would not be able
37895 to draw any conclusion from our observations.
37896
37897 @pindex script
37898 @cindex recording a session script
37899 To collect all this information, you can use a session recording program
37900 such as @command{script}, which is available on many Unix systems.
37901 Just run your @value{GDBN} session inside @command{script} and then
37902 include the @file{typescript} file with your bug report.
37903
37904 Another way to record a @value{GDBN} session is to run @value{GDBN}
37905 inside Emacs and then save the entire buffer to a file.
37906
37907 @item
37908 If you wish to suggest changes to the @value{GDBN} source, send us context
37909 diffs. If you even discuss something in the @value{GDBN} source, refer to
37910 it by context, not by line number.
37911
37912 The line numbers in our development sources will not match those in your
37913 sources. Your line numbers would convey no useful information to us.
37914
37915 @end itemize
37916
37917 Here are some things that are not necessary:
37918
37919 @itemize @bullet
37920 @item
37921 A description of the envelope of the bug.
37922
37923 Often people who encounter a bug spend a lot of time investigating
37924 which changes to the input file will make the bug go away and which
37925 changes will not affect it.
37926
37927 This is often time consuming and not very useful, because the way we
37928 will find the bug is by running a single example under the debugger
37929 with breakpoints, not by pure deduction from a series of examples.
37930 We recommend that you save your time for something else.
37931
37932 Of course, if you can find a simpler example to report @emph{instead}
37933 of the original one, that is a convenience for us. Errors in the
37934 output will be easier to spot, running under the debugger will take
37935 less time, and so on.
37936
37937 However, simplification is not vital; if you do not want to do this,
37938 report the bug anyway and send us the entire test case you used.
37939
37940 @item
37941 A patch for the bug.
37942
37943 A patch for the bug does help us if it is a good one. But do not omit
37944 the necessary information, such as the test case, on the assumption that
37945 a patch is all we need. We might see problems with your patch and decide
37946 to fix the problem another way, or we might not understand it at all.
37947
37948 Sometimes with a program as complicated as @value{GDBN} it is very hard to
37949 construct an example that will make the program follow a certain path
37950 through the code. If you do not send us the example, we will not be able
37951 to construct one, so we will not be able to verify that the bug is fixed.
37952
37953 And if we cannot understand what bug you are trying to fix, or why your
37954 patch should be an improvement, we will not install it. A test case will
37955 help us to understand.
37956
37957 @item
37958 A guess about what the bug is or what it depends on.
37959
37960 Such guesses are usually wrong. Even we cannot guess right about such
37961 things without first using the debugger to find the facts.
37962 @end itemize
37963
37964 @c The readline documentation is distributed with the readline code
37965 @c and consists of the two following files:
37966 @c rluser.texi
37967 @c hsuser.texi
37968 @c Use -I with makeinfo to point to the appropriate directory,
37969 @c environment var TEXINPUTS with TeX.
37970 @ifclear SYSTEM_READLINE
37971 @include rluser.texi
37972 @include hsuser.texi
37973 @end ifclear
37974
37975 @node In Memoriam
37976 @appendix In Memoriam
37977
37978 The @value{GDBN} project mourns the loss of the following long-time
37979 contributors:
37980
37981 @table @code
37982 @item Fred Fish
37983 Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
37984 to Free Software in general. Outside of @value{GDBN}, he was known in
37985 the Amiga world for his series of Fish Disks, and the GeekGadget project.
37986
37987 @item Michael Snyder
37988 Michael was one of the Global Maintainers of the @value{GDBN} project,
37989 with contributions recorded as early as 1996, until 2011. In addition
37990 to his day to day participation, he was a large driving force behind
37991 adding Reverse Debugging to @value{GDBN}.
37992 @end table
37993
37994 Beyond their technical contributions to the project, they were also
37995 enjoyable members of the Free Software Community. We will miss them.
37996
37997 @node Formatting Documentation
37998 @appendix Formatting Documentation
37999
38000 @cindex @value{GDBN} reference card
38001 @cindex reference card
38002 The @value{GDBN} 4 release includes an already-formatted reference card, ready
38003 for printing with PostScript or Ghostscript, in the @file{gdb}
38004 subdirectory of the main source directory@footnote{In
38005 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
38006 release.}. If you can use PostScript or Ghostscript with your printer,
38007 you can print the reference card immediately with @file{refcard.ps}.
38008
38009 The release also includes the source for the reference card. You
38010 can format it, using @TeX{}, by typing:
38011
38012 @smallexample
38013 make refcard.dvi
38014 @end smallexample
38015
38016 The @value{GDBN} reference card is designed to print in @dfn{landscape}
38017 mode on US ``letter'' size paper;
38018 that is, on a sheet 11 inches wide by 8.5 inches
38019 high. You will need to specify this form of printing as an option to
38020 your @sc{dvi} output program.
38021
38022 @cindex documentation
38023
38024 All the documentation for @value{GDBN} comes as part of the machine-readable
38025 distribution. The documentation is written in Texinfo format, which is
38026 a documentation system that uses a single source file to produce both
38027 on-line information and a printed manual. You can use one of the Info
38028 formatting commands to create the on-line version of the documentation
38029 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
38030
38031 @value{GDBN} includes an already formatted copy of the on-line Info
38032 version of this manual in the @file{gdb} subdirectory. The main Info
38033 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
38034 subordinate files matching @samp{gdb.info*} in the same directory. If
38035 necessary, you can print out these files, or read them with any editor;
38036 but they are easier to read using the @code{info} subsystem in @sc{gnu}
38037 Emacs or the standalone @code{info} program, available as part of the
38038 @sc{gnu} Texinfo distribution.
38039
38040 If you want to format these Info files yourself, you need one of the
38041 Info formatting programs, such as @code{texinfo-format-buffer} or
38042 @code{makeinfo}.
38043
38044 If you have @code{makeinfo} installed, and are in the top level
38045 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
38046 version @value{GDBVN}), you can make the Info file by typing:
38047
38048 @smallexample
38049 cd gdb
38050 make gdb.info
38051 @end smallexample
38052
38053 If you want to typeset and print copies of this manual, you need @TeX{},
38054 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
38055 Texinfo definitions file.
38056
38057 @TeX{} is a typesetting program; it does not print files directly, but
38058 produces output files called @sc{dvi} files. To print a typeset
38059 document, you need a program to print @sc{dvi} files. If your system
38060 has @TeX{} installed, chances are it has such a program. The precise
38061 command to use depends on your system; @kbd{lpr -d} is common; another
38062 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
38063 require a file name without any extension or a @samp{.dvi} extension.
38064
38065 @TeX{} also requires a macro definitions file called
38066 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
38067 written in Texinfo format. On its own, @TeX{} cannot either read or
38068 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
38069 and is located in the @file{gdb-@var{version-number}/texinfo}
38070 directory.
38071
38072 If you have @TeX{} and a @sc{dvi} printer program installed, you can
38073 typeset and print this manual. First switch to the @file{gdb}
38074 subdirectory of the main source directory (for example, to
38075 @file{gdb-@value{GDBVN}/gdb}) and type:
38076
38077 @smallexample
38078 make gdb.dvi
38079 @end smallexample
38080
38081 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
38082
38083 @node Installing GDB
38084 @appendix Installing @value{GDBN}
38085 @cindex installation
38086
38087 @menu
38088 * Requirements:: Requirements for building @value{GDBN}
38089 * Running Configure:: Invoking the @value{GDBN} @file{configure} script
38090 * Separate Objdir:: Compiling @value{GDBN} in another directory
38091 * Config Names:: Specifying names for hosts and targets
38092 * Configure Options:: Summary of options for configure
38093 * System-wide configuration:: Having a system-wide init file
38094 @end menu
38095
38096 @node Requirements
38097 @section Requirements for Building @value{GDBN}
38098 @cindex building @value{GDBN}, requirements for
38099
38100 Building @value{GDBN} requires various tools and packages to be available.
38101 Other packages will be used only if they are found.
38102
38103 @heading Tools/Packages Necessary for Building @value{GDBN}
38104 @table @asis
38105 @item C@t{++}11 compiler
38106 @value{GDBN} is written in C@t{++}11. It should be buildable with any
38107 recent C@t{++}11 compiler, e.g.@: GCC.
38108
38109 @item GNU make
38110 @value{GDBN}'s build system relies on features only found in the GNU
38111 make program. Other variants of @code{make} will not work.
38112
38113 @item GMP (The GNU Multiple Precision Arithmetic Library)
38114 @value{GDBN} now uses GMP to perform some of its arithmetics.
38115 This library may be included with your operating system distribution;
38116 if it is not, you can get the latest version from
38117 @url{https://gmplib.org/}. If GMP is installed at an unusual path,
38118 you can use the @option{--with-libgmp-prefix} option to specify
38119 its location.
38120
38121 @end table
38122
38123 @heading Tools/Packages Optional for Building @value{GDBN}
38124 @table @asis
38125 @item Expat
38126 @anchor{Expat}
38127 @value{GDBN} can use the Expat XML parsing library. This library may be
38128 included with your operating system distribution; if it is not, you
38129 can get the latest version from @url{http://expat.sourceforge.net}.
38130 The @file{configure} script will search for this library in several
38131 standard locations; if it is installed in an unusual path, you can
38132 use the @option{--with-libexpat-prefix} option to specify its location.
38133
38134 Expat is used for:
38135
38136 @itemize @bullet
38137 @item
38138 Remote protocol memory maps (@pxref{Memory Map Format})
38139 @item
38140 Target descriptions (@pxref{Target Descriptions})
38141 @item
38142 Remote shared library lists (@xref{Library List Format},
38143 or alternatively @pxref{Library List Format for SVR4 Targets})
38144 @item
38145 MS-Windows shared libraries (@pxref{Shared Libraries})
38146 @item
38147 Traceframe info (@pxref{Traceframe Info Format})
38148 @item
38149 Branch trace (@pxref{Branch Trace Format},
38150 @pxref{Branch Trace Configuration Format})
38151 @end itemize
38152
38153 @item Guile
38154 @value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
38155 default, @value{GDBN} will be compiled if the Guile libraries are
38156 installed and are found by @file{configure}. You can use the
38157 @code{--with-guile} option to request Guile, and pass either the Guile
38158 version number or the file name of the relevant @code{pkg-config}
38159 program to choose a particular version of Guile.
38160
38161 @item iconv
38162 @value{GDBN}'s features related to character sets (@pxref{Character
38163 Sets}) require a functioning @code{iconv} implementation. If you are
38164 on a GNU system, then this is provided by the GNU C Library. Some
38165 other systems also provide a working @code{iconv}.
38166
38167 If @value{GDBN} is using the @code{iconv} program which is installed
38168 in a non-standard place, you will need to tell @value{GDBN} where to
38169 find it. This is done with @option{--with-iconv-bin} which specifies
38170 the directory that contains the @code{iconv} program. This program is
38171 run in order to make a list of the available character sets.
38172
38173 On systems without @code{iconv}, you can install GNU Libiconv. If
38174 Libiconv is installed in a standard place, @value{GDBN} will
38175 automatically use it if it is needed. If you have previously
38176 installed Libiconv in a non-standard place, you can use the
38177 @option{--with-libiconv-prefix} option to @file{configure}.
38178
38179 @value{GDBN}'s top-level @file{configure} and @file{Makefile} will
38180 arrange to build Libiconv if a directory named @file{libiconv} appears
38181 in the top-most source directory. If Libiconv is built this way, and
38182 if the operating system does not provide a suitable @code{iconv}
38183 implementation, then the just-built library will automatically be used
38184 by @value{GDBN}. One easy way to set this up is to download GNU
38185 Libiconv, unpack it inside the top-level directory of the @value{GDBN}
38186 source tree, and then rename the directory holding the Libiconv source
38187 code to @samp{libiconv}.
38188
38189 @item lzma
38190 @value{GDBN} can support debugging sections that are compressed with
38191 the LZMA library. @xref{MiniDebugInfo}. If this library is not
38192 included with your operating system, you can find it in the xz package
38193 at @url{http://tukaani.org/xz/}. If the LZMA library is available in
38194 the usual place, then the @file{configure} script will use it
38195 automatically. If it is installed in an unusual path, you can use the
38196 @option{--with-lzma-prefix} option to specify its location.
38197
38198 @item MPFR
38199 @anchor{MPFR}
38200 @value{GDBN} can use the GNU MPFR multiple-precision floating-point
38201 library. This library may be included with your operating system
38202 distribution; if it is not, you can get the latest version from
38203 @url{http://www.mpfr.org}. The @file{configure} script will search
38204 for this library in several standard locations; if it is installed
38205 in an unusual path, you can use the @option{--with-libmpfr-prefix}
38206 option to specify its location.
38207
38208 GNU MPFR is used to emulate target floating-point arithmetic during
38209 expression evaluation when the target uses different floating-point
38210 formats than the host. If GNU MPFR it is not available, @value{GDBN}
38211 will fall back to using host floating-point arithmetic.
38212
38213 @item Python
38214 @value{GDBN} can be scripted using Python language. @xref{Python}.
38215 By default, @value{GDBN} will be compiled if the Python libraries are
38216 installed and are found by @file{configure}. You can use the
38217 @code{--with-python} option to request Python, and pass either the
38218 file name of the relevant @code{python} executable, or the name of the
38219 directory in which Python is installed, to choose a particular
38220 installation of Python.
38221
38222 @item zlib
38223 @cindex compressed debug sections
38224 @value{GDBN} will use the @samp{zlib} library, if available, to read
38225 compressed debug sections. Some linkers, such as GNU gold, are capable
38226 of producing binaries with compressed debug sections. If @value{GDBN}
38227 is compiled with @samp{zlib}, it will be able to read the debug
38228 information in such binaries.
38229
38230 The @samp{zlib} library is likely included with your operating system
38231 distribution; if it is not, you can get the latest version from
38232 @url{http://zlib.net}.
38233 @end table
38234
38235 @node Running Configure
38236 @section Invoking the @value{GDBN} @file{configure} Script
38237 @cindex configuring @value{GDBN}
38238 @value{GDBN} comes with a @file{configure} script that automates the process
38239 of preparing @value{GDBN} for installation; you can then use @code{make} to
38240 build the @code{gdb} program.
38241 @iftex
38242 @c irrelevant in info file; it's as current as the code it lives with.
38243 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
38244 look at the @file{README} file in the sources; we may have improved the
38245 installation procedures since publishing this manual.}
38246 @end iftex
38247
38248 The @value{GDBN} distribution includes all the source code you need for
38249 @value{GDBN} in a single directory, whose name is usually composed by
38250 appending the version number to @samp{gdb}.
38251
38252 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
38253 @file{gdb-@value{GDBVN}} directory. That directory contains:
38254
38255 @table @code
38256 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
38257 script for configuring @value{GDBN} and all its supporting libraries
38258
38259 @item gdb-@value{GDBVN}/gdb
38260 the source specific to @value{GDBN} itself
38261
38262 @item gdb-@value{GDBVN}/bfd
38263 source for the Binary File Descriptor library
38264
38265 @item gdb-@value{GDBVN}/include
38266 @sc{gnu} include files
38267
38268 @item gdb-@value{GDBVN}/libiberty
38269 source for the @samp{-liberty} free software library
38270
38271 @item gdb-@value{GDBVN}/opcodes
38272 source for the library of opcode tables and disassemblers
38273
38274 @item gdb-@value{GDBVN}/readline
38275 source for the @sc{gnu} command-line interface
38276 @end table
38277
38278 There may be other subdirectories as well.
38279
38280 The simplest way to configure and build @value{GDBN} is to run @file{configure}
38281 from the @file{gdb-@var{version-number}} source directory, which in
38282 this example is the @file{gdb-@value{GDBVN}} directory.
38283
38284 First switch to the @file{gdb-@var{version-number}} source directory
38285 if you are not already in it; then run @file{configure}. Pass the
38286 identifier for the platform on which @value{GDBN} will run as an
38287 argument.
38288
38289 For example:
38290
38291 @smallexample
38292 cd gdb-@value{GDBVN}
38293 ./configure
38294 make
38295 @end smallexample
38296
38297 Running @samp{configure} and then running @code{make} builds the
38298 included supporting libraries, then @code{gdb} itself. The configured
38299 source files, and the binaries, are left in the corresponding source
38300 directories.
38301
38302 @need 750
38303 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
38304 system does not recognize this automatically when you run a different
38305 shell, you may need to run @code{sh} on it explicitly:
38306
38307 @smallexample
38308 sh configure
38309 @end smallexample
38310
38311 You should run the @file{configure} script from the top directory in the
38312 source tree, the @file{gdb-@var{version-number}} directory. If you run
38313 @file{configure} from one of the subdirectories, you will configure only
38314 that subdirectory. That is usually not what you want. In particular,
38315 if you run the first @file{configure} from the @file{gdb} subdirectory
38316 of the @file{gdb-@var{version-number}} directory, you will omit the
38317 configuration of @file{bfd}, @file{readline}, and other sibling
38318 directories of the @file{gdb} subdirectory. This leads to build errors
38319 about missing include files such as @file{bfd/bfd.h}.
38320
38321 You can install @code{@value{GDBN}} anywhere. The best way to do this
38322 is to pass the @code{--prefix} option to @code{configure}, and then
38323 install it with @code{make install}.
38324
38325 @node Separate Objdir
38326 @section Compiling @value{GDBN} in Another Directory
38327
38328 If you want to run @value{GDBN} versions for several host or target machines,
38329 you need a different @code{gdb} compiled for each combination of
38330 host and target. @file{configure} is designed to make this easy by
38331 allowing you to generate each configuration in a separate subdirectory,
38332 rather than in the source directory. If your @code{make} program
38333 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
38334 @code{make} in each of these directories builds the @code{gdb}
38335 program specified there.
38336
38337 To build @code{gdb} in a separate directory, run @file{configure}
38338 with the @samp{--srcdir} option to specify where to find the source.
38339 (You also need to specify a path to find @file{configure}
38340 itself from your working directory. If the path to @file{configure}
38341 would be the same as the argument to @samp{--srcdir}, you can leave out
38342 the @samp{--srcdir} option; it is assumed.)
38343
38344 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
38345 separate directory for a Sun 4 like this:
38346
38347 @smallexample
38348 @group
38349 cd gdb-@value{GDBVN}
38350 mkdir ../gdb-sun4
38351 cd ../gdb-sun4
38352 ../gdb-@value{GDBVN}/configure
38353 make
38354 @end group
38355 @end smallexample
38356
38357 When @file{configure} builds a configuration using a remote source
38358 directory, it creates a tree for the binaries with the same structure
38359 (and using the same names) as the tree under the source directory. In
38360 the example, you'd find the Sun 4 library @file{libiberty.a} in the
38361 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
38362 @file{gdb-sun4/gdb}.
38363
38364 Make sure that your path to the @file{configure} script has just one
38365 instance of @file{gdb} in it. If your path to @file{configure} looks
38366 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
38367 one subdirectory of @value{GDBN}, not the whole package. This leads to
38368 build errors about missing include files such as @file{bfd/bfd.h}.
38369
38370 One popular reason to build several @value{GDBN} configurations in separate
38371 directories is to configure @value{GDBN} for cross-compiling (where
38372 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
38373 programs that run on another machine---the @dfn{target}).
38374 You specify a cross-debugging target by
38375 giving the @samp{--target=@var{target}} option to @file{configure}.
38376
38377 When you run @code{make} to build a program or library, you must run
38378 it in a configured directory---whatever directory you were in when you
38379 called @file{configure} (or one of its subdirectories).
38380
38381 The @code{Makefile} that @file{configure} generates in each source
38382 directory also runs recursively. If you type @code{make} in a source
38383 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
38384 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
38385 will build all the required libraries, and then build GDB.
38386
38387 When you have multiple hosts or targets configured in separate
38388 directories, you can run @code{make} on them in parallel (for example,
38389 if they are NFS-mounted on each of the hosts); they will not interfere
38390 with each other.
38391
38392 @node Config Names
38393 @section Specifying Names for Hosts and Targets
38394
38395 The specifications used for hosts and targets in the @file{configure}
38396 script are based on a three-part naming scheme, but some short predefined
38397 aliases are also supported. The full naming scheme encodes three pieces
38398 of information in the following pattern:
38399
38400 @smallexample
38401 @var{architecture}-@var{vendor}-@var{os}
38402 @end smallexample
38403
38404 For example, you can use the alias @code{sun4} as a @var{host} argument,
38405 or as the value for @var{target} in a @code{--target=@var{target}}
38406 option. The equivalent full name is @samp{sparc-sun-sunos4}.
38407
38408 The @file{configure} script accompanying @value{GDBN} does not provide
38409 any query facility to list all supported host and target names or
38410 aliases. @file{configure} calls the Bourne shell script
38411 @code{config.sub} to map abbreviations to full names; you can read the
38412 script, if you wish, or you can use it to test your guesses on
38413 abbreviations---for example:
38414
38415 @smallexample
38416 % sh config.sub i386-linux
38417 i386-pc-linux-gnu
38418 % sh config.sub alpha-linux
38419 alpha-unknown-linux-gnu
38420 % sh config.sub hp9k700
38421 hppa1.1-hp-hpux
38422 % sh config.sub sun4
38423 sparc-sun-sunos4.1.1
38424 % sh config.sub sun3
38425 m68k-sun-sunos4.1.1
38426 % sh config.sub i986v
38427 Invalid configuration `i986v': machine `i986v' not recognized
38428 @end smallexample
38429
38430 @noindent
38431 @code{config.sub} is also distributed in the @value{GDBN} source
38432 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
38433
38434 @node Configure Options
38435 @section @file{configure} Options
38436
38437 Here is a summary of the @file{configure} options and arguments that
38438 are most often useful for building @value{GDBN}. @file{configure}
38439 also has several other options not listed here. @inforef{Running
38440 configure scripts,,autoconf.info}, for a full
38441 explanation of @file{configure}.
38442
38443 @smallexample
38444 configure @r{[}--help@r{]}
38445 @r{[}--prefix=@var{dir}@r{]}
38446 @r{[}--exec-prefix=@var{dir}@r{]}
38447 @r{[}--srcdir=@var{dirname}@r{]}
38448 @r{[}--target=@var{target}@r{]}
38449 @end smallexample
38450
38451 @noindent
38452 You may introduce options with a single @samp{-} rather than
38453 @samp{--} if you prefer; but you may abbreviate option names if you use
38454 @samp{--}.
38455
38456 @table @code
38457 @item --help
38458 Display a quick summary of how to invoke @file{configure}.
38459
38460 @item --prefix=@var{dir}
38461 Configure the source to install programs and files under directory
38462 @file{@var{dir}}.
38463
38464 @item --exec-prefix=@var{dir}
38465 Configure the source to install programs under directory
38466 @file{@var{dir}}.
38467
38468 @c avoid splitting the warning from the explanation:
38469 @need 2000
38470 @item --srcdir=@var{dirname}
38471 Use this option to make configurations in directories separate from the
38472 @value{GDBN} source directories. Among other things, you can use this to
38473 build (or maintain) several configurations simultaneously, in separate
38474 directories. @file{configure} writes configuration-specific files in
38475 the current directory, but arranges for them to use the source in the
38476 directory @var{dirname}. @file{configure} creates directories under
38477 the working directory in parallel to the source directories below
38478 @var{dirname}.
38479
38480 @item --target=@var{target}
38481 Configure @value{GDBN} for cross-debugging programs running on the specified
38482 @var{target}. Without this option, @value{GDBN} is configured to debug
38483 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
38484
38485 There is no convenient way to generate a list of all available
38486 targets. Also see the @code{--enable-targets} option, below.
38487 @end table
38488
38489 There are many other options that are specific to @value{GDBN}. This
38490 lists just the most common ones; there are some very specialized
38491 options not described here.
38492
38493 @table @code
38494 @item --enable-targets=@r{[}@var{target}@r{]}@dots{}
38495 @itemx --enable-targets=all
38496 Configure @value{GDBN} for cross-debugging programs running on the
38497 specified list of targets. The special value @samp{all} configures
38498 @value{GDBN} for debugging programs running on any target it supports.
38499
38500 @item --with-gdb-datadir=@var{path}
38501 Set the @value{GDBN}-specific data directory. @value{GDBN} will look
38502 here for certain supporting files or scripts. This defaults to the
38503 @file{gdb} subdirectory of @samp{datadir} (which can be set using
38504 @code{--datadir}).
38505
38506 @item --with-relocated-sources=@var{dir}
38507 Sets up the default source path substitution rule so that directory
38508 names recorded in debug information will be automatically adjusted for
38509 any directory under @var{dir}. @var{dir} should be a subdirectory of
38510 @value{GDBN}'s configured prefix, the one mentioned in the
38511 @code{--prefix} or @code{--exec-prefix} options to configure. This
38512 option is useful if GDB is supposed to be moved to a different place
38513 after it is built.
38514
38515 @item --enable-64-bit-bfd
38516 Enable 64-bit support in BFD on 32-bit hosts.
38517
38518 @item --disable-gdbmi
38519 Build @value{GDBN} without the GDB/MI machine interface
38520 (@pxref{GDB/MI}).
38521
38522 @item --enable-tui
38523 Build @value{GDBN} with the text-mode full-screen user interface
38524 (TUI). Requires a curses library (ncurses and cursesX are also
38525 supported).
38526
38527 @item --with-curses
38528 Use the curses library instead of the termcap library, for text-mode
38529 terminal operations.
38530
38531 @item --with-debuginfod
38532 Build @value{GDBN} with libdebuginfod, the debuginfod client library.
38533 Used to automatically fetch source files and separate debug files from
38534 debuginfod servers using the associated executable's build ID. Enabled
38535 by default if libdebuginfod is installed and found at configure time.
38536 debuginfod is packaged with elfutils, starting with version 0.178. You
38537 can get the latest version from `https://sourceware.org/elfutils/'.
38538
38539 @item --with-libunwind-ia64
38540 Use the libunwind library for unwinding function call stack on ia64
38541 target platforms. See http://www.nongnu.org/libunwind/index.html for
38542 details.
38543
38544 @item --with-system-readline
38545 Use the readline library installed on the host, rather than the
38546 library supplied as part of @value{GDBN}. Readline 7 or newer is
38547 required; this is enforced by the build system.
38548
38549 @item --with-system-zlib
38550 Use the zlib library installed on the host, rather than the library
38551 supplied as part of @value{GDBN}.
38552
38553 @item --with-expat
38554 Build @value{GDBN} with Expat, a library for XML parsing. (Done by
38555 default if libexpat is installed and found at configure time.) This
38556 library is used to read XML files supplied with @value{GDBN}. If it
38557 is unavailable, some features, such as remote protocol memory maps,
38558 target descriptions, and shared library lists, that are based on XML
38559 files, will not be available in @value{GDBN}. If your host does not
38560 have libexpat installed, you can get the latest version from
38561 `http://expat.sourceforge.net'.
38562
38563 @item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
38564
38565 Build @value{GDBN} with GNU libiconv, a character set encoding
38566 conversion library. This is not done by default, as on GNU systems
38567 the @code{iconv} that is built in to the C library is sufficient. If
38568 your host does not have a working @code{iconv}, you can get the latest
38569 version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
38570
38571 @value{GDBN}'s build system also supports building GNU libiconv as
38572 part of the overall build. @xref{Requirements}.
38573
38574 @item --with-lzma
38575 Build @value{GDBN} with LZMA, a compression library. (Done by default
38576 if liblzma is installed and found at configure time.) LZMA is used by
38577 @value{GDBN}'s "mini debuginfo" feature, which is only useful on
38578 platforms using the ELF object file format. If your host does not
38579 have liblzma installed, you can get the latest version from
38580 `https://tukaani.org/xz/'.
38581
38582 @item --with-mpfr
38583 Build @value{GDBN} with GNU MPFR, a library for multiple-precision
38584 floating-point computation with correct rounding. (Done by default if
38585 GNU MPFR is installed and found at configure time.) This library is
38586 used to emulate target floating-point arithmetic during expression
38587 evaluation when the target uses different floating-point formats than
38588 the host. If GNU MPFR is not available, @value{GDBN} will fall back
38589 to using host floating-point arithmetic. If your host does not have
38590 GNU MPFR installed, you can get the latest version from
38591 `http://www.mpfr.org'.
38592
38593 @item --with-python@r{[}=@var{python}@r{]}
38594 Build @value{GDBN} with Python scripting support. (Done by default if
38595 libpython is present and found at configure time.) Python makes
38596 @value{GDBN} scripting much more powerful than the restricted CLI
38597 scripting language. If your host does not have Python installed, you
38598 can find it on `http://www.python.org/download/'. The oldest version
38599 of Python supported by GDB is 2.6. The optional argument @var{python}
38600 is used to find the Python headers and libraries. It can be either
38601 the name of a Python executable, or the name of the directory in which
38602 Python is installed.
38603
38604 @item --with-guile[=GUILE]'
38605 Build @value{GDBN} with GNU Guile scripting support. (Done by default
38606 if libguile is present and found at configure time.) If your host
38607 does not have Guile installed, you can find it at
38608 `https://www.gnu.org/software/guile/'. The optional argument GUILE
38609 can be a version number, which will cause @code{configure} to try to
38610 use that version of Guile; or the file name of a @code{pkg-config}
38611 executable, which will be queried to find the information needed to
38612 compile and link against Guile.
38613
38614 @item --without-included-regex
38615 Don't use the regex library included with @value{GDBN} (as part of the
38616 libiberty library). This is the default on hosts with version 2 of
38617 the GNU C library.
38618
38619 @item --with-sysroot=@var{dir}
38620 Use @var{dir} as the default system root directory for libraries whose
38621 file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
38622 @var{dir} can be modified at run time by using the @command{set
38623 sysroot} command.) If @var{dir} is under the @value{GDBN} configured
38624 prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
38625 default system root will be automatically adjusted if and when
38626 @value{GDBN} is moved to a different location.
38627
38628 @item --with-system-gdbinit=@var{file}
38629 Configure @value{GDBN} to automatically load a system-wide init file.
38630 @var{file} should be an absolute file name. If @var{file} is in a
38631 directory under the configured prefix, and @value{GDBN} is moved to
38632 another location after being built, the location of the system-wide
38633 init file will be adjusted accordingly.
38634
38635 @item --with-system-gdbinit-dir=@var{directory}
38636 Configure @value{GDBN} to automatically load init files from a
38637 system-wide directory. @var{directory} should be an absolute directory
38638 name. If @var{directory} is in a directory under the configured
38639 prefix, and @value{GDBN} is moved to another location after being
38640 built, the location of the system-wide init directory will be
38641 adjusted accordingly.
38642
38643 @item --enable-build-warnings
38644 When building the @value{GDBN} sources, ask the compiler to warn about
38645 any code which looks even vaguely suspicious. It passes many
38646 different warning flags, depending on the exact version of the
38647 compiler you are using.
38648
38649 @item --enable-werror
38650 Treat compiler warnings as werrors. It adds the @code{-Werror} flag
38651 to the compiler, which will fail the compilation if the compiler
38652 outputs any warning messages.
38653
38654 @item --enable-ubsan
38655 Enable the GCC undefined behavior sanitizer. This is disabled by
38656 default, but passing @code{--enable-ubsan=yes} or
38657 @code{--enable-ubsan=auto} to @code{configure} will enable it. The
38658 undefined behavior sanitizer checks for C@t{++} undefined behavior.
38659 It has a performance cost, so if you are looking at @value{GDBN}'s
38660 performance, you should disable it. The undefined behavior sanitizer
38661 was first introduced in GCC 4.9.
38662 @end table
38663
38664 @node System-wide configuration
38665 @section System-wide configuration and settings
38666 @cindex system-wide init file
38667
38668 @value{GDBN} can be configured to have a system-wide init file and a
38669 system-wide init file directory; this file and files in that directory
38670 (if they have a recognized file extension) will be read and executed at
38671 startup (@pxref{Startup, , What @value{GDBN} does during startup}).
38672
38673 Here are the corresponding configure options:
38674
38675 @table @code
38676 @item --with-system-gdbinit=@var{file}
38677 Specify that the default location of the system-wide init file is
38678 @var{file}.
38679 @item --with-system-gdbinit-dir=@var{directory}
38680 Specify that the default location of the system-wide init file directory
38681 is @var{directory}.
38682 @end table
38683
38684 If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
38685 they may be subject to relocation. Two possible cases:
38686
38687 @itemize @bullet
38688 @item
38689 If the default location of this init file/directory contains @file{$prefix},
38690 it will be subject to relocation. Suppose that the configure options
38691 are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
38692 if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
38693 init file is looked for as @file{$install/etc/gdbinit} instead of
38694 @file{$prefix/etc/gdbinit}.
38695
38696 @item
38697 By contrast, if the default location does not contain the prefix,
38698 it will not be relocated. E.g.@: if @value{GDBN} has been configured with
38699 @option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
38700 then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
38701 wherever @value{GDBN} is installed.
38702 @end itemize
38703
38704 If the configured location of the system-wide init file (as given by the
38705 @option{--with-system-gdbinit} option at configure time) is in the
38706 data-directory (as specified by @option{--with-gdb-datadir} at configure
38707 time) or in one of its subdirectories, then @value{GDBN} will look for the
38708 system-wide init file in the directory specified by the
38709 @option{--data-directory} command-line option.
38710 Note that the system-wide init file is only read once, during @value{GDBN}
38711 initialization. If the data-directory is changed after @value{GDBN} has
38712 started with the @code{set data-directory} command, the file will not be
38713 reread.
38714
38715 This applies similarly to the system-wide directory specified in
38716 @option{--with-system-gdbinit-dir}.
38717
38718 Any supported scripting language can be used for these init files, as long
38719 as the file extension matches the scripting language. To be interpreted
38720 as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
38721 extension.
38722
38723 @menu
38724 * System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
38725 @end menu
38726
38727 @node System-wide Configuration Scripts
38728 @subsection Installed System-wide Configuration Scripts
38729 @cindex system-wide configuration scripts
38730
38731 The @file{system-gdbinit} directory, located inside the data-directory
38732 (as specified by @option{--with-gdb-datadir} at configure time) contains
38733 a number of scripts which can be used as system-wide init files. To
38734 automatically source those scripts at startup, @value{GDBN} should be
38735 configured with @option{--with-system-gdbinit}. Otherwise, any user
38736 should be able to source them by hand as needed.
38737
38738 The following scripts are currently available:
38739 @itemize @bullet
38740
38741 @item @file{elinos.py}
38742 @pindex elinos.py
38743 @cindex ELinOS system-wide configuration script
38744 This script is useful when debugging a program on an ELinOS target.
38745 It takes advantage of the environment variables defined in a standard
38746 ELinOS environment in order to determine the location of the system
38747 shared libraries, and then sets the @samp{solib-absolute-prefix}
38748 and @samp{solib-search-path} variables appropriately.
38749
38750 @item @file{wrs-linux.py}
38751 @pindex wrs-linux.py
38752 @cindex Wind River Linux system-wide configuration script
38753 This script is useful when debugging a program on a target running
38754 Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
38755 the host-side sysroot used by the target system.
38756
38757 @end itemize
38758
38759 @node Maintenance Commands
38760 @appendix Maintenance Commands
38761 @cindex maintenance commands
38762 @cindex internal commands
38763
38764 In addition to commands intended for @value{GDBN} users, @value{GDBN}
38765 includes a number of commands intended for @value{GDBN} developers,
38766 that are not documented elsewhere in this manual. These commands are
38767 provided here for reference. (For commands that turn on debugging
38768 messages, see @ref{Debugging Output}.)
38769
38770 @table @code
38771 @kindex maint agent
38772 @kindex maint agent-eval
38773 @item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38774 @itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38775 Translate the given @var{expression} into remote agent bytecodes.
38776 This command is useful for debugging the Agent Expression mechanism
38777 (@pxref{Agent Expressions}). The @samp{agent} version produces an
38778 expression useful for data collection, such as by tracepoints, while
38779 @samp{maint agent-eval} produces an expression that evaluates directly
38780 to a result. For instance, a collection expression for @code{globa +
38781 globb} will include bytecodes to record four bytes of memory at each
38782 of the addresses of @code{globa} and @code{globb}, while discarding
38783 the result of the addition, while an evaluation expression will do the
38784 addition and return the sum.
38785 If @code{-at} is given, generate remote agent bytecode for @var{location}.
38786 If not, generate remote agent bytecode for current frame PC address.
38787
38788 @kindex maint agent-printf
38789 @item maint agent-printf @var{format},@var{expr},...
38790 Translate the given format string and list of argument expressions
38791 into remote agent bytecodes and display them as a disassembled list.
38792 This command is useful for debugging the agent version of dynamic
38793 printf (@pxref{Dynamic Printf}).
38794
38795 @kindex maint info breakpoints
38796 @item @anchor{maint info breakpoints}maint info breakpoints
38797 Using the same format as @samp{info breakpoints}, display both the
38798 breakpoints you've set explicitly, and those @value{GDBN} is using for
38799 internal purposes. Internal breakpoints are shown with negative
38800 breakpoint numbers. The type column identifies what kind of breakpoint
38801 is shown:
38802
38803 @table @code
38804 @item breakpoint
38805 Normal, explicitly set breakpoint.
38806
38807 @item watchpoint
38808 Normal, explicitly set watchpoint.
38809
38810 @item longjmp
38811 Internal breakpoint, used to handle correctly stepping through
38812 @code{longjmp} calls.
38813
38814 @item longjmp resume
38815 Internal breakpoint at the target of a @code{longjmp}.
38816
38817 @item until
38818 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
38819
38820 @item finish
38821 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
38822
38823 @item shlib events
38824 Shared library events.
38825
38826 @end table
38827
38828 @kindex maint info btrace
38829 @item maint info btrace
38830 Pint information about raw branch tracing data.
38831
38832 @kindex maint btrace packet-history
38833 @item maint btrace packet-history
38834 Print the raw branch trace packets that are used to compute the
38835 execution history for the @samp{record btrace} command. Both the
38836 information and the format in which it is printed depend on the btrace
38837 recording format.
38838
38839 @table @code
38840 @item bts
38841 For the BTS recording format, print a list of blocks of sequential
38842 code. For each block, the following information is printed:
38843
38844 @table @asis
38845 @item Block number
38846 Newer blocks have higher numbers. The oldest block has number zero.
38847 @item Lowest @samp{PC}
38848 @item Highest @samp{PC}
38849 @end table
38850
38851 @item pt
38852 For the Intel Processor Trace recording format, print a list of
38853 Intel Processor Trace packets. For each packet, the following
38854 information is printed:
38855
38856 @table @asis
38857 @item Packet number
38858 Newer packets have higher numbers. The oldest packet has number zero.
38859 @item Trace offset
38860 The packet's offset in the trace stream.
38861 @item Packet opcode and payload
38862 @end table
38863 @end table
38864
38865 @kindex maint btrace clear-packet-history
38866 @item maint btrace clear-packet-history
38867 Discards the cached packet history printed by the @samp{maint btrace
38868 packet-history} command. The history will be computed again when
38869 needed.
38870
38871 @kindex maint btrace clear
38872 @item maint btrace clear
38873 Discard the branch trace data. The data will be fetched anew and the
38874 branch trace will be recomputed when needed.
38875
38876 This implicitly truncates the branch trace to a single branch trace
38877 buffer. When updating branch trace incrementally, the branch trace
38878 available to @value{GDBN} may be bigger than a single branch trace
38879 buffer.
38880
38881 @kindex maint set btrace pt skip-pad
38882 @item maint set btrace pt skip-pad
38883 @kindex maint show btrace pt skip-pad
38884 @item maint show btrace pt skip-pad
38885 Control whether @value{GDBN} will skip PAD packets when computing the
38886 packet history.
38887
38888 @kindex set displaced-stepping
38889 @kindex show displaced-stepping
38890 @cindex displaced stepping support
38891 @cindex out-of-line single-stepping
38892 @item set displaced-stepping
38893 @itemx show displaced-stepping
38894 Control whether or not @value{GDBN} will do @dfn{displaced stepping}
38895 if the target supports it. Displaced stepping is a way to single-step
38896 over breakpoints without removing them from the inferior, by executing
38897 an out-of-line copy of the instruction that was originally at the
38898 breakpoint location. It is also known as out-of-line single-stepping.
38899
38900 @table @code
38901 @item set displaced-stepping on
38902 If the target architecture supports it, @value{GDBN} will use
38903 displaced stepping to step over breakpoints.
38904
38905 @item set displaced-stepping off
38906 @value{GDBN} will not use displaced stepping to step over breakpoints,
38907 even if such is supported by the target architecture.
38908
38909 @cindex non-stop mode, and @samp{set displaced-stepping}
38910 @item set displaced-stepping auto
38911 This is the default mode. @value{GDBN} will use displaced stepping
38912 only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
38913 architecture supports displaced stepping.
38914 @end table
38915
38916 @kindex maint check-psymtabs
38917 @item maint check-psymtabs
38918 Check the consistency of currently expanded psymtabs versus symtabs.
38919 Use this to check, for example, whether a symbol is in one but not the other.
38920
38921 @kindex maint check-symtabs
38922 @item maint check-symtabs
38923 Check the consistency of currently expanded symtabs.
38924
38925 @kindex maint expand-symtabs
38926 @item maint expand-symtabs [@var{regexp}]
38927 Expand symbol tables.
38928 If @var{regexp} is specified, only expand symbol tables for file
38929 names matching @var{regexp}.
38930
38931 @kindex maint set catch-demangler-crashes
38932 @kindex maint show catch-demangler-crashes
38933 @cindex demangler crashes
38934 @item maint set catch-demangler-crashes [on|off]
38935 @itemx maint show catch-demangler-crashes
38936 Control whether @value{GDBN} should attempt to catch crashes in the
38937 symbol name demangler. The default is to attempt to catch crashes.
38938 If enabled, the first time a crash is caught, a core file is created,
38939 the offending symbol is displayed and the user is presented with the
38940 option to terminate the current session.
38941
38942 @kindex maint cplus first_component
38943 @item maint cplus first_component @var{name}
38944 Print the first C@t{++} class/namespace component of @var{name}.
38945
38946 @kindex maint cplus namespace
38947 @item maint cplus namespace
38948 Print the list of possible C@t{++} namespaces.
38949
38950 @kindex maint deprecate
38951 @kindex maint undeprecate
38952 @cindex deprecated commands
38953 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
38954 @itemx maint undeprecate @var{command}
38955 Deprecate or undeprecate the named @var{command}. Deprecated commands
38956 cause @value{GDBN} to issue a warning when you use them. The optional
38957 argument @var{replacement} says which newer command should be used in
38958 favor of the deprecated one; if it is given, @value{GDBN} will mention
38959 the replacement as part of the warning.
38960
38961 @kindex maint dump-me
38962 @item maint dump-me
38963 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
38964 Cause a fatal signal in the debugger and force it to dump its core.
38965 This is supported only on systems which support aborting a program
38966 with the @code{SIGQUIT} signal.
38967
38968 @kindex maint internal-error
38969 @kindex maint internal-warning
38970 @kindex maint demangler-warning
38971 @cindex demangler crashes
38972 @item maint internal-error @r{[}@var{message-text}@r{]}
38973 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
38974 @itemx maint demangler-warning @r{[}@var{message-text}@r{]}
38975
38976 Cause @value{GDBN} to call the internal function @code{internal_error},
38977 @code{internal_warning} or @code{demangler_warning} and hence behave
38978 as though an internal problem has been detected. In addition to
38979 reporting the internal problem, these functions give the user the
38980 opportunity to either quit @value{GDBN} or (for @code{internal_error}
38981 and @code{internal_warning}) create a core file of the current
38982 @value{GDBN} session.
38983
38984 These commands take an optional parameter @var{message-text} that is
38985 used as the text of the error or warning message.
38986
38987 Here's an example of using @code{internal-error}:
38988
38989 @smallexample
38990 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
38991 @dots{}/maint.c:121: internal-error: testing, 1, 2
38992 A problem internal to GDB has been detected. Further
38993 debugging may prove unreliable.
38994 Quit this debugging session? (y or n) @kbd{n}
38995 Create a core file? (y or n) @kbd{n}
38996 (@value{GDBP})
38997 @end smallexample
38998
38999 @cindex @value{GDBN} internal error
39000 @cindex internal errors, control of @value{GDBN} behavior
39001 @cindex demangler crashes
39002
39003 @kindex maint set internal-error
39004 @kindex maint show internal-error
39005 @kindex maint set internal-warning
39006 @kindex maint show internal-warning
39007 @kindex maint set demangler-warning
39008 @kindex maint show demangler-warning
39009 @item maint set internal-error @var{action} [ask|yes|no]
39010 @itemx maint show internal-error @var{action}
39011 @itemx maint set internal-warning @var{action} [ask|yes|no]
39012 @itemx maint show internal-warning @var{action}
39013 @itemx maint set demangler-warning @var{action} [ask|yes|no]
39014 @itemx maint show demangler-warning @var{action}
39015 When @value{GDBN} reports an internal problem (error or warning) it
39016 gives the user the opportunity to both quit @value{GDBN} and create a
39017 core file of the current @value{GDBN} session. These commands let you
39018 override the default behaviour for each particular @var{action},
39019 described in the table below.
39020
39021 @table @samp
39022 @item quit
39023 You can specify that @value{GDBN} should always (yes) or never (no)
39024 quit. The default is to ask the user what to do.
39025
39026 @item corefile
39027 You can specify that @value{GDBN} should always (yes) or never (no)
39028 create a core file. The default is to ask the user what to do. Note
39029 that there is no @code{corefile} option for @code{demangler-warning}:
39030 demangler warnings always create a core file and this cannot be
39031 disabled.
39032 @end table
39033
39034 @kindex maint packet
39035 @item maint packet @var{text}
39036 If @value{GDBN} is talking to an inferior via the serial protocol,
39037 then this command sends the string @var{text} to the inferior, and
39038 displays the response packet. @value{GDBN} supplies the initial
39039 @samp{$} character, the terminating @samp{#} character, and the
39040 checksum.
39041
39042 @kindex maint print architecture
39043 @item maint print architecture @r{[}@var{file}@r{]}
39044 Print the entire architecture configuration. The optional argument
39045 @var{file} names the file where the output goes.
39046
39047 @kindex maint print c-tdesc
39048 @item maint print c-tdesc @r{[}-single-feature@r{]} @r{[}@var{file}@r{]}
39049 Print the target description (@pxref{Target Descriptions}) as
39050 a C source file. By default, the target description is for the current
39051 target, but if the optional argument @var{file} is provided, that file
39052 is used to produce the description. The @var{file} should be an XML
39053 document, of the form described in @ref{Target Description Format}.
39054 The created source file is built into @value{GDBN} when @value{GDBN} is
39055 built again. This command is used by developers after they add or
39056 modify XML target descriptions.
39057
39058 When the optional flag @samp{-single-feature} is provided then the
39059 target description being processed (either the default, or from
39060 @var{file}) must only contain a single feature. The source file
39061 produced is different in this case.
39062
39063 @kindex maint print xml-tdesc
39064 @item maint print xml-tdesc @r{[}@var{file}@r{]}
39065 Print the target description (@pxref{Target Descriptions}) as an XML
39066 file. By default print the target description for the current target,
39067 but if the optional argument @var{file} is provided, then that file is
39068 read in by GDB and then used to produce the description. The
39069 @var{file} should be an XML document, of the form described in
39070 @ref{Target Description Format}.
39071
39072 @kindex maint check xml-descriptions
39073 @item maint check xml-descriptions @var{dir}
39074 Check that the target descriptions dynamically created by @value{GDBN}
39075 equal the descriptions created from XML files found in @var{dir}.
39076
39077 @anchor{maint check libthread-db}
39078 @kindex maint check libthread-db
39079 @item maint check libthread-db
39080 Run integrity checks on the current inferior's thread debugging
39081 library. This exercises all @code{libthread_db} functionality used by
39082 @value{GDBN} on GNU/Linux systems, and by extension also exercises the
39083 @code{proc_service} functions provided by @value{GDBN} that
39084 @code{libthread_db} uses. Note that parts of the test may be skipped
39085 on some platforms when debugging core files.
39086
39087 @kindex maint print core-file-backed-mappings
39088 @cindex memory address space mappings
39089 @item maint print core-file-backed-mappings
39090 Print the file-backed mappings which were loaded from a core file note.
39091 This output represents state internal to @value{GDBN} and should be
39092 similar to the mappings displayed by the @code{info proc mappings}
39093 command.
39094
39095 @kindex maint print dummy-frames
39096 @item maint print dummy-frames
39097 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
39098
39099 @smallexample
39100 (@value{GDBP}) @kbd{b add}
39101 @dots{}
39102 (@value{GDBP}) @kbd{print add(2,3)}
39103 Breakpoint 2, add (a=2, b=3) at @dots{}
39104 58 return (a + b);
39105 The program being debugged stopped while in a function called from GDB.
39106 @dots{}
39107 (@value{GDBP}) @kbd{maint print dummy-frames}
39108 0xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
39109 (@value{GDBP})
39110 @end smallexample
39111
39112 Takes an optional file parameter.
39113
39114 @kindex maint print registers
39115 @kindex maint print raw-registers
39116 @kindex maint print cooked-registers
39117 @kindex maint print register-groups
39118 @kindex maint print remote-registers
39119 @item maint print registers @r{[}@var{file}@r{]}
39120 @itemx maint print raw-registers @r{[}@var{file}@r{]}
39121 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
39122 @itemx maint print register-groups @r{[}@var{file}@r{]}
39123 @itemx maint print remote-registers @r{[}@var{file}@r{]}
39124 Print @value{GDBN}'s internal register data structures.
39125
39126 The command @code{maint print raw-registers} includes the contents of
39127 the raw register cache; the command @code{maint print
39128 cooked-registers} includes the (cooked) value of all registers,
39129 including registers which aren't available on the target nor visible
39130 to user; the command @code{maint print register-groups} includes the
39131 groups that each register is a member of; and the command @code{maint
39132 print remote-registers} includes the remote target's register numbers
39133 and offsets in the `G' packets.
39134
39135 These commands take an optional parameter, a file name to which to
39136 write the information.
39137
39138 @kindex maint print reggroups
39139 @item maint print reggroups @r{[}@var{file}@r{]}
39140 Print @value{GDBN}'s internal register group data structures. The
39141 optional argument @var{file} tells to what file to write the
39142 information.
39143
39144 The register groups info looks like this:
39145
39146 @smallexample
39147 (@value{GDBP}) @kbd{maint print reggroups}
39148 Group Type
39149 general user
39150 float user
39151 all user
39152 vector user
39153 system user
39154 save internal
39155 restore internal
39156 @end smallexample
39157
39158 @kindex maint flush register-cache
39159 @kindex flushregs
39160 @cindex register cache, flushing
39161 @item maint flush register-cache
39162 @itemx flushregs
39163 Flush the contents of the register cache and as a consequence the
39164 frame cache. This command is useful when debugging issues related to
39165 register fetching, or frame unwinding. The command @code{flushregs}
39166 is deprecated in favor of @code{maint flush register-cache}.
39167
39168 @kindex maint print objfiles
39169 @cindex info for known object files
39170 @item maint print objfiles @r{[}@var{regexp}@r{]}
39171 Print a dump of all known object files.
39172 If @var{regexp} is specified, only print object files whose names
39173 match @var{regexp}. For each object file, this command prints its name,
39174 address in memory, and all of its psymtabs and symtabs.
39175
39176 @kindex maint print user-registers
39177 @cindex user registers
39178 @item maint print user-registers
39179 List all currently available @dfn{user registers}. User registers
39180 typically provide alternate names for actual hardware registers. They
39181 include the four ``standard'' registers @code{$fp}, @code{$pc},
39182 @code{$sp}, and @code{$ps}. @xref{standard registers}. User
39183 registers can be used in expressions in the same way as the canonical
39184 register names, but only the latter are listed by the @code{info
39185 registers} and @code{maint print registers} commands.
39186
39187 @kindex maint print section-scripts
39188 @cindex info for known .debug_gdb_scripts-loaded scripts
39189 @item maint print section-scripts [@var{regexp}]
39190 Print a dump of scripts specified in the @code{.debug_gdb_section} section.
39191 If @var{regexp} is specified, only print scripts loaded by object files
39192 matching @var{regexp}.
39193 For each script, this command prints its name as specified in the objfile,
39194 and the full path if known.
39195 @xref{dotdebug_gdb_scripts section}.
39196
39197 @kindex maint print statistics
39198 @cindex bcache statistics
39199 @item maint print statistics
39200 This command prints, for each object file in the program, various data
39201 about that object file followed by the byte cache (@dfn{bcache})
39202 statistics for the object file. The objfile data includes the number
39203 of minimal, partial, full, and stabs symbols, the number of types
39204 defined by the objfile, the number of as yet unexpanded psym tables,
39205 the number of line tables and string tables, and the amount of memory
39206 used by the various tables. The bcache statistics include the counts,
39207 sizes, and counts of duplicates of all and unique objects, max,
39208 average, and median entry size, total memory used and its overhead and
39209 savings, and various measures of the hash table size and chain
39210 lengths.
39211
39212 @kindex maint print target-stack
39213 @cindex target stack description
39214 @item maint print target-stack
39215 A @dfn{target} is an interface between the debugger and a particular
39216 kind of file or process. Targets can be stacked in @dfn{strata},
39217 so that more than one target can potentially respond to a request.
39218 In particular, memory accesses will walk down the stack of targets
39219 until they find a target that is interested in handling that particular
39220 address.
39221
39222 This command prints a short description of each layer that was pushed on
39223 the @dfn{target stack}, starting from the top layer down to the bottom one.
39224
39225 @kindex maint print type
39226 @cindex type chain of a data type
39227 @item maint print type @var{expr}
39228 Print the type chain for a type specified by @var{expr}. The argument
39229 can be either a type name or a symbol. If it is a symbol, the type of
39230 that symbol is described. The type chain produced by this command is
39231 a recursive definition of the data type as stored in @value{GDBN}'s
39232 data structures, including its flags and contained types.
39233
39234 @kindex maint selftest
39235 @cindex self tests
39236 @item maint selftest @r{[}@var{filter}@r{]}
39237 Run any self tests that were compiled in to @value{GDBN}. This will
39238 print a message showing how many tests were run, and how many failed.
39239 If a @var{filter} is passed, only the tests with @var{filter} in their
39240 name will by ran.
39241
39242 @kindex maint info selftests
39243 @cindex self tests
39244 @item maint info selftests
39245 List the selftests compiled in to @value{GDBN}.
39246
39247 @kindex maint set dwarf always-disassemble
39248 @kindex maint show dwarf always-disassemble
39249 @item maint set dwarf always-disassemble
39250 @item maint show dwarf always-disassemble
39251 Control the behavior of @code{info address} when using DWARF debugging
39252 information.
39253
39254 The default is @code{off}, which means that @value{GDBN} should try to
39255 describe a variable's location in an easily readable format. When
39256 @code{on}, @value{GDBN} will instead display the DWARF location
39257 expression in an assembly-like format. Note that some locations are
39258 too complex for @value{GDBN} to describe simply; in this case you will
39259 always see the disassembly form.
39260
39261 Here is an example of the resulting disassembly:
39262
39263 @smallexample
39264 (gdb) info addr argc
39265 Symbol "argc" is a complex DWARF expression:
39266 1: DW_OP_fbreg 0
39267 @end smallexample
39268
39269 For more information on these expressions, see
39270 @uref{http://www.dwarfstd.org/, the DWARF standard}.
39271
39272 @kindex maint set dwarf max-cache-age
39273 @kindex maint show dwarf max-cache-age
39274 @item maint set dwarf max-cache-age
39275 @itemx maint show dwarf max-cache-age
39276 Control the DWARF compilation unit cache.
39277
39278 @cindex DWARF compilation units cache
39279 In object files with inter-compilation-unit references, such as those
39280 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
39281 reader needs to frequently refer to previously read compilation units.
39282 This setting controls how long a compilation unit will remain in the
39283 cache if it is not referenced. A higher limit means that cached
39284 compilation units will be stored in memory longer, and more total
39285 memory will be used. Setting it to zero disables caching, which will
39286 slow down @value{GDBN} startup, but reduce memory consumption.
39287
39288 @kindex maint set dwarf unwinders
39289 @kindex maint show dwarf unwinders
39290 @item maint set dwarf unwinders
39291 @itemx maint show dwarf unwinders
39292 Control use of the DWARF frame unwinders.
39293
39294 @cindex DWARF frame unwinders
39295 Many targets that support DWARF debugging use @value{GDBN}'s DWARF
39296 frame unwinders to build the backtrace. Many of these targets will
39297 also have a second mechanism for building the backtrace for use in
39298 cases where DWARF information is not available, this second mechanism
39299 is often an analysis of a function's prologue.
39300
39301 In order to extend testing coverage of the second level stack
39302 unwinding mechanisms it is helpful to be able to disable the DWARF
39303 stack unwinders, this can be done with this switch.
39304
39305 In normal use of @value{GDBN} disabling the DWARF unwinders is not
39306 advisable, there are cases that are better handled through DWARF than
39307 prologue analysis, and the debug experience is likely to be better
39308 with the DWARF frame unwinders enabled.
39309
39310 If DWARF frame unwinders are not supported for a particular target
39311 architecture, then enabling this flag does not cause them to be used.
39312
39313 @kindex maint set worker-threads
39314 @kindex maint show worker-threads
39315 @item maint set worker-threads
39316 @item maint show worker-threads
39317 Control the number of worker threads that may be used by @value{GDBN}.
39318 On capable hosts, @value{GDBN} may use multiple threads to speed up
39319 certain CPU-intensive operations, such as demangling symbol names.
39320 While the number of threads used by @value{GDBN} may vary, this
39321 command can be used to set an upper bound on this number. The default
39322 is @code{unlimited}, which lets @value{GDBN} choose a reasonable
39323 number. Note that this only controls worker threads started by
39324 @value{GDBN} itself; libraries used by @value{GDBN} may start threads
39325 of their own.
39326
39327 @kindex maint set profile
39328 @kindex maint show profile
39329 @cindex profiling GDB
39330 @item maint set profile
39331 @itemx maint show profile
39332 Control profiling of @value{GDBN}.
39333
39334 Profiling will be disabled until you use the @samp{maint set profile}
39335 command to enable it. When you enable profiling, the system will begin
39336 collecting timing and execution count data; when you disable profiling or
39337 exit @value{GDBN}, the results will be written to a log file. Remember that
39338 if you use profiling, @value{GDBN} will overwrite the profiling log file
39339 (often called @file{gmon.out}). If you have a record of important profiling
39340 data in a @file{gmon.out} file, be sure to move it to a safe location.
39341
39342 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
39343 compiled with the @samp{-pg} compiler option.
39344
39345 @kindex maint set show-debug-regs
39346 @kindex maint show show-debug-regs
39347 @cindex hardware debug registers
39348 @item maint set show-debug-regs
39349 @itemx maint show show-debug-regs
39350 Control whether to show variables that mirror the hardware debug
39351 registers. Use @code{on} to enable, @code{off} to disable. If
39352 enabled, the debug registers values are shown when @value{GDBN} inserts or
39353 removes a hardware breakpoint or watchpoint, and when the inferior
39354 triggers a hardware-assisted breakpoint or watchpoint.
39355
39356 @kindex maint set show-all-tib
39357 @kindex maint show show-all-tib
39358 @item maint set show-all-tib
39359 @itemx maint show show-all-tib
39360 Control whether to show all non zero areas within a 1k block starting
39361 at thread local base, when using the @samp{info w32 thread-information-block}
39362 command.
39363
39364 @kindex maint set target-async
39365 @kindex maint show target-async
39366 @item maint set target-async
39367 @itemx maint show target-async
39368 This controls whether @value{GDBN} targets operate in synchronous or
39369 asynchronous mode (@pxref{Background Execution}). Normally the
39370 default is asynchronous, if it is available; but this can be changed
39371 to more easily debug problems occurring only in synchronous mode.
39372
39373 @kindex maint set target-non-stop @var{mode} [on|off|auto]
39374 @kindex maint show target-non-stop
39375 @item maint set target-non-stop
39376 @itemx maint show target-non-stop
39377
39378 This controls whether @value{GDBN} targets always operate in non-stop
39379 mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
39380 Mode}). The default is @code{auto}, meaning non-stop mode is enabled
39381 if supported by the target.
39382
39383 @table @code
39384 @item maint set target-non-stop auto
39385 This is the default mode. @value{GDBN} controls the target in
39386 non-stop mode if the target supports it.
39387
39388 @item maint set target-non-stop on
39389 @value{GDBN} controls the target in non-stop mode even if the target
39390 does not indicate support.
39391
39392 @item maint set target-non-stop off
39393 @value{GDBN} does not control the target in non-stop mode even if the
39394 target supports it.
39395 @end table
39396
39397 @kindex maint set tui-resize-message
39398 @kindex maint show tui-resize-message
39399 @item maint set tui-resize-message
39400 @item maint show tui-resize-message
39401 Control whether @value{GDBN} displays a message each time the terminal
39402 is resized when in TUI mode. The default is @code{off}, which means
39403 that @value{GDBN} is silent during resizes. When @code{on},
39404 @value{GDBN} will display a message after a resize is completed; the
39405 message will include a number indicating how many times the terminal
39406 has been resized. This setting is intended for use by the test suite,
39407 where it would otherwise be difficult to determine when a resize and
39408 refresh has been completed.
39409
39410 @kindex maint set per-command
39411 @kindex maint show per-command
39412 @item maint set per-command
39413 @itemx maint show per-command
39414 @cindex resources used by commands
39415
39416 @value{GDBN} can display the resources used by each command.
39417 This is useful in debugging performance problems.
39418
39419 @table @code
39420 @item maint set per-command space [on|off]
39421 @itemx maint show per-command space
39422 Enable or disable the printing of the memory used by GDB for each command.
39423 If enabled, @value{GDBN} will display how much memory each command
39424 took, following the command's own output.
39425 This can also be requested by invoking @value{GDBN} with the
39426 @option{--statistics} command-line switch (@pxref{Mode Options}).
39427
39428 @item maint set per-command time [on|off]
39429 @itemx maint show per-command time
39430 Enable or disable the printing of the execution time of @value{GDBN}
39431 for each command.
39432 If enabled, @value{GDBN} will display how much time it
39433 took to execute each command, following the command's own output.
39434 Both CPU time and wallclock time are printed.
39435 Printing both is useful when trying to determine whether the cost is
39436 CPU or, e.g., disk/network latency.
39437 Note that the CPU time printed is for @value{GDBN} only, it does not include
39438 the execution time of the inferior because there's no mechanism currently
39439 to compute how much time was spent by @value{GDBN} and how much time was
39440 spent by the program been debugged.
39441 This can also be requested by invoking @value{GDBN} with the
39442 @option{--statistics} command-line switch (@pxref{Mode Options}).
39443
39444 @item maint set per-command symtab [on|off]
39445 @itemx maint show per-command symtab
39446 Enable or disable the printing of basic symbol table statistics
39447 for each command.
39448 If enabled, @value{GDBN} will display the following information:
39449
39450 @enumerate a
39451 @item
39452 number of symbol tables
39453 @item
39454 number of primary symbol tables
39455 @item
39456 number of blocks in the blockvector
39457 @end enumerate
39458 @end table
39459
39460 @kindex maint set check-libthread-db
39461 @kindex maint show check-libthread-db
39462 @item maint set check-libthread-db [on|off]
39463 @itemx maint show check-libthread-db
39464 Control whether @value{GDBN} should run integrity checks on inferior
39465 specific thread debugging libraries as they are loaded. The default
39466 is not to perform such checks. If any check fails @value{GDBN} will
39467 unload the library and continue searching for a suitable candidate as
39468 described in @ref{set libthread-db-search-path}. For more information
39469 about the tests, see @ref{maint check libthread-db}.
39470
39471 @kindex maint space
39472 @cindex memory used by commands
39473 @item maint space @var{value}
39474 An alias for @code{maint set per-command space}.
39475 A non-zero value enables it, zero disables it.
39476
39477 @kindex maint time
39478 @cindex time of command execution
39479 @item maint time @var{value}
39480 An alias for @code{maint set per-command time}.
39481 A non-zero value enables it, zero disables it.
39482
39483 @kindex maint translate-address
39484 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
39485 Find the symbol stored at the location specified by the address
39486 @var{addr} and an optional section name @var{section}. If found,
39487 @value{GDBN} prints the name of the closest symbol and an offset from
39488 the symbol's location to the specified address. This is similar to
39489 the @code{info address} command (@pxref{Symbols}), except that this
39490 command also allows to find symbols in other sections.
39491
39492 If section was not specified, the section in which the symbol was found
39493 is also printed. For dynamically linked executables, the name of
39494 executable or shared library containing the symbol is printed as well.
39495
39496 @kindex maint test-options
39497 @item maint test-options require-delimiter
39498 @itemx maint test-options unknown-is-error
39499 @itemx maint test-options unknown-is-operand
39500 These commands are used by the testsuite to validate the command
39501 options framework. The @code{require-delimiter} variant requires a
39502 double-dash delimiter to indicate end of options. The
39503 @code{unknown-is-error} and @code{unknown-is-operand} do not. The
39504 @code{unknown-is-error} variant throws an error on unknown option,
39505 while @code{unknown-is-operand} treats unknown options as the start of
39506 the command's operands. When run, the commands output the result of
39507 the processed options. When completed, the commands store the
39508 internal result of completion in a variable exposed by the @code{maint
39509 show test-options-completion-result} command.
39510
39511 @kindex maint show test-options-completion-result
39512 @item maint show test-options-completion-result
39513 Shows the result of completing the @code{maint test-options}
39514 subcommands. This is used by the testsuite to validate completion
39515 support in the command options framework.
39516
39517 @kindex maint set test-settings
39518 @kindex maint show test-settings
39519 @item maint set test-settings @var{kind}
39520 @itemx maint show test-settings @var{kind}
39521 These are representative commands for each @var{kind} of setting type
39522 @value{GDBN} supports. They are used by the testsuite for exercising
39523 the settings infrastructure.
39524
39525 @kindex maint with
39526 @item maint with @var{setting} [@var{value}] [-- @var{command}]
39527 Like the @code{with} command, but works with @code{maintenance set}
39528 variables. This is used by the testsuite to exercise the @code{with}
39529 command's infrastructure.
39530
39531 @end table
39532
39533 The following command is useful for non-interactive invocations of
39534 @value{GDBN}, such as in the test suite.
39535
39536 @table @code
39537 @item set watchdog @var{nsec}
39538 @kindex set watchdog
39539 @cindex watchdog timer
39540 @cindex timeout for commands
39541 Set the maximum number of seconds @value{GDBN} will wait for the
39542 target operation to finish. If this time expires, @value{GDBN}
39543 reports and error and the command is aborted.
39544
39545 @item show watchdog
39546 Show the current setting of the target wait timeout.
39547 @end table
39548
39549 @node Remote Protocol
39550 @appendix @value{GDBN} Remote Serial Protocol
39551
39552 @menu
39553 * Overview::
39554 * Packets::
39555 * Stop Reply Packets::
39556 * General Query Packets::
39557 * Architecture-Specific Protocol Details::
39558 * Tracepoint Packets::
39559 * Host I/O Packets::
39560 * Interrupts::
39561 * Notification Packets::
39562 * Remote Non-Stop::
39563 * Packet Acknowledgment::
39564 * Examples::
39565 * File-I/O Remote Protocol Extension::
39566 * Library List Format::
39567 * Library List Format for SVR4 Targets::
39568 * Memory Map Format::
39569 * Thread List Format::
39570 * Traceframe Info Format::
39571 * Branch Trace Format::
39572 * Branch Trace Configuration Format::
39573 @end menu
39574
39575 @node Overview
39576 @section Overview
39577
39578 There may be occasions when you need to know something about the
39579 protocol---for example, if there is only one serial port to your target
39580 machine, you might want your program to do something special if it
39581 recognizes a packet meant for @value{GDBN}.
39582
39583 In the examples below, @samp{->} and @samp{<-} are used to indicate
39584 transmitted and received data, respectively.
39585
39586 @cindex protocol, @value{GDBN} remote serial
39587 @cindex serial protocol, @value{GDBN} remote
39588 @cindex remote serial protocol
39589 All @value{GDBN} commands and responses (other than acknowledgments
39590 and notifications, see @ref{Notification Packets}) are sent as a
39591 @var{packet}. A @var{packet} is introduced with the character
39592 @samp{$}, the actual @var{packet-data}, and the terminating character
39593 @samp{#} followed by a two-digit @var{checksum}:
39594
39595 @smallexample
39596 @code{$}@var{packet-data}@code{#}@var{checksum}
39597 @end smallexample
39598 @noindent
39599
39600 @cindex checksum, for @value{GDBN} remote
39601 @noindent
39602 The two-digit @var{checksum} is computed as the modulo 256 sum of all
39603 characters between the leading @samp{$} and the trailing @samp{#} (an
39604 eight bit unsigned checksum).
39605
39606 Implementors should note that prior to @value{GDBN} 5.0 the protocol
39607 specification also included an optional two-digit @var{sequence-id}:
39608
39609 @smallexample
39610 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
39611 @end smallexample
39612
39613 @cindex sequence-id, for @value{GDBN} remote
39614 @noindent
39615 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
39616 has never output @var{sequence-id}s. Stubs that handle packets added
39617 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
39618
39619 When either the host or the target machine receives a packet, the first
39620 response expected is an acknowledgment: either @samp{+} (to indicate
39621 the package was received correctly) or @samp{-} (to request
39622 retransmission):
39623
39624 @smallexample
39625 -> @code{$}@var{packet-data}@code{#}@var{checksum}
39626 <- @code{+}
39627 @end smallexample
39628 @noindent
39629
39630 The @samp{+}/@samp{-} acknowledgments can be disabled
39631 once a connection is established.
39632 @xref{Packet Acknowledgment}, for details.
39633
39634 The host (@value{GDBN}) sends @var{command}s, and the target (the
39635 debugging stub incorporated in your program) sends a @var{response}. In
39636 the case of step and continue @var{command}s, the response is only sent
39637 when the operation has completed, and the target has again stopped all
39638 threads in all attached processes. This is the default all-stop mode
39639 behavior, but the remote protocol also supports @value{GDBN}'s non-stop
39640 execution mode; see @ref{Remote Non-Stop}, for details.
39641
39642 @var{packet-data} consists of a sequence of characters with the
39643 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
39644 exceptions).
39645
39646 @cindex remote protocol, field separator
39647 Fields within the packet should be separated using @samp{,} @samp{;} or
39648 @samp{:}. Except where otherwise noted all numbers are represented in
39649 @sc{hex} with leading zeros suppressed.
39650
39651 Implementors should note that prior to @value{GDBN} 5.0, the character
39652 @samp{:} could not appear as the third character in a packet (as it
39653 would potentially conflict with the @var{sequence-id}).
39654
39655 @cindex remote protocol, binary data
39656 @anchor{Binary Data}
39657 Binary data in most packets is encoded either as two hexadecimal
39658 digits per byte of binary data. This allowed the traditional remote
39659 protocol to work over connections which were only seven-bit clean.
39660 Some packets designed more recently assume an eight-bit clean
39661 connection, and use a more efficient encoding to send and receive
39662 binary data.
39663
39664 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
39665 as an escape character. Any escaped byte is transmitted as the escape
39666 character followed by the original character XORed with @code{0x20}.
39667 For example, the byte @code{0x7d} would be transmitted as the two
39668 bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
39669 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
39670 @samp{@}}) must always be escaped. Responses sent by the stub
39671 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
39672 is not interpreted as the start of a run-length encoded sequence
39673 (described next).
39674
39675 Response @var{data} can be run-length encoded to save space.
39676 Run-length encoding replaces runs of identical characters with one
39677 instance of the repeated character, followed by a @samp{*} and a
39678 repeat count. The repeat count is itself sent encoded, to avoid
39679 binary characters in @var{data}: a value of @var{n} is sent as
39680 @code{@var{n}+29}. For a repeat count greater or equal to 3, this
39681 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
39682 code 32) for a repeat count of 3. (This is because run-length
39683 encoding starts to win for counts 3 or more.) Thus, for example,
39684 @samp{0* } is a run-length encoding of ``0000'': the space character
39685 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
39686 3}} more times.
39687
39688 The printable characters @samp{#} and @samp{$} or with a numeric value
39689 greater than 126 must not be used. Runs of six repeats (@samp{#}) or
39690 seven repeats (@samp{$}) can be expanded using a repeat count of only
39691 five (@samp{"}). For example, @samp{00000000} can be encoded as
39692 @samp{0*"00}.
39693
39694 The error response returned for some packets includes a two character
39695 error number. That number is not well defined.
39696
39697 @cindex empty response, for unsupported packets
39698 For any @var{command} not supported by the stub, an empty response
39699 (@samp{$#00}) should be returned. That way it is possible to extend the
39700 protocol. A newer @value{GDBN} can tell if a packet is supported based
39701 on that response.
39702
39703 At a minimum, a stub is required to support the @samp{?} command to
39704 tell @value{GDBN} the reason for halting, @samp{g} and @samp{G}
39705 commands for register access, and the @samp{m} and @samp{M} commands
39706 for memory access. Stubs that only control single-threaded targets
39707 can implement run control with the @samp{c} (continue) command, and if
39708 the target architecture supports hardware-assisted single-stepping,
39709 the @samp{s} (step) command. Stubs that support multi-threading
39710 targets should support the @samp{vCont} command. All other commands
39711 are optional.
39712
39713 @node Packets
39714 @section Packets
39715
39716 The following table provides a complete list of all currently defined
39717 @var{command}s and their corresponding response @var{data}.
39718 @xref{File-I/O Remote Protocol Extension}, for details about the File
39719 I/O extension of the remote protocol.
39720
39721 Each packet's description has a template showing the packet's overall
39722 syntax, followed by an explanation of the packet's meaning. We
39723 include spaces in some of the templates for clarity; these are not
39724 part of the packet's syntax. No @value{GDBN} packet uses spaces to
39725 separate its components. For example, a template like @samp{foo
39726 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
39727 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
39728 @var{baz}. @value{GDBN} does not transmit a space character between the
39729 @samp{foo} and the @var{bar}, or between the @var{bar} and the
39730 @var{baz}.
39731
39732 @cindex @var{thread-id}, in remote protocol
39733 @anchor{thread-id syntax}
39734 Several packets and replies include a @var{thread-id} field to identify
39735 a thread. Normally these are positive numbers with a target-specific
39736 interpretation, formatted as big-endian hex strings. A @var{thread-id}
39737 can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
39738 pick any thread.
39739
39740 In addition, the remote protocol supports a multiprocess feature in
39741 which the @var{thread-id} syntax is extended to optionally include both
39742 process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
39743 The @var{pid} (process) and @var{tid} (thread) components each have the
39744 format described above: a positive number with target-specific
39745 interpretation formatted as a big-endian hex string, literal @samp{-1}
39746 to indicate all processes or threads (respectively), or @samp{0} to
39747 indicate an arbitrary process or thread. Specifying just a process, as
39748 @samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
39749 error to specify all processes but a specific thread, such as
39750 @samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
39751 for those packets and replies explicitly documented to include a process
39752 ID, rather than a @var{thread-id}.
39753
39754 The multiprocess @var{thread-id} syntax extensions are only used if both
39755 @value{GDBN} and the stub report support for the @samp{multiprocess}
39756 feature using @samp{qSupported}. @xref{multiprocess extensions}, for
39757 more information.
39758
39759 Note that all packet forms beginning with an upper- or lower-case
39760 letter, other than those described here, are reserved for future use.
39761
39762 Here are the packet descriptions.
39763
39764 @table @samp
39765
39766 @item !
39767 @cindex @samp{!} packet
39768 @anchor{extended mode}
39769 Enable extended mode. In extended mode, the remote server is made
39770 persistent. The @samp{R} packet is used to restart the program being
39771 debugged.
39772
39773 Reply:
39774 @table @samp
39775 @item OK
39776 The remote target both supports and has enabled extended mode.
39777 @end table
39778
39779 @item ?
39780 @cindex @samp{?} packet
39781 @anchor{? packet}
39782 This is sent when connection is first established to query the reason
39783 the target halted. The reply is the same as for step and continue.
39784 This packet has a special interpretation when the target is in
39785 non-stop mode; see @ref{Remote Non-Stop}.
39786
39787 Reply:
39788 @xref{Stop Reply Packets}, for the reply specifications.
39789
39790 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
39791 @cindex @samp{A} packet
39792 Initialized @code{argv[]} array passed into program. @var{arglen}
39793 specifies the number of bytes in the hex encoded byte stream
39794 @var{arg}. See @code{gdbserver} for more details.
39795
39796 Reply:
39797 @table @samp
39798 @item OK
39799 The arguments were set.
39800 @item E @var{NN}
39801 An error occurred.
39802 @end table
39803
39804 @item b @var{baud}
39805 @cindex @samp{b} packet
39806 (Don't use this packet; its behavior is not well-defined.)
39807 Change the serial line speed to @var{baud}.
39808
39809 JTC: @emph{When does the transport layer state change? When it's
39810 received, or after the ACK is transmitted. In either case, there are
39811 problems if the command or the acknowledgment packet is dropped.}
39812
39813 Stan: @emph{If people really wanted to add something like this, and get
39814 it working for the first time, they ought to modify ser-unix.c to send
39815 some kind of out-of-band message to a specially-setup stub and have the
39816 switch happen "in between" packets, so that from remote protocol's point
39817 of view, nothing actually happened.}
39818
39819 @item B @var{addr},@var{mode}
39820 @cindex @samp{B} packet
39821 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
39822 breakpoint at @var{addr}.
39823
39824 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
39825 (@pxref{insert breakpoint or watchpoint packet}).
39826
39827 @cindex @samp{bc} packet
39828 @anchor{bc}
39829 @item bc
39830 Backward continue. Execute the target system in reverse. No parameter.
39831 @xref{Reverse Execution}, for more information.
39832
39833 Reply:
39834 @xref{Stop Reply Packets}, for the reply specifications.
39835
39836 @cindex @samp{bs} packet
39837 @anchor{bs}
39838 @item bs
39839 Backward single step. Execute one instruction in reverse. No parameter.
39840 @xref{Reverse Execution}, for more information.
39841
39842 Reply:
39843 @xref{Stop Reply Packets}, for the reply specifications.
39844
39845 @item c @r{[}@var{addr}@r{]}
39846 @cindex @samp{c} packet
39847 Continue at @var{addr}, which is the address to resume. If @var{addr}
39848 is omitted, resume at current address.
39849
39850 This packet is deprecated for multi-threading support. @xref{vCont
39851 packet}.
39852
39853 Reply:
39854 @xref{Stop Reply Packets}, for the reply specifications.
39855
39856 @item C @var{sig}@r{[};@var{addr}@r{]}
39857 @cindex @samp{C} packet
39858 Continue with signal @var{sig} (hex signal number). If
39859 @samp{;@var{addr}} is omitted, resume at same address.
39860
39861 This packet is deprecated for multi-threading support. @xref{vCont
39862 packet}.
39863
39864 Reply:
39865 @xref{Stop Reply Packets}, for the reply specifications.
39866
39867 @item d
39868 @cindex @samp{d} packet
39869 Toggle debug flag.
39870
39871 Don't use this packet; instead, define a general set packet
39872 (@pxref{General Query Packets}).
39873
39874 @item D
39875 @itemx D;@var{pid}
39876 @cindex @samp{D} packet
39877 The first form of the packet is used to detach @value{GDBN} from the
39878 remote system. It is sent to the remote target
39879 before @value{GDBN} disconnects via the @code{detach} command.
39880
39881 The second form, including a process ID, is used when multiprocess
39882 protocol extensions are enabled (@pxref{multiprocess extensions}), to
39883 detach only a specific process. The @var{pid} is specified as a
39884 big-endian hex string.
39885
39886 Reply:
39887 @table @samp
39888 @item OK
39889 for success
39890 @item E @var{NN}
39891 for an error
39892 @end table
39893
39894 @item F @var{RC},@var{EE},@var{CF};@var{XX}
39895 @cindex @samp{F} packet
39896 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
39897 This is part of the File-I/O protocol extension. @xref{File-I/O
39898 Remote Protocol Extension}, for the specification.
39899
39900 @item g
39901 @anchor{read registers packet}
39902 @cindex @samp{g} packet
39903 Read general registers.
39904
39905 Reply:
39906 @table @samp
39907 @item @var{XX@dots{}}
39908 Each byte of register data is described by two hex digits. The bytes
39909 with the register are transmitted in target byte order. The size of
39910 each register and their position within the @samp{g} packet are
39911 determined by the @value{GDBN} internal gdbarch functions
39912 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
39913
39914 When reading registers from a trace frame (@pxref{Analyze Collected
39915 Data,,Using the Collected Data}), the stub may also return a string of
39916 literal @samp{x}'s in place of the register data digits, to indicate
39917 that the corresponding register has not been collected, thus its value
39918 is unavailable. For example, for an architecture with 4 registers of
39919 4 bytes each, the following reply indicates to @value{GDBN} that
39920 registers 0 and 2 have not been collected, while registers 1 and 3
39921 have been collected, and both have zero value:
39922
39923 @smallexample
39924 -> @code{g}
39925 <- @code{xxxxxxxx00000000xxxxxxxx00000000}
39926 @end smallexample
39927
39928 @item E @var{NN}
39929 for an error.
39930 @end table
39931
39932 @item G @var{XX@dots{}}
39933 @cindex @samp{G} packet
39934 Write general registers. @xref{read registers packet}, for a
39935 description of the @var{XX@dots{}} data.
39936
39937 Reply:
39938 @table @samp
39939 @item OK
39940 for success
39941 @item E @var{NN}
39942 for an error
39943 @end table
39944
39945 @item H @var{op} @var{thread-id}
39946 @cindex @samp{H} packet
39947 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
39948 @samp{G}, et.al.). Depending on the operation to be performed, @var{op}
39949 should be @samp{c} for step and continue operations (note that this
39950 is deprecated, supporting the @samp{vCont} command is a better
39951 option), and @samp{g} for other operations. The thread designator
39952 @var{thread-id} has the format and interpretation described in
39953 @ref{thread-id syntax}.
39954
39955 Reply:
39956 @table @samp
39957 @item OK
39958 for success
39959 @item E @var{NN}
39960 for an error
39961 @end table
39962
39963 @c FIXME: JTC:
39964 @c 'H': How restrictive (or permissive) is the thread model. If a
39965 @c thread is selected and stopped, are other threads allowed
39966 @c to continue to execute? As I mentioned above, I think the
39967 @c semantics of each command when a thread is selected must be
39968 @c described. For example:
39969 @c
39970 @c 'g': If the stub supports threads and a specific thread is
39971 @c selected, returns the register block from that thread;
39972 @c otherwise returns current registers.
39973 @c
39974 @c 'G' If the stub supports threads and a specific thread is
39975 @c selected, sets the registers of the register block of
39976 @c that thread; otherwise sets current registers.
39977
39978 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
39979 @anchor{cycle step packet}
39980 @cindex @samp{i} packet
39981 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
39982 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
39983 step starting at that address.
39984
39985 @item I
39986 @cindex @samp{I} packet
39987 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
39988 step packet}.
39989
39990 @item k
39991 @cindex @samp{k} packet
39992 Kill request.
39993
39994 The exact effect of this packet is not specified.
39995
39996 For a bare-metal target, it may power cycle or reset the target
39997 system. For that reason, the @samp{k} packet has no reply.
39998
39999 For a single-process target, it may kill that process if possible.
40000
40001 A multiple-process target may choose to kill just one process, or all
40002 that are under @value{GDBN}'s control. For more precise control, use
40003 the vKill packet (@pxref{vKill packet}).
40004
40005 If the target system immediately closes the connection in response to
40006 @samp{k}, @value{GDBN} does not consider the lack of packet
40007 acknowledgment to be an error, and assumes the kill was successful.
40008
40009 If connected using @kbd{target extended-remote}, and the target does
40010 not close the connection in response to a kill request, @value{GDBN}
40011 probes the target state as if a new connection was opened
40012 (@pxref{? packet}).
40013
40014 @item m @var{addr},@var{length}
40015 @cindex @samp{m} packet
40016 Read @var{length} addressable memory units starting at address @var{addr}
40017 (@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
40018 any particular boundary.
40019
40020 The stub need not use any particular size or alignment when gathering
40021 data from memory for the response; even if @var{addr} is word-aligned
40022 and @var{length} is a multiple of the word size, the stub is free to
40023 use byte accesses, or not. For this reason, this packet may not be
40024 suitable for accessing memory-mapped I/O devices.
40025 @cindex alignment of remote memory accesses
40026 @cindex size of remote memory accesses
40027 @cindex memory, alignment and size of remote accesses
40028
40029 Reply:
40030 @table @samp
40031 @item @var{XX@dots{}}
40032 Memory contents; each byte is transmitted as a two-digit hexadecimal number.
40033 The reply may contain fewer addressable memory units than requested if the
40034 server was able to read only part of the region of memory.
40035 @item E @var{NN}
40036 @var{NN} is errno
40037 @end table
40038
40039 @item M @var{addr},@var{length}:@var{XX@dots{}}
40040 @cindex @samp{M} packet
40041 Write @var{length} addressable memory units starting at address @var{addr}
40042 (@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
40043 byte is transmitted as a two-digit hexadecimal number.
40044
40045 Reply:
40046 @table @samp
40047 @item OK
40048 for success
40049 @item E @var{NN}
40050 for an error (this includes the case where only part of the data was
40051 written).
40052 @end table
40053
40054 @item p @var{n}
40055 @cindex @samp{p} packet
40056 Read the value of register @var{n}; @var{n} is in hex.
40057 @xref{read registers packet}, for a description of how the returned
40058 register value is encoded.
40059
40060 Reply:
40061 @table @samp
40062 @item @var{XX@dots{}}
40063 the register's value
40064 @item E @var{NN}
40065 for an error
40066 @item @w{}
40067 Indicating an unrecognized @var{query}.
40068 @end table
40069
40070 @item P @var{n@dots{}}=@var{r@dots{}}
40071 @anchor{write register packet}
40072 @cindex @samp{P} packet
40073 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
40074 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
40075 digits for each byte in the register (target byte order).
40076
40077 Reply:
40078 @table @samp
40079 @item OK
40080 for success
40081 @item E @var{NN}
40082 for an error
40083 @end table
40084
40085 @item q @var{name} @var{params}@dots{}
40086 @itemx Q @var{name} @var{params}@dots{}
40087 @cindex @samp{q} packet
40088 @cindex @samp{Q} packet
40089 General query (@samp{q}) and set (@samp{Q}). These packets are
40090 described fully in @ref{General Query Packets}.
40091
40092 @item r
40093 @cindex @samp{r} packet
40094 Reset the entire system.
40095
40096 Don't use this packet; use the @samp{R} packet instead.
40097
40098 @item R @var{XX}
40099 @cindex @samp{R} packet
40100 Restart the program being debugged. The @var{XX}, while needed, is ignored.
40101 This packet is only available in extended mode (@pxref{extended mode}).
40102
40103 The @samp{R} packet has no reply.
40104
40105 @item s @r{[}@var{addr}@r{]}
40106 @cindex @samp{s} packet
40107 Single step, resuming at @var{addr}. If
40108 @var{addr} is omitted, resume at same address.
40109
40110 This packet is deprecated for multi-threading support. @xref{vCont
40111 packet}.
40112
40113 Reply:
40114 @xref{Stop Reply Packets}, for the reply specifications.
40115
40116 @item S @var{sig}@r{[};@var{addr}@r{]}
40117 @anchor{step with signal packet}
40118 @cindex @samp{S} packet
40119 Step with signal. This is analogous to the @samp{C} packet, but
40120 requests a single-step, rather than a normal resumption of execution.
40121
40122 This packet is deprecated for multi-threading support. @xref{vCont
40123 packet}.
40124
40125 Reply:
40126 @xref{Stop Reply Packets}, for the reply specifications.
40127
40128 @item t @var{addr}:@var{PP},@var{MM}
40129 @cindex @samp{t} packet
40130 Search backwards starting at address @var{addr} for a match with pattern
40131 @var{PP} and mask @var{MM}, both of which are are 4 byte long.
40132 There must be at least 3 digits in @var{addr}.
40133
40134 @item T @var{thread-id}
40135 @cindex @samp{T} packet
40136 Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
40137
40138 Reply:
40139 @table @samp
40140 @item OK
40141 thread is still alive
40142 @item E @var{NN}
40143 thread is dead
40144 @end table
40145
40146 @item v
40147 Packets starting with @samp{v} are identified by a multi-letter name,
40148 up to the first @samp{;} or @samp{?} (or the end of the packet).
40149
40150 @item vAttach;@var{pid}
40151 @cindex @samp{vAttach} packet
40152 Attach to a new process with the specified process ID @var{pid}.
40153 The process ID is a
40154 hexadecimal integer identifying the process. In all-stop mode, all
40155 threads in the attached process are stopped; in non-stop mode, it may be
40156 attached without being stopped if that is supported by the target.
40157
40158 @c In non-stop mode, on a successful vAttach, the stub should set the
40159 @c current thread to a thread of the newly-attached process. After
40160 @c attaching, GDB queries for the attached process's thread ID with qC.
40161 @c Also note that, from a user perspective, whether or not the
40162 @c target is stopped on attach in non-stop mode depends on whether you
40163 @c use the foreground or background version of the attach command, not
40164 @c on what vAttach does; GDB does the right thing with respect to either
40165 @c stopping or restarting threads.
40166
40167 This packet is only available in extended mode (@pxref{extended mode}).
40168
40169 Reply:
40170 @table @samp
40171 @item E @var{nn}
40172 for an error
40173 @item @r{Any stop packet}
40174 for success in all-stop mode (@pxref{Stop Reply Packets})
40175 @item OK
40176 for success in non-stop mode (@pxref{Remote Non-Stop})
40177 @end table
40178
40179 @item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
40180 @cindex @samp{vCont} packet
40181 @anchor{vCont packet}
40182 Resume the inferior, specifying different actions for each thread.
40183
40184 For each inferior thread, the leftmost action with a matching
40185 @var{thread-id} is applied. Threads that don't match any action
40186 remain in their current state. Thread IDs are specified using the
40187 syntax described in @ref{thread-id syntax}. If multiprocess
40188 extensions (@pxref{multiprocess extensions}) are supported, actions
40189 can be specified to match all threads in a process by using the
40190 @samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
40191 @var{thread-id} matches all threads. Specifying no actions is an
40192 error.
40193
40194 Currently supported actions are:
40195
40196 @table @samp
40197 @item c
40198 Continue.
40199 @item C @var{sig}
40200 Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
40201 @item s
40202 Step.
40203 @item S @var{sig}
40204 Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
40205 @item t
40206 Stop.
40207 @item r @var{start},@var{end}
40208 Step once, and then keep stepping as long as the thread stops at
40209 addresses between @var{start} (inclusive) and @var{end} (exclusive).
40210 The remote stub reports a stop reply when either the thread goes out
40211 of the range or is stopped due to an unrelated reason, such as hitting
40212 a breakpoint. @xref{range stepping}.
40213
40214 If the range is empty (@var{start} == @var{end}), then the action
40215 becomes equivalent to the @samp{s} action. In other words,
40216 single-step once, and report the stop (even if the stepped instruction
40217 jumps to @var{start}).
40218
40219 (A stop reply may be sent at any point even if the PC is still within
40220 the stepping range; for example, it is valid to implement this packet
40221 in a degenerate way as a single instruction step operation.)
40222
40223 @end table
40224
40225 The optional argument @var{addr} normally associated with the
40226 @samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
40227 not supported in @samp{vCont}.
40228
40229 The @samp{t} action is only relevant in non-stop mode
40230 (@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
40231 A stop reply should be generated for any affected thread not already stopped.
40232 When a thread is stopped by means of a @samp{t} action,
40233 the corresponding stop reply should indicate that the thread has stopped with
40234 signal @samp{0}, regardless of whether the target uses some other signal
40235 as an implementation detail.
40236
40237 The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
40238 @samp{r} actions for threads that are already running. Conversely,
40239 the server must ignore @samp{t} actions for threads that are already
40240 stopped.
40241
40242 @emph{Note:} In non-stop mode, a thread is considered running until
40243 @value{GDBN} acknowledges an asynchronous stop notification for it with
40244 the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
40245
40246 The stub must support @samp{vCont} if it reports support for
40247 multiprocess extensions (@pxref{multiprocess extensions}).
40248
40249 Reply:
40250 @xref{Stop Reply Packets}, for the reply specifications.
40251
40252 @item vCont?
40253 @cindex @samp{vCont?} packet
40254 Request a list of actions supported by the @samp{vCont} packet.
40255
40256 Reply:
40257 @table @samp
40258 @item vCont@r{[};@var{action}@dots{}@r{]}
40259 The @samp{vCont} packet is supported. Each @var{action} is a supported
40260 command in the @samp{vCont} packet.
40261 @item @w{}
40262 The @samp{vCont} packet is not supported.
40263 @end table
40264
40265 @anchor{vCtrlC packet}
40266 @item vCtrlC
40267 @cindex @samp{vCtrlC} packet
40268 Interrupt remote target as if a control-C was pressed on the remote
40269 terminal. This is the equivalent to reacting to the @code{^C}
40270 (@samp{\003}, the control-C character) character in all-stop mode
40271 while the target is running, except this works in non-stop mode.
40272 @xref{interrupting remote targets}, for more info on the all-stop
40273 variant.
40274
40275 Reply:
40276 @table @samp
40277 @item E @var{nn}
40278 for an error
40279 @item OK
40280 for success
40281 @end table
40282
40283 @item vFile:@var{operation}:@var{parameter}@dots{}
40284 @cindex @samp{vFile} packet
40285 Perform a file operation on the target system. For details,
40286 see @ref{Host I/O Packets}.
40287
40288 @item vFlashErase:@var{addr},@var{length}
40289 @cindex @samp{vFlashErase} packet
40290 Direct the stub to erase @var{length} bytes of flash starting at
40291 @var{addr}. The region may enclose any number of flash blocks, but
40292 its start and end must fall on block boundaries, as indicated by the
40293 flash block size appearing in the memory map (@pxref{Memory Map
40294 Format}). @value{GDBN} groups flash memory programming operations
40295 together, and sends a @samp{vFlashDone} request after each group; the
40296 stub is allowed to delay erase operation until the @samp{vFlashDone}
40297 packet is received.
40298
40299 Reply:
40300 @table @samp
40301 @item OK
40302 for success
40303 @item E @var{NN}
40304 for an error
40305 @end table
40306
40307 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
40308 @cindex @samp{vFlashWrite} packet
40309 Direct the stub to write data to flash address @var{addr}. The data
40310 is passed in binary form using the same encoding as for the @samp{X}
40311 packet (@pxref{Binary Data}). The memory ranges specified by
40312 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
40313 not overlap, and must appear in order of increasing addresses
40314 (although @samp{vFlashErase} packets for higher addresses may already
40315 have been received; the ordering is guaranteed only between
40316 @samp{vFlashWrite} packets). If a packet writes to an address that was
40317 neither erased by a preceding @samp{vFlashErase} packet nor by some other
40318 target-specific method, the results are unpredictable.
40319
40320
40321 Reply:
40322 @table @samp
40323 @item OK
40324 for success
40325 @item E.memtype
40326 for vFlashWrite addressing non-flash memory
40327 @item E @var{NN}
40328 for an error
40329 @end table
40330
40331 @item vFlashDone
40332 @cindex @samp{vFlashDone} packet
40333 Indicate to the stub that flash programming operation is finished.
40334 The stub is permitted to delay or batch the effects of a group of
40335 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
40336 @samp{vFlashDone} packet is received. The contents of the affected
40337 regions of flash memory are unpredictable until the @samp{vFlashDone}
40338 request is completed.
40339
40340 @item vKill;@var{pid}
40341 @cindex @samp{vKill} packet
40342 @anchor{vKill packet}
40343 Kill the process with the specified process ID @var{pid}, which is a
40344 hexadecimal integer identifying the process. This packet is used in
40345 preference to @samp{k} when multiprocess protocol extensions are
40346 supported; see @ref{multiprocess extensions}.
40347
40348 Reply:
40349 @table @samp
40350 @item E @var{nn}
40351 for an error
40352 @item OK
40353 for success
40354 @end table
40355
40356 @item vMustReplyEmpty
40357 @cindex @samp{vMustReplyEmpty} packet
40358 The correct reply to an unknown @samp{v} packet is to return the empty
40359 string, however, some older versions of @command{gdbserver} would
40360 incorrectly return @samp{OK} for unknown @samp{v} packets.
40361
40362 The @samp{vMustReplyEmpty} is used as a feature test to check how
40363 @command{gdbserver} handles unknown packets, it is important that this
40364 packet be handled in the same way as other unknown @samp{v} packets.
40365 If this packet is handled differently to other unknown @samp{v}
40366 packets then it is possible that @value{GDBN} may run into problems in
40367 other areas, specifically around use of @samp{vFile:setfs:}.
40368
40369 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
40370 @cindex @samp{vRun} packet
40371 Run the program @var{filename}, passing it each @var{argument} on its
40372 command line. The file and arguments are hex-encoded strings. If
40373 @var{filename} is an empty string, the stub may use a default program
40374 (e.g.@: the last program run). The program is created in the stopped
40375 state.
40376
40377 @c FIXME: What about non-stop mode?
40378
40379 This packet is only available in extended mode (@pxref{extended mode}).
40380
40381 Reply:
40382 @table @samp
40383 @item E @var{nn}
40384 for an error
40385 @item @r{Any stop packet}
40386 for success (@pxref{Stop Reply Packets})
40387 @end table
40388
40389 @item vStopped
40390 @cindex @samp{vStopped} packet
40391 @xref{Notification Packets}.
40392
40393 @item X @var{addr},@var{length}:@var{XX@dots{}}
40394 @anchor{X packet}
40395 @cindex @samp{X} packet
40396 Write data to memory, where the data is transmitted in binary.
40397 Memory is specified by its address @var{addr} and number of addressable memory
40398 units @var{length} (@pxref{addressable memory unit});
40399 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
40400
40401 Reply:
40402 @table @samp
40403 @item OK
40404 for success
40405 @item E @var{NN}
40406 for an error
40407 @end table
40408
40409 @item z @var{type},@var{addr},@var{kind}
40410 @itemx Z @var{type},@var{addr},@var{kind}
40411 @anchor{insert breakpoint or watchpoint packet}
40412 @cindex @samp{z} packet
40413 @cindex @samp{Z} packets
40414 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
40415 watchpoint starting at address @var{address} of kind @var{kind}.
40416
40417 Each breakpoint and watchpoint packet @var{type} is documented
40418 separately.
40419
40420 @emph{Implementation notes: A remote target shall return an empty string
40421 for an unrecognized breakpoint or watchpoint packet @var{type}. A
40422 remote target shall support either both or neither of a given
40423 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
40424 avoid potential problems with duplicate packets, the operations should
40425 be implemented in an idempotent way.}
40426
40427 @item z0,@var{addr},@var{kind}
40428 @itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
40429 @cindex @samp{z0} packet
40430 @cindex @samp{Z0} packet
40431 Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
40432 @var{addr} of type @var{kind}.
40433
40434 A software breakpoint is implemented by replacing the instruction at
40435 @var{addr} with a software breakpoint or trap instruction. The
40436 @var{kind} is target-specific and typically indicates the size of the
40437 breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
40438 @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
40439 architectures have additional meanings for @var{kind}
40440 (@pxref{Architecture-Specific Protocol Details}); if no
40441 architecture-specific value is being used, it should be @samp{0}.
40442 @var{kind} is hex-encoded. @var{cond_list} is an optional list of
40443 conditional expressions in bytecode form that should be evaluated on
40444 the target's side. These are the conditions that should be taken into
40445 consideration when deciding if the breakpoint trigger should be
40446 reported back to @value{GDBN}.
40447
40448 See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
40449 for how to best report a software breakpoint event to @value{GDBN}.
40450
40451 The @var{cond_list} parameter is comprised of a series of expressions,
40452 concatenated without separators. Each expression has the following form:
40453
40454 @table @samp
40455
40456 @item X @var{len},@var{expr}
40457 @var{len} is the length of the bytecode expression and @var{expr} is the
40458 actual conditional expression in bytecode form.
40459
40460 @end table
40461
40462 The optional @var{cmd_list} parameter introduces commands that may be
40463 run on the target, rather than being reported back to @value{GDBN}.
40464 The parameter starts with a numeric flag @var{persist}; if the flag is
40465 nonzero, then the breakpoint may remain active and the commands
40466 continue to be run even when @value{GDBN} disconnects from the target.
40467 Following this flag is a series of expressions concatenated with no
40468 separators. Each expression has the following form:
40469
40470 @table @samp
40471
40472 @item X @var{len},@var{expr}
40473 @var{len} is the length of the bytecode expression and @var{expr} is the
40474 actual commands expression in bytecode form.
40475
40476 @end table
40477
40478 @emph{Implementation note: It is possible for a target to copy or move
40479 code that contains software breakpoints (e.g., when implementing
40480 overlays). The behavior of this packet, in the presence of such a
40481 target, is not defined.}
40482
40483 Reply:
40484 @table @samp
40485 @item OK
40486 success
40487 @item @w{}
40488 not supported
40489 @item E @var{NN}
40490 for an error
40491 @end table
40492
40493 @item z1,@var{addr},@var{kind}
40494 @itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
40495 @cindex @samp{z1} packet
40496 @cindex @samp{Z1} packet
40497 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
40498 address @var{addr}.
40499
40500 A hardware breakpoint is implemented using a mechanism that is not
40501 dependent on being able to modify the target's memory. The
40502 @var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
40503 same meaning as in @samp{Z0} packets.
40504
40505 @emph{Implementation note: A hardware breakpoint is not affected by code
40506 movement.}
40507
40508 Reply:
40509 @table @samp
40510 @item OK
40511 success
40512 @item @w{}
40513 not supported
40514 @item E @var{NN}
40515 for an error
40516 @end table
40517
40518 @item z2,@var{addr},@var{kind}
40519 @itemx Z2,@var{addr},@var{kind}
40520 @cindex @samp{z2} packet
40521 @cindex @samp{Z2} packet
40522 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
40523 The number of bytes to watch is specified by @var{kind}.
40524
40525 Reply:
40526 @table @samp
40527 @item OK
40528 success
40529 @item @w{}
40530 not supported
40531 @item E @var{NN}
40532 for an error
40533 @end table
40534
40535 @item z3,@var{addr},@var{kind}
40536 @itemx Z3,@var{addr},@var{kind}
40537 @cindex @samp{z3} packet
40538 @cindex @samp{Z3} packet
40539 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
40540 The number of bytes to watch is specified by @var{kind}.
40541
40542 Reply:
40543 @table @samp
40544 @item OK
40545 success
40546 @item @w{}
40547 not supported
40548 @item E @var{NN}
40549 for an error
40550 @end table
40551
40552 @item z4,@var{addr},@var{kind}
40553 @itemx Z4,@var{addr},@var{kind}
40554 @cindex @samp{z4} packet
40555 @cindex @samp{Z4} packet
40556 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
40557 The number of bytes to watch is specified by @var{kind}.
40558
40559 Reply:
40560 @table @samp
40561 @item OK
40562 success
40563 @item @w{}
40564 not supported
40565 @item E @var{NN}
40566 for an error
40567 @end table
40568
40569 @end table
40570
40571 @node Stop Reply Packets
40572 @section Stop Reply Packets
40573 @cindex stop reply packets
40574
40575 The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
40576 @samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
40577 receive any of the below as a reply. Except for @samp{?}
40578 and @samp{vStopped}, that reply is only returned
40579 when the target halts. In the below the exact meaning of @dfn{signal
40580 number} is defined by the header @file{include/gdb/signals.h} in the
40581 @value{GDBN} source code.
40582
40583 In non-stop mode, the server will simply reply @samp{OK} to commands
40584 such as @samp{vCont}; any stop will be the subject of a future
40585 notification. @xref{Remote Non-Stop}.
40586
40587 As in the description of request packets, we include spaces in the
40588 reply templates for clarity; these are not part of the reply packet's
40589 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
40590 components.
40591
40592 @table @samp
40593
40594 @item S @var{AA}
40595 The program received signal number @var{AA} (a two-digit hexadecimal
40596 number). This is equivalent to a @samp{T} response with no
40597 @var{n}:@var{r} pairs.
40598
40599 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
40600 @cindex @samp{T} packet reply
40601 The program received signal number @var{AA} (a two-digit hexadecimal
40602 number). This is equivalent to an @samp{S} response, except that the
40603 @samp{@var{n}:@var{r}} pairs can carry values of important registers
40604 and other information directly in the stop reply packet, reducing
40605 round-trip latency. Single-step and breakpoint traps are reported
40606 this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
40607
40608 @itemize @bullet
40609 @item
40610 If @var{n} is a hexadecimal number, it is a register number, and the
40611 corresponding @var{r} gives that register's value. The data @var{r} is a
40612 series of bytes in target byte order, with each byte given by a
40613 two-digit hex number.
40614
40615 @item
40616 If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
40617 the stopped thread, as specified in @ref{thread-id syntax}.
40618
40619 @item
40620 If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
40621 the core on which the stop event was detected.
40622
40623 @item
40624 If @var{n} is a recognized @dfn{stop reason}, it describes a more
40625 specific event that stopped the target. The currently defined stop
40626 reasons are listed below. The @var{aa} should be @samp{05}, the trap
40627 signal. At most one stop reason should be present.
40628
40629 @item
40630 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
40631 and go on to the next; this allows us to extend the protocol in the
40632 future.
40633 @end itemize
40634
40635 The currently defined stop reasons are:
40636
40637 @table @samp
40638 @item watch
40639 @itemx rwatch
40640 @itemx awatch
40641 The packet indicates a watchpoint hit, and @var{r} is the data address, in
40642 hex.
40643
40644 @item syscall_entry
40645 @itemx syscall_return
40646 The packet indicates a syscall entry or return, and @var{r} is the
40647 syscall number, in hex.
40648
40649 @cindex shared library events, remote reply
40650 @item library
40651 The packet indicates that the loaded libraries have changed.
40652 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
40653 list of loaded libraries. The @var{r} part is ignored.
40654
40655 @cindex replay log events, remote reply
40656 @item replaylog
40657 The packet indicates that the target cannot continue replaying
40658 logged execution events, because it has reached the end (or the
40659 beginning when executing backward) of the log. The value of @var{r}
40660 will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
40661 for more information.
40662
40663 @item swbreak
40664 @anchor{swbreak stop reason}
40665 The packet indicates a software breakpoint instruction was executed,
40666 irrespective of whether it was @value{GDBN} that planted the
40667 breakpoint or the breakpoint is hardcoded in the program. The @var{r}
40668 part must be left empty.
40669
40670 On some architectures, such as x86, at the architecture level, when a
40671 breakpoint instruction executes the program counter points at the
40672 breakpoint address plus an offset. On such targets, the stub is
40673 responsible for adjusting the PC to point back at the breakpoint
40674 address.
40675
40676 This packet should not be sent by default; older @value{GDBN} versions
40677 did not support it. @value{GDBN} requests it, by supplying an
40678 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40679 remote stub must also supply the appropriate @samp{qSupported} feature
40680 indicating support.
40681
40682 This packet is required for correct non-stop mode operation.
40683
40684 @item hwbreak
40685 The packet indicates the target stopped for a hardware breakpoint.
40686 The @var{r} part must be left empty.
40687
40688 The same remarks about @samp{qSupported} and non-stop mode above
40689 apply.
40690
40691 @cindex fork events, remote reply
40692 @item fork
40693 The packet indicates that @code{fork} was called, and @var{r}
40694 is the thread ID of the new child process. Refer to
40695 @ref{thread-id syntax} for the format of the @var{thread-id}
40696 field. This packet is only applicable to targets that support
40697 fork events.
40698
40699 This packet should not be sent by default; older @value{GDBN} versions
40700 did not support it. @value{GDBN} requests it, by supplying an
40701 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40702 remote stub must also supply the appropriate @samp{qSupported} feature
40703 indicating support.
40704
40705 @cindex vfork events, remote reply
40706 @item vfork
40707 The packet indicates that @code{vfork} was called, and @var{r}
40708 is the thread ID of the new child process. Refer to
40709 @ref{thread-id syntax} for the format of the @var{thread-id}
40710 field. This packet is only applicable to targets that support
40711 vfork events.
40712
40713 This packet should not be sent by default; older @value{GDBN} versions
40714 did not support it. @value{GDBN} requests it, by supplying an
40715 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40716 remote stub must also supply the appropriate @samp{qSupported} feature
40717 indicating support.
40718
40719 @cindex vforkdone events, remote reply
40720 @item vforkdone
40721 The packet indicates that a child process created by a vfork
40722 has either called @code{exec} or terminated, so that the
40723 address spaces of the parent and child process are no longer
40724 shared. The @var{r} part is ignored. This packet is only
40725 applicable to targets that support vforkdone events.
40726
40727 This packet should not be sent by default; older @value{GDBN} versions
40728 did not support it. @value{GDBN} requests it, by supplying an
40729 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40730 remote stub must also supply the appropriate @samp{qSupported} feature
40731 indicating support.
40732
40733 @cindex exec events, remote reply
40734 @item exec
40735 The packet indicates that @code{execve} was called, and @var{r}
40736 is the absolute pathname of the file that was executed, in hex.
40737 This packet is only applicable to targets that support exec events.
40738
40739 This packet should not be sent by default; older @value{GDBN} versions
40740 did not support it. @value{GDBN} requests it, by supplying an
40741 appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40742 remote stub must also supply the appropriate @samp{qSupported} feature
40743 indicating support.
40744
40745 @cindex thread create event, remote reply
40746 @anchor{thread create event}
40747 @item create
40748 The packet indicates that the thread was just created. The new thread
40749 is stopped until @value{GDBN} sets it running with a resumption packet
40750 (@pxref{vCont packet}). This packet should not be sent by default;
40751 @value{GDBN} requests it with the @ref{QThreadEvents} packet. See
40752 also the @samp{w} (@pxref{thread exit event}) remote reply below. The
40753 @var{r} part is ignored.
40754
40755 @end table
40756
40757 @item W @var{AA}
40758 @itemx W @var{AA} ; process:@var{pid}
40759 The process exited, and @var{AA} is the exit status. This is only
40760 applicable to certain targets.
40761
40762 The second form of the response, including the process ID of the
40763 exited process, can be used only when @value{GDBN} has reported
40764 support for multiprocess protocol extensions; see @ref{multiprocess
40765 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40766 hex strings.
40767
40768 @item X @var{AA}
40769 @itemx X @var{AA} ; process:@var{pid}
40770 The process terminated with signal @var{AA}.
40771
40772 The second form of the response, including the process ID of the
40773 terminated process, can be used only when @value{GDBN} has reported
40774 support for multiprocess protocol extensions; see @ref{multiprocess
40775 extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40776 hex strings.
40777
40778 @anchor{thread exit event}
40779 @cindex thread exit event, remote reply
40780 @item w @var{AA} ; @var{tid}
40781
40782 The thread exited, and @var{AA} is the exit status. This response
40783 should not be sent by default; @value{GDBN} requests it with the
40784 @ref{QThreadEvents} packet. See also @ref{thread create event} above.
40785 @var{AA} is formatted as a big-endian hex string.
40786
40787 @item N
40788 There are no resumed threads left in the target. In other words, even
40789 though the process is alive, the last resumed thread has exited. For
40790 example, say the target process has two threads: thread 1 and thread
40791 2. The client leaves thread 1 stopped, and resumes thread 2, which
40792 subsequently exits. At this point, even though the process is still
40793 alive, and thus no @samp{W} stop reply is sent, no thread is actually
40794 executing either. The @samp{N} stop reply thus informs the client
40795 that it can stop waiting for stop replies. This packet should not be
40796 sent by default; older @value{GDBN} versions did not support it.
40797 @value{GDBN} requests it, by supplying an appropriate
40798 @samp{qSupported} feature (@pxref{qSupported}). The remote stub must
40799 also supply the appropriate @samp{qSupported} feature indicating
40800 support.
40801
40802 @item O @var{XX}@dots{}
40803 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
40804 written as the program's console output. This can happen at any time
40805 while the program is running and the debugger should continue to wait
40806 for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
40807
40808 @item F @var{call-id},@var{parameter}@dots{}
40809 @var{call-id} is the identifier which says which host system call should
40810 be called. This is just the name of the function. Translation into the
40811 correct system call is only applicable as it's defined in @value{GDBN}.
40812 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
40813 system calls.
40814
40815 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
40816 this very system call.
40817
40818 The target replies with this packet when it expects @value{GDBN} to
40819 call a host system call on behalf of the target. @value{GDBN} replies
40820 with an appropriate @samp{F} packet and keeps up waiting for the next
40821 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
40822 or @samp{s} action is expected to be continued. @xref{File-I/O Remote
40823 Protocol Extension}, for more details.
40824
40825 @end table
40826
40827 @node General Query Packets
40828 @section General Query Packets
40829 @cindex remote query requests
40830
40831 Packets starting with @samp{q} are @dfn{general query packets};
40832 packets starting with @samp{Q} are @dfn{general set packets}. General
40833 query and set packets are a semi-unified form for retrieving and
40834 sending information to and from the stub.
40835
40836 The initial letter of a query or set packet is followed by a name
40837 indicating what sort of thing the packet applies to. For example,
40838 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
40839 definitions with the stub. These packet names follow some
40840 conventions:
40841
40842 @itemize @bullet
40843 @item
40844 The name must not contain commas, colons or semicolons.
40845 @item
40846 Most @value{GDBN} query and set packets have a leading upper case
40847 letter.
40848 @item
40849 The names of custom vendor packets should use a company prefix, in
40850 lower case, followed by a period. For example, packets designed at
40851 the Acme Corporation might begin with @samp{qacme.foo} (for querying
40852 foos) or @samp{Qacme.bar} (for setting bars).
40853 @end itemize
40854
40855 The name of a query or set packet should be separated from any
40856 parameters by a @samp{:}; the parameters themselves should be
40857 separated by @samp{,} or @samp{;}. Stubs must be careful to match the
40858 full packet name, and check for a separator or the end of the packet,
40859 in case two packet names share a common prefix. New packets should not begin
40860 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
40861 packets predate these conventions, and have arguments without any terminator
40862 for the packet name; we suspect they are in widespread use in places that
40863 are difficult to upgrade. The @samp{qC} packet has no arguments, but some
40864 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
40865 packet.}.
40866
40867 Like the descriptions of the other packets, each description here
40868 has a template showing the packet's overall syntax, followed by an
40869 explanation of the packet's meaning. We include spaces in some of the
40870 templates for clarity; these are not part of the packet's syntax. No
40871 @value{GDBN} packet uses spaces to separate its components.
40872
40873 Here are the currently defined query and set packets:
40874
40875 @table @samp
40876
40877 @item QAgent:1
40878 @itemx QAgent:0
40879 Turn on or off the agent as a helper to perform some debugging operations
40880 delegated from @value{GDBN} (@pxref{Control Agent}).
40881
40882 @item QAllow:@var{op}:@var{val}@dots{}
40883 @cindex @samp{QAllow} packet
40884 Specify which operations @value{GDBN} expects to request of the
40885 target, as a semicolon-separated list of operation name and value
40886 pairs. Possible values for @var{op} include @samp{WriteReg},
40887 @samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
40888 @samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
40889 indicating that @value{GDBN} will not request the operation, or 1,
40890 indicating that it may. (The target can then use this to set up its
40891 own internals optimally, for instance if the debugger never expects to
40892 insert breakpoints, it may not need to install its own trap handler.)
40893
40894 @item qC
40895 @cindex current thread, remote request
40896 @cindex @samp{qC} packet
40897 Return the current thread ID.
40898
40899 Reply:
40900 @table @samp
40901 @item QC @var{thread-id}
40902 Where @var{thread-id} is a thread ID as documented in
40903 @ref{thread-id syntax}.
40904 @item @r{(anything else)}
40905 Any other reply implies the old thread ID.
40906 @end table
40907
40908 @item qCRC:@var{addr},@var{length}
40909 @cindex CRC of memory block, remote request
40910 @cindex @samp{qCRC} packet
40911 @anchor{qCRC packet}
40912 Compute the CRC checksum of a block of memory using CRC-32 defined in
40913 IEEE 802.3. The CRC is computed byte at a time, taking the most
40914 significant bit of each byte first. The initial pattern code
40915 @code{0xffffffff} is used to ensure leading zeros affect the CRC.
40916
40917 @emph{Note:} This is the same CRC used in validating separate debug
40918 files (@pxref{Separate Debug Files, , Debugging Information in Separate
40919 Files}). However the algorithm is slightly different. When validating
40920 separate debug files, the CRC is computed taking the @emph{least}
40921 significant bit of each byte first, and the final result is inverted to
40922 detect trailing zeros.
40923
40924 Reply:
40925 @table @samp
40926 @item E @var{NN}
40927 An error (such as memory fault)
40928 @item C @var{crc32}
40929 The specified memory region's checksum is @var{crc32}.
40930 @end table
40931
40932 @item QDisableRandomization:@var{value}
40933 @cindex disable address space randomization, remote request
40934 @cindex @samp{QDisableRandomization} packet
40935 Some target operating systems will randomize the virtual address space
40936 of the inferior process as a security feature, but provide a feature
40937 to disable such randomization, e.g.@: to allow for a more deterministic
40938 debugging experience. On such systems, this packet with a @var{value}
40939 of 1 directs the target to disable address space randomization for
40940 processes subsequently started via @samp{vRun} packets, while a packet
40941 with a @var{value} of 0 tells the target to enable address space
40942 randomization.
40943
40944 This packet is only available in extended mode (@pxref{extended mode}).
40945
40946 Reply:
40947 @table @samp
40948 @item OK
40949 The request succeeded.
40950
40951 @item E @var{nn}
40952 An error occurred. The error number @var{nn} is given as hex digits.
40953
40954 @item @w{}
40955 An empty reply indicates that @samp{QDisableRandomization} is not supported
40956 by the stub.
40957 @end table
40958
40959 This packet is not probed by default; the remote stub must request it,
40960 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40961 This should only be done on targets that actually support disabling
40962 address space randomization.
40963
40964 @item QStartupWithShell:@var{value}
40965 @cindex startup with shell, remote request
40966 @cindex @samp{QStartupWithShell} packet
40967 On UNIX-like targets, it is possible to start the inferior using a
40968 shell program. This is the default behavior on both @value{GDBN} and
40969 @command{gdbserver} (@pxref{set startup-with-shell}). This packet is
40970 used to inform @command{gdbserver} whether it should start the
40971 inferior using a shell or not.
40972
40973 If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
40974 to start the inferior. If @var{value} is @samp{1},
40975 @command{gdbserver} will use a shell to start the inferior. All other
40976 values are considered an error.
40977
40978 This packet is only available in extended mode (@pxref{extended
40979 mode}).
40980
40981 Reply:
40982 @table @samp
40983 @item OK
40984 The request succeeded.
40985
40986 @item E @var{nn}
40987 An error occurred. The error number @var{nn} is given as hex digits.
40988 @end table
40989
40990 This packet is not probed by default; the remote stub must request it,
40991 by supplying an appropriate @samp{qSupported} response
40992 (@pxref{qSupported}). This should only be done on targets that
40993 actually support starting the inferior using a shell.
40994
40995 Use of this packet is controlled by the @code{set startup-with-shell}
40996 command; @pxref{set startup-with-shell}.
40997
40998 @item QEnvironmentHexEncoded:@var{hex-value}
40999 @anchor{QEnvironmentHexEncoded}
41000 @cindex set environment variable, remote request
41001 @cindex @samp{QEnvironmentHexEncoded} packet
41002 On UNIX-like targets, it is possible to set environment variables that
41003 will be passed to the inferior during the startup process. This
41004 packet is used to inform @command{gdbserver} of an environment
41005 variable that has been defined by the user on @value{GDBN} (@pxref{set
41006 environment}).
41007
41008 The packet is composed by @var{hex-value}, an hex encoded
41009 representation of the @var{name=value} format representing an
41010 environment variable. The name of the environment variable is
41011 represented by @var{name}, and the value to be assigned to the
41012 environment variable is represented by @var{value}. If the variable
41013 has no value (i.e., the value is @code{null}), then @var{value} will
41014 not be present.
41015
41016 This packet is only available in extended mode (@pxref{extended
41017 mode}).
41018
41019 Reply:
41020 @table @samp
41021 @item OK
41022 The request succeeded.
41023 @end table
41024
41025 This packet is not probed by default; the remote stub must request it,
41026 by supplying an appropriate @samp{qSupported} response
41027 (@pxref{qSupported}). This should only be done on targets that
41028 actually support passing environment variables to the starting
41029 inferior.
41030
41031 This packet is related to the @code{set environment} command;
41032 @pxref{set environment}.
41033
41034 @item QEnvironmentUnset:@var{hex-value}
41035 @anchor{QEnvironmentUnset}
41036 @cindex unset environment variable, remote request
41037 @cindex @samp{QEnvironmentUnset} packet
41038 On UNIX-like targets, it is possible to unset environment variables
41039 before starting the inferior in the remote target. This packet is
41040 used to inform @command{gdbserver} of an environment variable that has
41041 been unset by the user on @value{GDBN} (@pxref{unset environment}).
41042
41043 The packet is composed by @var{hex-value}, an hex encoded
41044 representation of the name of the environment variable to be unset.
41045
41046 This packet is only available in extended mode (@pxref{extended
41047 mode}).
41048
41049 Reply:
41050 @table @samp
41051 @item OK
41052 The request succeeded.
41053 @end table
41054
41055 This packet is not probed by default; the remote stub must request it,
41056 by supplying an appropriate @samp{qSupported} response
41057 (@pxref{qSupported}). This should only be done on targets that
41058 actually support passing environment variables to the starting
41059 inferior.
41060
41061 This packet is related to the @code{unset environment} command;
41062 @pxref{unset environment}.
41063
41064 @item QEnvironmentReset
41065 @anchor{QEnvironmentReset}
41066 @cindex reset environment, remote request
41067 @cindex @samp{QEnvironmentReset} packet
41068 On UNIX-like targets, this packet is used to reset the state of
41069 environment variables in the remote target before starting the
41070 inferior. In this context, reset means unsetting all environment
41071 variables that were previously set by the user (i.e., were not
41072 initially present in the environment). It is sent to
41073 @command{gdbserver} before the @samp{QEnvironmentHexEncoded}
41074 (@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
41075 (@pxref{QEnvironmentUnset}) packets.
41076
41077 This packet is only available in extended mode (@pxref{extended
41078 mode}).
41079
41080 Reply:
41081 @table @samp
41082 @item OK
41083 The request succeeded.
41084 @end table
41085
41086 This packet is not probed by default; the remote stub must request it,
41087 by supplying an appropriate @samp{qSupported} response
41088 (@pxref{qSupported}). This should only be done on targets that
41089 actually support passing environment variables to the starting
41090 inferior.
41091
41092 @item QSetWorkingDir:@r{[}@var{directory}@r{]}
41093 @anchor{QSetWorkingDir packet}
41094 @cindex set working directory, remote request
41095 @cindex @samp{QSetWorkingDir} packet
41096 This packet is used to inform the remote server of the intended
41097 current working directory for programs that are going to be executed.
41098
41099 The packet is composed by @var{directory}, an hex encoded
41100 representation of the directory that the remote inferior will use as
41101 its current working directory. If @var{directory} is an empty string,
41102 the remote server should reset the inferior's current working
41103 directory to its original, empty value.
41104
41105 This packet is only available in extended mode (@pxref{extended
41106 mode}).
41107
41108 Reply:
41109 @table @samp
41110 @item OK
41111 The request succeeded.
41112 @end table
41113
41114 @item qfThreadInfo
41115 @itemx qsThreadInfo
41116 @cindex list active threads, remote request
41117 @cindex @samp{qfThreadInfo} packet
41118 @cindex @samp{qsThreadInfo} packet
41119 Obtain a list of all active thread IDs from the target (OS). Since there
41120 may be too many active threads to fit into one reply packet, this query
41121 works iteratively: it may require more than one query/reply sequence to
41122 obtain the entire list of threads. The first query of the sequence will
41123 be the @samp{qfThreadInfo} query; subsequent queries in the
41124 sequence will be the @samp{qsThreadInfo} query.
41125
41126 NOTE: This packet replaces the @samp{qL} query (see below).
41127
41128 Reply:
41129 @table @samp
41130 @item m @var{thread-id}
41131 A single thread ID
41132 @item m @var{thread-id},@var{thread-id}@dots{}
41133 a comma-separated list of thread IDs
41134 @item l
41135 (lower case letter @samp{L}) denotes end of list.
41136 @end table
41137
41138 In response to each query, the target will reply with a list of one or
41139 more thread IDs, separated by commas.
41140 @value{GDBN} will respond to each reply with a request for more thread
41141 ids (using the @samp{qs} form of the query), until the target responds
41142 with @samp{l} (lower-case ell, for @dfn{last}).
41143 Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
41144 fields.
41145
41146 @emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
41147 initial connection with the remote target, and the very first thread ID
41148 mentioned in the reply will be stopped by @value{GDBN} in a subsequent
41149 message. Therefore, the stub should ensure that the first thread ID in
41150 the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
41151
41152 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
41153 @cindex get thread-local storage address, remote request
41154 @cindex @samp{qGetTLSAddr} packet
41155 Fetch the address associated with thread local storage specified
41156 by @var{thread-id}, @var{offset}, and @var{lm}.
41157
41158 @var{thread-id} is the thread ID associated with the
41159 thread for which to fetch the TLS address. @xref{thread-id syntax}.
41160
41161 @var{offset} is the (big endian, hex encoded) offset associated with the
41162 thread local variable. (This offset is obtained from the debug
41163 information associated with the variable.)
41164
41165 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
41166 load module associated with the thread local storage. For example,
41167 a @sc{gnu}/Linux system will pass the link map address of the shared
41168 object associated with the thread local storage under consideration.
41169 Other operating environments may choose to represent the load module
41170 differently, so the precise meaning of this parameter will vary.
41171
41172 Reply:
41173 @table @samp
41174 @item @var{XX}@dots{}
41175 Hex encoded (big endian) bytes representing the address of the thread
41176 local storage requested.
41177
41178 @item E @var{nn}
41179 An error occurred. The error number @var{nn} is given as hex digits.
41180
41181 @item @w{}
41182 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
41183 @end table
41184
41185 @item qGetTIBAddr:@var{thread-id}
41186 @cindex get thread information block address
41187 @cindex @samp{qGetTIBAddr} packet
41188 Fetch address of the Windows OS specific Thread Information Block.
41189
41190 @var{thread-id} is the thread ID associated with the thread.
41191
41192 Reply:
41193 @table @samp
41194 @item @var{XX}@dots{}
41195 Hex encoded (big endian) bytes representing the linear address of the
41196 thread information block.
41197
41198 @item E @var{nn}
41199 An error occured. This means that either the thread was not found, or the
41200 address could not be retrieved.
41201
41202 @item @w{}
41203 An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
41204 @end table
41205
41206 @item qL @var{startflag} @var{threadcount} @var{nextthread}
41207 Obtain thread information from RTOS. Where: @var{startflag} (one hex
41208 digit) is one to indicate the first query and zero to indicate a
41209 subsequent query; @var{threadcount} (two hex digits) is the maximum
41210 number of threads the response packet can contain; and @var{nextthread}
41211 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
41212 returned in the response as @var{argthread}.
41213
41214 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
41215
41216 Reply:
41217 @table @samp
41218 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
41219 Where: @var{count} (two hex digits) is the number of threads being
41220 returned; @var{done} (one hex digit) is zero to indicate more threads
41221 and one indicates no further threads; @var{argthreadid} (eight hex
41222 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
41223 is a sequence of thread IDs, @var{threadid} (eight hex
41224 digits), from the target. See @code{remote.c:parse_threadlist_response()}.
41225 @end table
41226
41227 @item qMemTags:@var{start address},@var{length}:@var{type}
41228 @anchor{qMemTags}
41229 @cindex fetch memory tags
41230 @cindex @samp{qMemTags} packet
41231 Fetch memory tags of type @var{type} from the address range
41232 @w{@r{[}@var{start address}, @var{start address} + @var{length}@r{)}}. The
41233 target is responsible for calculating how many tags will be returned, as this
41234 is architecture-specific.
41235
41236 @var{start address} is the starting address of the memory range.
41237
41238 @var{length} is the length, in bytes, of the memory range.
41239
41240 @var{type} is the type of tag the request wants to fetch. The type is a signed
41241 integer.
41242
41243 Reply:
41244 @table @samp
41245 @item @var{mxx}@dots{}
41246 Hex encoded sequence of uninterpreted bytes, @var{xx}@dots{}, representing the
41247 tags found in the requested memory range.
41248
41249 @item E @var{nn}
41250 An error occured. This means that fetching of memory tags failed for some
41251 reason.
41252
41253 @item @w{}
41254 An empty reply indicates that @samp{qMemTags} is not supported by the stub,
41255 although this should not happen given @value{GDBN} will only send this packet
41256 if the stub has advertised support for memory tagging via @samp{qSupported}.
41257 @end table
41258
41259 @item QMemTags:@var{start address},@var{length}:@var{type}:@var{tag bytes}
41260 @anchor{QMemTags}
41261 @cindex store memory tags
41262 @cindex @samp{QMemTags} packet
41263 Store memory tags of type @var{type} to the address range
41264 @w{@r{[}@var{start address}, @var{start address} + @var{length}@r{)}}. The
41265 target is responsible for interpreting the type, the tag bytes and modifying
41266 the memory tag granules accordingly, given this is architecture-specific.
41267
41268 The interpretation of how many tags (@var{nt}) should be written to how many
41269 memory tag granules (@var{ng}) is also architecture-specific. The behavior is
41270 implementation-specific, but the following is suggested.
41271
41272 If the number of memory tags, @var{nt}, is greater than or equal to the
41273 number of memory tag granules, @var{ng}, only @var{ng} tags will be
41274 stored.
41275
41276 If @var{nt} is less than @var{ng}, the behavior is that of a fill operation,
41277 and the tag bytes will be used as a pattern that will get repeated until
41278 @var{ng} tags are stored.
41279
41280 @var{start address} is the starting address of the memory range. The address
41281 does not have any restriction on alignment or size.
41282
41283 @var{length} is the length, in bytes, of the memory range.
41284
41285 @var{type} is the type of tag the request wants to fetch. The type is a signed
41286 integer.
41287
41288 @var{tag bytes} is a sequence of hex encoded uninterpreted bytes which will be
41289 interpreted by the target. Each pair of hex digits is interpreted as a
41290 single byte.
41291
41292 Reply:
41293 @table @samp
41294 @item OK
41295 The request was successful and the memory tag granules were modified
41296 accordingly.
41297
41298 @item E @var{nn}
41299 An error occured. This means that modifying the memory tag granules failed
41300 for some reason.
41301
41302 @item @w{}
41303 An empty reply indicates that @samp{QMemTags} is not supported by the stub,
41304 although this should not happen given @value{GDBN} will only send this packet
41305 if the stub has advertised support for memory tagging via @samp{qSupported}.
41306 @end table
41307
41308 @item qOffsets
41309 @cindex section offsets, remote request
41310 @cindex @samp{qOffsets} packet
41311 Get section offsets that the target used when relocating the downloaded
41312 image.
41313
41314 Reply:
41315 @table @samp
41316 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
41317 Relocate the @code{Text} section by @var{xxx} from its original address.
41318 Relocate the @code{Data} section by @var{yyy} from its original address.
41319 If the object file format provides segment information (e.g.@: @sc{elf}
41320 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
41321 segments by the supplied offsets.
41322
41323 @emph{Note: while a @code{Bss} offset may be included in the response,
41324 @value{GDBN} ignores this and instead applies the @code{Data} offset
41325 to the @code{Bss} section.}
41326
41327 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
41328 Relocate the first segment of the object file, which conventionally
41329 contains program code, to a starting address of @var{xxx}. If
41330 @samp{DataSeg} is specified, relocate the second segment, which
41331 conventionally contains modifiable data, to a starting address of
41332 @var{yyy}. @value{GDBN} will report an error if the object file
41333 does not contain segment information, or does not contain at least
41334 as many segments as mentioned in the reply. Extra segments are
41335 kept at fixed offsets relative to the last relocated segment.
41336 @end table
41337
41338 @item qP @var{mode} @var{thread-id}
41339 @cindex thread information, remote request
41340 @cindex @samp{qP} packet
41341 Returns information on @var{thread-id}. Where: @var{mode} is a hex
41342 encoded 32 bit mode; @var{thread-id} is a thread ID
41343 (@pxref{thread-id syntax}).
41344
41345 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
41346 (see below).
41347
41348 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
41349
41350 @item QNonStop:1
41351 @itemx QNonStop:0
41352 @cindex non-stop mode, remote request
41353 @cindex @samp{QNonStop} packet
41354 @anchor{QNonStop}
41355 Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
41356 @xref{Remote Non-Stop}, for more information.
41357
41358 Reply:
41359 @table @samp
41360 @item OK
41361 The request succeeded.
41362
41363 @item E @var{nn}
41364 An error occurred. The error number @var{nn} is given as hex digits.
41365
41366 @item @w{}
41367 An empty reply indicates that @samp{QNonStop} is not supported by
41368 the stub.
41369 @end table
41370
41371 This packet is not probed by default; the remote stub must request it,
41372 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41373 Use of this packet is controlled by the @code{set non-stop} command;
41374 @pxref{Non-Stop Mode}.
41375
41376 @item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
41377 @itemx QCatchSyscalls:0
41378 @cindex catch syscalls from inferior, remote request
41379 @cindex @samp{QCatchSyscalls} packet
41380 @anchor{QCatchSyscalls}
41381 Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
41382 catching syscalls from the inferior process.
41383
41384 For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
41385 in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
41386 is listed, every system call should be reported.
41387
41388 Note that if a syscall not in the list is reported, @value{GDBN} will
41389 still filter the event according to its own list from all corresponding
41390 @code{catch syscall} commands. However, it is more efficient to only
41391 report the requested syscalls.
41392
41393 Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
41394 @samp{QCatchSyscalls:1} list is completely replaced by the new list.
41395
41396 If the inferior process execs, the state of @samp{QCatchSyscalls} is
41397 kept for the new process too. On targets where exec may affect syscall
41398 numbers, for example with exec between 32 and 64-bit processes, the
41399 client should send a new packet with the new syscall list.
41400
41401 Reply:
41402 @table @samp
41403 @item OK
41404 The request succeeded.
41405
41406 @item E @var{nn}
41407 An error occurred. @var{nn} are hex digits.
41408
41409 @item @w{}
41410 An empty reply indicates that @samp{QCatchSyscalls} is not supported by
41411 the stub.
41412 @end table
41413
41414 Use of this packet is controlled by the @code{set remote catch-syscalls}
41415 command (@pxref{Remote Configuration, set remote catch-syscalls}).
41416 This packet is not probed by default; the remote stub must request it,
41417 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41418
41419 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
41420 @cindex pass signals to inferior, remote request
41421 @cindex @samp{QPassSignals} packet
41422 @anchor{QPassSignals}
41423 Each listed @var{signal} should be passed directly to the inferior process.
41424 Signals are numbered identically to continue packets and stop replies
41425 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
41426 strictly greater than the previous item. These signals do not need to stop
41427 the inferior, or be reported to @value{GDBN}. All other signals should be
41428 reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
41429 combine; any earlier @samp{QPassSignals} list is completely replaced by the
41430 new list. This packet improves performance when using @samp{handle
41431 @var{signal} nostop noprint pass}.
41432
41433 Reply:
41434 @table @samp
41435 @item OK
41436 The request succeeded.
41437
41438 @item E @var{nn}
41439 An error occurred. The error number @var{nn} is given as hex digits.
41440
41441 @item @w{}
41442 An empty reply indicates that @samp{QPassSignals} is not supported by
41443 the stub.
41444 @end table
41445
41446 Use of this packet is controlled by the @code{set remote pass-signals}
41447 command (@pxref{Remote Configuration, set remote pass-signals}).
41448 This packet is not probed by default; the remote stub must request it,
41449 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41450
41451 @item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
41452 @cindex signals the inferior may see, remote request
41453 @cindex @samp{QProgramSignals} packet
41454 @anchor{QProgramSignals}
41455 Each listed @var{signal} may be delivered to the inferior process.
41456 Others should be silently discarded.
41457
41458 In some cases, the remote stub may need to decide whether to deliver a
41459 signal to the program or not without @value{GDBN} involvement. One
41460 example of that is while detaching --- the program's threads may have
41461 stopped for signals that haven't yet had a chance of being reported to
41462 @value{GDBN}, and so the remote stub can use the signal list specified
41463 by this packet to know whether to deliver or ignore those pending
41464 signals.
41465
41466 This does not influence whether to deliver a signal as requested by a
41467 resumption packet (@pxref{vCont packet}).
41468
41469 Signals are numbered identically to continue packets and stop replies
41470 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
41471 strictly greater than the previous item. Multiple
41472 @samp{QProgramSignals} packets do not combine; any earlier
41473 @samp{QProgramSignals} list is completely replaced by the new list.
41474
41475 Reply:
41476 @table @samp
41477 @item OK
41478 The request succeeded.
41479
41480 @item E @var{nn}
41481 An error occurred. The error number @var{nn} is given as hex digits.
41482
41483 @item @w{}
41484 An empty reply indicates that @samp{QProgramSignals} is not supported
41485 by the stub.
41486 @end table
41487
41488 Use of this packet is controlled by the @code{set remote program-signals}
41489 command (@pxref{Remote Configuration, set remote program-signals}).
41490 This packet is not probed by default; the remote stub must request it,
41491 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41492
41493 @anchor{QThreadEvents}
41494 @item QThreadEvents:1
41495 @itemx QThreadEvents:0
41496 @cindex thread create/exit events, remote request
41497 @cindex @samp{QThreadEvents} packet
41498
41499 Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
41500 reporting of thread create and exit events. @xref{thread create
41501 event}, for the reply specifications. For example, this is used in
41502 non-stop mode when @value{GDBN} stops a set of threads and
41503 synchronously waits for the their corresponding stop replies. Without
41504 exit events, if one of the threads exits, @value{GDBN} would hang
41505 forever not knowing that it should no longer expect a stop for that
41506 same thread. @value{GDBN} does not enable this feature unless the
41507 stub reports that it supports it by including @samp{QThreadEvents+} in
41508 its @samp{qSupported} reply.
41509
41510 Reply:
41511 @table @samp
41512 @item OK
41513 The request succeeded.
41514
41515 @item E @var{nn}
41516 An error occurred. The error number @var{nn} is given as hex digits.
41517
41518 @item @w{}
41519 An empty reply indicates that @samp{QThreadEvents} is not supported by
41520 the stub.
41521 @end table
41522
41523 Use of this packet is controlled by the @code{set remote thread-events}
41524 command (@pxref{Remote Configuration, set remote thread-events}).
41525
41526 @item qRcmd,@var{command}
41527 @cindex execute remote command, remote request
41528 @cindex @samp{qRcmd} packet
41529 @var{command} (hex encoded) is passed to the local interpreter for
41530 execution. Invalid commands should be reported using the output
41531 string. Before the final result packet, the target may also respond
41532 with a number of intermediate @samp{O@var{output}} console output
41533 packets. @emph{Implementors should note that providing access to a
41534 stubs's interpreter may have security implications}.
41535
41536 Reply:
41537 @table @samp
41538 @item OK
41539 A command response with no output.
41540 @item @var{OUTPUT}
41541 A command response with the hex encoded output string @var{OUTPUT}.
41542 @item E @var{NN}
41543 Indicate a badly formed request.
41544 @item @w{}
41545 An empty reply indicates that @samp{qRcmd} is not recognized.
41546 @end table
41547
41548 (Note that the @code{qRcmd} packet's name is separated from the
41549 command by a @samp{,}, not a @samp{:}, contrary to the naming
41550 conventions above. Please don't use this packet as a model for new
41551 packets.)
41552
41553 @item qSearch:memory:@var{address};@var{length};@var{search-pattern}
41554 @cindex searching memory, in remote debugging
41555 @ifnotinfo
41556 @cindex @samp{qSearch:memory} packet
41557 @end ifnotinfo
41558 @cindex @samp{qSearch memory} packet
41559 @anchor{qSearch memory}
41560 Search @var{length} bytes at @var{address} for @var{search-pattern}.
41561 Both @var{address} and @var{length} are encoded in hex;
41562 @var{search-pattern} is a sequence of bytes, also hex encoded.
41563
41564 Reply:
41565 @table @samp
41566 @item 0
41567 The pattern was not found.
41568 @item 1,address
41569 The pattern was found at @var{address}.
41570 @item E @var{NN}
41571 A badly formed request or an error was encountered while searching memory.
41572 @item @w{}
41573 An empty reply indicates that @samp{qSearch:memory} is not recognized.
41574 @end table
41575
41576 @item QStartNoAckMode
41577 @cindex @samp{QStartNoAckMode} packet
41578 @anchor{QStartNoAckMode}
41579 Request that the remote stub disable the normal @samp{+}/@samp{-}
41580 protocol acknowledgments (@pxref{Packet Acknowledgment}).
41581
41582 Reply:
41583 @table @samp
41584 @item OK
41585 The stub has switched to no-acknowledgment mode.
41586 @value{GDBN} acknowledges this response,
41587 but neither the stub nor @value{GDBN} shall send or expect further
41588 @samp{+}/@samp{-} acknowledgments in the current connection.
41589 @item @w{}
41590 An empty reply indicates that the stub does not support no-acknowledgment mode.
41591 @end table
41592
41593 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
41594 @cindex supported packets, remote query
41595 @cindex features of the remote protocol
41596 @cindex @samp{qSupported} packet
41597 @anchor{qSupported}
41598 Tell the remote stub about features supported by @value{GDBN}, and
41599 query the stub for features it supports. This packet allows
41600 @value{GDBN} and the remote stub to take advantage of each others'
41601 features. @samp{qSupported} also consolidates multiple feature probes
41602 at startup, to improve @value{GDBN} performance---a single larger
41603 packet performs better than multiple smaller probe packets on
41604 high-latency links. Some features may enable behavior which must not
41605 be on by default, e.g.@: because it would confuse older clients or
41606 stubs. Other features may describe packets which could be
41607 automatically probed for, but are not. These features must be
41608 reported before @value{GDBN} will use them. This ``default
41609 unsupported'' behavior is not appropriate for all packets, but it
41610 helps to keep the initial connection time under control with new
41611 versions of @value{GDBN} which support increasing numbers of packets.
41612
41613 Reply:
41614 @table @samp
41615 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
41616 The stub supports or does not support each returned @var{stubfeature},
41617 depending on the form of each @var{stubfeature} (see below for the
41618 possible forms).
41619 @item @w{}
41620 An empty reply indicates that @samp{qSupported} is not recognized,
41621 or that no features needed to be reported to @value{GDBN}.
41622 @end table
41623
41624 The allowed forms for each feature (either a @var{gdbfeature} in the
41625 @samp{qSupported} packet, or a @var{stubfeature} in the response)
41626 are:
41627
41628 @table @samp
41629 @item @var{name}=@var{value}
41630 The remote protocol feature @var{name} is supported, and associated
41631 with the specified @var{value}. The format of @var{value} depends
41632 on the feature, but it must not include a semicolon.
41633 @item @var{name}+
41634 The remote protocol feature @var{name} is supported, and does not
41635 need an associated value.
41636 @item @var{name}-
41637 The remote protocol feature @var{name} is not supported.
41638 @item @var{name}?
41639 The remote protocol feature @var{name} may be supported, and
41640 @value{GDBN} should auto-detect support in some other way when it is
41641 needed. This form will not be used for @var{gdbfeature} notifications,
41642 but may be used for @var{stubfeature} responses.
41643 @end table
41644
41645 Whenever the stub receives a @samp{qSupported} request, the
41646 supplied set of @value{GDBN} features should override any previous
41647 request. This allows @value{GDBN} to put the stub in a known
41648 state, even if the stub had previously been communicating with
41649 a different version of @value{GDBN}.
41650
41651 The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
41652 are defined:
41653
41654 @table @samp
41655 @item multiprocess
41656 This feature indicates whether @value{GDBN} supports multiprocess
41657 extensions to the remote protocol. @value{GDBN} does not use such
41658 extensions unless the stub also reports that it supports them by
41659 including @samp{multiprocess+} in its @samp{qSupported} reply.
41660 @xref{multiprocess extensions}, for details.
41661
41662 @item xmlRegisters
41663 This feature indicates that @value{GDBN} supports the XML target
41664 description. If the stub sees @samp{xmlRegisters=} with target
41665 specific strings separated by a comma, it will report register
41666 description.
41667
41668 @item qRelocInsn
41669 This feature indicates whether @value{GDBN} supports the
41670 @samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
41671 instruction reply packet}).
41672
41673 @item swbreak
41674 This feature indicates whether @value{GDBN} supports the swbreak stop
41675 reason in stop replies. @xref{swbreak stop reason}, for details.
41676
41677 @item hwbreak
41678 This feature indicates whether @value{GDBN} supports the hwbreak stop
41679 reason in stop replies. @xref{swbreak stop reason}, for details.
41680
41681 @item fork-events
41682 This feature indicates whether @value{GDBN} supports fork event
41683 extensions to the remote protocol. @value{GDBN} does not use such
41684 extensions unless the stub also reports that it supports them by
41685 including @samp{fork-events+} in its @samp{qSupported} reply.
41686
41687 @item vfork-events
41688 This feature indicates whether @value{GDBN} supports vfork event
41689 extensions to the remote protocol. @value{GDBN} does not use such
41690 extensions unless the stub also reports that it supports them by
41691 including @samp{vfork-events+} in its @samp{qSupported} reply.
41692
41693 @item exec-events
41694 This feature indicates whether @value{GDBN} supports exec event
41695 extensions to the remote protocol. @value{GDBN} does not use such
41696 extensions unless the stub also reports that it supports them by
41697 including @samp{exec-events+} in its @samp{qSupported} reply.
41698
41699 @item vContSupported
41700 This feature indicates whether @value{GDBN} wants to know the
41701 supported actions in the reply to @samp{vCont?} packet.
41702 @end table
41703
41704 Stubs should ignore any unknown values for
41705 @var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
41706 packet supports receiving packets of unlimited length (earlier
41707 versions of @value{GDBN} may reject overly long responses). Additional values
41708 for @var{gdbfeature} may be defined in the future to let the stub take
41709 advantage of new features in @value{GDBN}, e.g.@: incompatible
41710 improvements in the remote protocol---the @samp{multiprocess} feature is
41711 an example of such a feature. The stub's reply should be independent
41712 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
41713 describes all the features it supports, and then the stub replies with
41714 all the features it supports.
41715
41716 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
41717 responses, as long as each response uses one of the standard forms.
41718
41719 Some features are flags. A stub which supports a flag feature
41720 should respond with a @samp{+} form response. Other features
41721 require values, and the stub should respond with an @samp{=}
41722 form response.
41723
41724 Each feature has a default value, which @value{GDBN} will use if
41725 @samp{qSupported} is not available or if the feature is not mentioned
41726 in the @samp{qSupported} response. The default values are fixed; a
41727 stub is free to omit any feature responses that match the defaults.
41728
41729 Not all features can be probed, but for those which can, the probing
41730 mechanism is useful: in some cases, a stub's internal
41731 architecture may not allow the protocol layer to know some information
41732 about the underlying target in advance. This is especially common in
41733 stubs which may be configured for multiple targets.
41734
41735 These are the currently defined stub features and their properties:
41736
41737 @multitable @columnfractions 0.35 0.2 0.12 0.2
41738 @c NOTE: The first row should be @headitem, but we do not yet require
41739 @c a new enough version of Texinfo (4.7) to use @headitem.
41740 @item Feature Name
41741 @tab Value Required
41742 @tab Default
41743 @tab Probe Allowed
41744
41745 @item @samp{PacketSize}
41746 @tab Yes
41747 @tab @samp{-}
41748 @tab No
41749
41750 @item @samp{qXfer:auxv:read}
41751 @tab No
41752 @tab @samp{-}
41753 @tab Yes
41754
41755 @item @samp{qXfer:btrace:read}
41756 @tab No
41757 @tab @samp{-}
41758 @tab Yes
41759
41760 @item @samp{qXfer:btrace-conf:read}
41761 @tab No
41762 @tab @samp{-}
41763 @tab Yes
41764
41765 @item @samp{qXfer:exec-file:read}
41766 @tab No
41767 @tab @samp{-}
41768 @tab Yes
41769
41770 @item @samp{qXfer:features:read}
41771 @tab No
41772 @tab @samp{-}
41773 @tab Yes
41774
41775 @item @samp{qXfer:libraries:read}
41776 @tab No
41777 @tab @samp{-}
41778 @tab Yes
41779
41780 @item @samp{qXfer:libraries-svr4:read}
41781 @tab No
41782 @tab @samp{-}
41783 @tab Yes
41784
41785 @item @samp{augmented-libraries-svr4-read}
41786 @tab No
41787 @tab @samp{-}
41788 @tab No
41789
41790 @item @samp{qXfer:memory-map:read}
41791 @tab No
41792 @tab @samp{-}
41793 @tab Yes
41794
41795 @item @samp{qXfer:sdata:read}
41796 @tab No
41797 @tab @samp{-}
41798 @tab Yes
41799
41800 @item @samp{qXfer:siginfo:read}
41801 @tab No
41802 @tab @samp{-}
41803 @tab Yes
41804
41805 @item @samp{qXfer:siginfo:write}
41806 @tab No
41807 @tab @samp{-}
41808 @tab Yes
41809
41810 @item @samp{qXfer:threads:read}
41811 @tab No
41812 @tab @samp{-}
41813 @tab Yes
41814
41815 @item @samp{qXfer:traceframe-info:read}
41816 @tab No
41817 @tab @samp{-}
41818 @tab Yes
41819
41820 @item @samp{qXfer:uib:read}
41821 @tab No
41822 @tab @samp{-}
41823 @tab Yes
41824
41825 @item @samp{qXfer:fdpic:read}
41826 @tab No
41827 @tab @samp{-}
41828 @tab Yes
41829
41830 @item @samp{Qbtrace:off}
41831 @tab Yes
41832 @tab @samp{-}
41833 @tab Yes
41834
41835 @item @samp{Qbtrace:bts}
41836 @tab Yes
41837 @tab @samp{-}
41838 @tab Yes
41839
41840 @item @samp{Qbtrace:pt}
41841 @tab Yes
41842 @tab @samp{-}
41843 @tab Yes
41844
41845 @item @samp{Qbtrace-conf:bts:size}
41846 @tab Yes
41847 @tab @samp{-}
41848 @tab Yes
41849
41850 @item @samp{Qbtrace-conf:pt:size}
41851 @tab Yes
41852 @tab @samp{-}
41853 @tab Yes
41854
41855 @item @samp{QNonStop}
41856 @tab No
41857 @tab @samp{-}
41858 @tab Yes
41859
41860 @item @samp{QCatchSyscalls}
41861 @tab No
41862 @tab @samp{-}
41863 @tab Yes
41864
41865 @item @samp{QPassSignals}
41866 @tab No
41867 @tab @samp{-}
41868 @tab Yes
41869
41870 @item @samp{QStartNoAckMode}
41871 @tab No
41872 @tab @samp{-}
41873 @tab Yes
41874
41875 @item @samp{multiprocess}
41876 @tab No
41877 @tab @samp{-}
41878 @tab No
41879
41880 @item @samp{ConditionalBreakpoints}
41881 @tab No
41882 @tab @samp{-}
41883 @tab No
41884
41885 @item @samp{ConditionalTracepoints}
41886 @tab No
41887 @tab @samp{-}
41888 @tab No
41889
41890 @item @samp{ReverseContinue}
41891 @tab No
41892 @tab @samp{-}
41893 @tab No
41894
41895 @item @samp{ReverseStep}
41896 @tab No
41897 @tab @samp{-}
41898 @tab No
41899
41900 @item @samp{TracepointSource}
41901 @tab No
41902 @tab @samp{-}
41903 @tab No
41904
41905 @item @samp{QAgent}
41906 @tab No
41907 @tab @samp{-}
41908 @tab No
41909
41910 @item @samp{QAllow}
41911 @tab No
41912 @tab @samp{-}
41913 @tab No
41914
41915 @item @samp{QDisableRandomization}
41916 @tab No
41917 @tab @samp{-}
41918 @tab No
41919
41920 @item @samp{EnableDisableTracepoints}
41921 @tab No
41922 @tab @samp{-}
41923 @tab No
41924
41925 @item @samp{QTBuffer:size}
41926 @tab No
41927 @tab @samp{-}
41928 @tab No
41929
41930 @item @samp{tracenz}
41931 @tab No
41932 @tab @samp{-}
41933 @tab No
41934
41935 @item @samp{BreakpointCommands}
41936 @tab No
41937 @tab @samp{-}
41938 @tab No
41939
41940 @item @samp{swbreak}
41941 @tab No
41942 @tab @samp{-}
41943 @tab No
41944
41945 @item @samp{hwbreak}
41946 @tab No
41947 @tab @samp{-}
41948 @tab No
41949
41950 @item @samp{fork-events}
41951 @tab No
41952 @tab @samp{-}
41953 @tab No
41954
41955 @item @samp{vfork-events}
41956 @tab No
41957 @tab @samp{-}
41958 @tab No
41959
41960 @item @samp{exec-events}
41961 @tab No
41962 @tab @samp{-}
41963 @tab No
41964
41965 @item @samp{QThreadEvents}
41966 @tab No
41967 @tab @samp{-}
41968 @tab No
41969
41970 @item @samp{no-resumed}
41971 @tab No
41972 @tab @samp{-}
41973 @tab No
41974
41975 @item @samp{memory-tagging}
41976 @tab No
41977 @tab @samp{-}
41978 @tab No
41979
41980 @end multitable
41981
41982 These are the currently defined stub features, in more detail:
41983
41984 @table @samp
41985 @cindex packet size, remote protocol
41986 @item PacketSize=@var{bytes}
41987 The remote stub can accept packets up to at least @var{bytes} in
41988 length. @value{GDBN} will send packets up to this size for bulk
41989 transfers, and will never send larger packets. This is a limit on the
41990 data characters in the packet, including the frame and checksum.
41991 There is no trailing NUL byte in a remote protocol packet; if the stub
41992 stores packets in a NUL-terminated format, it should allow an extra
41993 byte in its buffer for the NUL. If this stub feature is not supported,
41994 @value{GDBN} guesses based on the size of the @samp{g} packet response.
41995
41996 @item qXfer:auxv:read
41997 The remote stub understands the @samp{qXfer:auxv:read} packet
41998 (@pxref{qXfer auxiliary vector read}).
41999
42000 @item qXfer:btrace:read
42001 The remote stub understands the @samp{qXfer:btrace:read}
42002 packet (@pxref{qXfer btrace read}).
42003
42004 @item qXfer:btrace-conf:read
42005 The remote stub understands the @samp{qXfer:btrace-conf:read}
42006 packet (@pxref{qXfer btrace-conf read}).
42007
42008 @item qXfer:exec-file:read
42009 The remote stub understands the @samp{qXfer:exec-file:read} packet
42010 (@pxref{qXfer executable filename read}).
42011
42012 @item qXfer:features:read
42013 The remote stub understands the @samp{qXfer:features:read} packet
42014 (@pxref{qXfer target description read}).
42015
42016 @item qXfer:libraries:read
42017 The remote stub understands the @samp{qXfer:libraries:read} packet
42018 (@pxref{qXfer library list read}).
42019
42020 @item qXfer:libraries-svr4:read
42021 The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
42022 (@pxref{qXfer svr4 library list read}).
42023
42024 @item augmented-libraries-svr4-read
42025 The remote stub understands the augmented form of the
42026 @samp{qXfer:libraries-svr4:read} packet
42027 (@pxref{qXfer svr4 library list read}).
42028
42029 @item qXfer:memory-map:read
42030 The remote stub understands the @samp{qXfer:memory-map:read} packet
42031 (@pxref{qXfer memory map read}).
42032
42033 @item qXfer:sdata:read
42034 The remote stub understands the @samp{qXfer:sdata:read} packet
42035 (@pxref{qXfer sdata read}).
42036
42037 @item qXfer:siginfo:read
42038 The remote stub understands the @samp{qXfer:siginfo:read} packet
42039 (@pxref{qXfer siginfo read}).
42040
42041 @item qXfer:siginfo:write
42042 The remote stub understands the @samp{qXfer:siginfo:write} packet
42043 (@pxref{qXfer siginfo write}).
42044
42045 @item qXfer:threads:read
42046 The remote stub understands the @samp{qXfer:threads:read} packet
42047 (@pxref{qXfer threads read}).
42048
42049 @item qXfer:traceframe-info:read
42050 The remote stub understands the @samp{qXfer:traceframe-info:read}
42051 packet (@pxref{qXfer traceframe info read}).
42052
42053 @item qXfer:uib:read
42054 The remote stub understands the @samp{qXfer:uib:read}
42055 packet (@pxref{qXfer unwind info block}).
42056
42057 @item qXfer:fdpic:read
42058 The remote stub understands the @samp{qXfer:fdpic:read}
42059 packet (@pxref{qXfer fdpic loadmap read}).
42060
42061 @item QNonStop
42062 The remote stub understands the @samp{QNonStop} packet
42063 (@pxref{QNonStop}).
42064
42065 @item QCatchSyscalls
42066 The remote stub understands the @samp{QCatchSyscalls} packet
42067 (@pxref{QCatchSyscalls}).
42068
42069 @item QPassSignals
42070 The remote stub understands the @samp{QPassSignals} packet
42071 (@pxref{QPassSignals}).
42072
42073 @item QStartNoAckMode
42074 The remote stub understands the @samp{QStartNoAckMode} packet and
42075 prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
42076
42077 @item multiprocess
42078 @anchor{multiprocess extensions}
42079 @cindex multiprocess extensions, in remote protocol
42080 The remote stub understands the multiprocess extensions to the remote
42081 protocol syntax. The multiprocess extensions affect the syntax of
42082 thread IDs in both packets and replies (@pxref{thread-id syntax}), and
42083 add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
42084 replies. Note that reporting this feature indicates support for the
42085 syntactic extensions only, not that the stub necessarily supports
42086 debugging of more than one process at a time. The stub must not use
42087 multiprocess extensions in packet replies unless @value{GDBN} has also
42088 indicated it supports them in its @samp{qSupported} request.
42089
42090 @item qXfer:osdata:read
42091 The remote stub understands the @samp{qXfer:osdata:read} packet
42092 ((@pxref{qXfer osdata read}).
42093
42094 @item ConditionalBreakpoints
42095 The target accepts and implements evaluation of conditional expressions
42096 defined for breakpoints. The target will only report breakpoint triggers
42097 when such conditions are true (@pxref{Conditions, ,Break Conditions}).
42098
42099 @item ConditionalTracepoints
42100 The remote stub accepts and implements conditional expressions defined
42101 for tracepoints (@pxref{Tracepoint Conditions}).
42102
42103 @item ReverseContinue
42104 The remote stub accepts and implements the reverse continue packet
42105 (@pxref{bc}).
42106
42107 @item ReverseStep
42108 The remote stub accepts and implements the reverse step packet
42109 (@pxref{bs}).
42110
42111 @item TracepointSource
42112 The remote stub understands the @samp{QTDPsrc} packet that supplies
42113 the source form of tracepoint definitions.
42114
42115 @item QAgent
42116 The remote stub understands the @samp{QAgent} packet.
42117
42118 @item QAllow
42119 The remote stub understands the @samp{QAllow} packet.
42120
42121 @item QDisableRandomization
42122 The remote stub understands the @samp{QDisableRandomization} packet.
42123
42124 @item StaticTracepoint
42125 @cindex static tracepoints, in remote protocol
42126 The remote stub supports static tracepoints.
42127
42128 @item InstallInTrace
42129 @anchor{install tracepoint in tracing}
42130 The remote stub supports installing tracepoint in tracing.
42131
42132 @item EnableDisableTracepoints
42133 The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
42134 @samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
42135 to be enabled and disabled while a trace experiment is running.
42136
42137 @item QTBuffer:size
42138 The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
42139 packet that allows to change the size of the trace buffer.
42140
42141 @item tracenz
42142 @cindex string tracing, in remote protocol
42143 The remote stub supports the @samp{tracenz} bytecode for collecting strings.
42144 See @ref{Bytecode Descriptions} for details about the bytecode.
42145
42146 @item BreakpointCommands
42147 @cindex breakpoint commands, in remote protocol
42148 The remote stub supports running a breakpoint's command list itself,
42149 rather than reporting the hit to @value{GDBN}.
42150
42151 @item Qbtrace:off
42152 The remote stub understands the @samp{Qbtrace:off} packet.
42153
42154 @item Qbtrace:bts
42155 The remote stub understands the @samp{Qbtrace:bts} packet.
42156
42157 @item Qbtrace:pt
42158 The remote stub understands the @samp{Qbtrace:pt} packet.
42159
42160 @item Qbtrace-conf:bts:size
42161 The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
42162
42163 @item Qbtrace-conf:pt:size
42164 The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
42165
42166 @item swbreak
42167 The remote stub reports the @samp{swbreak} stop reason for memory
42168 breakpoints.
42169
42170 @item hwbreak
42171 The remote stub reports the @samp{hwbreak} stop reason for hardware
42172 breakpoints.
42173
42174 @item fork-events
42175 The remote stub reports the @samp{fork} stop reason for fork events.
42176
42177 @item vfork-events
42178 The remote stub reports the @samp{vfork} stop reason for vfork events
42179 and vforkdone events.
42180
42181 @item exec-events
42182 The remote stub reports the @samp{exec} stop reason for exec events.
42183
42184 @item vContSupported
42185 The remote stub reports the supported actions in the reply to
42186 @samp{vCont?} packet.
42187
42188 @item QThreadEvents
42189 The remote stub understands the @samp{QThreadEvents} packet.
42190
42191 @item no-resumed
42192 The remote stub reports the @samp{N} stop reply.
42193
42194
42195 @item memory-tagging
42196 The remote stub supports and implements the required memory tagging
42197 functionality and understands the @samp{qMemTags} (@pxref{qMemTags}) and
42198 @samp{QMemTags} (@pxref{QMemTags}) packets.
42199
42200 For AArch64 GNU/Linux systems, this feature also requires access to the
42201 @file{/proc/@var{pid}/smaps} file so memory mapping page flags can be inspected.
42202 This is done via the @samp{vFile} requests.
42203
42204 @end table
42205
42206 @item qSymbol::
42207 @cindex symbol lookup, remote request
42208 @cindex @samp{qSymbol} packet
42209 Notify the target that @value{GDBN} is prepared to serve symbol lookup
42210 requests. Accept requests from the target for the values of symbols.
42211
42212 Reply:
42213 @table @samp
42214 @item OK
42215 The target does not need to look up any (more) symbols.
42216 @item qSymbol:@var{sym_name}
42217 The target requests the value of symbol @var{sym_name} (hex encoded).
42218 @value{GDBN} may provide the value by using the
42219 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
42220 below.
42221 @end table
42222
42223 @item qSymbol:@var{sym_value}:@var{sym_name}
42224 Set the value of @var{sym_name} to @var{sym_value}.
42225
42226 @var{sym_name} (hex encoded) is the name of a symbol whose value the
42227 target has previously requested.
42228
42229 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
42230 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
42231 will be empty.
42232
42233 Reply:
42234 @table @samp
42235 @item OK
42236 The target does not need to look up any (more) symbols.
42237 @item qSymbol:@var{sym_name}
42238 The target requests the value of a new symbol @var{sym_name} (hex
42239 encoded). @value{GDBN} will continue to supply the values of symbols
42240 (if available), until the target ceases to request them.
42241 @end table
42242
42243 @item qTBuffer
42244 @itemx QTBuffer
42245 @itemx QTDisconnected
42246 @itemx QTDP
42247 @itemx QTDPsrc
42248 @itemx QTDV
42249 @itemx qTfP
42250 @itemx qTfV
42251 @itemx QTFrame
42252 @itemx qTMinFTPILen
42253
42254 @xref{Tracepoint Packets}.
42255
42256 @item qThreadExtraInfo,@var{thread-id}
42257 @cindex thread attributes info, remote request
42258 @cindex @samp{qThreadExtraInfo} packet
42259 Obtain from the target OS a printable string description of thread
42260 attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
42261 for the forms of @var{thread-id}. This
42262 string may contain anything that the target OS thinks is interesting
42263 for @value{GDBN} to tell the user about the thread. The string is
42264 displayed in @value{GDBN}'s @code{info threads} display. Some
42265 examples of possible thread extra info strings are @samp{Runnable}, or
42266 @samp{Blocked on Mutex}.
42267
42268 Reply:
42269 @table @samp
42270 @item @var{XX}@dots{}
42271 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
42272 comprising the printable string containing the extra information about
42273 the thread's attributes.
42274 @end table
42275
42276 (Note that the @code{qThreadExtraInfo} packet's name is separated from
42277 the command by a @samp{,}, not a @samp{:}, contrary to the naming
42278 conventions above. Please don't use this packet as a model for new
42279 packets.)
42280
42281 @item QTNotes
42282 @itemx qTP
42283 @itemx QTSave
42284 @itemx qTsP
42285 @itemx qTsV
42286 @itemx QTStart
42287 @itemx QTStop
42288 @itemx QTEnable
42289 @itemx QTDisable
42290 @itemx QTinit
42291 @itemx QTro
42292 @itemx qTStatus
42293 @itemx qTV
42294 @itemx qTfSTM
42295 @itemx qTsSTM
42296 @itemx qTSTMat
42297 @xref{Tracepoint Packets}.
42298
42299 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
42300 @cindex read special object, remote request
42301 @cindex @samp{qXfer} packet
42302 @anchor{qXfer read}
42303 Read uninterpreted bytes from the target's special data area
42304 identified by the keyword @var{object}. Request @var{length} bytes
42305 starting at @var{offset} bytes into the data. The content and
42306 encoding of @var{annex} is specific to @var{object}; it can supply
42307 additional details about what data to access.
42308
42309 Reply:
42310 @table @samp
42311 @item m @var{data}
42312 Data @var{data} (@pxref{Binary Data}) has been read from the
42313 target. There may be more data at a higher address (although
42314 it is permitted to return @samp{m} even for the last valid
42315 block of data, as long as at least one byte of data was read).
42316 It is possible for @var{data} to have fewer bytes than the @var{length} in the
42317 request.
42318
42319 @item l @var{data}
42320 Data @var{data} (@pxref{Binary Data}) has been read from the target.
42321 There is no more data to be read. It is possible for @var{data} to
42322 have fewer bytes than the @var{length} in the request.
42323
42324 @item l
42325 The @var{offset} in the request is at the end of the data.
42326 There is no more data to be read.
42327
42328 @item E00
42329 The request was malformed, or @var{annex} was invalid.
42330
42331 @item E @var{nn}
42332 The offset was invalid, or there was an error encountered reading the data.
42333 The @var{nn} part is a hex-encoded @code{errno} value.
42334
42335 @item @w{}
42336 An empty reply indicates the @var{object} string was not recognized by
42337 the stub, or that the object does not support reading.
42338 @end table
42339
42340 Here are the specific requests of this form defined so far. All the
42341 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
42342 formats, listed above.
42343
42344 @table @samp
42345 @item qXfer:auxv:read::@var{offset},@var{length}
42346 @anchor{qXfer auxiliary vector read}
42347 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
42348 auxiliary vector}. Note @var{annex} must be empty.
42349
42350 This packet is not probed by default; the remote stub must request it,
42351 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42352
42353 @item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
42354 @anchor{qXfer btrace read}
42355
42356 Return a description of the current branch trace.
42357 @xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
42358 packet may have one of the following values:
42359
42360 @table @code
42361 @item all
42362 Returns all available branch trace.
42363
42364 @item new
42365 Returns all available branch trace if the branch trace changed since
42366 the last read request.
42367
42368 @item delta
42369 Returns the new branch trace since the last read request. Adds a new
42370 block to the end of the trace that begins at zero and ends at the source
42371 location of the first branch in the trace buffer. This extra block is
42372 used to stitch traces together.
42373
42374 If the trace buffer overflowed, returns an error indicating the overflow.
42375 @end table
42376
42377 This packet is not probed by default; the remote stub must request it
42378 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42379
42380 @item qXfer:btrace-conf:read::@var{offset},@var{length}
42381 @anchor{qXfer btrace-conf read}
42382
42383 Return a description of the current branch trace configuration.
42384 @xref{Branch Trace Configuration Format}.
42385
42386 This packet is not probed by default; the remote stub must request it
42387 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42388
42389 @item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
42390 @anchor{qXfer executable filename read}
42391 Return the full absolute name of the file that was executed to create
42392 a process running on the remote system. The annex specifies the
42393 numeric process ID of the process to query, encoded as a hexadecimal
42394 number. If the annex part is empty the remote stub should return the
42395 filename corresponding to the currently executing process.
42396
42397 This packet is not probed by default; the remote stub must request it,
42398 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42399
42400 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
42401 @anchor{qXfer target description read}
42402 Access the @dfn{target description}. @xref{Target Descriptions}. The
42403 annex specifies which XML document to access. The main description is
42404 always loaded from the @samp{target.xml} annex.
42405
42406 This packet is not probed by default; the remote stub must request it,
42407 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42408
42409 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
42410 @anchor{qXfer library list read}
42411 Access the target's list of loaded libraries. @xref{Library List Format}.
42412 The annex part of the generic @samp{qXfer} packet must be empty
42413 (@pxref{qXfer read}).
42414
42415 Targets which maintain a list of libraries in the program's memory do
42416 not need to implement this packet; it is designed for platforms where
42417 the operating system manages the list of loaded libraries.
42418
42419 This packet is not probed by default; the remote stub must request it,
42420 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42421
42422 @item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
42423 @anchor{qXfer svr4 library list read}
42424 Access the target's list of loaded libraries when the target is an SVR4
42425 platform. @xref{Library List Format for SVR4 Targets}. The annex part
42426 of the generic @samp{qXfer} packet must be empty unless the remote
42427 stub indicated it supports the augmented form of this packet
42428 by supplying an appropriate @samp{qSupported} response
42429 (@pxref{qXfer read}, @ref{qSupported}).
42430
42431 This packet is optional for better performance on SVR4 targets.
42432 @value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
42433
42434 This packet is not probed by default; the remote stub must request it,
42435 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42436
42437 If the remote stub indicates it supports the augmented form of this
42438 packet then the annex part of the generic @samp{qXfer} packet may
42439 contain a semicolon-separated list of @samp{@var{name}=@var{value}}
42440 arguments. The currently supported arguments are:
42441
42442 @table @code
42443 @item start=@var{address}
42444 A hexadecimal number specifying the address of the @samp{struct
42445 link_map} to start reading the library list from. If unset or zero
42446 then the first @samp{struct link_map} in the library list will be
42447 chosen as the starting point.
42448
42449 @item prev=@var{address}
42450 A hexadecimal number specifying the address of the @samp{struct
42451 link_map} immediately preceding the @samp{struct link_map}
42452 specified by the @samp{start} argument. If unset or zero then
42453 the remote stub will expect that no @samp{struct link_map}
42454 exists prior to the starting point.
42455
42456 @end table
42457
42458 Arguments that are not understood by the remote stub will be silently
42459 ignored.
42460
42461 @item qXfer:memory-map:read::@var{offset},@var{length}
42462 @anchor{qXfer memory map read}
42463 Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
42464 annex part of the generic @samp{qXfer} packet must be empty
42465 (@pxref{qXfer read}).
42466
42467 This packet is not probed by default; the remote stub must request it,
42468 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42469
42470 @item qXfer:sdata:read::@var{offset},@var{length}
42471 @anchor{qXfer sdata read}
42472
42473 Read contents of the extra collected static tracepoint marker
42474 information. The annex part of the generic @samp{qXfer} packet must
42475 be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
42476 Action Lists}.
42477
42478 This packet is not probed by default; the remote stub must request it,
42479 by supplying an appropriate @samp{qSupported} response
42480 (@pxref{qSupported}).
42481
42482 @item qXfer:siginfo:read::@var{offset},@var{length}
42483 @anchor{qXfer siginfo read}
42484 Read contents of the extra signal information on the target
42485 system. The annex part of the generic @samp{qXfer} packet must be
42486 empty (@pxref{qXfer read}).
42487
42488 This packet is not probed by default; the remote stub must request it,
42489 by supplying an appropriate @samp{qSupported} response
42490 (@pxref{qSupported}).
42491
42492 @item qXfer:threads:read::@var{offset},@var{length}
42493 @anchor{qXfer threads read}
42494 Access the list of threads on target. @xref{Thread List Format}. The
42495 annex part of the generic @samp{qXfer} packet must be empty
42496 (@pxref{qXfer read}).
42497
42498 This packet is not probed by default; the remote stub must request it,
42499 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42500
42501 @item qXfer:traceframe-info:read::@var{offset},@var{length}
42502 @anchor{qXfer traceframe info read}
42503
42504 Return a description of the current traceframe's contents.
42505 @xref{Traceframe Info Format}. The annex part of the generic
42506 @samp{qXfer} packet must be empty (@pxref{qXfer read}).
42507
42508 This packet is not probed by default; the remote stub must request it,
42509 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42510
42511 @item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
42512 @anchor{qXfer unwind info block}
42513
42514 Return the unwind information block for @var{pc}. This packet is used
42515 on OpenVMS/ia64 to ask the kernel unwind information.
42516
42517 This packet is not probed by default.
42518
42519 @item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
42520 @anchor{qXfer fdpic loadmap read}
42521 Read contents of @code{loadmap}s on the target system. The
42522 annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
42523 executable @code{loadmap} or interpreter @code{loadmap} to read.
42524
42525 This packet is not probed by default; the remote stub must request it,
42526 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
42527
42528 @item qXfer:osdata:read::@var{offset},@var{length}
42529 @anchor{qXfer osdata read}
42530 Access the target's @dfn{operating system information}.
42531 @xref{Operating System Information}.
42532
42533 @end table
42534
42535 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
42536 @cindex write data into object, remote request
42537 @anchor{qXfer write}
42538 Write uninterpreted bytes into the target's special data area
42539 identified by the keyword @var{object}, starting at @var{offset} bytes
42540 into the data. The binary-encoded data (@pxref{Binary Data}) to be
42541 written is given by @var{data}@dots{}. The content and encoding of @var{annex}
42542 is specific to @var{object}; it can supply additional details about what data
42543 to access.
42544
42545 Reply:
42546 @table @samp
42547 @item @var{nn}
42548 @var{nn} (hex encoded) is the number of bytes written.
42549 This may be fewer bytes than supplied in the request.
42550
42551 @item E00
42552 The request was malformed, or @var{annex} was invalid.
42553
42554 @item E @var{nn}
42555 The offset was invalid, or there was an error encountered writing the data.
42556 The @var{nn} part is a hex-encoded @code{errno} value.
42557
42558 @item @w{}
42559 An empty reply indicates the @var{object} string was not
42560 recognized by the stub, or that the object does not support writing.
42561 @end table
42562
42563 Here are the specific requests of this form defined so far. All the
42564 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
42565 formats, listed above.
42566
42567 @table @samp
42568 @item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
42569 @anchor{qXfer siginfo write}
42570 Write @var{data} to the extra signal information on the target system.
42571 The annex part of the generic @samp{qXfer} packet must be
42572 empty (@pxref{qXfer write}).
42573
42574 This packet is not probed by default; the remote stub must request it,
42575 by supplying an appropriate @samp{qSupported} response
42576 (@pxref{qSupported}).
42577 @end table
42578
42579 @item qXfer:@var{object}:@var{operation}:@dots{}
42580 Requests of this form may be added in the future. When a stub does
42581 not recognize the @var{object} keyword, or its support for
42582 @var{object} does not recognize the @var{operation} keyword, the stub
42583 must respond with an empty packet.
42584
42585 @item qAttached:@var{pid}
42586 @cindex query attached, remote request
42587 @cindex @samp{qAttached} packet
42588 Return an indication of whether the remote server attached to an
42589 existing process or created a new process. When the multiprocess
42590 protocol extensions are supported (@pxref{multiprocess extensions}),
42591 @var{pid} is an integer in hexadecimal format identifying the target
42592 process. Otherwise, @value{GDBN} will omit the @var{pid} field and
42593 the query packet will be simplified as @samp{qAttached}.
42594
42595 This query is used, for example, to know whether the remote process
42596 should be detached or killed when a @value{GDBN} session is ended with
42597 the @code{quit} command.
42598
42599 Reply:
42600 @table @samp
42601 @item 1
42602 The remote server attached to an existing process.
42603 @item 0
42604 The remote server created a new process.
42605 @item E @var{NN}
42606 A badly formed request or an error was encountered.
42607 @end table
42608
42609 @item Qbtrace:bts
42610 Enable branch tracing for the current thread using Branch Trace Store.
42611
42612 Reply:
42613 @table @samp
42614 @item OK
42615 Branch tracing has been enabled.
42616 @item E.errtext
42617 A badly formed request or an error was encountered.
42618 @end table
42619
42620 @item Qbtrace:pt
42621 Enable branch tracing for the current thread using Intel Processor Trace.
42622
42623 Reply:
42624 @table @samp
42625 @item OK
42626 Branch tracing has been enabled.
42627 @item E.errtext
42628 A badly formed request or an error was encountered.
42629 @end table
42630
42631 @item Qbtrace:off
42632 Disable branch tracing for the current thread.
42633
42634 Reply:
42635 @table @samp
42636 @item OK
42637 Branch tracing has been disabled.
42638 @item E.errtext
42639 A badly formed request or an error was encountered.
42640 @end table
42641
42642 @item Qbtrace-conf:bts:size=@var{value}
42643 Set the requested ring buffer size for new threads that use the
42644 btrace recording method in bts format.
42645
42646 Reply:
42647 @table @samp
42648 @item OK
42649 The ring buffer size has been set.
42650 @item E.errtext
42651 A badly formed request or an error was encountered.
42652 @end table
42653
42654 @item Qbtrace-conf:pt:size=@var{value}
42655 Set the requested ring buffer size for new threads that use the
42656 btrace recording method in pt format.
42657
42658 Reply:
42659 @table @samp
42660 @item OK
42661 The ring buffer size has been set.
42662 @item E.errtext
42663 A badly formed request or an error was encountered.
42664 @end table
42665
42666 @end table
42667
42668 @node Architecture-Specific Protocol Details
42669 @section Architecture-Specific Protocol Details
42670
42671 This section describes how the remote protocol is applied to specific
42672 target architectures. Also see @ref{Standard Target Features}, for
42673 details of XML target descriptions for each architecture.
42674
42675 @menu
42676 * ARM-Specific Protocol Details::
42677 * MIPS-Specific Protocol Details::
42678 @end menu
42679
42680 @node ARM-Specific Protocol Details
42681 @subsection @acronym{ARM}-specific Protocol Details
42682
42683 @menu
42684 * ARM Breakpoint Kinds::
42685 * ARM Memory Tag Types::
42686 @end menu
42687
42688 @node ARM Breakpoint Kinds
42689 @subsubsection @acronym{ARM} Breakpoint Kinds
42690 @cindex breakpoint kinds, @acronym{ARM}
42691
42692 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42693
42694 @table @r
42695
42696 @item 2
42697 16-bit Thumb mode breakpoint.
42698
42699 @item 3
42700 32-bit Thumb mode (Thumb-2) breakpoint.
42701
42702 @item 4
42703 32-bit @acronym{ARM} mode breakpoint.
42704
42705 @end table
42706
42707 @node ARM Memory Tag Types
42708 @subsubsection @acronym{ARM} Memory Tag Types
42709 @cindex memory tag types, @acronym{ARM}
42710
42711 These memory tag types are defined for the @samp{qMemTag} and @samp{QMemTag}
42712 packets.
42713
42714 @table @r
42715
42716 @item 0
42717 MTE logical tag
42718
42719 @item 1
42720 MTE allocation tag
42721
42722 @end table
42723
42724 @node MIPS-Specific Protocol Details
42725 @subsection @acronym{MIPS}-specific Protocol Details
42726
42727 @menu
42728 * MIPS Register packet Format::
42729 * MIPS Breakpoint Kinds::
42730 @end menu
42731
42732 @node MIPS Register packet Format
42733 @subsubsection @acronym{MIPS} Register Packet Format
42734 @cindex register packet format, @acronym{MIPS}
42735
42736 The following @code{g}/@code{G} packets have previously been defined.
42737 In the below, some thirty-two bit registers are transferred as
42738 sixty-four bits. Those registers should be zero/sign extended (which?)
42739 to fill the space allocated. Register bytes are transferred in target
42740 byte order. The two nibbles within a register byte are transferred
42741 most-significant -- least-significant.
42742
42743 @table @r
42744
42745 @item MIPS32
42746 All registers are transferred as thirty-two bit quantities in the order:
42747 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
42748 registers; fsr; fir; fp.
42749
42750 @item MIPS64
42751 All registers are transferred as sixty-four bit quantities (including
42752 thirty-two bit registers such as @code{sr}). The ordering is the same
42753 as @code{MIPS32}.
42754
42755 @end table
42756
42757 @node MIPS Breakpoint Kinds
42758 @subsubsection @acronym{MIPS} Breakpoint Kinds
42759 @cindex breakpoint kinds, @acronym{MIPS}
42760
42761 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42762
42763 @table @r
42764
42765 @item 2
42766 16-bit @acronym{MIPS16} mode breakpoint.
42767
42768 @item 3
42769 16-bit @acronym{microMIPS} mode breakpoint.
42770
42771 @item 4
42772 32-bit standard @acronym{MIPS} mode breakpoint.
42773
42774 @item 5
42775 32-bit @acronym{microMIPS} mode breakpoint.
42776
42777 @end table
42778
42779 @node Tracepoint Packets
42780 @section Tracepoint Packets
42781 @cindex tracepoint packets
42782 @cindex packets, tracepoint
42783
42784 Here we describe the packets @value{GDBN} uses to implement
42785 tracepoints (@pxref{Tracepoints}).
42786
42787 @table @samp
42788
42789 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
42790 @cindex @samp{QTDP} packet
42791 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
42792 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
42793 the tracepoint is disabled. The @var{step} gives the tracepoint's step
42794 count, and @var{pass} gives its pass count. If an @samp{F} is present,
42795 then the tracepoint is to be a fast tracepoint, and the @var{flen} is
42796 the number of bytes that the target should copy elsewhere to make room
42797 for the tracepoint. If an @samp{X} is present, it introduces a
42798 tracepoint condition, which consists of a hexadecimal length, followed
42799 by a comma and hex-encoded bytes, in a manner similar to action
42800 encodings as described below. If the trailing @samp{-} is present,
42801 further @samp{QTDP} packets will follow to specify this tracepoint's
42802 actions.
42803
42804 Replies:
42805 @table @samp
42806 @item OK
42807 The packet was understood and carried out.
42808 @item qRelocInsn
42809 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
42810 @item @w{}
42811 The packet was not recognized.
42812 @end table
42813
42814 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
42815 Define actions to be taken when a tracepoint is hit. The @var{n} and
42816 @var{addr} must be the same as in the initial @samp{QTDP} packet for
42817 this tracepoint. This packet may only be sent immediately after
42818 another @samp{QTDP} packet that ended with a @samp{-}. If the
42819 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
42820 specifying more actions for this tracepoint.
42821
42822 In the series of action packets for a given tracepoint, at most one
42823 can have an @samp{S} before its first @var{action}. If such a packet
42824 is sent, it and the following packets define ``while-stepping''
42825 actions. Any prior packets define ordinary actions --- that is, those
42826 taken when the tracepoint is first hit. If no action packet has an
42827 @samp{S}, then all the packets in the series specify ordinary
42828 tracepoint actions.
42829
42830 The @samp{@var{action}@dots{}} portion of the packet is a series of
42831 actions, concatenated without separators. Each action has one of the
42832 following forms:
42833
42834 @table @samp
42835
42836 @item R @var{mask}
42837 Collect the registers whose bits are set in @var{mask},
42838 a hexadecimal number whose @var{i}'th bit is set if register number
42839 @var{i} should be collected. (The least significant bit is numbered
42840 zero.) Note that @var{mask} may be any number of digits long; it may
42841 not fit in a 32-bit word.
42842
42843 @item M @var{basereg},@var{offset},@var{len}
42844 Collect @var{len} bytes of memory starting at the address in register
42845 number @var{basereg}, plus @var{offset}. If @var{basereg} is
42846 @samp{-1}, then the range has a fixed address: @var{offset} is the
42847 address of the lowest byte to collect. The @var{basereg},
42848 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
42849 values (the @samp{-1} value for @var{basereg} is a special case).
42850
42851 @item X @var{len},@var{expr}
42852 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
42853 it directs. The agent expression @var{expr} is as described in
42854 @ref{Agent Expressions}. Each byte of the expression is encoded as a
42855 two-digit hex number in the packet; @var{len} is the number of bytes
42856 in the expression (and thus one-half the number of hex digits in the
42857 packet).
42858
42859 @end table
42860
42861 Any number of actions may be packed together in a single @samp{QTDP}
42862 packet, as long as the packet does not exceed the maximum packet
42863 length (400 bytes, for many stubs). There may be only one @samp{R}
42864 action per tracepoint, and it must precede any @samp{M} or @samp{X}
42865 actions. Any registers referred to by @samp{M} and @samp{X} actions
42866 must be collected by a preceding @samp{R} action. (The
42867 ``while-stepping'' actions are treated as if they were attached to a
42868 separate tracepoint, as far as these restrictions are concerned.)
42869
42870 Replies:
42871 @table @samp
42872 @item OK
42873 The packet was understood and carried out.
42874 @item qRelocInsn
42875 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
42876 @item @w{}
42877 The packet was not recognized.
42878 @end table
42879
42880 @item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
42881 @cindex @samp{QTDPsrc} packet
42882 Specify a source string of tracepoint @var{n} at address @var{addr}.
42883 This is useful to get accurate reproduction of the tracepoints
42884 originally downloaded at the beginning of the trace run. The @var{type}
42885 is the name of the tracepoint part, such as @samp{cond} for the
42886 tracepoint's conditional expression (see below for a list of types), while
42887 @var{bytes} is the string, encoded in hexadecimal.
42888
42889 @var{start} is the offset of the @var{bytes} within the overall source
42890 string, while @var{slen} is the total length of the source string.
42891 This is intended for handling source strings that are longer than will
42892 fit in a single packet.
42893 @c Add detailed example when this info is moved into a dedicated
42894 @c tracepoint descriptions section.
42895
42896 The available string types are @samp{at} for the location,
42897 @samp{cond} for the conditional, and @samp{cmd} for an action command.
42898 @value{GDBN} sends a separate packet for each command in the action
42899 list, in the same order in which the commands are stored in the list.
42900
42901 The target does not need to do anything with source strings except
42902 report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
42903 query packets.
42904
42905 Although this packet is optional, and @value{GDBN} will only send it
42906 if the target replies with @samp{TracepointSource} @xref{General
42907 Query Packets}, it makes both disconnected tracing and trace files
42908 much easier to use. Otherwise the user must be careful that the
42909 tracepoints in effect while looking at trace frames are identical to
42910 the ones in effect during the trace run; even a small discrepancy
42911 could cause @samp{tdump} not to work, or a particular trace frame not
42912 be found.
42913
42914 @item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
42915 @cindex define trace state variable, remote request
42916 @cindex @samp{QTDV} packet
42917 Create a new trace state variable, number @var{n}, with an initial
42918 value of @var{value}, which is a 64-bit signed integer. Both @var{n}
42919 and @var{value} are encoded as hexadecimal values. @value{GDBN} has
42920 the option of not using this packet for initial values of zero; the
42921 target should simply create the trace state variables as they are
42922 mentioned in expressions. The value @var{builtin} should be 1 (one)
42923 if the trace state variable is builtin and 0 (zero) if it is not builtin.
42924 @value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
42925 @samp{qTsV} packet had it set. The contents of @var{name} is the
42926 hex-encoded name (without the leading @samp{$}) of the trace state
42927 variable.
42928
42929 @item QTFrame:@var{n}
42930 @cindex @samp{QTFrame} packet
42931 Select the @var{n}'th tracepoint frame from the buffer, and use the
42932 register and memory contents recorded there to answer subsequent
42933 request packets from @value{GDBN}.
42934
42935 A successful reply from the stub indicates that the stub has found the
42936 requested frame. The response is a series of parts, concatenated
42937 without separators, describing the frame we selected. Each part has
42938 one of the following forms:
42939
42940 @table @samp
42941 @item F @var{f}
42942 The selected frame is number @var{n} in the trace frame buffer;
42943 @var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
42944 was no frame matching the criteria in the request packet.
42945
42946 @item T @var{t}
42947 The selected trace frame records a hit of tracepoint number @var{t};
42948 @var{t} is a hexadecimal number.
42949
42950 @end table
42951
42952 @item QTFrame:pc:@var{addr}
42953 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42954 currently selected frame whose PC is @var{addr};
42955 @var{addr} is a hexadecimal number.
42956
42957 @item QTFrame:tdp:@var{t}
42958 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42959 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
42960 is a hexadecimal number.
42961
42962 @item QTFrame:range:@var{start}:@var{end}
42963 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42964 currently selected frame whose PC is between @var{start} (inclusive)
42965 and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
42966 numbers.
42967
42968 @item QTFrame:outside:@var{start}:@var{end}
42969 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
42970 frame @emph{outside} the given range of addresses (exclusive).
42971
42972 @item qTMinFTPILen
42973 @cindex @samp{qTMinFTPILen} packet
42974 This packet requests the minimum length of instruction at which a fast
42975 tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
42976 the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
42977 it depends on the target system being able to create trampolines in
42978 the first 64K of memory, which might or might not be possible for that
42979 system. So the reply to this packet will be 4 if it is able to
42980 arrange for that.
42981
42982 Replies:
42983
42984 @table @samp
42985 @item 0
42986 The minimum instruction length is currently unknown.
42987 @item @var{length}
42988 The minimum instruction length is @var{length}, where @var{length}
42989 is a hexadecimal number greater or equal to 1. A reply
42990 of 1 means that a fast tracepoint may be placed on any instruction
42991 regardless of size.
42992 @item E
42993 An error has occurred.
42994 @item @w{}
42995 An empty reply indicates that the request is not supported by the stub.
42996 @end table
42997
42998 @item QTStart
42999 @cindex @samp{QTStart} packet
43000 Begin the tracepoint experiment. Begin collecting data from
43001 tracepoint hits in the trace frame buffer. This packet supports the
43002 @samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
43003 instruction reply packet}).
43004
43005 @item QTStop
43006 @cindex @samp{QTStop} packet
43007 End the tracepoint experiment. Stop collecting trace frames.
43008
43009 @item QTEnable:@var{n}:@var{addr}
43010 @anchor{QTEnable}
43011 @cindex @samp{QTEnable} packet
43012 Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
43013 experiment. If the tracepoint was previously disabled, then collection
43014 of data from it will resume.
43015
43016 @item QTDisable:@var{n}:@var{addr}
43017 @anchor{QTDisable}
43018 @cindex @samp{QTDisable} packet
43019 Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
43020 experiment. No more data will be collected from the tracepoint unless
43021 @samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
43022
43023 @item QTinit
43024 @cindex @samp{QTinit} packet
43025 Clear the table of tracepoints, and empty the trace frame buffer.
43026
43027 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
43028 @cindex @samp{QTro} packet
43029 Establish the given ranges of memory as ``transparent''. The stub
43030 will answer requests for these ranges from memory's current contents,
43031 if they were not collected as part of the tracepoint hit.
43032
43033 @value{GDBN} uses this to mark read-only regions of memory, like those
43034 containing program code. Since these areas never change, they should
43035 still have the same contents they did when the tracepoint was hit, so
43036 there's no reason for the stub to refuse to provide their contents.
43037
43038 @item QTDisconnected:@var{value}
43039 @cindex @samp{QTDisconnected} packet
43040 Set the choice to what to do with the tracing run when @value{GDBN}
43041 disconnects from the target. A @var{value} of 1 directs the target to
43042 continue the tracing run, while 0 tells the target to stop tracing if
43043 @value{GDBN} is no longer in the picture.
43044
43045 @item qTStatus
43046 @cindex @samp{qTStatus} packet
43047 Ask the stub if there is a trace experiment running right now.
43048
43049 The reply has the form:
43050
43051 @table @samp
43052
43053 @item T@var{running}@r{[};@var{field}@r{]}@dots{}
43054 @var{running} is a single digit @code{1} if the trace is presently
43055 running, or @code{0} if not. It is followed by semicolon-separated
43056 optional fields that an agent may use to report additional status.
43057
43058 @end table
43059
43060 If the trace is not running, the agent may report any of several
43061 explanations as one of the optional fields:
43062
43063 @table @samp
43064
43065 @item tnotrun:0
43066 No trace has been run yet.
43067
43068 @item tstop[:@var{text}]:0
43069 The trace was stopped by a user-originated stop command. The optional
43070 @var{text} field is a user-supplied string supplied as part of the
43071 stop command (for instance, an explanation of why the trace was
43072 stopped manually). It is hex-encoded.
43073
43074 @item tfull:0
43075 The trace stopped because the trace buffer filled up.
43076
43077 @item tdisconnected:0
43078 The trace stopped because @value{GDBN} disconnected from the target.
43079
43080 @item tpasscount:@var{tpnum}
43081 The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
43082
43083 @item terror:@var{text}:@var{tpnum}
43084 The trace stopped because tracepoint @var{tpnum} had an error. The
43085 string @var{text} is available to describe the nature of the error
43086 (for instance, a divide by zero in the condition expression); it
43087 is hex encoded.
43088
43089 @item tunknown:0
43090 The trace stopped for some other reason.
43091
43092 @end table
43093
43094 Additional optional fields supply statistical and other information.
43095 Although not required, they are extremely useful for users monitoring
43096 the progress of a trace run. If a trace has stopped, and these
43097 numbers are reported, they must reflect the state of the just-stopped
43098 trace.
43099
43100 @table @samp
43101
43102 @item tframes:@var{n}
43103 The number of trace frames in the buffer.
43104
43105 @item tcreated:@var{n}
43106 The total number of trace frames created during the run. This may
43107 be larger than the trace frame count, if the buffer is circular.
43108
43109 @item tsize:@var{n}
43110 The total size of the trace buffer, in bytes.
43111
43112 @item tfree:@var{n}
43113 The number of bytes still unused in the buffer.
43114
43115 @item circular:@var{n}
43116 The value of the circular trace buffer flag. @code{1} means that the
43117 trace buffer is circular and old trace frames will be discarded if
43118 necessary to make room, @code{0} means that the trace buffer is linear
43119 and may fill up.
43120
43121 @item disconn:@var{n}
43122 The value of the disconnected tracing flag. @code{1} means that
43123 tracing will continue after @value{GDBN} disconnects, @code{0} means
43124 that the trace run will stop.
43125
43126 @end table
43127
43128 @item qTP:@var{tp}:@var{addr}
43129 @cindex tracepoint status, remote request
43130 @cindex @samp{qTP} packet
43131 Ask the stub for the current state of tracepoint number @var{tp} at
43132 address @var{addr}.
43133
43134 Replies:
43135 @table @samp
43136 @item V@var{hits}:@var{usage}
43137 The tracepoint has been hit @var{hits} times so far during the trace
43138 run, and accounts for @var{usage} in the trace buffer. Note that
43139 @code{while-stepping} steps are not counted as separate hits, but the
43140 steps' space consumption is added into the usage number.
43141
43142 @end table
43143
43144 @item qTV:@var{var}
43145 @cindex trace state variable value, remote request
43146 @cindex @samp{qTV} packet
43147 Ask the stub for the value of the trace state variable number @var{var}.
43148
43149 Replies:
43150 @table @samp
43151 @item V@var{value}
43152 The value of the variable is @var{value}. This will be the current
43153 value of the variable if the user is examining a running target, or a
43154 saved value if the variable was collected in the trace frame that the
43155 user is looking at. Note that multiple requests may result in
43156 different reply values, such as when requesting values while the
43157 program is running.
43158
43159 @item U
43160 The value of the variable is unknown. This would occur, for example,
43161 if the user is examining a trace frame in which the requested variable
43162 was not collected.
43163 @end table
43164
43165 @item qTfP
43166 @cindex @samp{qTfP} packet
43167 @itemx qTsP
43168 @cindex @samp{qTsP} packet
43169 These packets request data about tracepoints that are being used by
43170 the target. @value{GDBN} sends @code{qTfP} to get the first piece
43171 of data, and multiple @code{qTsP} to get additional pieces. Replies
43172 to these packets generally take the form of the @code{QTDP} packets
43173 that define tracepoints. (FIXME add detailed syntax)
43174
43175 @item qTfV
43176 @cindex @samp{qTfV} packet
43177 @itemx qTsV
43178 @cindex @samp{qTsV} packet
43179 These packets request data about trace state variables that are on the
43180 target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
43181 and multiple @code{qTsV} to get additional variables. Replies to
43182 these packets follow the syntax of the @code{QTDV} packets that define
43183 trace state variables.
43184
43185 @item qTfSTM
43186 @itemx qTsSTM
43187 @anchor{qTfSTM}
43188 @anchor{qTsSTM}
43189 @cindex @samp{qTfSTM} packet
43190 @cindex @samp{qTsSTM} packet
43191 These packets request data about static tracepoint markers that exist
43192 in the target program. @value{GDBN} sends @code{qTfSTM} to get the
43193 first piece of data, and multiple @code{qTsSTM} to get additional
43194 pieces. Replies to these packets take the following form:
43195
43196 Reply:
43197 @table @samp
43198 @item m @var{address}:@var{id}:@var{extra}
43199 A single marker
43200 @item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
43201 a comma-separated list of markers
43202 @item l
43203 (lower case letter @samp{L}) denotes end of list.
43204 @item E @var{nn}
43205 An error occurred. The error number @var{nn} is given as hex digits.
43206 @item @w{}
43207 An empty reply indicates that the request is not supported by the
43208 stub.
43209 @end table
43210
43211 The @var{address} is encoded in hex;
43212 @var{id} and @var{extra} are strings encoded in hex.
43213
43214 In response to each query, the target will reply with a list of one or
43215 more markers, separated by commas. @value{GDBN} will respond to each
43216 reply with a request for more markers (using the @samp{qs} form of the
43217 query), until the target responds with @samp{l} (lower-case ell, for
43218 @dfn{last}).
43219
43220 @item qTSTMat:@var{address}
43221 @anchor{qTSTMat}
43222 @cindex @samp{qTSTMat} packet
43223 This packets requests data about static tracepoint markers in the
43224 target program at @var{address}. Replies to this packet follow the
43225 syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
43226 tracepoint markers.
43227
43228 @item QTSave:@var{filename}
43229 @cindex @samp{QTSave} packet
43230 This packet directs the target to save trace data to the file name
43231 @var{filename} in the target's filesystem. The @var{filename} is encoded
43232 as a hex string; the interpretation of the file name (relative vs
43233 absolute, wild cards, etc) is up to the target.
43234
43235 @item qTBuffer:@var{offset},@var{len}
43236 @cindex @samp{qTBuffer} packet
43237 Return up to @var{len} bytes of the current contents of trace buffer,
43238 starting at @var{offset}. The trace buffer is treated as if it were
43239 a contiguous collection of traceframes, as per the trace file format.
43240 The reply consists as many hex-encoded bytes as the target can deliver
43241 in a packet; it is not an error to return fewer than were asked for.
43242 A reply consisting of just @code{l} indicates that no bytes are
43243 available.
43244
43245 @item QTBuffer:circular:@var{value}
43246 This packet directs the target to use a circular trace buffer if
43247 @var{value} is 1, or a linear buffer if the value is 0.
43248
43249 @item QTBuffer:size:@var{size}
43250 @anchor{QTBuffer-size}
43251 @cindex @samp{QTBuffer size} packet
43252 This packet directs the target to make the trace buffer be of size
43253 @var{size} if possible. A value of @code{-1} tells the target to
43254 use whatever size it prefers.
43255
43256 @item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
43257 @cindex @samp{QTNotes} packet
43258 This packet adds optional textual notes to the trace run. Allowable
43259 types include @code{user}, @code{notes}, and @code{tstop}, the
43260 @var{text} fields are arbitrary strings, hex-encoded.
43261
43262 @end table
43263
43264 @subsection Relocate instruction reply packet
43265 When installing fast tracepoints in memory, the target may need to
43266 relocate the instruction currently at the tracepoint address to a
43267 different address in memory. For most instructions, a simple copy is
43268 enough, but, for example, call instructions that implicitly push the
43269 return address on the stack, and relative branches or other
43270 PC-relative instructions require offset adjustment, so that the effect
43271 of executing the instruction at a different address is the same as if
43272 it had executed in the original location.
43273
43274 In response to several of the tracepoint packets, the target may also
43275 respond with a number of intermediate @samp{qRelocInsn} request
43276 packets before the final result packet, to have @value{GDBN} handle
43277 this relocation operation. If a packet supports this mechanism, its
43278 documentation will explicitly say so. See for example the above
43279 descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
43280 format of the request is:
43281
43282 @table @samp
43283 @item qRelocInsn:@var{from};@var{to}
43284
43285 This requests @value{GDBN} to copy instruction at address @var{from}
43286 to address @var{to}, possibly adjusted so that executing the
43287 instruction at @var{to} has the same effect as executing it at
43288 @var{from}. @value{GDBN} writes the adjusted instruction to target
43289 memory starting at @var{to}.
43290 @end table
43291
43292 Replies:
43293 @table @samp
43294 @item qRelocInsn:@var{adjusted_size}
43295 Informs the stub the relocation is complete. The @var{adjusted_size} is
43296 the length in bytes of resulting relocated instruction sequence.
43297 @item E @var{NN}
43298 A badly formed request was detected, or an error was encountered while
43299 relocating the instruction.
43300 @end table
43301
43302 @node Host I/O Packets
43303 @section Host I/O Packets
43304 @cindex Host I/O, remote protocol
43305 @cindex file transfer, remote protocol
43306
43307 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
43308 operations on the far side of a remote link. For example, Host I/O is
43309 used to upload and download files to a remote target with its own
43310 filesystem. Host I/O uses the same constant values and data structure
43311 layout as the target-initiated File-I/O protocol. However, the
43312 Host I/O packets are structured differently. The target-initiated
43313 protocol relies on target memory to store parameters and buffers.
43314 Host I/O requests are initiated by @value{GDBN}, and the
43315 target's memory is not involved. @xref{File-I/O Remote Protocol
43316 Extension}, for more details on the target-initiated protocol.
43317
43318 The Host I/O request packets all encode a single operation along with
43319 its arguments. They have this format:
43320
43321 @table @samp
43322
43323 @item vFile:@var{operation}: @var{parameter}@dots{}
43324 @var{operation} is the name of the particular request; the target
43325 should compare the entire packet name up to the second colon when checking
43326 for a supported operation. The format of @var{parameter} depends on
43327 the operation. Numbers are always passed in hexadecimal. Negative
43328 numbers have an explicit minus sign (i.e.@: two's complement is not
43329 used). Strings (e.g.@: filenames) are encoded as a series of
43330 hexadecimal bytes. The last argument to a system call may be a
43331 buffer of escaped binary data (@pxref{Binary Data}).
43332
43333 @end table
43334
43335 The valid responses to Host I/O packets are:
43336
43337 @table @samp
43338
43339 @item F @var{result} [, @var{errno}] [; @var{attachment}]
43340 @var{result} is the integer value returned by this operation, usually
43341 non-negative for success and -1 for errors. If an error has occured,
43342 @var{errno} will be included in the result specifying a
43343 value defined by the File-I/O protocol (@pxref{Errno Values}). For
43344 operations which return data, @var{attachment} supplies the data as a
43345 binary buffer. Binary buffers in response packets are escaped in the
43346 normal way (@pxref{Binary Data}). See the individual packet
43347 documentation for the interpretation of @var{result} and
43348 @var{attachment}.
43349
43350 @item @w{}
43351 An empty response indicates that this operation is not recognized.
43352
43353 @end table
43354
43355 These are the supported Host I/O operations:
43356
43357 @table @samp
43358 @item vFile:open: @var{filename}, @var{flags}, @var{mode}
43359 Open a file at @var{filename} and return a file descriptor for it, or
43360 return -1 if an error occurs. The @var{filename} is a string,
43361 @var{flags} is an integer indicating a mask of open flags
43362 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
43363 of mode bits to use if the file is created (@pxref{mode_t Values}).
43364 @xref{open}, for details of the open flags and mode values.
43365
43366 @item vFile:close: @var{fd}
43367 Close the open file corresponding to @var{fd} and return 0, or
43368 -1 if an error occurs.
43369
43370 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
43371 Read data from the open file corresponding to @var{fd}. Up to
43372 @var{count} bytes will be read from the file, starting at @var{offset}
43373 relative to the start of the file. The target may read fewer bytes;
43374 common reasons include packet size limits and an end-of-file
43375 condition. The number of bytes read is returned. Zero should only be
43376 returned for a successful read at the end of the file, or if
43377 @var{count} was zero.
43378
43379 The data read should be returned as a binary attachment on success.
43380 If zero bytes were read, the response should include an empty binary
43381 attachment (i.e.@: a trailing semicolon). The return value is the
43382 number of target bytes read; the binary attachment may be longer if
43383 some characters were escaped.
43384
43385 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
43386 Write @var{data} (a binary buffer) to the open file corresponding
43387 to @var{fd}. Start the write at @var{offset} from the start of the
43388 file. Unlike many @code{write} system calls, there is no
43389 separate @var{count} argument; the length of @var{data} in the
43390 packet is used. @samp{vFile:pwrite} returns the number of bytes written,
43391 which may be shorter than the length of @var{data}, or -1 if an
43392 error occurred.
43393
43394 @item vFile:fstat: @var{fd}
43395 Get information about the open file corresponding to @var{fd}.
43396 On success the information is returned as a binary attachment
43397 and the return value is the size of this attachment in bytes.
43398 If an error occurs the return value is -1. The format of the
43399 returned binary attachment is as described in @ref{struct stat}.
43400
43401 @item vFile:unlink: @var{filename}
43402 Delete the file at @var{filename} on the target. Return 0,
43403 or -1 if an error occurs. The @var{filename} is a string.
43404
43405 @item vFile:readlink: @var{filename}
43406 Read value of symbolic link @var{filename} on the target. Return
43407 the number of bytes read, or -1 if an error occurs.
43408
43409 The data read should be returned as a binary attachment on success.
43410 If zero bytes were read, the response should include an empty binary
43411 attachment (i.e.@: a trailing semicolon). The return value is the
43412 number of target bytes read; the binary attachment may be longer if
43413 some characters were escaped.
43414
43415 @item vFile:setfs: @var{pid}
43416 Select the filesystem on which @code{vFile} operations with
43417 @var{filename} arguments will operate. This is required for
43418 @value{GDBN} to be able to access files on remote targets where
43419 the remote stub does not share a common filesystem with the
43420 inferior(s).
43421
43422 If @var{pid} is nonzero, select the filesystem as seen by process
43423 @var{pid}. If @var{pid} is zero, select the filesystem as seen by
43424 the remote stub. Return 0 on success, or -1 if an error occurs.
43425 If @code{vFile:setfs:} indicates success, the selected filesystem
43426 remains selected until the next successful @code{vFile:setfs:}
43427 operation.
43428
43429 @end table
43430
43431 @node Interrupts
43432 @section Interrupts
43433 @cindex interrupts (remote protocol)
43434 @anchor{interrupting remote targets}
43435
43436 In all-stop mode, when a program on the remote target is running,
43437 @value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
43438 @code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
43439 is specified via @value{GDBN}'s @samp{interrupt-sequence}.
43440
43441 The precise meaning of @code{BREAK} is defined by the transport
43442 mechanism and may, in fact, be undefined. @value{GDBN} does not
43443 currently define a @code{BREAK} mechanism for any of the network
43444 interfaces except for TCP, in which case @value{GDBN} sends the
43445 @code{telnet} BREAK sequence.
43446
43447 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
43448 transport mechanisms. It is represented by sending the single byte
43449 @code{0x03} without any of the usual packet overhead described in
43450 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
43451 transmitted as part of a packet, it is considered to be packet data
43452 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
43453 (@pxref{X packet}), used for binary downloads, may include an unescaped
43454 @code{0x03} as part of its packet.
43455
43456 @code{BREAK} followed by @code{g} is also known as Magic SysRq g.
43457 When Linux kernel receives this sequence from serial port,
43458 it stops execution and connects to gdb.
43459
43460 In non-stop mode, because packet resumptions are asynchronous
43461 (@pxref{vCont packet}), @value{GDBN} is always free to send a remote
43462 command to the remote stub, even when the target is running. For that
43463 reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
43464 packet}) with the usual packet framing instead of the single byte
43465 @code{0x03}.
43466
43467 Stubs are not required to recognize these interrupt mechanisms and the
43468 precise meaning associated with receipt of the interrupt is
43469 implementation defined. If the target supports debugging of multiple
43470 threads and/or processes, it should attempt to interrupt all
43471 currently-executing threads and processes.
43472 If the stub is successful at interrupting the
43473 running program, it should send one of the stop
43474 reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
43475 of successfully stopping the program in all-stop mode, and a stop reply
43476 for each stopped thread in non-stop mode.
43477 Interrupts received while the
43478 program is stopped are queued and the program will be interrupted when
43479 it is resumed next time.
43480
43481 @node Notification Packets
43482 @section Notification Packets
43483 @cindex notification packets
43484 @cindex packets, notification
43485
43486 The @value{GDBN} remote serial protocol includes @dfn{notifications},
43487 packets that require no acknowledgment. Both the GDB and the stub
43488 may send notifications (although the only notifications defined at
43489 present are sent by the stub). Notifications carry information
43490 without incurring the round-trip latency of an acknowledgment, and so
43491 are useful for low-impact communications where occasional packet loss
43492 is not a problem.
43493
43494 A notification packet has the form @samp{% @var{data} #
43495 @var{checksum}}, where @var{data} is the content of the notification,
43496 and @var{checksum} is a checksum of @var{data}, computed and formatted
43497 as for ordinary @value{GDBN} packets. A notification's @var{data}
43498 never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
43499 receiving a notification, the recipient sends no @samp{+} or @samp{-}
43500 to acknowledge the notification's receipt or to report its corruption.
43501
43502 Every notification's @var{data} begins with a name, which contains no
43503 colon characters, followed by a colon character.
43504
43505 Recipients should silently ignore corrupted notifications and
43506 notifications they do not understand. Recipients should restart
43507 timeout periods on receipt of a well-formed notification, whether or
43508 not they understand it.
43509
43510 Senders should only send the notifications described here when this
43511 protocol description specifies that they are permitted. In the
43512 future, we may extend the protocol to permit existing notifications in
43513 new contexts; this rule helps older senders avoid confusing newer
43514 recipients.
43515
43516 (Older versions of @value{GDBN} ignore bytes received until they see
43517 the @samp{$} byte that begins an ordinary packet, so new stubs may
43518 transmit notifications without fear of confusing older clients. There
43519 are no notifications defined for @value{GDBN} to send at the moment, but we
43520 assume that most older stubs would ignore them, as well.)
43521
43522 Each notification is comprised of three parts:
43523 @table @samp
43524 @item @var{name}:@var{event}
43525 The notification packet is sent by the side that initiates the
43526 exchange (currently, only the stub does that), with @var{event}
43527 carrying the specific information about the notification, and
43528 @var{name} specifying the name of the notification.
43529 @item @var{ack}
43530 The acknowledge sent by the other side, usually @value{GDBN}, to
43531 acknowledge the exchange and request the event.
43532 @end table
43533
43534 The purpose of an asynchronous notification mechanism is to report to
43535 @value{GDBN} that something interesting happened in the remote stub.
43536
43537 The remote stub may send notification @var{name}:@var{event}
43538 at any time, but @value{GDBN} acknowledges the notification when
43539 appropriate. The notification event is pending before @value{GDBN}
43540 acknowledges. Only one notification at a time may be pending; if
43541 additional events occur before @value{GDBN} has acknowledged the
43542 previous notification, they must be queued by the stub for later
43543 synchronous transmission in response to @var{ack} packets from
43544 @value{GDBN}. Because the notification mechanism is unreliable,
43545 the stub is permitted to resend a notification if it believes
43546 @value{GDBN} may not have received it.
43547
43548 Specifically, notifications may appear when @value{GDBN} is not
43549 otherwise reading input from the stub, or when @value{GDBN} is
43550 expecting to read a normal synchronous response or a
43551 @samp{+}/@samp{-} acknowledgment to a packet it has sent.
43552 Notification packets are distinct from any other communication from
43553 the stub so there is no ambiguity.
43554
43555 After receiving a notification, @value{GDBN} shall acknowledge it by
43556 sending a @var{ack} packet as a regular, synchronous request to the
43557 stub. Such acknowledgment is not required to happen immediately, as
43558 @value{GDBN} is permitted to send other, unrelated packets to the
43559 stub first, which the stub should process normally.
43560
43561 Upon receiving a @var{ack} packet, if the stub has other queued
43562 events to report to @value{GDBN}, it shall respond by sending a
43563 normal @var{event}. @value{GDBN} shall then send another @var{ack}
43564 packet to solicit further responses; again, it is permitted to send
43565 other, unrelated packets as well which the stub should process
43566 normally.
43567
43568 If the stub receives a @var{ack} packet and there are no additional
43569 @var{event} to report, the stub shall return an @samp{OK} response.
43570 At this point, @value{GDBN} has finished processing a notification
43571 and the stub has completed sending any queued events. @value{GDBN}
43572 won't accept any new notifications until the final @samp{OK} is
43573 received . If further notification events occur, the stub shall send
43574 a new notification, @value{GDBN} shall accept the notification, and
43575 the process shall be repeated.
43576
43577 The process of asynchronous notification can be illustrated by the
43578 following example:
43579 @smallexample
43580 <- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
43581 @code{...}
43582 -> @code{vStopped}
43583 <- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
43584 -> @code{vStopped}
43585 <- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
43586 -> @code{vStopped}
43587 <- @code{OK}
43588 @end smallexample
43589
43590 The following notifications are defined:
43591 @multitable @columnfractions 0.12 0.12 0.38 0.38
43592
43593 @item Notification
43594 @tab Ack
43595 @tab Event
43596 @tab Description
43597
43598 @item Stop
43599 @tab vStopped
43600 @tab @var{reply}. The @var{reply} has the form of a stop reply, as
43601 described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
43602 for information on how these notifications are acknowledged by
43603 @value{GDBN}.
43604 @tab Report an asynchronous stop event in non-stop mode.
43605
43606 @end multitable
43607
43608 @node Remote Non-Stop
43609 @section Remote Protocol Support for Non-Stop Mode
43610
43611 @value{GDBN}'s remote protocol supports non-stop debugging of
43612 multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
43613 supports non-stop mode, it should report that to @value{GDBN} by including
43614 @samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
43615
43616 @value{GDBN} typically sends a @samp{QNonStop} packet only when
43617 establishing a new connection with the stub. Entering non-stop mode
43618 does not alter the state of any currently-running threads, but targets
43619 must stop all threads in any already-attached processes when entering
43620 all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
43621 probe the target state after a mode change.
43622
43623 In non-stop mode, when an attached process encounters an event that
43624 would otherwise be reported with a stop reply, it uses the
43625 asynchronous notification mechanism (@pxref{Notification Packets}) to
43626 inform @value{GDBN}. In contrast to all-stop mode, where all threads
43627 in all processes are stopped when a stop reply is sent, in non-stop
43628 mode only the thread reporting the stop event is stopped. That is,
43629 when reporting a @samp{S} or @samp{T} response to indicate completion
43630 of a step operation, hitting a breakpoint, or a fault, only the
43631 affected thread is stopped; any other still-running threads continue
43632 to run. When reporting a @samp{W} or @samp{X} response, all running
43633 threads belonging to other attached processes continue to run.
43634
43635 In non-stop mode, the target shall respond to the @samp{?} packet as
43636 follows. First, any incomplete stop reply notification/@samp{vStopped}
43637 sequence in progress is abandoned. The target must begin a new
43638 sequence reporting stop events for all stopped threads, whether or not
43639 it has previously reported those events to @value{GDBN}. The first
43640 stop reply is sent as a synchronous reply to the @samp{?} packet, and
43641 subsequent stop replies are sent as responses to @samp{vStopped} packets
43642 using the mechanism described above. The target must not send
43643 asynchronous stop reply notifications until the sequence is complete.
43644 If all threads are running when the target receives the @samp{?} packet,
43645 or if the target is not attached to any process, it shall respond
43646 @samp{OK}.
43647
43648 If the stub supports non-stop mode, it should also support the
43649 @samp{swbreak} stop reason if software breakpoints are supported, and
43650 the @samp{hwbreak} stop reason if hardware breakpoints are supported
43651 (@pxref{swbreak stop reason}). This is because given the asynchronous
43652 nature of non-stop mode, between the time a thread hits a breakpoint
43653 and the time the event is finally processed by @value{GDBN}, the
43654 breakpoint may have already been removed from the target. Due to
43655 this, @value{GDBN} needs to be able to tell whether a trap stop was
43656 caused by a delayed breakpoint event, which should be ignored, as
43657 opposed to a random trap signal, which should be reported to the user.
43658 Note the @samp{swbreak} feature implies that the target is responsible
43659 for adjusting the PC when a software breakpoint triggers, if
43660 necessary, such as on the x86 architecture.
43661
43662 @node Packet Acknowledgment
43663 @section Packet Acknowledgment
43664
43665 @cindex acknowledgment, for @value{GDBN} remote
43666 @cindex packet acknowledgment, for @value{GDBN} remote
43667 By default, when either the host or the target machine receives a packet,
43668 the first response expected is an acknowledgment: either @samp{+} (to indicate
43669 the package was received correctly) or @samp{-} (to request retransmission).
43670 This mechanism allows the @value{GDBN} remote protocol to operate over
43671 unreliable transport mechanisms, such as a serial line.
43672
43673 In cases where the transport mechanism is itself reliable (such as a pipe or
43674 TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
43675 It may be desirable to disable them in that case to reduce communication
43676 overhead, or for other reasons. This can be accomplished by means of the
43677 @samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
43678
43679 When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
43680 expect @samp{+}/@samp{-} protocol acknowledgments. The packet
43681 and response format still includes the normal checksum, as described in
43682 @ref{Overview}, but the checksum may be ignored by the receiver.
43683
43684 If the stub supports @samp{QStartNoAckMode} and prefers to operate in
43685 no-acknowledgment mode, it should report that to @value{GDBN}
43686 by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
43687 @pxref{qSupported}.
43688 If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
43689 disabled via the @code{set remote noack-packet off} command
43690 (@pxref{Remote Configuration}),
43691 @value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
43692 Only then may the stub actually turn off packet acknowledgments.
43693 @value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
43694 response, which can be safely ignored by the stub.
43695
43696 Note that @code{set remote noack-packet} command only affects negotiation
43697 between @value{GDBN} and the stub when subsequent connections are made;
43698 it does not affect the protocol acknowledgment state for any current
43699 connection.
43700 Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
43701 new connection is established,
43702 there is also no protocol request to re-enable the acknowledgments
43703 for the current connection, once disabled.
43704
43705 @node Examples
43706 @section Examples
43707
43708 Example sequence of a target being re-started. Notice how the restart
43709 does not get any direct output:
43710
43711 @smallexample
43712 -> @code{R00}
43713 <- @code{+}
43714 @emph{target restarts}
43715 -> @code{?}
43716 <- @code{+}
43717 <- @code{T001:1234123412341234}
43718 -> @code{+}
43719 @end smallexample
43720
43721 Example sequence of a target being stepped by a single instruction:
43722
43723 @smallexample
43724 -> @code{G1445@dots{}}
43725 <- @code{+}
43726 -> @code{s}
43727 <- @code{+}
43728 @emph{time passes}
43729 <- @code{T001:1234123412341234}
43730 -> @code{+}
43731 -> @code{g}
43732 <- @code{+}
43733 <- @code{1455@dots{}}
43734 -> @code{+}
43735 @end smallexample
43736
43737 @node File-I/O Remote Protocol Extension
43738 @section File-I/O Remote Protocol Extension
43739 @cindex File-I/O remote protocol extension
43740
43741 @menu
43742 * File-I/O Overview::
43743 * Protocol Basics::
43744 * The F Request Packet::
43745 * The F Reply Packet::
43746 * The Ctrl-C Message::
43747 * Console I/O::
43748 * List of Supported Calls::
43749 * Protocol-specific Representation of Datatypes::
43750 * Constants::
43751 * File-I/O Examples::
43752 @end menu
43753
43754 @node File-I/O Overview
43755 @subsection File-I/O Overview
43756 @cindex file-i/o overview
43757
43758 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
43759 target to use the host's file system and console I/O to perform various
43760 system calls. System calls on the target system are translated into a
43761 remote protocol packet to the host system, which then performs the needed
43762 actions and returns a response packet to the target system.
43763 This simulates file system operations even on targets that lack file systems.
43764
43765 The protocol is defined to be independent of both the host and target systems.
43766 It uses its own internal representation of datatypes and values. Both
43767 @value{GDBN} and the target's @value{GDBN} stub are responsible for
43768 translating the system-dependent value representations into the internal
43769 protocol representations when data is transmitted.
43770
43771 The communication is synchronous. A system call is possible only when
43772 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
43773 or @samp{s} packets. While @value{GDBN} handles the request for a system call,
43774 the target is stopped to allow deterministic access to the target's
43775 memory. Therefore File-I/O is not interruptible by target signals. On
43776 the other hand, it is possible to interrupt File-I/O by a user interrupt
43777 (@samp{Ctrl-C}) within @value{GDBN}.
43778
43779 The target's request to perform a host system call does not finish
43780 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
43781 after finishing the system call, the target returns to continuing the
43782 previous activity (continue, step). No additional continue or step
43783 request from @value{GDBN} is required.
43784
43785 @smallexample
43786 (@value{GDBP}) continue
43787 <- target requests 'system call X'
43788 target is stopped, @value{GDBN} executes system call
43789 -> @value{GDBN} returns result
43790 ... target continues, @value{GDBN} returns to wait for the target
43791 <- target hits breakpoint and sends a Txx packet
43792 @end smallexample
43793
43794 The protocol only supports I/O on the console and to regular files on
43795 the host file system. Character or block special devices, pipes,
43796 named pipes, sockets or any other communication method on the host
43797 system are not supported by this protocol.
43798
43799 File I/O is not supported in non-stop mode.
43800
43801 @node Protocol Basics
43802 @subsection Protocol Basics
43803 @cindex protocol basics, file-i/o
43804
43805 The File-I/O protocol uses the @code{F} packet as the request as well
43806 as reply packet. Since a File-I/O system call can only occur when
43807 @value{GDBN} is waiting for a response from the continuing or stepping target,
43808 the File-I/O request is a reply that @value{GDBN} has to expect as a result
43809 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
43810 This @code{F} packet contains all information needed to allow @value{GDBN}
43811 to call the appropriate host system call:
43812
43813 @itemize @bullet
43814 @item
43815 A unique identifier for the requested system call.
43816
43817 @item
43818 All parameters to the system call. Pointers are given as addresses
43819 in the target memory address space. Pointers to strings are given as
43820 pointer/length pair. Numerical values are given as they are.
43821 Numerical control flags are given in a protocol-specific representation.
43822
43823 @end itemize
43824
43825 At this point, @value{GDBN} has to perform the following actions.
43826
43827 @itemize @bullet
43828 @item
43829 If the parameters include pointer values to data needed as input to a
43830 system call, @value{GDBN} requests this data from the target with a
43831 standard @code{m} packet request. This additional communication has to be
43832 expected by the target implementation and is handled as any other @code{m}
43833 packet.
43834
43835 @item
43836 @value{GDBN} translates all value from protocol representation to host
43837 representation as needed. Datatypes are coerced into the host types.
43838
43839 @item
43840 @value{GDBN} calls the system call.
43841
43842 @item
43843 It then coerces datatypes back to protocol representation.
43844
43845 @item
43846 If the system call is expected to return data in buffer space specified
43847 by pointer parameters to the call, the data is transmitted to the
43848 target using a @code{M} or @code{X} packet. This packet has to be expected
43849 by the target implementation and is handled as any other @code{M} or @code{X}
43850 packet.
43851
43852 @end itemize
43853
43854 Eventually @value{GDBN} replies with another @code{F} packet which contains all
43855 necessary information for the target to continue. This at least contains
43856
43857 @itemize @bullet
43858 @item
43859 Return value.
43860
43861 @item
43862 @code{errno}, if has been changed by the system call.
43863
43864 @item
43865 ``Ctrl-C'' flag.
43866
43867 @end itemize
43868
43869 After having done the needed type and value coercion, the target continues
43870 the latest continue or step action.
43871
43872 @node The F Request Packet
43873 @subsection The @code{F} Request Packet
43874 @cindex file-i/o request packet
43875 @cindex @code{F} request packet
43876
43877 The @code{F} request packet has the following format:
43878
43879 @table @samp
43880 @item F@var{call-id},@var{parameter@dots{}}
43881
43882 @var{call-id} is the identifier to indicate the host system call to be called.
43883 This is just the name of the function.
43884
43885 @var{parameter@dots{}} are the parameters to the system call.
43886 Parameters are hexadecimal integer values, either the actual values in case
43887 of scalar datatypes, pointers to target buffer space in case of compound
43888 datatypes and unspecified memory areas, or pointer/length pairs in case
43889 of string parameters. These are appended to the @var{call-id} as a
43890 comma-delimited list. All values are transmitted in ASCII
43891 string representation, pointer/length pairs separated by a slash.
43892
43893 @end table
43894
43895
43896
43897 @node The F Reply Packet
43898 @subsection The @code{F} Reply Packet
43899 @cindex file-i/o reply packet
43900 @cindex @code{F} reply packet
43901
43902 The @code{F} reply packet has the following format:
43903
43904 @table @samp
43905
43906 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
43907
43908 @var{retcode} is the return code of the system call as hexadecimal value.
43909
43910 @var{errno} is the @code{errno} set by the call, in protocol-specific
43911 representation.
43912 This parameter can be omitted if the call was successful.
43913
43914 @var{Ctrl-C flag} is only sent if the user requested a break. In this
43915 case, @var{errno} must be sent as well, even if the call was successful.
43916 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
43917
43918 @smallexample
43919 F0,0,C
43920 @end smallexample
43921
43922 @noindent
43923 or, if the call was interrupted before the host call has been performed:
43924
43925 @smallexample
43926 F-1,4,C
43927 @end smallexample
43928
43929 @noindent
43930 assuming 4 is the protocol-specific representation of @code{EINTR}.
43931
43932 @end table
43933
43934
43935 @node The Ctrl-C Message
43936 @subsection The @samp{Ctrl-C} Message
43937 @cindex ctrl-c message, in file-i/o protocol
43938
43939 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
43940 reply packet (@pxref{The F Reply Packet}),
43941 the target should behave as if it had
43942 gotten a break message. The meaning for the target is ``system call
43943 interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
43944 (as with a break message) and return to @value{GDBN} with a @code{T02}
43945 packet.
43946
43947 It's important for the target to know in which
43948 state the system call was interrupted. There are two possible cases:
43949
43950 @itemize @bullet
43951 @item
43952 The system call hasn't been performed on the host yet.
43953
43954 @item
43955 The system call on the host has been finished.
43956
43957 @end itemize
43958
43959 These two states can be distinguished by the target by the value of the
43960 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
43961 call hasn't been performed. This is equivalent to the @code{EINTR} handling
43962 on POSIX systems. In any other case, the target may presume that the
43963 system call has been finished --- successfully or not --- and should behave
43964 as if the break message arrived right after the system call.
43965
43966 @value{GDBN} must behave reliably. If the system call has not been called
43967 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
43968 @code{errno} in the packet. If the system call on the host has been finished
43969 before the user requests a break, the full action must be finished by
43970 @value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
43971 The @code{F} packet may only be sent when either nothing has happened
43972 or the full action has been completed.
43973
43974 @node Console I/O
43975 @subsection Console I/O
43976 @cindex console i/o as part of file-i/o
43977
43978 By default and if not explicitly closed by the target system, the file
43979 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
43980 on the @value{GDBN} console is handled as any other file output operation
43981 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
43982 by @value{GDBN} so that after the target read request from file descriptor
43983 0 all following typing is buffered until either one of the following
43984 conditions is met:
43985
43986 @itemize @bullet
43987 @item
43988 The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
43989 @code{read}
43990 system call is treated as finished.
43991
43992 @item
43993 The user presses @key{RET}. This is treated as end of input with a trailing
43994 newline.
43995
43996 @item
43997 The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
43998 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
43999
44000 @end itemize
44001
44002 If the user has typed more characters than fit in the buffer given to
44003 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
44004 either another @code{read(0, @dots{})} is requested by the target, or debugging
44005 is stopped at the user's request.
44006
44007
44008 @node List of Supported Calls
44009 @subsection List of Supported Calls
44010 @cindex list of supported file-i/o calls
44011
44012 @menu
44013 * open::
44014 * close::
44015 * read::
44016 * write::
44017 * lseek::
44018 * rename::
44019 * unlink::
44020 * stat/fstat::
44021 * gettimeofday::
44022 * isatty::
44023 * system::
44024 @end menu
44025
44026 @node open
44027 @unnumberedsubsubsec open
44028 @cindex open, file-i/o system call
44029
44030 @table @asis
44031 @item Synopsis:
44032 @smallexample
44033 int open(const char *pathname, int flags);
44034 int open(const char *pathname, int flags, mode_t mode);
44035 @end smallexample
44036
44037 @item Request:
44038 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
44039
44040 @noindent
44041 @var{flags} is the bitwise @code{OR} of the following values:
44042
44043 @table @code
44044 @item O_CREAT
44045 If the file does not exist it will be created. The host
44046 rules apply as far as file ownership and time stamps
44047 are concerned.
44048
44049 @item O_EXCL
44050 When used with @code{O_CREAT}, if the file already exists it is
44051 an error and open() fails.
44052
44053 @item O_TRUNC
44054 If the file already exists and the open mode allows
44055 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
44056 truncated to zero length.
44057
44058 @item O_APPEND
44059 The file is opened in append mode.
44060
44061 @item O_RDONLY
44062 The file is opened for reading only.
44063
44064 @item O_WRONLY
44065 The file is opened for writing only.
44066
44067 @item O_RDWR
44068 The file is opened for reading and writing.
44069 @end table
44070
44071 @noindent
44072 Other bits are silently ignored.
44073
44074
44075 @noindent
44076 @var{mode} is the bitwise @code{OR} of the following values:
44077
44078 @table @code
44079 @item S_IRUSR
44080 User has read permission.
44081
44082 @item S_IWUSR
44083 User has write permission.
44084
44085 @item S_IRGRP
44086 Group has read permission.
44087
44088 @item S_IWGRP
44089 Group has write permission.
44090
44091 @item S_IROTH
44092 Others have read permission.
44093
44094 @item S_IWOTH
44095 Others have write permission.
44096 @end table
44097
44098 @noindent
44099 Other bits are silently ignored.
44100
44101
44102 @item Return value:
44103 @code{open} returns the new file descriptor or -1 if an error
44104 occurred.
44105
44106 @item Errors:
44107
44108 @table @code
44109 @item EEXIST
44110 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
44111
44112 @item EISDIR
44113 @var{pathname} refers to a directory.
44114
44115 @item EACCES
44116 The requested access is not allowed.
44117
44118 @item ENAMETOOLONG
44119 @var{pathname} was too long.
44120
44121 @item ENOENT
44122 A directory component in @var{pathname} does not exist.
44123
44124 @item ENODEV
44125 @var{pathname} refers to a device, pipe, named pipe or socket.
44126
44127 @item EROFS
44128 @var{pathname} refers to a file on a read-only filesystem and
44129 write access was requested.
44130
44131 @item EFAULT
44132 @var{pathname} is an invalid pointer value.
44133
44134 @item ENOSPC
44135 No space on device to create the file.
44136
44137 @item EMFILE
44138 The process already has the maximum number of files open.
44139
44140 @item ENFILE
44141 The limit on the total number of files open on the system
44142 has been reached.
44143
44144 @item EINTR
44145 The call was interrupted by the user.
44146 @end table
44147
44148 @end table
44149
44150 @node close
44151 @unnumberedsubsubsec close
44152 @cindex close, file-i/o system call
44153
44154 @table @asis
44155 @item Synopsis:
44156 @smallexample
44157 int close(int fd);
44158 @end smallexample
44159
44160 @item Request:
44161 @samp{Fclose,@var{fd}}
44162
44163 @item Return value:
44164 @code{close} returns zero on success, or -1 if an error occurred.
44165
44166 @item Errors:
44167
44168 @table @code
44169 @item EBADF
44170 @var{fd} isn't a valid open file descriptor.
44171
44172 @item EINTR
44173 The call was interrupted by the user.
44174 @end table
44175
44176 @end table
44177
44178 @node read
44179 @unnumberedsubsubsec read
44180 @cindex read, file-i/o system call
44181
44182 @table @asis
44183 @item Synopsis:
44184 @smallexample
44185 int read(int fd, void *buf, unsigned int count);
44186 @end smallexample
44187
44188 @item Request:
44189 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
44190
44191 @item Return value:
44192 On success, the number of bytes read is returned.
44193 Zero indicates end of file. If count is zero, read
44194 returns zero as well. On error, -1 is returned.
44195
44196 @item Errors:
44197
44198 @table @code
44199 @item EBADF
44200 @var{fd} is not a valid file descriptor or is not open for
44201 reading.
44202
44203 @item EFAULT
44204 @var{bufptr} is an invalid pointer value.
44205
44206 @item EINTR
44207 The call was interrupted by the user.
44208 @end table
44209
44210 @end table
44211
44212 @node write
44213 @unnumberedsubsubsec write
44214 @cindex write, file-i/o system call
44215
44216 @table @asis
44217 @item Synopsis:
44218 @smallexample
44219 int write(int fd, const void *buf, unsigned int count);
44220 @end smallexample
44221
44222 @item Request:
44223 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
44224
44225 @item Return value:
44226 On success, the number of bytes written are returned.
44227 Zero indicates nothing was written. On error, -1
44228 is returned.
44229
44230 @item Errors:
44231
44232 @table @code
44233 @item EBADF
44234 @var{fd} is not a valid file descriptor or is not open for
44235 writing.
44236
44237 @item EFAULT
44238 @var{bufptr} is an invalid pointer value.
44239
44240 @item EFBIG
44241 An attempt was made to write a file that exceeds the
44242 host-specific maximum file size allowed.
44243
44244 @item ENOSPC
44245 No space on device to write the data.
44246
44247 @item EINTR
44248 The call was interrupted by the user.
44249 @end table
44250
44251 @end table
44252
44253 @node lseek
44254 @unnumberedsubsubsec lseek
44255 @cindex lseek, file-i/o system call
44256
44257 @table @asis
44258 @item Synopsis:
44259 @smallexample
44260 long lseek (int fd, long offset, int flag);
44261 @end smallexample
44262
44263 @item Request:
44264 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
44265
44266 @var{flag} is one of:
44267
44268 @table @code
44269 @item SEEK_SET
44270 The offset is set to @var{offset} bytes.
44271
44272 @item SEEK_CUR
44273 The offset is set to its current location plus @var{offset}
44274 bytes.
44275
44276 @item SEEK_END
44277 The offset is set to the size of the file plus @var{offset}
44278 bytes.
44279 @end table
44280
44281 @item Return value:
44282 On success, the resulting unsigned offset in bytes from
44283 the beginning of the file is returned. Otherwise, a
44284 value of -1 is returned.
44285
44286 @item Errors:
44287
44288 @table @code
44289 @item EBADF
44290 @var{fd} is not a valid open file descriptor.
44291
44292 @item ESPIPE
44293 @var{fd} is associated with the @value{GDBN} console.
44294
44295 @item EINVAL
44296 @var{flag} is not a proper value.
44297
44298 @item EINTR
44299 The call was interrupted by the user.
44300 @end table
44301
44302 @end table
44303
44304 @node rename
44305 @unnumberedsubsubsec rename
44306 @cindex rename, file-i/o system call
44307
44308 @table @asis
44309 @item Synopsis:
44310 @smallexample
44311 int rename(const char *oldpath, const char *newpath);
44312 @end smallexample
44313
44314 @item Request:
44315 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
44316
44317 @item Return value:
44318 On success, zero is returned. On error, -1 is returned.
44319
44320 @item Errors:
44321
44322 @table @code
44323 @item EISDIR
44324 @var{newpath} is an existing directory, but @var{oldpath} is not a
44325 directory.
44326
44327 @item EEXIST
44328 @var{newpath} is a non-empty directory.
44329
44330 @item EBUSY
44331 @var{oldpath} or @var{newpath} is a directory that is in use by some
44332 process.
44333
44334 @item EINVAL
44335 An attempt was made to make a directory a subdirectory
44336 of itself.
44337
44338 @item ENOTDIR
44339 A component used as a directory in @var{oldpath} or new
44340 path is not a directory. Or @var{oldpath} is a directory
44341 and @var{newpath} exists but is not a directory.
44342
44343 @item EFAULT
44344 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
44345
44346 @item EACCES
44347 No access to the file or the path of the file.
44348
44349 @item ENAMETOOLONG
44350
44351 @var{oldpath} or @var{newpath} was too long.
44352
44353 @item ENOENT
44354 A directory component in @var{oldpath} or @var{newpath} does not exist.
44355
44356 @item EROFS
44357 The file is on a read-only filesystem.
44358
44359 @item ENOSPC
44360 The device containing the file has no room for the new
44361 directory entry.
44362
44363 @item EINTR
44364 The call was interrupted by the user.
44365 @end table
44366
44367 @end table
44368
44369 @node unlink
44370 @unnumberedsubsubsec unlink
44371 @cindex unlink, file-i/o system call
44372
44373 @table @asis
44374 @item Synopsis:
44375 @smallexample
44376 int unlink(const char *pathname);
44377 @end smallexample
44378
44379 @item Request:
44380 @samp{Funlink,@var{pathnameptr}/@var{len}}
44381
44382 @item Return value:
44383 On success, zero is returned. On error, -1 is returned.
44384
44385 @item Errors:
44386
44387 @table @code
44388 @item EACCES
44389 No access to the file or the path of the file.
44390
44391 @item EPERM
44392 The system does not allow unlinking of directories.
44393
44394 @item EBUSY
44395 The file @var{pathname} cannot be unlinked because it's
44396 being used by another process.
44397
44398 @item EFAULT
44399 @var{pathnameptr} is an invalid pointer value.
44400
44401 @item ENAMETOOLONG
44402 @var{pathname} was too long.
44403
44404 @item ENOENT
44405 A directory component in @var{pathname} does not exist.
44406
44407 @item ENOTDIR
44408 A component of the path is not a directory.
44409
44410 @item EROFS
44411 The file is on a read-only filesystem.
44412
44413 @item EINTR
44414 The call was interrupted by the user.
44415 @end table
44416
44417 @end table
44418
44419 @node stat/fstat
44420 @unnumberedsubsubsec stat/fstat
44421 @cindex fstat, file-i/o system call
44422 @cindex stat, file-i/o system call
44423
44424 @table @asis
44425 @item Synopsis:
44426 @smallexample
44427 int stat(const char *pathname, struct stat *buf);
44428 int fstat(int fd, struct stat *buf);
44429 @end smallexample
44430
44431 @item Request:
44432 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
44433 @samp{Ffstat,@var{fd},@var{bufptr}}
44434
44435 @item Return value:
44436 On success, zero is returned. On error, -1 is returned.
44437
44438 @item Errors:
44439
44440 @table @code
44441 @item EBADF
44442 @var{fd} is not a valid open file.
44443
44444 @item ENOENT
44445 A directory component in @var{pathname} does not exist or the
44446 path is an empty string.
44447
44448 @item ENOTDIR
44449 A component of the path is not a directory.
44450
44451 @item EFAULT
44452 @var{pathnameptr} is an invalid pointer value.
44453
44454 @item EACCES
44455 No access to the file or the path of the file.
44456
44457 @item ENAMETOOLONG
44458 @var{pathname} was too long.
44459
44460 @item EINTR
44461 The call was interrupted by the user.
44462 @end table
44463
44464 @end table
44465
44466 @node gettimeofday
44467 @unnumberedsubsubsec gettimeofday
44468 @cindex gettimeofday, file-i/o system call
44469
44470 @table @asis
44471 @item Synopsis:
44472 @smallexample
44473 int gettimeofday(struct timeval *tv, void *tz);
44474 @end smallexample
44475
44476 @item Request:
44477 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
44478
44479 @item Return value:
44480 On success, 0 is returned, -1 otherwise.
44481
44482 @item Errors:
44483
44484 @table @code
44485 @item EINVAL
44486 @var{tz} is a non-NULL pointer.
44487
44488 @item EFAULT
44489 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
44490 @end table
44491
44492 @end table
44493
44494 @node isatty
44495 @unnumberedsubsubsec isatty
44496 @cindex isatty, file-i/o system call
44497
44498 @table @asis
44499 @item Synopsis:
44500 @smallexample
44501 int isatty(int fd);
44502 @end smallexample
44503
44504 @item Request:
44505 @samp{Fisatty,@var{fd}}
44506
44507 @item Return value:
44508 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
44509
44510 @item Errors:
44511
44512 @table @code
44513 @item EINTR
44514 The call was interrupted by the user.
44515 @end table
44516
44517 @end table
44518
44519 Note that the @code{isatty} call is treated as a special case: it returns
44520 1 to the target if the file descriptor is attached
44521 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
44522 would require implementing @code{ioctl} and would be more complex than
44523 needed.
44524
44525
44526 @node system
44527 @unnumberedsubsubsec system
44528 @cindex system, file-i/o system call
44529
44530 @table @asis
44531 @item Synopsis:
44532 @smallexample
44533 int system(const char *command);
44534 @end smallexample
44535
44536 @item Request:
44537 @samp{Fsystem,@var{commandptr}/@var{len}}
44538
44539 @item Return value:
44540 If @var{len} is zero, the return value indicates whether a shell is
44541 available. A zero return value indicates a shell is not available.
44542 For non-zero @var{len}, the value returned is -1 on error and the
44543 return status of the command otherwise. Only the exit status of the
44544 command is returned, which is extracted from the host's @code{system}
44545 return value by calling @code{WEXITSTATUS(retval)}. In case
44546 @file{/bin/sh} could not be executed, 127 is returned.
44547
44548 @item Errors:
44549
44550 @table @code
44551 @item EINTR
44552 The call was interrupted by the user.
44553 @end table
44554
44555 @end table
44556
44557 @value{GDBN} takes over the full task of calling the necessary host calls
44558 to perform the @code{system} call. The return value of @code{system} on
44559 the host is simplified before it's returned
44560 to the target. Any termination signal information from the child process
44561 is discarded, and the return value consists
44562 entirely of the exit status of the called command.
44563
44564 Due to security concerns, the @code{system} call is by default refused
44565 by @value{GDBN}. The user has to allow this call explicitly with the
44566 @code{set remote system-call-allowed 1} command.
44567
44568 @table @code
44569 @item set remote system-call-allowed
44570 @kindex set remote system-call-allowed
44571 Control whether to allow the @code{system} calls in the File I/O
44572 protocol for the remote target. The default is zero (disabled).
44573
44574 @item show remote system-call-allowed
44575 @kindex show remote system-call-allowed
44576 Show whether the @code{system} calls are allowed in the File I/O
44577 protocol.
44578 @end table
44579
44580 @node Protocol-specific Representation of Datatypes
44581 @subsection Protocol-specific Representation of Datatypes
44582 @cindex protocol-specific representation of datatypes, in file-i/o protocol
44583
44584 @menu
44585 * Integral Datatypes::
44586 * Pointer Values::
44587 * Memory Transfer::
44588 * struct stat::
44589 * struct timeval::
44590 @end menu
44591
44592 @node Integral Datatypes
44593 @unnumberedsubsubsec Integral Datatypes
44594 @cindex integral datatypes, in file-i/o protocol
44595
44596 The integral datatypes used in the system calls are @code{int},
44597 @code{unsigned int}, @code{long}, @code{unsigned long},
44598 @code{mode_t}, and @code{time_t}.
44599
44600 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
44601 implemented as 32 bit values in this protocol.
44602
44603 @code{long} and @code{unsigned long} are implemented as 64 bit types.
44604
44605 @xref{Limits}, for corresponding MIN and MAX values (similar to those
44606 in @file{limits.h}) to allow range checking on host and target.
44607
44608 @code{time_t} datatypes are defined as seconds since the Epoch.
44609
44610 All integral datatypes transferred as part of a memory read or write of a
44611 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
44612 byte order.
44613
44614 @node Pointer Values
44615 @unnumberedsubsubsec Pointer Values
44616 @cindex pointer values, in file-i/o protocol
44617
44618 Pointers to target data are transmitted as they are. An exception
44619 is made for pointers to buffers for which the length isn't
44620 transmitted as part of the function call, namely strings. Strings
44621 are transmitted as a pointer/length pair, both as hex values, e.g.@:
44622
44623 @smallexample
44624 @code{1aaf/12}
44625 @end smallexample
44626
44627 @noindent
44628 which is a pointer to data of length 18 bytes at position 0x1aaf.
44629 The length is defined as the full string length in bytes, including
44630 the trailing null byte. For example, the string @code{"hello world"}
44631 at address 0x123456 is transmitted as
44632
44633 @smallexample
44634 @code{123456/d}
44635 @end smallexample
44636
44637 @node Memory Transfer
44638 @unnumberedsubsubsec Memory Transfer
44639 @cindex memory transfer, in file-i/o protocol
44640
44641 Structured data which is transferred using a memory read or write (for
44642 example, a @code{struct stat}) is expected to be in a protocol-specific format
44643 with all scalar multibyte datatypes being big endian. Translation to
44644 this representation needs to be done both by the target before the @code{F}
44645 packet is sent, and by @value{GDBN} before
44646 it transfers memory to the target. Transferred pointers to structured
44647 data should point to the already-coerced data at any time.
44648
44649
44650 @node struct stat
44651 @unnumberedsubsubsec struct stat
44652 @cindex struct stat, in file-i/o protocol
44653
44654 The buffer of type @code{struct stat} used by the target and @value{GDBN}
44655 is defined as follows:
44656
44657 @smallexample
44658 struct stat @{
44659 unsigned int st_dev; /* device */
44660 unsigned int st_ino; /* inode */
44661 mode_t st_mode; /* protection */
44662 unsigned int st_nlink; /* number of hard links */
44663 unsigned int st_uid; /* user ID of owner */
44664 unsigned int st_gid; /* group ID of owner */
44665 unsigned int st_rdev; /* device type (if inode device) */
44666 unsigned long st_size; /* total size, in bytes */
44667 unsigned long st_blksize; /* blocksize for filesystem I/O */
44668 unsigned long st_blocks; /* number of blocks allocated */
44669 time_t st_atime; /* time of last access */
44670 time_t st_mtime; /* time of last modification */
44671 time_t st_ctime; /* time of last change */
44672 @};
44673 @end smallexample
44674
44675 The integral datatypes conform to the definitions given in the
44676 appropriate section (see @ref{Integral Datatypes}, for details) so this
44677 structure is of size 64 bytes.
44678
44679 The values of several fields have a restricted meaning and/or
44680 range of values.
44681
44682 @table @code
44683
44684 @item st_dev
44685 A value of 0 represents a file, 1 the console.
44686
44687 @item st_ino
44688 No valid meaning for the target. Transmitted unchanged.
44689
44690 @item st_mode
44691 Valid mode bits are described in @ref{Constants}. Any other
44692 bits have currently no meaning for the target.
44693
44694 @item st_uid
44695 @itemx st_gid
44696 @itemx st_rdev
44697 No valid meaning for the target. Transmitted unchanged.
44698
44699 @item st_atime
44700 @itemx st_mtime
44701 @itemx st_ctime
44702 These values have a host and file system dependent
44703 accuracy. Especially on Windows hosts, the file system may not
44704 support exact timing values.
44705 @end table
44706
44707 The target gets a @code{struct stat} of the above representation and is
44708 responsible for coercing it to the target representation before
44709 continuing.
44710
44711 Note that due to size differences between the host, target, and protocol
44712 representations of @code{struct stat} members, these members could eventually
44713 get truncated on the target.
44714
44715 @node struct timeval
44716 @unnumberedsubsubsec struct timeval
44717 @cindex struct timeval, in file-i/o protocol
44718
44719 The buffer of type @code{struct timeval} used by the File-I/O protocol
44720 is defined as follows:
44721
44722 @smallexample
44723 struct timeval @{
44724 time_t tv_sec; /* second */
44725 long tv_usec; /* microsecond */
44726 @};
44727 @end smallexample
44728
44729 The integral datatypes conform to the definitions given in the
44730 appropriate section (see @ref{Integral Datatypes}, for details) so this
44731 structure is of size 8 bytes.
44732
44733 @node Constants
44734 @subsection Constants
44735 @cindex constants, in file-i/o protocol
44736
44737 The following values are used for the constants inside of the
44738 protocol. @value{GDBN} and target are responsible for translating these
44739 values before and after the call as needed.
44740
44741 @menu
44742 * Open Flags::
44743 * mode_t Values::
44744 * Errno Values::
44745 * Lseek Flags::
44746 * Limits::
44747 @end menu
44748
44749 @node Open Flags
44750 @unnumberedsubsubsec Open Flags
44751 @cindex open flags, in file-i/o protocol
44752
44753 All values are given in hexadecimal representation.
44754
44755 @smallexample
44756 O_RDONLY 0x0
44757 O_WRONLY 0x1
44758 O_RDWR 0x2
44759 O_APPEND 0x8
44760 O_CREAT 0x200
44761 O_TRUNC 0x400
44762 O_EXCL 0x800
44763 @end smallexample
44764
44765 @node mode_t Values
44766 @unnumberedsubsubsec mode_t Values
44767 @cindex mode_t values, in file-i/o protocol
44768
44769 All values are given in octal representation.
44770
44771 @smallexample
44772 S_IFREG 0100000
44773 S_IFDIR 040000
44774 S_IRUSR 0400
44775 S_IWUSR 0200
44776 S_IXUSR 0100
44777 S_IRGRP 040
44778 S_IWGRP 020
44779 S_IXGRP 010
44780 S_IROTH 04
44781 S_IWOTH 02
44782 S_IXOTH 01
44783 @end smallexample
44784
44785 @node Errno Values
44786 @unnumberedsubsubsec Errno Values
44787 @cindex errno values, in file-i/o protocol
44788
44789 All values are given in decimal representation.
44790
44791 @smallexample
44792 EPERM 1
44793 ENOENT 2
44794 EINTR 4
44795 EBADF 9
44796 EACCES 13
44797 EFAULT 14
44798 EBUSY 16
44799 EEXIST 17
44800 ENODEV 19
44801 ENOTDIR 20
44802 EISDIR 21
44803 EINVAL 22
44804 ENFILE 23
44805 EMFILE 24
44806 EFBIG 27
44807 ENOSPC 28
44808 ESPIPE 29
44809 EROFS 30
44810 ENAMETOOLONG 91
44811 EUNKNOWN 9999
44812 @end smallexample
44813
44814 @code{EUNKNOWN} is used as a fallback error value if a host system returns
44815 any error value not in the list of supported error numbers.
44816
44817 @node Lseek Flags
44818 @unnumberedsubsubsec Lseek Flags
44819 @cindex lseek flags, in file-i/o protocol
44820
44821 @smallexample
44822 SEEK_SET 0
44823 SEEK_CUR 1
44824 SEEK_END 2
44825 @end smallexample
44826
44827 @node Limits
44828 @unnumberedsubsubsec Limits
44829 @cindex limits, in file-i/o protocol
44830
44831 All values are given in decimal representation.
44832
44833 @smallexample
44834 INT_MIN -2147483648
44835 INT_MAX 2147483647
44836 UINT_MAX 4294967295
44837 LONG_MIN -9223372036854775808
44838 LONG_MAX 9223372036854775807
44839 ULONG_MAX 18446744073709551615
44840 @end smallexample
44841
44842 @node File-I/O Examples
44843 @subsection File-I/O Examples
44844 @cindex file-i/o examples
44845
44846 Example sequence of a write call, file descriptor 3, buffer is at target
44847 address 0x1234, 6 bytes should be written:
44848
44849 @smallexample
44850 <- @code{Fwrite,3,1234,6}
44851 @emph{request memory read from target}
44852 -> @code{m1234,6}
44853 <- XXXXXX
44854 @emph{return "6 bytes written"}
44855 -> @code{F6}
44856 @end smallexample
44857
44858 Example sequence of a read call, file descriptor 3, buffer is at target
44859 address 0x1234, 6 bytes should be read:
44860
44861 @smallexample
44862 <- @code{Fread,3,1234,6}
44863 @emph{request memory write to target}
44864 -> @code{X1234,6:XXXXXX}
44865 @emph{return "6 bytes read"}
44866 -> @code{F6}
44867 @end smallexample
44868
44869 Example sequence of a read call, call fails on the host due to invalid
44870 file descriptor (@code{EBADF}):
44871
44872 @smallexample
44873 <- @code{Fread,3,1234,6}
44874 -> @code{F-1,9}
44875 @end smallexample
44876
44877 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
44878 host is called:
44879
44880 @smallexample
44881 <- @code{Fread,3,1234,6}
44882 -> @code{F-1,4,C}
44883 <- @code{T02}
44884 @end smallexample
44885
44886 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
44887 host is called:
44888
44889 @smallexample
44890 <- @code{Fread,3,1234,6}
44891 -> @code{X1234,6:XXXXXX}
44892 <- @code{T02}
44893 @end smallexample
44894
44895 @node Library List Format
44896 @section Library List Format
44897 @cindex library list format, remote protocol
44898
44899 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
44900 same process as your application to manage libraries. In this case,
44901 @value{GDBN} can use the loader's symbol table and normal memory
44902 operations to maintain a list of shared libraries. On other
44903 platforms, the operating system manages loaded libraries.
44904 @value{GDBN} can not retrieve the list of currently loaded libraries
44905 through memory operations, so it uses the @samp{qXfer:libraries:read}
44906 packet (@pxref{qXfer library list read}) instead. The remote stub
44907 queries the target's operating system and reports which libraries
44908 are loaded.
44909
44910 The @samp{qXfer:libraries:read} packet returns an XML document which
44911 lists loaded libraries and their offsets. Each library has an
44912 associated name and one or more segment or section base addresses,
44913 which report where the library was loaded in memory.
44914
44915 For the common case of libraries that are fully linked binaries, the
44916 library should have a list of segments. If the target supports
44917 dynamic linking of a relocatable object file, its library XML element
44918 should instead include a list of allocated sections. The segment or
44919 section bases are start addresses, not relocation offsets; they do not
44920 depend on the library's link-time base addresses.
44921
44922 @value{GDBN} must be linked with the Expat library to support XML
44923 library lists. @xref{Expat}.
44924
44925 A simple memory map, with one loaded library relocated by a single
44926 offset, looks like this:
44927
44928 @smallexample
44929 <library-list>
44930 <library name="/lib/libc.so.6">
44931 <segment address="0x10000000"/>
44932 </library>
44933 </library-list>
44934 @end smallexample
44935
44936 Another simple memory map, with one loaded library with three
44937 allocated sections (.text, .data, .bss), looks like this:
44938
44939 @smallexample
44940 <library-list>
44941 <library name="sharedlib.o">
44942 <section address="0x10000000"/>
44943 <section address="0x20000000"/>
44944 <section address="0x30000000"/>
44945 </library>
44946 </library-list>
44947 @end smallexample
44948
44949 The format of a library list is described by this DTD:
44950
44951 @smallexample
44952 <!-- library-list: Root element with versioning -->
44953 <!ELEMENT library-list (library)*>
44954 <!ATTLIST library-list version CDATA #FIXED "1.0">
44955 <!ELEMENT library (segment*, section*)>
44956 <!ATTLIST library name CDATA #REQUIRED>
44957 <!ELEMENT segment EMPTY>
44958 <!ATTLIST segment address CDATA #REQUIRED>
44959 <!ELEMENT section EMPTY>
44960 <!ATTLIST section address CDATA #REQUIRED>
44961 @end smallexample
44962
44963 In addition, segments and section descriptors cannot be mixed within a
44964 single library element, and you must supply at least one segment or
44965 section for each library.
44966
44967 @node Library List Format for SVR4 Targets
44968 @section Library List Format for SVR4 Targets
44969 @cindex library list format, remote protocol
44970
44971 On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
44972 (e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
44973 shared libraries. Still a special library list provided by this packet is
44974 more efficient for the @value{GDBN} remote protocol.
44975
44976 The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
44977 loaded libraries and their SVR4 linker parameters. For each library on SVR4
44978 target, the following parameters are reported:
44979
44980 @itemize @minus
44981 @item
44982 @code{name}, the absolute file name from the @code{l_name} field of
44983 @code{struct link_map}.
44984 @item
44985 @code{lm} with address of @code{struct link_map} used for TLS
44986 (Thread Local Storage) access.
44987 @item
44988 @code{l_addr}, the displacement as read from the field @code{l_addr} of
44989 @code{struct link_map}. For prelinked libraries this is not an absolute
44990 memory address. It is a displacement of absolute memory address against
44991 address the file was prelinked to during the library load.
44992 @item
44993 @code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
44994 @end itemize
44995
44996 Additionally the single @code{main-lm} attribute specifies address of
44997 @code{struct link_map} used for the main executable. This parameter is used
44998 for TLS access and its presence is optional.
44999
45000 @value{GDBN} must be linked with the Expat library to support XML
45001 SVR4 library lists. @xref{Expat}.
45002
45003 A simple memory map, with two loaded libraries (which do not use prelink),
45004 looks like this:
45005
45006 @smallexample
45007 <library-list-svr4 version="1.0" main-lm="0xe4f8f8">
45008 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
45009 l_ld="0xe4eefc"/>
45010 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
45011 l_ld="0x152350"/>
45012 </library-list-svr>
45013 @end smallexample
45014
45015 The format of an SVR4 library list is described by this DTD:
45016
45017 @smallexample
45018 <!-- library-list-svr4: Root element with versioning -->
45019 <!ELEMENT library-list-svr4 (library)*>
45020 <!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
45021 <!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
45022 <!ELEMENT library EMPTY>
45023 <!ATTLIST library name CDATA #REQUIRED>
45024 <!ATTLIST library lm CDATA #REQUIRED>
45025 <!ATTLIST library l_addr CDATA #REQUIRED>
45026 <!ATTLIST library l_ld CDATA #REQUIRED>
45027 @end smallexample
45028
45029 @node Memory Map Format
45030 @section Memory Map Format
45031 @cindex memory map format
45032
45033 To be able to write into flash memory, @value{GDBN} needs to obtain a
45034 memory map from the target. This section describes the format of the
45035 memory map.
45036
45037 The memory map is obtained using the @samp{qXfer:memory-map:read}
45038 (@pxref{qXfer memory map read}) packet and is an XML document that
45039 lists memory regions.
45040
45041 @value{GDBN} must be linked with the Expat library to support XML
45042 memory maps. @xref{Expat}.
45043
45044 The top-level structure of the document is shown below:
45045
45046 @smallexample
45047 <?xml version="1.0"?>
45048 <!DOCTYPE memory-map
45049 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
45050 "http://sourceware.org/gdb/gdb-memory-map.dtd">
45051 <memory-map>
45052 region...
45053 </memory-map>
45054 @end smallexample
45055
45056 Each region can be either:
45057
45058 @itemize
45059
45060 @item
45061 A region of RAM starting at @var{addr} and extending for @var{length}
45062 bytes from there:
45063
45064 @smallexample
45065 <memory type="ram" start="@var{addr}" length="@var{length}"/>
45066 @end smallexample
45067
45068
45069 @item
45070 A region of read-only memory:
45071
45072 @smallexample
45073 <memory type="rom" start="@var{addr}" length="@var{length}"/>
45074 @end smallexample
45075
45076
45077 @item
45078 A region of flash memory, with erasure blocks @var{blocksize}
45079 bytes in length:
45080
45081 @smallexample
45082 <memory type="flash" start="@var{addr}" length="@var{length}">
45083 <property name="blocksize">@var{blocksize}</property>
45084 </memory>
45085 @end smallexample
45086
45087 @end itemize
45088
45089 Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
45090 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
45091 packets to write to addresses in such ranges.
45092
45093 The formal DTD for memory map format is given below:
45094
45095 @smallexample
45096 <!-- ................................................... -->
45097 <!-- Memory Map XML DTD ................................ -->
45098 <!-- File: memory-map.dtd .............................. -->
45099 <!-- .................................... .............. -->
45100 <!-- memory-map.dtd -->
45101 <!-- memory-map: Root element with versioning -->
45102 <!ELEMENT memory-map (memory)*>
45103 <!ATTLIST memory-map version CDATA #FIXED "1.0.0">
45104 <!ELEMENT memory (property)*>
45105 <!-- memory: Specifies a memory region,
45106 and its type, or device. -->
45107 <!ATTLIST memory type (ram|rom|flash) #REQUIRED
45108 start CDATA #REQUIRED
45109 length CDATA #REQUIRED>
45110 <!-- property: Generic attribute tag -->
45111 <!ELEMENT property (#PCDATA | property)*>
45112 <!ATTLIST property name (blocksize) #REQUIRED>
45113 @end smallexample
45114
45115 @node Thread List Format
45116 @section Thread List Format
45117 @cindex thread list format
45118
45119 To efficiently update the list of threads and their attributes,
45120 @value{GDBN} issues the @samp{qXfer:threads:read} packet
45121 (@pxref{qXfer threads read}) and obtains the XML document with
45122 the following structure:
45123
45124 @smallexample
45125 <?xml version="1.0"?>
45126 <threads>
45127 <thread id="id" core="0" name="name">
45128 ... description ...
45129 </thread>
45130 </threads>
45131 @end smallexample
45132
45133 Each @samp{thread} element must have the @samp{id} attribute that
45134 identifies the thread (@pxref{thread-id syntax}). The
45135 @samp{core} attribute, if present, specifies which processor core
45136 the thread was last executing on. The @samp{name} attribute, if
45137 present, specifies the human-readable name of the thread. The content
45138 of the of @samp{thread} element is interpreted as human-readable
45139 auxiliary information. The @samp{handle} attribute, if present,
45140 is a hex encoded representation of the thread handle.
45141
45142
45143 @node Traceframe Info Format
45144 @section Traceframe Info Format
45145 @cindex traceframe info format
45146
45147 To be able to know which objects in the inferior can be examined when
45148 inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
45149 memory ranges, registers and trace state variables that have been
45150 collected in a traceframe.
45151
45152 This list is obtained using the @samp{qXfer:traceframe-info:read}
45153 (@pxref{qXfer traceframe info read}) packet and is an XML document.
45154
45155 @value{GDBN} must be linked with the Expat library to support XML
45156 traceframe info discovery. @xref{Expat}.
45157
45158 The top-level structure of the document is shown below:
45159
45160 @smallexample
45161 <?xml version="1.0"?>
45162 <!DOCTYPE traceframe-info
45163 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
45164 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
45165 <traceframe-info>
45166 block...
45167 </traceframe-info>
45168 @end smallexample
45169
45170 Each traceframe block can be either:
45171
45172 @itemize
45173
45174 @item
45175 A region of collected memory starting at @var{addr} and extending for
45176 @var{length} bytes from there:
45177
45178 @smallexample
45179 <memory start="@var{addr}" length="@var{length}"/>
45180 @end smallexample
45181
45182 @item
45183 A block indicating trace state variable numbered @var{number} has been
45184 collected:
45185
45186 @smallexample
45187 <tvar id="@var{number}"/>
45188 @end smallexample
45189
45190 @end itemize
45191
45192 The formal DTD for the traceframe info format is given below:
45193
45194 @smallexample
45195 <!ELEMENT traceframe-info (memory | tvar)* >
45196 <!ATTLIST traceframe-info version CDATA #FIXED "1.0">
45197
45198 <!ELEMENT memory EMPTY>
45199 <!ATTLIST memory start CDATA #REQUIRED
45200 length CDATA #REQUIRED>
45201 <!ELEMENT tvar>
45202 <!ATTLIST tvar id CDATA #REQUIRED>
45203 @end smallexample
45204
45205 @node Branch Trace Format
45206 @section Branch Trace Format
45207 @cindex branch trace format
45208
45209 In order to display the branch trace of an inferior thread,
45210 @value{GDBN} needs to obtain the list of branches. This list is
45211 represented as list of sequential code blocks that are connected via
45212 branches. The code in each block has been executed sequentially.
45213
45214 This list is obtained using the @samp{qXfer:btrace:read}
45215 (@pxref{qXfer btrace read}) packet and is an XML document.
45216
45217 @value{GDBN} must be linked with the Expat library to support XML
45218 traceframe info discovery. @xref{Expat}.
45219
45220 The top-level structure of the document is shown below:
45221
45222 @smallexample
45223 <?xml version="1.0"?>
45224 <!DOCTYPE btrace
45225 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
45226 "http://sourceware.org/gdb/gdb-btrace.dtd">
45227 <btrace>
45228 block...
45229 </btrace>
45230 @end smallexample
45231
45232 @itemize
45233
45234 @item
45235 A block of sequentially executed instructions starting at @var{begin}
45236 and ending at @var{end}:
45237
45238 @smallexample
45239 <block begin="@var{begin}" end="@var{end}"/>
45240 @end smallexample
45241
45242 @end itemize
45243
45244 The formal DTD for the branch trace format is given below:
45245
45246 @smallexample
45247 <!ELEMENT btrace (block* | pt) >
45248 <!ATTLIST btrace version CDATA #FIXED "1.0">
45249
45250 <!ELEMENT block EMPTY>
45251 <!ATTLIST block begin CDATA #REQUIRED
45252 end CDATA #REQUIRED>
45253
45254 <!ELEMENT pt (pt-config?, raw?)>
45255
45256 <!ELEMENT pt-config (cpu?)>
45257
45258 <!ELEMENT cpu EMPTY>
45259 <!ATTLIST cpu vendor CDATA #REQUIRED
45260 family CDATA #REQUIRED
45261 model CDATA #REQUIRED
45262 stepping CDATA #REQUIRED>
45263
45264 <!ELEMENT raw (#PCDATA)>
45265 @end smallexample
45266
45267 @node Branch Trace Configuration Format
45268 @section Branch Trace Configuration Format
45269 @cindex branch trace configuration format
45270
45271 For each inferior thread, @value{GDBN} can obtain the branch trace
45272 configuration using the @samp{qXfer:btrace-conf:read}
45273 (@pxref{qXfer btrace-conf read}) packet.
45274
45275 The configuration describes the branch trace format and configuration
45276 settings for that format. The following information is described:
45277
45278 @table @code
45279 @item bts
45280 This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
45281 @table @code
45282 @item size
45283 The size of the @acronym{BTS} ring buffer in bytes.
45284 @end table
45285 @item pt
45286 This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
45287 PT}) format.
45288 @table @code
45289 @item size
45290 The size of the @acronym{Intel PT} ring buffer in bytes.
45291 @end table
45292 @end table
45293
45294 @value{GDBN} must be linked with the Expat library to support XML
45295 branch trace configuration discovery. @xref{Expat}.
45296
45297 The formal DTD for the branch trace configuration format is given below:
45298
45299 @smallexample
45300 <!ELEMENT btrace-conf (bts?, pt?)>
45301 <!ATTLIST btrace-conf version CDATA #FIXED "1.0">
45302
45303 <!ELEMENT bts EMPTY>
45304 <!ATTLIST bts size CDATA #IMPLIED>
45305
45306 <!ELEMENT pt EMPTY>
45307 <!ATTLIST pt size CDATA #IMPLIED>
45308 @end smallexample
45309
45310 @include agentexpr.texi
45311
45312 @node Target Descriptions
45313 @appendix Target Descriptions
45314 @cindex target descriptions
45315
45316 One of the challenges of using @value{GDBN} to debug embedded systems
45317 is that there are so many minor variants of each processor
45318 architecture in use. It is common practice for vendors to start with
45319 a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
45320 and then make changes to adapt it to a particular market niche. Some
45321 architectures have hundreds of variants, available from dozens of
45322 vendors. This leads to a number of problems:
45323
45324 @itemize @bullet
45325 @item
45326 With so many different customized processors, it is difficult for
45327 the @value{GDBN} maintainers to keep up with the changes.
45328 @item
45329 Since individual variants may have short lifetimes or limited
45330 audiences, it may not be worthwhile to carry information about every
45331 variant in the @value{GDBN} source tree.
45332 @item
45333 When @value{GDBN} does support the architecture of the embedded system
45334 at hand, the task of finding the correct architecture name to give the
45335 @command{set architecture} command can be error-prone.
45336 @end itemize
45337
45338 To address these problems, the @value{GDBN} remote protocol allows a
45339 target system to not only identify itself to @value{GDBN}, but to
45340 actually describe its own features. This lets @value{GDBN} support
45341 processor variants it has never seen before --- to the extent that the
45342 descriptions are accurate, and that @value{GDBN} understands them.
45343
45344 @value{GDBN} must be linked with the Expat library to support XML
45345 target descriptions. @xref{Expat}.
45346
45347 @menu
45348 * Retrieving Descriptions:: How descriptions are fetched from a target.
45349 * Target Description Format:: The contents of a target description.
45350 * Predefined Target Types:: Standard types available for target
45351 descriptions.
45352 * Enum Target Types:: How to define enum target types.
45353 * Standard Target Features:: Features @value{GDBN} knows about.
45354 @end menu
45355
45356 @node Retrieving Descriptions
45357 @section Retrieving Descriptions
45358
45359 Target descriptions can be read from the target automatically, or
45360 specified by the user manually. The default behavior is to read the
45361 description from the target. @value{GDBN} retrieves it via the remote
45362 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
45363 qXfer}). The @var{annex} in the @samp{qXfer} packet will be
45364 @samp{target.xml}. The contents of the @samp{target.xml} annex are an
45365 XML document, of the form described in @ref{Target Description
45366 Format}.
45367
45368 Alternatively, you can specify a file to read for the target description.
45369 If a file is set, the target will not be queried. The commands to
45370 specify a file are:
45371
45372 @table @code
45373 @cindex set tdesc filename
45374 @item set tdesc filename @var{path}
45375 Read the target description from @var{path}.
45376
45377 @cindex unset tdesc filename
45378 @item unset tdesc filename
45379 Do not read the XML target description from a file. @value{GDBN}
45380 will use the description supplied by the current target.
45381
45382 @cindex show tdesc filename
45383 @item show tdesc filename
45384 Show the filename to read for a target description, if any.
45385 @end table
45386
45387
45388 @node Target Description Format
45389 @section Target Description Format
45390 @cindex target descriptions, XML format
45391
45392 A target description annex is an @uref{http://www.w3.org/XML/, XML}
45393 document which complies with the Document Type Definition provided in
45394 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
45395 means you can use generally available tools like @command{xmllint} to
45396 check that your feature descriptions are well-formed and valid.
45397 However, to help people unfamiliar with XML write descriptions for
45398 their targets, we also describe the grammar here.
45399
45400 Target descriptions can identify the architecture of the remote target
45401 and (for some architectures) provide information about custom register
45402 sets. They can also identify the OS ABI of the remote target.
45403 @value{GDBN} can use this information to autoconfigure for your
45404 target, or to warn you if you connect to an unsupported target.
45405
45406 Here is a simple target description:
45407
45408 @smallexample
45409 <target version="1.0">
45410 <architecture>i386:x86-64</architecture>
45411 </target>
45412 @end smallexample
45413
45414 @noindent
45415 This minimal description only says that the target uses
45416 the x86-64 architecture.
45417
45418 A target description has the following overall form, with [ ] marking
45419 optional elements and @dots{} marking repeatable elements. The elements
45420 are explained further below.
45421
45422 @smallexample
45423 <?xml version="1.0"?>
45424 <!DOCTYPE target SYSTEM "gdb-target.dtd">
45425 <target version="1.0">
45426 @r{[}@var{architecture}@r{]}
45427 @r{[}@var{osabi}@r{]}
45428 @r{[}@var{compatible}@r{]}
45429 @r{[}@var{feature}@dots{}@r{]}
45430 </target>
45431 @end smallexample
45432
45433 @noindent
45434 The description is generally insensitive to whitespace and line
45435 breaks, under the usual common-sense rules. The XML version
45436 declaration and document type declaration can generally be omitted
45437 (@value{GDBN} does not require them), but specifying them may be
45438 useful for XML validation tools. The @samp{version} attribute for
45439 @samp{<target>} may also be omitted, but we recommend
45440 including it; if future versions of @value{GDBN} use an incompatible
45441 revision of @file{gdb-target.dtd}, they will detect and report
45442 the version mismatch.
45443
45444 @subsection Inclusion
45445 @cindex target descriptions, inclusion
45446 @cindex XInclude
45447 @ifnotinfo
45448 @cindex <xi:include>
45449 @end ifnotinfo
45450
45451 It can sometimes be valuable to split a target description up into
45452 several different annexes, either for organizational purposes, or to
45453 share files between different possible target descriptions. You can
45454 divide a description into multiple files by replacing any element of
45455 the target description with an inclusion directive of the form:
45456
45457 @smallexample
45458 <xi:include href="@var{document}"/>
45459 @end smallexample
45460
45461 @noindent
45462 When @value{GDBN} encounters an element of this form, it will retrieve
45463 the named XML @var{document}, and replace the inclusion directive with
45464 the contents of that document. If the current description was read
45465 using @samp{qXfer}, then so will be the included document;
45466 @var{document} will be interpreted as the name of an annex. If the
45467 current description was read from a file, @value{GDBN} will look for
45468 @var{document} as a file in the same directory where it found the
45469 original description.
45470
45471 @subsection Architecture
45472 @cindex <architecture>
45473
45474 An @samp{<architecture>} element has this form:
45475
45476 @smallexample
45477 <architecture>@var{arch}</architecture>
45478 @end smallexample
45479
45480 @var{arch} is one of the architectures from the set accepted by
45481 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
45482
45483 @subsection OS ABI
45484 @cindex @code{<osabi>}
45485
45486 This optional field was introduced in @value{GDBN} version 7.0.
45487 Previous versions of @value{GDBN} ignore it.
45488
45489 An @samp{<osabi>} element has this form:
45490
45491 @smallexample
45492 <osabi>@var{abi-name}</osabi>
45493 @end smallexample
45494
45495 @var{abi-name} is an OS ABI name from the same selection accepted by
45496 @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
45497
45498 @subsection Compatible Architecture
45499 @cindex @code{<compatible>}
45500
45501 This optional field was introduced in @value{GDBN} version 7.0.
45502 Previous versions of @value{GDBN} ignore it.
45503
45504 A @samp{<compatible>} element has this form:
45505
45506 @smallexample
45507 <compatible>@var{arch}</compatible>
45508 @end smallexample
45509
45510 @var{arch} is one of the architectures from the set accepted by
45511 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
45512
45513 A @samp{<compatible>} element is used to specify that the target
45514 is able to run binaries in some other than the main target architecture
45515 given by the @samp{<architecture>} element. For example, on the
45516 Cell Broadband Engine, the main architecture is @code{powerpc:common}
45517 or @code{powerpc:common64}, but the system is able to run binaries
45518 in the @code{spu} architecture as well. The way to describe this
45519 capability with @samp{<compatible>} is as follows:
45520
45521 @smallexample
45522 <architecture>powerpc:common</architecture>
45523 <compatible>spu</compatible>
45524 @end smallexample
45525
45526 @subsection Features
45527 @cindex <feature>
45528
45529 Each @samp{<feature>} describes some logical portion of the target
45530 system. Features are currently used to describe available CPU
45531 registers and the types of their contents. A @samp{<feature>} element
45532 has this form:
45533
45534 @smallexample
45535 <feature name="@var{name}">
45536 @r{[}@var{type}@dots{}@r{]}
45537 @var{reg}@dots{}
45538 </feature>
45539 @end smallexample
45540
45541 @noindent
45542 Each feature's name should be unique within the description. The name
45543 of a feature does not matter unless @value{GDBN} has some special
45544 knowledge of the contents of that feature; if it does, the feature
45545 should have its standard name. @xref{Standard Target Features}.
45546
45547 @subsection Types
45548
45549 Any register's value is a collection of bits which @value{GDBN} must
45550 interpret. The default interpretation is a two's complement integer,
45551 but other types can be requested by name in the register description.
45552 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
45553 Target Types}), and the description can define additional composite
45554 and enum types.
45555
45556 Each type element must have an @samp{id} attribute, which gives
45557 a unique (within the containing @samp{<feature>}) name to the type.
45558 Types must be defined before they are used.
45559
45560 @cindex <vector>
45561 Some targets offer vector registers, which can be treated as arrays
45562 of scalar elements. These types are written as @samp{<vector>} elements,
45563 specifying the array element type, @var{type}, and the number of elements,
45564 @var{count}:
45565
45566 @smallexample
45567 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
45568 @end smallexample
45569
45570 @cindex <union>
45571 If a register's value is usefully viewed in multiple ways, define it
45572 with a union type containing the useful representations. The
45573 @samp{<union>} element contains one or more @samp{<field>} elements,
45574 each of which has a @var{name} and a @var{type}:
45575
45576 @smallexample
45577 <union id="@var{id}">
45578 <field name="@var{name}" type="@var{type}"/>
45579 @dots{}
45580 </union>
45581 @end smallexample
45582
45583 @cindex <struct>
45584 @cindex <flags>
45585 If a register's value is composed from several separate values, define
45586 it with either a structure type or a flags type.
45587 A flags type may only contain bitfields.
45588 A structure type may either contain only bitfields or contain no bitfields.
45589 If the value contains only bitfields, its total size in bytes must be
45590 specified.
45591
45592 Non-bitfield values have a @var{name} and @var{type}.
45593
45594 @smallexample
45595 <struct id="@var{id}">
45596 <field name="@var{name}" type="@var{type}"/>
45597 @dots{}
45598 </struct>
45599 @end smallexample
45600
45601 Both @var{name} and @var{type} values are required.
45602 No implicit padding is added.
45603
45604 Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
45605
45606 @smallexample
45607 <struct id="@var{id}" size="@var{size}">
45608 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
45609 @dots{}
45610 </struct>
45611 @end smallexample
45612
45613 @smallexample
45614 <flags id="@var{id}" size="@var{size}">
45615 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
45616 @dots{}
45617 </flags>
45618 @end smallexample
45619
45620 The @var{name} value is required.
45621 Bitfield values may be named with the empty string, @samp{""},
45622 in which case the field is ``filler'' and its value is not printed.
45623 Not all bits need to be specified, so ``filler'' fields are optional.
45624
45625 The @var{start} and @var{end} values are required, and @var{type}
45626 is optional.
45627 The field's @var{start} must be less than or equal to its @var{end},
45628 and zero represents the least significant bit.
45629
45630 The default value of @var{type} is @code{bool} for single bit fields,
45631 and an unsigned integer otherwise.
45632
45633 Which to choose? Structures or flags?
45634
45635 Registers defined with @samp{flags} have these advantages over
45636 defining them with @samp{struct}:
45637
45638 @itemize @bullet
45639 @item
45640 Arithmetic may be performed on them as if they were integers.
45641 @item
45642 They are printed in a more readable fashion.
45643 @end itemize
45644
45645 Registers defined with @samp{struct} have one advantage over
45646 defining them with @samp{flags}:
45647
45648 @itemize @bullet
45649 @item
45650 One can fetch individual fields like in @samp{C}.
45651
45652 @smallexample
45653 (gdb) print $my_struct_reg.field3
45654 $1 = 42
45655 @end smallexample
45656
45657 @end itemize
45658
45659 @subsection Registers
45660 @cindex <reg>
45661
45662 Each register is represented as an element with this form:
45663
45664 @smallexample
45665 <reg name="@var{name}"
45666 bitsize="@var{size}"
45667 @r{[}regnum="@var{num}"@r{]}
45668 @r{[}save-restore="@var{save-restore}"@r{]}
45669 @r{[}type="@var{type}"@r{]}
45670 @r{[}group="@var{group}"@r{]}/>
45671 @end smallexample
45672
45673 @noindent
45674 The components are as follows:
45675
45676 @table @var
45677
45678 @item name
45679 The register's name; it must be unique within the target description.
45680
45681 @item bitsize
45682 The register's size, in bits.
45683
45684 @item regnum
45685 The register's number. If omitted, a register's number is one greater
45686 than that of the previous register (either in the current feature or in
45687 a preceding feature); the first register in the target description
45688 defaults to zero. This register number is used to read or write
45689 the register; e.g.@: it is used in the remote @code{p} and @code{P}
45690 packets, and registers appear in the @code{g} and @code{G} packets
45691 in order of increasing register number.
45692
45693 @item save-restore
45694 Whether the register should be preserved across inferior function
45695 calls; this must be either @code{yes} or @code{no}. The default is
45696 @code{yes}, which is appropriate for most registers except for
45697 some system control registers; this is not related to the target's
45698 ABI.
45699
45700 @item type
45701 The type of the register. It may be a predefined type, a type
45702 defined in the current feature, or one of the special types @code{int}
45703 and @code{float}. @code{int} is an integer type of the correct size
45704 for @var{bitsize}, and @code{float} is a floating point type (in the
45705 architecture's normal floating point format) of the correct size for
45706 @var{bitsize}. The default is @code{int}.
45707
45708 @item group
45709 The register group to which this register belongs. It can be one of the
45710 standard register groups @code{general}, @code{float}, @code{vector} or an
45711 arbitrary string. Group names should be limited to alphanumeric characters.
45712 If a group name is made up of multiple words the words may be separated by
45713 hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
45714 @var{group} is specified, @value{GDBN} will not display the register in
45715 @code{info registers}.
45716
45717 @end table
45718
45719 @node Predefined Target Types
45720 @section Predefined Target Types
45721 @cindex target descriptions, predefined types
45722
45723 Type definitions in the self-description can build up composite types
45724 from basic building blocks, but can not define fundamental types. Instead,
45725 standard identifiers are provided by @value{GDBN} for the fundamental
45726 types. The currently supported types are:
45727
45728 @table @code
45729
45730 @item bool
45731 Boolean type, occupying a single bit.
45732
45733 @item int8
45734 @itemx int16
45735 @itemx int24
45736 @itemx int32
45737 @itemx int64
45738 @itemx int128
45739 Signed integer types holding the specified number of bits.
45740
45741 @item uint8
45742 @itemx uint16
45743 @itemx uint24
45744 @itemx uint32
45745 @itemx uint64
45746 @itemx uint128
45747 Unsigned integer types holding the specified number of bits.
45748
45749 @item code_ptr
45750 @itemx data_ptr
45751 Pointers to unspecified code and data. The program counter and
45752 any dedicated return address register may be marked as code
45753 pointers; printing a code pointer converts it into a symbolic
45754 address. The stack pointer and any dedicated address registers
45755 may be marked as data pointers.
45756
45757 @item ieee_single
45758 Single precision IEEE floating point.
45759
45760 @item ieee_double
45761 Double precision IEEE floating point.
45762
45763 @item arm_fpa_ext
45764 The 12-byte extended precision format used by ARM FPA registers.
45765
45766 @item i387_ext
45767 The 10-byte extended precision format used by x87 registers.
45768
45769 @item i386_eflags
45770 32bit @sc{eflags} register used by x86.
45771
45772 @item i386_mxcsr
45773 32bit @sc{mxcsr} register used by x86.
45774
45775 @end table
45776
45777 @node Enum Target Types
45778 @section Enum Target Types
45779 @cindex target descriptions, enum types
45780
45781 Enum target types are useful in @samp{struct} and @samp{flags}
45782 register descriptions. @xref{Target Description Format}.
45783
45784 Enum types have a name, size and a list of name/value pairs.
45785
45786 @smallexample
45787 <enum id="@var{id}" size="@var{size}">
45788 <evalue name="@var{name}" value="@var{value}"/>
45789 @dots{}
45790 </enum>
45791 @end smallexample
45792
45793 Enums must be defined before they are used.
45794
45795 @smallexample
45796 <enum id="levels_type" size="4">
45797 <evalue name="low" value="0"/>
45798 <evalue name="high" value="1"/>
45799 </enum>
45800 <flags id="flags_type" size="4">
45801 <field name="X" start="0"/>
45802 <field name="LEVEL" start="1" end="1" type="levels_type"/>
45803 </flags>
45804 <reg name="flags" bitsize="32" type="flags_type"/>
45805 @end smallexample
45806
45807 Given that description, a value of 3 for the @samp{flags} register
45808 would be printed as:
45809
45810 @smallexample
45811 (gdb) info register flags
45812 flags 0x3 [ X LEVEL=high ]
45813 @end smallexample
45814
45815 @node Standard Target Features
45816 @section Standard Target Features
45817 @cindex target descriptions, standard features
45818
45819 A target description must contain either no registers or all the
45820 target's registers. If the description contains no registers, then
45821 @value{GDBN} will assume a default register layout, selected based on
45822 the architecture. If the description contains any registers, the
45823 default layout will not be used; the standard registers must be
45824 described in the target description, in such a way that @value{GDBN}
45825 can recognize them.
45826
45827 This is accomplished by giving specific names to feature elements
45828 which contain standard registers. @value{GDBN} will look for features
45829 with those names and verify that they contain the expected registers;
45830 if any known feature is missing required registers, or if any required
45831 feature is missing, @value{GDBN} will reject the target
45832 description. You can add additional registers to any of the
45833 standard features --- @value{GDBN} will display them just as if
45834 they were added to an unrecognized feature.
45835
45836 This section lists the known features and their expected contents.
45837 Sample XML documents for these features are included in the
45838 @value{GDBN} source tree, in the directory @file{gdb/features}.
45839
45840 Names recognized by @value{GDBN} should include the name of the
45841 company or organization which selected the name, and the overall
45842 architecture to which the feature applies; so e.g.@: the feature
45843 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
45844
45845 The names of registers are not case sensitive for the purpose
45846 of recognizing standard features, but @value{GDBN} will only display
45847 registers using the capitalization used in the description.
45848
45849 @menu
45850 * AArch64 Features::
45851 * ARC Features::
45852 * ARM Features::
45853 * i386 Features::
45854 * MicroBlaze Features::
45855 * MIPS Features::
45856 * M68K Features::
45857 * NDS32 Features::
45858 * Nios II Features::
45859 * OpenRISC 1000 Features::
45860 * PowerPC Features::
45861 * RISC-V Features::
45862 * RX Features::
45863 * S/390 and System z Features::
45864 * Sparc Features::
45865 * TIC6x Features::
45866 @end menu
45867
45868
45869 @node AArch64 Features
45870 @subsection AArch64 Features
45871 @cindex target descriptions, AArch64 features
45872
45873 The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
45874 targets. It should contain registers @samp{x0} through @samp{x30},
45875 @samp{sp}, @samp{pc}, and @samp{cpsr}.
45876
45877 The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
45878 it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
45879 and @samp{fpcr}.
45880
45881 The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
45882 it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
45883 through @samp{p15}, @samp{ffr} and @samp{vg}.
45884
45885 The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
45886 it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
45887
45888 @node ARC Features
45889 @subsection ARC Features
45890 @cindex target descriptions, ARC Features
45891
45892 ARC processors are so configurable that even core registers and their numbers
45893 are not predetermined completely. Moreover, @emph{flags} and @emph{PC}
45894 registers, which are important to @value{GDBN}, are not ``core'' registers in
45895 ARC. Therefore, there are two features that their presence is mandatory:
45896 @samp{org.gnu.gdb.arc.core} and @samp{org.gnu.gdb.arc.aux}.
45897
45898 The @samp{org.gnu.gdb.arc.core} feature is required for all targets. It must
45899 contain registers:
45900
45901 @itemize @minus
45902 @item
45903 @samp{r0} through @samp{r25} for normal register file targets.
45904 @item
45905 @samp{r0} through @samp{r3}, and @samp{r10} through @samp{r15} for reduced
45906 register file targets.
45907 @item
45908 @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}@footnote{Not necessary for ARCv1.},
45909 @samp{blink}, @samp{lp_count}, @samp{pcl}.
45910 @end itemize
45911
45912 In case of an ARCompact target (ARCv1 ISA), the @samp{org.gnu.gdb.arc.core}
45913 feature may contain registers @samp{ilink1} and @samp{ilink2}. While in case
45914 of ARC EM and ARC HS targets (ARCv2 ISA), register @samp{ilink} may be present.
45915 The difference between ARCv1 and ARCv2 is the naming of registers @emph{29th}
45916 and @emph{30th}. They are called @samp{ilink1} and @samp{ilink2} for ARCv1 and
45917 are optional. For ARCv2, they are called @samp{ilink} and @samp{r30} and only
45918 @samp{ilink} is optional. The optionality of @samp{ilink*} registers is
45919 because of their inaccessibility during user space debugging sessions.
45920
45921 Extension core registers @samp{r32} through @samp{r59} are optional and their
45922 existence depends on the configuration. When debugging GNU/Linux applications,
45923 i.e.@: user space debugging, these core registers are not available.
45924
45925 The @samp{org.gnu.gdb.arc.aux} feature is required for all ARC targets. Here
45926 is the list of registers pertinent to this feature:
45927
45928 @itemize @minus
45929 @item
45930 mandatory: @samp{pc} and @samp{status32}.
45931 @item
45932 optional: @samp{lp_start}, @samp{lp_end}, and @samp{bta}.
45933 @end itemize
45934
45935 @node ARM Features
45936 @subsection ARM Features
45937 @cindex target descriptions, ARM features
45938
45939 The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
45940 ARM targets.
45941 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
45942 @samp{lr}, @samp{pc}, and @samp{cpsr}.
45943
45944 For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
45945 feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
45946 registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
45947 and @samp{xpsr}.
45948
45949 The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
45950 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
45951
45952 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
45953 it should contain at least registers @samp{wR0} through @samp{wR15} and
45954 @samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
45955 @samp{wCSSF}, and @samp{wCASF} registers are optional.
45956
45957 The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
45958 should contain at least registers @samp{d0} through @samp{d15}. If
45959 they are present, @samp{d16} through @samp{d31} should also be included.
45960 @value{GDBN} will synthesize the single-precision registers from
45961 halves of the double-precision registers.
45962
45963 The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
45964 need to contain registers; it instructs @value{GDBN} to display the
45965 VFP double-precision registers as vectors and to synthesize the
45966 quad-precision registers from pairs of double-precision registers.
45967 If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
45968 be present and include 32 double-precision registers.
45969
45970 @node i386 Features
45971 @subsection i386 Features
45972 @cindex target descriptions, i386 features
45973
45974 The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
45975 targets. It should describe the following registers:
45976
45977 @itemize @minus
45978 @item
45979 @samp{eax} through @samp{edi} plus @samp{eip} for i386
45980 @item
45981 @samp{rax} through @samp{r15} plus @samp{rip} for amd64
45982 @item
45983 @samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
45984 @samp{fs}, @samp{gs}
45985 @item
45986 @samp{st0} through @samp{st7}
45987 @item
45988 @samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
45989 @samp{foseg}, @samp{fooff} and @samp{fop}
45990 @end itemize
45991
45992 The register sets may be different, depending on the target.
45993
45994 The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
45995 describe registers:
45996
45997 @itemize @minus
45998 @item
45999 @samp{xmm0} through @samp{xmm7} for i386
46000 @item
46001 @samp{xmm0} through @samp{xmm15} for amd64
46002 @item
46003 @samp{mxcsr}
46004 @end itemize
46005
46006 The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
46007 @samp{org.gnu.gdb.i386.sse} feature. It should
46008 describe the upper 128 bits of @sc{ymm} registers:
46009
46010 @itemize @minus
46011 @item
46012 @samp{ymm0h} through @samp{ymm7h} for i386
46013 @item
46014 @samp{ymm0h} through @samp{ymm15h} for amd64
46015 @end itemize
46016
46017 The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
46018 Memory Protection Extension (MPX). It should describe the following registers:
46019
46020 @itemize @minus
46021 @item
46022 @samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
46023 @item
46024 @samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
46025 @end itemize
46026
46027 The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
46028 describe a single register, @samp{orig_eax}.
46029
46030 The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
46031 describe two system registers: @samp{fs_base} and @samp{gs_base}.
46032
46033 The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
46034 @samp{org.gnu.gdb.i386.avx} feature. It should
46035 describe additional @sc{xmm} registers:
46036
46037 @itemize @minus
46038 @item
46039 @samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
46040 @end itemize
46041
46042 It should describe the upper 128 bits of additional @sc{ymm} registers:
46043
46044 @itemize @minus
46045 @item
46046 @samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
46047 @end itemize
46048
46049 It should
46050 describe the upper 256 bits of @sc{zmm} registers:
46051
46052 @itemize @minus
46053 @item
46054 @samp{zmm0h} through @samp{zmm7h} for i386.
46055 @item
46056 @samp{zmm0h} through @samp{zmm15h} for amd64.
46057 @end itemize
46058
46059 It should
46060 describe the additional @sc{zmm} registers:
46061
46062 @itemize @minus
46063 @item
46064 @samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
46065 @end itemize
46066
46067 The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
46068 describe a single register, @samp{pkru}. It is a 32-bit register
46069 valid for i386 and amd64.
46070
46071 @node MicroBlaze Features
46072 @subsection MicroBlaze Features
46073 @cindex target descriptions, MicroBlaze features
46074
46075 The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
46076 targets. It should contain registers @samp{r0} through @samp{r31},
46077 @samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
46078 @samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
46079 @samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
46080
46081 The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
46082 If present, it should contain registers @samp{rshr} and @samp{rslr}
46083
46084 @node MIPS Features
46085 @subsection @acronym{MIPS} Features
46086 @cindex target descriptions, @acronym{MIPS} features
46087
46088 The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
46089 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
46090 @samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
46091 on the target.
46092
46093 The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
46094 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
46095 registers. They may be 32-bit or 64-bit depending on the target.
46096
46097 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
46098 it may be optional in a future version of @value{GDBN}. It should
46099 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
46100 @samp{fir}. They may be 32-bit or 64-bit depending on the target.
46101
46102 The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
46103 contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
46104 @samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
46105 be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
46106
46107 The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
46108 contain a single register, @samp{restart}, which is used by the
46109 Linux kernel to control restartable syscalls.
46110
46111 @node M68K Features
46112 @subsection M68K Features
46113 @cindex target descriptions, M68K features
46114
46115 @table @code
46116 @item @samp{org.gnu.gdb.m68k.core}
46117 @itemx @samp{org.gnu.gdb.coldfire.core}
46118 @itemx @samp{org.gnu.gdb.fido.core}
46119 One of those features must be always present.
46120 The feature that is present determines which flavor of m68k is
46121 used. The feature that is present should contain registers
46122 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
46123 @samp{sp}, @samp{ps} and @samp{pc}.
46124
46125 @item @samp{org.gnu.gdb.coldfire.fp}
46126 This feature is optional. If present, it should contain registers
46127 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
46128 @samp{fpiaddr}.
46129
46130 Note that, despite the fact that this feature's name says
46131 @samp{coldfire}, it is used to describe any floating point registers.
46132 The size of the registers must match the main m68k flavor; so, for
46133 example, if the primary feature is reported as @samp{coldfire}, then
46134 64-bit floating point registers are required.
46135 @end table
46136
46137 @node NDS32 Features
46138 @subsection NDS32 Features
46139 @cindex target descriptions, NDS32 features
46140
46141 The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
46142 targets. It should contain at least registers @samp{r0} through
46143 @samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
46144 and @samp{pc}.
46145
46146 The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
46147 it should contain 64-bit double-precision floating-point registers
46148 @samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
46149 @samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
46150
46151 @emph{Note:} The first sixteen 64-bit double-precision floating-point
46152 registers are overlapped with the thirty-two 32-bit single-precision
46153 floating-point registers. The 32-bit single-precision registers, if
46154 not being listed explicitly, will be synthesized from halves of the
46155 overlapping 64-bit double-precision registers. Listing 32-bit
46156 single-precision registers explicitly is deprecated, and the
46157 support to it could be totally removed some day.
46158
46159 @node Nios II Features
46160 @subsection Nios II Features
46161 @cindex target descriptions, Nios II features
46162
46163 The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
46164 targets. It should contain the 32 core registers (@samp{zero},
46165 @samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
46166 @samp{pc}, and the 16 control registers (@samp{status} through
46167 @samp{mpuacc}).
46168
46169 @node OpenRISC 1000 Features
46170 @subsection Openrisc 1000 Features
46171 @cindex target descriptions, OpenRISC 1000 features
46172
46173 The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
46174 targets. It should contain the 32 general purpose registers (@samp{r0}
46175 through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
46176
46177 @node PowerPC Features
46178 @subsection PowerPC Features
46179 @cindex target descriptions, PowerPC features
46180
46181 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
46182 targets. It should contain registers @samp{r0} through @samp{r31},
46183 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
46184 @samp{xer}. They may be 32-bit or 64-bit depending on the target.
46185
46186 The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
46187 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
46188
46189 The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
46190 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
46191 @samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
46192 through @samp{v31} as aliases for the corresponding @samp{vrX}
46193 registers.
46194
46195 The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
46196 contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
46197 combine these registers with the floating point registers (@samp{f0}
46198 through @samp{f31}) and the altivec registers (@samp{vr0} through
46199 @samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
46200 @samp{vs63}, the set of vector-scalar registers for POWER7.
46201 Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
46202 @samp{org.gnu.gdb.power.altivec}.
46203
46204 The @samp{org.gnu.gdb.power.spe} feature is optional. It should
46205 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
46206 @samp{spefscr}. SPE targets should provide 32-bit registers in
46207 @samp{org.gnu.gdb.power.core} and provide the upper halves in
46208 @samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
46209 these to present registers @samp{ev0} through @samp{ev31} to the
46210 user.
46211
46212 The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
46213 contain the 64-bit register @samp{ppr}.
46214
46215 The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
46216 contain the 64-bit register @samp{dscr}.
46217
46218 The @samp{org.gnu.gdb.power.tar} feature is optional. It should
46219 contain the 64-bit register @samp{tar}.
46220
46221 The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
46222 contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
46223 64-bit wide.
46224
46225 The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
46226 contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
46227 and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
46228 server PMU registers provided by @sc{gnu}/Linux.
46229
46230 The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
46231 contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
46232 64-bit wide.
46233
46234 The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
46235 contain the checkpointed general-purpose registers @samp{cr0} through
46236 @samp{cr31}, as well as the checkpointed registers @samp{clr} and
46237 @samp{cctr}. These registers may all be either 32-bit or 64-bit
46238 depending on the target. It should also contain the checkpointed
46239 registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
46240 wide.
46241
46242 The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
46243 contain the checkpointed 64-bit floating-point registers @samp{cf0}
46244 through @samp{cf31}, as well as the checkpointed 64-bit register
46245 @samp{cfpscr}.
46246
46247 The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
46248 should contain the checkpointed altivec registers @samp{cvr0} through
46249 @samp{cvr31}, all 128-bit wide. It should also contain the
46250 checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
46251 wide.
46252
46253 The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
46254 contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
46255 will combine these registers with the checkpointed floating point
46256 registers (@samp{cf0} through @samp{cf31}) and the checkpointed
46257 altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
46258 128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
46259 @samp{cvs63}. Therefore, this feature requires both
46260 @samp{org.gnu.gdb.power.htm.altivec} and
46261 @samp{org.gnu.gdb.power.htm.fpu}.
46262
46263 The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
46264 contain the 64-bit checkpointed register @samp{cppr}.
46265
46266 The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
46267 contain the 64-bit checkpointed register @samp{cdscr}.
46268
46269 The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
46270 contain the 64-bit checkpointed register @samp{ctar}.
46271
46272
46273 @node RISC-V Features
46274 @subsection RISC-V Features
46275 @cindex target descriptions, RISC-V Features
46276
46277 The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
46278 targets. It should contain the registers @samp{x0} through
46279 @samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
46280 @samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
46281 etc).
46282
46283 The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
46284 should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
46285 @samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
46286 architectural register names, or the ABI names can be used.
46287
46288 The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
46289 it should contain registers that are not backed by real registers on
46290 the target, but are instead virtual, where the register value is
46291 derived from other target state. In many ways these are like
46292 @value{GDBN}s pseudo-registers, except implemented by the target.
46293 Currently the only register expected in this set is the one byte
46294 @samp{priv} register that contains the target's privilege level in the
46295 least significant two bits.
46296
46297 The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
46298 should contain all of the target's standard CSRs. Standard CSRs are
46299 those defined in the RISC-V specification documents. There is some
46300 overlap between this feature and the fpu feature; the @samp{fflags},
46301 @samp{frm}, and @samp{fcsr} registers could be in either feature. The
46302 expectation is that these registers will be in the fpu feature if the
46303 target has floating point hardware, but can be moved into the csr
46304 feature if the target has the floating point control registers, but no
46305 other floating point hardware.
46306
46307 @node RX Features
46308 @subsection RX Features
46309 @cindex target descriptions, RX Features
46310
46311 The @samp{org.gnu.gdb.rx.core} feature is required for RX
46312 targets. It should contain the registers @samp{r0} through
46313 @samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
46314 @samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
46315
46316 @node S/390 and System z Features
46317 @subsection S/390 and System z Features
46318 @cindex target descriptions, S/390 features
46319 @cindex target descriptions, System z features
46320
46321 The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
46322 System z targets. It should contain the PSW and the 16 general
46323 registers. In particular, System z targets should provide the 64-bit
46324 registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
46325 S/390 targets should provide the 32-bit versions of these registers.
46326 A System z target that runs in 31-bit addressing mode should provide
46327 32-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
46328 register's upper halves @samp{r0h} through @samp{r15h}, and their
46329 lower halves @samp{r0l} through @samp{r15l}.
46330
46331 The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
46332 contain the 64-bit registers @samp{f0} through @samp{f15}, and
46333 @samp{fpc}.
46334
46335 The @samp{org.gnu.gdb.s390.acr} feature is required. It should
46336 contain the 32-bit registers @samp{acr0} through @samp{acr15}.
46337
46338 The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
46339 contain the register @samp{orig_r2}, which is 64-bit wide on System z
46340 targets and 32-bit otherwise. In addition, the feature may contain
46341 the @samp{last_break} register, whose width depends on the addressing
46342 mode, as well as the @samp{system_call} register, which is always
46343 32-bit wide.
46344
46345 The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
46346 contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
46347 @samp{atia}, and @samp{tr0} through @samp{tr15}.
46348
46349 The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
46350 64-bit wide registers @samp{v0l} through @samp{v15l}, which will be
46351 combined by @value{GDBN} with the floating point registers @samp{f0}
46352 through @samp{f15} to present the 128-bit wide vector registers
46353 @samp{v0} through @samp{v15}. In addition, this feature should
46354 contain the 128-bit wide vector registers @samp{v16} through
46355 @samp{v31}.
46356
46357 The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
46358 the 64-bit wide guarded-storage-control registers @samp{gsd},
46359 @samp{gssm}, and @samp{gsepla}.
46360
46361 The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
46362 the 64-bit wide guarded-storage broadcast control registers
46363 @samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
46364
46365 @node Sparc Features
46366 @subsection Sparc Features
46367 @cindex target descriptions, sparc32 features
46368 @cindex target descriptions, sparc64 features
46369 The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
46370 targets. It should describe the following registers:
46371
46372 @itemize @minus
46373 @item
46374 @samp{g0} through @samp{g7}
46375 @item
46376 @samp{o0} through @samp{o7}
46377 @item
46378 @samp{l0} through @samp{l7}
46379 @item
46380 @samp{i0} through @samp{i7}
46381 @end itemize
46382
46383 They may be 32-bit or 64-bit depending on the target.
46384
46385 Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
46386 targets. It should describe the following registers:
46387
46388 @itemize @minus
46389 @item
46390 @samp{f0} through @samp{f31}
46391 @item
46392 @samp{f32} through @samp{f62} for sparc64
46393 @end itemize
46394
46395 The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
46396 targets. It should describe the following registers:
46397
46398 @itemize @minus
46399 @item
46400 @samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
46401 @samp{fsr}, and @samp{csr} for sparc32
46402 @item
46403 @samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
46404 for sparc64
46405 @end itemize
46406
46407 @node TIC6x Features
46408 @subsection TMS320C6x Features
46409 @cindex target descriptions, TIC6x features
46410 @cindex target descriptions, TMS320C6x features
46411 The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
46412 targets. It should contain registers @samp{A0} through @samp{A15},
46413 registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
46414
46415 The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
46416 contain registers @samp{A16} through @samp{A31} and @samp{B16}
46417 through @samp{B31}.
46418
46419 The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
46420 contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
46421
46422 @node Operating System Information
46423 @appendix Operating System Information
46424 @cindex operating system information
46425
46426 Users of @value{GDBN} often wish to obtain information about the state of
46427 the operating system running on the target---for example the list of
46428 processes, or the list of open files. This section describes the
46429 mechanism that makes it possible. This mechanism is similar to the
46430 target features mechanism (@pxref{Target Descriptions}), but focuses
46431 on a different aspect of target.
46432
46433 Operating system information is retrieved from the target via the
46434 remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
46435 read}). The object name in the request should be @samp{osdata}, and
46436 the @var{annex} identifies the data to be fetched.
46437
46438 @menu
46439 * Process list::
46440 @end menu
46441
46442 @node Process list
46443 @appendixsection Process list
46444 @cindex operating system information, process list
46445
46446 When requesting the process list, the @var{annex} field in the
46447 @samp{qXfer} request should be @samp{processes}. The returned data is
46448 an XML document. The formal syntax of this document is defined in
46449 @file{gdb/features/osdata.dtd}.
46450
46451 An example document is:
46452
46453 @smallexample
46454 <?xml version="1.0"?>
46455 <!DOCTYPE target SYSTEM "osdata.dtd">
46456 <osdata type="processes">
46457 <item>
46458 <column name="pid">1</column>
46459 <column name="user">root</column>
46460 <column name="command">/sbin/init</column>
46461 <column name="cores">1,2,3</column>
46462 </item>
46463 </osdata>
46464 @end smallexample
46465
46466 Each item should include a column whose name is @samp{pid}. The value
46467 of that column should identify the process on the target. The
46468 @samp{user} and @samp{command} columns are optional, and will be
46469 displayed by @value{GDBN}. The @samp{cores} column, if present,
46470 should contain a comma-separated list of cores that this process
46471 is running on. Target may provide additional columns,
46472 which @value{GDBN} currently ignores.
46473
46474 @node Trace File Format
46475 @appendix Trace File Format
46476 @cindex trace file format
46477
46478 The trace file comes in three parts: a header, a textual description
46479 section, and a trace frame section with binary data.
46480
46481 The header has the form @code{\x7fTRACE0\n}. The first byte is
46482 @code{0x7f} so as to indicate that the file contains binary data,
46483 while the @code{0} is a version number that may have different values
46484 in the future.
46485
46486 The description section consists of multiple lines of @sc{ascii} text
46487 separated by newline characters (@code{0xa}). The lines may include a
46488 variety of optional descriptive or context-setting information, such
46489 as tracepoint definitions or register set size. @value{GDBN} will
46490 ignore any line that it does not recognize. An empty line marks the end
46491 of this section.
46492
46493 @table @code
46494 @item R @var{size}
46495 Specifies the size of a register block in bytes. This is equal to the
46496 size of a @code{g} packet payload in the remote protocol. @var{size}
46497 is an ascii decimal number. There should be only one such line in
46498 a single trace file.
46499
46500 @item status @var{status}
46501 Trace status. @var{status} has the same format as a @code{qTStatus}
46502 remote packet reply. There should be only one such line in a single trace
46503 file.
46504
46505 @item tp @var{payload}
46506 Tracepoint definition. The @var{payload} has the same format as
46507 @code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
46508 may take multiple lines of definition, corresponding to the multiple
46509 reply packets.
46510
46511 @item tsv @var{payload}
46512 Trace state variable definition. The @var{payload} has the same format as
46513 @code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
46514 may take multiple lines of definition, corresponding to the multiple
46515 reply packets.
46516
46517 @item tdesc @var{payload}
46518 Target description in XML format. The @var{payload} is a single line of
46519 the XML file. All such lines should be concatenated together to get
46520 the original XML file. This file is in the same format as @code{qXfer}
46521 @code{features} payload, and corresponds to the main @code{target.xml}
46522 file. Includes are not allowed.
46523
46524 @end table
46525
46526 The trace frame section consists of a number of consecutive frames.
46527 Each frame begins with a two-byte tracepoint number, followed by a
46528 four-byte size giving the amount of data in the frame. The data in
46529 the frame consists of a number of blocks, each introduced by a
46530 character indicating its type (at least register, memory, and trace
46531 state variable). The data in this section is raw binary, not a
46532 hexadecimal or other encoding; its endianness matches the target's
46533 endianness.
46534
46535 @c FIXME bi-arch may require endianness/arch info in description section
46536
46537 @table @code
46538 @item R @var{bytes}
46539 Register block. The number and ordering of bytes matches that of a
46540 @code{g} packet in the remote protocol. Note that these are the
46541 actual bytes, in target order, not a hexadecimal encoding.
46542
46543 @item M @var{address} @var{length} @var{bytes}...
46544 Memory block. This is a contiguous block of memory, at the 8-byte
46545 address @var{address}, with a 2-byte length @var{length}, followed by
46546 @var{length} bytes.
46547
46548 @item V @var{number} @var{value}
46549 Trace state variable block. This records the 8-byte signed value
46550 @var{value} of trace state variable numbered @var{number}.
46551
46552 @end table
46553
46554 Future enhancements of the trace file format may include additional types
46555 of blocks.
46556
46557 @node Index Section Format
46558 @appendix @code{.gdb_index} section format
46559 @cindex .gdb_index section format
46560 @cindex index section format
46561
46562 This section documents the index section that is created by @code{save
46563 gdb-index} (@pxref{Index Files}). The index section is
46564 DWARF-specific; some knowledge of DWARF is assumed in this
46565 description.
46566
46567 The mapped index file format is designed to be directly
46568 @code{mmap}able on any architecture. In most cases, a datum is
46569 represented using a little-endian 32-bit integer value, called an
46570 @code{offset_type}. Big endian machines must byte-swap the values
46571 before using them. Exceptions to this rule are noted. The data is
46572 laid out such that alignment is always respected.
46573
46574 A mapped index consists of several areas, laid out in order.
46575
46576 @enumerate
46577 @item
46578 The file header. This is a sequence of values, of @code{offset_type}
46579 unless otherwise noted:
46580
46581 @enumerate
46582 @item
46583 The version number, currently 8. Versions 1, 2 and 3 are obsolete.
46584 Version 4 uses a different hashing function from versions 5 and 6.
46585 Version 6 includes symbols for inlined functions, whereas versions 4
46586 and 5 do not. Version 7 adds attributes to the CU indices in the
46587 symbol table. Version 8 specifies that symbols from DWARF type units
46588 (@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
46589 compilation unit (@samp{DW_TAG_comp_unit}) using the type.
46590
46591 @value{GDBN} will only read version 4, 5, or 6 indices
46592 by specifying @code{set use-deprecated-index-sections on}.
46593 GDB has a workaround for potentially broken version 7 indices so it is
46594 currently not flagged as deprecated.
46595
46596 @item
46597 The offset, from the start of the file, of the CU list.
46598
46599 @item
46600 The offset, from the start of the file, of the types CU list. Note
46601 that this area can be empty, in which case this offset will be equal
46602 to the next offset.
46603
46604 @item
46605 The offset, from the start of the file, of the address area.
46606
46607 @item
46608 The offset, from the start of the file, of the symbol table.
46609
46610 @item
46611 The offset, from the start of the file, of the constant pool.
46612 @end enumerate
46613
46614 @item
46615 The CU list. This is a sequence of pairs of 64-bit little-endian
46616 values, sorted by the CU offset. The first element in each pair is
46617 the offset of a CU in the @code{.debug_info} section. The second
46618 element in each pair is the length of that CU. References to a CU
46619 elsewhere in the map are done using a CU index, which is just the
46620 0-based index into this table. Note that if there are type CUs, then
46621 conceptually CUs and type CUs form a single list for the purposes of
46622 CU indices.
46623
46624 @item
46625 The types CU list. This is a sequence of triplets of 64-bit
46626 little-endian values. In a triplet, the first value is the CU offset,
46627 the second value is the type offset in the CU, and the third value is
46628 the type signature. The types CU list is not sorted.
46629
46630 @item
46631 The address area. The address area consists of a sequence of address
46632 entries. Each address entry has three elements:
46633
46634 @enumerate
46635 @item
46636 The low address. This is a 64-bit little-endian value.
46637
46638 @item
46639 The high address. This is a 64-bit little-endian value. Like
46640 @code{DW_AT_high_pc}, the value is one byte beyond the end.
46641
46642 @item
46643 The CU index. This is an @code{offset_type} value.
46644 @end enumerate
46645
46646 @item
46647 The symbol table. This is an open-addressed hash table. The size of
46648 the hash table is always a power of 2.
46649
46650 Each slot in the hash table consists of a pair of @code{offset_type}
46651 values. The first value is the offset of the symbol's name in the
46652 constant pool. The second value is the offset of the CU vector in the
46653 constant pool.
46654
46655 If both values are 0, then this slot in the hash table is empty. This
46656 is ok because while 0 is a valid constant pool index, it cannot be a
46657 valid index for both a string and a CU vector.
46658
46659 The hash value for a table entry is computed by applying an
46660 iterative hash function to the symbol's name. Starting with an
46661 initial value of @code{r = 0}, each (unsigned) character @samp{c} in
46662 the string is incorporated into the hash using the formula depending on the
46663 index version:
46664
46665 @table @asis
46666 @item Version 4
46667 The formula is @code{r = r * 67 + c - 113}.
46668
46669 @item Versions 5 to 7
46670 The formula is @code{r = r * 67 + tolower (c) - 113}.
46671 @end table
46672
46673 The terminating @samp{\0} is not incorporated into the hash.
46674
46675 The step size used in the hash table is computed via
46676 @code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
46677 value, and @samp{size} is the size of the hash table. The step size
46678 is used to find the next candidate slot when handling a hash
46679 collision.
46680
46681 The names of C@t{++} symbols in the hash table are canonicalized. We
46682 don't currently have a simple description of the canonicalization
46683 algorithm; if you intend to create new index sections, you must read
46684 the code.
46685
46686 @item
46687 The constant pool. This is simply a bunch of bytes. It is organized
46688 so that alignment is correct: CU vectors are stored first, followed by
46689 strings.
46690
46691 A CU vector in the constant pool is a sequence of @code{offset_type}
46692 values. The first value is the number of CU indices in the vector.
46693 Each subsequent value is the index and symbol attributes of a CU in
46694 the CU list. This element in the hash table is used to indicate which
46695 CUs define the symbol and how the symbol is used.
46696 See below for the format of each CU index+attributes entry.
46697
46698 A string in the constant pool is zero-terminated.
46699 @end enumerate
46700
46701 Attributes were added to CU index values in @code{.gdb_index} version 7.
46702 If a symbol has multiple uses within a CU then there is one
46703 CU index+attributes value for each use.
46704
46705 The format of each CU index+attributes entry is as follows
46706 (bit 0 = LSB):
46707
46708 @table @asis
46709
46710 @item Bits 0-23
46711 This is the index of the CU in the CU list.
46712 @item Bits 24-27
46713 These bits are reserved for future purposes and must be zero.
46714 @item Bits 28-30
46715 The kind of the symbol in the CU.
46716
46717 @table @asis
46718 @item 0
46719 This value is reserved and should not be used.
46720 By reserving zero the full @code{offset_type} value is backwards compatible
46721 with previous versions of the index.
46722 @item 1
46723 The symbol is a type.
46724 @item 2
46725 The symbol is a variable or an enum value.
46726 @item 3
46727 The symbol is a function.
46728 @item 4
46729 Any other kind of symbol.
46730 @item 5,6,7
46731 These values are reserved.
46732 @end table
46733
46734 @item Bit 31
46735 This bit is zero if the value is global and one if it is static.
46736
46737 The determination of whether a symbol is global or static is complicated.
46738 The authorative reference is the file @file{dwarf2read.c} in
46739 @value{GDBN} sources.
46740
46741 @end table
46742
46743 This pseudo-code describes the computation of a symbol's kind and
46744 global/static attributes in the index.
46745
46746 @smallexample
46747 is_external = get_attribute (die, DW_AT_external);
46748 language = get_attribute (cu_die, DW_AT_language);
46749 switch (die->tag)
46750 @{
46751 case DW_TAG_typedef:
46752 case DW_TAG_base_type:
46753 case DW_TAG_subrange_type:
46754 kind = TYPE;
46755 is_static = 1;
46756 break;
46757 case DW_TAG_enumerator:
46758 kind = VARIABLE;
46759 is_static = language != CPLUS;
46760 break;
46761 case DW_TAG_subprogram:
46762 kind = FUNCTION;
46763 is_static = ! (is_external || language == ADA);
46764 break;
46765 case DW_TAG_constant:
46766 kind = VARIABLE;
46767 is_static = ! is_external;
46768 break;
46769 case DW_TAG_variable:
46770 kind = VARIABLE;
46771 is_static = ! is_external;
46772 break;
46773 case DW_TAG_namespace:
46774 kind = TYPE;
46775 is_static = 0;
46776 break;
46777 case DW_TAG_class_type:
46778 case DW_TAG_interface_type:
46779 case DW_TAG_structure_type:
46780 case DW_TAG_union_type:
46781 case DW_TAG_enumeration_type:
46782 kind = TYPE;
46783 is_static = language != CPLUS;
46784 break;
46785 default:
46786 assert (0);
46787 @}
46788 @end smallexample
46789
46790 @node Man Pages
46791 @appendix Manual pages
46792 @cindex Man pages
46793
46794 @menu
46795 * gdb man:: The GNU Debugger man page
46796 * gdbserver man:: Remote Server for the GNU Debugger man page
46797 * gcore man:: Generate a core file of a running program
46798 * gdbinit man:: gdbinit scripts
46799 * gdb-add-index man:: Add index files to speed up GDB
46800 @end menu
46801
46802 @node gdb man
46803 @heading gdb man
46804
46805 @c man title gdb The GNU Debugger
46806
46807 @c man begin SYNOPSIS gdb
46808 gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
46809 [@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
46810 [@option{-b}@w{ }@var{bps}]
46811 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
46812 [@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
46813 [@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
46814 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
46815 [@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
46816 @c man end
46817
46818 @c man begin DESCRIPTION gdb
46819 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
46820 going on ``inside'' another program while it executes -- or what another
46821 program was doing at the moment it crashed.
46822
46823 @value{GDBN} can do four main kinds of things (plus other things in support of
46824 these) to help you catch bugs in the act:
46825
46826 @itemize @bullet
46827 @item
46828 Start your program, specifying anything that might affect its behavior.
46829
46830 @item
46831 Make your program stop on specified conditions.
46832
46833 @item
46834 Examine what has happened, when your program has stopped.
46835
46836 @item
46837 Change things in your program, so you can experiment with correcting the
46838 effects of one bug and go on to learn about another.
46839 @end itemize
46840
46841 You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
46842 Modula-2.
46843
46844 @value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
46845 commands from the terminal until you tell it to exit with the @value{GDBN}
46846 command @code{quit}. You can get online help from @value{GDBN} itself
46847 by using the command @code{help}.
46848
46849 You can run @code{gdb} with no arguments or options; but the most
46850 usual way to start @value{GDBN} is with one argument or two, specifying an
46851 executable program as the argument:
46852
46853 @smallexample
46854 gdb program
46855 @end smallexample
46856
46857 You can also start with both an executable program and a core file specified:
46858
46859 @smallexample
46860 gdb program core
46861 @end smallexample
46862
46863 You can, instead, specify a process ID as a second argument or use option
46864 @code{-p}, if you want to debug a running process:
46865
46866 @smallexample
46867 gdb program 1234
46868 gdb -p 1234
46869 @end smallexample
46870
46871 @noindent
46872 would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
46873 can omit the @var{program} filename.
46874
46875 Here are some of the most frequently needed @value{GDBN} commands:
46876
46877 @c pod2man highlights the right hand side of the @item lines.
46878 @table @env
46879 @item break [@var{file}:]@var{function}
46880 Set a breakpoint at @var{function} (in @var{file}).
46881
46882 @item run [@var{arglist}]
46883 Start your program (with @var{arglist}, if specified).
46884
46885 @item bt
46886 Backtrace: display the program stack.
46887
46888 @item print @var{expr}
46889 Display the value of an expression.
46890
46891 @item c
46892 Continue running your program (after stopping, e.g. at a breakpoint).
46893
46894 @item next
46895 Execute next program line (after stopping); step @emph{over} any
46896 function calls in the line.
46897
46898 @item edit [@var{file}:]@var{function}
46899 look at the program line where it is presently stopped.
46900
46901 @item list [@var{file}:]@var{function}
46902 type the text of the program in the vicinity of where it is presently stopped.
46903
46904 @item step
46905 Execute next program line (after stopping); step @emph{into} any
46906 function calls in the line.
46907
46908 @item help [@var{name}]
46909 Show information about @value{GDBN} command @var{name}, or general information
46910 about using @value{GDBN}.
46911
46912 @item quit
46913 Exit from @value{GDBN}.
46914 @end table
46915
46916 @ifset man
46917 For full details on @value{GDBN},
46918 see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46919 by Richard M. Stallman and Roland H. Pesch. The same text is available online
46920 as the @code{gdb} entry in the @code{info} program.
46921 @end ifset
46922 @c man end
46923
46924 @c man begin OPTIONS gdb
46925 Any arguments other than options specify an executable
46926 file and core file (or process ID); that is, the first argument
46927 encountered with no
46928 associated option flag is equivalent to a @option{-se} option, and the second,
46929 if any, is equivalent to a @option{-c} option if it's the name of a file.
46930 Many options have
46931 both long and short forms; both are shown here. The long forms are also
46932 recognized if you truncate them, so long as enough of the option is
46933 present to be unambiguous. (If you prefer, you can flag option
46934 arguments with @option{+} rather than @option{-}, though we illustrate the
46935 more usual convention.)
46936
46937 All the options and command line arguments you give are processed
46938 in sequential order. The order makes a difference when the @option{-x}
46939 option is used.
46940
46941 @table @env
46942 @item -help
46943 @itemx -h
46944 List all options, with brief explanations.
46945
46946 @item -symbols=@var{file}
46947 @itemx -s @var{file}
46948 Read symbol table from file @var{file}.
46949
46950 @item -write
46951 Enable writing into executable and core files.
46952
46953 @item -exec=@var{file}
46954 @itemx -e @var{file}
46955 Use file @var{file} as the executable file to execute when
46956 appropriate, and for examining pure data in conjunction with a core
46957 dump.
46958
46959 @item -se=@var{file}
46960 Read symbol table from file @var{file} and use it as the executable
46961 file.
46962
46963 @item -core=@var{file}
46964 @itemx -c @var{file}
46965 Use file @var{file} as a core dump to examine.
46966
46967 @item -command=@var{file}
46968 @itemx -x @var{file}
46969 Execute @value{GDBN} commands from file @var{file}.
46970
46971 @item -ex @var{command}
46972 Execute given @value{GDBN} @var{command}.
46973
46974 @item -directory=@var{directory}
46975 @itemx -d @var{directory}
46976 Add @var{directory} to the path to search for source files.
46977
46978 @item -nh
46979 Do not execute commands from @file{~/.config/gdb/gdbinit},
46980 @file{~/.gdbinit}, @file{~/.config/gdb/gdbearlyinit}, or
46981 @file{~/.gdbearlyinit}
46982
46983 @item -nx
46984 @itemx -n
46985 Do not execute commands from any @file{.gdbinit} or
46986 @file{.gdbearlyinit} initialization files.
46987
46988 @item -quiet
46989 @itemx -q
46990 ``Quiet''. Do not print the introductory and copyright messages. These
46991 messages are also suppressed in batch mode.
46992
46993 @item -batch
46994 Run in batch mode. Exit with status @code{0} after processing all the command
46995 files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
46996 Exit with nonzero status if an error occurs in executing the @value{GDBN}
46997 commands in the command files.
46998
46999 Batch mode may be useful for running @value{GDBN} as a filter, for example to
47000 download and run a program on another computer; in order to make this
47001 more useful, the message
47002
47003 @smallexample
47004 Program exited normally.
47005 @end smallexample
47006
47007 @noindent
47008 (which is ordinarily issued whenever a program running under @value{GDBN} control
47009 terminates) is not issued when running in batch mode.
47010
47011 @item -cd=@var{directory}
47012 Run @value{GDBN} using @var{directory} as its working directory,
47013 instead of the current directory.
47014
47015 @item -fullname
47016 @itemx -f
47017 Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
47018 @value{GDBN} to output the full file name and line number in a standard,
47019 recognizable fashion each time a stack frame is displayed (which
47020 includes each time the program stops). This recognizable format looks
47021 like two @samp{\032} characters, followed by the file name, line number
47022 and character position separated by colons, and a newline. The
47023 Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
47024 characters as a signal to display the source code for the frame.
47025
47026 @item -b @var{bps}
47027 Set the line speed (baud rate or bits per second) of any serial
47028 interface used by @value{GDBN} for remote debugging.
47029
47030 @item -tty=@var{device}
47031 Run using @var{device} for your program's standard input and output.
47032 @end table
47033 @c man end
47034
47035 @c man begin SEEALSO gdb
47036 @ifset man
47037 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47038 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47039 documentation are properly installed at your site, the command
47040
47041 @smallexample
47042 info gdb
47043 @end smallexample
47044
47045 @noindent
47046 should give you access to the complete manual.
47047
47048 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47049 Richard M. Stallman and Roland H. Pesch, July 1991.
47050 @end ifset
47051 @c man end
47052
47053 @node gdbserver man
47054 @heading gdbserver man
47055
47056 @c man title gdbserver Remote Server for the GNU Debugger
47057 @format
47058 @c man begin SYNOPSIS gdbserver
47059 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
47060
47061 gdbserver --attach @var{comm} @var{pid}
47062
47063 gdbserver --multi @var{comm}
47064 @c man end
47065 @end format
47066
47067 @c man begin DESCRIPTION gdbserver
47068 @command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
47069 than the one which is running the program being debugged.
47070
47071 @ifclear man
47072 @subheading Usage (server (target) side)
47073 @end ifclear
47074 @ifset man
47075 Usage (server (target) side):
47076 @end ifset
47077
47078 First, you need to have a copy of the program you want to debug put onto
47079 the target system. The program can be stripped to save space if needed, as
47080 @command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
47081 the @value{GDBN} running on the host system.
47082
47083 To use the server, you log on to the target system, and run the @command{gdbserver}
47084 program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
47085 your program, and (c) its arguments. The general syntax is:
47086
47087 @smallexample
47088 target> gdbserver @var{comm} @var{program} [@var{args} ...]
47089 @end smallexample
47090
47091 For example, using a serial port, you might say:
47092
47093 @smallexample
47094 @ifset man
47095 @c @file would wrap it as F</dev/com1>.
47096 target> gdbserver /dev/com1 emacs foo.txt
47097 @end ifset
47098 @ifclear man
47099 target> gdbserver @file{/dev/com1} emacs foo.txt
47100 @end ifclear
47101 @end smallexample
47102
47103 This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
47104 to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
47105 waits patiently for the host @value{GDBN} to communicate with it.
47106
47107 To use a TCP connection, you could say:
47108
47109 @smallexample
47110 target> gdbserver host:2345 emacs foo.txt
47111 @end smallexample
47112
47113 This says pretty much the same thing as the last example, except that we are
47114 going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
47115 that we are expecting to see a TCP connection from @code{host} to local TCP port
47116 2345. (Currently, the @code{host} part is ignored.) You can choose any number you
47117 want for the port number as long as it does not conflict with any existing TCP
47118 ports on the target system. This same port number must be used in the host
47119 @value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
47120 you chose a port number that conflicts with another service, @command{gdbserver} will
47121 print an error message and exit.
47122
47123 @command{gdbserver} can also attach to running programs.
47124 This is accomplished via the @option{--attach} argument. The syntax is:
47125
47126 @smallexample
47127 target> gdbserver --attach @var{comm} @var{pid}
47128 @end smallexample
47129
47130 @var{pid} is the process ID of a currently running process. It isn't
47131 necessary to point @command{gdbserver} at a binary for the running process.
47132
47133 To start @code{gdbserver} without supplying an initial command to run
47134 or process ID to attach, use the @option{--multi} command line option.
47135 In such case you should connect using @kbd{target extended-remote} to start
47136 the program you want to debug.
47137
47138 @smallexample
47139 target> gdbserver --multi @var{comm}
47140 @end smallexample
47141
47142 @ifclear man
47143 @subheading Usage (host side)
47144 @end ifclear
47145 @ifset man
47146 Usage (host side):
47147 @end ifset
47148
47149 You need an unstripped copy of the target program on your host system, since
47150 @value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
47151 would, with the target program as the first argument. (You may need to use the
47152 @option{--baud} option if the serial line is running at anything except 9600 baud.)
47153 That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
47154 new command you need to know about is @code{target remote}
47155 (or @code{target extended-remote}). Its argument is either
47156 a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
47157 descriptor. For example:
47158
47159 @smallexample
47160 @ifset man
47161 @c @file would wrap it as F</dev/ttyb>.
47162 (gdb) target remote /dev/ttyb
47163 @end ifset
47164 @ifclear man
47165 (gdb) target remote @file{/dev/ttyb}
47166 @end ifclear
47167 @end smallexample
47168
47169 @noindent
47170 communicates with the server via serial line @file{/dev/ttyb}, and:
47171
47172 @smallexample
47173 (gdb) target remote the-target:2345
47174 @end smallexample
47175
47176 @noindent
47177 communicates via a TCP connection to port 2345 on host `the-target', where
47178 you previously started up @command{gdbserver} with the same port number. Note that for
47179 TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
47180 command, otherwise you may get an error that looks something like
47181 `Connection refused'.
47182
47183 @command{gdbserver} can also debug multiple inferiors at once,
47184 described in
47185 @ifset man
47186 the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
47187 -- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
47188 @end ifset
47189 @ifclear man
47190 @ref{Inferiors Connections and Programs}.
47191 @end ifclear
47192 In such case use the @code{extended-remote} @value{GDBN} command variant:
47193
47194 @smallexample
47195 (gdb) target extended-remote the-target:2345
47196 @end smallexample
47197
47198 The @command{gdbserver} option @option{--multi} may or may not be used in such
47199 case.
47200 @c man end
47201
47202 @c man begin OPTIONS gdbserver
47203 There are three different modes for invoking @command{gdbserver}:
47204
47205 @itemize @bullet
47206
47207 @item
47208 Debug a specific program specified by its program name:
47209
47210 @smallexample
47211 gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
47212 @end smallexample
47213
47214 The @var{comm} parameter specifies how should the server communicate
47215 with @value{GDBN}; it is either a device name (to use a serial line),
47216 a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
47217 stdin/stdout of @code{gdbserver}. Specify the name of the program to
47218 debug in @var{prog}. Any remaining arguments will be passed to the
47219 program verbatim. When the program exits, @value{GDBN} will close the
47220 connection, and @code{gdbserver} will exit.
47221
47222 @item
47223 Debug a specific program by specifying the process ID of a running
47224 program:
47225
47226 @smallexample
47227 gdbserver --attach @var{comm} @var{pid}
47228 @end smallexample
47229
47230 The @var{comm} parameter is as described above. Supply the process ID
47231 of a running program in @var{pid}; @value{GDBN} will do everything
47232 else. Like with the previous mode, when the process @var{pid} exits,
47233 @value{GDBN} will close the connection, and @code{gdbserver} will exit.
47234
47235 @item
47236 Multi-process mode -- debug more than one program/process:
47237
47238 @smallexample
47239 gdbserver --multi @var{comm}
47240 @end smallexample
47241
47242 In this mode, @value{GDBN} can instruct @command{gdbserver} which
47243 command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
47244 close the connection when a process being debugged exits, so you can
47245 debug several processes in the same session.
47246 @end itemize
47247
47248 In each of the modes you may specify these options:
47249
47250 @table @env
47251
47252 @item --help
47253 List all options, with brief explanations.
47254
47255 @item --version
47256 This option causes @command{gdbserver} to print its version number and exit.
47257
47258 @item --attach
47259 @command{gdbserver} will attach to a running program. The syntax is:
47260
47261 @smallexample
47262 target> gdbserver --attach @var{comm} @var{pid}
47263 @end smallexample
47264
47265 @var{pid} is the process ID of a currently running process. It isn't
47266 necessary to point @command{gdbserver} at a binary for the running process.
47267
47268 @item --multi
47269 To start @code{gdbserver} without supplying an initial command to run
47270 or process ID to attach, use this command line option.
47271 Then you can connect using @kbd{target extended-remote} and start
47272 the program you want to debug. The syntax is:
47273
47274 @smallexample
47275 target> gdbserver --multi @var{comm}
47276 @end smallexample
47277
47278 @item --debug
47279 Instruct @code{gdbserver} to display extra status information about the debugging
47280 process.
47281 This option is intended for @code{gdbserver} development and for bug reports to
47282 the developers.
47283
47284 @item --remote-debug
47285 Instruct @code{gdbserver} to display remote protocol debug output.
47286 This option is intended for @code{gdbserver} development and for bug reports to
47287 the developers.
47288
47289 @item --debug-file=@var{filename}
47290 Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
47291 This option is intended for @code{gdbserver} development and for bug reports to
47292 the developers.
47293
47294 @item --debug-format=option1@r{[},option2,...@r{]}
47295 Instruct @code{gdbserver} to include extra information in each line
47296 of debugging output.
47297 @xref{Other Command-Line Arguments for gdbserver}.
47298
47299 @item --wrapper
47300 Specify a wrapper to launch programs
47301 for debugging. The option should be followed by the name of the
47302 wrapper, then any command-line arguments to pass to the wrapper, then
47303 @kbd{--} indicating the end of the wrapper arguments.
47304
47305 @item --once
47306 By default, @command{gdbserver} keeps the listening TCP port open, so that
47307 additional connections are possible. However, if you start @code{gdbserver}
47308 with the @option{--once} option, it will stop listening for any further
47309 connection attempts after connecting to the first @value{GDBN} session.
47310
47311 @c --disable-packet is not documented for users.
47312
47313 @c --disable-randomization and --no-disable-randomization are superseded by
47314 @c QDisableRandomization.
47315
47316 @end table
47317 @c man end
47318
47319 @c man begin SEEALSO gdbserver
47320 @ifset man
47321 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47322 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47323 documentation are properly installed at your site, the command
47324
47325 @smallexample
47326 info gdb
47327 @end smallexample
47328
47329 should give you access to the complete manual.
47330
47331 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47332 Richard M. Stallman and Roland H. Pesch, July 1991.
47333 @end ifset
47334 @c man end
47335
47336 @node gcore man
47337 @heading gcore
47338
47339 @c man title gcore Generate a core file of a running program
47340
47341 @format
47342 @c man begin SYNOPSIS gcore
47343 gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
47344 @c man end
47345 @end format
47346
47347 @c man begin DESCRIPTION gcore
47348 Generate core dumps of one or more running programs with process IDs
47349 @var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
47350 is equivalent to one produced by the kernel when the process crashes
47351 (and when @kbd{ulimit -c} was used to set up an appropriate core dump
47352 limit). However, unlike after a crash, after @command{gcore} finishes
47353 its job the program remains running without any change.
47354 @c man end
47355
47356 @c man begin OPTIONS gcore
47357 @table @env
47358 @item -a
47359 Dump all memory mappings. The actual effect of this option depends on
47360 the Operating System. On @sc{gnu}/Linux, it will disable
47361 @code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
47362 enable @code{dump-excluded-mappings} (@pxref{set
47363 dump-excluded-mappings}).
47364
47365 @item -o @var{prefix}
47366 The optional argument @var{prefix} specifies the prefix to be used
47367 when composing the file names of the core dumps. The file name is
47368 composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
47369 process ID of the running program being analyzed by @command{gcore}.
47370 If not specified, @var{prefix} defaults to @var{gcore}.
47371 @end table
47372 @c man end
47373
47374 @c man begin SEEALSO gcore
47375 @ifset man
47376 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47377 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47378 documentation are properly installed at your site, the command
47379
47380 @smallexample
47381 info gdb
47382 @end smallexample
47383
47384 @noindent
47385 should give you access to the complete manual.
47386
47387 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47388 Richard M. Stallman and Roland H. Pesch, July 1991.
47389 @end ifset
47390 @c man end
47391
47392 @node gdbinit man
47393 @heading gdbinit
47394
47395 @c man title gdbinit GDB initialization scripts
47396
47397 @format
47398 @c man begin SYNOPSIS gdbinit
47399 @ifset SYSTEM_GDBINIT
47400 @value{SYSTEM_GDBINIT}
47401 @end ifset
47402
47403 @ifset SYSTEM_GDBINIT_DIR
47404 @value{SYSTEM_GDBINIT_DIR}/*
47405 @end ifset
47406
47407 ~/.config/gdb/gdbinit
47408
47409 ~/.gdbinit
47410
47411 ./.gdbinit
47412 @c man end
47413 @end format
47414
47415 @c man begin DESCRIPTION gdbinit
47416 These files contain @value{GDBN} commands to automatically execute during
47417 @value{GDBN} startup. The lines of contents are canned sequences of commands,
47418 described in
47419 @ifset man
47420 the @value{GDBN} manual in node @code{Sequences}
47421 -- shell command @code{info -f gdb -n Sequences}.
47422 @end ifset
47423 @ifclear man
47424 @ref{Sequences}.
47425 @end ifclear
47426
47427 Please read more in
47428 @ifset man
47429 the @value{GDBN} manual in node @code{Startup}
47430 -- shell command @code{info -f gdb -n Startup}.
47431 @end ifset
47432 @ifclear man
47433 @ref{Startup}.
47434 @end ifclear
47435
47436 @table @env
47437 @ifset SYSTEM_GDBINIT
47438 @item @value{SYSTEM_GDBINIT}
47439 @end ifset
47440 @ifclear SYSTEM_GDBINIT
47441 @item (not enabled with @code{--with-system-gdbinit} during compilation)
47442 @end ifclear
47443 System-wide initialization file. It is executed unless user specified
47444 @value{GDBN} option @code{-nx} or @code{-n}.
47445 See more in
47446 @ifset man
47447 the @value{GDBN} manual in node @code{System-wide configuration}
47448 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
47449 @end ifset
47450 @ifset SYSTEM_GDBINIT_DIR
47451 @item @value{SYSTEM_GDBINIT_DIR}
47452 @end ifset
47453 @ifclear SYSTEM_GDBINIT_DIR
47454 @item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
47455 @end ifclear
47456 System-wide initialization directory. All files in this directory are
47457 executed on startup unless user specified @value{GDBN} option @code{-nx} or
47458 @code{-n}, as long as they have a recognized file extension.
47459 See more in
47460 @ifset man
47461 the @value{GDBN} manual in node @code{System-wide configuration}
47462 -- shell command @code{info -f gdb -n 'System-wide configuration'}.
47463 @end ifset
47464 @ifclear man
47465 @ref{System-wide configuration}.
47466 @end ifclear
47467
47468 @item @file{~/.config/gdb/gdbinit} or @file{~/.gdbinit}
47469 User initialization file. It is executed unless user specified
47470 @value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
47471
47472 @item @file{.gdbinit}
47473 Initialization file for current directory. It may need to be enabled with
47474 @value{GDBN} security command @code{set auto-load local-gdbinit}.
47475 See more in
47476 @ifset man
47477 the @value{GDBN} manual in node @code{Init File in the Current Directory}
47478 -- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
47479 @end ifset
47480 @ifclear man
47481 @ref{Init File in the Current Directory}.
47482 @end ifclear
47483 @end table
47484 @c man end
47485
47486 @c man begin SEEALSO gdbinit
47487 @ifset man
47488 gdb(1), @code{info -f gdb -n Startup}
47489
47490 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47491 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47492 documentation are properly installed at your site, the command
47493
47494 @smallexample
47495 info gdb
47496 @end smallexample
47497
47498 should give you access to the complete manual.
47499
47500 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47501 Richard M. Stallman and Roland H. Pesch, July 1991.
47502 @end ifset
47503 @c man end
47504
47505 @node gdb-add-index man
47506 @heading gdb-add-index
47507 @pindex gdb-add-index
47508 @anchor{gdb-add-index}
47509
47510 @c man title gdb-add-index Add index files to speed up GDB
47511
47512 @c man begin SYNOPSIS gdb-add-index
47513 gdb-add-index @var{filename}
47514 @c man end
47515
47516 @c man begin DESCRIPTION gdb-add-index
47517 When @value{GDBN} finds a symbol file, it scans the symbols in the
47518 file in order to construct an internal symbol table. This lets most
47519 @value{GDBN} operations work quickly--at the cost of a delay early on.
47520 For large programs, this delay can be quite lengthy, so @value{GDBN}
47521 provides a way to build an index, which speeds up startup.
47522
47523 To determine whether a file contains such an index, use the command
47524 @kbd{readelf -S filename}: the index is stored in a section named
47525 @code{.gdb_index}. The index file can only be produced on systems
47526 which use ELF binaries and DWARF debug information (i.e., sections
47527 named @code{.debug_*}).
47528
47529 @command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
47530 in the @env{PATH} environment variable. If you want to use different
47531 versions of these programs, you can specify them through the
47532 @env{GDB} and @env{OBJDUMP} environment variables.
47533
47534 See more in
47535 @ifset man
47536 the @value{GDBN} manual in node @code{Index Files}
47537 -- shell command @kbd{info -f gdb -n "Index Files"}.
47538 @end ifset
47539 @ifclear man
47540 @ref{Index Files}.
47541 @end ifclear
47542 @c man end
47543
47544 @c man begin SEEALSO gdb-add-index
47545 @ifset man
47546 The full documentation for @value{GDBN} is maintained as a Texinfo manual.
47547 If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
47548 documentation are properly installed at your site, the command
47549
47550 @smallexample
47551 info gdb
47552 @end smallexample
47553
47554 should give you access to the complete manual.
47555
47556 @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
47557 Richard M. Stallman and Roland H. Pesch, July 1991.
47558 @end ifset
47559 @c man end
47560
47561 @include gpl.texi
47562
47563 @node GNU Free Documentation License
47564 @appendix GNU Free Documentation License
47565 @include fdl.texi
47566
47567 @node Concept Index
47568 @unnumbered Concept Index
47569
47570 @printindex cp
47571
47572 @node Command and Variable Index
47573 @unnumbered Command, Variable, and Function Index
47574
47575 @printindex fn
47576
47577 @tex
47578 % I think something like @@colophon should be in texinfo. In the
47579 % meantime:
47580 \long\def\colophon{\hbox to0pt{}\vfill
47581 \centerline{The body of this manual is set in}
47582 \centerline{\fontname\tenrm,}
47583 \centerline{with headings in {\bf\fontname\tenbf}}
47584 \centerline{and examples in {\tt\fontname\tentt}.}
47585 \centerline{{\it\fontname\tenit\/},}
47586 \centerline{{\bf\fontname\tenbf}, and}
47587 \centerline{{\sl\fontname\tensl\/}}
47588 \centerline{are used for emphasis.}\vfill}
47589 \page\colophon
47590 % Blame: doc@@cygnus.com, 1991.
47591 @end tex
47592
47593 @bye