2010-06-18 Hui Zhu <teawater@gmail.com>
[binutils-gdb.git] / gdb / doc / gdb.texinfo
1 \input texinfo @c -*-texinfo-*-
2 @c Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,
3 @c 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 @c Free Software Foundation, Inc.
5 @c
6 @c %**start of header
7 @c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
8 @c of @set vars. However, you can override filename with makeinfo -o.
9 @setfilename gdb.info
10 @c
11 @include gdb-cfg.texi
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 @syncodeindex ky cp
24 @syncodeindex tp cp
25
26 @c readline appendices use @vindex, @findex and @ftable,
27 @c annotate.texi and gdbmi use @findex.
28 @syncodeindex vr cp
29 @syncodeindex fn cp
30
31 @c !!set GDB manual's edition---not the same as GDB version!
32 @c This is updated by GNU Press.
33 @set EDITION Ninth
34
35 @c !!set GDB edit command default editor
36 @set EDITOR /bin/ex
37
38 @c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
39
40 @c This is a dir.info fragment to support semi-automated addition of
41 @c manuals to an info tree.
42 @dircategory Software development
43 @direntry
44 * Gdb: (gdb). The GNU debugger.
45 @end direntry
46
47 @copying
48 Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
49 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
50 Free Software Foundation, Inc.
51
52 Permission is granted to copy, distribute and/or modify this document
53 under the terms of the GNU Free Documentation License, Version 1.1 or
54 any later version published by the Free Software Foundation; with the
55 Invariant Sections being ``Free Software'' and ``Free Software Needs
56 Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
57 and with the Back-Cover Texts as in (a) below.
58
59 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
60 this GNU Manual. Buying copies from GNU Press supports the FSF in
61 developing GNU and promoting software freedom.''
62 @end copying
63
64 @ifnottex
65 This file documents the @sc{gnu} debugger @value{GDBN}.
66
67 This is the @value{EDITION} Edition, of @cite{Debugging with
68 @value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
69 @ifset VERSION_PACKAGE
70 @value{VERSION_PACKAGE}
71 @end ifset
72 Version @value{GDBVN}.
73
74 @insertcopying
75 @end ifnottex
76
77 @titlepage
78 @title Debugging with @value{GDBN}
79 @subtitle The @sc{gnu} Source-Level Debugger
80 @sp 1
81 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
82 @ifset VERSION_PACKAGE
83 @sp 1
84 @subtitle @value{VERSION_PACKAGE}
85 @end ifset
86 @author Richard Stallman, Roland Pesch, Stan Shebs, et al.
87 @page
88 @tex
89 {\parskip=0pt
90 \hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
91 \hfill {\it Debugging with @value{GDBN}}\par
92 \hfill \TeX{}info \texinfoversion\par
93 }
94 @end tex
95
96 @vskip 0pt plus 1filll
97 Published by the Free Software Foundation @*
98 51 Franklin Street, Fifth Floor,
99 Boston, MA 02110-1301, USA@*
100 ISBN 1-882114-77-9 @*
101
102 @insertcopying
103 @page
104 This edition of the GDB manual is dedicated to the memory of Fred
105 Fish. Fred was a long-standing contributor to GDB and to Free
106 software in general. We will miss him.
107 @end titlepage
108 @page
109
110 @ifnottex
111 @node Top, Summary, (dir), (dir)
112
113 @top Debugging with @value{GDBN}
114
115 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
117 This is the @value{EDITION} Edition, for @value{GDBN}
118 @ifset VERSION_PACKAGE
119 @value{VERSION_PACKAGE}
120 @end ifset
121 Version @value{GDBVN}.
122
123 Copyright (C) 1988-2010 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
164 * GDB Bugs:: Reporting bugs in @value{GDBN}
165
166 * Command Line Editing:: Command Line Editing
167 * Using History Interactively:: Using History Interactively
168 * Formatting Documentation:: How to format and print @value{GDBN} documentation
169 * Installing GDB:: Installing GDB
170 * Maintenance Commands:: Maintenance Commands
171 * Remote Protocol:: GDB Remote Serial Protocol
172 * Agent Expressions:: The GDB Agent Expression Mechanism
173 * Target Descriptions:: How targets can describe themselves to
174 @value{GDBN}
175 * Operating System Information:: Getting additional information from
176 the operating system
177 * Trace File Format:: GDB trace file format
178 * Copying:: GNU General Public License says
179 how you can copy and share GDB
180 * GNU Free Documentation License:: The license for this documentation
181 * Index:: Index
182 @end menu
183
184 @end ifnottex
185
186 @contents
187
188 @node Summary
189 @unnumbered Summary of @value{GDBN}
190
191 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
192 going on ``inside'' another program while it executes---or what another
193 program was doing at the moment it crashed.
194
195 @value{GDBN} can do four main kinds of things (plus other things in support of
196 these) to help you catch bugs in the act:
197
198 @itemize @bullet
199 @item
200 Start your program, specifying anything that might affect its behavior.
201
202 @item
203 Make your program stop on specified conditions.
204
205 @item
206 Examine what has happened, when your program has stopped.
207
208 @item
209 Change things in your program, so you can experiment with correcting the
210 effects of one bug and go on to learn about another.
211 @end itemize
212
213 You can use @value{GDBN} to debug programs written in C and C@t{++}.
214 For more information, see @ref{Supported Languages,,Supported Languages}.
215 For more information, see @ref{C,,C and C++}.
216
217 Support for D is partial. For information on D, see
218 @ref{D,,D}.
219
220 @cindex Modula-2
221 Support for Modula-2 is partial. For information on Modula-2, see
222 @ref{Modula-2,,Modula-2}.
223
224 @cindex Pascal
225 Debugging Pascal programs which use sets, subranges, file variables, or
226 nested functions does not currently work. @value{GDBN} does not support
227 entering expressions, printing values, or similar features using Pascal
228 syntax.
229
230 @cindex Fortran
231 @value{GDBN} can be used to debug programs written in Fortran, although
232 it may be necessary to refer to some variables with a trailing
233 underscore.
234
235 @value{GDBN} can be used to debug programs written in Objective-C,
236 using either the Apple/NeXT or the GNU Objective-C runtime.
237
238 @menu
239 * Free Software:: Freely redistributable software
240 * Contributors:: Contributors to GDB
241 @end menu
242
243 @node Free Software
244 @unnumberedsec Free Software
245
246 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
247 General Public License
248 (GPL). The GPL gives you the freedom to copy or adapt a licensed
249 program---but every person getting a copy also gets with it the
250 freedom to modify that copy (which means that they must get access to
251 the source code), and the freedom to distribute further copies.
252 Typical software companies use copyrights to limit your freedoms; the
253 Free Software Foundation uses the GPL to preserve these freedoms.
254
255 Fundamentally, the General Public License is a license which says that
256 you have these freedoms and that you cannot take these freedoms away
257 from anyone else.
258
259 @unnumberedsec Free Software Needs Free Documentation
260
261 The biggest deficiency in the free software community today is not in
262 the software---it is the lack of good free documentation that we can
263 include with the free software. Many of our most important
264 programs do not come with free reference manuals and free introductory
265 texts. Documentation is an essential part of any software package;
266 when an important free software package does not come with a free
267 manual and a free tutorial, that is a major gap. We have many such
268 gaps today.
269
270 Consider Perl, for instance. The tutorial manuals that people
271 normally use are non-free. How did this come about? Because the
272 authors of those manuals published them with restrictive terms---no
273 copying, no modification, source files not available---which exclude
274 them from the free software world.
275
276 That wasn't the first time this sort of thing happened, and it was far
277 from the last. Many times we have heard a GNU user eagerly describe a
278 manual that he is writing, his intended contribution to the community,
279 only to learn that he had ruined everything by signing a publication
280 contract to make it non-free.
281
282 Free documentation, like free software, is a matter of freedom, not
283 price. The problem with the non-free manual is not that publishers
284 charge a price for printed copies---that in itself is fine. (The Free
285 Software Foundation sells printed copies of manuals, too.) The
286 problem is the restrictions on the use of the manual. Free manuals
287 are available in source code form, and give you permission to copy and
288 modify. Non-free manuals do not allow this.
289
290 The criteria of freedom for a free manual are roughly the same as for
291 free software. Redistribution (including the normal kinds of
292 commercial redistribution) must be permitted, so that the manual can
293 accompany every copy of the program, both on-line and on paper.
294
295 Permission for modification of the technical content is crucial too.
296 When people modify the software, adding or changing features, if they
297 are conscientious they will change the manual too---so they can
298 provide accurate and clear documentation for the modified program. A
299 manual that leaves you no choice but to write a new manual to document
300 a changed version of the program is not really available to our
301 community.
302
303 Some kinds of limits on the way modification is handled are
304 acceptable. For example, requirements to preserve the original
305 author's copyright notice, the distribution terms, or the list of
306 authors, are ok. It is also no problem to require modified versions
307 to include notice that they were modified. Even entire sections that
308 may not be deleted or changed are acceptable, as long as they deal
309 with nontechnical topics (like this one). These kinds of restrictions
310 are acceptable because they don't obstruct the community's normal use
311 of the manual.
312
313 However, it must be possible to modify all the @emph{technical}
314 content of the manual, and then distribute the result in all the usual
315 media, through all the usual channels. Otherwise, the restrictions
316 obstruct the use of the manual, it is not free, and we need another
317 manual to replace it.
318
319 Please spread the word about this issue. Our community continues to
320 lose manuals to proprietary publishing. If we spread the word that
321 free software needs free reference manuals and free tutorials, perhaps
322 the next person who wants to contribute by writing documentation will
323 realize, before it is too late, that only free manuals contribute to
324 the free software community.
325
326 If you are writing documentation, please insist on publishing it under
327 the GNU Free Documentation License or another free documentation
328 license. Remember that this decision requires your approval---you
329 don't have to let the publisher decide. Some commercial publishers
330 will use a free license if you insist, but they will not propose the
331 option; it is up to you to raise the issue and say firmly that this is
332 what you want. If the publisher you are dealing with refuses, please
333 try other publishers. If you're not sure whether a proposed license
334 is free, write to @email{licensing@@gnu.org}.
335
336 You can encourage commercial publishers to sell more free, copylefted
337 manuals and tutorials by buying them, and particularly by buying
338 copies from the publishers that paid for their writing or for major
339 improvements. Meanwhile, try to avoid buying non-free documentation
340 at all. Check the distribution terms of a manual before you buy it,
341 and insist that whoever seeks your business must respect your freedom.
342 Check the history of the book, and try to reward the publishers that
343 have paid or pay the authors to work on it.
344
345 The Free Software Foundation maintains a list of free documentation
346 published by other publishers, at
347 @url{http://www.fsf.org/doc/other-free-books.html}.
348
349 @node Contributors
350 @unnumberedsec Contributors to @value{GDBN}
351
352 Richard Stallman was the original author of @value{GDBN}, and of many
353 other @sc{gnu} programs. Many others have contributed to its
354 development. This section attempts to credit major contributors. One
355 of the virtues of free software is that everyone is free to contribute
356 to it; with regret, we cannot actually acknowledge everyone here. The
357 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
358 blow-by-blow account.
359
360 Changes much prior to version 2.0 are lost in the mists of time.
361
362 @quotation
363 @emph{Plea:} Additions to this section are particularly welcome. If you
364 or your friends (or enemies, to be evenhanded) have been unfairly
365 omitted from this list, we would like to add your names!
366 @end quotation
367
368 So that they may not regard their many labors as thankless, we
369 particularly thank those who shepherded @value{GDBN} through major
370 releases:
371 Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
372 Jim Blandy (release 4.18);
373 Jason Molenda (release 4.17);
374 Stan Shebs (release 4.14);
375 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
376 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
377 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
378 Jim Kingdon (releases 3.5, 3.4, and 3.3);
379 and Randy Smith (releases 3.2, 3.1, and 3.0).
380
381 Richard Stallman, assisted at various times by Peter TerMaat, Chris
382 Hanson, and Richard Mlynarik, handled releases through 2.8.
383
384 Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
385 in @value{GDBN}, with significant additional contributions from Per
386 Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
387 demangler. Early work on C@t{++} was by Peter TerMaat (who also did
388 much general update work leading to release 3.0).
389
390 @value{GDBN} uses the BFD subroutine library to examine multiple
391 object-file formats; BFD was a joint project of David V.
392 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
393
394 David Johnson wrote the original COFF support; Pace Willison did
395 the original support for encapsulated COFF.
396
397 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
398
399 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
400 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
401 support.
402 Jean-Daniel Fekete contributed Sun 386i support.
403 Chris Hanson improved the HP9000 support.
404 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
405 David Johnson contributed Encore Umax support.
406 Jyrki Kuoppala contributed Altos 3068 support.
407 Jeff Law contributed HP PA and SOM support.
408 Keith Packard contributed NS32K support.
409 Doug Rabson contributed Acorn Risc Machine support.
410 Bob Rusk contributed Harris Nighthawk CX-UX support.
411 Chris Smith contributed Convex support (and Fortran debugging).
412 Jonathan Stone contributed Pyramid support.
413 Michael Tiemann contributed SPARC support.
414 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
415 Pace Willison contributed Intel 386 support.
416 Jay Vosburgh contributed Symmetry support.
417 Marko Mlinar contributed OpenRISC 1000 support.
418
419 Andreas Schwab contributed M68K @sc{gnu}/Linux support.
420
421 Rich Schaefer and Peter Schauer helped with support of SunOS shared
422 libraries.
423
424 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
425 about several machine instruction sets.
426
427 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
428 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
429 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
430 and RDI targets, respectively.
431
432 Brian Fox is the author of the readline libraries providing
433 command-line editing and command history.
434
435 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
436 Modula-2 support, and contributed the Languages chapter of this manual.
437
438 Fred Fish wrote most of the support for Unix System Vr4.
439 He also enhanced the command-completion support to cover C@t{++} overloaded
440 symbols.
441
442 Hitachi America (now Renesas America), Ltd. sponsored the support for
443 H8/300, H8/500, and Super-H processors.
444
445 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
446
447 Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
448 processors.
449
450 Toshiba sponsored the support for the TX39 Mips processor.
451
452 Matsushita sponsored the support for the MN10200 and MN10300 processors.
453
454 Fujitsu sponsored the support for SPARClite and FR30 processors.
455
456 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
457 watchpoints.
458
459 Michael Snyder added support for tracepoints.
460
461 Stu Grossman wrote gdbserver.
462
463 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
464 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
465
466 The following people at the Hewlett-Packard Company contributed
467 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
468 (narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
469 compiler, and the Text User Interface (nee Terminal User Interface):
470 Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
471 Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
472 provided HP-specific information in this manual.
473
474 DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
475 Robert Hoehne made significant contributions to the DJGPP port.
476
477 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
478 development since 1991. Cygnus engineers who have worked on @value{GDBN}
479 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
480 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
481 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
482 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
483 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
484 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
485 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
486 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
487 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
488 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
489 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
490 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
491 Zuhn have made contributions both large and small.
492
493 Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
494 Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
495
496 Jim Blandy added support for preprocessor macros, while working for Red
497 Hat.
498
499 Andrew Cagney designed @value{GDBN}'s architecture vector. Many
500 people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
501 Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
502 Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
503 Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
504 with the migration of old architectures to this new framework.
505
506 Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
507 unwinder framework, this consisting of a fresh new design featuring
508 frame IDs, independent frame sniffers, and the sentinel frame. Mark
509 Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
510 libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
511 trad unwinders. The architecture-specific changes, each involving a
512 complete rewrite of the architecture's frame code, were carried out by
513 Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
514 Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
515 Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
516 Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
517 Weigand.
518
519 Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
520 Tensilica, Inc.@: contributed support for Xtensa processors. Others
521 who have worked on the Xtensa port of @value{GDBN} in the past include
522 Steve Tjiang, John Newlin, and Scott Foehner.
523
524 Michael Eager and staff of Xilinx, Inc., contributed support for the
525 Xilinx MicroBlaze architecture.
526
527 @node Sample Session
528 @chapter A Sample @value{GDBN} Session
529
530 You can use this manual at your leisure to read all about @value{GDBN}.
531 However, a handful of commands are enough to get started using the
532 debugger. This chapter illustrates those commands.
533
534 @iftex
535 In this sample session, we emphasize user input like this: @b{input},
536 to make it easier to pick out from the surrounding output.
537 @end iftex
538
539 @c FIXME: this example may not be appropriate for some configs, where
540 @c FIXME...primary interest is in remote use.
541
542 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
543 processor) exhibits the following bug: sometimes, when we change its
544 quote strings from the default, the commands used to capture one macro
545 definition within another stop working. In the following short @code{m4}
546 session, we define a macro @code{foo} which expands to @code{0000}; we
547 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
548 same thing. However, when we change the open quote string to
549 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
550 procedure fails to define a new synonym @code{baz}:
551
552 @smallexample
553 $ @b{cd gnu/m4}
554 $ @b{./m4}
555 @b{define(foo,0000)}
556
557 @b{foo}
558 0000
559 @b{define(bar,defn(`foo'))}
560
561 @b{bar}
562 0000
563 @b{changequote(<QUOTE>,<UNQUOTE>)}
564
565 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
566 @b{baz}
567 @b{Ctrl-d}
568 m4: End of input: 0: fatal error: EOF in string
569 @end smallexample
570
571 @noindent
572 Let us use @value{GDBN} to try to see what is going on.
573
574 @smallexample
575 $ @b{@value{GDBP} m4}
576 @c FIXME: this falsifies the exact text played out, to permit smallbook
577 @c FIXME... format to come out better.
578 @value{GDBN} is free software and you are welcome to distribute copies
579 of it under certain conditions; type "show copying" to see
580 the conditions.
581 There is absolutely no warranty for @value{GDBN}; type "show warranty"
582 for details.
583
584 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
585 (@value{GDBP})
586 @end smallexample
587
588 @noindent
589 @value{GDBN} reads only enough symbol data to know where to find the
590 rest when needed; as a result, the first prompt comes up very quickly.
591 We now tell @value{GDBN} to use a narrower display width than usual, so
592 that examples fit in this manual.
593
594 @smallexample
595 (@value{GDBP}) @b{set width 70}
596 @end smallexample
597
598 @noindent
599 We need to see how the @code{m4} built-in @code{changequote} works.
600 Having looked at the source, we know the relevant subroutine is
601 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
602 @code{break} command.
603
604 @smallexample
605 (@value{GDBP}) @b{break m4_changequote}
606 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
607 @end smallexample
608
609 @noindent
610 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
611 control; as long as control does not reach the @code{m4_changequote}
612 subroutine, the program runs as usual:
613
614 @smallexample
615 (@value{GDBP}) @b{run}
616 Starting program: /work/Editorial/gdb/gnu/m4/m4
617 @b{define(foo,0000)}
618
619 @b{foo}
620 0000
621 @end smallexample
622
623 @noindent
624 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
625 suspends execution of @code{m4}, displaying information about the
626 context where it stops.
627
628 @smallexample
629 @b{changequote(<QUOTE>,<UNQUOTE>)}
630
631 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
632 at builtin.c:879
633 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
634 @end smallexample
635
636 @noindent
637 Now we use the command @code{n} (@code{next}) to advance execution to
638 the next line of the current function.
639
640 @smallexample
641 (@value{GDBP}) @b{n}
642 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
643 : nil,
644 @end smallexample
645
646 @noindent
647 @code{set_quotes} looks like a promising subroutine. We can go into it
648 by using the command @code{s} (@code{step}) instead of @code{next}.
649 @code{step} goes to the next line to be executed in @emph{any}
650 subroutine, so it steps into @code{set_quotes}.
651
652 @smallexample
653 (@value{GDBP}) @b{s}
654 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
655 at input.c:530
656 530 if (lquote != def_lquote)
657 @end smallexample
658
659 @noindent
660 The display that shows the subroutine where @code{m4} is now
661 suspended (and its arguments) is called a stack frame display. It
662 shows a summary of the stack. We can use the @code{backtrace}
663 command (which can also be spelled @code{bt}), to see where we are
664 in the stack as a whole: the @code{backtrace} command displays a
665 stack frame for each active subroutine.
666
667 @smallexample
668 (@value{GDBP}) @b{bt}
669 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
670 at input.c:530
671 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
672 at builtin.c:882
673 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
674 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
675 at macro.c:71
676 #4 0x79dc in expand_input () at macro.c:40
677 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
678 @end smallexample
679
680 @noindent
681 We step through a few more lines to see what happens. The first two
682 times, we can use @samp{s}; the next two times we use @code{n} to avoid
683 falling into the @code{xstrdup} subroutine.
684
685 @smallexample
686 (@value{GDBP}) @b{s}
687 0x3b5c 532 if (rquote != def_rquote)
688 (@value{GDBP}) @b{s}
689 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
690 def_lquote : xstrdup(lq);
691 (@value{GDBP}) @b{n}
692 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
693 : xstrdup(rq);
694 (@value{GDBP}) @b{n}
695 538 len_lquote = strlen(rquote);
696 @end smallexample
697
698 @noindent
699 The last line displayed looks a little odd; we can examine the variables
700 @code{lquote} and @code{rquote} to see if they are in fact the new left
701 and right quotes we specified. We use the command @code{p}
702 (@code{print}) to see their values.
703
704 @smallexample
705 (@value{GDBP}) @b{p lquote}
706 $1 = 0x35d40 "<QUOTE>"
707 (@value{GDBP}) @b{p rquote}
708 $2 = 0x35d50 "<UNQUOTE>"
709 @end smallexample
710
711 @noindent
712 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
713 To look at some context, we can display ten lines of source
714 surrounding the current line with the @code{l} (@code{list}) command.
715
716 @smallexample
717 (@value{GDBP}) @b{l}
718 533 xfree(rquote);
719 534
720 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
721 : xstrdup (lq);
722 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
723 : xstrdup (rq);
724 537
725 538 len_lquote = strlen(rquote);
726 539 len_rquote = strlen(lquote);
727 540 @}
728 541
729 542 void
730 @end smallexample
731
732 @noindent
733 Let us step past the two lines that set @code{len_lquote} and
734 @code{len_rquote}, and then examine the values of those variables.
735
736 @smallexample
737 (@value{GDBP}) @b{n}
738 539 len_rquote = strlen(lquote);
739 (@value{GDBP}) @b{n}
740 540 @}
741 (@value{GDBP}) @b{p len_lquote}
742 $3 = 9
743 (@value{GDBP}) @b{p len_rquote}
744 $4 = 7
745 @end smallexample
746
747 @noindent
748 That certainly looks wrong, assuming @code{len_lquote} and
749 @code{len_rquote} are meant to be the lengths of @code{lquote} and
750 @code{rquote} respectively. We can set them to better values using
751 the @code{p} command, since it can print the value of
752 any expression---and that expression can include subroutine calls and
753 assignments.
754
755 @smallexample
756 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
757 $5 = 7
758 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
759 $6 = 9
760 @end smallexample
761
762 @noindent
763 Is that enough to fix the problem of using the new quotes with the
764 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
765 executing with the @code{c} (@code{continue}) command, and then try the
766 example that caused trouble initially:
767
768 @smallexample
769 (@value{GDBP}) @b{c}
770 Continuing.
771
772 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
773
774 baz
775 0000
776 @end smallexample
777
778 @noindent
779 Success! The new quotes now work just as well as the default ones. The
780 problem seems to have been just the two typos defining the wrong
781 lengths. We allow @code{m4} exit by giving it an EOF as input:
782
783 @smallexample
784 @b{Ctrl-d}
785 Program exited normally.
786 @end smallexample
787
788 @noindent
789 The message @samp{Program exited normally.} is from @value{GDBN}; it
790 indicates @code{m4} has finished executing. We can end our @value{GDBN}
791 session with the @value{GDBN} @code{quit} command.
792
793 @smallexample
794 (@value{GDBP}) @b{quit}
795 @end smallexample
796
797 @node Invocation
798 @chapter Getting In and Out of @value{GDBN}
799
800 This chapter discusses how to start @value{GDBN}, and how to get out of it.
801 The essentials are:
802 @itemize @bullet
803 @item
804 type @samp{@value{GDBP}} to start @value{GDBN}.
805 @item
806 type @kbd{quit} or @kbd{Ctrl-d} to exit.
807 @end itemize
808
809 @menu
810 * Invoking GDB:: How to start @value{GDBN}
811 * Quitting GDB:: How to quit @value{GDBN}
812 * Shell Commands:: How to use shell commands inside @value{GDBN}
813 * Logging Output:: How to log @value{GDBN}'s output to a file
814 @end menu
815
816 @node Invoking GDB
817 @section Invoking @value{GDBN}
818
819 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
820 @value{GDBN} reads commands from the terminal until you tell it to exit.
821
822 You can also run @code{@value{GDBP}} with a variety of arguments and options,
823 to specify more of your debugging environment at the outset.
824
825 The command-line options described here are designed
826 to cover a variety of situations; in some environments, some of these
827 options may effectively be unavailable.
828
829 The most usual way to start @value{GDBN} is with one argument,
830 specifying an executable program:
831
832 @smallexample
833 @value{GDBP} @var{program}
834 @end smallexample
835
836 @noindent
837 You can also start with both an executable program and a core file
838 specified:
839
840 @smallexample
841 @value{GDBP} @var{program} @var{core}
842 @end smallexample
843
844 You can, instead, specify a process ID as a second argument, if you want
845 to debug a running process:
846
847 @smallexample
848 @value{GDBP} @var{program} 1234
849 @end smallexample
850
851 @noindent
852 would attach @value{GDBN} to process @code{1234} (unless you also have a file
853 named @file{1234}; @value{GDBN} does check for a core file first).
854
855 Taking advantage of the second command-line argument requires a fairly
856 complete operating system; when you use @value{GDBN} as a remote
857 debugger attached to a bare board, there may not be any notion of
858 ``process'', and there is often no way to get a core dump. @value{GDBN}
859 will warn you if it is unable to attach or to read core dumps.
860
861 You can optionally have @code{@value{GDBP}} pass any arguments after the
862 executable file to the inferior using @code{--args}. This option stops
863 option processing.
864 @smallexample
865 @value{GDBP} --args gcc -O2 -c foo.c
866 @end smallexample
867 This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
868 @code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
869
870 You can run @code{@value{GDBP}} without printing the front material, which describes
871 @value{GDBN}'s non-warranty, by specifying @code{-silent}:
872
873 @smallexample
874 @value{GDBP} -silent
875 @end smallexample
876
877 @noindent
878 You can further control how @value{GDBN} starts up by using command-line
879 options. @value{GDBN} itself can remind you of the options available.
880
881 @noindent
882 Type
883
884 @smallexample
885 @value{GDBP} -help
886 @end smallexample
887
888 @noindent
889 to display all available options and briefly describe their use
890 (@samp{@value{GDBP} -h} is a shorter equivalent).
891
892 All options and command line arguments you give are processed
893 in sequential order. The order makes a difference when the
894 @samp{-x} option is used.
895
896
897 @menu
898 * File Options:: Choosing files
899 * Mode Options:: Choosing modes
900 * Startup:: What @value{GDBN} does during startup
901 @end menu
902
903 @node File Options
904 @subsection Choosing Files
905
906 When @value{GDBN} starts, it reads any arguments other than options as
907 specifying an executable file and core file (or process ID). This is
908 the same as if the arguments were specified by the @samp{-se} and
909 @samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
910 first argument that does not have an associated option flag as
911 equivalent to the @samp{-se} option followed by that argument; and the
912 second argument that does not have an associated option flag, if any, as
913 equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
914 If the second argument begins with a decimal digit, @value{GDBN} will
915 first attempt to attach to it as a process, and if that fails, attempt
916 to open it as a corefile. If you have a corefile whose name begins with
917 a digit, you can prevent @value{GDBN} from treating it as a pid by
918 prefixing it with @file{./}, e.g.@: @file{./12345}.
919
920 If @value{GDBN} has not been configured to included core file support,
921 such as for most embedded targets, then it will complain about a second
922 argument and ignore it.
923
924 Many options have both long and short forms; both are shown in the
925 following list. @value{GDBN} also recognizes the long forms if you truncate
926 them, so long as enough of the option is present to be unambiguous.
927 (If you prefer, you can flag option arguments with @samp{--} rather
928 than @samp{-}, though we illustrate the more usual convention.)
929
930 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
931 @c way, both those who look for -foo and --foo in the index, will find
932 @c it.
933
934 @table @code
935 @item -symbols @var{file}
936 @itemx -s @var{file}
937 @cindex @code{--symbols}
938 @cindex @code{-s}
939 Read symbol table from file @var{file}.
940
941 @item -exec @var{file}
942 @itemx -e @var{file}
943 @cindex @code{--exec}
944 @cindex @code{-e}
945 Use file @var{file} as the executable file to execute when appropriate,
946 and for examining pure data in conjunction with a core dump.
947
948 @item -se @var{file}
949 @cindex @code{--se}
950 Read symbol table from file @var{file} and use it as the executable
951 file.
952
953 @item -core @var{file}
954 @itemx -c @var{file}
955 @cindex @code{--core}
956 @cindex @code{-c}
957 Use file @var{file} as a core dump to examine.
958
959 @item -pid @var{number}
960 @itemx -p @var{number}
961 @cindex @code{--pid}
962 @cindex @code{-p}
963 Connect to process ID @var{number}, as with the @code{attach} command.
964
965 @item -command @var{file}
966 @itemx -x @var{file}
967 @cindex @code{--command}
968 @cindex @code{-x}
969 Execute commands from file @var{file}. The contents of this file is
970 evaluated exactly as the @code{source} command would.
971 @xref{Command Files,, Command files}.
972
973 @item -eval-command @var{command}
974 @itemx -ex @var{command}
975 @cindex @code{--eval-command}
976 @cindex @code{-ex}
977 Execute a single @value{GDBN} command.
978
979 This option may be used multiple times to call multiple commands. It may
980 also be interleaved with @samp{-command} as required.
981
982 @smallexample
983 @value{GDBP} -ex 'target sim' -ex 'load' \
984 -x setbreakpoints -ex 'run' a.out
985 @end smallexample
986
987 @item -directory @var{directory}
988 @itemx -d @var{directory}
989 @cindex @code{--directory}
990 @cindex @code{-d}
991 Add @var{directory} to the path to search for source and script files.
992
993 @item -r
994 @itemx -readnow
995 @cindex @code{--readnow}
996 @cindex @code{-r}
997 Read each symbol file's entire symbol table immediately, rather than
998 the default, which is to read it incrementally as it is needed.
999 This makes startup slower, but makes future operations faster.
1000
1001 @end table
1002
1003 @node Mode Options
1004 @subsection Choosing Modes
1005
1006 You can run @value{GDBN} in various alternative modes---for example, in
1007 batch mode or quiet mode.
1008
1009 @table @code
1010 @item -nx
1011 @itemx -n
1012 @cindex @code{--nx}
1013 @cindex @code{-n}
1014 Do not execute commands found in any initialization files. Normally,
1015 @value{GDBN} executes the commands in these files after all the command
1016 options and arguments have been processed. @xref{Command Files,,Command
1017 Files}.
1018
1019 @item -quiet
1020 @itemx -silent
1021 @itemx -q
1022 @cindex @code{--quiet}
1023 @cindex @code{--silent}
1024 @cindex @code{-q}
1025 ``Quiet''. Do not print the introductory and copyright messages. These
1026 messages are also suppressed in batch mode.
1027
1028 @item -batch
1029 @cindex @code{--batch}
1030 Run in batch mode. Exit with status @code{0} after processing all the
1031 command files specified with @samp{-x} (and all commands from
1032 initialization files, if not inhibited with @samp{-n}). Exit with
1033 nonzero status if an error occurs in executing the @value{GDBN} commands
1034 in the command files. Batch mode also disables pagination;
1035 @pxref{Screen Size} and acts as if @kbd{set confirm off} were in
1036 effect (@pxref{Messages/Warnings}).
1037
1038 Batch mode may be useful for running @value{GDBN} as a filter, for
1039 example to download and run a program on another computer; in order to
1040 make this more useful, the message
1041
1042 @smallexample
1043 Program exited normally.
1044 @end smallexample
1045
1046 @noindent
1047 (which is ordinarily issued whenever a program running under
1048 @value{GDBN} control terminates) is not issued when running in batch
1049 mode.
1050
1051 @item -batch-silent
1052 @cindex @code{--batch-silent}
1053 Run in batch mode exactly like @samp{-batch}, but totally silently. All
1054 @value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1055 unaffected). This is much quieter than @samp{-silent} and would be useless
1056 for an interactive session.
1057
1058 This is particularly useful when using targets that give @samp{Loading section}
1059 messages, for example.
1060
1061 Note that targets that give their output via @value{GDBN}, as opposed to
1062 writing directly to @code{stdout}, will also be made silent.
1063
1064 @item -return-child-result
1065 @cindex @code{--return-child-result}
1066 The return code from @value{GDBN} will be the return code from the child
1067 process (the process being debugged), with the following exceptions:
1068
1069 @itemize @bullet
1070 @item
1071 @value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1072 internal error. In this case the exit code is the same as it would have been
1073 without @samp{-return-child-result}.
1074 @item
1075 The user quits with an explicit value. E.g., @samp{quit 1}.
1076 @item
1077 The child process never runs, or is not allowed to terminate, in which case
1078 the exit code will be -1.
1079 @end itemize
1080
1081 This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1082 when @value{GDBN} is being used as a remote program loader or simulator
1083 interface.
1084
1085 @item -nowindows
1086 @itemx -nw
1087 @cindex @code{--nowindows}
1088 @cindex @code{-nw}
1089 ``No windows''. If @value{GDBN} comes with a graphical user interface
1090 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1091 interface. If no GUI is available, this option has no effect.
1092
1093 @item -windows
1094 @itemx -w
1095 @cindex @code{--windows}
1096 @cindex @code{-w}
1097 If @value{GDBN} includes a GUI, then this option requires it to be
1098 used if possible.
1099
1100 @item -cd @var{directory}
1101 @cindex @code{--cd}
1102 Run @value{GDBN} using @var{directory} as its working directory,
1103 instead of the current directory.
1104
1105 @item -fullname
1106 @itemx -f
1107 @cindex @code{--fullname}
1108 @cindex @code{-f}
1109 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1110 subprocess. It tells @value{GDBN} to output the full file name and line
1111 number in a standard, recognizable fashion each time a stack frame is
1112 displayed (which includes each time your program stops). This
1113 recognizable format looks like two @samp{\032} characters, followed by
1114 the file name, line number and character position separated by colons,
1115 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1116 @samp{\032} characters as a signal to display the source code for the
1117 frame.
1118
1119 @item -epoch
1120 @cindex @code{--epoch}
1121 The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1122 @value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1123 routines so as to allow Epoch to display values of expressions in a
1124 separate window.
1125
1126 @item -annotate @var{level}
1127 @cindex @code{--annotate}
1128 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1129 effect is identical to using @samp{set annotate @var{level}}
1130 (@pxref{Annotations}). The annotation @var{level} controls how much
1131 information @value{GDBN} prints together with its prompt, values of
1132 expressions, source lines, and other types of output. Level 0 is the
1133 normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1134 @sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1135 that control @value{GDBN}, and level 2 has been deprecated.
1136
1137 The annotation mechanism has largely been superseded by @sc{gdb/mi}
1138 (@pxref{GDB/MI}).
1139
1140 @item --args
1141 @cindex @code{--args}
1142 Change interpretation of command line so that arguments following the
1143 executable file are passed as command line arguments to the inferior.
1144 This option stops option processing.
1145
1146 @item -baud @var{bps}
1147 @itemx -b @var{bps}
1148 @cindex @code{--baud}
1149 @cindex @code{-b}
1150 Set the line speed (baud rate or bits per second) of any serial
1151 interface used by @value{GDBN} for remote debugging.
1152
1153 @item -l @var{timeout}
1154 @cindex @code{-l}
1155 Set the timeout (in seconds) of any communication used by @value{GDBN}
1156 for remote debugging.
1157
1158 @item -tty @var{device}
1159 @itemx -t @var{device}
1160 @cindex @code{--tty}
1161 @cindex @code{-t}
1162 Run using @var{device} for your program's standard input and output.
1163 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1164
1165 @c resolve the situation of these eventually
1166 @item -tui
1167 @cindex @code{--tui}
1168 Activate the @dfn{Text User Interface} when starting. The Text User
1169 Interface manages several text windows on the terminal, showing
1170 source, assembly, registers and @value{GDBN} command outputs
1171 (@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1172 Text User Interface can be enabled by invoking the program
1173 @samp{@value{GDBTUI}}. Do not use this option if you run @value{GDBN} from
1174 Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
1175
1176 @c @item -xdb
1177 @c @cindex @code{--xdb}
1178 @c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1179 @c For information, see the file @file{xdb_trans.html}, which is usually
1180 @c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1181 @c systems.
1182
1183 @item -interpreter @var{interp}
1184 @cindex @code{--interpreter}
1185 Use the interpreter @var{interp} for interface with the controlling
1186 program or device. This option is meant to be set by programs which
1187 communicate with @value{GDBN} using it as a back end.
1188 @xref{Interpreters, , Command Interpreters}.
1189
1190 @samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
1191 @value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
1192 The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
1193 previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1194 selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1195 @sc{gdb/mi} interfaces are no longer supported.
1196
1197 @item -write
1198 @cindex @code{--write}
1199 Open the executable and core files for both reading and writing. This
1200 is equivalent to the @samp{set write on} command inside @value{GDBN}
1201 (@pxref{Patching}).
1202
1203 @item -statistics
1204 @cindex @code{--statistics}
1205 This option causes @value{GDBN} to print statistics about time and
1206 memory usage after it completes each command and returns to the prompt.
1207
1208 @item -version
1209 @cindex @code{--version}
1210 This option causes @value{GDBN} to print its version number and
1211 no-warranty blurb, and exit.
1212
1213 @end table
1214
1215 @node Startup
1216 @subsection What @value{GDBN} Does During Startup
1217 @cindex @value{GDBN} startup
1218
1219 Here's the description of what @value{GDBN} does during session startup:
1220
1221 @enumerate
1222 @item
1223 Sets up the command interpreter as specified by the command line
1224 (@pxref{Mode Options, interpreter}).
1225
1226 @item
1227 @cindex init file
1228 Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1229 used when building @value{GDBN}; @pxref{System-wide configuration,
1230 ,System-wide configuration and settings}) and executes all the commands in
1231 that file.
1232
1233 @item
1234 Reads the init file (if any) in your home directory@footnote{On
1235 DOS/Windows systems, the home directory is the one pointed to by the
1236 @code{HOME} environment variable.} and executes all the commands in
1237 that file.
1238
1239 @item
1240 Processes command line options and operands.
1241
1242 @item
1243 Reads and executes the commands from init file (if any) in the current
1244 working directory. This is only done if the current directory is
1245 different from your home directory. Thus, you can have more than one
1246 init file, one generic in your home directory, and another, specific
1247 to the program you are debugging, in the directory where you invoke
1248 @value{GDBN}.
1249
1250 @item
1251 Reads command files specified by the @samp{-x} option. @xref{Command
1252 Files}, for more details about @value{GDBN} command files.
1253
1254 @item
1255 Reads the command history recorded in the @dfn{history file}.
1256 @xref{Command History}, for more details about the command history and the
1257 files where @value{GDBN} records it.
1258 @end enumerate
1259
1260 Init files use the same syntax as @dfn{command files} (@pxref{Command
1261 Files}) and are processed by @value{GDBN} in the same way. The init
1262 file in your home directory can set options (such as @samp{set
1263 complaints}) that affect subsequent processing of command line options
1264 and operands. Init files are not executed if you use the @samp{-nx}
1265 option (@pxref{Mode Options, ,Choosing Modes}).
1266
1267 To display the list of init files loaded by gdb at startup, you
1268 can use @kbd{gdb --help}.
1269
1270 @cindex init file name
1271 @cindex @file{.gdbinit}
1272 @cindex @file{gdb.ini}
1273 The @value{GDBN} init files are normally called @file{.gdbinit}.
1274 The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1275 the limitations of file names imposed by DOS filesystems. The Windows
1276 ports of @value{GDBN} use the standard name, but if they find a
1277 @file{gdb.ini} file, they warn you about that and suggest to rename
1278 the file to the standard name.
1279
1280
1281 @node Quitting GDB
1282 @section Quitting @value{GDBN}
1283 @cindex exiting @value{GDBN}
1284 @cindex leaving @value{GDBN}
1285
1286 @table @code
1287 @kindex quit @r{[}@var{expression}@r{]}
1288 @kindex q @r{(@code{quit})}
1289 @item quit @r{[}@var{expression}@r{]}
1290 @itemx q
1291 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1292 @code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
1293 do not supply @var{expression}, @value{GDBN} will terminate normally;
1294 otherwise it will terminate using the result of @var{expression} as the
1295 error code.
1296 @end table
1297
1298 @cindex interrupt
1299 An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
1300 terminates the action of any @value{GDBN} command that is in progress and
1301 returns to @value{GDBN} command level. It is safe to type the interrupt
1302 character at any time because @value{GDBN} does not allow it to take effect
1303 until a time when it is safe.
1304
1305 If you have been using @value{GDBN} to control an attached process or
1306 device, you can release it with the @code{detach} command
1307 (@pxref{Attach, ,Debugging an Already-running Process}).
1308
1309 @node Shell Commands
1310 @section Shell Commands
1311
1312 If you need to execute occasional shell commands during your
1313 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1314 just use the @code{shell} command.
1315
1316 @table @code
1317 @kindex shell
1318 @cindex shell escape
1319 @item shell @var{command string}
1320 Invoke a standard shell to execute @var{command string}.
1321 If it exists, the environment variable @code{SHELL} determines which
1322 shell to run. Otherwise @value{GDBN} uses the default shell
1323 (@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
1324 @end table
1325
1326 The utility @code{make} is often needed in development environments.
1327 You do not have to use the @code{shell} command for this purpose in
1328 @value{GDBN}:
1329
1330 @table @code
1331 @kindex make
1332 @cindex calling make
1333 @item make @var{make-args}
1334 Execute the @code{make} program with the specified
1335 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1336 @end table
1337
1338 @node Logging Output
1339 @section Logging Output
1340 @cindex logging @value{GDBN} output
1341 @cindex save @value{GDBN} output to a file
1342
1343 You may want to save the output of @value{GDBN} commands to a file.
1344 There are several commands to control @value{GDBN}'s logging.
1345
1346 @table @code
1347 @kindex set logging
1348 @item set logging on
1349 Enable logging.
1350 @item set logging off
1351 Disable logging.
1352 @cindex logging file name
1353 @item set logging file @var{file}
1354 Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1355 @item set logging overwrite [on|off]
1356 By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1357 you want @code{set logging on} to overwrite the logfile instead.
1358 @item set logging redirect [on|off]
1359 By default, @value{GDBN} output will go to both the terminal and the logfile.
1360 Set @code{redirect} if you want output to go only to the log file.
1361 @kindex show logging
1362 @item show logging
1363 Show the current values of the logging settings.
1364 @end table
1365
1366 @node Commands
1367 @chapter @value{GDBN} Commands
1368
1369 You can abbreviate a @value{GDBN} command to the first few letters of the command
1370 name, if that abbreviation is unambiguous; and you can repeat certain
1371 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1372 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1373 show you the alternatives available, if there is more than one possibility).
1374
1375 @menu
1376 * Command Syntax:: How to give commands to @value{GDBN}
1377 * Completion:: Command completion
1378 * Help:: How to ask @value{GDBN} for help
1379 @end menu
1380
1381 @node Command Syntax
1382 @section Command Syntax
1383
1384 A @value{GDBN} command is a single line of input. There is no limit on
1385 how long it can be. It starts with a command name, which is followed by
1386 arguments whose meaning depends on the command name. For example, the
1387 command @code{step} accepts an argument which is the number of times to
1388 step, as in @samp{step 5}. You can also use the @code{step} command
1389 with no arguments. Some commands do not allow any arguments.
1390
1391 @cindex abbreviation
1392 @value{GDBN} command names may always be truncated if that abbreviation is
1393 unambiguous. Other possible command abbreviations are listed in the
1394 documentation for individual commands. In some cases, even ambiguous
1395 abbreviations are allowed; for example, @code{s} is specially defined as
1396 equivalent to @code{step} even though there are other commands whose
1397 names start with @code{s}. You can test abbreviations by using them as
1398 arguments to the @code{help} command.
1399
1400 @cindex repeating commands
1401 @kindex RET @r{(repeat last command)}
1402 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1403 repeat the previous command. Certain commands (for example, @code{run})
1404 will not repeat this way; these are commands whose unintentional
1405 repetition might cause trouble and which you are unlikely to want to
1406 repeat. User-defined commands can disable this feature; see
1407 @ref{Define, dont-repeat}.
1408
1409 The @code{list} and @code{x} commands, when you repeat them with
1410 @key{RET}, construct new arguments rather than repeating
1411 exactly as typed. This permits easy scanning of source or memory.
1412
1413 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1414 output, in a way similar to the common utility @code{more}
1415 (@pxref{Screen Size,,Screen Size}). Since it is easy to press one
1416 @key{RET} too many in this situation, @value{GDBN} disables command
1417 repetition after any command that generates this sort of display.
1418
1419 @kindex # @r{(a comment)}
1420 @cindex comment
1421 Any text from a @kbd{#} to the end of the line is a comment; it does
1422 nothing. This is useful mainly in command files (@pxref{Command
1423 Files,,Command Files}).
1424
1425 @cindex repeating command sequences
1426 @kindex Ctrl-o @r{(operate-and-get-next)}
1427 The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1428 commands. This command accepts the current line, like @key{RET}, and
1429 then fetches the next line relative to the current line from the history
1430 for editing.
1431
1432 @node Completion
1433 @section Command Completion
1434
1435 @cindex completion
1436 @cindex word completion
1437 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1438 only one possibility; it can also show you what the valid possibilities
1439 are for the next word in a command, at any time. This works for @value{GDBN}
1440 commands, @value{GDBN} subcommands, and the names of symbols in your program.
1441
1442 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1443 of a word. If there is only one possibility, @value{GDBN} fills in the
1444 word, and waits for you to finish the command (or press @key{RET} to
1445 enter it). For example, if you type
1446
1447 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1448 @c complete accuracy in these examples; space introduced for clarity.
1449 @c If texinfo enhancements make it unnecessary, it would be nice to
1450 @c replace " @key" by "@key" in the following...
1451 @smallexample
1452 (@value{GDBP}) info bre @key{TAB}
1453 @end smallexample
1454
1455 @noindent
1456 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1457 the only @code{info} subcommand beginning with @samp{bre}:
1458
1459 @smallexample
1460 (@value{GDBP}) info breakpoints
1461 @end smallexample
1462
1463 @noindent
1464 You can either press @key{RET} at this point, to run the @code{info
1465 breakpoints} command, or backspace and enter something else, if
1466 @samp{breakpoints} does not look like the command you expected. (If you
1467 were sure you wanted @code{info breakpoints} in the first place, you
1468 might as well just type @key{RET} immediately after @samp{info bre},
1469 to exploit command abbreviations rather than command completion).
1470
1471 If there is more than one possibility for the next word when you press
1472 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1473 characters and try again, or just press @key{TAB} a second time;
1474 @value{GDBN} displays all the possible completions for that word. For
1475 example, you might want to set a breakpoint on a subroutine whose name
1476 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1477 just sounds the bell. Typing @key{TAB} again displays all the
1478 function names in your program that begin with those characters, for
1479 example:
1480
1481 @smallexample
1482 (@value{GDBP}) b make_ @key{TAB}
1483 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1484 make_a_section_from_file make_environ
1485 make_abs_section make_function_type
1486 make_blockvector make_pointer_type
1487 make_cleanup make_reference_type
1488 make_command make_symbol_completion_list
1489 (@value{GDBP}) b make_
1490 @end smallexample
1491
1492 @noindent
1493 After displaying the available possibilities, @value{GDBN} copies your
1494 partial input (@samp{b make_} in the example) so you can finish the
1495 command.
1496
1497 If you just want to see the list of alternatives in the first place, you
1498 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1499 means @kbd{@key{META} ?}. You can type this either by holding down a
1500 key designated as the @key{META} shift on your keyboard (if there is
1501 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1502
1503 @cindex quotes in commands
1504 @cindex completion of quoted strings
1505 Sometimes the string you need, while logically a ``word'', may contain
1506 parentheses or other characters that @value{GDBN} normally excludes from
1507 its notion of a word. To permit word completion to work in this
1508 situation, you may enclose words in @code{'} (single quote marks) in
1509 @value{GDBN} commands.
1510
1511 The most likely situation where you might need this is in typing the
1512 name of a C@t{++} function. This is because C@t{++} allows function
1513 overloading (multiple definitions of the same function, distinguished
1514 by argument type). For example, when you want to set a breakpoint you
1515 may need to distinguish whether you mean the version of @code{name}
1516 that takes an @code{int} parameter, @code{name(int)}, or the version
1517 that takes a @code{float} parameter, @code{name(float)}. To use the
1518 word-completion facilities in this situation, type a single quote
1519 @code{'} at the beginning of the function name. This alerts
1520 @value{GDBN} that it may need to consider more information than usual
1521 when you press @key{TAB} or @kbd{M-?} to request word completion:
1522
1523 @smallexample
1524 (@value{GDBP}) b 'bubble( @kbd{M-?}
1525 bubble(double,double) bubble(int,int)
1526 (@value{GDBP}) b 'bubble(
1527 @end smallexample
1528
1529 In some cases, @value{GDBN} can tell that completing a name requires using
1530 quotes. When this happens, @value{GDBN} inserts the quote for you (while
1531 completing as much as it can) if you do not type the quote in the first
1532 place:
1533
1534 @smallexample
1535 (@value{GDBP}) b bub @key{TAB}
1536 @exdent @value{GDBN} alters your input line to the following, and rings a bell:
1537 (@value{GDBP}) b 'bubble(
1538 @end smallexample
1539
1540 @noindent
1541 In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1542 you have not yet started typing the argument list when you ask for
1543 completion on an overloaded symbol.
1544
1545 For more information about overloaded functions, see @ref{C Plus Plus
1546 Expressions, ,C@t{++} Expressions}. You can use the command @code{set
1547 overload-resolution off} to disable overload resolution;
1548 see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
1549
1550 @cindex completion of structure field names
1551 @cindex structure field name completion
1552 @cindex completion of union field names
1553 @cindex union field name completion
1554 When completing in an expression which looks up a field in a
1555 structure, @value{GDBN} also tries@footnote{The completer can be
1556 confused by certain kinds of invalid expressions. Also, it only
1557 examines the static type of the expression, not the dynamic type.} to
1558 limit completions to the field names available in the type of the
1559 left-hand-side:
1560
1561 @smallexample
1562 (@value{GDBP}) p gdb_stdout.@kbd{M-?}
1563 magic to_delete to_fputs to_put to_rewind
1564 to_data to_flush to_isatty to_read to_write
1565 @end smallexample
1566
1567 @noindent
1568 This is because the @code{gdb_stdout} is a variable of the type
1569 @code{struct ui_file} that is defined in @value{GDBN} sources as
1570 follows:
1571
1572 @smallexample
1573 struct ui_file
1574 @{
1575 int *magic;
1576 ui_file_flush_ftype *to_flush;
1577 ui_file_write_ftype *to_write;
1578 ui_file_fputs_ftype *to_fputs;
1579 ui_file_read_ftype *to_read;
1580 ui_file_delete_ftype *to_delete;
1581 ui_file_isatty_ftype *to_isatty;
1582 ui_file_rewind_ftype *to_rewind;
1583 ui_file_put_ftype *to_put;
1584 void *to_data;
1585 @}
1586 @end smallexample
1587
1588
1589 @node Help
1590 @section Getting Help
1591 @cindex online documentation
1592 @kindex help
1593
1594 You can always ask @value{GDBN} itself for information on its commands,
1595 using the command @code{help}.
1596
1597 @table @code
1598 @kindex h @r{(@code{help})}
1599 @item help
1600 @itemx h
1601 You can use @code{help} (abbreviated @code{h}) with no arguments to
1602 display a short list of named classes of commands:
1603
1604 @smallexample
1605 (@value{GDBP}) help
1606 List of classes of commands:
1607
1608 aliases -- Aliases of other commands
1609 breakpoints -- Making program stop at certain points
1610 data -- Examining data
1611 files -- Specifying and examining files
1612 internals -- Maintenance commands
1613 obscure -- Obscure features
1614 running -- Running the program
1615 stack -- Examining the stack
1616 status -- Status inquiries
1617 support -- Support facilities
1618 tracepoints -- Tracing of program execution without
1619 stopping the program
1620 user-defined -- User-defined commands
1621
1622 Type "help" followed by a class name for a list of
1623 commands in that class.
1624 Type "help" followed by command name for full
1625 documentation.
1626 Command name abbreviations are allowed if unambiguous.
1627 (@value{GDBP})
1628 @end smallexample
1629 @c the above line break eliminates huge line overfull...
1630
1631 @item help @var{class}
1632 Using one of the general help classes as an argument, you can get a
1633 list of the individual commands in that class. For example, here is the
1634 help display for the class @code{status}:
1635
1636 @smallexample
1637 (@value{GDBP}) help status
1638 Status inquiries.
1639
1640 List of commands:
1641
1642 @c Line break in "show" line falsifies real output, but needed
1643 @c to fit in smallbook page size.
1644 info -- Generic command for showing things
1645 about the program being debugged
1646 show -- Generic command for showing things
1647 about the debugger
1648
1649 Type "help" followed by command name for full
1650 documentation.
1651 Command name abbreviations are allowed if unambiguous.
1652 (@value{GDBP})
1653 @end smallexample
1654
1655 @item help @var{command}
1656 With a command name as @code{help} argument, @value{GDBN} displays a
1657 short paragraph on how to use that command.
1658
1659 @kindex apropos
1660 @item apropos @var{args}
1661 The @code{apropos} command searches through all of the @value{GDBN}
1662 commands, and their documentation, for the regular expression specified in
1663 @var{args}. It prints out all matches found. For example:
1664
1665 @smallexample
1666 apropos reload
1667 @end smallexample
1668
1669 @noindent
1670 results in:
1671
1672 @smallexample
1673 @c @group
1674 set symbol-reloading -- Set dynamic symbol table reloading
1675 multiple times in one run
1676 show symbol-reloading -- Show dynamic symbol table reloading
1677 multiple times in one run
1678 @c @end group
1679 @end smallexample
1680
1681 @kindex complete
1682 @item complete @var{args}
1683 The @code{complete @var{args}} command lists all the possible completions
1684 for the beginning of a command. Use @var{args} to specify the beginning of the
1685 command you want completed. For example:
1686
1687 @smallexample
1688 complete i
1689 @end smallexample
1690
1691 @noindent results in:
1692
1693 @smallexample
1694 @group
1695 if
1696 ignore
1697 info
1698 inspect
1699 @end group
1700 @end smallexample
1701
1702 @noindent This is intended for use by @sc{gnu} Emacs.
1703 @end table
1704
1705 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1706 and @code{show} to inquire about the state of your program, or the state
1707 of @value{GDBN} itself. Each command supports many topics of inquiry; this
1708 manual introduces each of them in the appropriate context. The listings
1709 under @code{info} and under @code{show} in the Index point to
1710 all the sub-commands. @xref{Index}.
1711
1712 @c @group
1713 @table @code
1714 @kindex info
1715 @kindex i @r{(@code{info})}
1716 @item info
1717 This command (abbreviated @code{i}) is for describing the state of your
1718 program. For example, you can show the arguments passed to a function
1719 with @code{info args}, list the registers currently in use with @code{info
1720 registers}, or list the breakpoints you have set with @code{info breakpoints}.
1721 You can get a complete list of the @code{info} sub-commands with
1722 @w{@code{help info}}.
1723
1724 @kindex set
1725 @item set
1726 You can assign the result of an expression to an environment variable with
1727 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1728 @code{set prompt $}.
1729
1730 @kindex show
1731 @item show
1732 In contrast to @code{info}, @code{show} is for describing the state of
1733 @value{GDBN} itself.
1734 You can change most of the things you can @code{show}, by using the
1735 related command @code{set}; for example, you can control what number
1736 system is used for displays with @code{set radix}, or simply inquire
1737 which is currently in use with @code{show radix}.
1738
1739 @kindex info set
1740 To display all the settable parameters and their current
1741 values, you can use @code{show} with no arguments; you may also use
1742 @code{info set}. Both commands produce the same display.
1743 @c FIXME: "info set" violates the rule that "info" is for state of
1744 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1745 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1746 @end table
1747 @c @end group
1748
1749 Here are three miscellaneous @code{show} subcommands, all of which are
1750 exceptional in lacking corresponding @code{set} commands:
1751
1752 @table @code
1753 @kindex show version
1754 @cindex @value{GDBN} version number
1755 @item show version
1756 Show what version of @value{GDBN} is running. You should include this
1757 information in @value{GDBN} bug-reports. If multiple versions of
1758 @value{GDBN} are in use at your site, you may need to determine which
1759 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1760 commands are introduced, and old ones may wither away. Also, many
1761 system vendors ship variant versions of @value{GDBN}, and there are
1762 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
1763 The version number is the same as the one announced when you start
1764 @value{GDBN}.
1765
1766 @kindex show copying
1767 @kindex info copying
1768 @cindex display @value{GDBN} copyright
1769 @item show copying
1770 @itemx info copying
1771 Display information about permission for copying @value{GDBN}.
1772
1773 @kindex show warranty
1774 @kindex info warranty
1775 @item show warranty
1776 @itemx info warranty
1777 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
1778 if your version of @value{GDBN} comes with one.
1779
1780 @end table
1781
1782 @node Running
1783 @chapter Running Programs Under @value{GDBN}
1784
1785 When you run a program under @value{GDBN}, you must first generate
1786 debugging information when you compile it.
1787
1788 You may start @value{GDBN} with its arguments, if any, in an environment
1789 of your choice. If you are doing native debugging, you may redirect
1790 your program's input and output, debug an already running process, or
1791 kill a child process.
1792
1793 @menu
1794 * Compilation:: Compiling for debugging
1795 * Starting:: Starting your program
1796 * Arguments:: Your program's arguments
1797 * Environment:: Your program's environment
1798
1799 * Working Directory:: Your program's working directory
1800 * Input/Output:: Your program's input and output
1801 * Attach:: Debugging an already-running process
1802 * Kill Process:: Killing the child process
1803
1804 * Inferiors and Programs:: Debugging multiple inferiors and programs
1805 * Threads:: Debugging programs with multiple threads
1806 * Forks:: Debugging forks
1807 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
1808 @end menu
1809
1810 @node Compilation
1811 @section Compiling for Debugging
1812
1813 In order to debug a program effectively, you need to generate
1814 debugging information when you compile it. This debugging information
1815 is stored in the object file; it describes the data type of each
1816 variable or function and the correspondence between source line numbers
1817 and addresses in the executable code.
1818
1819 To request debugging information, specify the @samp{-g} option when you run
1820 the compiler.
1821
1822 Programs that are to be shipped to your customers are compiled with
1823 optimizations, using the @samp{-O} compiler option. However, some
1824 compilers are unable to handle the @samp{-g} and @samp{-O} options
1825 together. Using those compilers, you cannot generate optimized
1826 executables containing debugging information.
1827
1828 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
1829 without @samp{-O}, making it possible to debug optimized code. We
1830 recommend that you @emph{always} use @samp{-g} whenever you compile a
1831 program. You may think your program is correct, but there is no sense
1832 in pushing your luck. For more information, see @ref{Optimized Code}.
1833
1834 Older versions of the @sc{gnu} C compiler permitted a variant option
1835 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1836 format; if your @sc{gnu} C compiler has this option, do not use it.
1837
1838 @value{GDBN} knows about preprocessor macros and can show you their
1839 expansion (@pxref{Macros}). Most compilers do not include information
1840 about preprocessor macros in the debugging information if you specify
1841 the @option{-g} flag alone, because this information is rather large.
1842 Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1843 provides macro information if you specify the options
1844 @option{-gdwarf-2} and @option{-g3}; the former option requests
1845 debugging information in the Dwarf 2 format, and the latter requests
1846 ``extra information''. In the future, we hope to find more compact
1847 ways to represent macro information, so that it can be included with
1848 @option{-g} alone.
1849
1850 @need 2000
1851 @node Starting
1852 @section Starting your Program
1853 @cindex starting
1854 @cindex running
1855
1856 @table @code
1857 @kindex run
1858 @kindex r @r{(@code{run})}
1859 @item run
1860 @itemx r
1861 Use the @code{run} command to start your program under @value{GDBN}.
1862 You must first specify the program name (except on VxWorks) with an
1863 argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1864 @value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1865 (@pxref{Files, ,Commands to Specify Files}).
1866
1867 @end table
1868
1869 If you are running your program in an execution environment that
1870 supports processes, @code{run} creates an inferior process and makes
1871 that process run your program. In some environments without processes,
1872 @code{run} jumps to the start of your program. Other targets,
1873 like @samp{remote}, are always running. If you get an error
1874 message like this one:
1875
1876 @smallexample
1877 The "remote" target does not support "run".
1878 Try "help target" or "continue".
1879 @end smallexample
1880
1881 @noindent
1882 then use @code{continue} to run your program. You may need @code{load}
1883 first (@pxref{load}).
1884
1885 The execution of a program is affected by certain information it
1886 receives from its superior. @value{GDBN} provides ways to specify this
1887 information, which you must do @emph{before} starting your program. (You
1888 can change it after starting your program, but such changes only affect
1889 your program the next time you start it.) This information may be
1890 divided into four categories:
1891
1892 @table @asis
1893 @item The @emph{arguments.}
1894 Specify the arguments to give your program as the arguments of the
1895 @code{run} command. If a shell is available on your target, the shell
1896 is used to pass the arguments, so that you may use normal conventions
1897 (such as wildcard expansion or variable substitution) in describing
1898 the arguments.
1899 In Unix systems, you can control which shell is used with the
1900 @code{SHELL} environment variable.
1901 @xref{Arguments, ,Your Program's Arguments}.
1902
1903 @item The @emph{environment.}
1904 Your program normally inherits its environment from @value{GDBN}, but you can
1905 use the @value{GDBN} commands @code{set environment} and @code{unset
1906 environment} to change parts of the environment that affect
1907 your program. @xref{Environment, ,Your Program's Environment}.
1908
1909 @item The @emph{working directory.}
1910 Your program inherits its working directory from @value{GDBN}. You can set
1911 the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1912 @xref{Working Directory, ,Your Program's Working Directory}.
1913
1914 @item The @emph{standard input and output.}
1915 Your program normally uses the same device for standard input and
1916 standard output as @value{GDBN} is using. You can redirect input and output
1917 in the @code{run} command line, or you can use the @code{tty} command to
1918 set a different device for your program.
1919 @xref{Input/Output, ,Your Program's Input and Output}.
1920
1921 @cindex pipes
1922 @emph{Warning:} While input and output redirection work, you cannot use
1923 pipes to pass the output of the program you are debugging to another
1924 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1925 wrong program.
1926 @end table
1927
1928 When you issue the @code{run} command, your program begins to execute
1929 immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
1930 of how to arrange for your program to stop. Once your program has
1931 stopped, you may call functions in your program, using the @code{print}
1932 or @code{call} commands. @xref{Data, ,Examining Data}.
1933
1934 If the modification time of your symbol file has changed since the last
1935 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1936 table, and reads it again. When it does this, @value{GDBN} tries to retain
1937 your current breakpoints.
1938
1939 @table @code
1940 @kindex start
1941 @item start
1942 @cindex run to main procedure
1943 The name of the main procedure can vary from language to language.
1944 With C or C@t{++}, the main procedure name is always @code{main}, but
1945 other languages such as Ada do not require a specific name for their
1946 main procedure. The debugger provides a convenient way to start the
1947 execution of the program and to stop at the beginning of the main
1948 procedure, depending on the language used.
1949
1950 The @samp{start} command does the equivalent of setting a temporary
1951 breakpoint at the beginning of the main procedure and then invoking
1952 the @samp{run} command.
1953
1954 @cindex elaboration phase
1955 Some programs contain an @dfn{elaboration} phase where some startup code is
1956 executed before the main procedure is called. This depends on the
1957 languages used to write your program. In C@t{++}, for instance,
1958 constructors for static and global objects are executed before
1959 @code{main} is called. It is therefore possible that the debugger stops
1960 before reaching the main procedure. However, the temporary breakpoint
1961 will remain to halt execution.
1962
1963 Specify the arguments to give to your program as arguments to the
1964 @samp{start} command. These arguments will be given verbatim to the
1965 underlying @samp{run} command. Note that the same arguments will be
1966 reused if no argument is provided during subsequent calls to
1967 @samp{start} or @samp{run}.
1968
1969 It is sometimes necessary to debug the program during elaboration. In
1970 these cases, using the @code{start} command would stop the execution of
1971 your program too late, as the program would have already completed the
1972 elaboration phase. Under these circumstances, insert breakpoints in your
1973 elaboration code before running your program.
1974
1975 @kindex set exec-wrapper
1976 @item set exec-wrapper @var{wrapper}
1977 @itemx show exec-wrapper
1978 @itemx unset exec-wrapper
1979 When @samp{exec-wrapper} is set, the specified wrapper is used to
1980 launch programs for debugging. @value{GDBN} starts your program
1981 with a shell command of the form @kbd{exec @var{wrapper}
1982 @var{program}}. Quoting is added to @var{program} and its
1983 arguments, but not to @var{wrapper}, so you should add quotes if
1984 appropriate for your shell. The wrapper runs until it executes
1985 your program, and then @value{GDBN} takes control.
1986
1987 You can use any program that eventually calls @code{execve} with
1988 its arguments as a wrapper. Several standard Unix utilities do
1989 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
1990 with @code{exec "$@@"} will also work.
1991
1992 For example, you can use @code{env} to pass an environment variable to
1993 the debugged program, without setting the variable in your shell's
1994 environment:
1995
1996 @smallexample
1997 (@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
1998 (@value{GDBP}) run
1999 @end smallexample
2000
2001 This command is available when debugging locally on most targets, excluding
2002 @sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2003
2004 @kindex set disable-randomization
2005 @item set disable-randomization
2006 @itemx set disable-randomization on
2007 This option (enabled by default in @value{GDBN}) will turn off the native
2008 randomization of the virtual address space of the started program. This option
2009 is useful for multiple debugging sessions to make the execution better
2010 reproducible and memory addresses reusable across debugging sessions.
2011
2012 This feature is implemented only on @sc{gnu}/Linux. You can get the same
2013 behavior using
2014
2015 @smallexample
2016 (@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2017 @end smallexample
2018
2019 @item set disable-randomization off
2020 Leave the behavior of the started executable unchanged. Some bugs rear their
2021 ugly heads only when the program is loaded at certain addresses. If your bug
2022 disappears when you run the program under @value{GDBN}, that might be because
2023 @value{GDBN} by default disables the address randomization on platforms, such
2024 as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2025 disable-randomization off} to try to reproduce such elusive bugs.
2026
2027 The virtual address space randomization is implemented only on @sc{gnu}/Linux.
2028 It protects the programs against some kinds of security attacks. In these
2029 cases the attacker needs to know the exact location of a concrete executable
2030 code. Randomizing its location makes it impossible to inject jumps misusing
2031 a code at its expected addresses.
2032
2033 Prelinking shared libraries provides a startup performance advantage but it
2034 makes addresses in these libraries predictable for privileged processes by
2035 having just unprivileged access at the target system. Reading the shared
2036 library binary gives enough information for assembling the malicious code
2037 misusing it. Still even a prelinked shared library can get loaded at a new
2038 random address just requiring the regular relocation process during the
2039 startup. Shared libraries not already prelinked are always loaded at
2040 a randomly chosen address.
2041
2042 Position independent executables (PIE) contain position independent code
2043 similar to the shared libraries and therefore such executables get loaded at
2044 a randomly chosen address upon startup. PIE executables always load even
2045 already prelinked shared libraries at a random address. You can build such
2046 executable using @command{gcc -fPIE -pie}.
2047
2048 Heap (malloc storage), stack and custom mmap areas are always placed randomly
2049 (as long as the randomization is enabled).
2050
2051 @item show disable-randomization
2052 Show the current setting of the explicit disable of the native randomization of
2053 the virtual address space of the started program.
2054
2055 @end table
2056
2057 @node Arguments
2058 @section Your Program's Arguments
2059
2060 @cindex arguments (to your program)
2061 The arguments to your program can be specified by the arguments of the
2062 @code{run} command.
2063 They are passed to a shell, which expands wildcard characters and
2064 performs redirection of I/O, and thence to your program. Your
2065 @code{SHELL} environment variable (if it exists) specifies what shell
2066 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
2067 the default shell (@file{/bin/sh} on Unix).
2068
2069 On non-Unix systems, the program is usually invoked directly by
2070 @value{GDBN}, which emulates I/O redirection via the appropriate system
2071 calls, and the wildcard characters are expanded by the startup code of
2072 the program, not by the shell.
2073
2074 @code{run} with no arguments uses the same arguments used by the previous
2075 @code{run}, or those set by the @code{set args} command.
2076
2077 @table @code
2078 @kindex set args
2079 @item set args
2080 Specify the arguments to be used the next time your program is run. If
2081 @code{set args} has no arguments, @code{run} executes your program
2082 with no arguments. Once you have run your program with arguments,
2083 using @code{set args} before the next @code{run} is the only way to run
2084 it again without arguments.
2085
2086 @kindex show args
2087 @item show args
2088 Show the arguments to give your program when it is started.
2089 @end table
2090
2091 @node Environment
2092 @section Your Program's Environment
2093
2094 @cindex environment (of your program)
2095 The @dfn{environment} consists of a set of environment variables and
2096 their values. Environment variables conventionally record such things as
2097 your user name, your home directory, your terminal type, and your search
2098 path for programs to run. Usually you set up environment variables with
2099 the shell and they are inherited by all the other programs you run. When
2100 debugging, it can be useful to try running your program with a modified
2101 environment without having to start @value{GDBN} over again.
2102
2103 @table @code
2104 @kindex path
2105 @item path @var{directory}
2106 Add @var{directory} to the front of the @code{PATH} environment variable
2107 (the search path for executables) that will be passed to your program.
2108 The value of @code{PATH} used by @value{GDBN} does not change.
2109 You may specify several directory names, separated by whitespace or by a
2110 system-dependent separator character (@samp{:} on Unix, @samp{;} on
2111 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2112 is moved to the front, so it is searched sooner.
2113
2114 You can use the string @samp{$cwd} to refer to whatever is the current
2115 working directory at the time @value{GDBN} searches the path. If you
2116 use @samp{.} instead, it refers to the directory where you executed the
2117 @code{path} command. @value{GDBN} replaces @samp{.} in the
2118 @var{directory} argument (with the current path) before adding
2119 @var{directory} to the search path.
2120 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2121 @c document that, since repeating it would be a no-op.
2122
2123 @kindex show paths
2124 @item show paths
2125 Display the list of search paths for executables (the @code{PATH}
2126 environment variable).
2127
2128 @kindex show environment
2129 @item show environment @r{[}@var{varname}@r{]}
2130 Print the value of environment variable @var{varname} to be given to
2131 your program when it starts. If you do not supply @var{varname},
2132 print the names and values of all environment variables to be given to
2133 your program. You can abbreviate @code{environment} as @code{env}.
2134
2135 @kindex set environment
2136 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2137 Set environment variable @var{varname} to @var{value}. The value
2138 changes for your program only, not for @value{GDBN} itself. @var{value} may
2139 be any string; the values of environment variables are just strings, and
2140 any interpretation is supplied by your program itself. The @var{value}
2141 parameter is optional; if it is eliminated, the variable is set to a
2142 null value.
2143 @c "any string" here does not include leading, trailing
2144 @c blanks. Gnu asks: does anyone care?
2145
2146 For example, this command:
2147
2148 @smallexample
2149 set env USER = foo
2150 @end smallexample
2151
2152 @noindent
2153 tells the debugged program, when subsequently run, that its user is named
2154 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2155 are not actually required.)
2156
2157 @kindex unset environment
2158 @item unset environment @var{varname}
2159 Remove variable @var{varname} from the environment to be passed to your
2160 program. This is different from @samp{set env @var{varname} =};
2161 @code{unset environment} removes the variable from the environment,
2162 rather than assigning it an empty value.
2163 @end table
2164
2165 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2166 the shell indicated
2167 by your @code{SHELL} environment variable if it exists (or
2168 @code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2169 that runs an initialization file---such as @file{.cshrc} for C-shell, or
2170 @file{.bashrc} for BASH---any variables you set in that file affect
2171 your program. You may wish to move setting of environment variables to
2172 files that are only run when you sign on, such as @file{.login} or
2173 @file{.profile}.
2174
2175 @node Working Directory
2176 @section Your Program's Working Directory
2177
2178 @cindex working directory (of your program)
2179 Each time you start your program with @code{run}, it inherits its
2180 working directory from the current working directory of @value{GDBN}.
2181 The @value{GDBN} working directory is initially whatever it inherited
2182 from its parent process (typically the shell), but you can specify a new
2183 working directory in @value{GDBN} with the @code{cd} command.
2184
2185 The @value{GDBN} working directory also serves as a default for the commands
2186 that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2187 Specify Files}.
2188
2189 @table @code
2190 @kindex cd
2191 @cindex change working directory
2192 @item cd @var{directory}
2193 Set the @value{GDBN} working directory to @var{directory}.
2194
2195 @kindex pwd
2196 @item pwd
2197 Print the @value{GDBN} working directory.
2198 @end table
2199
2200 It is generally impossible to find the current working directory of
2201 the process being debugged (since a program can change its directory
2202 during its run). If you work on a system where @value{GDBN} is
2203 configured with the @file{/proc} support, you can use the @code{info
2204 proc} command (@pxref{SVR4 Process Information}) to find out the
2205 current working directory of the debuggee.
2206
2207 @node Input/Output
2208 @section Your Program's Input and Output
2209
2210 @cindex redirection
2211 @cindex i/o
2212 @cindex terminal
2213 By default, the program you run under @value{GDBN} does input and output to
2214 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
2215 to its own terminal modes to interact with you, but it records the terminal
2216 modes your program was using and switches back to them when you continue
2217 running your program.
2218
2219 @table @code
2220 @kindex info terminal
2221 @item info terminal
2222 Displays information recorded by @value{GDBN} about the terminal modes your
2223 program is using.
2224 @end table
2225
2226 You can redirect your program's input and/or output using shell
2227 redirection with the @code{run} command. For example,
2228
2229 @smallexample
2230 run > outfile
2231 @end smallexample
2232
2233 @noindent
2234 starts your program, diverting its output to the file @file{outfile}.
2235
2236 @kindex tty
2237 @cindex controlling terminal
2238 Another way to specify where your program should do input and output is
2239 with the @code{tty} command. This command accepts a file name as
2240 argument, and causes this file to be the default for future @code{run}
2241 commands. It also resets the controlling terminal for the child
2242 process, for future @code{run} commands. For example,
2243
2244 @smallexample
2245 tty /dev/ttyb
2246 @end smallexample
2247
2248 @noindent
2249 directs that processes started with subsequent @code{run} commands
2250 default to do input and output on the terminal @file{/dev/ttyb} and have
2251 that as their controlling terminal.
2252
2253 An explicit redirection in @code{run} overrides the @code{tty} command's
2254 effect on the input/output device, but not its effect on the controlling
2255 terminal.
2256
2257 When you use the @code{tty} command or redirect input in the @code{run}
2258 command, only the input @emph{for your program} is affected. The input
2259 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2260 for @code{set inferior-tty}.
2261
2262 @cindex inferior tty
2263 @cindex set inferior controlling terminal
2264 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2265 display the name of the terminal that will be used for future runs of your
2266 program.
2267
2268 @table @code
2269 @item set inferior-tty /dev/ttyb
2270 @kindex set inferior-tty
2271 Set the tty for the program being debugged to /dev/ttyb.
2272
2273 @item show inferior-tty
2274 @kindex show inferior-tty
2275 Show the current tty for the program being debugged.
2276 @end table
2277
2278 @node Attach
2279 @section Debugging an Already-running Process
2280 @kindex attach
2281 @cindex attach
2282
2283 @table @code
2284 @item attach @var{process-id}
2285 This command attaches to a running process---one that was started
2286 outside @value{GDBN}. (@code{info files} shows your active
2287 targets.) The command takes as argument a process ID. The usual way to
2288 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
2289 or with the @samp{jobs -l} shell command.
2290
2291 @code{attach} does not repeat if you press @key{RET} a second time after
2292 executing the command.
2293 @end table
2294
2295 To use @code{attach}, your program must be running in an environment
2296 which supports processes; for example, @code{attach} does not work for
2297 programs on bare-board targets that lack an operating system. You must
2298 also have permission to send the process a signal.
2299
2300 When you use @code{attach}, the debugger finds the program running in
2301 the process first by looking in the current working directory, then (if
2302 the program is not found) by using the source file search path
2303 (@pxref{Source Path, ,Specifying Source Directories}). You can also use
2304 the @code{file} command to load the program. @xref{Files, ,Commands to
2305 Specify Files}.
2306
2307 The first thing @value{GDBN} does after arranging to debug the specified
2308 process is to stop it. You can examine and modify an attached process
2309 with all the @value{GDBN} commands that are ordinarily available when
2310 you start processes with @code{run}. You can insert breakpoints; you
2311 can step and continue; you can modify storage. If you would rather the
2312 process continue running, you may use the @code{continue} command after
2313 attaching @value{GDBN} to the process.
2314
2315 @table @code
2316 @kindex detach
2317 @item detach
2318 When you have finished debugging the attached process, you can use the
2319 @code{detach} command to release it from @value{GDBN} control. Detaching
2320 the process continues its execution. After the @code{detach} command,
2321 that process and @value{GDBN} become completely independent once more, and you
2322 are ready to @code{attach} another process or start one with @code{run}.
2323 @code{detach} does not repeat if you press @key{RET} again after
2324 executing the command.
2325 @end table
2326
2327 If you exit @value{GDBN} while you have an attached process, you detach
2328 that process. If you use the @code{run} command, you kill that process.
2329 By default, @value{GDBN} asks for confirmation if you try to do either of these
2330 things; you can control whether or not you need to confirm by using the
2331 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
2332 Messages}).
2333
2334 @node Kill Process
2335 @section Killing the Child Process
2336
2337 @table @code
2338 @kindex kill
2339 @item kill
2340 Kill the child process in which your program is running under @value{GDBN}.
2341 @end table
2342
2343 This command is useful if you wish to debug a core dump instead of a
2344 running process. @value{GDBN} ignores any core dump file while your program
2345 is running.
2346
2347 On some operating systems, a program cannot be executed outside @value{GDBN}
2348 while you have breakpoints set on it inside @value{GDBN}. You can use the
2349 @code{kill} command in this situation to permit running your program
2350 outside the debugger.
2351
2352 The @code{kill} command is also useful if you wish to recompile and
2353 relink your program, since on many systems it is impossible to modify an
2354 executable file while it is running in a process. In this case, when you
2355 next type @code{run}, @value{GDBN} notices that the file has changed, and
2356 reads the symbol table again (while trying to preserve your current
2357 breakpoint settings).
2358
2359 @node Inferiors and Programs
2360 @section Debugging Multiple Inferiors and Programs
2361
2362 @value{GDBN} lets you run and debug multiple programs in a single
2363 session. In addition, @value{GDBN} on some systems may let you run
2364 several programs simultaneously (otherwise you have to exit from one
2365 before starting another). In the most general case, you can have
2366 multiple threads of execution in each of multiple processes, launched
2367 from multiple executables.
2368
2369 @cindex inferior
2370 @value{GDBN} represents the state of each program execution with an
2371 object called an @dfn{inferior}. An inferior typically corresponds to
2372 a process, but is more general and applies also to targets that do not
2373 have processes. Inferiors may be created before a process runs, and
2374 may be retained after a process exits. Inferiors have unique
2375 identifiers that are different from process ids. Usually each
2376 inferior will also have its own distinct address space, although some
2377 embedded targets may have several inferiors running in different parts
2378 of a single address space. Each inferior may in turn have multiple
2379 threads running in it.
2380
2381 To find out what inferiors exist at any moment, use @w{@code{info
2382 inferiors}}:
2383
2384 @table @code
2385 @kindex info inferiors
2386 @item info inferiors
2387 Print a list of all inferiors currently being managed by @value{GDBN}.
2388
2389 @value{GDBN} displays for each inferior (in this order):
2390
2391 @enumerate
2392 @item
2393 the inferior number assigned by @value{GDBN}
2394
2395 @item
2396 the target system's inferior identifier
2397
2398 @item
2399 the name of the executable the inferior is running.
2400
2401 @end enumerate
2402
2403 @noindent
2404 An asterisk @samp{*} preceding the @value{GDBN} inferior number
2405 indicates the current inferior.
2406
2407 For example,
2408 @end table
2409 @c end table here to get a little more width for example
2410
2411 @smallexample
2412 (@value{GDBP}) info inferiors
2413 Num Description Executable
2414 2 process 2307 hello
2415 * 1 process 3401 goodbye
2416 @end smallexample
2417
2418 To switch focus between inferiors, use the @code{inferior} command:
2419
2420 @table @code
2421 @kindex inferior @var{infno}
2422 @item inferior @var{infno}
2423 Make inferior number @var{infno} the current inferior. The argument
2424 @var{infno} is the inferior number assigned by @value{GDBN}, as shown
2425 in the first field of the @samp{info inferiors} display.
2426 @end table
2427
2428
2429 You can get multiple executables into a debugging session via the
2430 @code{add-inferior} and @w{@code{clone-inferior}} commands. On some
2431 systems @value{GDBN} can add inferiors to the debug session
2432 automatically by following calls to @code{fork} and @code{exec}. To
2433 remove inferiors from the debugging session use the
2434 @w{@code{remove-inferior}} command.
2435
2436 @table @code
2437 @kindex add-inferior
2438 @item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ]
2439 Adds @var{n} inferiors to be run using @var{executable} as the
2440 executable. @var{n} defaults to 1. If no executable is specified,
2441 the inferiors begins empty, with no program. You can still assign or
2442 change the program assigned to the inferior at any time by using the
2443 @code{file} command with the executable name as its argument.
2444
2445 @kindex clone-inferior
2446 @item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
2447 Adds @var{n} inferiors ready to execute the same program as inferior
2448 @var{infno}. @var{n} defaults to 1. @var{infno} defaults to the
2449 number of the current inferior. This is a convenient command when you
2450 want to run another instance of the inferior you are debugging.
2451
2452 @smallexample
2453 (@value{GDBP}) info inferiors
2454 Num Description Executable
2455 * 1 process 29964 helloworld
2456 (@value{GDBP}) clone-inferior
2457 Added inferior 2.
2458 1 inferiors added.
2459 (@value{GDBP}) info inferiors
2460 Num Description Executable
2461 2 <null> helloworld
2462 * 1 process 29964 helloworld
2463 @end smallexample
2464
2465 You can now simply switch focus to inferior 2 and run it.
2466
2467 @kindex remove-inferior
2468 @item remove-inferior @var{infno}
2469 Removes the inferior @var{infno}. It is not possible to remove an
2470 inferior that is running with this command. For those, use the
2471 @code{kill} or @code{detach} command first.
2472
2473 @end table
2474
2475 To quit debugging one of the running inferiors that is not the current
2476 inferior, you can either detach from it by using the @w{@code{detach
2477 inferior}} command (allowing it to run independently), or kill it
2478 using the @w{@code{kill inferior}} command:
2479
2480 @table @code
2481 @kindex detach inferior @var{infno}
2482 @item detach inferior @var{infno}
2483 Detach from the inferior identified by @value{GDBN} inferior number
2484 @var{infno}, and remove it from the inferior list.
2485
2486 @kindex kill inferior @var{infno}
2487 @item kill inferior @var{infno}
2488 Kill the inferior identified by @value{GDBN} inferior number
2489 @var{infno}, and remove it from the inferior list.
2490 @end table
2491
2492 After the successful completion of a command such as @code{detach},
2493 @code{detach inferior}, @code{kill} or @code{kill inferior}, or after
2494 a normal process exit, the inferior is still valid and listed with
2495 @code{info inferiors}, ready to be restarted.
2496
2497
2498 To be notified when inferiors are started or exit under @value{GDBN}'s
2499 control use @w{@code{set print inferior-events}}:
2500
2501 @table @code
2502 @kindex set print inferior-events
2503 @cindex print messages on inferior start and exit
2504 @item set print inferior-events
2505 @itemx set print inferior-events on
2506 @itemx set print inferior-events off
2507 The @code{set print inferior-events} command allows you to enable or
2508 disable printing of messages when @value{GDBN} notices that new
2509 inferiors have started or that inferiors have exited or have been
2510 detached. By default, these messages will not be printed.
2511
2512 @kindex show print inferior-events
2513 @item show print inferior-events
2514 Show whether messages will be printed when @value{GDBN} detects that
2515 inferiors have started, exited or have been detached.
2516 @end table
2517
2518 Many commands will work the same with multiple programs as with a
2519 single program: e.g., @code{print myglobal} will simply display the
2520 value of @code{myglobal} in the current inferior.
2521
2522
2523 Occasionaly, when debugging @value{GDBN} itself, it may be useful to
2524 get more info about the relationship of inferiors, programs, address
2525 spaces in a debug session. You can do that with the @w{@code{maint
2526 info program-spaces}} command.
2527
2528 @table @code
2529 @kindex maint info program-spaces
2530 @item maint info program-spaces
2531 Print a list of all program spaces currently being managed by
2532 @value{GDBN}.
2533
2534 @value{GDBN} displays for each program space (in this order):
2535
2536 @enumerate
2537 @item
2538 the program space number assigned by @value{GDBN}
2539
2540 @item
2541 the name of the executable loaded into the program space, with e.g.,
2542 the @code{file} command.
2543
2544 @end enumerate
2545
2546 @noindent
2547 An asterisk @samp{*} preceding the @value{GDBN} program space number
2548 indicates the current program space.
2549
2550 In addition, below each program space line, @value{GDBN} prints extra
2551 information that isn't suitable to display in tabular form. For
2552 example, the list of inferiors bound to the program space.
2553
2554 @smallexample
2555 (@value{GDBP}) maint info program-spaces
2556 Id Executable
2557 2 goodbye
2558 Bound inferiors: ID 1 (process 21561)
2559 * 1 hello
2560 @end smallexample
2561
2562 Here we can see that no inferior is running the program @code{hello},
2563 while @code{process 21561} is running the program @code{goodbye}. On
2564 some targets, it is possible that multiple inferiors are bound to the
2565 same program space. The most common example is that of debugging both
2566 the parent and child processes of a @code{vfork} call. For example,
2567
2568 @smallexample
2569 (@value{GDBP}) maint info program-spaces
2570 Id Executable
2571 * 1 vfork-test
2572 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
2573 @end smallexample
2574
2575 Here, both inferior 2 and inferior 1 are running in the same program
2576 space as a result of inferior 1 having executed a @code{vfork} call.
2577 @end table
2578
2579 @node Threads
2580 @section Debugging Programs with Multiple Threads
2581
2582 @cindex threads of execution
2583 @cindex multiple threads
2584 @cindex switching threads
2585 In some operating systems, such as HP-UX and Solaris, a single program
2586 may have more than one @dfn{thread} of execution. The precise semantics
2587 of threads differ from one operating system to another, but in general
2588 the threads of a single program are akin to multiple processes---except
2589 that they share one address space (that is, they can all examine and
2590 modify the same variables). On the other hand, each thread has its own
2591 registers and execution stack, and perhaps private memory.
2592
2593 @value{GDBN} provides these facilities for debugging multi-thread
2594 programs:
2595
2596 @itemize @bullet
2597 @item automatic notification of new threads
2598 @item @samp{thread @var{threadno}}, a command to switch among threads
2599 @item @samp{info threads}, a command to inquire about existing threads
2600 @item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
2601 a command to apply a command to a list of threads
2602 @item thread-specific breakpoints
2603 @item @samp{set print thread-events}, which controls printing of
2604 messages on thread start and exit.
2605 @item @samp{set libthread-db-search-path @var{path}}, which lets
2606 the user specify which @code{libthread_db} to use if the default choice
2607 isn't compatible with the program.
2608 @end itemize
2609
2610 @quotation
2611 @emph{Warning:} These facilities are not yet available on every
2612 @value{GDBN} configuration where the operating system supports threads.
2613 If your @value{GDBN} does not support threads, these commands have no
2614 effect. For example, a system without thread support shows no output
2615 from @samp{info threads}, and always rejects the @code{thread} command,
2616 like this:
2617
2618 @smallexample
2619 (@value{GDBP}) info threads
2620 (@value{GDBP}) thread 1
2621 Thread ID 1 not known. Use the "info threads" command to
2622 see the IDs of currently known threads.
2623 @end smallexample
2624 @c FIXME to implementors: how hard would it be to say "sorry, this GDB
2625 @c doesn't support threads"?
2626 @end quotation
2627
2628 @cindex focus of debugging
2629 @cindex current thread
2630 The @value{GDBN} thread debugging facility allows you to observe all
2631 threads while your program runs---but whenever @value{GDBN} takes
2632 control, one thread in particular is always the focus of debugging.
2633 This thread is called the @dfn{current thread}. Debugging commands show
2634 program information from the perspective of the current thread.
2635
2636 @cindex @code{New} @var{systag} message
2637 @cindex thread identifier (system)
2638 @c FIXME-implementors!! It would be more helpful if the [New...] message
2639 @c included GDB's numeric thread handle, so you could just go to that
2640 @c thread without first checking `info threads'.
2641 Whenever @value{GDBN} detects a new thread in your program, it displays
2642 the target system's identification for the thread with a message in the
2643 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2644 whose form varies depending on the particular system. For example, on
2645 @sc{gnu}/Linux, you might see
2646
2647 @smallexample
2648 [New Thread 46912507313328 (LWP 25582)]
2649 @end smallexample
2650
2651 @noindent
2652 when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2653 the @var{systag} is simply something like @samp{process 368}, with no
2654 further qualifier.
2655
2656 @c FIXME!! (1) Does the [New...] message appear even for the very first
2657 @c thread of a program, or does it only appear for the
2658 @c second---i.e.@: when it becomes obvious we have a multithread
2659 @c program?
2660 @c (2) *Is* there necessarily a first thread always? Or do some
2661 @c multithread systems permit starting a program with multiple
2662 @c threads ab initio?
2663
2664 @cindex thread number
2665 @cindex thread identifier (GDB)
2666 For debugging purposes, @value{GDBN} associates its own thread
2667 number---always a single integer---with each thread in your program.
2668
2669 @table @code
2670 @kindex info threads
2671 @item info threads
2672 Display a summary of all threads currently in your
2673 program. @value{GDBN} displays for each thread (in this order):
2674
2675 @enumerate
2676 @item
2677 the thread number assigned by @value{GDBN}
2678
2679 @item
2680 the target system's thread identifier (@var{systag})
2681
2682 @item
2683 the current stack frame summary for that thread
2684 @end enumerate
2685
2686 @noindent
2687 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2688 indicates the current thread.
2689
2690 For example,
2691 @end table
2692 @c end table here to get a little more width for example
2693
2694 @smallexample
2695 (@value{GDBP}) info threads
2696 3 process 35 thread 27 0x34e5 in sigpause ()
2697 2 process 35 thread 23 0x34e5 in sigpause ()
2698 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2699 at threadtest.c:68
2700 @end smallexample
2701
2702 On HP-UX systems:
2703
2704 @cindex debugging multithreaded programs (on HP-UX)
2705 @cindex thread identifier (GDB), on HP-UX
2706 For debugging purposes, @value{GDBN} associates its own thread
2707 number---a small integer assigned in thread-creation order---with each
2708 thread in your program.
2709
2710 @cindex @code{New} @var{systag} message, on HP-UX
2711 @cindex thread identifier (system), on HP-UX
2712 @c FIXME-implementors!! It would be more helpful if the [New...] message
2713 @c included GDB's numeric thread handle, so you could just go to that
2714 @c thread without first checking `info threads'.
2715 Whenever @value{GDBN} detects a new thread in your program, it displays
2716 both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2717 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2718 whose form varies depending on the particular system. For example, on
2719 HP-UX, you see
2720
2721 @smallexample
2722 [New thread 2 (system thread 26594)]
2723 @end smallexample
2724
2725 @noindent
2726 when @value{GDBN} notices a new thread.
2727
2728 @table @code
2729 @kindex info threads (HP-UX)
2730 @item info threads
2731 Display a summary of all threads currently in your
2732 program. @value{GDBN} displays for each thread (in this order):
2733
2734 @enumerate
2735 @item the thread number assigned by @value{GDBN}
2736
2737 @item the target system's thread identifier (@var{systag})
2738
2739 @item the current stack frame summary for that thread
2740 @end enumerate
2741
2742 @noindent
2743 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2744 indicates the current thread.
2745
2746 For example,
2747 @end table
2748 @c end table here to get a little more width for example
2749
2750 @smallexample
2751 (@value{GDBP}) info threads
2752 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2753 at quicksort.c:137
2754 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2755 from /usr/lib/libc.2
2756 1 system thread 27905 0x7b003498 in _brk () \@*
2757 from /usr/lib/libc.2
2758 @end smallexample
2759
2760 On Solaris, you can display more information about user threads with a
2761 Solaris-specific command:
2762
2763 @table @code
2764 @item maint info sol-threads
2765 @kindex maint info sol-threads
2766 @cindex thread info (Solaris)
2767 Display info on Solaris user threads.
2768 @end table
2769
2770 @table @code
2771 @kindex thread @var{threadno}
2772 @item thread @var{threadno}
2773 Make thread number @var{threadno} the current thread. The command
2774 argument @var{threadno} is the internal @value{GDBN} thread number, as
2775 shown in the first field of the @samp{info threads} display.
2776 @value{GDBN} responds by displaying the system identifier of the thread
2777 you selected, and its current stack frame summary:
2778
2779 @smallexample
2780 @c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2781 (@value{GDBP}) thread 2
2782 [Switching to process 35 thread 23]
2783 0x34e5 in sigpause ()
2784 @end smallexample
2785
2786 @noindent
2787 As with the @samp{[New @dots{}]} message, the form of the text after
2788 @samp{Switching to} depends on your system's conventions for identifying
2789 threads.
2790
2791 @kindex thread apply
2792 @cindex apply command to several threads
2793 @item thread apply [@var{threadno}] [@var{all}] @var{command}
2794 The @code{thread apply} command allows you to apply the named
2795 @var{command} to one or more threads. Specify the numbers of the
2796 threads that you want affected with the command argument
2797 @var{threadno}. It can be a single thread number, one of the numbers
2798 shown in the first field of the @samp{info threads} display; or it
2799 could be a range of thread numbers, as in @code{2-4}. To apply a
2800 command to all threads, type @kbd{thread apply all @var{command}}.
2801
2802 @kindex set print thread-events
2803 @cindex print messages on thread start and exit
2804 @item set print thread-events
2805 @itemx set print thread-events on
2806 @itemx set print thread-events off
2807 The @code{set print thread-events} command allows you to enable or
2808 disable printing of messages when @value{GDBN} notices that new threads have
2809 started or that threads have exited. By default, these messages will
2810 be printed if detection of these events is supported by the target.
2811 Note that these messages cannot be disabled on all targets.
2812
2813 @kindex show print thread-events
2814 @item show print thread-events
2815 Show whether messages will be printed when @value{GDBN} detects that threads
2816 have started and exited.
2817 @end table
2818
2819 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
2820 more information about how @value{GDBN} behaves when you stop and start
2821 programs with multiple threads.
2822
2823 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
2824 watchpoints in programs with multiple threads.
2825
2826 @table @code
2827 @kindex set libthread-db-search-path
2828 @cindex search path for @code{libthread_db}
2829 @item set libthread-db-search-path @r{[}@var{path}@r{]}
2830 If this variable is set, @var{path} is a colon-separated list of
2831 directories @value{GDBN} will use to search for @code{libthread_db}.
2832 If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
2833 an empty list.
2834
2835 On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
2836 @code{libthread_db} library to obtain information about threads in the
2837 inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
2838 to find @code{libthread_db}. If that fails, @value{GDBN} will continue
2839 with default system shared library directories, and finally the directory
2840 from which @code{libpthread} was loaded in the inferior process.
2841
2842 For any @code{libthread_db} library @value{GDBN} finds in above directories,
2843 @value{GDBN} attempts to initialize it with the current inferior process.
2844 If this initialization fails (which could happen because of a version
2845 mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
2846 will unload @code{libthread_db}, and continue with the next directory.
2847 If none of @code{libthread_db} libraries initialize successfully,
2848 @value{GDBN} will issue a warning and thread debugging will be disabled.
2849
2850 Setting @code{libthread-db-search-path} is currently implemented
2851 only on some platforms.
2852
2853 @kindex show libthread-db-search-path
2854 @item show libthread-db-search-path
2855 Display current libthread_db search path.
2856 @end table
2857
2858 @node Forks
2859 @section Debugging Forks
2860
2861 @cindex fork, debugging programs which call
2862 @cindex multiple processes
2863 @cindex processes, multiple
2864 On most systems, @value{GDBN} has no special support for debugging
2865 programs which create additional processes using the @code{fork}
2866 function. When a program forks, @value{GDBN} will continue to debug the
2867 parent process and the child process will run unimpeded. If you have
2868 set a breakpoint in any code which the child then executes, the child
2869 will get a @code{SIGTRAP} signal which (unless it catches the signal)
2870 will cause it to terminate.
2871
2872 However, if you want to debug the child process there is a workaround
2873 which isn't too painful. Put a call to @code{sleep} in the code which
2874 the child process executes after the fork. It may be useful to sleep
2875 only if a certain environment variable is set, or a certain file exists,
2876 so that the delay need not occur when you don't want to run @value{GDBN}
2877 on the child. While the child is sleeping, use the @code{ps} program to
2878 get its process ID. Then tell @value{GDBN} (a new invocation of
2879 @value{GDBN} if you are also debugging the parent process) to attach to
2880 the child process (@pxref{Attach}). From that point on you can debug
2881 the child process just like any other process which you attached to.
2882
2883 On some systems, @value{GDBN} provides support for debugging programs that
2884 create additional processes using the @code{fork} or @code{vfork} functions.
2885 Currently, the only platforms with this feature are HP-UX (11.x and later
2886 only?) and @sc{gnu}/Linux (kernel version 2.5.60 and later).
2887
2888 By default, when a program forks, @value{GDBN} will continue to debug
2889 the parent process and the child process will run unimpeded.
2890
2891 If you want to follow the child process instead of the parent process,
2892 use the command @w{@code{set follow-fork-mode}}.
2893
2894 @table @code
2895 @kindex set follow-fork-mode
2896 @item set follow-fork-mode @var{mode}
2897 Set the debugger response to a program call of @code{fork} or
2898 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2899 process. The @var{mode} argument can be:
2900
2901 @table @code
2902 @item parent
2903 The original process is debugged after a fork. The child process runs
2904 unimpeded. This is the default.
2905
2906 @item child
2907 The new process is debugged after a fork. The parent process runs
2908 unimpeded.
2909
2910 @end table
2911
2912 @kindex show follow-fork-mode
2913 @item show follow-fork-mode
2914 Display the current debugger response to a @code{fork} or @code{vfork} call.
2915 @end table
2916
2917 @cindex debugging multiple processes
2918 On Linux, if you want to debug both the parent and child processes, use the
2919 command @w{@code{set detach-on-fork}}.
2920
2921 @table @code
2922 @kindex set detach-on-fork
2923 @item set detach-on-fork @var{mode}
2924 Tells gdb whether to detach one of the processes after a fork, or
2925 retain debugger control over them both.
2926
2927 @table @code
2928 @item on
2929 The child process (or parent process, depending on the value of
2930 @code{follow-fork-mode}) will be detached and allowed to run
2931 independently. This is the default.
2932
2933 @item off
2934 Both processes will be held under the control of @value{GDBN}.
2935 One process (child or parent, depending on the value of
2936 @code{follow-fork-mode}) is debugged as usual, while the other
2937 is held suspended.
2938
2939 @end table
2940
2941 @kindex show detach-on-fork
2942 @item show detach-on-fork
2943 Show whether detach-on-fork mode is on/off.
2944 @end table
2945
2946 If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
2947 will retain control of all forked processes (including nested forks).
2948 You can list the forked processes under the control of @value{GDBN} by
2949 using the @w{@code{info inferiors}} command, and switch from one fork
2950 to another by using the @code{inferior} command (@pxref{Inferiors and
2951 Programs, ,Debugging Multiple Inferiors and Programs}).
2952
2953 To quit debugging one of the forked processes, you can either detach
2954 from it by using the @w{@code{detach inferior}} command (allowing it
2955 to run independently), or kill it using the @w{@code{kill inferior}}
2956 command. @xref{Inferiors and Programs, ,Debugging Multiple Inferiors
2957 and Programs}.
2958
2959 If you ask to debug a child process and a @code{vfork} is followed by an
2960 @code{exec}, @value{GDBN} executes the new target up to the first
2961 breakpoint in the new target. If you have a breakpoint set on
2962 @code{main} in your original program, the breakpoint will also be set on
2963 the child process's @code{main}.
2964
2965 On some systems, when a child process is spawned by @code{vfork}, you
2966 cannot debug the child or parent until an @code{exec} call completes.
2967
2968 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2969 call executes, the new target restarts. To restart the parent
2970 process, use the @code{file} command with the parent executable name
2971 as its argument. By default, after an @code{exec} call executes,
2972 @value{GDBN} discards the symbols of the previous executable image.
2973 You can change this behaviour with the @w{@code{set follow-exec-mode}}
2974 command.
2975
2976 @table @code
2977 @kindex set follow-exec-mode
2978 @item set follow-exec-mode @var{mode}
2979
2980 Set debugger response to a program call of @code{exec}. An
2981 @code{exec} call replaces the program image of a process.
2982
2983 @code{follow-exec-mode} can be:
2984
2985 @table @code
2986 @item new
2987 @value{GDBN} creates a new inferior and rebinds the process to this
2988 new inferior. The program the process was running before the
2989 @code{exec} call can be restarted afterwards by restarting the
2990 original inferior.
2991
2992 For example:
2993
2994 @smallexample
2995 (@value{GDBP}) info inferiors
2996 (gdb) info inferior
2997 Id Description Executable
2998 * 1 <null> prog1
2999 (@value{GDBP}) run
3000 process 12020 is executing new program: prog2
3001 Program exited normally.
3002 (@value{GDBP}) info inferiors
3003 Id Description Executable
3004 * 2 <null> prog2
3005 1 <null> prog1
3006 @end smallexample
3007
3008 @item same
3009 @value{GDBN} keeps the process bound to the same inferior. The new
3010 executable image replaces the previous executable loaded in the
3011 inferior. Restarting the inferior after the @code{exec} call, with
3012 e.g., the @code{run} command, restarts the executable the process was
3013 running after the @code{exec} call. This is the default mode.
3014
3015 For example:
3016
3017 @smallexample
3018 (@value{GDBP}) info inferiors
3019 Id Description Executable
3020 * 1 <null> prog1
3021 (@value{GDBP}) run
3022 process 12020 is executing new program: prog2
3023 Program exited normally.
3024 (@value{GDBP}) info inferiors
3025 Id Description Executable
3026 * 1 <null> prog2
3027 @end smallexample
3028
3029 @end table
3030 @end table
3031
3032 You can use the @code{catch} command to make @value{GDBN} stop whenever
3033 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
3034 Catchpoints, ,Setting Catchpoints}.
3035
3036 @node Checkpoint/Restart
3037 @section Setting a @emph{Bookmark} to Return to Later
3038
3039 @cindex checkpoint
3040 @cindex restart
3041 @cindex bookmark
3042 @cindex snapshot of a process
3043 @cindex rewind program state
3044
3045 On certain operating systems@footnote{Currently, only
3046 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3047 program's state, called a @dfn{checkpoint}, and come back to it
3048 later.
3049
3050 Returning to a checkpoint effectively undoes everything that has
3051 happened in the program since the @code{checkpoint} was saved. This
3052 includes changes in memory, registers, and even (within some limits)
3053 system state. Effectively, it is like going back in time to the
3054 moment when the checkpoint was saved.
3055
3056 Thus, if you're stepping thru a program and you think you're
3057 getting close to the point where things go wrong, you can save
3058 a checkpoint. Then, if you accidentally go too far and miss
3059 the critical statement, instead of having to restart your program
3060 from the beginning, you can just go back to the checkpoint and
3061 start again from there.
3062
3063 This can be especially useful if it takes a lot of time or
3064 steps to reach the point where you think the bug occurs.
3065
3066 To use the @code{checkpoint}/@code{restart} method of debugging:
3067
3068 @table @code
3069 @kindex checkpoint
3070 @item checkpoint
3071 Save a snapshot of the debugged program's current execution state.
3072 The @code{checkpoint} command takes no arguments, but each checkpoint
3073 is assigned a small integer id, similar to a breakpoint id.
3074
3075 @kindex info checkpoints
3076 @item info checkpoints
3077 List the checkpoints that have been saved in the current debugging
3078 session. For each checkpoint, the following information will be
3079 listed:
3080
3081 @table @code
3082 @item Checkpoint ID
3083 @item Process ID
3084 @item Code Address
3085 @item Source line, or label
3086 @end table
3087
3088 @kindex restart @var{checkpoint-id}
3089 @item restart @var{checkpoint-id}
3090 Restore the program state that was saved as checkpoint number
3091 @var{checkpoint-id}. All program variables, registers, stack frames
3092 etc.@: will be returned to the values that they had when the checkpoint
3093 was saved. In essence, gdb will ``wind back the clock'' to the point
3094 in time when the checkpoint was saved.
3095
3096 Note that breakpoints, @value{GDBN} variables, command history etc.
3097 are not affected by restoring a checkpoint. In general, a checkpoint
3098 only restores things that reside in the program being debugged, not in
3099 the debugger.
3100
3101 @kindex delete checkpoint @var{checkpoint-id}
3102 @item delete checkpoint @var{checkpoint-id}
3103 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3104
3105 @end table
3106
3107 Returning to a previously saved checkpoint will restore the user state
3108 of the program being debugged, plus a significant subset of the system
3109 (OS) state, including file pointers. It won't ``un-write'' data from
3110 a file, but it will rewind the file pointer to the previous location,
3111 so that the previously written data can be overwritten. For files
3112 opened in read mode, the pointer will also be restored so that the
3113 previously read data can be read again.
3114
3115 Of course, characters that have been sent to a printer (or other
3116 external device) cannot be ``snatched back'', and characters received
3117 from eg.@: a serial device can be removed from internal program buffers,
3118 but they cannot be ``pushed back'' into the serial pipeline, ready to
3119 be received again. Similarly, the actual contents of files that have
3120 been changed cannot be restored (at this time).
3121
3122 However, within those constraints, you actually can ``rewind'' your
3123 program to a previously saved point in time, and begin debugging it
3124 again --- and you can change the course of events so as to debug a
3125 different execution path this time.
3126
3127 @cindex checkpoints and process id
3128 Finally, there is one bit of internal program state that will be
3129 different when you return to a checkpoint --- the program's process
3130 id. Each checkpoint will have a unique process id (or @var{pid}),
3131 and each will be different from the program's original @var{pid}.
3132 If your program has saved a local copy of its process id, this could
3133 potentially pose a problem.
3134
3135 @subsection A Non-obvious Benefit of Using Checkpoints
3136
3137 On some systems such as @sc{gnu}/Linux, address space randomization
3138 is performed on new processes for security reasons. This makes it
3139 difficult or impossible to set a breakpoint, or watchpoint, on an
3140 absolute address if you have to restart the program, since the
3141 absolute location of a symbol will change from one execution to the
3142 next.
3143
3144 A checkpoint, however, is an @emph{identical} copy of a process.
3145 Therefore if you create a checkpoint at (eg.@:) the start of main,
3146 and simply return to that checkpoint instead of restarting the
3147 process, you can avoid the effects of address randomization and
3148 your symbols will all stay in the same place.
3149
3150 @node Stopping
3151 @chapter Stopping and Continuing
3152
3153 The principal purposes of using a debugger are so that you can stop your
3154 program before it terminates; or so that, if your program runs into
3155 trouble, you can investigate and find out why.
3156
3157 Inside @value{GDBN}, your program may stop for any of several reasons,
3158 such as a signal, a breakpoint, or reaching a new line after a
3159 @value{GDBN} command such as @code{step}. You may then examine and
3160 change variables, set new breakpoints or remove old ones, and then
3161 continue execution. Usually, the messages shown by @value{GDBN} provide
3162 ample explanation of the status of your program---but you can also
3163 explicitly request this information at any time.
3164
3165 @table @code
3166 @kindex info program
3167 @item info program
3168 Display information about the status of your program: whether it is
3169 running or not, what process it is, and why it stopped.
3170 @end table
3171
3172 @menu
3173 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
3174 * Continuing and Stepping:: Resuming execution
3175 * Signals:: Signals
3176 * Thread Stops:: Stopping and starting multi-thread programs
3177 @end menu
3178
3179 @node Breakpoints
3180 @section Breakpoints, Watchpoints, and Catchpoints
3181
3182 @cindex breakpoints
3183 A @dfn{breakpoint} makes your program stop whenever a certain point in
3184 the program is reached. For each breakpoint, you can add conditions to
3185 control in finer detail whether your program stops. You can set
3186 breakpoints with the @code{break} command and its variants (@pxref{Set
3187 Breaks, ,Setting Breakpoints}), to specify the place where your program
3188 should stop by line number, function name or exact address in the
3189 program.
3190
3191 On some systems, you can set breakpoints in shared libraries before
3192 the executable is run. There is a minor limitation on HP-UX systems:
3193 you must wait until the executable is run in order to set breakpoints
3194 in shared library routines that are not called directly by the program
3195 (for example, routines that are arguments in a @code{pthread_create}
3196 call).
3197
3198 @cindex watchpoints
3199 @cindex data breakpoints
3200 @cindex memory tracing
3201 @cindex breakpoint on memory address
3202 @cindex breakpoint on variable modification
3203 A @dfn{watchpoint} is a special breakpoint that stops your program
3204 when the value of an expression changes. The expression may be a value
3205 of a variable, or it could involve values of one or more variables
3206 combined by operators, such as @samp{a + b}. This is sometimes called
3207 @dfn{data breakpoints}. You must use a different command to set
3208 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
3209 from that, you can manage a watchpoint like any other breakpoint: you
3210 enable, disable, and delete both breakpoints and watchpoints using the
3211 same commands.
3212
3213 You can arrange to have values from your program displayed automatically
3214 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
3215 Automatic Display}.
3216
3217 @cindex catchpoints
3218 @cindex breakpoint on events
3219 A @dfn{catchpoint} is another special breakpoint that stops your program
3220 when a certain kind of event occurs, such as the throwing of a C@t{++}
3221 exception or the loading of a library. As with watchpoints, you use a
3222 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
3223 Catchpoints}), but aside from that, you can manage a catchpoint like any
3224 other breakpoint. (To stop when your program receives a signal, use the
3225 @code{handle} command; see @ref{Signals, ,Signals}.)
3226
3227 @cindex breakpoint numbers
3228 @cindex numbers for breakpoints
3229 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
3230 catchpoint when you create it; these numbers are successive integers
3231 starting with one. In many of the commands for controlling various
3232 features of breakpoints you use the breakpoint number to say which
3233 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
3234 @dfn{disabled}; if disabled, it has no effect on your program until you
3235 enable it again.
3236
3237 @cindex breakpoint ranges
3238 @cindex ranges of breakpoints
3239 Some @value{GDBN} commands accept a range of breakpoints on which to
3240 operate. A breakpoint range is either a single breakpoint number, like
3241 @samp{5}, or two such numbers, in increasing order, separated by a
3242 hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
3243 all breakpoints in that range are operated on.
3244
3245 @menu
3246 * Set Breaks:: Setting breakpoints
3247 * Set Watchpoints:: Setting watchpoints
3248 * Set Catchpoints:: Setting catchpoints
3249 * Delete Breaks:: Deleting breakpoints
3250 * Disabling:: Disabling breakpoints
3251 * Conditions:: Break conditions
3252 * Break Commands:: Breakpoint command lists
3253 * Save Breakpoints:: How to save breakpoints in a file
3254 * Error in Breakpoints:: ``Cannot insert breakpoints''
3255 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
3256 @end menu
3257
3258 @node Set Breaks
3259 @subsection Setting Breakpoints
3260
3261 @c FIXME LMB what does GDB do if no code on line of breakpt?
3262 @c consider in particular declaration with/without initialization.
3263 @c
3264 @c FIXME 2 is there stuff on this already? break at fun start, already init?
3265
3266 @kindex break
3267 @kindex b @r{(@code{break})}
3268 @vindex $bpnum@r{, convenience variable}
3269 @cindex latest breakpoint
3270 Breakpoints are set with the @code{break} command (abbreviated
3271 @code{b}). The debugger convenience variable @samp{$bpnum} records the
3272 number of the breakpoint you've set most recently; see @ref{Convenience
3273 Vars,, Convenience Variables}, for a discussion of what you can do with
3274 convenience variables.
3275
3276 @table @code
3277 @item break @var{location}
3278 Set a breakpoint at the given @var{location}, which can specify a
3279 function name, a line number, or an address of an instruction.
3280 (@xref{Specify Location}, for a list of all the possible ways to
3281 specify a @var{location}.) The breakpoint will stop your program just
3282 before it executes any of the code in the specified @var{location}.
3283
3284 When using source languages that permit overloading of symbols, such as
3285 C@t{++}, a function name may refer to more than one possible place to break.
3286 @xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
3287 that situation.
3288
3289 It is also possible to insert a breakpoint that will stop the program
3290 only if a specific thread (@pxref{Thread-Specific Breakpoints})
3291 or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
3292
3293 @item break
3294 When called without any arguments, @code{break} sets a breakpoint at
3295 the next instruction to be executed in the selected stack frame
3296 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
3297 innermost, this makes your program stop as soon as control
3298 returns to that frame. This is similar to the effect of a
3299 @code{finish} command in the frame inside the selected frame---except
3300 that @code{finish} does not leave an active breakpoint. If you use
3301 @code{break} without an argument in the innermost frame, @value{GDBN} stops
3302 the next time it reaches the current location; this may be useful
3303 inside loops.
3304
3305 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
3306 least one instruction has been executed. If it did not do this, you
3307 would be unable to proceed past a breakpoint without first disabling the
3308 breakpoint. This rule applies whether or not the breakpoint already
3309 existed when your program stopped.
3310
3311 @item break @dots{} if @var{cond}
3312 Set a breakpoint with condition @var{cond}; evaluate the expression
3313 @var{cond} each time the breakpoint is reached, and stop only if the
3314 value is nonzero---that is, if @var{cond} evaluates as true.
3315 @samp{@dots{}} stands for one of the possible arguments described
3316 above (or no argument) specifying where to break. @xref{Conditions,
3317 ,Break Conditions}, for more information on breakpoint conditions.
3318
3319 @kindex tbreak
3320 @item tbreak @var{args}
3321 Set a breakpoint enabled only for one stop. @var{args} are the
3322 same as for the @code{break} command, and the breakpoint is set in the same
3323 way, but the breakpoint is automatically deleted after the first time your
3324 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
3325
3326 @kindex hbreak
3327 @cindex hardware breakpoints
3328 @item hbreak @var{args}
3329 Set a hardware-assisted breakpoint. @var{args} are the same as for the
3330 @code{break} command and the breakpoint is set in the same way, but the
3331 breakpoint requires hardware support and some target hardware may not
3332 have this support. The main purpose of this is EPROM/ROM code
3333 debugging, so you can set a breakpoint at an instruction without
3334 changing the instruction. This can be used with the new trap-generation
3335 provided by SPARClite DSU and most x86-based targets. These targets
3336 will generate traps when a program accesses some data or instruction
3337 address that is assigned to the debug registers. However the hardware
3338 breakpoint registers can take a limited number of breakpoints. For
3339 example, on the DSU, only two data breakpoints can be set at a time, and
3340 @value{GDBN} will reject this command if more than two are used. Delete
3341 or disable unused hardware breakpoints before setting new ones
3342 (@pxref{Disabling, ,Disabling Breakpoints}).
3343 @xref{Conditions, ,Break Conditions}.
3344 For remote targets, you can restrict the number of hardware
3345 breakpoints @value{GDBN} will use, see @ref{set remote
3346 hardware-breakpoint-limit}.
3347
3348 @kindex thbreak
3349 @item thbreak @var{args}
3350 Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
3351 are the same as for the @code{hbreak} command and the breakpoint is set in
3352 the same way. However, like the @code{tbreak} command,
3353 the breakpoint is automatically deleted after the
3354 first time your program stops there. Also, like the @code{hbreak}
3355 command, the breakpoint requires hardware support and some target hardware
3356 may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
3357 See also @ref{Conditions, ,Break Conditions}.
3358
3359 @kindex rbreak
3360 @cindex regular expression
3361 @cindex breakpoints at functions matching a regexp
3362 @cindex set breakpoints in many functions
3363 @item rbreak @var{regex}
3364 Set breakpoints on all functions matching the regular expression
3365 @var{regex}. This command sets an unconditional breakpoint on all
3366 matches, printing a list of all breakpoints it set. Once these
3367 breakpoints are set, they are treated just like the breakpoints set with
3368 the @code{break} command. You can delete them, disable them, or make
3369 them conditional the same way as any other breakpoint.
3370
3371 The syntax of the regular expression is the standard one used with tools
3372 like @file{grep}. Note that this is different from the syntax used by
3373 shells, so for instance @code{foo*} matches all functions that include
3374 an @code{fo} followed by zero or more @code{o}s. There is an implicit
3375 @code{.*} leading and trailing the regular expression you supply, so to
3376 match only functions that begin with @code{foo}, use @code{^foo}.
3377
3378 @cindex non-member C@t{++} functions, set breakpoint in
3379 When debugging C@t{++} programs, @code{rbreak} is useful for setting
3380 breakpoints on overloaded functions that are not members of any special
3381 classes.
3382
3383 @cindex set breakpoints on all functions
3384 The @code{rbreak} command can be used to set breakpoints in
3385 @strong{all} the functions in a program, like this:
3386
3387 @smallexample
3388 (@value{GDBP}) rbreak .
3389 @end smallexample
3390
3391 @item rbreak @var{file}:@var{regex}
3392 If @code{rbreak} is called with a filename qualification, it limits
3393 the search for functions matching the given regular expression to the
3394 specified @var{file}. This can be used, for example, to set breakpoints on
3395 every function in a given file:
3396
3397 @smallexample
3398 (@value{GDBP}) rbreak file.c:.
3399 @end smallexample
3400
3401 The colon separating the filename qualifier from the regex may
3402 optionally be surrounded by spaces.
3403
3404 @kindex info breakpoints
3405 @cindex @code{$_} and @code{info breakpoints}
3406 @item info breakpoints @r{[}@var{n}@r{]}
3407 @itemx info break @r{[}@var{n}@r{]}
3408 Print a table of all breakpoints, watchpoints, and catchpoints set and
3409 not deleted. Optional argument @var{n} means print information only
3410 about the specified breakpoint (or watchpoint or catchpoint). For
3411 each breakpoint, following columns are printed:
3412
3413 @table @emph
3414 @item Breakpoint Numbers
3415 @item Type
3416 Breakpoint, watchpoint, or catchpoint.
3417 @item Disposition
3418 Whether the breakpoint is marked to be disabled or deleted when hit.
3419 @item Enabled or Disabled
3420 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
3421 that are not enabled.
3422 @item Address
3423 Where the breakpoint is in your program, as a memory address. For a
3424 pending breakpoint whose address is not yet known, this field will
3425 contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
3426 library that has the symbol or line referred by breakpoint is loaded.
3427 See below for details. A breakpoint with several locations will
3428 have @samp{<MULTIPLE>} in this field---see below for details.
3429 @item What
3430 Where the breakpoint is in the source for your program, as a file and
3431 line number. For a pending breakpoint, the original string passed to
3432 the breakpoint command will be listed as it cannot be resolved until
3433 the appropriate shared library is loaded in the future.
3434 @end table
3435
3436 @noindent
3437 If a breakpoint is conditional, @code{info break} shows the condition on
3438 the line following the affected breakpoint; breakpoint commands, if any,
3439 are listed after that. A pending breakpoint is allowed to have a condition
3440 specified for it. The condition is not parsed for validity until a shared
3441 library is loaded that allows the pending breakpoint to resolve to a
3442 valid location.
3443
3444 @noindent
3445 @code{info break} with a breakpoint
3446 number @var{n} as argument lists only that breakpoint. The
3447 convenience variable @code{$_} and the default examining-address for
3448 the @code{x} command are set to the address of the last breakpoint
3449 listed (@pxref{Memory, ,Examining Memory}).
3450
3451 @noindent
3452 @code{info break} displays a count of the number of times the breakpoint
3453 has been hit. This is especially useful in conjunction with the
3454 @code{ignore} command. You can ignore a large number of breakpoint
3455 hits, look at the breakpoint info to see how many times the breakpoint
3456 was hit, and then run again, ignoring one less than that number. This
3457 will get you quickly to the last hit of that breakpoint.
3458 @end table
3459
3460 @value{GDBN} allows you to set any number of breakpoints at the same place in
3461 your program. There is nothing silly or meaningless about this. When
3462 the breakpoints are conditional, this is even useful
3463 (@pxref{Conditions, ,Break Conditions}).
3464
3465 @cindex multiple locations, breakpoints
3466 @cindex breakpoints, multiple locations
3467 It is possible that a breakpoint corresponds to several locations
3468 in your program. Examples of this situation are:
3469
3470 @itemize @bullet
3471 @item
3472 For a C@t{++} constructor, the @value{NGCC} compiler generates several
3473 instances of the function body, used in different cases.
3474
3475 @item
3476 For a C@t{++} template function, a given line in the function can
3477 correspond to any number of instantiations.
3478
3479 @item
3480 For an inlined function, a given source line can correspond to
3481 several places where that function is inlined.
3482 @end itemize
3483
3484 In all those cases, @value{GDBN} will insert a breakpoint at all
3485 the relevant locations@footnote{
3486 As of this writing, multiple-location breakpoints work only if there's
3487 line number information for all the locations. This means that they
3488 will generally not work in system libraries, unless you have debug
3489 info with line numbers for them.}.
3490
3491 A breakpoint with multiple locations is displayed in the breakpoint
3492 table using several rows---one header row, followed by one row for
3493 each breakpoint location. The header row has @samp{<MULTIPLE>} in the
3494 address column. The rows for individual locations contain the actual
3495 addresses for locations, and show the functions to which those
3496 locations belong. The number column for a location is of the form
3497 @var{breakpoint-number}.@var{location-number}.
3498
3499 For example:
3500
3501 @smallexample
3502 Num Type Disp Enb Address What
3503 1 breakpoint keep y <MULTIPLE>
3504 stop only if i==1
3505 breakpoint already hit 1 time
3506 1.1 y 0x080486a2 in void foo<int>() at t.cc:8
3507 1.2 y 0x080486ca in void foo<double>() at t.cc:8
3508 @end smallexample
3509
3510 Each location can be individually enabled or disabled by passing
3511 @var{breakpoint-number}.@var{location-number} as argument to the
3512 @code{enable} and @code{disable} commands. Note that you cannot
3513 delete the individual locations from the list, you can only delete the
3514 entire list of locations that belong to their parent breakpoint (with
3515 the @kbd{delete @var{num}} command, where @var{num} is the number of
3516 the parent breakpoint, 1 in the above example). Disabling or enabling
3517 the parent breakpoint (@pxref{Disabling}) affects all of the locations
3518 that belong to that breakpoint.
3519
3520 @cindex pending breakpoints
3521 It's quite common to have a breakpoint inside a shared library.
3522 Shared libraries can be loaded and unloaded explicitly,
3523 and possibly repeatedly, as the program is executed. To support
3524 this use case, @value{GDBN} updates breakpoint locations whenever
3525 any shared library is loaded or unloaded. Typically, you would
3526 set a breakpoint in a shared library at the beginning of your
3527 debugging session, when the library is not loaded, and when the
3528 symbols from the library are not available. When you try to set
3529 breakpoint, @value{GDBN} will ask you if you want to set
3530 a so called @dfn{pending breakpoint}---breakpoint whose address
3531 is not yet resolved.
3532
3533 After the program is run, whenever a new shared library is loaded,
3534 @value{GDBN} reevaluates all the breakpoints. When a newly loaded
3535 shared library contains the symbol or line referred to by some
3536 pending breakpoint, that breakpoint is resolved and becomes an
3537 ordinary breakpoint. When a library is unloaded, all breakpoints
3538 that refer to its symbols or source lines become pending again.
3539
3540 This logic works for breakpoints with multiple locations, too. For
3541 example, if you have a breakpoint in a C@t{++} template function, and
3542 a newly loaded shared library has an instantiation of that template,
3543 a new location is added to the list of locations for the breakpoint.
3544
3545 Except for having unresolved address, pending breakpoints do not
3546 differ from regular breakpoints. You can set conditions or commands,
3547 enable and disable them and perform other breakpoint operations.
3548
3549 @value{GDBN} provides some additional commands for controlling what
3550 happens when the @samp{break} command cannot resolve breakpoint
3551 address specification to an address:
3552
3553 @kindex set breakpoint pending
3554 @kindex show breakpoint pending
3555 @table @code
3556 @item set breakpoint pending auto
3557 This is the default behavior. When @value{GDBN} cannot find the breakpoint
3558 location, it queries you whether a pending breakpoint should be created.
3559
3560 @item set breakpoint pending on
3561 This indicates that an unrecognized breakpoint location should automatically
3562 result in a pending breakpoint being created.
3563
3564 @item set breakpoint pending off
3565 This indicates that pending breakpoints are not to be created. Any
3566 unrecognized breakpoint location results in an error. This setting does
3567 not affect any pending breakpoints previously created.
3568
3569 @item show breakpoint pending
3570 Show the current behavior setting for creating pending breakpoints.
3571 @end table
3572
3573 The settings above only affect the @code{break} command and its
3574 variants. Once breakpoint is set, it will be automatically updated
3575 as shared libraries are loaded and unloaded.
3576
3577 @cindex automatic hardware breakpoints
3578 For some targets, @value{GDBN} can automatically decide if hardware or
3579 software breakpoints should be used, depending on whether the
3580 breakpoint address is read-only or read-write. This applies to
3581 breakpoints set with the @code{break} command as well as to internal
3582 breakpoints set by commands like @code{next} and @code{finish}. For
3583 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
3584 breakpoints.
3585
3586 You can control this automatic behaviour with the following commands::
3587
3588 @kindex set breakpoint auto-hw
3589 @kindex show breakpoint auto-hw
3590 @table @code
3591 @item set breakpoint auto-hw on
3592 This is the default behavior. When @value{GDBN} sets a breakpoint, it
3593 will try to use the target memory map to decide if software or hardware
3594 breakpoint must be used.
3595
3596 @item set breakpoint auto-hw off
3597 This indicates @value{GDBN} should not automatically select breakpoint
3598 type. If the target provides a memory map, @value{GDBN} will warn when
3599 trying to set software breakpoint at a read-only address.
3600 @end table
3601
3602 @value{GDBN} normally implements breakpoints by replacing the program code
3603 at the breakpoint address with a special instruction, which, when
3604 executed, given control to the debugger. By default, the program
3605 code is so modified only when the program is resumed. As soon as
3606 the program stops, @value{GDBN} restores the original instructions. This
3607 behaviour guards against leaving breakpoints inserted in the
3608 target should gdb abrubptly disconnect. However, with slow remote
3609 targets, inserting and removing breakpoint can reduce the performance.
3610 This behavior can be controlled with the following commands::
3611
3612 @kindex set breakpoint always-inserted
3613 @kindex show breakpoint always-inserted
3614 @table @code
3615 @item set breakpoint always-inserted off
3616 All breakpoints, including newly added by the user, are inserted in
3617 the target only when the target is resumed. All breakpoints are
3618 removed from the target when it stops.
3619
3620 @item set breakpoint always-inserted on
3621 Causes all breakpoints to be inserted in the target at all times. If
3622 the user adds a new breakpoint, or changes an existing breakpoint, the
3623 breakpoints in the target are updated immediately. A breakpoint is
3624 removed from the target only when breakpoint itself is removed.
3625
3626 @cindex non-stop mode, and @code{breakpoint always-inserted}
3627 @item set breakpoint always-inserted auto
3628 This is the default mode. If @value{GDBN} is controlling the inferior
3629 in non-stop mode (@pxref{Non-Stop Mode}), gdb behaves as if
3630 @code{breakpoint always-inserted} mode is on. If @value{GDBN} is
3631 controlling the inferior in all-stop mode, @value{GDBN} behaves as if
3632 @code{breakpoint always-inserted} mode is off.
3633 @end table
3634
3635 @cindex negative breakpoint numbers
3636 @cindex internal @value{GDBN} breakpoints
3637 @value{GDBN} itself sometimes sets breakpoints in your program for
3638 special purposes, such as proper handling of @code{longjmp} (in C
3639 programs). These internal breakpoints are assigned negative numbers,
3640 starting with @code{-1}; @samp{info breakpoints} does not display them.
3641 You can see these breakpoints with the @value{GDBN} maintenance command
3642 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
3643
3644
3645 @node Set Watchpoints
3646 @subsection Setting Watchpoints
3647
3648 @cindex setting watchpoints
3649 You can use a watchpoint to stop execution whenever the value of an
3650 expression changes, without having to predict a particular place where
3651 this may happen. (This is sometimes called a @dfn{data breakpoint}.)
3652 The expression may be as simple as the value of a single variable, or
3653 as complex as many variables combined by operators. Examples include:
3654
3655 @itemize @bullet
3656 @item
3657 A reference to the value of a single variable.
3658
3659 @item
3660 An address cast to an appropriate data type. For example,
3661 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3662 address (assuming an @code{int} occupies 4 bytes).
3663
3664 @item
3665 An arbitrarily complex expression, such as @samp{a*b + c/d}. The
3666 expression can use any operators valid in the program's native
3667 language (@pxref{Languages}).
3668 @end itemize
3669
3670 You can set a watchpoint on an expression even if the expression can
3671 not be evaluated yet. For instance, you can set a watchpoint on
3672 @samp{*global_ptr} before @samp{global_ptr} is initialized.
3673 @value{GDBN} will stop when your program sets @samp{global_ptr} and
3674 the expression produces a valid value. If the expression becomes
3675 valid in some other way than changing a variable (e.g.@: if the memory
3676 pointed to by @samp{*global_ptr} becomes readable as the result of a
3677 @code{malloc} call), @value{GDBN} may not stop until the next time
3678 the expression changes.
3679
3680 @cindex software watchpoints
3681 @cindex hardware watchpoints
3682 Depending on your system, watchpoints may be implemented in software or
3683 hardware. @value{GDBN} does software watchpointing by single-stepping your
3684 program and testing the variable's value each time, which is hundreds of
3685 times slower than normal execution. (But this may still be worth it, to
3686 catch errors where you have no clue what part of your program is the
3687 culprit.)
3688
3689 On some systems, such as HP-UX, PowerPC, @sc{gnu}/Linux and most other
3690 x86-based targets, @value{GDBN} includes support for hardware
3691 watchpoints, which do not slow down the running of your program.
3692
3693 @table @code
3694 @kindex watch
3695 @item watch @var{expr} @r{[}thread @var{threadnum}@r{]}
3696 Set a watchpoint for an expression. @value{GDBN} will break when the
3697 expression @var{expr} is written into by the program and its value
3698 changes. The simplest (and the most popular) use of this command is
3699 to watch the value of a single variable:
3700
3701 @smallexample
3702 (@value{GDBP}) watch foo
3703 @end smallexample
3704
3705 If the command includes a @code{@r{[}thread @var{threadnum}@r{]}}
3706 clause, @value{GDBN} breaks only when the thread identified by
3707 @var{threadnum} changes the value of @var{expr}. If any other threads
3708 change the value of @var{expr}, @value{GDBN} will not break. Note
3709 that watchpoints restricted to a single thread in this way only work
3710 with Hardware Watchpoints.
3711
3712 @kindex rwatch
3713 @item rwatch @var{expr} @r{[}thread @var{threadnum}@r{]}
3714 Set a watchpoint that will break when the value of @var{expr} is read
3715 by the program.
3716
3717 @kindex awatch
3718 @item awatch @var{expr} @r{[}thread @var{threadnum}@r{]}
3719 Set a watchpoint that will break when @var{expr} is either read from
3720 or written into by the program.
3721
3722 @kindex info watchpoints @r{[}@var{n}@r{]}
3723 @item info watchpoints
3724 This command prints a list of watchpoints, using the same format as
3725 @code{info break} (@pxref{Set Breaks}).
3726 @end table
3727
3728 If you watch for a change in a numerically entered address you need to
3729 dereference it, as the address itself is just a constant number which will
3730 never change. @value{GDBN} refuses to create a watchpoint that watches
3731 a never-changing value:
3732
3733 @smallexample
3734 (@value{GDBP}) watch 0x600850
3735 Cannot watch constant value 0x600850.
3736 (@value{GDBP}) watch *(int *) 0x600850
3737 Watchpoint 1: *(int *) 6293584
3738 @end smallexample
3739
3740 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3741 watchpoints execute very quickly, and the debugger reports a change in
3742 value at the exact instruction where the change occurs. If @value{GDBN}
3743 cannot set a hardware watchpoint, it sets a software watchpoint, which
3744 executes more slowly and reports the change in value at the next
3745 @emph{statement}, not the instruction, after the change occurs.
3746
3747 @cindex use only software watchpoints
3748 You can force @value{GDBN} to use only software watchpoints with the
3749 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3750 zero, @value{GDBN} will never try to use hardware watchpoints, even if
3751 the underlying system supports them. (Note that hardware-assisted
3752 watchpoints that were set @emph{before} setting
3753 @code{can-use-hw-watchpoints} to zero will still use the hardware
3754 mechanism of watching expression values.)
3755
3756 @table @code
3757 @item set can-use-hw-watchpoints
3758 @kindex set can-use-hw-watchpoints
3759 Set whether or not to use hardware watchpoints.
3760
3761 @item show can-use-hw-watchpoints
3762 @kindex show can-use-hw-watchpoints
3763 Show the current mode of using hardware watchpoints.
3764 @end table
3765
3766 For remote targets, you can restrict the number of hardware
3767 watchpoints @value{GDBN} will use, see @ref{set remote
3768 hardware-breakpoint-limit}.
3769
3770 When you issue the @code{watch} command, @value{GDBN} reports
3771
3772 @smallexample
3773 Hardware watchpoint @var{num}: @var{expr}
3774 @end smallexample
3775
3776 @noindent
3777 if it was able to set a hardware watchpoint.
3778
3779 Currently, the @code{awatch} and @code{rwatch} commands can only set
3780 hardware watchpoints, because accesses to data that don't change the
3781 value of the watched expression cannot be detected without examining
3782 every instruction as it is being executed, and @value{GDBN} does not do
3783 that currently. If @value{GDBN} finds that it is unable to set a
3784 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3785 will print a message like this:
3786
3787 @smallexample
3788 Expression cannot be implemented with read/access watchpoint.
3789 @end smallexample
3790
3791 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3792 data type of the watched expression is wider than what a hardware
3793 watchpoint on the target machine can handle. For example, some systems
3794 can only watch regions that are up to 4 bytes wide; on such systems you
3795 cannot set hardware watchpoints for an expression that yields a
3796 double-precision floating-point number (which is typically 8 bytes
3797 wide). As a work-around, it might be possible to break the large region
3798 into a series of smaller ones and watch them with separate watchpoints.
3799
3800 If you set too many hardware watchpoints, @value{GDBN} might be unable
3801 to insert all of them when you resume the execution of your program.
3802 Since the precise number of active watchpoints is unknown until such
3803 time as the program is about to be resumed, @value{GDBN} might not be
3804 able to warn you about this when you set the watchpoints, and the
3805 warning will be printed only when the program is resumed:
3806
3807 @smallexample
3808 Hardware watchpoint @var{num}: Could not insert watchpoint
3809 @end smallexample
3810
3811 @noindent
3812 If this happens, delete or disable some of the watchpoints.
3813
3814 Watching complex expressions that reference many variables can also
3815 exhaust the resources available for hardware-assisted watchpoints.
3816 That's because @value{GDBN} needs to watch every variable in the
3817 expression with separately allocated resources.
3818
3819 If you call a function interactively using @code{print} or @code{call},
3820 any watchpoints you have set will be inactive until @value{GDBN} reaches another
3821 kind of breakpoint or the call completes.
3822
3823 @value{GDBN} automatically deletes watchpoints that watch local
3824 (automatic) variables, or expressions that involve such variables, when
3825 they go out of scope, that is, when the execution leaves the block in
3826 which these variables were defined. In particular, when the program
3827 being debugged terminates, @emph{all} local variables go out of scope,
3828 and so only watchpoints that watch global variables remain set. If you
3829 rerun the program, you will need to set all such watchpoints again. One
3830 way of doing that would be to set a code breakpoint at the entry to the
3831 @code{main} function and when it breaks, set all the watchpoints.
3832
3833 @cindex watchpoints and threads
3834 @cindex threads and watchpoints
3835 In multi-threaded programs, watchpoints will detect changes to the
3836 watched expression from every thread.
3837
3838 @quotation
3839 @emph{Warning:} In multi-threaded programs, software watchpoints
3840 have only limited usefulness. If @value{GDBN} creates a software
3841 watchpoint, it can only watch the value of an expression @emph{in a
3842 single thread}. If you are confident that the expression can only
3843 change due to the current thread's activity (and if you are also
3844 confident that no other thread can become current), then you can use
3845 software watchpoints as usual. However, @value{GDBN} may not notice
3846 when a non-current thread's activity changes the expression. (Hardware
3847 watchpoints, in contrast, watch an expression in all threads.)
3848 @end quotation
3849
3850 @xref{set remote hardware-watchpoint-limit}.
3851
3852 @node Set Catchpoints
3853 @subsection Setting Catchpoints
3854 @cindex catchpoints, setting
3855 @cindex exception handlers
3856 @cindex event handling
3857
3858 You can use @dfn{catchpoints} to cause the debugger to stop for certain
3859 kinds of program events, such as C@t{++} exceptions or the loading of a
3860 shared library. Use the @code{catch} command to set a catchpoint.
3861
3862 @table @code
3863 @kindex catch
3864 @item catch @var{event}
3865 Stop when @var{event} occurs. @var{event} can be any of the following:
3866 @table @code
3867 @item throw
3868 @cindex stop on C@t{++} exceptions
3869 The throwing of a C@t{++} exception.
3870
3871 @item catch
3872 The catching of a C@t{++} exception.
3873
3874 @item exception
3875 @cindex Ada exception catching
3876 @cindex catch Ada exceptions
3877 An Ada exception being raised. If an exception name is specified
3878 at the end of the command (eg @code{catch exception Program_Error}),
3879 the debugger will stop only when this specific exception is raised.
3880 Otherwise, the debugger stops execution when any Ada exception is raised.
3881
3882 When inserting an exception catchpoint on a user-defined exception whose
3883 name is identical to one of the exceptions defined by the language, the
3884 fully qualified name must be used as the exception name. Otherwise,
3885 @value{GDBN} will assume that it should stop on the pre-defined exception
3886 rather than the user-defined one. For instance, assuming an exception
3887 called @code{Constraint_Error} is defined in package @code{Pck}, then
3888 the command to use to catch such exceptions is @kbd{catch exception
3889 Pck.Constraint_Error}.
3890
3891 @item exception unhandled
3892 An exception that was raised but is not handled by the program.
3893
3894 @item assert
3895 A failed Ada assertion.
3896
3897 @item exec
3898 @cindex break on fork/exec
3899 A call to @code{exec}. This is currently only available for HP-UX
3900 and @sc{gnu}/Linux.
3901
3902 @item syscall
3903 @itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{}
3904 @cindex break on a system call.
3905 A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
3906 syscall is a mechanism for application programs to request a service
3907 from the operating system (OS) or one of the OS system services.
3908 @value{GDBN} can catch some or all of the syscalls issued by the
3909 debuggee, and show the related information for each syscall. If no
3910 argument is specified, calls to and returns from all system calls
3911 will be caught.
3912
3913 @var{name} can be any system call name that is valid for the
3914 underlying OS. Just what syscalls are valid depends on the OS. On
3915 GNU and Unix systems, you can find the full list of valid syscall
3916 names on @file{/usr/include/asm/unistd.h}.
3917
3918 @c For MS-Windows, the syscall names and the corresponding numbers
3919 @c can be found, e.g., on this URL:
3920 @c http://www.metasploit.com/users/opcode/syscalls.html
3921 @c but we don't support Windows syscalls yet.
3922
3923 Normally, @value{GDBN} knows in advance which syscalls are valid for
3924 each OS, so you can use the @value{GDBN} command-line completion
3925 facilities (@pxref{Completion,, command completion}) to list the
3926 available choices.
3927
3928 You may also specify the system call numerically. A syscall's
3929 number is the value passed to the OS's syscall dispatcher to
3930 identify the requested service. When you specify the syscall by its
3931 name, @value{GDBN} uses its database of syscalls to convert the name
3932 into the corresponding numeric code, but using the number directly
3933 may be useful if @value{GDBN}'s database does not have the complete
3934 list of syscalls on your system (e.g., because @value{GDBN} lags
3935 behind the OS upgrades).
3936
3937 The example below illustrates how this command works if you don't provide
3938 arguments to it:
3939
3940 @smallexample
3941 (@value{GDBP}) catch syscall
3942 Catchpoint 1 (syscall)
3943 (@value{GDBP}) r
3944 Starting program: /tmp/catch-syscall
3945
3946 Catchpoint 1 (call to syscall 'close'), \
3947 0xffffe424 in __kernel_vsyscall ()
3948 (@value{GDBP}) c
3949 Continuing.
3950
3951 Catchpoint 1 (returned from syscall 'close'), \
3952 0xffffe424 in __kernel_vsyscall ()
3953 (@value{GDBP})
3954 @end smallexample
3955
3956 Here is an example of catching a system call by name:
3957
3958 @smallexample
3959 (@value{GDBP}) catch syscall chroot
3960 Catchpoint 1 (syscall 'chroot' [61])
3961 (@value{GDBP}) r
3962 Starting program: /tmp/catch-syscall
3963
3964 Catchpoint 1 (call to syscall 'chroot'), \
3965 0xffffe424 in __kernel_vsyscall ()
3966 (@value{GDBP}) c
3967 Continuing.
3968
3969 Catchpoint 1 (returned from syscall 'chroot'), \
3970 0xffffe424 in __kernel_vsyscall ()
3971 (@value{GDBP})
3972 @end smallexample
3973
3974 An example of specifying a system call numerically. In the case
3975 below, the syscall number has a corresponding entry in the XML
3976 file, so @value{GDBN} finds its name and prints it:
3977
3978 @smallexample
3979 (@value{GDBP}) catch syscall 252
3980 Catchpoint 1 (syscall(s) 'exit_group')
3981 (@value{GDBP}) r
3982 Starting program: /tmp/catch-syscall
3983
3984 Catchpoint 1 (call to syscall 'exit_group'), \
3985 0xffffe424 in __kernel_vsyscall ()
3986 (@value{GDBP}) c
3987 Continuing.
3988
3989 Program exited normally.
3990 (@value{GDBP})
3991 @end smallexample
3992
3993 However, there can be situations when there is no corresponding name
3994 in XML file for that syscall number. In this case, @value{GDBN} prints
3995 a warning message saying that it was not able to find the syscall name,
3996 but the catchpoint will be set anyway. See the example below:
3997
3998 @smallexample
3999 (@value{GDBP}) catch syscall 764
4000 warning: The number '764' does not represent a known syscall.
4001 Catchpoint 2 (syscall 764)
4002 (@value{GDBP})
4003 @end smallexample
4004
4005 If you configure @value{GDBN} using the @samp{--without-expat} option,
4006 it will not be able to display syscall names. Also, if your
4007 architecture does not have an XML file describing its system calls,
4008 you will not be able to see the syscall names. It is important to
4009 notice that these two features are used for accessing the syscall
4010 name database. In either case, you will see a warning like this:
4011
4012 @smallexample
4013 (@value{GDBP}) catch syscall
4014 warning: Could not open "syscalls/i386-linux.xml"
4015 warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
4016 GDB will not be able to display syscall names.
4017 Catchpoint 1 (syscall)
4018 (@value{GDBP})
4019 @end smallexample
4020
4021 Of course, the file name will change depending on your architecture and system.
4022
4023 Still using the example above, you can also try to catch a syscall by its
4024 number. In this case, you would see something like:
4025
4026 @smallexample
4027 (@value{GDBP}) catch syscall 252
4028 Catchpoint 1 (syscall(s) 252)
4029 @end smallexample
4030
4031 Again, in this case @value{GDBN} would not be able to display syscall's names.
4032
4033 @item fork
4034 A call to @code{fork}. This is currently only available for HP-UX
4035 and @sc{gnu}/Linux.
4036
4037 @item vfork
4038 A call to @code{vfork}. This is currently only available for HP-UX
4039 and @sc{gnu}/Linux.
4040
4041 @end table
4042
4043 @item tcatch @var{event}
4044 Set a catchpoint that is enabled only for one stop. The catchpoint is
4045 automatically deleted after the first time the event is caught.
4046
4047 @end table
4048
4049 Use the @code{info break} command to list the current catchpoints.
4050
4051 There are currently some limitations to C@t{++} exception handling
4052 (@code{catch throw} and @code{catch catch}) in @value{GDBN}:
4053
4054 @itemize @bullet
4055 @item
4056 If you call a function interactively, @value{GDBN} normally returns
4057 control to you when the function has finished executing. If the call
4058 raises an exception, however, the call may bypass the mechanism that
4059 returns control to you and cause your program either to abort or to
4060 simply continue running until it hits a breakpoint, catches a signal
4061 that @value{GDBN} is listening for, or exits. This is the case even if
4062 you set a catchpoint for the exception; catchpoints on exceptions are
4063 disabled within interactive calls.
4064
4065 @item
4066 You cannot raise an exception interactively.
4067
4068 @item
4069 You cannot install an exception handler interactively.
4070 @end itemize
4071
4072 @cindex raise exceptions
4073 Sometimes @code{catch} is not the best way to debug exception handling:
4074 if you need to know exactly where an exception is raised, it is better to
4075 stop @emph{before} the exception handler is called, since that way you
4076 can see the stack before any unwinding takes place. If you set a
4077 breakpoint in an exception handler instead, it may not be easy to find
4078 out where the exception was raised.
4079
4080 To stop just before an exception handler is called, you need some
4081 knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
4082 raised by calling a library function named @code{__raise_exception}
4083 which has the following ANSI C interface:
4084
4085 @smallexample
4086 /* @var{addr} is where the exception identifier is stored.
4087 @var{id} is the exception identifier. */
4088 void __raise_exception (void **addr, void *id);
4089 @end smallexample
4090
4091 @noindent
4092 To make the debugger catch all exceptions before any stack
4093 unwinding takes place, set a breakpoint on @code{__raise_exception}
4094 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Exceptions}).
4095
4096 With a conditional breakpoint (@pxref{Conditions, ,Break Conditions})
4097 that depends on the value of @var{id}, you can stop your program when
4098 a specific exception is raised. You can use multiple conditional
4099 breakpoints to stop your program when any of a number of exceptions are
4100 raised.
4101
4102
4103 @node Delete Breaks
4104 @subsection Deleting Breakpoints
4105
4106 @cindex clearing breakpoints, watchpoints, catchpoints
4107 @cindex deleting breakpoints, watchpoints, catchpoints
4108 It is often necessary to eliminate a breakpoint, watchpoint, or
4109 catchpoint once it has done its job and you no longer want your program
4110 to stop there. This is called @dfn{deleting} the breakpoint. A
4111 breakpoint that has been deleted no longer exists; it is forgotten.
4112
4113 With the @code{clear} command you can delete breakpoints according to
4114 where they are in your program. With the @code{delete} command you can
4115 delete individual breakpoints, watchpoints, or catchpoints by specifying
4116 their breakpoint numbers.
4117
4118 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
4119 automatically ignores breakpoints on the first instruction to be executed
4120 when you continue execution without changing the execution address.
4121
4122 @table @code
4123 @kindex clear
4124 @item clear
4125 Delete any breakpoints at the next instruction to be executed in the
4126 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
4127 the innermost frame is selected, this is a good way to delete a
4128 breakpoint where your program just stopped.
4129
4130 @item clear @var{location}
4131 Delete any breakpoints set at the specified @var{location}.
4132 @xref{Specify Location}, for the various forms of @var{location}; the
4133 most useful ones are listed below:
4134
4135 @table @code
4136 @item clear @var{function}
4137 @itemx clear @var{filename}:@var{function}
4138 Delete any breakpoints set at entry to the named @var{function}.
4139
4140 @item clear @var{linenum}
4141 @itemx clear @var{filename}:@var{linenum}
4142 Delete any breakpoints set at or within the code of the specified
4143 @var{linenum} of the specified @var{filename}.
4144 @end table
4145
4146 @cindex delete breakpoints
4147 @kindex delete
4148 @kindex d @r{(@code{delete})}
4149 @item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4150 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
4151 ranges specified as arguments. If no argument is specified, delete all
4152 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
4153 confirm off}). You can abbreviate this command as @code{d}.
4154 @end table
4155
4156 @node Disabling
4157 @subsection Disabling Breakpoints
4158
4159 @cindex enable/disable a breakpoint
4160 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
4161 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
4162 it had been deleted, but remembers the information on the breakpoint so
4163 that you can @dfn{enable} it again later.
4164
4165 You disable and enable breakpoints, watchpoints, and catchpoints with
4166 the @code{enable} and @code{disable} commands, optionally specifying
4167 one or more breakpoint numbers as arguments. Use @code{info break} to
4168 print a list of all breakpoints, watchpoints, and catchpoints if you
4169 do not know which numbers to use.
4170
4171 Disabling and enabling a breakpoint that has multiple locations
4172 affects all of its locations.
4173
4174 A breakpoint, watchpoint, or catchpoint can have any of four different
4175 states of enablement:
4176
4177 @itemize @bullet
4178 @item
4179 Enabled. The breakpoint stops your program. A breakpoint set
4180 with the @code{break} command starts out in this state.
4181 @item
4182 Disabled. The breakpoint has no effect on your program.
4183 @item
4184 Enabled once. The breakpoint stops your program, but then becomes
4185 disabled.
4186 @item
4187 Enabled for deletion. The breakpoint stops your program, but
4188 immediately after it does so it is deleted permanently. A breakpoint
4189 set with the @code{tbreak} command starts out in this state.
4190 @end itemize
4191
4192 You can use the following commands to enable or disable breakpoints,
4193 watchpoints, and catchpoints:
4194
4195 @table @code
4196 @kindex disable
4197 @kindex dis @r{(@code{disable})}
4198 @item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4199 Disable the specified breakpoints---or all breakpoints, if none are
4200 listed. A disabled breakpoint has no effect but is not forgotten. All
4201 options such as ignore-counts, conditions and commands are remembered in
4202 case the breakpoint is enabled again later. You may abbreviate
4203 @code{disable} as @code{dis}.
4204
4205 @kindex enable
4206 @item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4207 Enable the specified breakpoints (or all defined breakpoints). They
4208 become effective once again in stopping your program.
4209
4210 @item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
4211 Enable the specified breakpoints temporarily. @value{GDBN} disables any
4212 of these breakpoints immediately after stopping your program.
4213
4214 @item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
4215 Enable the specified breakpoints to work once, then die. @value{GDBN}
4216 deletes any of these breakpoints as soon as your program stops there.
4217 Breakpoints set by the @code{tbreak} command start out in this state.
4218 @end table
4219
4220 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
4221 @c confusing: tbreak is also initially enabled.
4222 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
4223 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
4224 subsequently, they become disabled or enabled only when you use one of
4225 the commands above. (The command @code{until} can set and delete a
4226 breakpoint of its own, but it does not change the state of your other
4227 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
4228 Stepping}.)
4229
4230 @node Conditions
4231 @subsection Break Conditions
4232 @cindex conditional breakpoints
4233 @cindex breakpoint conditions
4234
4235 @c FIXME what is scope of break condition expr? Context where wanted?
4236 @c in particular for a watchpoint?
4237 The simplest sort of breakpoint breaks every time your program reaches a
4238 specified place. You can also specify a @dfn{condition} for a
4239 breakpoint. A condition is just a Boolean expression in your
4240 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
4241 a condition evaluates the expression each time your program reaches it,
4242 and your program stops only if the condition is @emph{true}.
4243
4244 This is the converse of using assertions for program validation; in that
4245 situation, you want to stop when the assertion is violated---that is,
4246 when the condition is false. In C, if you want to test an assertion expressed
4247 by the condition @var{assert}, you should set the condition
4248 @samp{! @var{assert}} on the appropriate breakpoint.
4249
4250 Conditions are also accepted for watchpoints; you may not need them,
4251 since a watchpoint is inspecting the value of an expression anyhow---but
4252 it might be simpler, say, to just set a watchpoint on a variable name,
4253 and specify a condition that tests whether the new value is an interesting
4254 one.
4255
4256 Break conditions can have side effects, and may even call functions in
4257 your program. This can be useful, for example, to activate functions
4258 that log program progress, or to use your own print functions to
4259 format special data structures. The effects are completely predictable
4260 unless there is another enabled breakpoint at the same address. (In
4261 that case, @value{GDBN} might see the other breakpoint first and stop your
4262 program without checking the condition of this one.) Note that
4263 breakpoint commands are usually more convenient and flexible than break
4264 conditions for the
4265 purpose of performing side effects when a breakpoint is reached
4266 (@pxref{Break Commands, ,Breakpoint Command Lists}).
4267
4268 Break conditions can be specified when a breakpoint is set, by using
4269 @samp{if} in the arguments to the @code{break} command. @xref{Set
4270 Breaks, ,Setting Breakpoints}. They can also be changed at any time
4271 with the @code{condition} command.
4272
4273 You can also use the @code{if} keyword with the @code{watch} command.
4274 The @code{catch} command does not recognize the @code{if} keyword;
4275 @code{condition} is the only way to impose a further condition on a
4276 catchpoint.
4277
4278 @table @code
4279 @kindex condition
4280 @item condition @var{bnum} @var{expression}
4281 Specify @var{expression} as the break condition for breakpoint,
4282 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
4283 breakpoint @var{bnum} stops your program only if the value of
4284 @var{expression} is true (nonzero, in C). When you use
4285 @code{condition}, @value{GDBN} checks @var{expression} immediately for
4286 syntactic correctness, and to determine whether symbols in it have
4287 referents in the context of your breakpoint. If @var{expression} uses
4288 symbols not referenced in the context of the breakpoint, @value{GDBN}
4289 prints an error message:
4290
4291 @smallexample
4292 No symbol "foo" in current context.
4293 @end smallexample
4294
4295 @noindent
4296 @value{GDBN} does
4297 not actually evaluate @var{expression} at the time the @code{condition}
4298 command (or a command that sets a breakpoint with a condition, like
4299 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
4300
4301 @item condition @var{bnum}
4302 Remove the condition from breakpoint number @var{bnum}. It becomes
4303 an ordinary unconditional breakpoint.
4304 @end table
4305
4306 @cindex ignore count (of breakpoint)
4307 A special case of a breakpoint condition is to stop only when the
4308 breakpoint has been reached a certain number of times. This is so
4309 useful that there is a special way to do it, using the @dfn{ignore
4310 count} of the breakpoint. Every breakpoint has an ignore count, which
4311 is an integer. Most of the time, the ignore count is zero, and
4312 therefore has no effect. But if your program reaches a breakpoint whose
4313 ignore count is positive, then instead of stopping, it just decrements
4314 the ignore count by one and continues. As a result, if the ignore count
4315 value is @var{n}, the breakpoint does not stop the next @var{n} times
4316 your program reaches it.
4317
4318 @table @code
4319 @kindex ignore
4320 @item ignore @var{bnum} @var{count}
4321 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
4322 The next @var{count} times the breakpoint is reached, your program's
4323 execution does not stop; other than to decrement the ignore count, @value{GDBN}
4324 takes no action.
4325
4326 To make the breakpoint stop the next time it is reached, specify
4327 a count of zero.
4328
4329 When you use @code{continue} to resume execution of your program from a
4330 breakpoint, you can specify an ignore count directly as an argument to
4331 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
4332 Stepping,,Continuing and Stepping}.
4333
4334 If a breakpoint has a positive ignore count and a condition, the
4335 condition is not checked. Once the ignore count reaches zero,
4336 @value{GDBN} resumes checking the condition.
4337
4338 You could achieve the effect of the ignore count with a condition such
4339 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
4340 is decremented each time. @xref{Convenience Vars, ,Convenience
4341 Variables}.
4342 @end table
4343
4344 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
4345
4346
4347 @node Break Commands
4348 @subsection Breakpoint Command Lists
4349
4350 @cindex breakpoint commands
4351 You can give any breakpoint (or watchpoint or catchpoint) a series of
4352 commands to execute when your program stops due to that breakpoint. For
4353 example, you might want to print the values of certain expressions, or
4354 enable other breakpoints.
4355
4356 @table @code
4357 @kindex commands
4358 @kindex end@r{ (breakpoint commands)}
4359 @item commands @r{[}@var{range}@dots{}@r{]}
4360 @itemx @dots{} @var{command-list} @dots{}
4361 @itemx end
4362 Specify a list of commands for the given breakpoints. The commands
4363 themselves appear on the following lines. Type a line containing just
4364 @code{end} to terminate the commands.
4365
4366 To remove all commands from a breakpoint, type @code{commands} and
4367 follow it immediately with @code{end}; that is, give no commands.
4368
4369 With no argument, @code{commands} refers to the last breakpoint,
4370 watchpoint, or catchpoint set (not to the breakpoint most recently
4371 encountered). If the most recent breakpoints were set with a single
4372 command, then the @code{commands} will apply to all the breakpoints
4373 set by that command. This applies to breakpoints set by
4374 @code{rbreak}, and also applies when a single @code{break} command
4375 creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
4376 Expressions}).
4377 @end table
4378
4379 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
4380 disabled within a @var{command-list}.
4381
4382 You can use breakpoint commands to start your program up again. Simply
4383 use the @code{continue} command, or @code{step}, or any other command
4384 that resumes execution.
4385
4386 Any other commands in the command list, after a command that resumes
4387 execution, are ignored. This is because any time you resume execution
4388 (even with a simple @code{next} or @code{step}), you may encounter
4389 another breakpoint---which could have its own command list, leading to
4390 ambiguities about which list to execute.
4391
4392 @kindex silent
4393 If the first command you specify in a command list is @code{silent}, the
4394 usual message about stopping at a breakpoint is not printed. This may
4395 be desirable for breakpoints that are to print a specific message and
4396 then continue. If none of the remaining commands print anything, you
4397 see no sign that the breakpoint was reached. @code{silent} is
4398 meaningful only at the beginning of a breakpoint command list.
4399
4400 The commands @code{echo}, @code{output}, and @code{printf} allow you to
4401 print precisely controlled output, and are often useful in silent
4402 breakpoints. @xref{Output, ,Commands for Controlled Output}.
4403
4404 For example, here is how you could use breakpoint commands to print the
4405 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
4406
4407 @smallexample
4408 break foo if x>0
4409 commands
4410 silent
4411 printf "x is %d\n",x
4412 cont
4413 end
4414 @end smallexample
4415
4416 One application for breakpoint commands is to compensate for one bug so
4417 you can test for another. Put a breakpoint just after the erroneous line
4418 of code, give it a condition to detect the case in which something
4419 erroneous has been done, and give it commands to assign correct values
4420 to any variables that need them. End with the @code{continue} command
4421 so that your program does not stop, and start with the @code{silent}
4422 command so that no output is produced. Here is an example:
4423
4424 @smallexample
4425 break 403
4426 commands
4427 silent
4428 set x = y + 4
4429 cont
4430 end
4431 @end smallexample
4432
4433 @node Save Breakpoints
4434 @subsection How to save breakpoints to a file
4435
4436 To save breakpoint definitions to a file use the @w{@code{save
4437 breakpoints}} command.
4438
4439 @table @code
4440 @kindex save breakpoints
4441 @cindex save breakpoints to a file for future sessions
4442 @item save breakpoints [@var{filename}]
4443 This command saves all current breakpoint definitions together with
4444 their commands and ignore counts, into a file @file{@var{filename}}
4445 suitable for use in a later debugging session. This includes all
4446 types of breakpoints (breakpoints, watchpoints, catchpoints,
4447 tracepoints). To read the saved breakpoint definitions, use the
4448 @code{source} command (@pxref{Command Files}). Note that watchpoints
4449 with expressions involving local variables may fail to be recreated
4450 because it may not be possible to access the context where the
4451 watchpoint is valid anymore. Because the saved breakpoint definitions
4452 are simply a sequence of @value{GDBN} commands that recreate the
4453 breakpoints, you can edit the file in your favorite editing program,
4454 and remove the breakpoint definitions you're not interested in, or
4455 that can no longer be recreated.
4456 @end table
4457
4458 @c @ifclear BARETARGET
4459 @node Error in Breakpoints
4460 @subsection ``Cannot insert breakpoints''
4461
4462 If you request too many active hardware-assisted breakpoints and
4463 watchpoints, you will see this error message:
4464
4465 @c FIXME: the precise wording of this message may change; the relevant
4466 @c source change is not committed yet (Sep 3, 1999).
4467 @smallexample
4468 Stopped; cannot insert breakpoints.
4469 You may have requested too many hardware breakpoints and watchpoints.
4470 @end smallexample
4471
4472 @noindent
4473 This message is printed when you attempt to resume the program, since
4474 only then @value{GDBN} knows exactly how many hardware breakpoints and
4475 watchpoints it needs to insert.
4476
4477 When this message is printed, you need to disable or remove some of the
4478 hardware-assisted breakpoints and watchpoints, and then continue.
4479
4480 @node Breakpoint-related Warnings
4481 @subsection ``Breakpoint address adjusted...''
4482 @cindex breakpoint address adjusted
4483
4484 Some processor architectures place constraints on the addresses at
4485 which breakpoints may be placed. For architectures thus constrained,
4486 @value{GDBN} will attempt to adjust the breakpoint's address to comply
4487 with the constraints dictated by the architecture.
4488
4489 One example of such an architecture is the Fujitsu FR-V. The FR-V is
4490 a VLIW architecture in which a number of RISC-like instructions may be
4491 bundled together for parallel execution. The FR-V architecture
4492 constrains the location of a breakpoint instruction within such a
4493 bundle to the instruction with the lowest address. @value{GDBN}
4494 honors this constraint by adjusting a breakpoint's address to the
4495 first in the bundle.
4496
4497 It is not uncommon for optimized code to have bundles which contain
4498 instructions from different source statements, thus it may happen that
4499 a breakpoint's address will be adjusted from one source statement to
4500 another. Since this adjustment may significantly alter @value{GDBN}'s
4501 breakpoint related behavior from what the user expects, a warning is
4502 printed when the breakpoint is first set and also when the breakpoint
4503 is hit.
4504
4505 A warning like the one below is printed when setting a breakpoint
4506 that's been subject to address adjustment:
4507
4508 @smallexample
4509 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
4510 @end smallexample
4511
4512 Such warnings are printed both for user settable and @value{GDBN}'s
4513 internal breakpoints. If you see one of these warnings, you should
4514 verify that a breakpoint set at the adjusted address will have the
4515 desired affect. If not, the breakpoint in question may be removed and
4516 other breakpoints may be set which will have the desired behavior.
4517 E.g., it may be sufficient to place the breakpoint at a later
4518 instruction. A conditional breakpoint may also be useful in some
4519 cases to prevent the breakpoint from triggering too often.
4520
4521 @value{GDBN} will also issue a warning when stopping at one of these
4522 adjusted breakpoints:
4523
4524 @smallexample
4525 warning: Breakpoint 1 address previously adjusted from 0x00010414
4526 to 0x00010410.
4527 @end smallexample
4528
4529 When this warning is encountered, it may be too late to take remedial
4530 action except in cases where the breakpoint is hit earlier or more
4531 frequently than expected.
4532
4533 @node Continuing and Stepping
4534 @section Continuing and Stepping
4535
4536 @cindex stepping
4537 @cindex continuing
4538 @cindex resuming execution
4539 @dfn{Continuing} means resuming program execution until your program
4540 completes normally. In contrast, @dfn{stepping} means executing just
4541 one more ``step'' of your program, where ``step'' may mean either one
4542 line of source code, or one machine instruction (depending on what
4543 particular command you use). Either when continuing or when stepping,
4544 your program may stop even sooner, due to a breakpoint or a signal. (If
4545 it stops due to a signal, you may want to use @code{handle}, or use
4546 @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
4547
4548 @table @code
4549 @kindex continue
4550 @kindex c @r{(@code{continue})}
4551 @kindex fg @r{(resume foreground execution)}
4552 @item continue @r{[}@var{ignore-count}@r{]}
4553 @itemx c @r{[}@var{ignore-count}@r{]}
4554 @itemx fg @r{[}@var{ignore-count}@r{]}
4555 Resume program execution, at the address where your program last stopped;
4556 any breakpoints set at that address are bypassed. The optional argument
4557 @var{ignore-count} allows you to specify a further number of times to
4558 ignore a breakpoint at this location; its effect is like that of
4559 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
4560
4561 The argument @var{ignore-count} is meaningful only when your program
4562 stopped due to a breakpoint. At other times, the argument to
4563 @code{continue} is ignored.
4564
4565 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
4566 debugged program is deemed to be the foreground program) are provided
4567 purely for convenience, and have exactly the same behavior as
4568 @code{continue}.
4569 @end table
4570
4571 To resume execution at a different place, you can use @code{return}
4572 (@pxref{Returning, ,Returning from a Function}) to go back to the
4573 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
4574 Different Address}) to go to an arbitrary location in your program.
4575
4576 A typical technique for using stepping is to set a breakpoint
4577 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
4578 beginning of the function or the section of your program where a problem
4579 is believed to lie, run your program until it stops at that breakpoint,
4580 and then step through the suspect area, examining the variables that are
4581 interesting, until you see the problem happen.
4582
4583 @table @code
4584 @kindex step
4585 @kindex s @r{(@code{step})}
4586 @item step
4587 Continue running your program until control reaches a different source
4588 line, then stop it and return control to @value{GDBN}. This command is
4589 abbreviated @code{s}.
4590
4591 @quotation
4592 @c "without debugging information" is imprecise; actually "without line
4593 @c numbers in the debugging information". (gcc -g1 has debugging info but
4594 @c not line numbers). But it seems complex to try to make that
4595 @c distinction here.
4596 @emph{Warning:} If you use the @code{step} command while control is
4597 within a function that was compiled without debugging information,
4598 execution proceeds until control reaches a function that does have
4599 debugging information. Likewise, it will not step into a function which
4600 is compiled without debugging information. To step through functions
4601 without debugging information, use the @code{stepi} command, described
4602 below.
4603 @end quotation
4604
4605 The @code{step} command only stops at the first instruction of a source
4606 line. This prevents the multiple stops that could otherwise occur in
4607 @code{switch} statements, @code{for} loops, etc. @code{step} continues
4608 to stop if a function that has debugging information is called within
4609 the line. In other words, @code{step} @emph{steps inside} any functions
4610 called within the line.
4611
4612 Also, the @code{step} command only enters a function if there is line
4613 number information for the function. Otherwise it acts like the
4614 @code{next} command. This avoids problems when using @code{cc -gl}
4615 on MIPS machines. Previously, @code{step} entered subroutines if there
4616 was any debugging information about the routine.
4617
4618 @item step @var{count}
4619 Continue running as in @code{step}, but do so @var{count} times. If a
4620 breakpoint is reached, or a signal not related to stepping occurs before
4621 @var{count} steps, stepping stops right away.
4622
4623 @kindex next
4624 @kindex n @r{(@code{next})}
4625 @item next @r{[}@var{count}@r{]}
4626 Continue to the next source line in the current (innermost) stack frame.
4627 This is similar to @code{step}, but function calls that appear within
4628 the line of code are executed without stopping. Execution stops when
4629 control reaches a different line of code at the original stack level
4630 that was executing when you gave the @code{next} command. This command
4631 is abbreviated @code{n}.
4632
4633 An argument @var{count} is a repeat count, as for @code{step}.
4634
4635
4636 @c FIX ME!! Do we delete this, or is there a way it fits in with
4637 @c the following paragraph? --- Vctoria
4638 @c
4639 @c @code{next} within a function that lacks debugging information acts like
4640 @c @code{step}, but any function calls appearing within the code of the
4641 @c function are executed without stopping.
4642
4643 The @code{next} command only stops at the first instruction of a
4644 source line. This prevents multiple stops that could otherwise occur in
4645 @code{switch} statements, @code{for} loops, etc.
4646
4647 @kindex set step-mode
4648 @item set step-mode
4649 @cindex functions without line info, and stepping
4650 @cindex stepping into functions with no line info
4651 @itemx set step-mode on
4652 The @code{set step-mode on} command causes the @code{step} command to
4653 stop at the first instruction of a function which contains no debug line
4654 information rather than stepping over it.
4655
4656 This is useful in cases where you may be interested in inspecting the
4657 machine instructions of a function which has no symbolic info and do not
4658 want @value{GDBN} to automatically skip over this function.
4659
4660 @item set step-mode off
4661 Causes the @code{step} command to step over any functions which contains no
4662 debug information. This is the default.
4663
4664 @item show step-mode
4665 Show whether @value{GDBN} will stop in or step over functions without
4666 source line debug information.
4667
4668 @kindex finish
4669 @kindex fin @r{(@code{finish})}
4670 @item finish
4671 Continue running until just after function in the selected stack frame
4672 returns. Print the returned value (if any). This command can be
4673 abbreviated as @code{fin}.
4674
4675 Contrast this with the @code{return} command (@pxref{Returning,
4676 ,Returning from a Function}).
4677
4678 @kindex until
4679 @kindex u @r{(@code{until})}
4680 @cindex run until specified location
4681 @item until
4682 @itemx u
4683 Continue running until a source line past the current line, in the
4684 current stack frame, is reached. This command is used to avoid single
4685 stepping through a loop more than once. It is like the @code{next}
4686 command, except that when @code{until} encounters a jump, it
4687 automatically continues execution until the program counter is greater
4688 than the address of the jump.
4689
4690 This means that when you reach the end of a loop after single stepping
4691 though it, @code{until} makes your program continue execution until it
4692 exits the loop. In contrast, a @code{next} command at the end of a loop
4693 simply steps back to the beginning of the loop, which forces you to step
4694 through the next iteration.
4695
4696 @code{until} always stops your program if it attempts to exit the current
4697 stack frame.
4698
4699 @code{until} may produce somewhat counterintuitive results if the order
4700 of machine code does not match the order of the source lines. For
4701 example, in the following excerpt from a debugging session, the @code{f}
4702 (@code{frame}) command shows that execution is stopped at line
4703 @code{206}; yet when we use @code{until}, we get to line @code{195}:
4704
4705 @smallexample
4706 (@value{GDBP}) f
4707 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
4708 206 expand_input();
4709 (@value{GDBP}) until
4710 195 for ( ; argc > 0; NEXTARG) @{
4711 @end smallexample
4712
4713 This happened because, for execution efficiency, the compiler had
4714 generated code for the loop closure test at the end, rather than the
4715 start, of the loop---even though the test in a C @code{for}-loop is
4716 written before the body of the loop. The @code{until} command appeared
4717 to step back to the beginning of the loop when it advanced to this
4718 expression; however, it has not really gone to an earlier
4719 statement---not in terms of the actual machine code.
4720
4721 @code{until} with no argument works by means of single
4722 instruction stepping, and hence is slower than @code{until} with an
4723 argument.
4724
4725 @item until @var{location}
4726 @itemx u @var{location}
4727 Continue running your program until either the specified location is
4728 reached, or the current stack frame returns. @var{location} is any of
4729 the forms described in @ref{Specify Location}.
4730 This form of the command uses temporary breakpoints, and
4731 hence is quicker than @code{until} without an argument. The specified
4732 location is actually reached only if it is in the current frame. This
4733 implies that @code{until} can be used to skip over recursive function
4734 invocations. For instance in the code below, if the current location is
4735 line @code{96}, issuing @code{until 99} will execute the program up to
4736 line @code{99} in the same invocation of factorial, i.e., after the inner
4737 invocations have returned.
4738
4739 @smallexample
4740 94 int factorial (int value)
4741 95 @{
4742 96 if (value > 1) @{
4743 97 value *= factorial (value - 1);
4744 98 @}
4745 99 return (value);
4746 100 @}
4747 @end smallexample
4748
4749
4750 @kindex advance @var{location}
4751 @itemx advance @var{location}
4752 Continue running the program up to the given @var{location}. An argument is
4753 required, which should be of one of the forms described in
4754 @ref{Specify Location}.
4755 Execution will also stop upon exit from the current stack
4756 frame. This command is similar to @code{until}, but @code{advance} will
4757 not skip over recursive function calls, and the target location doesn't
4758 have to be in the same frame as the current one.
4759
4760
4761 @kindex stepi
4762 @kindex si @r{(@code{stepi})}
4763 @item stepi
4764 @itemx stepi @var{arg}
4765 @itemx si
4766 Execute one machine instruction, then stop and return to the debugger.
4767
4768 It is often useful to do @samp{display/i $pc} when stepping by machine
4769 instructions. This makes @value{GDBN} automatically display the next
4770 instruction to be executed, each time your program stops. @xref{Auto
4771 Display,, Automatic Display}.
4772
4773 An argument is a repeat count, as in @code{step}.
4774
4775 @need 750
4776 @kindex nexti
4777 @kindex ni @r{(@code{nexti})}
4778 @item nexti
4779 @itemx nexti @var{arg}
4780 @itemx ni
4781 Execute one machine instruction, but if it is a function call,
4782 proceed until the function returns.
4783
4784 An argument is a repeat count, as in @code{next}.
4785 @end table
4786
4787 @node Signals
4788 @section Signals
4789 @cindex signals
4790
4791 A signal is an asynchronous event that can happen in a program. The
4792 operating system defines the possible kinds of signals, and gives each
4793 kind a name and a number. For example, in Unix @code{SIGINT} is the
4794 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
4795 @code{SIGSEGV} is the signal a program gets from referencing a place in
4796 memory far away from all the areas in use; @code{SIGALRM} occurs when
4797 the alarm clock timer goes off (which happens only if your program has
4798 requested an alarm).
4799
4800 @cindex fatal signals
4801 Some signals, including @code{SIGALRM}, are a normal part of the
4802 functioning of your program. Others, such as @code{SIGSEGV}, indicate
4803 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
4804 program has not specified in advance some other way to handle the signal.
4805 @code{SIGINT} does not indicate an error in your program, but it is normally
4806 fatal so it can carry out the purpose of the interrupt: to kill the program.
4807
4808 @value{GDBN} has the ability to detect any occurrence of a signal in your
4809 program. You can tell @value{GDBN} in advance what to do for each kind of
4810 signal.
4811
4812 @cindex handling signals
4813 Normally, @value{GDBN} is set up to let the non-erroneous signals like
4814 @code{SIGALRM} be silently passed to your program
4815 (so as not to interfere with their role in the program's functioning)
4816 but to stop your program immediately whenever an error signal happens.
4817 You can change these settings with the @code{handle} command.
4818
4819 @table @code
4820 @kindex info signals
4821 @kindex info handle
4822 @item info signals
4823 @itemx info handle
4824 Print a table of all the kinds of signals and how @value{GDBN} has been told to
4825 handle each one. You can use this to see the signal numbers of all
4826 the defined types of signals.
4827
4828 @item info signals @var{sig}
4829 Similar, but print information only about the specified signal number.
4830
4831 @code{info handle} is an alias for @code{info signals}.
4832
4833 @kindex handle
4834 @item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
4835 Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
4836 can be the number of a signal or its name (with or without the
4837 @samp{SIG} at the beginning); a list of signal numbers of the form
4838 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
4839 known signals. Optional arguments @var{keywords}, described below,
4840 say what change to make.
4841 @end table
4842
4843 @c @group
4844 The keywords allowed by the @code{handle} command can be abbreviated.
4845 Their full names are:
4846
4847 @table @code
4848 @item nostop
4849 @value{GDBN} should not stop your program when this signal happens. It may
4850 still print a message telling you that the signal has come in.
4851
4852 @item stop
4853 @value{GDBN} should stop your program when this signal happens. This implies
4854 the @code{print} keyword as well.
4855
4856 @item print
4857 @value{GDBN} should print a message when this signal happens.
4858
4859 @item noprint
4860 @value{GDBN} should not mention the occurrence of the signal at all. This
4861 implies the @code{nostop} keyword as well.
4862
4863 @item pass
4864 @itemx noignore
4865 @value{GDBN} should allow your program to see this signal; your program
4866 can handle the signal, or else it may terminate if the signal is fatal
4867 and not handled. @code{pass} and @code{noignore} are synonyms.
4868
4869 @item nopass
4870 @itemx ignore
4871 @value{GDBN} should not allow your program to see this signal.
4872 @code{nopass} and @code{ignore} are synonyms.
4873 @end table
4874 @c @end group
4875
4876 When a signal stops your program, the signal is not visible to the
4877 program until you
4878 continue. Your program sees the signal then, if @code{pass} is in
4879 effect for the signal in question @emph{at that time}. In other words,
4880 after @value{GDBN} reports a signal, you can use the @code{handle}
4881 command with @code{pass} or @code{nopass} to control whether your
4882 program sees that signal when you continue.
4883
4884 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
4885 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
4886 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
4887 erroneous signals.
4888
4889 You can also use the @code{signal} command to prevent your program from
4890 seeing a signal, or cause it to see a signal it normally would not see,
4891 or to give it any signal at any time. For example, if your program stopped
4892 due to some sort of memory reference error, you might store correct
4893 values into the erroneous variables and continue, hoping to see more
4894 execution; but your program would probably terminate immediately as
4895 a result of the fatal signal once it saw the signal. To prevent this,
4896 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
4897 Program a Signal}.
4898
4899 @cindex extra signal information
4900 @anchor{extra signal information}
4901
4902 On some targets, @value{GDBN} can inspect extra signal information
4903 associated with the intercepted signal, before it is actually
4904 delivered to the program being debugged. This information is exported
4905 by the convenience variable @code{$_siginfo}, and consists of data
4906 that is passed by the kernel to the signal handler at the time of the
4907 receipt of a signal. The data type of the information itself is
4908 target dependent. You can see the data type using the @code{ptype
4909 $_siginfo} command. On Unix systems, it typically corresponds to the
4910 standard @code{siginfo_t} type, as defined in the @file{signal.h}
4911 system header.
4912
4913 Here's an example, on a @sc{gnu}/Linux system, printing the stray
4914 referenced address that raised a segmentation fault.
4915
4916 @smallexample
4917 @group
4918 (@value{GDBP}) continue
4919 Program received signal SIGSEGV, Segmentation fault.
4920 0x0000000000400766 in main ()
4921 69 *(int *)p = 0;
4922 (@value{GDBP}) ptype $_siginfo
4923 type = struct @{
4924 int si_signo;
4925 int si_errno;
4926 int si_code;
4927 union @{
4928 int _pad[28];
4929 struct @{...@} _kill;
4930 struct @{...@} _timer;
4931 struct @{...@} _rt;
4932 struct @{...@} _sigchld;
4933 struct @{...@} _sigfault;
4934 struct @{...@} _sigpoll;
4935 @} _sifields;
4936 @}
4937 (@value{GDBP}) ptype $_siginfo._sifields._sigfault
4938 type = struct @{
4939 void *si_addr;
4940 @}
4941 (@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
4942 $1 = (void *) 0x7ffff7ff7000
4943 @end group
4944 @end smallexample
4945
4946 Depending on target support, @code{$_siginfo} may also be writable.
4947
4948 @node Thread Stops
4949 @section Stopping and Starting Multi-thread Programs
4950
4951 @cindex stopped threads
4952 @cindex threads, stopped
4953
4954 @cindex continuing threads
4955 @cindex threads, continuing
4956
4957 @value{GDBN} supports debugging programs with multiple threads
4958 (@pxref{Threads,, Debugging Programs with Multiple Threads}). There
4959 are two modes of controlling execution of your program within the
4960 debugger. In the default mode, referred to as @dfn{all-stop mode},
4961 when any thread in your program stops (for example, at a breakpoint
4962 or while being stepped), all other threads in the program are also stopped by
4963 @value{GDBN}. On some targets, @value{GDBN} also supports
4964 @dfn{non-stop mode}, in which other threads can continue to run freely while
4965 you examine the stopped thread in the debugger.
4966
4967 @menu
4968 * All-Stop Mode:: All threads stop when GDB takes control
4969 * Non-Stop Mode:: Other threads continue to execute
4970 * Background Execution:: Running your program asynchronously
4971 * Thread-Specific Breakpoints:: Controlling breakpoints
4972 * Interrupted System Calls:: GDB may interfere with system calls
4973 * Observer Mode:: GDB does not alter program behavior
4974 @end menu
4975
4976 @node All-Stop Mode
4977 @subsection All-Stop Mode
4978
4979 @cindex all-stop mode
4980
4981 In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
4982 @emph{all} threads of execution stop, not just the current thread. This
4983 allows you to examine the overall state of the program, including
4984 switching between threads, without worrying that things may change
4985 underfoot.
4986
4987 Conversely, whenever you restart the program, @emph{all} threads start
4988 executing. @emph{This is true even when single-stepping} with commands
4989 like @code{step} or @code{next}.
4990
4991 In particular, @value{GDBN} cannot single-step all threads in lockstep.
4992 Since thread scheduling is up to your debugging target's operating
4993 system (not controlled by @value{GDBN}), other threads may
4994 execute more than one statement while the current thread completes a
4995 single step. Moreover, in general other threads stop in the middle of a
4996 statement, rather than at a clean statement boundary, when the program
4997 stops.
4998
4999 You might even find your program stopped in another thread after
5000 continuing or even single-stepping. This happens whenever some other
5001 thread runs into a breakpoint, a signal, or an exception before the
5002 first thread completes whatever you requested.
5003
5004 @cindex automatic thread selection
5005 @cindex switching threads automatically
5006 @cindex threads, automatic switching
5007 Whenever @value{GDBN} stops your program, due to a breakpoint or a
5008 signal, it automatically selects the thread where that breakpoint or
5009 signal happened. @value{GDBN} alerts you to the context switch with a
5010 message such as @samp{[Switching to Thread @var{n}]} to identify the
5011 thread.
5012
5013 On some OSes, you can modify @value{GDBN}'s default behavior by
5014 locking the OS scheduler to allow only a single thread to run.
5015
5016 @table @code
5017 @item set scheduler-locking @var{mode}
5018 @cindex scheduler locking mode
5019 @cindex lock scheduler
5020 Set the scheduler locking mode. If it is @code{off}, then there is no
5021 locking and any thread may run at any time. If @code{on}, then only the
5022 current thread may run when the inferior is resumed. The @code{step}
5023 mode optimizes for single-stepping; it prevents other threads
5024 from preempting the current thread while you are stepping, so that
5025 the focus of debugging does not change unexpectedly.
5026 Other threads only rarely (or never) get a chance to run
5027 when you step. They are more likely to run when you @samp{next} over a
5028 function call, and they are completely free to run when you use commands
5029 like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
5030 thread hits a breakpoint during its timeslice, @value{GDBN} does not change
5031 the current thread away from the thread that you are debugging.
5032
5033 @item show scheduler-locking
5034 Display the current scheduler locking mode.
5035 @end table
5036
5037 @cindex resume threads of multiple processes simultaneously
5038 By default, when you issue one of the execution commands such as
5039 @code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
5040 threads of the current inferior to run. For example, if @value{GDBN}
5041 is attached to two inferiors, each with two threads, the
5042 @code{continue} command resumes only the two threads of the current
5043 inferior. This is useful, for example, when you debug a program that
5044 forks and you want to hold the parent stopped (so that, for instance,
5045 it doesn't run to exit), while you debug the child. In other
5046 situations, you may not be interested in inspecting the current state
5047 of any of the processes @value{GDBN} is attached to, and you may want
5048 to resume them all until some breakpoint is hit. In the latter case,
5049 you can instruct @value{GDBN} to allow all threads of all the
5050 inferiors to run with the @w{@code{set schedule-multiple}} command.
5051
5052 @table @code
5053 @kindex set schedule-multiple
5054 @item set schedule-multiple
5055 Set the mode for allowing threads of multiple processes to be resumed
5056 when an execution command is issued. When @code{on}, all threads of
5057 all processes are allowed to run. When @code{off}, only the threads
5058 of the current process are resumed. The default is @code{off}. The
5059 @code{scheduler-locking} mode takes precedence when set to @code{on},
5060 or while you are stepping and set to @code{step}.
5061
5062 @item show schedule-multiple
5063 Display the current mode for resuming the execution of threads of
5064 multiple processes.
5065 @end table
5066
5067 @node Non-Stop Mode
5068 @subsection Non-Stop Mode
5069
5070 @cindex non-stop mode
5071
5072 @c This section is really only a place-holder, and needs to be expanded
5073 @c with more details.
5074
5075 For some multi-threaded targets, @value{GDBN} supports an optional
5076 mode of operation in which you can examine stopped program threads in
5077 the debugger while other threads continue to execute freely. This
5078 minimizes intrusion when debugging live systems, such as programs
5079 where some threads have real-time constraints or must continue to
5080 respond to external events. This is referred to as @dfn{non-stop} mode.
5081
5082 In non-stop mode, when a thread stops to report a debugging event,
5083 @emph{only} that thread is stopped; @value{GDBN} does not stop other
5084 threads as well, in contrast to the all-stop mode behavior. Additionally,
5085 execution commands such as @code{continue} and @code{step} apply by default
5086 only to the current thread in non-stop mode, rather than all threads as
5087 in all-stop mode. This allows you to control threads explicitly in
5088 ways that are not possible in all-stop mode --- for example, stepping
5089 one thread while allowing others to run freely, stepping
5090 one thread while holding all others stopped, or stepping several threads
5091 independently and simultaneously.
5092
5093 To enter non-stop mode, use this sequence of commands before you run
5094 or attach to your program:
5095
5096 @smallexample
5097 # Enable the async interface.
5098 set target-async 1
5099
5100 # If using the CLI, pagination breaks non-stop.
5101 set pagination off
5102
5103 # Finally, turn it on!
5104 set non-stop on
5105 @end smallexample
5106
5107 You can use these commands to manipulate the non-stop mode setting:
5108
5109 @table @code
5110 @kindex set non-stop
5111 @item set non-stop on
5112 Enable selection of non-stop mode.
5113 @item set non-stop off
5114 Disable selection of non-stop mode.
5115 @kindex show non-stop
5116 @item show non-stop
5117 Show the current non-stop enablement setting.
5118 @end table
5119
5120 Note these commands only reflect whether non-stop mode is enabled,
5121 not whether the currently-executing program is being run in non-stop mode.
5122 In particular, the @code{set non-stop} preference is only consulted when
5123 @value{GDBN} starts or connects to the target program, and it is generally
5124 not possible to switch modes once debugging has started. Furthermore,
5125 since not all targets support non-stop mode, even when you have enabled
5126 non-stop mode, @value{GDBN} may still fall back to all-stop operation by
5127 default.
5128
5129 In non-stop mode, all execution commands apply only to the current thread
5130 by default. That is, @code{continue} only continues one thread.
5131 To continue all threads, issue @code{continue -a} or @code{c -a}.
5132
5133 You can use @value{GDBN}'s background execution commands
5134 (@pxref{Background Execution}) to run some threads in the background
5135 while you continue to examine or step others from @value{GDBN}.
5136 The MI execution commands (@pxref{GDB/MI Program Execution}) are
5137 always executed asynchronously in non-stop mode.
5138
5139 Suspending execution is done with the @code{interrupt} command when
5140 running in the background, or @kbd{Ctrl-c} during foreground execution.
5141 In all-stop mode, this stops the whole process;
5142 but in non-stop mode the interrupt applies only to the current thread.
5143 To stop the whole program, use @code{interrupt -a}.
5144
5145 Other execution commands do not currently support the @code{-a} option.
5146
5147 In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
5148 that thread current, as it does in all-stop mode. This is because the
5149 thread stop notifications are asynchronous with respect to @value{GDBN}'s
5150 command interpreter, and it would be confusing if @value{GDBN} unexpectedly
5151 changed to a different thread just as you entered a command to operate on the
5152 previously current thread.
5153
5154 @node Background Execution
5155 @subsection Background Execution
5156
5157 @cindex foreground execution
5158 @cindex background execution
5159 @cindex asynchronous execution
5160 @cindex execution, foreground, background and asynchronous
5161
5162 @value{GDBN}'s execution commands have two variants: the normal
5163 foreground (synchronous) behavior, and a background
5164 (asynchronous) behavior. In foreground execution, @value{GDBN} waits for
5165 the program to report that some thread has stopped before prompting for
5166 another command. In background execution, @value{GDBN} immediately gives
5167 a command prompt so that you can issue other commands while your program runs.
5168
5169 You need to explicitly enable asynchronous mode before you can use
5170 background execution commands. You can use these commands to
5171 manipulate the asynchronous mode setting:
5172
5173 @table @code
5174 @kindex set target-async
5175 @item set target-async on
5176 Enable asynchronous mode.
5177 @item set target-async off
5178 Disable asynchronous mode.
5179 @kindex show target-async
5180 @item show target-async
5181 Show the current target-async setting.
5182 @end table
5183
5184 If the target doesn't support async mode, @value{GDBN} issues an error
5185 message if you attempt to use the background execution commands.
5186
5187 To specify background execution, add a @code{&} to the command. For example,
5188 the background form of the @code{continue} command is @code{continue&}, or
5189 just @code{c&}. The execution commands that accept background execution
5190 are:
5191
5192 @table @code
5193 @kindex run&
5194 @item run
5195 @xref{Starting, , Starting your Program}.
5196
5197 @item attach
5198 @kindex attach&
5199 @xref{Attach, , Debugging an Already-running Process}.
5200
5201 @item step
5202 @kindex step&
5203 @xref{Continuing and Stepping, step}.
5204
5205 @item stepi
5206 @kindex stepi&
5207 @xref{Continuing and Stepping, stepi}.
5208
5209 @item next
5210 @kindex next&
5211 @xref{Continuing and Stepping, next}.
5212
5213 @item nexti
5214 @kindex nexti&
5215 @xref{Continuing and Stepping, nexti}.
5216
5217 @item continue
5218 @kindex continue&
5219 @xref{Continuing and Stepping, continue}.
5220
5221 @item finish
5222 @kindex finish&
5223 @xref{Continuing and Stepping, finish}.
5224
5225 @item until
5226 @kindex until&
5227 @xref{Continuing and Stepping, until}.
5228
5229 @end table
5230
5231 Background execution is especially useful in conjunction with non-stop
5232 mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
5233 However, you can also use these commands in the normal all-stop mode with
5234 the restriction that you cannot issue another execution command until the
5235 previous one finishes. Examples of commands that are valid in all-stop
5236 mode while the program is running include @code{help} and @code{info break}.
5237
5238 You can interrupt your program while it is running in the background by
5239 using the @code{interrupt} command.
5240
5241 @table @code
5242 @kindex interrupt
5243 @item interrupt
5244 @itemx interrupt -a
5245
5246 Suspend execution of the running program. In all-stop mode,
5247 @code{interrupt} stops the whole process, but in non-stop mode, it stops
5248 only the current thread. To stop the whole program in non-stop mode,
5249 use @code{interrupt -a}.
5250 @end table
5251
5252 @node Thread-Specific Breakpoints
5253 @subsection Thread-Specific Breakpoints
5254
5255 When your program has multiple threads (@pxref{Threads,, Debugging
5256 Programs with Multiple Threads}), you can choose whether to set
5257 breakpoints on all threads, or on a particular thread.
5258
5259 @table @code
5260 @cindex breakpoints and threads
5261 @cindex thread breakpoints
5262 @kindex break @dots{} thread @var{threadno}
5263 @item break @var{linespec} thread @var{threadno}
5264 @itemx break @var{linespec} thread @var{threadno} if @dots{}
5265 @var{linespec} specifies source lines; there are several ways of
5266 writing them (@pxref{Specify Location}), but the effect is always to
5267 specify some source line.
5268
5269 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
5270 to specify that you only want @value{GDBN} to stop the program when a
5271 particular thread reaches this breakpoint. @var{threadno} is one of the
5272 numeric thread identifiers assigned by @value{GDBN}, shown in the first
5273 column of the @samp{info threads} display.
5274
5275 If you do not specify @samp{thread @var{threadno}} when you set a
5276 breakpoint, the breakpoint applies to @emph{all} threads of your
5277 program.
5278
5279 You can use the @code{thread} qualifier on conditional breakpoints as
5280 well; in this case, place @samp{thread @var{threadno}} before or
5281 after the breakpoint condition, like this:
5282
5283 @smallexample
5284 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
5285 @end smallexample
5286
5287 @end table
5288
5289 @node Interrupted System Calls
5290 @subsection Interrupted System Calls
5291
5292 @cindex thread breakpoints and system calls
5293 @cindex system calls and thread breakpoints
5294 @cindex premature return from system calls
5295 There is an unfortunate side effect when using @value{GDBN} to debug
5296 multi-threaded programs. If one thread stops for a
5297 breakpoint, or for some other reason, and another thread is blocked in a
5298 system call, then the system call may return prematurely. This is a
5299 consequence of the interaction between multiple threads and the signals
5300 that @value{GDBN} uses to implement breakpoints and other events that
5301 stop execution.
5302
5303 To handle this problem, your program should check the return value of
5304 each system call and react appropriately. This is good programming
5305 style anyways.
5306
5307 For example, do not write code like this:
5308
5309 @smallexample
5310 sleep (10);
5311 @end smallexample
5312
5313 The call to @code{sleep} will return early if a different thread stops
5314 at a breakpoint or for some other reason.
5315
5316 Instead, write this:
5317
5318 @smallexample
5319 int unslept = 10;
5320 while (unslept > 0)
5321 unslept = sleep (unslept);
5322 @end smallexample
5323
5324 A system call is allowed to return early, so the system is still
5325 conforming to its specification. But @value{GDBN} does cause your
5326 multi-threaded program to behave differently than it would without
5327 @value{GDBN}.
5328
5329 Also, @value{GDBN} uses internal breakpoints in the thread library to
5330 monitor certain events such as thread creation and thread destruction.
5331 When such an event happens, a system call in another thread may return
5332 prematurely, even though your program does not appear to stop.
5333
5334 @node Observer Mode
5335 @subsection Observer Mode
5336
5337 If you want to build on non-stop mode and observe program behavior
5338 without any chance of disruption by @value{GDBN}, you can set
5339 variables to disable all of the debugger's attempts to modify state,
5340 whether by writing memory, inserting breakpoints, etc. These operate
5341 at a low level, intercepting operations from all commands.
5342
5343 When all of these are set to @code{off}, then @value{GDBN} is said to
5344 be @dfn{observer mode}. As a convenience, the variable
5345 @code{observer} can be set to disable these, plus enable non-stop
5346 mode.
5347
5348 Note that @value{GDBN} will not prevent you from making nonsensical
5349 combinations of these settings. For instance, if you have enabled
5350 @code{may-insert-breakpoints} but disabled @code{may-write-memory},
5351 then breakpoints that work by writing trap instructions into the code
5352 stream will still not be able to be placed.
5353
5354 @table @code
5355
5356 @kindex observer
5357 @item set observer on
5358 @itemx set observer off
5359 When set to @code{on}, this disables all the permission variables
5360 below (except for @code{insert-fast-tracepoints}), plus enables
5361 non-stop debugging. Setting this to @code{off} switches back to
5362 normal debugging, though remaining in non-stop mode.
5363
5364 @item show observer
5365 Show whether observer mode is on or off.
5366
5367 @kindex may-write-registers
5368 @item set may-write-registers on
5369 @itemx set may-write-registers off
5370 This controls whether @value{GDBN} will attempt to alter the values of
5371 registers, such as with assignment expressions in @code{print}, or the
5372 @code{jump} command. It defaults to @code{on}.
5373
5374 @item show may-write-registers
5375 Show the current permission to write registers.
5376
5377 @kindex may-write-memory
5378 @item set may-write-memory on
5379 @itemx set may-write-memory off
5380 This controls whether @value{GDBN} will attempt to alter the contents
5381 of memory, such as with assignment expressions in @code{print}. It
5382 defaults to @code{on}.
5383
5384 @item show may-write-memory
5385 Show the current permission to write memory.
5386
5387 @kindex may-insert-breakpoints
5388 @item set may-insert-breakpoints on
5389 @itemx set may-insert-breakpoints off
5390 This controls whether @value{GDBN} will attempt to insert breakpoints.
5391 This affects all breakpoints, including internal breakpoints defined
5392 by @value{GDBN}. It defaults to @code{on}.
5393
5394 @item show may-insert-breakpoints
5395 Show the current permission to insert breakpoints.
5396
5397 @kindex may-insert-tracepoints
5398 @item set may-insert-tracepoints on
5399 @itemx set may-insert-tracepoints off
5400 This controls whether @value{GDBN} will attempt to insert (regular)
5401 tracepoints at the beginning of a tracing experiment. It affects only
5402 non-fast tracepoints, fast tracepoints being under the control of
5403 @code{may-insert-fast-tracepoints}. It defaults to @code{on}.
5404
5405 @item show may-insert-tracepoints
5406 Show the current permission to insert tracepoints.
5407
5408 @kindex may-insert-fast-tracepoints
5409 @item set may-insert-fast-tracepoints on
5410 @itemx set may-insert-fast-tracepoints off
5411 This controls whether @value{GDBN} will attempt to insert fast
5412 tracepoints at the beginning of a tracing experiment. It affects only
5413 fast tracepoints, regular (non-fast) tracepoints being under the
5414 control of @code{may-insert-tracepoints}. It defaults to @code{on}.
5415
5416 @item show may-insert-fast-tracepoints
5417 Show the current permission to insert fast tracepoints.
5418
5419 @kindex may-interrupt
5420 @item set may-interrupt on
5421 @itemx set may-interrupt off
5422 This controls whether @value{GDBN} will attempt to interrupt or stop
5423 program execution. When this variable is @code{off}, the
5424 @code{interrupt} command will have no effect, nor will
5425 @kbd{Ctrl-c}. It defaults to @code{on}.
5426
5427 @item show may-interrupt
5428 Show the current permission to interrupt or stop the program.
5429
5430 @end table
5431
5432 @node Reverse Execution
5433 @chapter Running programs backward
5434 @cindex reverse execution
5435 @cindex running programs backward
5436
5437 When you are debugging a program, it is not unusual to realize that
5438 you have gone too far, and some event of interest has already happened.
5439 If the target environment supports it, @value{GDBN} can allow you to
5440 ``rewind'' the program by running it backward.
5441
5442 A target environment that supports reverse execution should be able
5443 to ``undo'' the changes in machine state that have taken place as the
5444 program was executing normally. Variables, registers etc.@: should
5445 revert to their previous values. Obviously this requires a great
5446 deal of sophistication on the part of the target environment; not
5447 all target environments can support reverse execution.
5448
5449 When a program is executed in reverse, the instructions that
5450 have most recently been executed are ``un-executed'', in reverse
5451 order. The program counter runs backward, following the previous
5452 thread of execution in reverse. As each instruction is ``un-executed'',
5453 the values of memory and/or registers that were changed by that
5454 instruction are reverted to their previous states. After executing
5455 a piece of source code in reverse, all side effects of that code
5456 should be ``undone'', and all variables should be returned to their
5457 prior values@footnote{
5458 Note that some side effects are easier to undo than others. For instance,
5459 memory and registers are relatively easy, but device I/O is hard. Some
5460 targets may be able undo things like device I/O, and some may not.
5461
5462 The contract between @value{GDBN} and the reverse executing target
5463 requires only that the target do something reasonable when
5464 @value{GDBN} tells it to execute backwards, and then report the
5465 results back to @value{GDBN}. Whatever the target reports back to
5466 @value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
5467 assumes that the memory and registers that the target reports are in a
5468 consistant state, but @value{GDBN} accepts whatever it is given.
5469 }.
5470
5471 If you are debugging in a target environment that supports
5472 reverse execution, @value{GDBN} provides the following commands.
5473
5474 @table @code
5475 @kindex reverse-continue
5476 @kindex rc @r{(@code{reverse-continue})}
5477 @item reverse-continue @r{[}@var{ignore-count}@r{]}
5478 @itemx rc @r{[}@var{ignore-count}@r{]}
5479 Beginning at the point where your program last stopped, start executing
5480 in reverse. Reverse execution will stop for breakpoints and synchronous
5481 exceptions (signals), just like normal execution. Behavior of
5482 asynchronous signals depends on the target environment.
5483
5484 @kindex reverse-step
5485 @kindex rs @r{(@code{step})}
5486 @item reverse-step @r{[}@var{count}@r{]}
5487 Run the program backward until control reaches the start of a
5488 different source line; then stop it, and return control to @value{GDBN}.
5489
5490 Like the @code{step} command, @code{reverse-step} will only stop
5491 at the beginning of a source line. It ``un-executes'' the previously
5492 executed source line. If the previous source line included calls to
5493 debuggable functions, @code{reverse-step} will step (backward) into
5494 the called function, stopping at the beginning of the @emph{last}
5495 statement in the called function (typically a return statement).
5496
5497 Also, as with the @code{step} command, if non-debuggable functions are
5498 called, @code{reverse-step} will run thru them backward without stopping.
5499
5500 @kindex reverse-stepi
5501 @kindex rsi @r{(@code{reverse-stepi})}
5502 @item reverse-stepi @r{[}@var{count}@r{]}
5503 Reverse-execute one machine instruction. Note that the instruction
5504 to be reverse-executed is @emph{not} the one pointed to by the program
5505 counter, but the instruction executed prior to that one. For instance,
5506 if the last instruction was a jump, @code{reverse-stepi} will take you
5507 back from the destination of the jump to the jump instruction itself.
5508
5509 @kindex reverse-next
5510 @kindex rn @r{(@code{reverse-next})}
5511 @item reverse-next @r{[}@var{count}@r{]}
5512 Run backward to the beginning of the previous line executed in
5513 the current (innermost) stack frame. If the line contains function
5514 calls, they will be ``un-executed'' without stopping. Starting from
5515 the first line of a function, @code{reverse-next} will take you back
5516 to the caller of that function, @emph{before} the function was called,
5517 just as the normal @code{next} command would take you from the last
5518 line of a function back to its return to its caller
5519 @footnote{Unless the code is too heavily optimized.}.
5520
5521 @kindex reverse-nexti
5522 @kindex rni @r{(@code{reverse-nexti})}
5523 @item reverse-nexti @r{[}@var{count}@r{]}
5524 Like @code{nexti}, @code{reverse-nexti} executes a single instruction
5525 in reverse, except that called functions are ``un-executed'' atomically.
5526 That is, if the previously executed instruction was a return from
5527 another function, @code{reverse-nexti} will continue to execute
5528 in reverse until the call to that function (from the current stack
5529 frame) is reached.
5530
5531 @kindex reverse-finish
5532 @item reverse-finish
5533 Just as the @code{finish} command takes you to the point where the
5534 current function returns, @code{reverse-finish} takes you to the point
5535 where it was called. Instead of ending up at the end of the current
5536 function invocation, you end up at the beginning.
5537
5538 @kindex set exec-direction
5539 @item set exec-direction
5540 Set the direction of target execution.
5541 @itemx set exec-direction reverse
5542 @cindex execute forward or backward in time
5543 @value{GDBN} will perform all execution commands in reverse, until the
5544 exec-direction mode is changed to ``forward''. Affected commands include
5545 @code{step, stepi, next, nexti, continue, and finish}. The @code{return}
5546 command cannot be used in reverse mode.
5547 @item set exec-direction forward
5548 @value{GDBN} will perform all execution commands in the normal fashion.
5549 This is the default.
5550 @end table
5551
5552
5553 @node Process Record and Replay
5554 @chapter Recording Inferior's Execution and Replaying It
5555 @cindex process record and replay
5556 @cindex recording inferior's execution and replaying it
5557
5558 On some platforms, @value{GDBN} provides a special @dfn{process record
5559 and replay} target that can record a log of the process execution, and
5560 replay it later with both forward and reverse execution commands.
5561
5562 @cindex replay mode
5563 When this target is in use, if the execution log includes the record
5564 for the next instruction, @value{GDBN} will debug in @dfn{replay
5565 mode}. In the replay mode, the inferior does not really execute code
5566 instructions. Instead, all the events that normally happen during
5567 code execution are taken from the execution log. While code is not
5568 really executed in replay mode, the values of registers (including the
5569 program counter register) and the memory of the inferior are still
5570 changed as they normally would. Their contents are taken from the
5571 execution log.
5572
5573 @cindex record mode
5574 If the record for the next instruction is not in the execution log,
5575 @value{GDBN} will debug in @dfn{record mode}. In this mode, the
5576 inferior executes normally, and @value{GDBN} records the execution log
5577 for future replay.
5578
5579 The process record and replay target supports reverse execution
5580 (@pxref{Reverse Execution}), even if the platform on which the
5581 inferior runs does not. However, the reverse execution is limited in
5582 this case by the range of the instructions recorded in the execution
5583 log. In other words, reverse execution on platforms that don't
5584 support it directly can only be done in the replay mode.
5585
5586 When debugging in the reverse direction, @value{GDBN} will work in
5587 replay mode as long as the execution log includes the record for the
5588 previous instruction; otherwise, it will work in record mode, if the
5589 platform supports reverse execution, or stop if not.
5590
5591 For architecture environments that support process record and replay,
5592 @value{GDBN} provides the following commands:
5593
5594 @table @code
5595 @kindex target record
5596 @kindex record
5597 @kindex rec
5598 @item target record
5599 This command starts the process record and replay target. The process
5600 record and replay target can only debug a process that is already
5601 running. Therefore, you need first to start the process with the
5602 @kbd{run} or @kbd{start} commands, and then start the recording with
5603 the @kbd{target record} command.
5604
5605 Both @code{record} and @code{rec} are aliases of @code{target record}.
5606
5607 @cindex displaced stepping, and process record and replay
5608 Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
5609 will be automatically disabled when process record and replay target
5610 is started. That's because the process record and replay target
5611 doesn't support displaced stepping.
5612
5613 @cindex non-stop mode, and process record and replay
5614 @cindex asynchronous execution, and process record and replay
5615 If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
5616 the asynchronous execution mode (@pxref{Background Execution}), the
5617 process record and replay target cannot be started because it doesn't
5618 support these two modes.
5619
5620 @kindex record stop
5621 @kindex rec s
5622 @item record stop
5623 Stop the process record and replay target. When process record and
5624 replay target stops, the entire execution log will be deleted and the
5625 inferior will either be terminated, or will remain in its final state.
5626
5627 When you stop the process record and replay target in record mode (at
5628 the end of the execution log), the inferior will be stopped at the
5629 next instruction that would have been recorded. In other words, if
5630 you record for a while and then stop recording, the inferior process
5631 will be left in the same state as if the recording never happened.
5632
5633 On the other hand, if the process record and replay target is stopped
5634 while in replay mode (that is, not at the end of the execution log,
5635 but at some earlier point), the inferior process will become ``live''
5636 at that earlier state, and it will then be possible to continue the
5637 usual ``live'' debugging of the process from that state.
5638
5639 When the inferior process exits, or @value{GDBN} detaches from it,
5640 process record and replay target will automatically stop itself.
5641
5642 @kindex record save
5643 @item record save @var{filename}
5644 Save the execution log to a file @file{@var{filename}}.
5645 Default filename is @file{gdb_record.@var{process_id}}, where
5646 @var{process_id} is the process ID of the inferior.
5647
5648 @kindex record restore
5649 @item record restore @var{filename}
5650 Restore the execution log from a file @file{@var{filename}}.
5651 File must have been created with @code{record save}.
5652
5653 @kindex set record insn-number-max
5654 @item set record insn-number-max @var{limit}
5655 Set the limit of instructions to be recorded. Default value is 200000.
5656
5657 If @var{limit} is a positive number, then @value{GDBN} will start
5658 deleting instructions from the log once the number of the record
5659 instructions becomes greater than @var{limit}. For every new recorded
5660 instruction, @value{GDBN} will delete the earliest recorded
5661 instruction to keep the number of recorded instructions at the limit.
5662 (Since deleting recorded instructions loses information, @value{GDBN}
5663 lets you control what happens when the limit is reached, by means of
5664 the @code{stop-at-limit} option, described below.)
5665
5666 If @var{limit} is zero, @value{GDBN} will never delete recorded
5667 instructions from the execution log. The number of recorded
5668 instructions is unlimited in this case.
5669
5670 @kindex show record insn-number-max
5671 @item show record insn-number-max
5672 Show the limit of instructions to be recorded.
5673
5674 @kindex set record stop-at-limit
5675 @item set record stop-at-limit
5676 Control the behavior when the number of recorded instructions reaches
5677 the limit. If ON (the default), @value{GDBN} will stop when the limit
5678 is reached for the first time and ask you whether you want to stop the
5679 inferior or continue running it and recording the execution log. If
5680 you decide to continue recording, each new recorded instruction will
5681 cause the oldest one to be deleted.
5682
5683 If this option is OFF, @value{GDBN} will automatically delete the
5684 oldest record to make room for each new one, without asking.
5685
5686 @kindex show record stop-at-limit
5687 @item show record stop-at-limit
5688 Show the current setting of @code{stop-at-limit}.
5689
5690 @kindex info record
5691 @item info record
5692 Show various statistics about the state of process record and its
5693 in-memory execution log buffer, including:
5694
5695 @itemize @bullet
5696 @item
5697 Whether in record mode or replay mode.
5698 @item
5699 Lowest recorded instruction number (counting from when the current execution log started recording instructions).
5700 @item
5701 Highest recorded instruction number.
5702 @item
5703 Current instruction about to be replayed (if in replay mode).
5704 @item
5705 Number of instructions contained in the execution log.
5706 @item
5707 Maximum number of instructions that may be contained in the execution log.
5708 @end itemize
5709
5710 @kindex record delete
5711 @kindex rec del
5712 @item record delete
5713 When record target runs in replay mode (``in the past''), delete the
5714 subsequent execution log and begin to record a new execution log starting
5715 from the current address. This means you will abandon the previously
5716 recorded ``future'' and begin recording a new ``future''.
5717 @end table
5718
5719
5720 @node Stack
5721 @chapter Examining the Stack
5722
5723 When your program has stopped, the first thing you need to know is where it
5724 stopped and how it got there.
5725
5726 @cindex call stack
5727 Each time your program performs a function call, information about the call
5728 is generated.
5729 That information includes the location of the call in your program,
5730 the arguments of the call,
5731 and the local variables of the function being called.
5732 The information is saved in a block of data called a @dfn{stack frame}.
5733 The stack frames are allocated in a region of memory called the @dfn{call
5734 stack}.
5735
5736 When your program stops, the @value{GDBN} commands for examining the
5737 stack allow you to see all of this information.
5738
5739 @cindex selected frame
5740 One of the stack frames is @dfn{selected} by @value{GDBN} and many
5741 @value{GDBN} commands refer implicitly to the selected frame. In
5742 particular, whenever you ask @value{GDBN} for the value of a variable in
5743 your program, the value is found in the selected frame. There are
5744 special @value{GDBN} commands to select whichever frame you are
5745 interested in. @xref{Selection, ,Selecting a Frame}.
5746
5747 When your program stops, @value{GDBN} automatically selects the
5748 currently executing frame and describes it briefly, similar to the
5749 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
5750
5751 @menu
5752 * Frames:: Stack frames
5753 * Backtrace:: Backtraces
5754 * Selection:: Selecting a frame
5755 * Frame Info:: Information on a frame
5756
5757 @end menu
5758
5759 @node Frames
5760 @section Stack Frames
5761
5762 @cindex frame, definition
5763 @cindex stack frame
5764 The call stack is divided up into contiguous pieces called @dfn{stack
5765 frames}, or @dfn{frames} for short; each frame is the data associated
5766 with one call to one function. The frame contains the arguments given
5767 to the function, the function's local variables, and the address at
5768 which the function is executing.
5769
5770 @cindex initial frame
5771 @cindex outermost frame
5772 @cindex innermost frame
5773 When your program is started, the stack has only one frame, that of the
5774 function @code{main}. This is called the @dfn{initial} frame or the
5775 @dfn{outermost} frame. Each time a function is called, a new frame is
5776 made. Each time a function returns, the frame for that function invocation
5777 is eliminated. If a function is recursive, there can be many frames for
5778 the same function. The frame for the function in which execution is
5779 actually occurring is called the @dfn{innermost} frame. This is the most
5780 recently created of all the stack frames that still exist.
5781
5782 @cindex frame pointer
5783 Inside your program, stack frames are identified by their addresses. A
5784 stack frame consists of many bytes, each of which has its own address; each
5785 kind of computer has a convention for choosing one byte whose
5786 address serves as the address of the frame. Usually this address is kept
5787 in a register called the @dfn{frame pointer register}
5788 (@pxref{Registers, $fp}) while execution is going on in that frame.
5789
5790 @cindex frame number
5791 @value{GDBN} assigns numbers to all existing stack frames, starting with
5792 zero for the innermost frame, one for the frame that called it,
5793 and so on upward. These numbers do not really exist in your program;
5794 they are assigned by @value{GDBN} to give you a way of designating stack
5795 frames in @value{GDBN} commands.
5796
5797 @c The -fomit-frame-pointer below perennially causes hbox overflow
5798 @c underflow problems.
5799 @cindex frameless execution
5800 Some compilers provide a way to compile functions so that they operate
5801 without stack frames. (For example, the @value{NGCC} option
5802 @smallexample
5803 @samp{-fomit-frame-pointer}
5804 @end smallexample
5805 generates functions without a frame.)
5806 This is occasionally done with heavily used library functions to save
5807 the frame setup time. @value{GDBN} has limited facilities for dealing
5808 with these function invocations. If the innermost function invocation
5809 has no stack frame, @value{GDBN} nevertheless regards it as though
5810 it had a separate frame, which is numbered zero as usual, allowing
5811 correct tracing of the function call chain. However, @value{GDBN} has
5812 no provision for frameless functions elsewhere in the stack.
5813
5814 @table @code
5815 @kindex frame@r{, command}
5816 @cindex current stack frame
5817 @item frame @var{args}
5818 The @code{frame} command allows you to move from one stack frame to another,
5819 and to print the stack frame you select. @var{args} may be either the
5820 address of the frame or the stack frame number. Without an argument,
5821 @code{frame} prints the current stack frame.
5822
5823 @kindex select-frame
5824 @cindex selecting frame silently
5825 @item select-frame
5826 The @code{select-frame} command allows you to move from one stack frame
5827 to another without printing the frame. This is the silent version of
5828 @code{frame}.
5829 @end table
5830
5831 @node Backtrace
5832 @section Backtraces
5833
5834 @cindex traceback
5835 @cindex call stack traces
5836 A backtrace is a summary of how your program got where it is. It shows one
5837 line per frame, for many frames, starting with the currently executing
5838 frame (frame zero), followed by its caller (frame one), and on up the
5839 stack.
5840
5841 @table @code
5842 @kindex backtrace
5843 @kindex bt @r{(@code{backtrace})}
5844 @item backtrace
5845 @itemx bt
5846 Print a backtrace of the entire stack: one line per frame for all
5847 frames in the stack.
5848
5849 You can stop the backtrace at any time by typing the system interrupt
5850 character, normally @kbd{Ctrl-c}.
5851
5852 @item backtrace @var{n}
5853 @itemx bt @var{n}
5854 Similar, but print only the innermost @var{n} frames.
5855
5856 @item backtrace -@var{n}
5857 @itemx bt -@var{n}
5858 Similar, but print only the outermost @var{n} frames.
5859
5860 @item backtrace full
5861 @itemx bt full
5862 @itemx bt full @var{n}
5863 @itemx bt full -@var{n}
5864 Print the values of the local variables also. @var{n} specifies the
5865 number of frames to print, as described above.
5866 @end table
5867
5868 @kindex where
5869 @kindex info stack
5870 The names @code{where} and @code{info stack} (abbreviated @code{info s})
5871 are additional aliases for @code{backtrace}.
5872
5873 @cindex multiple threads, backtrace
5874 In a multi-threaded program, @value{GDBN} by default shows the
5875 backtrace only for the current thread. To display the backtrace for
5876 several or all of the threads, use the command @code{thread apply}
5877 (@pxref{Threads, thread apply}). For example, if you type @kbd{thread
5878 apply all backtrace}, @value{GDBN} will display the backtrace for all
5879 the threads; this is handy when you debug a core dump of a
5880 multi-threaded program.
5881
5882 Each line in the backtrace shows the frame number and the function name.
5883 The program counter value is also shown---unless you use @code{set
5884 print address off}. The backtrace also shows the source file name and
5885 line number, as well as the arguments to the function. The program
5886 counter value is omitted if it is at the beginning of the code for that
5887 line number.
5888
5889 Here is an example of a backtrace. It was made with the command
5890 @samp{bt 3}, so it shows the innermost three frames.
5891
5892 @smallexample
5893 @group
5894 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
5895 at builtin.c:993
5896 #1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
5897 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
5898 at macro.c:71
5899 (More stack frames follow...)
5900 @end group
5901 @end smallexample
5902
5903 @noindent
5904 The display for frame zero does not begin with a program counter
5905 value, indicating that your program has stopped at the beginning of the
5906 code for line @code{993} of @code{builtin.c}.
5907
5908 @noindent
5909 The value of parameter @code{data} in frame 1 has been replaced by
5910 @code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
5911 only if it is a scalar (integer, pointer, enumeration, etc). See command
5912 @kbd{set print frame-arguments} in @ref{Print Settings} for more details
5913 on how to configure the way function parameter values are printed.
5914
5915 @cindex value optimized out, in backtrace
5916 @cindex function call arguments, optimized out
5917 If your program was compiled with optimizations, some compilers will
5918 optimize away arguments passed to functions if those arguments are
5919 never used after the call. Such optimizations generate code that
5920 passes arguments through registers, but doesn't store those arguments
5921 in the stack frame. @value{GDBN} has no way of displaying such
5922 arguments in stack frames other than the innermost one. Here's what
5923 such a backtrace might look like:
5924
5925 @smallexample
5926 @group
5927 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
5928 at builtin.c:993
5929 #1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
5930 #2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
5931 at macro.c:71
5932 (More stack frames follow...)
5933 @end group
5934 @end smallexample
5935
5936 @noindent
5937 The values of arguments that were not saved in their stack frames are
5938 shown as @samp{<value optimized out>}.
5939
5940 If you need to display the values of such optimized-out arguments,
5941 either deduce that from other variables whose values depend on the one
5942 you are interested in, or recompile without optimizations.
5943
5944 @cindex backtrace beyond @code{main} function
5945 @cindex program entry point
5946 @cindex startup code, and backtrace
5947 Most programs have a standard user entry point---a place where system
5948 libraries and startup code transition into user code. For C this is
5949 @code{main}@footnote{
5950 Note that embedded programs (the so-called ``free-standing''
5951 environment) are not required to have a @code{main} function as the
5952 entry point. They could even have multiple entry points.}.
5953 When @value{GDBN} finds the entry function in a backtrace
5954 it will terminate the backtrace, to avoid tracing into highly
5955 system-specific (and generally uninteresting) code.
5956
5957 If you need to examine the startup code, or limit the number of levels
5958 in a backtrace, you can change this behavior:
5959
5960 @table @code
5961 @item set backtrace past-main
5962 @itemx set backtrace past-main on
5963 @kindex set backtrace
5964 Backtraces will continue past the user entry point.
5965
5966 @item set backtrace past-main off
5967 Backtraces will stop when they encounter the user entry point. This is the
5968 default.
5969
5970 @item show backtrace past-main
5971 @kindex show backtrace
5972 Display the current user entry point backtrace policy.
5973
5974 @item set backtrace past-entry
5975 @itemx set backtrace past-entry on
5976 Backtraces will continue past the internal entry point of an application.
5977 This entry point is encoded by the linker when the application is built,
5978 and is likely before the user entry point @code{main} (or equivalent) is called.
5979
5980 @item set backtrace past-entry off
5981 Backtraces will stop when they encounter the internal entry point of an
5982 application. This is the default.
5983
5984 @item show backtrace past-entry
5985 Display the current internal entry point backtrace policy.
5986
5987 @item set backtrace limit @var{n}
5988 @itemx set backtrace limit 0
5989 @cindex backtrace limit
5990 Limit the backtrace to @var{n} levels. A value of zero means
5991 unlimited.
5992
5993 @item show backtrace limit
5994 Display the current limit on backtrace levels.
5995 @end table
5996
5997 @node Selection
5998 @section Selecting a Frame
5999
6000 Most commands for examining the stack and other data in your program work on
6001 whichever stack frame is selected at the moment. Here are the commands for
6002 selecting a stack frame; all of them finish by printing a brief description
6003 of the stack frame just selected.
6004
6005 @table @code
6006 @kindex frame@r{, selecting}
6007 @kindex f @r{(@code{frame})}
6008 @item frame @var{n}
6009 @itemx f @var{n}
6010 Select frame number @var{n}. Recall that frame zero is the innermost
6011 (currently executing) frame, frame one is the frame that called the
6012 innermost one, and so on. The highest-numbered frame is the one for
6013 @code{main}.
6014
6015 @item frame @var{addr}
6016 @itemx f @var{addr}
6017 Select the frame at address @var{addr}. This is useful mainly if the
6018 chaining of stack frames has been damaged by a bug, making it
6019 impossible for @value{GDBN} to assign numbers properly to all frames. In
6020 addition, this can be useful when your program has multiple stacks and
6021 switches between them.
6022
6023 On the SPARC architecture, @code{frame} needs two addresses to
6024 select an arbitrary frame: a frame pointer and a stack pointer.
6025
6026 On the MIPS and Alpha architecture, it needs two addresses: a stack
6027 pointer and a program counter.
6028
6029 On the 29k architecture, it needs three addresses: a register stack
6030 pointer, a program counter, and a memory stack pointer.
6031
6032 @kindex up
6033 @item up @var{n}
6034 Move @var{n} frames up the stack. For positive numbers @var{n}, this
6035 advances toward the outermost frame, to higher frame numbers, to frames
6036 that have existed longer. @var{n} defaults to one.
6037
6038 @kindex down
6039 @kindex do @r{(@code{down})}
6040 @item down @var{n}
6041 Move @var{n} frames down the stack. For positive numbers @var{n}, this
6042 advances toward the innermost frame, to lower frame numbers, to frames
6043 that were created more recently. @var{n} defaults to one. You may
6044 abbreviate @code{down} as @code{do}.
6045 @end table
6046
6047 All of these commands end by printing two lines of output describing the
6048 frame. The first line shows the frame number, the function name, the
6049 arguments, and the source file and line number of execution in that
6050 frame. The second line shows the text of that source line.
6051
6052 @need 1000
6053 For example:
6054
6055 @smallexample
6056 @group
6057 (@value{GDBP}) up
6058 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
6059 at env.c:10
6060 10 read_input_file (argv[i]);
6061 @end group
6062 @end smallexample
6063
6064 After such a printout, the @code{list} command with no arguments
6065 prints ten lines centered on the point of execution in the frame.
6066 You can also edit the program at the point of execution with your favorite
6067 editing program by typing @code{edit}.
6068 @xref{List, ,Printing Source Lines},
6069 for details.
6070
6071 @table @code
6072 @kindex down-silently
6073 @kindex up-silently
6074 @item up-silently @var{n}
6075 @itemx down-silently @var{n}
6076 These two commands are variants of @code{up} and @code{down},
6077 respectively; they differ in that they do their work silently, without
6078 causing display of the new frame. They are intended primarily for use
6079 in @value{GDBN} command scripts, where the output might be unnecessary and
6080 distracting.
6081 @end table
6082
6083 @node Frame Info
6084 @section Information About a Frame
6085
6086 There are several other commands to print information about the selected
6087 stack frame.
6088
6089 @table @code
6090 @item frame
6091 @itemx f
6092 When used without any argument, this command does not change which
6093 frame is selected, but prints a brief description of the currently
6094 selected stack frame. It can be abbreviated @code{f}. With an
6095 argument, this command is used to select a stack frame.
6096 @xref{Selection, ,Selecting a Frame}.
6097
6098 @kindex info frame
6099 @kindex info f @r{(@code{info frame})}
6100 @item info frame
6101 @itemx info f
6102 This command prints a verbose description of the selected stack frame,
6103 including:
6104
6105 @itemize @bullet
6106 @item
6107 the address of the frame
6108 @item
6109 the address of the next frame down (called by this frame)
6110 @item
6111 the address of the next frame up (caller of this frame)
6112 @item
6113 the language in which the source code corresponding to this frame is written
6114 @item
6115 the address of the frame's arguments
6116 @item
6117 the address of the frame's local variables
6118 @item
6119 the program counter saved in it (the address of execution in the caller frame)
6120 @item
6121 which registers were saved in the frame
6122 @end itemize
6123
6124 @noindent The verbose description is useful when
6125 something has gone wrong that has made the stack format fail to fit
6126 the usual conventions.
6127
6128 @item info frame @var{addr}
6129 @itemx info f @var{addr}
6130 Print a verbose description of the frame at address @var{addr}, without
6131 selecting that frame. The selected frame remains unchanged by this
6132 command. This requires the same kind of address (more than one for some
6133 architectures) that you specify in the @code{frame} command.
6134 @xref{Selection, ,Selecting a Frame}.
6135
6136 @kindex info args
6137 @item info args
6138 Print the arguments of the selected frame, each on a separate line.
6139
6140 @item info locals
6141 @kindex info locals
6142 Print the local variables of the selected frame, each on a separate
6143 line. These are all variables (declared either static or automatic)
6144 accessible at the point of execution of the selected frame.
6145
6146 @kindex info catch
6147 @cindex catch exceptions, list active handlers
6148 @cindex exception handlers, how to list
6149 @item info catch
6150 Print a list of all the exception handlers that are active in the
6151 current stack frame at the current point of execution. To see other
6152 exception handlers, visit the associated frame (using the @code{up},
6153 @code{down}, or @code{frame} commands); then type @code{info catch}.
6154 @xref{Set Catchpoints, , Setting Catchpoints}.
6155
6156 @end table
6157
6158
6159 @node Source
6160 @chapter Examining Source Files
6161
6162 @value{GDBN} can print parts of your program's source, since the debugging
6163 information recorded in the program tells @value{GDBN} what source files were
6164 used to build it. When your program stops, @value{GDBN} spontaneously prints
6165 the line where it stopped. Likewise, when you select a stack frame
6166 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
6167 execution in that frame has stopped. You can print other portions of
6168 source files by explicit command.
6169
6170 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
6171 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
6172 @value{GDBN} under @sc{gnu} Emacs}.
6173
6174 @menu
6175 * List:: Printing source lines
6176 * Specify Location:: How to specify code locations
6177 * Edit:: Editing source files
6178 * Search:: Searching source files
6179 * Source Path:: Specifying source directories
6180 * Machine Code:: Source and machine code
6181 @end menu
6182
6183 @node List
6184 @section Printing Source Lines
6185
6186 @kindex list
6187 @kindex l @r{(@code{list})}
6188 To print lines from a source file, use the @code{list} command
6189 (abbreviated @code{l}). By default, ten lines are printed.
6190 There are several ways to specify what part of the file you want to
6191 print; see @ref{Specify Location}, for the full list.
6192
6193 Here are the forms of the @code{list} command most commonly used:
6194
6195 @table @code
6196 @item list @var{linenum}
6197 Print lines centered around line number @var{linenum} in the
6198 current source file.
6199
6200 @item list @var{function}
6201 Print lines centered around the beginning of function
6202 @var{function}.
6203
6204 @item list
6205 Print more lines. If the last lines printed were printed with a
6206 @code{list} command, this prints lines following the last lines
6207 printed; however, if the last line printed was a solitary line printed
6208 as part of displaying a stack frame (@pxref{Stack, ,Examining the
6209 Stack}), this prints lines centered around that line.
6210
6211 @item list -
6212 Print lines just before the lines last printed.
6213 @end table
6214
6215 @cindex @code{list}, how many lines to display
6216 By default, @value{GDBN} prints ten source lines with any of these forms of
6217 the @code{list} command. You can change this using @code{set listsize}:
6218
6219 @table @code
6220 @kindex set listsize
6221 @item set listsize @var{count}
6222 Make the @code{list} command display @var{count} source lines (unless
6223 the @code{list} argument explicitly specifies some other number).
6224
6225 @kindex show listsize
6226 @item show listsize
6227 Display the number of lines that @code{list} prints.
6228 @end table
6229
6230 Repeating a @code{list} command with @key{RET} discards the argument,
6231 so it is equivalent to typing just @code{list}. This is more useful
6232 than listing the same lines again. An exception is made for an
6233 argument of @samp{-}; that argument is preserved in repetition so that
6234 each repetition moves up in the source file.
6235
6236 In general, the @code{list} command expects you to supply zero, one or two
6237 @dfn{linespecs}. Linespecs specify source lines; there are several ways
6238 of writing them (@pxref{Specify Location}), but the effect is always
6239 to specify some source line.
6240
6241 Here is a complete description of the possible arguments for @code{list}:
6242
6243 @table @code
6244 @item list @var{linespec}
6245 Print lines centered around the line specified by @var{linespec}.
6246
6247 @item list @var{first},@var{last}
6248 Print lines from @var{first} to @var{last}. Both arguments are
6249 linespecs. When a @code{list} command has two linespecs, and the
6250 source file of the second linespec is omitted, this refers to
6251 the same source file as the first linespec.
6252
6253 @item list ,@var{last}
6254 Print lines ending with @var{last}.
6255
6256 @item list @var{first},
6257 Print lines starting with @var{first}.
6258
6259 @item list +
6260 Print lines just after the lines last printed.
6261
6262 @item list -
6263 Print lines just before the lines last printed.
6264
6265 @item list
6266 As described in the preceding table.
6267 @end table
6268
6269 @node Specify Location
6270 @section Specifying a Location
6271 @cindex specifying location
6272 @cindex linespec
6273
6274 Several @value{GDBN} commands accept arguments that specify a location
6275 of your program's code. Since @value{GDBN} is a source-level
6276 debugger, a location usually specifies some line in the source code;
6277 for that reason, locations are also known as @dfn{linespecs}.
6278
6279 Here are all the different ways of specifying a code location that
6280 @value{GDBN} understands:
6281
6282 @table @code
6283 @item @var{linenum}
6284 Specifies the line number @var{linenum} of the current source file.
6285
6286 @item -@var{offset}
6287 @itemx +@var{offset}
6288 Specifies the line @var{offset} lines before or after the @dfn{current
6289 line}. For the @code{list} command, the current line is the last one
6290 printed; for the breakpoint commands, this is the line at which
6291 execution stopped in the currently selected @dfn{stack frame}
6292 (@pxref{Frames, ,Frames}, for a description of stack frames.) When
6293 used as the second of the two linespecs in a @code{list} command,
6294 this specifies the line @var{offset} lines up or down from the first
6295 linespec.
6296
6297 @item @var{filename}:@var{linenum}
6298 Specifies the line @var{linenum} in the source file @var{filename}.
6299
6300 @item @var{function}
6301 Specifies the line that begins the body of the function @var{function}.
6302 For example, in C, this is the line with the open brace.
6303
6304 @item @var{filename}:@var{function}
6305 Specifies the line that begins the body of the function @var{function}
6306 in the file @var{filename}. You only need the file name with a
6307 function name to avoid ambiguity when there are identically named
6308 functions in different source files.
6309
6310 @item *@var{address}
6311 Specifies the program address @var{address}. For line-oriented
6312 commands, such as @code{list} and @code{edit}, this specifies a source
6313 line that contains @var{address}. For @code{break} and other
6314 breakpoint oriented commands, this can be used to set breakpoints in
6315 parts of your program which do not have debugging information or
6316 source files.
6317
6318 Here @var{address} may be any expression valid in the current working
6319 language (@pxref{Languages, working language}) that specifies a code
6320 address. In addition, as a convenience, @value{GDBN} extends the
6321 semantics of expressions used in locations to cover the situations
6322 that frequently happen during debugging. Here are the various forms
6323 of @var{address}:
6324
6325 @table @code
6326 @item @var{expression}
6327 Any expression valid in the current working language.
6328
6329 @item @var{funcaddr}
6330 An address of a function or procedure derived from its name. In C,
6331 C@t{++}, Java, Objective-C, Fortran, minimal, and assembly, this is
6332 simply the function's name @var{function} (and actually a special case
6333 of a valid expression). In Pascal and Modula-2, this is
6334 @code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
6335 (although the Pascal form also works).
6336
6337 This form specifies the address of the function's first instruction,
6338 before the stack frame and arguments have been set up.
6339
6340 @item '@var{filename}'::@var{funcaddr}
6341 Like @var{funcaddr} above, but also specifies the name of the source
6342 file explicitly. This is useful if the name of the function does not
6343 specify the function unambiguously, e.g., if there are several
6344 functions with identical names in different source files.
6345 @end table
6346
6347 @end table
6348
6349
6350 @node Edit
6351 @section Editing Source Files
6352 @cindex editing source files
6353
6354 @kindex edit
6355 @kindex e @r{(@code{edit})}
6356 To edit the lines in a source file, use the @code{edit} command.
6357 The editing program of your choice
6358 is invoked with the current line set to
6359 the active line in the program.
6360 Alternatively, there are several ways to specify what part of the file you
6361 want to print if you want to see other parts of the program:
6362
6363 @table @code
6364 @item edit @var{location}
6365 Edit the source file specified by @code{location}. Editing starts at
6366 that @var{location}, e.g., at the specified source line of the
6367 specified file. @xref{Specify Location}, for all the possible forms
6368 of the @var{location} argument; here are the forms of the @code{edit}
6369 command most commonly used:
6370
6371 @table @code
6372 @item edit @var{number}
6373 Edit the current source file with @var{number} as the active line number.
6374
6375 @item edit @var{function}
6376 Edit the file containing @var{function} at the beginning of its definition.
6377 @end table
6378
6379 @end table
6380
6381 @subsection Choosing your Editor
6382 You can customize @value{GDBN} to use any editor you want
6383 @footnote{
6384 The only restriction is that your editor (say @code{ex}), recognizes the
6385 following command-line syntax:
6386 @smallexample
6387 ex +@var{number} file
6388 @end smallexample
6389 The optional numeric value +@var{number} specifies the number of the line in
6390 the file where to start editing.}.
6391 By default, it is @file{@value{EDITOR}}, but you can change this
6392 by setting the environment variable @code{EDITOR} before using
6393 @value{GDBN}. For example, to configure @value{GDBN} to use the
6394 @code{vi} editor, you could use these commands with the @code{sh} shell:
6395 @smallexample
6396 EDITOR=/usr/bin/vi
6397 export EDITOR
6398 gdb @dots{}
6399 @end smallexample
6400 or in the @code{csh} shell,
6401 @smallexample
6402 setenv EDITOR /usr/bin/vi
6403 gdb @dots{}
6404 @end smallexample
6405
6406 @node Search
6407 @section Searching Source Files
6408 @cindex searching source files
6409
6410 There are two commands for searching through the current source file for a
6411 regular expression.
6412
6413 @table @code
6414 @kindex search
6415 @kindex forward-search
6416 @item forward-search @var{regexp}
6417 @itemx search @var{regexp}
6418 The command @samp{forward-search @var{regexp}} checks each line,
6419 starting with the one following the last line listed, for a match for
6420 @var{regexp}. It lists the line that is found. You can use the
6421 synonym @samp{search @var{regexp}} or abbreviate the command name as
6422 @code{fo}.
6423
6424 @kindex reverse-search
6425 @item reverse-search @var{regexp}
6426 The command @samp{reverse-search @var{regexp}} checks each line, starting
6427 with the one before the last line listed and going backward, for a match
6428 for @var{regexp}. It lists the line that is found. You can abbreviate
6429 this command as @code{rev}.
6430 @end table
6431
6432 @node Source Path
6433 @section Specifying Source Directories
6434
6435 @cindex source path
6436 @cindex directories for source files
6437 Executable programs sometimes do not record the directories of the source
6438 files from which they were compiled, just the names. Even when they do,
6439 the directories could be moved between the compilation and your debugging
6440 session. @value{GDBN} has a list of directories to search for source files;
6441 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
6442 it tries all the directories in the list, in the order they are present
6443 in the list, until it finds a file with the desired name.
6444
6445 For example, suppose an executable references the file
6446 @file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
6447 @file{/mnt/cross}. The file is first looked up literally; if this
6448 fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
6449 fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
6450 message is printed. @value{GDBN} does not look up the parts of the
6451 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
6452 Likewise, the subdirectories of the source path are not searched: if
6453 the source path is @file{/mnt/cross}, and the binary refers to
6454 @file{foo.c}, @value{GDBN} would not find it under
6455 @file{/mnt/cross/usr/src/foo-1.0/lib}.
6456
6457 Plain file names, relative file names with leading directories, file
6458 names containing dots, etc.@: are all treated as described above; for
6459 instance, if the source path is @file{/mnt/cross}, and the source file
6460 is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
6461 @file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
6462 that---@file{/mnt/cross/foo.c}.
6463
6464 Note that the executable search path is @emph{not} used to locate the
6465 source files.
6466
6467 Whenever you reset or rearrange the source path, @value{GDBN} clears out
6468 any information it has cached about where source files are found and where
6469 each line is in the file.
6470
6471 @kindex directory
6472 @kindex dir
6473 When you start @value{GDBN}, its source path includes only @samp{cdir}
6474 and @samp{cwd}, in that order.
6475 To add other directories, use the @code{directory} command.
6476
6477 The search path is used to find both program source files and @value{GDBN}
6478 script files (read using the @samp{-command} option and @samp{source} command).
6479
6480 In addition to the source path, @value{GDBN} provides a set of commands
6481 that manage a list of source path substitution rules. A @dfn{substitution
6482 rule} specifies how to rewrite source directories stored in the program's
6483 debug information in case the sources were moved to a different
6484 directory between compilation and debugging. A rule is made of
6485 two strings, the first specifying what needs to be rewritten in
6486 the path, and the second specifying how it should be rewritten.
6487 In @ref{set substitute-path}, we name these two parts @var{from} and
6488 @var{to} respectively. @value{GDBN} does a simple string replacement
6489 of @var{from} with @var{to} at the start of the directory part of the
6490 source file name, and uses that result instead of the original file
6491 name to look up the sources.
6492
6493 Using the previous example, suppose the @file{foo-1.0} tree has been
6494 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
6495 @value{GDBN} to replace @file{/usr/src} in all source path names with
6496 @file{/mnt/cross}. The first lookup will then be
6497 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
6498 of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
6499 substitution rule, use the @code{set substitute-path} command
6500 (@pxref{set substitute-path}).
6501
6502 To avoid unexpected substitution results, a rule is applied only if the
6503 @var{from} part of the directory name ends at a directory separator.
6504 For instance, a rule substituting @file{/usr/source} into
6505 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
6506 not to @file{/usr/sourceware/foo-2.0}. And because the substitution
6507 is applied only at the beginning of the directory name, this rule will
6508 not be applied to @file{/root/usr/source/baz.c} either.
6509
6510 In many cases, you can achieve the same result using the @code{directory}
6511 command. However, @code{set substitute-path} can be more efficient in
6512 the case where the sources are organized in a complex tree with multiple
6513 subdirectories. With the @code{directory} command, you need to add each
6514 subdirectory of your project. If you moved the entire tree while
6515 preserving its internal organization, then @code{set substitute-path}
6516 allows you to direct the debugger to all the sources with one single
6517 command.
6518
6519 @code{set substitute-path} is also more than just a shortcut command.
6520 The source path is only used if the file at the original location no
6521 longer exists. On the other hand, @code{set substitute-path} modifies
6522 the debugger behavior to look at the rewritten location instead. So, if
6523 for any reason a source file that is not relevant to your executable is
6524 located at the original location, a substitution rule is the only
6525 method available to point @value{GDBN} at the new location.
6526
6527 @cindex @samp{--with-relocated-sources}
6528 @cindex default source path substitution
6529 You can configure a default source path substitution rule by
6530 configuring @value{GDBN} with the
6531 @samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
6532 should be the name of a directory under @value{GDBN}'s configured
6533 prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
6534 directory names in debug information under @var{dir} will be adjusted
6535 automatically if the installed @value{GDBN} is moved to a new
6536 location. This is useful if @value{GDBN}, libraries or executables
6537 with debug information and corresponding source code are being moved
6538 together.
6539
6540 @table @code
6541 @item directory @var{dirname} @dots{}
6542 @item dir @var{dirname} @dots{}
6543 Add directory @var{dirname} to the front of the source path. Several
6544 directory names may be given to this command, separated by @samp{:}
6545 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
6546 part of absolute file names) or
6547 whitespace. You may specify a directory that is already in the source
6548 path; this moves it forward, so @value{GDBN} searches it sooner.
6549
6550 @kindex cdir
6551 @kindex cwd
6552 @vindex $cdir@r{, convenience variable}
6553 @vindex $cwd@r{, convenience variable}
6554 @cindex compilation directory
6555 @cindex current directory
6556 @cindex working directory
6557 @cindex directory, current
6558 @cindex directory, compilation
6559 You can use the string @samp{$cdir} to refer to the compilation
6560 directory (if one is recorded), and @samp{$cwd} to refer to the current
6561 working directory. @samp{$cwd} is not the same as @samp{.}---the former
6562 tracks the current working directory as it changes during your @value{GDBN}
6563 session, while the latter is immediately expanded to the current
6564 directory at the time you add an entry to the source path.
6565
6566 @item directory
6567 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
6568
6569 @c RET-repeat for @code{directory} is explicitly disabled, but since
6570 @c repeating it would be a no-op we do not say that. (thanks to RMS)
6571
6572 @item show directories
6573 @kindex show directories
6574 Print the source path: show which directories it contains.
6575
6576 @anchor{set substitute-path}
6577 @item set substitute-path @var{from} @var{to}
6578 @kindex set substitute-path
6579 Define a source path substitution rule, and add it at the end of the
6580 current list of existing substitution rules. If a rule with the same
6581 @var{from} was already defined, then the old rule is also deleted.
6582
6583 For example, if the file @file{/foo/bar/baz.c} was moved to
6584 @file{/mnt/cross/baz.c}, then the command
6585
6586 @smallexample
6587 (@value{GDBP}) set substitute-path /usr/src /mnt/cross
6588 @end smallexample
6589
6590 @noindent
6591 will tell @value{GDBN} to replace @samp{/usr/src} with
6592 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
6593 @file{baz.c} even though it was moved.
6594
6595 In the case when more than one substitution rule have been defined,
6596 the rules are evaluated one by one in the order where they have been
6597 defined. The first one matching, if any, is selected to perform
6598 the substitution.
6599
6600 For instance, if we had entered the following commands:
6601
6602 @smallexample
6603 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
6604 (@value{GDBP}) set substitute-path /usr/src /mnt/src
6605 @end smallexample
6606
6607 @noindent
6608 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
6609 @file{/mnt/include/defs.h} by using the first rule. However, it would
6610 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
6611 @file{/mnt/src/lib/foo.c}.
6612
6613
6614 @item unset substitute-path [path]
6615 @kindex unset substitute-path
6616 If a path is specified, search the current list of substitution rules
6617 for a rule that would rewrite that path. Delete that rule if found.
6618 A warning is emitted by the debugger if no rule could be found.
6619
6620 If no path is specified, then all substitution rules are deleted.
6621
6622 @item show substitute-path [path]
6623 @kindex show substitute-path
6624 If a path is specified, then print the source path substitution rule
6625 which would rewrite that path, if any.
6626
6627 If no path is specified, then print all existing source path substitution
6628 rules.
6629
6630 @end table
6631
6632 If your source path is cluttered with directories that are no longer of
6633 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
6634 versions of source. You can correct the situation as follows:
6635
6636 @enumerate
6637 @item
6638 Use @code{directory} with no argument to reset the source path to its default value.
6639
6640 @item
6641 Use @code{directory} with suitable arguments to reinstall the
6642 directories you want in the source path. You can add all the
6643 directories in one command.
6644 @end enumerate
6645
6646 @node Machine Code
6647 @section Source and Machine Code
6648 @cindex source line and its code address
6649
6650 You can use the command @code{info line} to map source lines to program
6651 addresses (and vice versa), and the command @code{disassemble} to display
6652 a range of addresses as machine instructions. You can use the command
6653 @code{set disassemble-next-line} to set whether to disassemble next
6654 source line when execution stops. When run under @sc{gnu} Emacs
6655 mode, the @code{info line} command causes the arrow to point to the
6656 line specified. Also, @code{info line} prints addresses in symbolic form as
6657 well as hex.
6658
6659 @table @code
6660 @kindex info line
6661 @item info line @var{linespec}
6662 Print the starting and ending addresses of the compiled code for
6663 source line @var{linespec}. You can specify source lines in any of
6664 the ways documented in @ref{Specify Location}.
6665 @end table
6666
6667 For example, we can use @code{info line} to discover the location of
6668 the object code for the first line of function
6669 @code{m4_changequote}:
6670
6671 @c FIXME: I think this example should also show the addresses in
6672 @c symbolic form, as they usually would be displayed.
6673 @smallexample
6674 (@value{GDBP}) info line m4_changequote
6675 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
6676 @end smallexample
6677
6678 @noindent
6679 @cindex code address and its source line
6680 We can also inquire (using @code{*@var{addr}} as the form for
6681 @var{linespec}) what source line covers a particular address:
6682 @smallexample
6683 (@value{GDBP}) info line *0x63ff
6684 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
6685 @end smallexample
6686
6687 @cindex @code{$_} and @code{info line}
6688 @cindex @code{x} command, default address
6689 @kindex x@r{(examine), and} info line
6690 After @code{info line}, the default address for the @code{x} command
6691 is changed to the starting address of the line, so that @samp{x/i} is
6692 sufficient to begin examining the machine code (@pxref{Memory,
6693 ,Examining Memory}). Also, this address is saved as the value of the
6694 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
6695 Variables}).
6696
6697 @table @code
6698 @kindex disassemble
6699 @cindex assembly instructions
6700 @cindex instructions, assembly
6701 @cindex machine instructions
6702 @cindex listing machine instructions
6703 @item disassemble
6704 @itemx disassemble /m
6705 @itemx disassemble /r
6706 This specialized command dumps a range of memory as machine
6707 instructions. It can also print mixed source+disassembly by specifying
6708 the @code{/m} modifier and print the raw instructions in hex as well as
6709 in symbolic form by specifying the @code{/r}.
6710 The default memory range is the function surrounding the
6711 program counter of the selected frame. A single argument to this
6712 command is a program counter value; @value{GDBN} dumps the function
6713 surrounding this value. When two arguments are given, they should
6714 be separated by a comma, possibly surrounded by whitespace. The
6715 arguments specify a range of addresses (first inclusive, second exclusive)
6716 to dump. In that case, the name of the function is also printed (since
6717 there could be several functions in the given range).
6718
6719 The argument(s) can be any expression yielding a numeric value, such as
6720 @samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
6721
6722 If the range of memory being disassembled contains current program counter,
6723 the instruction at that location is shown with a @code{=>} marker.
6724 @end table
6725
6726 The following example shows the disassembly of a range of addresses of
6727 HP PA-RISC 2.0 code:
6728
6729 @smallexample
6730 (@value{GDBP}) disas 0x32c4, 0x32e4
6731 Dump of assembler code from 0x32c4 to 0x32e4:
6732 0x32c4 <main+204>: addil 0,dp
6733 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
6734 0x32cc <main+212>: ldil 0x3000,r31
6735 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
6736 0x32d4 <main+220>: ldo 0(r31),rp
6737 0x32d8 <main+224>: addil -0x800,dp
6738 0x32dc <main+228>: ldo 0x588(r1),r26
6739 0x32e0 <main+232>: ldil 0x3000,r31
6740 End of assembler dump.
6741 @end smallexample
6742
6743 Here is an example showing mixed source+assembly for Intel x86, when the
6744 program is stopped just after function prologue:
6745
6746 @smallexample
6747 (@value{GDBP}) disas /m main
6748 Dump of assembler code for function main:
6749 5 @{
6750 0x08048330 <+0>: push %ebp
6751 0x08048331 <+1>: mov %esp,%ebp
6752 0x08048333 <+3>: sub $0x8,%esp
6753 0x08048336 <+6>: and $0xfffffff0,%esp
6754 0x08048339 <+9>: sub $0x10,%esp
6755
6756 6 printf ("Hello.\n");
6757 => 0x0804833c <+12>: movl $0x8048440,(%esp)
6758 0x08048343 <+19>: call 0x8048284 <puts@@plt>
6759
6760 7 return 0;
6761 8 @}
6762 0x08048348 <+24>: mov $0x0,%eax
6763 0x0804834d <+29>: leave
6764 0x0804834e <+30>: ret
6765
6766 End of assembler dump.
6767 @end smallexample
6768
6769 Some architectures have more than one commonly-used set of instruction
6770 mnemonics or other syntax.
6771
6772 For programs that were dynamically linked and use shared libraries,
6773 instructions that call functions or branch to locations in the shared
6774 libraries might show a seemingly bogus location---it's actually a
6775 location of the relocation table. On some architectures, @value{GDBN}
6776 might be able to resolve these to actual function names.
6777
6778 @table @code
6779 @kindex set disassembly-flavor
6780 @cindex Intel disassembly flavor
6781 @cindex AT&T disassembly flavor
6782 @item set disassembly-flavor @var{instruction-set}
6783 Select the instruction set to use when disassembling the
6784 program via the @code{disassemble} or @code{x/i} commands.
6785
6786 Currently this command is only defined for the Intel x86 family. You
6787 can set @var{instruction-set} to either @code{intel} or @code{att}.
6788 The default is @code{att}, the AT&T flavor used by default by Unix
6789 assemblers for x86-based targets.
6790
6791 @kindex show disassembly-flavor
6792 @item show disassembly-flavor
6793 Show the current setting of the disassembly flavor.
6794 @end table
6795
6796 @table @code
6797 @kindex set disassemble-next-line
6798 @kindex show disassemble-next-line
6799 @item set disassemble-next-line
6800 @itemx show disassemble-next-line
6801 Control whether or not @value{GDBN} will disassemble the next source
6802 line or instruction when execution stops. If ON, @value{GDBN} will
6803 display disassembly of the next source line when execution of the
6804 program being debugged stops. This is @emph{in addition} to
6805 displaying the source line itself, which @value{GDBN} always does if
6806 possible. If the next source line cannot be displayed for some reason
6807 (e.g., if @value{GDBN} cannot find the source file, or there's no line
6808 info in the debug info), @value{GDBN} will display disassembly of the
6809 next @emph{instruction} instead of showing the next source line. If
6810 AUTO, @value{GDBN} will display disassembly of next instruction only
6811 if the source line cannot be displayed. This setting causes
6812 @value{GDBN} to display some feedback when you step through a function
6813 with no line info or whose source file is unavailable. The default is
6814 OFF, which means never display the disassembly of the next line or
6815 instruction.
6816 @end table
6817
6818
6819 @node Data
6820 @chapter Examining Data
6821
6822 @cindex printing data
6823 @cindex examining data
6824 @kindex print
6825 @kindex inspect
6826 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
6827 @c document because it is nonstandard... Under Epoch it displays in a
6828 @c different window or something like that.
6829 The usual way to examine data in your program is with the @code{print}
6830 command (abbreviated @code{p}), or its synonym @code{inspect}. It
6831 evaluates and prints the value of an expression of the language your
6832 program is written in (@pxref{Languages, ,Using @value{GDBN} with
6833 Different Languages}). It may also print the expression using a
6834 Python-based pretty-printer (@pxref{Pretty Printing}).
6835
6836 @table @code
6837 @item print @var{expr}
6838 @itemx print /@var{f} @var{expr}
6839 @var{expr} is an expression (in the source language). By default the
6840 value of @var{expr} is printed in a format appropriate to its data type;
6841 you can choose a different format by specifying @samp{/@var{f}}, where
6842 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
6843 Formats}.
6844
6845 @item print
6846 @itemx print /@var{f}
6847 @cindex reprint the last value
6848 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
6849 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
6850 conveniently inspect the same value in an alternative format.
6851 @end table
6852
6853 A more low-level way of examining data is with the @code{x} command.
6854 It examines data in memory at a specified address and prints it in a
6855 specified format. @xref{Memory, ,Examining Memory}.
6856
6857 If you are interested in information about types, or about how the
6858 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
6859 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
6860 Table}.
6861
6862 @menu
6863 * Expressions:: Expressions
6864 * Ambiguous Expressions:: Ambiguous Expressions
6865 * Variables:: Program variables
6866 * Arrays:: Artificial arrays
6867 * Output Formats:: Output formats
6868 * Memory:: Examining memory
6869 * Auto Display:: Automatic display
6870 * Print Settings:: Print settings
6871 * Pretty Printing:: Python pretty printing
6872 * Value History:: Value history
6873 * Convenience Vars:: Convenience variables
6874 * Registers:: Registers
6875 * Floating Point Hardware:: Floating point hardware
6876 * Vector Unit:: Vector Unit
6877 * OS Information:: Auxiliary data provided by operating system
6878 * Memory Region Attributes:: Memory region attributes
6879 * Dump/Restore Files:: Copy between memory and a file
6880 * Core File Generation:: Cause a program dump its core
6881 * Character Sets:: Debugging programs that use a different
6882 character set than GDB does
6883 * Caching Remote Data:: Data caching for remote targets
6884 * Searching Memory:: Searching memory for a sequence of bytes
6885 @end menu
6886
6887 @node Expressions
6888 @section Expressions
6889
6890 @cindex expressions
6891 @code{print} and many other @value{GDBN} commands accept an expression and
6892 compute its value. Any kind of constant, variable or operator defined
6893 by the programming language you are using is valid in an expression in
6894 @value{GDBN}. This includes conditional expressions, function calls,
6895 casts, and string constants. It also includes preprocessor macros, if
6896 you compiled your program to include this information; see
6897 @ref{Compilation}.
6898
6899 @cindex arrays in expressions
6900 @value{GDBN} supports array constants in expressions input by
6901 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
6902 you can use the command @code{print @{1, 2, 3@}} to create an array
6903 of three integers. If you pass an array to a function or assign it
6904 to a program variable, @value{GDBN} copies the array to memory that
6905 is @code{malloc}ed in the target program.
6906
6907 Because C is so widespread, most of the expressions shown in examples in
6908 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
6909 Languages}, for information on how to use expressions in other
6910 languages.
6911
6912 In this section, we discuss operators that you can use in @value{GDBN}
6913 expressions regardless of your programming language.
6914
6915 @cindex casts, in expressions
6916 Casts are supported in all languages, not just in C, because it is so
6917 useful to cast a number into a pointer in order to examine a structure
6918 at that address in memory.
6919 @c FIXME: casts supported---Mod2 true?
6920
6921 @value{GDBN} supports these operators, in addition to those common
6922 to programming languages:
6923
6924 @table @code
6925 @item @@
6926 @samp{@@} is a binary operator for treating parts of memory as arrays.
6927 @xref{Arrays, ,Artificial Arrays}, for more information.
6928
6929 @item ::
6930 @samp{::} allows you to specify a variable in terms of the file or
6931 function where it is defined. @xref{Variables, ,Program Variables}.
6932
6933 @cindex @{@var{type}@}
6934 @cindex type casting memory
6935 @cindex memory, viewing as typed object
6936 @cindex casts, to view memory
6937 @item @{@var{type}@} @var{addr}
6938 Refers to an object of type @var{type} stored at address @var{addr} in
6939 memory. @var{addr} may be any expression whose value is an integer or
6940 pointer (but parentheses are required around binary operators, just as in
6941 a cast). This construct is allowed regardless of what kind of data is
6942 normally supposed to reside at @var{addr}.
6943 @end table
6944
6945 @node Ambiguous Expressions
6946 @section Ambiguous Expressions
6947 @cindex ambiguous expressions
6948
6949 Expressions can sometimes contain some ambiguous elements. For instance,
6950 some programming languages (notably Ada, C@t{++} and Objective-C) permit
6951 a single function name to be defined several times, for application in
6952 different contexts. This is called @dfn{overloading}. Another example
6953 involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
6954 templates and is typically instantiated several times, resulting in
6955 the same function name being defined in different contexts.
6956
6957 In some cases and depending on the language, it is possible to adjust
6958 the expression to remove the ambiguity. For instance in C@t{++}, you
6959 can specify the signature of the function you want to break on, as in
6960 @kbd{break @var{function}(@var{types})}. In Ada, using the fully
6961 qualified name of your function often makes the expression unambiguous
6962 as well.
6963
6964 When an ambiguity that needs to be resolved is detected, the debugger
6965 has the capability to display a menu of numbered choices for each
6966 possibility, and then waits for the selection with the prompt @samp{>}.
6967 The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
6968 aborts the current command. If the command in which the expression was
6969 used allows more than one choice to be selected, the next option in the
6970 menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
6971 choices.
6972
6973 For example, the following session excerpt shows an attempt to set a
6974 breakpoint at the overloaded symbol @code{String::after}.
6975 We choose three particular definitions of that function name:
6976
6977 @c FIXME! This is likely to change to show arg type lists, at least
6978 @smallexample
6979 @group
6980 (@value{GDBP}) b String::after
6981 [0] cancel
6982 [1] all
6983 [2] file:String.cc; line number:867
6984 [3] file:String.cc; line number:860
6985 [4] file:String.cc; line number:875
6986 [5] file:String.cc; line number:853
6987 [6] file:String.cc; line number:846
6988 [7] file:String.cc; line number:735
6989 > 2 4 6
6990 Breakpoint 1 at 0xb26c: file String.cc, line 867.
6991 Breakpoint 2 at 0xb344: file String.cc, line 875.
6992 Breakpoint 3 at 0xafcc: file String.cc, line 846.
6993 Multiple breakpoints were set.
6994 Use the "delete" command to delete unwanted
6995 breakpoints.
6996 (@value{GDBP})
6997 @end group
6998 @end smallexample
6999
7000 @table @code
7001 @kindex set multiple-symbols
7002 @item set multiple-symbols @var{mode}
7003 @cindex multiple-symbols menu
7004
7005 This option allows you to adjust the debugger behavior when an expression
7006 is ambiguous.
7007
7008 By default, @var{mode} is set to @code{all}. If the command with which
7009 the expression is used allows more than one choice, then @value{GDBN}
7010 automatically selects all possible choices. For instance, inserting
7011 a breakpoint on a function using an ambiguous name results in a breakpoint
7012 inserted on each possible match. However, if a unique choice must be made,
7013 then @value{GDBN} uses the menu to help you disambiguate the expression.
7014 For instance, printing the address of an overloaded function will result
7015 in the use of the menu.
7016
7017 When @var{mode} is set to @code{ask}, the debugger always uses the menu
7018 when an ambiguity is detected.
7019
7020 Finally, when @var{mode} is set to @code{cancel}, the debugger reports
7021 an error due to the ambiguity and the command is aborted.
7022
7023 @kindex show multiple-symbols
7024 @item show multiple-symbols
7025 Show the current value of the @code{multiple-symbols} setting.
7026 @end table
7027
7028 @node Variables
7029 @section Program Variables
7030
7031 The most common kind of expression to use is the name of a variable
7032 in your program.
7033
7034 Variables in expressions are understood in the selected stack frame
7035 (@pxref{Selection, ,Selecting a Frame}); they must be either:
7036
7037 @itemize @bullet
7038 @item
7039 global (or file-static)
7040 @end itemize
7041
7042 @noindent or
7043
7044 @itemize @bullet
7045 @item
7046 visible according to the scope rules of the
7047 programming language from the point of execution in that frame
7048 @end itemize
7049
7050 @noindent This means that in the function
7051
7052 @smallexample
7053 foo (a)
7054 int a;
7055 @{
7056 bar (a);
7057 @{
7058 int b = test ();
7059 bar (b);
7060 @}
7061 @}
7062 @end smallexample
7063
7064 @noindent
7065 you can examine and use the variable @code{a} whenever your program is
7066 executing within the function @code{foo}, but you can only use or
7067 examine the variable @code{b} while your program is executing inside
7068 the block where @code{b} is declared.
7069
7070 @cindex variable name conflict
7071 There is an exception: you can refer to a variable or function whose
7072 scope is a single source file even if the current execution point is not
7073 in this file. But it is possible to have more than one such variable or
7074 function with the same name (in different source files). If that
7075 happens, referring to that name has unpredictable effects. If you wish,
7076 you can specify a static variable in a particular function or file,
7077 using the colon-colon (@code{::}) notation:
7078
7079 @cindex colon-colon, context for variables/functions
7080 @ifnotinfo
7081 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
7082 @cindex @code{::}, context for variables/functions
7083 @end ifnotinfo
7084 @smallexample
7085 @var{file}::@var{variable}
7086 @var{function}::@var{variable}
7087 @end smallexample
7088
7089 @noindent
7090 Here @var{file} or @var{function} is the name of the context for the
7091 static @var{variable}. In the case of file names, you can use quotes to
7092 make sure @value{GDBN} parses the file name as a single word---for example,
7093 to print a global value of @code{x} defined in @file{f2.c}:
7094
7095 @smallexample
7096 (@value{GDBP}) p 'f2.c'::x
7097 @end smallexample
7098
7099 @cindex C@t{++} scope resolution
7100 This use of @samp{::} is very rarely in conflict with the very similar
7101 use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
7102 scope resolution operator in @value{GDBN} expressions.
7103 @c FIXME: Um, so what happens in one of those rare cases where it's in
7104 @c conflict?? --mew
7105
7106 @cindex wrong values
7107 @cindex variable values, wrong
7108 @cindex function entry/exit, wrong values of variables
7109 @cindex optimized code, wrong values of variables
7110 @quotation
7111 @emph{Warning:} Occasionally, a local variable may appear to have the
7112 wrong value at certain points in a function---just after entry to a new
7113 scope, and just before exit.
7114 @end quotation
7115 You may see this problem when you are stepping by machine instructions.
7116 This is because, on most machines, it takes more than one instruction to
7117 set up a stack frame (including local variable definitions); if you are
7118 stepping by machine instructions, variables may appear to have the wrong
7119 values until the stack frame is completely built. On exit, it usually
7120 also takes more than one machine instruction to destroy a stack frame;
7121 after you begin stepping through that group of instructions, local
7122 variable definitions may be gone.
7123
7124 This may also happen when the compiler does significant optimizations.
7125 To be sure of always seeing accurate values, turn off all optimization
7126 when compiling.
7127
7128 @cindex ``No symbol "foo" in current context''
7129 Another possible effect of compiler optimizations is to optimize
7130 unused variables out of existence, or assign variables to registers (as
7131 opposed to memory addresses). Depending on the support for such cases
7132 offered by the debug info format used by the compiler, @value{GDBN}
7133 might not be able to display values for such local variables. If that
7134 happens, @value{GDBN} will print a message like this:
7135
7136 @smallexample
7137 No symbol "foo" in current context.
7138 @end smallexample
7139
7140 To solve such problems, either recompile without optimizations, or use a
7141 different debug info format, if the compiler supports several such
7142 formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
7143 usually supports the @option{-gstabs+} option. @option{-gstabs+}
7144 produces debug info in a format that is superior to formats such as
7145 COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
7146 an effective form for debug info. @xref{Debugging Options,,Options
7147 for Debugging Your Program or GCC, gcc.info, Using the @sc{gnu}
7148 Compiler Collection (GCC)}.
7149 @xref{C, ,C and C@t{++}}, for more information about debug info formats
7150 that are best suited to C@t{++} programs.
7151
7152 If you ask to print an object whose contents are unknown to
7153 @value{GDBN}, e.g., because its data type is not completely specified
7154 by the debug information, @value{GDBN} will say @samp{<incomplete
7155 type>}. @xref{Symbols, incomplete type}, for more about this.
7156
7157 Strings are identified as arrays of @code{char} values without specified
7158 signedness. Arrays of either @code{signed char} or @code{unsigned char} get
7159 printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
7160 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
7161 defines literal string type @code{"char"} as @code{char} without a sign.
7162 For program code
7163
7164 @smallexample
7165 char var0[] = "A";
7166 signed char var1[] = "A";
7167 @end smallexample
7168
7169 You get during debugging
7170 @smallexample
7171 (gdb) print var0
7172 $1 = "A"
7173 (gdb) print var1
7174 $2 = @{65 'A', 0 '\0'@}
7175 @end smallexample
7176
7177 @node Arrays
7178 @section Artificial Arrays
7179
7180 @cindex artificial array
7181 @cindex arrays
7182 @kindex @@@r{, referencing memory as an array}
7183 It is often useful to print out several successive objects of the
7184 same type in memory; a section of an array, or an array of
7185 dynamically determined size for which only a pointer exists in the
7186 program.
7187
7188 You can do this by referring to a contiguous span of memory as an
7189 @dfn{artificial array}, using the binary operator @samp{@@}. The left
7190 operand of @samp{@@} should be the first element of the desired array
7191 and be an individual object. The right operand should be the desired length
7192 of the array. The result is an array value whose elements are all of
7193 the type of the left argument. The first element is actually the left
7194 argument; the second element comes from bytes of memory immediately
7195 following those that hold the first element, and so on. Here is an
7196 example. If a program says
7197
7198 @smallexample
7199 int *array = (int *) malloc (len * sizeof (int));
7200 @end smallexample
7201
7202 @noindent
7203 you can print the contents of @code{array} with
7204
7205 @smallexample
7206 p *array@@len
7207 @end smallexample
7208
7209 The left operand of @samp{@@} must reside in memory. Array values made
7210 with @samp{@@} in this way behave just like other arrays in terms of
7211 subscripting, and are coerced to pointers when used in expressions.
7212 Artificial arrays most often appear in expressions via the value history
7213 (@pxref{Value History, ,Value History}), after printing one out.
7214
7215 Another way to create an artificial array is to use a cast.
7216 This re-interprets a value as if it were an array.
7217 The value need not be in memory:
7218 @smallexample
7219 (@value{GDBP}) p/x (short[2])0x12345678
7220 $1 = @{0x1234, 0x5678@}
7221 @end smallexample
7222
7223 As a convenience, if you leave the array length out (as in
7224 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
7225 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
7226 @smallexample
7227 (@value{GDBP}) p/x (short[])0x12345678
7228 $2 = @{0x1234, 0x5678@}
7229 @end smallexample
7230
7231 Sometimes the artificial array mechanism is not quite enough; in
7232 moderately complex data structures, the elements of interest may not
7233 actually be adjacent---for example, if you are interested in the values
7234 of pointers in an array. One useful work-around in this situation is
7235 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
7236 Variables}) as a counter in an expression that prints the first
7237 interesting value, and then repeat that expression via @key{RET}. For
7238 instance, suppose you have an array @code{dtab} of pointers to
7239 structures, and you are interested in the values of a field @code{fv}
7240 in each structure. Here is an example of what you might type:
7241
7242 @smallexample
7243 set $i = 0
7244 p dtab[$i++]->fv
7245 @key{RET}
7246 @key{RET}
7247 @dots{}
7248 @end smallexample
7249
7250 @node Output Formats
7251 @section Output Formats
7252
7253 @cindex formatted output
7254 @cindex output formats
7255 By default, @value{GDBN} prints a value according to its data type. Sometimes
7256 this is not what you want. For example, you might want to print a number
7257 in hex, or a pointer in decimal. Or you might want to view data in memory
7258 at a certain address as a character string or as an instruction. To do
7259 these things, specify an @dfn{output format} when you print a value.
7260
7261 The simplest use of output formats is to say how to print a value
7262 already computed. This is done by starting the arguments of the
7263 @code{print} command with a slash and a format letter. The format
7264 letters supported are:
7265
7266 @table @code
7267 @item x
7268 Regard the bits of the value as an integer, and print the integer in
7269 hexadecimal.
7270
7271 @item d
7272 Print as integer in signed decimal.
7273
7274 @item u
7275 Print as integer in unsigned decimal.
7276
7277 @item o
7278 Print as integer in octal.
7279
7280 @item t
7281 Print as integer in binary. The letter @samp{t} stands for ``two''.
7282 @footnote{@samp{b} cannot be used because these format letters are also
7283 used with the @code{x} command, where @samp{b} stands for ``byte'';
7284 see @ref{Memory,,Examining Memory}.}
7285
7286 @item a
7287 @cindex unknown address, locating
7288 @cindex locate address
7289 Print as an address, both absolute in hexadecimal and as an offset from
7290 the nearest preceding symbol. You can use this format used to discover
7291 where (in what function) an unknown address is located:
7292
7293 @smallexample
7294 (@value{GDBP}) p/a 0x54320
7295 $3 = 0x54320 <_initialize_vx+396>
7296 @end smallexample
7297
7298 @noindent
7299 The command @code{info symbol 0x54320} yields similar results.
7300 @xref{Symbols, info symbol}.
7301
7302 @item c
7303 Regard as an integer and print it as a character constant. This
7304 prints both the numerical value and its character representation. The
7305 character representation is replaced with the octal escape @samp{\nnn}
7306 for characters outside the 7-bit @sc{ascii} range.
7307
7308 Without this format, @value{GDBN} displays @code{char},
7309 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
7310 constants. Single-byte members of vectors are displayed as integer
7311 data.
7312
7313 @item f
7314 Regard the bits of the value as a floating point number and print
7315 using typical floating point syntax.
7316
7317 @item s
7318 @cindex printing strings
7319 @cindex printing byte arrays
7320 Regard as a string, if possible. With this format, pointers to single-byte
7321 data are displayed as null-terminated strings and arrays of single-byte data
7322 are displayed as fixed-length strings. Other values are displayed in their
7323 natural types.
7324
7325 Without this format, @value{GDBN} displays pointers to and arrays of
7326 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
7327 strings. Single-byte members of a vector are displayed as an integer
7328 array.
7329
7330 @item r
7331 @cindex raw printing
7332 Print using the @samp{raw} formatting. By default, @value{GDBN} will
7333 use a Python-based pretty-printer, if one is available (@pxref{Pretty
7334 Printing}). This typically results in a higher-level display of the
7335 value's contents. The @samp{r} format bypasses any Python
7336 pretty-printer which might exist.
7337 @end table
7338
7339 For example, to print the program counter in hex (@pxref{Registers}), type
7340
7341 @smallexample
7342 p/x $pc
7343 @end smallexample
7344
7345 @noindent
7346 Note that no space is required before the slash; this is because command
7347 names in @value{GDBN} cannot contain a slash.
7348
7349 To reprint the last value in the value history with a different format,
7350 you can use the @code{print} command with just a format and no
7351 expression. For example, @samp{p/x} reprints the last value in hex.
7352
7353 @node Memory
7354 @section Examining Memory
7355
7356 You can use the command @code{x} (for ``examine'') to examine memory in
7357 any of several formats, independently of your program's data types.
7358
7359 @cindex examining memory
7360 @table @code
7361 @kindex x @r{(examine memory)}
7362 @item x/@var{nfu} @var{addr}
7363 @itemx x @var{addr}
7364 @itemx x
7365 Use the @code{x} command to examine memory.
7366 @end table
7367
7368 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
7369 much memory to display and how to format it; @var{addr} is an
7370 expression giving the address where you want to start displaying memory.
7371 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
7372 Several commands set convenient defaults for @var{addr}.
7373
7374 @table @r
7375 @item @var{n}, the repeat count
7376 The repeat count is a decimal integer; the default is 1. It specifies
7377 how much memory (counting by units @var{u}) to display.
7378 @c This really is **decimal**; unaffected by 'set radix' as of GDB
7379 @c 4.1.2.
7380
7381 @item @var{f}, the display format
7382 The display format is one of the formats used by @code{print}
7383 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
7384 @samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
7385 The default is @samp{x} (hexadecimal) initially. The default changes
7386 each time you use either @code{x} or @code{print}.
7387
7388 @item @var{u}, the unit size
7389 The unit size is any of
7390
7391 @table @code
7392 @item b
7393 Bytes.
7394 @item h
7395 Halfwords (two bytes).
7396 @item w
7397 Words (four bytes). This is the initial default.
7398 @item g
7399 Giant words (eight bytes).
7400 @end table
7401
7402 Each time you specify a unit size with @code{x}, that size becomes the
7403 default unit the next time you use @code{x}. For the @samp{i} format,
7404 the unit size is ignored and is normally not written. For the @samp{s} format,
7405 the unit size defaults to @samp{b}, unless it is explicitly given.
7406 Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
7407 32-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
7408 Note that the results depend on the programming language of the
7409 current compilation unit. If the language is C, the @samp{s}
7410 modifier will use the UTF-16 encoding while @samp{w} will use
7411 UTF-32. The encoding is set by the programming language and cannot
7412 be altered.
7413
7414 @item @var{addr}, starting display address
7415 @var{addr} is the address where you want @value{GDBN} to begin displaying
7416 memory. The expression need not have a pointer value (though it may);
7417 it is always interpreted as an integer address of a byte of memory.
7418 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
7419 @var{addr} is usually just after the last address examined---but several
7420 other commands also set the default address: @code{info breakpoints} (to
7421 the address of the last breakpoint listed), @code{info line} (to the
7422 starting address of a line), and @code{print} (if you use it to display
7423 a value from memory).
7424 @end table
7425
7426 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
7427 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
7428 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
7429 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
7430 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
7431
7432 Since the letters indicating unit sizes are all distinct from the
7433 letters specifying output formats, you do not have to remember whether
7434 unit size or format comes first; either order works. The output
7435 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
7436 (However, the count @var{n} must come first; @samp{wx4} does not work.)
7437
7438 Even though the unit size @var{u} is ignored for the formats @samp{s}
7439 and @samp{i}, you might still want to use a count @var{n}; for example,
7440 @samp{3i} specifies that you want to see three machine instructions,
7441 including any operands. For convenience, especially when used with
7442 the @code{display} command, the @samp{i} format also prints branch delay
7443 slot instructions, if any, beyond the count specified, which immediately
7444 follow the last instruction that is within the count. The command
7445 @code{disassemble} gives an alternative way of inspecting machine
7446 instructions; see @ref{Machine Code,,Source and Machine Code}.
7447
7448 All the defaults for the arguments to @code{x} are designed to make it
7449 easy to continue scanning memory with minimal specifications each time
7450 you use @code{x}. For example, after you have inspected three machine
7451 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
7452 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
7453 the repeat count @var{n} is used again; the other arguments default as
7454 for successive uses of @code{x}.
7455
7456 When examining machine instructions, the instruction at current program
7457 counter is shown with a @code{=>} marker. For example:
7458
7459 @smallexample
7460 (@value{GDBP}) x/5i $pc-6
7461 0x804837f <main+11>: mov %esp,%ebp
7462 0x8048381 <main+13>: push %ecx
7463 0x8048382 <main+14>: sub $0x4,%esp
7464 => 0x8048385 <main+17>: movl $0x8048460,(%esp)
7465 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
7466 @end smallexample
7467
7468 @cindex @code{$_}, @code{$__}, and value history
7469 The addresses and contents printed by the @code{x} command are not saved
7470 in the value history because there is often too much of them and they
7471 would get in the way. Instead, @value{GDBN} makes these values available for
7472 subsequent use in expressions as values of the convenience variables
7473 @code{$_} and @code{$__}. After an @code{x} command, the last address
7474 examined is available for use in expressions in the convenience variable
7475 @code{$_}. The contents of that address, as examined, are available in
7476 the convenience variable @code{$__}.
7477
7478 If the @code{x} command has a repeat count, the address and contents saved
7479 are from the last memory unit printed; this is not the same as the last
7480 address printed if several units were printed on the last line of output.
7481
7482 @cindex remote memory comparison
7483 @cindex verify remote memory image
7484 When you are debugging a program running on a remote target machine
7485 (@pxref{Remote Debugging}), you may wish to verify the program's image in the
7486 remote machine's memory against the executable file you downloaded to
7487 the target. The @code{compare-sections} command is provided for such
7488 situations.
7489
7490 @table @code
7491 @kindex compare-sections
7492 @item compare-sections @r{[}@var{section-name}@r{]}
7493 Compare the data of a loadable section @var{section-name} in the
7494 executable file of the program being debugged with the same section in
7495 the remote machine's memory, and report any mismatches. With no
7496 arguments, compares all loadable sections. This command's
7497 availability depends on the target's support for the @code{"qCRC"}
7498 remote request.
7499 @end table
7500
7501 @node Auto Display
7502 @section Automatic Display
7503 @cindex automatic display
7504 @cindex display of expressions
7505
7506 If you find that you want to print the value of an expression frequently
7507 (to see how it changes), you might want to add it to the @dfn{automatic
7508 display list} so that @value{GDBN} prints its value each time your program stops.
7509 Each expression added to the list is given a number to identify it;
7510 to remove an expression from the list, you specify that number.
7511 The automatic display looks like this:
7512
7513 @smallexample
7514 2: foo = 38
7515 3: bar[5] = (struct hack *) 0x3804
7516 @end smallexample
7517
7518 @noindent
7519 This display shows item numbers, expressions and their current values. As with
7520 displays you request manually using @code{x} or @code{print}, you can
7521 specify the output format you prefer; in fact, @code{display} decides
7522 whether to use @code{print} or @code{x} depending your format
7523 specification---it uses @code{x} if you specify either the @samp{i}
7524 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
7525
7526 @table @code
7527 @kindex display
7528 @item display @var{expr}
7529 Add the expression @var{expr} to the list of expressions to display
7530 each time your program stops. @xref{Expressions, ,Expressions}.
7531
7532 @code{display} does not repeat if you press @key{RET} again after using it.
7533
7534 @item display/@var{fmt} @var{expr}
7535 For @var{fmt} specifying only a display format and not a size or
7536 count, add the expression @var{expr} to the auto-display list but
7537 arrange to display it each time in the specified format @var{fmt}.
7538 @xref{Output Formats,,Output Formats}.
7539
7540 @item display/@var{fmt} @var{addr}
7541 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
7542 number of units, add the expression @var{addr} as a memory address to
7543 be examined each time your program stops. Examining means in effect
7544 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
7545 @end table
7546
7547 For example, @samp{display/i $pc} can be helpful, to see the machine
7548 instruction about to be executed each time execution stops (@samp{$pc}
7549 is a common name for the program counter; @pxref{Registers, ,Registers}).
7550
7551 @table @code
7552 @kindex delete display
7553 @kindex undisplay
7554 @item undisplay @var{dnums}@dots{}
7555 @itemx delete display @var{dnums}@dots{}
7556 Remove item numbers @var{dnums} from the list of expressions to display.
7557
7558 @code{undisplay} does not repeat if you press @key{RET} after using it.
7559 (Otherwise you would just get the error @samp{No display number @dots{}}.)
7560
7561 @kindex disable display
7562 @item disable display @var{dnums}@dots{}
7563 Disable the display of item numbers @var{dnums}. A disabled display
7564 item is not printed automatically, but is not forgotten. It may be
7565 enabled again later.
7566
7567 @kindex enable display
7568 @item enable display @var{dnums}@dots{}
7569 Enable display of item numbers @var{dnums}. It becomes effective once
7570 again in auto display of its expression, until you specify otherwise.
7571
7572 @item display
7573 Display the current values of the expressions on the list, just as is
7574 done when your program stops.
7575
7576 @kindex info display
7577 @item info display
7578 Print the list of expressions previously set up to display
7579 automatically, each one with its item number, but without showing the
7580 values. This includes disabled expressions, which are marked as such.
7581 It also includes expressions which would not be displayed right now
7582 because they refer to automatic variables not currently available.
7583 @end table
7584
7585 @cindex display disabled out of scope
7586 If a display expression refers to local variables, then it does not make
7587 sense outside the lexical context for which it was set up. Such an
7588 expression is disabled when execution enters a context where one of its
7589 variables is not defined. For example, if you give the command
7590 @code{display last_char} while inside a function with an argument
7591 @code{last_char}, @value{GDBN} displays this argument while your program
7592 continues to stop inside that function. When it stops elsewhere---where
7593 there is no variable @code{last_char}---the display is disabled
7594 automatically. The next time your program stops where @code{last_char}
7595 is meaningful, you can enable the display expression once again.
7596
7597 @node Print Settings
7598 @section Print Settings
7599
7600 @cindex format options
7601 @cindex print settings
7602 @value{GDBN} provides the following ways to control how arrays, structures,
7603 and symbols are printed.
7604
7605 @noindent
7606 These settings are useful for debugging programs in any language:
7607
7608 @table @code
7609 @kindex set print
7610 @item set print address
7611 @itemx set print address on
7612 @cindex print/don't print memory addresses
7613 @value{GDBN} prints memory addresses showing the location of stack
7614 traces, structure values, pointer values, breakpoints, and so forth,
7615 even when it also displays the contents of those addresses. The default
7616 is @code{on}. For example, this is what a stack frame display looks like with
7617 @code{set print address on}:
7618
7619 @smallexample
7620 @group
7621 (@value{GDBP}) f
7622 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
7623 at input.c:530
7624 530 if (lquote != def_lquote)
7625 @end group
7626 @end smallexample
7627
7628 @item set print address off
7629 Do not print addresses when displaying their contents. For example,
7630 this is the same stack frame displayed with @code{set print address off}:
7631
7632 @smallexample
7633 @group
7634 (@value{GDBP}) set print addr off
7635 (@value{GDBP}) f
7636 #0 set_quotes (lq="<<", rq=">>") at input.c:530
7637 530 if (lquote != def_lquote)
7638 @end group
7639 @end smallexample
7640
7641 You can use @samp{set print address off} to eliminate all machine
7642 dependent displays from the @value{GDBN} interface. For example, with
7643 @code{print address off}, you should get the same text for backtraces on
7644 all machines---whether or not they involve pointer arguments.
7645
7646 @kindex show print
7647 @item show print address
7648 Show whether or not addresses are to be printed.
7649 @end table
7650
7651 When @value{GDBN} prints a symbolic address, it normally prints the
7652 closest earlier symbol plus an offset. If that symbol does not uniquely
7653 identify the address (for example, it is a name whose scope is a single
7654 source file), you may need to clarify. One way to do this is with
7655 @code{info line}, for example @samp{info line *0x4537}. Alternately,
7656 you can set @value{GDBN} to print the source file and line number when
7657 it prints a symbolic address:
7658
7659 @table @code
7660 @item set print symbol-filename on
7661 @cindex source file and line of a symbol
7662 @cindex symbol, source file and line
7663 Tell @value{GDBN} to print the source file name and line number of a
7664 symbol in the symbolic form of an address.
7665
7666 @item set print symbol-filename off
7667 Do not print source file name and line number of a symbol. This is the
7668 default.
7669
7670 @item show print symbol-filename
7671 Show whether or not @value{GDBN} will print the source file name and
7672 line number of a symbol in the symbolic form of an address.
7673 @end table
7674
7675 Another situation where it is helpful to show symbol filenames and line
7676 numbers is when disassembling code; @value{GDBN} shows you the line
7677 number and source file that corresponds to each instruction.
7678
7679 Also, you may wish to see the symbolic form only if the address being
7680 printed is reasonably close to the closest earlier symbol:
7681
7682 @table @code
7683 @item set print max-symbolic-offset @var{max-offset}
7684 @cindex maximum value for offset of closest symbol
7685 Tell @value{GDBN} to only display the symbolic form of an address if the
7686 offset between the closest earlier symbol and the address is less than
7687 @var{max-offset}. The default is 0, which tells @value{GDBN}
7688 to always print the symbolic form of an address if any symbol precedes it.
7689
7690 @item show print max-symbolic-offset
7691 Ask how large the maximum offset is that @value{GDBN} prints in a
7692 symbolic address.
7693 @end table
7694
7695 @cindex wild pointer, interpreting
7696 @cindex pointer, finding referent
7697 If you have a pointer and you are not sure where it points, try
7698 @samp{set print symbol-filename on}. Then you can determine the name
7699 and source file location of the variable where it points, using
7700 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
7701 For example, here @value{GDBN} shows that a variable @code{ptt} points
7702 at another variable @code{t}, defined in @file{hi2.c}:
7703
7704 @smallexample
7705 (@value{GDBP}) set print symbol-filename on
7706 (@value{GDBP}) p/a ptt
7707 $4 = 0xe008 <t in hi2.c>
7708 @end smallexample
7709
7710 @quotation
7711 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
7712 does not show the symbol name and filename of the referent, even with
7713 the appropriate @code{set print} options turned on.
7714 @end quotation
7715
7716 Other settings control how different kinds of objects are printed:
7717
7718 @table @code
7719 @item set print array
7720 @itemx set print array on
7721 @cindex pretty print arrays
7722 Pretty print arrays. This format is more convenient to read,
7723 but uses more space. The default is off.
7724
7725 @item set print array off
7726 Return to compressed format for arrays.
7727
7728 @item show print array
7729 Show whether compressed or pretty format is selected for displaying
7730 arrays.
7731
7732 @cindex print array indexes
7733 @item set print array-indexes
7734 @itemx set print array-indexes on
7735 Print the index of each element when displaying arrays. May be more
7736 convenient to locate a given element in the array or quickly find the
7737 index of a given element in that printed array. The default is off.
7738
7739 @item set print array-indexes off
7740 Stop printing element indexes when displaying arrays.
7741
7742 @item show print array-indexes
7743 Show whether the index of each element is printed when displaying
7744 arrays.
7745
7746 @item set print elements @var{number-of-elements}
7747 @cindex number of array elements to print
7748 @cindex limit on number of printed array elements
7749 Set a limit on how many elements of an array @value{GDBN} will print.
7750 If @value{GDBN} is printing a large array, it stops printing after it has
7751 printed the number of elements set by the @code{set print elements} command.
7752 This limit also applies to the display of strings.
7753 When @value{GDBN} starts, this limit is set to 200.
7754 Setting @var{number-of-elements} to zero means that the printing is unlimited.
7755
7756 @item show print elements
7757 Display the number of elements of a large array that @value{GDBN} will print.
7758 If the number is 0, then the printing is unlimited.
7759
7760 @item set print frame-arguments @var{value}
7761 @kindex set print frame-arguments
7762 @cindex printing frame argument values
7763 @cindex print all frame argument values
7764 @cindex print frame argument values for scalars only
7765 @cindex do not print frame argument values
7766 This command allows to control how the values of arguments are printed
7767 when the debugger prints a frame (@pxref{Frames}). The possible
7768 values are:
7769
7770 @table @code
7771 @item all
7772 The values of all arguments are printed.
7773
7774 @item scalars
7775 Print the value of an argument only if it is a scalar. The value of more
7776 complex arguments such as arrays, structures, unions, etc, is replaced
7777 by @code{@dots{}}. This is the default. Here is an example where
7778 only scalar arguments are shown:
7779
7780 @smallexample
7781 #1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
7782 at frame-args.c:23
7783 @end smallexample
7784
7785 @item none
7786 None of the argument values are printed. Instead, the value of each argument
7787 is replaced by @code{@dots{}}. In this case, the example above now becomes:
7788
7789 @smallexample
7790 #1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
7791 at frame-args.c:23
7792 @end smallexample
7793 @end table
7794
7795 By default, only scalar arguments are printed. This command can be used
7796 to configure the debugger to print the value of all arguments, regardless
7797 of their type. However, it is often advantageous to not print the value
7798 of more complex parameters. For instance, it reduces the amount of
7799 information printed in each frame, making the backtrace more readable.
7800 Also, it improves performance when displaying Ada frames, because
7801 the computation of large arguments can sometimes be CPU-intensive,
7802 especially in large applications. Setting @code{print frame-arguments}
7803 to @code{scalars} (the default) or @code{none} avoids this computation,
7804 thus speeding up the display of each Ada frame.
7805
7806 @item show print frame-arguments
7807 Show how the value of arguments should be displayed when printing a frame.
7808
7809 @item set print repeats
7810 @cindex repeated array elements
7811 Set the threshold for suppressing display of repeated array
7812 elements. When the number of consecutive identical elements of an
7813 array exceeds the threshold, @value{GDBN} prints the string
7814 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
7815 identical repetitions, instead of displaying the identical elements
7816 themselves. Setting the threshold to zero will cause all elements to
7817 be individually printed. The default threshold is 10.
7818
7819 @item show print repeats
7820 Display the current threshold for printing repeated identical
7821 elements.
7822
7823 @item set print null-stop
7824 @cindex @sc{null} elements in arrays
7825 Cause @value{GDBN} to stop printing the characters of an array when the first
7826 @sc{null} is encountered. This is useful when large arrays actually
7827 contain only short strings.
7828 The default is off.
7829
7830 @item show print null-stop
7831 Show whether @value{GDBN} stops printing an array on the first
7832 @sc{null} character.
7833
7834 @item set print pretty on
7835 @cindex print structures in indented form
7836 @cindex indentation in structure display
7837 Cause @value{GDBN} to print structures in an indented format with one member
7838 per line, like this:
7839
7840 @smallexample
7841 @group
7842 $1 = @{
7843 next = 0x0,
7844 flags = @{
7845 sweet = 1,
7846 sour = 1
7847 @},
7848 meat = 0x54 "Pork"
7849 @}
7850 @end group
7851 @end smallexample
7852
7853 @item set print pretty off
7854 Cause @value{GDBN} to print structures in a compact format, like this:
7855
7856 @smallexample
7857 @group
7858 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
7859 meat = 0x54 "Pork"@}
7860 @end group
7861 @end smallexample
7862
7863 @noindent
7864 This is the default format.
7865
7866 @item show print pretty
7867 Show which format @value{GDBN} is using to print structures.
7868
7869 @item set print sevenbit-strings on
7870 @cindex eight-bit characters in strings
7871 @cindex octal escapes in strings
7872 Print using only seven-bit characters; if this option is set,
7873 @value{GDBN} displays any eight-bit characters (in strings or
7874 character values) using the notation @code{\}@var{nnn}. This setting is
7875 best if you are working in English (@sc{ascii}) and you use the
7876 high-order bit of characters as a marker or ``meta'' bit.
7877
7878 @item set print sevenbit-strings off
7879 Print full eight-bit characters. This allows the use of more
7880 international character sets, and is the default.
7881
7882 @item show print sevenbit-strings
7883 Show whether or not @value{GDBN} is printing only seven-bit characters.
7884
7885 @item set print union on
7886 @cindex unions in structures, printing
7887 Tell @value{GDBN} to print unions which are contained in structures
7888 and other unions. This is the default setting.
7889
7890 @item set print union off
7891 Tell @value{GDBN} not to print unions which are contained in
7892 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
7893 instead.
7894
7895 @item show print union
7896 Ask @value{GDBN} whether or not it will print unions which are contained in
7897 structures and other unions.
7898
7899 For example, given the declarations
7900
7901 @smallexample
7902 typedef enum @{Tree, Bug@} Species;
7903 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
7904 typedef enum @{Caterpillar, Cocoon, Butterfly@}
7905 Bug_forms;
7906
7907 struct thing @{
7908 Species it;
7909 union @{
7910 Tree_forms tree;
7911 Bug_forms bug;
7912 @} form;
7913 @};
7914
7915 struct thing foo = @{Tree, @{Acorn@}@};
7916 @end smallexample
7917
7918 @noindent
7919 with @code{set print union on} in effect @samp{p foo} would print
7920
7921 @smallexample
7922 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
7923 @end smallexample
7924
7925 @noindent
7926 and with @code{set print union off} in effect it would print
7927
7928 @smallexample
7929 $1 = @{it = Tree, form = @{...@}@}
7930 @end smallexample
7931
7932 @noindent
7933 @code{set print union} affects programs written in C-like languages
7934 and in Pascal.
7935 @end table
7936
7937 @need 1000
7938 @noindent
7939 These settings are of interest when debugging C@t{++} programs:
7940
7941 @table @code
7942 @cindex demangling C@t{++} names
7943 @item set print demangle
7944 @itemx set print demangle on
7945 Print C@t{++} names in their source form rather than in the encoded
7946 (``mangled'') form passed to the assembler and linker for type-safe
7947 linkage. The default is on.
7948
7949 @item show print demangle
7950 Show whether C@t{++} names are printed in mangled or demangled form.
7951
7952 @item set print asm-demangle
7953 @itemx set print asm-demangle on
7954 Print C@t{++} names in their source form rather than their mangled form, even
7955 in assembler code printouts such as instruction disassemblies.
7956 The default is off.
7957
7958 @item show print asm-demangle
7959 Show whether C@t{++} names in assembly listings are printed in mangled
7960 or demangled form.
7961
7962 @cindex C@t{++} symbol decoding style
7963 @cindex symbol decoding style, C@t{++}
7964 @kindex set demangle-style
7965 @item set demangle-style @var{style}
7966 Choose among several encoding schemes used by different compilers to
7967 represent C@t{++} names. The choices for @var{style} are currently:
7968
7969 @table @code
7970 @item auto
7971 Allow @value{GDBN} to choose a decoding style by inspecting your program.
7972
7973 @item gnu
7974 Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
7975 This is the default.
7976
7977 @item hp
7978 Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
7979
7980 @item lucid
7981 Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
7982
7983 @item arm
7984 Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
7985 @strong{Warning:} this setting alone is not sufficient to allow
7986 debugging @code{cfront}-generated executables. @value{GDBN} would
7987 require further enhancement to permit that.
7988
7989 @end table
7990 If you omit @var{style}, you will see a list of possible formats.
7991
7992 @item show demangle-style
7993 Display the encoding style currently in use for decoding C@t{++} symbols.
7994
7995 @item set print object
7996 @itemx set print object on
7997 @cindex derived type of an object, printing
7998 @cindex display derived types
7999 When displaying a pointer to an object, identify the @emph{actual}
8000 (derived) type of the object rather than the @emph{declared} type, using
8001 the virtual function table.
8002
8003 @item set print object off
8004 Display only the declared type of objects, without reference to the
8005 virtual function table. This is the default setting.
8006
8007 @item show print object
8008 Show whether actual, or declared, object types are displayed.
8009
8010 @item set print static-members
8011 @itemx set print static-members on
8012 @cindex static members of C@t{++} objects
8013 Print static members when displaying a C@t{++} object. The default is on.
8014
8015 @item set print static-members off
8016 Do not print static members when displaying a C@t{++} object.
8017
8018 @item show print static-members
8019 Show whether C@t{++} static members are printed or not.
8020
8021 @item set print pascal_static-members
8022 @itemx set print pascal_static-members on
8023 @cindex static members of Pascal objects
8024 @cindex Pascal objects, static members display
8025 Print static members when displaying a Pascal object. The default is on.
8026
8027 @item set print pascal_static-members off
8028 Do not print static members when displaying a Pascal object.
8029
8030 @item show print pascal_static-members
8031 Show whether Pascal static members are printed or not.
8032
8033 @c These don't work with HP ANSI C++ yet.
8034 @item set print vtbl
8035 @itemx set print vtbl on
8036 @cindex pretty print C@t{++} virtual function tables
8037 @cindex virtual functions (C@t{++}) display
8038 @cindex VTBL display
8039 Pretty print C@t{++} virtual function tables. The default is off.
8040 (The @code{vtbl} commands do not work on programs compiled with the HP
8041 ANSI C@t{++} compiler (@code{aCC}).)
8042
8043 @item set print vtbl off
8044 Do not pretty print C@t{++} virtual function tables.
8045
8046 @item show print vtbl
8047 Show whether C@t{++} virtual function tables are pretty printed, or not.
8048 @end table
8049
8050 @node Pretty Printing
8051 @section Pretty Printing
8052
8053 @value{GDBN} provides a mechanism to allow pretty-printing of values using
8054 Python code. It greatly simplifies the display of complex objects. This
8055 mechanism works for both MI and the CLI.
8056
8057 For example, here is how a C@t{++} @code{std::string} looks without a
8058 pretty-printer:
8059
8060 @smallexample
8061 (@value{GDBP}) print s
8062 $1 = @{
8063 static npos = 4294967295,
8064 _M_dataplus = @{
8065 <std::allocator<char>> = @{
8066 <__gnu_cxx::new_allocator<char>> = @{
8067 <No data fields>@}, <No data fields>
8068 @},
8069 members of std::basic_string<char, std::char_traits<char>,
8070 std::allocator<char> >::_Alloc_hider:
8071 _M_p = 0x804a014 "abcd"
8072 @}
8073 @}
8074 @end smallexample
8075
8076 With a pretty-printer for @code{std::string} only the contents are printed:
8077
8078 @smallexample
8079 (@value{GDBP}) print s
8080 $2 = "abcd"
8081 @end smallexample
8082
8083 For implementing pretty printers for new types you should read the Python API
8084 details (@pxref{Pretty Printing API}).
8085
8086 @node Value History
8087 @section Value History
8088
8089 @cindex value history
8090 @cindex history of values printed by @value{GDBN}
8091 Values printed by the @code{print} command are saved in the @value{GDBN}
8092 @dfn{value history}. This allows you to refer to them in other expressions.
8093 Values are kept until the symbol table is re-read or discarded
8094 (for example with the @code{file} or @code{symbol-file} commands).
8095 When the symbol table changes, the value history is discarded,
8096 since the values may contain pointers back to the types defined in the
8097 symbol table.
8098
8099 @cindex @code{$}
8100 @cindex @code{$$}
8101 @cindex history number
8102 The values printed are given @dfn{history numbers} by which you can
8103 refer to them. These are successive integers starting with one.
8104 @code{print} shows you the history number assigned to a value by
8105 printing @samp{$@var{num} = } before the value; here @var{num} is the
8106 history number.
8107
8108 To refer to any previous value, use @samp{$} followed by the value's
8109 history number. The way @code{print} labels its output is designed to
8110 remind you of this. Just @code{$} refers to the most recent value in
8111 the history, and @code{$$} refers to the value before that.
8112 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
8113 is the value just prior to @code{$$}, @code{$$1} is equivalent to
8114 @code{$$}, and @code{$$0} is equivalent to @code{$}.
8115
8116 For example, suppose you have just printed a pointer to a structure and
8117 want to see the contents of the structure. It suffices to type
8118
8119 @smallexample
8120 p *$
8121 @end smallexample
8122
8123 If you have a chain of structures where the component @code{next} points
8124 to the next one, you can print the contents of the next one with this:
8125
8126 @smallexample
8127 p *$.next
8128 @end smallexample
8129
8130 @noindent
8131 You can print successive links in the chain by repeating this
8132 command---which you can do by just typing @key{RET}.
8133
8134 Note that the history records values, not expressions. If the value of
8135 @code{x} is 4 and you type these commands:
8136
8137 @smallexample
8138 print x
8139 set x=5
8140 @end smallexample
8141
8142 @noindent
8143 then the value recorded in the value history by the @code{print} command
8144 remains 4 even though the value of @code{x} has changed.
8145
8146 @table @code
8147 @kindex show values
8148 @item show values
8149 Print the last ten values in the value history, with their item numbers.
8150 This is like @samp{p@ $$9} repeated ten times, except that @code{show
8151 values} does not change the history.
8152
8153 @item show values @var{n}
8154 Print ten history values centered on history item number @var{n}.
8155
8156 @item show values +
8157 Print ten history values just after the values last printed. If no more
8158 values are available, @code{show values +} produces no display.
8159 @end table
8160
8161 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
8162 same effect as @samp{show values +}.
8163
8164 @node Convenience Vars
8165 @section Convenience Variables
8166
8167 @cindex convenience variables
8168 @cindex user-defined variables
8169 @value{GDBN} provides @dfn{convenience variables} that you can use within
8170 @value{GDBN} to hold on to a value and refer to it later. These variables
8171 exist entirely within @value{GDBN}; they are not part of your program, and
8172 setting a convenience variable has no direct effect on further execution
8173 of your program. That is why you can use them freely.
8174
8175 Convenience variables are prefixed with @samp{$}. Any name preceded by
8176 @samp{$} can be used for a convenience variable, unless it is one of
8177 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
8178 (Value history references, in contrast, are @emph{numbers} preceded
8179 by @samp{$}. @xref{Value History, ,Value History}.)
8180
8181 You can save a value in a convenience variable with an assignment
8182 expression, just as you would set a variable in your program.
8183 For example:
8184
8185 @smallexample
8186 set $foo = *object_ptr
8187 @end smallexample
8188
8189 @noindent
8190 would save in @code{$foo} the value contained in the object pointed to by
8191 @code{object_ptr}.
8192
8193 Using a convenience variable for the first time creates it, but its
8194 value is @code{void} until you assign a new value. You can alter the
8195 value with another assignment at any time.
8196
8197 Convenience variables have no fixed types. You can assign a convenience
8198 variable any type of value, including structures and arrays, even if
8199 that variable already has a value of a different type. The convenience
8200 variable, when used as an expression, has the type of its current value.
8201
8202 @table @code
8203 @kindex show convenience
8204 @cindex show all user variables
8205 @item show convenience
8206 Print a list of convenience variables used so far, and their values.
8207 Abbreviated @code{show conv}.
8208
8209 @kindex init-if-undefined
8210 @cindex convenience variables, initializing
8211 @item init-if-undefined $@var{variable} = @var{expression}
8212 Set a convenience variable if it has not already been set. This is useful
8213 for user-defined commands that keep some state. It is similar, in concept,
8214 to using local static variables with initializers in C (except that
8215 convenience variables are global). It can also be used to allow users to
8216 override default values used in a command script.
8217
8218 If the variable is already defined then the expression is not evaluated so
8219 any side-effects do not occur.
8220 @end table
8221
8222 One of the ways to use a convenience variable is as a counter to be
8223 incremented or a pointer to be advanced. For example, to print
8224 a field from successive elements of an array of structures:
8225
8226 @smallexample
8227 set $i = 0
8228 print bar[$i++]->contents
8229 @end smallexample
8230
8231 @noindent
8232 Repeat that command by typing @key{RET}.
8233
8234 Some convenience variables are created automatically by @value{GDBN} and given
8235 values likely to be useful.
8236
8237 @table @code
8238 @vindex $_@r{, convenience variable}
8239 @item $_
8240 The variable @code{$_} is automatically set by the @code{x} command to
8241 the last address examined (@pxref{Memory, ,Examining Memory}). Other
8242 commands which provide a default address for @code{x} to examine also
8243 set @code{$_} to that address; these commands include @code{info line}
8244 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
8245 except when set by the @code{x} command, in which case it is a pointer
8246 to the type of @code{$__}.
8247
8248 @vindex $__@r{, convenience variable}
8249 @item $__
8250 The variable @code{$__} is automatically set by the @code{x} command
8251 to the value found in the last address examined. Its type is chosen
8252 to match the format in which the data was printed.
8253
8254 @item $_exitcode
8255 @vindex $_exitcode@r{, convenience variable}
8256 The variable @code{$_exitcode} is automatically set to the exit code when
8257 the program being debugged terminates.
8258
8259 @item $_siginfo
8260 @vindex $_siginfo@r{, convenience variable}
8261 The variable @code{$_siginfo} contains extra signal information
8262 (@pxref{extra signal information}). Note that @code{$_siginfo}
8263 could be empty, if the application has not yet received any signals.
8264 For example, it will be empty before you execute the @code{run} command.
8265
8266 @item $_tlb
8267 @vindex $_tlb@r{, convenience variable}
8268 The variable @code{$_tlb} is automatically set when debugging
8269 applications running on MS-Windows in native mode or connected to
8270 gdbserver that supports the @code{qGetTIBAddr} request.
8271 @xref{General Query Packets}.
8272 This variable contains the address of the thread information block.
8273
8274 @end table
8275
8276 On HP-UX systems, if you refer to a function or variable name that
8277 begins with a dollar sign, @value{GDBN} searches for a user or system
8278 name first, before it searches for a convenience variable.
8279
8280 @cindex convenience functions
8281 @value{GDBN} also supplies some @dfn{convenience functions}. These
8282 have a syntax similar to convenience variables. A convenience
8283 function can be used in an expression just like an ordinary function;
8284 however, a convenience function is implemented internally to
8285 @value{GDBN}.
8286
8287 @table @code
8288 @item help function
8289 @kindex help function
8290 @cindex show all convenience functions
8291 Print a list of all convenience functions.
8292 @end table
8293
8294 @node Registers
8295 @section Registers
8296
8297 @cindex registers
8298 You can refer to machine register contents, in expressions, as variables
8299 with names starting with @samp{$}. The names of registers are different
8300 for each machine; use @code{info registers} to see the names used on
8301 your machine.
8302
8303 @table @code
8304 @kindex info registers
8305 @item info registers
8306 Print the names and values of all registers except floating-point
8307 and vector registers (in the selected stack frame).
8308
8309 @kindex info all-registers
8310 @cindex floating point registers
8311 @item info all-registers
8312 Print the names and values of all registers, including floating-point
8313 and vector registers (in the selected stack frame).
8314
8315 @item info registers @var{regname} @dots{}
8316 Print the @dfn{relativized} value of each specified register @var{regname}.
8317 As discussed in detail below, register values are normally relative to
8318 the selected stack frame. @var{regname} may be any register name valid on
8319 the machine you are using, with or without the initial @samp{$}.
8320 @end table
8321
8322 @cindex stack pointer register
8323 @cindex program counter register
8324 @cindex process status register
8325 @cindex frame pointer register
8326 @cindex standard registers
8327 @value{GDBN} has four ``standard'' register names that are available (in
8328 expressions) on most machines---whenever they do not conflict with an
8329 architecture's canonical mnemonics for registers. The register names
8330 @code{$pc} and @code{$sp} are used for the program counter register and
8331 the stack pointer. @code{$fp} is used for a register that contains a
8332 pointer to the current stack frame, and @code{$ps} is used for a
8333 register that contains the processor status. For example,
8334 you could print the program counter in hex with
8335
8336 @smallexample
8337 p/x $pc
8338 @end smallexample
8339
8340 @noindent
8341 or print the instruction to be executed next with
8342
8343 @smallexample
8344 x/i $pc
8345 @end smallexample
8346
8347 @noindent
8348 or add four to the stack pointer@footnote{This is a way of removing
8349 one word from the stack, on machines where stacks grow downward in
8350 memory (most machines, nowadays). This assumes that the innermost
8351 stack frame is selected; setting @code{$sp} is not allowed when other
8352 stack frames are selected. To pop entire frames off the stack,
8353 regardless of machine architecture, use @code{return};
8354 see @ref{Returning, ,Returning from a Function}.} with
8355
8356 @smallexample
8357 set $sp += 4
8358 @end smallexample
8359
8360 Whenever possible, these four standard register names are available on
8361 your machine even though the machine has different canonical mnemonics,
8362 so long as there is no conflict. The @code{info registers} command
8363 shows the canonical names. For example, on the SPARC, @code{info
8364 registers} displays the processor status register as @code{$psr} but you
8365 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
8366 is an alias for the @sc{eflags} register.
8367
8368 @value{GDBN} always considers the contents of an ordinary register as an
8369 integer when the register is examined in this way. Some machines have
8370 special registers which can hold nothing but floating point; these
8371 registers are considered to have floating point values. There is no way
8372 to refer to the contents of an ordinary register as floating point value
8373 (although you can @emph{print} it as a floating point value with
8374 @samp{print/f $@var{regname}}).
8375
8376 Some registers have distinct ``raw'' and ``virtual'' data formats. This
8377 means that the data format in which the register contents are saved by
8378 the operating system is not the same one that your program normally
8379 sees. For example, the registers of the 68881 floating point
8380 coprocessor are always saved in ``extended'' (raw) format, but all C
8381 programs expect to work with ``double'' (virtual) format. In such
8382 cases, @value{GDBN} normally works with the virtual format only (the format
8383 that makes sense for your program), but the @code{info registers} command
8384 prints the data in both formats.
8385
8386 @cindex SSE registers (x86)
8387 @cindex MMX registers (x86)
8388 Some machines have special registers whose contents can be interpreted
8389 in several different ways. For example, modern x86-based machines
8390 have SSE and MMX registers that can hold several values packed
8391 together in several different formats. @value{GDBN} refers to such
8392 registers in @code{struct} notation:
8393
8394 @smallexample
8395 (@value{GDBP}) print $xmm1
8396 $1 = @{
8397 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
8398 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
8399 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
8400 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
8401 v4_int32 = @{0, 20657912, 11, 13@},
8402 v2_int64 = @{88725056443645952, 55834574859@},
8403 uint128 = 0x0000000d0000000b013b36f800000000
8404 @}
8405 @end smallexample
8406
8407 @noindent
8408 To set values of such registers, you need to tell @value{GDBN} which
8409 view of the register you wish to change, as if you were assigning
8410 value to a @code{struct} member:
8411
8412 @smallexample
8413 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
8414 @end smallexample
8415
8416 Normally, register values are relative to the selected stack frame
8417 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
8418 value that the register would contain if all stack frames farther in
8419 were exited and their saved registers restored. In order to see the
8420 true contents of hardware registers, you must select the innermost
8421 frame (with @samp{frame 0}).
8422
8423 However, @value{GDBN} must deduce where registers are saved, from the machine
8424 code generated by your compiler. If some registers are not saved, or if
8425 @value{GDBN} is unable to locate the saved registers, the selected stack
8426 frame makes no difference.
8427
8428 @node Floating Point Hardware
8429 @section Floating Point Hardware
8430 @cindex floating point
8431
8432 Depending on the configuration, @value{GDBN} may be able to give
8433 you more information about the status of the floating point hardware.
8434
8435 @table @code
8436 @kindex info float
8437 @item info float
8438 Display hardware-dependent information about the floating
8439 point unit. The exact contents and layout vary depending on the
8440 floating point chip. Currently, @samp{info float} is supported on
8441 the ARM and x86 machines.
8442 @end table
8443
8444 @node Vector Unit
8445 @section Vector Unit
8446 @cindex vector unit
8447
8448 Depending on the configuration, @value{GDBN} may be able to give you
8449 more information about the status of the vector unit.
8450
8451 @table @code
8452 @kindex info vector
8453 @item info vector
8454 Display information about the vector unit. The exact contents and
8455 layout vary depending on the hardware.
8456 @end table
8457
8458 @node OS Information
8459 @section Operating System Auxiliary Information
8460 @cindex OS information
8461
8462 @value{GDBN} provides interfaces to useful OS facilities that can help
8463 you debug your program.
8464
8465 @cindex @code{ptrace} system call
8466 @cindex @code{struct user} contents
8467 When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
8468 machines), it interfaces with the inferior via the @code{ptrace}
8469 system call. The operating system creates a special sata structure,
8470 called @code{struct user}, for this interface. You can use the
8471 command @code{info udot} to display the contents of this data
8472 structure.
8473
8474 @table @code
8475 @item info udot
8476 @kindex info udot
8477 Display the contents of the @code{struct user} maintained by the OS
8478 kernel for the program being debugged. @value{GDBN} displays the
8479 contents of @code{struct user} as a list of hex numbers, similar to
8480 the @code{examine} command.
8481 @end table
8482
8483 @cindex auxiliary vector
8484 @cindex vector, auxiliary
8485 Some operating systems supply an @dfn{auxiliary vector} to programs at
8486 startup. This is akin to the arguments and environment that you
8487 specify for a program, but contains a system-dependent variety of
8488 binary values that tell system libraries important details about the
8489 hardware, operating system, and process. Each value's purpose is
8490 identified by an integer tag; the meanings are well-known but system-specific.
8491 Depending on the configuration and operating system facilities,
8492 @value{GDBN} may be able to show you this information. For remote
8493 targets, this functionality may further depend on the remote stub's
8494 support of the @samp{qXfer:auxv:read} packet, see
8495 @ref{qXfer auxiliary vector read}.
8496
8497 @table @code
8498 @kindex info auxv
8499 @item info auxv
8500 Display the auxiliary vector of the inferior, which can be either a
8501 live process or a core dump file. @value{GDBN} prints each tag value
8502 numerically, and also shows names and text descriptions for recognized
8503 tags. Some values in the vector are numbers, some bit masks, and some
8504 pointers to strings or other data. @value{GDBN} displays each value in the
8505 most appropriate form for a recognized tag, and in hexadecimal for
8506 an unrecognized tag.
8507 @end table
8508
8509 On some targets, @value{GDBN} can access operating-system-specific information
8510 and display it to user, without interpretation. For remote targets,
8511 this functionality depends on the remote stub's support of the
8512 @samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
8513
8514 @table @code
8515 @kindex info os processes
8516 @item info os processes
8517 Display the list of processes on the target. For each process,
8518 @value{GDBN} prints the process identifier, the name of the user, and
8519 the command corresponding to the process.
8520 @end table
8521
8522 @node Memory Region Attributes
8523 @section Memory Region Attributes
8524 @cindex memory region attributes
8525
8526 @dfn{Memory region attributes} allow you to describe special handling
8527 required by regions of your target's memory. @value{GDBN} uses
8528 attributes to determine whether to allow certain types of memory
8529 accesses; whether to use specific width accesses; and whether to cache
8530 target memory. By default the description of memory regions is
8531 fetched from the target (if the current target supports this), but the
8532 user can override the fetched regions.
8533
8534 Defined memory regions can be individually enabled and disabled. When a
8535 memory region is disabled, @value{GDBN} uses the default attributes when
8536 accessing memory in that region. Similarly, if no memory regions have
8537 been defined, @value{GDBN} uses the default attributes when accessing
8538 all memory.
8539
8540 When a memory region is defined, it is given a number to identify it;
8541 to enable, disable, or remove a memory region, you specify that number.
8542
8543 @table @code
8544 @kindex mem
8545 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
8546 Define a memory region bounded by @var{lower} and @var{upper} with
8547 attributes @var{attributes}@dots{}, and add it to the list of regions
8548 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
8549 case: it is treated as the target's maximum memory address.
8550 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
8551
8552 @item mem auto
8553 Discard any user changes to the memory regions and use target-supplied
8554 regions, if available, or no regions if the target does not support.
8555
8556 @kindex delete mem
8557 @item delete mem @var{nums}@dots{}
8558 Remove memory regions @var{nums}@dots{} from the list of regions
8559 monitored by @value{GDBN}.
8560
8561 @kindex disable mem
8562 @item disable mem @var{nums}@dots{}
8563 Disable monitoring of memory regions @var{nums}@dots{}.
8564 A disabled memory region is not forgotten.
8565 It may be enabled again later.
8566
8567 @kindex enable mem
8568 @item enable mem @var{nums}@dots{}
8569 Enable monitoring of memory regions @var{nums}@dots{}.
8570
8571 @kindex info mem
8572 @item info mem
8573 Print a table of all defined memory regions, with the following columns
8574 for each region:
8575
8576 @table @emph
8577 @item Memory Region Number
8578 @item Enabled or Disabled.
8579 Enabled memory regions are marked with @samp{y}.
8580 Disabled memory regions are marked with @samp{n}.
8581
8582 @item Lo Address
8583 The address defining the inclusive lower bound of the memory region.
8584
8585 @item Hi Address
8586 The address defining the exclusive upper bound of the memory region.
8587
8588 @item Attributes
8589 The list of attributes set for this memory region.
8590 @end table
8591 @end table
8592
8593
8594 @subsection Attributes
8595
8596 @subsubsection Memory Access Mode
8597 The access mode attributes set whether @value{GDBN} may make read or
8598 write accesses to a memory region.
8599
8600 While these attributes prevent @value{GDBN} from performing invalid
8601 memory accesses, they do nothing to prevent the target system, I/O DMA,
8602 etc.@: from accessing memory.
8603
8604 @table @code
8605 @item ro
8606 Memory is read only.
8607 @item wo
8608 Memory is write only.
8609 @item rw
8610 Memory is read/write. This is the default.
8611 @end table
8612
8613 @subsubsection Memory Access Size
8614 The access size attribute tells @value{GDBN} to use specific sized
8615 accesses in the memory region. Often memory mapped device registers
8616 require specific sized accesses. If no access size attribute is
8617 specified, @value{GDBN} may use accesses of any size.
8618
8619 @table @code
8620 @item 8
8621 Use 8 bit memory accesses.
8622 @item 16
8623 Use 16 bit memory accesses.
8624 @item 32
8625 Use 32 bit memory accesses.
8626 @item 64
8627 Use 64 bit memory accesses.
8628 @end table
8629
8630 @c @subsubsection Hardware/Software Breakpoints
8631 @c The hardware/software breakpoint attributes set whether @value{GDBN}
8632 @c will use hardware or software breakpoints for the internal breakpoints
8633 @c used by the step, next, finish, until, etc. commands.
8634 @c
8635 @c @table @code
8636 @c @item hwbreak
8637 @c Always use hardware breakpoints
8638 @c @item swbreak (default)
8639 @c @end table
8640
8641 @subsubsection Data Cache
8642 The data cache attributes set whether @value{GDBN} will cache target
8643 memory. While this generally improves performance by reducing debug
8644 protocol overhead, it can lead to incorrect results because @value{GDBN}
8645 does not know about volatile variables or memory mapped device
8646 registers.
8647
8648 @table @code
8649 @item cache
8650 Enable @value{GDBN} to cache target memory.
8651 @item nocache
8652 Disable @value{GDBN} from caching target memory. This is the default.
8653 @end table
8654
8655 @subsection Memory Access Checking
8656 @value{GDBN} can be instructed to refuse accesses to memory that is
8657 not explicitly described. This can be useful if accessing such
8658 regions has undesired effects for a specific target, or to provide
8659 better error checking. The following commands control this behaviour.
8660
8661 @table @code
8662 @kindex set mem inaccessible-by-default
8663 @item set mem inaccessible-by-default [on|off]
8664 If @code{on} is specified, make @value{GDBN} treat memory not
8665 explicitly described by the memory ranges as non-existent and refuse accesses
8666 to such memory. The checks are only performed if there's at least one
8667 memory range defined. If @code{off} is specified, make @value{GDBN}
8668 treat the memory not explicitly described by the memory ranges as RAM.
8669 The default value is @code{on}.
8670 @kindex show mem inaccessible-by-default
8671 @item show mem inaccessible-by-default
8672 Show the current handling of accesses to unknown memory.
8673 @end table
8674
8675
8676 @c @subsubsection Memory Write Verification
8677 @c The memory write verification attributes set whether @value{GDBN}
8678 @c will re-reads data after each write to verify the write was successful.
8679 @c
8680 @c @table @code
8681 @c @item verify
8682 @c @item noverify (default)
8683 @c @end table
8684
8685 @node Dump/Restore Files
8686 @section Copy Between Memory and a File
8687 @cindex dump/restore files
8688 @cindex append data to a file
8689 @cindex dump data to a file
8690 @cindex restore data from a file
8691
8692 You can use the commands @code{dump}, @code{append}, and
8693 @code{restore} to copy data between target memory and a file. The
8694 @code{dump} and @code{append} commands write data to a file, and the
8695 @code{restore} command reads data from a file back into the inferior's
8696 memory. Files may be in binary, Motorola S-record, Intel hex, or
8697 Tektronix Hex format; however, @value{GDBN} can only append to binary
8698 files.
8699
8700 @table @code
8701
8702 @kindex dump
8703 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
8704 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
8705 Dump the contents of memory from @var{start_addr} to @var{end_addr},
8706 or the value of @var{expr}, to @var{filename} in the given format.
8707
8708 The @var{format} parameter may be any one of:
8709 @table @code
8710 @item binary
8711 Raw binary form.
8712 @item ihex
8713 Intel hex format.
8714 @item srec
8715 Motorola S-record format.
8716 @item tekhex
8717 Tektronix Hex format.
8718 @end table
8719
8720 @value{GDBN} uses the same definitions of these formats as the
8721 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
8722 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
8723 form.
8724
8725 @kindex append
8726 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
8727 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
8728 Append the contents of memory from @var{start_addr} to @var{end_addr},
8729 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
8730 (@value{GDBN} can only append data to files in raw binary form.)
8731
8732 @kindex restore
8733 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
8734 Restore the contents of file @var{filename} into memory. The
8735 @code{restore} command can automatically recognize any known @sc{bfd}
8736 file format, except for raw binary. To restore a raw binary file you
8737 must specify the optional keyword @code{binary} after the filename.
8738
8739 If @var{bias} is non-zero, its value will be added to the addresses
8740 contained in the file. Binary files always start at address zero, so
8741 they will be restored at address @var{bias}. Other bfd files have
8742 a built-in location; they will be restored at offset @var{bias}
8743 from that location.
8744
8745 If @var{start} and/or @var{end} are non-zero, then only data between
8746 file offset @var{start} and file offset @var{end} will be restored.
8747 These offsets are relative to the addresses in the file, before
8748 the @var{bias} argument is applied.
8749
8750 @end table
8751
8752 @node Core File Generation
8753 @section How to Produce a Core File from Your Program
8754 @cindex dump core from inferior
8755
8756 A @dfn{core file} or @dfn{core dump} is a file that records the memory
8757 image of a running process and its process status (register values
8758 etc.). Its primary use is post-mortem debugging of a program that
8759 crashed while it ran outside a debugger. A program that crashes
8760 automatically produces a core file, unless this feature is disabled by
8761 the user. @xref{Files}, for information on invoking @value{GDBN} in
8762 the post-mortem debugging mode.
8763
8764 Occasionally, you may wish to produce a core file of the program you
8765 are debugging in order to preserve a snapshot of its state.
8766 @value{GDBN} has a special command for that.
8767
8768 @table @code
8769 @kindex gcore
8770 @kindex generate-core-file
8771 @item generate-core-file [@var{file}]
8772 @itemx gcore [@var{file}]
8773 Produce a core dump of the inferior process. The optional argument
8774 @var{file} specifies the file name where to put the core dump. If not
8775 specified, the file name defaults to @file{core.@var{pid}}, where
8776 @var{pid} is the inferior process ID.
8777
8778 Note that this command is implemented only for some systems (as of
8779 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
8780 @end table
8781
8782 @node Character Sets
8783 @section Character Sets
8784 @cindex character sets
8785 @cindex charset
8786 @cindex translating between character sets
8787 @cindex host character set
8788 @cindex target character set
8789
8790 If the program you are debugging uses a different character set to
8791 represent characters and strings than the one @value{GDBN} uses itself,
8792 @value{GDBN} can automatically translate between the character sets for
8793 you. The character set @value{GDBN} uses we call the @dfn{host
8794 character set}; the one the inferior program uses we call the
8795 @dfn{target character set}.
8796
8797 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
8798 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
8799 remote protocol (@pxref{Remote Debugging}) to debug a program
8800 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
8801 then the host character set is Latin-1, and the target character set is
8802 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
8803 target-charset EBCDIC-US}, then @value{GDBN} translates between
8804 @sc{ebcdic} and Latin 1 as you print character or string values, or use
8805 character and string literals in expressions.
8806
8807 @value{GDBN} has no way to automatically recognize which character set
8808 the inferior program uses; you must tell it, using the @code{set
8809 target-charset} command, described below.
8810
8811 Here are the commands for controlling @value{GDBN}'s character set
8812 support:
8813
8814 @table @code
8815 @item set target-charset @var{charset}
8816 @kindex set target-charset
8817 Set the current target character set to @var{charset}. To display the
8818 list of supported target character sets, type
8819 @kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
8820
8821 @item set host-charset @var{charset}
8822 @kindex set host-charset
8823 Set the current host character set to @var{charset}.
8824
8825 By default, @value{GDBN} uses a host character set appropriate to the
8826 system it is running on; you can override that default using the
8827 @code{set host-charset} command. On some systems, @value{GDBN} cannot
8828 automatically determine the appropriate host character set. In this
8829 case, @value{GDBN} uses @samp{UTF-8}.
8830
8831 @value{GDBN} can only use certain character sets as its host character
8832 set. If you type @kbd{@w{set target-charset @key{TAB}@key{TAB}}},
8833 @value{GDBN} will list the host character sets it supports.
8834
8835 @item set charset @var{charset}
8836 @kindex set charset
8837 Set the current host and target character sets to @var{charset}. As
8838 above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
8839 @value{GDBN} will list the names of the character sets that can be used
8840 for both host and target.
8841
8842 @item show charset
8843 @kindex show charset
8844 Show the names of the current host and target character sets.
8845
8846 @item show host-charset
8847 @kindex show host-charset
8848 Show the name of the current host character set.
8849
8850 @item show target-charset
8851 @kindex show target-charset
8852 Show the name of the current target character set.
8853
8854 @item set target-wide-charset @var{charset}
8855 @kindex set target-wide-charset
8856 Set the current target's wide character set to @var{charset}. This is
8857 the character set used by the target's @code{wchar_t} type. To
8858 display the list of supported wide character sets, type
8859 @kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
8860
8861 @item show target-wide-charset
8862 @kindex show target-wide-charset
8863 Show the name of the current target's wide character set.
8864 @end table
8865
8866 Here is an example of @value{GDBN}'s character set support in action.
8867 Assume that the following source code has been placed in the file
8868 @file{charset-test.c}:
8869
8870 @smallexample
8871 #include <stdio.h>
8872
8873 char ascii_hello[]
8874 = @{72, 101, 108, 108, 111, 44, 32, 119,
8875 111, 114, 108, 100, 33, 10, 0@};
8876 char ibm1047_hello[]
8877 = @{200, 133, 147, 147, 150, 107, 64, 166,
8878 150, 153, 147, 132, 90, 37, 0@};
8879
8880 main ()
8881 @{
8882 printf ("Hello, world!\n");
8883 @}
8884 @end smallexample
8885
8886 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
8887 containing the string @samp{Hello, world!} followed by a newline,
8888 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
8889
8890 We compile the program, and invoke the debugger on it:
8891
8892 @smallexample
8893 $ gcc -g charset-test.c -o charset-test
8894 $ gdb -nw charset-test
8895 GNU gdb 2001-12-19-cvs
8896 Copyright 2001 Free Software Foundation, Inc.
8897 @dots{}
8898 (@value{GDBP})
8899 @end smallexample
8900
8901 We can use the @code{show charset} command to see what character sets
8902 @value{GDBN} is currently using to interpret and display characters and
8903 strings:
8904
8905 @smallexample
8906 (@value{GDBP}) show charset
8907 The current host and target character set is `ISO-8859-1'.
8908 (@value{GDBP})
8909 @end smallexample
8910
8911 For the sake of printing this manual, let's use @sc{ascii} as our
8912 initial character set:
8913 @smallexample
8914 (@value{GDBP}) set charset ASCII
8915 (@value{GDBP}) show charset
8916 The current host and target character set is `ASCII'.
8917 (@value{GDBP})
8918 @end smallexample
8919
8920 Let's assume that @sc{ascii} is indeed the correct character set for our
8921 host system --- in other words, let's assume that if @value{GDBN} prints
8922 characters using the @sc{ascii} character set, our terminal will display
8923 them properly. Since our current target character set is also
8924 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
8925
8926 @smallexample
8927 (@value{GDBP}) print ascii_hello
8928 $1 = 0x401698 "Hello, world!\n"
8929 (@value{GDBP}) print ascii_hello[0]
8930 $2 = 72 'H'
8931 (@value{GDBP})
8932 @end smallexample
8933
8934 @value{GDBN} uses the target character set for character and string
8935 literals you use in expressions:
8936
8937 @smallexample
8938 (@value{GDBP}) print '+'
8939 $3 = 43 '+'
8940 (@value{GDBP})
8941 @end smallexample
8942
8943 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
8944 character.
8945
8946 @value{GDBN} relies on the user to tell it which character set the
8947 target program uses. If we print @code{ibm1047_hello} while our target
8948 character set is still @sc{ascii}, we get jibberish:
8949
8950 @smallexample
8951 (@value{GDBP}) print ibm1047_hello
8952 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
8953 (@value{GDBP}) print ibm1047_hello[0]
8954 $5 = 200 '\310'
8955 (@value{GDBP})
8956 @end smallexample
8957
8958 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
8959 @value{GDBN} tells us the character sets it supports:
8960
8961 @smallexample
8962 (@value{GDBP}) set target-charset
8963 ASCII EBCDIC-US IBM1047 ISO-8859-1
8964 (@value{GDBP}) set target-charset
8965 @end smallexample
8966
8967 We can select @sc{ibm1047} as our target character set, and examine the
8968 program's strings again. Now the @sc{ascii} string is wrong, but
8969 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
8970 target character set, @sc{ibm1047}, to the host character set,
8971 @sc{ascii}, and they display correctly:
8972
8973 @smallexample
8974 (@value{GDBP}) set target-charset IBM1047
8975 (@value{GDBP}) show charset
8976 The current host character set is `ASCII'.
8977 The current target character set is `IBM1047'.
8978 (@value{GDBP}) print ascii_hello
8979 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
8980 (@value{GDBP}) print ascii_hello[0]
8981 $7 = 72 '\110'
8982 (@value{GDBP}) print ibm1047_hello
8983 $8 = 0x4016a8 "Hello, world!\n"
8984 (@value{GDBP}) print ibm1047_hello[0]
8985 $9 = 200 'H'
8986 (@value{GDBP})
8987 @end smallexample
8988
8989 As above, @value{GDBN} uses the target character set for character and
8990 string literals you use in expressions:
8991
8992 @smallexample
8993 (@value{GDBP}) print '+'
8994 $10 = 78 '+'
8995 (@value{GDBP})
8996 @end smallexample
8997
8998 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
8999 character.
9000
9001 @node Caching Remote Data
9002 @section Caching Data of Remote Targets
9003 @cindex caching data of remote targets
9004
9005 @value{GDBN} caches data exchanged between the debugger and a
9006 remote target (@pxref{Remote Debugging}). Such caching generally improves
9007 performance, because it reduces the overhead of the remote protocol by
9008 bundling memory reads and writes into large chunks. Unfortunately, simply
9009 caching everything would lead to incorrect results, since @value{GDBN}
9010 does not necessarily know anything about volatile values, memory-mapped I/O
9011 addresses, etc. Furthermore, in non-stop mode (@pxref{Non-Stop Mode})
9012 memory can be changed @emph{while} a gdb command is executing.
9013 Therefore, by default, @value{GDBN} only caches data
9014 known to be on the stack@footnote{In non-stop mode, it is moderately
9015 rare for a running thread to modify the stack of a stopped thread
9016 in a way that would interfere with a backtrace, and caching of
9017 stack reads provides a significant speed up of remote backtraces.}.
9018 Other regions of memory can be explicitly marked as
9019 cacheable; see @pxref{Memory Region Attributes}.
9020
9021 @table @code
9022 @kindex set remotecache
9023 @item set remotecache on
9024 @itemx set remotecache off
9025 This option no longer does anything; it exists for compatibility
9026 with old scripts.
9027
9028 @kindex show remotecache
9029 @item show remotecache
9030 Show the current state of the obsolete remotecache flag.
9031
9032 @kindex set stack-cache
9033 @item set stack-cache on
9034 @itemx set stack-cache off
9035 Enable or disable caching of stack accesses. When @code{ON}, use
9036 caching. By default, this option is @code{ON}.
9037
9038 @kindex show stack-cache
9039 @item show stack-cache
9040 Show the current state of data caching for memory accesses.
9041
9042 @kindex info dcache
9043 @item info dcache @r{[}line@r{]}
9044 Print the information about the data cache performance. The
9045 information displayed includes the dcache width and depth, and for
9046 each cache line, its number, address, and how many times it was
9047 referenced. This command is useful for debugging the data cache
9048 operation.
9049
9050 If a line number is specified, the contents of that line will be
9051 printed in hex.
9052 @end table
9053
9054 @node Searching Memory
9055 @section Search Memory
9056 @cindex searching memory
9057
9058 Memory can be searched for a particular sequence of bytes with the
9059 @code{find} command.
9060
9061 @table @code
9062 @kindex find
9063 @item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
9064 @itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
9065 Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
9066 etc. The search begins at address @var{start_addr} and continues for either
9067 @var{len} bytes or through to @var{end_addr} inclusive.
9068 @end table
9069
9070 @var{s} and @var{n} are optional parameters.
9071 They may be specified in either order, apart or together.
9072
9073 @table @r
9074 @item @var{s}, search query size
9075 The size of each search query value.
9076
9077 @table @code
9078 @item b
9079 bytes
9080 @item h
9081 halfwords (two bytes)
9082 @item w
9083 words (four bytes)
9084 @item g
9085 giant words (eight bytes)
9086 @end table
9087
9088 All values are interpreted in the current language.
9089 This means, for example, that if the current source language is C/C@t{++}
9090 then searching for the string ``hello'' includes the trailing '\0'.
9091
9092 If the value size is not specified, it is taken from the
9093 value's type in the current language.
9094 This is useful when one wants to specify the search
9095 pattern as a mixture of types.
9096 Note that this means, for example, that in the case of C-like languages
9097 a search for an untyped 0x42 will search for @samp{(int) 0x42}
9098 which is typically four bytes.
9099
9100 @item @var{n}, maximum number of finds
9101 The maximum number of matches to print. The default is to print all finds.
9102 @end table
9103
9104 You can use strings as search values. Quote them with double-quotes
9105 (@code{"}).
9106 The string value is copied into the search pattern byte by byte,
9107 regardless of the endianness of the target and the size specification.
9108
9109 The address of each match found is printed as well as a count of the
9110 number of matches found.
9111
9112 The address of the last value found is stored in convenience variable
9113 @samp{$_}.
9114 A count of the number of matches is stored in @samp{$numfound}.
9115
9116 For example, if stopped at the @code{printf} in this function:
9117
9118 @smallexample
9119 void
9120 hello ()
9121 @{
9122 static char hello[] = "hello-hello";
9123 static struct @{ char c; short s; int i; @}
9124 __attribute__ ((packed)) mixed
9125 = @{ 'c', 0x1234, 0x87654321 @};
9126 printf ("%s\n", hello);
9127 @}
9128 @end smallexample
9129
9130 @noindent
9131 you get during debugging:
9132
9133 @smallexample
9134 (gdb) find &hello[0], +sizeof(hello), "hello"
9135 0x804956d <hello.1620+6>
9136 1 pattern found
9137 (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
9138 0x8049567 <hello.1620>
9139 0x804956d <hello.1620+6>
9140 2 patterns found
9141 (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
9142 0x8049567 <hello.1620>
9143 1 pattern found
9144 (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
9145 0x8049560 <mixed.1625>
9146 1 pattern found
9147 (gdb) print $numfound
9148 $1 = 1
9149 (gdb) print $_
9150 $2 = (void *) 0x8049560
9151 @end smallexample
9152
9153 @node Optimized Code
9154 @chapter Debugging Optimized Code
9155 @cindex optimized code, debugging
9156 @cindex debugging optimized code
9157
9158 Almost all compilers support optimization. With optimization
9159 disabled, the compiler generates assembly code that corresponds
9160 directly to your source code, in a simplistic way. As the compiler
9161 applies more powerful optimizations, the generated assembly code
9162 diverges from your original source code. With help from debugging
9163 information generated by the compiler, @value{GDBN} can map from
9164 the running program back to constructs from your original source.
9165
9166 @value{GDBN} is more accurate with optimization disabled. If you
9167 can recompile without optimization, it is easier to follow the
9168 progress of your program during debugging. But, there are many cases
9169 where you may need to debug an optimized version.
9170
9171 When you debug a program compiled with @samp{-g -O}, remember that the
9172 optimizer has rearranged your code; the debugger shows you what is
9173 really there. Do not be too surprised when the execution path does not
9174 exactly match your source file! An extreme example: if you define a
9175 variable, but never use it, @value{GDBN} never sees that
9176 variable---because the compiler optimizes it out of existence.
9177
9178 Some things do not work as well with @samp{-g -O} as with just
9179 @samp{-g}, particularly on machines with instruction scheduling. If in
9180 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
9181 please report it to us as a bug (including a test case!).
9182 @xref{Variables}, for more information about debugging optimized code.
9183
9184 @menu
9185 * Inline Functions:: How @value{GDBN} presents inlining
9186 @end menu
9187
9188 @node Inline Functions
9189 @section Inline Functions
9190 @cindex inline functions, debugging
9191
9192 @dfn{Inlining} is an optimization that inserts a copy of the function
9193 body directly at each call site, instead of jumping to a shared
9194 routine. @value{GDBN} displays inlined functions just like
9195 non-inlined functions. They appear in backtraces. You can view their
9196 arguments and local variables, step into them with @code{step}, skip
9197 them with @code{next}, and escape from them with @code{finish}.
9198 You can check whether a function was inlined by using the
9199 @code{info frame} command.
9200
9201 For @value{GDBN} to support inlined functions, the compiler must
9202 record information about inlining in the debug information ---
9203 @value{NGCC} using the @sc{dwarf 2} format does this, and several
9204 other compilers do also. @value{GDBN} only supports inlined functions
9205 when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
9206 do not emit two required attributes (@samp{DW_AT_call_file} and
9207 @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
9208 function calls with earlier versions of @value{NGCC}. It instead
9209 displays the arguments and local variables of inlined functions as
9210 local variables in the caller.
9211
9212 The body of an inlined function is directly included at its call site;
9213 unlike a non-inlined function, there are no instructions devoted to
9214 the call. @value{GDBN} still pretends that the call site and the
9215 start of the inlined function are different instructions. Stepping to
9216 the call site shows the call site, and then stepping again shows
9217 the first line of the inlined function, even though no additional
9218 instructions are executed.
9219
9220 This makes source-level debugging much clearer; you can see both the
9221 context of the call and then the effect of the call. Only stepping by
9222 a single instruction using @code{stepi} or @code{nexti} does not do
9223 this; single instruction steps always show the inlined body.
9224
9225 There are some ways that @value{GDBN} does not pretend that inlined
9226 function calls are the same as normal calls:
9227
9228 @itemize @bullet
9229 @item
9230 You cannot set breakpoints on inlined functions. @value{GDBN}
9231 either reports that there is no symbol with that name, or else sets the
9232 breakpoint only on non-inlined copies of the function. This limitation
9233 will be removed in a future version of @value{GDBN}; until then,
9234 set a breakpoint by line number on the first line of the inlined
9235 function instead.
9236
9237 @item
9238 Setting breakpoints at the call site of an inlined function may not
9239 work, because the call site does not contain any code. @value{GDBN}
9240 may incorrectly move the breakpoint to the next line of the enclosing
9241 function, after the call. This limitation will be removed in a future
9242 version of @value{GDBN}; until then, set a breakpoint on an earlier line
9243 or inside the inlined function instead.
9244
9245 @item
9246 @value{GDBN} cannot locate the return value of inlined calls after
9247 using the @code{finish} command. This is a limitation of compiler-generated
9248 debugging information; after @code{finish}, you can step to the next line
9249 and print a variable where your program stored the return value.
9250
9251 @end itemize
9252
9253
9254 @node Macros
9255 @chapter C Preprocessor Macros
9256
9257 Some languages, such as C and C@t{++}, provide a way to define and invoke
9258 ``preprocessor macros'' which expand into strings of tokens.
9259 @value{GDBN} can evaluate expressions containing macro invocations, show
9260 the result of macro expansion, and show a macro's definition, including
9261 where it was defined.
9262
9263 You may need to compile your program specially to provide @value{GDBN}
9264 with information about preprocessor macros. Most compilers do not
9265 include macros in their debugging information, even when you compile
9266 with the @option{-g} flag. @xref{Compilation}.
9267
9268 A program may define a macro at one point, remove that definition later,
9269 and then provide a different definition after that. Thus, at different
9270 points in the program, a macro may have different definitions, or have
9271 no definition at all. If there is a current stack frame, @value{GDBN}
9272 uses the macros in scope at that frame's source code line. Otherwise,
9273 @value{GDBN} uses the macros in scope at the current listing location;
9274 see @ref{List}.
9275
9276 Whenever @value{GDBN} evaluates an expression, it always expands any
9277 macro invocations present in the expression. @value{GDBN} also provides
9278 the following commands for working with macros explicitly.
9279
9280 @table @code
9281
9282 @kindex macro expand
9283 @cindex macro expansion, showing the results of preprocessor
9284 @cindex preprocessor macro expansion, showing the results of
9285 @cindex expanding preprocessor macros
9286 @item macro expand @var{expression}
9287 @itemx macro exp @var{expression}
9288 Show the results of expanding all preprocessor macro invocations in
9289 @var{expression}. Since @value{GDBN} simply expands macros, but does
9290 not parse the result, @var{expression} need not be a valid expression;
9291 it can be any string of tokens.
9292
9293 @kindex macro exp1
9294 @item macro expand-once @var{expression}
9295 @itemx macro exp1 @var{expression}
9296 @cindex expand macro once
9297 @i{(This command is not yet implemented.)} Show the results of
9298 expanding those preprocessor macro invocations that appear explicitly in
9299 @var{expression}. Macro invocations appearing in that expansion are
9300 left unchanged. This command allows you to see the effect of a
9301 particular macro more clearly, without being confused by further
9302 expansions. Since @value{GDBN} simply expands macros, but does not
9303 parse the result, @var{expression} need not be a valid expression; it
9304 can be any string of tokens.
9305
9306 @kindex info macro
9307 @cindex macro definition, showing
9308 @cindex definition, showing a macro's
9309 @item info macro @var{macro}
9310 Show the definition of the macro named @var{macro}, and describe the
9311 source location or compiler command-line where that definition was established.
9312
9313 @kindex macro define
9314 @cindex user-defined macros
9315 @cindex defining macros interactively
9316 @cindex macros, user-defined
9317 @item macro define @var{macro} @var{replacement-list}
9318 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
9319 Introduce a definition for a preprocessor macro named @var{macro},
9320 invocations of which are replaced by the tokens given in
9321 @var{replacement-list}. The first form of this command defines an
9322 ``object-like'' macro, which takes no arguments; the second form
9323 defines a ``function-like'' macro, which takes the arguments given in
9324 @var{arglist}.
9325
9326 A definition introduced by this command is in scope in every
9327 expression evaluated in @value{GDBN}, until it is removed with the
9328 @code{macro undef} command, described below. The definition overrides
9329 all definitions for @var{macro} present in the program being debugged,
9330 as well as any previous user-supplied definition.
9331
9332 @kindex macro undef
9333 @item macro undef @var{macro}
9334 Remove any user-supplied definition for the macro named @var{macro}.
9335 This command only affects definitions provided with the @code{macro
9336 define} command, described above; it cannot remove definitions present
9337 in the program being debugged.
9338
9339 @kindex macro list
9340 @item macro list
9341 List all the macros defined using the @code{macro define} command.
9342 @end table
9343
9344 @cindex macros, example of debugging with
9345 Here is a transcript showing the above commands in action. First, we
9346 show our source files:
9347
9348 @smallexample
9349 $ cat sample.c
9350 #include <stdio.h>
9351 #include "sample.h"
9352
9353 #define M 42
9354 #define ADD(x) (M + x)
9355
9356 main ()
9357 @{
9358 #define N 28
9359 printf ("Hello, world!\n");
9360 #undef N
9361 printf ("We're so creative.\n");
9362 #define N 1729
9363 printf ("Goodbye, world!\n");
9364 @}
9365 $ cat sample.h
9366 #define Q <
9367 $
9368 @end smallexample
9369
9370 Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
9371 We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
9372 compiler includes information about preprocessor macros in the debugging
9373 information.
9374
9375 @smallexample
9376 $ gcc -gdwarf-2 -g3 sample.c -o sample
9377 $
9378 @end smallexample
9379
9380 Now, we start @value{GDBN} on our sample program:
9381
9382 @smallexample
9383 $ gdb -nw sample
9384 GNU gdb 2002-05-06-cvs
9385 Copyright 2002 Free Software Foundation, Inc.
9386 GDB is free software, @dots{}
9387 (@value{GDBP})
9388 @end smallexample
9389
9390 We can expand macros and examine their definitions, even when the
9391 program is not running. @value{GDBN} uses the current listing position
9392 to decide which macro definitions are in scope:
9393
9394 @smallexample
9395 (@value{GDBP}) list main
9396 3
9397 4 #define M 42
9398 5 #define ADD(x) (M + x)
9399 6
9400 7 main ()
9401 8 @{
9402 9 #define N 28
9403 10 printf ("Hello, world!\n");
9404 11 #undef N
9405 12 printf ("We're so creative.\n");
9406 (@value{GDBP}) info macro ADD
9407 Defined at /home/jimb/gdb/macros/play/sample.c:5
9408 #define ADD(x) (M + x)
9409 (@value{GDBP}) info macro Q
9410 Defined at /home/jimb/gdb/macros/play/sample.h:1
9411 included at /home/jimb/gdb/macros/play/sample.c:2
9412 #define Q <
9413 (@value{GDBP}) macro expand ADD(1)
9414 expands to: (42 + 1)
9415 (@value{GDBP}) macro expand-once ADD(1)
9416 expands to: once (M + 1)
9417 (@value{GDBP})
9418 @end smallexample
9419
9420 In the example above, note that @code{macro expand-once} expands only
9421 the macro invocation explicit in the original text --- the invocation of
9422 @code{ADD} --- but does not expand the invocation of the macro @code{M},
9423 which was introduced by @code{ADD}.
9424
9425 Once the program is running, @value{GDBN} uses the macro definitions in
9426 force at the source line of the current stack frame:
9427
9428 @smallexample
9429 (@value{GDBP}) break main
9430 Breakpoint 1 at 0x8048370: file sample.c, line 10.
9431 (@value{GDBP}) run
9432 Starting program: /home/jimb/gdb/macros/play/sample
9433
9434 Breakpoint 1, main () at sample.c:10
9435 10 printf ("Hello, world!\n");
9436 (@value{GDBP})
9437 @end smallexample
9438
9439 At line 10, the definition of the macro @code{N} at line 9 is in force:
9440
9441 @smallexample
9442 (@value{GDBP}) info macro N
9443 Defined at /home/jimb/gdb/macros/play/sample.c:9
9444 #define N 28
9445 (@value{GDBP}) macro expand N Q M
9446 expands to: 28 < 42
9447 (@value{GDBP}) print N Q M
9448 $1 = 1
9449 (@value{GDBP})
9450 @end smallexample
9451
9452 As we step over directives that remove @code{N}'s definition, and then
9453 give it a new definition, @value{GDBN} finds the definition (or lack
9454 thereof) in force at each point:
9455
9456 @smallexample
9457 (@value{GDBP}) next
9458 Hello, world!
9459 12 printf ("We're so creative.\n");
9460 (@value{GDBP}) info macro N
9461 The symbol `N' has no definition as a C/C++ preprocessor macro
9462 at /home/jimb/gdb/macros/play/sample.c:12
9463 (@value{GDBP}) next
9464 We're so creative.
9465 14 printf ("Goodbye, world!\n");
9466 (@value{GDBP}) info macro N
9467 Defined at /home/jimb/gdb/macros/play/sample.c:13
9468 #define N 1729
9469 (@value{GDBP}) macro expand N Q M
9470 expands to: 1729 < 42
9471 (@value{GDBP}) print N Q M
9472 $2 = 0
9473 (@value{GDBP})
9474 @end smallexample
9475
9476 In addition to source files, macros can be defined on the compilation command
9477 line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
9478 such a way, @value{GDBN} displays the location of their definition as line zero
9479 of the source file submitted to the compiler.
9480
9481 @smallexample
9482 (@value{GDBP}) info macro __STDC__
9483 Defined at /home/jimb/gdb/macros/play/sample.c:0
9484 -D__STDC__=1
9485 (@value{GDBP})
9486 @end smallexample
9487
9488
9489 @node Tracepoints
9490 @chapter Tracepoints
9491 @c This chapter is based on the documentation written by Michael
9492 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
9493
9494 @cindex tracepoints
9495 In some applications, it is not feasible for the debugger to interrupt
9496 the program's execution long enough for the developer to learn
9497 anything helpful about its behavior. If the program's correctness
9498 depends on its real-time behavior, delays introduced by a debugger
9499 might cause the program to change its behavior drastically, or perhaps
9500 fail, even when the code itself is correct. It is useful to be able
9501 to observe the program's behavior without interrupting it.
9502
9503 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
9504 specify locations in the program, called @dfn{tracepoints}, and
9505 arbitrary expressions to evaluate when those tracepoints are reached.
9506 Later, using the @code{tfind} command, you can examine the values
9507 those expressions had when the program hit the tracepoints. The
9508 expressions may also denote objects in memory---structures or arrays,
9509 for example---whose values @value{GDBN} should record; while visiting
9510 a particular tracepoint, you may inspect those objects as if they were
9511 in memory at that moment. However, because @value{GDBN} records these
9512 values without interacting with you, it can do so quickly and
9513 unobtrusively, hopefully not disturbing the program's behavior.
9514
9515 The tracepoint facility is currently available only for remote
9516 targets. @xref{Targets}. In addition, your remote target must know
9517 how to collect trace data. This functionality is implemented in the
9518 remote stub; however, none of the stubs distributed with @value{GDBN}
9519 support tracepoints as of this writing. The format of the remote
9520 packets used to implement tracepoints are described in @ref{Tracepoint
9521 Packets}.
9522
9523 It is also possible to get trace data from a file, in a manner reminiscent
9524 of corefiles; you specify the filename, and use @code{tfind} to search
9525 through the file. @xref{Trace Files}, for more details.
9526
9527 This chapter describes the tracepoint commands and features.
9528
9529 @menu
9530 * Set Tracepoints::
9531 * Analyze Collected Data::
9532 * Tracepoint Variables::
9533 * Trace Files::
9534 @end menu
9535
9536 @node Set Tracepoints
9537 @section Commands to Set Tracepoints
9538
9539 Before running such a @dfn{trace experiment}, an arbitrary number of
9540 tracepoints can be set. A tracepoint is actually a special type of
9541 breakpoint (@pxref{Set Breaks}), so you can manipulate it using
9542 standard breakpoint commands. For instance, as with breakpoints,
9543 tracepoint numbers are successive integers starting from one, and many
9544 of the commands associated with tracepoints take the tracepoint number
9545 as their argument, to identify which tracepoint to work on.
9546
9547 For each tracepoint, you can specify, in advance, some arbitrary set
9548 of data that you want the target to collect in the trace buffer when
9549 it hits that tracepoint. The collected data can include registers,
9550 local variables, or global data. Later, you can use @value{GDBN}
9551 commands to examine the values these data had at the time the
9552 tracepoint was hit.
9553
9554 Tracepoints do not support every breakpoint feature. Ignore counts on
9555 tracepoints have no effect, and tracepoints cannot run @value{GDBN}
9556 commands when they are hit. Tracepoints may not be thread-specific
9557 either.
9558
9559 @cindex fast tracepoints
9560 Some targets may support @dfn{fast tracepoints}, which are inserted in
9561 a different way (such as with a jump instead of a trap), that is
9562 faster but possibly restricted in where they may be installed.
9563
9564 @code{gdbserver} supports tracepoints on some target systems.
9565 @xref{Server,,Tracepoints support in @code{gdbserver}}.
9566
9567 This section describes commands to set tracepoints and associated
9568 conditions and actions.
9569
9570 @menu
9571 * Create and Delete Tracepoints::
9572 * Enable and Disable Tracepoints::
9573 * Tracepoint Passcounts::
9574 * Tracepoint Conditions::
9575 * Trace State Variables::
9576 * Tracepoint Actions::
9577 * Listing Tracepoints::
9578 * Starting and Stopping Trace Experiments::
9579 * Tracepoint Restrictions::
9580 @end menu
9581
9582 @node Create and Delete Tracepoints
9583 @subsection Create and Delete Tracepoints
9584
9585 @table @code
9586 @cindex set tracepoint
9587 @kindex trace
9588 @item trace @var{location}
9589 The @code{trace} command is very similar to the @code{break} command.
9590 Its argument @var{location} can be a source line, a function name, or
9591 an address in the target program. @xref{Specify Location}. The
9592 @code{trace} command defines a tracepoint, which is a point in the
9593 target program where the debugger will briefly stop, collect some
9594 data, and then allow the program to continue. Setting a tracepoint or
9595 changing its actions doesn't take effect until the next @code{tstart}
9596 command, and once a trace experiment is running, further changes will
9597 not have any effect until the next trace experiment starts.
9598
9599 Here are some examples of using the @code{trace} command:
9600
9601 @smallexample
9602 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
9603
9604 (@value{GDBP}) @b{trace +2} // 2 lines forward
9605
9606 (@value{GDBP}) @b{trace my_function} // first source line of function
9607
9608 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
9609
9610 (@value{GDBP}) @b{trace *0x2117c4} // an address
9611 @end smallexample
9612
9613 @noindent
9614 You can abbreviate @code{trace} as @code{tr}.
9615
9616 @item trace @var{location} if @var{cond}
9617 Set a tracepoint with condition @var{cond}; evaluate the expression
9618 @var{cond} each time the tracepoint is reached, and collect data only
9619 if the value is nonzero---that is, if @var{cond} evaluates as true.
9620 @xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
9621 information on tracepoint conditions.
9622
9623 @item ftrace @var{location} [ if @var{cond} ]
9624 @cindex set fast tracepoint
9625 @kindex ftrace
9626 The @code{ftrace} command sets a fast tracepoint. For targets that
9627 support them, fast tracepoints will use a more efficient but possibly
9628 less general technique to trigger data collection, such as a jump
9629 instruction instead of a trap, or some sort of hardware support. It
9630 may not be possible to create a fast tracepoint at the desired
9631 location, in which case the command will exit with an explanatory
9632 message.
9633
9634 @value{GDBN} handles arguments to @code{ftrace} exactly as for
9635 @code{trace}.
9636
9637 @vindex $tpnum
9638 @cindex last tracepoint number
9639 @cindex recent tracepoint number
9640 @cindex tracepoint number
9641 The convenience variable @code{$tpnum} records the tracepoint number
9642 of the most recently set tracepoint.
9643
9644 @kindex delete tracepoint
9645 @cindex tracepoint deletion
9646 @item delete tracepoint @r{[}@var{num}@r{]}
9647 Permanently delete one or more tracepoints. With no argument, the
9648 default is to delete all tracepoints. Note that the regular
9649 @code{delete} command can remove tracepoints also.
9650
9651 Examples:
9652
9653 @smallexample
9654 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
9655
9656 (@value{GDBP}) @b{delete trace} // remove all tracepoints
9657 @end smallexample
9658
9659 @noindent
9660 You can abbreviate this command as @code{del tr}.
9661 @end table
9662
9663 @node Enable and Disable Tracepoints
9664 @subsection Enable and Disable Tracepoints
9665
9666 These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
9667
9668 @table @code
9669 @kindex disable tracepoint
9670 @item disable tracepoint @r{[}@var{num}@r{]}
9671 Disable tracepoint @var{num}, or all tracepoints if no argument
9672 @var{num} is given. A disabled tracepoint will have no effect during
9673 the next trace experiment, but it is not forgotten. You can re-enable
9674 a disabled tracepoint using the @code{enable tracepoint} command.
9675
9676 @kindex enable tracepoint
9677 @item enable tracepoint @r{[}@var{num}@r{]}
9678 Enable tracepoint @var{num}, or all tracepoints. The enabled
9679 tracepoints will become effective the next time a trace experiment is
9680 run.
9681 @end table
9682
9683 @node Tracepoint Passcounts
9684 @subsection Tracepoint Passcounts
9685
9686 @table @code
9687 @kindex passcount
9688 @cindex tracepoint pass count
9689 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
9690 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
9691 automatically stop a trace experiment. If a tracepoint's passcount is
9692 @var{n}, then the trace experiment will be automatically stopped on
9693 the @var{n}'th time that tracepoint is hit. If the tracepoint number
9694 @var{num} is not specified, the @code{passcount} command sets the
9695 passcount of the most recently defined tracepoint. If no passcount is
9696 given, the trace experiment will run until stopped explicitly by the
9697 user.
9698
9699 Examples:
9700
9701 @smallexample
9702 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
9703 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
9704
9705 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
9706 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
9707 (@value{GDBP}) @b{trace foo}
9708 (@value{GDBP}) @b{pass 3}
9709 (@value{GDBP}) @b{trace bar}
9710 (@value{GDBP}) @b{pass 2}
9711 (@value{GDBP}) @b{trace baz}
9712 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
9713 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
9714 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
9715 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
9716 @end smallexample
9717 @end table
9718
9719 @node Tracepoint Conditions
9720 @subsection Tracepoint Conditions
9721 @cindex conditional tracepoints
9722 @cindex tracepoint conditions
9723
9724 The simplest sort of tracepoint collects data every time your program
9725 reaches a specified place. You can also specify a @dfn{condition} for
9726 a tracepoint. A condition is just a Boolean expression in your
9727 programming language (@pxref{Expressions, ,Expressions}). A
9728 tracepoint with a condition evaluates the expression each time your
9729 program reaches it, and data collection happens only if the condition
9730 is true.
9731
9732 Tracepoint conditions can be specified when a tracepoint is set, by
9733 using @samp{if} in the arguments to the @code{trace} command.
9734 @xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
9735 also be set or changed at any time with the @code{condition} command,
9736 just as with breakpoints.
9737
9738 Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
9739 the conditional expression itself. Instead, @value{GDBN} encodes the
9740 expression into an agent expression (@pxref{Agent Expressions}
9741 suitable for execution on the target, independently of @value{GDBN}.
9742 Global variables become raw memory locations, locals become stack
9743 accesses, and so forth.
9744
9745 For instance, suppose you have a function that is usually called
9746 frequently, but should not be called after an error has occurred. You
9747 could use the following tracepoint command to collect data about calls
9748 of that function that happen while the error code is propagating
9749 through the program; an unconditional tracepoint could end up
9750 collecting thousands of useless trace frames that you would have to
9751 search through.
9752
9753 @smallexample
9754 (@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
9755 @end smallexample
9756
9757 @node Trace State Variables
9758 @subsection Trace State Variables
9759 @cindex trace state variables
9760
9761 A @dfn{trace state variable} is a special type of variable that is
9762 created and managed by target-side code. The syntax is the same as
9763 that for GDB's convenience variables (a string prefixed with ``$''),
9764 but they are stored on the target. They must be created explicitly,
9765 using a @code{tvariable} command. They are always 64-bit signed
9766 integers.
9767
9768 Trace state variables are remembered by @value{GDBN}, and downloaded
9769 to the target along with tracepoint information when the trace
9770 experiment starts. There are no intrinsic limits on the number of
9771 trace state variables, beyond memory limitations of the target.
9772
9773 @cindex convenience variables, and trace state variables
9774 Although trace state variables are managed by the target, you can use
9775 them in print commands and expressions as if they were convenience
9776 variables; @value{GDBN} will get the current value from the target
9777 while the trace experiment is running. Trace state variables share
9778 the same namespace as other ``$'' variables, which means that you
9779 cannot have trace state variables with names like @code{$23} or
9780 @code{$pc}, nor can you have a trace state variable and a convenience
9781 variable with the same name.
9782
9783 @table @code
9784
9785 @item tvariable $@var{name} [ = @var{expression} ]
9786 @kindex tvariable
9787 The @code{tvariable} command creates a new trace state variable named
9788 @code{$@var{name}}, and optionally gives it an initial value of
9789 @var{expression}. @var{expression} is evaluated when this command is
9790 entered; the result will be converted to an integer if possible,
9791 otherwise @value{GDBN} will report an error. A subsequent
9792 @code{tvariable} command specifying the same name does not create a
9793 variable, but instead assigns the supplied initial value to the
9794 existing variable of that name, overwriting any previous initial
9795 value. The default initial value is 0.
9796
9797 @item info tvariables
9798 @kindex info tvariables
9799 List all the trace state variables along with their initial values.
9800 Their current values may also be displayed, if the trace experiment is
9801 currently running.
9802
9803 @item delete tvariable @r{[} $@var{name} @dots{} @r{]}
9804 @kindex delete tvariable
9805 Delete the given trace state variables, or all of them if no arguments
9806 are specified.
9807
9808 @end table
9809
9810 @node Tracepoint Actions
9811 @subsection Tracepoint Action Lists
9812
9813 @table @code
9814 @kindex actions
9815 @cindex tracepoint actions
9816 @item actions @r{[}@var{num}@r{]}
9817 This command will prompt for a list of actions to be taken when the
9818 tracepoint is hit. If the tracepoint number @var{num} is not
9819 specified, this command sets the actions for the one that was most
9820 recently defined (so that you can define a tracepoint and then say
9821 @code{actions} without bothering about its number). You specify the
9822 actions themselves on the following lines, one action at a time, and
9823 terminate the actions list with a line containing just @code{end}. So
9824 far, the only defined actions are @code{collect}, @code{teval}, and
9825 @code{while-stepping}.
9826
9827 @code{actions} is actually equivalent to @code{commands} (@pxref{Break
9828 Commands, ,Breakpoint Command Lists}), except that only the defined
9829 actions are allowed; any other @value{GDBN} command is rejected.
9830
9831 @cindex remove actions from a tracepoint
9832 To remove all actions from a tracepoint, type @samp{actions @var{num}}
9833 and follow it immediately with @samp{end}.
9834
9835 @smallexample
9836 (@value{GDBP}) @b{collect @var{data}} // collect some data
9837
9838 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
9839
9840 (@value{GDBP}) @b{end} // signals the end of actions.
9841 @end smallexample
9842
9843 In the following example, the action list begins with @code{collect}
9844 commands indicating the things to be collected when the tracepoint is
9845 hit. Then, in order to single-step and collect additional data
9846 following the tracepoint, a @code{while-stepping} command is used,
9847 followed by the list of things to be collected after each step in a
9848 sequence of single steps. The @code{while-stepping} command is
9849 terminated by its own separate @code{end} command. Lastly, the action
9850 list is terminated by an @code{end} command.
9851
9852 @smallexample
9853 (@value{GDBP}) @b{trace foo}
9854 (@value{GDBP}) @b{actions}
9855 Enter actions for tracepoint 1, one per line:
9856 > collect bar,baz
9857 > collect $regs
9858 > while-stepping 12
9859 > collect $pc, arr[i]
9860 > end
9861 end
9862 @end smallexample
9863
9864 @kindex collect @r{(tracepoints)}
9865 @item collect @var{expr1}, @var{expr2}, @dots{}
9866 Collect values of the given expressions when the tracepoint is hit.
9867 This command accepts a comma-separated list of any valid expressions.
9868 In addition to global, static, or local variables, the following
9869 special arguments are supported:
9870
9871 @table @code
9872 @item $regs
9873 collect all registers
9874
9875 @item $args
9876 collect all function arguments
9877
9878 @item $locals
9879 collect all local variables.
9880 @end table
9881
9882 You can give several consecutive @code{collect} commands, each one
9883 with a single argument, or one @code{collect} command with several
9884 arguments separated by commas; the effect is the same.
9885
9886 The command @code{info scope} (@pxref{Symbols, info scope}) is
9887 particularly useful for figuring out what data to collect.
9888
9889 @kindex teval @r{(tracepoints)}
9890 @item teval @var{expr1}, @var{expr2}, @dots{}
9891 Evaluate the given expressions when the tracepoint is hit. This
9892 command accepts a comma-separated list of expressions. The results
9893 are discarded, so this is mainly useful for assigning values to trace
9894 state variables (@pxref{Trace State Variables}) without adding those
9895 values to the trace buffer, as would be the case if the @code{collect}
9896 action were used.
9897
9898 @kindex while-stepping @r{(tracepoints)}
9899 @item while-stepping @var{n}
9900 Perform @var{n} single-step instruction traces after the tracepoint,
9901 collecting new data after each step. The @code{while-stepping}
9902 command is followed by the list of what to collect while stepping
9903 (followed by its own @code{end} command):
9904
9905 @smallexample
9906 > while-stepping 12
9907 > collect $regs, myglobal
9908 > end
9909 >
9910 @end smallexample
9911
9912 @noindent
9913 Note that @code{$pc} is not automatically collected by
9914 @code{while-stepping}; you need to explicitly collect that register if
9915 you need it. You may abbreviate @code{while-stepping} as @code{ws} or
9916 @code{stepping}.
9917
9918 @item set default-collect @var{expr1}, @var{expr2}, @dots{}
9919 @kindex set default-collect
9920 @cindex default collection action
9921 This variable is a list of expressions to collect at each tracepoint
9922 hit. It is effectively an additional @code{collect} action prepended
9923 to every tracepoint action list. The expressions are parsed
9924 individually for each tracepoint, so for instance a variable named
9925 @code{xyz} may be interpreted as a global for one tracepoint, and a
9926 local for another, as appropriate to the tracepoint's location.
9927
9928 @item show default-collect
9929 @kindex show default-collect
9930 Show the list of expressions that are collected by default at each
9931 tracepoint hit.
9932
9933 @end table
9934
9935 @node Listing Tracepoints
9936 @subsection Listing Tracepoints
9937
9938 @table @code
9939 @kindex info tracepoints
9940 @kindex info tp
9941 @cindex information about tracepoints
9942 @item info tracepoints @r{[}@var{num}@r{]}
9943 Display information about the tracepoint @var{num}. If you don't
9944 specify a tracepoint number, displays information about all the
9945 tracepoints defined so far. The format is similar to that used for
9946 @code{info breakpoints}; in fact, @code{info tracepoints} is the same
9947 command, simply restricting itself to tracepoints.
9948
9949 A tracepoint's listing may include additional information specific to
9950 tracing:
9951
9952 @itemize @bullet
9953 @item
9954 its passcount as given by the @code{passcount @var{n}} command
9955 @end itemize
9956
9957 @smallexample
9958 (@value{GDBP}) @b{info trace}
9959 Num Type Disp Enb Address What
9960 1 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
9961 while-stepping 20
9962 collect globfoo, $regs
9963 end
9964 collect globfoo2
9965 end
9966 pass count 1200
9967 (@value{GDBP})
9968 @end smallexample
9969
9970 @noindent
9971 This command can be abbreviated @code{info tp}.
9972 @end table
9973
9974 @node Starting and Stopping Trace Experiments
9975 @subsection Starting and Stopping Trace Experiments
9976
9977 @table @code
9978 @kindex tstart
9979 @cindex start a new trace experiment
9980 @cindex collected data discarded
9981 @item tstart
9982 This command takes no arguments. It starts the trace experiment, and
9983 begins collecting data. This has the side effect of discarding all
9984 the data collected in the trace buffer during the previous trace
9985 experiment.
9986
9987 @kindex tstop
9988 @cindex stop a running trace experiment
9989 @item tstop
9990 This command takes no arguments. It ends the trace experiment, and
9991 stops collecting data.
9992
9993 @strong{Note}: a trace experiment and data collection may stop
9994 automatically if any tracepoint's passcount is reached
9995 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
9996
9997 @kindex tstatus
9998 @cindex status of trace data collection
9999 @cindex trace experiment, status of
10000 @item tstatus
10001 This command displays the status of the current trace data
10002 collection.
10003 @end table
10004
10005 Here is an example of the commands we described so far:
10006
10007 @smallexample
10008 (@value{GDBP}) @b{trace gdb_c_test}
10009 (@value{GDBP}) @b{actions}
10010 Enter actions for tracepoint #1, one per line.
10011 > collect $regs,$locals,$args
10012 > while-stepping 11
10013 > collect $regs
10014 > end
10015 > end
10016 (@value{GDBP}) @b{tstart}
10017 [time passes @dots{}]
10018 (@value{GDBP}) @b{tstop}
10019 @end smallexample
10020
10021 @cindex disconnected tracing
10022 You can choose to continue running the trace experiment even if
10023 @value{GDBN} disconnects from the target, voluntarily or
10024 involuntarily. For commands such as @code{detach}, the debugger will
10025 ask what you want to do with the trace. But for unexpected
10026 terminations (@value{GDBN} crash, network outage), it would be
10027 unfortunate to lose hard-won trace data, so the variable
10028 @code{disconnected-tracing} lets you decide whether the trace should
10029 continue running without @value{GDBN}.
10030
10031 @table @code
10032 @item set disconnected-tracing on
10033 @itemx set disconnected-tracing off
10034 @kindex set disconnected-tracing
10035 Choose whether a tracing run should continue to run if @value{GDBN}
10036 has disconnected from the target. Note that @code{detach} or
10037 @code{quit} will ask you directly what to do about a running trace no
10038 matter what this variable's setting, so the variable is mainly useful
10039 for handling unexpected situations, such as loss of the network.
10040
10041 @item show disconnected-tracing
10042 @kindex show disconnected-tracing
10043 Show the current choice for disconnected tracing.
10044
10045 @end table
10046
10047 When you reconnect to the target, the trace experiment may or may not
10048 still be running; it might have filled the trace buffer in the
10049 meantime, or stopped for one of the other reasons. If it is running,
10050 it will continue after reconnection.
10051
10052 Upon reconnection, the target will upload information about the
10053 tracepoints in effect. @value{GDBN} will then compare that
10054 information to the set of tracepoints currently defined, and attempt
10055 to match them up, allowing for the possibility that the numbers may
10056 have changed due to creation and deletion in the meantime. If one of
10057 the target's tracepoints does not match any in @value{GDBN}, the
10058 debugger will create a new tracepoint, so that you have a number with
10059 which to specify that tracepoint. This matching-up process is
10060 necessarily heuristic, and it may result in useless tracepoints being
10061 created; you may simply delete them if they are of no use.
10062
10063 @cindex circular trace buffer
10064 If your target agent supports a @dfn{circular trace buffer}, then you
10065 can run a trace experiment indefinitely without filling the trace
10066 buffer; when space runs out, the agent deletes already-collected trace
10067 frames, oldest first, until there is enough room to continue
10068 collecting. This is especially useful if your tracepoints are being
10069 hit too often, and your trace gets terminated prematurely because the
10070 buffer is full. To ask for a circular trace buffer, simply set
10071 @samp{circular_trace_buffer} to on. You can set this at any time,
10072 including during tracing; if the agent can do it, it will change
10073 buffer handling on the fly, otherwise it will not take effect until
10074 the next run.
10075
10076 @table @code
10077 @item set circular-trace-buffer on
10078 @itemx set circular-trace-buffer off
10079 @kindex set circular-trace-buffer
10080 Choose whether a tracing run should use a linear or circular buffer
10081 for trace data. A linear buffer will not lose any trace data, but may
10082 fill up prematurely, while a circular buffer will discard old trace
10083 data, but it will have always room for the latest tracepoint hits.
10084
10085 @item show circular-trace-buffer
10086 @kindex show circular-trace-buffer
10087 Show the current choice for the trace buffer. Note that this may not
10088 match the agent's current buffer handling, nor is it guaranteed to
10089 match the setting that might have been in effect during a past run,
10090 for instance if you are looking at frames from a trace file.
10091
10092 @end table
10093
10094 @node Tracepoint Restrictions
10095 @subsection Tracepoint Restrictions
10096
10097 @cindex tracepoint restrictions
10098 There are a number of restrictions on the use of tracepoints. As
10099 described above, tracepoint data gathering occurs on the target
10100 without interaction from @value{GDBN}. Thus the full capabilities of
10101 the debugger are not available during data gathering, and then at data
10102 examination time, you will be limited by only having what was
10103 collected. The following items describe some common problems, but it
10104 is not exhaustive, and you may run into additional difficulties not
10105 mentioned here.
10106
10107 @itemize @bullet
10108
10109 @item
10110 Tracepoint expressions are intended to gather objects (lvalues). Thus
10111 the full flexibility of GDB's expression evaluator is not available.
10112 You cannot call functions, cast objects to aggregate types, access
10113 convenience variables or modify values (except by assignment to trace
10114 state variables). Some language features may implicitly call
10115 functions (for instance Objective-C fields with accessors), and therefore
10116 cannot be collected either.
10117
10118 @item
10119 Collection of local variables, either individually or in bulk with
10120 @code{$locals} or @code{$args}, during @code{while-stepping} may
10121 behave erratically. The stepping action may enter a new scope (for
10122 instance by stepping into a function), or the location of the variable
10123 may change (for instance it is loaded into a register). The
10124 tracepoint data recorded uses the location information for the
10125 variables that is correct for the tracepoint location. When the
10126 tracepoint is created, it is not possible, in general, to determine
10127 where the steps of a @code{while-stepping} sequence will advance the
10128 program---particularly if a conditional branch is stepped.
10129
10130 @item
10131 Collection of an incompletely-initialized or partially-destroyed object
10132 may result in something that @value{GDBN} cannot display, or displays
10133 in a misleading way.
10134
10135 @item
10136 When @value{GDBN} displays a pointer to character it automatically
10137 dereferences the pointer to also display characters of the string
10138 being pointed to. However, collecting the pointer during tracing does
10139 not automatically collect the string. You need to explicitly
10140 dereference the pointer and provide size information if you want to
10141 collect not only the pointer, but the memory pointed to. For example,
10142 @code{*ptr@@50} can be used to collect the 50 element array pointed to
10143 by @code{ptr}.
10144
10145 @item
10146 It is not possible to collect a complete stack backtrace at a
10147 tracepoint. Instead, you may collect the registers and a few hundred
10148 bytes from the stack pointer with something like @code{*$esp@@300}
10149 (adjust to use the name of the actual stack pointer register on your
10150 target architecture, and the amount of stack you wish to capture).
10151 Then the @code{backtrace} command will show a partial backtrace when
10152 using a trace frame. The number of stack frames that can be examined
10153 depends on the sizes of the frames in the collected stack. Note that
10154 if you ask for a block so large that it goes past the bottom of the
10155 stack, the target agent may report an error trying to read from an
10156 invalid address.
10157
10158 @item
10159 If you do not collect registers at a tracepoint, @value{GDBN} can
10160 infer that the value of @code{$pc} must be the same as the address of
10161 the tracepoint and use that when you are looking at a trace frame
10162 for that tracepoint. However, this cannot work if the tracepoint has
10163 multiple locations (for instance if it was set in a function that was
10164 inlined), or if it has a @code{while-stepping} loop. In those cases
10165 @value{GDBN} will warn you that it can't infer @code{$pc}, and default
10166 it to zero.
10167
10168 @end itemize
10169
10170 @node Analyze Collected Data
10171 @section Using the Collected Data
10172
10173 After the tracepoint experiment ends, you use @value{GDBN} commands
10174 for examining the trace data. The basic idea is that each tracepoint
10175 collects a trace @dfn{snapshot} every time it is hit and another
10176 snapshot every time it single-steps. All these snapshots are
10177 consecutively numbered from zero and go into a buffer, and you can
10178 examine them later. The way you examine them is to @dfn{focus} on a
10179 specific trace snapshot. When the remote stub is focused on a trace
10180 snapshot, it will respond to all @value{GDBN} requests for memory and
10181 registers by reading from the buffer which belongs to that snapshot,
10182 rather than from @emph{real} memory or registers of the program being
10183 debugged. This means that @strong{all} @value{GDBN} commands
10184 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
10185 behave as if we were currently debugging the program state as it was
10186 when the tracepoint occurred. Any requests for data that are not in
10187 the buffer will fail.
10188
10189 @menu
10190 * tfind:: How to select a trace snapshot
10191 * tdump:: How to display all data for a snapshot
10192 * save tracepoints:: How to save tracepoints for a future run
10193 @end menu
10194
10195 @node tfind
10196 @subsection @code{tfind @var{n}}
10197
10198 @kindex tfind
10199 @cindex select trace snapshot
10200 @cindex find trace snapshot
10201 The basic command for selecting a trace snapshot from the buffer is
10202 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
10203 counting from zero. If no argument @var{n} is given, the next
10204 snapshot is selected.
10205
10206 Here are the various forms of using the @code{tfind} command.
10207
10208 @table @code
10209 @item tfind start
10210 Find the first snapshot in the buffer. This is a synonym for
10211 @code{tfind 0} (since 0 is the number of the first snapshot).
10212
10213 @item tfind none
10214 Stop debugging trace snapshots, resume @emph{live} debugging.
10215
10216 @item tfind end
10217 Same as @samp{tfind none}.
10218
10219 @item tfind
10220 No argument means find the next trace snapshot.
10221
10222 @item tfind -
10223 Find the previous trace snapshot before the current one. This permits
10224 retracing earlier steps.
10225
10226 @item tfind tracepoint @var{num}
10227 Find the next snapshot associated with tracepoint @var{num}. Search
10228 proceeds forward from the last examined trace snapshot. If no
10229 argument @var{num} is given, it means find the next snapshot collected
10230 for the same tracepoint as the current snapshot.
10231
10232 @item tfind pc @var{addr}
10233 Find the next snapshot associated with the value @var{addr} of the
10234 program counter. Search proceeds forward from the last examined trace
10235 snapshot. If no argument @var{addr} is given, it means find the next
10236 snapshot with the same value of PC as the current snapshot.
10237
10238 @item tfind outside @var{addr1}, @var{addr2}
10239 Find the next snapshot whose PC is outside the given range of
10240 addresses (exclusive).
10241
10242 @item tfind range @var{addr1}, @var{addr2}
10243 Find the next snapshot whose PC is between @var{addr1} and
10244 @var{addr2} (inclusive).
10245
10246 @item tfind line @r{[}@var{file}:@r{]}@var{n}
10247 Find the next snapshot associated with the source line @var{n}. If
10248 the optional argument @var{file} is given, refer to line @var{n} in
10249 that source file. Search proceeds forward from the last examined
10250 trace snapshot. If no argument @var{n} is given, it means find the
10251 next line other than the one currently being examined; thus saying
10252 @code{tfind line} repeatedly can appear to have the same effect as
10253 stepping from line to line in a @emph{live} debugging session.
10254 @end table
10255
10256 The default arguments for the @code{tfind} commands are specifically
10257 designed to make it easy to scan through the trace buffer. For
10258 instance, @code{tfind} with no argument selects the next trace
10259 snapshot, and @code{tfind -} with no argument selects the previous
10260 trace snapshot. So, by giving one @code{tfind} command, and then
10261 simply hitting @key{RET} repeatedly you can examine all the trace
10262 snapshots in order. Or, by saying @code{tfind -} and then hitting
10263 @key{RET} repeatedly you can examine the snapshots in reverse order.
10264 The @code{tfind line} command with no argument selects the snapshot
10265 for the next source line executed. The @code{tfind pc} command with
10266 no argument selects the next snapshot with the same program counter
10267 (PC) as the current frame. The @code{tfind tracepoint} command with
10268 no argument selects the next trace snapshot collected by the same
10269 tracepoint as the current one.
10270
10271 In addition to letting you scan through the trace buffer manually,
10272 these commands make it easy to construct @value{GDBN} scripts that
10273 scan through the trace buffer and print out whatever collected data
10274 you are interested in. Thus, if we want to examine the PC, FP, and SP
10275 registers from each trace frame in the buffer, we can say this:
10276
10277 @smallexample
10278 (@value{GDBP}) @b{tfind start}
10279 (@value{GDBP}) @b{while ($trace_frame != -1)}
10280 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
10281 $trace_frame, $pc, $sp, $fp
10282 > tfind
10283 > end
10284
10285 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
10286 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
10287 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
10288 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
10289 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
10290 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
10291 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
10292 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
10293 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
10294 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
10295 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
10296 @end smallexample
10297
10298 Or, if we want to examine the variable @code{X} at each source line in
10299 the buffer:
10300
10301 @smallexample
10302 (@value{GDBP}) @b{tfind start}
10303 (@value{GDBP}) @b{while ($trace_frame != -1)}
10304 > printf "Frame %d, X == %d\n", $trace_frame, X
10305 > tfind line
10306 > end
10307
10308 Frame 0, X = 1
10309 Frame 7, X = 2
10310 Frame 13, X = 255
10311 @end smallexample
10312
10313 @node tdump
10314 @subsection @code{tdump}
10315 @kindex tdump
10316 @cindex dump all data collected at tracepoint
10317 @cindex tracepoint data, display
10318
10319 This command takes no arguments. It prints all the data collected at
10320 the current trace snapshot.
10321
10322 @smallexample
10323 (@value{GDBP}) @b{trace 444}
10324 (@value{GDBP}) @b{actions}
10325 Enter actions for tracepoint #2, one per line:
10326 > collect $regs, $locals, $args, gdb_long_test
10327 > end
10328
10329 (@value{GDBP}) @b{tstart}
10330
10331 (@value{GDBP}) @b{tfind line 444}
10332 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
10333 at gdb_test.c:444
10334 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
10335
10336 (@value{GDBP}) @b{tdump}
10337 Data collected at tracepoint 2, trace frame 1:
10338 d0 0xc4aa0085 -995491707
10339 d1 0x18 24
10340 d2 0x80 128
10341 d3 0x33 51
10342 d4 0x71aea3d 119204413
10343 d5 0x22 34
10344 d6 0xe0 224
10345 d7 0x380035 3670069
10346 a0 0x19e24a 1696330
10347 a1 0x3000668 50333288
10348 a2 0x100 256
10349 a3 0x322000 3284992
10350 a4 0x3000698 50333336
10351 a5 0x1ad3cc 1758156
10352 fp 0x30bf3c 0x30bf3c
10353 sp 0x30bf34 0x30bf34
10354 ps 0x0 0
10355 pc 0x20b2c8 0x20b2c8
10356 fpcontrol 0x0 0
10357 fpstatus 0x0 0
10358 fpiaddr 0x0 0
10359 p = 0x20e5b4 "gdb-test"
10360 p1 = (void *) 0x11
10361 p2 = (void *) 0x22
10362 p3 = (void *) 0x33
10363 p4 = (void *) 0x44
10364 p5 = (void *) 0x55
10365 p6 = (void *) 0x66
10366 gdb_long_test = 17 '\021'
10367
10368 (@value{GDBP})
10369 @end smallexample
10370
10371 @code{tdump} works by scanning the tracepoint's current collection
10372 actions and printing the value of each expression listed. So
10373 @code{tdump} can fail, if after a run, you change the tracepoint's
10374 actions to mention variables that were not collected during the run.
10375
10376 Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
10377 uses the collected value of @code{$pc} to distinguish between trace
10378 frames that were collected at the tracepoint hit, and frames that were
10379 collected while stepping. This allows it to correctly choose whether
10380 to display the basic list of collections, or the collections from the
10381 body of the while-stepping loop. However, if @code{$pc} was not collected,
10382 then @code{tdump} will always attempt to dump using the basic collection
10383 list, and may fail if a while-stepping frame does not include all the
10384 same data that is collected at the tracepoint hit.
10385 @c This is getting pretty arcane, example would be good.
10386
10387 @node save tracepoints
10388 @subsection @code{save tracepoints @var{filename}}
10389 @kindex save tracepoints
10390 @kindex save-tracepoints
10391 @cindex save tracepoints for future sessions
10392
10393 This command saves all current tracepoint definitions together with
10394 their actions and passcounts, into a file @file{@var{filename}}
10395 suitable for use in a later debugging session. To read the saved
10396 tracepoint definitions, use the @code{source} command (@pxref{Command
10397 Files}). The @w{@code{save-tracepoints}} command is a deprecated
10398 alias for @w{@code{save tracepoints}}
10399
10400 @node Tracepoint Variables
10401 @section Convenience Variables for Tracepoints
10402 @cindex tracepoint variables
10403 @cindex convenience variables for tracepoints
10404
10405 @table @code
10406 @vindex $trace_frame
10407 @item (int) $trace_frame
10408 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
10409 snapshot is selected.
10410
10411 @vindex $tracepoint
10412 @item (int) $tracepoint
10413 The tracepoint for the current trace snapshot.
10414
10415 @vindex $trace_line
10416 @item (int) $trace_line
10417 The line number for the current trace snapshot.
10418
10419 @vindex $trace_file
10420 @item (char []) $trace_file
10421 The source file for the current trace snapshot.
10422
10423 @vindex $trace_func
10424 @item (char []) $trace_func
10425 The name of the function containing @code{$tracepoint}.
10426 @end table
10427
10428 Note: @code{$trace_file} is not suitable for use in @code{printf},
10429 use @code{output} instead.
10430
10431 Here's a simple example of using these convenience variables for
10432 stepping through all the trace snapshots and printing some of their
10433 data. Note that these are not the same as trace state variables,
10434 which are managed by the target.
10435
10436 @smallexample
10437 (@value{GDBP}) @b{tfind start}
10438
10439 (@value{GDBP}) @b{while $trace_frame != -1}
10440 > output $trace_file
10441 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
10442 > tfind
10443 > end
10444 @end smallexample
10445
10446 @node Trace Files
10447 @section Using Trace Files
10448 @cindex trace files
10449
10450 In some situations, the target running a trace experiment may no
10451 longer be available; perhaps it crashed, or the hardware was needed
10452 for a different activity. To handle these cases, you can arrange to
10453 dump the trace data into a file, and later use that file as a source
10454 of trace data, via the @code{target tfile} command.
10455
10456 @table @code
10457
10458 @kindex tsave
10459 @item tsave [ -r ] @var{filename}
10460 Save the trace data to @var{filename}. By default, this command
10461 assumes that @var{filename} refers to the host filesystem, so if
10462 necessary @value{GDBN} will copy raw trace data up from the target and
10463 then save it. If the target supports it, you can also supply the
10464 optional argument @code{-r} (``remote'') to direct the target to save
10465 the data directly into @var{filename} in its own filesystem, which may be
10466 more efficient if the trace buffer is very large. (Note, however, that
10467 @code{target tfile} can only read from files accessible to the host.)
10468
10469 @kindex target tfile
10470 @kindex tfile
10471 @item target tfile @var{filename}
10472 Use the file named @var{filename} as a source of trace data. Commands
10473 that examine data work as they do with a live target, but it is not
10474 possible to run any new trace experiments. @code{tstatus} will report
10475 the state of the trace run at the moment the data was saved, as well
10476 as the current trace frame you are examining. @var{filename} must be
10477 on a filesystem accessible to the host.
10478
10479 @end table
10480
10481 @node Overlays
10482 @chapter Debugging Programs That Use Overlays
10483 @cindex overlays
10484
10485 If your program is too large to fit completely in your target system's
10486 memory, you can sometimes use @dfn{overlays} to work around this
10487 problem. @value{GDBN} provides some support for debugging programs that
10488 use overlays.
10489
10490 @menu
10491 * How Overlays Work:: A general explanation of overlays.
10492 * Overlay Commands:: Managing overlays in @value{GDBN}.
10493 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
10494 mapped by asking the inferior.
10495 * Overlay Sample Program:: A sample program using overlays.
10496 @end menu
10497
10498 @node How Overlays Work
10499 @section How Overlays Work
10500 @cindex mapped overlays
10501 @cindex unmapped overlays
10502 @cindex load address, overlay's
10503 @cindex mapped address
10504 @cindex overlay area
10505
10506 Suppose you have a computer whose instruction address space is only 64
10507 kilobytes long, but which has much more memory which can be accessed by
10508 other means: special instructions, segment registers, or memory
10509 management hardware, for example. Suppose further that you want to
10510 adapt a program which is larger than 64 kilobytes to run on this system.
10511
10512 One solution is to identify modules of your program which are relatively
10513 independent, and need not call each other directly; call these modules
10514 @dfn{overlays}. Separate the overlays from the main program, and place
10515 their machine code in the larger memory. Place your main program in
10516 instruction memory, but leave at least enough space there to hold the
10517 largest overlay as well.
10518
10519 Now, to call a function located in an overlay, you must first copy that
10520 overlay's machine code from the large memory into the space set aside
10521 for it in the instruction memory, and then jump to its entry point
10522 there.
10523
10524 @c NB: In the below the mapped area's size is greater or equal to the
10525 @c size of all overlays. This is intentional to remind the developer
10526 @c that overlays don't necessarily need to be the same size.
10527
10528 @smallexample
10529 @group
10530 Data Instruction Larger
10531 Address Space Address Space Address Space
10532 +-----------+ +-----------+ +-----------+
10533 | | | | | |
10534 +-----------+ +-----------+ +-----------+<-- overlay 1
10535 | program | | main | .----| overlay 1 | load address
10536 | variables | | program | | +-----------+
10537 | and heap | | | | | |
10538 +-----------+ | | | +-----------+<-- overlay 2
10539 | | +-----------+ | | | load address
10540 +-----------+ | | | .-| overlay 2 |
10541 | | | | | |
10542 mapped --->+-----------+ | | +-----------+
10543 address | | | | | |
10544 | overlay | <-' | | |
10545 | area | <---' +-----------+<-- overlay 3
10546 | | <---. | | load address
10547 +-----------+ `--| overlay 3 |
10548 | | | |
10549 +-----------+ | |
10550 +-----------+
10551 | |
10552 +-----------+
10553
10554 @anchor{A code overlay}A code overlay
10555 @end group
10556 @end smallexample
10557
10558 The diagram (@pxref{A code overlay}) shows a system with separate data
10559 and instruction address spaces. To map an overlay, the program copies
10560 its code from the larger address space to the instruction address space.
10561 Since the overlays shown here all use the same mapped address, only one
10562 may be mapped at a time. For a system with a single address space for
10563 data and instructions, the diagram would be similar, except that the
10564 program variables and heap would share an address space with the main
10565 program and the overlay area.
10566
10567 An overlay loaded into instruction memory and ready for use is called a
10568 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
10569 instruction memory. An overlay not present (or only partially present)
10570 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
10571 is its address in the larger memory. The mapped address is also called
10572 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
10573 called the @dfn{load memory address}, or @dfn{LMA}.
10574
10575 Unfortunately, overlays are not a completely transparent way to adapt a
10576 program to limited instruction memory. They introduce a new set of
10577 global constraints you must keep in mind as you design your program:
10578
10579 @itemize @bullet
10580
10581 @item
10582 Before calling or returning to a function in an overlay, your program
10583 must make sure that overlay is actually mapped. Otherwise, the call or
10584 return will transfer control to the right address, but in the wrong
10585 overlay, and your program will probably crash.
10586
10587 @item
10588 If the process of mapping an overlay is expensive on your system, you
10589 will need to choose your overlays carefully to minimize their effect on
10590 your program's performance.
10591
10592 @item
10593 The executable file you load onto your system must contain each
10594 overlay's instructions, appearing at the overlay's load address, not its
10595 mapped address. However, each overlay's instructions must be relocated
10596 and its symbols defined as if the overlay were at its mapped address.
10597 You can use GNU linker scripts to specify different load and relocation
10598 addresses for pieces of your program; see @ref{Overlay Description,,,
10599 ld.info, Using ld: the GNU linker}.
10600
10601 @item
10602 The procedure for loading executable files onto your system must be able
10603 to load their contents into the larger address space as well as the
10604 instruction and data spaces.
10605
10606 @end itemize
10607
10608 The overlay system described above is rather simple, and could be
10609 improved in many ways:
10610
10611 @itemize @bullet
10612
10613 @item
10614 If your system has suitable bank switch registers or memory management
10615 hardware, you could use those facilities to make an overlay's load area
10616 contents simply appear at their mapped address in instruction space.
10617 This would probably be faster than copying the overlay to its mapped
10618 area in the usual way.
10619
10620 @item
10621 If your overlays are small enough, you could set aside more than one
10622 overlay area, and have more than one overlay mapped at a time.
10623
10624 @item
10625 You can use overlays to manage data, as well as instructions. In
10626 general, data overlays are even less transparent to your design than
10627 code overlays: whereas code overlays only require care when you call or
10628 return to functions, data overlays require care every time you access
10629 the data. Also, if you change the contents of a data overlay, you
10630 must copy its contents back out to its load address before you can copy a
10631 different data overlay into the same mapped area.
10632
10633 @end itemize
10634
10635
10636 @node Overlay Commands
10637 @section Overlay Commands
10638
10639 To use @value{GDBN}'s overlay support, each overlay in your program must
10640 correspond to a separate section of the executable file. The section's
10641 virtual memory address and load memory address must be the overlay's
10642 mapped and load addresses. Identifying overlays with sections allows
10643 @value{GDBN} to determine the appropriate address of a function or
10644 variable, depending on whether the overlay is mapped or not.
10645
10646 @value{GDBN}'s overlay commands all start with the word @code{overlay};
10647 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
10648
10649 @table @code
10650 @item overlay off
10651 @kindex overlay
10652 Disable @value{GDBN}'s overlay support. When overlay support is
10653 disabled, @value{GDBN} assumes that all functions and variables are
10654 always present at their mapped addresses. By default, @value{GDBN}'s
10655 overlay support is disabled.
10656
10657 @item overlay manual
10658 @cindex manual overlay debugging
10659 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
10660 relies on you to tell it which overlays are mapped, and which are not,
10661 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
10662 commands described below.
10663
10664 @item overlay map-overlay @var{overlay}
10665 @itemx overlay map @var{overlay}
10666 @cindex map an overlay
10667 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
10668 be the name of the object file section containing the overlay. When an
10669 overlay is mapped, @value{GDBN} assumes it can find the overlay's
10670 functions and variables at their mapped addresses. @value{GDBN} assumes
10671 that any other overlays whose mapped ranges overlap that of
10672 @var{overlay} are now unmapped.
10673
10674 @item overlay unmap-overlay @var{overlay}
10675 @itemx overlay unmap @var{overlay}
10676 @cindex unmap an overlay
10677 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
10678 must be the name of the object file section containing the overlay.
10679 When an overlay is unmapped, @value{GDBN} assumes it can find the
10680 overlay's functions and variables at their load addresses.
10681
10682 @item overlay auto
10683 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
10684 consults a data structure the overlay manager maintains in the inferior
10685 to see which overlays are mapped. For details, see @ref{Automatic
10686 Overlay Debugging}.
10687
10688 @item overlay load-target
10689 @itemx overlay load
10690 @cindex reloading the overlay table
10691 Re-read the overlay table from the inferior. Normally, @value{GDBN}
10692 re-reads the table @value{GDBN} automatically each time the inferior
10693 stops, so this command should only be necessary if you have changed the
10694 overlay mapping yourself using @value{GDBN}. This command is only
10695 useful when using automatic overlay debugging.
10696
10697 @item overlay list-overlays
10698 @itemx overlay list
10699 @cindex listing mapped overlays
10700 Display a list of the overlays currently mapped, along with their mapped
10701 addresses, load addresses, and sizes.
10702
10703 @end table
10704
10705 Normally, when @value{GDBN} prints a code address, it includes the name
10706 of the function the address falls in:
10707
10708 @smallexample
10709 (@value{GDBP}) print main
10710 $3 = @{int ()@} 0x11a0 <main>
10711 @end smallexample
10712 @noindent
10713 When overlay debugging is enabled, @value{GDBN} recognizes code in
10714 unmapped overlays, and prints the names of unmapped functions with
10715 asterisks around them. For example, if @code{foo} is a function in an
10716 unmapped overlay, @value{GDBN} prints it this way:
10717
10718 @smallexample
10719 (@value{GDBP}) overlay list
10720 No sections are mapped.
10721 (@value{GDBP}) print foo
10722 $5 = @{int (int)@} 0x100000 <*foo*>
10723 @end smallexample
10724 @noindent
10725 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
10726 name normally:
10727
10728 @smallexample
10729 (@value{GDBP}) overlay list
10730 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
10731 mapped at 0x1016 - 0x104a
10732 (@value{GDBP}) print foo
10733 $6 = @{int (int)@} 0x1016 <foo>
10734 @end smallexample
10735
10736 When overlay debugging is enabled, @value{GDBN} can find the correct
10737 address for functions and variables in an overlay, whether or not the
10738 overlay is mapped. This allows most @value{GDBN} commands, like
10739 @code{break} and @code{disassemble}, to work normally, even on unmapped
10740 code. However, @value{GDBN}'s breakpoint support has some limitations:
10741
10742 @itemize @bullet
10743 @item
10744 @cindex breakpoints in overlays
10745 @cindex overlays, setting breakpoints in
10746 You can set breakpoints in functions in unmapped overlays, as long as
10747 @value{GDBN} can write to the overlay at its load address.
10748 @item
10749 @value{GDBN} can not set hardware or simulator-based breakpoints in
10750 unmapped overlays. However, if you set a breakpoint at the end of your
10751 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
10752 you are using manual overlay management), @value{GDBN} will re-set its
10753 breakpoints properly.
10754 @end itemize
10755
10756
10757 @node Automatic Overlay Debugging
10758 @section Automatic Overlay Debugging
10759 @cindex automatic overlay debugging
10760
10761 @value{GDBN} can automatically track which overlays are mapped and which
10762 are not, given some simple co-operation from the overlay manager in the
10763 inferior. If you enable automatic overlay debugging with the
10764 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
10765 looks in the inferior's memory for certain variables describing the
10766 current state of the overlays.
10767
10768 Here are the variables your overlay manager must define to support
10769 @value{GDBN}'s automatic overlay debugging:
10770
10771 @table @asis
10772
10773 @item @code{_ovly_table}:
10774 This variable must be an array of the following structures:
10775
10776 @smallexample
10777 struct
10778 @{
10779 /* The overlay's mapped address. */
10780 unsigned long vma;
10781
10782 /* The size of the overlay, in bytes. */
10783 unsigned long size;
10784
10785 /* The overlay's load address. */
10786 unsigned long lma;
10787
10788 /* Non-zero if the overlay is currently mapped;
10789 zero otherwise. */
10790 unsigned long mapped;
10791 @}
10792 @end smallexample
10793
10794 @item @code{_novlys}:
10795 This variable must be a four-byte signed integer, holding the total
10796 number of elements in @code{_ovly_table}.
10797
10798 @end table
10799
10800 To decide whether a particular overlay is mapped or not, @value{GDBN}
10801 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
10802 @code{lma} members equal the VMA and LMA of the overlay's section in the
10803 executable file. When @value{GDBN} finds a matching entry, it consults
10804 the entry's @code{mapped} member to determine whether the overlay is
10805 currently mapped.
10806
10807 In addition, your overlay manager may define a function called
10808 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
10809 will silently set a breakpoint there. If the overlay manager then
10810 calls this function whenever it has changed the overlay table, this
10811 will enable @value{GDBN} to accurately keep track of which overlays
10812 are in program memory, and update any breakpoints that may be set
10813 in overlays. This will allow breakpoints to work even if the
10814 overlays are kept in ROM or other non-writable memory while they
10815 are not being executed.
10816
10817 @node Overlay Sample Program
10818 @section Overlay Sample Program
10819 @cindex overlay example program
10820
10821 When linking a program which uses overlays, you must place the overlays
10822 at their load addresses, while relocating them to run at their mapped
10823 addresses. To do this, you must write a linker script (@pxref{Overlay
10824 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
10825 since linker scripts are specific to a particular host system, target
10826 architecture, and target memory layout, this manual cannot provide
10827 portable sample code demonstrating @value{GDBN}'s overlay support.
10828
10829 However, the @value{GDBN} source distribution does contain an overlaid
10830 program, with linker scripts for a few systems, as part of its test
10831 suite. The program consists of the following files from
10832 @file{gdb/testsuite/gdb.base}:
10833
10834 @table @file
10835 @item overlays.c
10836 The main program file.
10837 @item ovlymgr.c
10838 A simple overlay manager, used by @file{overlays.c}.
10839 @item foo.c
10840 @itemx bar.c
10841 @itemx baz.c
10842 @itemx grbx.c
10843 Overlay modules, loaded and used by @file{overlays.c}.
10844 @item d10v.ld
10845 @itemx m32r.ld
10846 Linker scripts for linking the test program on the @code{d10v-elf}
10847 and @code{m32r-elf} targets.
10848 @end table
10849
10850 You can build the test program using the @code{d10v-elf} GCC
10851 cross-compiler like this:
10852
10853 @smallexample
10854 $ d10v-elf-gcc -g -c overlays.c
10855 $ d10v-elf-gcc -g -c ovlymgr.c
10856 $ d10v-elf-gcc -g -c foo.c
10857 $ d10v-elf-gcc -g -c bar.c
10858 $ d10v-elf-gcc -g -c baz.c
10859 $ d10v-elf-gcc -g -c grbx.c
10860 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
10861 baz.o grbx.o -Wl,-Td10v.ld -o overlays
10862 @end smallexample
10863
10864 The build process is identical for any other architecture, except that
10865 you must substitute the appropriate compiler and linker script for the
10866 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
10867
10868
10869 @node Languages
10870 @chapter Using @value{GDBN} with Different Languages
10871 @cindex languages
10872
10873 Although programming languages generally have common aspects, they are
10874 rarely expressed in the same manner. For instance, in ANSI C,
10875 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
10876 Modula-2, it is accomplished by @code{p^}. Values can also be
10877 represented (and displayed) differently. Hex numbers in C appear as
10878 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
10879
10880 @cindex working language
10881 Language-specific information is built into @value{GDBN} for some languages,
10882 allowing you to express operations like the above in your program's
10883 native language, and allowing @value{GDBN} to output values in a manner
10884 consistent with the syntax of your program's native language. The
10885 language you use to build expressions is called the @dfn{working
10886 language}.
10887
10888 @menu
10889 * Setting:: Switching between source languages
10890 * Show:: Displaying the language
10891 * Checks:: Type and range checks
10892 * Supported Languages:: Supported languages
10893 * Unsupported Languages:: Unsupported languages
10894 @end menu
10895
10896 @node Setting
10897 @section Switching Between Source Languages
10898
10899 There are two ways to control the working language---either have @value{GDBN}
10900 set it automatically, or select it manually yourself. You can use the
10901 @code{set language} command for either purpose. On startup, @value{GDBN}
10902 defaults to setting the language automatically. The working language is
10903 used to determine how expressions you type are interpreted, how values
10904 are printed, etc.
10905
10906 In addition to the working language, every source file that
10907 @value{GDBN} knows about has its own working language. For some object
10908 file formats, the compiler might indicate which language a particular
10909 source file is in. However, most of the time @value{GDBN} infers the
10910 language from the name of the file. The language of a source file
10911 controls whether C@t{++} names are demangled---this way @code{backtrace} can
10912 show each frame appropriately for its own language. There is no way to
10913 set the language of a source file from within @value{GDBN}, but you can
10914 set the language associated with a filename extension. @xref{Show, ,
10915 Displaying the Language}.
10916
10917 This is most commonly a problem when you use a program, such
10918 as @code{cfront} or @code{f2c}, that generates C but is written in
10919 another language. In that case, make the
10920 program use @code{#line} directives in its C output; that way
10921 @value{GDBN} will know the correct language of the source code of the original
10922 program, and will display that source code, not the generated C code.
10923
10924 @menu
10925 * Filenames:: Filename extensions and languages.
10926 * Manually:: Setting the working language manually
10927 * Automatically:: Having @value{GDBN} infer the source language
10928 @end menu
10929
10930 @node Filenames
10931 @subsection List of Filename Extensions and Languages
10932
10933 If a source file name ends in one of the following extensions, then
10934 @value{GDBN} infers that its language is the one indicated.
10935
10936 @table @file
10937 @item .ada
10938 @itemx .ads
10939 @itemx .adb
10940 @itemx .a
10941 Ada source file.
10942
10943 @item .c
10944 C source file
10945
10946 @item .C
10947 @itemx .cc
10948 @itemx .cp
10949 @itemx .cpp
10950 @itemx .cxx
10951 @itemx .c++
10952 C@t{++} source file
10953
10954 @item .d
10955 D source file
10956
10957 @item .m
10958 Objective-C source file
10959
10960 @item .f
10961 @itemx .F
10962 Fortran source file
10963
10964 @item .mod
10965 Modula-2 source file
10966
10967 @item .s
10968 @itemx .S
10969 Assembler source file. This actually behaves almost like C, but
10970 @value{GDBN} does not skip over function prologues when stepping.
10971 @end table
10972
10973 In addition, you may set the language associated with a filename
10974 extension. @xref{Show, , Displaying the Language}.
10975
10976 @node Manually
10977 @subsection Setting the Working Language
10978
10979 If you allow @value{GDBN} to set the language automatically,
10980 expressions are interpreted the same way in your debugging session and
10981 your program.
10982
10983 @kindex set language
10984 If you wish, you may set the language manually. To do this, issue the
10985 command @samp{set language @var{lang}}, where @var{lang} is the name of
10986 a language, such as
10987 @code{c} or @code{modula-2}.
10988 For a list of the supported languages, type @samp{set language}.
10989
10990 Setting the language manually prevents @value{GDBN} from updating the working
10991 language automatically. This can lead to confusion if you try
10992 to debug a program when the working language is not the same as the
10993 source language, when an expression is acceptable to both
10994 languages---but means different things. For instance, if the current
10995 source file were written in C, and @value{GDBN} was parsing Modula-2, a
10996 command such as:
10997
10998 @smallexample
10999 print a = b + c
11000 @end smallexample
11001
11002 @noindent
11003 might not have the effect you intended. In C, this means to add
11004 @code{b} and @code{c} and place the result in @code{a}. The result
11005 printed would be the value of @code{a}. In Modula-2, this means to compare
11006 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
11007
11008 @node Automatically
11009 @subsection Having @value{GDBN} Infer the Source Language
11010
11011 To have @value{GDBN} set the working language automatically, use
11012 @samp{set language local} or @samp{set language auto}. @value{GDBN}
11013 then infers the working language. That is, when your program stops in a
11014 frame (usually by encountering a breakpoint), @value{GDBN} sets the
11015 working language to the language recorded for the function in that
11016 frame. If the language for a frame is unknown (that is, if the function
11017 or block corresponding to the frame was defined in a source file that
11018 does not have a recognized extension), the current working language is
11019 not changed, and @value{GDBN} issues a warning.
11020
11021 This may not seem necessary for most programs, which are written
11022 entirely in one source language. However, program modules and libraries
11023 written in one source language can be used by a main program written in
11024 a different source language. Using @samp{set language auto} in this
11025 case frees you from having to set the working language manually.
11026
11027 @node Show
11028 @section Displaying the Language
11029
11030 The following commands help you find out which language is the
11031 working language, and also what language source files were written in.
11032
11033 @table @code
11034 @item show language
11035 @kindex show language
11036 Display the current working language. This is the
11037 language you can use with commands such as @code{print} to
11038 build and compute expressions that may involve variables in your program.
11039
11040 @item info frame
11041 @kindex info frame@r{, show the source language}
11042 Display the source language for this frame. This language becomes the
11043 working language if you use an identifier from this frame.
11044 @xref{Frame Info, ,Information about a Frame}, to identify the other
11045 information listed here.
11046
11047 @item info source
11048 @kindex info source@r{, show the source language}
11049 Display the source language of this source file.
11050 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
11051 information listed here.
11052 @end table
11053
11054 In unusual circumstances, you may have source files with extensions
11055 not in the standard list. You can then set the extension associated
11056 with a language explicitly:
11057
11058 @table @code
11059 @item set extension-language @var{ext} @var{language}
11060 @kindex set extension-language
11061 Tell @value{GDBN} that source files with extension @var{ext} are to be
11062 assumed as written in the source language @var{language}.
11063
11064 @item info extensions
11065 @kindex info extensions
11066 List all the filename extensions and the associated languages.
11067 @end table
11068
11069 @node Checks
11070 @section Type and Range Checking
11071
11072 @quotation
11073 @emph{Warning:} In this release, the @value{GDBN} commands for type and range
11074 checking are included, but they do not yet have any effect. This
11075 section documents the intended facilities.
11076 @end quotation
11077 @c FIXME remove warning when type/range code added
11078
11079 Some languages are designed to guard you against making seemingly common
11080 errors through a series of compile- and run-time checks. These include
11081 checking the type of arguments to functions and operators, and making
11082 sure mathematical overflows are caught at run time. Checks such as
11083 these help to ensure a program's correctness once it has been compiled
11084 by eliminating type mismatches, and providing active checks for range
11085 errors when your program is running.
11086
11087 @value{GDBN} can check for conditions like the above if you wish.
11088 Although @value{GDBN} does not check the statements in your program,
11089 it can check expressions entered directly into @value{GDBN} for
11090 evaluation via the @code{print} command, for example. As with the
11091 working language, @value{GDBN} can also decide whether or not to check
11092 automatically based on your program's source language.
11093 @xref{Supported Languages, ,Supported Languages}, for the default
11094 settings of supported languages.
11095
11096 @menu
11097 * Type Checking:: An overview of type checking
11098 * Range Checking:: An overview of range checking
11099 @end menu
11100
11101 @cindex type checking
11102 @cindex checks, type
11103 @node Type Checking
11104 @subsection An Overview of Type Checking
11105
11106 Some languages, such as Modula-2, are strongly typed, meaning that the
11107 arguments to operators and functions have to be of the correct type,
11108 otherwise an error occurs. These checks prevent type mismatch
11109 errors from ever causing any run-time problems. For example,
11110
11111 @smallexample
11112 1 + 2 @result{} 3
11113 @exdent but
11114 @error{} 1 + 2.3
11115 @end smallexample
11116
11117 The second example fails because the @code{CARDINAL} 1 is not
11118 type-compatible with the @code{REAL} 2.3.
11119
11120 For the expressions you use in @value{GDBN} commands, you can tell the
11121 @value{GDBN} type checker to skip checking;
11122 to treat any mismatches as errors and abandon the expression;
11123 or to only issue warnings when type mismatches occur,
11124 but evaluate the expression anyway. When you choose the last of
11125 these, @value{GDBN} evaluates expressions like the second example above, but
11126 also issues a warning.
11127
11128 Even if you turn type checking off, there may be other reasons
11129 related to type that prevent @value{GDBN} from evaluating an expression.
11130 For instance, @value{GDBN} does not know how to add an @code{int} and
11131 a @code{struct foo}. These particular type errors have nothing to do
11132 with the language in use, and usually arise from expressions, such as
11133 the one described above, which make little sense to evaluate anyway.
11134
11135 Each language defines to what degree it is strict about type. For
11136 instance, both Modula-2 and C require the arguments to arithmetical
11137 operators to be numbers. In C, enumerated types and pointers can be
11138 represented as numbers, so that they are valid arguments to mathematical
11139 operators. @xref{Supported Languages, ,Supported Languages}, for further
11140 details on specific languages.
11141
11142 @value{GDBN} provides some additional commands for controlling the type checker:
11143
11144 @kindex set check type
11145 @kindex show check type
11146 @table @code
11147 @item set check type auto
11148 Set type checking on or off based on the current working language.
11149 @xref{Supported Languages, ,Supported Languages}, for the default settings for
11150 each language.
11151
11152 @item set check type on
11153 @itemx set check type off
11154 Set type checking on or off, overriding the default setting for the
11155 current working language. Issue a warning if the setting does not
11156 match the language default. If any type mismatches occur in
11157 evaluating an expression while type checking is on, @value{GDBN} prints a
11158 message and aborts evaluation of the expression.
11159
11160 @item set check type warn
11161 Cause the type checker to issue warnings, but to always attempt to
11162 evaluate the expression. Evaluating the expression may still
11163 be impossible for other reasons. For example, @value{GDBN} cannot add
11164 numbers and structures.
11165
11166 @item show type
11167 Show the current setting of the type checker, and whether or not @value{GDBN}
11168 is setting it automatically.
11169 @end table
11170
11171 @cindex range checking
11172 @cindex checks, range
11173 @node Range Checking
11174 @subsection An Overview of Range Checking
11175
11176 In some languages (such as Modula-2), it is an error to exceed the
11177 bounds of a type; this is enforced with run-time checks. Such range
11178 checking is meant to ensure program correctness by making sure
11179 computations do not overflow, or indices on an array element access do
11180 not exceed the bounds of the array.
11181
11182 For expressions you use in @value{GDBN} commands, you can tell
11183 @value{GDBN} to treat range errors in one of three ways: ignore them,
11184 always treat them as errors and abandon the expression, or issue
11185 warnings but evaluate the expression anyway.
11186
11187 A range error can result from numerical overflow, from exceeding an
11188 array index bound, or when you type a constant that is not a member
11189 of any type. Some languages, however, do not treat overflows as an
11190 error. In many implementations of C, mathematical overflow causes the
11191 result to ``wrap around'' to lower values---for example, if @var{m} is
11192 the largest integer value, and @var{s} is the smallest, then
11193
11194 @smallexample
11195 @var{m} + 1 @result{} @var{s}
11196 @end smallexample
11197
11198 This, too, is specific to individual languages, and in some cases
11199 specific to individual compilers or machines. @xref{Supported Languages, ,
11200 Supported Languages}, for further details on specific languages.
11201
11202 @value{GDBN} provides some additional commands for controlling the range checker:
11203
11204 @kindex set check range
11205 @kindex show check range
11206 @table @code
11207 @item set check range auto
11208 Set range checking on or off based on the current working language.
11209 @xref{Supported Languages, ,Supported Languages}, for the default settings for
11210 each language.
11211
11212 @item set check range on
11213 @itemx set check range off
11214 Set range checking on or off, overriding the default setting for the
11215 current working language. A warning is issued if the setting does not
11216 match the language default. If a range error occurs and range checking is on,
11217 then a message is printed and evaluation of the expression is aborted.
11218
11219 @item set check range warn
11220 Output messages when the @value{GDBN} range checker detects a range error,
11221 but attempt to evaluate the expression anyway. Evaluating the
11222 expression may still be impossible for other reasons, such as accessing
11223 memory that the process does not own (a typical example from many Unix
11224 systems).
11225
11226 @item show range
11227 Show the current setting of the range checker, and whether or not it is
11228 being set automatically by @value{GDBN}.
11229 @end table
11230
11231 @node Supported Languages
11232 @section Supported Languages
11233
11234 @value{GDBN} supports C, C@t{++}, D, Objective-C, Fortran, Java, Pascal,
11235 assembly, Modula-2, and Ada.
11236 @c This is false ...
11237 Some @value{GDBN} features may be used in expressions regardless of the
11238 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
11239 and the @samp{@{type@}addr} construct (@pxref{Expressions,
11240 ,Expressions}) can be used with the constructs of any supported
11241 language.
11242
11243 The following sections detail to what degree each source language is
11244 supported by @value{GDBN}. These sections are not meant to be language
11245 tutorials or references, but serve only as a reference guide to what the
11246 @value{GDBN} expression parser accepts, and what input and output
11247 formats should look like for different languages. There are many good
11248 books written on each of these languages; please look to these for a
11249 language reference or tutorial.
11250
11251 @menu
11252 * C:: C and C@t{++}
11253 * D:: D
11254 * Objective-C:: Objective-C
11255 * Fortran:: Fortran
11256 * Pascal:: Pascal
11257 * Modula-2:: Modula-2
11258 * Ada:: Ada
11259 @end menu
11260
11261 @node C
11262 @subsection C and C@t{++}
11263
11264 @cindex C and C@t{++}
11265 @cindex expressions in C or C@t{++}
11266
11267 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
11268 to both languages. Whenever this is the case, we discuss those languages
11269 together.
11270
11271 @cindex C@t{++}
11272 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
11273 @cindex @sc{gnu} C@t{++}
11274 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
11275 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
11276 effectively, you must compile your C@t{++} programs with a supported
11277 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
11278 compiler (@code{aCC}).
11279
11280 For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
11281 format; if it doesn't work on your system, try the stabs+ debugging
11282 format. You can select those formats explicitly with the @code{g++}
11283 command-line options @option{-gdwarf-2} and @option{-gstabs+}.
11284 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
11285 gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}.
11286
11287 @menu
11288 * C Operators:: C and C@t{++} operators
11289 * C Constants:: C and C@t{++} constants
11290 * C Plus Plus Expressions:: C@t{++} expressions
11291 * C Defaults:: Default settings for C and C@t{++}
11292 * C Checks:: C and C@t{++} type and range checks
11293 * Debugging C:: @value{GDBN} and C
11294 * Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
11295 * Decimal Floating Point:: Numbers in Decimal Floating Point format
11296 @end menu
11297
11298 @node C Operators
11299 @subsubsection C and C@t{++} Operators
11300
11301 @cindex C and C@t{++} operators
11302
11303 Operators must be defined on values of specific types. For instance,
11304 @code{+} is defined on numbers, but not on structures. Operators are
11305 often defined on groups of types.
11306
11307 For the purposes of C and C@t{++}, the following definitions hold:
11308
11309 @itemize @bullet
11310
11311 @item
11312 @emph{Integral types} include @code{int} with any of its storage-class
11313 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
11314
11315 @item
11316 @emph{Floating-point types} include @code{float}, @code{double}, and
11317 @code{long double} (if supported by the target platform).
11318
11319 @item
11320 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
11321
11322 @item
11323 @emph{Scalar types} include all of the above.
11324
11325 @end itemize
11326
11327 @noindent
11328 The following operators are supported. They are listed here
11329 in order of increasing precedence:
11330
11331 @table @code
11332 @item ,
11333 The comma or sequencing operator. Expressions in a comma-separated list
11334 are evaluated from left to right, with the result of the entire
11335 expression being the last expression evaluated.
11336
11337 @item =
11338 Assignment. The value of an assignment expression is the value
11339 assigned. Defined on scalar types.
11340
11341 @item @var{op}=
11342 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
11343 and translated to @w{@code{@var{a} = @var{a op b}}}.
11344 @w{@code{@var{op}=}} and @code{=} have the same precedence.
11345 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
11346 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
11347
11348 @item ?:
11349 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
11350 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
11351 integral type.
11352
11353 @item ||
11354 Logical @sc{or}. Defined on integral types.
11355
11356 @item &&
11357 Logical @sc{and}. Defined on integral types.
11358
11359 @item |
11360 Bitwise @sc{or}. Defined on integral types.
11361
11362 @item ^
11363 Bitwise exclusive-@sc{or}. Defined on integral types.
11364
11365 @item &
11366 Bitwise @sc{and}. Defined on integral types.
11367
11368 @item ==@r{, }!=
11369 Equality and inequality. Defined on scalar types. The value of these
11370 expressions is 0 for false and non-zero for true.
11371
11372 @item <@r{, }>@r{, }<=@r{, }>=
11373 Less than, greater than, less than or equal, greater than or equal.
11374 Defined on scalar types. The value of these expressions is 0 for false
11375 and non-zero for true.
11376
11377 @item <<@r{, }>>
11378 left shift, and right shift. Defined on integral types.
11379
11380 @item @@
11381 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
11382
11383 @item +@r{, }-
11384 Addition and subtraction. Defined on integral types, floating-point types and
11385 pointer types.
11386
11387 @item *@r{, }/@r{, }%
11388 Multiplication, division, and modulus. Multiplication and division are
11389 defined on integral and floating-point types. Modulus is defined on
11390 integral types.
11391
11392 @item ++@r{, }--
11393 Increment and decrement. When appearing before a variable, the
11394 operation is performed before the variable is used in an expression;
11395 when appearing after it, the variable's value is used before the
11396 operation takes place.
11397
11398 @item *
11399 Pointer dereferencing. Defined on pointer types. Same precedence as
11400 @code{++}.
11401
11402 @item &
11403 Address operator. Defined on variables. Same precedence as @code{++}.
11404
11405 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
11406 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
11407 to examine the address
11408 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
11409 stored.
11410
11411 @item -
11412 Negative. Defined on integral and floating-point types. Same
11413 precedence as @code{++}.
11414
11415 @item !
11416 Logical negation. Defined on integral types. Same precedence as
11417 @code{++}.
11418
11419 @item ~
11420 Bitwise complement operator. Defined on integral types. Same precedence as
11421 @code{++}.
11422
11423
11424 @item .@r{, }->
11425 Structure member, and pointer-to-structure member. For convenience,
11426 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
11427 pointer based on the stored type information.
11428 Defined on @code{struct} and @code{union} data.
11429
11430 @item .*@r{, }->*
11431 Dereferences of pointers to members.
11432
11433 @item []
11434 Array indexing. @code{@var{a}[@var{i}]} is defined as
11435 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
11436
11437 @item ()
11438 Function parameter list. Same precedence as @code{->}.
11439
11440 @item ::
11441 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
11442 and @code{class} types.
11443
11444 @item ::
11445 Doubled colons also represent the @value{GDBN} scope operator
11446 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
11447 above.
11448 @end table
11449
11450 If an operator is redefined in the user code, @value{GDBN} usually
11451 attempts to invoke the redefined version instead of using the operator's
11452 predefined meaning.
11453
11454 @node C Constants
11455 @subsubsection C and C@t{++} Constants
11456
11457 @cindex C and C@t{++} constants
11458
11459 @value{GDBN} allows you to express the constants of C and C@t{++} in the
11460 following ways:
11461
11462 @itemize @bullet
11463 @item
11464 Integer constants are a sequence of digits. Octal constants are
11465 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
11466 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
11467 @samp{l}, specifying that the constant should be treated as a
11468 @code{long} value.
11469
11470 @item
11471 Floating point constants are a sequence of digits, followed by a decimal
11472 point, followed by a sequence of digits, and optionally followed by an
11473 exponent. An exponent is of the form:
11474 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
11475 sequence of digits. The @samp{+} is optional for positive exponents.
11476 A floating-point constant may also end with a letter @samp{f} or
11477 @samp{F}, specifying that the constant should be treated as being of
11478 the @code{float} (as opposed to the default @code{double}) type; or with
11479 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
11480 constant.
11481
11482 @item
11483 Enumerated constants consist of enumerated identifiers, or their
11484 integral equivalents.
11485
11486 @item
11487 Character constants are a single character surrounded by single quotes
11488 (@code{'}), or a number---the ordinal value of the corresponding character
11489 (usually its @sc{ascii} value). Within quotes, the single character may
11490 be represented by a letter or by @dfn{escape sequences}, which are of
11491 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
11492 of the character's ordinal value; or of the form @samp{\@var{x}}, where
11493 @samp{@var{x}} is a predefined special character---for example,
11494 @samp{\n} for newline.
11495
11496 @item
11497 String constants are a sequence of character constants surrounded by
11498 double quotes (@code{"}). Any valid character constant (as described
11499 above) may appear. Double quotes within the string must be preceded by
11500 a backslash, so for instance @samp{"a\"b'c"} is a string of five
11501 characters.
11502
11503 @item
11504 Pointer constants are an integral value. You can also write pointers
11505 to constants using the C operator @samp{&}.
11506
11507 @item
11508 Array constants are comma-separated lists surrounded by braces @samp{@{}
11509 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
11510 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
11511 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
11512 @end itemize
11513
11514 @node C Plus Plus Expressions
11515 @subsubsection C@t{++} Expressions
11516
11517 @cindex expressions in C@t{++}
11518 @value{GDBN} expression handling can interpret most C@t{++} expressions.
11519
11520 @cindex debugging C@t{++} programs
11521 @cindex C@t{++} compilers
11522 @cindex debug formats and C@t{++}
11523 @cindex @value{NGCC} and C@t{++}
11524 @quotation
11525 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
11526 proper compiler and the proper debug format. Currently, @value{GDBN}
11527 works best when debugging C@t{++} code that is compiled with
11528 @value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
11529 @option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
11530 stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
11531 stabs+ as their default debug format, so you usually don't need to
11532 specify a debug format explicitly. Other compilers and/or debug formats
11533 are likely to work badly or not at all when using @value{GDBN} to debug
11534 C@t{++} code.
11535 @end quotation
11536
11537 @enumerate
11538
11539 @cindex member functions
11540 @item
11541 Member function calls are allowed; you can use expressions like
11542
11543 @smallexample
11544 count = aml->GetOriginal(x, y)
11545 @end smallexample
11546
11547 @vindex this@r{, inside C@t{++} member functions}
11548 @cindex namespace in C@t{++}
11549 @item
11550 While a member function is active (in the selected stack frame), your
11551 expressions have the same namespace available as the member function;
11552 that is, @value{GDBN} allows implicit references to the class instance
11553 pointer @code{this} following the same rules as C@t{++}.
11554
11555 @cindex call overloaded functions
11556 @cindex overloaded functions, calling
11557 @cindex type conversions in C@t{++}
11558 @item
11559 You can call overloaded functions; @value{GDBN} resolves the function
11560 call to the right definition, with some restrictions. @value{GDBN} does not
11561 perform overload resolution involving user-defined type conversions,
11562 calls to constructors, or instantiations of templates that do not exist
11563 in the program. It also cannot handle ellipsis argument lists or
11564 default arguments.
11565
11566 It does perform integral conversions and promotions, floating-point
11567 promotions, arithmetic conversions, pointer conversions, conversions of
11568 class objects to base classes, and standard conversions such as those of
11569 functions or arrays to pointers; it requires an exact match on the
11570 number of function arguments.
11571
11572 Overload resolution is always performed, unless you have specified
11573 @code{set overload-resolution off}. @xref{Debugging C Plus Plus,
11574 ,@value{GDBN} Features for C@t{++}}.
11575
11576 You must specify @code{set overload-resolution off} in order to use an
11577 explicit function signature to call an overloaded function, as in
11578 @smallexample
11579 p 'foo(char,int)'('x', 13)
11580 @end smallexample
11581
11582 The @value{GDBN} command-completion facility can simplify this;
11583 see @ref{Completion, ,Command Completion}.
11584
11585 @cindex reference declarations
11586 @item
11587 @value{GDBN} understands variables declared as C@t{++} references; you can use
11588 them in expressions just as you do in C@t{++} source---they are automatically
11589 dereferenced.
11590
11591 In the parameter list shown when @value{GDBN} displays a frame, the values of
11592 reference variables are not displayed (unlike other variables); this
11593 avoids clutter, since references are often used for large structures.
11594 The @emph{address} of a reference variable is always shown, unless
11595 you have specified @samp{set print address off}.
11596
11597 @item
11598 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
11599 expressions can use it just as expressions in your program do. Since
11600 one scope may be defined in another, you can use @code{::} repeatedly if
11601 necessary, for example in an expression like
11602 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
11603 resolving name scope by reference to source files, in both C and C@t{++}
11604 debugging (@pxref{Variables, ,Program Variables}).
11605 @end enumerate
11606
11607 In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
11608 calling virtual functions correctly, printing out virtual bases of
11609 objects, calling functions in a base subobject, casting objects, and
11610 invoking user-defined operators.
11611
11612 @node C Defaults
11613 @subsubsection C and C@t{++} Defaults
11614
11615 @cindex C and C@t{++} defaults
11616
11617 If you allow @value{GDBN} to set type and range checking automatically, they
11618 both default to @code{off} whenever the working language changes to
11619 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
11620 selects the working language.
11621
11622 If you allow @value{GDBN} to set the language automatically, it
11623 recognizes source files whose names end with @file{.c}, @file{.C}, or
11624 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
11625 these files, it sets the working language to C or C@t{++}.
11626 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
11627 for further details.
11628
11629 @c Type checking is (a) primarily motivated by Modula-2, and (b)
11630 @c unimplemented. If (b) changes, it might make sense to let this node
11631 @c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
11632
11633 @node C Checks
11634 @subsubsection C and C@t{++} Type and Range Checks
11635
11636 @cindex C and C@t{++} checks
11637
11638 By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
11639 is not used. However, if you turn type checking on, @value{GDBN}
11640 considers two variables type equivalent if:
11641
11642 @itemize @bullet
11643 @item
11644 The two variables are structured and have the same structure, union, or
11645 enumerated tag.
11646
11647 @item
11648 The two variables have the same type name, or types that have been
11649 declared equivalent through @code{typedef}.
11650
11651 @ignore
11652 @c leaving this out because neither J Gilmore nor R Pesch understand it.
11653 @c FIXME--beers?
11654 @item
11655 The two @code{struct}, @code{union}, or @code{enum} variables are
11656 declared in the same declaration. (Note: this may not be true for all C
11657 compilers.)
11658 @end ignore
11659 @end itemize
11660
11661 Range checking, if turned on, is done on mathematical operations. Array
11662 indices are not checked, since they are often used to index a pointer
11663 that is not itself an array.
11664
11665 @node Debugging C
11666 @subsubsection @value{GDBN} and C
11667
11668 The @code{set print union} and @code{show print union} commands apply to
11669 the @code{union} type. When set to @samp{on}, any @code{union} that is
11670 inside a @code{struct} or @code{class} is also printed. Otherwise, it
11671 appears as @samp{@{...@}}.
11672
11673 The @code{@@} operator aids in the debugging of dynamic arrays, formed
11674 with pointers and a memory allocation function. @xref{Expressions,
11675 ,Expressions}.
11676
11677 @node Debugging C Plus Plus
11678 @subsubsection @value{GDBN} Features for C@t{++}
11679
11680 @cindex commands for C@t{++}
11681
11682 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
11683 designed specifically for use with C@t{++}. Here is a summary:
11684
11685 @table @code
11686 @cindex break in overloaded functions
11687 @item @r{breakpoint menus}
11688 When you want a breakpoint in a function whose name is overloaded,
11689 @value{GDBN} has the capability to display a menu of possible breakpoint
11690 locations to help you specify which function definition you want.
11691 @xref{Ambiguous Expressions,,Ambiguous Expressions}.
11692
11693 @cindex overloading in C@t{++}
11694 @item rbreak @var{regex}
11695 Setting breakpoints using regular expressions is helpful for setting
11696 breakpoints on overloaded functions that are not members of any special
11697 classes.
11698 @xref{Set Breaks, ,Setting Breakpoints}.
11699
11700 @cindex C@t{++} exception handling
11701 @item catch throw
11702 @itemx catch catch
11703 Debug C@t{++} exception handling using these commands. @xref{Set
11704 Catchpoints, , Setting Catchpoints}.
11705
11706 @cindex inheritance
11707 @item ptype @var{typename}
11708 Print inheritance relationships as well as other information for type
11709 @var{typename}.
11710 @xref{Symbols, ,Examining the Symbol Table}.
11711
11712 @cindex C@t{++} symbol display
11713 @item set print demangle
11714 @itemx show print demangle
11715 @itemx set print asm-demangle
11716 @itemx show print asm-demangle
11717 Control whether C@t{++} symbols display in their source form, both when
11718 displaying code as C@t{++} source and when displaying disassemblies.
11719 @xref{Print Settings, ,Print Settings}.
11720
11721 @item set print object
11722 @itemx show print object
11723 Choose whether to print derived (actual) or declared types of objects.
11724 @xref{Print Settings, ,Print Settings}.
11725
11726 @item set print vtbl
11727 @itemx show print vtbl
11728 Control the format for printing virtual function tables.
11729 @xref{Print Settings, ,Print Settings}.
11730 (The @code{vtbl} commands do not work on programs compiled with the HP
11731 ANSI C@t{++} compiler (@code{aCC}).)
11732
11733 @kindex set overload-resolution
11734 @cindex overloaded functions, overload resolution
11735 @item set overload-resolution on
11736 Enable overload resolution for C@t{++} expression evaluation. The default
11737 is on. For overloaded functions, @value{GDBN} evaluates the arguments
11738 and searches for a function whose signature matches the argument types,
11739 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
11740 Expressions, ,C@t{++} Expressions}, for details).
11741 If it cannot find a match, it emits a message.
11742
11743 @item set overload-resolution off
11744 Disable overload resolution for C@t{++} expression evaluation. For
11745 overloaded functions that are not class member functions, @value{GDBN}
11746 chooses the first function of the specified name that it finds in the
11747 symbol table, whether or not its arguments are of the correct type. For
11748 overloaded functions that are class member functions, @value{GDBN}
11749 searches for a function whose signature @emph{exactly} matches the
11750 argument types.
11751
11752 @kindex show overload-resolution
11753 @item show overload-resolution
11754 Show the current setting of overload resolution.
11755
11756 @item @r{Overloaded symbol names}
11757 You can specify a particular definition of an overloaded symbol, using
11758 the same notation that is used to declare such symbols in C@t{++}: type
11759 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
11760 also use the @value{GDBN} command-line word completion facilities to list the
11761 available choices, or to finish the type list for you.
11762 @xref{Completion,, Command Completion}, for details on how to do this.
11763 @end table
11764
11765 @node Decimal Floating Point
11766 @subsubsection Decimal Floating Point format
11767 @cindex decimal floating point format
11768
11769 @value{GDBN} can examine, set and perform computations with numbers in
11770 decimal floating point format, which in the C language correspond to the
11771 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
11772 specified by the extension to support decimal floating-point arithmetic.
11773
11774 There are two encodings in use, depending on the architecture: BID (Binary
11775 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
11776 PowerPC. @value{GDBN} will use the appropriate encoding for the configured
11777 target.
11778
11779 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
11780 to manipulate decimal floating point numbers, it is not possible to convert
11781 (using a cast, for example) integers wider than 32-bit to decimal float.
11782
11783 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
11784 point computations, error checking in decimal float operations ignores
11785 underflow, overflow and divide by zero exceptions.
11786
11787 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
11788 to inspect @code{_Decimal128} values stored in floating point registers.
11789 See @ref{PowerPC,,PowerPC} for more details.
11790
11791 @node D
11792 @subsection D
11793
11794 @cindex D
11795 @value{GDBN} can be used to debug programs written in D and compiled with
11796 GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
11797 specific feature --- dynamic arrays.
11798
11799 @node Objective-C
11800 @subsection Objective-C
11801
11802 @cindex Objective-C
11803 This section provides information about some commands and command
11804 options that are useful for debugging Objective-C code. See also
11805 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
11806 few more commands specific to Objective-C support.
11807
11808 @menu
11809 * Method Names in Commands::
11810 * The Print Command with Objective-C::
11811 @end menu
11812
11813 @node Method Names in Commands
11814 @subsubsection Method Names in Commands
11815
11816 The following commands have been extended to accept Objective-C method
11817 names as line specifications:
11818
11819 @kindex clear@r{, and Objective-C}
11820 @kindex break@r{, and Objective-C}
11821 @kindex info line@r{, and Objective-C}
11822 @kindex jump@r{, and Objective-C}
11823 @kindex list@r{, and Objective-C}
11824 @itemize
11825 @item @code{clear}
11826 @item @code{break}
11827 @item @code{info line}
11828 @item @code{jump}
11829 @item @code{list}
11830 @end itemize
11831
11832 A fully qualified Objective-C method name is specified as
11833
11834 @smallexample
11835 -[@var{Class} @var{methodName}]
11836 @end smallexample
11837
11838 where the minus sign is used to indicate an instance method and a
11839 plus sign (not shown) is used to indicate a class method. The class
11840 name @var{Class} and method name @var{methodName} are enclosed in
11841 brackets, similar to the way messages are specified in Objective-C
11842 source code. For example, to set a breakpoint at the @code{create}
11843 instance method of class @code{Fruit} in the program currently being
11844 debugged, enter:
11845
11846 @smallexample
11847 break -[Fruit create]
11848 @end smallexample
11849
11850 To list ten program lines around the @code{initialize} class method,
11851 enter:
11852
11853 @smallexample
11854 list +[NSText initialize]
11855 @end smallexample
11856
11857 In the current version of @value{GDBN}, the plus or minus sign is
11858 required. In future versions of @value{GDBN}, the plus or minus
11859 sign will be optional, but you can use it to narrow the search. It
11860 is also possible to specify just a method name:
11861
11862 @smallexample
11863 break create
11864 @end smallexample
11865
11866 You must specify the complete method name, including any colons. If
11867 your program's source files contain more than one @code{create} method,
11868 you'll be presented with a numbered list of classes that implement that
11869 method. Indicate your choice by number, or type @samp{0} to exit if
11870 none apply.
11871
11872 As another example, to clear a breakpoint established at the
11873 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
11874
11875 @smallexample
11876 clear -[NSWindow makeKeyAndOrderFront:]
11877 @end smallexample
11878
11879 @node The Print Command with Objective-C
11880 @subsubsection The Print Command With Objective-C
11881 @cindex Objective-C, print objects
11882 @kindex print-object
11883 @kindex po @r{(@code{print-object})}
11884
11885 The print command has also been extended to accept methods. For example:
11886
11887 @smallexample
11888 print -[@var{object} hash]
11889 @end smallexample
11890
11891 @cindex print an Objective-C object description
11892 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
11893 @noindent
11894 will tell @value{GDBN} to send the @code{hash} message to @var{object}
11895 and print the result. Also, an additional command has been added,
11896 @code{print-object} or @code{po} for short, which is meant to print
11897 the description of an object. However, this command may only work
11898 with certain Objective-C libraries that have a particular hook
11899 function, @code{_NSPrintForDebugger}, defined.
11900
11901 @node Fortran
11902 @subsection Fortran
11903 @cindex Fortran-specific support in @value{GDBN}
11904
11905 @value{GDBN} can be used to debug programs written in Fortran, but it
11906 currently supports only the features of Fortran 77 language.
11907
11908 @cindex trailing underscore, in Fortran symbols
11909 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
11910 among them) append an underscore to the names of variables and
11911 functions. When you debug programs compiled by those compilers, you
11912 will need to refer to variables and functions with a trailing
11913 underscore.
11914
11915 @menu
11916 * Fortran Operators:: Fortran operators and expressions
11917 * Fortran Defaults:: Default settings for Fortran
11918 * Special Fortran Commands:: Special @value{GDBN} commands for Fortran
11919 @end menu
11920
11921 @node Fortran Operators
11922 @subsubsection Fortran Operators and Expressions
11923
11924 @cindex Fortran operators and expressions
11925
11926 Operators must be defined on values of specific types. For instance,
11927 @code{+} is defined on numbers, but not on characters or other non-
11928 arithmetic types. Operators are often defined on groups of types.
11929
11930 @table @code
11931 @item **
11932 The exponentiation operator. It raises the first operand to the power
11933 of the second one.
11934
11935 @item :
11936 The range operator. Normally used in the form of array(low:high) to
11937 represent a section of array.
11938
11939 @item %
11940 The access component operator. Normally used to access elements in derived
11941 types. Also suitable for unions. As unions aren't part of regular Fortran,
11942 this can only happen when accessing a register that uses a gdbarch-defined
11943 union type.
11944 @end table
11945
11946 @node Fortran Defaults
11947 @subsubsection Fortran Defaults
11948
11949 @cindex Fortran Defaults
11950
11951 Fortran symbols are usually case-insensitive, so @value{GDBN} by
11952 default uses case-insensitive matches for Fortran symbols. You can
11953 change that with the @samp{set case-insensitive} command, see
11954 @ref{Symbols}, for the details.
11955
11956 @node Special Fortran Commands
11957 @subsubsection Special Fortran Commands
11958
11959 @cindex Special Fortran commands
11960
11961 @value{GDBN} has some commands to support Fortran-specific features,
11962 such as displaying common blocks.
11963
11964 @table @code
11965 @cindex @code{COMMON} blocks, Fortran
11966 @kindex info common
11967 @item info common @r{[}@var{common-name}@r{]}
11968 This command prints the values contained in the Fortran @code{COMMON}
11969 block whose name is @var{common-name}. With no argument, the names of
11970 all @code{COMMON} blocks visible at the current program location are
11971 printed.
11972 @end table
11973
11974 @node Pascal
11975 @subsection Pascal
11976
11977 @cindex Pascal support in @value{GDBN}, limitations
11978 Debugging Pascal programs which use sets, subranges, file variables, or
11979 nested functions does not currently work. @value{GDBN} does not support
11980 entering expressions, printing values, or similar features using Pascal
11981 syntax.
11982
11983 The Pascal-specific command @code{set print pascal_static-members}
11984 controls whether static members of Pascal objects are displayed.
11985 @xref{Print Settings, pascal_static-members}.
11986
11987 @node Modula-2
11988 @subsection Modula-2
11989
11990 @cindex Modula-2, @value{GDBN} support
11991
11992 The extensions made to @value{GDBN} to support Modula-2 only support
11993 output from the @sc{gnu} Modula-2 compiler (which is currently being
11994 developed). Other Modula-2 compilers are not currently supported, and
11995 attempting to debug executables produced by them is most likely
11996 to give an error as @value{GDBN} reads in the executable's symbol
11997 table.
11998
11999 @cindex expressions in Modula-2
12000 @menu
12001 * M2 Operators:: Built-in operators
12002 * Built-In Func/Proc:: Built-in functions and procedures
12003 * M2 Constants:: Modula-2 constants
12004 * M2 Types:: Modula-2 types
12005 * M2 Defaults:: Default settings for Modula-2
12006 * Deviations:: Deviations from standard Modula-2
12007 * M2 Checks:: Modula-2 type and range checks
12008 * M2 Scope:: The scope operators @code{::} and @code{.}
12009 * GDB/M2:: @value{GDBN} and Modula-2
12010 @end menu
12011
12012 @node M2 Operators
12013 @subsubsection Operators
12014 @cindex Modula-2 operators
12015
12016 Operators must be defined on values of specific types. For instance,
12017 @code{+} is defined on numbers, but not on structures. Operators are
12018 often defined on groups of types. For the purposes of Modula-2, the
12019 following definitions hold:
12020
12021 @itemize @bullet
12022
12023 @item
12024 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
12025 their subranges.
12026
12027 @item
12028 @emph{Character types} consist of @code{CHAR} and its subranges.
12029
12030 @item
12031 @emph{Floating-point types} consist of @code{REAL}.
12032
12033 @item
12034 @emph{Pointer types} consist of anything declared as @code{POINTER TO
12035 @var{type}}.
12036
12037 @item
12038 @emph{Scalar types} consist of all of the above.
12039
12040 @item
12041 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
12042
12043 @item
12044 @emph{Boolean types} consist of @code{BOOLEAN}.
12045 @end itemize
12046
12047 @noindent
12048 The following operators are supported, and appear in order of
12049 increasing precedence:
12050
12051 @table @code
12052 @item ,
12053 Function argument or array index separator.
12054
12055 @item :=
12056 Assignment. The value of @var{var} @code{:=} @var{value} is
12057 @var{value}.
12058
12059 @item <@r{, }>
12060 Less than, greater than on integral, floating-point, or enumerated
12061 types.
12062
12063 @item <=@r{, }>=
12064 Less than or equal to, greater than or equal to
12065 on integral, floating-point and enumerated types, or set inclusion on
12066 set types. Same precedence as @code{<}.
12067
12068 @item =@r{, }<>@r{, }#
12069 Equality and two ways of expressing inequality, valid on scalar types.
12070 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
12071 available for inequality, since @code{#} conflicts with the script
12072 comment character.
12073
12074 @item IN
12075 Set membership. Defined on set types and the types of their members.
12076 Same precedence as @code{<}.
12077
12078 @item OR
12079 Boolean disjunction. Defined on boolean types.
12080
12081 @item AND@r{, }&
12082 Boolean conjunction. Defined on boolean types.
12083
12084 @item @@
12085 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
12086
12087 @item +@r{, }-
12088 Addition and subtraction on integral and floating-point types, or union
12089 and difference on set types.
12090
12091 @item *
12092 Multiplication on integral and floating-point types, or set intersection
12093 on set types.
12094
12095 @item /
12096 Division on floating-point types, or symmetric set difference on set
12097 types. Same precedence as @code{*}.
12098
12099 @item DIV@r{, }MOD
12100 Integer division and remainder. Defined on integral types. Same
12101 precedence as @code{*}.
12102
12103 @item -
12104 Negative. Defined on @code{INTEGER} and @code{REAL} data.
12105
12106 @item ^
12107 Pointer dereferencing. Defined on pointer types.
12108
12109 @item NOT
12110 Boolean negation. Defined on boolean types. Same precedence as
12111 @code{^}.
12112
12113 @item .
12114 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
12115 precedence as @code{^}.
12116
12117 @item []
12118 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
12119
12120 @item ()
12121 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
12122 as @code{^}.
12123
12124 @item ::@r{, }.
12125 @value{GDBN} and Modula-2 scope operators.
12126 @end table
12127
12128 @quotation
12129 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
12130 treats the use of the operator @code{IN}, or the use of operators
12131 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
12132 @code{<=}, and @code{>=} on sets as an error.
12133 @end quotation
12134
12135
12136 @node Built-In Func/Proc
12137 @subsubsection Built-in Functions and Procedures
12138 @cindex Modula-2 built-ins
12139
12140 Modula-2 also makes available several built-in procedures and functions.
12141 In describing these, the following metavariables are used:
12142
12143 @table @var
12144
12145 @item a
12146 represents an @code{ARRAY} variable.
12147
12148 @item c
12149 represents a @code{CHAR} constant or variable.
12150
12151 @item i
12152 represents a variable or constant of integral type.
12153
12154 @item m
12155 represents an identifier that belongs to a set. Generally used in the
12156 same function with the metavariable @var{s}. The type of @var{s} should
12157 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
12158
12159 @item n
12160 represents a variable or constant of integral or floating-point type.
12161
12162 @item r
12163 represents a variable or constant of floating-point type.
12164
12165 @item t
12166 represents a type.
12167
12168 @item v
12169 represents a variable.
12170
12171 @item x
12172 represents a variable or constant of one of many types. See the
12173 explanation of the function for details.
12174 @end table
12175
12176 All Modula-2 built-in procedures also return a result, described below.
12177
12178 @table @code
12179 @item ABS(@var{n})
12180 Returns the absolute value of @var{n}.
12181
12182 @item CAP(@var{c})
12183 If @var{c} is a lower case letter, it returns its upper case
12184 equivalent, otherwise it returns its argument.
12185
12186 @item CHR(@var{i})
12187 Returns the character whose ordinal value is @var{i}.
12188
12189 @item DEC(@var{v})
12190 Decrements the value in the variable @var{v} by one. Returns the new value.
12191
12192 @item DEC(@var{v},@var{i})
12193 Decrements the value in the variable @var{v} by @var{i}. Returns the
12194 new value.
12195
12196 @item EXCL(@var{m},@var{s})
12197 Removes the element @var{m} from the set @var{s}. Returns the new
12198 set.
12199
12200 @item FLOAT(@var{i})
12201 Returns the floating point equivalent of the integer @var{i}.
12202
12203 @item HIGH(@var{a})
12204 Returns the index of the last member of @var{a}.
12205
12206 @item INC(@var{v})
12207 Increments the value in the variable @var{v} by one. Returns the new value.
12208
12209 @item INC(@var{v},@var{i})
12210 Increments the value in the variable @var{v} by @var{i}. Returns the
12211 new value.
12212
12213 @item INCL(@var{m},@var{s})
12214 Adds the element @var{m} to the set @var{s} if it is not already
12215 there. Returns the new set.
12216
12217 @item MAX(@var{t})
12218 Returns the maximum value of the type @var{t}.
12219
12220 @item MIN(@var{t})
12221 Returns the minimum value of the type @var{t}.
12222
12223 @item ODD(@var{i})
12224 Returns boolean TRUE if @var{i} is an odd number.
12225
12226 @item ORD(@var{x})
12227 Returns the ordinal value of its argument. For example, the ordinal
12228 value of a character is its @sc{ascii} value (on machines supporting the
12229 @sc{ascii} character set). @var{x} must be of an ordered type, which include
12230 integral, character and enumerated types.
12231
12232 @item SIZE(@var{x})
12233 Returns the size of its argument. @var{x} can be a variable or a type.
12234
12235 @item TRUNC(@var{r})
12236 Returns the integral part of @var{r}.
12237
12238 @item TSIZE(@var{x})
12239 Returns the size of its argument. @var{x} can be a variable or a type.
12240
12241 @item VAL(@var{t},@var{i})
12242 Returns the member of the type @var{t} whose ordinal value is @var{i}.
12243 @end table
12244
12245 @quotation
12246 @emph{Warning:} Sets and their operations are not yet supported, so
12247 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
12248 an error.
12249 @end quotation
12250
12251 @cindex Modula-2 constants
12252 @node M2 Constants
12253 @subsubsection Constants
12254
12255 @value{GDBN} allows you to express the constants of Modula-2 in the following
12256 ways:
12257
12258 @itemize @bullet
12259
12260 @item
12261 Integer constants are simply a sequence of digits. When used in an
12262 expression, a constant is interpreted to be type-compatible with the
12263 rest of the expression. Hexadecimal integers are specified by a
12264 trailing @samp{H}, and octal integers by a trailing @samp{B}.
12265
12266 @item
12267 Floating point constants appear as a sequence of digits, followed by a
12268 decimal point and another sequence of digits. An optional exponent can
12269 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
12270 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
12271 digits of the floating point constant must be valid decimal (base 10)
12272 digits.
12273
12274 @item
12275 Character constants consist of a single character enclosed by a pair of
12276 like quotes, either single (@code{'}) or double (@code{"}). They may
12277 also be expressed by their ordinal value (their @sc{ascii} value, usually)
12278 followed by a @samp{C}.
12279
12280 @item
12281 String constants consist of a sequence of characters enclosed by a
12282 pair of like quotes, either single (@code{'}) or double (@code{"}).
12283 Escape sequences in the style of C are also allowed. @xref{C
12284 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
12285 sequences.
12286
12287 @item
12288 Enumerated constants consist of an enumerated identifier.
12289
12290 @item
12291 Boolean constants consist of the identifiers @code{TRUE} and
12292 @code{FALSE}.
12293
12294 @item
12295 Pointer constants consist of integral values only.
12296
12297 @item
12298 Set constants are not yet supported.
12299 @end itemize
12300
12301 @node M2 Types
12302 @subsubsection Modula-2 Types
12303 @cindex Modula-2 types
12304
12305 Currently @value{GDBN} can print the following data types in Modula-2
12306 syntax: array types, record types, set types, pointer types, procedure
12307 types, enumerated types, subrange types and base types. You can also
12308 print the contents of variables declared using these type.
12309 This section gives a number of simple source code examples together with
12310 sample @value{GDBN} sessions.
12311
12312 The first example contains the following section of code:
12313
12314 @smallexample
12315 VAR
12316 s: SET OF CHAR ;
12317 r: [20..40] ;
12318 @end smallexample
12319
12320 @noindent
12321 and you can request @value{GDBN} to interrogate the type and value of
12322 @code{r} and @code{s}.
12323
12324 @smallexample
12325 (@value{GDBP}) print s
12326 @{'A'..'C', 'Z'@}
12327 (@value{GDBP}) ptype s
12328 SET OF CHAR
12329 (@value{GDBP}) print r
12330 21
12331 (@value{GDBP}) ptype r
12332 [20..40]
12333 @end smallexample
12334
12335 @noindent
12336 Likewise if your source code declares @code{s} as:
12337
12338 @smallexample
12339 VAR
12340 s: SET ['A'..'Z'] ;
12341 @end smallexample
12342
12343 @noindent
12344 then you may query the type of @code{s} by:
12345
12346 @smallexample
12347 (@value{GDBP}) ptype s
12348 type = SET ['A'..'Z']
12349 @end smallexample
12350
12351 @noindent
12352 Note that at present you cannot interactively manipulate set
12353 expressions using the debugger.
12354
12355 The following example shows how you might declare an array in Modula-2
12356 and how you can interact with @value{GDBN} to print its type and contents:
12357
12358 @smallexample
12359 VAR
12360 s: ARRAY [-10..10] OF CHAR ;
12361 @end smallexample
12362
12363 @smallexample
12364 (@value{GDBP}) ptype s
12365 ARRAY [-10..10] OF CHAR
12366 @end smallexample
12367
12368 Note that the array handling is not yet complete and although the type
12369 is printed correctly, expression handling still assumes that all
12370 arrays have a lower bound of zero and not @code{-10} as in the example
12371 above.
12372
12373 Here are some more type related Modula-2 examples:
12374
12375 @smallexample
12376 TYPE
12377 colour = (blue, red, yellow, green) ;
12378 t = [blue..yellow] ;
12379 VAR
12380 s: t ;
12381 BEGIN
12382 s := blue ;
12383 @end smallexample
12384
12385 @noindent
12386 The @value{GDBN} interaction shows how you can query the data type
12387 and value of a variable.
12388
12389 @smallexample
12390 (@value{GDBP}) print s
12391 $1 = blue
12392 (@value{GDBP}) ptype t
12393 type = [blue..yellow]
12394 @end smallexample
12395
12396 @noindent
12397 In this example a Modula-2 array is declared and its contents
12398 displayed. Observe that the contents are written in the same way as
12399 their @code{C} counterparts.
12400
12401 @smallexample
12402 VAR
12403 s: ARRAY [1..5] OF CARDINAL ;
12404 BEGIN
12405 s[1] := 1 ;
12406 @end smallexample
12407
12408 @smallexample
12409 (@value{GDBP}) print s
12410 $1 = @{1, 0, 0, 0, 0@}
12411 (@value{GDBP}) ptype s
12412 type = ARRAY [1..5] OF CARDINAL
12413 @end smallexample
12414
12415 The Modula-2 language interface to @value{GDBN} also understands
12416 pointer types as shown in this example:
12417
12418 @smallexample
12419 VAR
12420 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
12421 BEGIN
12422 NEW(s) ;
12423 s^[1] := 1 ;
12424 @end smallexample
12425
12426 @noindent
12427 and you can request that @value{GDBN} describes the type of @code{s}.
12428
12429 @smallexample
12430 (@value{GDBP}) ptype s
12431 type = POINTER TO ARRAY [1..5] OF CARDINAL
12432 @end smallexample
12433
12434 @value{GDBN} handles compound types as we can see in this example.
12435 Here we combine array types, record types, pointer types and subrange
12436 types:
12437
12438 @smallexample
12439 TYPE
12440 foo = RECORD
12441 f1: CARDINAL ;
12442 f2: CHAR ;
12443 f3: myarray ;
12444 END ;
12445
12446 myarray = ARRAY myrange OF CARDINAL ;
12447 myrange = [-2..2] ;
12448 VAR
12449 s: POINTER TO ARRAY myrange OF foo ;
12450 @end smallexample
12451
12452 @noindent
12453 and you can ask @value{GDBN} to describe the type of @code{s} as shown
12454 below.
12455
12456 @smallexample
12457 (@value{GDBP}) ptype s
12458 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
12459 f1 : CARDINAL;
12460 f2 : CHAR;
12461 f3 : ARRAY [-2..2] OF CARDINAL;
12462 END
12463 @end smallexample
12464
12465 @node M2 Defaults
12466 @subsubsection Modula-2 Defaults
12467 @cindex Modula-2 defaults
12468
12469 If type and range checking are set automatically by @value{GDBN}, they
12470 both default to @code{on} whenever the working language changes to
12471 Modula-2. This happens regardless of whether you or @value{GDBN}
12472 selected the working language.
12473
12474 If you allow @value{GDBN} to set the language automatically, then entering
12475 code compiled from a file whose name ends with @file{.mod} sets the
12476 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
12477 Infer the Source Language}, for further details.
12478
12479 @node Deviations
12480 @subsubsection Deviations from Standard Modula-2
12481 @cindex Modula-2, deviations from
12482
12483 A few changes have been made to make Modula-2 programs easier to debug.
12484 This is done primarily via loosening its type strictness:
12485
12486 @itemize @bullet
12487 @item
12488 Unlike in standard Modula-2, pointer constants can be formed by
12489 integers. This allows you to modify pointer variables during
12490 debugging. (In standard Modula-2, the actual address contained in a
12491 pointer variable is hidden from you; it can only be modified
12492 through direct assignment to another pointer variable or expression that
12493 returned a pointer.)
12494
12495 @item
12496 C escape sequences can be used in strings and characters to represent
12497 non-printable characters. @value{GDBN} prints out strings with these
12498 escape sequences embedded. Single non-printable characters are
12499 printed using the @samp{CHR(@var{nnn})} format.
12500
12501 @item
12502 The assignment operator (@code{:=}) returns the value of its right-hand
12503 argument.
12504
12505 @item
12506 All built-in procedures both modify @emph{and} return their argument.
12507 @end itemize
12508
12509 @node M2 Checks
12510 @subsubsection Modula-2 Type and Range Checks
12511 @cindex Modula-2 checks
12512
12513 @quotation
12514 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
12515 range checking.
12516 @end quotation
12517 @c FIXME remove warning when type/range checks added
12518
12519 @value{GDBN} considers two Modula-2 variables type equivalent if:
12520
12521 @itemize @bullet
12522 @item
12523 They are of types that have been declared equivalent via a @code{TYPE
12524 @var{t1} = @var{t2}} statement
12525
12526 @item
12527 They have been declared on the same line. (Note: This is true of the
12528 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
12529 @end itemize
12530
12531 As long as type checking is enabled, any attempt to combine variables
12532 whose types are not equivalent is an error.
12533
12534 Range checking is done on all mathematical operations, assignment, array
12535 index bounds, and all built-in functions and procedures.
12536
12537 @node M2 Scope
12538 @subsubsection The Scope Operators @code{::} and @code{.}
12539 @cindex scope
12540 @cindex @code{.}, Modula-2 scope operator
12541 @cindex colon, doubled as scope operator
12542 @ifinfo
12543 @vindex colon-colon@r{, in Modula-2}
12544 @c Info cannot handle :: but TeX can.
12545 @end ifinfo
12546 @ifnotinfo
12547 @vindex ::@r{, in Modula-2}
12548 @end ifnotinfo
12549
12550 There are a few subtle differences between the Modula-2 scope operator
12551 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
12552 similar syntax:
12553
12554 @smallexample
12555
12556 @var{module} . @var{id}
12557 @var{scope} :: @var{id}
12558 @end smallexample
12559
12560 @noindent
12561 where @var{scope} is the name of a module or a procedure,
12562 @var{module} the name of a module, and @var{id} is any declared
12563 identifier within your program, except another module.
12564
12565 Using the @code{::} operator makes @value{GDBN} search the scope
12566 specified by @var{scope} for the identifier @var{id}. If it is not
12567 found in the specified scope, then @value{GDBN} searches all scopes
12568 enclosing the one specified by @var{scope}.
12569
12570 Using the @code{.} operator makes @value{GDBN} search the current scope for
12571 the identifier specified by @var{id} that was imported from the
12572 definition module specified by @var{module}. With this operator, it is
12573 an error if the identifier @var{id} was not imported from definition
12574 module @var{module}, or if @var{id} is not an identifier in
12575 @var{module}.
12576
12577 @node GDB/M2
12578 @subsubsection @value{GDBN} and Modula-2
12579
12580 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
12581 Five subcommands of @code{set print} and @code{show print} apply
12582 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
12583 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
12584 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
12585 analogue in Modula-2.
12586
12587 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
12588 with any language, is not useful with Modula-2. Its
12589 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
12590 created in Modula-2 as they can in C or C@t{++}. However, because an
12591 address can be specified by an integral constant, the construct
12592 @samp{@{@var{type}@}@var{adrexp}} is still useful.
12593
12594 @cindex @code{#} in Modula-2
12595 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
12596 interpreted as the beginning of a comment. Use @code{<>} instead.
12597
12598 @node Ada
12599 @subsection Ada
12600 @cindex Ada
12601
12602 The extensions made to @value{GDBN} for Ada only support
12603 output from the @sc{gnu} Ada (GNAT) compiler.
12604 Other Ada compilers are not currently supported, and
12605 attempting to debug executables produced by them is most likely
12606 to be difficult.
12607
12608
12609 @cindex expressions in Ada
12610 @menu
12611 * Ada Mode Intro:: General remarks on the Ada syntax
12612 and semantics supported by Ada mode
12613 in @value{GDBN}.
12614 * Omissions from Ada:: Restrictions on the Ada expression syntax.
12615 * Additions to Ada:: Extensions of the Ada expression syntax.
12616 * Stopping Before Main Program:: Debugging the program during elaboration.
12617 * Ada Tasks:: Listing and setting breakpoints in tasks.
12618 * Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
12619 * Ada Glitches:: Known peculiarities of Ada mode.
12620 @end menu
12621
12622 @node Ada Mode Intro
12623 @subsubsection Introduction
12624 @cindex Ada mode, general
12625
12626 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
12627 syntax, with some extensions.
12628 The philosophy behind the design of this subset is
12629
12630 @itemize @bullet
12631 @item
12632 That @value{GDBN} should provide basic literals and access to operations for
12633 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
12634 leaving more sophisticated computations to subprograms written into the
12635 program (which therefore may be called from @value{GDBN}).
12636
12637 @item
12638 That type safety and strict adherence to Ada language restrictions
12639 are not particularly important to the @value{GDBN} user.
12640
12641 @item
12642 That brevity is important to the @value{GDBN} user.
12643 @end itemize
12644
12645 Thus, for brevity, the debugger acts as if all names declared in
12646 user-written packages are directly visible, even if they are not visible
12647 according to Ada rules, thus making it unnecessary to fully qualify most
12648 names with their packages, regardless of context. Where this causes
12649 ambiguity, @value{GDBN} asks the user's intent.
12650
12651 The debugger will start in Ada mode if it detects an Ada main program.
12652 As for other languages, it will enter Ada mode when stopped in a program that
12653 was translated from an Ada source file.
12654
12655 While in Ada mode, you may use `@t{--}' for comments. This is useful
12656 mostly for documenting command files. The standard @value{GDBN} comment
12657 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
12658 middle (to allow based literals).
12659
12660 The debugger supports limited overloading. Given a subprogram call in which
12661 the function symbol has multiple definitions, it will use the number of
12662 actual parameters and some information about their types to attempt to narrow
12663 the set of definitions. It also makes very limited use of context, preferring
12664 procedures to functions in the context of the @code{call} command, and
12665 functions to procedures elsewhere.
12666
12667 @node Omissions from Ada
12668 @subsubsection Omissions from Ada
12669 @cindex Ada, omissions from
12670
12671 Here are the notable omissions from the subset:
12672
12673 @itemize @bullet
12674 @item
12675 Only a subset of the attributes are supported:
12676
12677 @itemize @minus
12678 @item
12679 @t{'First}, @t{'Last}, and @t{'Length}
12680 on array objects (not on types and subtypes).
12681
12682 @item
12683 @t{'Min} and @t{'Max}.
12684
12685 @item
12686 @t{'Pos} and @t{'Val}.
12687
12688 @item
12689 @t{'Tag}.
12690
12691 @item
12692 @t{'Range} on array objects (not subtypes), but only as the right
12693 operand of the membership (@code{in}) operator.
12694
12695 @item
12696 @t{'Access}, @t{'Unchecked_Access}, and
12697 @t{'Unrestricted_Access} (a GNAT extension).
12698
12699 @item
12700 @t{'Address}.
12701 @end itemize
12702
12703 @item
12704 The names in
12705 @code{Characters.Latin_1} are not available and
12706 concatenation is not implemented. Thus, escape characters in strings are
12707 not currently available.
12708
12709 @item
12710 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
12711 equality of representations. They will generally work correctly
12712 for strings and arrays whose elements have integer or enumeration types.
12713 They may not work correctly for arrays whose element
12714 types have user-defined equality, for arrays of real values
12715 (in particular, IEEE-conformant floating point, because of negative
12716 zeroes and NaNs), and for arrays whose elements contain unused bits with
12717 indeterminate values.
12718
12719 @item
12720 The other component-by-component array operations (@code{and}, @code{or},
12721 @code{xor}, @code{not}, and relational tests other than equality)
12722 are not implemented.
12723
12724 @item
12725 @cindex array aggregates (Ada)
12726 @cindex record aggregates (Ada)
12727 @cindex aggregates (Ada)
12728 There is limited support for array and record aggregates. They are
12729 permitted only on the right sides of assignments, as in these examples:
12730
12731 @smallexample
12732 (@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
12733 (@value{GDBP}) set An_Array := (1, others => 0)
12734 (@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
12735 (@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
12736 (@value{GDBP}) set A_Record := (1, "Peter", True);
12737 (@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
12738 @end smallexample
12739
12740 Changing a
12741 discriminant's value by assigning an aggregate has an
12742 undefined effect if that discriminant is used within the record.
12743 However, you can first modify discriminants by directly assigning to
12744 them (which normally would not be allowed in Ada), and then performing an
12745 aggregate assignment. For example, given a variable @code{A_Rec}
12746 declared to have a type such as:
12747
12748 @smallexample
12749 type Rec (Len : Small_Integer := 0) is record
12750 Id : Integer;
12751 Vals : IntArray (1 .. Len);
12752 end record;
12753 @end smallexample
12754
12755 you can assign a value with a different size of @code{Vals} with two
12756 assignments:
12757
12758 @smallexample
12759 (@value{GDBP}) set A_Rec.Len := 4
12760 (@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
12761 @end smallexample
12762
12763 As this example also illustrates, @value{GDBN} is very loose about the usual
12764 rules concerning aggregates. You may leave out some of the
12765 components of an array or record aggregate (such as the @code{Len}
12766 component in the assignment to @code{A_Rec} above); they will retain their
12767 original values upon assignment. You may freely use dynamic values as
12768 indices in component associations. You may even use overlapping or
12769 redundant component associations, although which component values are
12770 assigned in such cases is not defined.
12771
12772 @item
12773 Calls to dispatching subprograms are not implemented.
12774
12775 @item
12776 The overloading algorithm is much more limited (i.e., less selective)
12777 than that of real Ada. It makes only limited use of the context in
12778 which a subexpression appears to resolve its meaning, and it is much
12779 looser in its rules for allowing type matches. As a result, some
12780 function calls will be ambiguous, and the user will be asked to choose
12781 the proper resolution.
12782
12783 @item
12784 The @code{new} operator is not implemented.
12785
12786 @item
12787 Entry calls are not implemented.
12788
12789 @item
12790 Aside from printing, arithmetic operations on the native VAX floating-point
12791 formats are not supported.
12792
12793 @item
12794 It is not possible to slice a packed array.
12795
12796 @item
12797 The names @code{True} and @code{False}, when not part of a qualified name,
12798 are interpreted as if implicitly prefixed by @code{Standard}, regardless of
12799 context.
12800 Should your program
12801 redefine these names in a package or procedure (at best a dubious practice),
12802 you will have to use fully qualified names to access their new definitions.
12803 @end itemize
12804
12805 @node Additions to Ada
12806 @subsubsection Additions to Ada
12807 @cindex Ada, deviations from
12808
12809 As it does for other languages, @value{GDBN} makes certain generic
12810 extensions to Ada (@pxref{Expressions}):
12811
12812 @itemize @bullet
12813 @item
12814 If the expression @var{E} is a variable residing in memory (typically
12815 a local variable or array element) and @var{N} is a positive integer,
12816 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
12817 @var{N}-1 adjacent variables following it in memory as an array. In
12818 Ada, this operator is generally not necessary, since its prime use is
12819 in displaying parts of an array, and slicing will usually do this in
12820 Ada. However, there are occasional uses when debugging programs in
12821 which certain debugging information has been optimized away.
12822
12823 @item
12824 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
12825 appears in function or file @var{B}.'' When @var{B} is a file name,
12826 you must typically surround it in single quotes.
12827
12828 @item
12829 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
12830 @var{type} that appears at address @var{addr}.''
12831
12832 @item
12833 A name starting with @samp{$} is a convenience variable
12834 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
12835 @end itemize
12836
12837 In addition, @value{GDBN} provides a few other shortcuts and outright
12838 additions specific to Ada:
12839
12840 @itemize @bullet
12841 @item
12842 The assignment statement is allowed as an expression, returning
12843 its right-hand operand as its value. Thus, you may enter
12844
12845 @smallexample
12846 (@value{GDBP}) set x := y + 3
12847 (@value{GDBP}) print A(tmp := y + 1)
12848 @end smallexample
12849
12850 @item
12851 The semicolon is allowed as an ``operator,'' returning as its value
12852 the value of its right-hand operand.
12853 This allows, for example,
12854 complex conditional breaks:
12855
12856 @smallexample
12857 (@value{GDBP}) break f
12858 (@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
12859 @end smallexample
12860
12861 @item
12862 Rather than use catenation and symbolic character names to introduce special
12863 characters into strings, one may instead use a special bracket notation,
12864 which is also used to print strings. A sequence of characters of the form
12865 @samp{["@var{XX}"]} within a string or character literal denotes the
12866 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
12867 sequence of characters @samp{["""]} also denotes a single quotation mark
12868 in strings. For example,
12869 @smallexample
12870 "One line.["0a"]Next line.["0a"]"
12871 @end smallexample
12872 @noindent
12873 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
12874 after each period.
12875
12876 @item
12877 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
12878 @t{'Max} is optional (and is ignored in any case). For example, it is valid
12879 to write
12880
12881 @smallexample
12882 (@value{GDBP}) print 'max(x, y)
12883 @end smallexample
12884
12885 @item
12886 When printing arrays, @value{GDBN} uses positional notation when the
12887 array has a lower bound of 1, and uses a modified named notation otherwise.
12888 For example, a one-dimensional array of three integers with a lower bound
12889 of 3 might print as
12890
12891 @smallexample
12892 (3 => 10, 17, 1)
12893 @end smallexample
12894
12895 @noindent
12896 That is, in contrast to valid Ada, only the first component has a @code{=>}
12897 clause.
12898
12899 @item
12900 You may abbreviate attributes in expressions with any unique,
12901 multi-character subsequence of
12902 their names (an exact match gets preference).
12903 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
12904 in place of @t{a'length}.
12905
12906 @item
12907 @cindex quoting Ada internal identifiers
12908 Since Ada is case-insensitive, the debugger normally maps identifiers you type
12909 to lower case. The GNAT compiler uses upper-case characters for
12910 some of its internal identifiers, which are normally of no interest to users.
12911 For the rare occasions when you actually have to look at them,
12912 enclose them in angle brackets to avoid the lower-case mapping.
12913 For example,
12914 @smallexample
12915 (@value{GDBP}) print <JMPBUF_SAVE>[0]
12916 @end smallexample
12917
12918 @item
12919 Printing an object of class-wide type or dereferencing an
12920 access-to-class-wide value will display all the components of the object's
12921 specific type (as indicated by its run-time tag). Likewise, component
12922 selection on such a value will operate on the specific type of the
12923 object.
12924
12925 @end itemize
12926
12927 @node Stopping Before Main Program
12928 @subsubsection Stopping at the Very Beginning
12929
12930 @cindex breakpointing Ada elaboration code
12931 It is sometimes necessary to debug the program during elaboration, and
12932 before reaching the main procedure.
12933 As defined in the Ada Reference
12934 Manual, the elaboration code is invoked from a procedure called
12935 @code{adainit}. To run your program up to the beginning of
12936 elaboration, simply use the following two commands:
12937 @code{tbreak adainit} and @code{run}.
12938
12939 @node Ada Tasks
12940 @subsubsection Extensions for Ada Tasks
12941 @cindex Ada, tasking
12942
12943 Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
12944 @value{GDBN} provides the following task-related commands:
12945
12946 @table @code
12947 @kindex info tasks
12948 @item info tasks
12949 This command shows a list of current Ada tasks, as in the following example:
12950
12951
12952 @smallexample
12953 @iftex
12954 @leftskip=0.5cm
12955 @end iftex
12956 (@value{GDBP}) info tasks
12957 ID TID P-ID Pri State Name
12958 1 8088000 0 15 Child Activation Wait main_task
12959 2 80a4000 1 15 Accept Statement b
12960 3 809a800 1 15 Child Activation Wait a
12961 * 4 80ae800 3 15 Runnable c
12962
12963 @end smallexample
12964
12965 @noindent
12966 In this listing, the asterisk before the last task indicates it to be the
12967 task currently being inspected.
12968
12969 @table @asis
12970 @item ID
12971 Represents @value{GDBN}'s internal task number.
12972
12973 @item TID
12974 The Ada task ID.
12975
12976 @item P-ID
12977 The parent's task ID (@value{GDBN}'s internal task number).
12978
12979 @item Pri
12980 The base priority of the task.
12981
12982 @item State
12983 Current state of the task.
12984
12985 @table @code
12986 @item Unactivated
12987 The task has been created but has not been activated. It cannot be
12988 executing.
12989
12990 @item Runnable
12991 The task is not blocked for any reason known to Ada. (It may be waiting
12992 for a mutex, though.) It is conceptually "executing" in normal mode.
12993
12994 @item Terminated
12995 The task is terminated, in the sense of ARM 9.3 (5). Any dependents
12996 that were waiting on terminate alternatives have been awakened and have
12997 terminated themselves.
12998
12999 @item Child Activation Wait
13000 The task is waiting for created tasks to complete activation.
13001
13002 @item Accept Statement
13003 The task is waiting on an accept or selective wait statement.
13004
13005 @item Waiting on entry call
13006 The task is waiting on an entry call.
13007
13008 @item Async Select Wait
13009 The task is waiting to start the abortable part of an asynchronous
13010 select statement.
13011
13012 @item Delay Sleep
13013 The task is waiting on a select statement with only a delay
13014 alternative open.
13015
13016 @item Child Termination Wait
13017 The task is sleeping having completed a master within itself, and is
13018 waiting for the tasks dependent on that master to become terminated or
13019 waiting on a terminate Phase.
13020
13021 @item Wait Child in Term Alt
13022 The task is sleeping waiting for tasks on terminate alternatives to
13023 finish terminating.
13024
13025 @item Accepting RV with @var{taskno}
13026 The task is accepting a rendez-vous with the task @var{taskno}.
13027 @end table
13028
13029 @item Name
13030 Name of the task in the program.
13031
13032 @end table
13033
13034 @kindex info task @var{taskno}
13035 @item info task @var{taskno}
13036 This command shows detailled informations on the specified task, as in
13037 the following example:
13038 @smallexample
13039 @iftex
13040 @leftskip=0.5cm
13041 @end iftex
13042 (@value{GDBP}) info tasks
13043 ID TID P-ID Pri State Name
13044 1 8077880 0 15 Child Activation Wait main_task
13045 * 2 807c468 1 15 Runnable task_1
13046 (@value{GDBP}) info task 2
13047 Ada Task: 0x807c468
13048 Name: task_1
13049 Thread: 0x807f378
13050 Parent: 1 (main_task)
13051 Base Priority: 15
13052 State: Runnable
13053 @end smallexample
13054
13055 @item task
13056 @kindex task@r{ (Ada)}
13057 @cindex current Ada task ID
13058 This command prints the ID of the current task.
13059
13060 @smallexample
13061 @iftex
13062 @leftskip=0.5cm
13063 @end iftex
13064 (@value{GDBP}) info tasks
13065 ID TID P-ID Pri State Name
13066 1 8077870 0 15 Child Activation Wait main_task
13067 * 2 807c458 1 15 Runnable t
13068 (@value{GDBP}) task
13069 [Current task is 2]
13070 @end smallexample
13071
13072 @item task @var{taskno}
13073 @cindex Ada task switching
13074 This command is like the @code{thread @var{threadno}}
13075 command (@pxref{Threads}). It switches the context of debugging
13076 from the current task to the given task.
13077
13078 @smallexample
13079 @iftex
13080 @leftskip=0.5cm
13081 @end iftex
13082 (@value{GDBP}) info tasks
13083 ID TID P-ID Pri State Name
13084 1 8077870 0 15 Child Activation Wait main_task
13085 * 2 807c458 1 15 Runnable t
13086 (@value{GDBP}) task 1
13087 [Switching to task 1]
13088 #0 0x8067726 in pthread_cond_wait ()
13089 (@value{GDBP}) bt
13090 #0 0x8067726 in pthread_cond_wait ()
13091 #1 0x8056714 in system.os_interface.pthread_cond_wait ()
13092 #2 0x805cb63 in system.task_primitives.operations.sleep ()
13093 #3 0x806153e in system.tasking.stages.activate_tasks ()
13094 #4 0x804aacc in un () at un.adb:5
13095 @end smallexample
13096
13097 @item break @var{linespec} task @var{taskno}
13098 @itemx break @var{linespec} task @var{taskno} if @dots{}
13099 @cindex breakpoints and tasks, in Ada
13100 @cindex task breakpoints, in Ada
13101 @kindex break @dots{} task @var{taskno}@r{ (Ada)}
13102 These commands are like the @code{break @dots{} thread @dots{}}
13103 command (@pxref{Thread Stops}).
13104 @var{linespec} specifies source lines, as described
13105 in @ref{Specify Location}.
13106
13107 Use the qualifier @samp{task @var{taskno}} with a breakpoint command
13108 to specify that you only want @value{GDBN} to stop the program when a
13109 particular Ada task reaches this breakpoint. @var{taskno} is one of the
13110 numeric task identifiers assigned by @value{GDBN}, shown in the first
13111 column of the @samp{info tasks} display.
13112
13113 If you do not specify @samp{task @var{taskno}} when you set a
13114 breakpoint, the breakpoint applies to @emph{all} tasks of your
13115 program.
13116
13117 You can use the @code{task} qualifier on conditional breakpoints as
13118 well; in this case, place @samp{task @var{taskno}} before the
13119 breakpoint condition (before the @code{if}).
13120
13121 For example,
13122
13123 @smallexample
13124 @iftex
13125 @leftskip=0.5cm
13126 @end iftex
13127 (@value{GDBP}) info tasks
13128 ID TID P-ID Pri State Name
13129 1 140022020 0 15 Child Activation Wait main_task
13130 2 140045060 1 15 Accept/Select Wait t2
13131 3 140044840 1 15 Runnable t1
13132 * 4 140056040 1 15 Runnable t3
13133 (@value{GDBP}) b 15 task 2
13134 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
13135 (@value{GDBP}) cont
13136 Continuing.
13137 task # 1 running
13138 task # 2 running
13139
13140 Breakpoint 5, test_task_debug () at test_task_debug.adb:15
13141 15 flush;
13142 (@value{GDBP}) info tasks
13143 ID TID P-ID Pri State Name
13144 1 140022020 0 15 Child Activation Wait main_task
13145 * 2 140045060 1 15 Runnable t2
13146 3 140044840 1 15 Runnable t1
13147 4 140056040 1 15 Delay Sleep t3
13148 @end smallexample
13149 @end table
13150
13151 @node Ada Tasks and Core Files
13152 @subsubsection Tasking Support when Debugging Core Files
13153 @cindex Ada tasking and core file debugging
13154
13155 When inspecting a core file, as opposed to debugging a live program,
13156 tasking support may be limited or even unavailable, depending on
13157 the platform being used.
13158 For instance, on x86-linux, the list of tasks is available, but task
13159 switching is not supported. On Tru64, however, task switching will work
13160 as usual.
13161
13162 On certain platforms, including Tru64, the debugger needs to perform some
13163 memory writes in order to provide Ada tasking support. When inspecting
13164 a core file, this means that the core file must be opened with read-write
13165 privileges, using the command @samp{"set write on"} (@pxref{Patching}).
13166 Under these circumstances, you should make a backup copy of the core
13167 file before inspecting it with @value{GDBN}.
13168
13169 @node Ada Glitches
13170 @subsubsection Known Peculiarities of Ada Mode
13171 @cindex Ada, problems
13172
13173 Besides the omissions listed previously (@pxref{Omissions from Ada}),
13174 we know of several problems with and limitations of Ada mode in
13175 @value{GDBN},
13176 some of which will be fixed with planned future releases of the debugger
13177 and the GNU Ada compiler.
13178
13179 @itemize @bullet
13180 @item
13181 Currently, the debugger
13182 has insufficient information to determine whether certain pointers represent
13183 pointers to objects or the objects themselves.
13184 Thus, the user may have to tack an extra @code{.all} after an expression
13185 to get it printed properly.
13186
13187 @item
13188 Static constants that the compiler chooses not to materialize as objects in
13189 storage are invisible to the debugger.
13190
13191 @item
13192 Named parameter associations in function argument lists are ignored (the
13193 argument lists are treated as positional).
13194
13195 @item
13196 Many useful library packages are currently invisible to the debugger.
13197
13198 @item
13199 Fixed-point arithmetic, conversions, input, and output is carried out using
13200 floating-point arithmetic, and may give results that only approximate those on
13201 the host machine.
13202
13203 @item
13204 The GNAT compiler never generates the prefix @code{Standard} for any of
13205 the standard symbols defined by the Ada language. @value{GDBN} knows about
13206 this: it will strip the prefix from names when you use it, and will never
13207 look for a name you have so qualified among local symbols, nor match against
13208 symbols in other packages or subprograms. If you have
13209 defined entities anywhere in your program other than parameters and
13210 local variables whose simple names match names in @code{Standard},
13211 GNAT's lack of qualification here can cause confusion. When this happens,
13212 you can usually resolve the confusion
13213 by qualifying the problematic names with package
13214 @code{Standard} explicitly.
13215 @end itemize
13216
13217 Older versions of the compiler sometimes generate erroneous debugging
13218 information, resulting in the debugger incorrectly printing the value
13219 of affected entities. In some cases, the debugger is able to work
13220 around an issue automatically. In other cases, the debugger is able
13221 to work around the issue, but the work-around has to be specifically
13222 enabled.
13223
13224 @kindex set ada trust-PAD-over-XVS
13225 @kindex show ada trust-PAD-over-XVS
13226 @table @code
13227
13228 @item set ada trust-PAD-over-XVS on
13229 Configure GDB to strictly follow the GNAT encoding when computing the
13230 value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
13231 types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
13232 a complete description of the encoding used by the GNAT compiler).
13233 This is the default.
13234
13235 @item set ada trust-PAD-over-XVS off
13236 This is related to the encoding using by the GNAT compiler. If @value{GDBN}
13237 sometimes prints the wrong value for certain entities, changing @code{ada
13238 trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
13239 the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
13240 @code{off}, but this incurs a slight performance penalty, so it is
13241 recommended to leave this setting to @code{on} unless necessary.
13242
13243 @end table
13244
13245 @node Unsupported Languages
13246 @section Unsupported Languages
13247
13248 @cindex unsupported languages
13249 @cindex minimal language
13250 In addition to the other fully-supported programming languages,
13251 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
13252 It does not represent a real programming language, but provides a set
13253 of capabilities close to what the C or assembly languages provide.
13254 This should allow most simple operations to be performed while debugging
13255 an application that uses a language currently not supported by @value{GDBN}.
13256
13257 If the language is set to @code{auto}, @value{GDBN} will automatically
13258 select this language if the current frame corresponds to an unsupported
13259 language.
13260
13261 @node Symbols
13262 @chapter Examining the Symbol Table
13263
13264 The commands described in this chapter allow you to inquire about the
13265 symbols (names of variables, functions and types) defined in your
13266 program. This information is inherent in the text of your program and
13267 does not change as your program executes. @value{GDBN} finds it in your
13268 program's symbol table, in the file indicated when you started @value{GDBN}
13269 (@pxref{File Options, ,Choosing Files}), or by one of the
13270 file-management commands (@pxref{Files, ,Commands to Specify Files}).
13271
13272 @cindex symbol names
13273 @cindex names of symbols
13274 @cindex quoting names
13275 Occasionally, you may need to refer to symbols that contain unusual
13276 characters, which @value{GDBN} ordinarily treats as word delimiters. The
13277 most frequent case is in referring to static variables in other
13278 source files (@pxref{Variables,,Program Variables}). File names
13279 are recorded in object files as debugging symbols, but @value{GDBN} would
13280 ordinarily parse a typical file name, like @file{foo.c}, as the three words
13281 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
13282 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
13283
13284 @smallexample
13285 p 'foo.c'::x
13286 @end smallexample
13287
13288 @noindent
13289 looks up the value of @code{x} in the scope of the file @file{foo.c}.
13290
13291 @table @code
13292 @cindex case-insensitive symbol names
13293 @cindex case sensitivity in symbol names
13294 @kindex set case-sensitive
13295 @item set case-sensitive on
13296 @itemx set case-sensitive off
13297 @itemx set case-sensitive auto
13298 Normally, when @value{GDBN} looks up symbols, it matches their names
13299 with case sensitivity determined by the current source language.
13300 Occasionally, you may wish to control that. The command @code{set
13301 case-sensitive} lets you do that by specifying @code{on} for
13302 case-sensitive matches or @code{off} for case-insensitive ones. If
13303 you specify @code{auto}, case sensitivity is reset to the default
13304 suitable for the source language. The default is case-sensitive
13305 matches for all languages except for Fortran, for which the default is
13306 case-insensitive matches.
13307
13308 @kindex show case-sensitive
13309 @item show case-sensitive
13310 This command shows the current setting of case sensitivity for symbols
13311 lookups.
13312
13313 @kindex info address
13314 @cindex address of a symbol
13315 @item info address @var{symbol}
13316 Describe where the data for @var{symbol} is stored. For a register
13317 variable, this says which register it is kept in. For a non-register
13318 local variable, this prints the stack-frame offset at which the variable
13319 is always stored.
13320
13321 Note the contrast with @samp{print &@var{symbol}}, which does not work
13322 at all for a register variable, and for a stack local variable prints
13323 the exact address of the current instantiation of the variable.
13324
13325 @kindex info symbol
13326 @cindex symbol from address
13327 @cindex closest symbol and offset for an address
13328 @item info symbol @var{addr}
13329 Print the name of a symbol which is stored at the address @var{addr}.
13330 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
13331 nearest symbol and an offset from it:
13332
13333 @smallexample
13334 (@value{GDBP}) info symbol 0x54320
13335 _initialize_vx + 396 in section .text
13336 @end smallexample
13337
13338 @noindent
13339 This is the opposite of the @code{info address} command. You can use
13340 it to find out the name of a variable or a function given its address.
13341
13342 For dynamically linked executables, the name of executable or shared
13343 library containing the symbol is also printed:
13344
13345 @smallexample
13346 (@value{GDBP}) info symbol 0x400225
13347 _start + 5 in section .text of /tmp/a.out
13348 (@value{GDBP}) info symbol 0x2aaaac2811cf
13349 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
13350 @end smallexample
13351
13352 @kindex whatis
13353 @item whatis [@var{arg}]
13354 Print the data type of @var{arg}, which can be either an expression or
13355 a data type. With no argument, print the data type of @code{$}, the
13356 last value in the value history. If @var{arg} is an expression, it is
13357 not actually evaluated, and any side-effecting operations (such as
13358 assignments or function calls) inside it do not take place. If
13359 @var{arg} is a type name, it may be the name of a type or typedef, or
13360 for C code it may have the form @samp{class @var{class-name}},
13361 @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
13362 @samp{enum @var{enum-tag}}.
13363 @xref{Expressions, ,Expressions}.
13364
13365 @kindex ptype
13366 @item ptype [@var{arg}]
13367 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
13368 detailed description of the type, instead of just the name of the type.
13369 @xref{Expressions, ,Expressions}.
13370
13371 For example, for this variable declaration:
13372
13373 @smallexample
13374 struct complex @{double real; double imag;@} v;
13375 @end smallexample
13376
13377 @noindent
13378 the two commands give this output:
13379
13380 @smallexample
13381 @group
13382 (@value{GDBP}) whatis v
13383 type = struct complex
13384 (@value{GDBP}) ptype v
13385 type = struct complex @{
13386 double real;
13387 double imag;
13388 @}
13389 @end group
13390 @end smallexample
13391
13392 @noindent
13393 As with @code{whatis}, using @code{ptype} without an argument refers to
13394 the type of @code{$}, the last value in the value history.
13395
13396 @cindex incomplete type
13397 Sometimes, programs use opaque data types or incomplete specifications
13398 of complex data structure. If the debug information included in the
13399 program does not allow @value{GDBN} to display a full declaration of
13400 the data type, it will say @samp{<incomplete type>}. For example,
13401 given these declarations:
13402
13403 @smallexample
13404 struct foo;
13405 struct foo *fooptr;
13406 @end smallexample
13407
13408 @noindent
13409 but no definition for @code{struct foo} itself, @value{GDBN} will say:
13410
13411 @smallexample
13412 (@value{GDBP}) ptype foo
13413 $1 = <incomplete type>
13414 @end smallexample
13415
13416 @noindent
13417 ``Incomplete type'' is C terminology for data types that are not
13418 completely specified.
13419
13420 @kindex info types
13421 @item info types @var{regexp}
13422 @itemx info types
13423 Print a brief description of all types whose names match the regular
13424 expression @var{regexp} (or all types in your program, if you supply
13425 no argument). Each complete typename is matched as though it were a
13426 complete line; thus, @samp{i type value} gives information on all
13427 types in your program whose names include the string @code{value}, but
13428 @samp{i type ^value$} gives information only on types whose complete
13429 name is @code{value}.
13430
13431 This command differs from @code{ptype} in two ways: first, like
13432 @code{whatis}, it does not print a detailed description; second, it
13433 lists all source files where a type is defined.
13434
13435 @kindex info scope
13436 @cindex local variables
13437 @item info scope @var{location}
13438 List all the variables local to a particular scope. This command
13439 accepts a @var{location} argument---a function name, a source line, or
13440 an address preceded by a @samp{*}, and prints all the variables local
13441 to the scope defined by that location. (@xref{Specify Location}, for
13442 details about supported forms of @var{location}.) For example:
13443
13444 @smallexample
13445 (@value{GDBP}) @b{info scope command_line_handler}
13446 Scope for command_line_handler:
13447 Symbol rl is an argument at stack/frame offset 8, length 4.
13448 Symbol linebuffer is in static storage at address 0x150a18, length 4.
13449 Symbol linelength is in static storage at address 0x150a1c, length 4.
13450 Symbol p is a local variable in register $esi, length 4.
13451 Symbol p1 is a local variable in register $ebx, length 4.
13452 Symbol nline is a local variable in register $edx, length 4.
13453 Symbol repeat is a local variable at frame offset -8, length 4.
13454 @end smallexample
13455
13456 @noindent
13457 This command is especially useful for determining what data to collect
13458 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
13459 collect}.
13460
13461 @kindex info source
13462 @item info source
13463 Show information about the current source file---that is, the source file for
13464 the function containing the current point of execution:
13465 @itemize @bullet
13466 @item
13467 the name of the source file, and the directory containing it,
13468 @item
13469 the directory it was compiled in,
13470 @item
13471 its length, in lines,
13472 @item
13473 which programming language it is written in,
13474 @item
13475 whether the executable includes debugging information for that file, and
13476 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
13477 @item
13478 whether the debugging information includes information about
13479 preprocessor macros.
13480 @end itemize
13481
13482
13483 @kindex info sources
13484 @item info sources
13485 Print the names of all source files in your program for which there is
13486 debugging information, organized into two lists: files whose symbols
13487 have already been read, and files whose symbols will be read when needed.
13488
13489 @kindex info functions
13490 @item info functions
13491 Print the names and data types of all defined functions.
13492
13493 @item info functions @var{regexp}
13494 Print the names and data types of all defined functions
13495 whose names contain a match for regular expression @var{regexp}.
13496 Thus, @samp{info fun step} finds all functions whose names
13497 include @code{step}; @samp{info fun ^step} finds those whose names
13498 start with @code{step}. If a function name contains characters
13499 that conflict with the regular expression language (e.g.@:
13500 @samp{operator*()}), they may be quoted with a backslash.
13501
13502 @kindex info variables
13503 @item info variables
13504 Print the names and data types of all variables that are defined
13505 outside of functions (i.e.@: excluding local variables).
13506
13507 @item info variables @var{regexp}
13508 Print the names and data types of all variables (except for local
13509 variables) whose names contain a match for regular expression
13510 @var{regexp}.
13511
13512 @kindex info classes
13513 @cindex Objective-C, classes and selectors
13514 @item info classes
13515 @itemx info classes @var{regexp}
13516 Display all Objective-C classes in your program, or
13517 (with the @var{regexp} argument) all those matching a particular regular
13518 expression.
13519
13520 @kindex info selectors
13521 @item info selectors
13522 @itemx info selectors @var{regexp}
13523 Display all Objective-C selectors in your program, or
13524 (with the @var{regexp} argument) all those matching a particular regular
13525 expression.
13526
13527 @ignore
13528 This was never implemented.
13529 @kindex info methods
13530 @item info methods
13531 @itemx info methods @var{regexp}
13532 The @code{info methods} command permits the user to examine all defined
13533 methods within C@t{++} program, or (with the @var{regexp} argument) a
13534 specific set of methods found in the various C@t{++} classes. Many
13535 C@t{++} classes provide a large number of methods. Thus, the output
13536 from the @code{ptype} command can be overwhelming and hard to use. The
13537 @code{info-methods} command filters the methods, printing only those
13538 which match the regular-expression @var{regexp}.
13539 @end ignore
13540
13541 @cindex reloading symbols
13542 Some systems allow individual object files that make up your program to
13543 be replaced without stopping and restarting your program. For example,
13544 in VxWorks you can simply recompile a defective object file and keep on
13545 running. If you are running on one of these systems, you can allow
13546 @value{GDBN} to reload the symbols for automatically relinked modules:
13547
13548 @table @code
13549 @kindex set symbol-reloading
13550 @item set symbol-reloading on
13551 Replace symbol definitions for the corresponding source file when an
13552 object file with a particular name is seen again.
13553
13554 @item set symbol-reloading off
13555 Do not replace symbol definitions when encountering object files of the
13556 same name more than once. This is the default state; if you are not
13557 running on a system that permits automatic relinking of modules, you
13558 should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
13559 may discard symbols when linking large programs, that may contain
13560 several modules (from different directories or libraries) with the same
13561 name.
13562
13563 @kindex show symbol-reloading
13564 @item show symbol-reloading
13565 Show the current @code{on} or @code{off} setting.
13566 @end table
13567
13568 @cindex opaque data types
13569 @kindex set opaque-type-resolution
13570 @item set opaque-type-resolution on
13571 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
13572 declared as a pointer to a @code{struct}, @code{class}, or
13573 @code{union}---for example, @code{struct MyType *}---that is used in one
13574 source file although the full declaration of @code{struct MyType} is in
13575 another source file. The default is on.
13576
13577 A change in the setting of this subcommand will not take effect until
13578 the next time symbols for a file are loaded.
13579
13580 @item set opaque-type-resolution off
13581 Tell @value{GDBN} not to resolve opaque types. In this case, the type
13582 is printed as follows:
13583 @smallexample
13584 @{<no data fields>@}
13585 @end smallexample
13586
13587 @kindex show opaque-type-resolution
13588 @item show opaque-type-resolution
13589 Show whether opaque types are resolved or not.
13590
13591 @kindex maint print symbols
13592 @cindex symbol dump
13593 @kindex maint print psymbols
13594 @cindex partial symbol dump
13595 @item maint print symbols @var{filename}
13596 @itemx maint print psymbols @var{filename}
13597 @itemx maint print msymbols @var{filename}
13598 Write a dump of debugging symbol data into the file @var{filename}.
13599 These commands are used to debug the @value{GDBN} symbol-reading code. Only
13600 symbols with debugging data are included. If you use @samp{maint print
13601 symbols}, @value{GDBN} includes all the symbols for which it has already
13602 collected full details: that is, @var{filename} reflects symbols for
13603 only those files whose symbols @value{GDBN} has read. You can use the
13604 command @code{info sources} to find out which files these are. If you
13605 use @samp{maint print psymbols} instead, the dump shows information about
13606 symbols that @value{GDBN} only knows partially---that is, symbols defined in
13607 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
13608 @samp{maint print msymbols} dumps just the minimal symbol information
13609 required for each object file from which @value{GDBN} has read some symbols.
13610 @xref{Files, ,Commands to Specify Files}, for a discussion of how
13611 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
13612
13613 @kindex maint info symtabs
13614 @kindex maint info psymtabs
13615 @cindex listing @value{GDBN}'s internal symbol tables
13616 @cindex symbol tables, listing @value{GDBN}'s internal
13617 @cindex full symbol tables, listing @value{GDBN}'s internal
13618 @cindex partial symbol tables, listing @value{GDBN}'s internal
13619 @item maint info symtabs @r{[} @var{regexp} @r{]}
13620 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
13621
13622 List the @code{struct symtab} or @code{struct partial_symtab}
13623 structures whose names match @var{regexp}. If @var{regexp} is not
13624 given, list them all. The output includes expressions which you can
13625 copy into a @value{GDBN} debugging this one to examine a particular
13626 structure in more detail. For example:
13627
13628 @smallexample
13629 (@value{GDBP}) maint info psymtabs dwarf2read
13630 @{ objfile /home/gnu/build/gdb/gdb
13631 ((struct objfile *) 0x82e69d0)
13632 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
13633 ((struct partial_symtab *) 0x8474b10)
13634 readin no
13635 fullname (null)
13636 text addresses 0x814d3c8 -- 0x8158074
13637 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
13638 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
13639 dependencies (none)
13640 @}
13641 @}
13642 (@value{GDBP}) maint info symtabs
13643 (@value{GDBP})
13644 @end smallexample
13645 @noindent
13646 We see that there is one partial symbol table whose filename contains
13647 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
13648 and we see that @value{GDBN} has not read in any symtabs yet at all.
13649 If we set a breakpoint on a function, that will cause @value{GDBN} to
13650 read the symtab for the compilation unit containing that function:
13651
13652 @smallexample
13653 (@value{GDBP}) break dwarf2_psymtab_to_symtab
13654 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
13655 line 1574.
13656 (@value{GDBP}) maint info symtabs
13657 @{ objfile /home/gnu/build/gdb/gdb
13658 ((struct objfile *) 0x82e69d0)
13659 @{ symtab /home/gnu/src/gdb/dwarf2read.c
13660 ((struct symtab *) 0x86c1f38)
13661 dirname (null)
13662 fullname (null)
13663 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
13664 linetable ((struct linetable *) 0x8370fa0)
13665 debugformat DWARF 2
13666 @}
13667 @}
13668 (@value{GDBP})
13669 @end smallexample
13670 @end table
13671
13672
13673 @node Altering
13674 @chapter Altering Execution
13675
13676 Once you think you have found an error in your program, you might want to
13677 find out for certain whether correcting the apparent error would lead to
13678 correct results in the rest of the run. You can find the answer by
13679 experiment, using the @value{GDBN} features for altering execution of the
13680 program.
13681
13682 For example, you can store new values into variables or memory
13683 locations, give your program a signal, restart it at a different
13684 address, or even return prematurely from a function.
13685
13686 @menu
13687 * Assignment:: Assignment to variables
13688 * Jumping:: Continuing at a different address
13689 * Signaling:: Giving your program a signal
13690 * Returning:: Returning from a function
13691 * Calling:: Calling your program's functions
13692 * Patching:: Patching your program
13693 @end menu
13694
13695 @node Assignment
13696 @section Assignment to Variables
13697
13698 @cindex assignment
13699 @cindex setting variables
13700 To alter the value of a variable, evaluate an assignment expression.
13701 @xref{Expressions, ,Expressions}. For example,
13702
13703 @smallexample
13704 print x=4
13705 @end smallexample
13706
13707 @noindent
13708 stores the value 4 into the variable @code{x}, and then prints the
13709 value of the assignment expression (which is 4).
13710 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
13711 information on operators in supported languages.
13712
13713 @kindex set variable
13714 @cindex variables, setting
13715 If you are not interested in seeing the value of the assignment, use the
13716 @code{set} command instead of the @code{print} command. @code{set} is
13717 really the same as @code{print} except that the expression's value is
13718 not printed and is not put in the value history (@pxref{Value History,
13719 ,Value History}). The expression is evaluated only for its effects.
13720
13721 If the beginning of the argument string of the @code{set} command
13722 appears identical to a @code{set} subcommand, use the @code{set
13723 variable} command instead of just @code{set}. This command is identical
13724 to @code{set} except for its lack of subcommands. For example, if your
13725 program has a variable @code{width}, you get an error if you try to set
13726 a new value with just @samp{set width=13}, because @value{GDBN} has the
13727 command @code{set width}:
13728
13729 @smallexample
13730 (@value{GDBP}) whatis width
13731 type = double
13732 (@value{GDBP}) p width
13733 $4 = 13
13734 (@value{GDBP}) set width=47
13735 Invalid syntax in expression.
13736 @end smallexample
13737
13738 @noindent
13739 The invalid expression, of course, is @samp{=47}. In
13740 order to actually set the program's variable @code{width}, use
13741
13742 @smallexample
13743 (@value{GDBP}) set var width=47
13744 @end smallexample
13745
13746 Because the @code{set} command has many subcommands that can conflict
13747 with the names of program variables, it is a good idea to use the
13748 @code{set variable} command instead of just @code{set}. For example, if
13749 your program has a variable @code{g}, you run into problems if you try
13750 to set a new value with just @samp{set g=4}, because @value{GDBN} has
13751 the command @code{set gnutarget}, abbreviated @code{set g}:
13752
13753 @smallexample
13754 @group
13755 (@value{GDBP}) whatis g
13756 type = double
13757 (@value{GDBP}) p g
13758 $1 = 1
13759 (@value{GDBP}) set g=4
13760 (@value{GDBP}) p g
13761 $2 = 1
13762 (@value{GDBP}) r
13763 The program being debugged has been started already.
13764 Start it from the beginning? (y or n) y
13765 Starting program: /home/smith/cc_progs/a.out
13766 "/home/smith/cc_progs/a.out": can't open to read symbols:
13767 Invalid bfd target.
13768 (@value{GDBP}) show g
13769 The current BFD target is "=4".
13770 @end group
13771 @end smallexample
13772
13773 @noindent
13774 The program variable @code{g} did not change, and you silently set the
13775 @code{gnutarget} to an invalid value. In order to set the variable
13776 @code{g}, use
13777
13778 @smallexample
13779 (@value{GDBP}) set var g=4
13780 @end smallexample
13781
13782 @value{GDBN} allows more implicit conversions in assignments than C; you can
13783 freely store an integer value into a pointer variable or vice versa,
13784 and you can convert any structure to any other structure that is the
13785 same length or shorter.
13786 @comment FIXME: how do structs align/pad in these conversions?
13787 @comment /doc@cygnus.com 18dec1990
13788
13789 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
13790 construct to generate a value of specified type at a specified address
13791 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
13792 to memory location @code{0x83040} as an integer (which implies a certain size
13793 and representation in memory), and
13794
13795 @smallexample
13796 set @{int@}0x83040 = 4
13797 @end smallexample
13798
13799 @noindent
13800 stores the value 4 into that memory location.
13801
13802 @node Jumping
13803 @section Continuing at a Different Address
13804
13805 Ordinarily, when you continue your program, you do so at the place where
13806 it stopped, with the @code{continue} command. You can instead continue at
13807 an address of your own choosing, with the following commands:
13808
13809 @table @code
13810 @kindex jump
13811 @item jump @var{linespec}
13812 @itemx jump @var{location}
13813 Resume execution at line @var{linespec} or at address given by
13814 @var{location}. Execution stops again immediately if there is a
13815 breakpoint there. @xref{Specify Location}, for a description of the
13816 different forms of @var{linespec} and @var{location}. It is common
13817 practice to use the @code{tbreak} command in conjunction with
13818 @code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
13819
13820 The @code{jump} command does not change the current stack frame, or
13821 the stack pointer, or the contents of any memory location or any
13822 register other than the program counter. If line @var{linespec} is in
13823 a different function from the one currently executing, the results may
13824 be bizarre if the two functions expect different patterns of arguments or
13825 of local variables. For this reason, the @code{jump} command requests
13826 confirmation if the specified line is not in the function currently
13827 executing. However, even bizarre results are predictable if you are
13828 well acquainted with the machine-language code of your program.
13829 @end table
13830
13831 @c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
13832 On many systems, you can get much the same effect as the @code{jump}
13833 command by storing a new value into the register @code{$pc}. The
13834 difference is that this does not start your program running; it only
13835 changes the address of where it @emph{will} run when you continue. For
13836 example,
13837
13838 @smallexample
13839 set $pc = 0x485
13840 @end smallexample
13841
13842 @noindent
13843 makes the next @code{continue} command or stepping command execute at
13844 address @code{0x485}, rather than at the address where your program stopped.
13845 @xref{Continuing and Stepping, ,Continuing and Stepping}.
13846
13847 The most common occasion to use the @code{jump} command is to back
13848 up---perhaps with more breakpoints set---over a portion of a program
13849 that has already executed, in order to examine its execution in more
13850 detail.
13851
13852 @c @group
13853 @node Signaling
13854 @section Giving your Program a Signal
13855 @cindex deliver a signal to a program
13856
13857 @table @code
13858 @kindex signal
13859 @item signal @var{signal}
13860 Resume execution where your program stopped, but immediately give it the
13861 signal @var{signal}. @var{signal} can be the name or the number of a
13862 signal. For example, on many systems @code{signal 2} and @code{signal
13863 SIGINT} are both ways of sending an interrupt signal.
13864
13865 Alternatively, if @var{signal} is zero, continue execution without
13866 giving a signal. This is useful when your program stopped on account of
13867 a signal and would ordinary see the signal when resumed with the
13868 @code{continue} command; @samp{signal 0} causes it to resume without a
13869 signal.
13870
13871 @code{signal} does not repeat when you press @key{RET} a second time
13872 after executing the command.
13873 @end table
13874 @c @end group
13875
13876 Invoking the @code{signal} command is not the same as invoking the
13877 @code{kill} utility from the shell. Sending a signal with @code{kill}
13878 causes @value{GDBN} to decide what to do with the signal depending on
13879 the signal handling tables (@pxref{Signals}). The @code{signal} command
13880 passes the signal directly to your program.
13881
13882
13883 @node Returning
13884 @section Returning from a Function
13885
13886 @table @code
13887 @cindex returning from a function
13888 @kindex return
13889 @item return
13890 @itemx return @var{expression}
13891 You can cancel execution of a function call with the @code{return}
13892 command. If you give an
13893 @var{expression} argument, its value is used as the function's return
13894 value.
13895 @end table
13896
13897 When you use @code{return}, @value{GDBN} discards the selected stack frame
13898 (and all frames within it). You can think of this as making the
13899 discarded frame return prematurely. If you wish to specify a value to
13900 be returned, give that value as the argument to @code{return}.
13901
13902 This pops the selected stack frame (@pxref{Selection, ,Selecting a
13903 Frame}), and any other frames inside of it, leaving its caller as the
13904 innermost remaining frame. That frame becomes selected. The
13905 specified value is stored in the registers used for returning values
13906 of functions.
13907
13908 The @code{return} command does not resume execution; it leaves the
13909 program stopped in the state that would exist if the function had just
13910 returned. In contrast, the @code{finish} command (@pxref{Continuing
13911 and Stepping, ,Continuing and Stepping}) resumes execution until the
13912 selected stack frame returns naturally.
13913
13914 @value{GDBN} needs to know how the @var{expression} argument should be set for
13915 the inferior. The concrete registers assignment depends on the OS ABI and the
13916 type being returned by the selected stack frame. For example it is common for
13917 OS ABI to return floating point values in FPU registers while integer values in
13918 CPU registers. Still some ABIs return even floating point values in CPU
13919 registers. Larger integer widths (such as @code{long long int}) also have
13920 specific placement rules. @value{GDBN} already knows the OS ABI from its
13921 current target so it needs to find out also the type being returned to make the
13922 assignment into the right register(s).
13923
13924 Normally, the selected stack frame has debug info. @value{GDBN} will always
13925 use the debug info instead of the implicit type of @var{expression} when the
13926 debug info is available. For example, if you type @kbd{return -1}, and the
13927 function in the current stack frame is declared to return a @code{long long
13928 int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
13929 into a @code{long long int}:
13930
13931 @smallexample
13932 Breakpoint 1, func () at gdb.base/return-nodebug.c:29
13933 29 return 31;
13934 (@value{GDBP}) return -1
13935 Make func return now? (y or n) y
13936 #0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
13937 43 printf ("result=%lld\n", func ());
13938 (@value{GDBP})
13939 @end smallexample
13940
13941 However, if the selected stack frame does not have a debug info, e.g., if the
13942 function was compiled without debug info, @value{GDBN} has to find out the type
13943 to return from user. Specifying a different type by mistake may set the value
13944 in different inferior registers than the caller code expects. For example,
13945 typing @kbd{return -1} with its implicit type @code{int} would set only a part
13946 of a @code{long long int} result for a debug info less function (on 32-bit
13947 architectures). Therefore the user is required to specify the return type by
13948 an appropriate cast explicitly:
13949
13950 @smallexample
13951 Breakpoint 2, 0x0040050b in func ()
13952 (@value{GDBP}) return -1
13953 Return value type not available for selected stack frame.
13954 Please use an explicit cast of the value to return.
13955 (@value{GDBP}) return (long long int) -1
13956 Make selected stack frame return now? (y or n) y
13957 #0 0x00400526 in main ()
13958 (@value{GDBP})
13959 @end smallexample
13960
13961 @node Calling
13962 @section Calling Program Functions
13963
13964 @table @code
13965 @cindex calling functions
13966 @cindex inferior functions, calling
13967 @item print @var{expr}
13968 Evaluate the expression @var{expr} and display the resulting value.
13969 @var{expr} may include calls to functions in the program being
13970 debugged.
13971
13972 @kindex call
13973 @item call @var{expr}
13974 Evaluate the expression @var{expr} without displaying @code{void}
13975 returned values.
13976
13977 You can use this variant of the @code{print} command if you want to
13978 execute a function from your program that does not return anything
13979 (a.k.a.@: @dfn{a void function}), but without cluttering the output
13980 with @code{void} returned values that @value{GDBN} will otherwise
13981 print. If the result is not void, it is printed and saved in the
13982 value history.
13983 @end table
13984
13985 It is possible for the function you call via the @code{print} or
13986 @code{call} command to generate a signal (e.g., if there's a bug in
13987 the function, or if you passed it incorrect arguments). What happens
13988 in that case is controlled by the @code{set unwindonsignal} command.
13989
13990 Similarly, with a C@t{++} program it is possible for the function you
13991 call via the @code{print} or @code{call} command to generate an
13992 exception that is not handled due to the constraints of the dummy
13993 frame. In this case, any exception that is raised in the frame, but has
13994 an out-of-frame exception handler will not be found. GDB builds a
13995 dummy-frame for the inferior function call, and the unwinder cannot
13996 seek for exception handlers outside of this dummy-frame. What happens
13997 in that case is controlled by the
13998 @code{set unwind-on-terminating-exception} command.
13999
14000 @table @code
14001 @item set unwindonsignal
14002 @kindex set unwindonsignal
14003 @cindex unwind stack in called functions
14004 @cindex call dummy stack unwinding
14005 Set unwinding of the stack if a signal is received while in a function
14006 that @value{GDBN} called in the program being debugged. If set to on,
14007 @value{GDBN} unwinds the stack it created for the call and restores
14008 the context to what it was before the call. If set to off (the
14009 default), @value{GDBN} stops in the frame where the signal was
14010 received.
14011
14012 @item show unwindonsignal
14013 @kindex show unwindonsignal
14014 Show the current setting of stack unwinding in the functions called by
14015 @value{GDBN}.
14016
14017 @item set unwind-on-terminating-exception
14018 @kindex set unwind-on-terminating-exception
14019 @cindex unwind stack in called functions with unhandled exceptions
14020 @cindex call dummy stack unwinding on unhandled exception.
14021 Set unwinding of the stack if a C@t{++} exception is raised, but left
14022 unhandled while in a function that @value{GDBN} called in the program being
14023 debugged. If set to on (the default), @value{GDBN} unwinds the stack
14024 it created for the call and restores the context to what it was before
14025 the call. If set to off, @value{GDBN} the exception is delivered to
14026 the default C@t{++} exception handler and the inferior terminated.
14027
14028 @item show unwind-on-terminating-exception
14029 @kindex show unwind-on-terminating-exception
14030 Show the current setting of stack unwinding in the functions called by
14031 @value{GDBN}.
14032
14033 @end table
14034
14035 @cindex weak alias functions
14036 Sometimes, a function you wish to call is actually a @dfn{weak alias}
14037 for another function. In such case, @value{GDBN} might not pick up
14038 the type information, including the types of the function arguments,
14039 which causes @value{GDBN} to call the inferior function incorrectly.
14040 As a result, the called function will function erroneously and may
14041 even crash. A solution to that is to use the name of the aliased
14042 function instead.
14043
14044 @node Patching
14045 @section Patching Programs
14046
14047 @cindex patching binaries
14048 @cindex writing into executables
14049 @cindex writing into corefiles
14050
14051 By default, @value{GDBN} opens the file containing your program's
14052 executable code (or the corefile) read-only. This prevents accidental
14053 alterations to machine code; but it also prevents you from intentionally
14054 patching your program's binary.
14055
14056 If you'd like to be able to patch the binary, you can specify that
14057 explicitly with the @code{set write} command. For example, you might
14058 want to turn on internal debugging flags, or even to make emergency
14059 repairs.
14060
14061 @table @code
14062 @kindex set write
14063 @item set write on
14064 @itemx set write off
14065 If you specify @samp{set write on}, @value{GDBN} opens executable and
14066 core files for both reading and writing; if you specify @kbd{set write
14067 off} (the default), @value{GDBN} opens them read-only.
14068
14069 If you have already loaded a file, you must load it again (using the
14070 @code{exec-file} or @code{core-file} command) after changing @code{set
14071 write}, for your new setting to take effect.
14072
14073 @item show write
14074 @kindex show write
14075 Display whether executable files and core files are opened for writing
14076 as well as reading.
14077 @end table
14078
14079 @node GDB Files
14080 @chapter @value{GDBN} Files
14081
14082 @value{GDBN} needs to know the file name of the program to be debugged,
14083 both in order to read its symbol table and in order to start your
14084 program. To debug a core dump of a previous run, you must also tell
14085 @value{GDBN} the name of the core dump file.
14086
14087 @menu
14088 * Files:: Commands to specify files
14089 * Separate Debug Files:: Debugging information in separate files
14090 * Symbol Errors:: Errors reading symbol files
14091 * Data Files:: GDB data files
14092 @end menu
14093
14094 @node Files
14095 @section Commands to Specify Files
14096
14097 @cindex symbol table
14098 @cindex core dump file
14099
14100 You may want to specify executable and core dump file names. The usual
14101 way to do this is at start-up time, using the arguments to
14102 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
14103 Out of @value{GDBN}}).
14104
14105 Occasionally it is necessary to change to a different file during a
14106 @value{GDBN} session. Or you may run @value{GDBN} and forget to
14107 specify a file you want to use. Or you are debugging a remote target
14108 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
14109 Program}). In these situations the @value{GDBN} commands to specify
14110 new files are useful.
14111
14112 @table @code
14113 @cindex executable file
14114 @kindex file
14115 @item file @var{filename}
14116 Use @var{filename} as the program to be debugged. It is read for its
14117 symbols and for the contents of pure memory. It is also the program
14118 executed when you use the @code{run} command. If you do not specify a
14119 directory and the file is not found in the @value{GDBN} working directory,
14120 @value{GDBN} uses the environment variable @code{PATH} as a list of
14121 directories to search, just as the shell does when looking for a program
14122 to run. You can change the value of this variable, for both @value{GDBN}
14123 and your program, using the @code{path} command.
14124
14125 @cindex unlinked object files
14126 @cindex patching object files
14127 You can load unlinked object @file{.o} files into @value{GDBN} using
14128 the @code{file} command. You will not be able to ``run'' an object
14129 file, but you can disassemble functions and inspect variables. Also,
14130 if the underlying BFD functionality supports it, you could use
14131 @kbd{gdb -write} to patch object files using this technique. Note
14132 that @value{GDBN} can neither interpret nor modify relocations in this
14133 case, so branches and some initialized variables will appear to go to
14134 the wrong place. But this feature is still handy from time to time.
14135
14136 @item file
14137 @code{file} with no argument makes @value{GDBN} discard any information it
14138 has on both executable file and the symbol table.
14139
14140 @kindex exec-file
14141 @item exec-file @r{[} @var{filename} @r{]}
14142 Specify that the program to be run (but not the symbol table) is found
14143 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
14144 if necessary to locate your program. Omitting @var{filename} means to
14145 discard information on the executable file.
14146
14147 @kindex symbol-file
14148 @item symbol-file @r{[} @var{filename} @r{]}
14149 Read symbol table information from file @var{filename}. @code{PATH} is
14150 searched when necessary. Use the @code{file} command to get both symbol
14151 table and program to run from the same file.
14152
14153 @code{symbol-file} with no argument clears out @value{GDBN} information on your
14154 program's symbol table.
14155
14156 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
14157 some breakpoints and auto-display expressions. This is because they may
14158 contain pointers to the internal data recording symbols and data types,
14159 which are part of the old symbol table data being discarded inside
14160 @value{GDBN}.
14161
14162 @code{symbol-file} does not repeat if you press @key{RET} again after
14163 executing it once.
14164
14165 When @value{GDBN} is configured for a particular environment, it
14166 understands debugging information in whatever format is the standard
14167 generated for that environment; you may use either a @sc{gnu} compiler, or
14168 other compilers that adhere to the local conventions.
14169 Best results are usually obtained from @sc{gnu} compilers; for example,
14170 using @code{@value{NGCC}} you can generate debugging information for
14171 optimized code.
14172
14173 For most kinds of object files, with the exception of old SVR3 systems
14174 using COFF, the @code{symbol-file} command does not normally read the
14175 symbol table in full right away. Instead, it scans the symbol table
14176 quickly to find which source files and which symbols are present. The
14177 details are read later, one source file at a time, as they are needed.
14178
14179 The purpose of this two-stage reading strategy is to make @value{GDBN}
14180 start up faster. For the most part, it is invisible except for
14181 occasional pauses while the symbol table details for a particular source
14182 file are being read. (The @code{set verbose} command can turn these
14183 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
14184 Warnings and Messages}.)
14185
14186 We have not implemented the two-stage strategy for COFF yet. When the
14187 symbol table is stored in COFF format, @code{symbol-file} reads the
14188 symbol table data in full right away. Note that ``stabs-in-COFF''
14189 still does the two-stage strategy, since the debug info is actually
14190 in stabs format.
14191
14192 @kindex readnow
14193 @cindex reading symbols immediately
14194 @cindex symbols, reading immediately
14195 @item symbol-file @r{[} -readnow @r{]} @var{filename}
14196 @itemx file @r{[} -readnow @r{]} @var{filename}
14197 You can override the @value{GDBN} two-stage strategy for reading symbol
14198 tables by using the @samp{-readnow} option with any of the commands that
14199 load symbol table information, if you want to be sure @value{GDBN} has the
14200 entire symbol table available.
14201
14202 @c FIXME: for now no mention of directories, since this seems to be in
14203 @c flux. 13mar1992 status is that in theory GDB would look either in
14204 @c current dir or in same dir as myprog; but issues like competing
14205 @c GDB's, or clutter in system dirs, mean that in practice right now
14206 @c only current dir is used. FFish says maybe a special GDB hierarchy
14207 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
14208 @c files.
14209
14210 @kindex core-file
14211 @item core-file @r{[}@var{filename}@r{]}
14212 @itemx core
14213 Specify the whereabouts of a core dump file to be used as the ``contents
14214 of memory''. Traditionally, core files contain only some parts of the
14215 address space of the process that generated them; @value{GDBN} can access the
14216 executable file itself for other parts.
14217
14218 @code{core-file} with no argument specifies that no core file is
14219 to be used.
14220
14221 Note that the core file is ignored when your program is actually running
14222 under @value{GDBN}. So, if you have been running your program and you
14223 wish to debug a core file instead, you must kill the subprocess in which
14224 the program is running. To do this, use the @code{kill} command
14225 (@pxref{Kill Process, ,Killing the Child Process}).
14226
14227 @kindex add-symbol-file
14228 @cindex dynamic linking
14229 @item add-symbol-file @var{filename} @var{address}
14230 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
14231 @itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
14232 The @code{add-symbol-file} command reads additional symbol table
14233 information from the file @var{filename}. You would use this command
14234 when @var{filename} has been dynamically loaded (by some other means)
14235 into the program that is running. @var{address} should be the memory
14236 address at which the file has been loaded; @value{GDBN} cannot figure
14237 this out for itself. You can additionally specify an arbitrary number
14238 of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
14239 section name and base address for that section. You can specify any
14240 @var{address} as an expression.
14241
14242 The symbol table of the file @var{filename} is added to the symbol table
14243 originally read with the @code{symbol-file} command. You can use the
14244 @code{add-symbol-file} command any number of times; the new symbol data
14245 thus read keeps adding to the old. To discard all old symbol data
14246 instead, use the @code{symbol-file} command without any arguments.
14247
14248 @cindex relocatable object files, reading symbols from
14249 @cindex object files, relocatable, reading symbols from
14250 @cindex reading symbols from relocatable object files
14251 @cindex symbols, reading from relocatable object files
14252 @cindex @file{.o} files, reading symbols from
14253 Although @var{filename} is typically a shared library file, an
14254 executable file, or some other object file which has been fully
14255 relocated for loading into a process, you can also load symbolic
14256 information from relocatable @file{.o} files, as long as:
14257
14258 @itemize @bullet
14259 @item
14260 the file's symbolic information refers only to linker symbols defined in
14261 that file, not to symbols defined by other object files,
14262 @item
14263 every section the file's symbolic information refers to has actually
14264 been loaded into the inferior, as it appears in the file, and
14265 @item
14266 you can determine the address at which every section was loaded, and
14267 provide these to the @code{add-symbol-file} command.
14268 @end itemize
14269
14270 @noindent
14271 Some embedded operating systems, like Sun Chorus and VxWorks, can load
14272 relocatable files into an already running program; such systems
14273 typically make the requirements above easy to meet. However, it's
14274 important to recognize that many native systems use complex link
14275 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
14276 assembly, for example) that make the requirements difficult to meet. In
14277 general, one cannot assume that using @code{add-symbol-file} to read a
14278 relocatable object file's symbolic information will have the same effect
14279 as linking the relocatable object file into the program in the normal
14280 way.
14281
14282 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
14283
14284 @kindex add-symbol-file-from-memory
14285 @cindex @code{syscall DSO}
14286 @cindex load symbols from memory
14287 @item add-symbol-file-from-memory @var{address}
14288 Load symbols from the given @var{address} in a dynamically loaded
14289 object file whose image is mapped directly into the inferior's memory.
14290 For example, the Linux kernel maps a @code{syscall DSO} into each
14291 process's address space; this DSO provides kernel-specific code for
14292 some system calls. The argument can be any expression whose
14293 evaluation yields the address of the file's shared object file header.
14294 For this command to work, you must have used @code{symbol-file} or
14295 @code{exec-file} commands in advance.
14296
14297 @kindex add-shared-symbol-files
14298 @kindex assf
14299 @item add-shared-symbol-files @var{library-file}
14300 @itemx assf @var{library-file}
14301 The @code{add-shared-symbol-files} command can currently be used only
14302 in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
14303 alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
14304 @value{GDBN} automatically looks for shared libraries, however if
14305 @value{GDBN} does not find yours, you can invoke
14306 @code{add-shared-symbol-files}. It takes one argument: the shared
14307 library's file name. @code{assf} is a shorthand alias for
14308 @code{add-shared-symbol-files}.
14309
14310 @kindex section
14311 @item section @var{section} @var{addr}
14312 The @code{section} command changes the base address of the named
14313 @var{section} of the exec file to @var{addr}. This can be used if the
14314 exec file does not contain section addresses, (such as in the
14315 @code{a.out} format), or when the addresses specified in the file
14316 itself are wrong. Each section must be changed separately. The
14317 @code{info files} command, described below, lists all the sections and
14318 their addresses.
14319
14320 @kindex info files
14321 @kindex info target
14322 @item info files
14323 @itemx info target
14324 @code{info files} and @code{info target} are synonymous; both print the
14325 current target (@pxref{Targets, ,Specifying a Debugging Target}),
14326 including the names of the executable and core dump files currently in
14327 use by @value{GDBN}, and the files from which symbols were loaded. The
14328 command @code{help target} lists all possible targets rather than
14329 current ones.
14330
14331 @kindex maint info sections
14332 @item maint info sections
14333 Another command that can give you extra information about program sections
14334 is @code{maint info sections}. In addition to the section information
14335 displayed by @code{info files}, this command displays the flags and file
14336 offset of each section in the executable and core dump files. In addition,
14337 @code{maint info sections} provides the following command options (which
14338 may be arbitrarily combined):
14339
14340 @table @code
14341 @item ALLOBJ
14342 Display sections for all loaded object files, including shared libraries.
14343 @item @var{sections}
14344 Display info only for named @var{sections}.
14345 @item @var{section-flags}
14346 Display info only for sections for which @var{section-flags} are true.
14347 The section flags that @value{GDBN} currently knows about are:
14348 @table @code
14349 @item ALLOC
14350 Section will have space allocated in the process when loaded.
14351 Set for all sections except those containing debug information.
14352 @item LOAD
14353 Section will be loaded from the file into the child process memory.
14354 Set for pre-initialized code and data, clear for @code{.bss} sections.
14355 @item RELOC
14356 Section needs to be relocated before loading.
14357 @item READONLY
14358 Section cannot be modified by the child process.
14359 @item CODE
14360 Section contains executable code only.
14361 @item DATA
14362 Section contains data only (no executable code).
14363 @item ROM
14364 Section will reside in ROM.
14365 @item CONSTRUCTOR
14366 Section contains data for constructor/destructor lists.
14367 @item HAS_CONTENTS
14368 Section is not empty.
14369 @item NEVER_LOAD
14370 An instruction to the linker to not output the section.
14371 @item COFF_SHARED_LIBRARY
14372 A notification to the linker that the section contains
14373 COFF shared library information.
14374 @item IS_COMMON
14375 Section contains common symbols.
14376 @end table
14377 @end table
14378 @kindex set trust-readonly-sections
14379 @cindex read-only sections
14380 @item set trust-readonly-sections on
14381 Tell @value{GDBN} that readonly sections in your object file
14382 really are read-only (i.e.@: that their contents will not change).
14383 In that case, @value{GDBN} can fetch values from these sections
14384 out of the object file, rather than from the target program.
14385 For some targets (notably embedded ones), this can be a significant
14386 enhancement to debugging performance.
14387
14388 The default is off.
14389
14390 @item set trust-readonly-sections off
14391 Tell @value{GDBN} not to trust readonly sections. This means that
14392 the contents of the section might change while the program is running,
14393 and must therefore be fetched from the target when needed.
14394
14395 @item show trust-readonly-sections
14396 Show the current setting of trusting readonly sections.
14397 @end table
14398
14399 All file-specifying commands allow both absolute and relative file names
14400 as arguments. @value{GDBN} always converts the file name to an absolute file
14401 name and remembers it that way.
14402
14403 @cindex shared libraries
14404 @anchor{Shared Libraries}
14405 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
14406 and IBM RS/6000 AIX shared libraries.
14407
14408 On MS-Windows @value{GDBN} must be linked with the Expat library to support
14409 shared libraries. @xref{Expat}.
14410
14411 @value{GDBN} automatically loads symbol definitions from shared libraries
14412 when you use the @code{run} command, or when you examine a core file.
14413 (Before you issue the @code{run} command, @value{GDBN} does not understand
14414 references to a function in a shared library, however---unless you are
14415 debugging a core file).
14416
14417 On HP-UX, if the program loads a library explicitly, @value{GDBN}
14418 automatically loads the symbols at the time of the @code{shl_load} call.
14419
14420 @c FIXME: some @value{GDBN} release may permit some refs to undef
14421 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
14422 @c FIXME...lib; check this from time to time when updating manual
14423
14424 There are times, however, when you may wish to not automatically load
14425 symbol definitions from shared libraries, such as when they are
14426 particularly large or there are many of them.
14427
14428 To control the automatic loading of shared library symbols, use the
14429 commands:
14430
14431 @table @code
14432 @kindex set auto-solib-add
14433 @item set auto-solib-add @var{mode}
14434 If @var{mode} is @code{on}, symbols from all shared object libraries
14435 will be loaded automatically when the inferior begins execution, you
14436 attach to an independently started inferior, or when the dynamic linker
14437 informs @value{GDBN} that a new library has been loaded. If @var{mode}
14438 is @code{off}, symbols must be loaded manually, using the
14439 @code{sharedlibrary} command. The default value is @code{on}.
14440
14441 @cindex memory used for symbol tables
14442 If your program uses lots of shared libraries with debug info that
14443 takes large amounts of memory, you can decrease the @value{GDBN}
14444 memory footprint by preventing it from automatically loading the
14445 symbols from shared libraries. To that end, type @kbd{set
14446 auto-solib-add off} before running the inferior, then load each
14447 library whose debug symbols you do need with @kbd{sharedlibrary
14448 @var{regexp}}, where @var{regexp} is a regular expression that matches
14449 the libraries whose symbols you want to be loaded.
14450
14451 @kindex show auto-solib-add
14452 @item show auto-solib-add
14453 Display the current autoloading mode.
14454 @end table
14455
14456 @cindex load shared library
14457 To explicitly load shared library symbols, use the @code{sharedlibrary}
14458 command:
14459
14460 @table @code
14461 @kindex info sharedlibrary
14462 @kindex info share
14463 @item info share @var{regex}
14464 @itemx info sharedlibrary @var{regex}
14465 Print the names of the shared libraries which are currently loaded
14466 that match @var{regex}. If @var{regex} is omitted then print
14467 all shared libraries that are loaded.
14468
14469 @kindex sharedlibrary
14470 @kindex share
14471 @item sharedlibrary @var{regex}
14472 @itemx share @var{regex}
14473 Load shared object library symbols for files matching a
14474 Unix regular expression.
14475 As with files loaded automatically, it only loads shared libraries
14476 required by your program for a core file or after typing @code{run}. If
14477 @var{regex} is omitted all shared libraries required by your program are
14478 loaded.
14479
14480 @item nosharedlibrary
14481 @kindex nosharedlibrary
14482 @cindex unload symbols from shared libraries
14483 Unload all shared object library symbols. This discards all symbols
14484 that have been loaded from all shared libraries. Symbols from shared
14485 libraries that were loaded by explicit user requests are not
14486 discarded.
14487 @end table
14488
14489 Sometimes you may wish that @value{GDBN} stops and gives you control
14490 when any of shared library events happen. Use the @code{set
14491 stop-on-solib-events} command for this:
14492
14493 @table @code
14494 @item set stop-on-solib-events
14495 @kindex set stop-on-solib-events
14496 This command controls whether @value{GDBN} should give you control
14497 when the dynamic linker notifies it about some shared library event.
14498 The most common event of interest is loading or unloading of a new
14499 shared library.
14500
14501 @item show stop-on-solib-events
14502 @kindex show stop-on-solib-events
14503 Show whether @value{GDBN} stops and gives you control when shared
14504 library events happen.
14505 @end table
14506
14507 Shared libraries are also supported in many cross or remote debugging
14508 configurations. @value{GDBN} needs to have access to the target's libraries;
14509 this can be accomplished either by providing copies of the libraries
14510 on the host system, or by asking @value{GDBN} to automatically retrieve the
14511 libraries from the target. If copies of the target libraries are
14512 provided, they need to be the same as the target libraries, although the
14513 copies on the target can be stripped as long as the copies on the host are
14514 not.
14515
14516 @cindex where to look for shared libraries
14517 For remote debugging, you need to tell @value{GDBN} where the target
14518 libraries are, so that it can load the correct copies---otherwise, it
14519 may try to load the host's libraries. @value{GDBN} has two variables
14520 to specify the search directories for target libraries.
14521
14522 @table @code
14523 @cindex prefix for shared library file names
14524 @cindex system root, alternate
14525 @kindex set solib-absolute-prefix
14526 @kindex set sysroot
14527 @item set sysroot @var{path}
14528 Use @var{path} as the system root for the program being debugged. Any
14529 absolute shared library paths will be prefixed with @var{path}; many
14530 runtime loaders store the absolute paths to the shared library in the
14531 target program's memory. If you use @code{set sysroot} to find shared
14532 libraries, they need to be laid out in the same way that they are on
14533 the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
14534 under @var{path}.
14535
14536 If @var{path} starts with the sequence @file{remote:}, @value{GDBN} will
14537 retrieve the target libraries from the remote system. This is only
14538 supported when using a remote target that supports the @code{remote get}
14539 command (@pxref{File Transfer,,Sending files to a remote system}).
14540 The part of @var{path} following the initial @file{remote:}
14541 (if present) is used as system root prefix on the remote file system.
14542 @footnote{If you want to specify a local system root using a directory
14543 that happens to be named @file{remote:}, you need to use some equivalent
14544 variant of the name like @file{./remote:}.}
14545
14546 For targets with an MS-DOS based filesystem, such as MS-Windows and
14547 SymbianOS, @value{GDBN} tries prefixing a few variants of the target
14548 absolute file name with @var{path}. But first, on Unix hosts,
14549 @value{GDBN} converts all backslash directory separators into forward
14550 slashes, because the backslash is not a directory separator on Unix:
14551
14552 @smallexample
14553 c:\foo\bar.dll @result{} c:/foo/bar.dll
14554 @end smallexample
14555
14556 Then, @value{GDBN} attempts prefixing the target file name with
14557 @var{path}, and looks for the resulting file name in the host file
14558 system:
14559
14560 @smallexample
14561 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
14562 @end smallexample
14563
14564 If that does not find the shared library, @value{GDBN} tries removing
14565 the @samp{:} character from the drive spec, both for convenience, and,
14566 for the case of the host file system not supporting file names with
14567 colons:
14568
14569 @smallexample
14570 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
14571 @end smallexample
14572
14573 This makes it possible to have a system root that mirrors a target
14574 with more than one drive. E.g., you may want to setup your local
14575 copies of the target system shared libraries like so (note @samp{c} vs
14576 @samp{z}):
14577
14578 @smallexample
14579 @file{/path/to/sysroot/c/sys/bin/foo.dll}
14580 @file{/path/to/sysroot/c/sys/bin/bar.dll}
14581 @file{/path/to/sysroot/z/sys/bin/bar.dll}
14582 @end smallexample
14583
14584 @noindent
14585 and point the system root at @file{/path/to/sysroot}, so that
14586 @value{GDBN} can find the correct copies of both
14587 @file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
14588
14589 If that still does not find the shared library, @value{GDBN} tries
14590 removing the whole drive spec from the target file name:
14591
14592 @smallexample
14593 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
14594 @end smallexample
14595
14596 This last lookup makes it possible to not care about the drive name,
14597 if you don't want or need to.
14598
14599 The @code{set solib-absolute-prefix} command is an alias for @code{set
14600 sysroot}.
14601
14602 @cindex default system root
14603 @cindex @samp{--with-sysroot}
14604 You can set the default system root by using the configure-time
14605 @samp{--with-sysroot} option. If the system root is inside
14606 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
14607 @samp{--exec-prefix}), then the default system root will be updated
14608 automatically if the installed @value{GDBN} is moved to a new
14609 location.
14610
14611 @kindex show sysroot
14612 @item show sysroot
14613 Display the current shared library prefix.
14614
14615 @kindex set solib-search-path
14616 @item set solib-search-path @var{path}
14617 If this variable is set, @var{path} is a colon-separated list of
14618 directories to search for shared libraries. @samp{solib-search-path}
14619 is used after @samp{sysroot} fails to locate the library, or if the
14620 path to the library is relative instead of absolute. If you want to
14621 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
14622 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
14623 finding your host's libraries. @samp{sysroot} is preferred; setting
14624 it to a nonexistent directory may interfere with automatic loading
14625 of shared library symbols.
14626
14627 @kindex show solib-search-path
14628 @item show solib-search-path
14629 Display the current shared library search path.
14630
14631 @cindex DOS file-name semantics of file names.
14632 @kindex set target-file-system-kind (unix|dos-based|auto)
14633 @kindex show target-file-system-kind
14634 @item set target-file-system-kind @var{kind}
14635 Set assumed file system kind for target reported file names.
14636
14637 Shared library file names as reported by the target system may not
14638 make sense as is on the system @value{GDBN} is running on. For
14639 example, when remote debugging a target that has MS-DOS based file
14640 system semantics, from a Unix host, the target may be reporting to
14641 @value{GDBN} a list of loaded shared libraries with file names such as
14642 @file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
14643 drive letters, so the @samp{c:\} prefix is not normally understood as
14644 indicating an absolute file name, and neither is the backslash
14645 normally considered a directory separator character. In that case,
14646 the native file system would interpret this whole absolute file name
14647 as a relative file name with no directory components. This would make
14648 it impossible to point @value{GDBN} at a copy of the remote target's
14649 shared libraries on the host using @code{set sysroot}, and impractical
14650 with @code{set solib-search-path}. Setting
14651 @code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
14652 to interpret such file names similarly to how the target would, and to
14653 map them to file names valid on @value{GDBN}'s native file system
14654 semantics. The value of @var{kind} can be @code{"auto"}, in addition
14655 to one of the supported file system kinds. In that case, @value{GDBN}
14656 tries to determine the appropriate file system variant based on the
14657 current target's operating system (@pxref{ABI, ,Configuring the
14658 Current ABI}). The supported file system settings are:
14659
14660 @table @code
14661 @item unix
14662 Instruct @value{GDBN} to assume the target file system is of Unix
14663 kind. Only file names starting the forward slash (@samp{/}) character
14664 are considered absolute, and the directory separator character is also
14665 the forward slash.
14666
14667 @item dos-based
14668 Instruct @value{GDBN} to assume the target file system is DOS based.
14669 File names starting with either a forward slash, or a drive letter
14670 followed by a colon (e.g., @samp{c:}), are considered absolute, and
14671 both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
14672 considered directory separators.
14673
14674 @item auto
14675 Instruct @value{GDBN} to use the file system kind associated with the
14676 target operating system (@pxref{ABI, ,Configuring the Current ABI}).
14677 This is the default.
14678 @end table
14679 @end table
14680
14681
14682 @node Separate Debug Files
14683 @section Debugging Information in Separate Files
14684 @cindex separate debugging information files
14685 @cindex debugging information in separate files
14686 @cindex @file{.debug} subdirectories
14687 @cindex debugging information directory, global
14688 @cindex global debugging information directory
14689 @cindex build ID, and separate debugging files
14690 @cindex @file{.build-id} directory
14691
14692 @value{GDBN} allows you to put a program's debugging information in a
14693 file separate from the executable itself, in a way that allows
14694 @value{GDBN} to find and load the debugging information automatically.
14695 Since debugging information can be very large---sometimes larger
14696 than the executable code itself---some systems distribute debugging
14697 information for their executables in separate files, which users can
14698 install only when they need to debug a problem.
14699
14700 @value{GDBN} supports two ways of specifying the separate debug info
14701 file:
14702
14703 @itemize @bullet
14704 @item
14705 The executable contains a @dfn{debug link} that specifies the name of
14706 the separate debug info file. The separate debug file's name is
14707 usually @file{@var{executable}.debug}, where @var{executable} is the
14708 name of the corresponding executable file without leading directories
14709 (e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
14710 debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
14711 checksum for the debug file, which @value{GDBN} uses to validate that
14712 the executable and the debug file came from the same build.
14713
14714 @item
14715 The executable contains a @dfn{build ID}, a unique bit string that is
14716 also present in the corresponding debug info file. (This is supported
14717 only on some operating systems, notably those which use the ELF format
14718 for binary files and the @sc{gnu} Binutils.) For more details about
14719 this feature, see the description of the @option{--build-id}
14720 command-line option in @ref{Options, , Command Line Options, ld.info,
14721 The GNU Linker}. The debug info file's name is not specified
14722 explicitly by the build ID, but can be computed from the build ID, see
14723 below.
14724 @end itemize
14725
14726 Depending on the way the debug info file is specified, @value{GDBN}
14727 uses two different methods of looking for the debug file:
14728
14729 @itemize @bullet
14730 @item
14731 For the ``debug link'' method, @value{GDBN} looks up the named file in
14732 the directory of the executable file, then in a subdirectory of that
14733 directory named @file{.debug}, and finally under the global debug
14734 directory, in a subdirectory whose name is identical to the leading
14735 directories of the executable's absolute file name.
14736
14737 @item
14738 For the ``build ID'' method, @value{GDBN} looks in the
14739 @file{.build-id} subdirectory of the global debug directory for a file
14740 named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
14741 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
14742 are the rest of the bit string. (Real build ID strings are 32 or more
14743 hex characters, not 10.)
14744 @end itemize
14745
14746 So, for example, suppose you ask @value{GDBN} to debug
14747 @file{/usr/bin/ls}, which has a debug link that specifies the
14748 file @file{ls.debug}, and a build ID whose value in hex is
14749 @code{abcdef1234}. If the global debug directory is
14750 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
14751 debug information files, in the indicated order:
14752
14753 @itemize @minus
14754 @item
14755 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
14756 @item
14757 @file{/usr/bin/ls.debug}
14758 @item
14759 @file{/usr/bin/.debug/ls.debug}
14760 @item
14761 @file{/usr/lib/debug/usr/bin/ls.debug}.
14762 @end itemize
14763
14764 You can set the global debugging info directory's name, and view the
14765 name @value{GDBN} is currently using.
14766
14767 @table @code
14768
14769 @kindex set debug-file-directory
14770 @item set debug-file-directory @var{directories}
14771 Set the directories which @value{GDBN} searches for separate debugging
14772 information files to @var{directory}. Multiple directory components can be set
14773 concatenating them by a directory separator.
14774
14775 @kindex show debug-file-directory
14776 @item show debug-file-directory
14777 Show the directories @value{GDBN} searches for separate debugging
14778 information files.
14779
14780 @end table
14781
14782 @cindex @code{.gnu_debuglink} sections
14783 @cindex debug link sections
14784 A debug link is a special section of the executable file named
14785 @code{.gnu_debuglink}. The section must contain:
14786
14787 @itemize
14788 @item
14789 A filename, with any leading directory components removed, followed by
14790 a zero byte,
14791 @item
14792 zero to three bytes of padding, as needed to reach the next four-byte
14793 boundary within the section, and
14794 @item
14795 a four-byte CRC checksum, stored in the same endianness used for the
14796 executable file itself. The checksum is computed on the debugging
14797 information file's full contents by the function given below, passing
14798 zero as the @var{crc} argument.
14799 @end itemize
14800
14801 Any executable file format can carry a debug link, as long as it can
14802 contain a section named @code{.gnu_debuglink} with the contents
14803 described above.
14804
14805 @cindex @code{.note.gnu.build-id} sections
14806 @cindex build ID sections
14807 The build ID is a special section in the executable file (and in other
14808 ELF binary files that @value{GDBN} may consider). This section is
14809 often named @code{.note.gnu.build-id}, but that name is not mandatory.
14810 It contains unique identification for the built files---the ID remains
14811 the same across multiple builds of the same build tree. The default
14812 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
14813 content for the build ID string. The same section with an identical
14814 value is present in the original built binary with symbols, in its
14815 stripped variant, and in the separate debugging information file.
14816
14817 The debugging information file itself should be an ordinary
14818 executable, containing a full set of linker symbols, sections, and
14819 debugging information. The sections of the debugging information file
14820 should have the same names, addresses, and sizes as the original file,
14821 but they need not contain any data---much like a @code{.bss} section
14822 in an ordinary executable.
14823
14824 The @sc{gnu} binary utilities (Binutils) package includes the
14825 @samp{objcopy} utility that can produce
14826 the separated executable / debugging information file pairs using the
14827 following commands:
14828
14829 @smallexample
14830 @kbd{objcopy --only-keep-debug foo foo.debug}
14831 @kbd{strip -g foo}
14832 @end smallexample
14833
14834 @noindent
14835 These commands remove the debugging
14836 information from the executable file @file{foo} and place it in the file
14837 @file{foo.debug}. You can use the first, second or both methods to link the
14838 two files:
14839
14840 @itemize @bullet
14841 @item
14842 The debug link method needs the following additional command to also leave
14843 behind a debug link in @file{foo}:
14844
14845 @smallexample
14846 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
14847 @end smallexample
14848
14849 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
14850 a version of the @code{strip} command such that the command @kbd{strip foo -f
14851 foo.debug} has the same functionality as the two @code{objcopy} commands and
14852 the @code{ln -s} command above, together.
14853
14854 @item
14855 Build ID gets embedded into the main executable using @code{ld --build-id} or
14856 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
14857 compatibility fixes for debug files separation are present in @sc{gnu} binary
14858 utilities (Binutils) package since version 2.18.
14859 @end itemize
14860
14861 @noindent
14862
14863 @cindex CRC algorithm definition
14864 The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
14865 IEEE 802.3 using the polynomial:
14866
14867 @c TexInfo requires naked braces for multi-digit exponents for Tex
14868 @c output, but this causes HTML output to barf. HTML has to be set using
14869 @c raw commands. So we end up having to specify this equation in 2
14870 @c different ways!
14871 @ifhtml
14872 @display
14873 @html
14874 <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>
14875 + <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
14876 @end html
14877 @end display
14878 @end ifhtml
14879 @ifnothtml
14880 @display
14881 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
14882 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
14883 @end display
14884 @end ifnothtml
14885
14886 The function is computed byte at a time, taking the least
14887 significant bit of each byte first. The initial pattern
14888 @code{0xffffffff} is used, to ensure leading zeros affect the CRC and
14889 the final result is inverted to ensure trailing zeros also affect the
14890 CRC.
14891
14892 @emph{Note:} This is the same CRC polynomial as used in handling the
14893 @dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{Remote Protocol,
14894 , @value{GDBN} Remote Serial Protocol}). However in the
14895 case of the Remote Serial Protocol, the CRC is computed @emph{most}
14896 significant bit first, and the result is not inverted, so trailing
14897 zeros have no effect on the CRC value.
14898
14899 To complete the description, we show below the code of the function
14900 which produces the CRC used in @code{.gnu_debuglink}. Inverting the
14901 initially supplied @code{crc} argument means that an initial call to
14902 this function passing in zero will start computing the CRC using
14903 @code{0xffffffff}.
14904
14905 @kindex gnu_debuglink_crc32
14906 @smallexample
14907 unsigned long
14908 gnu_debuglink_crc32 (unsigned long crc,
14909 unsigned char *buf, size_t len)
14910 @{
14911 static const unsigned long crc32_table[256] =
14912 @{
14913 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
14914 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
14915 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
14916 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
14917 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
14918 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
14919 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
14920 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
14921 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
14922 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
14923 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
14924 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
14925 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
14926 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
14927 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
14928 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
14929 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
14930 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
14931 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
14932 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
14933 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
14934 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
14935 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
14936 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
14937 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
14938 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
14939 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
14940 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
14941 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
14942 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
14943 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
14944 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
14945 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
14946 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
14947 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
14948 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
14949 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
14950 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
14951 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
14952 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
14953 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
14954 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
14955 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
14956 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
14957 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
14958 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
14959 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
14960 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
14961 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
14962 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
14963 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
14964 0x2d02ef8d
14965 @};
14966 unsigned char *end;
14967
14968 crc = ~crc & 0xffffffff;
14969 for (end = buf + len; buf < end; ++buf)
14970 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
14971 return ~crc & 0xffffffff;
14972 @}
14973 @end smallexample
14974
14975 @noindent
14976 This computation does not apply to the ``build ID'' method.
14977
14978
14979 @node Symbol Errors
14980 @section Errors Reading Symbol Files
14981
14982 While reading a symbol file, @value{GDBN} occasionally encounters problems,
14983 such as symbol types it does not recognize, or known bugs in compiler
14984 output. By default, @value{GDBN} does not notify you of such problems, since
14985 they are relatively common and primarily of interest to people
14986 debugging compilers. If you are interested in seeing information
14987 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
14988 only one message about each such type of problem, no matter how many
14989 times the problem occurs; or you can ask @value{GDBN} to print more messages,
14990 to see how many times the problems occur, with the @code{set
14991 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
14992 Messages}).
14993
14994 The messages currently printed, and their meanings, include:
14995
14996 @table @code
14997 @item inner block not inside outer block in @var{symbol}
14998
14999 The symbol information shows where symbol scopes begin and end
15000 (such as at the start of a function or a block of statements). This
15001 error indicates that an inner scope block is not fully contained
15002 in its outer scope blocks.
15003
15004 @value{GDBN} circumvents the problem by treating the inner block as if it had
15005 the same scope as the outer block. In the error message, @var{symbol}
15006 may be shown as ``@code{(don't know)}'' if the outer block is not a
15007 function.
15008
15009 @item block at @var{address} out of order
15010
15011 The symbol information for symbol scope blocks should occur in
15012 order of increasing addresses. This error indicates that it does not
15013 do so.
15014
15015 @value{GDBN} does not circumvent this problem, and has trouble
15016 locating symbols in the source file whose symbols it is reading. (You
15017 can often determine what source file is affected by specifying
15018 @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
15019 Messages}.)
15020
15021 @item bad block start address patched
15022
15023 The symbol information for a symbol scope block has a start address
15024 smaller than the address of the preceding source line. This is known
15025 to occur in the SunOS 4.1.1 (and earlier) C compiler.
15026
15027 @value{GDBN} circumvents the problem by treating the symbol scope block as
15028 starting on the previous source line.
15029
15030 @item bad string table offset in symbol @var{n}
15031
15032 @cindex foo
15033 Symbol number @var{n} contains a pointer into the string table which is
15034 larger than the size of the string table.
15035
15036 @value{GDBN} circumvents the problem by considering the symbol to have the
15037 name @code{foo}, which may cause other problems if many symbols end up
15038 with this name.
15039
15040 @item unknown symbol type @code{0x@var{nn}}
15041
15042 The symbol information contains new data types that @value{GDBN} does
15043 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
15044 uncomprehended information, in hexadecimal.
15045
15046 @value{GDBN} circumvents the error by ignoring this symbol information.
15047 This usually allows you to debug your program, though certain symbols
15048 are not accessible. If you encounter such a problem and feel like
15049 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
15050 on @code{complain}, then go up to the function @code{read_dbx_symtab}
15051 and examine @code{*bufp} to see the symbol.
15052
15053 @item stub type has NULL name
15054
15055 @value{GDBN} could not find the full definition for a struct or class.
15056
15057 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
15058 The symbol information for a C@t{++} member function is missing some
15059 information that recent versions of the compiler should have output for
15060 it.
15061
15062 @item info mismatch between compiler and debugger
15063
15064 @value{GDBN} could not parse a type specification output by the compiler.
15065
15066 @end table
15067
15068 @node Data Files
15069 @section GDB Data Files
15070
15071 @cindex prefix for data files
15072 @value{GDBN} will sometimes read an auxiliary data file. These files
15073 are kept in a directory known as the @dfn{data directory}.
15074
15075 You can set the data directory's name, and view the name @value{GDBN}
15076 is currently using.
15077
15078 @table @code
15079 @kindex set data-directory
15080 @item set data-directory @var{directory}
15081 Set the directory which @value{GDBN} searches for auxiliary data files
15082 to @var{directory}.
15083
15084 @kindex show data-directory
15085 @item show data-directory
15086 Show the directory @value{GDBN} searches for auxiliary data files.
15087 @end table
15088
15089 @cindex default data directory
15090 @cindex @samp{--with-gdb-datadir}
15091 You can set the default data directory by using the configure-time
15092 @samp{--with-gdb-datadir} option. If the data directory is inside
15093 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
15094 @samp{--exec-prefix}), then the default data directory will be updated
15095 automatically if the installed @value{GDBN} is moved to a new
15096 location.
15097
15098 @node Targets
15099 @chapter Specifying a Debugging Target
15100
15101 @cindex debugging target
15102 A @dfn{target} is the execution environment occupied by your program.
15103
15104 Often, @value{GDBN} runs in the same host environment as your program;
15105 in that case, the debugging target is specified as a side effect when
15106 you use the @code{file} or @code{core} commands. When you need more
15107 flexibility---for example, running @value{GDBN} on a physically separate
15108 host, or controlling a standalone system over a serial port or a
15109 realtime system over a TCP/IP connection---you can use the @code{target}
15110 command to specify one of the target types configured for @value{GDBN}
15111 (@pxref{Target Commands, ,Commands for Managing Targets}).
15112
15113 @cindex target architecture
15114 It is possible to build @value{GDBN} for several different @dfn{target
15115 architectures}. When @value{GDBN} is built like that, you can choose
15116 one of the available architectures with the @kbd{set architecture}
15117 command.
15118
15119 @table @code
15120 @kindex set architecture
15121 @kindex show architecture
15122 @item set architecture @var{arch}
15123 This command sets the current target architecture to @var{arch}. The
15124 value of @var{arch} can be @code{"auto"}, in addition to one of the
15125 supported architectures.
15126
15127 @item show architecture
15128 Show the current target architecture.
15129
15130 @item set processor
15131 @itemx processor
15132 @kindex set processor
15133 @kindex show processor
15134 These are alias commands for, respectively, @code{set architecture}
15135 and @code{show architecture}.
15136 @end table
15137
15138 @menu
15139 * Active Targets:: Active targets
15140 * Target Commands:: Commands for managing targets
15141 * Byte Order:: Choosing target byte order
15142 @end menu
15143
15144 @node Active Targets
15145 @section Active Targets
15146
15147 @cindex stacking targets
15148 @cindex active targets
15149 @cindex multiple targets
15150
15151 There are three classes of targets: processes, core files, and
15152 executable files. @value{GDBN} can work concurrently on up to three
15153 active targets, one in each class. This allows you to (for example)
15154 start a process and inspect its activity without abandoning your work on
15155 a core file.
15156
15157 For example, if you execute @samp{gdb a.out}, then the executable file
15158 @code{a.out} is the only active target. If you designate a core file as
15159 well---presumably from a prior run that crashed and coredumped---then
15160 @value{GDBN} has two active targets and uses them in tandem, looking
15161 first in the corefile target, then in the executable file, to satisfy
15162 requests for memory addresses. (Typically, these two classes of target
15163 are complementary, since core files contain only a program's
15164 read-write memory---variables and so on---plus machine status, while
15165 executable files contain only the program text and initialized data.)
15166
15167 When you type @code{run}, your executable file becomes an active process
15168 target as well. When a process target is active, all @value{GDBN}
15169 commands requesting memory addresses refer to that target; addresses in
15170 an active core file or executable file target are obscured while the
15171 process target is active.
15172
15173 Use the @code{core-file} and @code{exec-file} commands to select a new
15174 core file or executable target (@pxref{Files, ,Commands to Specify
15175 Files}). To specify as a target a process that is already running, use
15176 the @code{attach} command (@pxref{Attach, ,Debugging an Already-running
15177 Process}).
15178
15179 @node Target Commands
15180 @section Commands for Managing Targets
15181
15182 @table @code
15183 @item target @var{type} @var{parameters}
15184 Connects the @value{GDBN} host environment to a target machine or
15185 process. A target is typically a protocol for talking to debugging
15186 facilities. You use the argument @var{type} to specify the type or
15187 protocol of the target machine.
15188
15189 Further @var{parameters} are interpreted by the target protocol, but
15190 typically include things like device names or host names to connect
15191 with, process numbers, and baud rates.
15192
15193 The @code{target} command does not repeat if you press @key{RET} again
15194 after executing the command.
15195
15196 @kindex help target
15197 @item help target
15198 Displays the names of all targets available. To display targets
15199 currently selected, use either @code{info target} or @code{info files}
15200 (@pxref{Files, ,Commands to Specify Files}).
15201
15202 @item help target @var{name}
15203 Describe a particular target, including any parameters necessary to
15204 select it.
15205
15206 @kindex set gnutarget
15207 @item set gnutarget @var{args}
15208 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
15209 knows whether it is reading an @dfn{executable},
15210 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
15211 with the @code{set gnutarget} command. Unlike most @code{target} commands,
15212 with @code{gnutarget} the @code{target} refers to a program, not a machine.
15213
15214 @quotation
15215 @emph{Warning:} To specify a file format with @code{set gnutarget},
15216 you must know the actual BFD name.
15217 @end quotation
15218
15219 @noindent
15220 @xref{Files, , Commands to Specify Files}.
15221
15222 @kindex show gnutarget
15223 @item show gnutarget
15224 Use the @code{show gnutarget} command to display what file format
15225 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
15226 @value{GDBN} will determine the file format for each file automatically,
15227 and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
15228 @end table
15229
15230 @cindex common targets
15231 Here are some common targets (available, or not, depending on the GDB
15232 configuration):
15233
15234 @table @code
15235 @kindex target
15236 @item target exec @var{program}
15237 @cindex executable file target
15238 An executable file. @samp{target exec @var{program}} is the same as
15239 @samp{exec-file @var{program}}.
15240
15241 @item target core @var{filename}
15242 @cindex core dump file target
15243 A core dump file. @samp{target core @var{filename}} is the same as
15244 @samp{core-file @var{filename}}.
15245
15246 @item target remote @var{medium}
15247 @cindex remote target
15248 A remote system connected to @value{GDBN} via a serial line or network
15249 connection. This command tells @value{GDBN} to use its own remote
15250 protocol over @var{medium} for debugging. @xref{Remote Debugging}.
15251
15252 For example, if you have a board connected to @file{/dev/ttya} on the
15253 machine running @value{GDBN}, you could say:
15254
15255 @smallexample
15256 target remote /dev/ttya
15257 @end smallexample
15258
15259 @code{target remote} supports the @code{load} command. This is only
15260 useful if you have some other way of getting the stub to the target
15261 system, and you can put it somewhere in memory where it won't get
15262 clobbered by the download.
15263
15264 @item target sim @r{[}@var{simargs}@r{]} @dots{}
15265 @cindex built-in simulator target
15266 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
15267 In general,
15268 @smallexample
15269 target sim
15270 load
15271 run
15272 @end smallexample
15273 @noindent
15274 works; however, you cannot assume that a specific memory map, device
15275 drivers, or even basic I/O is available, although some simulators do
15276 provide these. For info about any processor-specific simulator details,
15277 see the appropriate section in @ref{Embedded Processors, ,Embedded
15278 Processors}.
15279
15280 @end table
15281
15282 Some configurations may include these targets as well:
15283
15284 @table @code
15285
15286 @item target nrom @var{dev}
15287 @cindex NetROM ROM emulator target
15288 NetROM ROM emulator. This target only supports downloading.
15289
15290 @end table
15291
15292 Different targets are available on different configurations of @value{GDBN};
15293 your configuration may have more or fewer targets.
15294
15295 Many remote targets require you to download the executable's code once
15296 you've successfully established a connection. You may wish to control
15297 various aspects of this process.
15298
15299 @table @code
15300
15301 @item set hash
15302 @kindex set hash@r{, for remote monitors}
15303 @cindex hash mark while downloading
15304 This command controls whether a hash mark @samp{#} is displayed while
15305 downloading a file to the remote monitor. If on, a hash mark is
15306 displayed after each S-record is successfully downloaded to the
15307 monitor.
15308
15309 @item show hash
15310 @kindex show hash@r{, for remote monitors}
15311 Show the current status of displaying the hash mark.
15312
15313 @item set debug monitor
15314 @kindex set debug monitor
15315 @cindex display remote monitor communications
15316 Enable or disable display of communications messages between
15317 @value{GDBN} and the remote monitor.
15318
15319 @item show debug monitor
15320 @kindex show debug monitor
15321 Show the current status of displaying communications between
15322 @value{GDBN} and the remote monitor.
15323 @end table
15324
15325 @table @code
15326
15327 @kindex load @var{filename}
15328 @item load @var{filename}
15329 @anchor{load}
15330 Depending on what remote debugging facilities are configured into
15331 @value{GDBN}, the @code{load} command may be available. Where it exists, it
15332 is meant to make @var{filename} (an executable) available for debugging
15333 on the remote system---by downloading, or dynamic linking, for example.
15334 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
15335 the @code{add-symbol-file} command.
15336
15337 If your @value{GDBN} does not have a @code{load} command, attempting to
15338 execute it gets the error message ``@code{You can't do that when your
15339 target is @dots{}}''
15340
15341 The file is loaded at whatever address is specified in the executable.
15342 For some object file formats, you can specify the load address when you
15343 link the program; for other formats, like a.out, the object file format
15344 specifies a fixed address.
15345 @c FIXME! This would be a good place for an xref to the GNU linker doc.
15346
15347 Depending on the remote side capabilities, @value{GDBN} may be able to
15348 load programs into flash memory.
15349
15350 @code{load} does not repeat if you press @key{RET} again after using it.
15351 @end table
15352
15353 @node Byte Order
15354 @section Choosing Target Byte Order
15355
15356 @cindex choosing target byte order
15357 @cindex target byte order
15358
15359 Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
15360 offer the ability to run either big-endian or little-endian byte
15361 orders. Usually the executable or symbol will include a bit to
15362 designate the endian-ness, and you will not need to worry about
15363 which to use. However, you may still find it useful to adjust
15364 @value{GDBN}'s idea of processor endian-ness manually.
15365
15366 @table @code
15367 @kindex set endian
15368 @item set endian big
15369 Instruct @value{GDBN} to assume the target is big-endian.
15370
15371 @item set endian little
15372 Instruct @value{GDBN} to assume the target is little-endian.
15373
15374 @item set endian auto
15375 Instruct @value{GDBN} to use the byte order associated with the
15376 executable.
15377
15378 @item show endian
15379 Display @value{GDBN}'s current idea of the target byte order.
15380
15381 @end table
15382
15383 Note that these commands merely adjust interpretation of symbolic
15384 data on the host, and that they have absolutely no effect on the
15385 target system.
15386
15387
15388 @node Remote Debugging
15389 @chapter Debugging Remote Programs
15390 @cindex remote debugging
15391
15392 If you are trying to debug a program running on a machine that cannot run
15393 @value{GDBN} in the usual way, it is often useful to use remote debugging.
15394 For example, you might use remote debugging on an operating system kernel,
15395 or on a small system which does not have a general purpose operating system
15396 powerful enough to run a full-featured debugger.
15397
15398 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
15399 to make this work with particular debugging targets. In addition,
15400 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
15401 but not specific to any particular target system) which you can use if you
15402 write the remote stubs---the code that runs on the remote system to
15403 communicate with @value{GDBN}.
15404
15405 Other remote targets may be available in your
15406 configuration of @value{GDBN}; use @code{help target} to list them.
15407
15408 @menu
15409 * Connecting:: Connecting to a remote target
15410 * File Transfer:: Sending files to a remote system
15411 * Server:: Using the gdbserver program
15412 * Remote Configuration:: Remote configuration
15413 * Remote Stub:: Implementing a remote stub
15414 @end menu
15415
15416 @node Connecting
15417 @section Connecting to a Remote Target
15418
15419 On the @value{GDBN} host machine, you will need an unstripped copy of
15420 your program, since @value{GDBN} needs symbol and debugging information.
15421 Start up @value{GDBN} as usual, using the name of the local copy of your
15422 program as the first argument.
15423
15424 @cindex @code{target remote}
15425 @value{GDBN} can communicate with the target over a serial line, or
15426 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
15427 each case, @value{GDBN} uses the same protocol for debugging your
15428 program; only the medium carrying the debugging packets varies. The
15429 @code{target remote} command establishes a connection to the target.
15430 Its arguments indicate which medium to use:
15431
15432 @table @code
15433
15434 @item target remote @var{serial-device}
15435 @cindex serial line, @code{target remote}
15436 Use @var{serial-device} to communicate with the target. For example,
15437 to use a serial line connected to the device named @file{/dev/ttyb}:
15438
15439 @smallexample
15440 target remote /dev/ttyb
15441 @end smallexample
15442
15443 If you're using a serial line, you may want to give @value{GDBN} the
15444 @w{@samp{--baud}} option, or use the @code{set remotebaud} command
15445 (@pxref{Remote Configuration, set remotebaud}) before the
15446 @code{target} command.
15447
15448 @item target remote @code{@var{host}:@var{port}}
15449 @itemx target remote @code{tcp:@var{host}:@var{port}}
15450 @cindex @acronym{TCP} port, @code{target remote}
15451 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
15452 The @var{host} may be either a host name or a numeric @acronym{IP}
15453 address; @var{port} must be a decimal number. The @var{host} could be
15454 the target machine itself, if it is directly connected to the net, or
15455 it might be a terminal server which in turn has a serial line to the
15456 target.
15457
15458 For example, to connect to port 2828 on a terminal server named
15459 @code{manyfarms}:
15460
15461 @smallexample
15462 target remote manyfarms:2828
15463 @end smallexample
15464
15465 If your remote target is actually running on the same machine as your
15466 debugger session (e.g.@: a simulator for your target running on the
15467 same host), you can omit the hostname. For example, to connect to
15468 port 1234 on your local machine:
15469
15470 @smallexample
15471 target remote :1234
15472 @end smallexample
15473 @noindent
15474
15475 Note that the colon is still required here.
15476
15477 @item target remote @code{udp:@var{host}:@var{port}}
15478 @cindex @acronym{UDP} port, @code{target remote}
15479 Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
15480 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
15481
15482 @smallexample
15483 target remote udp:manyfarms:2828
15484 @end smallexample
15485
15486 When using a @acronym{UDP} connection for remote debugging, you should
15487 keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
15488 can silently drop packets on busy or unreliable networks, which will
15489 cause havoc with your debugging session.
15490
15491 @item target remote | @var{command}
15492 @cindex pipe, @code{target remote} to
15493 Run @var{command} in the background and communicate with it using a
15494 pipe. The @var{command} is a shell command, to be parsed and expanded
15495 by the system's command shell, @code{/bin/sh}; it should expect remote
15496 protocol packets on its standard input, and send replies on its
15497 standard output. You could use this to run a stand-alone simulator
15498 that speaks the remote debugging protocol, to make net connections
15499 using programs like @code{ssh}, or for other similar tricks.
15500
15501 If @var{command} closes its standard output (perhaps by exiting),
15502 @value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
15503 program has already exited, this will have no effect.)
15504
15505 @end table
15506
15507 Once the connection has been established, you can use all the usual
15508 commands to examine and change data. The remote program is already
15509 running; you can use @kbd{step} and @kbd{continue}, and you do not
15510 need to use @kbd{run}.
15511
15512 @cindex interrupting remote programs
15513 @cindex remote programs, interrupting
15514 Whenever @value{GDBN} is waiting for the remote program, if you type the
15515 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
15516 program. This may or may not succeed, depending in part on the hardware
15517 and the serial drivers the remote system uses. If you type the
15518 interrupt character once again, @value{GDBN} displays this prompt:
15519
15520 @smallexample
15521 Interrupted while waiting for the program.
15522 Give up (and stop debugging it)? (y or n)
15523 @end smallexample
15524
15525 If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
15526 (If you decide you want to try again later, you can use @samp{target
15527 remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
15528 goes back to waiting.
15529
15530 @table @code
15531 @kindex detach (remote)
15532 @item detach
15533 When you have finished debugging the remote program, you can use the
15534 @code{detach} command to release it from @value{GDBN} control.
15535 Detaching from the target normally resumes its execution, but the results
15536 will depend on your particular remote stub. After the @code{detach}
15537 command, @value{GDBN} is free to connect to another target.
15538
15539 @kindex disconnect
15540 @item disconnect
15541 The @code{disconnect} command behaves like @code{detach}, except that
15542 the target is generally not resumed. It will wait for @value{GDBN}
15543 (this instance or another one) to connect and continue debugging. After
15544 the @code{disconnect} command, @value{GDBN} is again free to connect to
15545 another target.
15546
15547 @cindex send command to remote monitor
15548 @cindex extend @value{GDBN} for remote targets
15549 @cindex add new commands for external monitor
15550 @kindex monitor
15551 @item monitor @var{cmd}
15552 This command allows you to send arbitrary commands directly to the
15553 remote monitor. Since @value{GDBN} doesn't care about the commands it
15554 sends like this, this command is the way to extend @value{GDBN}---you
15555 can add new commands that only the external monitor will understand
15556 and implement.
15557 @end table
15558
15559 @node File Transfer
15560 @section Sending files to a remote system
15561 @cindex remote target, file transfer
15562 @cindex file transfer
15563 @cindex sending files to remote systems
15564
15565 Some remote targets offer the ability to transfer files over the same
15566 connection used to communicate with @value{GDBN}. This is convenient
15567 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
15568 running @code{gdbserver} over a network interface. For other targets,
15569 e.g.@: embedded devices with only a single serial port, this may be
15570 the only way to upload or download files.
15571
15572 Not all remote targets support these commands.
15573
15574 @table @code
15575 @kindex remote put
15576 @item remote put @var{hostfile} @var{targetfile}
15577 Copy file @var{hostfile} from the host system (the machine running
15578 @value{GDBN}) to @var{targetfile} on the target system.
15579
15580 @kindex remote get
15581 @item remote get @var{targetfile} @var{hostfile}
15582 Copy file @var{targetfile} from the target system to @var{hostfile}
15583 on the host system.
15584
15585 @kindex remote delete
15586 @item remote delete @var{targetfile}
15587 Delete @var{targetfile} from the target system.
15588
15589 @end table
15590
15591 @node Server
15592 @section Using the @code{gdbserver} Program
15593
15594 @kindex gdbserver
15595 @cindex remote connection without stubs
15596 @code{gdbserver} is a control program for Unix-like systems, which
15597 allows you to connect your program with a remote @value{GDBN} via
15598 @code{target remote}---but without linking in the usual debugging stub.
15599
15600 @code{gdbserver} is not a complete replacement for the debugging stubs,
15601 because it requires essentially the same operating-system facilities
15602 that @value{GDBN} itself does. In fact, a system that can run
15603 @code{gdbserver} to connect to a remote @value{GDBN} could also run
15604 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
15605 because it is a much smaller program than @value{GDBN} itself. It is
15606 also easier to port than all of @value{GDBN}, so you may be able to get
15607 started more quickly on a new system by using @code{gdbserver}.
15608 Finally, if you develop code for real-time systems, you may find that
15609 the tradeoffs involved in real-time operation make it more convenient to
15610 do as much development work as possible on another system, for example
15611 by cross-compiling. You can use @code{gdbserver} to make a similar
15612 choice for debugging.
15613
15614 @value{GDBN} and @code{gdbserver} communicate via either a serial line
15615 or a TCP connection, using the standard @value{GDBN} remote serial
15616 protocol.
15617
15618 @quotation
15619 @emph{Warning:} @code{gdbserver} does not have any built-in security.
15620 Do not run @code{gdbserver} connected to any public network; a
15621 @value{GDBN} connection to @code{gdbserver} provides access to the
15622 target system with the same privileges as the user running
15623 @code{gdbserver}.
15624 @end quotation
15625
15626 @subsection Running @code{gdbserver}
15627 @cindex arguments, to @code{gdbserver}
15628
15629 Run @code{gdbserver} on the target system. You need a copy of the
15630 program you want to debug, including any libraries it requires.
15631 @code{gdbserver} does not need your program's symbol table, so you can
15632 strip the program if necessary to save space. @value{GDBN} on the host
15633 system does all the symbol handling.
15634
15635 To use the server, you must tell it how to communicate with @value{GDBN};
15636 the name of your program; and the arguments for your program. The usual
15637 syntax is:
15638
15639 @smallexample
15640 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
15641 @end smallexample
15642
15643 @var{comm} is either a device name (to use a serial line) or a TCP
15644 hostname and portnumber. For example, to debug Emacs with the argument
15645 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
15646 @file{/dev/com1}:
15647
15648 @smallexample
15649 target> gdbserver /dev/com1 emacs foo.txt
15650 @end smallexample
15651
15652 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
15653 with it.
15654
15655 To use a TCP connection instead of a serial line:
15656
15657 @smallexample
15658 target> gdbserver host:2345 emacs foo.txt
15659 @end smallexample
15660
15661 The only difference from the previous example is the first argument,
15662 specifying that you are communicating with the host @value{GDBN} via
15663 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
15664 expect a TCP connection from machine @samp{host} to local TCP port 2345.
15665 (Currently, the @samp{host} part is ignored.) You can choose any number
15666 you want for the port number as long as it does not conflict with any
15667 TCP ports already in use on the target system (for example, @code{23} is
15668 reserved for @code{telnet}).@footnote{If you choose a port number that
15669 conflicts with another service, @code{gdbserver} prints an error message
15670 and exits.} You must use the same port number with the host @value{GDBN}
15671 @code{target remote} command.
15672
15673 @subsubsection Attaching to a Running Program
15674
15675 On some targets, @code{gdbserver} can also attach to running programs.
15676 This is accomplished via the @code{--attach} argument. The syntax is:
15677
15678 @smallexample
15679 target> gdbserver --attach @var{comm} @var{pid}
15680 @end smallexample
15681
15682 @var{pid} is the process ID of a currently running process. It isn't necessary
15683 to point @code{gdbserver} at a binary for the running process.
15684
15685 @pindex pidof
15686 @cindex attach to a program by name
15687 You can debug processes by name instead of process ID if your target has the
15688 @code{pidof} utility:
15689
15690 @smallexample
15691 target> gdbserver --attach @var{comm} `pidof @var{program}`
15692 @end smallexample
15693
15694 In case more than one copy of @var{program} is running, or @var{program}
15695 has multiple threads, most versions of @code{pidof} support the
15696 @code{-s} option to only return the first process ID.
15697
15698 @subsubsection Multi-Process Mode for @code{gdbserver}
15699 @cindex gdbserver, multiple processes
15700 @cindex multiple processes with gdbserver
15701
15702 When you connect to @code{gdbserver} using @code{target remote},
15703 @code{gdbserver} debugs the specified program only once. When the
15704 program exits, or you detach from it, @value{GDBN} closes the connection
15705 and @code{gdbserver} exits.
15706
15707 If you connect using @kbd{target extended-remote}, @code{gdbserver}
15708 enters multi-process mode. When the debugged program exits, or you
15709 detach from it, @value{GDBN} stays connected to @code{gdbserver} even
15710 though no program is running. The @code{run} and @code{attach}
15711 commands instruct @code{gdbserver} to run or attach to a new program.
15712 The @code{run} command uses @code{set remote exec-file} (@pxref{set
15713 remote exec-file}) to select the program to run. Command line
15714 arguments are supported, except for wildcard expansion and I/O
15715 redirection (@pxref{Arguments}).
15716
15717 To start @code{gdbserver} without supplying an initial command to run
15718 or process ID to attach, use the @option{--multi} command line option.
15719 Then you can connect using @kbd{target extended-remote} and start
15720 the program you want to debug.
15721
15722 @code{gdbserver} does not automatically exit in multi-process mode.
15723 You can terminate it by using @code{monitor exit}
15724 (@pxref{Monitor Commands for gdbserver}).
15725
15726 @subsubsection Other Command-Line Arguments for @code{gdbserver}
15727
15728 The @option{--debug} option tells @code{gdbserver} to display extra
15729 status information about the debugging process. The
15730 @option{--remote-debug} option tells @code{gdbserver} to display
15731 remote protocol debug output. These options are intended for
15732 @code{gdbserver} development and for bug reports to the developers.
15733
15734 The @option{--wrapper} option specifies a wrapper to launch programs
15735 for debugging. The option should be followed by the name of the
15736 wrapper, then any command-line arguments to pass to the wrapper, then
15737 @kbd{--} indicating the end of the wrapper arguments.
15738
15739 @code{gdbserver} runs the specified wrapper program with a combined
15740 command line including the wrapper arguments, then the name of the
15741 program to debug, then any arguments to the program. The wrapper
15742 runs until it executes your program, and then @value{GDBN} gains control.
15743
15744 You can use any program that eventually calls @code{execve} with
15745 its arguments as a wrapper. Several standard Unix utilities do
15746 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
15747 with @code{exec "$@@"} will also work.
15748
15749 For example, you can use @code{env} to pass an environment variable to
15750 the debugged program, without setting the variable in @code{gdbserver}'s
15751 environment:
15752
15753 @smallexample
15754 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
15755 @end smallexample
15756
15757 @subsection Connecting to @code{gdbserver}
15758
15759 Run @value{GDBN} on the host system.
15760
15761 First make sure you have the necessary symbol files. Load symbols for
15762 your application using the @code{file} command before you connect. Use
15763 @code{set sysroot} to locate target libraries (unless your @value{GDBN}
15764 was compiled with the correct sysroot using @code{--with-sysroot}).
15765
15766 The symbol file and target libraries must exactly match the executable
15767 and libraries on the target, with one exception: the files on the host
15768 system should not be stripped, even if the files on the target system
15769 are. Mismatched or missing files will lead to confusing results
15770 during debugging. On @sc{gnu}/Linux targets, mismatched or missing
15771 files may also prevent @code{gdbserver} from debugging multi-threaded
15772 programs.
15773
15774 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
15775 For TCP connections, you must start up @code{gdbserver} prior to using
15776 the @code{target remote} command. Otherwise you may get an error whose
15777 text depends on the host system, but which usually looks something like
15778 @samp{Connection refused}. Don't use the @code{load}
15779 command in @value{GDBN} when using @code{gdbserver}, since the program is
15780 already on the target.
15781
15782 @subsection Monitor Commands for @code{gdbserver}
15783 @cindex monitor commands, for @code{gdbserver}
15784 @anchor{Monitor Commands for gdbserver}
15785
15786 During a @value{GDBN} session using @code{gdbserver}, you can use the
15787 @code{monitor} command to send special requests to @code{gdbserver}.
15788 Here are the available commands.
15789
15790 @table @code
15791 @item monitor help
15792 List the available monitor commands.
15793
15794 @item monitor set debug 0
15795 @itemx monitor set debug 1
15796 Disable or enable general debugging messages.
15797
15798 @item monitor set remote-debug 0
15799 @itemx monitor set remote-debug 1
15800 Disable or enable specific debugging messages associated with the remote
15801 protocol (@pxref{Remote Protocol}).
15802
15803 @item monitor set libthread-db-search-path [PATH]
15804 @cindex gdbserver, search path for @code{libthread_db}
15805 When this command is issued, @var{path} is a colon-separated list of
15806 directories to search for @code{libthread_db} (@pxref{Threads,,set
15807 libthread-db-search-path}). If you omit @var{path},
15808 @samp{libthread-db-search-path} will be reset to an empty list.
15809
15810 @item monitor exit
15811 Tell gdbserver to exit immediately. This command should be followed by
15812 @code{disconnect} to close the debugging session. @code{gdbserver} will
15813 detach from any attached processes and kill any processes it created.
15814 Use @code{monitor exit} to terminate @code{gdbserver} at the end
15815 of a multi-process mode debug session.
15816
15817 @end table
15818
15819 @subsection Tracepoints support in @code{gdbserver}
15820 @cindex tracepoints support in @code{gdbserver}
15821
15822 On some targets, @code{gdbserver} supports tracepoints and fast
15823 tracepoints.
15824
15825 For fast tracepoints to work, a special library called the
15826 @dfn{in-process agent} (IPA), must be loaded in the inferior process.
15827 This library is built and distributed as an integral part of
15828 @code{gdbserver}.
15829
15830 There are several ways to load the in-process agent in your program:
15831
15832 @table @code
15833 @item Specifying it as dependency at link time
15834
15835 You can link your program dynamically with the in-process agent
15836 library. On most systems, this is accomplished by adding
15837 @code{-linproctrace} to the link command.
15838
15839 @item Using the system's preloading mechanisms
15840
15841 You can force loading the in-process agent at startup time by using
15842 your system's support for preloading shared libraries. Many Unixes
15843 support the concept of preloading user defined libraries. In most
15844 cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
15845 in the environment. See also the description of @code{gdbserver}'s
15846 @option{--wrapper} command line option.
15847
15848 @item Using @value{GDBN} to force loading the agent at run time
15849
15850 On some systems, you can force the inferior to load a shared library,
15851 by calling a dynamic loader function in the inferior that takes care
15852 of dynamically looking up and loading a shared library. On most Unix
15853 systems, the function is @code{dlopen}. You'll use the @code{call}
15854 command for that. For example:
15855
15856 @smallexample
15857 (@value{GDBP}) call dlopen ("libinproctrace.so", ...)
15858 @end smallexample
15859
15860 Note that on most Unix systems, for the @code{dlopen} function to be
15861 available, the program needs to be linked with @code{-ldl}.
15862 @end table
15863
15864 On systems that have a userspace dynamic loader, like most Unix
15865 systems, when you connect to @code{gdbserver} using @code{target
15866 remote}, you'll find that the program is stopped at the dynamic
15867 loader's entry point, and no shared library has been loaded in the
15868 program's address space yet, including the in-process agent. In that
15869 case, before being able to use any of the fast tracepoints features,
15870 you need to let the loader run and load the shared libraries. The
15871 most simple way to do that is to run the program to the main
15872 procedure. E.g., if debugging a C or C@t{++} program, start
15873 @code{gdbserver} like so:
15874
15875 @smallexample
15876 $ gdbserver :9999 myprogram
15877 @end smallexample
15878
15879 Start GDB and connect to @code{gdbserver} like so, and run to main:
15880
15881 @smallexample
15882 $ gdb myprogram
15883 (@value{GDBP}) target remote myhost:9999
15884 0x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
15885 (@value{GDBP}) b main
15886 (@value{GDBP}) continue
15887 @end smallexample
15888
15889 The in-process tracing agent library should now be loaded into the
15890 process; you can confirm it with the @code{info sharedlibrary}
15891 command, which will list @file{libinproctrace.so} as loaded in the
15892 process. You are now ready to install fast tracepoints and start
15893 tracing.
15894
15895 @node Remote Configuration
15896 @section Remote Configuration
15897
15898 @kindex set remote
15899 @kindex show remote
15900 This section documents the configuration options available when
15901 debugging remote programs. For the options related to the File I/O
15902 extensions of the remote protocol, see @ref{system,
15903 system-call-allowed}.
15904
15905 @table @code
15906 @item set remoteaddresssize @var{bits}
15907 @cindex address size for remote targets
15908 @cindex bits in remote address
15909 Set the maximum size of address in a memory packet to the specified
15910 number of bits. @value{GDBN} will mask off the address bits above
15911 that number, when it passes addresses to the remote target. The
15912 default value is the number of bits in the target's address.
15913
15914 @item show remoteaddresssize
15915 Show the current value of remote address size in bits.
15916
15917 @item set remotebaud @var{n}
15918 @cindex baud rate for remote targets
15919 Set the baud rate for the remote serial I/O to @var{n} baud. The
15920 value is used to set the speed of the serial port used for debugging
15921 remote targets.
15922
15923 @item show remotebaud
15924 Show the current speed of the remote connection.
15925
15926 @item set remotebreak
15927 @cindex interrupt remote programs
15928 @cindex BREAK signal instead of Ctrl-C
15929 @anchor{set remotebreak}
15930 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
15931 when you type @kbd{Ctrl-c} to interrupt the program running
15932 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
15933 character instead. The default is off, since most remote systems
15934 expect to see @samp{Ctrl-C} as the interrupt signal.
15935
15936 @item show remotebreak
15937 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
15938 interrupt the remote program.
15939
15940 @item set remoteflow on
15941 @itemx set remoteflow off
15942 @kindex set remoteflow
15943 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
15944 on the serial port used to communicate to the remote target.
15945
15946 @item show remoteflow
15947 @kindex show remoteflow
15948 Show the current setting of hardware flow control.
15949
15950 @item set remotelogbase @var{base}
15951 Set the base (a.k.a.@: radix) of logging serial protocol
15952 communications to @var{base}. Supported values of @var{base} are:
15953 @code{ascii}, @code{octal}, and @code{hex}. The default is
15954 @code{ascii}.
15955
15956 @item show remotelogbase
15957 Show the current setting of the radix for logging remote serial
15958 protocol.
15959
15960 @item set remotelogfile @var{file}
15961 @cindex record serial communications on file
15962 Record remote serial communications on the named @var{file}. The
15963 default is not to record at all.
15964
15965 @item show remotelogfile.
15966 Show the current setting of the file name on which to record the
15967 serial communications.
15968
15969 @item set remotetimeout @var{num}
15970 @cindex timeout for serial communications
15971 @cindex remote timeout
15972 Set the timeout limit to wait for the remote target to respond to
15973 @var{num} seconds. The default is 2 seconds.
15974
15975 @item show remotetimeout
15976 Show the current number of seconds to wait for the remote target
15977 responses.
15978
15979 @cindex limit hardware breakpoints and watchpoints
15980 @cindex remote target, limit break- and watchpoints
15981 @anchor{set remote hardware-watchpoint-limit}
15982 @anchor{set remote hardware-breakpoint-limit}
15983 @item set remote hardware-watchpoint-limit @var{limit}
15984 @itemx set remote hardware-breakpoint-limit @var{limit}
15985 Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
15986 watchpoints. A limit of -1, the default, is treated as unlimited.
15987
15988 @item set remote exec-file @var{filename}
15989 @itemx show remote exec-file
15990 @anchor{set remote exec-file}
15991 @cindex executable file, for remote target
15992 Select the file used for @code{run} with @code{target
15993 extended-remote}. This should be set to a filename valid on the
15994 target system. If it is not set, the target will use a default
15995 filename (e.g.@: the last program run).
15996
15997 @item set remote interrupt-sequence
15998 @cindex interrupt remote programs
15999 @cindex select Ctrl-C, BREAK or BREAK-g
16000 Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
16001 @samp{BREAK-g} as the
16002 sequence to the remote target in order to interrupt the execution.
16003 @samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
16004 is high level of serial line for some certain time.
16005 Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
16006 It is @code{BREAK} signal followed by character @code{g}.
16007
16008 @item show interrupt-sequence
16009 Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
16010 is sent by @value{GDBN} to interrupt the remote program.
16011 @code{BREAK-g} is BREAK signal followed by @code{g} and
16012 also known as Magic SysRq g.
16013
16014 @item set remote interrupt-on-connect
16015 @cindex send interrupt-sequence on start
16016 Specify whether interrupt-sequence is sent to remote target when
16017 @value{GDBN} connects to it. This is mostly needed when you debug
16018 Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
16019 which is known as Magic SysRq g in order to connect @value{GDBN}.
16020
16021 @item show interrupt-on-connect
16022 Show whether interrupt-sequence is sent
16023 to remote target when @value{GDBN} connects to it.
16024
16025 @kindex set tcp
16026 @kindex show tcp
16027 @item set tcp auto-retry on
16028 @cindex auto-retry, for remote TCP target
16029 Enable auto-retry for remote TCP connections. This is useful if the remote
16030 debugging agent is launched in parallel with @value{GDBN}; there is a race
16031 condition because the agent may not become ready to accept the connection
16032 before @value{GDBN} attempts to connect. When auto-retry is
16033 enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
16034 to establish the connection using the timeout specified by
16035 @code{set tcp connect-timeout}.
16036
16037 @item set tcp auto-retry off
16038 Do not auto-retry failed TCP connections.
16039
16040 @item show tcp auto-retry
16041 Show the current auto-retry setting.
16042
16043 @item set tcp connect-timeout @var{seconds}
16044 @cindex connection timeout, for remote TCP target
16045 @cindex timeout, for remote target connection
16046 Set the timeout for establishing a TCP connection to the remote target to
16047 @var{seconds}. The timeout affects both polling to retry failed connections
16048 (enabled by @code{set tcp auto-retry on}) and waiting for connections
16049 that are merely slow to complete, and represents an approximate cumulative
16050 value.
16051
16052 @item show tcp connect-timeout
16053 Show the current connection timeout setting.
16054 @end table
16055
16056 @cindex remote packets, enabling and disabling
16057 The @value{GDBN} remote protocol autodetects the packets supported by
16058 your debugging stub. If you need to override the autodetection, you
16059 can use these commands to enable or disable individual packets. Each
16060 packet can be set to @samp{on} (the remote target supports this
16061 packet), @samp{off} (the remote target does not support this packet),
16062 or @samp{auto} (detect remote target support for this packet). They
16063 all default to @samp{auto}. For more information about each packet,
16064 see @ref{Remote Protocol}.
16065
16066 During normal use, you should not have to use any of these commands.
16067 If you do, that may be a bug in your remote debugging stub, or a bug
16068 in @value{GDBN}. You may want to report the problem to the
16069 @value{GDBN} developers.
16070
16071 For each packet @var{name}, the command to enable or disable the
16072 packet is @code{set remote @var{name}-packet}. The available settings
16073 are:
16074
16075 @multitable @columnfractions 0.28 0.32 0.25
16076 @item Command Name
16077 @tab Remote Packet
16078 @tab Related Features
16079
16080 @item @code{fetch-register}
16081 @tab @code{p}
16082 @tab @code{info registers}
16083
16084 @item @code{set-register}
16085 @tab @code{P}
16086 @tab @code{set}
16087
16088 @item @code{binary-download}
16089 @tab @code{X}
16090 @tab @code{load}, @code{set}
16091
16092 @item @code{read-aux-vector}
16093 @tab @code{qXfer:auxv:read}
16094 @tab @code{info auxv}
16095
16096 @item @code{symbol-lookup}
16097 @tab @code{qSymbol}
16098 @tab Detecting multiple threads
16099
16100 @item @code{attach}
16101 @tab @code{vAttach}
16102 @tab @code{attach}
16103
16104 @item @code{verbose-resume}
16105 @tab @code{vCont}
16106 @tab Stepping or resuming multiple threads
16107
16108 @item @code{run}
16109 @tab @code{vRun}
16110 @tab @code{run}
16111
16112 @item @code{software-breakpoint}
16113 @tab @code{Z0}
16114 @tab @code{break}
16115
16116 @item @code{hardware-breakpoint}
16117 @tab @code{Z1}
16118 @tab @code{hbreak}
16119
16120 @item @code{write-watchpoint}
16121 @tab @code{Z2}
16122 @tab @code{watch}
16123
16124 @item @code{read-watchpoint}
16125 @tab @code{Z3}
16126 @tab @code{rwatch}
16127
16128 @item @code{access-watchpoint}
16129 @tab @code{Z4}
16130 @tab @code{awatch}
16131
16132 @item @code{target-features}
16133 @tab @code{qXfer:features:read}
16134 @tab @code{set architecture}
16135
16136 @item @code{library-info}
16137 @tab @code{qXfer:libraries:read}
16138 @tab @code{info sharedlibrary}
16139
16140 @item @code{memory-map}
16141 @tab @code{qXfer:memory-map:read}
16142 @tab @code{info mem}
16143
16144 @item @code{read-spu-object}
16145 @tab @code{qXfer:spu:read}
16146 @tab @code{info spu}
16147
16148 @item @code{write-spu-object}
16149 @tab @code{qXfer:spu:write}
16150 @tab @code{info spu}
16151
16152 @item @code{read-siginfo-object}
16153 @tab @code{qXfer:siginfo:read}
16154 @tab @code{print $_siginfo}
16155
16156 @item @code{write-siginfo-object}
16157 @tab @code{qXfer:siginfo:write}
16158 @tab @code{set $_siginfo}
16159
16160 @item @code{threads}
16161 @tab @code{qXfer:threads:read}
16162 @tab @code{info threads}
16163
16164 @item @code{get-thread-local-@*storage-address}
16165 @tab @code{qGetTLSAddr}
16166 @tab Displaying @code{__thread} variables
16167
16168 @item @code{get-thread-information-block-address}
16169 @tab @code{qGetTIBAddr}
16170 @tab Display MS-Windows Thread Information Block.
16171
16172 @item @code{search-memory}
16173 @tab @code{qSearch:memory}
16174 @tab @code{find}
16175
16176 @item @code{supported-packets}
16177 @tab @code{qSupported}
16178 @tab Remote communications parameters
16179
16180 @item @code{pass-signals}
16181 @tab @code{QPassSignals}
16182 @tab @code{handle @var{signal}}
16183
16184 @item @code{hostio-close-packet}
16185 @tab @code{vFile:close}
16186 @tab @code{remote get}, @code{remote put}
16187
16188 @item @code{hostio-open-packet}
16189 @tab @code{vFile:open}
16190 @tab @code{remote get}, @code{remote put}
16191
16192 @item @code{hostio-pread-packet}
16193 @tab @code{vFile:pread}
16194 @tab @code{remote get}, @code{remote put}
16195
16196 @item @code{hostio-pwrite-packet}
16197 @tab @code{vFile:pwrite}
16198 @tab @code{remote get}, @code{remote put}
16199
16200 @item @code{hostio-unlink-packet}
16201 @tab @code{vFile:unlink}
16202 @tab @code{remote delete}
16203
16204 @item @code{noack-packet}
16205 @tab @code{QStartNoAckMode}
16206 @tab Packet acknowledgment
16207
16208 @item @code{osdata}
16209 @tab @code{qXfer:osdata:read}
16210 @tab @code{info os}
16211
16212 @item @code{query-attached}
16213 @tab @code{qAttached}
16214 @tab Querying remote process attach state.
16215 @end multitable
16216
16217 @node Remote Stub
16218 @section Implementing a Remote Stub
16219
16220 @cindex debugging stub, example
16221 @cindex remote stub, example
16222 @cindex stub example, remote debugging
16223 The stub files provided with @value{GDBN} implement the target side of the
16224 communication protocol, and the @value{GDBN} side is implemented in the
16225 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
16226 these subroutines to communicate, and ignore the details. (If you're
16227 implementing your own stub file, you can still ignore the details: start
16228 with one of the existing stub files. @file{sparc-stub.c} is the best
16229 organized, and therefore the easiest to read.)
16230
16231 @cindex remote serial debugging, overview
16232 To debug a program running on another machine (the debugging
16233 @dfn{target} machine), you must first arrange for all the usual
16234 prerequisites for the program to run by itself. For example, for a C
16235 program, you need:
16236
16237 @enumerate
16238 @item
16239 A startup routine to set up the C runtime environment; these usually
16240 have a name like @file{crt0}. The startup routine may be supplied by
16241 your hardware supplier, or you may have to write your own.
16242
16243 @item
16244 A C subroutine library to support your program's
16245 subroutine calls, notably managing input and output.
16246
16247 @item
16248 A way of getting your program to the other machine---for example, a
16249 download program. These are often supplied by the hardware
16250 manufacturer, but you may have to write your own from hardware
16251 documentation.
16252 @end enumerate
16253
16254 The next step is to arrange for your program to use a serial port to
16255 communicate with the machine where @value{GDBN} is running (the @dfn{host}
16256 machine). In general terms, the scheme looks like this:
16257
16258 @table @emph
16259 @item On the host,
16260 @value{GDBN} already understands how to use this protocol; when everything
16261 else is set up, you can simply use the @samp{target remote} command
16262 (@pxref{Targets,,Specifying a Debugging Target}).
16263
16264 @item On the target,
16265 you must link with your program a few special-purpose subroutines that
16266 implement the @value{GDBN} remote serial protocol. The file containing these
16267 subroutines is called a @dfn{debugging stub}.
16268
16269 On certain remote targets, you can use an auxiliary program
16270 @code{gdbserver} instead of linking a stub into your program.
16271 @xref{Server,,Using the @code{gdbserver} Program}, for details.
16272 @end table
16273
16274 The debugging stub is specific to the architecture of the remote
16275 machine; for example, use @file{sparc-stub.c} to debug programs on
16276 @sc{sparc} boards.
16277
16278 @cindex remote serial stub list
16279 These working remote stubs are distributed with @value{GDBN}:
16280
16281 @table @code
16282
16283 @item i386-stub.c
16284 @cindex @file{i386-stub.c}
16285 @cindex Intel
16286 @cindex i386
16287 For Intel 386 and compatible architectures.
16288
16289 @item m68k-stub.c
16290 @cindex @file{m68k-stub.c}
16291 @cindex Motorola 680x0
16292 @cindex m680x0
16293 For Motorola 680x0 architectures.
16294
16295 @item sh-stub.c
16296 @cindex @file{sh-stub.c}
16297 @cindex Renesas
16298 @cindex SH
16299 For Renesas SH architectures.
16300
16301 @item sparc-stub.c
16302 @cindex @file{sparc-stub.c}
16303 @cindex Sparc
16304 For @sc{sparc} architectures.
16305
16306 @item sparcl-stub.c
16307 @cindex @file{sparcl-stub.c}
16308 @cindex Fujitsu
16309 @cindex SparcLite
16310 For Fujitsu @sc{sparclite} architectures.
16311
16312 @end table
16313
16314 The @file{README} file in the @value{GDBN} distribution may list other
16315 recently added stubs.
16316
16317 @menu
16318 * Stub Contents:: What the stub can do for you
16319 * Bootstrapping:: What you must do for the stub
16320 * Debug Session:: Putting it all together
16321 @end menu
16322
16323 @node Stub Contents
16324 @subsection What the Stub Can Do for You
16325
16326 @cindex remote serial stub
16327 The debugging stub for your architecture supplies these three
16328 subroutines:
16329
16330 @table @code
16331 @item set_debug_traps
16332 @findex set_debug_traps
16333 @cindex remote serial stub, initialization
16334 This routine arranges for @code{handle_exception} to run when your
16335 program stops. You must call this subroutine explicitly near the
16336 beginning of your program.
16337
16338 @item handle_exception
16339 @findex handle_exception
16340 @cindex remote serial stub, main routine
16341 This is the central workhorse, but your program never calls it
16342 explicitly---the setup code arranges for @code{handle_exception} to
16343 run when a trap is triggered.
16344
16345 @code{handle_exception} takes control when your program stops during
16346 execution (for example, on a breakpoint), and mediates communications
16347 with @value{GDBN} on the host machine. This is where the communications
16348 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
16349 representative on the target machine. It begins by sending summary
16350 information on the state of your program, then continues to execute,
16351 retrieving and transmitting any information @value{GDBN} needs, until you
16352 execute a @value{GDBN} command that makes your program resume; at that point,
16353 @code{handle_exception} returns control to your own code on the target
16354 machine.
16355
16356 @item breakpoint
16357 @cindex @code{breakpoint} subroutine, remote
16358 Use this auxiliary subroutine to make your program contain a
16359 breakpoint. Depending on the particular situation, this may be the only
16360 way for @value{GDBN} to get control. For instance, if your target
16361 machine has some sort of interrupt button, you won't need to call this;
16362 pressing the interrupt button transfers control to
16363 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
16364 simply receiving characters on the serial port may also trigger a trap;
16365 again, in that situation, you don't need to call @code{breakpoint} from
16366 your own program---simply running @samp{target remote} from the host
16367 @value{GDBN} session gets control.
16368
16369 Call @code{breakpoint} if none of these is true, or if you simply want
16370 to make certain your program stops at a predetermined point for the
16371 start of your debugging session.
16372 @end table
16373
16374 @node Bootstrapping
16375 @subsection What You Must Do for the Stub
16376
16377 @cindex remote stub, support routines
16378 The debugging stubs that come with @value{GDBN} are set up for a particular
16379 chip architecture, but they have no information about the rest of your
16380 debugging target machine.
16381
16382 First of all you need to tell the stub how to communicate with the
16383 serial port.
16384
16385 @table @code
16386 @item int getDebugChar()
16387 @findex getDebugChar
16388 Write this subroutine to read a single character from the serial port.
16389 It may be identical to @code{getchar} for your target system; a
16390 different name is used to allow you to distinguish the two if you wish.
16391
16392 @item void putDebugChar(int)
16393 @findex putDebugChar
16394 Write this subroutine to write a single character to the serial port.
16395 It may be identical to @code{putchar} for your target system; a
16396 different name is used to allow you to distinguish the two if you wish.
16397 @end table
16398
16399 @cindex control C, and remote debugging
16400 @cindex interrupting remote targets
16401 If you want @value{GDBN} to be able to stop your program while it is
16402 running, you need to use an interrupt-driven serial driver, and arrange
16403 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
16404 character). That is the character which @value{GDBN} uses to tell the
16405 remote system to stop.
16406
16407 Getting the debugging target to return the proper status to @value{GDBN}
16408 probably requires changes to the standard stub; one quick and dirty way
16409 is to just execute a breakpoint instruction (the ``dirty'' part is that
16410 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
16411
16412 Other routines you need to supply are:
16413
16414 @table @code
16415 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
16416 @findex exceptionHandler
16417 Write this function to install @var{exception_address} in the exception
16418 handling tables. You need to do this because the stub does not have any
16419 way of knowing what the exception handling tables on your target system
16420 are like (for example, the processor's table might be in @sc{rom},
16421 containing entries which point to a table in @sc{ram}).
16422 @var{exception_number} is the exception number which should be changed;
16423 its meaning is architecture-dependent (for example, different numbers
16424 might represent divide by zero, misaligned access, etc). When this
16425 exception occurs, control should be transferred directly to
16426 @var{exception_address}, and the processor state (stack, registers,
16427 and so on) should be just as it is when a processor exception occurs. So if
16428 you want to use a jump instruction to reach @var{exception_address}, it
16429 should be a simple jump, not a jump to subroutine.
16430
16431 For the 386, @var{exception_address} should be installed as an interrupt
16432 gate so that interrupts are masked while the handler runs. The gate
16433 should be at privilege level 0 (the most privileged level). The
16434 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
16435 help from @code{exceptionHandler}.
16436
16437 @item void flush_i_cache()
16438 @findex flush_i_cache
16439 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
16440 instruction cache, if any, on your target machine. If there is no
16441 instruction cache, this subroutine may be a no-op.
16442
16443 On target machines that have instruction caches, @value{GDBN} requires this
16444 function to make certain that the state of your program is stable.
16445 @end table
16446
16447 @noindent
16448 You must also make sure this library routine is available:
16449
16450 @table @code
16451 @item void *memset(void *, int, int)
16452 @findex memset
16453 This is the standard library function @code{memset} that sets an area of
16454 memory to a known value. If you have one of the free versions of
16455 @code{libc.a}, @code{memset} can be found there; otherwise, you must
16456 either obtain it from your hardware manufacturer, or write your own.
16457 @end table
16458
16459 If you do not use the GNU C compiler, you may need other standard
16460 library subroutines as well; this varies from one stub to another,
16461 but in general the stubs are likely to use any of the common library
16462 subroutines which @code{@value{NGCC}} generates as inline code.
16463
16464
16465 @node Debug Session
16466 @subsection Putting it All Together
16467
16468 @cindex remote serial debugging summary
16469 In summary, when your program is ready to debug, you must follow these
16470 steps.
16471
16472 @enumerate
16473 @item
16474 Make sure you have defined the supporting low-level routines
16475 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
16476 @display
16477 @code{getDebugChar}, @code{putDebugChar},
16478 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
16479 @end display
16480
16481 @item
16482 Insert these lines near the top of your program:
16483
16484 @smallexample
16485 set_debug_traps();
16486 breakpoint();
16487 @end smallexample
16488
16489 @item
16490 For the 680x0 stub only, you need to provide a variable called
16491 @code{exceptionHook}. Normally you just use:
16492
16493 @smallexample
16494 void (*exceptionHook)() = 0;
16495 @end smallexample
16496
16497 @noindent
16498 but if before calling @code{set_debug_traps}, you set it to point to a
16499 function in your program, that function is called when
16500 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
16501 error). The function indicated by @code{exceptionHook} is called with
16502 one parameter: an @code{int} which is the exception number.
16503
16504 @item
16505 Compile and link together: your program, the @value{GDBN} debugging stub for
16506 your target architecture, and the supporting subroutines.
16507
16508 @item
16509 Make sure you have a serial connection between your target machine and
16510 the @value{GDBN} host, and identify the serial port on the host.
16511
16512 @item
16513 @c The "remote" target now provides a `load' command, so we should
16514 @c document that. FIXME.
16515 Download your program to your target machine (or get it there by
16516 whatever means the manufacturer provides), and start it.
16517
16518 @item
16519 Start @value{GDBN} on the host, and connect to the target
16520 (@pxref{Connecting,,Connecting to a Remote Target}).
16521
16522 @end enumerate
16523
16524 @node Configurations
16525 @chapter Configuration-Specific Information
16526
16527 While nearly all @value{GDBN} commands are available for all native and
16528 cross versions of the debugger, there are some exceptions. This chapter
16529 describes things that are only available in certain configurations.
16530
16531 There are three major categories of configurations: native
16532 configurations, where the host and target are the same, embedded
16533 operating system configurations, which are usually the same for several
16534 different processor architectures, and bare embedded processors, which
16535 are quite different from each other.
16536
16537 @menu
16538 * Native::
16539 * Embedded OS::
16540 * Embedded Processors::
16541 * Architectures::
16542 @end menu
16543
16544 @node Native
16545 @section Native
16546
16547 This section describes details specific to particular native
16548 configurations.
16549
16550 @menu
16551 * HP-UX:: HP-UX
16552 * BSD libkvm Interface:: Debugging BSD kernel memory images
16553 * SVR4 Process Information:: SVR4 process information
16554 * DJGPP Native:: Features specific to the DJGPP port
16555 * Cygwin Native:: Features specific to the Cygwin port
16556 * Hurd Native:: Features specific to @sc{gnu} Hurd
16557 * Neutrino:: Features specific to QNX Neutrino
16558 * Darwin:: Features specific to Darwin
16559 @end menu
16560
16561 @node HP-UX
16562 @subsection HP-UX
16563
16564 On HP-UX systems, if you refer to a function or variable name that
16565 begins with a dollar sign, @value{GDBN} searches for a user or system
16566 name first, before it searches for a convenience variable.
16567
16568
16569 @node BSD libkvm Interface
16570 @subsection BSD libkvm Interface
16571
16572 @cindex libkvm
16573 @cindex kernel memory image
16574 @cindex kernel crash dump
16575
16576 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
16577 interface that provides a uniform interface for accessing kernel virtual
16578 memory images, including live systems and crash dumps. @value{GDBN}
16579 uses this interface to allow you to debug live kernels and kernel crash
16580 dumps on many native BSD configurations. This is implemented as a
16581 special @code{kvm} debugging target. For debugging a live system, load
16582 the currently running kernel into @value{GDBN} and connect to the
16583 @code{kvm} target:
16584
16585 @smallexample
16586 (@value{GDBP}) @b{target kvm}
16587 @end smallexample
16588
16589 For debugging crash dumps, provide the file name of the crash dump as an
16590 argument:
16591
16592 @smallexample
16593 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
16594 @end smallexample
16595
16596 Once connected to the @code{kvm} target, the following commands are
16597 available:
16598
16599 @table @code
16600 @kindex kvm
16601 @item kvm pcb
16602 Set current context from the @dfn{Process Control Block} (PCB) address.
16603
16604 @item kvm proc
16605 Set current context from proc address. This command isn't available on
16606 modern FreeBSD systems.
16607 @end table
16608
16609 @node SVR4 Process Information
16610 @subsection SVR4 Process Information
16611 @cindex /proc
16612 @cindex examine process image
16613 @cindex process info via @file{/proc}
16614
16615 Many versions of SVR4 and compatible systems provide a facility called
16616 @samp{/proc} that can be used to examine the image of a running
16617 process using file-system subroutines. If @value{GDBN} is configured
16618 for an operating system with this facility, the command @code{info
16619 proc} is available to report information about the process running
16620 your program, or about any process running on your system. @code{info
16621 proc} works only on SVR4 systems that include the @code{procfs} code.
16622 This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
16623 Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
16624
16625 @table @code
16626 @kindex info proc
16627 @cindex process ID
16628 @item info proc
16629 @itemx info proc @var{process-id}
16630 Summarize available information about any running process. If a
16631 process ID is specified by @var{process-id}, display information about
16632 that process; otherwise display information about the program being
16633 debugged. The summary includes the debugged process ID, the command
16634 line used to invoke it, its current working directory, and its
16635 executable file's absolute file name.
16636
16637 On some systems, @var{process-id} can be of the form
16638 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
16639 within a process. If the optional @var{pid} part is missing, it means
16640 a thread from the process being debugged (the leading @samp{/} still
16641 needs to be present, or else @value{GDBN} will interpret the number as
16642 a process ID rather than a thread ID).
16643
16644 @item info proc mappings
16645 @cindex memory address space mappings
16646 Report the memory address space ranges accessible in the program, with
16647 information on whether the process has read, write, or execute access
16648 rights to each range. On @sc{gnu}/Linux systems, each memory range
16649 includes the object file which is mapped to that range, instead of the
16650 memory access rights to that range.
16651
16652 @item info proc stat
16653 @itemx info proc status
16654 @cindex process detailed status information
16655 These subcommands are specific to @sc{gnu}/Linux systems. They show
16656 the process-related information, including the user ID and group ID;
16657 how many threads are there in the process; its virtual memory usage;
16658 the signals that are pending, blocked, and ignored; its TTY; its
16659 consumption of system and user time; its stack size; its @samp{nice}
16660 value; etc. For more information, see the @samp{proc} man page
16661 (type @kbd{man 5 proc} from your shell prompt).
16662
16663 @item info proc all
16664 Show all the information about the process described under all of the
16665 above @code{info proc} subcommands.
16666
16667 @ignore
16668 @comment These sub-options of 'info proc' were not included when
16669 @comment procfs.c was re-written. Keep their descriptions around
16670 @comment against the day when someone finds the time to put them back in.
16671 @kindex info proc times
16672 @item info proc times
16673 Starting time, user CPU time, and system CPU time for your program and
16674 its children.
16675
16676 @kindex info proc id
16677 @item info proc id
16678 Report on the process IDs related to your program: its own process ID,
16679 the ID of its parent, the process group ID, and the session ID.
16680 @end ignore
16681
16682 @item set procfs-trace
16683 @kindex set procfs-trace
16684 @cindex @code{procfs} API calls
16685 This command enables and disables tracing of @code{procfs} API calls.
16686
16687 @item show procfs-trace
16688 @kindex show procfs-trace
16689 Show the current state of @code{procfs} API call tracing.
16690
16691 @item set procfs-file @var{file}
16692 @kindex set procfs-file
16693 Tell @value{GDBN} to write @code{procfs} API trace to the named
16694 @var{file}. @value{GDBN} appends the trace info to the previous
16695 contents of the file. The default is to display the trace on the
16696 standard output.
16697
16698 @item show procfs-file
16699 @kindex show procfs-file
16700 Show the file to which @code{procfs} API trace is written.
16701
16702 @item proc-trace-entry
16703 @itemx proc-trace-exit
16704 @itemx proc-untrace-entry
16705 @itemx proc-untrace-exit
16706 @kindex proc-trace-entry
16707 @kindex proc-trace-exit
16708 @kindex proc-untrace-entry
16709 @kindex proc-untrace-exit
16710 These commands enable and disable tracing of entries into and exits
16711 from the @code{syscall} interface.
16712
16713 @item info pidlist
16714 @kindex info pidlist
16715 @cindex process list, QNX Neutrino
16716 For QNX Neutrino only, this command displays the list of all the
16717 processes and all the threads within each process.
16718
16719 @item info meminfo
16720 @kindex info meminfo
16721 @cindex mapinfo list, QNX Neutrino
16722 For QNX Neutrino only, this command displays the list of all mapinfos.
16723 @end table
16724
16725 @node DJGPP Native
16726 @subsection Features for Debugging @sc{djgpp} Programs
16727 @cindex @sc{djgpp} debugging
16728 @cindex native @sc{djgpp} debugging
16729 @cindex MS-DOS-specific commands
16730
16731 @cindex DPMI
16732 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
16733 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
16734 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
16735 top of real-mode DOS systems and their emulations.
16736
16737 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
16738 defines a few commands specific to the @sc{djgpp} port. This
16739 subsection describes those commands.
16740
16741 @table @code
16742 @kindex info dos
16743 @item info dos
16744 This is a prefix of @sc{djgpp}-specific commands which print
16745 information about the target system and important OS structures.
16746
16747 @kindex sysinfo
16748 @cindex MS-DOS system info
16749 @cindex free memory information (MS-DOS)
16750 @item info dos sysinfo
16751 This command displays assorted information about the underlying
16752 platform: the CPU type and features, the OS version and flavor, the
16753 DPMI version, and the available conventional and DPMI memory.
16754
16755 @cindex GDT
16756 @cindex LDT
16757 @cindex IDT
16758 @cindex segment descriptor tables
16759 @cindex descriptor tables display
16760 @item info dos gdt
16761 @itemx info dos ldt
16762 @itemx info dos idt
16763 These 3 commands display entries from, respectively, Global, Local,
16764 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
16765 tables are data structures which store a descriptor for each segment
16766 that is currently in use. The segment's selector is an index into a
16767 descriptor table; the table entry for that index holds the
16768 descriptor's base address and limit, and its attributes and access
16769 rights.
16770
16771 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
16772 segment (used for both data and the stack), and a DOS segment (which
16773 allows access to DOS/BIOS data structures and absolute addresses in
16774 conventional memory). However, the DPMI host will usually define
16775 additional segments in order to support the DPMI environment.
16776
16777 @cindex garbled pointers
16778 These commands allow to display entries from the descriptor tables.
16779 Without an argument, all entries from the specified table are
16780 displayed. An argument, which should be an integer expression, means
16781 display a single entry whose index is given by the argument. For
16782 example, here's a convenient way to display information about the
16783 debugged program's data segment:
16784
16785 @smallexample
16786 @exdent @code{(@value{GDBP}) info dos ldt $ds}
16787 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
16788 @end smallexample
16789
16790 @noindent
16791 This comes in handy when you want to see whether a pointer is outside
16792 the data segment's limit (i.e.@: @dfn{garbled}).
16793
16794 @cindex page tables display (MS-DOS)
16795 @item info dos pde
16796 @itemx info dos pte
16797 These two commands display entries from, respectively, the Page
16798 Directory and the Page Tables. Page Directories and Page Tables are
16799 data structures which control how virtual memory addresses are mapped
16800 into physical addresses. A Page Table includes an entry for every
16801 page of memory that is mapped into the program's address space; there
16802 may be several Page Tables, each one holding up to 4096 entries. A
16803 Page Directory has up to 4096 entries, one each for every Page Table
16804 that is currently in use.
16805
16806 Without an argument, @kbd{info dos pde} displays the entire Page
16807 Directory, and @kbd{info dos pte} displays all the entries in all of
16808 the Page Tables. An argument, an integer expression, given to the
16809 @kbd{info dos pde} command means display only that entry from the Page
16810 Directory table. An argument given to the @kbd{info dos pte} command
16811 means display entries from a single Page Table, the one pointed to by
16812 the specified entry in the Page Directory.
16813
16814 @cindex direct memory access (DMA) on MS-DOS
16815 These commands are useful when your program uses @dfn{DMA} (Direct
16816 Memory Access), which needs physical addresses to program the DMA
16817 controller.
16818
16819 These commands are supported only with some DPMI servers.
16820
16821 @cindex physical address from linear address
16822 @item info dos address-pte @var{addr}
16823 This command displays the Page Table entry for a specified linear
16824 address. The argument @var{addr} is a linear address which should
16825 already have the appropriate segment's base address added to it,
16826 because this command accepts addresses which may belong to @emph{any}
16827 segment. For example, here's how to display the Page Table entry for
16828 the page where a variable @code{i} is stored:
16829
16830 @smallexample
16831 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
16832 @exdent @code{Page Table entry for address 0x11a00d30:}
16833 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
16834 @end smallexample
16835
16836 @noindent
16837 This says that @code{i} is stored at offset @code{0xd30} from the page
16838 whose physical base address is @code{0x02698000}, and shows all the
16839 attributes of that page.
16840
16841 Note that you must cast the addresses of variables to a @code{char *},
16842 since otherwise the value of @code{__djgpp_base_address}, the base
16843 address of all variables and functions in a @sc{djgpp} program, will
16844 be added using the rules of C pointer arithmetics: if @code{i} is
16845 declared an @code{int}, @value{GDBN} will add 4 times the value of
16846 @code{__djgpp_base_address} to the address of @code{i}.
16847
16848 Here's another example, it displays the Page Table entry for the
16849 transfer buffer:
16850
16851 @smallexample
16852 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
16853 @exdent @code{Page Table entry for address 0x29110:}
16854 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
16855 @end smallexample
16856
16857 @noindent
16858 (The @code{+ 3} offset is because the transfer buffer's address is the
16859 3rd member of the @code{_go32_info_block} structure.) The output
16860 clearly shows that this DPMI server maps the addresses in conventional
16861 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
16862 linear (@code{0x29110}) addresses are identical.
16863
16864 This command is supported only with some DPMI servers.
16865 @end table
16866
16867 @cindex DOS serial data link, remote debugging
16868 In addition to native debugging, the DJGPP port supports remote
16869 debugging via a serial data link. The following commands are specific
16870 to remote serial debugging in the DJGPP port of @value{GDBN}.
16871
16872 @table @code
16873 @kindex set com1base
16874 @kindex set com1irq
16875 @kindex set com2base
16876 @kindex set com2irq
16877 @kindex set com3base
16878 @kindex set com3irq
16879 @kindex set com4base
16880 @kindex set com4irq
16881 @item set com1base @var{addr}
16882 This command sets the base I/O port address of the @file{COM1} serial
16883 port.
16884
16885 @item set com1irq @var{irq}
16886 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
16887 for the @file{COM1} serial port.
16888
16889 There are similar commands @samp{set com2base}, @samp{set com3irq},
16890 etc.@: for setting the port address and the @code{IRQ} lines for the
16891 other 3 COM ports.
16892
16893 @kindex show com1base
16894 @kindex show com1irq
16895 @kindex show com2base
16896 @kindex show com2irq
16897 @kindex show com3base
16898 @kindex show com3irq
16899 @kindex show com4base
16900 @kindex show com4irq
16901 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
16902 display the current settings of the base address and the @code{IRQ}
16903 lines used by the COM ports.
16904
16905 @item info serial
16906 @kindex info serial
16907 @cindex DOS serial port status
16908 This command prints the status of the 4 DOS serial ports. For each
16909 port, it prints whether it's active or not, its I/O base address and
16910 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
16911 counts of various errors encountered so far.
16912 @end table
16913
16914
16915 @node Cygwin Native
16916 @subsection Features for Debugging MS Windows PE Executables
16917 @cindex MS Windows debugging
16918 @cindex native Cygwin debugging
16919 @cindex Cygwin-specific commands
16920
16921 @value{GDBN} supports native debugging of MS Windows programs, including
16922 DLLs with and without symbolic debugging information.
16923
16924 @cindex Ctrl-BREAK, MS-Windows
16925 @cindex interrupt debuggee on MS-Windows
16926 MS-Windows programs that call @code{SetConsoleMode} to switch off the
16927 special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
16928 by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
16929 supports @kbd{C-@key{BREAK}} as an alternative interrupt key
16930 sequence, which can be used to interrupt the debuggee even if it
16931 ignores @kbd{C-c}.
16932
16933 There are various additional Cygwin-specific commands, described in
16934 this section. Working with DLLs that have no debugging symbols is
16935 described in @ref{Non-debug DLL Symbols}.
16936
16937 @table @code
16938 @kindex info w32
16939 @item info w32
16940 This is a prefix of MS Windows-specific commands which print
16941 information about the target system and important OS structures.
16942
16943 @item info w32 selector
16944 This command displays information returned by
16945 the Win32 API @code{GetThreadSelectorEntry} function.
16946 It takes an optional argument that is evaluated to
16947 a long value to give the information about this given selector.
16948 Without argument, this command displays information
16949 about the six segment registers.
16950
16951 @item info w32 thread-information-block
16952 This command displays thread specific information stored in the
16953 Thread Information Block (readable on the X86 CPU family using @code{$fs}
16954 selector for 32-bit programs and @code{$gs} for 64-bit programs).
16955
16956 @kindex info dll
16957 @item info dll
16958 This is a Cygwin-specific alias of @code{info shared}.
16959
16960 @kindex dll-symbols
16961 @item dll-symbols
16962 This command loads symbols from a dll similarly to
16963 add-sym command but without the need to specify a base address.
16964
16965 @kindex set cygwin-exceptions
16966 @cindex debugging the Cygwin DLL
16967 @cindex Cygwin DLL, debugging
16968 @item set cygwin-exceptions @var{mode}
16969 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
16970 happen inside the Cygwin DLL. If @var{mode} is @code{off},
16971 @value{GDBN} will delay recognition of exceptions, and may ignore some
16972 exceptions which seem to be caused by internal Cygwin DLL
16973 ``bookkeeping''. This option is meant primarily for debugging the
16974 Cygwin DLL itself; the default value is @code{off} to avoid annoying
16975 @value{GDBN} users with false @code{SIGSEGV} signals.
16976
16977 @kindex show cygwin-exceptions
16978 @item show cygwin-exceptions
16979 Displays whether @value{GDBN} will break on exceptions that happen
16980 inside the Cygwin DLL itself.
16981
16982 @kindex set new-console
16983 @item set new-console @var{mode}
16984 If @var{mode} is @code{on} the debuggee will
16985 be started in a new console on next start.
16986 If @var{mode} is @code{off}, the debuggee will
16987 be started in the same console as the debugger.
16988
16989 @kindex show new-console
16990 @item show new-console
16991 Displays whether a new console is used
16992 when the debuggee is started.
16993
16994 @kindex set new-group
16995 @item set new-group @var{mode}
16996 This boolean value controls whether the debuggee should
16997 start a new group or stay in the same group as the debugger.
16998 This affects the way the Windows OS handles
16999 @samp{Ctrl-C}.
17000
17001 @kindex show new-group
17002 @item show new-group
17003 Displays current value of new-group boolean.
17004
17005 @kindex set debugevents
17006 @item set debugevents
17007 This boolean value adds debug output concerning kernel events related
17008 to the debuggee seen by the debugger. This includes events that
17009 signal thread and process creation and exit, DLL loading and
17010 unloading, console interrupts, and debugging messages produced by the
17011 Windows @code{OutputDebugString} API call.
17012
17013 @kindex set debugexec
17014 @item set debugexec
17015 This boolean value adds debug output concerning execute events
17016 (such as resume thread) seen by the debugger.
17017
17018 @kindex set debugexceptions
17019 @item set debugexceptions
17020 This boolean value adds debug output concerning exceptions in the
17021 debuggee seen by the debugger.
17022
17023 @kindex set debugmemory
17024 @item set debugmemory
17025 This boolean value adds debug output concerning debuggee memory reads
17026 and writes by the debugger.
17027
17028 @kindex set shell
17029 @item set shell
17030 This boolean values specifies whether the debuggee is called
17031 via a shell or directly (default value is on).
17032
17033 @kindex show shell
17034 @item show shell
17035 Displays if the debuggee will be started with a shell.
17036
17037 @end table
17038
17039 @menu
17040 * Non-debug DLL Symbols:: Support for DLLs without debugging symbols
17041 @end menu
17042
17043 @node Non-debug DLL Symbols
17044 @subsubsection Support for DLLs without Debugging Symbols
17045 @cindex DLLs with no debugging symbols
17046 @cindex Minimal symbols and DLLs
17047
17048 Very often on windows, some of the DLLs that your program relies on do
17049 not include symbolic debugging information (for example,
17050 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
17051 symbols in a DLL, it relies on the minimal amount of symbolic
17052 information contained in the DLL's export table. This section
17053 describes working with such symbols, known internally to @value{GDBN} as
17054 ``minimal symbols''.
17055
17056 Note that before the debugged program has started execution, no DLLs
17057 will have been loaded. The easiest way around this problem is simply to
17058 start the program --- either by setting a breakpoint or letting the
17059 program run once to completion. It is also possible to force
17060 @value{GDBN} to load a particular DLL before starting the executable ---
17061 see the shared library information in @ref{Files}, or the
17062 @code{dll-symbols} command in @ref{Cygwin Native}. Currently,
17063 explicitly loading symbols from a DLL with no debugging information will
17064 cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
17065 which may adversely affect symbol lookup performance.
17066
17067 @subsubsection DLL Name Prefixes
17068
17069 In keeping with the naming conventions used by the Microsoft debugging
17070 tools, DLL export symbols are made available with a prefix based on the
17071 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
17072 also entered into the symbol table, so @code{CreateFileA} is often
17073 sufficient. In some cases there will be name clashes within a program
17074 (particularly if the executable itself includes full debugging symbols)
17075 necessitating the use of the fully qualified name when referring to the
17076 contents of the DLL. Use single-quotes around the name to avoid the
17077 exclamation mark (``!'') being interpreted as a language operator.
17078
17079 Note that the internal name of the DLL may be all upper-case, even
17080 though the file name of the DLL is lower-case, or vice-versa. Since
17081 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
17082 some confusion. If in doubt, try the @code{info functions} and
17083 @code{info variables} commands or even @code{maint print msymbols}
17084 (@pxref{Symbols}). Here's an example:
17085
17086 @smallexample
17087 (@value{GDBP}) info function CreateFileA
17088 All functions matching regular expression "CreateFileA":
17089
17090 Non-debugging symbols:
17091 0x77e885f4 CreateFileA
17092 0x77e885f4 KERNEL32!CreateFileA
17093 @end smallexample
17094
17095 @smallexample
17096 (@value{GDBP}) info function !
17097 All functions matching regular expression "!":
17098
17099 Non-debugging symbols:
17100 0x6100114c cygwin1!__assert
17101 0x61004034 cygwin1!_dll_crt0@@0
17102 0x61004240 cygwin1!dll_crt0(per_process *)
17103 [etc...]
17104 @end smallexample
17105
17106 @subsubsection Working with Minimal Symbols
17107
17108 Symbols extracted from a DLL's export table do not contain very much
17109 type information. All that @value{GDBN} can do is guess whether a symbol
17110 refers to a function or variable depending on the linker section that
17111 contains the symbol. Also note that the actual contents of the memory
17112 contained in a DLL are not available unless the program is running. This
17113 means that you cannot examine the contents of a variable or disassemble
17114 a function within a DLL without a running program.
17115
17116 Variables are generally treated as pointers and dereferenced
17117 automatically. For this reason, it is often necessary to prefix a
17118 variable name with the address-of operator (``&'') and provide explicit
17119 type information in the command. Here's an example of the type of
17120 problem:
17121
17122 @smallexample
17123 (@value{GDBP}) print 'cygwin1!__argv'
17124 $1 = 268572168
17125 @end smallexample
17126
17127 @smallexample
17128 (@value{GDBP}) x 'cygwin1!__argv'
17129 0x10021610: "\230y\""
17130 @end smallexample
17131
17132 And two possible solutions:
17133
17134 @smallexample
17135 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
17136 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
17137 @end smallexample
17138
17139 @smallexample
17140 (@value{GDBP}) x/2x &'cygwin1!__argv'
17141 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
17142 (@value{GDBP}) x/x 0x10021608
17143 0x10021608: 0x0022fd98
17144 (@value{GDBP}) x/s 0x0022fd98
17145 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
17146 @end smallexample
17147
17148 Setting a break point within a DLL is possible even before the program
17149 starts execution. However, under these circumstances, @value{GDBN} can't
17150 examine the initial instructions of the function in order to skip the
17151 function's frame set-up code. You can work around this by using ``*&''
17152 to set the breakpoint at a raw memory address:
17153
17154 @smallexample
17155 (@value{GDBP}) break *&'python22!PyOS_Readline'
17156 Breakpoint 1 at 0x1e04eff0
17157 @end smallexample
17158
17159 The author of these extensions is not entirely convinced that setting a
17160 break point within a shared DLL like @file{kernel32.dll} is completely
17161 safe.
17162
17163 @node Hurd Native
17164 @subsection Commands Specific to @sc{gnu} Hurd Systems
17165 @cindex @sc{gnu} Hurd debugging
17166
17167 This subsection describes @value{GDBN} commands specific to the
17168 @sc{gnu} Hurd native debugging.
17169
17170 @table @code
17171 @item set signals
17172 @itemx set sigs
17173 @kindex set signals@r{, Hurd command}
17174 @kindex set sigs@r{, Hurd command}
17175 This command toggles the state of inferior signal interception by
17176 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
17177 affected by this command. @code{sigs} is a shorthand alias for
17178 @code{signals}.
17179
17180 @item show signals
17181 @itemx show sigs
17182 @kindex show signals@r{, Hurd command}
17183 @kindex show sigs@r{, Hurd command}
17184 Show the current state of intercepting inferior's signals.
17185
17186 @item set signal-thread
17187 @itemx set sigthread
17188 @kindex set signal-thread
17189 @kindex set sigthread
17190 This command tells @value{GDBN} which thread is the @code{libc} signal
17191 thread. That thread is run when a signal is delivered to a running
17192 process. @code{set sigthread} is the shorthand alias of @code{set
17193 signal-thread}.
17194
17195 @item show signal-thread
17196 @itemx show sigthread
17197 @kindex show signal-thread
17198 @kindex show sigthread
17199 These two commands show which thread will run when the inferior is
17200 delivered a signal.
17201
17202 @item set stopped
17203 @kindex set stopped@r{, Hurd command}
17204 This commands tells @value{GDBN} that the inferior process is stopped,
17205 as with the @code{SIGSTOP} signal. The stopped process can be
17206 continued by delivering a signal to it.
17207
17208 @item show stopped
17209 @kindex show stopped@r{, Hurd command}
17210 This command shows whether @value{GDBN} thinks the debuggee is
17211 stopped.
17212
17213 @item set exceptions
17214 @kindex set exceptions@r{, Hurd command}
17215 Use this command to turn off trapping of exceptions in the inferior.
17216 When exception trapping is off, neither breakpoints nor
17217 single-stepping will work. To restore the default, set exception
17218 trapping on.
17219
17220 @item show exceptions
17221 @kindex show exceptions@r{, Hurd command}
17222 Show the current state of trapping exceptions in the inferior.
17223
17224 @item set task pause
17225 @kindex set task@r{, Hurd commands}
17226 @cindex task attributes (@sc{gnu} Hurd)
17227 @cindex pause current task (@sc{gnu} Hurd)
17228 This command toggles task suspension when @value{GDBN} has control.
17229 Setting it to on takes effect immediately, and the task is suspended
17230 whenever @value{GDBN} gets control. Setting it to off will take
17231 effect the next time the inferior is continued. If this option is set
17232 to off, you can use @code{set thread default pause on} or @code{set
17233 thread pause on} (see below) to pause individual threads.
17234
17235 @item show task pause
17236 @kindex show task@r{, Hurd commands}
17237 Show the current state of task suspension.
17238
17239 @item set task detach-suspend-count
17240 @cindex task suspend count
17241 @cindex detach from task, @sc{gnu} Hurd
17242 This command sets the suspend count the task will be left with when
17243 @value{GDBN} detaches from it.
17244
17245 @item show task detach-suspend-count
17246 Show the suspend count the task will be left with when detaching.
17247
17248 @item set task exception-port
17249 @itemx set task excp
17250 @cindex task exception port, @sc{gnu} Hurd
17251 This command sets the task exception port to which @value{GDBN} will
17252 forward exceptions. The argument should be the value of the @dfn{send
17253 rights} of the task. @code{set task excp} is a shorthand alias.
17254
17255 @item set noninvasive
17256 @cindex noninvasive task options
17257 This command switches @value{GDBN} to a mode that is the least
17258 invasive as far as interfering with the inferior is concerned. This
17259 is the same as using @code{set task pause}, @code{set exceptions}, and
17260 @code{set signals} to values opposite to the defaults.
17261
17262 @item info send-rights
17263 @itemx info receive-rights
17264 @itemx info port-rights
17265 @itemx info port-sets
17266 @itemx info dead-names
17267 @itemx info ports
17268 @itemx info psets
17269 @cindex send rights, @sc{gnu} Hurd
17270 @cindex receive rights, @sc{gnu} Hurd
17271 @cindex port rights, @sc{gnu} Hurd
17272 @cindex port sets, @sc{gnu} Hurd
17273 @cindex dead names, @sc{gnu} Hurd
17274 These commands display information about, respectively, send rights,
17275 receive rights, port rights, port sets, and dead names of a task.
17276 There are also shorthand aliases: @code{info ports} for @code{info
17277 port-rights} and @code{info psets} for @code{info port-sets}.
17278
17279 @item set thread pause
17280 @kindex set thread@r{, Hurd command}
17281 @cindex thread properties, @sc{gnu} Hurd
17282 @cindex pause current thread (@sc{gnu} Hurd)
17283 This command toggles current thread suspension when @value{GDBN} has
17284 control. Setting it to on takes effect immediately, and the current
17285 thread is suspended whenever @value{GDBN} gets control. Setting it to
17286 off will take effect the next time the inferior is continued.
17287 Normally, this command has no effect, since when @value{GDBN} has
17288 control, the whole task is suspended. However, if you used @code{set
17289 task pause off} (see above), this command comes in handy to suspend
17290 only the current thread.
17291
17292 @item show thread pause
17293 @kindex show thread@r{, Hurd command}
17294 This command shows the state of current thread suspension.
17295
17296 @item set thread run
17297 This command sets whether the current thread is allowed to run.
17298
17299 @item show thread run
17300 Show whether the current thread is allowed to run.
17301
17302 @item set thread detach-suspend-count
17303 @cindex thread suspend count, @sc{gnu} Hurd
17304 @cindex detach from thread, @sc{gnu} Hurd
17305 This command sets the suspend count @value{GDBN} will leave on a
17306 thread when detaching. This number is relative to the suspend count
17307 found by @value{GDBN} when it notices the thread; use @code{set thread
17308 takeover-suspend-count} to force it to an absolute value.
17309
17310 @item show thread detach-suspend-count
17311 Show the suspend count @value{GDBN} will leave on the thread when
17312 detaching.
17313
17314 @item set thread exception-port
17315 @itemx set thread excp
17316 Set the thread exception port to which to forward exceptions. This
17317 overrides the port set by @code{set task exception-port} (see above).
17318 @code{set thread excp} is the shorthand alias.
17319
17320 @item set thread takeover-suspend-count
17321 Normally, @value{GDBN}'s thread suspend counts are relative to the
17322 value @value{GDBN} finds when it notices each thread. This command
17323 changes the suspend counts to be absolute instead.
17324
17325 @item set thread default
17326 @itemx show thread default
17327 @cindex thread default settings, @sc{gnu} Hurd
17328 Each of the above @code{set thread} commands has a @code{set thread
17329 default} counterpart (e.g., @code{set thread default pause}, @code{set
17330 thread default exception-port}, etc.). The @code{thread default}
17331 variety of commands sets the default thread properties for all
17332 threads; you can then change the properties of individual threads with
17333 the non-default commands.
17334 @end table
17335
17336
17337 @node Neutrino
17338 @subsection QNX Neutrino
17339 @cindex QNX Neutrino
17340
17341 @value{GDBN} provides the following commands specific to the QNX
17342 Neutrino target:
17343
17344 @table @code
17345 @item set debug nto-debug
17346 @kindex set debug nto-debug
17347 When set to on, enables debugging messages specific to the QNX
17348 Neutrino support.
17349
17350 @item show debug nto-debug
17351 @kindex show debug nto-debug
17352 Show the current state of QNX Neutrino messages.
17353 @end table
17354
17355 @node Darwin
17356 @subsection Darwin
17357 @cindex Darwin
17358
17359 @value{GDBN} provides the following commands specific to the Darwin target:
17360
17361 @table @code
17362 @item set debug darwin @var{num}
17363 @kindex set debug darwin
17364 When set to a non zero value, enables debugging messages specific to
17365 the Darwin support. Higher values produce more verbose output.
17366
17367 @item show debug darwin
17368 @kindex show debug darwin
17369 Show the current state of Darwin messages.
17370
17371 @item set debug mach-o @var{num}
17372 @kindex set debug mach-o
17373 When set to a non zero value, enables debugging messages while
17374 @value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
17375 file format used on Darwin for object and executable files.) Higher
17376 values produce more verbose output. This is a command to diagnose
17377 problems internal to @value{GDBN} and should not be needed in normal
17378 usage.
17379
17380 @item show debug mach-o
17381 @kindex show debug mach-o
17382 Show the current state of Mach-O file messages.
17383
17384 @item set mach-exceptions on
17385 @itemx set mach-exceptions off
17386 @kindex set mach-exceptions
17387 On Darwin, faults are first reported as a Mach exception and are then
17388 mapped to a Posix signal. Use this command to turn on trapping of
17389 Mach exceptions in the inferior. This might be sometimes useful to
17390 better understand the cause of a fault. The default is off.
17391
17392 @item show mach-exceptions
17393 @kindex show mach-exceptions
17394 Show the current state of exceptions trapping.
17395 @end table
17396
17397
17398 @node Embedded OS
17399 @section Embedded Operating Systems
17400
17401 This section describes configurations involving the debugging of
17402 embedded operating systems that are available for several different
17403 architectures.
17404
17405 @menu
17406 * VxWorks:: Using @value{GDBN} with VxWorks
17407 @end menu
17408
17409 @value{GDBN} includes the ability to debug programs running on
17410 various real-time operating systems.
17411
17412 @node VxWorks
17413 @subsection Using @value{GDBN} with VxWorks
17414
17415 @cindex VxWorks
17416
17417 @table @code
17418
17419 @kindex target vxworks
17420 @item target vxworks @var{machinename}
17421 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
17422 is the target system's machine name or IP address.
17423
17424 @end table
17425
17426 On VxWorks, @code{load} links @var{filename} dynamically on the
17427 current target system as well as adding its symbols in @value{GDBN}.
17428
17429 @value{GDBN} enables developers to spawn and debug tasks running on networked
17430 VxWorks targets from a Unix host. Already-running tasks spawned from
17431 the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
17432 both the Unix host and on the VxWorks target. The program
17433 @code{@value{GDBP}} is installed and executed on the Unix host. (It may be
17434 installed with the name @code{vxgdb}, to distinguish it from a
17435 @value{GDBN} for debugging programs on the host itself.)
17436
17437 @table @code
17438 @item VxWorks-timeout @var{args}
17439 @kindex vxworks-timeout
17440 All VxWorks-based targets now support the option @code{vxworks-timeout}.
17441 This option is set by the user, and @var{args} represents the number of
17442 seconds @value{GDBN} waits for responses to rpc's. You might use this if
17443 your VxWorks target is a slow software simulator or is on the far side
17444 of a thin network line.
17445 @end table
17446
17447 The following information on connecting to VxWorks was current when
17448 this manual was produced; newer releases of VxWorks may use revised
17449 procedures.
17450
17451 @findex INCLUDE_RDB
17452 To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
17453 to include the remote debugging interface routines in the VxWorks
17454 library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
17455 VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
17456 kernel. The resulting kernel contains @file{rdb.a}, and spawns the
17457 source debugging task @code{tRdbTask} when VxWorks is booted. For more
17458 information on configuring and remaking VxWorks, see the manufacturer's
17459 manual.
17460 @c VxWorks, see the @cite{VxWorks Programmer's Guide}.
17461
17462 Once you have included @file{rdb.a} in your VxWorks system image and set
17463 your Unix execution search path to find @value{GDBN}, you are ready to
17464 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
17465 @code{vxgdb}, depending on your installation).
17466
17467 @value{GDBN} comes up showing the prompt:
17468
17469 @smallexample
17470 (vxgdb)
17471 @end smallexample
17472
17473 @menu
17474 * VxWorks Connection:: Connecting to VxWorks
17475 * VxWorks Download:: VxWorks download
17476 * VxWorks Attach:: Running tasks
17477 @end menu
17478
17479 @node VxWorks Connection
17480 @subsubsection Connecting to VxWorks
17481
17482 The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
17483 network. To connect to a target whose host name is ``@code{tt}'', type:
17484
17485 @smallexample
17486 (vxgdb) target vxworks tt
17487 @end smallexample
17488
17489 @need 750
17490 @value{GDBN} displays messages like these:
17491
17492 @smallexample
17493 Attaching remote machine across net...
17494 Connected to tt.
17495 @end smallexample
17496
17497 @need 1000
17498 @value{GDBN} then attempts to read the symbol tables of any object modules
17499 loaded into the VxWorks target since it was last booted. @value{GDBN} locates
17500 these files by searching the directories listed in the command search
17501 path (@pxref{Environment, ,Your Program's Environment}); if it fails
17502 to find an object file, it displays a message such as:
17503
17504 @smallexample
17505 prog.o: No such file or directory.
17506 @end smallexample
17507
17508 When this happens, add the appropriate directory to the search path with
17509 the @value{GDBN} command @code{path}, and execute the @code{target}
17510 command again.
17511
17512 @node VxWorks Download
17513 @subsubsection VxWorks Download
17514
17515 @cindex download to VxWorks
17516 If you have connected to the VxWorks target and you want to debug an
17517 object that has not yet been loaded, you can use the @value{GDBN}
17518 @code{load} command to download a file from Unix to VxWorks
17519 incrementally. The object file given as an argument to the @code{load}
17520 command is actually opened twice: first by the VxWorks target in order
17521 to download the code, then by @value{GDBN} in order to read the symbol
17522 table. This can lead to problems if the current working directories on
17523 the two systems differ. If both systems have NFS mounted the same
17524 filesystems, you can avoid these problems by using absolute paths.
17525 Otherwise, it is simplest to set the working directory on both systems
17526 to the directory in which the object file resides, and then to reference
17527 the file by its name, without any path. For instance, a program
17528 @file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
17529 and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
17530 program, type this on VxWorks:
17531
17532 @smallexample
17533 -> cd "@var{vxpath}/vw/demo/rdb"
17534 @end smallexample
17535
17536 @noindent
17537 Then, in @value{GDBN}, type:
17538
17539 @smallexample
17540 (vxgdb) cd @var{hostpath}/vw/demo/rdb
17541 (vxgdb) load prog.o
17542 @end smallexample
17543
17544 @value{GDBN} displays a response similar to this:
17545
17546 @smallexample
17547 Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
17548 @end smallexample
17549
17550 You can also use the @code{load} command to reload an object module
17551 after editing and recompiling the corresponding source file. Note that
17552 this makes @value{GDBN} delete all currently-defined breakpoints,
17553 auto-displays, and convenience variables, and to clear the value
17554 history. (This is necessary in order to preserve the integrity of
17555 debugger's data structures that reference the target system's symbol
17556 table.)
17557
17558 @node VxWorks Attach
17559 @subsubsection Running Tasks
17560
17561 @cindex running VxWorks tasks
17562 You can also attach to an existing task using the @code{attach} command as
17563 follows:
17564
17565 @smallexample
17566 (vxgdb) attach @var{task}
17567 @end smallexample
17568
17569 @noindent
17570 where @var{task} is the VxWorks hexadecimal task ID. The task can be running
17571 or suspended when you attach to it. Running tasks are suspended at
17572 the time of attachment.
17573
17574 @node Embedded Processors
17575 @section Embedded Processors
17576
17577 This section goes into details specific to particular embedded
17578 configurations.
17579
17580 @cindex send command to simulator
17581 Whenever a specific embedded processor has a simulator, @value{GDBN}
17582 allows to send an arbitrary command to the simulator.
17583
17584 @table @code
17585 @item sim @var{command}
17586 @kindex sim@r{, a command}
17587 Send an arbitrary @var{command} string to the simulator. Consult the
17588 documentation for the specific simulator in use for information about
17589 acceptable commands.
17590 @end table
17591
17592
17593 @menu
17594 * ARM:: ARM RDI
17595 * M32R/D:: Renesas M32R/D
17596 * M68K:: Motorola M68K
17597 * MicroBlaze:: Xilinx MicroBlaze
17598 * MIPS Embedded:: MIPS Embedded
17599 * OpenRISC 1000:: OpenRisc 1000
17600 * PA:: HP PA Embedded
17601 * PowerPC Embedded:: PowerPC Embedded
17602 * Sparclet:: Tsqware Sparclet
17603 * Sparclite:: Fujitsu Sparclite
17604 * Z8000:: Zilog Z8000
17605 * AVR:: Atmel AVR
17606 * CRIS:: CRIS
17607 * Super-H:: Renesas Super-H
17608 @end menu
17609
17610 @node ARM
17611 @subsection ARM
17612 @cindex ARM RDI
17613
17614 @table @code
17615 @kindex target rdi
17616 @item target rdi @var{dev}
17617 ARM Angel monitor, via RDI library interface to ADP protocol. You may
17618 use this target to communicate with both boards running the Angel
17619 monitor, or with the EmbeddedICE JTAG debug device.
17620
17621 @kindex target rdp
17622 @item target rdp @var{dev}
17623 ARM Demon monitor.
17624
17625 @end table
17626
17627 @value{GDBN} provides the following ARM-specific commands:
17628
17629 @table @code
17630 @item set arm disassembler
17631 @kindex set arm
17632 This commands selects from a list of disassembly styles. The
17633 @code{"std"} style is the standard style.
17634
17635 @item show arm disassembler
17636 @kindex show arm
17637 Show the current disassembly style.
17638
17639 @item set arm apcs32
17640 @cindex ARM 32-bit mode
17641 This command toggles ARM operation mode between 32-bit and 26-bit.
17642
17643 @item show arm apcs32
17644 Display the current usage of the ARM 32-bit mode.
17645
17646 @item set arm fpu @var{fputype}
17647 This command sets the ARM floating-point unit (FPU) type. The
17648 argument @var{fputype} can be one of these:
17649
17650 @table @code
17651 @item auto
17652 Determine the FPU type by querying the OS ABI.
17653 @item softfpa
17654 Software FPU, with mixed-endian doubles on little-endian ARM
17655 processors.
17656 @item fpa
17657 GCC-compiled FPA co-processor.
17658 @item softvfp
17659 Software FPU with pure-endian doubles.
17660 @item vfp
17661 VFP co-processor.
17662 @end table
17663
17664 @item show arm fpu
17665 Show the current type of the FPU.
17666
17667 @item set arm abi
17668 This command forces @value{GDBN} to use the specified ABI.
17669
17670 @item show arm abi
17671 Show the currently used ABI.
17672
17673 @item set arm fallback-mode (arm|thumb|auto)
17674 @value{GDBN} uses the symbol table, when available, to determine
17675 whether instructions are ARM or Thumb. This command controls
17676 @value{GDBN}'s default behavior when the symbol table is not
17677 available. The default is @samp{auto}, which causes @value{GDBN} to
17678 use the current execution mode (from the @code{T} bit in the @code{CPSR}
17679 register).
17680
17681 @item show arm fallback-mode
17682 Show the current fallback instruction mode.
17683
17684 @item set arm force-mode (arm|thumb|auto)
17685 This command overrides use of the symbol table to determine whether
17686 instructions are ARM or Thumb. The default is @samp{auto}, which
17687 causes @value{GDBN} to use the symbol table and then the setting
17688 of @samp{set arm fallback-mode}.
17689
17690 @item show arm force-mode
17691 Show the current forced instruction mode.
17692
17693 @item set debug arm
17694 Toggle whether to display ARM-specific debugging messages from the ARM
17695 target support subsystem.
17696
17697 @item show debug arm
17698 Show whether ARM-specific debugging messages are enabled.
17699 @end table
17700
17701 The following commands are available when an ARM target is debugged
17702 using the RDI interface:
17703
17704 @table @code
17705 @item rdilogfile @r{[}@var{file}@r{]}
17706 @kindex rdilogfile
17707 @cindex ADP (Angel Debugger Protocol) logging
17708 Set the filename for the ADP (Angel Debugger Protocol) packet log.
17709 With an argument, sets the log file to the specified @var{file}. With
17710 no argument, show the current log file name. The default log file is
17711 @file{rdi.log}.
17712
17713 @item rdilogenable @r{[}@var{arg}@r{]}
17714 @kindex rdilogenable
17715 Control logging of ADP packets. With an argument of 1 or @code{"yes"}
17716 enables logging, with an argument 0 or @code{"no"} disables it. With
17717 no arguments displays the current setting. When logging is enabled,
17718 ADP packets exchanged between @value{GDBN} and the RDI target device
17719 are logged to a file.
17720
17721 @item set rdiromatzero
17722 @kindex set rdiromatzero
17723 @cindex ROM at zero address, RDI
17724 Tell @value{GDBN} whether the target has ROM at address 0. If on,
17725 vector catching is disabled, so that zero address can be used. If off
17726 (the default), vector catching is enabled. For this command to take
17727 effect, it needs to be invoked prior to the @code{target rdi} command.
17728
17729 @item show rdiromatzero
17730 @kindex show rdiromatzero
17731 Show the current setting of ROM at zero address.
17732
17733 @item set rdiheartbeat
17734 @kindex set rdiheartbeat
17735 @cindex RDI heartbeat
17736 Enable or disable RDI heartbeat packets. It is not recommended to
17737 turn on this option, since it confuses ARM and EPI JTAG interface, as
17738 well as the Angel monitor.
17739
17740 @item show rdiheartbeat
17741 @kindex show rdiheartbeat
17742 Show the setting of RDI heartbeat packets.
17743 @end table
17744
17745 @table @code
17746 @item target sim @r{[}@var{simargs}@r{]} @dots{}
17747 The @value{GDBN} ARM simulator accepts the following optional arguments.
17748
17749 @table @code
17750 @item --swi-support=@var{type}
17751 Tell the simulator which SWI interfaces to support.
17752 @var{type} may be a comma separated list of the following values.
17753 The default value is @code{all}.
17754
17755 @table @code
17756 @item none
17757 @item demon
17758 @item angel
17759 @item redboot
17760 @item all
17761 @end table
17762 @end table
17763 @end table
17764
17765 @node M32R/D
17766 @subsection Renesas M32R/D and M32R/SDI
17767
17768 @table @code
17769 @kindex target m32r
17770 @item target m32r @var{dev}
17771 Renesas M32R/D ROM monitor.
17772
17773 @kindex target m32rsdi
17774 @item target m32rsdi @var{dev}
17775 Renesas M32R SDI server, connected via parallel port to the board.
17776 @end table
17777
17778 The following @value{GDBN} commands are specific to the M32R monitor:
17779
17780 @table @code
17781 @item set download-path @var{path}
17782 @kindex set download-path
17783 @cindex find downloadable @sc{srec} files (M32R)
17784 Set the default path for finding downloadable @sc{srec} files.
17785
17786 @item show download-path
17787 @kindex show download-path
17788 Show the default path for downloadable @sc{srec} files.
17789
17790 @item set board-address @var{addr}
17791 @kindex set board-address
17792 @cindex M32-EVA target board address
17793 Set the IP address for the M32R-EVA target board.
17794
17795 @item show board-address
17796 @kindex show board-address
17797 Show the current IP address of the target board.
17798
17799 @item set server-address @var{addr}
17800 @kindex set server-address
17801 @cindex download server address (M32R)
17802 Set the IP address for the download server, which is the @value{GDBN}'s
17803 host machine.
17804
17805 @item show server-address
17806 @kindex show server-address
17807 Display the IP address of the download server.
17808
17809 @item upload @r{[}@var{file}@r{]}
17810 @kindex upload@r{, M32R}
17811 Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
17812 upload capability. If no @var{file} argument is given, the current
17813 executable file is uploaded.
17814
17815 @item tload @r{[}@var{file}@r{]}
17816 @kindex tload@r{, M32R}
17817 Test the @code{upload} command.
17818 @end table
17819
17820 The following commands are available for M32R/SDI:
17821
17822 @table @code
17823 @item sdireset
17824 @kindex sdireset
17825 @cindex reset SDI connection, M32R
17826 This command resets the SDI connection.
17827
17828 @item sdistatus
17829 @kindex sdistatus
17830 This command shows the SDI connection status.
17831
17832 @item debug_chaos
17833 @kindex debug_chaos
17834 @cindex M32R/Chaos debugging
17835 Instructs the remote that M32R/Chaos debugging is to be used.
17836
17837 @item use_debug_dma
17838 @kindex use_debug_dma
17839 Instructs the remote to use the DEBUG_DMA method of accessing memory.
17840
17841 @item use_mon_code
17842 @kindex use_mon_code
17843 Instructs the remote to use the MON_CODE method of accessing memory.
17844
17845 @item use_ib_break
17846 @kindex use_ib_break
17847 Instructs the remote to set breakpoints by IB break.
17848
17849 @item use_dbt_break
17850 @kindex use_dbt_break
17851 Instructs the remote to set breakpoints by DBT.
17852 @end table
17853
17854 @node M68K
17855 @subsection M68k
17856
17857 The Motorola m68k configuration includes ColdFire support, and a
17858 target command for the following ROM monitor.
17859
17860 @table @code
17861
17862 @kindex target dbug
17863 @item target dbug @var{dev}
17864 dBUG ROM monitor for Motorola ColdFire.
17865
17866 @end table
17867
17868 @node MicroBlaze
17869 @subsection MicroBlaze
17870 @cindex Xilinx MicroBlaze
17871 @cindex XMD, Xilinx Microprocessor Debugger
17872
17873 The MicroBlaze is a soft-core processor supported on various Xilinx
17874 FPGAs, such as Spartan or Virtex series. Boards with these processors
17875 usually have JTAG ports which connect to a host system running the Xilinx
17876 Embedded Development Kit (EDK) or Software Development Kit (SDK).
17877 This host system is used to download the configuration bitstream to
17878 the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
17879 communicates with the target board using the JTAG interface and
17880 presents a @code{gdbserver} interface to the board. By default
17881 @code{xmd} uses port @code{1234}. (While it is possible to change
17882 this default port, it requires the use of undocumented @code{xmd}
17883 commands. Contact Xilinx support if you need to do this.)
17884
17885 Use these GDB commands to connect to the MicroBlaze target processor.
17886
17887 @table @code
17888 @item target remote :1234
17889 Use this command to connect to the target if you are running @value{GDBN}
17890 on the same system as @code{xmd}.
17891
17892 @item target remote @var{xmd-host}:1234
17893 Use this command to connect to the target if it is connected to @code{xmd}
17894 running on a different system named @var{xmd-host}.
17895
17896 @item load
17897 Use this command to download a program to the MicroBlaze target.
17898
17899 @item set debug microblaze @var{n}
17900 Enable MicroBlaze-specific debugging messages if non-zero.
17901
17902 @item show debug microblaze @var{n}
17903 Show MicroBlaze-specific debugging level.
17904 @end table
17905
17906 @node MIPS Embedded
17907 @subsection MIPS Embedded
17908
17909 @cindex MIPS boards
17910 @value{GDBN} can use the MIPS remote debugging protocol to talk to a
17911 MIPS board attached to a serial line. This is available when
17912 you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
17913
17914 @need 1000
17915 Use these @value{GDBN} commands to specify the connection to your target board:
17916
17917 @table @code
17918 @item target mips @var{port}
17919 @kindex target mips @var{port}
17920 To run a program on the board, start up @code{@value{GDBP}} with the
17921 name of your program as the argument. To connect to the board, use the
17922 command @samp{target mips @var{port}}, where @var{port} is the name of
17923 the serial port connected to the board. If the program has not already
17924 been downloaded to the board, you may use the @code{load} command to
17925 download it. You can then use all the usual @value{GDBN} commands.
17926
17927 For example, this sequence connects to the target board through a serial
17928 port, and loads and runs a program called @var{prog} through the
17929 debugger:
17930
17931 @smallexample
17932 host$ @value{GDBP} @var{prog}
17933 @value{GDBN} is free software and @dots{}
17934 (@value{GDBP}) target mips /dev/ttyb
17935 (@value{GDBP}) load @var{prog}
17936 (@value{GDBP}) run
17937 @end smallexample
17938
17939 @item target mips @var{hostname}:@var{portnumber}
17940 On some @value{GDBN} host configurations, you can specify a TCP
17941 connection (for instance, to a serial line managed by a terminal
17942 concentrator) instead of a serial port, using the syntax
17943 @samp{@var{hostname}:@var{portnumber}}.
17944
17945 @item target pmon @var{port}
17946 @kindex target pmon @var{port}
17947 PMON ROM monitor.
17948
17949 @item target ddb @var{port}
17950 @kindex target ddb @var{port}
17951 NEC's DDB variant of PMON for Vr4300.
17952
17953 @item target lsi @var{port}
17954 @kindex target lsi @var{port}
17955 LSI variant of PMON.
17956
17957 @kindex target r3900
17958 @item target r3900 @var{dev}
17959 Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
17960
17961 @kindex target array
17962 @item target array @var{dev}
17963 Array Tech LSI33K RAID controller board.
17964
17965 @end table
17966
17967
17968 @noindent
17969 @value{GDBN} also supports these special commands for MIPS targets:
17970
17971 @table @code
17972 @item set mipsfpu double
17973 @itemx set mipsfpu single
17974 @itemx set mipsfpu none
17975 @itemx set mipsfpu auto
17976 @itemx show mipsfpu
17977 @kindex set mipsfpu
17978 @kindex show mipsfpu
17979 @cindex MIPS remote floating point
17980 @cindex floating point, MIPS remote
17981 If your target board does not support the MIPS floating point
17982 coprocessor, you should use the command @samp{set mipsfpu none} (if you
17983 need this, you may wish to put the command in your @value{GDBN} init
17984 file). This tells @value{GDBN} how to find the return value of
17985 functions which return floating point values. It also allows
17986 @value{GDBN} to avoid saving the floating point registers when calling
17987 functions on the board. If you are using a floating point coprocessor
17988 with only single precision floating point support, as on the @sc{r4650}
17989 processor, use the command @samp{set mipsfpu single}. The default
17990 double precision floating point coprocessor may be selected using
17991 @samp{set mipsfpu double}.
17992
17993 In previous versions the only choices were double precision or no
17994 floating point, so @samp{set mipsfpu on} will select double precision
17995 and @samp{set mipsfpu off} will select no floating point.
17996
17997 As usual, you can inquire about the @code{mipsfpu} variable with
17998 @samp{show mipsfpu}.
17999
18000 @item set timeout @var{seconds}
18001 @itemx set retransmit-timeout @var{seconds}
18002 @itemx show timeout
18003 @itemx show retransmit-timeout
18004 @cindex @code{timeout}, MIPS protocol
18005 @cindex @code{retransmit-timeout}, MIPS protocol
18006 @kindex set timeout
18007 @kindex show timeout
18008 @kindex set retransmit-timeout
18009 @kindex show retransmit-timeout
18010 You can control the timeout used while waiting for a packet, in the MIPS
18011 remote protocol, with the @code{set timeout @var{seconds}} command. The
18012 default is 5 seconds. Similarly, you can control the timeout used while
18013 waiting for an acknowledgment of a packet with the @code{set
18014 retransmit-timeout @var{seconds}} command. The default is 3 seconds.
18015 You can inspect both values with @code{show timeout} and @code{show
18016 retransmit-timeout}. (These commands are @emph{only} available when
18017 @value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
18018
18019 The timeout set by @code{set timeout} does not apply when @value{GDBN}
18020 is waiting for your program to stop. In that case, @value{GDBN} waits
18021 forever because it has no way of knowing how long the program is going
18022 to run before stopping.
18023
18024 @item set syn-garbage-limit @var{num}
18025 @kindex set syn-garbage-limit@r{, MIPS remote}
18026 @cindex synchronize with remote MIPS target
18027 Limit the maximum number of characters @value{GDBN} should ignore when
18028 it tries to synchronize with the remote target. The default is 10
18029 characters. Setting the limit to -1 means there's no limit.
18030
18031 @item show syn-garbage-limit
18032 @kindex show syn-garbage-limit@r{, MIPS remote}
18033 Show the current limit on the number of characters to ignore when
18034 trying to synchronize with the remote system.
18035
18036 @item set monitor-prompt @var{prompt}
18037 @kindex set monitor-prompt@r{, MIPS remote}
18038 @cindex remote monitor prompt
18039 Tell @value{GDBN} to expect the specified @var{prompt} string from the
18040 remote monitor. The default depends on the target:
18041 @table @asis
18042 @item pmon target
18043 @samp{PMON}
18044 @item ddb target
18045 @samp{NEC010}
18046 @item lsi target
18047 @samp{PMON>}
18048 @end table
18049
18050 @item show monitor-prompt
18051 @kindex show monitor-prompt@r{, MIPS remote}
18052 Show the current strings @value{GDBN} expects as the prompt from the
18053 remote monitor.
18054
18055 @item set monitor-warnings
18056 @kindex set monitor-warnings@r{, MIPS remote}
18057 Enable or disable monitor warnings about hardware breakpoints. This
18058 has effect only for the @code{lsi} target. When on, @value{GDBN} will
18059 display warning messages whose codes are returned by the @code{lsi}
18060 PMON monitor for breakpoint commands.
18061
18062 @item show monitor-warnings
18063 @kindex show monitor-warnings@r{, MIPS remote}
18064 Show the current setting of printing monitor warnings.
18065
18066 @item pmon @var{command}
18067 @kindex pmon@r{, MIPS remote}
18068 @cindex send PMON command
18069 This command allows sending an arbitrary @var{command} string to the
18070 monitor. The monitor must be in debug mode for this to work.
18071 @end table
18072
18073 @node OpenRISC 1000
18074 @subsection OpenRISC 1000
18075 @cindex OpenRISC 1000
18076
18077 @cindex or1k boards
18078 See OR1k Architecture document (@uref{www.opencores.org}) for more information
18079 about platform and commands.
18080
18081 @table @code
18082
18083 @kindex target jtag
18084 @item target jtag jtag://@var{host}:@var{port}
18085
18086 Connects to remote JTAG server.
18087 JTAG remote server can be either an or1ksim or JTAG server,
18088 connected via parallel port to the board.
18089
18090 Example: @code{target jtag jtag://localhost:9999}
18091
18092 @kindex or1ksim
18093 @item or1ksim @var{command}
18094 If connected to @code{or1ksim} OpenRISC 1000 Architectural
18095 Simulator, proprietary commands can be executed.
18096
18097 @kindex info or1k spr
18098 @item info or1k spr
18099 Displays spr groups.
18100
18101 @item info or1k spr @var{group}
18102 @itemx info or1k spr @var{groupno}
18103 Displays register names in selected group.
18104
18105 @item info or1k spr @var{group} @var{register}
18106 @itemx info or1k spr @var{register}
18107 @itemx info or1k spr @var{groupno} @var{registerno}
18108 @itemx info or1k spr @var{registerno}
18109 Shows information about specified spr register.
18110
18111 @kindex spr
18112 @item spr @var{group} @var{register} @var{value}
18113 @itemx spr @var{register @var{value}}
18114 @itemx spr @var{groupno} @var{registerno @var{value}}
18115 @itemx spr @var{registerno @var{value}}
18116 Writes @var{value} to specified spr register.
18117 @end table
18118
18119 Some implementations of OpenRISC 1000 Architecture also have hardware trace.
18120 It is very similar to @value{GDBN} trace, except it does not interfere with normal
18121 program execution and is thus much faster. Hardware breakpoints/watchpoint
18122 triggers can be set using:
18123 @table @code
18124 @item $LEA/$LDATA
18125 Load effective address/data
18126 @item $SEA/$SDATA
18127 Store effective address/data
18128 @item $AEA/$ADATA
18129 Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
18130 @item $FETCH
18131 Fetch data
18132 @end table
18133
18134 When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
18135 @code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
18136
18137 @code{htrace} commands:
18138 @cindex OpenRISC 1000 htrace
18139 @table @code
18140 @kindex hwatch
18141 @item hwatch @var{conditional}
18142 Set hardware watchpoint on combination of Load/Store Effective Address(es)
18143 or Data. For example:
18144
18145 @code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
18146
18147 @code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
18148
18149 @kindex htrace
18150 @item htrace info
18151 Display information about current HW trace configuration.
18152
18153 @item htrace trigger @var{conditional}
18154 Set starting criteria for HW trace.
18155
18156 @item htrace qualifier @var{conditional}
18157 Set acquisition qualifier for HW trace.
18158
18159 @item htrace stop @var{conditional}
18160 Set HW trace stopping criteria.
18161
18162 @item htrace record [@var{data}]*
18163 Selects the data to be recorded, when qualifier is met and HW trace was
18164 triggered.
18165
18166 @item htrace enable
18167 @itemx htrace disable
18168 Enables/disables the HW trace.
18169
18170 @item htrace rewind [@var{filename}]
18171 Clears currently recorded trace data.
18172
18173 If filename is specified, new trace file is made and any newly collected data
18174 will be written there.
18175
18176 @item htrace print [@var{start} [@var{len}]]
18177 Prints trace buffer, using current record configuration.
18178
18179 @item htrace mode continuous
18180 Set continuous trace mode.
18181
18182 @item htrace mode suspend
18183 Set suspend trace mode.
18184
18185 @end table
18186
18187 @node PowerPC Embedded
18188 @subsection PowerPC Embedded
18189
18190 @value{GDBN} provides the following PowerPC-specific commands:
18191
18192 @table @code
18193 @kindex set powerpc
18194 @item set powerpc soft-float
18195 @itemx show powerpc soft-float
18196 Force @value{GDBN} to use (or not use) a software floating point calling
18197 convention. By default, @value{GDBN} selects the calling convention based
18198 on the selected architecture and the provided executable file.
18199
18200 @item set powerpc vector-abi
18201 @itemx show powerpc vector-abi
18202 Force @value{GDBN} to use the specified calling convention for vector
18203 arguments and return values. The valid options are @samp{auto};
18204 @samp{generic}, to avoid vector registers even if they are present;
18205 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
18206 registers. By default, @value{GDBN} selects the calling convention
18207 based on the selected architecture and the provided executable file.
18208
18209 @kindex target dink32
18210 @item target dink32 @var{dev}
18211 DINK32 ROM monitor.
18212
18213 @kindex target ppcbug
18214 @item target ppcbug @var{dev}
18215 @kindex target ppcbug1
18216 @item target ppcbug1 @var{dev}
18217 PPCBUG ROM monitor for PowerPC.
18218
18219 @kindex target sds
18220 @item target sds @var{dev}
18221 SDS monitor, running on a PowerPC board (such as Motorola's ADS).
18222 @end table
18223
18224 @cindex SDS protocol
18225 The following commands specific to the SDS protocol are supported
18226 by @value{GDBN}:
18227
18228 @table @code
18229 @item set sdstimeout @var{nsec}
18230 @kindex set sdstimeout
18231 Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
18232 default is 2 seconds.
18233
18234 @item show sdstimeout
18235 @kindex show sdstimeout
18236 Show the current value of the SDS timeout.
18237
18238 @item sds @var{command}
18239 @kindex sds@r{, a command}
18240 Send the specified @var{command} string to the SDS monitor.
18241 @end table
18242
18243
18244 @node PA
18245 @subsection HP PA Embedded
18246
18247 @table @code
18248
18249 @kindex target op50n
18250 @item target op50n @var{dev}
18251 OP50N monitor, running on an OKI HPPA board.
18252
18253 @kindex target w89k
18254 @item target w89k @var{dev}
18255 W89K monitor, running on a Winbond HPPA board.
18256
18257 @end table
18258
18259 @node Sparclet
18260 @subsection Tsqware Sparclet
18261
18262 @cindex Sparclet
18263
18264 @value{GDBN} enables developers to debug tasks running on
18265 Sparclet targets from a Unix host.
18266 @value{GDBN} uses code that runs on
18267 both the Unix host and on the Sparclet target. The program
18268 @code{@value{GDBP}} is installed and executed on the Unix host.
18269
18270 @table @code
18271 @item remotetimeout @var{args}
18272 @kindex remotetimeout
18273 @value{GDBN} supports the option @code{remotetimeout}.
18274 This option is set by the user, and @var{args} represents the number of
18275 seconds @value{GDBN} waits for responses.
18276 @end table
18277
18278 @cindex compiling, on Sparclet
18279 When compiling for debugging, include the options @samp{-g} to get debug
18280 information and @samp{-Ttext} to relocate the program to where you wish to
18281 load it on the target. You may also want to add the options @samp{-n} or
18282 @samp{-N} in order to reduce the size of the sections. Example:
18283
18284 @smallexample
18285 sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
18286 @end smallexample
18287
18288 You can use @code{objdump} to verify that the addresses are what you intended:
18289
18290 @smallexample
18291 sparclet-aout-objdump --headers --syms prog
18292 @end smallexample
18293
18294 @cindex running, on Sparclet
18295 Once you have set
18296 your Unix execution search path to find @value{GDBN}, you are ready to
18297 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
18298 (or @code{sparclet-aout-gdb}, depending on your installation).
18299
18300 @value{GDBN} comes up showing the prompt:
18301
18302 @smallexample
18303 (gdbslet)
18304 @end smallexample
18305
18306 @menu
18307 * Sparclet File:: Setting the file to debug
18308 * Sparclet Connection:: Connecting to Sparclet
18309 * Sparclet Download:: Sparclet download
18310 * Sparclet Execution:: Running and debugging
18311 @end menu
18312
18313 @node Sparclet File
18314 @subsubsection Setting File to Debug
18315
18316 The @value{GDBN} command @code{file} lets you choose with program to debug.
18317
18318 @smallexample
18319 (gdbslet) file prog
18320 @end smallexample
18321
18322 @need 1000
18323 @value{GDBN} then attempts to read the symbol table of @file{prog}.
18324 @value{GDBN} locates
18325 the file by searching the directories listed in the command search
18326 path.
18327 If the file was compiled with debug information (option @samp{-g}), source
18328 files will be searched as well.
18329 @value{GDBN} locates
18330 the source files by searching the directories listed in the directory search
18331 path (@pxref{Environment, ,Your Program's Environment}).
18332 If it fails
18333 to find a file, it displays a message such as:
18334
18335 @smallexample
18336 prog: No such file or directory.
18337 @end smallexample
18338
18339 When this happens, add the appropriate directories to the search paths with
18340 the @value{GDBN} commands @code{path} and @code{dir}, and execute the
18341 @code{target} command again.
18342
18343 @node Sparclet Connection
18344 @subsubsection Connecting to Sparclet
18345
18346 The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
18347 To connect to a target on serial port ``@code{ttya}'', type:
18348
18349 @smallexample
18350 (gdbslet) target sparclet /dev/ttya
18351 Remote target sparclet connected to /dev/ttya
18352 main () at ../prog.c:3
18353 @end smallexample
18354
18355 @need 750
18356 @value{GDBN} displays messages like these:
18357
18358 @smallexample
18359 Connected to ttya.
18360 @end smallexample
18361
18362 @node Sparclet Download
18363 @subsubsection Sparclet Download
18364
18365 @cindex download to Sparclet
18366 Once connected to the Sparclet target,
18367 you can use the @value{GDBN}
18368 @code{load} command to download the file from the host to the target.
18369 The file name and load offset should be given as arguments to the @code{load}
18370 command.
18371 Since the file format is aout, the program must be loaded to the starting
18372 address. You can use @code{objdump} to find out what this value is. The load
18373 offset is an offset which is added to the VMA (virtual memory address)
18374 of each of the file's sections.
18375 For instance, if the program
18376 @file{prog} was linked to text address 0x1201000, with data at 0x12010160
18377 and bss at 0x12010170, in @value{GDBN}, type:
18378
18379 @smallexample
18380 (gdbslet) load prog 0x12010000
18381 Loading section .text, size 0xdb0 vma 0x12010000
18382 @end smallexample
18383
18384 If the code is loaded at a different address then what the program was linked
18385 to, you may need to use the @code{section} and @code{add-symbol-file} commands
18386 to tell @value{GDBN} where to map the symbol table.
18387
18388 @node Sparclet Execution
18389 @subsubsection Running and Debugging
18390
18391 @cindex running and debugging Sparclet programs
18392 You can now begin debugging the task using @value{GDBN}'s execution control
18393 commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
18394 manual for the list of commands.
18395
18396 @smallexample
18397 (gdbslet) b main
18398 Breakpoint 1 at 0x12010000: file prog.c, line 3.
18399 (gdbslet) run
18400 Starting program: prog
18401 Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
18402 3 char *symarg = 0;
18403 (gdbslet) step
18404 4 char *execarg = "hello!";
18405 (gdbslet)
18406 @end smallexample
18407
18408 @node Sparclite
18409 @subsection Fujitsu Sparclite
18410
18411 @table @code
18412
18413 @kindex target sparclite
18414 @item target sparclite @var{dev}
18415 Fujitsu sparclite boards, used only for the purpose of loading.
18416 You must use an additional command to debug the program.
18417 For example: target remote @var{dev} using @value{GDBN} standard
18418 remote protocol.
18419
18420 @end table
18421
18422 @node Z8000
18423 @subsection Zilog Z8000
18424
18425 @cindex Z8000
18426 @cindex simulator, Z8000
18427 @cindex Zilog Z8000 simulator
18428
18429 When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
18430 a Z8000 simulator.
18431
18432 For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
18433 unsegmented variant of the Z8000 architecture) or the Z8001 (the
18434 segmented variant). The simulator recognizes which architecture is
18435 appropriate by inspecting the object code.
18436
18437 @table @code
18438 @item target sim @var{args}
18439 @kindex sim
18440 @kindex target sim@r{, with Z8000}
18441 Debug programs on a simulated CPU. If the simulator supports setup
18442 options, specify them via @var{args}.
18443 @end table
18444
18445 @noindent
18446 After specifying this target, you can debug programs for the simulated
18447 CPU in the same style as programs for your host computer; use the
18448 @code{file} command to load a new program image, the @code{run} command
18449 to run your program, and so on.
18450
18451 As well as making available all the usual machine registers
18452 (@pxref{Registers, ,Registers}), the Z8000 simulator provides three
18453 additional items of information as specially named registers:
18454
18455 @table @code
18456
18457 @item cycles
18458 Counts clock-ticks in the simulator.
18459
18460 @item insts
18461 Counts instructions run in the simulator.
18462
18463 @item time
18464 Execution time in 60ths of a second.
18465
18466 @end table
18467
18468 You can refer to these values in @value{GDBN} expressions with the usual
18469 conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
18470 conditional breakpoint that suspends only after at least 5000
18471 simulated clock ticks.
18472
18473 @node AVR
18474 @subsection Atmel AVR
18475 @cindex AVR
18476
18477 When configured for debugging the Atmel AVR, @value{GDBN} supports the
18478 following AVR-specific commands:
18479
18480 @table @code
18481 @item info io_registers
18482 @kindex info io_registers@r{, AVR}
18483 @cindex I/O registers (Atmel AVR)
18484 This command displays information about the AVR I/O registers. For
18485 each register, @value{GDBN} prints its number and value.
18486 @end table
18487
18488 @node CRIS
18489 @subsection CRIS
18490 @cindex CRIS
18491
18492 When configured for debugging CRIS, @value{GDBN} provides the
18493 following CRIS-specific commands:
18494
18495 @table @code
18496 @item set cris-version @var{ver}
18497 @cindex CRIS version
18498 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
18499 The CRIS version affects register names and sizes. This command is useful in
18500 case autodetection of the CRIS version fails.
18501
18502 @item show cris-version
18503 Show the current CRIS version.
18504
18505 @item set cris-dwarf2-cfi
18506 @cindex DWARF-2 CFI and CRIS
18507 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
18508 Change to @samp{off} when using @code{gcc-cris} whose version is below
18509 @code{R59}.
18510
18511 @item show cris-dwarf2-cfi
18512 Show the current state of using DWARF-2 CFI.
18513
18514 @item set cris-mode @var{mode}
18515 @cindex CRIS mode
18516 Set the current CRIS mode to @var{mode}. It should only be changed when
18517 debugging in guru mode, in which case it should be set to
18518 @samp{guru} (the default is @samp{normal}).
18519
18520 @item show cris-mode
18521 Show the current CRIS mode.
18522 @end table
18523
18524 @node Super-H
18525 @subsection Renesas Super-H
18526 @cindex Super-H
18527
18528 For the Renesas Super-H processor, @value{GDBN} provides these
18529 commands:
18530
18531 @table @code
18532 @item regs
18533 @kindex regs@r{, Super-H}
18534 Show the values of all Super-H registers.
18535
18536 @item set sh calling-convention @var{convention}
18537 @kindex set sh calling-convention
18538 Set the calling-convention used when calling functions from @value{GDBN}.
18539 Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
18540 With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
18541 convention. If the DWARF-2 information of the called function specifies
18542 that the function follows the Renesas calling convention, the function
18543 is called using the Renesas calling convention. If the calling convention
18544 is set to @samp{renesas}, the Renesas calling convention is always used,
18545 regardless of the DWARF-2 information. This can be used to override the
18546 default of @samp{gcc} if debug information is missing, or the compiler
18547 does not emit the DWARF-2 calling convention entry for a function.
18548
18549 @item show sh calling-convention
18550 @kindex show sh calling-convention
18551 Show the current calling convention setting.
18552
18553 @end table
18554
18555
18556 @node Architectures
18557 @section Architectures
18558
18559 This section describes characteristics of architectures that affect
18560 all uses of @value{GDBN} with the architecture, both native and cross.
18561
18562 @menu
18563 * i386::
18564 * A29K::
18565 * Alpha::
18566 * MIPS::
18567 * HPPA:: HP PA architecture
18568 * SPU:: Cell Broadband Engine SPU architecture
18569 * PowerPC::
18570 @end menu
18571
18572 @node i386
18573 @subsection x86 Architecture-specific Issues
18574
18575 @table @code
18576 @item set struct-convention @var{mode}
18577 @kindex set struct-convention
18578 @cindex struct return convention
18579 @cindex struct/union returned in registers
18580 Set the convention used by the inferior to return @code{struct}s and
18581 @code{union}s from functions to @var{mode}. Possible values of
18582 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
18583 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
18584 are returned on the stack, while @code{"reg"} means that a
18585 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
18586 be returned in a register.
18587
18588 @item show struct-convention
18589 @kindex show struct-convention
18590 Show the current setting of the convention to return @code{struct}s
18591 from functions.
18592 @end table
18593
18594 @node A29K
18595 @subsection A29K
18596
18597 @table @code
18598
18599 @kindex set rstack_high_address
18600 @cindex AMD 29K register stack
18601 @cindex register stack, AMD29K
18602 @item set rstack_high_address @var{address}
18603 On AMD 29000 family processors, registers are saved in a separate
18604 @dfn{register stack}. There is no way for @value{GDBN} to determine the
18605 extent of this stack. Normally, @value{GDBN} just assumes that the
18606 stack is ``large enough''. This may result in @value{GDBN} referencing
18607 memory locations that do not exist. If necessary, you can get around
18608 this problem by specifying the ending address of the register stack with
18609 the @code{set rstack_high_address} command. The argument should be an
18610 address, which you probably want to precede with @samp{0x} to specify in
18611 hexadecimal.
18612
18613 @kindex show rstack_high_address
18614 @item show rstack_high_address
18615 Display the current limit of the register stack, on AMD 29000 family
18616 processors.
18617
18618 @end table
18619
18620 @node Alpha
18621 @subsection Alpha
18622
18623 See the following section.
18624
18625 @node MIPS
18626 @subsection MIPS
18627
18628 @cindex stack on Alpha
18629 @cindex stack on MIPS
18630 @cindex Alpha stack
18631 @cindex MIPS stack
18632 Alpha- and MIPS-based computers use an unusual stack frame, which
18633 sometimes requires @value{GDBN} to search backward in the object code to
18634 find the beginning of a function.
18635
18636 @cindex response time, MIPS debugging
18637 To improve response time (especially for embedded applications, where
18638 @value{GDBN} may be restricted to a slow serial line for this search)
18639 you may want to limit the size of this search, using one of these
18640 commands:
18641
18642 @table @code
18643 @cindex @code{heuristic-fence-post} (Alpha, MIPS)
18644 @item set heuristic-fence-post @var{limit}
18645 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
18646 search for the beginning of a function. A value of @var{0} (the
18647 default) means there is no limit. However, except for @var{0}, the
18648 larger the limit the more bytes @code{heuristic-fence-post} must search
18649 and therefore the longer it takes to run. You should only need to use
18650 this command when debugging a stripped executable.
18651
18652 @item show heuristic-fence-post
18653 Display the current limit.
18654 @end table
18655
18656 @noindent
18657 These commands are available @emph{only} when @value{GDBN} is configured
18658 for debugging programs on Alpha or MIPS processors.
18659
18660 Several MIPS-specific commands are available when debugging MIPS
18661 programs:
18662
18663 @table @code
18664 @item set mips abi @var{arg}
18665 @kindex set mips abi
18666 @cindex set ABI for MIPS
18667 Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
18668 values of @var{arg} are:
18669
18670 @table @samp
18671 @item auto
18672 The default ABI associated with the current binary (this is the
18673 default).
18674 @item o32
18675 @item o64
18676 @item n32
18677 @item n64
18678 @item eabi32
18679 @item eabi64
18680 @item auto
18681 @end table
18682
18683 @item show mips abi
18684 @kindex show mips abi
18685 Show the MIPS ABI used by @value{GDBN} to debug the inferior.
18686
18687 @item set mipsfpu
18688 @itemx show mipsfpu
18689 @xref{MIPS Embedded, set mipsfpu}.
18690
18691 @item set mips mask-address @var{arg}
18692 @kindex set mips mask-address
18693 @cindex MIPS addresses, masking
18694 This command determines whether the most-significant 32 bits of 64-bit
18695 MIPS addresses are masked off. The argument @var{arg} can be
18696 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
18697 setting, which lets @value{GDBN} determine the correct value.
18698
18699 @item show mips mask-address
18700 @kindex show mips mask-address
18701 Show whether the upper 32 bits of MIPS addresses are masked off or
18702 not.
18703
18704 @item set remote-mips64-transfers-32bit-regs
18705 @kindex set remote-mips64-transfers-32bit-regs
18706 This command controls compatibility with 64-bit MIPS targets that
18707 transfer data in 32-bit quantities. If you have an old MIPS 64 target
18708 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
18709 and 64 bits for other registers, set this option to @samp{on}.
18710
18711 @item show remote-mips64-transfers-32bit-regs
18712 @kindex show remote-mips64-transfers-32bit-regs
18713 Show the current setting of compatibility with older MIPS 64 targets.
18714
18715 @item set debug mips
18716 @kindex set debug mips
18717 This command turns on and off debugging messages for the MIPS-specific
18718 target code in @value{GDBN}.
18719
18720 @item show debug mips
18721 @kindex show debug mips
18722 Show the current setting of MIPS debugging messages.
18723 @end table
18724
18725
18726 @node HPPA
18727 @subsection HPPA
18728 @cindex HPPA support
18729
18730 When @value{GDBN} is debugging the HP PA architecture, it provides the
18731 following special commands:
18732
18733 @table @code
18734 @item set debug hppa
18735 @kindex set debug hppa
18736 This command determines whether HPPA architecture-specific debugging
18737 messages are to be displayed.
18738
18739 @item show debug hppa
18740 Show whether HPPA debugging messages are displayed.
18741
18742 @item maint print unwind @var{address}
18743 @kindex maint print unwind@r{, HPPA}
18744 This command displays the contents of the unwind table entry at the
18745 given @var{address}.
18746
18747 @end table
18748
18749
18750 @node SPU
18751 @subsection Cell Broadband Engine SPU architecture
18752 @cindex Cell Broadband Engine
18753 @cindex SPU
18754
18755 When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
18756 it provides the following special commands:
18757
18758 @table @code
18759 @item info spu event
18760 @kindex info spu
18761 Display SPU event facility status. Shows current event mask
18762 and pending event status.
18763
18764 @item info spu signal
18765 Display SPU signal notification facility status. Shows pending
18766 signal-control word and signal notification mode of both signal
18767 notification channels.
18768
18769 @item info spu mailbox
18770 Display SPU mailbox facility status. Shows all pending entries,
18771 in order of processing, in each of the SPU Write Outbound,
18772 SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
18773
18774 @item info spu dma
18775 Display MFC DMA status. Shows all pending commands in the MFC
18776 DMA queue. For each entry, opcode, tag, class IDs, effective
18777 and local store addresses and transfer size are shown.
18778
18779 @item info spu proxydma
18780 Display MFC Proxy-DMA status. Shows all pending commands in the MFC
18781 Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
18782 and local store addresses and transfer size are shown.
18783
18784 @end table
18785
18786 When @value{GDBN} is debugging a combined PowerPC/SPU application
18787 on the Cell Broadband Engine, it provides in addition the following
18788 special commands:
18789
18790 @table @code
18791 @item set spu stop-on-load @var{arg}
18792 @kindex set spu
18793 Set whether to stop for new SPE threads. When set to @code{on}, @value{GDBN}
18794 will give control to the user when a new SPE thread enters its @code{main}
18795 function. The default is @code{off}.
18796
18797 @item show spu stop-on-load
18798 @kindex show spu
18799 Show whether to stop for new SPE threads.
18800
18801 @item set spu auto-flush-cache @var{arg}
18802 Set whether to automatically flush the software-managed cache. When set to
18803 @code{on}, @value{GDBN} will automatically cause the SPE software-managed
18804 cache to be flushed whenever SPE execution stops. This provides a consistent
18805 view of PowerPC memory that is accessed via the cache. If an application
18806 does not use the software-managed cache, this option has no effect.
18807
18808 @item show spu auto-flush-cache
18809 Show whether to automatically flush the software-managed cache.
18810
18811 @end table
18812
18813 @node PowerPC
18814 @subsection PowerPC
18815 @cindex PowerPC architecture
18816
18817 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
18818 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
18819 numbers stored in the floating point registers. These values must be stored
18820 in two consecutive registers, always starting at an even register like
18821 @code{f0} or @code{f2}.
18822
18823 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
18824 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
18825 @code{f2} and @code{f3} for @code{$dl1} and so on.
18826
18827 For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
18828 wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
18829
18830
18831 @node Controlling GDB
18832 @chapter Controlling @value{GDBN}
18833
18834 You can alter the way @value{GDBN} interacts with you by using the
18835 @code{set} command. For commands controlling how @value{GDBN} displays
18836 data, see @ref{Print Settings, ,Print Settings}. Other settings are
18837 described here.
18838
18839 @menu
18840 * Prompt:: Prompt
18841 * Editing:: Command editing
18842 * Command History:: Command history
18843 * Screen Size:: Screen size
18844 * Numbers:: Numbers
18845 * ABI:: Configuring the current ABI
18846 * Messages/Warnings:: Optional warnings and messages
18847 * Debugging Output:: Optional messages about internal happenings
18848 * Other Misc Settings:: Other Miscellaneous Settings
18849 @end menu
18850
18851 @node Prompt
18852 @section Prompt
18853
18854 @cindex prompt
18855
18856 @value{GDBN} indicates its readiness to read a command by printing a string
18857 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
18858 can change the prompt string with the @code{set prompt} command. For
18859 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
18860 the prompt in one of the @value{GDBN} sessions so that you can always tell
18861 which one you are talking to.
18862
18863 @emph{Note:} @code{set prompt} does not add a space for you after the
18864 prompt you set. This allows you to set a prompt which ends in a space
18865 or a prompt that does not.
18866
18867 @table @code
18868 @kindex set prompt
18869 @item set prompt @var{newprompt}
18870 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
18871
18872 @kindex show prompt
18873 @item show prompt
18874 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
18875 @end table
18876
18877 @node Editing
18878 @section Command Editing
18879 @cindex readline
18880 @cindex command line editing
18881
18882 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
18883 @sc{gnu} library provides consistent behavior for programs which provide a
18884 command line interface to the user. Advantages are @sc{gnu} Emacs-style
18885 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
18886 substitution, and a storage and recall of command history across
18887 debugging sessions.
18888
18889 You may control the behavior of command line editing in @value{GDBN} with the
18890 command @code{set}.
18891
18892 @table @code
18893 @kindex set editing
18894 @cindex editing
18895 @item set editing
18896 @itemx set editing on
18897 Enable command line editing (enabled by default).
18898
18899 @item set editing off
18900 Disable command line editing.
18901
18902 @kindex show editing
18903 @item show editing
18904 Show whether command line editing is enabled.
18905 @end table
18906
18907 @xref{Command Line Editing}, for more details about the Readline
18908 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
18909 encouraged to read that chapter.
18910
18911 @node Command History
18912 @section Command History
18913 @cindex command history
18914
18915 @value{GDBN} can keep track of the commands you type during your
18916 debugging sessions, so that you can be certain of precisely what
18917 happened. Use these commands to manage the @value{GDBN} command
18918 history facility.
18919
18920 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
18921 package, to provide the history facility. @xref{Using History
18922 Interactively}, for the detailed description of the History library.
18923
18924 To issue a command to @value{GDBN} without affecting certain aspects of
18925 the state which is seen by users, prefix it with @samp{server }
18926 (@pxref{Server Prefix}). This
18927 means that this command will not affect the command history, nor will it
18928 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
18929 pressed on a line by itself.
18930
18931 @cindex @code{server}, command prefix
18932 The server prefix does not affect the recording of values into the value
18933 history; to print a value without recording it into the value history,
18934 use the @code{output} command instead of the @code{print} command.
18935
18936 Here is the description of @value{GDBN} commands related to command
18937 history.
18938
18939 @table @code
18940 @cindex history substitution
18941 @cindex history file
18942 @kindex set history filename
18943 @cindex @env{GDBHISTFILE}, environment variable
18944 @item set history filename @var{fname}
18945 Set the name of the @value{GDBN} command history file to @var{fname}.
18946 This is the file where @value{GDBN} reads an initial command history
18947 list, and where it writes the command history from this session when it
18948 exits. You can access this list through history expansion or through
18949 the history command editing characters listed below. This file defaults
18950 to the value of the environment variable @code{GDBHISTFILE}, or to
18951 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
18952 is not set.
18953
18954 @cindex save command history
18955 @kindex set history save
18956 @item set history save
18957 @itemx set history save on
18958 Record command history in a file, whose name may be specified with the
18959 @code{set history filename} command. By default, this option is disabled.
18960
18961 @item set history save off
18962 Stop recording command history in a file.
18963
18964 @cindex history size
18965 @kindex set history size
18966 @cindex @env{HISTSIZE}, environment variable
18967 @item set history size @var{size}
18968 Set the number of commands which @value{GDBN} keeps in its history list.
18969 This defaults to the value of the environment variable
18970 @code{HISTSIZE}, or to 256 if this variable is not set.
18971 @end table
18972
18973 History expansion assigns special meaning to the character @kbd{!}.
18974 @xref{Event Designators}, for more details.
18975
18976 @cindex history expansion, turn on/off
18977 Since @kbd{!} is also the logical not operator in C, history expansion
18978 is off by default. If you decide to enable history expansion with the
18979 @code{set history expansion on} command, you may sometimes need to
18980 follow @kbd{!} (when it is used as logical not, in an expression) with
18981 a space or a tab to prevent it from being expanded. The readline
18982 history facilities do not attempt substitution on the strings
18983 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
18984
18985 The commands to control history expansion are:
18986
18987 @table @code
18988 @item set history expansion on
18989 @itemx set history expansion
18990 @kindex set history expansion
18991 Enable history expansion. History expansion is off by default.
18992
18993 @item set history expansion off
18994 Disable history expansion.
18995
18996 @c @group
18997 @kindex show history
18998 @item show history
18999 @itemx show history filename
19000 @itemx show history save
19001 @itemx show history size
19002 @itemx show history expansion
19003 These commands display the state of the @value{GDBN} history parameters.
19004 @code{show history} by itself displays all four states.
19005 @c @end group
19006 @end table
19007
19008 @table @code
19009 @kindex show commands
19010 @cindex show last commands
19011 @cindex display command history
19012 @item show commands
19013 Display the last ten commands in the command history.
19014
19015 @item show commands @var{n}
19016 Print ten commands centered on command number @var{n}.
19017
19018 @item show commands +
19019 Print ten commands just after the commands last printed.
19020 @end table
19021
19022 @node Screen Size
19023 @section Screen Size
19024 @cindex size of screen
19025 @cindex pauses in output
19026
19027 Certain commands to @value{GDBN} may produce large amounts of
19028 information output to the screen. To help you read all of it,
19029 @value{GDBN} pauses and asks you for input at the end of each page of
19030 output. Type @key{RET} when you want to continue the output, or @kbd{q}
19031 to discard the remaining output. Also, the screen width setting
19032 determines when to wrap lines of output. Depending on what is being
19033 printed, @value{GDBN} tries to break the line at a readable place,
19034 rather than simply letting it overflow onto the following line.
19035
19036 Normally @value{GDBN} knows the size of the screen from the terminal
19037 driver software. For example, on Unix @value{GDBN} uses the termcap data base
19038 together with the value of the @code{TERM} environment variable and the
19039 @code{stty rows} and @code{stty cols} settings. If this is not correct,
19040 you can override it with the @code{set height} and @code{set
19041 width} commands:
19042
19043 @table @code
19044 @kindex set height
19045 @kindex set width
19046 @kindex show width
19047 @kindex show height
19048 @item set height @var{lpp}
19049 @itemx show height
19050 @itemx set width @var{cpl}
19051 @itemx show width
19052 These @code{set} commands specify a screen height of @var{lpp} lines and
19053 a screen width of @var{cpl} characters. The associated @code{show}
19054 commands display the current settings.
19055
19056 If you specify a height of zero lines, @value{GDBN} does not pause during
19057 output no matter how long the output is. This is useful if output is to a
19058 file or to an editor buffer.
19059
19060 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
19061 from wrapping its output.
19062
19063 @item set pagination on
19064 @itemx set pagination off
19065 @kindex set pagination
19066 Turn the output pagination on or off; the default is on. Turning
19067 pagination off is the alternative to @code{set height 0}. Note that
19068 running @value{GDBN} with the @option{--batch} option (@pxref{Mode
19069 Options, -batch}) also automatically disables pagination.
19070
19071 @item show pagination
19072 @kindex show pagination
19073 Show the current pagination mode.
19074 @end table
19075
19076 @node Numbers
19077 @section Numbers
19078 @cindex number representation
19079 @cindex entering numbers
19080
19081 You can always enter numbers in octal, decimal, or hexadecimal in
19082 @value{GDBN} by the usual conventions: octal numbers begin with
19083 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
19084 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
19085 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
19086 10; likewise, the default display for numbers---when no particular
19087 format is specified---is base 10. You can change the default base for
19088 both input and output with the commands described below.
19089
19090 @table @code
19091 @kindex set input-radix
19092 @item set input-radix @var{base}
19093 Set the default base for numeric input. Supported choices
19094 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
19095 specified either unambiguously or using the current input radix; for
19096 example, any of
19097
19098 @smallexample
19099 set input-radix 012
19100 set input-radix 10.
19101 set input-radix 0xa
19102 @end smallexample
19103
19104 @noindent
19105 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
19106 leaves the input radix unchanged, no matter what it was, since
19107 @samp{10}, being without any leading or trailing signs of its base, is
19108 interpreted in the current radix. Thus, if the current radix is 16,
19109 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
19110 change the radix.
19111
19112 @kindex set output-radix
19113 @item set output-radix @var{base}
19114 Set the default base for numeric display. Supported choices
19115 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
19116 specified either unambiguously or using the current input radix.
19117
19118 @kindex show input-radix
19119 @item show input-radix
19120 Display the current default base for numeric input.
19121
19122 @kindex show output-radix
19123 @item show output-radix
19124 Display the current default base for numeric display.
19125
19126 @item set radix @r{[}@var{base}@r{]}
19127 @itemx show radix
19128 @kindex set radix
19129 @kindex show radix
19130 These commands set and show the default base for both input and output
19131 of numbers. @code{set radix} sets the radix of input and output to
19132 the same base; without an argument, it resets the radix back to its
19133 default value of 10.
19134
19135 @end table
19136
19137 @node ABI
19138 @section Configuring the Current ABI
19139
19140 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
19141 application automatically. However, sometimes you need to override its
19142 conclusions. Use these commands to manage @value{GDBN}'s view of the
19143 current ABI.
19144
19145 @cindex OS ABI
19146 @kindex set osabi
19147 @kindex show osabi
19148
19149 One @value{GDBN} configuration can debug binaries for multiple operating
19150 system targets, either via remote debugging or native emulation.
19151 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
19152 but you can override its conclusion using the @code{set osabi} command.
19153 One example where this is useful is in debugging of binaries which use
19154 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
19155 not have the same identifying marks that the standard C library for your
19156 platform provides.
19157
19158 @table @code
19159 @item show osabi
19160 Show the OS ABI currently in use.
19161
19162 @item set osabi
19163 With no argument, show the list of registered available OS ABI's.
19164
19165 @item set osabi @var{abi}
19166 Set the current OS ABI to @var{abi}.
19167 @end table
19168
19169 @cindex float promotion
19170
19171 Generally, the way that an argument of type @code{float} is passed to a
19172 function depends on whether the function is prototyped. For a prototyped
19173 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
19174 according to the architecture's convention for @code{float}. For unprototyped
19175 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
19176 @code{double} and then passed.
19177
19178 Unfortunately, some forms of debug information do not reliably indicate whether
19179 a function is prototyped. If @value{GDBN} calls a function that is not marked
19180 as prototyped, it consults @kbd{set coerce-float-to-double}.
19181
19182 @table @code
19183 @kindex set coerce-float-to-double
19184 @item set coerce-float-to-double
19185 @itemx set coerce-float-to-double on
19186 Arguments of type @code{float} will be promoted to @code{double} when passed
19187 to an unprototyped function. This is the default setting.
19188
19189 @item set coerce-float-to-double off
19190 Arguments of type @code{float} will be passed directly to unprototyped
19191 functions.
19192
19193 @kindex show coerce-float-to-double
19194 @item show coerce-float-to-double
19195 Show the current setting of promoting @code{float} to @code{double}.
19196 @end table
19197
19198 @kindex set cp-abi
19199 @kindex show cp-abi
19200 @value{GDBN} needs to know the ABI used for your program's C@t{++}
19201 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
19202 used to build your application. @value{GDBN} only fully supports
19203 programs with a single C@t{++} ABI; if your program contains code using
19204 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
19205 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
19206 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
19207 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
19208 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
19209 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
19210 ``auto''.
19211
19212 @table @code
19213 @item show cp-abi
19214 Show the C@t{++} ABI currently in use.
19215
19216 @item set cp-abi
19217 With no argument, show the list of supported C@t{++} ABI's.
19218
19219 @item set cp-abi @var{abi}
19220 @itemx set cp-abi auto
19221 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
19222 @end table
19223
19224 @node Messages/Warnings
19225 @section Optional Warnings and Messages
19226
19227 @cindex verbose operation
19228 @cindex optional warnings
19229 By default, @value{GDBN} is silent about its inner workings. If you are
19230 running on a slow machine, you may want to use the @code{set verbose}
19231 command. This makes @value{GDBN} tell you when it does a lengthy
19232 internal operation, so you will not think it has crashed.
19233
19234 Currently, the messages controlled by @code{set verbose} are those
19235 which announce that the symbol table for a source file is being read;
19236 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
19237
19238 @table @code
19239 @kindex set verbose
19240 @item set verbose on
19241 Enables @value{GDBN} output of certain informational messages.
19242
19243 @item set verbose off
19244 Disables @value{GDBN} output of certain informational messages.
19245
19246 @kindex show verbose
19247 @item show verbose
19248 Displays whether @code{set verbose} is on or off.
19249 @end table
19250
19251 By default, if @value{GDBN} encounters bugs in the symbol table of an
19252 object file, it is silent; but if you are debugging a compiler, you may
19253 find this information useful (@pxref{Symbol Errors, ,Errors Reading
19254 Symbol Files}).
19255
19256 @table @code
19257
19258 @kindex set complaints
19259 @item set complaints @var{limit}
19260 Permits @value{GDBN} to output @var{limit} complaints about each type of
19261 unusual symbols before becoming silent about the problem. Set
19262 @var{limit} to zero to suppress all complaints; set it to a large number
19263 to prevent complaints from being suppressed.
19264
19265 @kindex show complaints
19266 @item show complaints
19267 Displays how many symbol complaints @value{GDBN} is permitted to produce.
19268
19269 @end table
19270
19271 @anchor{confirmation requests}
19272 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
19273 lot of stupid questions to confirm certain commands. For example, if
19274 you try to run a program which is already running:
19275
19276 @smallexample
19277 (@value{GDBP}) run
19278 The program being debugged has been started already.
19279 Start it from the beginning? (y or n)
19280 @end smallexample
19281
19282 If you are willing to unflinchingly face the consequences of your own
19283 commands, you can disable this ``feature'':
19284
19285 @table @code
19286
19287 @kindex set confirm
19288 @cindex flinching
19289 @cindex confirmation
19290 @cindex stupid questions
19291 @item set confirm off
19292 Disables confirmation requests. Note that running @value{GDBN} with
19293 the @option{--batch} option (@pxref{Mode Options, -batch}) also
19294 automatically disables confirmation requests.
19295
19296 @item set confirm on
19297 Enables confirmation requests (the default).
19298
19299 @kindex show confirm
19300 @item show confirm
19301 Displays state of confirmation requests.
19302
19303 @end table
19304
19305 @cindex command tracing
19306 If you need to debug user-defined commands or sourced files you may find it
19307 useful to enable @dfn{command tracing}. In this mode each command will be
19308 printed as it is executed, prefixed with one or more @samp{+} symbols, the
19309 quantity denoting the call depth of each command.
19310
19311 @table @code
19312 @kindex set trace-commands
19313 @cindex command scripts, debugging
19314 @item set trace-commands on
19315 Enable command tracing.
19316 @item set trace-commands off
19317 Disable command tracing.
19318 @item show trace-commands
19319 Display the current state of command tracing.
19320 @end table
19321
19322 @node Debugging Output
19323 @section Optional Messages about Internal Happenings
19324 @cindex optional debugging messages
19325
19326 @value{GDBN} has commands that enable optional debugging messages from
19327 various @value{GDBN} subsystems; normally these commands are of
19328 interest to @value{GDBN} maintainers, or when reporting a bug. This
19329 section documents those commands.
19330
19331 @table @code
19332 @kindex set exec-done-display
19333 @item set exec-done-display
19334 Turns on or off the notification of asynchronous commands'
19335 completion. When on, @value{GDBN} will print a message when an
19336 asynchronous command finishes its execution. The default is off.
19337 @kindex show exec-done-display
19338 @item show exec-done-display
19339 Displays the current setting of asynchronous command completion
19340 notification.
19341 @kindex set debug
19342 @cindex gdbarch debugging info
19343 @cindex architecture debugging info
19344 @item set debug arch
19345 Turns on or off display of gdbarch debugging info. The default is off
19346 @kindex show debug
19347 @item show debug arch
19348 Displays the current state of displaying gdbarch debugging info.
19349 @item set debug aix-thread
19350 @cindex AIX threads
19351 Display debugging messages about inner workings of the AIX thread
19352 module.
19353 @item show debug aix-thread
19354 Show the current state of AIX thread debugging info display.
19355 @item set debug dwarf2-die
19356 @cindex DWARF2 DIEs
19357 Dump DWARF2 DIEs after they are read in.
19358 The value is the number of nesting levels to print.
19359 A value of zero turns off the display.
19360 @item show debug dwarf2-die
19361 Show the current state of DWARF2 DIE debugging.
19362 @item set debug displaced
19363 @cindex displaced stepping debugging info
19364 Turns on or off display of @value{GDBN} debugging info for the
19365 displaced stepping support. The default is off.
19366 @item show debug displaced
19367 Displays the current state of displaying @value{GDBN} debugging info
19368 related to displaced stepping.
19369 @item set debug event
19370 @cindex event debugging info
19371 Turns on or off display of @value{GDBN} event debugging info. The
19372 default is off.
19373 @item show debug event
19374 Displays the current state of displaying @value{GDBN} event debugging
19375 info.
19376 @item set debug expression
19377 @cindex expression debugging info
19378 Turns on or off display of debugging info about @value{GDBN}
19379 expression parsing. The default is off.
19380 @item show debug expression
19381 Displays the current state of displaying debugging info about
19382 @value{GDBN} expression parsing.
19383 @item set debug frame
19384 @cindex frame debugging info
19385 Turns on or off display of @value{GDBN} frame debugging info. The
19386 default is off.
19387 @item show debug frame
19388 Displays the current state of displaying @value{GDBN} frame debugging
19389 info.
19390 @item set debug gnu-nat
19391 @cindex @sc{gnu}/Hurd debug messages
19392 Turns on or off debugging messages from the @sc{gnu}/Hurd debug support.
19393 @item show debug gnu-nat
19394 Show the current state of @sc{gnu}/Hurd debugging messages.
19395 @item set debug infrun
19396 @cindex inferior debugging info
19397 Turns on or off display of @value{GDBN} debugging info for running the inferior.
19398 The default is off. @file{infrun.c} contains GDB's runtime state machine used
19399 for implementing operations such as single-stepping the inferior.
19400 @item show debug infrun
19401 Displays the current state of @value{GDBN} inferior debugging.
19402 @item set debug lin-lwp
19403 @cindex @sc{gnu}/Linux LWP debug messages
19404 @cindex Linux lightweight processes
19405 Turns on or off debugging messages from the Linux LWP debug support.
19406 @item show debug lin-lwp
19407 Show the current state of Linux LWP debugging messages.
19408 @item set debug lin-lwp-async
19409 @cindex @sc{gnu}/Linux LWP async debug messages
19410 @cindex Linux lightweight processes
19411 Turns on or off debugging messages from the Linux LWP async debug support.
19412 @item show debug lin-lwp-async
19413 Show the current state of Linux LWP async debugging messages.
19414 @item set debug observer
19415 @cindex observer debugging info
19416 Turns on or off display of @value{GDBN} observer debugging. This
19417 includes info such as the notification of observable events.
19418 @item show debug observer
19419 Displays the current state of observer debugging.
19420 @item set debug overload
19421 @cindex C@t{++} overload debugging info
19422 Turns on or off display of @value{GDBN} C@t{++} overload debugging
19423 info. This includes info such as ranking of functions, etc. The default
19424 is off.
19425 @item show debug overload
19426 Displays the current state of displaying @value{GDBN} C@t{++} overload
19427 debugging info.
19428 @cindex expression parser, debugging info
19429 @cindex debug expression parser
19430 @item set debug parser
19431 Turns on or off the display of expression parser debugging output.
19432 Internally, this sets the @code{yydebug} variable in the expression
19433 parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
19434 details. The default is off.
19435 @item show debug parser
19436 Show the current state of expression parser debugging.
19437 @cindex packets, reporting on stdout
19438 @cindex serial connections, debugging
19439 @cindex debug remote protocol
19440 @cindex remote protocol debugging
19441 @cindex display remote packets
19442 @item set debug remote
19443 Turns on or off display of reports on all packets sent back and forth across
19444 the serial line to the remote machine. The info is printed on the
19445 @value{GDBN} standard output stream. The default is off.
19446 @item show debug remote
19447 Displays the state of display of remote packets.
19448 @item set debug serial
19449 Turns on or off display of @value{GDBN} serial debugging info. The
19450 default is off.
19451 @item show debug serial
19452 Displays the current state of displaying @value{GDBN} serial debugging
19453 info.
19454 @item set debug solib-frv
19455 @cindex FR-V shared-library debugging
19456 Turns on or off debugging messages for FR-V shared-library code.
19457 @item show debug solib-frv
19458 Display the current state of FR-V shared-library code debugging
19459 messages.
19460 @item set debug target
19461 @cindex target debugging info
19462 Turns on or off display of @value{GDBN} target debugging info. This info
19463 includes what is going on at the target level of GDB, as it happens. The
19464 default is 0. Set it to 1 to track events, and to 2 to also track the
19465 value of large memory transfers. Changes to this flag do not take effect
19466 until the next time you connect to a target or use the @code{run} command.
19467 @item show debug target
19468 Displays the current state of displaying @value{GDBN} target debugging
19469 info.
19470 @item set debug timestamp
19471 @cindex timestampping debugging info
19472 Turns on or off display of timestamps with @value{GDBN} debugging info.
19473 When enabled, seconds and microseconds are displayed before each debugging
19474 message.
19475 @item show debug timestamp
19476 Displays the current state of displaying timestamps with @value{GDBN}
19477 debugging info.
19478 @item set debugvarobj
19479 @cindex variable object debugging info
19480 Turns on or off display of @value{GDBN} variable object debugging
19481 info. The default is off.
19482 @item show debugvarobj
19483 Displays the current state of displaying @value{GDBN} variable object
19484 debugging info.
19485 @item set debug xml
19486 @cindex XML parser debugging
19487 Turns on or off debugging messages for built-in XML parsers.
19488 @item show debug xml
19489 Displays the current state of XML debugging messages.
19490 @end table
19491
19492 @node Other Misc Settings
19493 @section Other Miscellaneous Settings
19494 @cindex miscellaneous settings
19495
19496 @table @code
19497 @kindex set interactive-mode
19498 @item set interactive-mode
19499 If @code{on}, forces @value{GDBN} to operate interactively.
19500 If @code{off}, forces @value{GDBN} to operate non-interactively,
19501 If @code{auto} (the default), @value{GDBN} guesses which mode to use,
19502 based on whether the debugger was started in a terminal or not.
19503
19504 In the vast majority of cases, the debugger should be able to guess
19505 correctly which mode should be used. But this setting can be useful
19506 in certain specific cases, such as running a MinGW @value{GDBN}
19507 inside a cygwin window.
19508
19509 @kindex show interactive-mode
19510 @item show interactive-mode
19511 Displays whether the debugger is operating in interactive mode or not.
19512 @end table
19513
19514 @node Extending GDB
19515 @chapter Extending @value{GDBN}
19516 @cindex extending GDB
19517
19518 @value{GDBN} provides two mechanisms for extension. The first is based
19519 on composition of @value{GDBN} commands, and the second is based on the
19520 Python scripting language.
19521
19522 To facilitate the use of these extensions, @value{GDBN} is capable
19523 of evaluating the contents of a file. When doing so, @value{GDBN}
19524 can recognize which scripting language is being used by looking at
19525 the filename extension. Files with an unrecognized filename extension
19526 are always treated as a @value{GDBN} Command Files.
19527 @xref{Command Files,, Command files}.
19528
19529 You can control how @value{GDBN} evaluates these files with the following
19530 setting:
19531
19532 @table @code
19533 @kindex set script-extension
19534 @kindex show script-extension
19535 @item set script-extension off
19536 All scripts are always evaluated as @value{GDBN} Command Files.
19537
19538 @item set script-extension soft
19539 The debugger determines the scripting language based on filename
19540 extension. If this scripting language is supported, @value{GDBN}
19541 evaluates the script using that language. Otherwise, it evaluates
19542 the file as a @value{GDBN} Command File.
19543
19544 @item set script-extension strict
19545 The debugger determines the scripting language based on filename
19546 extension, and evaluates the script using that language. If the
19547 language is not supported, then the evaluation fails.
19548
19549 @item show script-extension
19550 Display the current value of the @code{script-extension} option.
19551
19552 @end table
19553
19554 @menu
19555 * Sequences:: Canned Sequences of Commands
19556 * Python:: Scripting @value{GDBN} using Python
19557 @end menu
19558
19559 @node Sequences
19560 @section Canned Sequences of Commands
19561
19562 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
19563 Command Lists}), @value{GDBN} provides two ways to store sequences of
19564 commands for execution as a unit: user-defined commands and command
19565 files.
19566
19567 @menu
19568 * Define:: How to define your own commands
19569 * Hooks:: Hooks for user-defined commands
19570 * Command Files:: How to write scripts of commands to be stored in a file
19571 * Output:: Commands for controlled output
19572 @end menu
19573
19574 @node Define
19575 @subsection User-defined Commands
19576
19577 @cindex user-defined command
19578 @cindex arguments, to user-defined commands
19579 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
19580 which you assign a new name as a command. This is done with the
19581 @code{define} command. User commands may accept up to 10 arguments
19582 separated by whitespace. Arguments are accessed within the user command
19583 via @code{$arg0@dots{}$arg9}. A trivial example:
19584
19585 @smallexample
19586 define adder
19587 print $arg0 + $arg1 + $arg2
19588 end
19589 @end smallexample
19590
19591 @noindent
19592 To execute the command use:
19593
19594 @smallexample
19595 adder 1 2 3
19596 @end smallexample
19597
19598 @noindent
19599 This defines the command @code{adder}, which prints the sum of
19600 its three arguments. Note the arguments are text substitutions, so they may
19601 reference variables, use complex expressions, or even perform inferior
19602 functions calls.
19603
19604 @cindex argument count in user-defined commands
19605 @cindex how many arguments (user-defined commands)
19606 In addition, @code{$argc} may be used to find out how many arguments have
19607 been passed. This expands to a number in the range 0@dots{}10.
19608
19609 @smallexample
19610 define adder
19611 if $argc == 2
19612 print $arg0 + $arg1
19613 end
19614 if $argc == 3
19615 print $arg0 + $arg1 + $arg2
19616 end
19617 end
19618 @end smallexample
19619
19620 @table @code
19621
19622 @kindex define
19623 @item define @var{commandname}
19624 Define a command named @var{commandname}. If there is already a command
19625 by that name, you are asked to confirm that you want to redefine it.
19626 @var{commandname} may be a bare command name consisting of letters,
19627 numbers, dashes, and underscores. It may also start with any predefined
19628 prefix command. For example, @samp{define target my-target} creates
19629 a user-defined @samp{target my-target} command.
19630
19631 The definition of the command is made up of other @value{GDBN} command lines,
19632 which are given following the @code{define} command. The end of these
19633 commands is marked by a line containing @code{end}.
19634
19635 @kindex document
19636 @kindex end@r{ (user-defined commands)}
19637 @item document @var{commandname}
19638 Document the user-defined command @var{commandname}, so that it can be
19639 accessed by @code{help}. The command @var{commandname} must already be
19640 defined. This command reads lines of documentation just as @code{define}
19641 reads the lines of the command definition, ending with @code{end}.
19642 After the @code{document} command is finished, @code{help} on command
19643 @var{commandname} displays the documentation you have written.
19644
19645 You may use the @code{document} command again to change the
19646 documentation of a command. Redefining the command with @code{define}
19647 does not change the documentation.
19648
19649 @kindex dont-repeat
19650 @cindex don't repeat command
19651 @item dont-repeat
19652 Used inside a user-defined command, this tells @value{GDBN} that this
19653 command should not be repeated when the user hits @key{RET}
19654 (@pxref{Command Syntax, repeat last command}).
19655
19656 @kindex help user-defined
19657 @item help user-defined
19658 List all user-defined commands, with the first line of the documentation
19659 (if any) for each.
19660
19661 @kindex show user
19662 @item show user
19663 @itemx show user @var{commandname}
19664 Display the @value{GDBN} commands used to define @var{commandname} (but
19665 not its documentation). If no @var{commandname} is given, display the
19666 definitions for all user-defined commands.
19667
19668 @cindex infinite recursion in user-defined commands
19669 @kindex show max-user-call-depth
19670 @kindex set max-user-call-depth
19671 @item show max-user-call-depth
19672 @itemx set max-user-call-depth
19673 The value of @code{max-user-call-depth} controls how many recursion
19674 levels are allowed in user-defined commands before @value{GDBN} suspects an
19675 infinite recursion and aborts the command.
19676 @end table
19677
19678 In addition to the above commands, user-defined commands frequently
19679 use control flow commands, described in @ref{Command Files}.
19680
19681 When user-defined commands are executed, the
19682 commands of the definition are not printed. An error in any command
19683 stops execution of the user-defined command.
19684
19685 If used interactively, commands that would ask for confirmation proceed
19686 without asking when used inside a user-defined command. Many @value{GDBN}
19687 commands that normally print messages to say what they are doing omit the
19688 messages when used in a user-defined command.
19689
19690 @node Hooks
19691 @subsection User-defined Command Hooks
19692 @cindex command hooks
19693 @cindex hooks, for commands
19694 @cindex hooks, pre-command
19695
19696 @kindex hook
19697 You may define @dfn{hooks}, which are a special kind of user-defined
19698 command. Whenever you run the command @samp{foo}, if the user-defined
19699 command @samp{hook-foo} exists, it is executed (with no arguments)
19700 before that command.
19701
19702 @cindex hooks, post-command
19703 @kindex hookpost
19704 A hook may also be defined which is run after the command you executed.
19705 Whenever you run the command @samp{foo}, if the user-defined command
19706 @samp{hookpost-foo} exists, it is executed (with no arguments) after
19707 that command. Post-execution hooks may exist simultaneously with
19708 pre-execution hooks, for the same command.
19709
19710 It is valid for a hook to call the command which it hooks. If this
19711 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
19712
19713 @c It would be nice if hookpost could be passed a parameter indicating
19714 @c if the command it hooks executed properly or not. FIXME!
19715
19716 @kindex stop@r{, a pseudo-command}
19717 In addition, a pseudo-command, @samp{stop} exists. Defining
19718 (@samp{hook-stop}) makes the associated commands execute every time
19719 execution stops in your program: before breakpoint commands are run,
19720 displays are printed, or the stack frame is printed.
19721
19722 For example, to ignore @code{SIGALRM} signals while
19723 single-stepping, but treat them normally during normal execution,
19724 you could define:
19725
19726 @smallexample
19727 define hook-stop
19728 handle SIGALRM nopass
19729 end
19730
19731 define hook-run
19732 handle SIGALRM pass
19733 end
19734
19735 define hook-continue
19736 handle SIGALRM pass
19737 end
19738 @end smallexample
19739
19740 As a further example, to hook at the beginning and end of the @code{echo}
19741 command, and to add extra text to the beginning and end of the message,
19742 you could define:
19743
19744 @smallexample
19745 define hook-echo
19746 echo <<<---
19747 end
19748
19749 define hookpost-echo
19750 echo --->>>\n
19751 end
19752
19753 (@value{GDBP}) echo Hello World
19754 <<<---Hello World--->>>
19755 (@value{GDBP})
19756
19757 @end smallexample
19758
19759 You can define a hook for any single-word command in @value{GDBN}, but
19760 not for command aliases; you should define a hook for the basic command
19761 name, e.g.@: @code{backtrace} rather than @code{bt}.
19762 @c FIXME! So how does Joe User discover whether a command is an alias
19763 @c or not?
19764 You can hook a multi-word command by adding @code{hook-} or
19765 @code{hookpost-} to the last word of the command, e.g.@:
19766 @samp{define target hook-remote} to add a hook to @samp{target remote}.
19767
19768 If an error occurs during the execution of your hook, execution of
19769 @value{GDBN} commands stops and @value{GDBN} issues a prompt
19770 (before the command that you actually typed had a chance to run).
19771
19772 If you try to define a hook which does not match any known command, you
19773 get a warning from the @code{define} command.
19774
19775 @node Command Files
19776 @subsection Command Files
19777
19778 @cindex command files
19779 @cindex scripting commands
19780 A command file for @value{GDBN} is a text file made of lines that are
19781 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
19782 also be included. An empty line in a command file does nothing; it
19783 does not mean to repeat the last command, as it would from the
19784 terminal.
19785
19786 You can request the execution of a command file with the @code{source}
19787 command. Note that the @code{source} command is also used to evaluate
19788 scripts that are not Command Files. The exact behavior can be configured
19789 using the @code{script-extension} setting.
19790 @xref{Extending GDB,, Extending GDB}.
19791
19792 @table @code
19793 @kindex source
19794 @cindex execute commands from a file
19795 @item source [-s] [-v] @var{filename}
19796 Execute the command file @var{filename}.
19797 @end table
19798
19799 The lines in a command file are generally executed sequentially,
19800 unless the order of execution is changed by one of the
19801 @emph{flow-control commands} described below. The commands are not
19802 printed as they are executed. An error in any command terminates
19803 execution of the command file and control is returned to the console.
19804
19805 @value{GDBN} first searches for @var{filename} in the current directory.
19806 If the file is not found there, and @var{filename} does not specify a
19807 directory, then @value{GDBN} also looks for the file on the source search path
19808 (specified with the @samp{directory} command);
19809 except that @file{$cdir} is not searched because the compilation directory
19810 is not relevant to scripts.
19811
19812 If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
19813 on the search path even if @var{filename} specifies a directory.
19814 The search is done by appending @var{filename} to each element of the
19815 search path. So, for example, if @var{filename} is @file{mylib/myscript}
19816 and the search path contains @file{/home/user} then @value{GDBN} will
19817 look for the script @file{/home/user/mylib/myscript}.
19818 The search is also done if @var{filename} is an absolute path.
19819 For example, if @var{filename} is @file{/tmp/myscript} and
19820 the search path contains @file{/home/user} then @value{GDBN} will
19821 look for the script @file{/home/user/tmp/myscript}.
19822 For DOS-like systems, if @var{filename} contains a drive specification,
19823 it is stripped before concatenation. For example, if @var{filename} is
19824 @file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
19825 will look for the script @file{c:/tmp/myscript}.
19826
19827 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
19828 each command as it is executed. The option must be given before
19829 @var{filename}, and is interpreted as part of the filename anywhere else.
19830
19831 Commands that would ask for confirmation if used interactively proceed
19832 without asking when used in a command file. Many @value{GDBN} commands that
19833 normally print messages to say what they are doing omit the messages
19834 when called from command files.
19835
19836 @value{GDBN} also accepts command input from standard input. In this
19837 mode, normal output goes to standard output and error output goes to
19838 standard error. Errors in a command file supplied on standard input do
19839 not terminate execution of the command file---execution continues with
19840 the next command.
19841
19842 @smallexample
19843 gdb < cmds > log 2>&1
19844 @end smallexample
19845
19846 (The syntax above will vary depending on the shell used.) This example
19847 will execute commands from the file @file{cmds}. All output and errors
19848 would be directed to @file{log}.
19849
19850 Since commands stored on command files tend to be more general than
19851 commands typed interactively, they frequently need to deal with
19852 complicated situations, such as different or unexpected values of
19853 variables and symbols, changes in how the program being debugged is
19854 built, etc. @value{GDBN} provides a set of flow-control commands to
19855 deal with these complexities. Using these commands, you can write
19856 complex scripts that loop over data structures, execute commands
19857 conditionally, etc.
19858
19859 @table @code
19860 @kindex if
19861 @kindex else
19862 @item if
19863 @itemx else
19864 This command allows to include in your script conditionally executed
19865 commands. The @code{if} command takes a single argument, which is an
19866 expression to evaluate. It is followed by a series of commands that
19867 are executed only if the expression is true (its value is nonzero).
19868 There can then optionally be an @code{else} line, followed by a series
19869 of commands that are only executed if the expression was false. The
19870 end of the list is marked by a line containing @code{end}.
19871
19872 @kindex while
19873 @item while
19874 This command allows to write loops. Its syntax is similar to
19875 @code{if}: the command takes a single argument, which is an expression
19876 to evaluate, and must be followed by the commands to execute, one per
19877 line, terminated by an @code{end}. These commands are called the
19878 @dfn{body} of the loop. The commands in the body of @code{while} are
19879 executed repeatedly as long as the expression evaluates to true.
19880
19881 @kindex loop_break
19882 @item loop_break
19883 This command exits the @code{while} loop in whose body it is included.
19884 Execution of the script continues after that @code{while}s @code{end}
19885 line.
19886
19887 @kindex loop_continue
19888 @item loop_continue
19889 This command skips the execution of the rest of the body of commands
19890 in the @code{while} loop in whose body it is included. Execution
19891 branches to the beginning of the @code{while} loop, where it evaluates
19892 the controlling expression.
19893
19894 @kindex end@r{ (if/else/while commands)}
19895 @item end
19896 Terminate the block of commands that are the body of @code{if},
19897 @code{else}, or @code{while} flow-control commands.
19898 @end table
19899
19900
19901 @node Output
19902 @subsection Commands for Controlled Output
19903
19904 During the execution of a command file or a user-defined command, normal
19905 @value{GDBN} output is suppressed; the only output that appears is what is
19906 explicitly printed by the commands in the definition. This section
19907 describes three commands useful for generating exactly the output you
19908 want.
19909
19910 @table @code
19911 @kindex echo
19912 @item echo @var{text}
19913 @c I do not consider backslash-space a standard C escape sequence
19914 @c because it is not in ANSI.
19915 Print @var{text}. Nonprinting characters can be included in
19916 @var{text} using C escape sequences, such as @samp{\n} to print a
19917 newline. @strong{No newline is printed unless you specify one.}
19918 In addition to the standard C escape sequences, a backslash followed
19919 by a space stands for a space. This is useful for displaying a
19920 string with spaces at the beginning or the end, since leading and
19921 trailing spaces are otherwise trimmed from all arguments.
19922 To print @samp{@w{ }and foo =@w{ }}, use the command
19923 @samp{echo \@w{ }and foo = \@w{ }}.
19924
19925 A backslash at the end of @var{text} can be used, as in C, to continue
19926 the command onto subsequent lines. For example,
19927
19928 @smallexample
19929 echo This is some text\n\
19930 which is continued\n\
19931 onto several lines.\n
19932 @end smallexample
19933
19934 produces the same output as
19935
19936 @smallexample
19937 echo This is some text\n
19938 echo which is continued\n
19939 echo onto several lines.\n
19940 @end smallexample
19941
19942 @kindex output
19943 @item output @var{expression}
19944 Print the value of @var{expression} and nothing but that value: no
19945 newlines, no @samp{$@var{nn} = }. The value is not entered in the
19946 value history either. @xref{Expressions, ,Expressions}, for more information
19947 on expressions.
19948
19949 @item output/@var{fmt} @var{expression}
19950 Print the value of @var{expression} in format @var{fmt}. You can use
19951 the same formats as for @code{print}. @xref{Output Formats,,Output
19952 Formats}, for more information.
19953
19954 @kindex printf
19955 @item printf @var{template}, @var{expressions}@dots{}
19956 Print the values of one or more @var{expressions} under the control of
19957 the string @var{template}. To print several values, make
19958 @var{expressions} be a comma-separated list of individual expressions,
19959 which may be either numbers or pointers. Their values are printed as
19960 specified by @var{template}, exactly as a C program would do by
19961 executing the code below:
19962
19963 @smallexample
19964 printf (@var{template}, @var{expressions}@dots{});
19965 @end smallexample
19966
19967 As in @code{C} @code{printf}, ordinary characters in @var{template}
19968 are printed verbatim, while @dfn{conversion specification} introduced
19969 by the @samp{%} character cause subsequent @var{expressions} to be
19970 evaluated, their values converted and formatted according to type and
19971 style information encoded in the conversion specifications, and then
19972 printed.
19973
19974 For example, you can print two values in hex like this:
19975
19976 @smallexample
19977 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
19978 @end smallexample
19979
19980 @code{printf} supports all the standard @code{C} conversion
19981 specifications, including the flags and modifiers between the @samp{%}
19982 character and the conversion letter, with the following exceptions:
19983
19984 @itemize @bullet
19985 @item
19986 The argument-ordering modifiers, such as @samp{2$}, are not supported.
19987
19988 @item
19989 The modifier @samp{*} is not supported for specifying precision or
19990 width.
19991
19992 @item
19993 The @samp{'} flag (for separation of digits into groups according to
19994 @code{LC_NUMERIC'}) is not supported.
19995
19996 @item
19997 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
19998 supported.
19999
20000 @item
20001 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
20002
20003 @item
20004 The conversion letters @samp{a} and @samp{A} are not supported.
20005 @end itemize
20006
20007 @noindent
20008 Note that the @samp{ll} type modifier is supported only if the
20009 underlying @code{C} implementation used to build @value{GDBN} supports
20010 the @code{long long int} type, and the @samp{L} type modifier is
20011 supported only if @code{long double} type is available.
20012
20013 As in @code{C}, @code{printf} supports simple backslash-escape
20014 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
20015 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
20016 single character. Octal and hexadecimal escape sequences are not
20017 supported.
20018
20019 Additionally, @code{printf} supports conversion specifications for DFP
20020 (@dfn{Decimal Floating Point}) types using the following length modifiers
20021 together with a floating point specifier.
20022 letters:
20023
20024 @itemize @bullet
20025 @item
20026 @samp{H} for printing @code{Decimal32} types.
20027
20028 @item
20029 @samp{D} for printing @code{Decimal64} types.
20030
20031 @item
20032 @samp{DD} for printing @code{Decimal128} types.
20033 @end itemize
20034
20035 If the underlying @code{C} implementation used to build @value{GDBN} has
20036 support for the three length modifiers for DFP types, other modifiers
20037 such as width and precision will also be available for @value{GDBN} to use.
20038
20039 In case there is no such @code{C} support, no additional modifiers will be
20040 available and the value will be printed in the standard way.
20041
20042 Here's an example of printing DFP types using the above conversion letters:
20043 @smallexample
20044 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
20045 @end smallexample
20046
20047 @end table
20048
20049 @node Python
20050 @section Scripting @value{GDBN} using Python
20051 @cindex python scripting
20052 @cindex scripting with python
20053
20054 You can script @value{GDBN} using the @uref{http://www.python.org/,
20055 Python programming language}. This feature is available only if
20056 @value{GDBN} was configured using @option{--with-python}.
20057
20058 @menu
20059 * Python Commands:: Accessing Python from @value{GDBN}.
20060 * Python API:: Accessing @value{GDBN} from Python.
20061 * Auto-loading:: Automatically loading Python code.
20062 @end menu
20063
20064 @node Python Commands
20065 @subsection Python Commands
20066 @cindex python commands
20067 @cindex commands to access python
20068
20069 @value{GDBN} provides one command for accessing the Python interpreter,
20070 and one related setting:
20071
20072 @table @code
20073 @kindex python
20074 @item python @r{[}@var{code}@r{]}
20075 The @code{python} command can be used to evaluate Python code.
20076
20077 If given an argument, the @code{python} command will evaluate the
20078 argument as a Python command. For example:
20079
20080 @smallexample
20081 (@value{GDBP}) python print 23
20082 23
20083 @end smallexample
20084
20085 If you do not provide an argument to @code{python}, it will act as a
20086 multi-line command, like @code{define}. In this case, the Python
20087 script is made up of subsequent command lines, given after the
20088 @code{python} command. This command list is terminated using a line
20089 containing @code{end}. For example:
20090
20091 @smallexample
20092 (@value{GDBP}) python
20093 Type python script
20094 End with a line saying just "end".
20095 >print 23
20096 >end
20097 23
20098 @end smallexample
20099
20100 @kindex maint set python print-stack
20101 @item maint set python print-stack
20102 By default, @value{GDBN} will print a stack trace when an error occurs
20103 in a Python script. This can be controlled using @code{maint set
20104 python print-stack}: if @code{on}, the default, then Python stack
20105 printing is enabled; if @code{off}, then Python stack printing is
20106 disabled.
20107 @end table
20108
20109 It is also possible to execute a Python script from the @value{GDBN}
20110 interpreter:
20111
20112 @table @code
20113 @item source @file{script-name}
20114 The script name must end with @samp{.py} and @value{GDBN} must be configured
20115 to recognize the script language based on filename extension using
20116 the @code{script-extension} setting. @xref{Extending GDB, ,Extending GDB}.
20117
20118 @item python execfile ("script-name")
20119 This method is based on the @code{execfile} Python built-in function,
20120 and thus is always available.
20121 @end table
20122
20123 @node Python API
20124 @subsection Python API
20125 @cindex python api
20126 @cindex programming in python
20127
20128 @cindex python stdout
20129 @cindex python pagination
20130 At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
20131 @code{sys.stderr} to print using @value{GDBN}'s output-paging streams.
20132 A Python program which outputs to one of these streams may have its
20133 output interrupted by the user (@pxref{Screen Size}). In this
20134 situation, a Python @code{KeyboardInterrupt} exception is thrown.
20135
20136 @menu
20137 * Basic Python:: Basic Python Functions.
20138 * Exception Handling::
20139 * Values From Inferior::
20140 * Types In Python:: Python representation of types.
20141 * Pretty Printing API:: Pretty-printing values.
20142 * Selecting Pretty-Printers:: How GDB chooses a pretty-printer.
20143 * Disabling Pretty-Printers:: Disabling broken printers.
20144 * Commands In Python:: Implementing new commands in Python.
20145 * Parameters In Python:: Adding new @value{GDBN} parameters.
20146 * Functions In Python:: Writing new convenience functions.
20147 * Progspaces In Python:: Program spaces.
20148 * Objfiles In Python:: Object files.
20149 * Frames In Python:: Accessing inferior stack frames from Python.
20150 * Blocks In Python:: Accessing frame blocks from Python.
20151 * Symbols In Python:: Python representation of symbols.
20152 * Symbol Tables In Python:: Python representation of symbol tables.
20153 * Lazy Strings In Python:: Python representation of lazy strings.
20154 * Breakpoints In Python:: Manipulating breakpoints using Python.
20155 @end menu
20156
20157 @node Basic Python
20158 @subsubsection Basic Python
20159
20160 @cindex python functions
20161 @cindex python module
20162 @cindex gdb module
20163 @value{GDBN} introduces a new Python module, named @code{gdb}. All
20164 methods and classes added by @value{GDBN} are placed in this module.
20165 @value{GDBN} automatically @code{import}s the @code{gdb} module for
20166 use in all scripts evaluated by the @code{python} command.
20167
20168 @findex gdb.execute
20169 @defun execute command [from_tty]
20170 Evaluate @var{command}, a string, as a @value{GDBN} CLI command.
20171 If a GDB exception happens while @var{command} runs, it is
20172 translated as described in @ref{Exception Handling,,Exception Handling}.
20173 If no exceptions occur, this function returns @code{None}.
20174
20175 @var{from_tty} specifies whether @value{GDBN} ought to consider this
20176 command as having originated from the user invoking it interactively.
20177 It must be a boolean value. If omitted, it defaults to @code{False}.
20178 @end defun
20179
20180 @findex gdb.breakpoints
20181 @defun breakpoints
20182 Return a sequence holding all of @value{GDBN}'s breakpoints.
20183 @xref{Breakpoints In Python}, for more information.
20184 @end defun
20185
20186 @findex gdb.parameter
20187 @defun parameter parameter
20188 Return the value of a @value{GDBN} parameter. @var{parameter} is a
20189 string naming the parameter to look up; @var{parameter} may contain
20190 spaces if the parameter has a multi-part name. For example,
20191 @samp{print object} is a valid parameter name.
20192
20193 If the named parameter does not exist, this function throws a
20194 @code{RuntimeError}. Otherwise, the parameter's value is converted to
20195 a Python value of the appropriate type, and returned.
20196 @end defun
20197
20198 @findex gdb.history
20199 @defun history number
20200 Return a value from @value{GDBN}'s value history (@pxref{Value
20201 History}). @var{number} indicates which history element to return.
20202 If @var{number} is negative, then @value{GDBN} will take its absolute value
20203 and count backward from the last element (i.e., the most recent element) to
20204 find the value to return. If @var{number} is zero, then @value{GDBN} will
20205 return the most recent element. If the element specified by @var{number}
20206 doesn't exist in the value history, a @code{RuntimeError} exception will be
20207 raised.
20208
20209 If no exception is raised, the return value is always an instance of
20210 @code{gdb.Value} (@pxref{Values From Inferior}).
20211 @end defun
20212
20213 @findex gdb.parse_and_eval
20214 @defun parse_and_eval expression
20215 Parse @var{expression} as an expression in the current language,
20216 evaluate it, and return the result as a @code{gdb.Value}.
20217 @var{expression} must be a string.
20218
20219 This function can be useful when implementing a new command
20220 (@pxref{Commands In Python}), as it provides a way to parse the
20221 command's argument as an expression. It is also useful simply to
20222 compute values, for example, it is the only way to get the value of a
20223 convenience variable (@pxref{Convenience Vars}) as a @code{gdb.Value}.
20224 @end defun
20225
20226 @findex gdb.write
20227 @defun write string
20228 Print a string to @value{GDBN}'s paginated standard output stream.
20229 Writing to @code{sys.stdout} or @code{sys.stderr} will automatically
20230 call this function.
20231 @end defun
20232
20233 @findex gdb.flush
20234 @defun flush
20235 Flush @value{GDBN}'s paginated standard output stream. Flushing
20236 @code{sys.stdout} or @code{sys.stderr} will automatically call this
20237 function.
20238 @end defun
20239
20240 @findex gdb.target_charset
20241 @defun target_charset
20242 Return the name of the current target character set (@pxref{Character
20243 Sets}). This differs from @code{gdb.parameter('target-charset')} in
20244 that @samp{auto} is never returned.
20245 @end defun
20246
20247 @findex gdb.target_wide_charset
20248 @defun target_wide_charset
20249 Return the name of the current target wide character set
20250 (@pxref{Character Sets}). This differs from
20251 @code{gdb.parameter('target-wide-charset')} in that @samp{auto} is
20252 never returned.
20253 @end defun
20254
20255 @node Exception Handling
20256 @subsubsection Exception Handling
20257 @cindex python exceptions
20258 @cindex exceptions, python
20259
20260 When executing the @code{python} command, Python exceptions
20261 uncaught within the Python code are translated to calls to
20262 @value{GDBN} error-reporting mechanism. If the command that called
20263 @code{python} does not handle the error, @value{GDBN} will
20264 terminate it and print an error message containing the Python
20265 exception name, the associated value, and the Python call stack
20266 backtrace at the point where the exception was raised. Example:
20267
20268 @smallexample
20269 (@value{GDBP}) python print foo
20270 Traceback (most recent call last):
20271 File "<string>", line 1, in <module>
20272 NameError: name 'foo' is not defined
20273 @end smallexample
20274
20275 @value{GDBN} errors that happen in @value{GDBN} commands invoked by Python
20276 code are converted to Python @code{RuntimeError} exceptions. User
20277 interrupt (via @kbd{C-c} or by typing @kbd{q} at a pagination
20278 prompt) is translated to a Python @code{KeyboardInterrupt}
20279 exception. If you catch these exceptions in your Python code, your
20280 exception handler will see @code{RuntimeError} or
20281 @code{KeyboardInterrupt} as the exception type, the @value{GDBN} error
20282 message as its value, and the Python call stack backtrace at the
20283 Python statement closest to where the @value{GDBN} error occured as the
20284 traceback.
20285
20286 @findex gdb.GdbError
20287 When implementing @value{GDBN} commands in Python via @code{gdb.Command},
20288 it is useful to be able to throw an exception that doesn't cause a
20289 traceback to be printed. For example, the user may have invoked the
20290 command incorrectly. Use the @code{gdb.GdbError} exception
20291 to handle this case. Example:
20292
20293 @smallexample
20294 (gdb) python
20295 >class HelloWorld (gdb.Command):
20296 > """Greet the whole world."""
20297 > def __init__ (self):
20298 > super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_OBSCURE)
20299 > def invoke (self, args, from_tty):
20300 > argv = gdb.string_to_argv (args)
20301 > if len (argv) != 0:
20302 > raise gdb.GdbError ("hello-world takes no arguments")
20303 > print "Hello, World!"
20304 >HelloWorld ()
20305 >end
20306 (gdb) hello-world 42
20307 hello-world takes no arguments
20308 @end smallexample
20309
20310 @node Values From Inferior
20311 @subsubsection Values From Inferior
20312 @cindex values from inferior, with Python
20313 @cindex python, working with values from inferior
20314
20315 @cindex @code{gdb.Value}
20316 @value{GDBN} provides values it obtains from the inferior program in
20317 an object of type @code{gdb.Value}. @value{GDBN} uses this object
20318 for its internal bookkeeping of the inferior's values, and for
20319 fetching values when necessary.
20320
20321 Inferior values that are simple scalars can be used directly in
20322 Python expressions that are valid for the value's data type. Here's
20323 an example for an integer or floating-point value @code{some_val}:
20324
20325 @smallexample
20326 bar = some_val + 2
20327 @end smallexample
20328
20329 @noindent
20330 As result of this, @code{bar} will also be a @code{gdb.Value} object
20331 whose values are of the same type as those of @code{some_val}.
20332
20333 Inferior values that are structures or instances of some class can
20334 be accessed using the Python @dfn{dictionary syntax}. For example, if
20335 @code{some_val} is a @code{gdb.Value} instance holding a structure, you
20336 can access its @code{foo} element with:
20337
20338 @smallexample
20339 bar = some_val['foo']
20340 @end smallexample
20341
20342 Again, @code{bar} will also be a @code{gdb.Value} object.
20343
20344 The following attributes are provided:
20345
20346 @table @code
20347 @defivar Value address
20348 If this object is addressable, this read-only attribute holds a
20349 @code{gdb.Value} object representing the address. Otherwise,
20350 this attribute holds @code{None}.
20351 @end defivar
20352
20353 @cindex optimized out value in Python
20354 @defivar Value is_optimized_out
20355 This read-only boolean attribute is true if the compiler optimized out
20356 this value, thus it is not available for fetching from the inferior.
20357 @end defivar
20358
20359 @defivar Value type
20360 The type of this @code{gdb.Value}. The value of this attribute is a
20361 @code{gdb.Type} object.
20362 @end defivar
20363 @end table
20364
20365 The following methods are provided:
20366
20367 @table @code
20368 @defmethod Value cast type
20369 Return a new instance of @code{gdb.Value} that is the result of
20370 casting this instance to the type described by @var{type}, which must
20371 be a @code{gdb.Type} object. If the cast cannot be performed for some
20372 reason, this method throws an exception.
20373 @end defmethod
20374
20375 @defmethod Value dereference
20376 For pointer data types, this method returns a new @code{gdb.Value} object
20377 whose contents is the object pointed to by the pointer. For example, if
20378 @code{foo} is a C pointer to an @code{int}, declared in your C program as
20379
20380 @smallexample
20381 int *foo;
20382 @end smallexample
20383
20384 @noindent
20385 then you can use the corresponding @code{gdb.Value} to access what
20386 @code{foo} points to like this:
20387
20388 @smallexample
20389 bar = foo.dereference ()
20390 @end smallexample
20391
20392 The result @code{bar} will be a @code{gdb.Value} object holding the
20393 value pointed to by @code{foo}.
20394 @end defmethod
20395
20396 @defmethod Value string @r{[}encoding@r{]} @r{[}errors@r{]} @r{[}length@r{]}
20397 If this @code{gdb.Value} represents a string, then this method
20398 converts the contents to a Python string. Otherwise, this method will
20399 throw an exception.
20400
20401 Strings are recognized in a language-specific way; whether a given
20402 @code{gdb.Value} represents a string is determined by the current
20403 language.
20404
20405 For C-like languages, a value is a string if it is a pointer to or an
20406 array of characters or ints. The string is assumed to be terminated
20407 by a zero of the appropriate width. However if the optional length
20408 argument is given, the string will be converted to that given length,
20409 ignoring any embedded zeros that the string may contain.
20410
20411 If the optional @var{encoding} argument is given, it must be a string
20412 naming the encoding of the string in the @code{gdb.Value}, such as
20413 @code{"ascii"}, @code{"iso-8859-6"} or @code{"utf-8"}. It accepts
20414 the same encodings as the corresponding argument to Python's
20415 @code{string.decode} method, and the Python codec machinery will be used
20416 to convert the string. If @var{encoding} is not given, or if
20417 @var{encoding} is the empty string, then either the @code{target-charset}
20418 (@pxref{Character Sets}) will be used, or a language-specific encoding
20419 will be used, if the current language is able to supply one.
20420
20421 The optional @var{errors} argument is the same as the corresponding
20422 argument to Python's @code{string.decode} method.
20423
20424 If the optional @var{length} argument is given, the string will be
20425 fetched and converted to the given length.
20426 @end defmethod
20427
20428 @defmethod Value lazy_string @r{[}encoding@r{]} @r{[}length@r{]}
20429 If this @code{gdb.Value} represents a string, then this method
20430 converts the contents to a @code{gdb.LazyString} (@pxref{Lazy Strings
20431 In Python}). Otherwise, this method will throw an exception.
20432
20433 If the optional @var{encoding} argument is given, it must be a string
20434 naming the encoding of the @code{gdb.LazyString}. Some examples are:
20435 @samp{ascii}, @samp{iso-8859-6} or @samp{utf-8}. If the
20436 @var{encoding} argument is an encoding that @value{GDBN} does
20437 recognize, @value{GDBN} will raise an error.
20438
20439 When a lazy string is printed, the @value{GDBN} encoding machinery is
20440 used to convert the string during printing. If the optional
20441 @var{encoding} argument is not provided, or is an empty string,
20442 @value{GDBN} will automatically select the encoding most suitable for
20443 the string type. For further information on encoding in @value{GDBN}
20444 please see @ref{Character Sets}.
20445
20446 If the optional @var{length} argument is given, the string will be
20447 fetched and encoded to the length of characters specified. If
20448 the @var{length} argument is not provided, the string will be fetched
20449 and encoded until a null of appropriate width is found.
20450 @end defmethod
20451 @end table
20452
20453 @node Types In Python
20454 @subsubsection Types In Python
20455 @cindex types in Python
20456 @cindex Python, working with types
20457
20458 @tindex gdb.Type
20459 @value{GDBN} represents types from the inferior using the class
20460 @code{gdb.Type}.
20461
20462 The following type-related functions are available in the @code{gdb}
20463 module:
20464
20465 @findex gdb.lookup_type
20466 @defun lookup_type name [block]
20467 This function looks up a type by name. @var{name} is the name of the
20468 type to look up. It must be a string.
20469
20470 If @var{block} is given, then @var{name} is looked up in that scope.
20471 Otherwise, it is searched for globally.
20472
20473 Ordinarily, this function will return an instance of @code{gdb.Type}.
20474 If the named type cannot be found, it will throw an exception.
20475 @end defun
20476
20477 An instance of @code{Type} has the following attributes:
20478
20479 @table @code
20480 @defivar Type code
20481 The type code for this type. The type code will be one of the
20482 @code{TYPE_CODE_} constants defined below.
20483 @end defivar
20484
20485 @defivar Type sizeof
20486 The size of this type, in target @code{char} units. Usually, a
20487 target's @code{char} type will be an 8-bit byte. However, on some
20488 unusual platforms, this type may have a different size.
20489 @end defivar
20490
20491 @defivar Type tag
20492 The tag name for this type. The tag name is the name after
20493 @code{struct}, @code{union}, or @code{enum} in C and C@t{++}; not all
20494 languages have this concept. If this type has no tag name, then
20495 @code{None} is returned.
20496 @end defivar
20497 @end table
20498
20499 The following methods are provided:
20500
20501 @table @code
20502 @defmethod Type fields
20503 For structure and union types, this method returns the fields. Range
20504 types have two fields, the minimum and maximum values. Enum types
20505 have one field per enum constant. Function and method types have one
20506 field per parameter. The base types of C@t{++} classes are also
20507 represented as fields. If the type has no fields, or does not fit
20508 into one of these categories, an empty sequence will be returned.
20509
20510 Each field is an object, with some pre-defined attributes:
20511 @table @code
20512 @item bitpos
20513 This attribute is not available for @code{static} fields (as in
20514 C@t{++} or Java). For non-@code{static} fields, the value is the bit
20515 position of the field.
20516
20517 @item name
20518 The name of the field, or @code{None} for anonymous fields.
20519
20520 @item artificial
20521 This is @code{True} if the field is artificial, usually meaning that
20522 it was provided by the compiler and not the user. This attribute is
20523 always provided, and is @code{False} if the field is not artificial.
20524
20525 @item is_base_class
20526 This is @code{True} if the field represents a base class of a C@t{++}
20527 structure. This attribute is always provided, and is @code{False}
20528 if the field is not a base class of the type that is the argument of
20529 @code{fields}, or if that type was not a C@t{++} class.
20530
20531 @item bitsize
20532 If the field is packed, or is a bitfield, then this will have a
20533 non-zero value, which is the size of the field in bits. Otherwise,
20534 this will be zero; in this case the field's size is given by its type.
20535
20536 @item type
20537 The type of the field. This is usually an instance of @code{Type},
20538 but it can be @code{None} in some situations.
20539 @end table
20540 @end defmethod
20541
20542 @defmethod Type const
20543 Return a new @code{gdb.Type} object which represents a
20544 @code{const}-qualified variant of this type.
20545 @end defmethod
20546
20547 @defmethod Type volatile
20548 Return a new @code{gdb.Type} object which represents a
20549 @code{volatile}-qualified variant of this type.
20550 @end defmethod
20551
20552 @defmethod Type unqualified
20553 Return a new @code{gdb.Type} object which represents an unqualified
20554 variant of this type. That is, the result is neither @code{const} nor
20555 @code{volatile}.
20556 @end defmethod
20557
20558 @defmethod Type range
20559 Return a Python @code{Tuple} object that contains two elements: the
20560 low bound of the argument type and the high bound of that type. If
20561 the type does not have a range, @value{GDBN} will raise a
20562 @code{RuntimeError} exception.
20563 @end defmethod
20564
20565 @defmethod Type reference
20566 Return a new @code{gdb.Type} object which represents a reference to this
20567 type.
20568 @end defmethod
20569
20570 @defmethod Type pointer
20571 Return a new @code{gdb.Type} object which represents a pointer to this
20572 type.
20573 @end defmethod
20574
20575 @defmethod Type strip_typedefs
20576 Return a new @code{gdb.Type} that represents the real type,
20577 after removing all layers of typedefs.
20578 @end defmethod
20579
20580 @defmethod Type target
20581 Return a new @code{gdb.Type} object which represents the target type
20582 of this type.
20583
20584 For a pointer type, the target type is the type of the pointed-to
20585 object. For an array type (meaning C-like arrays), the target type is
20586 the type of the elements of the array. For a function or method type,
20587 the target type is the type of the return value. For a complex type,
20588 the target type is the type of the elements. For a typedef, the
20589 target type is the aliased type.
20590
20591 If the type does not have a target, this method will throw an
20592 exception.
20593 @end defmethod
20594
20595 @defmethod Type template_argument n [block]
20596 If this @code{gdb.Type} is an instantiation of a template, this will
20597 return a new @code{gdb.Type} which represents the type of the
20598 @var{n}th template argument.
20599
20600 If this @code{gdb.Type} is not a template type, this will throw an
20601 exception. Ordinarily, only C@t{++} code will have template types.
20602
20603 If @var{block} is given, then @var{name} is looked up in that scope.
20604 Otherwise, it is searched for globally.
20605 @end defmethod
20606 @end table
20607
20608
20609 Each type has a code, which indicates what category this type falls
20610 into. The available type categories are represented by constants
20611 defined in the @code{gdb} module:
20612
20613 @table @code
20614 @findex TYPE_CODE_PTR
20615 @findex gdb.TYPE_CODE_PTR
20616 @item TYPE_CODE_PTR
20617 The type is a pointer.
20618
20619 @findex TYPE_CODE_ARRAY
20620 @findex gdb.TYPE_CODE_ARRAY
20621 @item TYPE_CODE_ARRAY
20622 The type is an array.
20623
20624 @findex TYPE_CODE_STRUCT
20625 @findex gdb.TYPE_CODE_STRUCT
20626 @item TYPE_CODE_STRUCT
20627 The type is a structure.
20628
20629 @findex TYPE_CODE_UNION
20630 @findex gdb.TYPE_CODE_UNION
20631 @item TYPE_CODE_UNION
20632 The type is a union.
20633
20634 @findex TYPE_CODE_ENUM
20635 @findex gdb.TYPE_CODE_ENUM
20636 @item TYPE_CODE_ENUM
20637 The type is an enum.
20638
20639 @findex TYPE_CODE_FLAGS
20640 @findex gdb.TYPE_CODE_FLAGS
20641 @item TYPE_CODE_FLAGS
20642 A bit flags type, used for things such as status registers.
20643
20644 @findex TYPE_CODE_FUNC
20645 @findex gdb.TYPE_CODE_FUNC
20646 @item TYPE_CODE_FUNC
20647 The type is a function.
20648
20649 @findex TYPE_CODE_INT
20650 @findex gdb.TYPE_CODE_INT
20651 @item TYPE_CODE_INT
20652 The type is an integer type.
20653
20654 @findex TYPE_CODE_FLT
20655 @findex gdb.TYPE_CODE_FLT
20656 @item TYPE_CODE_FLT
20657 A floating point type.
20658
20659 @findex TYPE_CODE_VOID
20660 @findex gdb.TYPE_CODE_VOID
20661 @item TYPE_CODE_VOID
20662 The special type @code{void}.
20663
20664 @findex TYPE_CODE_SET
20665 @findex gdb.TYPE_CODE_SET
20666 @item TYPE_CODE_SET
20667 A Pascal set type.
20668
20669 @findex TYPE_CODE_RANGE
20670 @findex gdb.TYPE_CODE_RANGE
20671 @item TYPE_CODE_RANGE
20672 A range type, that is, an integer type with bounds.
20673
20674 @findex TYPE_CODE_STRING
20675 @findex gdb.TYPE_CODE_STRING
20676 @item TYPE_CODE_STRING
20677 A string type. Note that this is only used for certain languages with
20678 language-defined string types; C strings are not represented this way.
20679
20680 @findex TYPE_CODE_BITSTRING
20681 @findex gdb.TYPE_CODE_BITSTRING
20682 @item TYPE_CODE_BITSTRING
20683 A string of bits.
20684
20685 @findex TYPE_CODE_ERROR
20686 @findex gdb.TYPE_CODE_ERROR
20687 @item TYPE_CODE_ERROR
20688 An unknown or erroneous type.
20689
20690 @findex TYPE_CODE_METHOD
20691 @findex gdb.TYPE_CODE_METHOD
20692 @item TYPE_CODE_METHOD
20693 A method type, as found in C@t{++} or Java.
20694
20695 @findex TYPE_CODE_METHODPTR
20696 @findex gdb.TYPE_CODE_METHODPTR
20697 @item TYPE_CODE_METHODPTR
20698 A pointer-to-member-function.
20699
20700 @findex TYPE_CODE_MEMBERPTR
20701 @findex gdb.TYPE_CODE_MEMBERPTR
20702 @item TYPE_CODE_MEMBERPTR
20703 A pointer-to-member.
20704
20705 @findex TYPE_CODE_REF
20706 @findex gdb.TYPE_CODE_REF
20707 @item TYPE_CODE_REF
20708 A reference type.
20709
20710 @findex TYPE_CODE_CHAR
20711 @findex gdb.TYPE_CODE_CHAR
20712 @item TYPE_CODE_CHAR
20713 A character type.
20714
20715 @findex TYPE_CODE_BOOL
20716 @findex gdb.TYPE_CODE_BOOL
20717 @item TYPE_CODE_BOOL
20718 A boolean type.
20719
20720 @findex TYPE_CODE_COMPLEX
20721 @findex gdb.TYPE_CODE_COMPLEX
20722 @item TYPE_CODE_COMPLEX
20723 A complex float type.
20724
20725 @findex TYPE_CODE_TYPEDEF
20726 @findex gdb.TYPE_CODE_TYPEDEF
20727 @item TYPE_CODE_TYPEDEF
20728 A typedef to some other type.
20729
20730 @findex TYPE_CODE_NAMESPACE
20731 @findex gdb.TYPE_CODE_NAMESPACE
20732 @item TYPE_CODE_NAMESPACE
20733 A C@t{++} namespace.
20734
20735 @findex TYPE_CODE_DECFLOAT
20736 @findex gdb.TYPE_CODE_DECFLOAT
20737 @item TYPE_CODE_DECFLOAT
20738 A decimal floating point type.
20739
20740 @findex TYPE_CODE_INTERNAL_FUNCTION
20741 @findex gdb.TYPE_CODE_INTERNAL_FUNCTION
20742 @item TYPE_CODE_INTERNAL_FUNCTION
20743 A function internal to @value{GDBN}. This is the type used to represent
20744 convenience functions.
20745 @end table
20746
20747 @node Pretty Printing API
20748 @subsubsection Pretty Printing API
20749
20750 An example output is provided (@pxref{Pretty Printing}).
20751
20752 A pretty-printer is just an object that holds a value and implements a
20753 specific interface, defined here.
20754
20755 @defop Operation {pretty printer} children (self)
20756 @value{GDBN} will call this method on a pretty-printer to compute the
20757 children of the pretty-printer's value.
20758
20759 This method must return an object conforming to the Python iterator
20760 protocol. Each item returned by the iterator must be a tuple holding
20761 two elements. The first element is the ``name'' of the child; the
20762 second element is the child's value. The value can be any Python
20763 object which is convertible to a @value{GDBN} value.
20764
20765 This method is optional. If it does not exist, @value{GDBN} will act
20766 as though the value has no children.
20767 @end defop
20768
20769 @defop Operation {pretty printer} display_hint (self)
20770 The CLI may call this method and use its result to change the
20771 formatting of a value. The result will also be supplied to an MI
20772 consumer as a @samp{displayhint} attribute of the variable being
20773 printed.
20774
20775 This method is optional. If it does exist, this method must return a
20776 string.
20777
20778 Some display hints are predefined by @value{GDBN}:
20779
20780 @table @samp
20781 @item array
20782 Indicate that the object being printed is ``array-like''. The CLI
20783 uses this to respect parameters such as @code{set print elements} and
20784 @code{set print array}.
20785
20786 @item map
20787 Indicate that the object being printed is ``map-like'', and that the
20788 children of this value can be assumed to alternate between keys and
20789 values.
20790
20791 @item string
20792 Indicate that the object being printed is ``string-like''. If the
20793 printer's @code{to_string} method returns a Python string of some
20794 kind, then @value{GDBN} will call its internal language-specific
20795 string-printing function to format the string. For the CLI this means
20796 adding quotation marks, possibly escaping some characters, respecting
20797 @code{set print elements}, and the like.
20798 @end table
20799 @end defop
20800
20801 @defop Operation {pretty printer} to_string (self)
20802 @value{GDBN} will call this method to display the string
20803 representation of the value passed to the object's constructor.
20804
20805 When printing from the CLI, if the @code{to_string} method exists,
20806 then @value{GDBN} will prepend its result to the values returned by
20807 @code{children}. Exactly how this formatting is done is dependent on
20808 the display hint, and may change as more hints are added. Also,
20809 depending on the print settings (@pxref{Print Settings}), the CLI may
20810 print just the result of @code{to_string} in a stack trace, omitting
20811 the result of @code{children}.
20812
20813 If this method returns a string, it is printed verbatim.
20814
20815 Otherwise, if this method returns an instance of @code{gdb.Value},
20816 then @value{GDBN} prints this value. This may result in a call to
20817 another pretty-printer.
20818
20819 If instead the method returns a Python value which is convertible to a
20820 @code{gdb.Value}, then @value{GDBN} performs the conversion and prints
20821 the resulting value. Again, this may result in a call to another
20822 pretty-printer. Python scalars (integers, floats, and booleans) and
20823 strings are convertible to @code{gdb.Value}; other types are not.
20824
20825 Finally, if this method returns @code{None} then no further operations
20826 are peformed in this method and nothing is printed.
20827
20828 If the result is not one of these types, an exception is raised.
20829 @end defop
20830
20831 @node Selecting Pretty-Printers
20832 @subsubsection Selecting Pretty-Printers
20833
20834 The Python list @code{gdb.pretty_printers} contains an array of
20835 functions or callable objects that have been registered via addition
20836 as a pretty-printer.
20837 Each @code{gdb.Progspace} contains a @code{pretty_printers} attribute.
20838 Each @code{gdb.Objfile} also contains a @code{pretty_printers}
20839 attribute.
20840
20841 A function on one of these lists is passed a single @code{gdb.Value}
20842 argument and should return a pretty-printer object conforming to the
20843 interface definition above (@pxref{Pretty Printing API}). If a function
20844 cannot create a pretty-printer for the value, it should return
20845 @code{None}.
20846
20847 @value{GDBN} first checks the @code{pretty_printers} attribute of each
20848 @code{gdb.Objfile} in the current program space and iteratively calls
20849 each enabled function (@pxref{Disabling Pretty-Printers})
20850 in the list for that @code{gdb.Objfile} until it receives
20851 a pretty-printer object.
20852 If no pretty-printer is found in the objfile lists, @value{GDBN} then
20853 searches the pretty-printer list of the current program space,
20854 calling each enabled function until an object is returned.
20855 After these lists have been exhausted, it tries the global
20856 @code{gdb.pretty_printers} list, again calling each enabled function until an
20857 object is returned.
20858
20859 The order in which the objfiles are searched is not specified. For a
20860 given list, functions are always invoked from the head of the list,
20861 and iterated over sequentially until the end of the list, or a printer
20862 object is returned.
20863
20864 Here is an example showing how a @code{std::string} printer might be
20865 written:
20866
20867 @smallexample
20868 class StdStringPrinter:
20869 "Print a std::string"
20870
20871 def __init__ (self, val):
20872 self.val = val
20873
20874 def to_string (self):
20875 return self.val['_M_dataplus']['_M_p']
20876
20877 def display_hint (self):
20878 return 'string'
20879 @end smallexample
20880
20881 And here is an example showing how a lookup function for the printer
20882 example above might be written.
20883
20884 @smallexample
20885 def str_lookup_function (val):
20886
20887 lookup_tag = val.type.tag
20888 regex = re.compile ("^std::basic_string<char,.*>$")
20889 if lookup_tag == None:
20890 return None
20891 if regex.match (lookup_tag):
20892 return StdStringPrinter (val)
20893
20894 return None
20895 @end smallexample
20896
20897 The example lookup function extracts the value's type, and attempts to
20898 match it to a type that it can pretty-print. If it is a type the
20899 printer can pretty-print, it will return a printer object. If not, it
20900 returns @code{None}.
20901
20902 We recommend that you put your core pretty-printers into a Python
20903 package. If your pretty-printers are for use with a library, we
20904 further recommend embedding a version number into the package name.
20905 This practice will enable @value{GDBN} to load multiple versions of
20906 your pretty-printers at the same time, because they will have
20907 different names.
20908
20909 You should write auto-loaded code (@pxref{Auto-loading}) such that it
20910 can be evaluated multiple times without changing its meaning. An
20911 ideal auto-load file will consist solely of @code{import}s of your
20912 printer modules, followed by a call to a register pretty-printers with
20913 the current objfile.
20914
20915 Taken as a whole, this approach will scale nicely to multiple
20916 inferiors, each potentially using a different library version.
20917 Embedding a version number in the Python package name will ensure that
20918 @value{GDBN} is able to load both sets of printers simultaneously.
20919 Then, because the search for pretty-printers is done by objfile, and
20920 because your auto-loaded code took care to register your library's
20921 printers with a specific objfile, @value{GDBN} will find the correct
20922 printers for the specific version of the library used by each
20923 inferior.
20924
20925 To continue the @code{std::string} example (@pxref{Pretty Printing API}),
20926 this code might appear in @code{gdb.libstdcxx.v6}:
20927
20928 @smallexample
20929 def register_printers (objfile):
20930 objfile.pretty_printers.add (str_lookup_function)
20931 @end smallexample
20932
20933 @noindent
20934 And then the corresponding contents of the auto-load file would be:
20935
20936 @smallexample
20937 import gdb.libstdcxx.v6
20938 gdb.libstdcxx.v6.register_printers (gdb.current_objfile ())
20939 @end smallexample
20940
20941 @node Disabling Pretty-Printers
20942 @subsubsection Disabling Pretty-Printers
20943 @cindex disabling pretty-printers
20944
20945 For various reasons a pretty-printer may not work.
20946 For example, the underlying data structure may have changed and
20947 the pretty-printer is out of date.
20948
20949 The consequences of a broken pretty-printer are severe enough that
20950 @value{GDBN} provides support for enabling and disabling individual
20951 printers. For example, if @code{print frame-arguments} is on,
20952 a backtrace can become highly illegible if any argument is printed
20953 with a broken printer.
20954
20955 Pretty-printers are enabled and disabled by attaching an @code{enabled}
20956 attribute to the registered function or callable object. If this attribute
20957 is present and its value is @code{False}, the printer is disabled, otherwise
20958 the printer is enabled.
20959
20960 @node Commands In Python
20961 @subsubsection Commands In Python
20962
20963 @cindex commands in python
20964 @cindex python commands
20965 You can implement new @value{GDBN} CLI commands in Python. A CLI
20966 command is implemented using an instance of the @code{gdb.Command}
20967 class, most commonly using a subclass.
20968
20969 @defmethod Command __init__ name @var{command_class} @r{[}@var{completer_class}@r{]} @r{[}@var{prefix}@r{]}
20970 The object initializer for @code{Command} registers the new command
20971 with @value{GDBN}. This initializer is normally invoked from the
20972 subclass' own @code{__init__} method.
20973
20974 @var{name} is the name of the command. If @var{name} consists of
20975 multiple words, then the initial words are looked for as prefix
20976 commands. In this case, if one of the prefix commands does not exist,
20977 an exception is raised.
20978
20979 There is no support for multi-line commands.
20980
20981 @var{command_class} should be one of the @samp{COMMAND_} constants
20982 defined below. This argument tells @value{GDBN} how to categorize the
20983 new command in the help system.
20984
20985 @var{completer_class} is an optional argument. If given, it should be
20986 one of the @samp{COMPLETE_} constants defined below. This argument
20987 tells @value{GDBN} how to perform completion for this command. If not
20988 given, @value{GDBN} will attempt to complete using the object's
20989 @code{complete} method (see below); if no such method is found, an
20990 error will occur when completion is attempted.
20991
20992 @var{prefix} is an optional argument. If @code{True}, then the new
20993 command is a prefix command; sub-commands of this command may be
20994 registered.
20995
20996 The help text for the new command is taken from the Python
20997 documentation string for the command's class, if there is one. If no
20998 documentation string is provided, the default value ``This command is
20999 not documented.'' is used.
21000 @end defmethod
21001
21002 @cindex don't repeat Python command
21003 @defmethod Command dont_repeat
21004 By default, a @value{GDBN} command is repeated when the user enters a
21005 blank line at the command prompt. A command can suppress this
21006 behavior by invoking the @code{dont_repeat} method. This is similar
21007 to the user command @code{dont-repeat}, see @ref{Define, dont-repeat}.
21008 @end defmethod
21009
21010 @defmethod Command invoke argument from_tty
21011 This method is called by @value{GDBN} when this command is invoked.
21012
21013 @var{argument} is a string. It is the argument to the command, after
21014 leading and trailing whitespace has been stripped.
21015
21016 @var{from_tty} is a boolean argument. When true, this means that the
21017 command was entered by the user at the terminal; when false it means
21018 that the command came from elsewhere.
21019
21020 If this method throws an exception, it is turned into a @value{GDBN}
21021 @code{error} call. Otherwise, the return value is ignored.
21022
21023 @findex gdb.string_to_argv
21024 To break @var{argument} up into an argv-like string use
21025 @code{gdb.string_to_argv}. This function behaves identically to
21026 @value{GDBN}'s internal argument lexer @code{buildargv}.
21027 It is recommended to use this for consistency.
21028 Arguments are separated by spaces and may be quoted.
21029 Example:
21030
21031 @smallexample
21032 print gdb.string_to_argv ("1 2\ \\\"3 '4 \"5' \"6 '7\"")
21033 ['1', '2 "3', '4 "5', "6 '7"]
21034 @end smallexample
21035
21036 @end defmethod
21037
21038 @cindex completion of Python commands
21039 @defmethod Command complete text word
21040 This method is called by @value{GDBN} when the user attempts
21041 completion on this command. All forms of completion are handled by
21042 this method, that is, the @key{TAB} and @key{M-?} key bindings
21043 (@pxref{Completion}), and the @code{complete} command (@pxref{Help,
21044 complete}).
21045
21046 The arguments @var{text} and @var{word} are both strings. @var{text}
21047 holds the complete command line up to the cursor's location.
21048 @var{word} holds the last word of the command line; this is computed
21049 using a word-breaking heuristic.
21050
21051 The @code{complete} method can return several values:
21052 @itemize @bullet
21053 @item
21054 If the return value is a sequence, the contents of the sequence are
21055 used as the completions. It is up to @code{complete} to ensure that the
21056 contents actually do complete the word. A zero-length sequence is
21057 allowed, it means that there were no completions available. Only
21058 string elements of the sequence are used; other elements in the
21059 sequence are ignored.
21060
21061 @item
21062 If the return value is one of the @samp{COMPLETE_} constants defined
21063 below, then the corresponding @value{GDBN}-internal completion
21064 function is invoked, and its result is used.
21065
21066 @item
21067 All other results are treated as though there were no available
21068 completions.
21069 @end itemize
21070 @end defmethod
21071
21072 When a new command is registered, it must be declared as a member of
21073 some general class of commands. This is used to classify top-level
21074 commands in the on-line help system; note that prefix commands are not
21075 listed under their own category but rather that of their top-level
21076 command. The available classifications are represented by constants
21077 defined in the @code{gdb} module:
21078
21079 @table @code
21080 @findex COMMAND_NONE
21081 @findex gdb.COMMAND_NONE
21082 @item COMMAND_NONE
21083 The command does not belong to any particular class. A command in
21084 this category will not be displayed in any of the help categories.
21085
21086 @findex COMMAND_RUNNING
21087 @findex gdb.COMMAND_RUNNING
21088 @item COMMAND_RUNNING
21089 The command is related to running the inferior. For example,
21090 @code{start}, @code{step}, and @code{continue} are in this category.
21091 Type @kbd{help running} at the @value{GDBN} prompt to see a list of
21092 commands in this category.
21093
21094 @findex COMMAND_DATA
21095 @findex gdb.COMMAND_DATA
21096 @item COMMAND_DATA
21097 The command is related to data or variables. For example,
21098 @code{call}, @code{find}, and @code{print} are in this category. Type
21099 @kbd{help data} at the @value{GDBN} prompt to see a list of commands
21100 in this category.
21101
21102 @findex COMMAND_STACK
21103 @findex gdb.COMMAND_STACK
21104 @item COMMAND_STACK
21105 The command has to do with manipulation of the stack. For example,
21106 @code{backtrace}, @code{frame}, and @code{return} are in this
21107 category. Type @kbd{help stack} at the @value{GDBN} prompt to see a
21108 list of commands in this category.
21109
21110 @findex COMMAND_FILES
21111 @findex gdb.COMMAND_FILES
21112 @item COMMAND_FILES
21113 This class is used for file-related commands. For example,
21114 @code{file}, @code{list} and @code{section} are in this category.
21115 Type @kbd{help files} at the @value{GDBN} prompt to see a list of
21116 commands in this category.
21117
21118 @findex COMMAND_SUPPORT
21119 @findex gdb.COMMAND_SUPPORT
21120 @item COMMAND_SUPPORT
21121 This should be used for ``support facilities'', generally meaning
21122 things that are useful to the user when interacting with @value{GDBN},
21123 but not related to the state of the inferior. For example,
21124 @code{help}, @code{make}, and @code{shell} are in this category. Type
21125 @kbd{help support} at the @value{GDBN} prompt to see a list of
21126 commands in this category.
21127
21128 @findex COMMAND_STATUS
21129 @findex gdb.COMMAND_STATUS
21130 @item COMMAND_STATUS
21131 The command is an @samp{info}-related command, that is, related to the
21132 state of @value{GDBN} itself. For example, @code{info}, @code{macro},
21133 and @code{show} are in this category. Type @kbd{help status} at the
21134 @value{GDBN} prompt to see a list of commands in this category.
21135
21136 @findex COMMAND_BREAKPOINTS
21137 @findex gdb.COMMAND_BREAKPOINTS
21138 @item COMMAND_BREAKPOINTS
21139 The command has to do with breakpoints. For example, @code{break},
21140 @code{clear}, and @code{delete} are in this category. Type @kbd{help
21141 breakpoints} at the @value{GDBN} prompt to see a list of commands in
21142 this category.
21143
21144 @findex COMMAND_TRACEPOINTS
21145 @findex gdb.COMMAND_TRACEPOINTS
21146 @item COMMAND_TRACEPOINTS
21147 The command has to do with tracepoints. For example, @code{trace},
21148 @code{actions}, and @code{tfind} are in this category. Type
21149 @kbd{help tracepoints} at the @value{GDBN} prompt to see a list of
21150 commands in this category.
21151
21152 @findex COMMAND_OBSCURE
21153 @findex gdb.COMMAND_OBSCURE
21154 @item COMMAND_OBSCURE
21155 The command is only used in unusual circumstances, or is not of
21156 general interest to users. For example, @code{checkpoint},
21157 @code{fork}, and @code{stop} are in this category. Type @kbd{help
21158 obscure} at the @value{GDBN} prompt to see a list of commands in this
21159 category.
21160
21161 @findex COMMAND_MAINTENANCE
21162 @findex gdb.COMMAND_MAINTENANCE
21163 @item COMMAND_MAINTENANCE
21164 The command is only useful to @value{GDBN} maintainers. The
21165 @code{maintenance} and @code{flushregs} commands are in this category.
21166 Type @kbd{help internals} at the @value{GDBN} prompt to see a list of
21167 commands in this category.
21168 @end table
21169
21170 A new command can use a predefined completion function, either by
21171 specifying it via an argument at initialization, or by returning it
21172 from the @code{complete} method. These predefined completion
21173 constants are all defined in the @code{gdb} module:
21174
21175 @table @code
21176 @findex COMPLETE_NONE
21177 @findex gdb.COMPLETE_NONE
21178 @item COMPLETE_NONE
21179 This constant means that no completion should be done.
21180
21181 @findex COMPLETE_FILENAME
21182 @findex gdb.COMPLETE_FILENAME
21183 @item COMPLETE_FILENAME
21184 This constant means that filename completion should be performed.
21185
21186 @findex COMPLETE_LOCATION
21187 @findex gdb.COMPLETE_LOCATION
21188 @item COMPLETE_LOCATION
21189 This constant means that location completion should be done.
21190 @xref{Specify Location}.
21191
21192 @findex COMPLETE_COMMAND
21193 @findex gdb.COMPLETE_COMMAND
21194 @item COMPLETE_COMMAND
21195 This constant means that completion should examine @value{GDBN}
21196 command names.
21197
21198 @findex COMPLETE_SYMBOL
21199 @findex gdb.COMPLETE_SYMBOL
21200 @item COMPLETE_SYMBOL
21201 This constant means that completion should be done using symbol names
21202 as the source.
21203 @end table
21204
21205 The following code snippet shows how a trivial CLI command can be
21206 implemented in Python:
21207
21208 @smallexample
21209 class HelloWorld (gdb.Command):
21210 """Greet the whole world."""
21211
21212 def __init__ (self):
21213 super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_OBSCURE)
21214
21215 def invoke (self, arg, from_tty):
21216 print "Hello, World!"
21217
21218 HelloWorld ()
21219 @end smallexample
21220
21221 The last line instantiates the class, and is necessary to trigger the
21222 registration of the command with @value{GDBN}. Depending on how the
21223 Python code is read into @value{GDBN}, you may need to import the
21224 @code{gdb} module explicitly.
21225
21226 @node Parameters In Python
21227 @subsubsection Parameters In Python
21228
21229 @cindex parameters in python
21230 @cindex python parameters
21231 @tindex gdb.Parameter
21232 @tindex Parameter
21233 You can implement new @value{GDBN} parameters using Python. A new
21234 parameter is implemented as an instance of the @code{gdb.Parameter}
21235 class.
21236
21237 Parameters are exposed to the user via the @code{set} and
21238 @code{show} commands. @xref{Help}.
21239
21240 There are many parameters that already exist and can be set in
21241 @value{GDBN}. Two examples are: @code{set follow fork} and
21242 @code{set charset}. Setting these parameters influences certain
21243 behavior in @value{GDBN}. Similarly, you can define parameters that
21244 can be used to influence behavior in custom Python scripts and commands.
21245
21246 @defmethod Parameter __init__ name @var{command-class} @var{parameter-class} @r{[}@var{enum-sequence}@r{]}
21247 The object initializer for @code{Parameter} registers the new
21248 parameter with @value{GDBN}. This initializer is normally invoked
21249 from the subclass' own @code{__init__} method.
21250
21251 @var{name} is the name of the new parameter. If @var{name} consists
21252 of multiple words, then the initial words are looked for as prefix
21253 parameters. An example of this can be illustrated with the
21254 @code{set print} set of parameters. If @var{name} is
21255 @code{print foo}, then @code{print} will be searched as the prefix
21256 parameter. In this case the parameter can subsequently be accessed in
21257 @value{GDBN} as @code{set print foo}.
21258
21259 If @var{name} consists of multiple words, and no prefix parameter group
21260 can be found, an exception is raised.
21261
21262 @var{command-class} should be one of the @samp{COMMAND_} constants
21263 (@pxref{Commands In Python}). This argument tells @value{GDBN} how to
21264 categorize the new parameter in the help system.
21265
21266 @var{parameter-class} should be one of the @samp{PARAM_} constants
21267 defined below. This argument tells @value{GDBN} the type of the new
21268 parameter; this information is used for input validation and
21269 completion.
21270
21271 If @var{parameter-class} is @code{PARAM_ENUM}, then
21272 @var{enum-sequence} must be a sequence of strings. These strings
21273 represent the possible values for the parameter.
21274
21275 If @var{parameter-class} is not @code{PARAM_ENUM}, then the presence
21276 of a fourth argument will cause an exception to be thrown.
21277
21278 The help text for the new parameter is taken from the Python
21279 documentation string for the parameter's class, if there is one. If
21280 there is no documentation string, a default value is used.
21281 @end defmethod
21282
21283 @defivar Parameter set_doc
21284 If this attribute exists, and is a string, then its value is used as
21285 the help text for this parameter's @code{set} command. The value is
21286 examined when @code{Parameter.__init__} is invoked; subsequent changes
21287 have no effect.
21288 @end defivar
21289
21290 @defivar Parameter show_doc
21291 If this attribute exists, and is a string, then its value is used as
21292 the help text for this parameter's @code{show} command. The value is
21293 examined when @code{Parameter.__init__} is invoked; subsequent changes
21294 have no effect.
21295 @end defivar
21296
21297 @defivar Parameter value
21298 The @code{value} attribute holds the underlying value of the
21299 parameter. It can be read and assigned to just as any other
21300 attribute. @value{GDBN} does validation when assignments are made.
21301 @end defivar
21302
21303
21304 When a new parameter is defined, its type must be specified. The
21305 available types are represented by constants defined in the @code{gdb}
21306 module:
21307
21308 @table @code
21309 @findex PARAM_BOOLEAN
21310 @findex gdb.PARAM_BOOLEAN
21311 @item PARAM_BOOLEAN
21312 The value is a plain boolean. The Python boolean values, @code{True}
21313 and @code{False} are the only valid values.
21314
21315 @findex PARAM_AUTO_BOOLEAN
21316 @findex gdb.PARAM_AUTO_BOOLEAN
21317 @item PARAM_AUTO_BOOLEAN
21318 The value has three possible states: true, false, and @samp{auto}. In
21319 Python, true and false are represented using boolean constants, and
21320 @samp{auto} is represented using @code{None}.
21321
21322 @findex PARAM_UINTEGER
21323 @findex gdb.PARAM_UINTEGER
21324 @item PARAM_UINTEGER
21325 The value is an unsigned integer. The value of 0 should be
21326 interpreted to mean ``unlimited''.
21327
21328 @findex PARAM_INTEGER
21329 @findex gdb.PARAM_INTEGER
21330 @item PARAM_INTEGER
21331 The value is a signed integer. The value of 0 should be interpreted
21332 to mean ``unlimited''.
21333
21334 @findex PARAM_STRING
21335 @findex gdb.PARAM_STRING
21336 @item PARAM_STRING
21337 The value is a string. When the user modifies the string, any escape
21338 sequences, such as @samp{\t}, @samp{\f}, and octal escapes, are
21339 translated into corresponding characters and encoded into the current
21340 host charset.
21341
21342 @findex PARAM_STRING_NOESCAPE
21343 @findex gdb.PARAM_STRING_NOESCAPE
21344 @item PARAM_STRING_NOESCAPE
21345 The value is a string. When the user modifies the string, escapes are
21346 passed through untranslated.
21347
21348 @findex PARAM_OPTIONAL_FILENAME
21349 @findex gdb.PARAM_OPTIONAL_FILENAME
21350 @item PARAM_OPTIONAL_FILENAME
21351 The value is a either a filename (a string), or @code{None}.
21352
21353 @findex PARAM_FILENAME
21354 @findex gdb.PARAM_FILENAME
21355 @item PARAM_FILENAME
21356 The value is a filename. This is just like
21357 @code{PARAM_STRING_NOESCAPE}, but uses file names for completion.
21358
21359 @findex PARAM_ZINTEGER
21360 @findex gdb.PARAM_ZINTEGER
21361 @item PARAM_ZINTEGER
21362 The value is an integer. This is like @code{PARAM_INTEGER}, except 0
21363 is interpreted as itself.
21364
21365 @findex PARAM_ENUM
21366 @findex gdb.PARAM_ENUM
21367 @item PARAM_ENUM
21368 The value is a string, which must be one of a collection string
21369 constants provided when the parameter is created.
21370 @end table
21371
21372 @node Functions In Python
21373 @subsubsection Writing new convenience functions
21374
21375 @cindex writing convenience functions
21376 @cindex convenience functions in python
21377 @cindex python convenience functions
21378 @tindex gdb.Function
21379 @tindex Function
21380 You can implement new convenience functions (@pxref{Convenience Vars})
21381 in Python. A convenience function is an instance of a subclass of the
21382 class @code{gdb.Function}.
21383
21384 @defmethod Function __init__ name
21385 The initializer for @code{Function} registers the new function with
21386 @value{GDBN}. The argument @var{name} is the name of the function,
21387 a string. The function will be visible to the user as a convenience
21388 variable of type @code{internal function}, whose name is the same as
21389 the given @var{name}.
21390
21391 The documentation for the new function is taken from the documentation
21392 string for the new class.
21393 @end defmethod
21394
21395 @defmethod Function invoke @var{*args}
21396 When a convenience function is evaluated, its arguments are converted
21397 to instances of @code{gdb.Value}, and then the function's
21398 @code{invoke} method is called. Note that @value{GDBN} does not
21399 predetermine the arity of convenience functions. Instead, all
21400 available arguments are passed to @code{invoke}, following the
21401 standard Python calling convention. In particular, a convenience
21402 function can have default values for parameters without ill effect.
21403
21404 The return value of this method is used as its value in the enclosing
21405 expression. If an ordinary Python value is returned, it is converted
21406 to a @code{gdb.Value} following the usual rules.
21407 @end defmethod
21408
21409 The following code snippet shows how a trivial convenience function can
21410 be implemented in Python:
21411
21412 @smallexample
21413 class Greet (gdb.Function):
21414 """Return string to greet someone.
21415 Takes a name as argument."""
21416
21417 def __init__ (self):
21418 super (Greet, self).__init__ ("greet")
21419
21420 def invoke (self, name):
21421 return "Hello, %s!" % name.string ()
21422
21423 Greet ()
21424 @end smallexample
21425
21426 The last line instantiates the class, and is necessary to trigger the
21427 registration of the function with @value{GDBN}. Depending on how the
21428 Python code is read into @value{GDBN}, you may need to import the
21429 @code{gdb} module explicitly.
21430
21431 @node Progspaces In Python
21432 @subsubsection Program Spaces In Python
21433
21434 @cindex progspaces in python
21435 @tindex gdb.Progspace
21436 @tindex Progspace
21437 A program space, or @dfn{progspace}, represents a symbolic view
21438 of an address space.
21439 It consists of all of the objfiles of the program.
21440 @xref{Objfiles In Python}.
21441 @xref{Inferiors and Programs, program spaces}, for more details
21442 about program spaces.
21443
21444 The following progspace-related functions are available in the
21445 @code{gdb} module:
21446
21447 @findex gdb.current_progspace
21448 @defun current_progspace
21449 This function returns the program space of the currently selected inferior.
21450 @xref{Inferiors and Programs}.
21451 @end defun
21452
21453 @findex gdb.progspaces
21454 @defun progspaces
21455 Return a sequence of all the progspaces currently known to @value{GDBN}.
21456 @end defun
21457
21458 Each progspace is represented by an instance of the @code{gdb.Progspace}
21459 class.
21460
21461 @defivar Progspace filename
21462 The file name of the progspace as a string.
21463 @end defivar
21464
21465 @defivar Progspace pretty_printers
21466 The @code{pretty_printers} attribute is a list of functions. It is
21467 used to look up pretty-printers. A @code{Value} is passed to each
21468 function in order; if the function returns @code{None}, then the
21469 search continues. Otherwise, the return value should be an object
21470 which is used to format the value. @xref{Pretty Printing API}, for more
21471 information.
21472 @end defivar
21473
21474 @node Objfiles In Python
21475 @subsubsection Objfiles In Python
21476
21477 @cindex objfiles in python
21478 @tindex gdb.Objfile
21479 @tindex Objfile
21480 @value{GDBN} loads symbols for an inferior from various
21481 symbol-containing files (@pxref{Files}). These include the primary
21482 executable file, any shared libraries used by the inferior, and any
21483 separate debug info files (@pxref{Separate Debug Files}).
21484 @value{GDBN} calls these symbol-containing files @dfn{objfiles}.
21485
21486 The following objfile-related functions are available in the
21487 @code{gdb} module:
21488
21489 @findex gdb.current_objfile
21490 @defun current_objfile
21491 When auto-loading a Python script (@pxref{Auto-loading}), @value{GDBN}
21492 sets the ``current objfile'' to the corresponding objfile. This
21493 function returns the current objfile. If there is no current objfile,
21494 this function returns @code{None}.
21495 @end defun
21496
21497 @findex gdb.objfiles
21498 @defun objfiles
21499 Return a sequence of all the objfiles current known to @value{GDBN}.
21500 @xref{Objfiles In Python}.
21501 @end defun
21502
21503 Each objfile is represented by an instance of the @code{gdb.Objfile}
21504 class.
21505
21506 @defivar Objfile filename
21507 The file name of the objfile as a string.
21508 @end defivar
21509
21510 @defivar Objfile pretty_printers
21511 The @code{pretty_printers} attribute is a list of functions. It is
21512 used to look up pretty-printers. A @code{Value} is passed to each
21513 function in order; if the function returns @code{None}, then the
21514 search continues. Otherwise, the return value should be an object
21515 which is used to format the value. @xref{Pretty Printing API}, for more
21516 information.
21517 @end defivar
21518
21519 @node Frames In Python
21520 @subsubsection Accessing inferior stack frames from Python.
21521
21522 @cindex frames in python
21523 When the debugged program stops, @value{GDBN} is able to analyze its call
21524 stack (@pxref{Frames,,Stack frames}). The @code{gdb.Frame} class
21525 represents a frame in the stack. A @code{gdb.Frame} object is only valid
21526 while its corresponding frame exists in the inferior's stack. If you try
21527 to use an invalid frame object, @value{GDBN} will throw a @code{RuntimeError}
21528 exception.
21529
21530 Two @code{gdb.Frame} objects can be compared for equality with the @code{==}
21531 operator, like:
21532
21533 @smallexample
21534 (@value{GDBP}) python print gdb.newest_frame() == gdb.selected_frame ()
21535 True
21536 @end smallexample
21537
21538 The following frame-related functions are available in the @code{gdb} module:
21539
21540 @findex gdb.selected_frame
21541 @defun selected_frame
21542 Return the selected frame object. (@pxref{Selection,,Selecting a Frame}).
21543 @end defun
21544
21545 @defun frame_stop_reason_string reason
21546 Return a string explaining the reason why @value{GDBN} stopped unwinding
21547 frames, as expressed by the given @var{reason} code (an integer, see the
21548 @code{unwind_stop_reason} method further down in this section).
21549 @end defun
21550
21551 A @code{gdb.Frame} object has the following methods:
21552
21553 @table @code
21554 @defmethod Frame is_valid
21555 Returns true if the @code{gdb.Frame} object is valid, false if not.
21556 A frame object can become invalid if the frame it refers to doesn't
21557 exist anymore in the inferior. All @code{gdb.Frame} methods will throw
21558 an exception if it is invalid at the time the method is called.
21559 @end defmethod
21560
21561 @defmethod Frame name
21562 Returns the function name of the frame, or @code{None} if it can't be
21563 obtained.
21564 @end defmethod
21565
21566 @defmethod Frame type
21567 Returns the type of the frame. The value can be one of
21568 @code{gdb.NORMAL_FRAME}, @code{gdb.DUMMY_FRAME}, @code{gdb.SIGTRAMP_FRAME}
21569 or @code{gdb.SENTINEL_FRAME}.
21570 @end defmethod
21571
21572 @defmethod Frame unwind_stop_reason
21573 Return an integer representing the reason why it's not possible to find
21574 more frames toward the outermost frame. Use
21575 @code{gdb.frame_stop_reason_string} to convert the value returned by this
21576 function to a string.
21577 @end defmethod
21578
21579 @defmethod Frame pc
21580 Returns the frame's resume address.
21581 @end defmethod
21582
21583 @defmethod Frame block
21584 Return the frame's code block. @xref{Blocks In Python}.
21585 @end defmethod
21586
21587 @defmethod Frame function
21588 Return the symbol for the function corresponding to this frame.
21589 @xref{Symbols In Python}.
21590 @end defmethod
21591
21592 @defmethod Frame older
21593 Return the frame that called this frame.
21594 @end defmethod
21595
21596 @defmethod Frame newer
21597 Return the frame called by this frame.
21598 @end defmethod
21599
21600 @defmethod Frame find_sal
21601 Return the frame's symtab and line object.
21602 @xref{Symbol Tables In Python}.
21603 @end defmethod
21604
21605 @defmethod Frame read_var variable @r{[}block@r{]}
21606 Return the value of @var{variable} in this frame. If the optional
21607 argument @var{block} is provided, search for the variable from that
21608 block; otherwise start at the frame's current block (which is
21609 determined by the frame's current program counter). @var{variable}
21610 must be a string or a @code{gdb.Symbol} object. @var{block} must be a
21611 @code{gdb.Block} object.
21612 @end defmethod
21613
21614 @defmethod Frame select
21615 Set this frame to be the selected frame. @xref{Stack, ,Examining the
21616 Stack}.
21617 @end defmethod
21618 @end table
21619
21620 @node Blocks In Python
21621 @subsubsection Accessing frame blocks from Python.
21622
21623 @cindex blocks in python
21624 @tindex gdb.Block
21625
21626 Within each frame, @value{GDBN} maintains information on each block
21627 stored in that frame. These blocks are organized hierarchically, and
21628 are represented individually in Python as a @code{gdb.Block}.
21629 Please see @ref{Frames In Python}, for a more in-depth discussion on
21630 frames. Furthermore, see @ref{Stack, ,Examining the Stack}, for more
21631 detailed technical information on @value{GDBN}'s book-keeping of the
21632 stack.
21633
21634 The following block-related functions are available in the @code{gdb}
21635 module:
21636
21637 @findex gdb.block_for_pc
21638 @defun block_for_pc pc
21639 Return the @code{gdb.Block} containing the given @var{pc} value. If the
21640 block cannot be found for the @var{pc} value specified, the function
21641 will return @code{None}.
21642 @end defun
21643
21644 A @code{gdb.Block} object has the following attributes:
21645
21646 @table @code
21647 @defivar Block start
21648 The start address of the block. This attribute is not writable.
21649 @end defivar
21650
21651 @defivar Block end
21652 The end address of the block. This attribute is not writable.
21653 @end defivar
21654
21655 @defivar Block function
21656 The name of the block represented as a @code{gdb.Symbol}. If the
21657 block is not named, then this attribute holds @code{None}. This
21658 attribute is not writable.
21659 @end defivar
21660
21661 @defivar Block superblock
21662 The block containing this block. If this parent block does not exist,
21663 this attribute holds @code{None}. This attribute is not writable.
21664 @end defivar
21665 @end table
21666
21667 @node Symbols In Python
21668 @subsubsection Python representation of Symbols.
21669
21670 @cindex symbols in python
21671 @tindex gdb.Symbol
21672
21673 @value{GDBN} represents every variable, function and type as an
21674 entry in a symbol table. @xref{Symbols, ,Examining the Symbol Table}.
21675 Similarly, Python represents these symbols in @value{GDBN} with the
21676 @code{gdb.Symbol} object.
21677
21678 The following symbol-related functions are available in the @code{gdb}
21679 module:
21680
21681 @findex gdb.lookup_symbol
21682 @defun lookup_symbol name [block] [domain]
21683 This function searches for a symbol by name. The search scope can be
21684 restricted to the parameters defined in the optional domain and block
21685 arguments.
21686
21687 @var{name} is the name of the symbol. It must be a string. The
21688 optional @var{block} argument restricts the search to symbols visible
21689 in that @var{block}. The @var{block} argument must be a
21690 @code{gdb.Block} object. The optional @var{domain} argument restricts
21691 the search to the domain type. The @var{domain} argument must be a
21692 domain constant defined in the @code{gdb} module and described later
21693 in this chapter.
21694 @end defun
21695
21696 A @code{gdb.Symbol} object has the following attributes:
21697
21698 @table @code
21699 @defivar Symbol symtab
21700 The symbol table in which the symbol appears. This attribute is
21701 represented as a @code{gdb.Symtab} object. @xref{Symbol Tables In
21702 Python}. This attribute is not writable.
21703 @end defivar
21704
21705 @defivar Symbol name
21706 The name of the symbol as a string. This attribute is not writable.
21707 @end defivar
21708
21709 @defivar Symbol linkage_name
21710 The name of the symbol, as used by the linker (i.e., may be mangled).
21711 This attribute is not writable.
21712 @end defivar
21713
21714 @defivar Symbol print_name
21715 The name of the symbol in a form suitable for output. This is either
21716 @code{name} or @code{linkage_name}, depending on whether the user
21717 asked @value{GDBN} to display demangled or mangled names.
21718 @end defivar
21719
21720 @defivar Symbol addr_class
21721 The address class of the symbol. This classifies how to find the value
21722 of a symbol. Each address class is a constant defined in the
21723 @code{gdb} module and described later in this chapter.
21724 @end defivar
21725
21726 @defivar Symbol is_argument
21727 @code{True} if the symbol is an argument of a function.
21728 @end defivar
21729
21730 @defivar Symbol is_constant
21731 @code{True} if the symbol is a constant.
21732 @end defivar
21733
21734 @defivar Symbol is_function
21735 @code{True} if the symbol is a function or a method.
21736 @end defivar
21737
21738 @defivar Symbol is_variable
21739 @code{True} if the symbol is a variable.
21740 @end defivar
21741 @end table
21742
21743 The available domain categories in @code{gdb.Symbol} are represented
21744 as constants in the @code{gdb} module:
21745
21746 @table @code
21747 @findex SYMBOL_UNDEF_DOMAIN
21748 @findex gdb.SYMBOL_UNDEF_DOMAIN
21749 @item SYMBOL_UNDEF_DOMAIN
21750 This is used when a domain has not been discovered or none of the
21751 following domains apply. This usually indicates an error either
21752 in the symbol information or in @value{GDBN}'s handling of symbols.
21753 @findex SYMBOL_VAR_DOMAIN
21754 @findex gdb.SYMBOL_VAR_DOMAIN
21755 @item SYMBOL_VAR_DOMAIN
21756 This domain contains variables, function names, typedef names and enum
21757 type values.
21758 @findex SYMBOL_STRUCT_DOMAIN
21759 @findex gdb.SYMBOL_STRUCT_DOMAIN
21760 @item SYMBOL_STRUCT_DOMAIN
21761 This domain holds struct, union and enum type names.
21762 @findex SYMBOL_LABEL_DOMAIN
21763 @findex gdb.SYMBOL_LABEL_DOMAIN
21764 @item SYMBOL_LABEL_DOMAIN
21765 This domain contains names of labels (for gotos).
21766 @findex SYMBOL_VARIABLES_DOMAIN
21767 @findex gdb.SYMBOL_VARIABLES_DOMAIN
21768 @item SYMBOL_VARIABLES_DOMAIN
21769 This domain holds a subset of the @code{SYMBOLS_VAR_DOMAIN}; it
21770 contains everything minus functions and types.
21771 @findex SYMBOL_FUNCTIONS_DOMAIN
21772 @findex gdb.SYMBOL_FUNCTIONS_DOMAIN
21773 @item SYMBOL_FUNCTION_DOMAIN
21774 This domain contains all functions.
21775 @findex SYMBOL_TYPES_DOMAIN
21776 @findex gdb.SYMBOL_TYPES_DOMAIN
21777 @item SYMBOL_TYPES_DOMAIN
21778 This domain contains all types.
21779 @end table
21780
21781 The available address class categories in @code{gdb.Symbol} are represented
21782 as constants in the @code{gdb} module:
21783
21784 @table @code
21785 @findex SYMBOL_LOC_UNDEF
21786 @findex gdb.SYMBOL_LOC_UNDEF
21787 @item SYMBOL_LOC_UNDEF
21788 If this is returned by address class, it indicates an error either in
21789 the symbol information or in @value{GDBN}'s handling of symbols.
21790 @findex SYMBOL_LOC_CONST
21791 @findex gdb.SYMBOL_LOC_CONST
21792 @item SYMBOL_LOC_CONST
21793 Value is constant int.
21794 @findex SYMBOL_LOC_STATIC
21795 @findex gdb.SYMBOL_LOC_STATIC
21796 @item SYMBOL_LOC_STATIC
21797 Value is at a fixed address.
21798 @findex SYMBOL_LOC_REGISTER
21799 @findex gdb.SYMBOL_LOC_REGISTER
21800 @item SYMBOL_LOC_REGISTER
21801 Value is in a register.
21802 @findex SYMBOL_LOC_ARG
21803 @findex gdb.SYMBOL_LOC_ARG
21804 @item SYMBOL_LOC_ARG
21805 Value is an argument. This value is at the offset stored within the
21806 symbol inside the frame's argument list.
21807 @findex SYMBOL_LOC_REF_ARG
21808 @findex gdb.SYMBOL_LOC_REF_ARG
21809 @item SYMBOL_LOC_REF_ARG
21810 Value address is stored in the frame's argument list. Just like
21811 @code{LOC_ARG} except that the value's address is stored at the
21812 offset, not the value itself.
21813 @findex SYMBOL_LOC_REGPARM_ADDR
21814 @findex gdb.SYMBOL_LOC_REGPARM_ADDR
21815 @item SYMBOL_LOC_REGPARM_ADDR
21816 Value is a specified register. Just like @code{LOC_REGISTER} except
21817 the register holds the address of the argument instead of the argument
21818 itself.
21819 @findex SYMBOL_LOC_LOCAL
21820 @findex gdb.SYMBOL_LOC_LOCAL
21821 @item SYMBOL_LOC_LOCAL
21822 Value is a local variable.
21823 @findex SYMBOL_LOC_TYPEDEF
21824 @findex gdb.SYMBOL_LOC_TYPEDEF
21825 @item SYMBOL_LOC_TYPEDEF
21826 Value not used. Symbols in the domain @code{SYMBOL_STRUCT_DOMAIN} all
21827 have this class.
21828 @findex SYMBOL_LOC_BLOCK
21829 @findex gdb.SYMBOL_LOC_BLOCK
21830 @item SYMBOL_LOC_BLOCK
21831 Value is a block.
21832 @findex SYMBOL_LOC_CONST_BYTES
21833 @findex gdb.SYMBOL_LOC_CONST_BYTES
21834 @item SYMBOL_LOC_CONST_BYTES
21835 Value is a byte-sequence.
21836 @findex SYMBOL_LOC_UNRESOLVED
21837 @findex gdb.SYMBOL_LOC_UNRESOLVED
21838 @item SYMBOL_LOC_UNRESOLVED
21839 Value is at a fixed address, but the address of the variable has to be
21840 determined from the minimal symbol table whenever the variable is
21841 referenced.
21842 @findex SYMBOL_LOC_OPTIMIZED_OUT
21843 @findex gdb.SYMBOL_LOC_OPTIMIZED_OUT
21844 @item SYMBOL_LOC_OPTIMIZED_OUT
21845 The value does not actually exist in the program.
21846 @findex SYMBOL_LOC_COMPUTED
21847 @findex gdb.SYMBOL_LOC_COMPUTED
21848 @item SYMBOL_LOC_COMPUTED
21849 The value's address is a computed location.
21850 @end table
21851
21852 @node Symbol Tables In Python
21853 @subsubsection Symbol table representation in Python.
21854
21855 @cindex symbol tables in python
21856 @tindex gdb.Symtab
21857 @tindex gdb.Symtab_and_line
21858
21859 Access to symbol table data maintained by @value{GDBN} on the inferior
21860 is exposed to Python via two objects: @code{gdb.Symtab_and_line} and
21861 @code{gdb.Symtab}. Symbol table and line data for a frame is returned
21862 from the @code{find_sal} method in @code{gdb.Frame} object.
21863 @xref{Frames In Python}.
21864
21865 For more information on @value{GDBN}'s symbol table management, see
21866 @ref{Symbols, ,Examining the Symbol Table}, for more information.
21867
21868 A @code{gdb.Symtab_and_line} object has the following attributes:
21869
21870 @table @code
21871 @defivar Symtab_and_line symtab
21872 The symbol table object (@code{gdb.Symtab}) for this frame.
21873 This attribute is not writable.
21874 @end defivar
21875
21876 @defivar Symtab_and_line pc
21877 Indicates the current program counter address. This attribute is not
21878 writable.
21879 @end defivar
21880
21881 @defivar Symtab_and_line line
21882 Indicates the current line number for this object. This
21883 attribute is not writable.
21884 @end defivar
21885 @end table
21886
21887 A @code{gdb.Symtab} object has the following attributes:
21888
21889 @table @code
21890 @defivar Symtab filename
21891 The symbol table's source filename. This attribute is not writable.
21892 @end defivar
21893
21894 @defivar Symtab objfile
21895 The symbol table's backing object file. @xref{Objfiles In Python}.
21896 This attribute is not writable.
21897 @end defivar
21898 @end table
21899
21900 The following methods are provided:
21901
21902 @table @code
21903 @defmethod Symtab fullname
21904 Return the symbol table's source absolute file name.
21905 @end defmethod
21906 @end table
21907
21908 @node Breakpoints In Python
21909 @subsubsection Manipulating breakpoints using Python
21910
21911 @cindex breakpoints in python
21912 @tindex gdb.Breakpoint
21913
21914 Python code can manipulate breakpoints via the @code{gdb.Breakpoint}
21915 class.
21916
21917 @defmethod Breakpoint __init__ spec @r{[}type@r{]} @r{[}wp_class@r{]}
21918 Create a new breakpoint. @var{spec} is a string naming the
21919 location of the breakpoint, or an expression that defines a
21920 watchpoint. The contents can be any location recognized by the
21921 @code{break} command, or in the case of a watchpoint, by the @code{watch}
21922 command. The optional @var{type} denotes the breakpoint to create
21923 from the types defined later in this chapter. This argument can be
21924 either: @code{BP_BREAKPOINT} or @code{BP_WATCHPOINT}. @var{type}
21925 defaults to @code{BP_BREAKPOINT}. The optional @var{wp_class}
21926 argument defines the class of watchpoint to create, if @var{type} is
21927 defined as @code{BP_WATCHPOINT}. If a watchpoint class is not
21928 provided, it is assumed to be a @var{WP_WRITE} class.
21929 @end defmethod
21930
21931 The available watchpoint types represented by constants are defined in the
21932 @code{gdb} module:
21933
21934 @table @code
21935 @findex WP_READ
21936 @findex gdb.WP_READ
21937 @item WP_READ
21938 Read only watchpoint.
21939
21940 @findex WP_WRITE
21941 @findex gdb.WP_WRITE
21942 @item WP_WRITE
21943 Write only watchpoint.
21944
21945 @findex WP_ACCESS
21946 @findex gdb.WP_ACCESS
21947 @item WP_ACCESS
21948 Read/Write watchpoint.
21949 @end table
21950
21951 @defmethod Breakpoint is_valid
21952 Return @code{True} if this @code{Breakpoint} object is valid,
21953 @code{False} otherwise. A @code{Breakpoint} object can become invalid
21954 if the user deletes the breakpoint. In this case, the object still
21955 exists, but the underlying breakpoint does not. In the cases of
21956 watchpoint scope, the watchpoint remains valid even if execution of the
21957 inferior leaves the scope of that watchpoint.
21958 @end defmethod
21959
21960 @defivar Breakpoint enabled
21961 This attribute is @code{True} if the breakpoint is enabled, and
21962 @code{False} otherwise. This attribute is writable.
21963 @end defivar
21964
21965 @defivar Breakpoint silent
21966 This attribute is @code{True} if the breakpoint is silent, and
21967 @code{False} otherwise. This attribute is writable.
21968
21969 Note that a breakpoint can also be silent if it has commands and the
21970 first command is @code{silent}. This is not reported by the
21971 @code{silent} attribute.
21972 @end defivar
21973
21974 @defivar Breakpoint thread
21975 If the breakpoint is thread-specific, this attribute holds the thread
21976 id. If the breakpoint is not thread-specific, this attribute is
21977 @code{None}. This attribute is writable.
21978 @end defivar
21979
21980 @defivar Breakpoint task
21981 If the breakpoint is Ada task-specific, this attribute holds the Ada task
21982 id. If the breakpoint is not task-specific (or the underlying
21983 language is not Ada), this attribute is @code{None}. This attribute
21984 is writable.
21985 @end defivar
21986
21987 @defivar Breakpoint ignore_count
21988 This attribute holds the ignore count for the breakpoint, an integer.
21989 This attribute is writable.
21990 @end defivar
21991
21992 @defivar Breakpoint number
21993 This attribute holds the breakpoint's number --- the identifier used by
21994 the user to manipulate the breakpoint. This attribute is not writable.
21995 @end defivar
21996
21997 @defivar Breakpoint type
21998 This attribute holds the breakpoint's type --- the identifier used to
21999 determine the actual breakpoint type or use-case. This attribute is not
22000 writable.
22001 @end defivar
22002
22003 The available types are represented by constants defined in the @code{gdb}
22004 module:
22005
22006 @table @code
22007 @findex BP_BREAKPOINT
22008 @findex gdb.BP_BREAKPOINT
22009 @item BP_BREAKPOINT
22010 Normal code breakpoint.
22011
22012 @findex BP_WATCHPOINT
22013 @findex gdb.BP_WATCHPOINT
22014 @item BP_WATCHPOINT
22015 Watchpoint breakpoint.
22016
22017 @findex BP_HARDWARE_WATCHPOINT
22018 @findex gdb.BP_HARDWARE_WATCHPOINT
22019 @item BP_HARDWARE_WATCHPOINT
22020 Hardware assisted watchpoint.
22021
22022 @findex BP_READ_WATCHPOINT
22023 @findex gdb.BP_READ_WATCHPOINT
22024 @item BP_READ_WATCHPOINT
22025 Hardware assisted read watchpoint.
22026
22027 @findex BP_ACCESS_WATCHPOINT
22028 @findex gdb.BP_ACCESS_WATCHPOINT
22029 @item BP_ACCESS_WATCHPOINT
22030 Hardware assisted access watchpoint.
22031 @end table
22032
22033 @defivar Breakpoint hit_count
22034 This attribute holds the hit count for the breakpoint, an integer.
22035 This attribute is writable, but currently it can only be set to zero.
22036 @end defivar
22037
22038 @defivar Breakpoint location
22039 This attribute holds the location of the breakpoint, as specified by
22040 the user. It is a string. If the breakpoint does not have a location
22041 (that is, it is a watchpoint) the attribute's value is @code{None}. This
22042 attribute is not writable.
22043 @end defivar
22044
22045 @defivar Breakpoint expression
22046 This attribute holds a breakpoint expression, as specified by
22047 the user. It is a string. If the breakpoint does not have an
22048 expression (the breakpoint is not a watchpoint) the attribute's value
22049 is @code{None}. This attribute is not writable.
22050 @end defivar
22051
22052 @defivar Breakpoint condition
22053 This attribute holds the condition of the breakpoint, as specified by
22054 the user. It is a string. If there is no condition, this attribute's
22055 value is @code{None}. This attribute is writable.
22056 @end defivar
22057
22058 @defivar Breakpoint commands
22059 This attribute holds the commands attached to the breakpoint. If
22060 there are commands, this attribute's value is a string holding all the
22061 commands, separated by newlines. If there are no commands, this
22062 attribute is @code{None}. This attribute is not writable.
22063 @end defivar
22064
22065 @node Lazy Strings In Python
22066 @subsubsection Python representation of lazy strings.
22067
22068 @cindex lazy strings in python
22069 @tindex gdb.LazyString
22070
22071 A @dfn{lazy string} is a string whose contents is not retrieved or
22072 encoded until it is needed.
22073
22074 A @code{gdb.LazyString} is represented in @value{GDBN} as an
22075 @code{address} that points to a region of memory, an @code{encoding}
22076 that will be used to encode that region of memory, and a @code{length}
22077 to delimit the region of memory that represents the string. The
22078 difference between a @code{gdb.LazyString} and a string wrapped within
22079 a @code{gdb.Value} is that a @code{gdb.LazyString} will be treated
22080 differently by @value{GDBN} when printing. A @code{gdb.LazyString} is
22081 retrieved and encoded during printing, while a @code{gdb.Value}
22082 wrapping a string is immediately retrieved and encoded on creation.
22083
22084 A @code{gdb.LazyString} object has the following functions:
22085
22086 @defmethod LazyString value
22087 Convert the @code{gdb.LazyString} to a @code{gdb.Value}. This value
22088 will point to the string in memory, but will lose all the delayed
22089 retrieval, encoding and handling that @value{GDBN} applies to a
22090 @code{gdb.LazyString}.
22091 @end defmethod
22092
22093 @defivar LazyString address
22094 This attribute holds the address of the string. This attribute is not
22095 writable.
22096 @end defivar
22097
22098 @defivar LazyString length
22099 This attribute holds the length of the string in characters. If the
22100 length is -1, then the string will be fetched and encoded up to the
22101 first null of appropriate width. This attribute is not writable.
22102 @end defivar
22103
22104 @defivar LazyString encoding
22105 This attribute holds the encoding that will be applied to the string
22106 when the string is printed by @value{GDBN}. If the encoding is not
22107 set, or contains an empty string, then @value{GDBN} will select the
22108 most appropriate encoding when the string is printed. This attribute
22109 is not writable.
22110 @end defivar
22111
22112 @defivar LazyString type
22113 This attribute holds the type that is represented by the lazy string's
22114 type. For a lazy string this will always be a pointer type. To
22115 resolve this to the lazy string's character type, use the type's
22116 @code{target} method. @xref{Types In Python}. This attribute is not
22117 writable.
22118 @end defivar
22119
22120 @node Auto-loading
22121 @subsection Auto-loading
22122 @cindex auto-loading, Python
22123
22124 When a new object file is read (for example, due to the @code{file}
22125 command, or because the inferior has loaded a shared library),
22126 @value{GDBN} will look for Python support scripts in several ways:
22127 @file{@var{objfile}-gdb.py} and @code{.debug_gdb_scripts} section.
22128
22129 @menu
22130 * objfile-gdb.py file:: The @file{@var{objfile}-gdb.py} file
22131 * .debug_gdb_scripts section:: The @code{.debug_gdb_scripts} section
22132 * Which flavor to choose?::
22133 @end menu
22134
22135 The auto-loading feature is useful for supplying application-specific
22136 debugging commands and scripts.
22137
22138 Auto-loading can be enabled or disabled.
22139
22140 @table @code
22141 @kindex maint set python auto-load
22142 @item maint set python auto-load [yes|no]
22143 Enable or disable the Python auto-loading feature.
22144
22145 @kindex maint show python auto-load
22146 @item maint show python auto-load
22147 Show whether Python auto-loading is enabled or disabled.
22148 @end table
22149
22150 When reading an auto-loaded file, @value{GDBN} sets the
22151 @dfn{current objfile}. This is available via the @code{gdb.current_objfile}
22152 function (@pxref{Objfiles In Python}). This can be useful for
22153 registering objfile-specific pretty-printers.
22154
22155 @node objfile-gdb.py file
22156 @subsubsection The @file{@var{objfile}-gdb.py} file
22157 @cindex @file{@var{objfile}-gdb.py}
22158
22159 When a new object file is read, @value{GDBN} looks for
22160 a file named @file{@var{objfile}-gdb.py},
22161 where @var{objfile} is the object file's real name, formed by ensuring
22162 that the file name is absolute, following all symlinks, and resolving
22163 @code{.} and @code{..} components. If this file exists and is
22164 readable, @value{GDBN} will evaluate it as a Python script.
22165
22166 If this file does not exist, and if the parameter
22167 @code{debug-file-directory} is set (@pxref{Separate Debug Files}),
22168 then @value{GDBN} will look for @var{real-name} in all of the
22169 directories mentioned in the value of @code{debug-file-directory}.
22170
22171 Finally, if this file does not exist, then @value{GDBN} will look for
22172 a file named @file{@var{data-directory}/python/auto-load/@var{real-name}}, where
22173 @var{data-directory} is @value{GDBN}'s data directory (available via
22174 @code{show data-directory}, @pxref{Data Files}), and @var{real-name}
22175 is the object file's real name, as described above.
22176
22177 @value{GDBN} does not track which files it has already auto-loaded this way.
22178 @value{GDBN} will load the associated script every time the corresponding
22179 @var{objfile} is opened.
22180 So your @file{-gdb.py} file should be careful to avoid errors if it
22181 is evaluated more than once.
22182
22183 @node .debug_gdb_scripts section
22184 @subsubsection The @code{.debug_gdb_scripts} section
22185 @cindex @code{.debug_gdb_scripts} section
22186
22187 For systems using file formats like ELF and COFF,
22188 when @value{GDBN} loads a new object file
22189 it will look for a special section named @samp{.debug_gdb_scripts}.
22190 If this section exists, its contents is a list of names of scripts to load.
22191
22192 @value{GDBN} will look for each specified script file first in the
22193 current directory and then along the source search path
22194 (@pxref{Source Path, ,Specifying Source Directories}),
22195 except that @file{$cdir} is not searched, since the compilation
22196 directory is not relevant to scripts.
22197
22198 Entries can be placed in section @code{.debug_gdb_scripts} with,
22199 for example, this GCC macro:
22200
22201 @example
22202 /* Note: The "MS" section flags are to remote duplicates. */
22203 #define DEFINE_GDB_SCRIPT(script_name) \
22204 asm("\
22205 .pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
22206 .byte 1\n\
22207 .asciz \"" script_name "\"\n\
22208 .popsection \n\
22209 ");
22210 @end example
22211
22212 @noindent
22213 Then one can reference the macro in a header or source file like this:
22214
22215 @example
22216 DEFINE_GDB_SCRIPT ("my-app-scripts.py")
22217 @end example
22218
22219 The script name may include directories if desired.
22220
22221 If the macro is put in a header, any application or library
22222 using this header will get a reference to the specified script.
22223
22224 @node Which flavor to choose?
22225 @subsubsection Which flavor to choose?
22226
22227 Given the multiple ways of auto-loading Python scripts, it might not always
22228 be clear which one to choose. This section provides some guidance.
22229
22230 Benefits of the @file{-gdb.py} way:
22231
22232 @itemize @bullet
22233 @item
22234 Can be used with file formats that don't support multiple sections.
22235
22236 @item
22237 Ease of finding scripts for public libraries.
22238
22239 Scripts specified in the @code{.debug_gdb_scripts} section are searched for
22240 in the source search path.
22241 For publicly installed libraries, e.g., @file{libstdc++}, there typically
22242 isn't a source directory in which to find the script.
22243
22244 @item
22245 Doesn't require source code additions.
22246 @end itemize
22247
22248 Benefits of the @code{.debug_gdb_scripts} way:
22249
22250 @itemize @bullet
22251 @item
22252 Works with static linking.
22253
22254 Scripts for libraries done the @file{-gdb.py} way require an objfile to
22255 trigger their loading. When an application is statically linked the only
22256 objfile available is the executable, and it is cumbersome to attach all the
22257 scripts from all the input libraries to the executable's @file{-gdb.py} script.
22258
22259 @item
22260 Works with classes that are entirely inlined.
22261
22262 Some classes can be entirely inlined, and thus there may not be an associated
22263 shared library to attach a @file{-gdb.py} script to.
22264
22265 @item
22266 Scripts needn't be copied out of the source tree.
22267
22268 In some circumstances, apps can be built out of large collections of internal
22269 libraries, and the build infrastructure necessary to install the
22270 @file{-gdb.py} scripts in a place where @value{GDBN} can find them is
22271 cumbersome. It may be easier to specify the scripts in the
22272 @code{.debug_gdb_scripts} section as relative paths, and add a path to the
22273 top of the source tree to the source search path.
22274 @end itemize
22275
22276 @node Interpreters
22277 @chapter Command Interpreters
22278 @cindex command interpreters
22279
22280 @value{GDBN} supports multiple command interpreters, and some command
22281 infrastructure to allow users or user interface writers to switch
22282 between interpreters or run commands in other interpreters.
22283
22284 @value{GDBN} currently supports two command interpreters, the console
22285 interpreter (sometimes called the command-line interpreter or @sc{cli})
22286 and the machine interface interpreter (or @sc{gdb/mi}). This manual
22287 describes both of these interfaces in great detail.
22288
22289 By default, @value{GDBN} will start with the console interpreter.
22290 However, the user may choose to start @value{GDBN} with another
22291 interpreter by specifying the @option{-i} or @option{--interpreter}
22292 startup options. Defined interpreters include:
22293
22294 @table @code
22295 @item console
22296 @cindex console interpreter
22297 The traditional console or command-line interpreter. This is the most often
22298 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
22299 @value{GDBN} will use this interpreter.
22300
22301 @item mi
22302 @cindex mi interpreter
22303 The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
22304 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
22305 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
22306 Interface}.
22307
22308 @item mi2
22309 @cindex mi2 interpreter
22310 The current @sc{gdb/mi} interface.
22311
22312 @item mi1
22313 @cindex mi1 interpreter
22314 The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
22315
22316 @end table
22317
22318 @cindex invoke another interpreter
22319 The interpreter being used by @value{GDBN} may not be dynamically
22320 switched at runtime. Although possible, this could lead to a very
22321 precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
22322 enters the command "interpreter-set console" in a console view,
22323 @value{GDBN} would switch to using the console interpreter, rendering
22324 the IDE inoperable!
22325
22326 @kindex interpreter-exec
22327 Although you may only choose a single interpreter at startup, you may execute
22328 commands in any interpreter from the current interpreter using the appropriate
22329 command. If you are running the console interpreter, simply use the
22330 @code{interpreter-exec} command:
22331
22332 @smallexample
22333 interpreter-exec mi "-data-list-register-names"
22334 @end smallexample
22335
22336 @sc{gdb/mi} has a similar command, although it is only available in versions of
22337 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
22338
22339 @node TUI
22340 @chapter @value{GDBN} Text User Interface
22341 @cindex TUI
22342 @cindex Text User Interface
22343
22344 @menu
22345 * TUI Overview:: TUI overview
22346 * TUI Keys:: TUI key bindings
22347 * TUI Single Key Mode:: TUI single key mode
22348 * TUI Commands:: TUI-specific commands
22349 * TUI Configuration:: TUI configuration variables
22350 @end menu
22351
22352 The @value{GDBN} Text User Interface (TUI) is a terminal
22353 interface which uses the @code{curses} library to show the source
22354 file, the assembly output, the program registers and @value{GDBN}
22355 commands in separate text windows. The TUI mode is supported only
22356 on platforms where a suitable version of the @code{curses} library
22357 is available.
22358
22359 @pindex @value{GDBTUI}
22360 The TUI mode is enabled by default when you invoke @value{GDBN} as
22361 either @samp{@value{GDBTUI}} or @samp{@value{GDBP} -tui}.
22362 You can also switch in and out of TUI mode while @value{GDBN} runs by
22363 using various TUI commands and key bindings, such as @kbd{C-x C-a}.
22364 @xref{TUI Keys, ,TUI Key Bindings}.
22365
22366 @node TUI Overview
22367 @section TUI Overview
22368
22369 In TUI mode, @value{GDBN} can display several text windows:
22370
22371 @table @emph
22372 @item command
22373 This window is the @value{GDBN} command window with the @value{GDBN}
22374 prompt and the @value{GDBN} output. The @value{GDBN} input is still
22375 managed using readline.
22376
22377 @item source
22378 The source window shows the source file of the program. The current
22379 line and active breakpoints are displayed in this window.
22380
22381 @item assembly
22382 The assembly window shows the disassembly output of the program.
22383
22384 @item register
22385 This window shows the processor registers. Registers are highlighted
22386 when their values change.
22387 @end table
22388
22389 The source and assembly windows show the current program position
22390 by highlighting the current line and marking it with a @samp{>} marker.
22391 Breakpoints are indicated with two markers. The first marker
22392 indicates the breakpoint type:
22393
22394 @table @code
22395 @item B
22396 Breakpoint which was hit at least once.
22397
22398 @item b
22399 Breakpoint which was never hit.
22400
22401 @item H
22402 Hardware breakpoint which was hit at least once.
22403
22404 @item h
22405 Hardware breakpoint which was never hit.
22406 @end table
22407
22408 The second marker indicates whether the breakpoint is enabled or not:
22409
22410 @table @code
22411 @item +
22412 Breakpoint is enabled.
22413
22414 @item -
22415 Breakpoint is disabled.
22416 @end table
22417
22418 The source, assembly and register windows are updated when the current
22419 thread changes, when the frame changes, or when the program counter
22420 changes.
22421
22422 These windows are not all visible at the same time. The command
22423 window is always visible. The others can be arranged in several
22424 layouts:
22425
22426 @itemize @bullet
22427 @item
22428 source only,
22429
22430 @item
22431 assembly only,
22432
22433 @item
22434 source and assembly,
22435
22436 @item
22437 source and registers, or
22438
22439 @item
22440 assembly and registers.
22441 @end itemize
22442
22443 A status line above the command window shows the following information:
22444
22445 @table @emph
22446 @item target
22447 Indicates the current @value{GDBN} target.
22448 (@pxref{Targets, ,Specifying a Debugging Target}).
22449
22450 @item process
22451 Gives the current process or thread number.
22452 When no process is being debugged, this field is set to @code{No process}.
22453
22454 @item function
22455 Gives the current function name for the selected frame.
22456 The name is demangled if demangling is turned on (@pxref{Print Settings}).
22457 When there is no symbol corresponding to the current program counter,
22458 the string @code{??} is displayed.
22459
22460 @item line
22461 Indicates the current line number for the selected frame.
22462 When the current line number is not known, the string @code{??} is displayed.
22463
22464 @item pc
22465 Indicates the current program counter address.
22466 @end table
22467
22468 @node TUI Keys
22469 @section TUI Key Bindings
22470 @cindex TUI key bindings
22471
22472 The TUI installs several key bindings in the readline keymaps
22473 (@pxref{Command Line Editing}). The following key bindings
22474 are installed for both TUI mode and the @value{GDBN} standard mode.
22475
22476 @table @kbd
22477 @kindex C-x C-a
22478 @item C-x C-a
22479 @kindex C-x a
22480 @itemx C-x a
22481 @kindex C-x A
22482 @itemx C-x A
22483 Enter or leave the TUI mode. When leaving the TUI mode,
22484 the curses window management stops and @value{GDBN} operates using
22485 its standard mode, writing on the terminal directly. When reentering
22486 the TUI mode, control is given back to the curses windows.
22487 The screen is then refreshed.
22488
22489 @kindex C-x 1
22490 @item C-x 1
22491 Use a TUI layout with only one window. The layout will
22492 either be @samp{source} or @samp{assembly}. When the TUI mode
22493 is not active, it will switch to the TUI mode.
22494
22495 Think of this key binding as the Emacs @kbd{C-x 1} binding.
22496
22497 @kindex C-x 2
22498 @item C-x 2
22499 Use a TUI layout with at least two windows. When the current
22500 layout already has two windows, the next layout with two windows is used.
22501 When a new layout is chosen, one window will always be common to the
22502 previous layout and the new one.
22503
22504 Think of it as the Emacs @kbd{C-x 2} binding.
22505
22506 @kindex C-x o
22507 @item C-x o
22508 Change the active window. The TUI associates several key bindings
22509 (like scrolling and arrow keys) with the active window. This command
22510 gives the focus to the next TUI window.
22511
22512 Think of it as the Emacs @kbd{C-x o} binding.
22513
22514 @kindex C-x s
22515 @item C-x s
22516 Switch in and out of the TUI SingleKey mode that binds single
22517 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
22518 @end table
22519
22520 The following key bindings only work in the TUI mode:
22521
22522 @table @asis
22523 @kindex PgUp
22524 @item @key{PgUp}
22525 Scroll the active window one page up.
22526
22527 @kindex PgDn
22528 @item @key{PgDn}
22529 Scroll the active window one page down.
22530
22531 @kindex Up
22532 @item @key{Up}
22533 Scroll the active window one line up.
22534
22535 @kindex Down
22536 @item @key{Down}
22537 Scroll the active window one line down.
22538
22539 @kindex Left
22540 @item @key{Left}
22541 Scroll the active window one column left.
22542
22543 @kindex Right
22544 @item @key{Right}
22545 Scroll the active window one column right.
22546
22547 @kindex C-L
22548 @item @kbd{C-L}
22549 Refresh the screen.
22550 @end table
22551
22552 Because the arrow keys scroll the active window in the TUI mode, they
22553 are not available for their normal use by readline unless the command
22554 window has the focus. When another window is active, you must use
22555 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
22556 and @kbd{C-f} to control the command window.
22557
22558 @node TUI Single Key Mode
22559 @section TUI Single Key Mode
22560 @cindex TUI single key mode
22561
22562 The TUI also provides a @dfn{SingleKey} mode, which binds several
22563 frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
22564 switch into this mode, where the following key bindings are used:
22565
22566 @table @kbd
22567 @kindex c @r{(SingleKey TUI key)}
22568 @item c
22569 continue
22570
22571 @kindex d @r{(SingleKey TUI key)}
22572 @item d
22573 down
22574
22575 @kindex f @r{(SingleKey TUI key)}
22576 @item f
22577 finish
22578
22579 @kindex n @r{(SingleKey TUI key)}
22580 @item n
22581 next
22582
22583 @kindex q @r{(SingleKey TUI key)}
22584 @item q
22585 exit the SingleKey mode.
22586
22587 @kindex r @r{(SingleKey TUI key)}
22588 @item r
22589 run
22590
22591 @kindex s @r{(SingleKey TUI key)}
22592 @item s
22593 step
22594
22595 @kindex u @r{(SingleKey TUI key)}
22596 @item u
22597 up
22598
22599 @kindex v @r{(SingleKey TUI key)}
22600 @item v
22601 info locals
22602
22603 @kindex w @r{(SingleKey TUI key)}
22604 @item w
22605 where
22606 @end table
22607
22608 Other keys temporarily switch to the @value{GDBN} command prompt.
22609 The key that was pressed is inserted in the editing buffer so that
22610 it is possible to type most @value{GDBN} commands without interaction
22611 with the TUI SingleKey mode. Once the command is entered the TUI
22612 SingleKey mode is restored. The only way to permanently leave
22613 this mode is by typing @kbd{q} or @kbd{C-x s}.
22614
22615
22616 @node TUI Commands
22617 @section TUI-specific Commands
22618 @cindex TUI commands
22619
22620 The TUI has specific commands to control the text windows.
22621 These commands are always available, even when @value{GDBN} is not in
22622 the TUI mode. When @value{GDBN} is in the standard mode, most
22623 of these commands will automatically switch to the TUI mode.
22624
22625 Note that if @value{GDBN}'s @code{stdout} is not connected to a
22626 terminal, or @value{GDBN} has been started with the machine interface
22627 interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
22628 these commands will fail with an error, because it would not be
22629 possible or desirable to enable curses window management.
22630
22631 @table @code
22632 @item info win
22633 @kindex info win
22634 List and give the size of all displayed windows.
22635
22636 @item layout next
22637 @kindex layout
22638 Display the next layout.
22639
22640 @item layout prev
22641 Display the previous layout.
22642
22643 @item layout src
22644 Display the source window only.
22645
22646 @item layout asm
22647 Display the assembly window only.
22648
22649 @item layout split
22650 Display the source and assembly window.
22651
22652 @item layout regs
22653 Display the register window together with the source or assembly window.
22654
22655 @item focus next
22656 @kindex focus
22657 Make the next window active for scrolling.
22658
22659 @item focus prev
22660 Make the previous window active for scrolling.
22661
22662 @item focus src
22663 Make the source window active for scrolling.
22664
22665 @item focus asm
22666 Make the assembly window active for scrolling.
22667
22668 @item focus regs
22669 Make the register window active for scrolling.
22670
22671 @item focus cmd
22672 Make the command window active for scrolling.
22673
22674 @item refresh
22675 @kindex refresh
22676 Refresh the screen. This is similar to typing @kbd{C-L}.
22677
22678 @item tui reg float
22679 @kindex tui reg
22680 Show the floating point registers in the register window.
22681
22682 @item tui reg general
22683 Show the general registers in the register window.
22684
22685 @item tui reg next
22686 Show the next register group. The list of register groups as well as
22687 their order is target specific. The predefined register groups are the
22688 following: @code{general}, @code{float}, @code{system}, @code{vector},
22689 @code{all}, @code{save}, @code{restore}.
22690
22691 @item tui reg system
22692 Show the system registers in the register window.
22693
22694 @item update
22695 @kindex update
22696 Update the source window and the current execution point.
22697
22698 @item winheight @var{name} +@var{count}
22699 @itemx winheight @var{name} -@var{count}
22700 @kindex winheight
22701 Change the height of the window @var{name} by @var{count}
22702 lines. Positive counts increase the height, while negative counts
22703 decrease it.
22704
22705 @item tabset @var{nchars}
22706 @kindex tabset
22707 Set the width of tab stops to be @var{nchars} characters.
22708 @end table
22709
22710 @node TUI Configuration
22711 @section TUI Configuration Variables
22712 @cindex TUI configuration variables
22713
22714 Several configuration variables control the appearance of TUI windows.
22715
22716 @table @code
22717 @item set tui border-kind @var{kind}
22718 @kindex set tui border-kind
22719 Select the border appearance for the source, assembly and register windows.
22720 The possible values are the following:
22721 @table @code
22722 @item space
22723 Use a space character to draw the border.
22724
22725 @item ascii
22726 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
22727
22728 @item acs
22729 Use the Alternate Character Set to draw the border. The border is
22730 drawn using character line graphics if the terminal supports them.
22731 @end table
22732
22733 @item set tui border-mode @var{mode}
22734 @kindex set tui border-mode
22735 @itemx set tui active-border-mode @var{mode}
22736 @kindex set tui active-border-mode
22737 Select the display attributes for the borders of the inactive windows
22738 or the active window. The @var{mode} can be one of the following:
22739 @table @code
22740 @item normal
22741 Use normal attributes to display the border.
22742
22743 @item standout
22744 Use standout mode.
22745
22746 @item reverse
22747 Use reverse video mode.
22748
22749 @item half
22750 Use half bright mode.
22751
22752 @item half-standout
22753 Use half bright and standout mode.
22754
22755 @item bold
22756 Use extra bright or bold mode.
22757
22758 @item bold-standout
22759 Use extra bright or bold and standout mode.
22760 @end table
22761 @end table
22762
22763 @node Emacs
22764 @chapter Using @value{GDBN} under @sc{gnu} Emacs
22765
22766 @cindex Emacs
22767 @cindex @sc{gnu} Emacs
22768 A special interface allows you to use @sc{gnu} Emacs to view (and
22769 edit) the source files for the program you are debugging with
22770 @value{GDBN}.
22771
22772 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
22773 executable file you want to debug as an argument. This command starts
22774 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
22775 created Emacs buffer.
22776 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
22777
22778 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
22779 things:
22780
22781 @itemize @bullet
22782 @item
22783 All ``terminal'' input and output goes through an Emacs buffer, called
22784 the GUD buffer.
22785
22786 This applies both to @value{GDBN} commands and their output, and to the input
22787 and output done by the program you are debugging.
22788
22789 This is useful because it means that you can copy the text of previous
22790 commands and input them again; you can even use parts of the output
22791 in this way.
22792
22793 All the facilities of Emacs' Shell mode are available for interacting
22794 with your program. In particular, you can send signals the usual
22795 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
22796 stop.
22797
22798 @item
22799 @value{GDBN} displays source code through Emacs.
22800
22801 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
22802 source file for that frame and puts an arrow (@samp{=>}) at the
22803 left margin of the current line. Emacs uses a separate buffer for
22804 source display, and splits the screen to show both your @value{GDBN} session
22805 and the source.
22806
22807 Explicit @value{GDBN} @code{list} or search commands still produce output as
22808 usual, but you probably have no reason to use them from Emacs.
22809 @end itemize
22810
22811 We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
22812 a graphical mode, enabled by default, which provides further buffers
22813 that can control the execution and describe the state of your program.
22814 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
22815
22816 If you specify an absolute file name when prompted for the @kbd{M-x
22817 gdb} argument, then Emacs sets your current working directory to where
22818 your program resides. If you only specify the file name, then Emacs
22819 sets your current working directory to to the directory associated
22820 with the previous buffer. In this case, @value{GDBN} may find your
22821 program by searching your environment's @code{PATH} variable, but on
22822 some operating systems it might not find the source. So, although the
22823 @value{GDBN} input and output session proceeds normally, the auxiliary
22824 buffer does not display the current source and line of execution.
22825
22826 The initial working directory of @value{GDBN} is printed on the top
22827 line of the GUD buffer and this serves as a default for the commands
22828 that specify files for @value{GDBN} to operate on. @xref{Files,
22829 ,Commands to Specify Files}.
22830
22831 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
22832 need to call @value{GDBN} by a different name (for example, if you
22833 keep several configurations around, with different names) you can
22834 customize the Emacs variable @code{gud-gdb-command-name} to run the
22835 one you want.
22836
22837 In the GUD buffer, you can use these special Emacs commands in
22838 addition to the standard Shell mode commands:
22839
22840 @table @kbd
22841 @item C-h m
22842 Describe the features of Emacs' GUD Mode.
22843
22844 @item C-c C-s
22845 Execute to another source line, like the @value{GDBN} @code{step} command; also
22846 update the display window to show the current file and location.
22847
22848 @item C-c C-n
22849 Execute to next source line in this function, skipping all function
22850 calls, like the @value{GDBN} @code{next} command. Then update the display window
22851 to show the current file and location.
22852
22853 @item C-c C-i
22854 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
22855 display window accordingly.
22856
22857 @item C-c C-f
22858 Execute until exit from the selected stack frame, like the @value{GDBN}
22859 @code{finish} command.
22860
22861 @item C-c C-r
22862 Continue execution of your program, like the @value{GDBN} @code{continue}
22863 command.
22864
22865 @item C-c <
22866 Go up the number of frames indicated by the numeric argument
22867 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
22868 like the @value{GDBN} @code{up} command.
22869
22870 @item C-c >
22871 Go down the number of frames indicated by the numeric argument, like the
22872 @value{GDBN} @code{down} command.
22873 @end table
22874
22875 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
22876 tells @value{GDBN} to set a breakpoint on the source line point is on.
22877
22878 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
22879 separate frame which shows a backtrace when the GUD buffer is current.
22880 Move point to any frame in the stack and type @key{RET} to make it
22881 become the current frame and display the associated source in the
22882 source buffer. Alternatively, click @kbd{Mouse-2} to make the
22883 selected frame become the current one. In graphical mode, the
22884 speedbar displays watch expressions.
22885
22886 If you accidentally delete the source-display buffer, an easy way to get
22887 it back is to type the command @code{f} in the @value{GDBN} buffer, to
22888 request a frame display; when you run under Emacs, this recreates
22889 the source buffer if necessary to show you the context of the current
22890 frame.
22891
22892 The source files displayed in Emacs are in ordinary Emacs buffers
22893 which are visiting the source files in the usual way. You can edit
22894 the files with these buffers if you wish; but keep in mind that @value{GDBN}
22895 communicates with Emacs in terms of line numbers. If you add or
22896 delete lines from the text, the line numbers that @value{GDBN} knows cease
22897 to correspond properly with the code.
22898
22899 A more detailed description of Emacs' interaction with @value{GDBN} is
22900 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
22901 Emacs Manual}).
22902
22903 @c The following dropped because Epoch is nonstandard. Reactivate
22904 @c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
22905 @ignore
22906 @kindex Emacs Epoch environment
22907 @kindex Epoch
22908 @kindex inspect
22909
22910 Version 18 of @sc{gnu} Emacs has a built-in window system
22911 called the @code{epoch}
22912 environment. Users of this environment can use a new command,
22913 @code{inspect} which performs identically to @code{print} except that
22914 each value is printed in its own window.
22915 @end ignore
22916
22917
22918 @node GDB/MI
22919 @chapter The @sc{gdb/mi} Interface
22920
22921 @unnumberedsec Function and Purpose
22922
22923 @cindex @sc{gdb/mi}, its purpose
22924 @sc{gdb/mi} is a line based machine oriented text interface to
22925 @value{GDBN} and is activated by specifying using the
22926 @option{--interpreter} command line option (@pxref{Mode Options}). It
22927 is specifically intended to support the development of systems which
22928 use the debugger as just one small component of a larger system.
22929
22930 This chapter is a specification of the @sc{gdb/mi} interface. It is written
22931 in the form of a reference manual.
22932
22933 Note that @sc{gdb/mi} is still under construction, so some of the
22934 features described below are incomplete and subject to change
22935 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
22936
22937 @unnumberedsec Notation and Terminology
22938
22939 @cindex notational conventions, for @sc{gdb/mi}
22940 This chapter uses the following notation:
22941
22942 @itemize @bullet
22943 @item
22944 @code{|} separates two alternatives.
22945
22946 @item
22947 @code{[ @var{something} ]} indicates that @var{something} is optional:
22948 it may or may not be given.
22949
22950 @item
22951 @code{( @var{group} )*} means that @var{group} inside the parentheses
22952 may repeat zero or more times.
22953
22954 @item
22955 @code{( @var{group} )+} means that @var{group} inside the parentheses
22956 may repeat one or more times.
22957
22958 @item
22959 @code{"@var{string}"} means a literal @var{string}.
22960 @end itemize
22961
22962 @ignore
22963 @heading Dependencies
22964 @end ignore
22965
22966 @menu
22967 * GDB/MI General Design::
22968 * GDB/MI Command Syntax::
22969 * GDB/MI Compatibility with CLI::
22970 * GDB/MI Development and Front Ends::
22971 * GDB/MI Output Records::
22972 * GDB/MI Simple Examples::
22973 * GDB/MI Command Description Format::
22974 * GDB/MI Breakpoint Commands::
22975 * GDB/MI Program Context::
22976 * GDB/MI Thread Commands::
22977 * GDB/MI Program Execution::
22978 * GDB/MI Stack Manipulation::
22979 * GDB/MI Variable Objects::
22980 * GDB/MI Data Manipulation::
22981 * GDB/MI Tracepoint Commands::
22982 * GDB/MI Symbol Query::
22983 * GDB/MI File Commands::
22984 @ignore
22985 * GDB/MI Kod Commands::
22986 * GDB/MI Memory Overlay Commands::
22987 * GDB/MI Signal Handling Commands::
22988 @end ignore
22989 * GDB/MI Target Manipulation::
22990 * GDB/MI File Transfer Commands::
22991 * GDB/MI Miscellaneous Commands::
22992 @end menu
22993
22994 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22995 @node GDB/MI General Design
22996 @section @sc{gdb/mi} General Design
22997 @cindex GDB/MI General Design
22998
22999 Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
23000 parts---commands sent to @value{GDBN}, responses to those commands
23001 and notifications. Each command results in exactly one response,
23002 indicating either successful completion of the command, or an error.
23003 For the commands that do not resume the target, the response contains the
23004 requested information. For the commands that resume the target, the
23005 response only indicates whether the target was successfully resumed.
23006 Notifications is the mechanism for reporting changes in the state of the
23007 target, or in @value{GDBN} state, that cannot conveniently be associated with
23008 a command and reported as part of that command response.
23009
23010 The important examples of notifications are:
23011 @itemize @bullet
23012
23013 @item
23014 Exec notifications. These are used to report changes in
23015 target state---when a target is resumed, or stopped. It would not
23016 be feasible to include this information in response of resuming
23017 commands, because one resume commands can result in multiple events in
23018 different threads. Also, quite some time may pass before any event
23019 happens in the target, while a frontend needs to know whether the resuming
23020 command itself was successfully executed.
23021
23022 @item
23023 Console output, and status notifications. Console output
23024 notifications are used to report output of CLI commands, as well as
23025 diagnostics for other commands. Status notifications are used to
23026 report the progress of a long-running operation. Naturally, including
23027 this information in command response would mean no output is produced
23028 until the command is finished, which is undesirable.
23029
23030 @item
23031 General notifications. Commands may have various side effects on
23032 the @value{GDBN} or target state beyond their official purpose. For example,
23033 a command may change the selected thread. Although such changes can
23034 be included in command response, using notification allows for more
23035 orthogonal frontend design.
23036
23037 @end itemize
23038
23039 There's no guarantee that whenever an MI command reports an error,
23040 @value{GDBN} or the target are in any specific state, and especially,
23041 the state is not reverted to the state before the MI command was
23042 processed. Therefore, whenever an MI command results in an error,
23043 we recommend that the frontend refreshes all the information shown in
23044 the user interface.
23045
23046
23047 @menu
23048 * Context management::
23049 * Asynchronous and non-stop modes::
23050 * Thread groups::
23051 @end menu
23052
23053 @node Context management
23054 @subsection Context management
23055
23056 In most cases when @value{GDBN} accesses the target, this access is
23057 done in context of a specific thread and frame (@pxref{Frames}).
23058 Often, even when accessing global data, the target requires that a thread
23059 be specified. The CLI interface maintains the selected thread and frame,
23060 and supplies them to target on each command. This is convenient,
23061 because a command line user would not want to specify that information
23062 explicitly on each command, and because user interacts with
23063 @value{GDBN} via a single terminal, so no confusion is possible as
23064 to what thread and frame are the current ones.
23065
23066 In the case of MI, the concept of selected thread and frame is less
23067 useful. First, a frontend can easily remember this information
23068 itself. Second, a graphical frontend can have more than one window,
23069 each one used for debugging a different thread, and the frontend might
23070 want to access additional threads for internal purposes. This
23071 increases the risk that by relying on implicitly selected thread, the
23072 frontend may be operating on a wrong one. Therefore, each MI command
23073 should explicitly specify which thread and frame to operate on. To
23074 make it possible, each MI command accepts the @samp{--thread} and
23075 @samp{--frame} options, the value to each is @value{GDBN} identifier
23076 for thread and frame to operate on.
23077
23078 Usually, each top-level window in a frontend allows the user to select
23079 a thread and a frame, and remembers the user selection for further
23080 operations. However, in some cases @value{GDBN} may suggest that the
23081 current thread be changed. For example, when stopping on a breakpoint
23082 it is reasonable to switch to the thread where breakpoint is hit. For
23083 another example, if the user issues the CLI @samp{thread} command via
23084 the frontend, it is desirable to change the frontend's selected thread to the
23085 one specified by user. @value{GDBN} communicates the suggestion to
23086 change current thread using the @samp{=thread-selected} notification.
23087 No such notification is available for the selected frame at the moment.
23088
23089 Note that historically, MI shares the selected thread with CLI, so
23090 frontends used the @code{-thread-select} to execute commands in the
23091 right context. However, getting this to work right is cumbersome. The
23092 simplest way is for frontend to emit @code{-thread-select} command
23093 before every command. This doubles the number of commands that need
23094 to be sent. The alternative approach is to suppress @code{-thread-select}
23095 if the selected thread in @value{GDBN} is supposed to be identical to the
23096 thread the frontend wants to operate on. However, getting this
23097 optimization right can be tricky. In particular, if the frontend
23098 sends several commands to @value{GDBN}, and one of the commands changes the
23099 selected thread, then the behaviour of subsequent commands will
23100 change. So, a frontend should either wait for response from such
23101 problematic commands, or explicitly add @code{-thread-select} for
23102 all subsequent commands. No frontend is known to do this exactly
23103 right, so it is suggested to just always pass the @samp{--thread} and
23104 @samp{--frame} options.
23105
23106 @node Asynchronous and non-stop modes
23107 @subsection Asynchronous command execution and non-stop mode
23108
23109 On some targets, @value{GDBN} is capable of processing MI commands
23110 even while the target is running. This is called @dfn{asynchronous
23111 command execution} (@pxref{Background Execution}). The frontend may
23112 specify a preferrence for asynchronous execution using the
23113 @code{-gdb-set target-async 1} command, which should be emitted before
23114 either running the executable or attaching to the target. After the
23115 frontend has started the executable or attached to the target, it can
23116 find if asynchronous execution is enabled using the
23117 @code{-list-target-features} command.
23118
23119 Even if @value{GDBN} can accept a command while target is running,
23120 many commands that access the target do not work when the target is
23121 running. Therefore, asynchronous command execution is most useful
23122 when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
23123 it is possible to examine the state of one thread, while other threads
23124 are running.
23125
23126 When a given thread is running, MI commands that try to access the
23127 target in the context of that thread may not work, or may work only on
23128 some targets. In particular, commands that try to operate on thread's
23129 stack will not work, on any target. Commands that read memory, or
23130 modify breakpoints, may work or not work, depending on the target. Note
23131 that even commands that operate on global state, such as @code{print},
23132 @code{set}, and breakpoint commands, still access the target in the
23133 context of a specific thread, so frontend should try to find a
23134 stopped thread and perform the operation on that thread (using the
23135 @samp{--thread} option).
23136
23137 Which commands will work in the context of a running thread is
23138 highly target dependent. However, the two commands
23139 @code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
23140 to find the state of a thread, will always work.
23141
23142 @node Thread groups
23143 @subsection Thread groups
23144 @value{GDBN} may be used to debug several processes at the same time.
23145 On some platfroms, @value{GDBN} may support debugging of several
23146 hardware systems, each one having several cores with several different
23147 processes running on each core. This section describes the MI
23148 mechanism to support such debugging scenarios.
23149
23150 The key observation is that regardless of the structure of the
23151 target, MI can have a global list of threads, because most commands that
23152 accept the @samp{--thread} option do not need to know what process that
23153 thread belongs to. Therefore, it is not necessary to introduce
23154 neither additional @samp{--process} option, nor an notion of the
23155 current process in the MI interface. The only strictly new feature
23156 that is required is the ability to find how the threads are grouped
23157 into processes.
23158
23159 To allow the user to discover such grouping, and to support arbitrary
23160 hierarchy of machines/cores/processes, MI introduces the concept of a
23161 @dfn{thread group}. Thread group is a collection of threads and other
23162 thread groups. A thread group always has a string identifier, a type,
23163 and may have additional attributes specific to the type. A new
23164 command, @code{-list-thread-groups}, returns the list of top-level
23165 thread groups, which correspond to processes that @value{GDBN} is
23166 debugging at the moment. By passing an identifier of a thread group
23167 to the @code{-list-thread-groups} command, it is possible to obtain
23168 the members of specific thread group.
23169
23170 To allow the user to easily discover processes, and other objects, he
23171 wishes to debug, a concept of @dfn{available thread group} is
23172 introduced. Available thread group is an thread group that
23173 @value{GDBN} is not debugging, but that can be attached to, using the
23174 @code{-target-attach} command. The list of available top-level thread
23175 groups can be obtained using @samp{-list-thread-groups --available}.
23176 In general, the content of a thread group may be only retrieved only
23177 after attaching to that thread group.
23178
23179 Thread groups are related to inferiors (@pxref{Inferiors and
23180 Programs}). Each inferior corresponds to a thread group of a special
23181 type @samp{process}, and some additional operations are permitted on
23182 such thread groups.
23183
23184 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23185 @node GDB/MI Command Syntax
23186 @section @sc{gdb/mi} Command Syntax
23187
23188 @menu
23189 * GDB/MI Input Syntax::
23190 * GDB/MI Output Syntax::
23191 @end menu
23192
23193 @node GDB/MI Input Syntax
23194 @subsection @sc{gdb/mi} Input Syntax
23195
23196 @cindex input syntax for @sc{gdb/mi}
23197 @cindex @sc{gdb/mi}, input syntax
23198 @table @code
23199 @item @var{command} @expansion{}
23200 @code{@var{cli-command} | @var{mi-command}}
23201
23202 @item @var{cli-command} @expansion{}
23203 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
23204 @var{cli-command} is any existing @value{GDBN} CLI command.
23205
23206 @item @var{mi-command} @expansion{}
23207 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
23208 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
23209
23210 @item @var{token} @expansion{}
23211 "any sequence of digits"
23212
23213 @item @var{option} @expansion{}
23214 @code{"-" @var{parameter} [ " " @var{parameter} ]}
23215
23216 @item @var{parameter} @expansion{}
23217 @code{@var{non-blank-sequence} | @var{c-string}}
23218
23219 @item @var{operation} @expansion{}
23220 @emph{any of the operations described in this chapter}
23221
23222 @item @var{non-blank-sequence} @expansion{}
23223 @emph{anything, provided it doesn't contain special characters such as
23224 "-", @var{nl}, """ and of course " "}
23225
23226 @item @var{c-string} @expansion{}
23227 @code{""" @var{seven-bit-iso-c-string-content} """}
23228
23229 @item @var{nl} @expansion{}
23230 @code{CR | CR-LF}
23231 @end table
23232
23233 @noindent
23234 Notes:
23235
23236 @itemize @bullet
23237 @item
23238 The CLI commands are still handled by the @sc{mi} interpreter; their
23239 output is described below.
23240
23241 @item
23242 The @code{@var{token}}, when present, is passed back when the command
23243 finishes.
23244
23245 @item
23246 Some @sc{mi} commands accept optional arguments as part of the parameter
23247 list. Each option is identified by a leading @samp{-} (dash) and may be
23248 followed by an optional argument parameter. Options occur first in the
23249 parameter list and can be delimited from normal parameters using
23250 @samp{--} (this is useful when some parameters begin with a dash).
23251 @end itemize
23252
23253 Pragmatics:
23254
23255 @itemize @bullet
23256 @item
23257 We want easy access to the existing CLI syntax (for debugging).
23258
23259 @item
23260 We want it to be easy to spot a @sc{mi} operation.
23261 @end itemize
23262
23263 @node GDB/MI Output Syntax
23264 @subsection @sc{gdb/mi} Output Syntax
23265
23266 @cindex output syntax of @sc{gdb/mi}
23267 @cindex @sc{gdb/mi}, output syntax
23268 The output from @sc{gdb/mi} consists of zero or more out-of-band records
23269 followed, optionally, by a single result record. This result record
23270 is for the most recent command. The sequence of output records is
23271 terminated by @samp{(gdb)}.
23272
23273 If an input command was prefixed with a @code{@var{token}} then the
23274 corresponding output for that command will also be prefixed by that same
23275 @var{token}.
23276
23277 @table @code
23278 @item @var{output} @expansion{}
23279 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
23280
23281 @item @var{result-record} @expansion{}
23282 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
23283
23284 @item @var{out-of-band-record} @expansion{}
23285 @code{@var{async-record} | @var{stream-record}}
23286
23287 @item @var{async-record} @expansion{}
23288 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
23289
23290 @item @var{exec-async-output} @expansion{}
23291 @code{[ @var{token} ] "*" @var{async-output}}
23292
23293 @item @var{status-async-output} @expansion{}
23294 @code{[ @var{token} ] "+" @var{async-output}}
23295
23296 @item @var{notify-async-output} @expansion{}
23297 @code{[ @var{token} ] "=" @var{async-output}}
23298
23299 @item @var{async-output} @expansion{}
23300 @code{@var{async-class} ( "," @var{result} )* @var{nl}}
23301
23302 @item @var{result-class} @expansion{}
23303 @code{"done" | "running" | "connected" | "error" | "exit"}
23304
23305 @item @var{async-class} @expansion{}
23306 @code{"stopped" | @var{others}} (where @var{others} will be added
23307 depending on the needs---this is still in development).
23308
23309 @item @var{result} @expansion{}
23310 @code{ @var{variable} "=" @var{value}}
23311
23312 @item @var{variable} @expansion{}
23313 @code{ @var{string} }
23314
23315 @item @var{value} @expansion{}
23316 @code{ @var{const} | @var{tuple} | @var{list} }
23317
23318 @item @var{const} @expansion{}
23319 @code{@var{c-string}}
23320
23321 @item @var{tuple} @expansion{}
23322 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
23323
23324 @item @var{list} @expansion{}
23325 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
23326 @var{result} ( "," @var{result} )* "]" }
23327
23328 @item @var{stream-record} @expansion{}
23329 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
23330
23331 @item @var{console-stream-output} @expansion{}
23332 @code{"~" @var{c-string}}
23333
23334 @item @var{target-stream-output} @expansion{}
23335 @code{"@@" @var{c-string}}
23336
23337 @item @var{log-stream-output} @expansion{}
23338 @code{"&" @var{c-string}}
23339
23340 @item @var{nl} @expansion{}
23341 @code{CR | CR-LF}
23342
23343 @item @var{token} @expansion{}
23344 @emph{any sequence of digits}.
23345 @end table
23346
23347 @noindent
23348 Notes:
23349
23350 @itemize @bullet
23351 @item
23352 All output sequences end in a single line containing a period.
23353
23354 @item
23355 The @code{@var{token}} is from the corresponding request. Note that
23356 for all async output, while the token is allowed by the grammar and
23357 may be output by future versions of @value{GDBN} for select async
23358 output messages, it is generally omitted. Frontends should treat
23359 all async output as reporting general changes in the state of the
23360 target and there should be no need to associate async output to any
23361 prior command.
23362
23363 @item
23364 @cindex status output in @sc{gdb/mi}
23365 @var{status-async-output} contains on-going status information about the
23366 progress of a slow operation. It can be discarded. All status output is
23367 prefixed by @samp{+}.
23368
23369 @item
23370 @cindex async output in @sc{gdb/mi}
23371 @var{exec-async-output} contains asynchronous state change on the target
23372 (stopped, started, disappeared). All async output is prefixed by
23373 @samp{*}.
23374
23375 @item
23376 @cindex notify output in @sc{gdb/mi}
23377 @var{notify-async-output} contains supplementary information that the
23378 client should handle (e.g., a new breakpoint information). All notify
23379 output is prefixed by @samp{=}.
23380
23381 @item
23382 @cindex console output in @sc{gdb/mi}
23383 @var{console-stream-output} is output that should be displayed as is in the
23384 console. It is the textual response to a CLI command. All the console
23385 output is prefixed by @samp{~}.
23386
23387 @item
23388 @cindex target output in @sc{gdb/mi}
23389 @var{target-stream-output} is the output produced by the target program.
23390 All the target output is prefixed by @samp{@@}.
23391
23392 @item
23393 @cindex log output in @sc{gdb/mi}
23394 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
23395 instance messages that should be displayed as part of an error log. All
23396 the log output is prefixed by @samp{&}.
23397
23398 @item
23399 @cindex list output in @sc{gdb/mi}
23400 New @sc{gdb/mi} commands should only output @var{lists} containing
23401 @var{values}.
23402
23403
23404 @end itemize
23405
23406 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
23407 details about the various output records.
23408
23409 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23410 @node GDB/MI Compatibility with CLI
23411 @section @sc{gdb/mi} Compatibility with CLI
23412
23413 @cindex compatibility, @sc{gdb/mi} and CLI
23414 @cindex @sc{gdb/mi}, compatibility with CLI
23415
23416 For the developers convenience CLI commands can be entered directly,
23417 but there may be some unexpected behaviour. For example, commands
23418 that query the user will behave as if the user replied yes, breakpoint
23419 command lists are not executed and some CLI commands, such as
23420 @code{if}, @code{when} and @code{define}, prompt for further input with
23421 @samp{>}, which is not valid MI output.
23422
23423 This feature may be removed at some stage in the future and it is
23424 recommended that front ends use the @code{-interpreter-exec} command
23425 (@pxref{-interpreter-exec}).
23426
23427 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23428 @node GDB/MI Development and Front Ends
23429 @section @sc{gdb/mi} Development and Front Ends
23430 @cindex @sc{gdb/mi} development
23431
23432 The application which takes the MI output and presents the state of the
23433 program being debugged to the user is called a @dfn{front end}.
23434
23435 Although @sc{gdb/mi} is still incomplete, it is currently being used
23436 by a variety of front ends to @value{GDBN}. This makes it difficult
23437 to introduce new functionality without breaking existing usage. This
23438 section tries to minimize the problems by describing how the protocol
23439 might change.
23440
23441 Some changes in MI need not break a carefully designed front end, and
23442 for these the MI version will remain unchanged. The following is a
23443 list of changes that may occur within one level, so front ends should
23444 parse MI output in a way that can handle them:
23445
23446 @itemize @bullet
23447 @item
23448 New MI commands may be added.
23449
23450 @item
23451 New fields may be added to the output of any MI command.
23452
23453 @item
23454 The range of values for fields with specified values, e.g.,
23455 @code{in_scope} (@pxref{-var-update}) may be extended.
23456
23457 @c The format of field's content e.g type prefix, may change so parse it
23458 @c at your own risk. Yes, in general?
23459
23460 @c The order of fields may change? Shouldn't really matter but it might
23461 @c resolve inconsistencies.
23462 @end itemize
23463
23464 If the changes are likely to break front ends, the MI version level
23465 will be increased by one. This will allow the front end to parse the
23466 output according to the MI version. Apart from mi0, new versions of
23467 @value{GDBN} will not support old versions of MI and it will be the
23468 responsibility of the front end to work with the new one.
23469
23470 @c Starting with mi3, add a new command -mi-version that prints the MI
23471 @c version?
23472
23473 The best way to avoid unexpected changes in MI that might break your front
23474 end is to make your project known to @value{GDBN} developers and
23475 follow development on @email{gdb@@sourceware.org} and
23476 @email{gdb-patches@@sourceware.org}.
23477 @cindex mailing lists
23478
23479 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23480 @node GDB/MI Output Records
23481 @section @sc{gdb/mi} Output Records
23482
23483 @menu
23484 * GDB/MI Result Records::
23485 * GDB/MI Stream Records::
23486 * GDB/MI Async Records::
23487 * GDB/MI Frame Information::
23488 * GDB/MI Thread Information::
23489 @end menu
23490
23491 @node GDB/MI Result Records
23492 @subsection @sc{gdb/mi} Result Records
23493
23494 @cindex result records in @sc{gdb/mi}
23495 @cindex @sc{gdb/mi}, result records
23496 In addition to a number of out-of-band notifications, the response to a
23497 @sc{gdb/mi} command includes one of the following result indications:
23498
23499 @table @code
23500 @findex ^done
23501 @item "^done" [ "," @var{results} ]
23502 The synchronous operation was successful, @code{@var{results}} are the return
23503 values.
23504
23505 @item "^running"
23506 @findex ^running
23507 This result record is equivalent to @samp{^done}. Historically, it
23508 was output instead of @samp{^done} if the command has resumed the
23509 target. This behaviour is maintained for backward compatibility, but
23510 all frontends should treat @samp{^done} and @samp{^running}
23511 identically and rely on the @samp{*running} output record to determine
23512 which threads are resumed.
23513
23514 @item "^connected"
23515 @findex ^connected
23516 @value{GDBN} has connected to a remote target.
23517
23518 @item "^error" "," @var{c-string}
23519 @findex ^error
23520 The operation failed. The @code{@var{c-string}} contains the corresponding
23521 error message.
23522
23523 @item "^exit"
23524 @findex ^exit
23525 @value{GDBN} has terminated.
23526
23527 @end table
23528
23529 @node GDB/MI Stream Records
23530 @subsection @sc{gdb/mi} Stream Records
23531
23532 @cindex @sc{gdb/mi}, stream records
23533 @cindex stream records in @sc{gdb/mi}
23534 @value{GDBN} internally maintains a number of output streams: the console, the
23535 target, and the log. The output intended for each of these streams is
23536 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
23537
23538 Each stream record begins with a unique @dfn{prefix character} which
23539 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
23540 Syntax}). In addition to the prefix, each stream record contains a
23541 @code{@var{string-output}}. This is either raw text (with an implicit new
23542 line) or a quoted C string (which does not contain an implicit newline).
23543
23544 @table @code
23545 @item "~" @var{string-output}
23546 The console output stream contains text that should be displayed in the
23547 CLI console window. It contains the textual responses to CLI commands.
23548
23549 @item "@@" @var{string-output}
23550 The target output stream contains any textual output from the running
23551 target. This is only present when GDB's event loop is truly
23552 asynchronous, which is currently only the case for remote targets.
23553
23554 @item "&" @var{string-output}
23555 The log stream contains debugging messages being produced by @value{GDBN}'s
23556 internals.
23557 @end table
23558
23559 @node GDB/MI Async Records
23560 @subsection @sc{gdb/mi} Async Records
23561
23562 @cindex async records in @sc{gdb/mi}
23563 @cindex @sc{gdb/mi}, async records
23564 @dfn{Async} records are used to notify the @sc{gdb/mi} client of
23565 additional changes that have occurred. Those changes can either be a
23566 consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
23567 target activity (e.g., target stopped).
23568
23569 The following is the list of possible async records:
23570
23571 @table @code
23572
23573 @item *running,thread-id="@var{thread}"
23574 The target is now running. The @var{thread} field tells which
23575 specific thread is now running, and can be @samp{all} if all threads
23576 are running. The frontend should assume that no interaction with a
23577 running thread is possible after this notification is produced.
23578 The frontend should not assume that this notification is output
23579 only once for any command. @value{GDBN} may emit this notification
23580 several times, either for different threads, because it cannot resume
23581 all threads together, or even for a single thread, if the thread must
23582 be stepped though some code before letting it run freely.
23583
23584 @item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
23585 The target has stopped. The @var{reason} field can have one of the
23586 following values:
23587
23588 @table @code
23589 @item breakpoint-hit
23590 A breakpoint was reached.
23591 @item watchpoint-trigger
23592 A watchpoint was triggered.
23593 @item read-watchpoint-trigger
23594 A read watchpoint was triggered.
23595 @item access-watchpoint-trigger
23596 An access watchpoint was triggered.
23597 @item function-finished
23598 An -exec-finish or similar CLI command was accomplished.
23599 @item location-reached
23600 An -exec-until or similar CLI command was accomplished.
23601 @item watchpoint-scope
23602 A watchpoint has gone out of scope.
23603 @item end-stepping-range
23604 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
23605 similar CLI command was accomplished.
23606 @item exited-signalled
23607 The inferior exited because of a signal.
23608 @item exited
23609 The inferior exited.
23610 @item exited-normally
23611 The inferior exited normally.
23612 @item signal-received
23613 A signal was received by the inferior.
23614 @end table
23615
23616 The @var{id} field identifies the thread that directly caused the stop
23617 -- for example by hitting a breakpoint. Depending on whether all-stop
23618 mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
23619 stop all threads, or only the thread that directly triggered the stop.
23620 If all threads are stopped, the @var{stopped} field will have the
23621 value of @code{"all"}. Otherwise, the value of the @var{stopped}
23622 field will be a list of thread identifiers. Presently, this list will
23623 always include a single thread, but frontend should be prepared to see
23624 several threads in the list. The @var{core} field reports the
23625 processor core on which the stop event has happened. This field may be absent
23626 if such information is not available.
23627
23628 @item =thread-group-added,id="@var{id}"
23629 @itemx =thread-group-removed,id="@var{id}"
23630 A thread group was either added or removed. The @var{id} field
23631 contains the @value{GDBN} identifier of the thread group. When a thread
23632 group is added, it generally might not be associated with a running
23633 process. When a thread group is removed, its id becomes invalid and
23634 cannot be used in any way.
23635
23636 @item =thread-group-started,id="@var{id}",pid="@var{pid}"
23637 A thread group became associated with a running program,
23638 either because the program was just started or the thread group
23639 was attached to a program. The @var{id} field contains the
23640 @value{GDBN} identifier of the thread group. The @var{pid} field
23641 contains process identifier, specific to the operating system.
23642
23643 @itemx =thread-group-exited,id="@var{id}"
23644 A thread group is no longer associated with a running program,
23645 either because the program has exited, or because it was detached
23646 from. The @var{id} field contains the @value{GDBN} identifier of the
23647 thread group.
23648
23649 @item =thread-created,id="@var{id}",group-id="@var{gid}"
23650 @itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
23651 A thread either was created, or has exited. The @var{id} field
23652 contains the @value{GDBN} identifier of the thread. The @var{gid}
23653 field identifies the thread group this thread belongs to.
23654
23655 @item =thread-selected,id="@var{id}"
23656 Informs that the selected thread was changed as result of the last
23657 command. This notification is not emitted as result of @code{-thread-select}
23658 command but is emitted whenever an MI command that is not documented
23659 to change the selected thread actually changes it. In particular,
23660 invoking, directly or indirectly (via user-defined command), the CLI
23661 @code{thread} command, will generate this notification.
23662
23663 We suggest that in response to this notification, front ends
23664 highlight the selected thread and cause subsequent commands to apply to
23665 that thread.
23666
23667 @item =library-loaded,...
23668 Reports that a new library file was loaded by the program. This
23669 notification has 4 fields---@var{id}, @var{target-name},
23670 @var{host-name}, and @var{symbols-loaded}. The @var{id} field is an
23671 opaque identifier of the library. For remote debugging case,
23672 @var{target-name} and @var{host-name} fields give the name of the
23673 library file on the target, and on the host respectively. For native
23674 debugging, both those fields have the same value. The
23675 @var{symbols-loaded} field reports if the debug symbols for this
23676 library are loaded. The @var{thread-group} field, if present,
23677 specifies the id of the thread group in whose context the library was loaded.
23678 If the field is absent, it means the library was loaded in the context
23679 of all present thread groups.
23680
23681 @item =library-unloaded,...
23682 Reports that a library was unloaded by the program. This notification
23683 has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
23684 the same meaning as for the @code{=library-loaded} notification.
23685 The @var{thread-group} field, if present, specifies the id of the
23686 thread group in whose context the library was unloaded. If the field is
23687 absent, it means the library was unloaded in the context of all present
23688 thread groups.
23689
23690 @end table
23691
23692 @node GDB/MI Frame Information
23693 @subsection @sc{gdb/mi} Frame Information
23694
23695 Response from many MI commands includes an information about stack
23696 frame. This information is a tuple that may have the following
23697 fields:
23698
23699 @table @code
23700 @item level
23701 The level of the stack frame. The innermost frame has the level of
23702 zero. This field is always present.
23703
23704 @item func
23705 The name of the function corresponding to the frame. This field may
23706 be absent if @value{GDBN} is unable to determine the function name.
23707
23708 @item addr
23709 The code address for the frame. This field is always present.
23710
23711 @item file
23712 The name of the source files that correspond to the frame's code
23713 address. This field may be absent.
23714
23715 @item line
23716 The source line corresponding to the frames' code address. This field
23717 may be absent.
23718
23719 @item from
23720 The name of the binary file (either executable or shared library) the
23721 corresponds to the frame's code address. This field may be absent.
23722
23723 @end table
23724
23725 @node GDB/MI Thread Information
23726 @subsection @sc{gdb/mi} Thread Information
23727
23728 Whenever @value{GDBN} has to report an information about a thread, it
23729 uses a tuple with the following fields:
23730
23731 @table @code
23732 @item id
23733 The numeric id assigned to the thread by @value{GDBN}. This field is
23734 always present.
23735
23736 @item target-id
23737 Target-specific string identifying the thread. This field is always present.
23738
23739 @item details
23740 Additional information about the thread provided by the target.
23741 It is supposed to be human-readable and not interpreted by the
23742 frontend. This field is optional.
23743
23744 @item state
23745 Either @samp{stopped} or @samp{running}, depending on whether the
23746 thread is presently running. This field is always present.
23747
23748 @item core
23749 The value of this field is an integer number of the processor core the
23750 thread was last seen on. This field is optional.
23751 @end table
23752
23753
23754 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23755 @node GDB/MI Simple Examples
23756 @section Simple Examples of @sc{gdb/mi} Interaction
23757 @cindex @sc{gdb/mi}, simple examples
23758
23759 This subsection presents several simple examples of interaction using
23760 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
23761 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
23762 the output received from @sc{gdb/mi}.
23763
23764 Note the line breaks shown in the examples are here only for
23765 readability, they don't appear in the real output.
23766
23767 @subheading Setting a Breakpoint
23768
23769 Setting a breakpoint generates synchronous output which contains detailed
23770 information of the breakpoint.
23771
23772 @smallexample
23773 -> -break-insert main
23774 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
23775 enabled="y",addr="0x08048564",func="main",file="myprog.c",
23776 fullname="/home/nickrob/myprog.c",line="68",times="0"@}
23777 <- (gdb)
23778 @end smallexample
23779
23780 @subheading Program Execution
23781
23782 Program execution generates asynchronous records and MI gives the
23783 reason that execution stopped.
23784
23785 @smallexample
23786 -> -exec-run
23787 <- ^running
23788 <- (gdb)
23789 <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
23790 frame=@{addr="0x08048564",func="main",
23791 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
23792 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
23793 <- (gdb)
23794 -> -exec-continue
23795 <- ^running
23796 <- (gdb)
23797 <- *stopped,reason="exited-normally"
23798 <- (gdb)
23799 @end smallexample
23800
23801 @subheading Quitting @value{GDBN}
23802
23803 Quitting @value{GDBN} just prints the result class @samp{^exit}.
23804
23805 @smallexample
23806 -> (gdb)
23807 <- -gdb-exit
23808 <- ^exit
23809 @end smallexample
23810
23811 Please note that @samp{^exit} is printed immediately, but it might
23812 take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
23813 performs necessary cleanups, including killing programs being debugged
23814 or disconnecting from debug hardware, so the frontend should wait till
23815 @value{GDBN} exits and should only forcibly kill @value{GDBN} if it
23816 fails to exit in reasonable time.
23817
23818 @subheading A Bad Command
23819
23820 Here's what happens if you pass a non-existent command:
23821
23822 @smallexample
23823 -> -rubbish
23824 <- ^error,msg="Undefined MI command: rubbish"
23825 <- (gdb)
23826 @end smallexample
23827
23828
23829 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23830 @node GDB/MI Command Description Format
23831 @section @sc{gdb/mi} Command Description Format
23832
23833 The remaining sections describe blocks of commands. Each block of
23834 commands is laid out in a fashion similar to this section.
23835
23836 @subheading Motivation
23837
23838 The motivation for this collection of commands.
23839
23840 @subheading Introduction
23841
23842 A brief introduction to this collection of commands as a whole.
23843
23844 @subheading Commands
23845
23846 For each command in the block, the following is described:
23847
23848 @subsubheading Synopsis
23849
23850 @smallexample
23851 -command @var{args}@dots{}
23852 @end smallexample
23853
23854 @subsubheading Result
23855
23856 @subsubheading @value{GDBN} Command
23857
23858 The corresponding @value{GDBN} CLI command(s), if any.
23859
23860 @subsubheading Example
23861
23862 Example(s) formatted for readability. Some of the described commands have
23863 not been implemented yet and these are labeled N.A.@: (not available).
23864
23865
23866 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23867 @node GDB/MI Breakpoint Commands
23868 @section @sc{gdb/mi} Breakpoint Commands
23869
23870 @cindex breakpoint commands for @sc{gdb/mi}
23871 @cindex @sc{gdb/mi}, breakpoint commands
23872 This section documents @sc{gdb/mi} commands for manipulating
23873 breakpoints.
23874
23875 @subheading The @code{-break-after} Command
23876 @findex -break-after
23877
23878 @subsubheading Synopsis
23879
23880 @smallexample
23881 -break-after @var{number} @var{count}
23882 @end smallexample
23883
23884 The breakpoint number @var{number} is not in effect until it has been
23885 hit @var{count} times. To see how this is reflected in the output of
23886 the @samp{-break-list} command, see the description of the
23887 @samp{-break-list} command below.
23888
23889 @subsubheading @value{GDBN} Command
23890
23891 The corresponding @value{GDBN} command is @samp{ignore}.
23892
23893 @subsubheading Example
23894
23895 @smallexample
23896 (gdb)
23897 -break-insert main
23898 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
23899 enabled="y",addr="0x000100d0",func="main",file="hello.c",
23900 fullname="/home/foo/hello.c",line="5",times="0"@}
23901 (gdb)
23902 -break-after 1 3
23903 ~
23904 ^done
23905 (gdb)
23906 -break-list
23907 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
23908 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
23909 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
23910 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
23911 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
23912 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
23913 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
23914 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
23915 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
23916 line="5",times="0",ignore="3"@}]@}
23917 (gdb)
23918 @end smallexample
23919
23920 @ignore
23921 @subheading The @code{-break-catch} Command
23922 @findex -break-catch
23923 @end ignore
23924
23925 @subheading The @code{-break-commands} Command
23926 @findex -break-commands
23927
23928 @subsubheading Synopsis
23929
23930 @smallexample
23931 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
23932 @end smallexample
23933
23934 Specifies the CLI commands that should be executed when breakpoint
23935 @var{number} is hit. The parameters @var{command1} to @var{commandN}
23936 are the commands. If no command is specified, any previously-set
23937 commands are cleared. @xref{Break Commands}. Typical use of this
23938 functionality is tracing a program, that is, printing of values of
23939 some variables whenever breakpoint is hit and then continuing.
23940
23941 @subsubheading @value{GDBN} Command
23942
23943 The corresponding @value{GDBN} command is @samp{commands}.
23944
23945 @subsubheading Example
23946
23947 @smallexample
23948 (gdb)
23949 -break-insert main
23950 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
23951 enabled="y",addr="0x000100d0",func="main",file="hello.c",
23952 fullname="/home/foo/hello.c",line="5",times="0"@}
23953 (gdb)
23954 -break-commands 1 "print v" "continue"
23955 ^done
23956 (gdb)
23957 @end smallexample
23958
23959 @subheading The @code{-break-condition} Command
23960 @findex -break-condition
23961
23962 @subsubheading Synopsis
23963
23964 @smallexample
23965 -break-condition @var{number} @var{expr}
23966 @end smallexample
23967
23968 Breakpoint @var{number} will stop the program only if the condition in
23969 @var{expr} is true. The condition becomes part of the
23970 @samp{-break-list} output (see the description of the @samp{-break-list}
23971 command below).
23972
23973 @subsubheading @value{GDBN} Command
23974
23975 The corresponding @value{GDBN} command is @samp{condition}.
23976
23977 @subsubheading Example
23978
23979 @smallexample
23980 (gdb)
23981 -break-condition 1 1
23982 ^done
23983 (gdb)
23984 -break-list
23985 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
23986 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
23987 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
23988 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
23989 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
23990 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
23991 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
23992 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
23993 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
23994 line="5",cond="1",times="0",ignore="3"@}]@}
23995 (gdb)
23996 @end smallexample
23997
23998 @subheading The @code{-break-delete} Command
23999 @findex -break-delete
24000
24001 @subsubheading Synopsis
24002
24003 @smallexample
24004 -break-delete ( @var{breakpoint} )+
24005 @end smallexample
24006
24007 Delete the breakpoint(s) whose number(s) are specified in the argument
24008 list. This is obviously reflected in the breakpoint list.
24009
24010 @subsubheading @value{GDBN} Command
24011
24012 The corresponding @value{GDBN} command is @samp{delete}.
24013
24014 @subsubheading Example
24015
24016 @smallexample
24017 (gdb)
24018 -break-delete 1
24019 ^done
24020 (gdb)
24021 -break-list
24022 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
24023 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
24024 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
24025 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
24026 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
24027 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
24028 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
24029 body=[]@}
24030 (gdb)
24031 @end smallexample
24032
24033 @subheading The @code{-break-disable} Command
24034 @findex -break-disable
24035
24036 @subsubheading Synopsis
24037
24038 @smallexample
24039 -break-disable ( @var{breakpoint} )+
24040 @end smallexample
24041
24042 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
24043 break list is now set to @samp{n} for the named @var{breakpoint}(s).
24044
24045 @subsubheading @value{GDBN} Command
24046
24047 The corresponding @value{GDBN} command is @samp{disable}.
24048
24049 @subsubheading Example
24050
24051 @smallexample
24052 (gdb)
24053 -break-disable 2
24054 ^done
24055 (gdb)
24056 -break-list
24057 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
24058 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
24059 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
24060 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
24061 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
24062 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
24063 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
24064 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
24065 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
24066 line="5",times="0"@}]@}
24067 (gdb)
24068 @end smallexample
24069
24070 @subheading The @code{-break-enable} Command
24071 @findex -break-enable
24072
24073 @subsubheading Synopsis
24074
24075 @smallexample
24076 -break-enable ( @var{breakpoint} )+
24077 @end smallexample
24078
24079 Enable (previously disabled) @var{breakpoint}(s).
24080
24081 @subsubheading @value{GDBN} Command
24082
24083 The corresponding @value{GDBN} command is @samp{enable}.
24084
24085 @subsubheading Example
24086
24087 @smallexample
24088 (gdb)
24089 -break-enable 2
24090 ^done
24091 (gdb)
24092 -break-list
24093 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
24094 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
24095 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
24096 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
24097 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
24098 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
24099 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
24100 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
24101 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
24102 line="5",times="0"@}]@}
24103 (gdb)
24104 @end smallexample
24105
24106 @subheading The @code{-break-info} Command
24107 @findex -break-info
24108
24109 @subsubheading Synopsis
24110
24111 @smallexample
24112 -break-info @var{breakpoint}
24113 @end smallexample
24114
24115 @c REDUNDANT???
24116 Get information about a single breakpoint.
24117
24118 @subsubheading @value{GDBN} Command
24119
24120 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
24121
24122 @subsubheading Example
24123 N.A.
24124
24125 @subheading The @code{-break-insert} Command
24126 @findex -break-insert
24127
24128 @subsubheading Synopsis
24129
24130 @smallexample
24131 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
24132 [ -c @var{condition} ] [ -i @var{ignore-count} ]
24133 [ -p @var{thread} ] [ @var{location} ]
24134 @end smallexample
24135
24136 @noindent
24137 If specified, @var{location}, can be one of:
24138
24139 @itemize @bullet
24140 @item function
24141 @c @item +offset
24142 @c @item -offset
24143 @c @item linenum
24144 @item filename:linenum
24145 @item filename:function
24146 @item *address
24147 @end itemize
24148
24149 The possible optional parameters of this command are:
24150
24151 @table @samp
24152 @item -t
24153 Insert a temporary breakpoint.
24154 @item -h
24155 Insert a hardware breakpoint.
24156 @item -c @var{condition}
24157 Make the breakpoint conditional on @var{condition}.
24158 @item -i @var{ignore-count}
24159 Initialize the @var{ignore-count}.
24160 @item -f
24161 If @var{location} cannot be parsed (for example if it
24162 refers to unknown files or functions), create a pending
24163 breakpoint. Without this flag, @value{GDBN} will report
24164 an error, and won't create a breakpoint, if @var{location}
24165 cannot be parsed.
24166 @item -d
24167 Create a disabled breakpoint.
24168 @item -a
24169 Create a tracepoint. @xref{Tracepoints}. When this parameter
24170 is used together with @samp{-h}, a fast tracepoint is created.
24171 @end table
24172
24173 @subsubheading Result
24174
24175 The result is in the form:
24176
24177 @smallexample
24178 ^done,bkpt=@{number="@var{number}",type="@var{type}",disp="del"|"keep",
24179 enabled="y"|"n",addr="@var{hex}",func="@var{funcname}",file="@var{filename}",
24180 fullname="@var{full_filename}",line="@var{lineno}",[thread="@var{threadno},]
24181 times="@var{times}"@}
24182 @end smallexample
24183
24184 @noindent
24185 where @var{number} is the @value{GDBN} number for this breakpoint,
24186 @var{funcname} is the name of the function where the breakpoint was
24187 inserted, @var{filename} is the name of the source file which contains
24188 this function, @var{lineno} is the source line number within that file
24189 and @var{times} the number of times that the breakpoint has been hit
24190 (always 0 for -break-insert but may be greater for -break-info or -break-list
24191 which use the same output).
24192
24193 Note: this format is open to change.
24194 @c An out-of-band breakpoint instead of part of the result?
24195
24196 @subsubheading @value{GDBN} Command
24197
24198 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
24199 @samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
24200
24201 @subsubheading Example
24202
24203 @smallexample
24204 (gdb)
24205 -break-insert main
24206 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
24207 fullname="/home/foo/recursive2.c,line="4",times="0"@}
24208 (gdb)
24209 -break-insert -t foo
24210 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
24211 fullname="/home/foo/recursive2.c,line="11",times="0"@}
24212 (gdb)
24213 -break-list
24214 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
24215 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
24216 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
24217 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
24218 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
24219 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
24220 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
24221 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
24222 addr="0x0001072c", func="main",file="recursive2.c",
24223 fullname="/home/foo/recursive2.c,"line="4",times="0"@},
24224 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
24225 addr="0x00010774",func="foo",file="recursive2.c",
24226 fullname="/home/foo/recursive2.c",line="11",times="0"@}]@}
24227 (gdb)
24228 -break-insert -r foo.*
24229 ~int foo(int, int);
24230 ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
24231 "fullname="/home/foo/recursive2.c",line="11",times="0"@}
24232 (gdb)
24233 @end smallexample
24234
24235 @subheading The @code{-break-list} Command
24236 @findex -break-list
24237
24238 @subsubheading Synopsis
24239
24240 @smallexample
24241 -break-list
24242 @end smallexample
24243
24244 Displays the list of inserted breakpoints, showing the following fields:
24245
24246 @table @samp
24247 @item Number
24248 number of the breakpoint
24249 @item Type
24250 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
24251 @item Disposition
24252 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
24253 or @samp{nokeep}
24254 @item Enabled
24255 is the breakpoint enabled or no: @samp{y} or @samp{n}
24256 @item Address
24257 memory location at which the breakpoint is set
24258 @item What
24259 logical location of the breakpoint, expressed by function name, file
24260 name, line number
24261 @item Times
24262 number of times the breakpoint has been hit
24263 @end table
24264
24265 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
24266 @code{body} field is an empty list.
24267
24268 @subsubheading @value{GDBN} Command
24269
24270 The corresponding @value{GDBN} command is @samp{info break}.
24271
24272 @subsubheading Example
24273
24274 @smallexample
24275 (gdb)
24276 -break-list
24277 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
24278 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
24279 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
24280 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
24281 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
24282 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
24283 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
24284 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
24285 addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
24286 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
24287 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
24288 line="13",times="0"@}]@}
24289 (gdb)
24290 @end smallexample
24291
24292 Here's an example of the result when there are no breakpoints:
24293
24294 @smallexample
24295 (gdb)
24296 -break-list
24297 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
24298 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
24299 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
24300 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
24301 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
24302 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
24303 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
24304 body=[]@}
24305 (gdb)
24306 @end smallexample
24307
24308 @subheading The @code{-break-passcount} Command
24309 @findex -break-passcount
24310
24311 @subsubheading Synopsis
24312
24313 @smallexample
24314 -break-passcount @var{tracepoint-number} @var{passcount}
24315 @end smallexample
24316
24317 Set the passcount for tracepoint @var{tracepoint-number} to
24318 @var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
24319 is not a tracepoint, error is emitted. This corresponds to CLI
24320 command @samp{passcount}.
24321
24322 @subheading The @code{-break-watch} Command
24323 @findex -break-watch
24324
24325 @subsubheading Synopsis
24326
24327 @smallexample
24328 -break-watch [ -a | -r ]
24329 @end smallexample
24330
24331 Create a watchpoint. With the @samp{-a} option it will create an
24332 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
24333 read from or on a write to the memory location. With the @samp{-r}
24334 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
24335 trigger only when the memory location is accessed for reading. Without
24336 either of the options, the watchpoint created is a regular watchpoint,
24337 i.e., it will trigger when the memory location is accessed for writing.
24338 @xref{Set Watchpoints, , Setting Watchpoints}.
24339
24340 Note that @samp{-break-list} will report a single list of watchpoints and
24341 breakpoints inserted.
24342
24343 @subsubheading @value{GDBN} Command
24344
24345 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
24346 @samp{rwatch}.
24347
24348 @subsubheading Example
24349
24350 Setting a watchpoint on a variable in the @code{main} function:
24351
24352 @smallexample
24353 (gdb)
24354 -break-watch x
24355 ^done,wpt=@{number="2",exp="x"@}
24356 (gdb)
24357 -exec-continue
24358 ^running
24359 (gdb)
24360 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
24361 value=@{old="-268439212",new="55"@},
24362 frame=@{func="main",args=[],file="recursive2.c",
24363 fullname="/home/foo/bar/recursive2.c",line="5"@}
24364 (gdb)
24365 @end smallexample
24366
24367 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
24368 the program execution twice: first for the variable changing value, then
24369 for the watchpoint going out of scope.
24370
24371 @smallexample
24372 (gdb)
24373 -break-watch C
24374 ^done,wpt=@{number="5",exp="C"@}
24375 (gdb)
24376 -exec-continue
24377 ^running
24378 (gdb)
24379 *stopped,reason="watchpoint-trigger",
24380 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
24381 frame=@{func="callee4",args=[],
24382 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
24383 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
24384 (gdb)
24385 -exec-continue
24386 ^running
24387 (gdb)
24388 *stopped,reason="watchpoint-scope",wpnum="5",
24389 frame=@{func="callee3",args=[@{name="strarg",
24390 value="0x11940 \"A string argument.\""@}],
24391 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
24392 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
24393 (gdb)
24394 @end smallexample
24395
24396 Listing breakpoints and watchpoints, at different points in the program
24397 execution. Note that once the watchpoint goes out of scope, it is
24398 deleted.
24399
24400 @smallexample
24401 (gdb)
24402 -break-watch C
24403 ^done,wpt=@{number="2",exp="C"@}
24404 (gdb)
24405 -break-list
24406 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
24407 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
24408 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
24409 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
24410 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
24411 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
24412 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
24413 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
24414 addr="0x00010734",func="callee4",
24415 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
24416 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",times="1"@},
24417 bkpt=@{number="2",type="watchpoint",disp="keep",
24418 enabled="y",addr="",what="C",times="0"@}]@}
24419 (gdb)
24420 -exec-continue
24421 ^running
24422 (gdb)
24423 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
24424 value=@{old="-276895068",new="3"@},
24425 frame=@{func="callee4",args=[],
24426 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
24427 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
24428 (gdb)
24429 -break-list
24430 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
24431 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
24432 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
24433 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
24434 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
24435 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
24436 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
24437 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
24438 addr="0x00010734",func="callee4",
24439 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
24440 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
24441 bkpt=@{number="2",type="watchpoint",disp="keep",
24442 enabled="y",addr="",what="C",times="-5"@}]@}
24443 (gdb)
24444 -exec-continue
24445 ^running
24446 ^done,reason="watchpoint-scope",wpnum="2",
24447 frame=@{func="callee3",args=[@{name="strarg",
24448 value="0x11940 \"A string argument.\""@}],
24449 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
24450 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
24451 (gdb)
24452 -break-list
24453 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
24454 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
24455 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
24456 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
24457 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
24458 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
24459 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
24460 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
24461 addr="0x00010734",func="callee4",
24462 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
24463 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
24464 times="1"@}]@}
24465 (gdb)
24466 @end smallexample
24467
24468 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24469 @node GDB/MI Program Context
24470 @section @sc{gdb/mi} Program Context
24471
24472 @subheading The @code{-exec-arguments} Command
24473 @findex -exec-arguments
24474
24475
24476 @subsubheading Synopsis
24477
24478 @smallexample
24479 -exec-arguments @var{args}
24480 @end smallexample
24481
24482 Set the inferior program arguments, to be used in the next
24483 @samp{-exec-run}.
24484
24485 @subsubheading @value{GDBN} Command
24486
24487 The corresponding @value{GDBN} command is @samp{set args}.
24488
24489 @subsubheading Example
24490
24491 @smallexample
24492 (gdb)
24493 -exec-arguments -v word
24494 ^done
24495 (gdb)
24496 @end smallexample
24497
24498
24499 @ignore
24500 @subheading The @code{-exec-show-arguments} Command
24501 @findex -exec-show-arguments
24502
24503 @subsubheading Synopsis
24504
24505 @smallexample
24506 -exec-show-arguments
24507 @end smallexample
24508
24509 Print the arguments of the program.
24510
24511 @subsubheading @value{GDBN} Command
24512
24513 The corresponding @value{GDBN} command is @samp{show args}.
24514
24515 @subsubheading Example
24516 N.A.
24517 @end ignore
24518
24519
24520 @subheading The @code{-environment-cd} Command
24521 @findex -environment-cd
24522
24523 @subsubheading Synopsis
24524
24525 @smallexample
24526 -environment-cd @var{pathdir}
24527 @end smallexample
24528
24529 Set @value{GDBN}'s working directory.
24530
24531 @subsubheading @value{GDBN} Command
24532
24533 The corresponding @value{GDBN} command is @samp{cd}.
24534
24535 @subsubheading Example
24536
24537 @smallexample
24538 (gdb)
24539 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
24540 ^done
24541 (gdb)
24542 @end smallexample
24543
24544
24545 @subheading The @code{-environment-directory} Command
24546 @findex -environment-directory
24547
24548 @subsubheading Synopsis
24549
24550 @smallexample
24551 -environment-directory [ -r ] [ @var{pathdir} ]+
24552 @end smallexample
24553
24554 Add directories @var{pathdir} to beginning of search path for source files.
24555 If the @samp{-r} option is used, the search path is reset to the default
24556 search path. If directories @var{pathdir} are supplied in addition to the
24557 @samp{-r} option, the search path is first reset and then addition
24558 occurs as normal.
24559 Multiple directories may be specified, separated by blanks. Specifying
24560 multiple directories in a single command
24561 results in the directories added to the beginning of the
24562 search path in the same order they were presented in the command.
24563 If blanks are needed as
24564 part of a directory name, double-quotes should be used around
24565 the name. In the command output, the path will show up separated
24566 by the system directory-separator character. The directory-separator
24567 character must not be used
24568 in any directory name.
24569 If no directories are specified, the current search path is displayed.
24570
24571 @subsubheading @value{GDBN} Command
24572
24573 The corresponding @value{GDBN} command is @samp{dir}.
24574
24575 @subsubheading Example
24576
24577 @smallexample
24578 (gdb)
24579 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
24580 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
24581 (gdb)
24582 -environment-directory ""
24583 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
24584 (gdb)
24585 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
24586 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
24587 (gdb)
24588 -environment-directory -r
24589 ^done,source-path="$cdir:$cwd"
24590 (gdb)
24591 @end smallexample
24592
24593
24594 @subheading The @code{-environment-path} Command
24595 @findex -environment-path
24596
24597 @subsubheading Synopsis
24598
24599 @smallexample
24600 -environment-path [ -r ] [ @var{pathdir} ]+
24601 @end smallexample
24602
24603 Add directories @var{pathdir} to beginning of search path for object files.
24604 If the @samp{-r} option is used, the search path is reset to the original
24605 search path that existed at gdb start-up. If directories @var{pathdir} are
24606 supplied in addition to the
24607 @samp{-r} option, the search path is first reset and then addition
24608 occurs as normal.
24609 Multiple directories may be specified, separated by blanks. Specifying
24610 multiple directories in a single command
24611 results in the directories added to the beginning of the
24612 search path in the same order they were presented in the command.
24613 If blanks are needed as
24614 part of a directory name, double-quotes should be used around
24615 the name. In the command output, the path will show up separated
24616 by the system directory-separator character. The directory-separator
24617 character must not be used
24618 in any directory name.
24619 If no directories are specified, the current path is displayed.
24620
24621
24622 @subsubheading @value{GDBN} Command
24623
24624 The corresponding @value{GDBN} command is @samp{path}.
24625
24626 @subsubheading Example
24627
24628 @smallexample
24629 (gdb)
24630 -environment-path
24631 ^done,path="/usr/bin"
24632 (gdb)
24633 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
24634 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
24635 (gdb)
24636 -environment-path -r /usr/local/bin
24637 ^done,path="/usr/local/bin:/usr/bin"
24638 (gdb)
24639 @end smallexample
24640
24641
24642 @subheading The @code{-environment-pwd} Command
24643 @findex -environment-pwd
24644
24645 @subsubheading Synopsis
24646
24647 @smallexample
24648 -environment-pwd
24649 @end smallexample
24650
24651 Show the current working directory.
24652
24653 @subsubheading @value{GDBN} Command
24654
24655 The corresponding @value{GDBN} command is @samp{pwd}.
24656
24657 @subsubheading Example
24658
24659 @smallexample
24660 (gdb)
24661 -environment-pwd
24662 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
24663 (gdb)
24664 @end smallexample
24665
24666 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24667 @node GDB/MI Thread Commands
24668 @section @sc{gdb/mi} Thread Commands
24669
24670
24671 @subheading The @code{-thread-info} Command
24672 @findex -thread-info
24673
24674 @subsubheading Synopsis
24675
24676 @smallexample
24677 -thread-info [ @var{thread-id} ]
24678 @end smallexample
24679
24680 Reports information about either a specific thread, if
24681 the @var{thread-id} parameter is present, or about all
24682 threads. When printing information about all threads,
24683 also reports the current thread.
24684
24685 @subsubheading @value{GDBN} Command
24686
24687 The @samp{info thread} command prints the same information
24688 about all threads.
24689
24690 @subsubheading Example
24691
24692 @smallexample
24693 -thread-info
24694 ^done,threads=[
24695 @{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
24696 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
24697 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
24698 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
24699 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}],
24700 current-thread-id="1"
24701 (gdb)
24702 @end smallexample
24703
24704 The @samp{state} field may have the following values:
24705
24706 @table @code
24707 @item stopped
24708 The thread is stopped. Frame information is available for stopped
24709 threads.
24710
24711 @item running
24712 The thread is running. There's no frame information for running
24713 threads.
24714
24715 @end table
24716
24717 @subheading The @code{-thread-list-ids} Command
24718 @findex -thread-list-ids
24719
24720 @subsubheading Synopsis
24721
24722 @smallexample
24723 -thread-list-ids
24724 @end smallexample
24725
24726 Produces a list of the currently known @value{GDBN} thread ids. At the
24727 end of the list it also prints the total number of such threads.
24728
24729 This command is retained for historical reasons, the
24730 @code{-thread-info} command should be used instead.
24731
24732 @subsubheading @value{GDBN} Command
24733
24734 Part of @samp{info threads} supplies the same information.
24735
24736 @subsubheading Example
24737
24738 @smallexample
24739 (gdb)
24740 -thread-list-ids
24741 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
24742 current-thread-id="1",number-of-threads="3"
24743 (gdb)
24744 @end smallexample
24745
24746
24747 @subheading The @code{-thread-select} Command
24748 @findex -thread-select
24749
24750 @subsubheading Synopsis
24751
24752 @smallexample
24753 -thread-select @var{threadnum}
24754 @end smallexample
24755
24756 Make @var{threadnum} the current thread. It prints the number of the new
24757 current thread, and the topmost frame for that thread.
24758
24759 This command is deprecated in favor of explicitly using the
24760 @samp{--thread} option to each command.
24761
24762 @subsubheading @value{GDBN} Command
24763
24764 The corresponding @value{GDBN} command is @samp{thread}.
24765
24766 @subsubheading Example
24767
24768 @smallexample
24769 (gdb)
24770 -exec-next
24771 ^running
24772 (gdb)
24773 *stopped,reason="end-stepping-range",thread-id="2",line="187",
24774 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
24775 (gdb)
24776 -thread-list-ids
24777 ^done,
24778 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
24779 number-of-threads="3"
24780 (gdb)
24781 -thread-select 3
24782 ^done,new-thread-id="3",
24783 frame=@{level="0",func="vprintf",
24784 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
24785 @{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
24786 (gdb)
24787 @end smallexample
24788
24789 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24790 @node GDB/MI Program Execution
24791 @section @sc{gdb/mi} Program Execution
24792
24793 These are the asynchronous commands which generate the out-of-band
24794 record @samp{*stopped}. Currently @value{GDBN} only really executes
24795 asynchronously with remote targets and this interaction is mimicked in
24796 other cases.
24797
24798 @subheading The @code{-exec-continue} Command
24799 @findex -exec-continue
24800
24801 @subsubheading Synopsis
24802
24803 @smallexample
24804 -exec-continue [--reverse] [--all|--thread-group N]
24805 @end smallexample
24806
24807 Resumes the execution of the inferior program, which will continue
24808 to execute until it reaches a debugger stop event. If the
24809 @samp{--reverse} option is specified, execution resumes in reverse until
24810 it reaches a stop event. Stop events may include
24811 @itemize @bullet
24812 @item
24813 breakpoints or watchpoints
24814 @item
24815 signals or exceptions
24816 @item
24817 the end of the process (or its beginning under @samp{--reverse})
24818 @item
24819 the end or beginning of a replay log if one is being used.
24820 @end itemize
24821 In all-stop mode (@pxref{All-Stop
24822 Mode}), may resume only one thread, or all threads, depending on the
24823 value of the @samp{scheduler-locking} variable. If @samp{--all} is
24824 specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
24825 ignored in all-stop mode. If the @samp{--thread-group} options is
24826 specified, then all threads in that thread group are resumed.
24827
24828 @subsubheading @value{GDBN} Command
24829
24830 The corresponding @value{GDBN} corresponding is @samp{continue}.
24831
24832 @subsubheading Example
24833
24834 @smallexample
24835 -exec-continue
24836 ^running
24837 (gdb)
24838 @@Hello world
24839 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
24840 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
24841 line="13"@}
24842 (gdb)
24843 @end smallexample
24844
24845
24846 @subheading The @code{-exec-finish} Command
24847 @findex -exec-finish
24848
24849 @subsubheading Synopsis
24850
24851 @smallexample
24852 -exec-finish [--reverse]
24853 @end smallexample
24854
24855 Resumes the execution of the inferior program until the current
24856 function is exited. Displays the results returned by the function.
24857 If the @samp{--reverse} option is specified, resumes the reverse
24858 execution of the inferior program until the point where current
24859 function was called.
24860
24861 @subsubheading @value{GDBN} Command
24862
24863 The corresponding @value{GDBN} command is @samp{finish}.
24864
24865 @subsubheading Example
24866
24867 Function returning @code{void}.
24868
24869 @smallexample
24870 -exec-finish
24871 ^running
24872 (gdb)
24873 @@hello from foo
24874 *stopped,reason="function-finished",frame=@{func="main",args=[],
24875 file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
24876 (gdb)
24877 @end smallexample
24878
24879 Function returning other than @code{void}. The name of the internal
24880 @value{GDBN} variable storing the result is printed, together with the
24881 value itself.
24882
24883 @smallexample
24884 -exec-finish
24885 ^running
24886 (gdb)
24887 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
24888 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
24889 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
24890 gdb-result-var="$1",return-value="0"
24891 (gdb)
24892 @end smallexample
24893
24894
24895 @subheading The @code{-exec-interrupt} Command
24896 @findex -exec-interrupt
24897
24898 @subsubheading Synopsis
24899
24900 @smallexample
24901 -exec-interrupt [--all|--thread-group N]
24902 @end smallexample
24903
24904 Interrupts the background execution of the target. Note how the token
24905 associated with the stop message is the one for the execution command
24906 that has been interrupted. The token for the interrupt itself only
24907 appears in the @samp{^done} output. If the user is trying to
24908 interrupt a non-running program, an error message will be printed.
24909
24910 Note that when asynchronous execution is enabled, this command is
24911 asynchronous just like other execution commands. That is, first the
24912 @samp{^done} response will be printed, and the target stop will be
24913 reported after that using the @samp{*stopped} notification.
24914
24915 In non-stop mode, only the context thread is interrupted by default.
24916 All threads (in all inferiors) will be interrupted if the
24917 @samp{--all} option is specified. If the @samp{--thread-group}
24918 option is specified, all threads in that group will be interrupted.
24919
24920 @subsubheading @value{GDBN} Command
24921
24922 The corresponding @value{GDBN} command is @samp{interrupt}.
24923
24924 @subsubheading Example
24925
24926 @smallexample
24927 (gdb)
24928 111-exec-continue
24929 111^running
24930
24931 (gdb)
24932 222-exec-interrupt
24933 222^done
24934 (gdb)
24935 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
24936 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
24937 fullname="/home/foo/bar/try.c",line="13"@}
24938 (gdb)
24939
24940 (gdb)
24941 -exec-interrupt
24942 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
24943 (gdb)
24944 @end smallexample
24945
24946 @subheading The @code{-exec-jump} Command
24947 @findex -exec-jump
24948
24949 @subsubheading Synopsis
24950
24951 @smallexample
24952 -exec-jump @var{location}
24953 @end smallexample
24954
24955 Resumes execution of the inferior program at the location specified by
24956 parameter. @xref{Specify Location}, for a description of the
24957 different forms of @var{location}.
24958
24959 @subsubheading @value{GDBN} Command
24960
24961 The corresponding @value{GDBN} command is @samp{jump}.
24962
24963 @subsubheading Example
24964
24965 @smallexample
24966 -exec-jump foo.c:10
24967 *running,thread-id="all"
24968 ^running
24969 @end smallexample
24970
24971
24972 @subheading The @code{-exec-next} Command
24973 @findex -exec-next
24974
24975 @subsubheading Synopsis
24976
24977 @smallexample
24978 -exec-next [--reverse]
24979 @end smallexample
24980
24981 Resumes execution of the inferior program, stopping when the beginning
24982 of the next source line is reached.
24983
24984 If the @samp{--reverse} option is specified, resumes reverse execution
24985 of the inferior program, stopping at the beginning of the previous
24986 source line. If you issue this command on the first line of a
24987 function, it will take you back to the caller of that function, to the
24988 source line where the function was called.
24989
24990
24991 @subsubheading @value{GDBN} Command
24992
24993 The corresponding @value{GDBN} command is @samp{next}.
24994
24995 @subsubheading Example
24996
24997 @smallexample
24998 -exec-next
24999 ^running
25000 (gdb)
25001 *stopped,reason="end-stepping-range",line="8",file="hello.c"
25002 (gdb)
25003 @end smallexample
25004
25005
25006 @subheading The @code{-exec-next-instruction} Command
25007 @findex -exec-next-instruction
25008
25009 @subsubheading Synopsis
25010
25011 @smallexample
25012 -exec-next-instruction [--reverse]
25013 @end smallexample
25014
25015 Executes one machine instruction. If the instruction is a function
25016 call, continues until the function returns. If the program stops at an
25017 instruction in the middle of a source line, the address will be
25018 printed as well.
25019
25020 If the @samp{--reverse} option is specified, resumes reverse execution
25021 of the inferior program, stopping at the previous instruction. If the
25022 previously executed instruction was a return from another function,
25023 it will continue to execute in reverse until the call to that function
25024 (from the current stack frame) is reached.
25025
25026 @subsubheading @value{GDBN} Command
25027
25028 The corresponding @value{GDBN} command is @samp{nexti}.
25029
25030 @subsubheading Example
25031
25032 @smallexample
25033 (gdb)
25034 -exec-next-instruction
25035 ^running
25036
25037 (gdb)
25038 *stopped,reason="end-stepping-range",
25039 addr="0x000100d4",line="5",file="hello.c"
25040 (gdb)
25041 @end smallexample
25042
25043
25044 @subheading The @code{-exec-return} Command
25045 @findex -exec-return
25046
25047 @subsubheading Synopsis
25048
25049 @smallexample
25050 -exec-return
25051 @end smallexample
25052
25053 Makes current function return immediately. Doesn't execute the inferior.
25054 Displays the new current frame.
25055
25056 @subsubheading @value{GDBN} Command
25057
25058 The corresponding @value{GDBN} command is @samp{return}.
25059
25060 @subsubheading Example
25061
25062 @smallexample
25063 (gdb)
25064 200-break-insert callee4
25065 200^done,bkpt=@{number="1",addr="0x00010734",
25066 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
25067 (gdb)
25068 000-exec-run
25069 000^running
25070 (gdb)
25071 000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
25072 frame=@{func="callee4",args=[],
25073 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25074 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
25075 (gdb)
25076 205-break-delete
25077 205^done
25078 (gdb)
25079 111-exec-return
25080 111^done,frame=@{level="0",func="callee3",
25081 args=[@{name="strarg",
25082 value="0x11940 \"A string argument.\""@}],
25083 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25084 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
25085 (gdb)
25086 @end smallexample
25087
25088
25089 @subheading The @code{-exec-run} Command
25090 @findex -exec-run
25091
25092 @subsubheading Synopsis
25093
25094 @smallexample
25095 -exec-run [--all | --thread-group N]
25096 @end smallexample
25097
25098 Starts execution of the inferior from the beginning. The inferior
25099 executes until either a breakpoint is encountered or the program
25100 exits. In the latter case the output will include an exit code, if
25101 the program has exited exceptionally.
25102
25103 When no option is specified, the current inferior is started. If the
25104 @samp{--thread-group} option is specified, it should refer to a thread
25105 group of type @samp{process}, and that thread group will be started.
25106 If the @samp{--all} option is specified, then all inferiors will be started.
25107
25108 @subsubheading @value{GDBN} Command
25109
25110 The corresponding @value{GDBN} command is @samp{run}.
25111
25112 @subsubheading Examples
25113
25114 @smallexample
25115 (gdb)
25116 -break-insert main
25117 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
25118 (gdb)
25119 -exec-run
25120 ^running
25121 (gdb)
25122 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
25123 frame=@{func="main",args=[],file="recursive2.c",
25124 fullname="/home/foo/bar/recursive2.c",line="4"@}
25125 (gdb)
25126 @end smallexample
25127
25128 @noindent
25129 Program exited normally:
25130
25131 @smallexample
25132 (gdb)
25133 -exec-run
25134 ^running
25135 (gdb)
25136 x = 55
25137 *stopped,reason="exited-normally"
25138 (gdb)
25139 @end smallexample
25140
25141 @noindent
25142 Program exited exceptionally:
25143
25144 @smallexample
25145 (gdb)
25146 -exec-run
25147 ^running
25148 (gdb)
25149 x = 55
25150 *stopped,reason="exited",exit-code="01"
25151 (gdb)
25152 @end smallexample
25153
25154 Another way the program can terminate is if it receives a signal such as
25155 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
25156
25157 @smallexample
25158 (gdb)
25159 *stopped,reason="exited-signalled",signal-name="SIGINT",
25160 signal-meaning="Interrupt"
25161 @end smallexample
25162
25163
25164 @c @subheading -exec-signal
25165
25166
25167 @subheading The @code{-exec-step} Command
25168 @findex -exec-step
25169
25170 @subsubheading Synopsis
25171
25172 @smallexample
25173 -exec-step [--reverse]
25174 @end smallexample
25175
25176 Resumes execution of the inferior program, stopping when the beginning
25177 of the next source line is reached, if the next source line is not a
25178 function call. If it is, stop at the first instruction of the called
25179 function. If the @samp{--reverse} option is specified, resumes reverse
25180 execution of the inferior program, stopping at the beginning of the
25181 previously executed source line.
25182
25183 @subsubheading @value{GDBN} Command
25184
25185 The corresponding @value{GDBN} command is @samp{step}.
25186
25187 @subsubheading Example
25188
25189 Stepping into a function:
25190
25191 @smallexample
25192 -exec-step
25193 ^running
25194 (gdb)
25195 *stopped,reason="end-stepping-range",
25196 frame=@{func="foo",args=[@{name="a",value="10"@},
25197 @{name="b",value="0"@}],file="recursive2.c",
25198 fullname="/home/foo/bar/recursive2.c",line="11"@}
25199 (gdb)
25200 @end smallexample
25201
25202 Regular stepping:
25203
25204 @smallexample
25205 -exec-step
25206 ^running
25207 (gdb)
25208 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
25209 (gdb)
25210 @end smallexample
25211
25212
25213 @subheading The @code{-exec-step-instruction} Command
25214 @findex -exec-step-instruction
25215
25216 @subsubheading Synopsis
25217
25218 @smallexample
25219 -exec-step-instruction [--reverse]
25220 @end smallexample
25221
25222 Resumes the inferior which executes one machine instruction. If the
25223 @samp{--reverse} option is specified, resumes reverse execution of the
25224 inferior program, stopping at the previously executed instruction.
25225 The output, once @value{GDBN} has stopped, will vary depending on
25226 whether we have stopped in the middle of a source line or not. In the
25227 former case, the address at which the program stopped will be printed
25228 as well.
25229
25230 @subsubheading @value{GDBN} Command
25231
25232 The corresponding @value{GDBN} command is @samp{stepi}.
25233
25234 @subsubheading Example
25235
25236 @smallexample
25237 (gdb)
25238 -exec-step-instruction
25239 ^running
25240
25241 (gdb)
25242 *stopped,reason="end-stepping-range",
25243 frame=@{func="foo",args=[],file="try.c",
25244 fullname="/home/foo/bar/try.c",line="10"@}
25245 (gdb)
25246 -exec-step-instruction
25247 ^running
25248
25249 (gdb)
25250 *stopped,reason="end-stepping-range",
25251 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
25252 fullname="/home/foo/bar/try.c",line="10"@}
25253 (gdb)
25254 @end smallexample
25255
25256
25257 @subheading The @code{-exec-until} Command
25258 @findex -exec-until
25259
25260 @subsubheading Synopsis
25261
25262 @smallexample
25263 -exec-until [ @var{location} ]
25264 @end smallexample
25265
25266 Executes the inferior until the @var{location} specified in the
25267 argument is reached. If there is no argument, the inferior executes
25268 until a source line greater than the current one is reached. The
25269 reason for stopping in this case will be @samp{location-reached}.
25270
25271 @subsubheading @value{GDBN} Command
25272
25273 The corresponding @value{GDBN} command is @samp{until}.
25274
25275 @subsubheading Example
25276
25277 @smallexample
25278 (gdb)
25279 -exec-until recursive2.c:6
25280 ^running
25281 (gdb)
25282 x = 55
25283 *stopped,reason="location-reached",frame=@{func="main",args=[],
25284 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
25285 (gdb)
25286 @end smallexample
25287
25288 @ignore
25289 @subheading -file-clear
25290 Is this going away????
25291 @end ignore
25292
25293 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25294 @node GDB/MI Stack Manipulation
25295 @section @sc{gdb/mi} Stack Manipulation Commands
25296
25297
25298 @subheading The @code{-stack-info-frame} Command
25299 @findex -stack-info-frame
25300
25301 @subsubheading Synopsis
25302
25303 @smallexample
25304 -stack-info-frame
25305 @end smallexample
25306
25307 Get info on the selected frame.
25308
25309 @subsubheading @value{GDBN} Command
25310
25311 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
25312 (without arguments).
25313
25314 @subsubheading Example
25315
25316 @smallexample
25317 (gdb)
25318 -stack-info-frame
25319 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
25320 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25321 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
25322 (gdb)
25323 @end smallexample
25324
25325 @subheading The @code{-stack-info-depth} Command
25326 @findex -stack-info-depth
25327
25328 @subsubheading Synopsis
25329
25330 @smallexample
25331 -stack-info-depth [ @var{max-depth} ]
25332 @end smallexample
25333
25334 Return the depth of the stack. If the integer argument @var{max-depth}
25335 is specified, do not count beyond @var{max-depth} frames.
25336
25337 @subsubheading @value{GDBN} Command
25338
25339 There's no equivalent @value{GDBN} command.
25340
25341 @subsubheading Example
25342
25343 For a stack with frame levels 0 through 11:
25344
25345 @smallexample
25346 (gdb)
25347 -stack-info-depth
25348 ^done,depth="12"
25349 (gdb)
25350 -stack-info-depth 4
25351 ^done,depth="4"
25352 (gdb)
25353 -stack-info-depth 12
25354 ^done,depth="12"
25355 (gdb)
25356 -stack-info-depth 11
25357 ^done,depth="11"
25358 (gdb)
25359 -stack-info-depth 13
25360 ^done,depth="12"
25361 (gdb)
25362 @end smallexample
25363
25364 @subheading The @code{-stack-list-arguments} Command
25365 @findex -stack-list-arguments
25366
25367 @subsubheading Synopsis
25368
25369 @smallexample
25370 -stack-list-arguments @var{print-values}
25371 [ @var{low-frame} @var{high-frame} ]
25372 @end smallexample
25373
25374 Display a list of the arguments for the frames between @var{low-frame}
25375 and @var{high-frame} (inclusive). If @var{low-frame} and
25376 @var{high-frame} are not provided, list the arguments for the whole
25377 call stack. If the two arguments are equal, show the single frame
25378 at the corresponding level. It is an error if @var{low-frame} is
25379 larger than the actual number of frames. On the other hand,
25380 @var{high-frame} may be larger than the actual number of frames, in
25381 which case only existing frames will be returned.
25382
25383 If @var{print-values} is 0 or @code{--no-values}, print only the names of
25384 the variables; if it is 1 or @code{--all-values}, print also their
25385 values; and if it is 2 or @code{--simple-values}, print the name,
25386 type and value for simple data types, and the name and type for arrays,
25387 structures and unions.
25388
25389 Use of this command to obtain arguments in a single frame is
25390 deprecated in favor of the @samp{-stack-list-variables} command.
25391
25392 @subsubheading @value{GDBN} Command
25393
25394 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
25395 @samp{gdb_get_args} command which partially overlaps with the
25396 functionality of @samp{-stack-list-arguments}.
25397
25398 @subsubheading Example
25399
25400 @smallexample
25401 (gdb)
25402 -stack-list-frames
25403 ^done,
25404 stack=[
25405 frame=@{level="0",addr="0x00010734",func="callee4",
25406 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25407 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
25408 frame=@{level="1",addr="0x0001076c",func="callee3",
25409 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25410 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
25411 frame=@{level="2",addr="0x0001078c",func="callee2",
25412 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25413 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
25414 frame=@{level="3",addr="0x000107b4",func="callee1",
25415 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25416 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
25417 frame=@{level="4",addr="0x000107e0",func="main",
25418 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
25419 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
25420 (gdb)
25421 -stack-list-arguments 0
25422 ^done,
25423 stack-args=[
25424 frame=@{level="0",args=[]@},
25425 frame=@{level="1",args=[name="strarg"]@},
25426 frame=@{level="2",args=[name="intarg",name="strarg"]@},
25427 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
25428 frame=@{level="4",args=[]@}]
25429 (gdb)
25430 -stack-list-arguments 1
25431 ^done,
25432 stack-args=[
25433 frame=@{level="0",args=[]@},
25434 frame=@{level="1",
25435 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
25436 frame=@{level="2",args=[
25437 @{name="intarg",value="2"@},
25438 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
25439 @{frame=@{level="3",args=[
25440 @{name="intarg",value="2"@},
25441 @{name="strarg",value="0x11940 \"A string argument.\""@},
25442 @{name="fltarg",value="3.5"@}]@},
25443 frame=@{level="4",args=[]@}]
25444 (gdb)
25445 -stack-list-arguments 0 2 2
25446 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
25447 (gdb)
25448 -stack-list-arguments 1 2 2
25449 ^done,stack-args=[frame=@{level="2",
25450 args=[@{name="intarg",value="2"@},
25451 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
25452 (gdb)
25453 @end smallexample
25454
25455 @c @subheading -stack-list-exception-handlers
25456
25457
25458 @subheading The @code{-stack-list-frames} Command
25459 @findex -stack-list-frames
25460
25461 @subsubheading Synopsis
25462
25463 @smallexample
25464 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
25465 @end smallexample
25466
25467 List the frames currently on the stack. For each frame it displays the
25468 following info:
25469
25470 @table @samp
25471 @item @var{level}
25472 The frame number, 0 being the topmost frame, i.e., the innermost function.
25473 @item @var{addr}
25474 The @code{$pc} value for that frame.
25475 @item @var{func}
25476 Function name.
25477 @item @var{file}
25478 File name of the source file where the function lives.
25479 @item @var{line}
25480 Line number corresponding to the @code{$pc}.
25481 @end table
25482
25483 If invoked without arguments, this command prints a backtrace for the
25484 whole stack. If given two integer arguments, it shows the frames whose
25485 levels are between the two arguments (inclusive). If the two arguments
25486 are equal, it shows the single frame at the corresponding level. It is
25487 an error if @var{low-frame} is larger than the actual number of
25488 frames. On the other hand, @var{high-frame} may be larger than the
25489 actual number of frames, in which case only existing frames will be returned.
25490
25491 @subsubheading @value{GDBN} Command
25492
25493 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
25494
25495 @subsubheading Example
25496
25497 Full stack backtrace:
25498
25499 @smallexample
25500 (gdb)
25501 -stack-list-frames
25502 ^done,stack=
25503 [frame=@{level="0",addr="0x0001076c",func="foo",
25504 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
25505 frame=@{level="1",addr="0x000107a4",func="foo",
25506 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
25507 frame=@{level="2",addr="0x000107a4",func="foo",
25508 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
25509 frame=@{level="3",addr="0x000107a4",func="foo",
25510 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
25511 frame=@{level="4",addr="0x000107a4",func="foo",
25512 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
25513 frame=@{level="5",addr="0x000107a4",func="foo",
25514 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
25515 frame=@{level="6",addr="0x000107a4",func="foo",
25516 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
25517 frame=@{level="7",addr="0x000107a4",func="foo",
25518 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
25519 frame=@{level="8",addr="0x000107a4",func="foo",
25520 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
25521 frame=@{level="9",addr="0x000107a4",func="foo",
25522 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
25523 frame=@{level="10",addr="0x000107a4",func="foo",
25524 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
25525 frame=@{level="11",addr="0x00010738",func="main",
25526 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
25527 (gdb)
25528 @end smallexample
25529
25530 Show frames between @var{low_frame} and @var{high_frame}:
25531
25532 @smallexample
25533 (gdb)
25534 -stack-list-frames 3 5
25535 ^done,stack=
25536 [frame=@{level="3",addr="0x000107a4",func="foo",
25537 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
25538 frame=@{level="4",addr="0x000107a4",func="foo",
25539 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
25540 frame=@{level="5",addr="0x000107a4",func="foo",
25541 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
25542 (gdb)
25543 @end smallexample
25544
25545 Show a single frame:
25546
25547 @smallexample
25548 (gdb)
25549 -stack-list-frames 3 3
25550 ^done,stack=
25551 [frame=@{level="3",addr="0x000107a4",func="foo",
25552 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
25553 (gdb)
25554 @end smallexample
25555
25556
25557 @subheading The @code{-stack-list-locals} Command
25558 @findex -stack-list-locals
25559
25560 @subsubheading Synopsis
25561
25562 @smallexample
25563 -stack-list-locals @var{print-values}
25564 @end smallexample
25565
25566 Display the local variable names for the selected frame. If
25567 @var{print-values} is 0 or @code{--no-values}, print only the names of
25568 the variables; if it is 1 or @code{--all-values}, print also their
25569 values; and if it is 2 or @code{--simple-values}, print the name,
25570 type and value for simple data types, and the name and type for arrays,
25571 structures and unions. In this last case, a frontend can immediately
25572 display the value of simple data types and create variable objects for
25573 other data types when the user wishes to explore their values in
25574 more detail.
25575
25576 This command is deprecated in favor of the
25577 @samp{-stack-list-variables} command.
25578
25579 @subsubheading @value{GDBN} Command
25580
25581 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
25582
25583 @subsubheading Example
25584
25585 @smallexample
25586 (gdb)
25587 -stack-list-locals 0
25588 ^done,locals=[name="A",name="B",name="C"]
25589 (gdb)
25590 -stack-list-locals --all-values
25591 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
25592 @{name="C",value="@{1, 2, 3@}"@}]
25593 -stack-list-locals --simple-values
25594 ^done,locals=[@{name="A",type="int",value="1"@},
25595 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
25596 (gdb)
25597 @end smallexample
25598
25599 @subheading The @code{-stack-list-variables} Command
25600 @findex -stack-list-variables
25601
25602 @subsubheading Synopsis
25603
25604 @smallexample
25605 -stack-list-variables @var{print-values}
25606 @end smallexample
25607
25608 Display the names of local variables and function arguments for the selected frame. If
25609 @var{print-values} is 0 or @code{--no-values}, print only the names of
25610 the variables; if it is 1 or @code{--all-values}, print also their
25611 values; and if it is 2 or @code{--simple-values}, print the name,
25612 type and value for simple data types, and the name and type for arrays,
25613 structures and unions.
25614
25615 @subsubheading Example
25616
25617 @smallexample
25618 (gdb)
25619 -stack-list-variables --thread 1 --frame 0 --all-values
25620 ^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
25621 (gdb)
25622 @end smallexample
25623
25624
25625 @subheading The @code{-stack-select-frame} Command
25626 @findex -stack-select-frame
25627
25628 @subsubheading Synopsis
25629
25630 @smallexample
25631 -stack-select-frame @var{framenum}
25632 @end smallexample
25633
25634 Change the selected frame. Select a different frame @var{framenum} on
25635 the stack.
25636
25637 This command in deprecated in favor of passing the @samp{--frame}
25638 option to every command.
25639
25640 @subsubheading @value{GDBN} Command
25641
25642 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
25643 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
25644
25645 @subsubheading Example
25646
25647 @smallexample
25648 (gdb)
25649 -stack-select-frame 2
25650 ^done
25651 (gdb)
25652 @end smallexample
25653
25654 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25655 @node GDB/MI Variable Objects
25656 @section @sc{gdb/mi} Variable Objects
25657
25658 @ignore
25659
25660 @subheading Motivation for Variable Objects in @sc{gdb/mi}
25661
25662 For the implementation of a variable debugger window (locals, watched
25663 expressions, etc.), we are proposing the adaptation of the existing code
25664 used by @code{Insight}.
25665
25666 The two main reasons for that are:
25667
25668 @enumerate 1
25669 @item
25670 It has been proven in practice (it is already on its second generation).
25671
25672 @item
25673 It will shorten development time (needless to say how important it is
25674 now).
25675 @end enumerate
25676
25677 The original interface was designed to be used by Tcl code, so it was
25678 slightly changed so it could be used through @sc{gdb/mi}. This section
25679 describes the @sc{gdb/mi} operations that will be available and gives some
25680 hints about their use.
25681
25682 @emph{Note}: In addition to the set of operations described here, we
25683 expect the @sc{gui} implementation of a variable window to require, at
25684 least, the following operations:
25685
25686 @itemize @bullet
25687 @item @code{-gdb-show} @code{output-radix}
25688 @item @code{-stack-list-arguments}
25689 @item @code{-stack-list-locals}
25690 @item @code{-stack-select-frame}
25691 @end itemize
25692
25693 @end ignore
25694
25695 @subheading Introduction to Variable Objects
25696
25697 @cindex variable objects in @sc{gdb/mi}
25698
25699 Variable objects are "object-oriented" MI interface for examining and
25700 changing values of expressions. Unlike some other MI interfaces that
25701 work with expressions, variable objects are specifically designed for
25702 simple and efficient presentation in the frontend. A variable object
25703 is identified by string name. When a variable object is created, the
25704 frontend specifies the expression for that variable object. The
25705 expression can be a simple variable, or it can be an arbitrary complex
25706 expression, and can even involve CPU registers. After creating a
25707 variable object, the frontend can invoke other variable object
25708 operations---for example to obtain or change the value of a variable
25709 object, or to change display format.
25710
25711 Variable objects have hierarchical tree structure. Any variable object
25712 that corresponds to a composite type, such as structure in C, has
25713 a number of child variable objects, for example corresponding to each
25714 element of a structure. A child variable object can itself have
25715 children, recursively. Recursion ends when we reach
25716 leaf variable objects, which always have built-in types. Child variable
25717 objects are created only by explicit request, so if a frontend
25718 is not interested in the children of a particular variable object, no
25719 child will be created.
25720
25721 For a leaf variable object it is possible to obtain its value as a
25722 string, or set the value from a string. String value can be also
25723 obtained for a non-leaf variable object, but it's generally a string
25724 that only indicates the type of the object, and does not list its
25725 contents. Assignment to a non-leaf variable object is not allowed.
25726
25727 A frontend does not need to read the values of all variable objects each time
25728 the program stops. Instead, MI provides an update command that lists all
25729 variable objects whose values has changed since the last update
25730 operation. This considerably reduces the amount of data that must
25731 be transferred to the frontend. As noted above, children variable
25732 objects are created on demand, and only leaf variable objects have a
25733 real value. As result, gdb will read target memory only for leaf
25734 variables that frontend has created.
25735
25736 The automatic update is not always desirable. For example, a frontend
25737 might want to keep a value of some expression for future reference,
25738 and never update it. For another example, fetching memory is
25739 relatively slow for embedded targets, so a frontend might want
25740 to disable automatic update for the variables that are either not
25741 visible on the screen, or ``closed''. This is possible using so
25742 called ``frozen variable objects''. Such variable objects are never
25743 implicitly updated.
25744
25745 Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
25746 fixed variable object, the expression is parsed when the variable
25747 object is created, including associating identifiers to specific
25748 variables. The meaning of expression never changes. For a floating
25749 variable object the values of variables whose names appear in the
25750 expressions are re-evaluated every time in the context of the current
25751 frame. Consider this example:
25752
25753 @smallexample
25754 void do_work(...)
25755 @{
25756 struct work_state state;
25757
25758 if (...)
25759 do_work(...);
25760 @}
25761 @end smallexample
25762
25763 If a fixed variable object for the @code{state} variable is created in
25764 this function, and we enter the recursive call, the the variable
25765 object will report the value of @code{state} in the top-level
25766 @code{do_work} invocation. On the other hand, a floating variable
25767 object will report the value of @code{state} in the current frame.
25768
25769 If an expression specified when creating a fixed variable object
25770 refers to a local variable, the variable object becomes bound to the
25771 thread and frame in which the variable object is created. When such
25772 variable object is updated, @value{GDBN} makes sure that the
25773 thread/frame combination the variable object is bound to still exists,
25774 and re-evaluates the variable object in context of that thread/frame.
25775
25776 The following is the complete set of @sc{gdb/mi} operations defined to
25777 access this functionality:
25778
25779 @multitable @columnfractions .4 .6
25780 @item @strong{Operation}
25781 @tab @strong{Description}
25782
25783 @item @code{-enable-pretty-printing}
25784 @tab enable Python-based pretty-printing
25785 @item @code{-var-create}
25786 @tab create a variable object
25787 @item @code{-var-delete}
25788 @tab delete the variable object and/or its children
25789 @item @code{-var-set-format}
25790 @tab set the display format of this variable
25791 @item @code{-var-show-format}
25792 @tab show the display format of this variable
25793 @item @code{-var-info-num-children}
25794 @tab tells how many children this object has
25795 @item @code{-var-list-children}
25796 @tab return a list of the object's children
25797 @item @code{-var-info-type}
25798 @tab show the type of this variable object
25799 @item @code{-var-info-expression}
25800 @tab print parent-relative expression that this variable object represents
25801 @item @code{-var-info-path-expression}
25802 @tab print full expression that this variable object represents
25803 @item @code{-var-show-attributes}
25804 @tab is this variable editable? does it exist here?
25805 @item @code{-var-evaluate-expression}
25806 @tab get the value of this variable
25807 @item @code{-var-assign}
25808 @tab set the value of this variable
25809 @item @code{-var-update}
25810 @tab update the variable and its children
25811 @item @code{-var-set-frozen}
25812 @tab set frozeness attribute
25813 @item @code{-var-set-update-range}
25814 @tab set range of children to display on update
25815 @end multitable
25816
25817 In the next subsection we describe each operation in detail and suggest
25818 how it can be used.
25819
25820 @subheading Description And Use of Operations on Variable Objects
25821
25822 @subheading The @code{-enable-pretty-printing} Command
25823 @findex -enable-pretty-printing
25824
25825 @smallexample
25826 -enable-pretty-printing
25827 @end smallexample
25828
25829 @value{GDBN} allows Python-based visualizers to affect the output of the
25830 MI variable object commands. However, because there was no way to
25831 implement this in a fully backward-compatible way, a front end must
25832 request that this functionality be enabled.
25833
25834 Once enabled, this feature cannot be disabled.
25835
25836 Note that if Python support has not been compiled into @value{GDBN},
25837 this command will still succeed (and do nothing).
25838
25839 This feature is currently (as of @value{GDBN} 7.0) experimental, and
25840 may work differently in future versions of @value{GDBN}.
25841
25842 @subheading The @code{-var-create} Command
25843 @findex -var-create
25844
25845 @subsubheading Synopsis
25846
25847 @smallexample
25848 -var-create @{@var{name} | "-"@}
25849 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
25850 @end smallexample
25851
25852 This operation creates a variable object, which allows the monitoring of
25853 a variable, the result of an expression, a memory cell or a CPU
25854 register.
25855
25856 The @var{name} parameter is the string by which the object can be
25857 referenced. It must be unique. If @samp{-} is specified, the varobj
25858 system will generate a string ``varNNNNNN'' automatically. It will be
25859 unique provided that one does not specify @var{name} of that format.
25860 The command fails if a duplicate name is found.
25861
25862 The frame under which the expression should be evaluated can be
25863 specified by @var{frame-addr}. A @samp{*} indicates that the current
25864 frame should be used. A @samp{@@} indicates that a floating variable
25865 object must be created.
25866
25867 @var{expression} is any expression valid on the current language set (must not
25868 begin with a @samp{*}), or one of the following:
25869
25870 @itemize @bullet
25871 @item
25872 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
25873
25874 @item
25875 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
25876
25877 @item
25878 @samp{$@var{regname}} --- a CPU register name
25879 @end itemize
25880
25881 @cindex dynamic varobj
25882 A varobj's contents may be provided by a Python-based pretty-printer. In this
25883 case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
25884 have slightly different semantics in some cases. If the
25885 @code{-enable-pretty-printing} command is not sent, then @value{GDBN}
25886 will never create a dynamic varobj. This ensures backward
25887 compatibility for existing clients.
25888
25889 @subsubheading Result
25890
25891 This operation returns attributes of the newly-created varobj. These
25892 are:
25893
25894 @table @samp
25895 @item name
25896 The name of the varobj.
25897
25898 @item numchild
25899 The number of children of the varobj. This number is not necessarily
25900 reliable for a dynamic varobj. Instead, you must examine the
25901 @samp{has_more} attribute.
25902
25903 @item value
25904 The varobj's scalar value. For a varobj whose type is some sort of
25905 aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
25906 will not be interesting.
25907
25908 @item type
25909 The varobj's type. This is a string representation of the type, as
25910 would be printed by the @value{GDBN} CLI.
25911
25912 @item thread-id
25913 If a variable object is bound to a specific thread, then this is the
25914 thread's identifier.
25915
25916 @item has_more
25917 For a dynamic varobj, this indicates whether there appear to be any
25918 children available. For a non-dynamic varobj, this will be 0.
25919
25920 @item dynamic
25921 This attribute will be present and have the value @samp{1} if the
25922 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
25923 then this attribute will not be present.
25924
25925 @item displayhint
25926 A dynamic varobj can supply a display hint to the front end. The
25927 value comes directly from the Python pretty-printer object's
25928 @code{display_hint} method. @xref{Pretty Printing API}.
25929 @end table
25930
25931 Typical output will look like this:
25932
25933 @smallexample
25934 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
25935 has_more="@var{has_more}"
25936 @end smallexample
25937
25938
25939 @subheading The @code{-var-delete} Command
25940 @findex -var-delete
25941
25942 @subsubheading Synopsis
25943
25944 @smallexample
25945 -var-delete [ -c ] @var{name}
25946 @end smallexample
25947
25948 Deletes a previously created variable object and all of its children.
25949 With the @samp{-c} option, just deletes the children.
25950
25951 Returns an error if the object @var{name} is not found.
25952
25953
25954 @subheading The @code{-var-set-format} Command
25955 @findex -var-set-format
25956
25957 @subsubheading Synopsis
25958
25959 @smallexample
25960 -var-set-format @var{name} @var{format-spec}
25961 @end smallexample
25962
25963 Sets the output format for the value of the object @var{name} to be
25964 @var{format-spec}.
25965
25966 @anchor{-var-set-format}
25967 The syntax for the @var{format-spec} is as follows:
25968
25969 @smallexample
25970 @var{format-spec} @expansion{}
25971 @{binary | decimal | hexadecimal | octal | natural@}
25972 @end smallexample
25973
25974 The natural format is the default format choosen automatically
25975 based on the variable type (like decimal for an @code{int}, hex
25976 for pointers, etc.).
25977
25978 For a variable with children, the format is set only on the
25979 variable itself, and the children are not affected.
25980
25981 @subheading The @code{-var-show-format} Command
25982 @findex -var-show-format
25983
25984 @subsubheading Synopsis
25985
25986 @smallexample
25987 -var-show-format @var{name}
25988 @end smallexample
25989
25990 Returns the format used to display the value of the object @var{name}.
25991
25992 @smallexample
25993 @var{format} @expansion{}
25994 @var{format-spec}
25995 @end smallexample
25996
25997
25998 @subheading The @code{-var-info-num-children} Command
25999 @findex -var-info-num-children
26000
26001 @subsubheading Synopsis
26002
26003 @smallexample
26004 -var-info-num-children @var{name}
26005 @end smallexample
26006
26007 Returns the number of children of a variable object @var{name}:
26008
26009 @smallexample
26010 numchild=@var{n}
26011 @end smallexample
26012
26013 Note that this number is not completely reliable for a dynamic varobj.
26014 It will return the current number of children, but more children may
26015 be available.
26016
26017
26018 @subheading The @code{-var-list-children} Command
26019 @findex -var-list-children
26020
26021 @subsubheading Synopsis
26022
26023 @smallexample
26024 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
26025 @end smallexample
26026 @anchor{-var-list-children}
26027
26028 Return a list of the children of the specified variable object and
26029 create variable objects for them, if they do not already exist. With
26030 a single argument or if @var{print-values} has a value for of 0 or
26031 @code{--no-values}, print only the names of the variables; if
26032 @var{print-values} is 1 or @code{--all-values}, also print their
26033 values; and if it is 2 or @code{--simple-values} print the name and
26034 value for simple data types and just the name for arrays, structures
26035 and unions.
26036
26037 @var{from} and @var{to}, if specified, indicate the range of children
26038 to report. If @var{from} or @var{to} is less than zero, the range is
26039 reset and all children will be reported. Otherwise, children starting
26040 at @var{from} (zero-based) and up to and excluding @var{to} will be
26041 reported.
26042
26043 If a child range is requested, it will only affect the current call to
26044 @code{-var-list-children}, but not future calls to @code{-var-update}.
26045 For this, you must instead use @code{-var-set-update-range}. The
26046 intent of this approach is to enable a front end to implement any
26047 update approach it likes; for example, scrolling a view may cause the
26048 front end to request more children with @code{-var-list-children}, and
26049 then the front end could call @code{-var-set-update-range} with a
26050 different range to ensure that future updates are restricted to just
26051 the visible items.
26052
26053 For each child the following results are returned:
26054
26055 @table @var
26056
26057 @item name
26058 Name of the variable object created for this child.
26059
26060 @item exp
26061 The expression to be shown to the user by the front end to designate this child.
26062 For example this may be the name of a structure member.
26063
26064 For a dynamic varobj, this value cannot be used to form an
26065 expression. There is no way to do this at all with a dynamic varobj.
26066
26067 For C/C@t{++} structures there are several pseudo children returned to
26068 designate access qualifiers. For these pseudo children @var{exp} is
26069 @samp{public}, @samp{private}, or @samp{protected}. In this case the
26070 type and value are not present.
26071
26072 A dynamic varobj will not report the access qualifying
26073 pseudo-children, regardless of the language. This information is not
26074 available at all with a dynamic varobj.
26075
26076 @item numchild
26077 Number of children this child has. For a dynamic varobj, this will be
26078 0.
26079
26080 @item type
26081 The type of the child.
26082
26083 @item value
26084 If values were requested, this is the value.
26085
26086 @item thread-id
26087 If this variable object is associated with a thread, this is the thread id.
26088 Otherwise this result is not present.
26089
26090 @item frozen
26091 If the variable object is frozen, this variable will be present with a value of 1.
26092 @end table
26093
26094 The result may have its own attributes:
26095
26096 @table @samp
26097 @item displayhint
26098 A dynamic varobj can supply a display hint to the front end. The
26099 value comes directly from the Python pretty-printer object's
26100 @code{display_hint} method. @xref{Pretty Printing API}.
26101
26102 @item has_more
26103 This is an integer attribute which is nonzero if there are children
26104 remaining after the end of the selected range.
26105 @end table
26106
26107 @subsubheading Example
26108
26109 @smallexample
26110 (gdb)
26111 -var-list-children n
26112 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
26113 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
26114 (gdb)
26115 -var-list-children --all-values n
26116 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
26117 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
26118 @end smallexample
26119
26120
26121 @subheading The @code{-var-info-type} Command
26122 @findex -var-info-type
26123
26124 @subsubheading Synopsis
26125
26126 @smallexample
26127 -var-info-type @var{name}
26128 @end smallexample
26129
26130 Returns the type of the specified variable @var{name}. The type is
26131 returned as a string in the same format as it is output by the
26132 @value{GDBN} CLI:
26133
26134 @smallexample
26135 type=@var{typename}
26136 @end smallexample
26137
26138
26139 @subheading The @code{-var-info-expression} Command
26140 @findex -var-info-expression
26141
26142 @subsubheading Synopsis
26143
26144 @smallexample
26145 -var-info-expression @var{name}
26146 @end smallexample
26147
26148 Returns a string that is suitable for presenting this
26149 variable object in user interface. The string is generally
26150 not valid expression in the current language, and cannot be evaluated.
26151
26152 For example, if @code{a} is an array, and variable object
26153 @code{A} was created for @code{a}, then we'll get this output:
26154
26155 @smallexample
26156 (gdb) -var-info-expression A.1
26157 ^done,lang="C",exp="1"
26158 @end smallexample
26159
26160 @noindent
26161 Here, the values of @code{lang} can be @code{@{"C" | "C++" | "Java"@}}.
26162
26163 Note that the output of the @code{-var-list-children} command also
26164 includes those expressions, so the @code{-var-info-expression} command
26165 is of limited use.
26166
26167 @subheading The @code{-var-info-path-expression} Command
26168 @findex -var-info-path-expression
26169
26170 @subsubheading Synopsis
26171
26172 @smallexample
26173 -var-info-path-expression @var{name}
26174 @end smallexample
26175
26176 Returns an expression that can be evaluated in the current
26177 context and will yield the same value that a variable object has.
26178 Compare this with the @code{-var-info-expression} command, which
26179 result can be used only for UI presentation. Typical use of
26180 the @code{-var-info-path-expression} command is creating a
26181 watchpoint from a variable object.
26182
26183 This command is currently not valid for children of a dynamic varobj,
26184 and will give an error when invoked on one.
26185
26186 For example, suppose @code{C} is a C@t{++} class, derived from class
26187 @code{Base}, and that the @code{Base} class has a member called
26188 @code{m_size}. Assume a variable @code{c} is has the type of
26189 @code{C} and a variable object @code{C} was created for variable
26190 @code{c}. Then, we'll get this output:
26191 @smallexample
26192 (gdb) -var-info-path-expression C.Base.public.m_size
26193 ^done,path_expr=((Base)c).m_size)
26194 @end smallexample
26195
26196 @subheading The @code{-var-show-attributes} Command
26197 @findex -var-show-attributes
26198
26199 @subsubheading Synopsis
26200
26201 @smallexample
26202 -var-show-attributes @var{name}
26203 @end smallexample
26204
26205 List attributes of the specified variable object @var{name}:
26206
26207 @smallexample
26208 status=@var{attr} [ ( ,@var{attr} )* ]
26209 @end smallexample
26210
26211 @noindent
26212 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
26213
26214 @subheading The @code{-var-evaluate-expression} Command
26215 @findex -var-evaluate-expression
26216
26217 @subsubheading Synopsis
26218
26219 @smallexample
26220 -var-evaluate-expression [-f @var{format-spec}] @var{name}
26221 @end smallexample
26222
26223 Evaluates the expression that is represented by the specified variable
26224 object and returns its value as a string. The format of the string
26225 can be specified with the @samp{-f} option. The possible values of
26226 this option are the same as for @code{-var-set-format}
26227 (@pxref{-var-set-format}). If the @samp{-f} option is not specified,
26228 the current display format will be used. The current display format
26229 can be changed using the @code{-var-set-format} command.
26230
26231 @smallexample
26232 value=@var{value}
26233 @end smallexample
26234
26235 Note that one must invoke @code{-var-list-children} for a variable
26236 before the value of a child variable can be evaluated.
26237
26238 @subheading The @code{-var-assign} Command
26239 @findex -var-assign
26240
26241 @subsubheading Synopsis
26242
26243 @smallexample
26244 -var-assign @var{name} @var{expression}
26245 @end smallexample
26246
26247 Assigns the value of @var{expression} to the variable object specified
26248 by @var{name}. The object must be @samp{editable}. If the variable's
26249 value is altered by the assign, the variable will show up in any
26250 subsequent @code{-var-update} list.
26251
26252 @subsubheading Example
26253
26254 @smallexample
26255 (gdb)
26256 -var-assign var1 3
26257 ^done,value="3"
26258 (gdb)
26259 -var-update *
26260 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
26261 (gdb)
26262 @end smallexample
26263
26264 @subheading The @code{-var-update} Command
26265 @findex -var-update
26266
26267 @subsubheading Synopsis
26268
26269 @smallexample
26270 -var-update [@var{print-values}] @{@var{name} | "*"@}
26271 @end smallexample
26272
26273 Reevaluate the expressions corresponding to the variable object
26274 @var{name} and all its direct and indirect children, and return the
26275 list of variable objects whose values have changed; @var{name} must
26276 be a root variable object. Here, ``changed'' means that the result of
26277 @code{-var-evaluate-expression} before and after the
26278 @code{-var-update} is different. If @samp{*} is used as the variable
26279 object names, all existing variable objects are updated, except
26280 for frozen ones (@pxref{-var-set-frozen}). The option
26281 @var{print-values} determines whether both names and values, or just
26282 names are printed. The possible values of this option are the same
26283 as for @code{-var-list-children} (@pxref{-var-list-children}). It is
26284 recommended to use the @samp{--all-values} option, to reduce the
26285 number of MI commands needed on each program stop.
26286
26287 With the @samp{*} parameter, if a variable object is bound to a
26288 currently running thread, it will not be updated, without any
26289 diagnostic.
26290
26291 If @code{-var-set-update-range} was previously used on a varobj, then
26292 only the selected range of children will be reported.
26293
26294 @code{-var-update} reports all the changed varobjs in a tuple named
26295 @samp{changelist}.
26296
26297 Each item in the change list is itself a tuple holding:
26298
26299 @table @samp
26300 @item name
26301 The name of the varobj.
26302
26303 @item value
26304 If values were requested for this update, then this field will be
26305 present and will hold the value of the varobj.
26306
26307 @item in_scope
26308 @anchor{-var-update}
26309 This field is a string which may take one of three values:
26310
26311 @table @code
26312 @item "true"
26313 The variable object's current value is valid.
26314
26315 @item "false"
26316 The variable object does not currently hold a valid value but it may
26317 hold one in the future if its associated expression comes back into
26318 scope.
26319
26320 @item "invalid"
26321 The variable object no longer holds a valid value.
26322 This can occur when the executable file being debugged has changed,
26323 either through recompilation or by using the @value{GDBN} @code{file}
26324 command. The front end should normally choose to delete these variable
26325 objects.
26326 @end table
26327
26328 In the future new values may be added to this list so the front should
26329 be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
26330
26331 @item type_changed
26332 This is only present if the varobj is still valid. If the type
26333 changed, then this will be the string @samp{true}; otherwise it will
26334 be @samp{false}.
26335
26336 @item new_type
26337 If the varobj's type changed, then this field will be present and will
26338 hold the new type.
26339
26340 @item new_num_children
26341 For a dynamic varobj, if the number of children changed, or if the
26342 type changed, this will be the new number of children.
26343
26344 The @samp{numchild} field in other varobj responses is generally not
26345 valid for a dynamic varobj -- it will show the number of children that
26346 @value{GDBN} knows about, but because dynamic varobjs lazily
26347 instantiate their children, this will not reflect the number of
26348 children which may be available.
26349
26350 The @samp{new_num_children} attribute only reports changes to the
26351 number of children known by @value{GDBN}. This is the only way to
26352 detect whether an update has removed children (which necessarily can
26353 only happen at the end of the update range).
26354
26355 @item displayhint
26356 The display hint, if any.
26357
26358 @item has_more
26359 This is an integer value, which will be 1 if there are more children
26360 available outside the varobj's update range.
26361
26362 @item dynamic
26363 This attribute will be present and have the value @samp{1} if the
26364 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
26365 then this attribute will not be present.
26366
26367 @item new_children
26368 If new children were added to a dynamic varobj within the selected
26369 update range (as set by @code{-var-set-update-range}), then they will
26370 be listed in this attribute.
26371 @end table
26372
26373 @subsubheading Example
26374
26375 @smallexample
26376 (gdb)
26377 -var-assign var1 3
26378 ^done,value="3"
26379 (gdb)
26380 -var-update --all-values var1
26381 ^done,changelist=[@{name="var1",value="3",in_scope="true",
26382 type_changed="false"@}]
26383 (gdb)
26384 @end smallexample
26385
26386 @subheading The @code{-var-set-frozen} Command
26387 @findex -var-set-frozen
26388 @anchor{-var-set-frozen}
26389
26390 @subsubheading Synopsis
26391
26392 @smallexample
26393 -var-set-frozen @var{name} @var{flag}
26394 @end smallexample
26395
26396 Set the frozenness flag on the variable object @var{name}. The
26397 @var{flag} parameter should be either @samp{1} to make the variable
26398 frozen or @samp{0} to make it unfrozen. If a variable object is
26399 frozen, then neither itself, nor any of its children, are
26400 implicitly updated by @code{-var-update} of
26401 a parent variable or by @code{-var-update *}. Only
26402 @code{-var-update} of the variable itself will update its value and
26403 values of its children. After a variable object is unfrozen, it is
26404 implicitly updated by all subsequent @code{-var-update} operations.
26405 Unfreezing a variable does not update it, only subsequent
26406 @code{-var-update} does.
26407
26408 @subsubheading Example
26409
26410 @smallexample
26411 (gdb)
26412 -var-set-frozen V 1
26413 ^done
26414 (gdb)
26415 @end smallexample
26416
26417 @subheading The @code{-var-set-update-range} command
26418 @findex -var-set-update-range
26419 @anchor{-var-set-update-range}
26420
26421 @subsubheading Synopsis
26422
26423 @smallexample
26424 -var-set-update-range @var{name} @var{from} @var{to}
26425 @end smallexample
26426
26427 Set the range of children to be returned by future invocations of
26428 @code{-var-update}.
26429
26430 @var{from} and @var{to} indicate the range of children to report. If
26431 @var{from} or @var{to} is less than zero, the range is reset and all
26432 children will be reported. Otherwise, children starting at @var{from}
26433 (zero-based) and up to and excluding @var{to} will be reported.
26434
26435 @subsubheading Example
26436
26437 @smallexample
26438 (gdb)
26439 -var-set-update-range V 1 2
26440 ^done
26441 @end smallexample
26442
26443 @subheading The @code{-var-set-visualizer} command
26444 @findex -var-set-visualizer
26445 @anchor{-var-set-visualizer}
26446
26447 @subsubheading Synopsis
26448
26449 @smallexample
26450 -var-set-visualizer @var{name} @var{visualizer}
26451 @end smallexample
26452
26453 Set a visualizer for the variable object @var{name}.
26454
26455 @var{visualizer} is the visualizer to use. The special value
26456 @samp{None} means to disable any visualizer in use.
26457
26458 If not @samp{None}, @var{visualizer} must be a Python expression.
26459 This expression must evaluate to a callable object which accepts a
26460 single argument. @value{GDBN} will call this object with the value of
26461 the varobj @var{name} as an argument (this is done so that the same
26462 Python pretty-printing code can be used for both the CLI and MI).
26463 When called, this object must return an object which conforms to the
26464 pretty-printing interface (@pxref{Pretty Printing API}).
26465
26466 The pre-defined function @code{gdb.default_visualizer} may be used to
26467 select a visualizer by following the built-in process
26468 (@pxref{Selecting Pretty-Printers}). This is done automatically when
26469 a varobj is created, and so ordinarily is not needed.
26470
26471 This feature is only available if Python support is enabled. The MI
26472 command @code{-list-features} (@pxref{GDB/MI Miscellaneous Commands})
26473 can be used to check this.
26474
26475 @subsubheading Example
26476
26477 Resetting the visualizer:
26478
26479 @smallexample
26480 (gdb)
26481 -var-set-visualizer V None
26482 ^done
26483 @end smallexample
26484
26485 Reselecting the default (type-based) visualizer:
26486
26487 @smallexample
26488 (gdb)
26489 -var-set-visualizer V gdb.default_visualizer
26490 ^done
26491 @end smallexample
26492
26493 Suppose @code{SomeClass} is a visualizer class. A lambda expression
26494 can be used to instantiate this class for a varobj:
26495
26496 @smallexample
26497 (gdb)
26498 -var-set-visualizer V "lambda val: SomeClass()"
26499 ^done
26500 @end smallexample
26501
26502 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26503 @node GDB/MI Data Manipulation
26504 @section @sc{gdb/mi} Data Manipulation
26505
26506 @cindex data manipulation, in @sc{gdb/mi}
26507 @cindex @sc{gdb/mi}, data manipulation
26508 This section describes the @sc{gdb/mi} commands that manipulate data:
26509 examine memory and registers, evaluate expressions, etc.
26510
26511 @c REMOVED FROM THE INTERFACE.
26512 @c @subheading -data-assign
26513 @c Change the value of a program variable. Plenty of side effects.
26514 @c @subsubheading GDB Command
26515 @c set variable
26516 @c @subsubheading Example
26517 @c N.A.
26518
26519 @subheading The @code{-data-disassemble} Command
26520 @findex -data-disassemble
26521
26522 @subsubheading Synopsis
26523
26524 @smallexample
26525 -data-disassemble
26526 [ -s @var{start-addr} -e @var{end-addr} ]
26527 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
26528 -- @var{mode}
26529 @end smallexample
26530
26531 @noindent
26532 Where:
26533
26534 @table @samp
26535 @item @var{start-addr}
26536 is the beginning address (or @code{$pc})
26537 @item @var{end-addr}
26538 is the end address
26539 @item @var{filename}
26540 is the name of the file to disassemble
26541 @item @var{linenum}
26542 is the line number to disassemble around
26543 @item @var{lines}
26544 is the number of disassembly lines to be produced. If it is -1,
26545 the whole function will be disassembled, in case no @var{end-addr} is
26546 specified. If @var{end-addr} is specified as a non-zero value, and
26547 @var{lines} is lower than the number of disassembly lines between
26548 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
26549 displayed; if @var{lines} is higher than the number of lines between
26550 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
26551 are displayed.
26552 @item @var{mode}
26553 is either 0 (meaning only disassembly) or 1 (meaning mixed source and
26554 disassembly).
26555 @end table
26556
26557 @subsubheading Result
26558
26559 The output for each instruction is composed of four fields:
26560
26561 @itemize @bullet
26562 @item Address
26563 @item Func-name
26564 @item Offset
26565 @item Instruction
26566 @end itemize
26567
26568 Note that whatever included in the instruction field, is not manipulated
26569 directly by @sc{gdb/mi}, i.e., it is not possible to adjust its format.
26570
26571 @subsubheading @value{GDBN} Command
26572
26573 There's no direct mapping from this command to the CLI.
26574
26575 @subsubheading Example
26576
26577 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
26578
26579 @smallexample
26580 (gdb)
26581 -data-disassemble -s $pc -e "$pc + 20" -- 0
26582 ^done,
26583 asm_insns=[
26584 @{address="0x000107c0",func-name="main",offset="4",
26585 inst="mov 2, %o0"@},
26586 @{address="0x000107c4",func-name="main",offset="8",
26587 inst="sethi %hi(0x11800), %o2"@},
26588 @{address="0x000107c8",func-name="main",offset="12",
26589 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
26590 @{address="0x000107cc",func-name="main",offset="16",
26591 inst="sethi %hi(0x11800), %o2"@},
26592 @{address="0x000107d0",func-name="main",offset="20",
26593 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
26594 (gdb)
26595 @end smallexample
26596
26597 Disassemble the whole @code{main} function. Line 32 is part of
26598 @code{main}.
26599
26600 @smallexample
26601 -data-disassemble -f basics.c -l 32 -- 0
26602 ^done,asm_insns=[
26603 @{address="0x000107bc",func-name="main",offset="0",
26604 inst="save %sp, -112, %sp"@},
26605 @{address="0x000107c0",func-name="main",offset="4",
26606 inst="mov 2, %o0"@},
26607 @{address="0x000107c4",func-name="main",offset="8",
26608 inst="sethi %hi(0x11800), %o2"@},
26609 [@dots{}]
26610 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
26611 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
26612 (gdb)
26613 @end smallexample
26614
26615 Disassemble 3 instructions from the start of @code{main}:
26616
26617 @smallexample
26618 (gdb)
26619 -data-disassemble -f basics.c -l 32 -n 3 -- 0
26620 ^done,asm_insns=[
26621 @{address="0x000107bc",func-name="main",offset="0",
26622 inst="save %sp, -112, %sp"@},
26623 @{address="0x000107c0",func-name="main",offset="4",
26624 inst="mov 2, %o0"@},
26625 @{address="0x000107c4",func-name="main",offset="8",
26626 inst="sethi %hi(0x11800), %o2"@}]
26627 (gdb)
26628 @end smallexample
26629
26630 Disassemble 3 instructions from the start of @code{main} in mixed mode:
26631
26632 @smallexample
26633 (gdb)
26634 -data-disassemble -f basics.c -l 32 -n 3 -- 1
26635 ^done,asm_insns=[
26636 src_and_asm_line=@{line="31",
26637 file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
26638 testsuite/gdb.mi/basics.c",line_asm_insn=[
26639 @{address="0x000107bc",func-name="main",offset="0",
26640 inst="save %sp, -112, %sp"@}]@},
26641 src_and_asm_line=@{line="32",
26642 file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
26643 testsuite/gdb.mi/basics.c",line_asm_insn=[
26644 @{address="0x000107c0",func-name="main",offset="4",
26645 inst="mov 2, %o0"@},
26646 @{address="0x000107c4",func-name="main",offset="8",
26647 inst="sethi %hi(0x11800), %o2"@}]@}]
26648 (gdb)
26649 @end smallexample
26650
26651
26652 @subheading The @code{-data-evaluate-expression} Command
26653 @findex -data-evaluate-expression
26654
26655 @subsubheading Synopsis
26656
26657 @smallexample
26658 -data-evaluate-expression @var{expr}
26659 @end smallexample
26660
26661 Evaluate @var{expr} as an expression. The expression could contain an
26662 inferior function call. The function call will execute synchronously.
26663 If the expression contains spaces, it must be enclosed in double quotes.
26664
26665 @subsubheading @value{GDBN} Command
26666
26667 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
26668 @samp{call}. In @code{gdbtk} only, there's a corresponding
26669 @samp{gdb_eval} command.
26670
26671 @subsubheading Example
26672
26673 In the following example, the numbers that precede the commands are the
26674 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
26675 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
26676 output.
26677
26678 @smallexample
26679 211-data-evaluate-expression A
26680 211^done,value="1"
26681 (gdb)
26682 311-data-evaluate-expression &A
26683 311^done,value="0xefffeb7c"
26684 (gdb)
26685 411-data-evaluate-expression A+3
26686 411^done,value="4"
26687 (gdb)
26688 511-data-evaluate-expression "A + 3"
26689 511^done,value="4"
26690 (gdb)
26691 @end smallexample
26692
26693
26694 @subheading The @code{-data-list-changed-registers} Command
26695 @findex -data-list-changed-registers
26696
26697 @subsubheading Synopsis
26698
26699 @smallexample
26700 -data-list-changed-registers
26701 @end smallexample
26702
26703 Display a list of the registers that have changed.
26704
26705 @subsubheading @value{GDBN} Command
26706
26707 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
26708 has the corresponding command @samp{gdb_changed_register_list}.
26709
26710 @subsubheading Example
26711
26712 On a PPC MBX board:
26713
26714 @smallexample
26715 (gdb)
26716 -exec-continue
26717 ^running
26718
26719 (gdb)
26720 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
26721 func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
26722 line="5"@}
26723 (gdb)
26724 -data-list-changed-registers
26725 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
26726 "10","11","13","14","15","16","17","18","19","20","21","22","23",
26727 "24","25","26","27","28","30","31","64","65","66","67","69"]
26728 (gdb)
26729 @end smallexample
26730
26731
26732 @subheading The @code{-data-list-register-names} Command
26733 @findex -data-list-register-names
26734
26735 @subsubheading Synopsis
26736
26737 @smallexample
26738 -data-list-register-names [ ( @var{regno} )+ ]
26739 @end smallexample
26740
26741 Show a list of register names for the current target. If no arguments
26742 are given, it shows a list of the names of all the registers. If
26743 integer numbers are given as arguments, it will print a list of the
26744 names of the registers corresponding to the arguments. To ensure
26745 consistency between a register name and its number, the output list may
26746 include empty register names.
26747
26748 @subsubheading @value{GDBN} Command
26749
26750 @value{GDBN} does not have a command which corresponds to
26751 @samp{-data-list-register-names}. In @code{gdbtk} there is a
26752 corresponding command @samp{gdb_regnames}.
26753
26754 @subsubheading Example
26755
26756 For the PPC MBX board:
26757 @smallexample
26758 (gdb)
26759 -data-list-register-names
26760 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
26761 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
26762 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
26763 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
26764 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
26765 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
26766 "", "pc","ps","cr","lr","ctr","xer"]
26767 (gdb)
26768 -data-list-register-names 1 2 3
26769 ^done,register-names=["r1","r2","r3"]
26770 (gdb)
26771 @end smallexample
26772
26773 @subheading The @code{-data-list-register-values} Command
26774 @findex -data-list-register-values
26775
26776 @subsubheading Synopsis
26777
26778 @smallexample
26779 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
26780 @end smallexample
26781
26782 Display the registers' contents. @var{fmt} is the format according to
26783 which the registers' contents are to be returned, followed by an optional
26784 list of numbers specifying the registers to display. A missing list of
26785 numbers indicates that the contents of all the registers must be returned.
26786
26787 Allowed formats for @var{fmt} are:
26788
26789 @table @code
26790 @item x
26791 Hexadecimal
26792 @item o
26793 Octal
26794 @item t
26795 Binary
26796 @item d
26797 Decimal
26798 @item r
26799 Raw
26800 @item N
26801 Natural
26802 @end table
26803
26804 @subsubheading @value{GDBN} Command
26805
26806 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
26807 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
26808
26809 @subsubheading Example
26810
26811 For a PPC MBX board (note: line breaks are for readability only, they
26812 don't appear in the actual output):
26813
26814 @smallexample
26815 (gdb)
26816 -data-list-register-values r 64 65
26817 ^done,register-values=[@{number="64",value="0xfe00a300"@},
26818 @{number="65",value="0x00029002"@}]
26819 (gdb)
26820 -data-list-register-values x
26821 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
26822 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
26823 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
26824 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
26825 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
26826 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
26827 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
26828 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
26829 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
26830 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
26831 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
26832 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
26833 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
26834 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
26835 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
26836 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
26837 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
26838 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
26839 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
26840 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
26841 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
26842 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
26843 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
26844 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
26845 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
26846 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
26847 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
26848 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
26849 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
26850 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
26851 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
26852 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
26853 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
26854 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
26855 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
26856 @{number="69",value="0x20002b03"@}]
26857 (gdb)
26858 @end smallexample
26859
26860
26861 @subheading The @code{-data-read-memory} Command
26862 @findex -data-read-memory
26863
26864 @subsubheading Synopsis
26865
26866 @smallexample
26867 -data-read-memory [ -o @var{byte-offset} ]
26868 @var{address} @var{word-format} @var{word-size}
26869 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
26870 @end smallexample
26871
26872 @noindent
26873 where:
26874
26875 @table @samp
26876 @item @var{address}
26877 An expression specifying the address of the first memory word to be
26878 read. Complex expressions containing embedded white space should be
26879 quoted using the C convention.
26880
26881 @item @var{word-format}
26882 The format to be used to print the memory words. The notation is the
26883 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
26884 ,Output Formats}).
26885
26886 @item @var{word-size}
26887 The size of each memory word in bytes.
26888
26889 @item @var{nr-rows}
26890 The number of rows in the output table.
26891
26892 @item @var{nr-cols}
26893 The number of columns in the output table.
26894
26895 @item @var{aschar}
26896 If present, indicates that each row should include an @sc{ascii} dump. The
26897 value of @var{aschar} is used as a padding character when a byte is not a
26898 member of the printable @sc{ascii} character set (printable @sc{ascii}
26899 characters are those whose code is between 32 and 126, inclusively).
26900
26901 @item @var{byte-offset}
26902 An offset to add to the @var{address} before fetching memory.
26903 @end table
26904
26905 This command displays memory contents as a table of @var{nr-rows} by
26906 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
26907 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
26908 (returned as @samp{total-bytes}). Should less than the requested number
26909 of bytes be returned by the target, the missing words are identified
26910 using @samp{N/A}. The number of bytes read from the target is returned
26911 in @samp{nr-bytes} and the starting address used to read memory in
26912 @samp{addr}.
26913
26914 The address of the next/previous row or page is available in
26915 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
26916 @samp{prev-page}.
26917
26918 @subsubheading @value{GDBN} Command
26919
26920 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
26921 @samp{gdb_get_mem} memory read command.
26922
26923 @subsubheading Example
26924
26925 Read six bytes of memory starting at @code{bytes+6} but then offset by
26926 @code{-6} bytes. Format as three rows of two columns. One byte per
26927 word. Display each word in hex.
26928
26929 @smallexample
26930 (gdb)
26931 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
26932 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
26933 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
26934 prev-page="0x0000138a",memory=[
26935 @{addr="0x00001390",data=["0x00","0x01"]@},
26936 @{addr="0x00001392",data=["0x02","0x03"]@},
26937 @{addr="0x00001394",data=["0x04","0x05"]@}]
26938 (gdb)
26939 @end smallexample
26940
26941 Read two bytes of memory starting at address @code{shorts + 64} and
26942 display as a single word formatted in decimal.
26943
26944 @smallexample
26945 (gdb)
26946 5-data-read-memory shorts+64 d 2 1 1
26947 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
26948 next-row="0x00001512",prev-row="0x0000150e",
26949 next-page="0x00001512",prev-page="0x0000150e",memory=[
26950 @{addr="0x00001510",data=["128"]@}]
26951 (gdb)
26952 @end smallexample
26953
26954 Read thirty two bytes of memory starting at @code{bytes+16} and format
26955 as eight rows of four columns. Include a string encoding with @samp{x}
26956 used as the non-printable character.
26957
26958 @smallexample
26959 (gdb)
26960 4-data-read-memory bytes+16 x 1 8 4 x
26961 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
26962 next-row="0x000013c0",prev-row="0x0000139c",
26963 next-page="0x000013c0",prev-page="0x00001380",memory=[
26964 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
26965 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
26966 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
26967 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
26968 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
26969 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
26970 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
26971 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
26972 (gdb)
26973 @end smallexample
26974
26975 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26976 @node GDB/MI Tracepoint Commands
26977 @section @sc{gdb/mi} Tracepoint Commands
26978
26979 The commands defined in this section implement MI support for
26980 tracepoints. For detailed introduction, see @ref{Tracepoints}.
26981
26982 @subheading The @code{-trace-find} Command
26983 @findex -trace-find
26984
26985 @subsubheading Synopsis
26986
26987 @smallexample
26988 -trace-find @var{mode} [@var{parameters}@dots{}]
26989 @end smallexample
26990
26991 Find a trace frame using criteria defined by @var{mode} and
26992 @var{parameters}. The following table lists permissible
26993 modes and their parameters. For details of operation, see @ref{tfind}.
26994
26995 @table @samp
26996
26997 @item none
26998 No parameters are required. Stops examining trace frames.
26999
27000 @item frame-number
27001 An integer is required as parameter. Selects tracepoint frame with
27002 that index.
27003
27004 @item tracepoint-number
27005 An integer is required as parameter. Finds next
27006 trace frame that corresponds to tracepoint with the specified number.
27007
27008 @item pc
27009 An address is required as parameter. Finds
27010 next trace frame that corresponds to any tracepoint at the specified
27011 address.
27012
27013 @item pc-inside-range
27014 Two addresses are required as parameters. Finds next trace
27015 frame that corresponds to a tracepoint at an address inside the
27016 specified range. Both bounds are considered to be inside the range.
27017
27018 @item pc-outside-range
27019 Two addresses are required as parameters. Finds
27020 next trace frame that corresponds to a tracepoint at an address outside
27021 the specified range. Both bounds are considered to be inside the range.
27022
27023 @item line
27024 Line specification is required as parameter. @xref{Specify Location}.
27025 Finds next trace frame that corresponds to a tracepoint at
27026 the specified location.
27027
27028 @end table
27029
27030 If @samp{none} was passed as @var{mode}, the response does not
27031 have fields. Otherwise, the response may have the following fields:
27032
27033 @table @samp
27034 @item found
27035 This field has either @samp{0} or @samp{1} as the value, depending
27036 on whether a matching tracepoint was found.
27037
27038 @item traceframe
27039 The index of the found traceframe. This field is present iff
27040 the @samp{found} field has value of @samp{1}.
27041
27042 @item tracepoint
27043 The index of the found tracepoint. This field is present iff
27044 the @samp{found} field has value of @samp{1}.
27045
27046 @item frame
27047 The information about the frame corresponding to the found trace
27048 frame. This field is present only if a trace frame was found.
27049 @xref{GDB/MI Frame Information}, for description of this field.
27050
27051 @end table
27052
27053 @subsubheading @value{GDBN} Command
27054
27055 The corresponding @value{GDBN} command is @samp{tfind}.
27056
27057 @subheading -trace-define-variable
27058 @findex -trace-define-variable
27059
27060 @subsubheading Synopsis
27061
27062 @smallexample
27063 -trace-define-variable @var{name} [ @var{value} ]
27064 @end smallexample
27065
27066 Create trace variable @var{name} if it does not exist. If
27067 @var{value} is specified, sets the initial value of the specified
27068 trace variable to that value. Note that the @var{name} should start
27069 with the @samp{$} character.
27070
27071 @subsubheading @value{GDBN} Command
27072
27073 The corresponding @value{GDBN} command is @samp{tvariable}.
27074
27075 @subheading -trace-list-variables
27076 @findex -trace-list-variables
27077
27078 @subsubheading Synopsis
27079
27080 @smallexample
27081 -trace-list-variables
27082 @end smallexample
27083
27084 Return a table of all defined trace variables. Each element of the
27085 table has the following fields:
27086
27087 @table @samp
27088 @item name
27089 The name of the trace variable. This field is always present.
27090
27091 @item initial
27092 The initial value. This is a 64-bit signed integer. This
27093 field is always present.
27094
27095 @item current
27096 The value the trace variable has at the moment. This is a 64-bit
27097 signed integer. This field is absent iff current value is
27098 not defined, for example if the trace was never run, or is
27099 presently running.
27100
27101 @end table
27102
27103 @subsubheading @value{GDBN} Command
27104
27105 The corresponding @value{GDBN} command is @samp{tvariables}.
27106
27107 @subsubheading Example
27108
27109 @smallexample
27110 (gdb)
27111 -trace-list-variables
27112 ^done,trace-variables=@{nr_rows="1",nr_cols="3",
27113 hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
27114 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
27115 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
27116 body=[variable=@{name="$trace_timestamp",initial="0"@}
27117 variable=@{name="$foo",initial="10",current="15"@}]@}
27118 (gdb)
27119 @end smallexample
27120
27121 @subheading -trace-save
27122 @findex -trace-save
27123
27124 @subsubheading Synopsis
27125
27126 @smallexample
27127 -trace-save [-r ] @var{filename}
27128 @end smallexample
27129
27130 Saves the collected trace data to @var{filename}. Without the
27131 @samp{-r} option, the data is downloaded from the target and saved
27132 in a local file. With the @samp{-r} option the target is asked
27133 to perform the save.
27134
27135 @subsubheading @value{GDBN} Command
27136
27137 The corresponding @value{GDBN} command is @samp{tsave}.
27138
27139
27140 @subheading -trace-start
27141 @findex -trace-start
27142
27143 @subsubheading Synopsis
27144
27145 @smallexample
27146 -trace-start
27147 @end smallexample
27148
27149 Starts a tracing experiments. The result of this command does not
27150 have any fields.
27151
27152 @subsubheading @value{GDBN} Command
27153
27154 The corresponding @value{GDBN} command is @samp{tstart}.
27155
27156 @subheading -trace-status
27157 @findex -trace-status
27158
27159 @subsubheading Synopsis
27160
27161 @smallexample
27162 -trace-status
27163 @end smallexample
27164
27165 Obtains the status of a tracing experiment. The result may include
27166 the following fields:
27167
27168 @table @samp
27169
27170 @item supported
27171 May have a value of either @samp{0}, when no tracing operations are
27172 supported, @samp{1}, when all tracing operations are supported, or
27173 @samp{file} when examining trace file. In the latter case, examining
27174 of trace frame is possible but new tracing experiement cannot be
27175 started. This field is always present.
27176
27177 @item running
27178 May have a value of either @samp{0} or @samp{1} depending on whether
27179 tracing experiement is in progress on target. This field is present
27180 if @samp{supported} field is not @samp{0}.
27181
27182 @item stop-reason
27183 Report the reason why the tracing was stopped last time. This field
27184 may be absent iff tracing was never stopped on target yet. The
27185 value of @samp{request} means the tracing was stopped as result of
27186 the @code{-trace-stop} command. The value of @samp{overflow} means
27187 the tracing buffer is full. The value of @samp{disconnection} means
27188 tracing was automatically stopped when @value{GDBN} has disconnected.
27189 The value of @samp{passcount} means tracing was stopped when a
27190 tracepoint was passed a maximal number of times for that tracepoint.
27191 This field is present if @samp{supported} field is not @samp{0}.
27192
27193 @item stopping-tracepoint
27194 The number of tracepoint whose passcount as exceeded. This field is
27195 present iff the @samp{stop-reason} field has the value of
27196 @samp{passcount}.
27197
27198 @item frames
27199 @itemx frames-created
27200 The @samp{frames} field is a count of the total number of trace frames
27201 in the trace buffer, while @samp{frames-created} is the total created
27202 during the run, including ones that were discarded, such as when a
27203 circular trace buffer filled up. Both fields are optional.
27204
27205 @item buffer-size
27206 @itemx buffer-free
27207 These fields tell the current size of the tracing buffer and the
27208 remaining space. These fields are optional.
27209
27210 @item circular
27211 The value of the circular trace buffer flag. @code{1} means that the
27212 trace buffer is circular and old trace frames will be discarded if
27213 necessary to make room, @code{0} means that the trace buffer is linear
27214 and may fill up.
27215
27216 @item disconnected
27217 The value of the disconnected tracing flag. @code{1} means that
27218 tracing will continue after @value{GDBN} disconnects, @code{0} means
27219 that the trace run will stop.
27220
27221 @end table
27222
27223 @subsubheading @value{GDBN} Command
27224
27225 The corresponding @value{GDBN} command is @samp{tstatus}.
27226
27227 @subheading -trace-stop
27228 @findex -trace-stop
27229
27230 @subsubheading Synopsis
27231
27232 @smallexample
27233 -trace-stop
27234 @end smallexample
27235
27236 Stops a tracing experiment. The result of this command has the same
27237 fields as @code{-trace-status}, except that the @samp{supported} and
27238 @samp{running} fields are not output.
27239
27240 @subsubheading @value{GDBN} Command
27241
27242 The corresponding @value{GDBN} command is @samp{tstop}.
27243
27244
27245 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27246 @node GDB/MI Symbol Query
27247 @section @sc{gdb/mi} Symbol Query Commands
27248
27249
27250 @ignore
27251 @subheading The @code{-symbol-info-address} Command
27252 @findex -symbol-info-address
27253
27254 @subsubheading Synopsis
27255
27256 @smallexample
27257 -symbol-info-address @var{symbol}
27258 @end smallexample
27259
27260 Describe where @var{symbol} is stored.
27261
27262 @subsubheading @value{GDBN} Command
27263
27264 The corresponding @value{GDBN} command is @samp{info address}.
27265
27266 @subsubheading Example
27267 N.A.
27268
27269
27270 @subheading The @code{-symbol-info-file} Command
27271 @findex -symbol-info-file
27272
27273 @subsubheading Synopsis
27274
27275 @smallexample
27276 -symbol-info-file
27277 @end smallexample
27278
27279 Show the file for the symbol.
27280
27281 @subsubheading @value{GDBN} Command
27282
27283 There's no equivalent @value{GDBN} command. @code{gdbtk} has
27284 @samp{gdb_find_file}.
27285
27286 @subsubheading Example
27287 N.A.
27288
27289
27290 @subheading The @code{-symbol-info-function} Command
27291 @findex -symbol-info-function
27292
27293 @subsubheading Synopsis
27294
27295 @smallexample
27296 -symbol-info-function
27297 @end smallexample
27298
27299 Show which function the symbol lives in.
27300
27301 @subsubheading @value{GDBN} Command
27302
27303 @samp{gdb_get_function} in @code{gdbtk}.
27304
27305 @subsubheading Example
27306 N.A.
27307
27308
27309 @subheading The @code{-symbol-info-line} Command
27310 @findex -symbol-info-line
27311
27312 @subsubheading Synopsis
27313
27314 @smallexample
27315 -symbol-info-line
27316 @end smallexample
27317
27318 Show the core addresses of the code for a source line.
27319
27320 @subsubheading @value{GDBN} Command
27321
27322 The corresponding @value{GDBN} command is @samp{info line}.
27323 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
27324
27325 @subsubheading Example
27326 N.A.
27327
27328
27329 @subheading The @code{-symbol-info-symbol} Command
27330 @findex -symbol-info-symbol
27331
27332 @subsubheading Synopsis
27333
27334 @smallexample
27335 -symbol-info-symbol @var{addr}
27336 @end smallexample
27337
27338 Describe what symbol is at location @var{addr}.
27339
27340 @subsubheading @value{GDBN} Command
27341
27342 The corresponding @value{GDBN} command is @samp{info symbol}.
27343
27344 @subsubheading Example
27345 N.A.
27346
27347
27348 @subheading The @code{-symbol-list-functions} Command
27349 @findex -symbol-list-functions
27350
27351 @subsubheading Synopsis
27352
27353 @smallexample
27354 -symbol-list-functions
27355 @end smallexample
27356
27357 List the functions in the executable.
27358
27359 @subsubheading @value{GDBN} Command
27360
27361 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
27362 @samp{gdb_search} in @code{gdbtk}.
27363
27364 @subsubheading Example
27365 N.A.
27366 @end ignore
27367
27368
27369 @subheading The @code{-symbol-list-lines} Command
27370 @findex -symbol-list-lines
27371
27372 @subsubheading Synopsis
27373
27374 @smallexample
27375 -symbol-list-lines @var{filename}
27376 @end smallexample
27377
27378 Print the list of lines that contain code and their associated program
27379 addresses for the given source filename. The entries are sorted in
27380 ascending PC order.
27381
27382 @subsubheading @value{GDBN} Command
27383
27384 There is no corresponding @value{GDBN} command.
27385
27386 @subsubheading Example
27387 @smallexample
27388 (gdb)
27389 -symbol-list-lines basics.c
27390 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
27391 (gdb)
27392 @end smallexample
27393
27394
27395 @ignore
27396 @subheading The @code{-symbol-list-types} Command
27397 @findex -symbol-list-types
27398
27399 @subsubheading Synopsis
27400
27401 @smallexample
27402 -symbol-list-types
27403 @end smallexample
27404
27405 List all the type names.
27406
27407 @subsubheading @value{GDBN} Command
27408
27409 The corresponding commands are @samp{info types} in @value{GDBN},
27410 @samp{gdb_search} in @code{gdbtk}.
27411
27412 @subsubheading Example
27413 N.A.
27414
27415
27416 @subheading The @code{-symbol-list-variables} Command
27417 @findex -symbol-list-variables
27418
27419 @subsubheading Synopsis
27420
27421 @smallexample
27422 -symbol-list-variables
27423 @end smallexample
27424
27425 List all the global and static variable names.
27426
27427 @subsubheading @value{GDBN} Command
27428
27429 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
27430
27431 @subsubheading Example
27432 N.A.
27433
27434
27435 @subheading The @code{-symbol-locate} Command
27436 @findex -symbol-locate
27437
27438 @subsubheading Synopsis
27439
27440 @smallexample
27441 -symbol-locate
27442 @end smallexample
27443
27444 @subsubheading @value{GDBN} Command
27445
27446 @samp{gdb_loc} in @code{gdbtk}.
27447
27448 @subsubheading Example
27449 N.A.
27450
27451
27452 @subheading The @code{-symbol-type} Command
27453 @findex -symbol-type
27454
27455 @subsubheading Synopsis
27456
27457 @smallexample
27458 -symbol-type @var{variable}
27459 @end smallexample
27460
27461 Show type of @var{variable}.
27462
27463 @subsubheading @value{GDBN} Command
27464
27465 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
27466 @samp{gdb_obj_variable}.
27467
27468 @subsubheading Example
27469 N.A.
27470 @end ignore
27471
27472
27473 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27474 @node GDB/MI File Commands
27475 @section @sc{gdb/mi} File Commands
27476
27477 This section describes the GDB/MI commands to specify executable file names
27478 and to read in and obtain symbol table information.
27479
27480 @subheading The @code{-file-exec-and-symbols} Command
27481 @findex -file-exec-and-symbols
27482
27483 @subsubheading Synopsis
27484
27485 @smallexample
27486 -file-exec-and-symbols @var{file}
27487 @end smallexample
27488
27489 Specify the executable file to be debugged. This file is the one from
27490 which the symbol table is also read. If no file is specified, the
27491 command clears the executable and symbol information. If breakpoints
27492 are set when using this command with no arguments, @value{GDBN} will produce
27493 error messages. Otherwise, no output is produced, except a completion
27494 notification.
27495
27496 @subsubheading @value{GDBN} Command
27497
27498 The corresponding @value{GDBN} command is @samp{file}.
27499
27500 @subsubheading Example
27501
27502 @smallexample
27503 (gdb)
27504 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
27505 ^done
27506 (gdb)
27507 @end smallexample
27508
27509
27510 @subheading The @code{-file-exec-file} Command
27511 @findex -file-exec-file
27512
27513 @subsubheading Synopsis
27514
27515 @smallexample
27516 -file-exec-file @var{file}
27517 @end smallexample
27518
27519 Specify the executable file to be debugged. Unlike
27520 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
27521 from this file. If used without argument, @value{GDBN} clears the information
27522 about the executable file. No output is produced, except a completion
27523 notification.
27524
27525 @subsubheading @value{GDBN} Command
27526
27527 The corresponding @value{GDBN} command is @samp{exec-file}.
27528
27529 @subsubheading Example
27530
27531 @smallexample
27532 (gdb)
27533 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
27534 ^done
27535 (gdb)
27536 @end smallexample
27537
27538
27539 @ignore
27540 @subheading The @code{-file-list-exec-sections} Command
27541 @findex -file-list-exec-sections
27542
27543 @subsubheading Synopsis
27544
27545 @smallexample
27546 -file-list-exec-sections
27547 @end smallexample
27548
27549 List the sections of the current executable file.
27550
27551 @subsubheading @value{GDBN} Command
27552
27553 The @value{GDBN} command @samp{info file} shows, among the rest, the same
27554 information as this command. @code{gdbtk} has a corresponding command
27555 @samp{gdb_load_info}.
27556
27557 @subsubheading Example
27558 N.A.
27559 @end ignore
27560
27561
27562 @subheading The @code{-file-list-exec-source-file} Command
27563 @findex -file-list-exec-source-file
27564
27565 @subsubheading Synopsis
27566
27567 @smallexample
27568 -file-list-exec-source-file
27569 @end smallexample
27570
27571 List the line number, the current source file, and the absolute path
27572 to the current source file for the current executable. The macro
27573 information field has a value of @samp{1} or @samp{0} depending on
27574 whether or not the file includes preprocessor macro information.
27575
27576 @subsubheading @value{GDBN} Command
27577
27578 The @value{GDBN} equivalent is @samp{info source}
27579
27580 @subsubheading Example
27581
27582 @smallexample
27583 (gdb)
27584 123-file-list-exec-source-file
27585 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
27586 (gdb)
27587 @end smallexample
27588
27589
27590 @subheading The @code{-file-list-exec-source-files} Command
27591 @findex -file-list-exec-source-files
27592
27593 @subsubheading Synopsis
27594
27595 @smallexample
27596 -file-list-exec-source-files
27597 @end smallexample
27598
27599 List the source files for the current executable.
27600
27601 It will always output the filename, but only when @value{GDBN} can find
27602 the absolute file name of a source file, will it output the fullname.
27603
27604 @subsubheading @value{GDBN} Command
27605
27606 The @value{GDBN} equivalent is @samp{info sources}.
27607 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
27608
27609 @subsubheading Example
27610 @smallexample
27611 (gdb)
27612 -file-list-exec-source-files
27613 ^done,files=[
27614 @{file=foo.c,fullname=/home/foo.c@},
27615 @{file=/home/bar.c,fullname=/home/bar.c@},
27616 @{file=gdb_could_not_find_fullpath.c@}]
27617 (gdb)
27618 @end smallexample
27619
27620 @ignore
27621 @subheading The @code{-file-list-shared-libraries} Command
27622 @findex -file-list-shared-libraries
27623
27624 @subsubheading Synopsis
27625
27626 @smallexample
27627 -file-list-shared-libraries
27628 @end smallexample
27629
27630 List the shared libraries in the program.
27631
27632 @subsubheading @value{GDBN} Command
27633
27634 The corresponding @value{GDBN} command is @samp{info shared}.
27635
27636 @subsubheading Example
27637 N.A.
27638
27639
27640 @subheading The @code{-file-list-symbol-files} Command
27641 @findex -file-list-symbol-files
27642
27643 @subsubheading Synopsis
27644
27645 @smallexample
27646 -file-list-symbol-files
27647 @end smallexample
27648
27649 List symbol files.
27650
27651 @subsubheading @value{GDBN} Command
27652
27653 The corresponding @value{GDBN} command is @samp{info file} (part of it).
27654
27655 @subsubheading Example
27656 N.A.
27657 @end ignore
27658
27659
27660 @subheading The @code{-file-symbol-file} Command
27661 @findex -file-symbol-file
27662
27663 @subsubheading Synopsis
27664
27665 @smallexample
27666 -file-symbol-file @var{file}
27667 @end smallexample
27668
27669 Read symbol table info from the specified @var{file} argument. When
27670 used without arguments, clears @value{GDBN}'s symbol table info. No output is
27671 produced, except for a completion notification.
27672
27673 @subsubheading @value{GDBN} Command
27674
27675 The corresponding @value{GDBN} command is @samp{symbol-file}.
27676
27677 @subsubheading Example
27678
27679 @smallexample
27680 (gdb)
27681 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
27682 ^done
27683 (gdb)
27684 @end smallexample
27685
27686 @ignore
27687 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27688 @node GDB/MI Memory Overlay Commands
27689 @section @sc{gdb/mi} Memory Overlay Commands
27690
27691 The memory overlay commands are not implemented.
27692
27693 @c @subheading -overlay-auto
27694
27695 @c @subheading -overlay-list-mapping-state
27696
27697 @c @subheading -overlay-list-overlays
27698
27699 @c @subheading -overlay-map
27700
27701 @c @subheading -overlay-off
27702
27703 @c @subheading -overlay-on
27704
27705 @c @subheading -overlay-unmap
27706
27707 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27708 @node GDB/MI Signal Handling Commands
27709 @section @sc{gdb/mi} Signal Handling Commands
27710
27711 Signal handling commands are not implemented.
27712
27713 @c @subheading -signal-handle
27714
27715 @c @subheading -signal-list-handle-actions
27716
27717 @c @subheading -signal-list-signal-types
27718 @end ignore
27719
27720
27721 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27722 @node GDB/MI Target Manipulation
27723 @section @sc{gdb/mi} Target Manipulation Commands
27724
27725
27726 @subheading The @code{-target-attach} Command
27727 @findex -target-attach
27728
27729 @subsubheading Synopsis
27730
27731 @smallexample
27732 -target-attach @var{pid} | @var{gid} | @var{file}
27733 @end smallexample
27734
27735 Attach to a process @var{pid} or a file @var{file} outside of
27736 @value{GDBN}, or a thread group @var{gid}. If attaching to a thread
27737 group, the id previously returned by
27738 @samp{-list-thread-groups --available} must be used.
27739
27740 @subsubheading @value{GDBN} Command
27741
27742 The corresponding @value{GDBN} command is @samp{attach}.
27743
27744 @subsubheading Example
27745 @smallexample
27746 (gdb)
27747 -target-attach 34
27748 =thread-created,id="1"
27749 *stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
27750 ^done
27751 (gdb)
27752 @end smallexample
27753
27754 @ignore
27755 @subheading The @code{-target-compare-sections} Command
27756 @findex -target-compare-sections
27757
27758 @subsubheading Synopsis
27759
27760 @smallexample
27761 -target-compare-sections [ @var{section} ]
27762 @end smallexample
27763
27764 Compare data of section @var{section} on target to the exec file.
27765 Without the argument, all sections are compared.
27766
27767 @subsubheading @value{GDBN} Command
27768
27769 The @value{GDBN} equivalent is @samp{compare-sections}.
27770
27771 @subsubheading Example
27772 N.A.
27773 @end ignore
27774
27775
27776 @subheading The @code{-target-detach} Command
27777 @findex -target-detach
27778
27779 @subsubheading Synopsis
27780
27781 @smallexample
27782 -target-detach [ @var{pid} | @var{gid} ]
27783 @end smallexample
27784
27785 Detach from the remote target which normally resumes its execution.
27786 If either @var{pid} or @var{gid} is specified, detaches from either
27787 the specified process, or specified thread group. There's no output.
27788
27789 @subsubheading @value{GDBN} Command
27790
27791 The corresponding @value{GDBN} command is @samp{detach}.
27792
27793 @subsubheading Example
27794
27795 @smallexample
27796 (gdb)
27797 -target-detach
27798 ^done
27799 (gdb)
27800 @end smallexample
27801
27802
27803 @subheading The @code{-target-disconnect} Command
27804 @findex -target-disconnect
27805
27806 @subsubheading Synopsis
27807
27808 @smallexample
27809 -target-disconnect
27810 @end smallexample
27811
27812 Disconnect from the remote target. There's no output and the target is
27813 generally not resumed.
27814
27815 @subsubheading @value{GDBN} Command
27816
27817 The corresponding @value{GDBN} command is @samp{disconnect}.
27818
27819 @subsubheading Example
27820
27821 @smallexample
27822 (gdb)
27823 -target-disconnect
27824 ^done
27825 (gdb)
27826 @end smallexample
27827
27828
27829 @subheading The @code{-target-download} Command
27830 @findex -target-download
27831
27832 @subsubheading Synopsis
27833
27834 @smallexample
27835 -target-download
27836 @end smallexample
27837
27838 Loads the executable onto the remote target.
27839 It prints out an update message every half second, which includes the fields:
27840
27841 @table @samp
27842 @item section
27843 The name of the section.
27844 @item section-sent
27845 The size of what has been sent so far for that section.
27846 @item section-size
27847 The size of the section.
27848 @item total-sent
27849 The total size of what was sent so far (the current and the previous sections).
27850 @item total-size
27851 The size of the overall executable to download.
27852 @end table
27853
27854 @noindent
27855 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
27856 @sc{gdb/mi} Output Syntax}).
27857
27858 In addition, it prints the name and size of the sections, as they are
27859 downloaded. These messages include the following fields:
27860
27861 @table @samp
27862 @item section
27863 The name of the section.
27864 @item section-size
27865 The size of the section.
27866 @item total-size
27867 The size of the overall executable to download.
27868 @end table
27869
27870 @noindent
27871 At the end, a summary is printed.
27872
27873 @subsubheading @value{GDBN} Command
27874
27875 The corresponding @value{GDBN} command is @samp{load}.
27876
27877 @subsubheading Example
27878
27879 Note: each status message appears on a single line. Here the messages
27880 have been broken down so that they can fit onto a page.
27881
27882 @smallexample
27883 (gdb)
27884 -target-download
27885 +download,@{section=".text",section-size="6668",total-size="9880"@}
27886 +download,@{section=".text",section-sent="512",section-size="6668",
27887 total-sent="512",total-size="9880"@}
27888 +download,@{section=".text",section-sent="1024",section-size="6668",
27889 total-sent="1024",total-size="9880"@}
27890 +download,@{section=".text",section-sent="1536",section-size="6668",
27891 total-sent="1536",total-size="9880"@}
27892 +download,@{section=".text",section-sent="2048",section-size="6668",
27893 total-sent="2048",total-size="9880"@}
27894 +download,@{section=".text",section-sent="2560",section-size="6668",
27895 total-sent="2560",total-size="9880"@}
27896 +download,@{section=".text",section-sent="3072",section-size="6668",
27897 total-sent="3072",total-size="9880"@}
27898 +download,@{section=".text",section-sent="3584",section-size="6668",
27899 total-sent="3584",total-size="9880"@}
27900 +download,@{section=".text",section-sent="4096",section-size="6668",
27901 total-sent="4096",total-size="9880"@}
27902 +download,@{section=".text",section-sent="4608",section-size="6668",
27903 total-sent="4608",total-size="9880"@}
27904 +download,@{section=".text",section-sent="5120",section-size="6668",
27905 total-sent="5120",total-size="9880"@}
27906 +download,@{section=".text",section-sent="5632",section-size="6668",
27907 total-sent="5632",total-size="9880"@}
27908 +download,@{section=".text",section-sent="6144",section-size="6668",
27909 total-sent="6144",total-size="9880"@}
27910 +download,@{section=".text",section-sent="6656",section-size="6668",
27911 total-sent="6656",total-size="9880"@}
27912 +download,@{section=".init",section-size="28",total-size="9880"@}
27913 +download,@{section=".fini",section-size="28",total-size="9880"@}
27914 +download,@{section=".data",section-size="3156",total-size="9880"@}
27915 +download,@{section=".data",section-sent="512",section-size="3156",
27916 total-sent="7236",total-size="9880"@}
27917 +download,@{section=".data",section-sent="1024",section-size="3156",
27918 total-sent="7748",total-size="9880"@}
27919 +download,@{section=".data",section-sent="1536",section-size="3156",
27920 total-sent="8260",total-size="9880"@}
27921 +download,@{section=".data",section-sent="2048",section-size="3156",
27922 total-sent="8772",total-size="9880"@}
27923 +download,@{section=".data",section-sent="2560",section-size="3156",
27924 total-sent="9284",total-size="9880"@}
27925 +download,@{section=".data",section-sent="3072",section-size="3156",
27926 total-sent="9796",total-size="9880"@}
27927 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
27928 write-rate="429"
27929 (gdb)
27930 @end smallexample
27931
27932
27933 @ignore
27934 @subheading The @code{-target-exec-status} Command
27935 @findex -target-exec-status
27936
27937 @subsubheading Synopsis
27938
27939 @smallexample
27940 -target-exec-status
27941 @end smallexample
27942
27943 Provide information on the state of the target (whether it is running or
27944 not, for instance).
27945
27946 @subsubheading @value{GDBN} Command
27947
27948 There's no equivalent @value{GDBN} command.
27949
27950 @subsubheading Example
27951 N.A.
27952
27953
27954 @subheading The @code{-target-list-available-targets} Command
27955 @findex -target-list-available-targets
27956
27957 @subsubheading Synopsis
27958
27959 @smallexample
27960 -target-list-available-targets
27961 @end smallexample
27962
27963 List the possible targets to connect to.
27964
27965 @subsubheading @value{GDBN} Command
27966
27967 The corresponding @value{GDBN} command is @samp{help target}.
27968
27969 @subsubheading Example
27970 N.A.
27971
27972
27973 @subheading The @code{-target-list-current-targets} Command
27974 @findex -target-list-current-targets
27975
27976 @subsubheading Synopsis
27977
27978 @smallexample
27979 -target-list-current-targets
27980 @end smallexample
27981
27982 Describe the current target.
27983
27984 @subsubheading @value{GDBN} Command
27985
27986 The corresponding information is printed by @samp{info file} (among
27987 other things).
27988
27989 @subsubheading Example
27990 N.A.
27991
27992
27993 @subheading The @code{-target-list-parameters} Command
27994 @findex -target-list-parameters
27995
27996 @subsubheading Synopsis
27997
27998 @smallexample
27999 -target-list-parameters
28000 @end smallexample
28001
28002 @c ????
28003 @end ignore
28004
28005 @subsubheading @value{GDBN} Command
28006
28007 No equivalent.
28008
28009 @subsubheading Example
28010 N.A.
28011
28012
28013 @subheading The @code{-target-select} Command
28014 @findex -target-select
28015
28016 @subsubheading Synopsis
28017
28018 @smallexample
28019 -target-select @var{type} @var{parameters @dots{}}
28020 @end smallexample
28021
28022 Connect @value{GDBN} to the remote target. This command takes two args:
28023
28024 @table @samp
28025 @item @var{type}
28026 The type of target, for instance @samp{remote}, etc.
28027 @item @var{parameters}
28028 Device names, host names and the like. @xref{Target Commands, ,
28029 Commands for Managing Targets}, for more details.
28030 @end table
28031
28032 The output is a connection notification, followed by the address at
28033 which the target program is, in the following form:
28034
28035 @smallexample
28036 ^connected,addr="@var{address}",func="@var{function name}",
28037 args=[@var{arg list}]
28038 @end smallexample
28039
28040 @subsubheading @value{GDBN} Command
28041
28042 The corresponding @value{GDBN} command is @samp{target}.
28043
28044 @subsubheading Example
28045
28046 @smallexample
28047 (gdb)
28048 -target-select remote /dev/ttya
28049 ^connected,addr="0xfe00a300",func="??",args=[]
28050 (gdb)
28051 @end smallexample
28052
28053 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28054 @node GDB/MI File Transfer Commands
28055 @section @sc{gdb/mi} File Transfer Commands
28056
28057
28058 @subheading The @code{-target-file-put} Command
28059 @findex -target-file-put
28060
28061 @subsubheading Synopsis
28062
28063 @smallexample
28064 -target-file-put @var{hostfile} @var{targetfile}
28065 @end smallexample
28066
28067 Copy file @var{hostfile} from the host system (the machine running
28068 @value{GDBN}) to @var{targetfile} on the target system.
28069
28070 @subsubheading @value{GDBN} Command
28071
28072 The corresponding @value{GDBN} command is @samp{remote put}.
28073
28074 @subsubheading Example
28075
28076 @smallexample
28077 (gdb)
28078 -target-file-put localfile remotefile
28079 ^done
28080 (gdb)
28081 @end smallexample
28082
28083
28084 @subheading The @code{-target-file-get} Command
28085 @findex -target-file-get
28086
28087 @subsubheading Synopsis
28088
28089 @smallexample
28090 -target-file-get @var{targetfile} @var{hostfile}
28091 @end smallexample
28092
28093 Copy file @var{targetfile} from the target system to @var{hostfile}
28094 on the host system.
28095
28096 @subsubheading @value{GDBN} Command
28097
28098 The corresponding @value{GDBN} command is @samp{remote get}.
28099
28100 @subsubheading Example
28101
28102 @smallexample
28103 (gdb)
28104 -target-file-get remotefile localfile
28105 ^done
28106 (gdb)
28107 @end smallexample
28108
28109
28110 @subheading The @code{-target-file-delete} Command
28111 @findex -target-file-delete
28112
28113 @subsubheading Synopsis
28114
28115 @smallexample
28116 -target-file-delete @var{targetfile}
28117 @end smallexample
28118
28119 Delete @var{targetfile} from the target system.
28120
28121 @subsubheading @value{GDBN} Command
28122
28123 The corresponding @value{GDBN} command is @samp{remote delete}.
28124
28125 @subsubheading Example
28126
28127 @smallexample
28128 (gdb)
28129 -target-file-delete remotefile
28130 ^done
28131 (gdb)
28132 @end smallexample
28133
28134
28135 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28136 @node GDB/MI Miscellaneous Commands
28137 @section Miscellaneous @sc{gdb/mi} Commands
28138
28139 @c @subheading -gdb-complete
28140
28141 @subheading The @code{-gdb-exit} Command
28142 @findex -gdb-exit
28143
28144 @subsubheading Synopsis
28145
28146 @smallexample
28147 -gdb-exit
28148 @end smallexample
28149
28150 Exit @value{GDBN} immediately.
28151
28152 @subsubheading @value{GDBN} Command
28153
28154 Approximately corresponds to @samp{quit}.
28155
28156 @subsubheading Example
28157
28158 @smallexample
28159 (gdb)
28160 -gdb-exit
28161 ^exit
28162 @end smallexample
28163
28164
28165 @ignore
28166 @subheading The @code{-exec-abort} Command
28167 @findex -exec-abort
28168
28169 @subsubheading Synopsis
28170
28171 @smallexample
28172 -exec-abort
28173 @end smallexample
28174
28175 Kill the inferior running program.
28176
28177 @subsubheading @value{GDBN} Command
28178
28179 The corresponding @value{GDBN} command is @samp{kill}.
28180
28181 @subsubheading Example
28182 N.A.
28183 @end ignore
28184
28185
28186 @subheading The @code{-gdb-set} Command
28187 @findex -gdb-set
28188
28189 @subsubheading Synopsis
28190
28191 @smallexample
28192 -gdb-set
28193 @end smallexample
28194
28195 Set an internal @value{GDBN} variable.
28196 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
28197
28198 @subsubheading @value{GDBN} Command
28199
28200 The corresponding @value{GDBN} command is @samp{set}.
28201
28202 @subsubheading Example
28203
28204 @smallexample
28205 (gdb)
28206 -gdb-set $foo=3
28207 ^done
28208 (gdb)
28209 @end smallexample
28210
28211
28212 @subheading The @code{-gdb-show} Command
28213 @findex -gdb-show
28214
28215 @subsubheading Synopsis
28216
28217 @smallexample
28218 -gdb-show
28219 @end smallexample
28220
28221 Show the current value of a @value{GDBN} variable.
28222
28223 @subsubheading @value{GDBN} Command
28224
28225 The corresponding @value{GDBN} command is @samp{show}.
28226
28227 @subsubheading Example
28228
28229 @smallexample
28230 (gdb)
28231 -gdb-show annotate
28232 ^done,value="0"
28233 (gdb)
28234 @end smallexample
28235
28236 @c @subheading -gdb-source
28237
28238
28239 @subheading The @code{-gdb-version} Command
28240 @findex -gdb-version
28241
28242 @subsubheading Synopsis
28243
28244 @smallexample
28245 -gdb-version
28246 @end smallexample
28247
28248 Show version information for @value{GDBN}. Used mostly in testing.
28249
28250 @subsubheading @value{GDBN} Command
28251
28252 The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
28253 default shows this information when you start an interactive session.
28254
28255 @subsubheading Example
28256
28257 @c This example modifies the actual output from GDB to avoid overfull
28258 @c box in TeX.
28259 @smallexample
28260 (gdb)
28261 -gdb-version
28262 ~GNU gdb 5.2.1
28263 ~Copyright 2000 Free Software Foundation, Inc.
28264 ~GDB is free software, covered by the GNU General Public License, and
28265 ~you are welcome to change it and/or distribute copies of it under
28266 ~ certain conditions.
28267 ~Type "show copying" to see the conditions.
28268 ~There is absolutely no warranty for GDB. Type "show warranty" for
28269 ~ details.
28270 ~This GDB was configured as
28271 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
28272 ^done
28273 (gdb)
28274 @end smallexample
28275
28276 @subheading The @code{-list-features} Command
28277 @findex -list-features
28278
28279 Returns a list of particular features of the MI protocol that
28280 this version of gdb implements. A feature can be a command,
28281 or a new field in an output of some command, or even an
28282 important bugfix. While a frontend can sometimes detect presence
28283 of a feature at runtime, it is easier to perform detection at debugger
28284 startup.
28285
28286 The command returns a list of strings, with each string naming an
28287 available feature. Each returned string is just a name, it does not
28288 have any internal structure. The list of possible feature names
28289 is given below.
28290
28291 Example output:
28292
28293 @smallexample
28294 (gdb) -list-features
28295 ^done,result=["feature1","feature2"]
28296 @end smallexample
28297
28298 The current list of features is:
28299
28300 @table @samp
28301 @item frozen-varobjs
28302 Indicates presence of the @code{-var-set-frozen} command, as well
28303 as possible presense of the @code{frozen} field in the output
28304 of @code{-varobj-create}.
28305 @item pending-breakpoints
28306 Indicates presence of the @option{-f} option to the @code{-break-insert} command.
28307 @item python
28308 Indicates presence of Python scripting support, Python-based
28309 pretty-printing commands, and possible presence of the
28310 @samp{display_hint} field in the output of @code{-var-list-children}
28311 @item thread-info
28312 Indicates presence of the @code{-thread-info} command.
28313
28314 @end table
28315
28316 @subheading The @code{-list-target-features} Command
28317 @findex -list-target-features
28318
28319 Returns a list of particular features that are supported by the
28320 target. Those features affect the permitted MI commands, but
28321 unlike the features reported by the @code{-list-features} command, the
28322 features depend on which target GDB is using at the moment. Whenever
28323 a target can change, due to commands such as @code{-target-select},
28324 @code{-target-attach} or @code{-exec-run}, the list of target features
28325 may change, and the frontend should obtain it again.
28326 Example output:
28327
28328 @smallexample
28329 (gdb) -list-features
28330 ^done,result=["async"]
28331 @end smallexample
28332
28333 The current list of features is:
28334
28335 @table @samp
28336 @item async
28337 Indicates that the target is capable of asynchronous command
28338 execution, which means that @value{GDBN} will accept further commands
28339 while the target is running.
28340
28341 @end table
28342
28343 @subheading The @code{-list-thread-groups} Command
28344 @findex -list-thread-groups
28345
28346 @subheading Synopsis
28347
28348 @smallexample
28349 -list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
28350 @end smallexample
28351
28352 Lists thread groups (@pxref{Thread groups}). When a single thread
28353 group is passed as the argument, lists the children of that group.
28354 When several thread group are passed, lists information about those
28355 thread groups. Without any parameters, lists information about all
28356 top-level thread groups.
28357
28358 Normally, thread groups that are being debugged are reported.
28359 With the @samp{--available} option, @value{GDBN} reports thread groups
28360 available on the target.
28361
28362 The output of this command may have either a @samp{threads} result or
28363 a @samp{groups} result. The @samp{thread} result has a list of tuples
28364 as value, with each tuple describing a thread (@pxref{GDB/MI Thread
28365 Information}). The @samp{groups} result has a list of tuples as value,
28366 each tuple describing a thread group. If top-level groups are
28367 requested (that is, no parameter is passed), or when several groups
28368 are passed, the output always has a @samp{groups} result. The format
28369 of the @samp{group} result is described below.
28370
28371 To reduce the number of roundtrips it's possible to list thread groups
28372 together with their children, by passing the @samp{--recurse} option
28373 and the recursion depth. Presently, only recursion depth of 1 is
28374 permitted. If this option is present, then every reported thread group
28375 will also include its children, either as @samp{group} or
28376 @samp{threads} field.
28377
28378 In general, any combination of option and parameters is permitted, with
28379 the following caveats:
28380
28381 @itemize @bullet
28382 @item
28383 When a single thread group is passed, the output will typically
28384 be the @samp{threads} result. Because threads may not contain
28385 anything, the @samp{recurse} option will be ignored.
28386
28387 @item
28388 When the @samp{--available} option is passed, limited information may
28389 be available. In particular, the list of threads of a process might
28390 be inaccessible. Further, specifying specific thread groups might
28391 not give any performance advantage over listing all thread groups.
28392 The frontend should assume that @samp{-list-thread-groups --available}
28393 is always an expensive operation and cache the results.
28394
28395 @end itemize
28396
28397 The @samp{groups} result is a list of tuples, where each tuple may
28398 have the following fields:
28399
28400 @table @code
28401 @item id
28402 Identifier of the thread group. This field is always present.
28403 The identifier is an opaque string; frontends should not try to
28404 convert it to an integer, even though it might look like one.
28405
28406 @item type
28407 The type of the thread group. At present, only @samp{process} is a
28408 valid type.
28409
28410 @item pid
28411 The target-specific process identifier. This field is only present
28412 for thread groups of type @samp{process} and only if the process exists.
28413
28414 @item num_children
28415 The number of children this thread group has. This field may be
28416 absent for an available thread group.
28417
28418 @item threads
28419 This field has a list of tuples as value, each tuple describing a
28420 thread. It may be present if the @samp{--recurse} option is
28421 specified, and it's actually possible to obtain the threads.
28422
28423 @item cores
28424 This field is a list of integers, each identifying a core that one
28425 thread of the group is running on. This field may be absent if
28426 such information is not available.
28427
28428 @item executable
28429 The name of the executable file that corresponds to this thread group.
28430 The field is only present for thread groups of type @samp{process},
28431 and only if there is a corresponding executable file.
28432
28433 @end table
28434
28435 @subheading Example
28436
28437 @smallexample
28438 @value{GDBP}
28439 -list-thread-groups
28440 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
28441 -list-thread-groups 17
28442 ^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
28443 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
28444 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
28445 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
28446 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}]]
28447 -list-thread-groups --available
28448 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
28449 -list-thread-groups --available --recurse 1
28450 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
28451 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
28452 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
28453 -list-thread-groups --available --recurse 1 17 18
28454 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
28455 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
28456 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
28457 @end smallexample
28458
28459
28460 @subheading The @code{-add-inferior} Command
28461 @findex -add-inferior
28462
28463 @subheading Synopsis
28464
28465 @smallexample
28466 -add-inferior
28467 @end smallexample
28468
28469 Creates a new inferior (@pxref{Inferiors and Programs}). The created
28470 inferior is not associated with any executable. Such association may
28471 be established with the @samp{-file-exec-and-symbols} command
28472 (@pxref{GDB/MI File Commands}). The command response has a single
28473 field, @samp{thread-group}, whose value is the identifier of the
28474 thread group corresponding to the new inferior.
28475
28476 @subheading Example
28477
28478 @smallexample
28479 @value{GDBP}
28480 -add-inferior
28481 ^done,thread-group="i3"
28482 @end smallexample
28483
28484 @subheading The @code{-interpreter-exec} Command
28485 @findex -interpreter-exec
28486
28487 @subheading Synopsis
28488
28489 @smallexample
28490 -interpreter-exec @var{interpreter} @var{command}
28491 @end smallexample
28492 @anchor{-interpreter-exec}
28493
28494 Execute the specified @var{command} in the given @var{interpreter}.
28495
28496 @subheading @value{GDBN} Command
28497
28498 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
28499
28500 @subheading Example
28501
28502 @smallexample
28503 (gdb)
28504 -interpreter-exec console "break main"
28505 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
28506 &"During symbol reading, bad structure-type format.\n"
28507 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
28508 ^done
28509 (gdb)
28510 @end smallexample
28511
28512 @subheading The @code{-inferior-tty-set} Command
28513 @findex -inferior-tty-set
28514
28515 @subheading Synopsis
28516
28517 @smallexample
28518 -inferior-tty-set /dev/pts/1
28519 @end smallexample
28520
28521 Set terminal for future runs of the program being debugged.
28522
28523 @subheading @value{GDBN} Command
28524
28525 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
28526
28527 @subheading Example
28528
28529 @smallexample
28530 (gdb)
28531 -inferior-tty-set /dev/pts/1
28532 ^done
28533 (gdb)
28534 @end smallexample
28535
28536 @subheading The @code{-inferior-tty-show} Command
28537 @findex -inferior-tty-show
28538
28539 @subheading Synopsis
28540
28541 @smallexample
28542 -inferior-tty-show
28543 @end smallexample
28544
28545 Show terminal for future runs of program being debugged.
28546
28547 @subheading @value{GDBN} Command
28548
28549 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
28550
28551 @subheading Example
28552
28553 @smallexample
28554 (gdb)
28555 -inferior-tty-set /dev/pts/1
28556 ^done
28557 (gdb)
28558 -inferior-tty-show
28559 ^done,inferior_tty_terminal="/dev/pts/1"
28560 (gdb)
28561 @end smallexample
28562
28563 @subheading The @code{-enable-timings} Command
28564 @findex -enable-timings
28565
28566 @subheading Synopsis
28567
28568 @smallexample
28569 -enable-timings [yes | no]
28570 @end smallexample
28571
28572 Toggle the printing of the wallclock, user and system times for an MI
28573 command as a field in its output. This command is to help frontend
28574 developers optimize the performance of their code. No argument is
28575 equivalent to @samp{yes}.
28576
28577 @subheading @value{GDBN} Command
28578
28579 No equivalent.
28580
28581 @subheading Example
28582
28583 @smallexample
28584 (gdb)
28585 -enable-timings
28586 ^done
28587 (gdb)
28588 -break-insert main
28589 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
28590 addr="0x080484ed",func="main",file="myprog.c",
28591 fullname="/home/nickrob/myprog.c",line="73",times="0"@},
28592 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
28593 (gdb)
28594 -enable-timings no
28595 ^done
28596 (gdb)
28597 -exec-run
28598 ^running
28599 (gdb)
28600 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
28601 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
28602 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
28603 fullname="/home/nickrob/myprog.c",line="73"@}
28604 (gdb)
28605 @end smallexample
28606
28607 @node Annotations
28608 @chapter @value{GDBN} Annotations
28609
28610 This chapter describes annotations in @value{GDBN}. Annotations were
28611 designed to interface @value{GDBN} to graphical user interfaces or other
28612 similar programs which want to interact with @value{GDBN} at a
28613 relatively high level.
28614
28615 The annotation mechanism has largely been superseded by @sc{gdb/mi}
28616 (@pxref{GDB/MI}).
28617
28618 @ignore
28619 This is Edition @value{EDITION}, @value{DATE}.
28620 @end ignore
28621
28622 @menu
28623 * Annotations Overview:: What annotations are; the general syntax.
28624 * Server Prefix:: Issuing a command without affecting user state.
28625 * Prompting:: Annotations marking @value{GDBN}'s need for input.
28626 * Errors:: Annotations for error messages.
28627 * Invalidation:: Some annotations describe things now invalid.
28628 * Annotations for Running::
28629 Whether the program is running, how it stopped, etc.
28630 * Source Annotations:: Annotations describing source code.
28631 @end menu
28632
28633 @node Annotations Overview
28634 @section What is an Annotation?
28635 @cindex annotations
28636
28637 Annotations start with a newline character, two @samp{control-z}
28638 characters, and the name of the annotation. If there is no additional
28639 information associated with this annotation, the name of the annotation
28640 is followed immediately by a newline. If there is additional
28641 information, the name of the annotation is followed by a space, the
28642 additional information, and a newline. The additional information
28643 cannot contain newline characters.
28644
28645 Any output not beginning with a newline and two @samp{control-z}
28646 characters denotes literal output from @value{GDBN}. Currently there is
28647 no need for @value{GDBN} to output a newline followed by two
28648 @samp{control-z} characters, but if there was such a need, the
28649 annotations could be extended with an @samp{escape} annotation which
28650 means those three characters as output.
28651
28652 The annotation @var{level}, which is specified using the
28653 @option{--annotate} command line option (@pxref{Mode Options}), controls
28654 how much information @value{GDBN} prints together with its prompt,
28655 values of expressions, source lines, and other types of output. Level 0
28656 is for no annotations, level 1 is for use when @value{GDBN} is run as a
28657 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
28658 for programs that control @value{GDBN}, and level 2 annotations have
28659 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
28660 Interface, annotate, GDB's Obsolete Annotations}).
28661
28662 @table @code
28663 @kindex set annotate
28664 @item set annotate @var{level}
28665 The @value{GDBN} command @code{set annotate} sets the level of
28666 annotations to the specified @var{level}.
28667
28668 @item show annotate
28669 @kindex show annotate
28670 Show the current annotation level.
28671 @end table
28672
28673 This chapter describes level 3 annotations.
28674
28675 A simple example of starting up @value{GDBN} with annotations is:
28676
28677 @smallexample
28678 $ @kbd{gdb --annotate=3}
28679 GNU gdb 6.0
28680 Copyright 2003 Free Software Foundation, Inc.
28681 GDB is free software, covered by the GNU General Public License,
28682 and you are welcome to change it and/or distribute copies of it
28683 under certain conditions.
28684 Type "show copying" to see the conditions.
28685 There is absolutely no warranty for GDB. Type "show warranty"
28686 for details.
28687 This GDB was configured as "i386-pc-linux-gnu"
28688
28689 ^Z^Zpre-prompt
28690 (@value{GDBP})
28691 ^Z^Zprompt
28692 @kbd{quit}
28693
28694 ^Z^Zpost-prompt
28695 $
28696 @end smallexample
28697
28698 Here @samp{quit} is input to @value{GDBN}; the rest is output from
28699 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
28700 denotes a @samp{control-z} character) are annotations; the rest is
28701 output from @value{GDBN}.
28702
28703 @node Server Prefix
28704 @section The Server Prefix
28705 @cindex server prefix
28706
28707 If you prefix a command with @samp{server } then it will not affect
28708 the command history, nor will it affect @value{GDBN}'s notion of which
28709 command to repeat if @key{RET} is pressed on a line by itself. This
28710 means that commands can be run behind a user's back by a front-end in
28711 a transparent manner.
28712
28713 The @code{server } prefix does not affect the recording of values into
28714 the value history; to print a value without recording it into the
28715 value history, use the @code{output} command instead of the
28716 @code{print} command.
28717
28718 Using this prefix also disables confirmation requests
28719 (@pxref{confirmation requests}).
28720
28721 @node Prompting
28722 @section Annotation for @value{GDBN} Input
28723
28724 @cindex annotations for prompts
28725 When @value{GDBN} prompts for input, it annotates this fact so it is possible
28726 to know when to send output, when the output from a given command is
28727 over, etc.
28728
28729 Different kinds of input each have a different @dfn{input type}. Each
28730 input type has three annotations: a @code{pre-} annotation, which
28731 denotes the beginning of any prompt which is being output, a plain
28732 annotation, which denotes the end of the prompt, and then a @code{post-}
28733 annotation which denotes the end of any echo which may (or may not) be
28734 associated with the input. For example, the @code{prompt} input type
28735 features the following annotations:
28736
28737 @smallexample
28738 ^Z^Zpre-prompt
28739 ^Z^Zprompt
28740 ^Z^Zpost-prompt
28741 @end smallexample
28742
28743 The input types are
28744
28745 @table @code
28746 @findex pre-prompt annotation
28747 @findex prompt annotation
28748 @findex post-prompt annotation
28749 @item prompt
28750 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
28751
28752 @findex pre-commands annotation
28753 @findex commands annotation
28754 @findex post-commands annotation
28755 @item commands
28756 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
28757 command. The annotations are repeated for each command which is input.
28758
28759 @findex pre-overload-choice annotation
28760 @findex overload-choice annotation
28761 @findex post-overload-choice annotation
28762 @item overload-choice
28763 When @value{GDBN} wants the user to select between various overloaded functions.
28764
28765 @findex pre-query annotation
28766 @findex query annotation
28767 @findex post-query annotation
28768 @item query
28769 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
28770
28771 @findex pre-prompt-for-continue annotation
28772 @findex prompt-for-continue annotation
28773 @findex post-prompt-for-continue annotation
28774 @item prompt-for-continue
28775 When @value{GDBN} is asking the user to press return to continue. Note: Don't
28776 expect this to work well; instead use @code{set height 0} to disable
28777 prompting. This is because the counting of lines is buggy in the
28778 presence of annotations.
28779 @end table
28780
28781 @node Errors
28782 @section Errors
28783 @cindex annotations for errors, warnings and interrupts
28784
28785 @findex quit annotation
28786 @smallexample
28787 ^Z^Zquit
28788 @end smallexample
28789
28790 This annotation occurs right before @value{GDBN} responds to an interrupt.
28791
28792 @findex error annotation
28793 @smallexample
28794 ^Z^Zerror
28795 @end smallexample
28796
28797 This annotation occurs right before @value{GDBN} responds to an error.
28798
28799 Quit and error annotations indicate that any annotations which @value{GDBN} was
28800 in the middle of may end abruptly. For example, if a
28801 @code{value-history-begin} annotation is followed by a @code{error}, one
28802 cannot expect to receive the matching @code{value-history-end}. One
28803 cannot expect not to receive it either, however; an error annotation
28804 does not necessarily mean that @value{GDBN} is immediately returning all the way
28805 to the top level.
28806
28807 @findex error-begin annotation
28808 A quit or error annotation may be preceded by
28809
28810 @smallexample
28811 ^Z^Zerror-begin
28812 @end smallexample
28813
28814 Any output between that and the quit or error annotation is the error
28815 message.
28816
28817 Warning messages are not yet annotated.
28818 @c If we want to change that, need to fix warning(), type_error(),
28819 @c range_error(), and possibly other places.
28820
28821 @node Invalidation
28822 @section Invalidation Notices
28823
28824 @cindex annotations for invalidation messages
28825 The following annotations say that certain pieces of state may have
28826 changed.
28827
28828 @table @code
28829 @findex frames-invalid annotation
28830 @item ^Z^Zframes-invalid
28831
28832 The frames (for example, output from the @code{backtrace} command) may
28833 have changed.
28834
28835 @findex breakpoints-invalid annotation
28836 @item ^Z^Zbreakpoints-invalid
28837
28838 The breakpoints may have changed. For example, the user just added or
28839 deleted a breakpoint.
28840 @end table
28841
28842 @node Annotations for Running
28843 @section Running the Program
28844 @cindex annotations for running programs
28845
28846 @findex starting annotation
28847 @findex stopping annotation
28848 When the program starts executing due to a @value{GDBN} command such as
28849 @code{step} or @code{continue},
28850
28851 @smallexample
28852 ^Z^Zstarting
28853 @end smallexample
28854
28855 is output. When the program stops,
28856
28857 @smallexample
28858 ^Z^Zstopped
28859 @end smallexample
28860
28861 is output. Before the @code{stopped} annotation, a variety of
28862 annotations describe how the program stopped.
28863
28864 @table @code
28865 @findex exited annotation
28866 @item ^Z^Zexited @var{exit-status}
28867 The program exited, and @var{exit-status} is the exit status (zero for
28868 successful exit, otherwise nonzero).
28869
28870 @findex signalled annotation
28871 @findex signal-name annotation
28872 @findex signal-name-end annotation
28873 @findex signal-string annotation
28874 @findex signal-string-end annotation
28875 @item ^Z^Zsignalled
28876 The program exited with a signal. After the @code{^Z^Zsignalled}, the
28877 annotation continues:
28878
28879 @smallexample
28880 @var{intro-text}
28881 ^Z^Zsignal-name
28882 @var{name}
28883 ^Z^Zsignal-name-end
28884 @var{middle-text}
28885 ^Z^Zsignal-string
28886 @var{string}
28887 ^Z^Zsignal-string-end
28888 @var{end-text}
28889 @end smallexample
28890
28891 @noindent
28892 where @var{name} is the name of the signal, such as @code{SIGILL} or
28893 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
28894 as @code{Illegal Instruction} or @code{Segmentation fault}.
28895 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
28896 user's benefit and have no particular format.
28897
28898 @findex signal annotation
28899 @item ^Z^Zsignal
28900 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
28901 just saying that the program received the signal, not that it was
28902 terminated with it.
28903
28904 @findex breakpoint annotation
28905 @item ^Z^Zbreakpoint @var{number}
28906 The program hit breakpoint number @var{number}.
28907
28908 @findex watchpoint annotation
28909 @item ^Z^Zwatchpoint @var{number}
28910 The program hit watchpoint number @var{number}.
28911 @end table
28912
28913 @node Source Annotations
28914 @section Displaying Source
28915 @cindex annotations for source display
28916
28917 @findex source annotation
28918 The following annotation is used instead of displaying source code:
28919
28920 @smallexample
28921 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
28922 @end smallexample
28923
28924 where @var{filename} is an absolute file name indicating which source
28925 file, @var{line} is the line number within that file (where 1 is the
28926 first line in the file), @var{character} is the character position
28927 within the file (where 0 is the first character in the file) (for most
28928 debug formats this will necessarily point to the beginning of a line),
28929 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
28930 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
28931 @var{addr} is the address in the target program associated with the
28932 source which is being displayed. @var{addr} is in the form @samp{0x}
28933 followed by one or more lowercase hex digits (note that this does not
28934 depend on the language).
28935
28936 @node JIT Interface
28937 @chapter JIT Compilation Interface
28938 @cindex just-in-time compilation
28939 @cindex JIT compilation interface
28940
28941 This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
28942 interface. A JIT compiler is a program or library that generates native
28943 executable code at runtime and executes it, usually in order to achieve good
28944 performance while maintaining platform independence.
28945
28946 Programs that use JIT compilation are normally difficult to debug because
28947 portions of their code are generated at runtime, instead of being loaded from
28948 object files, which is where @value{GDBN} normally finds the program's symbols
28949 and debug information. In order to debug programs that use JIT compilation,
28950 @value{GDBN} has an interface that allows the program to register in-memory
28951 symbol files with @value{GDBN} at runtime.
28952
28953 If you are using @value{GDBN} to debug a program that uses this interface, then
28954 it should work transparently so long as you have not stripped the binary. If
28955 you are developing a JIT compiler, then the interface is documented in the rest
28956 of this chapter. At this time, the only known client of this interface is the
28957 LLVM JIT.
28958
28959 Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
28960 JIT compiler communicates with @value{GDBN} by writing data into a global
28961 variable and calling a fuction at a well-known symbol. When @value{GDBN}
28962 attaches, it reads a linked list of symbol files from the global variable to
28963 find existing code, and puts a breakpoint in the function so that it can find
28964 out about additional code.
28965
28966 @menu
28967 * Declarations:: Relevant C struct declarations
28968 * Registering Code:: Steps to register code
28969 * Unregistering Code:: Steps to unregister code
28970 @end menu
28971
28972 @node Declarations
28973 @section JIT Declarations
28974
28975 These are the relevant struct declarations that a C program should include to
28976 implement the interface:
28977
28978 @smallexample
28979 typedef enum
28980 @{
28981 JIT_NOACTION = 0,
28982 JIT_REGISTER_FN,
28983 JIT_UNREGISTER_FN
28984 @} jit_actions_t;
28985
28986 struct jit_code_entry
28987 @{
28988 struct jit_code_entry *next_entry;
28989 struct jit_code_entry *prev_entry;
28990 const char *symfile_addr;
28991 uint64_t symfile_size;
28992 @};
28993
28994 struct jit_descriptor
28995 @{
28996 uint32_t version;
28997 /* This type should be jit_actions_t, but we use uint32_t
28998 to be explicit about the bitwidth. */
28999 uint32_t action_flag;
29000 struct jit_code_entry *relevant_entry;
29001 struct jit_code_entry *first_entry;
29002 @};
29003
29004 /* GDB puts a breakpoint in this function. */
29005 void __attribute__((noinline)) __jit_debug_register_code() @{ @};
29006
29007 /* Make sure to specify the version statically, because the
29008 debugger may check the version before we can set it. */
29009 struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
29010 @end smallexample
29011
29012 If the JIT is multi-threaded, then it is important that the JIT synchronize any
29013 modifications to this global data properly, which can easily be done by putting
29014 a global mutex around modifications to these structures.
29015
29016 @node Registering Code
29017 @section Registering Code
29018
29019 To register code with @value{GDBN}, the JIT should follow this protocol:
29020
29021 @itemize @bullet
29022 @item
29023 Generate an object file in memory with symbols and other desired debug
29024 information. The file must include the virtual addresses of the sections.
29025
29026 @item
29027 Create a code entry for the file, which gives the start and size of the symbol
29028 file.
29029
29030 @item
29031 Add it to the linked list in the JIT descriptor.
29032
29033 @item
29034 Point the relevant_entry field of the descriptor at the entry.
29035
29036 @item
29037 Set @code{action_flag} to @code{JIT_REGISTER} and call
29038 @code{__jit_debug_register_code}.
29039 @end itemize
29040
29041 When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
29042 @code{relevant_entry} pointer so it doesn't have to walk the list looking for
29043 new code. However, the linked list must still be maintained in order to allow
29044 @value{GDBN} to attach to a running process and still find the symbol files.
29045
29046 @node Unregistering Code
29047 @section Unregistering Code
29048
29049 If code is freed, then the JIT should use the following protocol:
29050
29051 @itemize @bullet
29052 @item
29053 Remove the code entry corresponding to the code from the linked list.
29054
29055 @item
29056 Point the @code{relevant_entry} field of the descriptor at the code entry.
29057
29058 @item
29059 Set @code{action_flag} to @code{JIT_UNREGISTER} and call
29060 @code{__jit_debug_register_code}.
29061 @end itemize
29062
29063 If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
29064 and the JIT will leak the memory used for the associated symbol files.
29065
29066 @node GDB Bugs
29067 @chapter Reporting Bugs in @value{GDBN}
29068 @cindex bugs in @value{GDBN}
29069 @cindex reporting bugs in @value{GDBN}
29070
29071 Your bug reports play an essential role in making @value{GDBN} reliable.
29072
29073 Reporting a bug may help you by bringing a solution to your problem, or it
29074 may not. But in any case the principal function of a bug report is to help
29075 the entire community by making the next version of @value{GDBN} work better. Bug
29076 reports are your contribution to the maintenance of @value{GDBN}.
29077
29078 In order for a bug report to serve its purpose, you must include the
29079 information that enables us to fix the bug.
29080
29081 @menu
29082 * Bug Criteria:: Have you found a bug?
29083 * Bug Reporting:: How to report bugs
29084 @end menu
29085
29086 @node Bug Criteria
29087 @section Have You Found a Bug?
29088 @cindex bug criteria
29089
29090 If you are not sure whether you have found a bug, here are some guidelines:
29091
29092 @itemize @bullet
29093 @cindex fatal signal
29094 @cindex debugger crash
29095 @cindex crash of debugger
29096 @item
29097 If the debugger gets a fatal signal, for any input whatever, that is a
29098 @value{GDBN} bug. Reliable debuggers never crash.
29099
29100 @cindex error on valid input
29101 @item
29102 If @value{GDBN} produces an error message for valid input, that is a
29103 bug. (Note that if you're cross debugging, the problem may also be
29104 somewhere in the connection to the target.)
29105
29106 @cindex invalid input
29107 @item
29108 If @value{GDBN} does not produce an error message for invalid input,
29109 that is a bug. However, you should note that your idea of
29110 ``invalid input'' might be our idea of ``an extension'' or ``support
29111 for traditional practice''.
29112
29113 @item
29114 If you are an experienced user of debugging tools, your suggestions
29115 for improvement of @value{GDBN} are welcome in any case.
29116 @end itemize
29117
29118 @node Bug Reporting
29119 @section How to Report Bugs
29120 @cindex bug reports
29121 @cindex @value{GDBN} bugs, reporting
29122
29123 A number of companies and individuals offer support for @sc{gnu} products.
29124 If you obtained @value{GDBN} from a support organization, we recommend you
29125 contact that organization first.
29126
29127 You can find contact information for many support companies and
29128 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
29129 distribution.
29130 @c should add a web page ref...
29131
29132 @ifset BUGURL
29133 @ifset BUGURL_DEFAULT
29134 In any event, we also recommend that you submit bug reports for
29135 @value{GDBN}. The preferred method is to submit them directly using
29136 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
29137 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
29138 be used.
29139
29140 @strong{Do not send bug reports to @samp{info-gdb}, or to
29141 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
29142 not want to receive bug reports. Those that do have arranged to receive
29143 @samp{bug-gdb}.
29144
29145 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
29146 serves as a repeater. The mailing list and the newsgroup carry exactly
29147 the same messages. Often people think of posting bug reports to the
29148 newsgroup instead of mailing them. This appears to work, but it has one
29149 problem which can be crucial: a newsgroup posting often lacks a mail
29150 path back to the sender. Thus, if we need to ask for more information,
29151 we may be unable to reach you. For this reason, it is better to send
29152 bug reports to the mailing list.
29153 @end ifset
29154 @ifclear BUGURL_DEFAULT
29155 In any event, we also recommend that you submit bug reports for
29156 @value{GDBN} to @value{BUGURL}.
29157 @end ifclear
29158 @end ifset
29159
29160 The fundamental principle of reporting bugs usefully is this:
29161 @strong{report all the facts}. If you are not sure whether to state a
29162 fact or leave it out, state it!
29163
29164 Often people omit facts because they think they know what causes the
29165 problem and assume that some details do not matter. Thus, you might
29166 assume that the name of the variable you use in an example does not matter.
29167 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
29168 stray memory reference which happens to fetch from the location where that
29169 name is stored in memory; perhaps, if the name were different, the contents
29170 of that location would fool the debugger into doing the right thing despite
29171 the bug. Play it safe and give a specific, complete example. That is the
29172 easiest thing for you to do, and the most helpful.
29173
29174 Keep in mind that the purpose of a bug report is to enable us to fix the
29175 bug. It may be that the bug has been reported previously, but neither
29176 you nor we can know that unless your bug report is complete and
29177 self-contained.
29178
29179 Sometimes people give a few sketchy facts and ask, ``Does this ring a
29180 bell?'' Those bug reports are useless, and we urge everyone to
29181 @emph{refuse to respond to them} except to chide the sender to report
29182 bugs properly.
29183
29184 To enable us to fix the bug, you should include all these things:
29185
29186 @itemize @bullet
29187 @item
29188 The version of @value{GDBN}. @value{GDBN} announces it if you start
29189 with no arguments; you can also print it at any time using @code{show
29190 version}.
29191
29192 Without this, we will not know whether there is any point in looking for
29193 the bug in the current version of @value{GDBN}.
29194
29195 @item
29196 The type of machine you are using, and the operating system name and
29197 version number.
29198
29199 @item
29200 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
29201 ``@value{GCC}--2.8.1''.
29202
29203 @item
29204 What compiler (and its version) was used to compile the program you are
29205 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
29206 C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
29207 to get this information; for other compilers, see the documentation for
29208 those compilers.
29209
29210 @item
29211 The command arguments you gave the compiler to compile your example and
29212 observe the bug. For example, did you use @samp{-O}? To guarantee
29213 you will not omit something important, list them all. A copy of the
29214 Makefile (or the output from make) is sufficient.
29215
29216 If we were to try to guess the arguments, we would probably guess wrong
29217 and then we might not encounter the bug.
29218
29219 @item
29220 A complete input script, and all necessary source files, that will
29221 reproduce the bug.
29222
29223 @item
29224 A description of what behavior you observe that you believe is
29225 incorrect. For example, ``It gets a fatal signal.''
29226
29227 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
29228 will certainly notice it. But if the bug is incorrect output, we might
29229 not notice unless it is glaringly wrong. You might as well not give us
29230 a chance to make a mistake.
29231
29232 Even if the problem you experience is a fatal signal, you should still
29233 say so explicitly. Suppose something strange is going on, such as, your
29234 copy of @value{GDBN} is out of synch, or you have encountered a bug in
29235 the C library on your system. (This has happened!) Your copy might
29236 crash and ours would not. If you told us to expect a crash, then when
29237 ours fails to crash, we would know that the bug was not happening for
29238 us. If you had not told us to expect a crash, then we would not be able
29239 to draw any conclusion from our observations.
29240
29241 @pindex script
29242 @cindex recording a session script
29243 To collect all this information, you can use a session recording program
29244 such as @command{script}, which is available on many Unix systems.
29245 Just run your @value{GDBN} session inside @command{script} and then
29246 include the @file{typescript} file with your bug report.
29247
29248 Another way to record a @value{GDBN} session is to run @value{GDBN}
29249 inside Emacs and then save the entire buffer to a file.
29250
29251 @item
29252 If you wish to suggest changes to the @value{GDBN} source, send us context
29253 diffs. If you even discuss something in the @value{GDBN} source, refer to
29254 it by context, not by line number.
29255
29256 The line numbers in our development sources will not match those in your
29257 sources. Your line numbers would convey no useful information to us.
29258
29259 @end itemize
29260
29261 Here are some things that are not necessary:
29262
29263 @itemize @bullet
29264 @item
29265 A description of the envelope of the bug.
29266
29267 Often people who encounter a bug spend a lot of time investigating
29268 which changes to the input file will make the bug go away and which
29269 changes will not affect it.
29270
29271 This is often time consuming and not very useful, because the way we
29272 will find the bug is by running a single example under the debugger
29273 with breakpoints, not by pure deduction from a series of examples.
29274 We recommend that you save your time for something else.
29275
29276 Of course, if you can find a simpler example to report @emph{instead}
29277 of the original one, that is a convenience for us. Errors in the
29278 output will be easier to spot, running under the debugger will take
29279 less time, and so on.
29280
29281 However, simplification is not vital; if you do not want to do this,
29282 report the bug anyway and send us the entire test case you used.
29283
29284 @item
29285 A patch for the bug.
29286
29287 A patch for the bug does help us if it is a good one. But do not omit
29288 the necessary information, such as the test case, on the assumption that
29289 a patch is all we need. We might see problems with your patch and decide
29290 to fix the problem another way, or we might not understand it at all.
29291
29292 Sometimes with a program as complicated as @value{GDBN} it is very hard to
29293 construct an example that will make the program follow a certain path
29294 through the code. If you do not send us the example, we will not be able
29295 to construct one, so we will not be able to verify that the bug is fixed.
29296
29297 And if we cannot understand what bug you are trying to fix, or why your
29298 patch should be an improvement, we will not install it. A test case will
29299 help us to understand.
29300
29301 @item
29302 A guess about what the bug is or what it depends on.
29303
29304 Such guesses are usually wrong. Even we cannot guess right about such
29305 things without first using the debugger to find the facts.
29306 @end itemize
29307
29308 @c The readline documentation is distributed with the readline code
29309 @c and consists of the two following files:
29310 @c rluser.texinfo
29311 @c inc-hist.texinfo
29312 @c Use -I with makeinfo to point to the appropriate directory,
29313 @c environment var TEXINPUTS with TeX.
29314 @include rluser.texi
29315 @include inc-hist.texinfo
29316
29317
29318 @node Formatting Documentation
29319 @appendix Formatting Documentation
29320
29321 @cindex @value{GDBN} reference card
29322 @cindex reference card
29323 The @value{GDBN} 4 release includes an already-formatted reference card, ready
29324 for printing with PostScript or Ghostscript, in the @file{gdb}
29325 subdirectory of the main source directory@footnote{In
29326 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
29327 release.}. If you can use PostScript or Ghostscript with your printer,
29328 you can print the reference card immediately with @file{refcard.ps}.
29329
29330 The release also includes the source for the reference card. You
29331 can format it, using @TeX{}, by typing:
29332
29333 @smallexample
29334 make refcard.dvi
29335 @end smallexample
29336
29337 The @value{GDBN} reference card is designed to print in @dfn{landscape}
29338 mode on US ``letter'' size paper;
29339 that is, on a sheet 11 inches wide by 8.5 inches
29340 high. You will need to specify this form of printing as an option to
29341 your @sc{dvi} output program.
29342
29343 @cindex documentation
29344
29345 All the documentation for @value{GDBN} comes as part of the machine-readable
29346 distribution. The documentation is written in Texinfo format, which is
29347 a documentation system that uses a single source file to produce both
29348 on-line information and a printed manual. You can use one of the Info
29349 formatting commands to create the on-line version of the documentation
29350 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
29351
29352 @value{GDBN} includes an already formatted copy of the on-line Info
29353 version of this manual in the @file{gdb} subdirectory. The main Info
29354 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
29355 subordinate files matching @samp{gdb.info*} in the same directory. If
29356 necessary, you can print out these files, or read them with any editor;
29357 but they are easier to read using the @code{info} subsystem in @sc{gnu}
29358 Emacs or the standalone @code{info} program, available as part of the
29359 @sc{gnu} Texinfo distribution.
29360
29361 If you want to format these Info files yourself, you need one of the
29362 Info formatting programs, such as @code{texinfo-format-buffer} or
29363 @code{makeinfo}.
29364
29365 If you have @code{makeinfo} installed, and are in the top level
29366 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
29367 version @value{GDBVN}), you can make the Info file by typing:
29368
29369 @smallexample
29370 cd gdb
29371 make gdb.info
29372 @end smallexample
29373
29374 If you want to typeset and print copies of this manual, you need @TeX{},
29375 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
29376 Texinfo definitions file.
29377
29378 @TeX{} is a typesetting program; it does not print files directly, but
29379 produces output files called @sc{dvi} files. To print a typeset
29380 document, you need a program to print @sc{dvi} files. If your system
29381 has @TeX{} installed, chances are it has such a program. The precise
29382 command to use depends on your system; @kbd{lpr -d} is common; another
29383 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
29384 require a file name without any extension or a @samp{.dvi} extension.
29385
29386 @TeX{} also requires a macro definitions file called
29387 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
29388 written in Texinfo format. On its own, @TeX{} cannot either read or
29389 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
29390 and is located in the @file{gdb-@var{version-number}/texinfo}
29391 directory.
29392
29393 If you have @TeX{} and a @sc{dvi} printer program installed, you can
29394 typeset and print this manual. First switch to the @file{gdb}
29395 subdirectory of the main source directory (for example, to
29396 @file{gdb-@value{GDBVN}/gdb}) and type:
29397
29398 @smallexample
29399 make gdb.dvi
29400 @end smallexample
29401
29402 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
29403
29404 @node Installing GDB
29405 @appendix Installing @value{GDBN}
29406 @cindex installation
29407
29408 @menu
29409 * Requirements:: Requirements for building @value{GDBN}
29410 * Running Configure:: Invoking the @value{GDBN} @file{configure} script
29411 * Separate Objdir:: Compiling @value{GDBN} in another directory
29412 * Config Names:: Specifying names for hosts and targets
29413 * Configure Options:: Summary of options for configure
29414 * System-wide configuration:: Having a system-wide init file
29415 @end menu
29416
29417 @node Requirements
29418 @section Requirements for Building @value{GDBN}
29419 @cindex building @value{GDBN}, requirements for
29420
29421 Building @value{GDBN} requires various tools and packages to be available.
29422 Other packages will be used only if they are found.
29423
29424 @heading Tools/Packages Necessary for Building @value{GDBN}
29425 @table @asis
29426 @item ISO C90 compiler
29427 @value{GDBN} is written in ISO C90. It should be buildable with any
29428 working C90 compiler, e.g.@: GCC.
29429
29430 @end table
29431
29432 @heading Tools/Packages Optional for Building @value{GDBN}
29433 @table @asis
29434 @item Expat
29435 @anchor{Expat}
29436 @value{GDBN} can use the Expat XML parsing library. This library may be
29437 included with your operating system distribution; if it is not, you
29438 can get the latest version from @url{http://expat.sourceforge.net}.
29439 The @file{configure} script will search for this library in several
29440 standard locations; if it is installed in an unusual path, you can
29441 use the @option{--with-libexpat-prefix} option to specify its location.
29442
29443 Expat is used for:
29444
29445 @itemize @bullet
29446 @item
29447 Remote protocol memory maps (@pxref{Memory Map Format})
29448 @item
29449 Target descriptions (@pxref{Target Descriptions})
29450 @item
29451 Remote shared library lists (@pxref{Library List Format})
29452 @item
29453 MS-Windows shared libraries (@pxref{Shared Libraries})
29454 @end itemize
29455
29456 @item zlib
29457 @cindex compressed debug sections
29458 @value{GDBN} will use the @samp{zlib} library, if available, to read
29459 compressed debug sections. Some linkers, such as GNU gold, are capable
29460 of producing binaries with compressed debug sections. If @value{GDBN}
29461 is compiled with @samp{zlib}, it will be able to read the debug
29462 information in such binaries.
29463
29464 The @samp{zlib} library is likely included with your operating system
29465 distribution; if it is not, you can get the latest version from
29466 @url{http://zlib.net}.
29467
29468 @item iconv
29469 @value{GDBN}'s features related to character sets (@pxref{Character
29470 Sets}) require a functioning @code{iconv} implementation. If you are
29471 on a GNU system, then this is provided by the GNU C Library. Some
29472 other systems also provide a working @code{iconv}.
29473
29474 On systems with @code{iconv}, you can install GNU Libiconv. If you
29475 have previously installed Libiconv, you can use the
29476 @option{--with-libiconv-prefix} option to configure.
29477
29478 @value{GDBN}'s top-level @file{configure} and @file{Makefile} will
29479 arrange to build Libiconv if a directory named @file{libiconv} appears
29480 in the top-most source directory. If Libiconv is built this way, and
29481 if the operating system does not provide a suitable @code{iconv}
29482 implementation, then the just-built library will automatically be used
29483 by @value{GDBN}. One easy way to set this up is to download GNU
29484 Libiconv, unpack it, and then rename the directory holding the
29485 Libiconv source code to @samp{libiconv}.
29486 @end table
29487
29488 @node Running Configure
29489 @section Invoking the @value{GDBN} @file{configure} Script
29490 @cindex configuring @value{GDBN}
29491 @value{GDBN} comes with a @file{configure} script that automates the process
29492 of preparing @value{GDBN} for installation; you can then use @code{make} to
29493 build the @code{gdb} program.
29494 @iftex
29495 @c irrelevant in info file; it's as current as the code it lives with.
29496 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
29497 look at the @file{README} file in the sources; we may have improved the
29498 installation procedures since publishing this manual.}
29499 @end iftex
29500
29501 The @value{GDBN} distribution includes all the source code you need for
29502 @value{GDBN} in a single directory, whose name is usually composed by
29503 appending the version number to @samp{gdb}.
29504
29505 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
29506 @file{gdb-@value{GDBVN}} directory. That directory contains:
29507
29508 @table @code
29509 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
29510 script for configuring @value{GDBN} and all its supporting libraries
29511
29512 @item gdb-@value{GDBVN}/gdb
29513 the source specific to @value{GDBN} itself
29514
29515 @item gdb-@value{GDBVN}/bfd
29516 source for the Binary File Descriptor library
29517
29518 @item gdb-@value{GDBVN}/include
29519 @sc{gnu} include files
29520
29521 @item gdb-@value{GDBVN}/libiberty
29522 source for the @samp{-liberty} free software library
29523
29524 @item gdb-@value{GDBVN}/opcodes
29525 source for the library of opcode tables and disassemblers
29526
29527 @item gdb-@value{GDBVN}/readline
29528 source for the @sc{gnu} command-line interface
29529
29530 @item gdb-@value{GDBVN}/glob
29531 source for the @sc{gnu} filename pattern-matching subroutine
29532
29533 @item gdb-@value{GDBVN}/mmalloc
29534 source for the @sc{gnu} memory-mapped malloc package
29535 @end table
29536
29537 The simplest way to configure and build @value{GDBN} is to run @file{configure}
29538 from the @file{gdb-@var{version-number}} source directory, which in
29539 this example is the @file{gdb-@value{GDBVN}} directory.
29540
29541 First switch to the @file{gdb-@var{version-number}} source directory
29542 if you are not already in it; then run @file{configure}. Pass the
29543 identifier for the platform on which @value{GDBN} will run as an
29544 argument.
29545
29546 For example:
29547
29548 @smallexample
29549 cd gdb-@value{GDBVN}
29550 ./configure @var{host}
29551 make
29552 @end smallexample
29553
29554 @noindent
29555 where @var{host} is an identifier such as @samp{sun4} or
29556 @samp{decstation}, that identifies the platform where @value{GDBN} will run.
29557 (You can often leave off @var{host}; @file{configure} tries to guess the
29558 correct value by examining your system.)
29559
29560 Running @samp{configure @var{host}} and then running @code{make} builds the
29561 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
29562 libraries, then @code{gdb} itself. The configured source files, and the
29563 binaries, are left in the corresponding source directories.
29564
29565 @need 750
29566 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
29567 system does not recognize this automatically when you run a different
29568 shell, you may need to run @code{sh} on it explicitly:
29569
29570 @smallexample
29571 sh configure @var{host}
29572 @end smallexample
29573
29574 If you run @file{configure} from a directory that contains source
29575 directories for multiple libraries or programs, such as the
29576 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
29577 @file{configure}
29578 creates configuration files for every directory level underneath (unless
29579 you tell it not to, with the @samp{--norecursion} option).
29580
29581 You should run the @file{configure} script from the top directory in the
29582 source tree, the @file{gdb-@var{version-number}} directory. If you run
29583 @file{configure} from one of the subdirectories, you will configure only
29584 that subdirectory. That is usually not what you want. In particular,
29585 if you run the first @file{configure} from the @file{gdb} subdirectory
29586 of the @file{gdb-@var{version-number}} directory, you will omit the
29587 configuration of @file{bfd}, @file{readline}, and other sibling
29588 directories of the @file{gdb} subdirectory. This leads to build errors
29589 about missing include files such as @file{bfd/bfd.h}.
29590
29591 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
29592 However, you should make sure that the shell on your path (named by
29593 the @samp{SHELL} environment variable) is publicly readable. Remember
29594 that @value{GDBN} uses the shell to start your program---some systems refuse to
29595 let @value{GDBN} debug child processes whose programs are not readable.
29596
29597 @node Separate Objdir
29598 @section Compiling @value{GDBN} in Another Directory
29599
29600 If you want to run @value{GDBN} versions for several host or target machines,
29601 you need a different @code{gdb} compiled for each combination of
29602 host and target. @file{configure} is designed to make this easy by
29603 allowing you to generate each configuration in a separate subdirectory,
29604 rather than in the source directory. If your @code{make} program
29605 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
29606 @code{make} in each of these directories builds the @code{gdb}
29607 program specified there.
29608
29609 To build @code{gdb} in a separate directory, run @file{configure}
29610 with the @samp{--srcdir} option to specify where to find the source.
29611 (You also need to specify a path to find @file{configure}
29612 itself from your working directory. If the path to @file{configure}
29613 would be the same as the argument to @samp{--srcdir}, you can leave out
29614 the @samp{--srcdir} option; it is assumed.)
29615
29616 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
29617 separate directory for a Sun 4 like this:
29618
29619 @smallexample
29620 @group
29621 cd gdb-@value{GDBVN}
29622 mkdir ../gdb-sun4
29623 cd ../gdb-sun4
29624 ../gdb-@value{GDBVN}/configure sun4
29625 make
29626 @end group
29627 @end smallexample
29628
29629 When @file{configure} builds a configuration using a remote source
29630 directory, it creates a tree for the binaries with the same structure
29631 (and using the same names) as the tree under the source directory. In
29632 the example, you'd find the Sun 4 library @file{libiberty.a} in the
29633 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
29634 @file{gdb-sun4/gdb}.
29635
29636 Make sure that your path to the @file{configure} script has just one
29637 instance of @file{gdb} in it. If your path to @file{configure} looks
29638 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
29639 one subdirectory of @value{GDBN}, not the whole package. This leads to
29640 build errors about missing include files such as @file{bfd/bfd.h}.
29641
29642 One popular reason to build several @value{GDBN} configurations in separate
29643 directories is to configure @value{GDBN} for cross-compiling (where
29644 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
29645 programs that run on another machine---the @dfn{target}).
29646 You specify a cross-debugging target by
29647 giving the @samp{--target=@var{target}} option to @file{configure}.
29648
29649 When you run @code{make} to build a program or library, you must run
29650 it in a configured directory---whatever directory you were in when you
29651 called @file{configure} (or one of its subdirectories).
29652
29653 The @code{Makefile} that @file{configure} generates in each source
29654 directory also runs recursively. If you type @code{make} in a source
29655 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
29656 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
29657 will build all the required libraries, and then build GDB.
29658
29659 When you have multiple hosts or targets configured in separate
29660 directories, you can run @code{make} on them in parallel (for example,
29661 if they are NFS-mounted on each of the hosts); they will not interfere
29662 with each other.
29663
29664 @node Config Names
29665 @section Specifying Names for Hosts and Targets
29666
29667 The specifications used for hosts and targets in the @file{configure}
29668 script are based on a three-part naming scheme, but some short predefined
29669 aliases are also supported. The full naming scheme encodes three pieces
29670 of information in the following pattern:
29671
29672 @smallexample
29673 @var{architecture}-@var{vendor}-@var{os}
29674 @end smallexample
29675
29676 For example, you can use the alias @code{sun4} as a @var{host} argument,
29677 or as the value for @var{target} in a @code{--target=@var{target}}
29678 option. The equivalent full name is @samp{sparc-sun-sunos4}.
29679
29680 The @file{configure} script accompanying @value{GDBN} does not provide
29681 any query facility to list all supported host and target names or
29682 aliases. @file{configure} calls the Bourne shell script
29683 @code{config.sub} to map abbreviations to full names; you can read the
29684 script, if you wish, or you can use it to test your guesses on
29685 abbreviations---for example:
29686
29687 @smallexample
29688 % sh config.sub i386-linux
29689 i386-pc-linux-gnu
29690 % sh config.sub alpha-linux
29691 alpha-unknown-linux-gnu
29692 % sh config.sub hp9k700
29693 hppa1.1-hp-hpux
29694 % sh config.sub sun4
29695 sparc-sun-sunos4.1.1
29696 % sh config.sub sun3
29697 m68k-sun-sunos4.1.1
29698 % sh config.sub i986v
29699 Invalid configuration `i986v': machine `i986v' not recognized
29700 @end smallexample
29701
29702 @noindent
29703 @code{config.sub} is also distributed in the @value{GDBN} source
29704 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
29705
29706 @node Configure Options
29707 @section @file{configure} Options
29708
29709 Here is a summary of the @file{configure} options and arguments that
29710 are most often useful for building @value{GDBN}. @file{configure} also has
29711 several other options not listed here. @inforef{What Configure
29712 Does,,configure.info}, for a full explanation of @file{configure}.
29713
29714 @smallexample
29715 configure @r{[}--help@r{]}
29716 @r{[}--prefix=@var{dir}@r{]}
29717 @r{[}--exec-prefix=@var{dir}@r{]}
29718 @r{[}--srcdir=@var{dirname}@r{]}
29719 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
29720 @r{[}--target=@var{target}@r{]}
29721 @var{host}
29722 @end smallexample
29723
29724 @noindent
29725 You may introduce options with a single @samp{-} rather than
29726 @samp{--} if you prefer; but you may abbreviate option names if you use
29727 @samp{--}.
29728
29729 @table @code
29730 @item --help
29731 Display a quick summary of how to invoke @file{configure}.
29732
29733 @item --prefix=@var{dir}
29734 Configure the source to install programs and files under directory
29735 @file{@var{dir}}.
29736
29737 @item --exec-prefix=@var{dir}
29738 Configure the source to install programs under directory
29739 @file{@var{dir}}.
29740
29741 @c avoid splitting the warning from the explanation:
29742 @need 2000
29743 @item --srcdir=@var{dirname}
29744 @strong{Warning: using this option requires @sc{gnu} @code{make}, or another
29745 @code{make} that implements the @code{VPATH} feature.}@*
29746 Use this option to make configurations in directories separate from the
29747 @value{GDBN} source directories. Among other things, you can use this to
29748 build (or maintain) several configurations simultaneously, in separate
29749 directories. @file{configure} writes configuration-specific files in
29750 the current directory, but arranges for them to use the source in the
29751 directory @var{dirname}. @file{configure} creates directories under
29752 the working directory in parallel to the source directories below
29753 @var{dirname}.
29754
29755 @item --norecursion
29756 Configure only the directory level where @file{configure} is executed; do not
29757 propagate configuration to subdirectories.
29758
29759 @item --target=@var{target}
29760 Configure @value{GDBN} for cross-debugging programs running on the specified
29761 @var{target}. Without this option, @value{GDBN} is configured to debug
29762 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
29763
29764 There is no convenient way to generate a list of all available targets.
29765
29766 @item @var{host} @dots{}
29767 Configure @value{GDBN} to run on the specified @var{host}.
29768
29769 There is no convenient way to generate a list of all available hosts.
29770 @end table
29771
29772 There are many other options available as well, but they are generally
29773 needed for special purposes only.
29774
29775 @node System-wide configuration
29776 @section System-wide configuration and settings
29777 @cindex system-wide init file
29778
29779 @value{GDBN} can be configured to have a system-wide init file;
29780 this file will be read and executed at startup (@pxref{Startup, , What
29781 @value{GDBN} does during startup}).
29782
29783 Here is the corresponding configure option:
29784
29785 @table @code
29786 @item --with-system-gdbinit=@var{file}
29787 Specify that the default location of the system-wide init file is
29788 @var{file}.
29789 @end table
29790
29791 If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
29792 it may be subject to relocation. Two possible cases:
29793
29794 @itemize @bullet
29795 @item
29796 If the default location of this init file contains @file{$prefix},
29797 it will be subject to relocation. Suppose that the configure options
29798 are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
29799 if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
29800 init file is looked for as @file{$install/etc/gdbinit} instead of
29801 @file{$prefix/etc/gdbinit}.
29802
29803 @item
29804 By contrast, if the default location does not contain the prefix,
29805 it will not be relocated. E.g.@: if @value{GDBN} has been configured with
29806 @option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
29807 then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
29808 wherever @value{GDBN} is installed.
29809 @end itemize
29810
29811 @node Maintenance Commands
29812 @appendix Maintenance Commands
29813 @cindex maintenance commands
29814 @cindex internal commands
29815
29816 In addition to commands intended for @value{GDBN} users, @value{GDBN}
29817 includes a number of commands intended for @value{GDBN} developers,
29818 that are not documented elsewhere in this manual. These commands are
29819 provided here for reference. (For commands that turn on debugging
29820 messages, see @ref{Debugging Output}.)
29821
29822 @table @code
29823 @kindex maint agent
29824 @kindex maint agent-eval
29825 @item maint agent @var{expression}
29826 @itemx maint agent-eval @var{expression}
29827 Translate the given @var{expression} into remote agent bytecodes.
29828 This command is useful for debugging the Agent Expression mechanism
29829 (@pxref{Agent Expressions}). The @samp{agent} version produces an
29830 expression useful for data collection, such as by tracepoints, while
29831 @samp{maint agent-eval} produces an expression that evaluates directly
29832 to a result. For instance, a collection expression for @code{globa +
29833 globb} will include bytecodes to record four bytes of memory at each
29834 of the addresses of @code{globa} and @code{globb}, while discarding
29835 the result of the addition, while an evaluation expression will do the
29836 addition and return the sum.
29837
29838 @kindex maint info breakpoints
29839 @item @anchor{maint info breakpoints}maint info breakpoints
29840 Using the same format as @samp{info breakpoints}, display both the
29841 breakpoints you've set explicitly, and those @value{GDBN} is using for
29842 internal purposes. Internal breakpoints are shown with negative
29843 breakpoint numbers. The type column identifies what kind of breakpoint
29844 is shown:
29845
29846 @table @code
29847 @item breakpoint
29848 Normal, explicitly set breakpoint.
29849
29850 @item watchpoint
29851 Normal, explicitly set watchpoint.
29852
29853 @item longjmp
29854 Internal breakpoint, used to handle correctly stepping through
29855 @code{longjmp} calls.
29856
29857 @item longjmp resume
29858 Internal breakpoint at the target of a @code{longjmp}.
29859
29860 @item until
29861 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
29862
29863 @item finish
29864 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
29865
29866 @item shlib events
29867 Shared library events.
29868
29869 @end table
29870
29871 @kindex set displaced-stepping
29872 @kindex show displaced-stepping
29873 @cindex displaced stepping support
29874 @cindex out-of-line single-stepping
29875 @item set displaced-stepping
29876 @itemx show displaced-stepping
29877 Control whether or not @value{GDBN} will do @dfn{displaced stepping}
29878 if the target supports it. Displaced stepping is a way to single-step
29879 over breakpoints without removing them from the inferior, by executing
29880 an out-of-line copy of the instruction that was originally at the
29881 breakpoint location. It is also known as out-of-line single-stepping.
29882
29883 @table @code
29884 @item set displaced-stepping on
29885 If the target architecture supports it, @value{GDBN} will use
29886 displaced stepping to step over breakpoints.
29887
29888 @item set displaced-stepping off
29889 @value{GDBN} will not use displaced stepping to step over breakpoints,
29890 even if such is supported by the target architecture.
29891
29892 @cindex non-stop mode, and @samp{set displaced-stepping}
29893 @item set displaced-stepping auto
29894 This is the default mode. @value{GDBN} will use displaced stepping
29895 only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
29896 architecture supports displaced stepping.
29897 @end table
29898
29899 @kindex maint check-symtabs
29900 @item maint check-symtabs
29901 Check the consistency of psymtabs and symtabs.
29902
29903 @kindex maint cplus first_component
29904 @item maint cplus first_component @var{name}
29905 Print the first C@t{++} class/namespace component of @var{name}.
29906
29907 @kindex maint cplus namespace
29908 @item maint cplus namespace
29909 Print the list of possible C@t{++} namespaces.
29910
29911 @kindex maint demangle
29912 @item maint demangle @var{name}
29913 Demangle a C@t{++} or Objective-C mangled @var{name}.
29914
29915 @kindex maint deprecate
29916 @kindex maint undeprecate
29917 @cindex deprecated commands
29918 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
29919 @itemx maint undeprecate @var{command}
29920 Deprecate or undeprecate the named @var{command}. Deprecated commands
29921 cause @value{GDBN} to issue a warning when you use them. The optional
29922 argument @var{replacement} says which newer command should be used in
29923 favor of the deprecated one; if it is given, @value{GDBN} will mention
29924 the replacement as part of the warning.
29925
29926 @kindex maint dump-me
29927 @item maint dump-me
29928 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
29929 Cause a fatal signal in the debugger and force it to dump its core.
29930 This is supported only on systems which support aborting a program
29931 with the @code{SIGQUIT} signal.
29932
29933 @kindex maint internal-error
29934 @kindex maint internal-warning
29935 @item maint internal-error @r{[}@var{message-text}@r{]}
29936 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
29937 Cause @value{GDBN} to call the internal function @code{internal_error}
29938 or @code{internal_warning} and hence behave as though an internal error
29939 or internal warning has been detected. In addition to reporting the
29940 internal problem, these functions give the user the opportunity to
29941 either quit @value{GDBN} or create a core file of the current
29942 @value{GDBN} session.
29943
29944 These commands take an optional parameter @var{message-text} that is
29945 used as the text of the error or warning message.
29946
29947 Here's an example of using @code{internal-error}:
29948
29949 @smallexample
29950 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
29951 @dots{}/maint.c:121: internal-error: testing, 1, 2
29952 A problem internal to GDB has been detected. Further
29953 debugging may prove unreliable.
29954 Quit this debugging session? (y or n) @kbd{n}
29955 Create a core file? (y or n) @kbd{n}
29956 (@value{GDBP})
29957 @end smallexample
29958
29959 @cindex @value{GDBN} internal error
29960 @cindex internal errors, control of @value{GDBN} behavior
29961
29962 @kindex maint set internal-error
29963 @kindex maint show internal-error
29964 @kindex maint set internal-warning
29965 @kindex maint show internal-warning
29966 @item maint set internal-error @var{action} [ask|yes|no]
29967 @itemx maint show internal-error @var{action}
29968 @itemx maint set internal-warning @var{action} [ask|yes|no]
29969 @itemx maint show internal-warning @var{action}
29970 When @value{GDBN} reports an internal problem (error or warning) it
29971 gives the user the opportunity to both quit @value{GDBN} and create a
29972 core file of the current @value{GDBN} session. These commands let you
29973 override the default behaviour for each particular @var{action},
29974 described in the table below.
29975
29976 @table @samp
29977 @item quit
29978 You can specify that @value{GDBN} should always (yes) or never (no)
29979 quit. The default is to ask the user what to do.
29980
29981 @item corefile
29982 You can specify that @value{GDBN} should always (yes) or never (no)
29983 create a core file. The default is to ask the user what to do.
29984 @end table
29985
29986 @kindex maint packet
29987 @item maint packet @var{text}
29988 If @value{GDBN} is talking to an inferior via the serial protocol,
29989 then this command sends the string @var{text} to the inferior, and
29990 displays the response packet. @value{GDBN} supplies the initial
29991 @samp{$} character, the terminating @samp{#} character, and the
29992 checksum.
29993
29994 @kindex maint print architecture
29995 @item maint print architecture @r{[}@var{file}@r{]}
29996 Print the entire architecture configuration. The optional argument
29997 @var{file} names the file where the output goes.
29998
29999 @kindex maint print c-tdesc
30000 @item maint print c-tdesc
30001 Print the current target description (@pxref{Target Descriptions}) as
30002 a C source file. The created source file can be used in @value{GDBN}
30003 when an XML parser is not available to parse the description.
30004
30005 @kindex maint print dummy-frames
30006 @item maint print dummy-frames
30007 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
30008
30009 @smallexample
30010 (@value{GDBP}) @kbd{b add}
30011 @dots{}
30012 (@value{GDBP}) @kbd{print add(2,3)}
30013 Breakpoint 2, add (a=2, b=3) at @dots{}
30014 58 return (a + b);
30015 The program being debugged stopped while in a function called from GDB.
30016 @dots{}
30017 (@value{GDBP}) @kbd{maint print dummy-frames}
30018 0x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
30019 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
30020 call_lo=0x01014000 call_hi=0x01014001
30021 (@value{GDBP})
30022 @end smallexample
30023
30024 Takes an optional file parameter.
30025
30026 @kindex maint print registers
30027 @kindex maint print raw-registers
30028 @kindex maint print cooked-registers
30029 @kindex maint print register-groups
30030 @item maint print registers @r{[}@var{file}@r{]}
30031 @itemx maint print raw-registers @r{[}@var{file}@r{]}
30032 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
30033 @itemx maint print register-groups @r{[}@var{file}@r{]}
30034 Print @value{GDBN}'s internal register data structures.
30035
30036 The command @code{maint print raw-registers} includes the contents of
30037 the raw register cache; the command @code{maint print cooked-registers}
30038 includes the (cooked) value of all registers, including registers which
30039 aren't available on the target nor visible to user; and the
30040 command @code{maint print register-groups} includes the groups that each
30041 register is a member of. @xref{Registers,, Registers, gdbint,
30042 @value{GDBN} Internals}.
30043
30044 These commands take an optional parameter, a file name to which to
30045 write the information.
30046
30047 @kindex maint print reggroups
30048 @item maint print reggroups @r{[}@var{file}@r{]}
30049 Print @value{GDBN}'s internal register group data structures. The
30050 optional argument @var{file} tells to what file to write the
30051 information.
30052
30053 The register groups info looks like this:
30054
30055 @smallexample
30056 (@value{GDBP}) @kbd{maint print reggroups}
30057 Group Type
30058 general user
30059 float user
30060 all user
30061 vector user
30062 system user
30063 save internal
30064 restore internal
30065 @end smallexample
30066
30067 @kindex flushregs
30068 @item flushregs
30069 This command forces @value{GDBN} to flush its internal register cache.
30070
30071 @kindex maint print objfiles
30072 @cindex info for known object files
30073 @item maint print objfiles
30074 Print a dump of all known object files. For each object file, this
30075 command prints its name, address in memory, and all of its psymtabs
30076 and symtabs.
30077
30078 @kindex maint print section-scripts
30079 @cindex info for known .debug_gdb_scripts-loaded scripts
30080 @item maint print section-scripts [@var{regexp}]
30081 Print a dump of scripts specified in the @code{.debug_gdb_section} section.
30082 If @var{regexp} is specified, only print scripts loaded by object files
30083 matching @var{regexp}.
30084 For each script, this command prints its name as specified in the objfile,
30085 and the full path if known.
30086 @xref{.debug_gdb_scripts section}.
30087
30088 @kindex maint print statistics
30089 @cindex bcache statistics
30090 @item maint print statistics
30091 This command prints, for each object file in the program, various data
30092 about that object file followed by the byte cache (@dfn{bcache})
30093 statistics for the object file. The objfile data includes the number
30094 of minimal, partial, full, and stabs symbols, the number of types
30095 defined by the objfile, the number of as yet unexpanded psym tables,
30096 the number of line tables and string tables, and the amount of memory
30097 used by the various tables. The bcache statistics include the counts,
30098 sizes, and counts of duplicates of all and unique objects, max,
30099 average, and median entry size, total memory used and its overhead and
30100 savings, and various measures of the hash table size and chain
30101 lengths.
30102
30103 @kindex maint print target-stack
30104 @cindex target stack description
30105 @item maint print target-stack
30106 A @dfn{target} is an interface between the debugger and a particular
30107 kind of file or process. Targets can be stacked in @dfn{strata},
30108 so that more than one target can potentially respond to a request.
30109 In particular, memory accesses will walk down the stack of targets
30110 until they find a target that is interested in handling that particular
30111 address.
30112
30113 This command prints a short description of each layer that was pushed on
30114 the @dfn{target stack}, starting from the top layer down to the bottom one.
30115
30116 @kindex maint print type
30117 @cindex type chain of a data type
30118 @item maint print type @var{expr}
30119 Print the type chain for a type specified by @var{expr}. The argument
30120 can be either a type name or a symbol. If it is a symbol, the type of
30121 that symbol is described. The type chain produced by this command is
30122 a recursive definition of the data type as stored in @value{GDBN}'s
30123 data structures, including its flags and contained types.
30124
30125 @kindex maint set dwarf2 always-disassemble
30126 @kindex maint show dwarf2 always-disassemble
30127 @item maint set dwarf2 always-disassemble
30128 @item maint show dwarf2 always-disassemble
30129 Control the behavior of @code{info address} when using DWARF debugging
30130 information.
30131
30132 The default is @code{off}, which means that @value{GDBN} should try to
30133 describe a variable's location in an easily readable format. When
30134 @code{on}, @value{GDBN} will instead display the DWARF location
30135 expression in an assembly-like format. Note that some locations are
30136 too complex for @value{GDBN} to describe simply; in this case you will
30137 always see the disassembly form.
30138
30139 Here is an example of the resulting disassembly:
30140
30141 @smallexample
30142 (gdb) info addr argc
30143 Symbol "argc" is a complex DWARF expression:
30144 1: DW_OP_fbreg 0
30145 @end smallexample
30146
30147 For more information on these expressions, see
30148 @uref{http://www.dwarfstd.org/, the DWARF standard}.
30149
30150 @kindex maint set dwarf2 max-cache-age
30151 @kindex maint show dwarf2 max-cache-age
30152 @item maint set dwarf2 max-cache-age
30153 @itemx maint show dwarf2 max-cache-age
30154 Control the DWARF 2 compilation unit cache.
30155
30156 @cindex DWARF 2 compilation units cache
30157 In object files with inter-compilation-unit references, such as those
30158 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
30159 reader needs to frequently refer to previously read compilation units.
30160 This setting controls how long a compilation unit will remain in the
30161 cache if it is not referenced. A higher limit means that cached
30162 compilation units will be stored in memory longer, and more total
30163 memory will be used. Setting it to zero disables caching, which will
30164 slow down @value{GDBN} startup, but reduce memory consumption.
30165
30166 @kindex maint set profile
30167 @kindex maint show profile
30168 @cindex profiling GDB
30169 @item maint set profile
30170 @itemx maint show profile
30171 Control profiling of @value{GDBN}.
30172
30173 Profiling will be disabled until you use the @samp{maint set profile}
30174 command to enable it. When you enable profiling, the system will begin
30175 collecting timing and execution count data; when you disable profiling or
30176 exit @value{GDBN}, the results will be written to a log file. Remember that
30177 if you use profiling, @value{GDBN} will overwrite the profiling log file
30178 (often called @file{gmon.out}). If you have a record of important profiling
30179 data in a @file{gmon.out} file, be sure to move it to a safe location.
30180
30181 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
30182 compiled with the @samp{-pg} compiler option.
30183
30184 @kindex maint set show-debug-regs
30185 @kindex maint show show-debug-regs
30186 @cindex hardware debug registers
30187 @item maint set show-debug-regs
30188 @itemx maint show show-debug-regs
30189 Control whether to show variables that mirror the hardware debug
30190 registers. Use @code{ON} to enable, @code{OFF} to disable. If
30191 enabled, the debug registers values are shown when @value{GDBN} inserts or
30192 removes a hardware breakpoint or watchpoint, and when the inferior
30193 triggers a hardware-assisted breakpoint or watchpoint.
30194
30195 @kindex maint set show-all-tib
30196 @kindex maint show show-all-tib
30197 @item maint set show-all-tib
30198 @itemx maint show show-all-tib
30199 Control whether to show all non zero areas within a 1k block starting
30200 at thread local base, when using the @samp{info w32 thread-information-block}
30201 command.
30202
30203 @kindex maint space
30204 @cindex memory used by commands
30205 @item maint space
30206 Control whether to display memory usage for each command. If set to a
30207 nonzero value, @value{GDBN} will display how much memory each command
30208 took, following the command's own output. This can also be requested
30209 by invoking @value{GDBN} with the @option{--statistics} command-line
30210 switch (@pxref{Mode Options}).
30211
30212 @kindex maint time
30213 @cindex time of command execution
30214 @item maint time
30215 Control whether to display the execution time for each command. If
30216 set to a nonzero value, @value{GDBN} will display how much time it
30217 took to execute each command, following the command's own output.
30218 The time is not printed for the commands that run the target, since
30219 there's no mechanism currently to compute how much time was spend
30220 by @value{GDBN} and how much time was spend by the program been debugged.
30221 it's not possibly currently
30222 This can also be requested by invoking @value{GDBN} with the
30223 @option{--statistics} command-line switch (@pxref{Mode Options}).
30224
30225 @kindex maint translate-address
30226 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
30227 Find the symbol stored at the location specified by the address
30228 @var{addr} and an optional section name @var{section}. If found,
30229 @value{GDBN} prints the name of the closest symbol and an offset from
30230 the symbol's location to the specified address. This is similar to
30231 the @code{info address} command (@pxref{Symbols}), except that this
30232 command also allows to find symbols in other sections.
30233
30234 If section was not specified, the section in which the symbol was found
30235 is also printed. For dynamically linked executables, the name of
30236 executable or shared library containing the symbol is printed as well.
30237
30238 @end table
30239
30240 The following command is useful for non-interactive invocations of
30241 @value{GDBN}, such as in the test suite.
30242
30243 @table @code
30244 @item set watchdog @var{nsec}
30245 @kindex set watchdog
30246 @cindex watchdog timer
30247 @cindex timeout for commands
30248 Set the maximum number of seconds @value{GDBN} will wait for the
30249 target operation to finish. If this time expires, @value{GDBN}
30250 reports and error and the command is aborted.
30251
30252 @item show watchdog
30253 Show the current setting of the target wait timeout.
30254 @end table
30255
30256 @node Remote Protocol
30257 @appendix @value{GDBN} Remote Serial Protocol
30258
30259 @menu
30260 * Overview::
30261 * Packets::
30262 * Stop Reply Packets::
30263 * General Query Packets::
30264 * Architecture-Specific Protocol Details::
30265 * Tracepoint Packets::
30266 * Host I/O Packets::
30267 * Interrupts::
30268 * Notification Packets::
30269 * Remote Non-Stop::
30270 * Packet Acknowledgment::
30271 * Examples::
30272 * File-I/O Remote Protocol Extension::
30273 * Library List Format::
30274 * Memory Map Format::
30275 * Thread List Format::
30276 @end menu
30277
30278 @node Overview
30279 @section Overview
30280
30281 There may be occasions when you need to know something about the
30282 protocol---for example, if there is only one serial port to your target
30283 machine, you might want your program to do something special if it
30284 recognizes a packet meant for @value{GDBN}.
30285
30286 In the examples below, @samp{->} and @samp{<-} are used to indicate
30287 transmitted and received data, respectively.
30288
30289 @cindex protocol, @value{GDBN} remote serial
30290 @cindex serial protocol, @value{GDBN} remote
30291 @cindex remote serial protocol
30292 All @value{GDBN} commands and responses (other than acknowledgments
30293 and notifications, see @ref{Notification Packets}) are sent as a
30294 @var{packet}. A @var{packet} is introduced with the character
30295 @samp{$}, the actual @var{packet-data}, and the terminating character
30296 @samp{#} followed by a two-digit @var{checksum}:
30297
30298 @smallexample
30299 @code{$}@var{packet-data}@code{#}@var{checksum}
30300 @end smallexample
30301 @noindent
30302
30303 @cindex checksum, for @value{GDBN} remote
30304 @noindent
30305 The two-digit @var{checksum} is computed as the modulo 256 sum of all
30306 characters between the leading @samp{$} and the trailing @samp{#} (an
30307 eight bit unsigned checksum).
30308
30309 Implementors should note that prior to @value{GDBN} 5.0 the protocol
30310 specification also included an optional two-digit @var{sequence-id}:
30311
30312 @smallexample
30313 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
30314 @end smallexample
30315
30316 @cindex sequence-id, for @value{GDBN} remote
30317 @noindent
30318 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
30319 has never output @var{sequence-id}s. Stubs that handle packets added
30320 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
30321
30322 When either the host or the target machine receives a packet, the first
30323 response expected is an acknowledgment: either @samp{+} (to indicate
30324 the package was received correctly) or @samp{-} (to request
30325 retransmission):
30326
30327 @smallexample
30328 -> @code{$}@var{packet-data}@code{#}@var{checksum}
30329 <- @code{+}
30330 @end smallexample
30331 @noindent
30332
30333 The @samp{+}/@samp{-} acknowledgments can be disabled
30334 once a connection is established.
30335 @xref{Packet Acknowledgment}, for details.
30336
30337 The host (@value{GDBN}) sends @var{command}s, and the target (the
30338 debugging stub incorporated in your program) sends a @var{response}. In
30339 the case of step and continue @var{command}s, the response is only sent
30340 when the operation has completed, and the target has again stopped all
30341 threads in all attached processes. This is the default all-stop mode
30342 behavior, but the remote protocol also supports @value{GDBN}'s non-stop
30343 execution mode; see @ref{Remote Non-Stop}, for details.
30344
30345 @var{packet-data} consists of a sequence of characters with the
30346 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
30347 exceptions).
30348
30349 @cindex remote protocol, field separator
30350 Fields within the packet should be separated using @samp{,} @samp{;} or
30351 @samp{:}. Except where otherwise noted all numbers are represented in
30352 @sc{hex} with leading zeros suppressed.
30353
30354 Implementors should note that prior to @value{GDBN} 5.0, the character
30355 @samp{:} could not appear as the third character in a packet (as it
30356 would potentially conflict with the @var{sequence-id}).
30357
30358 @cindex remote protocol, binary data
30359 @anchor{Binary Data}
30360 Binary data in most packets is encoded either as two hexadecimal
30361 digits per byte of binary data. This allowed the traditional remote
30362 protocol to work over connections which were only seven-bit clean.
30363 Some packets designed more recently assume an eight-bit clean
30364 connection, and use a more efficient encoding to send and receive
30365 binary data.
30366
30367 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
30368 as an escape character. Any escaped byte is transmitted as the escape
30369 character followed by the original character XORed with @code{0x20}.
30370 For example, the byte @code{0x7d} would be transmitted as the two
30371 bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
30372 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
30373 @samp{@}}) must always be escaped. Responses sent by the stub
30374 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
30375 is not interpreted as the start of a run-length encoded sequence
30376 (described next).
30377
30378 Response @var{data} can be run-length encoded to save space.
30379 Run-length encoding replaces runs of identical characters with one
30380 instance of the repeated character, followed by a @samp{*} and a
30381 repeat count. The repeat count is itself sent encoded, to avoid
30382 binary characters in @var{data}: a value of @var{n} is sent as
30383 @code{@var{n}+29}. For a repeat count greater or equal to 3, this
30384 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
30385 code 32) for a repeat count of 3. (This is because run-length
30386 encoding starts to win for counts 3 or more.) Thus, for example,
30387 @samp{0* } is a run-length encoding of ``0000'': the space character
30388 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
30389 3}} more times.
30390
30391 The printable characters @samp{#} and @samp{$} or with a numeric value
30392 greater than 126 must not be used. Runs of six repeats (@samp{#}) or
30393 seven repeats (@samp{$}) can be expanded using a repeat count of only
30394 five (@samp{"}). For example, @samp{00000000} can be encoded as
30395 @samp{0*"00}.
30396
30397 The error response returned for some packets includes a two character
30398 error number. That number is not well defined.
30399
30400 @cindex empty response, for unsupported packets
30401 For any @var{command} not supported by the stub, an empty response
30402 (@samp{$#00}) should be returned. That way it is possible to extend the
30403 protocol. A newer @value{GDBN} can tell if a packet is supported based
30404 on that response.
30405
30406 A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
30407 @samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
30408 optional.
30409
30410 @node Packets
30411 @section Packets
30412
30413 The following table provides a complete list of all currently defined
30414 @var{command}s and their corresponding response @var{data}.
30415 @xref{File-I/O Remote Protocol Extension}, for details about the File
30416 I/O extension of the remote protocol.
30417
30418 Each packet's description has a template showing the packet's overall
30419 syntax, followed by an explanation of the packet's meaning. We
30420 include spaces in some of the templates for clarity; these are not
30421 part of the packet's syntax. No @value{GDBN} packet uses spaces to
30422 separate its components. For example, a template like @samp{foo
30423 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
30424 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
30425 @var{baz}. @value{GDBN} does not transmit a space character between the
30426 @samp{foo} and the @var{bar}, or between the @var{bar} and the
30427 @var{baz}.
30428
30429 @cindex @var{thread-id}, in remote protocol
30430 @anchor{thread-id syntax}
30431 Several packets and replies include a @var{thread-id} field to identify
30432 a thread. Normally these are positive numbers with a target-specific
30433 interpretation, formatted as big-endian hex strings. A @var{thread-id}
30434 can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
30435 pick any thread.
30436
30437 In addition, the remote protocol supports a multiprocess feature in
30438 which the @var{thread-id} syntax is extended to optionally include both
30439 process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
30440 The @var{pid} (process) and @var{tid} (thread) components each have the
30441 format described above: a positive number with target-specific
30442 interpretation formatted as a big-endian hex string, literal @samp{-1}
30443 to indicate all processes or threads (respectively), or @samp{0} to
30444 indicate an arbitrary process or thread. Specifying just a process, as
30445 @samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
30446 error to specify all processes but a specific thread, such as
30447 @samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
30448 for those packets and replies explicitly documented to include a process
30449 ID, rather than a @var{thread-id}.
30450
30451 The multiprocess @var{thread-id} syntax extensions are only used if both
30452 @value{GDBN} and the stub report support for the @samp{multiprocess}
30453 feature using @samp{qSupported}. @xref{multiprocess extensions}, for
30454 more information.
30455
30456 Note that all packet forms beginning with an upper- or lower-case
30457 letter, other than those described here, are reserved for future use.
30458
30459 Here are the packet descriptions.
30460
30461 @table @samp
30462
30463 @item !
30464 @cindex @samp{!} packet
30465 @anchor{extended mode}
30466 Enable extended mode. In extended mode, the remote server is made
30467 persistent. The @samp{R} packet is used to restart the program being
30468 debugged.
30469
30470 Reply:
30471 @table @samp
30472 @item OK
30473 The remote target both supports and has enabled extended mode.
30474 @end table
30475
30476 @item ?
30477 @cindex @samp{?} packet
30478 Indicate the reason the target halted. The reply is the same as for
30479 step and continue. This packet has a special interpretation when the
30480 target is in non-stop mode; see @ref{Remote Non-Stop}.
30481
30482 Reply:
30483 @xref{Stop Reply Packets}, for the reply specifications.
30484
30485 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
30486 @cindex @samp{A} packet
30487 Initialized @code{argv[]} array passed into program. @var{arglen}
30488 specifies the number of bytes in the hex encoded byte stream
30489 @var{arg}. See @code{gdbserver} for more details.
30490
30491 Reply:
30492 @table @samp
30493 @item OK
30494 The arguments were set.
30495 @item E @var{NN}
30496 An error occurred.
30497 @end table
30498
30499 @item b @var{baud}
30500 @cindex @samp{b} packet
30501 (Don't use this packet; its behavior is not well-defined.)
30502 Change the serial line speed to @var{baud}.
30503
30504 JTC: @emph{When does the transport layer state change? When it's
30505 received, or after the ACK is transmitted. In either case, there are
30506 problems if the command or the acknowledgment packet is dropped.}
30507
30508 Stan: @emph{If people really wanted to add something like this, and get
30509 it working for the first time, they ought to modify ser-unix.c to send
30510 some kind of out-of-band message to a specially-setup stub and have the
30511 switch happen "in between" packets, so that from remote protocol's point
30512 of view, nothing actually happened.}
30513
30514 @item B @var{addr},@var{mode}
30515 @cindex @samp{B} packet
30516 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
30517 breakpoint at @var{addr}.
30518
30519 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
30520 (@pxref{insert breakpoint or watchpoint packet}).
30521
30522 @cindex @samp{bc} packet
30523 @anchor{bc}
30524 @item bc
30525 Backward continue. Execute the target system in reverse. No parameter.
30526 @xref{Reverse Execution}, for more information.
30527
30528 Reply:
30529 @xref{Stop Reply Packets}, for the reply specifications.
30530
30531 @cindex @samp{bs} packet
30532 @anchor{bs}
30533 @item bs
30534 Backward single step. Execute one instruction in reverse. No parameter.
30535 @xref{Reverse Execution}, for more information.
30536
30537 Reply:
30538 @xref{Stop Reply Packets}, for the reply specifications.
30539
30540 @item c @r{[}@var{addr}@r{]}
30541 @cindex @samp{c} packet
30542 Continue. @var{addr} is address to resume. If @var{addr} is omitted,
30543 resume at current address.
30544
30545 Reply:
30546 @xref{Stop Reply Packets}, for the reply specifications.
30547
30548 @item C @var{sig}@r{[};@var{addr}@r{]}
30549 @cindex @samp{C} packet
30550 Continue with signal @var{sig} (hex signal number). If
30551 @samp{;@var{addr}} is omitted, resume at same address.
30552
30553 Reply:
30554 @xref{Stop Reply Packets}, for the reply specifications.
30555
30556 @item d
30557 @cindex @samp{d} packet
30558 Toggle debug flag.
30559
30560 Don't use this packet; instead, define a general set packet
30561 (@pxref{General Query Packets}).
30562
30563 @item D
30564 @itemx D;@var{pid}
30565 @cindex @samp{D} packet
30566 The first form of the packet is used to detach @value{GDBN} from the
30567 remote system. It is sent to the remote target
30568 before @value{GDBN} disconnects via the @code{detach} command.
30569
30570 The second form, including a process ID, is used when multiprocess
30571 protocol extensions are enabled (@pxref{multiprocess extensions}), to
30572 detach only a specific process. The @var{pid} is specified as a
30573 big-endian hex string.
30574
30575 Reply:
30576 @table @samp
30577 @item OK
30578 for success
30579 @item E @var{NN}
30580 for an error
30581 @end table
30582
30583 @item F @var{RC},@var{EE},@var{CF};@var{XX}
30584 @cindex @samp{F} packet
30585 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
30586 This is part of the File-I/O protocol extension. @xref{File-I/O
30587 Remote Protocol Extension}, for the specification.
30588
30589 @item g
30590 @anchor{read registers packet}
30591 @cindex @samp{g} packet
30592 Read general registers.
30593
30594 Reply:
30595 @table @samp
30596 @item @var{XX@dots{}}
30597 Each byte of register data is described by two hex digits. The bytes
30598 with the register are transmitted in target byte order. The size of
30599 each register and their position within the @samp{g} packet are
30600 determined by the @value{GDBN} internal gdbarch functions
30601 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}. The
30602 specification of several standard @samp{g} packets is specified below.
30603 @item E @var{NN}
30604 for an error.
30605 @end table
30606
30607 @item G @var{XX@dots{}}
30608 @cindex @samp{G} packet
30609 Write general registers. @xref{read registers packet}, for a
30610 description of the @var{XX@dots{}} data.
30611
30612 Reply:
30613 @table @samp
30614 @item OK
30615 for success
30616 @item E @var{NN}
30617 for an error
30618 @end table
30619
30620 @item H @var{c} @var{thread-id}
30621 @cindex @samp{H} packet
30622 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
30623 @samp{G}, et.al.). @var{c} depends on the operation to be performed: it
30624 should be @samp{c} for step and continue operations, @samp{g} for other
30625 operations. The thread designator @var{thread-id} has the format and
30626 interpretation described in @ref{thread-id syntax}.
30627
30628 Reply:
30629 @table @samp
30630 @item OK
30631 for success
30632 @item E @var{NN}
30633 for an error
30634 @end table
30635
30636 @c FIXME: JTC:
30637 @c 'H': How restrictive (or permissive) is the thread model. If a
30638 @c thread is selected and stopped, are other threads allowed
30639 @c to continue to execute? As I mentioned above, I think the
30640 @c semantics of each command when a thread is selected must be
30641 @c described. For example:
30642 @c
30643 @c 'g': If the stub supports threads and a specific thread is
30644 @c selected, returns the register block from that thread;
30645 @c otherwise returns current registers.
30646 @c
30647 @c 'G' If the stub supports threads and a specific thread is
30648 @c selected, sets the registers of the register block of
30649 @c that thread; otherwise sets current registers.
30650
30651 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
30652 @anchor{cycle step packet}
30653 @cindex @samp{i} packet
30654 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
30655 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
30656 step starting at that address.
30657
30658 @item I
30659 @cindex @samp{I} packet
30660 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
30661 step packet}.
30662
30663 @item k
30664 @cindex @samp{k} packet
30665 Kill request.
30666
30667 FIXME: @emph{There is no description of how to operate when a specific
30668 thread context has been selected (i.e.@: does 'k' kill only that
30669 thread?)}.
30670
30671 @item m @var{addr},@var{length}
30672 @cindex @samp{m} packet
30673 Read @var{length} bytes of memory starting at address @var{addr}.
30674 Note that @var{addr} may not be aligned to any particular boundary.
30675
30676 The stub need not use any particular size or alignment when gathering
30677 data from memory for the response; even if @var{addr} is word-aligned
30678 and @var{length} is a multiple of the word size, the stub is free to
30679 use byte accesses, or not. For this reason, this packet may not be
30680 suitable for accessing memory-mapped I/O devices.
30681 @cindex alignment of remote memory accesses
30682 @cindex size of remote memory accesses
30683 @cindex memory, alignment and size of remote accesses
30684
30685 Reply:
30686 @table @samp
30687 @item @var{XX@dots{}}
30688 Memory contents; each byte is transmitted as a two-digit hexadecimal
30689 number. The reply may contain fewer bytes than requested if the
30690 server was able to read only part of the region of memory.
30691 @item E @var{NN}
30692 @var{NN} is errno
30693 @end table
30694
30695 @item M @var{addr},@var{length}:@var{XX@dots{}}
30696 @cindex @samp{M} packet
30697 Write @var{length} bytes of memory starting at address @var{addr}.
30698 @var{XX@dots{}} is the data; each byte is transmitted as a two-digit
30699 hexadecimal number.
30700
30701 Reply:
30702 @table @samp
30703 @item OK
30704 for success
30705 @item E @var{NN}
30706 for an error (this includes the case where only part of the data was
30707 written).
30708 @end table
30709
30710 @item p @var{n}
30711 @cindex @samp{p} packet
30712 Read the value of register @var{n}; @var{n} is in hex.
30713 @xref{read registers packet}, for a description of how the returned
30714 register value is encoded.
30715
30716 Reply:
30717 @table @samp
30718 @item @var{XX@dots{}}
30719 the register's value
30720 @item E @var{NN}
30721 for an error
30722 @item
30723 Indicating an unrecognized @var{query}.
30724 @end table
30725
30726 @item P @var{n@dots{}}=@var{r@dots{}}
30727 @anchor{write register packet}
30728 @cindex @samp{P} packet
30729 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
30730 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
30731 digits for each byte in the register (target byte order).
30732
30733 Reply:
30734 @table @samp
30735 @item OK
30736 for success
30737 @item E @var{NN}
30738 for an error
30739 @end table
30740
30741 @item q @var{name} @var{params}@dots{}
30742 @itemx Q @var{name} @var{params}@dots{}
30743 @cindex @samp{q} packet
30744 @cindex @samp{Q} packet
30745 General query (@samp{q}) and set (@samp{Q}). These packets are
30746 described fully in @ref{General Query Packets}.
30747
30748 @item r
30749 @cindex @samp{r} packet
30750 Reset the entire system.
30751
30752 Don't use this packet; use the @samp{R} packet instead.
30753
30754 @item R @var{XX}
30755 @cindex @samp{R} packet
30756 Restart the program being debugged. @var{XX}, while needed, is ignored.
30757 This packet is only available in extended mode (@pxref{extended mode}).
30758
30759 The @samp{R} packet has no reply.
30760
30761 @item s @r{[}@var{addr}@r{]}
30762 @cindex @samp{s} packet
30763 Single step. @var{addr} is the address at which to resume. If
30764 @var{addr} is omitted, resume at same address.
30765
30766 Reply:
30767 @xref{Stop Reply Packets}, for the reply specifications.
30768
30769 @item S @var{sig}@r{[};@var{addr}@r{]}
30770 @anchor{step with signal packet}
30771 @cindex @samp{S} packet
30772 Step with signal. This is analogous to the @samp{C} packet, but
30773 requests a single-step, rather than a normal resumption of execution.
30774
30775 Reply:
30776 @xref{Stop Reply Packets}, for the reply specifications.
30777
30778 @item t @var{addr}:@var{PP},@var{MM}
30779 @cindex @samp{t} packet
30780 Search backwards starting at address @var{addr} for a match with pattern
30781 @var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
30782 @var{addr} must be at least 3 digits.
30783
30784 @item T @var{thread-id}
30785 @cindex @samp{T} packet
30786 Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
30787
30788 Reply:
30789 @table @samp
30790 @item OK
30791 thread is still alive
30792 @item E @var{NN}
30793 thread is dead
30794 @end table
30795
30796 @item v
30797 Packets starting with @samp{v} are identified by a multi-letter name,
30798 up to the first @samp{;} or @samp{?} (or the end of the packet).
30799
30800 @item vAttach;@var{pid}
30801 @cindex @samp{vAttach} packet
30802 Attach to a new process with the specified process ID @var{pid}.
30803 The process ID is a
30804 hexadecimal integer identifying the process. In all-stop mode, all
30805 threads in the attached process are stopped; in non-stop mode, it may be
30806 attached without being stopped if that is supported by the target.
30807
30808 @c In non-stop mode, on a successful vAttach, the stub should set the
30809 @c current thread to a thread of the newly-attached process. After
30810 @c attaching, GDB queries for the attached process's thread ID with qC.
30811 @c Also note that, from a user perspective, whether or not the
30812 @c target is stopped on attach in non-stop mode depends on whether you
30813 @c use the foreground or background version of the attach command, not
30814 @c on what vAttach does; GDB does the right thing with respect to either
30815 @c stopping or restarting threads.
30816
30817 This packet is only available in extended mode (@pxref{extended mode}).
30818
30819 Reply:
30820 @table @samp
30821 @item E @var{nn}
30822 for an error
30823 @item @r{Any stop packet}
30824 for success in all-stop mode (@pxref{Stop Reply Packets})
30825 @item OK
30826 for success in non-stop mode (@pxref{Remote Non-Stop})
30827 @end table
30828
30829 @item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
30830 @cindex @samp{vCont} packet
30831 Resume the inferior, specifying different actions for each thread.
30832 If an action is specified with no @var{thread-id}, then it is applied to any
30833 threads that don't have a specific action specified; if no default action is
30834 specified then other threads should remain stopped in all-stop mode and
30835 in their current state in non-stop mode.
30836 Specifying multiple
30837 default actions is an error; specifying no actions is also an error.
30838 Thread IDs are specified using the syntax described in @ref{thread-id syntax}.
30839
30840 Currently supported actions are:
30841
30842 @table @samp
30843 @item c
30844 Continue.
30845 @item C @var{sig}
30846 Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
30847 @item s
30848 Step.
30849 @item S @var{sig}
30850 Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
30851 @item t
30852 Stop.
30853 @end table
30854
30855 The optional argument @var{addr} normally associated with the
30856 @samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
30857 not supported in @samp{vCont}.
30858
30859 The @samp{t} action is only relevant in non-stop mode
30860 (@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
30861 A stop reply should be generated for any affected thread not already stopped.
30862 When a thread is stopped by means of a @samp{t} action,
30863 the corresponding stop reply should indicate that the thread has stopped with
30864 signal @samp{0}, regardless of whether the target uses some other signal
30865 as an implementation detail.
30866
30867 Reply:
30868 @xref{Stop Reply Packets}, for the reply specifications.
30869
30870 @item vCont?
30871 @cindex @samp{vCont?} packet
30872 Request a list of actions supported by the @samp{vCont} packet.
30873
30874 Reply:
30875 @table @samp
30876 @item vCont@r{[};@var{action}@dots{}@r{]}
30877 The @samp{vCont} packet is supported. Each @var{action} is a supported
30878 command in the @samp{vCont} packet.
30879 @item
30880 The @samp{vCont} packet is not supported.
30881 @end table
30882
30883 @item vFile:@var{operation}:@var{parameter}@dots{}
30884 @cindex @samp{vFile} packet
30885 Perform a file operation on the target system. For details,
30886 see @ref{Host I/O Packets}.
30887
30888 @item vFlashErase:@var{addr},@var{length}
30889 @cindex @samp{vFlashErase} packet
30890 Direct the stub to erase @var{length} bytes of flash starting at
30891 @var{addr}. The region may enclose any number of flash blocks, but
30892 its start and end must fall on block boundaries, as indicated by the
30893 flash block size appearing in the memory map (@pxref{Memory Map
30894 Format}). @value{GDBN} groups flash memory programming operations
30895 together, and sends a @samp{vFlashDone} request after each group; the
30896 stub is allowed to delay erase operation until the @samp{vFlashDone}
30897 packet is received.
30898
30899 The stub must support @samp{vCont} if it reports support for
30900 multiprocess extensions (@pxref{multiprocess extensions}). Note that in
30901 this case @samp{vCont} actions can be specified to apply to all threads
30902 in a process by using the @samp{p@var{pid}.-1} form of the
30903 @var{thread-id}.
30904
30905 Reply:
30906 @table @samp
30907 @item OK
30908 for success
30909 @item E @var{NN}
30910 for an error
30911 @end table
30912
30913 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
30914 @cindex @samp{vFlashWrite} packet
30915 Direct the stub to write data to flash address @var{addr}. The data
30916 is passed in binary form using the same encoding as for the @samp{X}
30917 packet (@pxref{Binary Data}). The memory ranges specified by
30918 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
30919 not overlap, and must appear in order of increasing addresses
30920 (although @samp{vFlashErase} packets for higher addresses may already
30921 have been received; the ordering is guaranteed only between
30922 @samp{vFlashWrite} packets). If a packet writes to an address that was
30923 neither erased by a preceding @samp{vFlashErase} packet nor by some other
30924 target-specific method, the results are unpredictable.
30925
30926
30927 Reply:
30928 @table @samp
30929 @item OK
30930 for success
30931 @item E.memtype
30932 for vFlashWrite addressing non-flash memory
30933 @item E @var{NN}
30934 for an error
30935 @end table
30936
30937 @item vFlashDone
30938 @cindex @samp{vFlashDone} packet
30939 Indicate to the stub that flash programming operation is finished.
30940 The stub is permitted to delay or batch the effects of a group of
30941 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
30942 @samp{vFlashDone} packet is received. The contents of the affected
30943 regions of flash memory are unpredictable until the @samp{vFlashDone}
30944 request is completed.
30945
30946 @item vKill;@var{pid}
30947 @cindex @samp{vKill} packet
30948 Kill the process with the specified process ID. @var{pid} is a
30949 hexadecimal integer identifying the process. This packet is used in
30950 preference to @samp{k} when multiprocess protocol extensions are
30951 supported; see @ref{multiprocess extensions}.
30952
30953 Reply:
30954 @table @samp
30955 @item E @var{nn}
30956 for an error
30957 @item OK
30958 for success
30959 @end table
30960
30961 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
30962 @cindex @samp{vRun} packet
30963 Run the program @var{filename}, passing it each @var{argument} on its
30964 command line. The file and arguments are hex-encoded strings. If
30965 @var{filename} is an empty string, the stub may use a default program
30966 (e.g.@: the last program run). The program is created in the stopped
30967 state.
30968
30969 @c FIXME: What about non-stop mode?
30970
30971 This packet is only available in extended mode (@pxref{extended mode}).
30972
30973 Reply:
30974 @table @samp
30975 @item E @var{nn}
30976 for an error
30977 @item @r{Any stop packet}
30978 for success (@pxref{Stop Reply Packets})
30979 @end table
30980
30981 @item vStopped
30982 @anchor{vStopped packet}
30983 @cindex @samp{vStopped} packet
30984
30985 In non-stop mode (@pxref{Remote Non-Stop}), acknowledge a previous stop
30986 reply and prompt for the stub to report another one.
30987
30988 Reply:
30989 @table @samp
30990 @item @r{Any stop packet}
30991 if there is another unreported stop event (@pxref{Stop Reply Packets})
30992 @item OK
30993 if there are no unreported stop events
30994 @end table
30995
30996 @item X @var{addr},@var{length}:@var{XX@dots{}}
30997 @anchor{X packet}
30998 @cindex @samp{X} packet
30999 Write data to memory, where the data is transmitted in binary.
31000 @var{addr} is address, @var{length} is number of bytes,
31001 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
31002
31003 Reply:
31004 @table @samp
31005 @item OK
31006 for success
31007 @item E @var{NN}
31008 for an error
31009 @end table
31010
31011 @item z @var{type},@var{addr},@var{kind}
31012 @itemx Z @var{type},@var{addr},@var{kind}
31013 @anchor{insert breakpoint or watchpoint packet}
31014 @cindex @samp{z} packet
31015 @cindex @samp{Z} packets
31016 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
31017 watchpoint starting at address @var{address} of kind @var{kind}.
31018
31019 Each breakpoint and watchpoint packet @var{type} is documented
31020 separately.
31021
31022 @emph{Implementation notes: A remote target shall return an empty string
31023 for an unrecognized breakpoint or watchpoint packet @var{type}. A
31024 remote target shall support either both or neither of a given
31025 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
31026 avoid potential problems with duplicate packets, the operations should
31027 be implemented in an idempotent way.}
31028
31029 @item z0,@var{addr},@var{kind}
31030 @itemx Z0,@var{addr},@var{kind}
31031 @cindex @samp{z0} packet
31032 @cindex @samp{Z0} packet
31033 Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
31034 @var{addr} of type @var{kind}.
31035
31036 A memory breakpoint is implemented by replacing the instruction at
31037 @var{addr} with a software breakpoint or trap instruction. The
31038 @var{kind} is target-specific and typically indicates the size of
31039 the breakpoint in bytes that should be inserted. E.g., the @sc{arm}
31040 and @sc{mips} can insert either a 2 or 4 byte breakpoint. Some
31041 architectures have additional meanings for @var{kind};
31042 see @ref{Architecture-Specific Protocol Details}.
31043
31044 @emph{Implementation note: It is possible for a target to copy or move
31045 code that contains memory breakpoints (e.g., when implementing
31046 overlays). The behavior of this packet, in the presence of such a
31047 target, is not defined.}
31048
31049 Reply:
31050 @table @samp
31051 @item OK
31052 success
31053 @item
31054 not supported
31055 @item E @var{NN}
31056 for an error
31057 @end table
31058
31059 @item z1,@var{addr},@var{kind}
31060 @itemx Z1,@var{addr},@var{kind}
31061 @cindex @samp{z1} packet
31062 @cindex @samp{Z1} packet
31063 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
31064 address @var{addr}.
31065
31066 A hardware breakpoint is implemented using a mechanism that is not
31067 dependant on being able to modify the target's memory. @var{kind}
31068 has the same meaning as in @samp{Z0} packets.
31069
31070 @emph{Implementation note: A hardware breakpoint is not affected by code
31071 movement.}
31072
31073 Reply:
31074 @table @samp
31075 @item OK
31076 success
31077 @item
31078 not supported
31079 @item E @var{NN}
31080 for an error
31081 @end table
31082
31083 @item z2,@var{addr},@var{kind}
31084 @itemx Z2,@var{addr},@var{kind}
31085 @cindex @samp{z2} packet
31086 @cindex @samp{Z2} packet
31087 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
31088 @var{kind} is interpreted as the number of bytes to watch.
31089
31090 Reply:
31091 @table @samp
31092 @item OK
31093 success
31094 @item
31095 not supported
31096 @item E @var{NN}
31097 for an error
31098 @end table
31099
31100 @item z3,@var{addr},@var{kind}
31101 @itemx Z3,@var{addr},@var{kind}
31102 @cindex @samp{z3} packet
31103 @cindex @samp{Z3} packet
31104 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
31105 @var{kind} is interpreted as the number of bytes to watch.
31106
31107 Reply:
31108 @table @samp
31109 @item OK
31110 success
31111 @item
31112 not supported
31113 @item E @var{NN}
31114 for an error
31115 @end table
31116
31117 @item z4,@var{addr},@var{kind}
31118 @itemx Z4,@var{addr},@var{kind}
31119 @cindex @samp{z4} packet
31120 @cindex @samp{Z4} packet
31121 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
31122 @var{kind} is interpreted as the number of bytes to watch.
31123
31124 Reply:
31125 @table @samp
31126 @item OK
31127 success
31128 @item
31129 not supported
31130 @item E @var{NN}
31131 for an error
31132 @end table
31133
31134 @end table
31135
31136 @node Stop Reply Packets
31137 @section Stop Reply Packets
31138 @cindex stop reply packets
31139
31140 The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
31141 @samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
31142 receive any of the below as a reply. Except for @samp{?}
31143 and @samp{vStopped}, that reply is only returned
31144 when the target halts. In the below the exact meaning of @dfn{signal
31145 number} is defined by the header @file{include/gdb/signals.h} in the
31146 @value{GDBN} source code.
31147
31148 As in the description of request packets, we include spaces in the
31149 reply templates for clarity; these are not part of the reply packet's
31150 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
31151 components.
31152
31153 @table @samp
31154
31155 @item S @var{AA}
31156 The program received signal number @var{AA} (a two-digit hexadecimal
31157 number). This is equivalent to a @samp{T} response with no
31158 @var{n}:@var{r} pairs.
31159
31160 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
31161 @cindex @samp{T} packet reply
31162 The program received signal number @var{AA} (a two-digit hexadecimal
31163 number). This is equivalent to an @samp{S} response, except that the
31164 @samp{@var{n}:@var{r}} pairs can carry values of important registers
31165 and other information directly in the stop reply packet, reducing
31166 round-trip latency. Single-step and breakpoint traps are reported
31167 this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
31168
31169 @itemize @bullet
31170 @item
31171 If @var{n} is a hexadecimal number, it is a register number, and the
31172 corresponding @var{r} gives that register's value. @var{r} is a
31173 series of bytes in target byte order, with each byte given by a
31174 two-digit hex number.
31175
31176 @item
31177 If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
31178 the stopped thread, as specified in @ref{thread-id syntax}.
31179
31180 @item
31181 If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
31182 the core on which the stop event was detected.
31183
31184 @item
31185 If @var{n} is a recognized @dfn{stop reason}, it describes a more
31186 specific event that stopped the target. The currently defined stop
31187 reasons are listed below. @var{aa} should be @samp{05}, the trap
31188 signal. At most one stop reason should be present.
31189
31190 @item
31191 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
31192 and go on to the next; this allows us to extend the protocol in the
31193 future.
31194 @end itemize
31195
31196 The currently defined stop reasons are:
31197
31198 @table @samp
31199 @item watch
31200 @itemx rwatch
31201 @itemx awatch
31202 The packet indicates a watchpoint hit, and @var{r} is the data address, in
31203 hex.
31204
31205 @cindex shared library events, remote reply
31206 @item library
31207 The packet indicates that the loaded libraries have changed.
31208 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
31209 list of loaded libraries. @var{r} is ignored.
31210
31211 @cindex replay log events, remote reply
31212 @item replaylog
31213 The packet indicates that the target cannot continue replaying
31214 logged execution events, because it has reached the end (or the
31215 beginning when executing backward) of the log. The value of @var{r}
31216 will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
31217 for more information.
31218 @end table
31219
31220 @item W @var{AA}
31221 @itemx W @var{AA} ; process:@var{pid}
31222 The process exited, and @var{AA} is the exit status. This is only
31223 applicable to certain targets.
31224
31225 The second form of the response, including the process ID of the exited
31226 process, can be used only when @value{GDBN} has reported support for
31227 multiprocess protocol extensions; see @ref{multiprocess extensions}.
31228 The @var{pid} is formatted as a big-endian hex string.
31229
31230 @item X @var{AA}
31231 @itemx X @var{AA} ; process:@var{pid}
31232 The process terminated with signal @var{AA}.
31233
31234 The second form of the response, including the process ID of the
31235 terminated process, can be used only when @value{GDBN} has reported
31236 support for multiprocess protocol extensions; see @ref{multiprocess
31237 extensions}. The @var{pid} is formatted as a big-endian hex string.
31238
31239 @item O @var{XX}@dots{}
31240 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
31241 written as the program's console output. This can happen at any time
31242 while the program is running and the debugger should continue to wait
31243 for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
31244
31245 @item F @var{call-id},@var{parameter}@dots{}
31246 @var{call-id} is the identifier which says which host system call should
31247 be called. This is just the name of the function. Translation into the
31248 correct system call is only applicable as it's defined in @value{GDBN}.
31249 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
31250 system calls.
31251
31252 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
31253 this very system call.
31254
31255 The target replies with this packet when it expects @value{GDBN} to
31256 call a host system call on behalf of the target. @value{GDBN} replies
31257 with an appropriate @samp{F} packet and keeps up waiting for the next
31258 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
31259 or @samp{s} action is expected to be continued. @xref{File-I/O Remote
31260 Protocol Extension}, for more details.
31261
31262 @end table
31263
31264 @node General Query Packets
31265 @section General Query Packets
31266 @cindex remote query requests
31267
31268 Packets starting with @samp{q} are @dfn{general query packets};
31269 packets starting with @samp{Q} are @dfn{general set packets}. General
31270 query and set packets are a semi-unified form for retrieving and
31271 sending information to and from the stub.
31272
31273 The initial letter of a query or set packet is followed by a name
31274 indicating what sort of thing the packet applies to. For example,
31275 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
31276 definitions with the stub. These packet names follow some
31277 conventions:
31278
31279 @itemize @bullet
31280 @item
31281 The name must not contain commas, colons or semicolons.
31282 @item
31283 Most @value{GDBN} query and set packets have a leading upper case
31284 letter.
31285 @item
31286 The names of custom vendor packets should use a company prefix, in
31287 lower case, followed by a period. For example, packets designed at
31288 the Acme Corporation might begin with @samp{qacme.foo} (for querying
31289 foos) or @samp{Qacme.bar} (for setting bars).
31290 @end itemize
31291
31292 The name of a query or set packet should be separated from any
31293 parameters by a @samp{:}; the parameters themselves should be
31294 separated by @samp{,} or @samp{;}. Stubs must be careful to match the
31295 full packet name, and check for a separator or the end of the packet,
31296 in case two packet names share a common prefix. New packets should not begin
31297 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
31298 packets predate these conventions, and have arguments without any terminator
31299 for the packet name; we suspect they are in widespread use in places that
31300 are difficult to upgrade. The @samp{qC} packet has no arguments, but some
31301 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
31302 packet.}.
31303
31304 Like the descriptions of the other packets, each description here
31305 has a template showing the packet's overall syntax, followed by an
31306 explanation of the packet's meaning. We include spaces in some of the
31307 templates for clarity; these are not part of the packet's syntax. No
31308 @value{GDBN} packet uses spaces to separate its components.
31309
31310 Here are the currently defined query and set packets:
31311
31312 @table @samp
31313
31314 @item QAllow:@var{op}:@var{val}@dots{}
31315 @cindex @samp{QAllow} packet
31316 Specify which operations @value{GDBN} expects to request of the
31317 target, as a semicolon-separated list of operation name and value
31318 pairs. Possible values for @var{op} include @samp{WriteReg},
31319 @samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
31320 @samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
31321 indicating that @value{GDBN} will not request the operation, or 1,
31322 indicating that it may. (The target can then use this to set up its
31323 own internals optimally, for instance if the debugger never expects to
31324 insert breakpoints, it may not need to install its own trap handler.)
31325
31326 @item qC
31327 @cindex current thread, remote request
31328 @cindex @samp{qC} packet
31329 Return the current thread ID.
31330
31331 Reply:
31332 @table @samp
31333 @item QC @var{thread-id}
31334 Where @var{thread-id} is a thread ID as documented in
31335 @ref{thread-id syntax}.
31336 @item @r{(anything else)}
31337 Any other reply implies the old thread ID.
31338 @end table
31339
31340 @item qCRC:@var{addr},@var{length}
31341 @cindex CRC of memory block, remote request
31342 @cindex @samp{qCRC} packet
31343 Compute the CRC checksum of a block of memory using CRC-32 defined in
31344 IEEE 802.3. The CRC is computed byte at a time, taking the most
31345 significant bit of each byte first. The initial pattern code
31346 @code{0xffffffff} is used to ensure leading zeros affect the CRC.
31347
31348 @emph{Note:} This is the same CRC used in validating separate debug
31349 files (@pxref{Separate Debug Files, , Debugging Information in Separate
31350 Files}). However the algorithm is slightly different. When validating
31351 separate debug files, the CRC is computed taking the @emph{least}
31352 significant bit of each byte first, and the final result is inverted to
31353 detect trailing zeros.
31354
31355 Reply:
31356 @table @samp
31357 @item E @var{NN}
31358 An error (such as memory fault)
31359 @item C @var{crc32}
31360 The specified memory region's checksum is @var{crc32}.
31361 @end table
31362
31363 @item qfThreadInfo
31364 @itemx qsThreadInfo
31365 @cindex list active threads, remote request
31366 @cindex @samp{qfThreadInfo} packet
31367 @cindex @samp{qsThreadInfo} packet
31368 Obtain a list of all active thread IDs from the target (OS). Since there
31369 may be too many active threads to fit into one reply packet, this query
31370 works iteratively: it may require more than one query/reply sequence to
31371 obtain the entire list of threads. The first query of the sequence will
31372 be the @samp{qfThreadInfo} query; subsequent queries in the
31373 sequence will be the @samp{qsThreadInfo} query.
31374
31375 NOTE: This packet replaces the @samp{qL} query (see below).
31376
31377 Reply:
31378 @table @samp
31379 @item m @var{thread-id}
31380 A single thread ID
31381 @item m @var{thread-id},@var{thread-id}@dots{}
31382 a comma-separated list of thread IDs
31383 @item l
31384 (lower case letter @samp{L}) denotes end of list.
31385 @end table
31386
31387 In response to each query, the target will reply with a list of one or
31388 more thread IDs, separated by commas.
31389 @value{GDBN} will respond to each reply with a request for more thread
31390 ids (using the @samp{qs} form of the query), until the target responds
31391 with @samp{l} (lower-case el, for @dfn{last}).
31392 Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
31393 fields.
31394
31395 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
31396 @cindex get thread-local storage address, remote request
31397 @cindex @samp{qGetTLSAddr} packet
31398 Fetch the address associated with thread local storage specified
31399 by @var{thread-id}, @var{offset}, and @var{lm}.
31400
31401 @var{thread-id} is the thread ID associated with the
31402 thread for which to fetch the TLS address. @xref{thread-id syntax}.
31403
31404 @var{offset} is the (big endian, hex encoded) offset associated with the
31405 thread local variable. (This offset is obtained from the debug
31406 information associated with the variable.)
31407
31408 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
31409 the load module associated with the thread local storage. For example,
31410 a @sc{gnu}/Linux system will pass the link map address of the shared
31411 object associated with the thread local storage under consideration.
31412 Other operating environments may choose to represent the load module
31413 differently, so the precise meaning of this parameter will vary.
31414
31415 Reply:
31416 @table @samp
31417 @item @var{XX}@dots{}
31418 Hex encoded (big endian) bytes representing the address of the thread
31419 local storage requested.
31420
31421 @item E @var{nn}
31422 An error occurred. @var{nn} are hex digits.
31423
31424 @item
31425 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
31426 @end table
31427
31428 @item qGetTIBAddr:@var{thread-id}
31429 @cindex get thread information block address
31430 @cindex @samp{qGetTIBAddr} packet
31431 Fetch address of the Windows OS specific Thread Information Block.
31432
31433 @var{thread-id} is the thread ID associated with the thread.
31434
31435 Reply:
31436 @table @samp
31437 @item @var{XX}@dots{}
31438 Hex encoded (big endian) bytes representing the linear address of the
31439 thread information block.
31440
31441 @item E @var{nn}
31442 An error occured. This means that either the thread was not found, or the
31443 address could not be retrieved.
31444
31445 @item
31446 An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
31447 @end table
31448
31449 @item qL @var{startflag} @var{threadcount} @var{nextthread}
31450 Obtain thread information from RTOS. Where: @var{startflag} (one hex
31451 digit) is one to indicate the first query and zero to indicate a
31452 subsequent query; @var{threadcount} (two hex digits) is the maximum
31453 number of threads the response packet can contain; and @var{nextthread}
31454 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
31455 returned in the response as @var{argthread}.
31456
31457 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
31458
31459 Reply:
31460 @table @samp
31461 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
31462 Where: @var{count} (two hex digits) is the number of threads being
31463 returned; @var{done} (one hex digit) is zero to indicate more threads
31464 and one indicates no further threads; @var{argthreadid} (eight hex
31465 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
31466 is a sequence of thread IDs from the target. @var{threadid} (eight hex
31467 digits). See @code{remote.c:parse_threadlist_response()}.
31468 @end table
31469
31470 @item qOffsets
31471 @cindex section offsets, remote request
31472 @cindex @samp{qOffsets} packet
31473 Get section offsets that the target used when relocating the downloaded
31474 image.
31475
31476 Reply:
31477 @table @samp
31478 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
31479 Relocate the @code{Text} section by @var{xxx} from its original address.
31480 Relocate the @code{Data} section by @var{yyy} from its original address.
31481 If the object file format provides segment information (e.g.@: @sc{elf}
31482 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
31483 segments by the supplied offsets.
31484
31485 @emph{Note: while a @code{Bss} offset may be included in the response,
31486 @value{GDBN} ignores this and instead applies the @code{Data} offset
31487 to the @code{Bss} section.}
31488
31489 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
31490 Relocate the first segment of the object file, which conventionally
31491 contains program code, to a starting address of @var{xxx}. If
31492 @samp{DataSeg} is specified, relocate the second segment, which
31493 conventionally contains modifiable data, to a starting address of
31494 @var{yyy}. @value{GDBN} will report an error if the object file
31495 does not contain segment information, or does not contain at least
31496 as many segments as mentioned in the reply. Extra segments are
31497 kept at fixed offsets relative to the last relocated segment.
31498 @end table
31499
31500 @item qP @var{mode} @var{thread-id}
31501 @cindex thread information, remote request
31502 @cindex @samp{qP} packet
31503 Returns information on @var{thread-id}. Where: @var{mode} is a hex
31504 encoded 32 bit mode; @var{thread-id} is a thread ID
31505 (@pxref{thread-id syntax}).
31506
31507 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
31508 (see below).
31509
31510 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
31511
31512 @item QNonStop:1
31513 @item QNonStop:0
31514 @cindex non-stop mode, remote request
31515 @cindex @samp{QNonStop} packet
31516 @anchor{QNonStop}
31517 Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
31518 @xref{Remote Non-Stop}, for more information.
31519
31520 Reply:
31521 @table @samp
31522 @item OK
31523 The request succeeded.
31524
31525 @item E @var{nn}
31526 An error occurred. @var{nn} are hex digits.
31527
31528 @item
31529 An empty reply indicates that @samp{QNonStop} is not supported by
31530 the stub.
31531 @end table
31532
31533 This packet is not probed by default; the remote stub must request it,
31534 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
31535 Use of this packet is controlled by the @code{set non-stop} command;
31536 @pxref{Non-Stop Mode}.
31537
31538 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
31539 @cindex pass signals to inferior, remote request
31540 @cindex @samp{QPassSignals} packet
31541 @anchor{QPassSignals}
31542 Each listed @var{signal} should be passed directly to the inferior process.
31543 Signals are numbered identically to continue packets and stop replies
31544 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
31545 strictly greater than the previous item. These signals do not need to stop
31546 the inferior, or be reported to @value{GDBN}. All other signals should be
31547 reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
31548 combine; any earlier @samp{QPassSignals} list is completely replaced by the
31549 new list. This packet improves performance when using @samp{handle
31550 @var{signal} nostop noprint pass}.
31551
31552 Reply:
31553 @table @samp
31554 @item OK
31555 The request succeeded.
31556
31557 @item E @var{nn}
31558 An error occurred. @var{nn} are hex digits.
31559
31560 @item
31561 An empty reply indicates that @samp{QPassSignals} is not supported by
31562 the stub.
31563 @end table
31564
31565 Use of this packet is controlled by the @code{set remote pass-signals}
31566 command (@pxref{Remote Configuration, set remote pass-signals}).
31567 This packet is not probed by default; the remote stub must request it,
31568 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
31569
31570 @item qRcmd,@var{command}
31571 @cindex execute remote command, remote request
31572 @cindex @samp{qRcmd} packet
31573 @var{command} (hex encoded) is passed to the local interpreter for
31574 execution. Invalid commands should be reported using the output
31575 string. Before the final result packet, the target may also respond
31576 with a number of intermediate @samp{O@var{output}} console output
31577 packets. @emph{Implementors should note that providing access to a
31578 stubs's interpreter may have security implications}.
31579
31580 Reply:
31581 @table @samp
31582 @item OK
31583 A command response with no output.
31584 @item @var{OUTPUT}
31585 A command response with the hex encoded output string @var{OUTPUT}.
31586 @item E @var{NN}
31587 Indicate a badly formed request.
31588 @item
31589 An empty reply indicates that @samp{qRcmd} is not recognized.
31590 @end table
31591
31592 (Note that the @code{qRcmd} packet's name is separated from the
31593 command by a @samp{,}, not a @samp{:}, contrary to the naming
31594 conventions above. Please don't use this packet as a model for new
31595 packets.)
31596
31597 @item qSearch:memory:@var{address};@var{length};@var{search-pattern}
31598 @cindex searching memory, in remote debugging
31599 @cindex @samp{qSearch:memory} packet
31600 @anchor{qSearch memory}
31601 Search @var{length} bytes at @var{address} for @var{search-pattern}.
31602 @var{address} and @var{length} are encoded in hex.
31603 @var{search-pattern} is a sequence of bytes, hex encoded.
31604
31605 Reply:
31606 @table @samp
31607 @item 0
31608 The pattern was not found.
31609 @item 1,address
31610 The pattern was found at @var{address}.
31611 @item E @var{NN}
31612 A badly formed request or an error was encountered while searching memory.
31613 @item
31614 An empty reply indicates that @samp{qSearch:memory} is not recognized.
31615 @end table
31616
31617 @item QStartNoAckMode
31618 @cindex @samp{QStartNoAckMode} packet
31619 @anchor{QStartNoAckMode}
31620 Request that the remote stub disable the normal @samp{+}/@samp{-}
31621 protocol acknowledgments (@pxref{Packet Acknowledgment}).
31622
31623 Reply:
31624 @table @samp
31625 @item OK
31626 The stub has switched to no-acknowledgment mode.
31627 @value{GDBN} acknowledges this reponse,
31628 but neither the stub nor @value{GDBN} shall send or expect further
31629 @samp{+}/@samp{-} acknowledgments in the current connection.
31630 @item
31631 An empty reply indicates that the stub does not support no-acknowledgment mode.
31632 @end table
31633
31634 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
31635 @cindex supported packets, remote query
31636 @cindex features of the remote protocol
31637 @cindex @samp{qSupported} packet
31638 @anchor{qSupported}
31639 Tell the remote stub about features supported by @value{GDBN}, and
31640 query the stub for features it supports. This packet allows
31641 @value{GDBN} and the remote stub to take advantage of each others'
31642 features. @samp{qSupported} also consolidates multiple feature probes
31643 at startup, to improve @value{GDBN} performance---a single larger
31644 packet performs better than multiple smaller probe packets on
31645 high-latency links. Some features may enable behavior which must not
31646 be on by default, e.g.@: because it would confuse older clients or
31647 stubs. Other features may describe packets which could be
31648 automatically probed for, but are not. These features must be
31649 reported before @value{GDBN} will use them. This ``default
31650 unsupported'' behavior is not appropriate for all packets, but it
31651 helps to keep the initial connection time under control with new
31652 versions of @value{GDBN} which support increasing numbers of packets.
31653
31654 Reply:
31655 @table @samp
31656 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
31657 The stub supports or does not support each returned @var{stubfeature},
31658 depending on the form of each @var{stubfeature} (see below for the
31659 possible forms).
31660 @item
31661 An empty reply indicates that @samp{qSupported} is not recognized,
31662 or that no features needed to be reported to @value{GDBN}.
31663 @end table
31664
31665 The allowed forms for each feature (either a @var{gdbfeature} in the
31666 @samp{qSupported} packet, or a @var{stubfeature} in the response)
31667 are:
31668
31669 @table @samp
31670 @item @var{name}=@var{value}
31671 The remote protocol feature @var{name} is supported, and associated
31672 with the specified @var{value}. The format of @var{value} depends
31673 on the feature, but it must not include a semicolon.
31674 @item @var{name}+
31675 The remote protocol feature @var{name} is supported, and does not
31676 need an associated value.
31677 @item @var{name}-
31678 The remote protocol feature @var{name} is not supported.
31679 @item @var{name}?
31680 The remote protocol feature @var{name} may be supported, and
31681 @value{GDBN} should auto-detect support in some other way when it is
31682 needed. This form will not be used for @var{gdbfeature} notifications,
31683 but may be used for @var{stubfeature} responses.
31684 @end table
31685
31686 Whenever the stub receives a @samp{qSupported} request, the
31687 supplied set of @value{GDBN} features should override any previous
31688 request. This allows @value{GDBN} to put the stub in a known
31689 state, even if the stub had previously been communicating with
31690 a different version of @value{GDBN}.
31691
31692 The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
31693 are defined:
31694
31695 @table @samp
31696 @item multiprocess
31697 This feature indicates whether @value{GDBN} supports multiprocess
31698 extensions to the remote protocol. @value{GDBN} does not use such
31699 extensions unless the stub also reports that it supports them by
31700 including @samp{multiprocess+} in its @samp{qSupported} reply.
31701 @xref{multiprocess extensions}, for details.
31702
31703 @item xmlRegisters
31704 This feature indicates that @value{GDBN} supports the XML target
31705 description. If the stub sees @samp{xmlRegisters=} with target
31706 specific strings separated by a comma, it will report register
31707 description.
31708
31709 @item qRelocInsn
31710 This feature indicates whether @value{GDBN} supports the
31711 @samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
31712 instruction reply packet}).
31713 @end table
31714
31715 Stubs should ignore any unknown values for
31716 @var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
31717 packet supports receiving packets of unlimited length (earlier
31718 versions of @value{GDBN} may reject overly long responses). Additional values
31719 for @var{gdbfeature} may be defined in the future to let the stub take
31720 advantage of new features in @value{GDBN}, e.g.@: incompatible
31721 improvements in the remote protocol---the @samp{multiprocess} feature is
31722 an example of such a feature. The stub's reply should be independent
31723 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
31724 describes all the features it supports, and then the stub replies with
31725 all the features it supports.
31726
31727 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
31728 responses, as long as each response uses one of the standard forms.
31729
31730 Some features are flags. A stub which supports a flag feature
31731 should respond with a @samp{+} form response. Other features
31732 require values, and the stub should respond with an @samp{=}
31733 form response.
31734
31735 Each feature has a default value, which @value{GDBN} will use if
31736 @samp{qSupported} is not available or if the feature is not mentioned
31737 in the @samp{qSupported} response. The default values are fixed; a
31738 stub is free to omit any feature responses that match the defaults.
31739
31740 Not all features can be probed, but for those which can, the probing
31741 mechanism is useful: in some cases, a stub's internal
31742 architecture may not allow the protocol layer to know some information
31743 about the underlying target in advance. This is especially common in
31744 stubs which may be configured for multiple targets.
31745
31746 These are the currently defined stub features and their properties:
31747
31748 @multitable @columnfractions 0.35 0.2 0.12 0.2
31749 @c NOTE: The first row should be @headitem, but we do not yet require
31750 @c a new enough version of Texinfo (4.7) to use @headitem.
31751 @item Feature Name
31752 @tab Value Required
31753 @tab Default
31754 @tab Probe Allowed
31755
31756 @item @samp{PacketSize}
31757 @tab Yes
31758 @tab @samp{-}
31759 @tab No
31760
31761 @item @samp{qXfer:auxv:read}
31762 @tab No
31763 @tab @samp{-}
31764 @tab Yes
31765
31766 @item @samp{qXfer:features:read}
31767 @tab No
31768 @tab @samp{-}
31769 @tab Yes
31770
31771 @item @samp{qXfer:libraries:read}
31772 @tab No
31773 @tab @samp{-}
31774 @tab Yes
31775
31776 @item @samp{qXfer:memory-map:read}
31777 @tab No
31778 @tab @samp{-}
31779 @tab Yes
31780
31781 @item @samp{qXfer:spu:read}
31782 @tab No
31783 @tab @samp{-}
31784 @tab Yes
31785
31786 @item @samp{qXfer:spu:write}
31787 @tab No
31788 @tab @samp{-}
31789 @tab Yes
31790
31791 @item @samp{qXfer:siginfo:read}
31792 @tab No
31793 @tab @samp{-}
31794 @tab Yes
31795
31796 @item @samp{qXfer:siginfo:write}
31797 @tab No
31798 @tab @samp{-}
31799 @tab Yes
31800
31801 @item @samp{qXfer:threads:read}
31802 @tab No
31803 @tab @samp{-}
31804 @tab Yes
31805
31806
31807 @item @samp{QNonStop}
31808 @tab No
31809 @tab @samp{-}
31810 @tab Yes
31811
31812 @item @samp{QPassSignals}
31813 @tab No
31814 @tab @samp{-}
31815 @tab Yes
31816
31817 @item @samp{QStartNoAckMode}
31818 @tab No
31819 @tab @samp{-}
31820 @tab Yes
31821
31822 @item @samp{multiprocess}
31823 @tab No
31824 @tab @samp{-}
31825 @tab No
31826
31827 @item @samp{ConditionalTracepoints}
31828 @tab No
31829 @tab @samp{-}
31830 @tab No
31831
31832 @item @samp{ReverseContinue}
31833 @tab No
31834 @tab @samp{-}
31835 @tab No
31836
31837 @item @samp{ReverseStep}
31838 @tab No
31839 @tab @samp{-}
31840 @tab No
31841
31842 @item @samp{TracepointSource}
31843 @tab No
31844 @tab @samp{-}
31845 @tab No
31846
31847 @item @samp{QAllow}
31848 @tab No
31849 @tab @samp{-}
31850 @tab No
31851
31852 @end multitable
31853
31854 These are the currently defined stub features, in more detail:
31855
31856 @table @samp
31857 @cindex packet size, remote protocol
31858 @item PacketSize=@var{bytes}
31859 The remote stub can accept packets up to at least @var{bytes} in
31860 length. @value{GDBN} will send packets up to this size for bulk
31861 transfers, and will never send larger packets. This is a limit on the
31862 data characters in the packet, including the frame and checksum.
31863 There is no trailing NUL byte in a remote protocol packet; if the stub
31864 stores packets in a NUL-terminated format, it should allow an extra
31865 byte in its buffer for the NUL. If this stub feature is not supported,
31866 @value{GDBN} guesses based on the size of the @samp{g} packet response.
31867
31868 @item qXfer:auxv:read
31869 The remote stub understands the @samp{qXfer:auxv:read} packet
31870 (@pxref{qXfer auxiliary vector read}).
31871
31872 @item qXfer:features:read
31873 The remote stub understands the @samp{qXfer:features:read} packet
31874 (@pxref{qXfer target description read}).
31875
31876 @item qXfer:libraries:read
31877 The remote stub understands the @samp{qXfer:libraries:read} packet
31878 (@pxref{qXfer library list read}).
31879
31880 @item qXfer:memory-map:read
31881 The remote stub understands the @samp{qXfer:memory-map:read} packet
31882 (@pxref{qXfer memory map read}).
31883
31884 @item qXfer:spu:read
31885 The remote stub understands the @samp{qXfer:spu:read} packet
31886 (@pxref{qXfer spu read}).
31887
31888 @item qXfer:spu:write
31889 The remote stub understands the @samp{qXfer:spu:write} packet
31890 (@pxref{qXfer spu write}).
31891
31892 @item qXfer:siginfo:read
31893 The remote stub understands the @samp{qXfer:siginfo:read} packet
31894 (@pxref{qXfer siginfo read}).
31895
31896 @item qXfer:siginfo:write
31897 The remote stub understands the @samp{qXfer:siginfo:write} packet
31898 (@pxref{qXfer siginfo write}).
31899
31900 @item qXfer:threads:read
31901 The remote stub understands the @samp{qXfer:threads:read} packet
31902 (@pxref{qXfer threads read}).
31903
31904 @item QNonStop
31905 The remote stub understands the @samp{QNonStop} packet
31906 (@pxref{QNonStop}).
31907
31908 @item QPassSignals
31909 The remote stub understands the @samp{QPassSignals} packet
31910 (@pxref{QPassSignals}).
31911
31912 @item QStartNoAckMode
31913 The remote stub understands the @samp{QStartNoAckMode} packet and
31914 prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
31915
31916 @item multiprocess
31917 @anchor{multiprocess extensions}
31918 @cindex multiprocess extensions, in remote protocol
31919 The remote stub understands the multiprocess extensions to the remote
31920 protocol syntax. The multiprocess extensions affect the syntax of
31921 thread IDs in both packets and replies (@pxref{thread-id syntax}), and
31922 add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
31923 replies. Note that reporting this feature indicates support for the
31924 syntactic extensions only, not that the stub necessarily supports
31925 debugging of more than one process at a time. The stub must not use
31926 multiprocess extensions in packet replies unless @value{GDBN} has also
31927 indicated it supports them in its @samp{qSupported} request.
31928
31929 @item qXfer:osdata:read
31930 The remote stub understands the @samp{qXfer:osdata:read} packet
31931 ((@pxref{qXfer osdata read}).
31932
31933 @item ConditionalTracepoints
31934 The remote stub accepts and implements conditional expressions defined
31935 for tracepoints (@pxref{Tracepoint Conditions}).
31936
31937 @item ReverseContinue
31938 The remote stub accepts and implements the reverse continue packet
31939 (@pxref{bc}).
31940
31941 @item ReverseStep
31942 The remote stub accepts and implements the reverse step packet
31943 (@pxref{bs}).
31944
31945 @item TracepointSource
31946 The remote stub understands the @samp{QTDPsrc} packet that supplies
31947 the source form of tracepoint definitions.
31948
31949 @item QAllow
31950 The remote stub understands the @samp{QAllow} packet.
31951
31952 @end table
31953
31954 @item qSymbol::
31955 @cindex symbol lookup, remote request
31956 @cindex @samp{qSymbol} packet
31957 Notify the target that @value{GDBN} is prepared to serve symbol lookup
31958 requests. Accept requests from the target for the values of symbols.
31959
31960 Reply:
31961 @table @samp
31962 @item OK
31963 The target does not need to look up any (more) symbols.
31964 @item qSymbol:@var{sym_name}
31965 The target requests the value of symbol @var{sym_name} (hex encoded).
31966 @value{GDBN} may provide the value by using the
31967 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
31968 below.
31969 @end table
31970
31971 @item qSymbol:@var{sym_value}:@var{sym_name}
31972 Set the value of @var{sym_name} to @var{sym_value}.
31973
31974 @var{sym_name} (hex encoded) is the name of a symbol whose value the
31975 target has previously requested.
31976
31977 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
31978 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
31979 will be empty.
31980
31981 Reply:
31982 @table @samp
31983 @item OK
31984 The target does not need to look up any (more) symbols.
31985 @item qSymbol:@var{sym_name}
31986 The target requests the value of a new symbol @var{sym_name} (hex
31987 encoded). @value{GDBN} will continue to supply the values of symbols
31988 (if available), until the target ceases to request them.
31989 @end table
31990
31991 @item qTBuffer
31992 @item QTBuffer
31993 @item QTDisconnected
31994 @itemx QTDP
31995 @itemx QTDPsrc
31996 @itemx QTDV
31997 @itemx qTfP
31998 @itemx qTfV
31999 @itemx QTFrame
32000 @xref{Tracepoint Packets}.
32001
32002 @item qThreadExtraInfo,@var{thread-id}
32003 @cindex thread attributes info, remote request
32004 @cindex @samp{qThreadExtraInfo} packet
32005 Obtain a printable string description of a thread's attributes from
32006 the target OS. @var{thread-id} is a thread ID;
32007 see @ref{thread-id syntax}. This
32008 string may contain anything that the target OS thinks is interesting
32009 for @value{GDBN} to tell the user about the thread. The string is
32010 displayed in @value{GDBN}'s @code{info threads} display. Some
32011 examples of possible thread extra info strings are @samp{Runnable}, or
32012 @samp{Blocked on Mutex}.
32013
32014 Reply:
32015 @table @samp
32016 @item @var{XX}@dots{}
32017 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
32018 comprising the printable string containing the extra information about
32019 the thread's attributes.
32020 @end table
32021
32022 (Note that the @code{qThreadExtraInfo} packet's name is separated from
32023 the command by a @samp{,}, not a @samp{:}, contrary to the naming
32024 conventions above. Please don't use this packet as a model for new
32025 packets.)
32026
32027 @item QTSave
32028 @item qTsP
32029 @item qTsV
32030 @itemx QTStart
32031 @itemx QTStop
32032 @itemx QTinit
32033 @itemx QTro
32034 @itemx qTStatus
32035 @itemx qTV
32036 @xref{Tracepoint Packets}.
32037
32038 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
32039 @cindex read special object, remote request
32040 @cindex @samp{qXfer} packet
32041 @anchor{qXfer read}
32042 Read uninterpreted bytes from the target's special data area
32043 identified by the keyword @var{object}. Request @var{length} bytes
32044 starting at @var{offset} bytes into the data. The content and
32045 encoding of @var{annex} is specific to @var{object}; it can supply
32046 additional details about what data to access.
32047
32048 Here are the specific requests of this form defined so far. All
32049 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
32050 formats, listed below.
32051
32052 @table @samp
32053 @item qXfer:auxv:read::@var{offset},@var{length}
32054 @anchor{qXfer auxiliary vector read}
32055 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
32056 auxiliary vector}. Note @var{annex} must be empty.
32057
32058 This packet is not probed by default; the remote stub must request it,
32059 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
32060
32061 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
32062 @anchor{qXfer target description read}
32063 Access the @dfn{target description}. @xref{Target Descriptions}. The
32064 annex specifies which XML document to access. The main description is
32065 always loaded from the @samp{target.xml} annex.
32066
32067 This packet is not probed by default; the remote stub must request it,
32068 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
32069
32070 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
32071 @anchor{qXfer library list read}
32072 Access the target's list of loaded libraries. @xref{Library List Format}.
32073 The annex part of the generic @samp{qXfer} packet must be empty
32074 (@pxref{qXfer read}).
32075
32076 Targets which maintain a list of libraries in the program's memory do
32077 not need to implement this packet; it is designed for platforms where
32078 the operating system manages the list of loaded libraries.
32079
32080 This packet is not probed by default; the remote stub must request it,
32081 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
32082
32083 @item qXfer:memory-map:read::@var{offset},@var{length}
32084 @anchor{qXfer memory map read}
32085 Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
32086 annex part of the generic @samp{qXfer} packet must be empty
32087 (@pxref{qXfer read}).
32088
32089 This packet is not probed by default; the remote stub must request it,
32090 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
32091
32092 @item qXfer:siginfo:read::@var{offset},@var{length}
32093 @anchor{qXfer siginfo read}
32094 Read contents of the extra signal information on the target
32095 system. The annex part of the generic @samp{qXfer} packet must be
32096 empty (@pxref{qXfer read}).
32097
32098 This packet is not probed by default; the remote stub must request it,
32099 by supplying an appropriate @samp{qSupported} response
32100 (@pxref{qSupported}).
32101
32102 @item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
32103 @anchor{qXfer spu read}
32104 Read contents of an @code{spufs} file on the target system. The
32105 annex specifies which file to read; it must be of the form
32106 @file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
32107 in the target process, and @var{name} identifes the @code{spufs} file
32108 in that context to be accessed.
32109
32110 This packet is not probed by default; the remote stub must request it,
32111 by supplying an appropriate @samp{qSupported} response
32112 (@pxref{qSupported}).
32113
32114 @item qXfer:threads:read::@var{offset},@var{length}
32115 @anchor{qXfer threads read}
32116 Access the list of threads on target. @xref{Thread List Format}. The
32117 annex part of the generic @samp{qXfer} packet must be empty
32118 (@pxref{qXfer read}).
32119
32120 This packet is not probed by default; the remote stub must request it,
32121 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
32122
32123 @item qXfer:osdata:read::@var{offset},@var{length}
32124 @anchor{qXfer osdata read}
32125 Access the target's @dfn{operating system information}.
32126 @xref{Operating System Information}.
32127
32128 @end table
32129
32130 Reply:
32131 @table @samp
32132 @item m @var{data}
32133 Data @var{data} (@pxref{Binary Data}) has been read from the
32134 target. There may be more data at a higher address (although
32135 it is permitted to return @samp{m} even for the last valid
32136 block of data, as long as at least one byte of data was read).
32137 @var{data} may have fewer bytes than the @var{length} in the
32138 request.
32139
32140 @item l @var{data}
32141 Data @var{data} (@pxref{Binary Data}) has been read from the target.
32142 There is no more data to be read. @var{data} may have fewer bytes
32143 than the @var{length} in the request.
32144
32145 @item l
32146 The @var{offset} in the request is at the end of the data.
32147 There is no more data to be read.
32148
32149 @item E00
32150 The request was malformed, or @var{annex} was invalid.
32151
32152 @item E @var{nn}
32153 The offset was invalid, or there was an error encountered reading the data.
32154 @var{nn} is a hex-encoded @code{errno} value.
32155
32156 @item
32157 An empty reply indicates the @var{object} string was not recognized by
32158 the stub, or that the object does not support reading.
32159 @end table
32160
32161 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
32162 @cindex write data into object, remote request
32163 @anchor{qXfer write}
32164 Write uninterpreted bytes into the target's special data area
32165 identified by the keyword @var{object}, starting at @var{offset} bytes
32166 into the data. @var{data}@dots{} is the binary-encoded data
32167 (@pxref{Binary Data}) to be written. The content and encoding of @var{annex}
32168 is specific to @var{object}; it can supply additional details about what data
32169 to access.
32170
32171 Here are the specific requests of this form defined so far. All
32172 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
32173 formats, listed below.
32174
32175 @table @samp
32176 @item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
32177 @anchor{qXfer siginfo write}
32178 Write @var{data} to the extra signal information on the target system.
32179 The annex part of the generic @samp{qXfer} packet must be
32180 empty (@pxref{qXfer write}).
32181
32182 This packet is not probed by default; the remote stub must request it,
32183 by supplying an appropriate @samp{qSupported} response
32184 (@pxref{qSupported}).
32185
32186 @item qXfer:spu:write:@var{annex}:@var{offset}:@var{data}@dots{}
32187 @anchor{qXfer spu write}
32188 Write @var{data} to an @code{spufs} file on the target system. The
32189 annex specifies which file to write; it must be of the form
32190 @file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
32191 in the target process, and @var{name} identifes the @code{spufs} file
32192 in that context to be accessed.
32193
32194 This packet is not probed by default; the remote stub must request it,
32195 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
32196 @end table
32197
32198 Reply:
32199 @table @samp
32200 @item @var{nn}
32201 @var{nn} (hex encoded) is the number of bytes written.
32202 This may be fewer bytes than supplied in the request.
32203
32204 @item E00
32205 The request was malformed, or @var{annex} was invalid.
32206
32207 @item E @var{nn}
32208 The offset was invalid, or there was an error encountered writing the data.
32209 @var{nn} is a hex-encoded @code{errno} value.
32210
32211 @item
32212 An empty reply indicates the @var{object} string was not
32213 recognized by the stub, or that the object does not support writing.
32214 @end table
32215
32216 @item qXfer:@var{object}:@var{operation}:@dots{}
32217 Requests of this form may be added in the future. When a stub does
32218 not recognize the @var{object} keyword, or its support for
32219 @var{object} does not recognize the @var{operation} keyword, the stub
32220 must respond with an empty packet.
32221
32222 @item qAttached:@var{pid}
32223 @cindex query attached, remote request
32224 @cindex @samp{qAttached} packet
32225 Return an indication of whether the remote server attached to an
32226 existing process or created a new process. When the multiprocess
32227 protocol extensions are supported (@pxref{multiprocess extensions}),
32228 @var{pid} is an integer in hexadecimal format identifying the target
32229 process. Otherwise, @value{GDBN} will omit the @var{pid} field and
32230 the query packet will be simplified as @samp{qAttached}.
32231
32232 This query is used, for example, to know whether the remote process
32233 should be detached or killed when a @value{GDBN} session is ended with
32234 the @code{quit} command.
32235
32236 Reply:
32237 @table @samp
32238 @item 1
32239 The remote server attached to an existing process.
32240 @item 0
32241 The remote server created a new process.
32242 @item E @var{NN}
32243 A badly formed request or an error was encountered.
32244 @end table
32245
32246 @end table
32247
32248 @node Architecture-Specific Protocol Details
32249 @section Architecture-Specific Protocol Details
32250
32251 This section describes how the remote protocol is applied to specific
32252 target architectures. Also see @ref{Standard Target Features}, for
32253 details of XML target descriptions for each architecture.
32254
32255 @subsection ARM
32256
32257 @subsubsection Breakpoint Kinds
32258
32259 These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
32260
32261 @table @r
32262
32263 @item 2
32264 16-bit Thumb mode breakpoint.
32265
32266 @item 3
32267 32-bit Thumb mode (Thumb-2) breakpoint.
32268
32269 @item 4
32270 32-bit ARM mode breakpoint.
32271
32272 @end table
32273
32274 @subsection MIPS
32275
32276 @subsubsection Register Packet Format
32277
32278 The following @code{g}/@code{G} packets have previously been defined.
32279 In the below, some thirty-two bit registers are transferred as
32280 sixty-four bits. Those registers should be zero/sign extended (which?)
32281 to fill the space allocated. Register bytes are transferred in target
32282 byte order. The two nibbles within a register byte are transferred
32283 most-significant - least-significant.
32284
32285 @table @r
32286
32287 @item MIPS32
32288
32289 All registers are transferred as thirty-two bit quantities in the order:
32290 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
32291 registers; fsr; fir; fp.
32292
32293 @item MIPS64
32294
32295 All registers are transferred as sixty-four bit quantities (including
32296 thirty-two bit registers such as @code{sr}). The ordering is the same
32297 as @code{MIPS32}.
32298
32299 @end table
32300
32301 @node Tracepoint Packets
32302 @section Tracepoint Packets
32303 @cindex tracepoint packets
32304 @cindex packets, tracepoint
32305
32306 Here we describe the packets @value{GDBN} uses to implement
32307 tracepoints (@pxref{Tracepoints}).
32308
32309 @table @samp
32310
32311 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
32312 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
32313 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
32314 the tracepoint is disabled. @var{step} is the tracepoint's step
32315 count, and @var{pass} is its pass count. If an @samp{F} is present,
32316 then the tracepoint is to be a fast tracepoint, and the @var{flen} is
32317 the number of bytes that the target should copy elsewhere to make room
32318 for the tracepoint. If an @samp{X} is present, it introduces a
32319 tracepoint condition, which consists of a hexadecimal length, followed
32320 by a comma and hex-encoded bytes, in a manner similar to action
32321 encodings as described below. If the trailing @samp{-} is present,
32322 further @samp{QTDP} packets will follow to specify this tracepoint's
32323 actions.
32324
32325 Replies:
32326 @table @samp
32327 @item OK
32328 The packet was understood and carried out.
32329 @item qRelocInsn
32330 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
32331 @item
32332 The packet was not recognized.
32333 @end table
32334
32335 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
32336 Define actions to be taken when a tracepoint is hit. @var{n} and
32337 @var{addr} must be the same as in the initial @samp{QTDP} packet for
32338 this tracepoint. This packet may only be sent immediately after
32339 another @samp{QTDP} packet that ended with a @samp{-}. If the
32340 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
32341 specifying more actions for this tracepoint.
32342
32343 In the series of action packets for a given tracepoint, at most one
32344 can have an @samp{S} before its first @var{action}. If such a packet
32345 is sent, it and the following packets define ``while-stepping''
32346 actions. Any prior packets define ordinary actions --- that is, those
32347 taken when the tracepoint is first hit. If no action packet has an
32348 @samp{S}, then all the packets in the series specify ordinary
32349 tracepoint actions.
32350
32351 The @samp{@var{action}@dots{}} portion of the packet is a series of
32352 actions, concatenated without separators. Each action has one of the
32353 following forms:
32354
32355 @table @samp
32356
32357 @item R @var{mask}
32358 Collect the registers whose bits are set in @var{mask}. @var{mask} is
32359 a hexadecimal number whose @var{i}'th bit is set if register number
32360 @var{i} should be collected. (The least significant bit is numbered
32361 zero.) Note that @var{mask} may be any number of digits long; it may
32362 not fit in a 32-bit word.
32363
32364 @item M @var{basereg},@var{offset},@var{len}
32365 Collect @var{len} bytes of memory starting at the address in register
32366 number @var{basereg}, plus @var{offset}. If @var{basereg} is
32367 @samp{-1}, then the range has a fixed address: @var{offset} is the
32368 address of the lowest byte to collect. The @var{basereg},
32369 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
32370 values (the @samp{-1} value for @var{basereg} is a special case).
32371
32372 @item X @var{len},@var{expr}
32373 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
32374 it directs. @var{expr} is an agent expression, as described in
32375 @ref{Agent Expressions}. Each byte of the expression is encoded as a
32376 two-digit hex number in the packet; @var{len} is the number of bytes
32377 in the expression (and thus one-half the number of hex digits in the
32378 packet).
32379
32380 @end table
32381
32382 Any number of actions may be packed together in a single @samp{QTDP}
32383 packet, as long as the packet does not exceed the maximum packet
32384 length (400 bytes, for many stubs). There may be only one @samp{R}
32385 action per tracepoint, and it must precede any @samp{M} or @samp{X}
32386 actions. Any registers referred to by @samp{M} and @samp{X} actions
32387 must be collected by a preceding @samp{R} action. (The
32388 ``while-stepping'' actions are treated as if they were attached to a
32389 separate tracepoint, as far as these restrictions are concerned.)
32390
32391 Replies:
32392 @table @samp
32393 @item OK
32394 The packet was understood and carried out.
32395 @item qRelocInsn
32396 @xref{Tracepoint Packets,,Relocate instruction reply packet}.
32397 @item
32398 The packet was not recognized.
32399 @end table
32400
32401 @item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
32402 @cindex @samp{QTDPsrc} packet
32403 Specify a source string of tracepoint @var{n} at address @var{addr}.
32404 This is useful to get accurate reproduction of the tracepoints
32405 originally downloaded at the beginning of the trace run. @var{type}
32406 is the name of the tracepoint part, such as @samp{cond} for the
32407 tracepoint's conditional expression (see below for a list of types), while
32408 @var{bytes} is the string, encoded in hexadecimal.
32409
32410 @var{start} is the offset of the @var{bytes} within the overall source
32411 string, while @var{slen} is the total length of the source string.
32412 This is intended for handling source strings that are longer than will
32413 fit in a single packet.
32414 @c Add detailed example when this info is moved into a dedicated
32415 @c tracepoint descriptions section.
32416
32417 The available string types are @samp{at} for the location,
32418 @samp{cond} for the conditional, and @samp{cmd} for an action command.
32419 @value{GDBN} sends a separate packet for each command in the action
32420 list, in the same order in which the commands are stored in the list.
32421
32422 The target does not need to do anything with source strings except
32423 report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
32424 query packets.
32425
32426 Although this packet is optional, and @value{GDBN} will only send it
32427 if the target replies with @samp{TracepointSource} @xref{General
32428 Query Packets}, it makes both disconnected tracing and trace files
32429 much easier to use. Otherwise the user must be careful that the
32430 tracepoints in effect while looking at trace frames are identical to
32431 the ones in effect during the trace run; even a small discrepancy
32432 could cause @samp{tdump} not to work, or a particular trace frame not
32433 be found.
32434
32435 @item QTDV:@var{n}:@var{value}
32436 @cindex define trace state variable, remote request
32437 @cindex @samp{QTDV} packet
32438 Create a new trace state variable, number @var{n}, with an initial
32439 value of @var{value}, which is a 64-bit signed integer. Both @var{n}
32440 and @var{value} are encoded as hexadecimal values. @value{GDBN} has
32441 the option of not using this packet for initial values of zero; the
32442 target should simply create the trace state variables as they are
32443 mentioned in expressions.
32444
32445 @item QTFrame:@var{n}
32446 Select the @var{n}'th tracepoint frame from the buffer, and use the
32447 register and memory contents recorded there to answer subsequent
32448 request packets from @value{GDBN}.
32449
32450 A successful reply from the stub indicates that the stub has found the
32451 requested frame. The response is a series of parts, concatenated
32452 without separators, describing the frame we selected. Each part has
32453 one of the following forms:
32454
32455 @table @samp
32456 @item F @var{f}
32457 The selected frame is number @var{n} in the trace frame buffer;
32458 @var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
32459 was no frame matching the criteria in the request packet.
32460
32461 @item T @var{t}
32462 The selected trace frame records a hit of tracepoint number @var{t};
32463 @var{t} is a hexadecimal number.
32464
32465 @end table
32466
32467 @item QTFrame:pc:@var{addr}
32468 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
32469 currently selected frame whose PC is @var{addr};
32470 @var{addr} is a hexadecimal number.
32471
32472 @item QTFrame:tdp:@var{t}
32473 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
32474 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
32475 is a hexadecimal number.
32476
32477 @item QTFrame:range:@var{start}:@var{end}
32478 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
32479 currently selected frame whose PC is between @var{start} (inclusive)
32480 and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
32481 numbers.
32482
32483 @item QTFrame:outside:@var{start}:@var{end}
32484 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
32485 frame @emph{outside} the given range of addresses (exclusive).
32486
32487 @item QTStart
32488 Begin the tracepoint experiment. Begin collecting data from
32489 tracepoint hits in the trace frame buffer. This packet supports the
32490 @samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
32491 instruction reply packet}).
32492
32493 @item QTStop
32494 End the tracepoint experiment. Stop collecting trace frames.
32495
32496 @item QTinit
32497 Clear the table of tracepoints, and empty the trace frame buffer.
32498
32499 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
32500 Establish the given ranges of memory as ``transparent''. The stub
32501 will answer requests for these ranges from memory's current contents,
32502 if they were not collected as part of the tracepoint hit.
32503
32504 @value{GDBN} uses this to mark read-only regions of memory, like those
32505 containing program code. Since these areas never change, they should
32506 still have the same contents they did when the tracepoint was hit, so
32507 there's no reason for the stub to refuse to provide their contents.
32508
32509 @item QTDisconnected:@var{value}
32510 Set the choice to what to do with the tracing run when @value{GDBN}
32511 disconnects from the target. A @var{value} of 1 directs the target to
32512 continue the tracing run, while 0 tells the target to stop tracing if
32513 @value{GDBN} is no longer in the picture.
32514
32515 @item qTStatus
32516 Ask the stub if there is a trace experiment running right now.
32517
32518 The reply has the form:
32519
32520 @table @samp
32521
32522 @item T@var{running}@r{[};@var{field}@r{]}@dots{}
32523 @var{running} is a single digit @code{1} if the trace is presently
32524 running, or @code{0} if not. It is followed by semicolon-separated
32525 optional fields that an agent may use to report additional status.
32526
32527 @end table
32528
32529 If the trace is not running, the agent may report any of several
32530 explanations as one of the optional fields:
32531
32532 @table @samp
32533
32534 @item tnotrun:0
32535 No trace has been run yet.
32536
32537 @item tstop:0
32538 The trace was stopped by a user-originated stop command.
32539
32540 @item tfull:0
32541 The trace stopped because the trace buffer filled up.
32542
32543 @item tdisconnected:0
32544 The trace stopped because @value{GDBN} disconnected from the target.
32545
32546 @item tpasscount:@var{tpnum}
32547 The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
32548
32549 @item terror:@var{text}:@var{tpnum}
32550 The trace stopped because tracepoint @var{tpnum} had an error. The
32551 string @var{text} is available to describe the nature of the error
32552 (for instance, a divide by zero in the condition expression).
32553 @var{text} is hex encoded.
32554
32555 @item tunknown:0
32556 The trace stopped for some other reason.
32557
32558 @end table
32559
32560 Additional optional fields supply statistical and other information.
32561 Although not required, they are extremely useful for users monitoring
32562 the progress of a trace run. If a trace has stopped, and these
32563 numbers are reported, they must reflect the state of the just-stopped
32564 trace.
32565
32566 @table @samp
32567
32568 @item tframes:@var{n}
32569 The number of trace frames in the buffer.
32570
32571 @item tcreated:@var{n}
32572 The total number of trace frames created during the run. This may
32573 be larger than the trace frame count, if the buffer is circular.
32574
32575 @item tsize:@var{n}
32576 The total size of the trace buffer, in bytes.
32577
32578 @item tfree:@var{n}
32579 The number of bytes still unused in the buffer.
32580
32581 @item circular:@var{n}
32582 The value of the circular trace buffer flag. @code{1} means that the
32583 trace buffer is circular and old trace frames will be discarded if
32584 necessary to make room, @code{0} means that the trace buffer is linear
32585 and may fill up.
32586
32587 @item disconn:@var{n}
32588 The value of the disconnected tracing flag. @code{1} means that
32589 tracing will continue after @value{GDBN} disconnects, @code{0} means
32590 that the trace run will stop.
32591
32592 @end table
32593
32594 @item qTV:@var{var}
32595 @cindex trace state variable value, remote request
32596 @cindex @samp{qTV} packet
32597 Ask the stub for the value of the trace state variable number @var{var}.
32598
32599 Replies:
32600 @table @samp
32601 @item V@var{value}
32602 The value of the variable is @var{value}. This will be the current
32603 value of the variable if the user is examining a running target, or a
32604 saved value if the variable was collected in the trace frame that the
32605 user is looking at. Note that multiple requests may result in
32606 different reply values, such as when requesting values while the
32607 program is running.
32608
32609 @item U
32610 The value of the variable is unknown. This would occur, for example,
32611 if the user is examining a trace frame in which the requested variable
32612 was not collected.
32613 @end table
32614
32615 @item qTfP
32616 @itemx qTsP
32617 These packets request data about tracepoints that are being used by
32618 the target. @value{GDBN} sends @code{qTfP} to get the first piece
32619 of data, and multiple @code{qTsP} to get additional pieces. Replies
32620 to these packets generally take the form of the @code{QTDP} packets
32621 that define tracepoints. (FIXME add detailed syntax)
32622
32623 @item qTfV
32624 @itemx qTsV
32625 These packets request data about trace state variables that are on the
32626 target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
32627 and multiple @code{qTsV} to get additional variables. Replies to
32628 these packets follow the syntax of the @code{QTDV} packets that define
32629 trace state variables.
32630
32631 @item QTSave:@var{filename}
32632 This packet directs the target to save trace data to the file name
32633 @var{filename} in the target's filesystem. @var{filename} is encoded
32634 as a hex string; the interpretation of the file name (relative vs
32635 absolute, wild cards, etc) is up to the target.
32636
32637 @item qTBuffer:@var{offset},@var{len}
32638 Return up to @var{len} bytes of the current contents of trace buffer,
32639 starting at @var{offset}. The trace buffer is treated as if it were
32640 a contiguous collection of traceframes, as per the trace file format.
32641 The reply consists as many hex-encoded bytes as the target can deliver
32642 in a packet; it is not an error to return fewer than were asked for.
32643 A reply consisting of just @code{l} indicates that no bytes are
32644 available.
32645
32646 @item QTBuffer:circular:@var{value}
32647 This packet directs the target to use a circular trace buffer if
32648 @var{value} is 1, or a linear buffer if the value is 0.
32649
32650 @end table
32651
32652 @subsection Relocate instruction reply packet
32653 When installing fast tracepoints in memory, the target may need to
32654 relocate the instruction currently at the tracepoint address to a
32655 different address in memory. For most instructions, a simple copy is
32656 enough, but, for example, call instructions that implicitly push the
32657 return address on the stack, and relative branches or other
32658 PC-relative instructions require offset adjustment, so that the effect
32659 of executing the instruction at a different address is the same as if
32660 it had executed in the original location.
32661
32662 In response to several of the tracepoint packets, the target may also
32663 respond with a number of intermediate @samp{qRelocInsn} request
32664 packets before the final result packet, to have @value{GDBN} handle
32665 this relocation operation. If a packet supports this mechanism, its
32666 documentation will explicitly say so. See for example the above
32667 descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
32668 format of the request is:
32669
32670 @table @samp
32671 @item qRelocInsn:@var{from};@var{to}
32672
32673 This requests @value{GDBN} to copy instruction at address @var{from}
32674 to address @var{to}, possibly adjusted so that executing the
32675 instruction at @var{to} has the same effect as executing it at
32676 @var{from}. @value{GDBN} writes the adjusted instruction to target
32677 memory starting at @var{to}.
32678 @end table
32679
32680 Replies:
32681 @table @samp
32682 @item qRelocInsn:@var{adjusted_size}
32683 Informs the stub the relocation is complete. @var{adjusted_size} is
32684 the length in bytes of resulting relocated instruction sequence.
32685 @item E @var{NN}
32686 A badly formed request was detected, or an error was encountered while
32687 relocating the instruction.
32688 @end table
32689
32690 @node Host I/O Packets
32691 @section Host I/O Packets
32692 @cindex Host I/O, remote protocol
32693 @cindex file transfer, remote protocol
32694
32695 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
32696 operations on the far side of a remote link. For example, Host I/O is
32697 used to upload and download files to a remote target with its own
32698 filesystem. Host I/O uses the same constant values and data structure
32699 layout as the target-initiated File-I/O protocol. However, the
32700 Host I/O packets are structured differently. The target-initiated
32701 protocol relies on target memory to store parameters and buffers.
32702 Host I/O requests are initiated by @value{GDBN}, and the
32703 target's memory is not involved. @xref{File-I/O Remote Protocol
32704 Extension}, for more details on the target-initiated protocol.
32705
32706 The Host I/O request packets all encode a single operation along with
32707 its arguments. They have this format:
32708
32709 @table @samp
32710
32711 @item vFile:@var{operation}: @var{parameter}@dots{}
32712 @var{operation} is the name of the particular request; the target
32713 should compare the entire packet name up to the second colon when checking
32714 for a supported operation. The format of @var{parameter} depends on
32715 the operation. Numbers are always passed in hexadecimal. Negative
32716 numbers have an explicit minus sign (i.e.@: two's complement is not
32717 used). Strings (e.g.@: filenames) are encoded as a series of
32718 hexadecimal bytes. The last argument to a system call may be a
32719 buffer of escaped binary data (@pxref{Binary Data}).
32720
32721 @end table
32722
32723 The valid responses to Host I/O packets are:
32724
32725 @table @samp
32726
32727 @item F @var{result} [, @var{errno}] [; @var{attachment}]
32728 @var{result} is the integer value returned by this operation, usually
32729 non-negative for success and -1 for errors. If an error has occured,
32730 @var{errno} will be included in the result. @var{errno} will have a
32731 value defined by the File-I/O protocol (@pxref{Errno Values}). For
32732 operations which return data, @var{attachment} supplies the data as a
32733 binary buffer. Binary buffers in response packets are escaped in the
32734 normal way (@pxref{Binary Data}). See the individual packet
32735 documentation for the interpretation of @var{result} and
32736 @var{attachment}.
32737
32738 @item
32739 An empty response indicates that this operation is not recognized.
32740
32741 @end table
32742
32743 These are the supported Host I/O operations:
32744
32745 @table @samp
32746 @item vFile:open: @var{pathname}, @var{flags}, @var{mode}
32747 Open a file at @var{pathname} and return a file descriptor for it, or
32748 return -1 if an error occurs. @var{pathname} is a string,
32749 @var{flags} is an integer indicating a mask of open flags
32750 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
32751 of mode bits to use if the file is created (@pxref{mode_t Values}).
32752 @xref{open}, for details of the open flags and mode values.
32753
32754 @item vFile:close: @var{fd}
32755 Close the open file corresponding to @var{fd} and return 0, or
32756 -1 if an error occurs.
32757
32758 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
32759 Read data from the open file corresponding to @var{fd}. Up to
32760 @var{count} bytes will be read from the file, starting at @var{offset}
32761 relative to the start of the file. The target may read fewer bytes;
32762 common reasons include packet size limits and an end-of-file
32763 condition. The number of bytes read is returned. Zero should only be
32764 returned for a successful read at the end of the file, or if
32765 @var{count} was zero.
32766
32767 The data read should be returned as a binary attachment on success.
32768 If zero bytes were read, the response should include an empty binary
32769 attachment (i.e.@: a trailing semicolon). The return value is the
32770 number of target bytes read; the binary attachment may be longer if
32771 some characters were escaped.
32772
32773 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
32774 Write @var{data} (a binary buffer) to the open file corresponding
32775 to @var{fd}. Start the write at @var{offset} from the start of the
32776 file. Unlike many @code{write} system calls, there is no
32777 separate @var{count} argument; the length of @var{data} in the
32778 packet is used. @samp{vFile:write} returns the number of bytes written,
32779 which may be shorter than the length of @var{data}, or -1 if an
32780 error occurred.
32781
32782 @item vFile:unlink: @var{pathname}
32783 Delete the file at @var{pathname} on the target. Return 0,
32784 or -1 if an error occurs. @var{pathname} is a string.
32785
32786 @end table
32787
32788 @node Interrupts
32789 @section Interrupts
32790 @cindex interrupts (remote protocol)
32791
32792 When a program on the remote target is running, @value{GDBN} may
32793 attempt to interrupt it by sending a @samp{Ctrl-C}, @code{BREAK} or
32794 a @code{BREAK} followed by @code{g},
32795 control of which is specified via @value{GDBN}'s @samp{interrupt-sequence}.
32796
32797 The precise meaning of @code{BREAK} is defined by the transport
32798 mechanism and may, in fact, be undefined. @value{GDBN} does not
32799 currently define a @code{BREAK} mechanism for any of the network
32800 interfaces except for TCP, in which case @value{GDBN} sends the
32801 @code{telnet} BREAK sequence.
32802
32803 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
32804 transport mechanisms. It is represented by sending the single byte
32805 @code{0x03} without any of the usual packet overhead described in
32806 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
32807 transmitted as part of a packet, it is considered to be packet data
32808 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
32809 (@pxref{X packet}), used for binary downloads, may include an unescaped
32810 @code{0x03} as part of its packet.
32811
32812 @code{BREAK} followed by @code{g} is also known as Magic SysRq g.
32813 When Linux kernel receives this sequence from serial port,
32814 it stops execution and connects to gdb.
32815
32816 Stubs are not required to recognize these interrupt mechanisms and the
32817 precise meaning associated with receipt of the interrupt is
32818 implementation defined. If the target supports debugging of multiple
32819 threads and/or processes, it should attempt to interrupt all
32820 currently-executing threads and processes.
32821 If the stub is successful at interrupting the
32822 running program, it should send one of the stop
32823 reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
32824 of successfully stopping the program in all-stop mode, and a stop reply
32825 for each stopped thread in non-stop mode.
32826 Interrupts received while the
32827 program is stopped are discarded.
32828
32829 @node Notification Packets
32830 @section Notification Packets
32831 @cindex notification packets
32832 @cindex packets, notification
32833
32834 The @value{GDBN} remote serial protocol includes @dfn{notifications},
32835 packets that require no acknowledgment. Both the GDB and the stub
32836 may send notifications (although the only notifications defined at
32837 present are sent by the stub). Notifications carry information
32838 without incurring the round-trip latency of an acknowledgment, and so
32839 are useful for low-impact communications where occasional packet loss
32840 is not a problem.
32841
32842 A notification packet has the form @samp{% @var{data} #
32843 @var{checksum}}, where @var{data} is the content of the notification,
32844 and @var{checksum} is a checksum of @var{data}, computed and formatted
32845 as for ordinary @value{GDBN} packets. A notification's @var{data}
32846 never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
32847 receiving a notification, the recipient sends no @samp{+} or @samp{-}
32848 to acknowledge the notification's receipt or to report its corruption.
32849
32850 Every notification's @var{data} begins with a name, which contains no
32851 colon characters, followed by a colon character.
32852
32853 Recipients should silently ignore corrupted notifications and
32854 notifications they do not understand. Recipients should restart
32855 timeout periods on receipt of a well-formed notification, whether or
32856 not they understand it.
32857
32858 Senders should only send the notifications described here when this
32859 protocol description specifies that they are permitted. In the
32860 future, we may extend the protocol to permit existing notifications in
32861 new contexts; this rule helps older senders avoid confusing newer
32862 recipients.
32863
32864 (Older versions of @value{GDBN} ignore bytes received until they see
32865 the @samp{$} byte that begins an ordinary packet, so new stubs may
32866 transmit notifications without fear of confusing older clients. There
32867 are no notifications defined for @value{GDBN} to send at the moment, but we
32868 assume that most older stubs would ignore them, as well.)
32869
32870 The following notification packets from the stub to @value{GDBN} are
32871 defined:
32872
32873 @table @samp
32874 @item Stop: @var{reply}
32875 Report an asynchronous stop event in non-stop mode.
32876 The @var{reply} has the form of a stop reply, as
32877 described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
32878 for information on how these notifications are acknowledged by
32879 @value{GDBN}.
32880 @end table
32881
32882 @node Remote Non-Stop
32883 @section Remote Protocol Support for Non-Stop Mode
32884
32885 @value{GDBN}'s remote protocol supports non-stop debugging of
32886 multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
32887 supports non-stop mode, it should report that to @value{GDBN} by including
32888 @samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
32889
32890 @value{GDBN} typically sends a @samp{QNonStop} packet only when
32891 establishing a new connection with the stub. Entering non-stop mode
32892 does not alter the state of any currently-running threads, but targets
32893 must stop all threads in any already-attached processes when entering
32894 all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
32895 probe the target state after a mode change.
32896
32897 In non-stop mode, when an attached process encounters an event that
32898 would otherwise be reported with a stop reply, it uses the
32899 asynchronous notification mechanism (@pxref{Notification Packets}) to
32900 inform @value{GDBN}. In contrast to all-stop mode, where all threads
32901 in all processes are stopped when a stop reply is sent, in non-stop
32902 mode only the thread reporting the stop event is stopped. That is,
32903 when reporting a @samp{S} or @samp{T} response to indicate completion
32904 of a step operation, hitting a breakpoint, or a fault, only the
32905 affected thread is stopped; any other still-running threads continue
32906 to run. When reporting a @samp{W} or @samp{X} response, all running
32907 threads belonging to other attached processes continue to run.
32908
32909 Only one stop reply notification at a time may be pending; if
32910 additional stop events occur before @value{GDBN} has acknowledged the
32911 previous notification, they must be queued by the stub for later
32912 synchronous transmission in response to @samp{vStopped} packets from
32913 @value{GDBN}. Because the notification mechanism is unreliable,
32914 the stub is permitted to resend a stop reply notification
32915 if it believes @value{GDBN} may not have received it. @value{GDBN}
32916 ignores additional stop reply notifications received before it has
32917 finished processing a previous notification and the stub has completed
32918 sending any queued stop events.
32919
32920 Otherwise, @value{GDBN} must be prepared to receive a stop reply
32921 notification at any time. Specifically, they may appear when
32922 @value{GDBN} is not otherwise reading input from the stub, or when
32923 @value{GDBN} is expecting to read a normal synchronous response or a
32924 @samp{+}/@samp{-} acknowledgment to a packet it has sent.
32925 Notification packets are distinct from any other communication from
32926 the stub so there is no ambiguity.
32927
32928 After receiving a stop reply notification, @value{GDBN} shall
32929 acknowledge it by sending a @samp{vStopped} packet (@pxref{vStopped packet})
32930 as a regular, synchronous request to the stub. Such acknowledgment
32931 is not required to happen immediately, as @value{GDBN} is permitted to
32932 send other, unrelated packets to the stub first, which the stub should
32933 process normally.
32934
32935 Upon receiving a @samp{vStopped} packet, if the stub has other queued
32936 stop events to report to @value{GDBN}, it shall respond by sending a
32937 normal stop reply response. @value{GDBN} shall then send another
32938 @samp{vStopped} packet to solicit further responses; again, it is
32939 permitted to send other, unrelated packets as well which the stub
32940 should process normally.
32941
32942 If the stub receives a @samp{vStopped} packet and there are no
32943 additional stop events to report, the stub shall return an @samp{OK}
32944 response. At this point, if further stop events occur, the stub shall
32945 send a new stop reply notification, @value{GDBN} shall accept the
32946 notification, and the process shall be repeated.
32947
32948 In non-stop mode, the target shall respond to the @samp{?} packet as
32949 follows. First, any incomplete stop reply notification/@samp{vStopped}
32950 sequence in progress is abandoned. The target must begin a new
32951 sequence reporting stop events for all stopped threads, whether or not
32952 it has previously reported those events to @value{GDBN}. The first
32953 stop reply is sent as a synchronous reply to the @samp{?} packet, and
32954 subsequent stop replies are sent as responses to @samp{vStopped} packets
32955 using the mechanism described above. The target must not send
32956 asynchronous stop reply notifications until the sequence is complete.
32957 If all threads are running when the target receives the @samp{?} packet,
32958 or if the target is not attached to any process, it shall respond
32959 @samp{OK}.
32960
32961 @node Packet Acknowledgment
32962 @section Packet Acknowledgment
32963
32964 @cindex acknowledgment, for @value{GDBN} remote
32965 @cindex packet acknowledgment, for @value{GDBN} remote
32966 By default, when either the host or the target machine receives a packet,
32967 the first response expected is an acknowledgment: either @samp{+} (to indicate
32968 the package was received correctly) or @samp{-} (to request retransmission).
32969 This mechanism allows the @value{GDBN} remote protocol to operate over
32970 unreliable transport mechanisms, such as a serial line.
32971
32972 In cases where the transport mechanism is itself reliable (such as a pipe or
32973 TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
32974 It may be desirable to disable them in that case to reduce communication
32975 overhead, or for other reasons. This can be accomplished by means of the
32976 @samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
32977
32978 When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
32979 expect @samp{+}/@samp{-} protocol acknowledgments. The packet
32980 and response format still includes the normal checksum, as described in
32981 @ref{Overview}, but the checksum may be ignored by the receiver.
32982
32983 If the stub supports @samp{QStartNoAckMode} and prefers to operate in
32984 no-acknowledgment mode, it should report that to @value{GDBN}
32985 by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
32986 @pxref{qSupported}.
32987 If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
32988 disabled via the @code{set remote noack-packet off} command
32989 (@pxref{Remote Configuration}),
32990 @value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
32991 Only then may the stub actually turn off packet acknowledgments.
32992 @value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
32993 response, which can be safely ignored by the stub.
32994
32995 Note that @code{set remote noack-packet} command only affects negotiation
32996 between @value{GDBN} and the stub when subsequent connections are made;
32997 it does not affect the protocol acknowledgment state for any current
32998 connection.
32999 Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
33000 new connection is established,
33001 there is also no protocol request to re-enable the acknowledgments
33002 for the current connection, once disabled.
33003
33004 @node Examples
33005 @section Examples
33006
33007 Example sequence of a target being re-started. Notice how the restart
33008 does not get any direct output:
33009
33010 @smallexample
33011 -> @code{R00}
33012 <- @code{+}
33013 @emph{target restarts}
33014 -> @code{?}
33015 <- @code{+}
33016 <- @code{T001:1234123412341234}
33017 -> @code{+}
33018 @end smallexample
33019
33020 Example sequence of a target being stepped by a single instruction:
33021
33022 @smallexample
33023 -> @code{G1445@dots{}}
33024 <- @code{+}
33025 -> @code{s}
33026 <- @code{+}
33027 @emph{time passes}
33028 <- @code{T001:1234123412341234}
33029 -> @code{+}
33030 -> @code{g}
33031 <- @code{+}
33032 <- @code{1455@dots{}}
33033 -> @code{+}
33034 @end smallexample
33035
33036 @node File-I/O Remote Protocol Extension
33037 @section File-I/O Remote Protocol Extension
33038 @cindex File-I/O remote protocol extension
33039
33040 @menu
33041 * File-I/O Overview::
33042 * Protocol Basics::
33043 * The F Request Packet::
33044 * The F Reply Packet::
33045 * The Ctrl-C Message::
33046 * Console I/O::
33047 * List of Supported Calls::
33048 * Protocol-specific Representation of Datatypes::
33049 * Constants::
33050 * File-I/O Examples::
33051 @end menu
33052
33053 @node File-I/O Overview
33054 @subsection File-I/O Overview
33055 @cindex file-i/o overview
33056
33057 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
33058 target to use the host's file system and console I/O to perform various
33059 system calls. System calls on the target system are translated into a
33060 remote protocol packet to the host system, which then performs the needed
33061 actions and returns a response packet to the target system.
33062 This simulates file system operations even on targets that lack file systems.
33063
33064 The protocol is defined to be independent of both the host and target systems.
33065 It uses its own internal representation of datatypes and values. Both
33066 @value{GDBN} and the target's @value{GDBN} stub are responsible for
33067 translating the system-dependent value representations into the internal
33068 protocol representations when data is transmitted.
33069
33070 The communication is synchronous. A system call is possible only when
33071 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
33072 or @samp{s} packets. While @value{GDBN} handles the request for a system call,
33073 the target is stopped to allow deterministic access to the target's
33074 memory. Therefore File-I/O is not interruptible by target signals. On
33075 the other hand, it is possible to interrupt File-I/O by a user interrupt
33076 (@samp{Ctrl-C}) within @value{GDBN}.
33077
33078 The target's request to perform a host system call does not finish
33079 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
33080 after finishing the system call, the target returns to continuing the
33081 previous activity (continue, step). No additional continue or step
33082 request from @value{GDBN} is required.
33083
33084 @smallexample
33085 (@value{GDBP}) continue
33086 <- target requests 'system call X'
33087 target is stopped, @value{GDBN} executes system call
33088 -> @value{GDBN} returns result
33089 ... target continues, @value{GDBN} returns to wait for the target
33090 <- target hits breakpoint and sends a Txx packet
33091 @end smallexample
33092
33093 The protocol only supports I/O on the console and to regular files on
33094 the host file system. Character or block special devices, pipes,
33095 named pipes, sockets or any other communication method on the host
33096 system are not supported by this protocol.
33097
33098 File I/O is not supported in non-stop mode.
33099
33100 @node Protocol Basics
33101 @subsection Protocol Basics
33102 @cindex protocol basics, file-i/o
33103
33104 The File-I/O protocol uses the @code{F} packet as the request as well
33105 as reply packet. Since a File-I/O system call can only occur when
33106 @value{GDBN} is waiting for a response from the continuing or stepping target,
33107 the File-I/O request is a reply that @value{GDBN} has to expect as a result
33108 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
33109 This @code{F} packet contains all information needed to allow @value{GDBN}
33110 to call the appropriate host system call:
33111
33112 @itemize @bullet
33113 @item
33114 A unique identifier for the requested system call.
33115
33116 @item
33117 All parameters to the system call. Pointers are given as addresses
33118 in the target memory address space. Pointers to strings are given as
33119 pointer/length pair. Numerical values are given as they are.
33120 Numerical control flags are given in a protocol-specific representation.
33121
33122 @end itemize
33123
33124 At this point, @value{GDBN} has to perform the following actions.
33125
33126 @itemize @bullet
33127 @item
33128 If the parameters include pointer values to data needed as input to a
33129 system call, @value{GDBN} requests this data from the target with a
33130 standard @code{m} packet request. This additional communication has to be
33131 expected by the target implementation and is handled as any other @code{m}
33132 packet.
33133
33134 @item
33135 @value{GDBN} translates all value from protocol representation to host
33136 representation as needed. Datatypes are coerced into the host types.
33137
33138 @item
33139 @value{GDBN} calls the system call.
33140
33141 @item
33142 It then coerces datatypes back to protocol representation.
33143
33144 @item
33145 If the system call is expected to return data in buffer space specified
33146 by pointer parameters to the call, the data is transmitted to the
33147 target using a @code{M} or @code{X} packet. This packet has to be expected
33148 by the target implementation and is handled as any other @code{M} or @code{X}
33149 packet.
33150
33151 @end itemize
33152
33153 Eventually @value{GDBN} replies with another @code{F} packet which contains all
33154 necessary information for the target to continue. This at least contains
33155
33156 @itemize @bullet
33157 @item
33158 Return value.
33159
33160 @item
33161 @code{errno}, if has been changed by the system call.
33162
33163 @item
33164 ``Ctrl-C'' flag.
33165
33166 @end itemize
33167
33168 After having done the needed type and value coercion, the target continues
33169 the latest continue or step action.
33170
33171 @node The F Request Packet
33172 @subsection The @code{F} Request Packet
33173 @cindex file-i/o request packet
33174 @cindex @code{F} request packet
33175
33176 The @code{F} request packet has the following format:
33177
33178 @table @samp
33179 @item F@var{call-id},@var{parameter@dots{}}
33180
33181 @var{call-id} is the identifier to indicate the host system call to be called.
33182 This is just the name of the function.
33183
33184 @var{parameter@dots{}} are the parameters to the system call.
33185 Parameters are hexadecimal integer values, either the actual values in case
33186 of scalar datatypes, pointers to target buffer space in case of compound
33187 datatypes and unspecified memory areas, or pointer/length pairs in case
33188 of string parameters. These are appended to the @var{call-id} as a
33189 comma-delimited list. All values are transmitted in ASCII
33190 string representation, pointer/length pairs separated by a slash.
33191
33192 @end table
33193
33194
33195
33196 @node The F Reply Packet
33197 @subsection The @code{F} Reply Packet
33198 @cindex file-i/o reply packet
33199 @cindex @code{F} reply packet
33200
33201 The @code{F} reply packet has the following format:
33202
33203 @table @samp
33204
33205 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
33206
33207 @var{retcode} is the return code of the system call as hexadecimal value.
33208
33209 @var{errno} is the @code{errno} set by the call, in protocol-specific
33210 representation.
33211 This parameter can be omitted if the call was successful.
33212
33213 @var{Ctrl-C flag} is only sent if the user requested a break. In this
33214 case, @var{errno} must be sent as well, even if the call was successful.
33215 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
33216
33217 @smallexample
33218 F0,0,C
33219 @end smallexample
33220
33221 @noindent
33222 or, if the call was interrupted before the host call has been performed:
33223
33224 @smallexample
33225 F-1,4,C
33226 @end smallexample
33227
33228 @noindent
33229 assuming 4 is the protocol-specific representation of @code{EINTR}.
33230
33231 @end table
33232
33233
33234 @node The Ctrl-C Message
33235 @subsection The @samp{Ctrl-C} Message
33236 @cindex ctrl-c message, in file-i/o protocol
33237
33238 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
33239 reply packet (@pxref{The F Reply Packet}),
33240 the target should behave as if it had
33241 gotten a break message. The meaning for the target is ``system call
33242 interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
33243 (as with a break message) and return to @value{GDBN} with a @code{T02}
33244 packet.
33245
33246 It's important for the target to know in which
33247 state the system call was interrupted. There are two possible cases:
33248
33249 @itemize @bullet
33250 @item
33251 The system call hasn't been performed on the host yet.
33252
33253 @item
33254 The system call on the host has been finished.
33255
33256 @end itemize
33257
33258 These two states can be distinguished by the target by the value of the
33259 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
33260 call hasn't been performed. This is equivalent to the @code{EINTR} handling
33261 on POSIX systems. In any other case, the target may presume that the
33262 system call has been finished --- successfully or not --- and should behave
33263 as if the break message arrived right after the system call.
33264
33265 @value{GDBN} must behave reliably. If the system call has not been called
33266 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
33267 @code{errno} in the packet. If the system call on the host has been finished
33268 before the user requests a break, the full action must be finished by
33269 @value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
33270 The @code{F} packet may only be sent when either nothing has happened
33271 or the full action has been completed.
33272
33273 @node Console I/O
33274 @subsection Console I/O
33275 @cindex console i/o as part of file-i/o
33276
33277 By default and if not explicitly closed by the target system, the file
33278 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
33279 on the @value{GDBN} console is handled as any other file output operation
33280 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
33281 by @value{GDBN} so that after the target read request from file descriptor
33282 0 all following typing is buffered until either one of the following
33283 conditions is met:
33284
33285 @itemize @bullet
33286 @item
33287 The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
33288 @code{read}
33289 system call is treated as finished.
33290
33291 @item
33292 The user presses @key{RET}. This is treated as end of input with a trailing
33293 newline.
33294
33295 @item
33296 The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
33297 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
33298
33299 @end itemize
33300
33301 If the user has typed more characters than fit in the buffer given to
33302 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
33303 either another @code{read(0, @dots{})} is requested by the target, or debugging
33304 is stopped at the user's request.
33305
33306
33307 @node List of Supported Calls
33308 @subsection List of Supported Calls
33309 @cindex list of supported file-i/o calls
33310
33311 @menu
33312 * open::
33313 * close::
33314 * read::
33315 * write::
33316 * lseek::
33317 * rename::
33318 * unlink::
33319 * stat/fstat::
33320 * gettimeofday::
33321 * isatty::
33322 * system::
33323 @end menu
33324
33325 @node open
33326 @unnumberedsubsubsec open
33327 @cindex open, file-i/o system call
33328
33329 @table @asis
33330 @item Synopsis:
33331 @smallexample
33332 int open(const char *pathname, int flags);
33333 int open(const char *pathname, int flags, mode_t mode);
33334 @end smallexample
33335
33336 @item Request:
33337 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
33338
33339 @noindent
33340 @var{flags} is the bitwise @code{OR} of the following values:
33341
33342 @table @code
33343 @item O_CREAT
33344 If the file does not exist it will be created. The host
33345 rules apply as far as file ownership and time stamps
33346 are concerned.
33347
33348 @item O_EXCL
33349 When used with @code{O_CREAT}, if the file already exists it is
33350 an error and open() fails.
33351
33352 @item O_TRUNC
33353 If the file already exists and the open mode allows
33354 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
33355 truncated to zero length.
33356
33357 @item O_APPEND
33358 The file is opened in append mode.
33359
33360 @item O_RDONLY
33361 The file is opened for reading only.
33362
33363 @item O_WRONLY
33364 The file is opened for writing only.
33365
33366 @item O_RDWR
33367 The file is opened for reading and writing.
33368 @end table
33369
33370 @noindent
33371 Other bits are silently ignored.
33372
33373
33374 @noindent
33375 @var{mode} is the bitwise @code{OR} of the following values:
33376
33377 @table @code
33378 @item S_IRUSR
33379 User has read permission.
33380
33381 @item S_IWUSR
33382 User has write permission.
33383
33384 @item S_IRGRP
33385 Group has read permission.
33386
33387 @item S_IWGRP
33388 Group has write permission.
33389
33390 @item S_IROTH
33391 Others have read permission.
33392
33393 @item S_IWOTH
33394 Others have write permission.
33395 @end table
33396
33397 @noindent
33398 Other bits are silently ignored.
33399
33400
33401 @item Return value:
33402 @code{open} returns the new file descriptor or -1 if an error
33403 occurred.
33404
33405 @item Errors:
33406
33407 @table @code
33408 @item EEXIST
33409 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
33410
33411 @item EISDIR
33412 @var{pathname} refers to a directory.
33413
33414 @item EACCES
33415 The requested access is not allowed.
33416
33417 @item ENAMETOOLONG
33418 @var{pathname} was too long.
33419
33420 @item ENOENT
33421 A directory component in @var{pathname} does not exist.
33422
33423 @item ENODEV
33424 @var{pathname} refers to a device, pipe, named pipe or socket.
33425
33426 @item EROFS
33427 @var{pathname} refers to a file on a read-only filesystem and
33428 write access was requested.
33429
33430 @item EFAULT
33431 @var{pathname} is an invalid pointer value.
33432
33433 @item ENOSPC
33434 No space on device to create the file.
33435
33436 @item EMFILE
33437 The process already has the maximum number of files open.
33438
33439 @item ENFILE
33440 The limit on the total number of files open on the system
33441 has been reached.
33442
33443 @item EINTR
33444 The call was interrupted by the user.
33445 @end table
33446
33447 @end table
33448
33449 @node close
33450 @unnumberedsubsubsec close
33451 @cindex close, file-i/o system call
33452
33453 @table @asis
33454 @item Synopsis:
33455 @smallexample
33456 int close(int fd);
33457 @end smallexample
33458
33459 @item Request:
33460 @samp{Fclose,@var{fd}}
33461
33462 @item Return value:
33463 @code{close} returns zero on success, or -1 if an error occurred.
33464
33465 @item Errors:
33466
33467 @table @code
33468 @item EBADF
33469 @var{fd} isn't a valid open file descriptor.
33470
33471 @item EINTR
33472 The call was interrupted by the user.
33473 @end table
33474
33475 @end table
33476
33477 @node read
33478 @unnumberedsubsubsec read
33479 @cindex read, file-i/o system call
33480
33481 @table @asis
33482 @item Synopsis:
33483 @smallexample
33484 int read(int fd, void *buf, unsigned int count);
33485 @end smallexample
33486
33487 @item Request:
33488 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
33489
33490 @item Return value:
33491 On success, the number of bytes read is returned.
33492 Zero indicates end of file. If count is zero, read
33493 returns zero as well. On error, -1 is returned.
33494
33495 @item Errors:
33496
33497 @table @code
33498 @item EBADF
33499 @var{fd} is not a valid file descriptor or is not open for
33500 reading.
33501
33502 @item EFAULT
33503 @var{bufptr} is an invalid pointer value.
33504
33505 @item EINTR
33506 The call was interrupted by the user.
33507 @end table
33508
33509 @end table
33510
33511 @node write
33512 @unnumberedsubsubsec write
33513 @cindex write, file-i/o system call
33514
33515 @table @asis
33516 @item Synopsis:
33517 @smallexample
33518 int write(int fd, const void *buf, unsigned int count);
33519 @end smallexample
33520
33521 @item Request:
33522 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
33523
33524 @item Return value:
33525 On success, the number of bytes written are returned.
33526 Zero indicates nothing was written. On error, -1
33527 is returned.
33528
33529 @item Errors:
33530
33531 @table @code
33532 @item EBADF
33533 @var{fd} is not a valid file descriptor or is not open for
33534 writing.
33535
33536 @item EFAULT
33537 @var{bufptr} is an invalid pointer value.
33538
33539 @item EFBIG
33540 An attempt was made to write a file that exceeds the
33541 host-specific maximum file size allowed.
33542
33543 @item ENOSPC
33544 No space on device to write the data.
33545
33546 @item EINTR
33547 The call was interrupted by the user.
33548 @end table
33549
33550 @end table
33551
33552 @node lseek
33553 @unnumberedsubsubsec lseek
33554 @cindex lseek, file-i/o system call
33555
33556 @table @asis
33557 @item Synopsis:
33558 @smallexample
33559 long lseek (int fd, long offset, int flag);
33560 @end smallexample
33561
33562 @item Request:
33563 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
33564
33565 @var{flag} is one of:
33566
33567 @table @code
33568 @item SEEK_SET
33569 The offset is set to @var{offset} bytes.
33570
33571 @item SEEK_CUR
33572 The offset is set to its current location plus @var{offset}
33573 bytes.
33574
33575 @item SEEK_END
33576 The offset is set to the size of the file plus @var{offset}
33577 bytes.
33578 @end table
33579
33580 @item Return value:
33581 On success, the resulting unsigned offset in bytes from
33582 the beginning of the file is returned. Otherwise, a
33583 value of -1 is returned.
33584
33585 @item Errors:
33586
33587 @table @code
33588 @item EBADF
33589 @var{fd} is not a valid open file descriptor.
33590
33591 @item ESPIPE
33592 @var{fd} is associated with the @value{GDBN} console.
33593
33594 @item EINVAL
33595 @var{flag} is not a proper value.
33596
33597 @item EINTR
33598 The call was interrupted by the user.
33599 @end table
33600
33601 @end table
33602
33603 @node rename
33604 @unnumberedsubsubsec rename
33605 @cindex rename, file-i/o system call
33606
33607 @table @asis
33608 @item Synopsis:
33609 @smallexample
33610 int rename(const char *oldpath, const char *newpath);
33611 @end smallexample
33612
33613 @item Request:
33614 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
33615
33616 @item Return value:
33617 On success, zero is returned. On error, -1 is returned.
33618
33619 @item Errors:
33620
33621 @table @code
33622 @item EISDIR
33623 @var{newpath} is an existing directory, but @var{oldpath} is not a
33624 directory.
33625
33626 @item EEXIST
33627 @var{newpath} is a non-empty directory.
33628
33629 @item EBUSY
33630 @var{oldpath} or @var{newpath} is a directory that is in use by some
33631 process.
33632
33633 @item EINVAL
33634 An attempt was made to make a directory a subdirectory
33635 of itself.
33636
33637 @item ENOTDIR
33638 A component used as a directory in @var{oldpath} or new
33639 path is not a directory. Or @var{oldpath} is a directory
33640 and @var{newpath} exists but is not a directory.
33641
33642 @item EFAULT
33643 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
33644
33645 @item EACCES
33646 No access to the file or the path of the file.
33647
33648 @item ENAMETOOLONG
33649
33650 @var{oldpath} or @var{newpath} was too long.
33651
33652 @item ENOENT
33653 A directory component in @var{oldpath} or @var{newpath} does not exist.
33654
33655 @item EROFS
33656 The file is on a read-only filesystem.
33657
33658 @item ENOSPC
33659 The device containing the file has no room for the new
33660 directory entry.
33661
33662 @item EINTR
33663 The call was interrupted by the user.
33664 @end table
33665
33666 @end table
33667
33668 @node unlink
33669 @unnumberedsubsubsec unlink
33670 @cindex unlink, file-i/o system call
33671
33672 @table @asis
33673 @item Synopsis:
33674 @smallexample
33675 int unlink(const char *pathname);
33676 @end smallexample
33677
33678 @item Request:
33679 @samp{Funlink,@var{pathnameptr}/@var{len}}
33680
33681 @item Return value:
33682 On success, zero is returned. On error, -1 is returned.
33683
33684 @item Errors:
33685
33686 @table @code
33687 @item EACCES
33688 No access to the file or the path of the file.
33689
33690 @item EPERM
33691 The system does not allow unlinking of directories.
33692
33693 @item EBUSY
33694 The file @var{pathname} cannot be unlinked because it's
33695 being used by another process.
33696
33697 @item EFAULT
33698 @var{pathnameptr} is an invalid pointer value.
33699
33700 @item ENAMETOOLONG
33701 @var{pathname} was too long.
33702
33703 @item ENOENT
33704 A directory component in @var{pathname} does not exist.
33705
33706 @item ENOTDIR
33707 A component of the path is not a directory.
33708
33709 @item EROFS
33710 The file is on a read-only filesystem.
33711
33712 @item EINTR
33713 The call was interrupted by the user.
33714 @end table
33715
33716 @end table
33717
33718 @node stat/fstat
33719 @unnumberedsubsubsec stat/fstat
33720 @cindex fstat, file-i/o system call
33721 @cindex stat, file-i/o system call
33722
33723 @table @asis
33724 @item Synopsis:
33725 @smallexample
33726 int stat(const char *pathname, struct stat *buf);
33727 int fstat(int fd, struct stat *buf);
33728 @end smallexample
33729
33730 @item Request:
33731 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
33732 @samp{Ffstat,@var{fd},@var{bufptr}}
33733
33734 @item Return value:
33735 On success, zero is returned. On error, -1 is returned.
33736
33737 @item Errors:
33738
33739 @table @code
33740 @item EBADF
33741 @var{fd} is not a valid open file.
33742
33743 @item ENOENT
33744 A directory component in @var{pathname} does not exist or the
33745 path is an empty string.
33746
33747 @item ENOTDIR
33748 A component of the path is not a directory.
33749
33750 @item EFAULT
33751 @var{pathnameptr} is an invalid pointer value.
33752
33753 @item EACCES
33754 No access to the file or the path of the file.
33755
33756 @item ENAMETOOLONG
33757 @var{pathname} was too long.
33758
33759 @item EINTR
33760 The call was interrupted by the user.
33761 @end table
33762
33763 @end table
33764
33765 @node gettimeofday
33766 @unnumberedsubsubsec gettimeofday
33767 @cindex gettimeofday, file-i/o system call
33768
33769 @table @asis
33770 @item Synopsis:
33771 @smallexample
33772 int gettimeofday(struct timeval *tv, void *tz);
33773 @end smallexample
33774
33775 @item Request:
33776 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
33777
33778 @item Return value:
33779 On success, 0 is returned, -1 otherwise.
33780
33781 @item Errors:
33782
33783 @table @code
33784 @item EINVAL
33785 @var{tz} is a non-NULL pointer.
33786
33787 @item EFAULT
33788 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
33789 @end table
33790
33791 @end table
33792
33793 @node isatty
33794 @unnumberedsubsubsec isatty
33795 @cindex isatty, file-i/o system call
33796
33797 @table @asis
33798 @item Synopsis:
33799 @smallexample
33800 int isatty(int fd);
33801 @end smallexample
33802
33803 @item Request:
33804 @samp{Fisatty,@var{fd}}
33805
33806 @item Return value:
33807 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
33808
33809 @item Errors:
33810
33811 @table @code
33812 @item EINTR
33813 The call was interrupted by the user.
33814 @end table
33815
33816 @end table
33817
33818 Note that the @code{isatty} call is treated as a special case: it returns
33819 1 to the target if the file descriptor is attached
33820 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
33821 would require implementing @code{ioctl} and would be more complex than
33822 needed.
33823
33824
33825 @node system
33826 @unnumberedsubsubsec system
33827 @cindex system, file-i/o system call
33828
33829 @table @asis
33830 @item Synopsis:
33831 @smallexample
33832 int system(const char *command);
33833 @end smallexample
33834
33835 @item Request:
33836 @samp{Fsystem,@var{commandptr}/@var{len}}
33837
33838 @item Return value:
33839 If @var{len} is zero, the return value indicates whether a shell is
33840 available. A zero return value indicates a shell is not available.
33841 For non-zero @var{len}, the value returned is -1 on error and the
33842 return status of the command otherwise. Only the exit status of the
33843 command is returned, which is extracted from the host's @code{system}
33844 return value by calling @code{WEXITSTATUS(retval)}. In case
33845 @file{/bin/sh} could not be executed, 127 is returned.
33846
33847 @item Errors:
33848
33849 @table @code
33850 @item EINTR
33851 The call was interrupted by the user.
33852 @end table
33853
33854 @end table
33855
33856 @value{GDBN} takes over the full task of calling the necessary host calls
33857 to perform the @code{system} call. The return value of @code{system} on
33858 the host is simplified before it's returned
33859 to the target. Any termination signal information from the child process
33860 is discarded, and the return value consists
33861 entirely of the exit status of the called command.
33862
33863 Due to security concerns, the @code{system} call is by default refused
33864 by @value{GDBN}. The user has to allow this call explicitly with the
33865 @code{set remote system-call-allowed 1} command.
33866
33867 @table @code
33868 @item set remote system-call-allowed
33869 @kindex set remote system-call-allowed
33870 Control whether to allow the @code{system} calls in the File I/O
33871 protocol for the remote target. The default is zero (disabled).
33872
33873 @item show remote system-call-allowed
33874 @kindex show remote system-call-allowed
33875 Show whether the @code{system} calls are allowed in the File I/O
33876 protocol.
33877 @end table
33878
33879 @node Protocol-specific Representation of Datatypes
33880 @subsection Protocol-specific Representation of Datatypes
33881 @cindex protocol-specific representation of datatypes, in file-i/o protocol
33882
33883 @menu
33884 * Integral Datatypes::
33885 * Pointer Values::
33886 * Memory Transfer::
33887 * struct stat::
33888 * struct timeval::
33889 @end menu
33890
33891 @node Integral Datatypes
33892 @unnumberedsubsubsec Integral Datatypes
33893 @cindex integral datatypes, in file-i/o protocol
33894
33895 The integral datatypes used in the system calls are @code{int},
33896 @code{unsigned int}, @code{long}, @code{unsigned long},
33897 @code{mode_t}, and @code{time_t}.
33898
33899 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
33900 implemented as 32 bit values in this protocol.
33901
33902 @code{long} and @code{unsigned long} are implemented as 64 bit types.
33903
33904 @xref{Limits}, for corresponding MIN and MAX values (similar to those
33905 in @file{limits.h}) to allow range checking on host and target.
33906
33907 @code{time_t} datatypes are defined as seconds since the Epoch.
33908
33909 All integral datatypes transferred as part of a memory read or write of a
33910 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
33911 byte order.
33912
33913 @node Pointer Values
33914 @unnumberedsubsubsec Pointer Values
33915 @cindex pointer values, in file-i/o protocol
33916
33917 Pointers to target data are transmitted as they are. An exception
33918 is made for pointers to buffers for which the length isn't
33919 transmitted as part of the function call, namely strings. Strings
33920 are transmitted as a pointer/length pair, both as hex values, e.g.@:
33921
33922 @smallexample
33923 @code{1aaf/12}
33924 @end smallexample
33925
33926 @noindent
33927 which is a pointer to data of length 18 bytes at position 0x1aaf.
33928 The length is defined as the full string length in bytes, including
33929 the trailing null byte. For example, the string @code{"hello world"}
33930 at address 0x123456 is transmitted as
33931
33932 @smallexample
33933 @code{123456/d}
33934 @end smallexample
33935
33936 @node Memory Transfer
33937 @unnumberedsubsubsec Memory Transfer
33938 @cindex memory transfer, in file-i/o protocol
33939
33940 Structured data which is transferred using a memory read or write (for
33941 example, a @code{struct stat}) is expected to be in a protocol-specific format
33942 with all scalar multibyte datatypes being big endian. Translation to
33943 this representation needs to be done both by the target before the @code{F}
33944 packet is sent, and by @value{GDBN} before
33945 it transfers memory to the target. Transferred pointers to structured
33946 data should point to the already-coerced data at any time.
33947
33948
33949 @node struct stat
33950 @unnumberedsubsubsec struct stat
33951 @cindex struct stat, in file-i/o protocol
33952
33953 The buffer of type @code{struct stat} used by the target and @value{GDBN}
33954 is defined as follows:
33955
33956 @smallexample
33957 struct stat @{
33958 unsigned int st_dev; /* device */
33959 unsigned int st_ino; /* inode */
33960 mode_t st_mode; /* protection */
33961 unsigned int st_nlink; /* number of hard links */
33962 unsigned int st_uid; /* user ID of owner */
33963 unsigned int st_gid; /* group ID of owner */
33964 unsigned int st_rdev; /* device type (if inode device) */
33965 unsigned long st_size; /* total size, in bytes */
33966 unsigned long st_blksize; /* blocksize for filesystem I/O */
33967 unsigned long st_blocks; /* number of blocks allocated */
33968 time_t st_atime; /* time of last access */
33969 time_t st_mtime; /* time of last modification */
33970 time_t st_ctime; /* time of last change */
33971 @};
33972 @end smallexample
33973
33974 The integral datatypes conform to the definitions given in the
33975 appropriate section (see @ref{Integral Datatypes}, for details) so this
33976 structure is of size 64 bytes.
33977
33978 The values of several fields have a restricted meaning and/or
33979 range of values.
33980
33981 @table @code
33982
33983 @item st_dev
33984 A value of 0 represents a file, 1 the console.
33985
33986 @item st_ino
33987 No valid meaning for the target. Transmitted unchanged.
33988
33989 @item st_mode
33990 Valid mode bits are described in @ref{Constants}. Any other
33991 bits have currently no meaning for the target.
33992
33993 @item st_uid
33994 @itemx st_gid
33995 @itemx st_rdev
33996 No valid meaning for the target. Transmitted unchanged.
33997
33998 @item st_atime
33999 @itemx st_mtime
34000 @itemx st_ctime
34001 These values have a host and file system dependent
34002 accuracy. Especially on Windows hosts, the file system may not
34003 support exact timing values.
34004 @end table
34005
34006 The target gets a @code{struct stat} of the above representation and is
34007 responsible for coercing it to the target representation before
34008 continuing.
34009
34010 Note that due to size differences between the host, target, and protocol
34011 representations of @code{struct stat} members, these members could eventually
34012 get truncated on the target.
34013
34014 @node struct timeval
34015 @unnumberedsubsubsec struct timeval
34016 @cindex struct timeval, in file-i/o protocol
34017
34018 The buffer of type @code{struct timeval} used by the File-I/O protocol
34019 is defined as follows:
34020
34021 @smallexample
34022 struct timeval @{
34023 time_t tv_sec; /* second */
34024 long tv_usec; /* microsecond */
34025 @};
34026 @end smallexample
34027
34028 The integral datatypes conform to the definitions given in the
34029 appropriate section (see @ref{Integral Datatypes}, for details) so this
34030 structure is of size 8 bytes.
34031
34032 @node Constants
34033 @subsection Constants
34034 @cindex constants, in file-i/o protocol
34035
34036 The following values are used for the constants inside of the
34037 protocol. @value{GDBN} and target are responsible for translating these
34038 values before and after the call as needed.
34039
34040 @menu
34041 * Open Flags::
34042 * mode_t Values::
34043 * Errno Values::
34044 * Lseek Flags::
34045 * Limits::
34046 @end menu
34047
34048 @node Open Flags
34049 @unnumberedsubsubsec Open Flags
34050 @cindex open flags, in file-i/o protocol
34051
34052 All values are given in hexadecimal representation.
34053
34054 @smallexample
34055 O_RDONLY 0x0
34056 O_WRONLY 0x1
34057 O_RDWR 0x2
34058 O_APPEND 0x8
34059 O_CREAT 0x200
34060 O_TRUNC 0x400
34061 O_EXCL 0x800
34062 @end smallexample
34063
34064 @node mode_t Values
34065 @unnumberedsubsubsec mode_t Values
34066 @cindex mode_t values, in file-i/o protocol
34067
34068 All values are given in octal representation.
34069
34070 @smallexample
34071 S_IFREG 0100000
34072 S_IFDIR 040000
34073 S_IRUSR 0400
34074 S_IWUSR 0200
34075 S_IXUSR 0100
34076 S_IRGRP 040
34077 S_IWGRP 020
34078 S_IXGRP 010
34079 S_IROTH 04
34080 S_IWOTH 02
34081 S_IXOTH 01
34082 @end smallexample
34083
34084 @node Errno Values
34085 @unnumberedsubsubsec Errno Values
34086 @cindex errno values, in file-i/o protocol
34087
34088 All values are given in decimal representation.
34089
34090 @smallexample
34091 EPERM 1
34092 ENOENT 2
34093 EINTR 4
34094 EBADF 9
34095 EACCES 13
34096 EFAULT 14
34097 EBUSY 16
34098 EEXIST 17
34099 ENODEV 19
34100 ENOTDIR 20
34101 EISDIR 21
34102 EINVAL 22
34103 ENFILE 23
34104 EMFILE 24
34105 EFBIG 27
34106 ENOSPC 28
34107 ESPIPE 29
34108 EROFS 30
34109 ENAMETOOLONG 91
34110 EUNKNOWN 9999
34111 @end smallexample
34112
34113 @code{EUNKNOWN} is used as a fallback error value if a host system returns
34114 any error value not in the list of supported error numbers.
34115
34116 @node Lseek Flags
34117 @unnumberedsubsubsec Lseek Flags
34118 @cindex lseek flags, in file-i/o protocol
34119
34120 @smallexample
34121 SEEK_SET 0
34122 SEEK_CUR 1
34123 SEEK_END 2
34124 @end smallexample
34125
34126 @node Limits
34127 @unnumberedsubsubsec Limits
34128 @cindex limits, in file-i/o protocol
34129
34130 All values are given in decimal representation.
34131
34132 @smallexample
34133 INT_MIN -2147483648
34134 INT_MAX 2147483647
34135 UINT_MAX 4294967295
34136 LONG_MIN -9223372036854775808
34137 LONG_MAX 9223372036854775807
34138 ULONG_MAX 18446744073709551615
34139 @end smallexample
34140
34141 @node File-I/O Examples
34142 @subsection File-I/O Examples
34143 @cindex file-i/o examples
34144
34145 Example sequence of a write call, file descriptor 3, buffer is at target
34146 address 0x1234, 6 bytes should be written:
34147
34148 @smallexample
34149 <- @code{Fwrite,3,1234,6}
34150 @emph{request memory read from target}
34151 -> @code{m1234,6}
34152 <- XXXXXX
34153 @emph{return "6 bytes written"}
34154 -> @code{F6}
34155 @end smallexample
34156
34157 Example sequence of a read call, file descriptor 3, buffer is at target
34158 address 0x1234, 6 bytes should be read:
34159
34160 @smallexample
34161 <- @code{Fread,3,1234,6}
34162 @emph{request memory write to target}
34163 -> @code{X1234,6:XXXXXX}
34164 @emph{return "6 bytes read"}
34165 -> @code{F6}
34166 @end smallexample
34167
34168 Example sequence of a read call, call fails on the host due to invalid
34169 file descriptor (@code{EBADF}):
34170
34171 @smallexample
34172 <- @code{Fread,3,1234,6}
34173 -> @code{F-1,9}
34174 @end smallexample
34175
34176 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
34177 host is called:
34178
34179 @smallexample
34180 <- @code{Fread,3,1234,6}
34181 -> @code{F-1,4,C}
34182 <- @code{T02}
34183 @end smallexample
34184
34185 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
34186 host is called:
34187
34188 @smallexample
34189 <- @code{Fread,3,1234,6}
34190 -> @code{X1234,6:XXXXXX}
34191 <- @code{T02}
34192 @end smallexample
34193
34194 @node Library List Format
34195 @section Library List Format
34196 @cindex library list format, remote protocol
34197
34198 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
34199 same process as your application to manage libraries. In this case,
34200 @value{GDBN} can use the loader's symbol table and normal memory
34201 operations to maintain a list of shared libraries. On other
34202 platforms, the operating system manages loaded libraries.
34203 @value{GDBN} can not retrieve the list of currently loaded libraries
34204 through memory operations, so it uses the @samp{qXfer:libraries:read}
34205 packet (@pxref{qXfer library list read}) instead. The remote stub
34206 queries the target's operating system and reports which libraries
34207 are loaded.
34208
34209 The @samp{qXfer:libraries:read} packet returns an XML document which
34210 lists loaded libraries and their offsets. Each library has an
34211 associated name and one or more segment or section base addresses,
34212 which report where the library was loaded in memory.
34213
34214 For the common case of libraries that are fully linked binaries, the
34215 library should have a list of segments. If the target supports
34216 dynamic linking of a relocatable object file, its library XML element
34217 should instead include a list of allocated sections. The segment or
34218 section bases are start addresses, not relocation offsets; they do not
34219 depend on the library's link-time base addresses.
34220
34221 @value{GDBN} must be linked with the Expat library to support XML
34222 library lists. @xref{Expat}.
34223
34224 A simple memory map, with one loaded library relocated by a single
34225 offset, looks like this:
34226
34227 @smallexample
34228 <library-list>
34229 <library name="/lib/libc.so.6">
34230 <segment address="0x10000000"/>
34231 </library>
34232 </library-list>
34233 @end smallexample
34234
34235 Another simple memory map, with one loaded library with three
34236 allocated sections (.text, .data, .bss), looks like this:
34237
34238 @smallexample
34239 <library-list>
34240 <library name="sharedlib.o">
34241 <section address="0x10000000"/>
34242 <section address="0x20000000"/>
34243 <section address="0x30000000"/>
34244 </library>
34245 </library-list>
34246 @end smallexample
34247
34248 The format of a library list is described by this DTD:
34249
34250 @smallexample
34251 <!-- library-list: Root element with versioning -->
34252 <!ELEMENT library-list (library)*>
34253 <!ATTLIST library-list version CDATA #FIXED "1.0">
34254 <!ELEMENT library (segment*, section*)>
34255 <!ATTLIST library name CDATA #REQUIRED>
34256 <!ELEMENT segment EMPTY>
34257 <!ATTLIST segment address CDATA #REQUIRED>
34258 <!ELEMENT section EMPTY>
34259 <!ATTLIST section address CDATA #REQUIRED>
34260 @end smallexample
34261
34262 In addition, segments and section descriptors cannot be mixed within a
34263 single library element, and you must supply at least one segment or
34264 section for each library.
34265
34266 @node Memory Map Format
34267 @section Memory Map Format
34268 @cindex memory map format
34269
34270 To be able to write into flash memory, @value{GDBN} needs to obtain a
34271 memory map from the target. This section describes the format of the
34272 memory map.
34273
34274 The memory map is obtained using the @samp{qXfer:memory-map:read}
34275 (@pxref{qXfer memory map read}) packet and is an XML document that
34276 lists memory regions.
34277
34278 @value{GDBN} must be linked with the Expat library to support XML
34279 memory maps. @xref{Expat}.
34280
34281 The top-level structure of the document is shown below:
34282
34283 @smallexample
34284 <?xml version="1.0"?>
34285 <!DOCTYPE memory-map
34286 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
34287 "http://sourceware.org/gdb/gdb-memory-map.dtd">
34288 <memory-map>
34289 region...
34290 </memory-map>
34291 @end smallexample
34292
34293 Each region can be either:
34294
34295 @itemize
34296
34297 @item
34298 A region of RAM starting at @var{addr} and extending for @var{length}
34299 bytes from there:
34300
34301 @smallexample
34302 <memory type="ram" start="@var{addr}" length="@var{length}"/>
34303 @end smallexample
34304
34305
34306 @item
34307 A region of read-only memory:
34308
34309 @smallexample
34310 <memory type="rom" start="@var{addr}" length="@var{length}"/>
34311 @end smallexample
34312
34313
34314 @item
34315 A region of flash memory, with erasure blocks @var{blocksize}
34316 bytes in length:
34317
34318 @smallexample
34319 <memory type="flash" start="@var{addr}" length="@var{length}">
34320 <property name="blocksize">@var{blocksize}</property>
34321 </memory>
34322 @end smallexample
34323
34324 @end itemize
34325
34326 Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
34327 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
34328 packets to write to addresses in such ranges.
34329
34330 The formal DTD for memory map format is given below:
34331
34332 @smallexample
34333 <!-- ................................................... -->
34334 <!-- Memory Map XML DTD ................................ -->
34335 <!-- File: memory-map.dtd .............................. -->
34336 <!-- .................................... .............. -->
34337 <!-- memory-map.dtd -->
34338 <!-- memory-map: Root element with versioning -->
34339 <!ELEMENT memory-map (memory | property)>
34340 <!ATTLIST memory-map version CDATA #FIXED "1.0.0">
34341 <!ELEMENT memory (property)>
34342 <!-- memory: Specifies a memory region,
34343 and its type, or device. -->
34344 <!ATTLIST memory type CDATA #REQUIRED
34345 start CDATA #REQUIRED
34346 length CDATA #REQUIRED
34347 device CDATA #IMPLIED>
34348 <!-- property: Generic attribute tag -->
34349 <!ELEMENT property (#PCDATA | property)*>
34350 <!ATTLIST property name CDATA #REQUIRED>
34351 @end smallexample
34352
34353 @node Thread List Format
34354 @section Thread List Format
34355 @cindex thread list format
34356
34357 To efficiently update the list of threads and their attributes,
34358 @value{GDBN} issues the @samp{qXfer:threads:read} packet
34359 (@pxref{qXfer threads read}) and obtains the XML document with
34360 the following structure:
34361
34362 @smallexample
34363 <?xml version="1.0"?>
34364 <threads>
34365 <thread id="id" core="0">
34366 ... description ...
34367 </thread>
34368 </threads>
34369 @end smallexample
34370
34371 Each @samp{thread} element must have the @samp{id} attribute that
34372 identifies the thread (@pxref{thread-id syntax}). The
34373 @samp{core} attribute, if present, specifies which processor core
34374 the thread was last executing on. The content of the of @samp{thread}
34375 element is interpreted as human-readable auxilliary information.
34376
34377 @include agentexpr.texi
34378
34379 @node Trace File Format
34380 @appendix Trace File Format
34381 @cindex trace file format
34382
34383 The trace file comes in three parts: a header, a textual description
34384 section, and a trace frame section with binary data.
34385
34386 The header has the form @code{\x7fTRACE0\n}. The first byte is
34387 @code{0x7f} so as to indicate that the file contains binary data,
34388 while the @code{0} is a version number that may have different values
34389 in the future.
34390
34391 The description section consists of multiple lines of @sc{ascii} text
34392 separated by newline characters (@code{0xa}). The lines may include a
34393 variety of optional descriptive or context-setting information, such
34394 as tracepoint definitions or register set size. @value{GDBN} will
34395 ignore any line that it does not recognize. An empty line marks the end
34396 of this section.
34397
34398 @c FIXME add some specific types of data
34399
34400 The trace frame section consists of a number of consecutive frames.
34401 Each frame begins with a two-byte tracepoint number, followed by a
34402 four-byte size giving the amount of data in the frame. The data in
34403 the frame consists of a number of blocks, each introduced by a
34404 character indicating its type (at least register, memory, and trace
34405 state variable). The data in this section is raw binary, not a
34406 hexadecimal or other encoding; its endianness matches the target's
34407 endianness.
34408
34409 @c FIXME bi-arch may require endianness/arch info in description section
34410
34411 @table @code
34412 @item R @var{bytes}
34413 Register block. The number and ordering of bytes matches that of a
34414 @code{g} packet in the remote protocol. Note that these are the
34415 actual bytes, in target order and @value{GDBN} register order, not a
34416 hexadecimal encoding.
34417
34418 @item M @var{address} @var{length} @var{bytes}...
34419 Memory block. This is a contiguous block of memory, at the 8-byte
34420 address @var{address}, with a 2-byte length @var{length}, followed by
34421 @var{length} bytes.
34422
34423 @item V @var{number} @var{value}
34424 Trace state variable block. This records the 8-byte signed value
34425 @var{value} of trace state variable numbered @var{number}.
34426
34427 @end table
34428
34429 Future enhancements of the trace file format may include additional types
34430 of blocks.
34431
34432 @node Target Descriptions
34433 @appendix Target Descriptions
34434 @cindex target descriptions
34435
34436 @strong{Warning:} target descriptions are still under active development,
34437 and the contents and format may change between @value{GDBN} releases.
34438 The format is expected to stabilize in the future.
34439
34440 One of the challenges of using @value{GDBN} to debug embedded systems
34441 is that there are so many minor variants of each processor
34442 architecture in use. It is common practice for vendors to start with
34443 a standard processor core --- ARM, PowerPC, or MIPS, for example ---
34444 and then make changes to adapt it to a particular market niche. Some
34445 architectures have hundreds of variants, available from dozens of
34446 vendors. This leads to a number of problems:
34447
34448 @itemize @bullet
34449 @item
34450 With so many different customized processors, it is difficult for
34451 the @value{GDBN} maintainers to keep up with the changes.
34452 @item
34453 Since individual variants may have short lifetimes or limited
34454 audiences, it may not be worthwhile to carry information about every
34455 variant in the @value{GDBN} source tree.
34456 @item
34457 When @value{GDBN} does support the architecture of the embedded system
34458 at hand, the task of finding the correct architecture name to give the
34459 @command{set architecture} command can be error-prone.
34460 @end itemize
34461
34462 To address these problems, the @value{GDBN} remote protocol allows a
34463 target system to not only identify itself to @value{GDBN}, but to
34464 actually describe its own features. This lets @value{GDBN} support
34465 processor variants it has never seen before --- to the extent that the
34466 descriptions are accurate, and that @value{GDBN} understands them.
34467
34468 @value{GDBN} must be linked with the Expat library to support XML
34469 target descriptions. @xref{Expat}.
34470
34471 @menu
34472 * Retrieving Descriptions:: How descriptions are fetched from a target.
34473 * Target Description Format:: The contents of a target description.
34474 * Predefined Target Types:: Standard types available for target
34475 descriptions.
34476 * Standard Target Features:: Features @value{GDBN} knows about.
34477 @end menu
34478
34479 @node Retrieving Descriptions
34480 @section Retrieving Descriptions
34481
34482 Target descriptions can be read from the target automatically, or
34483 specified by the user manually. The default behavior is to read the
34484 description from the target. @value{GDBN} retrieves it via the remote
34485 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
34486 qXfer}). The @var{annex} in the @samp{qXfer} packet will be
34487 @samp{target.xml}. The contents of the @samp{target.xml} annex are an
34488 XML document, of the form described in @ref{Target Description
34489 Format}.
34490
34491 Alternatively, you can specify a file to read for the target description.
34492 If a file is set, the target will not be queried. The commands to
34493 specify a file are:
34494
34495 @table @code
34496 @cindex set tdesc filename
34497 @item set tdesc filename @var{path}
34498 Read the target description from @var{path}.
34499
34500 @cindex unset tdesc filename
34501 @item unset tdesc filename
34502 Do not read the XML target description from a file. @value{GDBN}
34503 will use the description supplied by the current target.
34504
34505 @cindex show tdesc filename
34506 @item show tdesc filename
34507 Show the filename to read for a target description, if any.
34508 @end table
34509
34510
34511 @node Target Description Format
34512 @section Target Description Format
34513 @cindex target descriptions, XML format
34514
34515 A target description annex is an @uref{http://www.w3.org/XML/, XML}
34516 document which complies with the Document Type Definition provided in
34517 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
34518 means you can use generally available tools like @command{xmllint} to
34519 check that your feature descriptions are well-formed and valid.
34520 However, to help people unfamiliar with XML write descriptions for
34521 their targets, we also describe the grammar here.
34522
34523 Target descriptions can identify the architecture of the remote target
34524 and (for some architectures) provide information about custom register
34525 sets. They can also identify the OS ABI of the remote target.
34526 @value{GDBN} can use this information to autoconfigure for your
34527 target, or to warn you if you connect to an unsupported target.
34528
34529 Here is a simple target description:
34530
34531 @smallexample
34532 <target version="1.0">
34533 <architecture>i386:x86-64</architecture>
34534 </target>
34535 @end smallexample
34536
34537 @noindent
34538 This minimal description only says that the target uses
34539 the x86-64 architecture.
34540
34541 A target description has the following overall form, with [ ] marking
34542 optional elements and @dots{} marking repeatable elements. The elements
34543 are explained further below.
34544
34545 @smallexample
34546 <?xml version="1.0"?>
34547 <!DOCTYPE target SYSTEM "gdb-target.dtd">
34548 <target version="1.0">
34549 @r{[}@var{architecture}@r{]}
34550 @r{[}@var{osabi}@r{]}
34551 @r{[}@var{compatible}@r{]}
34552 @r{[}@var{feature}@dots{}@r{]}
34553 </target>
34554 @end smallexample
34555
34556 @noindent
34557 The description is generally insensitive to whitespace and line
34558 breaks, under the usual common-sense rules. The XML version
34559 declaration and document type declaration can generally be omitted
34560 (@value{GDBN} does not require them), but specifying them may be
34561 useful for XML validation tools. The @samp{version} attribute for
34562 @samp{<target>} may also be omitted, but we recommend
34563 including it; if future versions of @value{GDBN} use an incompatible
34564 revision of @file{gdb-target.dtd}, they will detect and report
34565 the version mismatch.
34566
34567 @subsection Inclusion
34568 @cindex target descriptions, inclusion
34569 @cindex XInclude
34570 @ifnotinfo
34571 @cindex <xi:include>
34572 @end ifnotinfo
34573
34574 It can sometimes be valuable to split a target description up into
34575 several different annexes, either for organizational purposes, or to
34576 share files between different possible target descriptions. You can
34577 divide a description into multiple files by replacing any element of
34578 the target description with an inclusion directive of the form:
34579
34580 @smallexample
34581 <xi:include href="@var{document}"/>
34582 @end smallexample
34583
34584 @noindent
34585 When @value{GDBN} encounters an element of this form, it will retrieve
34586 the named XML @var{document}, and replace the inclusion directive with
34587 the contents of that document. If the current description was read
34588 using @samp{qXfer}, then so will be the included document;
34589 @var{document} will be interpreted as the name of an annex. If the
34590 current description was read from a file, @value{GDBN} will look for
34591 @var{document} as a file in the same directory where it found the
34592 original description.
34593
34594 @subsection Architecture
34595 @cindex <architecture>
34596
34597 An @samp{<architecture>} element has this form:
34598
34599 @smallexample
34600 <architecture>@var{arch}</architecture>
34601 @end smallexample
34602
34603 @var{arch} is one of the architectures from the set accepted by
34604 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
34605
34606 @subsection OS ABI
34607 @cindex @code{<osabi>}
34608
34609 This optional field was introduced in @value{GDBN} version 7.0.
34610 Previous versions of @value{GDBN} ignore it.
34611
34612 An @samp{<osabi>} element has this form:
34613
34614 @smallexample
34615 <osabi>@var{abi-name}</osabi>
34616 @end smallexample
34617
34618 @var{abi-name} is an OS ABI name from the same selection accepted by
34619 @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
34620
34621 @subsection Compatible Architecture
34622 @cindex @code{<compatible>}
34623
34624 This optional field was introduced in @value{GDBN} version 7.0.
34625 Previous versions of @value{GDBN} ignore it.
34626
34627 A @samp{<compatible>} element has this form:
34628
34629 @smallexample
34630 <compatible>@var{arch}</compatible>
34631 @end smallexample
34632
34633 @var{arch} is one of the architectures from the set accepted by
34634 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
34635
34636 A @samp{<compatible>} element is used to specify that the target
34637 is able to run binaries in some other than the main target architecture
34638 given by the @samp{<architecture>} element. For example, on the
34639 Cell Broadband Engine, the main architecture is @code{powerpc:common}
34640 or @code{powerpc:common64}, but the system is able to run binaries
34641 in the @code{spu} architecture as well. The way to describe this
34642 capability with @samp{<compatible>} is as follows:
34643
34644 @smallexample
34645 <architecture>powerpc:common</architecture>
34646 <compatible>spu</compatible>
34647 @end smallexample
34648
34649 @subsection Features
34650 @cindex <feature>
34651
34652 Each @samp{<feature>} describes some logical portion of the target
34653 system. Features are currently used to describe available CPU
34654 registers and the types of their contents. A @samp{<feature>} element
34655 has this form:
34656
34657 @smallexample
34658 <feature name="@var{name}">
34659 @r{[}@var{type}@dots{}@r{]}
34660 @var{reg}@dots{}
34661 </feature>
34662 @end smallexample
34663
34664 @noindent
34665 Each feature's name should be unique within the description. The name
34666 of a feature does not matter unless @value{GDBN} has some special
34667 knowledge of the contents of that feature; if it does, the feature
34668 should have its standard name. @xref{Standard Target Features}.
34669
34670 @subsection Types
34671
34672 Any register's value is a collection of bits which @value{GDBN} must
34673 interpret. The default interpretation is a two's complement integer,
34674 but other types can be requested by name in the register description.
34675 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
34676 Target Types}), and the description can define additional composite types.
34677
34678 Each type element must have an @samp{id} attribute, which gives
34679 a unique (within the containing @samp{<feature>}) name to the type.
34680 Types must be defined before they are used.
34681
34682 @cindex <vector>
34683 Some targets offer vector registers, which can be treated as arrays
34684 of scalar elements. These types are written as @samp{<vector>} elements,
34685 specifying the array element type, @var{type}, and the number of elements,
34686 @var{count}:
34687
34688 @smallexample
34689 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
34690 @end smallexample
34691
34692 @cindex <union>
34693 If a register's value is usefully viewed in multiple ways, define it
34694 with a union type containing the useful representations. The
34695 @samp{<union>} element contains one or more @samp{<field>} elements,
34696 each of which has a @var{name} and a @var{type}:
34697
34698 @smallexample
34699 <union id="@var{id}">
34700 <field name="@var{name}" type="@var{type}"/>
34701 @dots{}
34702 </union>
34703 @end smallexample
34704
34705 @cindex <struct>
34706 If a register's value is composed from several separate values, define
34707 it with a structure type. There are two forms of the @samp{<struct>}
34708 element; a @samp{<struct>} element must either contain only bitfields
34709 or contain no bitfields. If the structure contains only bitfields,
34710 its total size in bytes must be specified, each bitfield must have an
34711 explicit start and end, and bitfields are automatically assigned an
34712 integer type. The field's @var{start} should be less than or
34713 equal to its @var{end}, and zero represents the least significant bit.
34714
34715 @smallexample
34716 <struct id="@var{id}" size="@var{size}">
34717 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
34718 @dots{}
34719 </struct>
34720 @end smallexample
34721
34722 If the structure contains no bitfields, then each field has an
34723 explicit type, and no implicit padding is added.
34724
34725 @smallexample
34726 <struct id="@var{id}">
34727 <field name="@var{name}" type="@var{type}"/>
34728 @dots{}
34729 </struct>
34730 @end smallexample
34731
34732 @cindex <flags>
34733 If a register's value is a series of single-bit flags, define it with
34734 a flags type. The @samp{<flags>} element has an explicit @var{size}
34735 and contains one or more @samp{<field>} elements. Each field has a
34736 @var{name}, a @var{start}, and an @var{end}. Only single-bit flags
34737 are supported.
34738
34739 @smallexample
34740 <flags id="@var{id}" size="@var{size}">
34741 <field name="@var{name}" start="@var{start}" end="@var{end}"/>
34742 @dots{}
34743 </flags>
34744 @end smallexample
34745
34746 @subsection Registers
34747 @cindex <reg>
34748
34749 Each register is represented as an element with this form:
34750
34751 @smallexample
34752 <reg name="@var{name}"
34753 bitsize="@var{size}"
34754 @r{[}regnum="@var{num}"@r{]}
34755 @r{[}save-restore="@var{save-restore}"@r{]}
34756 @r{[}type="@var{type}"@r{]}
34757 @r{[}group="@var{group}"@r{]}/>
34758 @end smallexample
34759
34760 @noindent
34761 The components are as follows:
34762
34763 @table @var
34764
34765 @item name
34766 The register's name; it must be unique within the target description.
34767
34768 @item bitsize
34769 The register's size, in bits.
34770
34771 @item regnum
34772 The register's number. If omitted, a register's number is one greater
34773 than that of the previous register (either in the current feature or in
34774 a preceeding feature); the first register in the target description
34775 defaults to zero. This register number is used to read or write
34776 the register; e.g.@: it is used in the remote @code{p} and @code{P}
34777 packets, and registers appear in the @code{g} and @code{G} packets
34778 in order of increasing register number.
34779
34780 @item save-restore
34781 Whether the register should be preserved across inferior function
34782 calls; this must be either @code{yes} or @code{no}. The default is
34783 @code{yes}, which is appropriate for most registers except for
34784 some system control registers; this is not related to the target's
34785 ABI.
34786
34787 @item type
34788 The type of the register. @var{type} may be a predefined type, a type
34789 defined in the current feature, or one of the special types @code{int}
34790 and @code{float}. @code{int} is an integer type of the correct size
34791 for @var{bitsize}, and @code{float} is a floating point type (in the
34792 architecture's normal floating point format) of the correct size for
34793 @var{bitsize}. The default is @code{int}.
34794
34795 @item group
34796 The register group to which this register belongs. @var{group} must
34797 be either @code{general}, @code{float}, or @code{vector}. If no
34798 @var{group} is specified, @value{GDBN} will not display the register
34799 in @code{info registers}.
34800
34801 @end table
34802
34803 @node Predefined Target Types
34804 @section Predefined Target Types
34805 @cindex target descriptions, predefined types
34806
34807 Type definitions in the self-description can build up composite types
34808 from basic building blocks, but can not define fundamental types. Instead,
34809 standard identifiers are provided by @value{GDBN} for the fundamental
34810 types. The currently supported types are:
34811
34812 @table @code
34813
34814 @item int8
34815 @itemx int16
34816 @itemx int32
34817 @itemx int64
34818 @itemx int128
34819 Signed integer types holding the specified number of bits.
34820
34821 @item uint8
34822 @itemx uint16
34823 @itemx uint32
34824 @itemx uint64
34825 @itemx uint128
34826 Unsigned integer types holding the specified number of bits.
34827
34828 @item code_ptr
34829 @itemx data_ptr
34830 Pointers to unspecified code and data. The program counter and
34831 any dedicated return address register may be marked as code
34832 pointers; printing a code pointer converts it into a symbolic
34833 address. The stack pointer and any dedicated address registers
34834 may be marked as data pointers.
34835
34836 @item ieee_single
34837 Single precision IEEE floating point.
34838
34839 @item ieee_double
34840 Double precision IEEE floating point.
34841
34842 @item arm_fpa_ext
34843 The 12-byte extended precision format used by ARM FPA registers.
34844
34845 @item i387_ext
34846 The 10-byte extended precision format used by x87 registers.
34847
34848 @item i386_eflags
34849 32bit @sc{eflags} register used by x86.
34850
34851 @item i386_mxcsr
34852 32bit @sc{mxcsr} register used by x86.
34853
34854 @end table
34855
34856 @node Standard Target Features
34857 @section Standard Target Features
34858 @cindex target descriptions, standard features
34859
34860 A target description must contain either no registers or all the
34861 target's registers. If the description contains no registers, then
34862 @value{GDBN} will assume a default register layout, selected based on
34863 the architecture. If the description contains any registers, the
34864 default layout will not be used; the standard registers must be
34865 described in the target description, in such a way that @value{GDBN}
34866 can recognize them.
34867
34868 This is accomplished by giving specific names to feature elements
34869 which contain standard registers. @value{GDBN} will look for features
34870 with those names and verify that they contain the expected registers;
34871 if any known feature is missing required registers, or if any required
34872 feature is missing, @value{GDBN} will reject the target
34873 description. You can add additional registers to any of the
34874 standard features --- @value{GDBN} will display them just as if
34875 they were added to an unrecognized feature.
34876
34877 This section lists the known features and their expected contents.
34878 Sample XML documents for these features are included in the
34879 @value{GDBN} source tree, in the directory @file{gdb/features}.
34880
34881 Names recognized by @value{GDBN} should include the name of the
34882 company or organization which selected the name, and the overall
34883 architecture to which the feature applies; so e.g.@: the feature
34884 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
34885
34886 The names of registers are not case sensitive for the purpose
34887 of recognizing standard features, but @value{GDBN} will only display
34888 registers using the capitalization used in the description.
34889
34890 @menu
34891 * ARM Features::
34892 * i386 Features::
34893 * MIPS Features::
34894 * M68K Features::
34895 * PowerPC Features::
34896 @end menu
34897
34898
34899 @node ARM Features
34900 @subsection ARM Features
34901 @cindex target descriptions, ARM features
34902
34903 The @samp{org.gnu.gdb.arm.core} feature is required for ARM targets.
34904 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
34905 @samp{lr}, @samp{pc}, and @samp{cpsr}.
34906
34907 The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
34908 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
34909
34910 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
34911 it should contain at least registers @samp{wR0} through @samp{wR15} and
34912 @samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
34913 @samp{wCSSF}, and @samp{wCASF} registers are optional.
34914
34915 The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
34916 should contain at least registers @samp{d0} through @samp{d15}. If
34917 they are present, @samp{d16} through @samp{d31} should also be included.
34918 @value{GDBN} will synthesize the single-precision registers from
34919 halves of the double-precision registers.
34920
34921 The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
34922 need to contain registers; it instructs @value{GDBN} to display the
34923 VFP double-precision registers as vectors and to synthesize the
34924 quad-precision registers from pairs of double-precision registers.
34925 If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
34926 be present and include 32 double-precision registers.
34927
34928 @node i386 Features
34929 @subsection i386 Features
34930 @cindex target descriptions, i386 features
34931
34932 The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
34933 targets. It should describe the following registers:
34934
34935 @itemize @minus
34936 @item
34937 @samp{eax} through @samp{edi} plus @samp{eip} for i386
34938 @item
34939 @samp{rax} through @samp{r15} plus @samp{rip} for amd64
34940 @item
34941 @samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
34942 @samp{fs}, @samp{gs}
34943 @item
34944 @samp{st0} through @samp{st7}
34945 @item
34946 @samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
34947 @samp{foseg}, @samp{fooff} and @samp{fop}
34948 @end itemize
34949
34950 The register sets may be different, depending on the target.
34951
34952 The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
34953 describe registers:
34954
34955 @itemize @minus
34956 @item
34957 @samp{xmm0} through @samp{xmm7} for i386
34958 @item
34959 @samp{xmm0} through @samp{xmm15} for amd64
34960 @item
34961 @samp{mxcsr}
34962 @end itemize
34963
34964 The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
34965 @samp{org.gnu.gdb.i386.sse} feature. It should
34966 describe the upper 128 bits of @sc{ymm} registers:
34967
34968 @itemize @minus
34969 @item
34970 @samp{ymm0h} through @samp{ymm7h} for i386
34971 @item
34972 @samp{ymm0h} through @samp{ymm15h} for amd64
34973 @item
34974 @end itemize
34975
34976 The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
34977 describe a single register, @samp{orig_eax}.
34978
34979 @node MIPS Features
34980 @subsection MIPS Features
34981 @cindex target descriptions, MIPS features
34982
34983 The @samp{org.gnu.gdb.mips.cpu} feature is required for MIPS targets.
34984 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
34985 @samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
34986 on the target.
34987
34988 The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
34989 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
34990 registers. They may be 32-bit or 64-bit depending on the target.
34991
34992 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
34993 it may be optional in a future version of @value{GDBN}. It should
34994 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
34995 @samp{fir}. They may be 32-bit or 64-bit depending on the target.
34996
34997 The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
34998 contain a single register, @samp{restart}, which is used by the
34999 Linux kernel to control restartable syscalls.
35000
35001 @node M68K Features
35002 @subsection M68K Features
35003 @cindex target descriptions, M68K features
35004
35005 @table @code
35006 @item @samp{org.gnu.gdb.m68k.core}
35007 @itemx @samp{org.gnu.gdb.coldfire.core}
35008 @itemx @samp{org.gnu.gdb.fido.core}
35009 One of those features must be always present.
35010 The feature that is present determines which flavor of m68k is
35011 used. The feature that is present should contain registers
35012 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
35013 @samp{sp}, @samp{ps} and @samp{pc}.
35014
35015 @item @samp{org.gnu.gdb.coldfire.fp}
35016 This feature is optional. If present, it should contain registers
35017 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
35018 @samp{fpiaddr}.
35019 @end table
35020
35021 @node PowerPC Features
35022 @subsection PowerPC Features
35023 @cindex target descriptions, PowerPC features
35024
35025 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
35026 targets. It should contain registers @samp{r0} through @samp{r31},
35027 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
35028 @samp{xer}. They may be 32-bit or 64-bit depending on the target.
35029
35030 The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
35031 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
35032
35033 The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
35034 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
35035 and @samp{vrsave}.
35036
35037 The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
35038 contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN}
35039 will combine these registers with the floating point registers
35040 (@samp{f0} through @samp{f31}) and the altivec registers (@samp{vr0}
35041 through @samp{vr31}) to present the 128-bit wide registers @samp{vs0}
35042 through @samp{vs63}, the set of vector registers for POWER7.
35043
35044 The @samp{org.gnu.gdb.power.spe} feature is optional. It should
35045 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
35046 @samp{spefscr}. SPE targets should provide 32-bit registers in
35047 @samp{org.gnu.gdb.power.core} and provide the upper halves in
35048 @samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
35049 these to present registers @samp{ev0} through @samp{ev31} to the
35050 user.
35051
35052 @node Operating System Information
35053 @appendix Operating System Information
35054 @cindex operating system information
35055
35056 @menu
35057 * Process list::
35058 @end menu
35059
35060 Users of @value{GDBN} often wish to obtain information about the state of
35061 the operating system running on the target---for example the list of
35062 processes, or the list of open files. This section describes the
35063 mechanism that makes it possible. This mechanism is similar to the
35064 target features mechanism (@pxref{Target Descriptions}), but focuses
35065 on a different aspect of target.
35066
35067 Operating system information is retrived from the target via the
35068 remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
35069 read}). The object name in the request should be @samp{osdata}, and
35070 the @var{annex} identifies the data to be fetched.
35071
35072 @node Process list
35073 @appendixsection Process list
35074 @cindex operating system information, process list
35075
35076 When requesting the process list, the @var{annex} field in the
35077 @samp{qXfer} request should be @samp{processes}. The returned data is
35078 an XML document. The formal syntax of this document is defined in
35079 @file{gdb/features/osdata.dtd}.
35080
35081 An example document is:
35082
35083 @smallexample
35084 <?xml version="1.0"?>
35085 <!DOCTYPE target SYSTEM "osdata.dtd">
35086 <osdata type="processes">
35087 <item>
35088 <column name="pid">1</column>
35089 <column name="user">root</column>
35090 <column name="command">/sbin/init</column>
35091 <column name="cores">1,2,3</column>
35092 </item>
35093 </osdata>
35094 @end smallexample
35095
35096 Each item should include a column whose name is @samp{pid}. The value
35097 of that column should identify the process on the target. The
35098 @samp{user} and @samp{command} columns are optional, and will be
35099 displayed by @value{GDBN}. The @samp{cores} column, if present,
35100 should contain a comma-separated list of cores that this process
35101 is running on. Target may provide additional columns,
35102 which @value{GDBN} currently ignores.
35103
35104 @include gpl.texi
35105
35106 @raisesections
35107 @include fdl.texi
35108 @lowersections
35109
35110 @node Index
35111 @unnumbered Index
35112
35113 @printindex cp
35114
35115 @tex
35116 % I think something like @colophon should be in texinfo. In the
35117 % meantime:
35118 \long\def\colophon{\hbox to0pt{}\vfill
35119 \centerline{The body of this manual is set in}
35120 \centerline{\fontname\tenrm,}
35121 \centerline{with headings in {\bf\fontname\tenbf}}
35122 \centerline{and examples in {\tt\fontname\tentt}.}
35123 \centerline{{\it\fontname\tenit\/},}
35124 \centerline{{\bf\fontname\tenbf}, and}
35125 \centerline{{\sl\fontname\tensl\/}}
35126 \centerline{are used for emphasis.}\vfill}
35127 \page\colophon
35128 % Blame: doc@cygnus.com, 1991.
35129 @end tex
35130
35131 @bye