Add trace file support.
[deliverable/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 @cindex Modula-2
218 Support for Modula-2 is partial. For information on Modula-2, see
219 @ref{Modula-2,,Modula-2}.
220
221 @cindex Pascal
222 Debugging Pascal programs which use sets, subranges, file variables, or
223 nested functions does not currently work. @value{GDBN} does not support
224 entering expressions, printing values, or similar features using Pascal
225 syntax.
226
227 @cindex Fortran
228 @value{GDBN} can be used to debug programs written in Fortran, although
229 it may be necessary to refer to some variables with a trailing
230 underscore.
231
232 @value{GDBN} can be used to debug programs written in Objective-C,
233 using either the Apple/NeXT or the GNU Objective-C runtime.
234
235 @menu
236 * Free Software:: Freely redistributable software
237 * Contributors:: Contributors to GDB
238 @end menu
239
240 @node Free Software
241 @unnumberedsec Free Software
242
243 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
244 General Public License
245 (GPL). The GPL gives you the freedom to copy or adapt a licensed
246 program---but every person getting a copy also gets with it the
247 freedom to modify that copy (which means that they must get access to
248 the source code), and the freedom to distribute further copies.
249 Typical software companies use copyrights to limit your freedoms; the
250 Free Software Foundation uses the GPL to preserve these freedoms.
251
252 Fundamentally, the General Public License is a license which says that
253 you have these freedoms and that you cannot take these freedoms away
254 from anyone else.
255
256 @unnumberedsec Free Software Needs Free Documentation
257
258 The biggest deficiency in the free software community today is not in
259 the software---it is the lack of good free documentation that we can
260 include with the free software. Many of our most important
261 programs do not come with free reference manuals and free introductory
262 texts. Documentation is an essential part of any software package;
263 when an important free software package does not come with a free
264 manual and a free tutorial, that is a major gap. We have many such
265 gaps today.
266
267 Consider Perl, for instance. The tutorial manuals that people
268 normally use are non-free. How did this come about? Because the
269 authors of those manuals published them with restrictive terms---no
270 copying, no modification, source files not available---which exclude
271 them from the free software world.
272
273 That wasn't the first time this sort of thing happened, and it was far
274 from the last. Many times we have heard a GNU user eagerly describe a
275 manual that he is writing, his intended contribution to the community,
276 only to learn that he had ruined everything by signing a publication
277 contract to make it non-free.
278
279 Free documentation, like free software, is a matter of freedom, not
280 price. The problem with the non-free manual is not that publishers
281 charge a price for printed copies---that in itself is fine. (The Free
282 Software Foundation sells printed copies of manuals, too.) The
283 problem is the restrictions on the use of the manual. Free manuals
284 are available in source code form, and give you permission to copy and
285 modify. Non-free manuals do not allow this.
286
287 The criteria of freedom for a free manual are roughly the same as for
288 free software. Redistribution (including the normal kinds of
289 commercial redistribution) must be permitted, so that the manual can
290 accompany every copy of the program, both on-line and on paper.
291
292 Permission for modification of the technical content is crucial too.
293 When people modify the software, adding or changing features, if they
294 are conscientious they will change the manual too---so they can
295 provide accurate and clear documentation for the modified program. A
296 manual that leaves you no choice but to write a new manual to document
297 a changed version of the program is not really available to our
298 community.
299
300 Some kinds of limits on the way modification is handled are
301 acceptable. For example, requirements to preserve the original
302 author's copyright notice, the distribution terms, or the list of
303 authors, are ok. It is also no problem to require modified versions
304 to include notice that they were modified. Even entire sections that
305 may not be deleted or changed are acceptable, as long as they deal
306 with nontechnical topics (like this one). These kinds of restrictions
307 are acceptable because they don't obstruct the community's normal use
308 of the manual.
309
310 However, it must be possible to modify all the @emph{technical}
311 content of the manual, and then distribute the result in all the usual
312 media, through all the usual channels. Otherwise, the restrictions
313 obstruct the use of the manual, it is not free, and we need another
314 manual to replace it.
315
316 Please spread the word about this issue. Our community continues to
317 lose manuals to proprietary publishing. If we spread the word that
318 free software needs free reference manuals and free tutorials, perhaps
319 the next person who wants to contribute by writing documentation will
320 realize, before it is too late, that only free manuals contribute to
321 the free software community.
322
323 If you are writing documentation, please insist on publishing it under
324 the GNU Free Documentation License or another free documentation
325 license. Remember that this decision requires your approval---you
326 don't have to let the publisher decide. Some commercial publishers
327 will use a free license if you insist, but they will not propose the
328 option; it is up to you to raise the issue and say firmly that this is
329 what you want. If the publisher you are dealing with refuses, please
330 try other publishers. If you're not sure whether a proposed license
331 is free, write to @email{licensing@@gnu.org}.
332
333 You can encourage commercial publishers to sell more free, copylefted
334 manuals and tutorials by buying them, and particularly by buying
335 copies from the publishers that paid for their writing or for major
336 improvements. Meanwhile, try to avoid buying non-free documentation
337 at all. Check the distribution terms of a manual before you buy it,
338 and insist that whoever seeks your business must respect your freedom.
339 Check the history of the book, and try to reward the publishers that
340 have paid or pay the authors to work on it.
341
342 The Free Software Foundation maintains a list of free documentation
343 published by other publishers, at
344 @url{http://www.fsf.org/doc/other-free-books.html}.
345
346 @node Contributors
347 @unnumberedsec Contributors to @value{GDBN}
348
349 Richard Stallman was the original author of @value{GDBN}, and of many
350 other @sc{gnu} programs. Many others have contributed to its
351 development. This section attempts to credit major contributors. One
352 of the virtues of free software is that everyone is free to contribute
353 to it; with regret, we cannot actually acknowledge everyone here. The
354 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
355 blow-by-blow account.
356
357 Changes much prior to version 2.0 are lost in the mists of time.
358
359 @quotation
360 @emph{Plea:} Additions to this section are particularly welcome. If you
361 or your friends (or enemies, to be evenhanded) have been unfairly
362 omitted from this list, we would like to add your names!
363 @end quotation
364
365 So that they may not regard their many labors as thankless, we
366 particularly thank those who shepherded @value{GDBN} through major
367 releases:
368 Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
369 Jim Blandy (release 4.18);
370 Jason Molenda (release 4.17);
371 Stan Shebs (release 4.14);
372 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
373 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
374 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
375 Jim Kingdon (releases 3.5, 3.4, and 3.3);
376 and Randy Smith (releases 3.2, 3.1, and 3.0).
377
378 Richard Stallman, assisted at various times by Peter TerMaat, Chris
379 Hanson, and Richard Mlynarik, handled releases through 2.8.
380
381 Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
382 in @value{GDBN}, with significant additional contributions from Per
383 Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
384 demangler. Early work on C@t{++} was by Peter TerMaat (who also did
385 much general update work leading to release 3.0).
386
387 @value{GDBN} uses the BFD subroutine library to examine multiple
388 object-file formats; BFD was a joint project of David V.
389 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
390
391 David Johnson wrote the original COFF support; Pace Willison did
392 the original support for encapsulated COFF.
393
394 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
395
396 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
397 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
398 support.
399 Jean-Daniel Fekete contributed Sun 386i support.
400 Chris Hanson improved the HP9000 support.
401 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
402 David Johnson contributed Encore Umax support.
403 Jyrki Kuoppala contributed Altos 3068 support.
404 Jeff Law contributed HP PA and SOM support.
405 Keith Packard contributed NS32K support.
406 Doug Rabson contributed Acorn Risc Machine support.
407 Bob Rusk contributed Harris Nighthawk CX-UX support.
408 Chris Smith contributed Convex support (and Fortran debugging).
409 Jonathan Stone contributed Pyramid support.
410 Michael Tiemann contributed SPARC support.
411 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
412 Pace Willison contributed Intel 386 support.
413 Jay Vosburgh contributed Symmetry support.
414 Marko Mlinar contributed OpenRISC 1000 support.
415
416 Andreas Schwab contributed M68K @sc{gnu}/Linux support.
417
418 Rich Schaefer and Peter Schauer helped with support of SunOS shared
419 libraries.
420
421 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
422 about several machine instruction sets.
423
424 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
425 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
426 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
427 and RDI targets, respectively.
428
429 Brian Fox is the author of the readline libraries providing
430 command-line editing and command history.
431
432 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
433 Modula-2 support, and contributed the Languages chapter of this manual.
434
435 Fred Fish wrote most of the support for Unix System Vr4.
436 He also enhanced the command-completion support to cover C@t{++} overloaded
437 symbols.
438
439 Hitachi America (now Renesas America), Ltd. sponsored the support for
440 H8/300, H8/500, and Super-H processors.
441
442 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
443
444 Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
445 processors.
446
447 Toshiba sponsored the support for the TX39 Mips processor.
448
449 Matsushita sponsored the support for the MN10200 and MN10300 processors.
450
451 Fujitsu sponsored the support for SPARClite and FR30 processors.
452
453 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
454 watchpoints.
455
456 Michael Snyder added support for tracepoints.
457
458 Stu Grossman wrote gdbserver.
459
460 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
461 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
462
463 The following people at the Hewlett-Packard Company contributed
464 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
465 (narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
466 compiler, and the Text User Interface (nee Terminal User Interface):
467 Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
468 Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
469 provided HP-specific information in this manual.
470
471 DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
472 Robert Hoehne made significant contributions to the DJGPP port.
473
474 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
475 development since 1991. Cygnus engineers who have worked on @value{GDBN}
476 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
477 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
478 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
479 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
480 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
481 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
482 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
483 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
484 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
485 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
486 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
487 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
488 Zuhn have made contributions both large and small.
489
490 Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
491 Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
492
493 Jim Blandy added support for preprocessor macros, while working for Red
494 Hat.
495
496 Andrew Cagney designed @value{GDBN}'s architecture vector. Many
497 people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
498 Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
499 Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
500 Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
501 with the migration of old architectures to this new framework.
502
503 Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
504 unwinder framework, this consisting of a fresh new design featuring
505 frame IDs, independent frame sniffers, and the sentinel frame. Mark
506 Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
507 libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
508 trad unwinders. The architecture-specific changes, each involving a
509 complete rewrite of the architecture's frame code, were carried out by
510 Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
511 Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
512 Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
513 Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
514 Weigand.
515
516 Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
517 Tensilica, Inc.@: contributed support for Xtensa processors. Others
518 who have worked on the Xtensa port of @value{GDBN} in the past include
519 Steve Tjiang, John Newlin, and Scott Foehner.
520
521 Michael Eager and staff of Xilinx, Inc., contributed support for the
522 Xilinx MicroBlaze architecture.
523
524 @node Sample Session
525 @chapter A Sample @value{GDBN} Session
526
527 You can use this manual at your leisure to read all about @value{GDBN}.
528 However, a handful of commands are enough to get started using the
529 debugger. This chapter illustrates those commands.
530
531 @iftex
532 In this sample session, we emphasize user input like this: @b{input},
533 to make it easier to pick out from the surrounding output.
534 @end iftex
535
536 @c FIXME: this example may not be appropriate for some configs, where
537 @c FIXME...primary interest is in remote use.
538
539 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
540 processor) exhibits the following bug: sometimes, when we change its
541 quote strings from the default, the commands used to capture one macro
542 definition within another stop working. In the following short @code{m4}
543 session, we define a macro @code{foo} which expands to @code{0000}; we
544 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
545 same thing. However, when we change the open quote string to
546 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
547 procedure fails to define a new synonym @code{baz}:
548
549 @smallexample
550 $ @b{cd gnu/m4}
551 $ @b{./m4}
552 @b{define(foo,0000)}
553
554 @b{foo}
555 0000
556 @b{define(bar,defn(`foo'))}
557
558 @b{bar}
559 0000
560 @b{changequote(<QUOTE>,<UNQUOTE>)}
561
562 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
563 @b{baz}
564 @b{Ctrl-d}
565 m4: End of input: 0: fatal error: EOF in string
566 @end smallexample
567
568 @noindent
569 Let us use @value{GDBN} to try to see what is going on.
570
571 @smallexample
572 $ @b{@value{GDBP} m4}
573 @c FIXME: this falsifies the exact text played out, to permit smallbook
574 @c FIXME... format to come out better.
575 @value{GDBN} is free software and you are welcome to distribute copies
576 of it under certain conditions; type "show copying" to see
577 the conditions.
578 There is absolutely no warranty for @value{GDBN}; type "show warranty"
579 for details.
580
581 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
582 (@value{GDBP})
583 @end smallexample
584
585 @noindent
586 @value{GDBN} reads only enough symbol data to know where to find the
587 rest when needed; as a result, the first prompt comes up very quickly.
588 We now tell @value{GDBN} to use a narrower display width than usual, so
589 that examples fit in this manual.
590
591 @smallexample
592 (@value{GDBP}) @b{set width 70}
593 @end smallexample
594
595 @noindent
596 We need to see how the @code{m4} built-in @code{changequote} works.
597 Having looked at the source, we know the relevant subroutine is
598 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
599 @code{break} command.
600
601 @smallexample
602 (@value{GDBP}) @b{break m4_changequote}
603 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
604 @end smallexample
605
606 @noindent
607 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
608 control; as long as control does not reach the @code{m4_changequote}
609 subroutine, the program runs as usual:
610
611 @smallexample
612 (@value{GDBP}) @b{run}
613 Starting program: /work/Editorial/gdb/gnu/m4/m4
614 @b{define(foo,0000)}
615
616 @b{foo}
617 0000
618 @end smallexample
619
620 @noindent
621 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
622 suspends execution of @code{m4}, displaying information about the
623 context where it stops.
624
625 @smallexample
626 @b{changequote(<QUOTE>,<UNQUOTE>)}
627
628 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
629 at builtin.c:879
630 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
631 @end smallexample
632
633 @noindent
634 Now we use the command @code{n} (@code{next}) to advance execution to
635 the next line of the current function.
636
637 @smallexample
638 (@value{GDBP}) @b{n}
639 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
640 : nil,
641 @end smallexample
642
643 @noindent
644 @code{set_quotes} looks like a promising subroutine. We can go into it
645 by using the command @code{s} (@code{step}) instead of @code{next}.
646 @code{step} goes to the next line to be executed in @emph{any}
647 subroutine, so it steps into @code{set_quotes}.
648
649 @smallexample
650 (@value{GDBP}) @b{s}
651 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
652 at input.c:530
653 530 if (lquote != def_lquote)
654 @end smallexample
655
656 @noindent
657 The display that shows the subroutine where @code{m4} is now
658 suspended (and its arguments) is called a stack frame display. It
659 shows a summary of the stack. We can use the @code{backtrace}
660 command (which can also be spelled @code{bt}), to see where we are
661 in the stack as a whole: the @code{backtrace} command displays a
662 stack frame for each active subroutine.
663
664 @smallexample
665 (@value{GDBP}) @b{bt}
666 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
667 at input.c:530
668 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
669 at builtin.c:882
670 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
671 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
672 at macro.c:71
673 #4 0x79dc in expand_input () at macro.c:40
674 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
675 @end smallexample
676
677 @noindent
678 We step through a few more lines to see what happens. The first two
679 times, we can use @samp{s}; the next two times we use @code{n} to avoid
680 falling into the @code{xstrdup} subroutine.
681
682 @smallexample
683 (@value{GDBP}) @b{s}
684 0x3b5c 532 if (rquote != def_rquote)
685 (@value{GDBP}) @b{s}
686 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
687 def_lquote : xstrdup(lq);
688 (@value{GDBP}) @b{n}
689 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
690 : xstrdup(rq);
691 (@value{GDBP}) @b{n}
692 538 len_lquote = strlen(rquote);
693 @end smallexample
694
695 @noindent
696 The last line displayed looks a little odd; we can examine the variables
697 @code{lquote} and @code{rquote} to see if they are in fact the new left
698 and right quotes we specified. We use the command @code{p}
699 (@code{print}) to see their values.
700
701 @smallexample
702 (@value{GDBP}) @b{p lquote}
703 $1 = 0x35d40 "<QUOTE>"
704 (@value{GDBP}) @b{p rquote}
705 $2 = 0x35d50 "<UNQUOTE>"
706 @end smallexample
707
708 @noindent
709 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
710 To look at some context, we can display ten lines of source
711 surrounding the current line with the @code{l} (@code{list}) command.
712
713 @smallexample
714 (@value{GDBP}) @b{l}
715 533 xfree(rquote);
716 534
717 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
718 : xstrdup (lq);
719 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
720 : xstrdup (rq);
721 537
722 538 len_lquote = strlen(rquote);
723 539 len_rquote = strlen(lquote);
724 540 @}
725 541
726 542 void
727 @end smallexample
728
729 @noindent
730 Let us step past the two lines that set @code{len_lquote} and
731 @code{len_rquote}, and then examine the values of those variables.
732
733 @smallexample
734 (@value{GDBP}) @b{n}
735 539 len_rquote = strlen(lquote);
736 (@value{GDBP}) @b{n}
737 540 @}
738 (@value{GDBP}) @b{p len_lquote}
739 $3 = 9
740 (@value{GDBP}) @b{p len_rquote}
741 $4 = 7
742 @end smallexample
743
744 @noindent
745 That certainly looks wrong, assuming @code{len_lquote} and
746 @code{len_rquote} are meant to be the lengths of @code{lquote} and
747 @code{rquote} respectively. We can set them to better values using
748 the @code{p} command, since it can print the value of
749 any expression---and that expression can include subroutine calls and
750 assignments.
751
752 @smallexample
753 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
754 $5 = 7
755 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
756 $6 = 9
757 @end smallexample
758
759 @noindent
760 Is that enough to fix the problem of using the new quotes with the
761 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
762 executing with the @code{c} (@code{continue}) command, and then try the
763 example that caused trouble initially:
764
765 @smallexample
766 (@value{GDBP}) @b{c}
767 Continuing.
768
769 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
770
771 baz
772 0000
773 @end smallexample
774
775 @noindent
776 Success! The new quotes now work just as well as the default ones. The
777 problem seems to have been just the two typos defining the wrong
778 lengths. We allow @code{m4} exit by giving it an EOF as input:
779
780 @smallexample
781 @b{Ctrl-d}
782 Program exited normally.
783 @end smallexample
784
785 @noindent
786 The message @samp{Program exited normally.} is from @value{GDBN}; it
787 indicates @code{m4} has finished executing. We can end our @value{GDBN}
788 session with the @value{GDBN} @code{quit} command.
789
790 @smallexample
791 (@value{GDBP}) @b{quit}
792 @end smallexample
793
794 @node Invocation
795 @chapter Getting In and Out of @value{GDBN}
796
797 This chapter discusses how to start @value{GDBN}, and how to get out of it.
798 The essentials are:
799 @itemize @bullet
800 @item
801 type @samp{@value{GDBP}} to start @value{GDBN}.
802 @item
803 type @kbd{quit} or @kbd{Ctrl-d} to exit.
804 @end itemize
805
806 @menu
807 * Invoking GDB:: How to start @value{GDBN}
808 * Quitting GDB:: How to quit @value{GDBN}
809 * Shell Commands:: How to use shell commands inside @value{GDBN}
810 * Logging Output:: How to log @value{GDBN}'s output to a file
811 @end menu
812
813 @node Invoking GDB
814 @section Invoking @value{GDBN}
815
816 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
817 @value{GDBN} reads commands from the terminal until you tell it to exit.
818
819 You can also run @code{@value{GDBP}} with a variety of arguments and options,
820 to specify more of your debugging environment at the outset.
821
822 The command-line options described here are designed
823 to cover a variety of situations; in some environments, some of these
824 options may effectively be unavailable.
825
826 The most usual way to start @value{GDBN} is with one argument,
827 specifying an executable program:
828
829 @smallexample
830 @value{GDBP} @var{program}
831 @end smallexample
832
833 @noindent
834 You can also start with both an executable program and a core file
835 specified:
836
837 @smallexample
838 @value{GDBP} @var{program} @var{core}
839 @end smallexample
840
841 You can, instead, specify a process ID as a second argument, if you want
842 to debug a running process:
843
844 @smallexample
845 @value{GDBP} @var{program} 1234
846 @end smallexample
847
848 @noindent
849 would attach @value{GDBN} to process @code{1234} (unless you also have a file
850 named @file{1234}; @value{GDBN} does check for a core file first).
851
852 Taking advantage of the second command-line argument requires a fairly
853 complete operating system; when you use @value{GDBN} as a remote
854 debugger attached to a bare board, there may not be any notion of
855 ``process'', and there is often no way to get a core dump. @value{GDBN}
856 will warn you if it is unable to attach or to read core dumps.
857
858 You can optionally have @code{@value{GDBP}} pass any arguments after the
859 executable file to the inferior using @code{--args}. This option stops
860 option processing.
861 @smallexample
862 @value{GDBP} --args gcc -O2 -c foo.c
863 @end smallexample
864 This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
865 @code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
866
867 You can run @code{@value{GDBP}} without printing the front material, which describes
868 @value{GDBN}'s non-warranty, by specifying @code{-silent}:
869
870 @smallexample
871 @value{GDBP} -silent
872 @end smallexample
873
874 @noindent
875 You can further control how @value{GDBN} starts up by using command-line
876 options. @value{GDBN} itself can remind you of the options available.
877
878 @noindent
879 Type
880
881 @smallexample
882 @value{GDBP} -help
883 @end smallexample
884
885 @noindent
886 to display all available options and briefly describe their use
887 (@samp{@value{GDBP} -h} is a shorter equivalent).
888
889 All options and command line arguments you give are processed
890 in sequential order. The order makes a difference when the
891 @samp{-x} option is used.
892
893
894 @menu
895 * File Options:: Choosing files
896 * Mode Options:: Choosing modes
897 * Startup:: What @value{GDBN} does during startup
898 @end menu
899
900 @node File Options
901 @subsection Choosing Files
902
903 When @value{GDBN} starts, it reads any arguments other than options as
904 specifying an executable file and core file (or process ID). This is
905 the same as if the arguments were specified by the @samp{-se} and
906 @samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
907 first argument that does not have an associated option flag as
908 equivalent to the @samp{-se} option followed by that argument; and the
909 second argument that does not have an associated option flag, if any, as
910 equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
911 If the second argument begins with a decimal digit, @value{GDBN} will
912 first attempt to attach to it as a process, and if that fails, attempt
913 to open it as a corefile. If you have a corefile whose name begins with
914 a digit, you can prevent @value{GDBN} from treating it as a pid by
915 prefixing it with @file{./}, e.g.@: @file{./12345}.
916
917 If @value{GDBN} has not been configured to included core file support,
918 such as for most embedded targets, then it will complain about a second
919 argument and ignore it.
920
921 Many options have both long and short forms; both are shown in the
922 following list. @value{GDBN} also recognizes the long forms if you truncate
923 them, so long as enough of the option is present to be unambiguous.
924 (If you prefer, you can flag option arguments with @samp{--} rather
925 than @samp{-}, though we illustrate the more usual convention.)
926
927 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
928 @c way, both those who look for -foo and --foo in the index, will find
929 @c it.
930
931 @table @code
932 @item -symbols @var{file}
933 @itemx -s @var{file}
934 @cindex @code{--symbols}
935 @cindex @code{-s}
936 Read symbol table from file @var{file}.
937
938 @item -exec @var{file}
939 @itemx -e @var{file}
940 @cindex @code{--exec}
941 @cindex @code{-e}
942 Use file @var{file} as the executable file to execute when appropriate,
943 and for examining pure data in conjunction with a core dump.
944
945 @item -se @var{file}
946 @cindex @code{--se}
947 Read symbol table from file @var{file} and use it as the executable
948 file.
949
950 @item -core @var{file}
951 @itemx -c @var{file}
952 @cindex @code{--core}
953 @cindex @code{-c}
954 Use file @var{file} as a core dump to examine.
955
956 @item -pid @var{number}
957 @itemx -p @var{number}
958 @cindex @code{--pid}
959 @cindex @code{-p}
960 Connect to process ID @var{number}, as with the @code{attach} command.
961
962 @item -command @var{file}
963 @itemx -x @var{file}
964 @cindex @code{--command}
965 @cindex @code{-x}
966 Execute @value{GDBN} commands from file @var{file}. @xref{Command
967 Files,, Command files}.
968
969 @item -eval-command @var{command}
970 @itemx -ex @var{command}
971 @cindex @code{--eval-command}
972 @cindex @code{-ex}
973 Execute a single @value{GDBN} command.
974
975 This option may be used multiple times to call multiple commands. It may
976 also be interleaved with @samp{-command} as required.
977
978 @smallexample
979 @value{GDBP} -ex 'target sim' -ex 'load' \
980 -x setbreakpoints -ex 'run' a.out
981 @end smallexample
982
983 @item -directory @var{directory}
984 @itemx -d @var{directory}
985 @cindex @code{--directory}
986 @cindex @code{-d}
987 Add @var{directory} to the path to search for source and script files.
988
989 @item -r
990 @itemx -readnow
991 @cindex @code{--readnow}
992 @cindex @code{-r}
993 Read each symbol file's entire symbol table immediately, rather than
994 the default, which is to read it incrementally as it is needed.
995 This makes startup slower, but makes future operations faster.
996
997 @end table
998
999 @node Mode Options
1000 @subsection Choosing Modes
1001
1002 You can run @value{GDBN} in various alternative modes---for example, in
1003 batch mode or quiet mode.
1004
1005 @table @code
1006 @item -nx
1007 @itemx -n
1008 @cindex @code{--nx}
1009 @cindex @code{-n}
1010 Do not execute commands found in any initialization files. Normally,
1011 @value{GDBN} executes the commands in these files after all the command
1012 options and arguments have been processed. @xref{Command Files,,Command
1013 Files}.
1014
1015 @item -quiet
1016 @itemx -silent
1017 @itemx -q
1018 @cindex @code{--quiet}
1019 @cindex @code{--silent}
1020 @cindex @code{-q}
1021 ``Quiet''. Do not print the introductory and copyright messages. These
1022 messages are also suppressed in batch mode.
1023
1024 @item -batch
1025 @cindex @code{--batch}
1026 Run in batch mode. Exit with status @code{0} after processing all the
1027 command files specified with @samp{-x} (and all commands from
1028 initialization files, if not inhibited with @samp{-n}). Exit with
1029 nonzero status if an error occurs in executing the @value{GDBN} commands
1030 in the command files.
1031
1032 Batch mode may be useful for running @value{GDBN} as a filter, for
1033 example to download and run a program on another computer; in order to
1034 make this more useful, the message
1035
1036 @smallexample
1037 Program exited normally.
1038 @end smallexample
1039
1040 @noindent
1041 (which is ordinarily issued whenever a program running under
1042 @value{GDBN} control terminates) is not issued when running in batch
1043 mode.
1044
1045 @item -batch-silent
1046 @cindex @code{--batch-silent}
1047 Run in batch mode exactly like @samp{-batch}, but totally silently. All
1048 @value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1049 unaffected). This is much quieter than @samp{-silent} and would be useless
1050 for an interactive session.
1051
1052 This is particularly useful when using targets that give @samp{Loading section}
1053 messages, for example.
1054
1055 Note that targets that give their output via @value{GDBN}, as opposed to
1056 writing directly to @code{stdout}, will also be made silent.
1057
1058 @item -return-child-result
1059 @cindex @code{--return-child-result}
1060 The return code from @value{GDBN} will be the return code from the child
1061 process (the process being debugged), with the following exceptions:
1062
1063 @itemize @bullet
1064 @item
1065 @value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1066 internal error. In this case the exit code is the same as it would have been
1067 without @samp{-return-child-result}.
1068 @item
1069 The user quits with an explicit value. E.g., @samp{quit 1}.
1070 @item
1071 The child process never runs, or is not allowed to terminate, in which case
1072 the exit code will be -1.
1073 @end itemize
1074
1075 This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1076 when @value{GDBN} is being used as a remote program loader or simulator
1077 interface.
1078
1079 @item -nowindows
1080 @itemx -nw
1081 @cindex @code{--nowindows}
1082 @cindex @code{-nw}
1083 ``No windows''. If @value{GDBN} comes with a graphical user interface
1084 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1085 interface. If no GUI is available, this option has no effect.
1086
1087 @item -windows
1088 @itemx -w
1089 @cindex @code{--windows}
1090 @cindex @code{-w}
1091 If @value{GDBN} includes a GUI, then this option requires it to be
1092 used if possible.
1093
1094 @item -cd @var{directory}
1095 @cindex @code{--cd}
1096 Run @value{GDBN} using @var{directory} as its working directory,
1097 instead of the current directory.
1098
1099 @item -fullname
1100 @itemx -f
1101 @cindex @code{--fullname}
1102 @cindex @code{-f}
1103 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1104 subprocess. It tells @value{GDBN} to output the full file name and line
1105 number in a standard, recognizable fashion each time a stack frame is
1106 displayed (which includes each time your program stops). This
1107 recognizable format looks like two @samp{\032} characters, followed by
1108 the file name, line number and character position separated by colons,
1109 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1110 @samp{\032} characters as a signal to display the source code for the
1111 frame.
1112
1113 @item -epoch
1114 @cindex @code{--epoch}
1115 The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1116 @value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1117 routines so as to allow Epoch to display values of expressions in a
1118 separate window.
1119
1120 @item -annotate @var{level}
1121 @cindex @code{--annotate}
1122 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1123 effect is identical to using @samp{set annotate @var{level}}
1124 (@pxref{Annotations}). The annotation @var{level} controls how much
1125 information @value{GDBN} prints together with its prompt, values of
1126 expressions, source lines, and other types of output. Level 0 is the
1127 normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1128 @sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1129 that control @value{GDBN}, and level 2 has been deprecated.
1130
1131 The annotation mechanism has largely been superseded by @sc{gdb/mi}
1132 (@pxref{GDB/MI}).
1133
1134 @item --args
1135 @cindex @code{--args}
1136 Change interpretation of command line so that arguments following the
1137 executable file are passed as command line arguments to the inferior.
1138 This option stops option processing.
1139
1140 @item -baud @var{bps}
1141 @itemx -b @var{bps}
1142 @cindex @code{--baud}
1143 @cindex @code{-b}
1144 Set the line speed (baud rate or bits per second) of any serial
1145 interface used by @value{GDBN} for remote debugging.
1146
1147 @item -l @var{timeout}
1148 @cindex @code{-l}
1149 Set the timeout (in seconds) of any communication used by @value{GDBN}
1150 for remote debugging.
1151
1152 @item -tty @var{device}
1153 @itemx -t @var{device}
1154 @cindex @code{--tty}
1155 @cindex @code{-t}
1156 Run using @var{device} for your program's standard input and output.
1157 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1158
1159 @c resolve the situation of these eventually
1160 @item -tui
1161 @cindex @code{--tui}
1162 Activate the @dfn{Text User Interface} when starting. The Text User
1163 Interface manages several text windows on the terminal, showing
1164 source, assembly, registers and @value{GDBN} command outputs
1165 (@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1166 Text User Interface can be enabled by invoking the program
1167 @samp{@value{GDBTUI}}. Do not use this option if you run @value{GDBN} from
1168 Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
1169
1170 @c @item -xdb
1171 @c @cindex @code{--xdb}
1172 @c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1173 @c For information, see the file @file{xdb_trans.html}, which is usually
1174 @c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1175 @c systems.
1176
1177 @item -interpreter @var{interp}
1178 @cindex @code{--interpreter}
1179 Use the interpreter @var{interp} for interface with the controlling
1180 program or device. This option is meant to be set by programs which
1181 communicate with @value{GDBN} using it as a back end.
1182 @xref{Interpreters, , Command Interpreters}.
1183
1184 @samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
1185 @value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
1186 The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
1187 previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1188 selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1189 @sc{gdb/mi} interfaces are no longer supported.
1190
1191 @item -write
1192 @cindex @code{--write}
1193 Open the executable and core files for both reading and writing. This
1194 is equivalent to the @samp{set write on} command inside @value{GDBN}
1195 (@pxref{Patching}).
1196
1197 @item -statistics
1198 @cindex @code{--statistics}
1199 This option causes @value{GDBN} to print statistics about time and
1200 memory usage after it completes each command and returns to the prompt.
1201
1202 @item -version
1203 @cindex @code{--version}
1204 This option causes @value{GDBN} to print its version number and
1205 no-warranty blurb, and exit.
1206
1207 @end table
1208
1209 @node Startup
1210 @subsection What @value{GDBN} Does During Startup
1211 @cindex @value{GDBN} startup
1212
1213 Here's the description of what @value{GDBN} does during session startup:
1214
1215 @enumerate
1216 @item
1217 Sets up the command interpreter as specified by the command line
1218 (@pxref{Mode Options, interpreter}).
1219
1220 @item
1221 @cindex init file
1222 Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1223 used when building @value{GDBN}; @pxref{System-wide configuration,
1224 ,System-wide configuration and settings}) and executes all the commands in
1225 that file.
1226
1227 @item
1228 Reads the init file (if any) in your home directory@footnote{On
1229 DOS/Windows systems, the home directory is the one pointed to by the
1230 @code{HOME} environment variable.} and executes all the commands in
1231 that file.
1232
1233 @item
1234 Processes command line options and operands.
1235
1236 @item
1237 Reads and executes the commands from init file (if any) in the current
1238 working directory. This is only done if the current directory is
1239 different from your home directory. Thus, you can have more than one
1240 init file, one generic in your home directory, and another, specific
1241 to the program you are debugging, in the directory where you invoke
1242 @value{GDBN}.
1243
1244 @item
1245 Reads command files specified by the @samp{-x} option. @xref{Command
1246 Files}, for more details about @value{GDBN} command files.
1247
1248 @item
1249 Reads the command history recorded in the @dfn{history file}.
1250 @xref{Command History}, for more details about the command history and the
1251 files where @value{GDBN} records it.
1252 @end enumerate
1253
1254 Init files use the same syntax as @dfn{command files} (@pxref{Command
1255 Files}) and are processed by @value{GDBN} in the same way. The init
1256 file in your home directory can set options (such as @samp{set
1257 complaints}) that affect subsequent processing of command line options
1258 and operands. Init files are not executed if you use the @samp{-nx}
1259 option (@pxref{Mode Options, ,Choosing Modes}).
1260
1261 To display the list of init files loaded by gdb at startup, you
1262 can use @kbd{gdb --help}.
1263
1264 @cindex init file name
1265 @cindex @file{.gdbinit}
1266 @cindex @file{gdb.ini}
1267 The @value{GDBN} init files are normally called @file{.gdbinit}.
1268 The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1269 the limitations of file names imposed by DOS filesystems. The Windows
1270 ports of @value{GDBN} use the standard name, but if they find a
1271 @file{gdb.ini} file, they warn you about that and suggest to rename
1272 the file to the standard name.
1273
1274
1275 @node Quitting GDB
1276 @section Quitting @value{GDBN}
1277 @cindex exiting @value{GDBN}
1278 @cindex leaving @value{GDBN}
1279
1280 @table @code
1281 @kindex quit @r{[}@var{expression}@r{]}
1282 @kindex q @r{(@code{quit})}
1283 @item quit @r{[}@var{expression}@r{]}
1284 @itemx q
1285 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1286 @code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
1287 do not supply @var{expression}, @value{GDBN} will terminate normally;
1288 otherwise it will terminate using the result of @var{expression} as the
1289 error code.
1290 @end table
1291
1292 @cindex interrupt
1293 An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
1294 terminates the action of any @value{GDBN} command that is in progress and
1295 returns to @value{GDBN} command level. It is safe to type the interrupt
1296 character at any time because @value{GDBN} does not allow it to take effect
1297 until a time when it is safe.
1298
1299 If you have been using @value{GDBN} to control an attached process or
1300 device, you can release it with the @code{detach} command
1301 (@pxref{Attach, ,Debugging an Already-running Process}).
1302
1303 @node Shell Commands
1304 @section Shell Commands
1305
1306 If you need to execute occasional shell commands during your
1307 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1308 just use the @code{shell} command.
1309
1310 @table @code
1311 @kindex shell
1312 @cindex shell escape
1313 @item shell @var{command string}
1314 Invoke a standard shell to execute @var{command string}.
1315 If it exists, the environment variable @code{SHELL} determines which
1316 shell to run. Otherwise @value{GDBN} uses the default shell
1317 (@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
1318 @end table
1319
1320 The utility @code{make} is often needed in development environments.
1321 You do not have to use the @code{shell} command for this purpose in
1322 @value{GDBN}:
1323
1324 @table @code
1325 @kindex make
1326 @cindex calling make
1327 @item make @var{make-args}
1328 Execute the @code{make} program with the specified
1329 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1330 @end table
1331
1332 @node Logging Output
1333 @section Logging Output
1334 @cindex logging @value{GDBN} output
1335 @cindex save @value{GDBN} output to a file
1336
1337 You may want to save the output of @value{GDBN} commands to a file.
1338 There are several commands to control @value{GDBN}'s logging.
1339
1340 @table @code
1341 @kindex set logging
1342 @item set logging on
1343 Enable logging.
1344 @item set logging off
1345 Disable logging.
1346 @cindex logging file name
1347 @item set logging file @var{file}
1348 Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1349 @item set logging overwrite [on|off]
1350 By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1351 you want @code{set logging on} to overwrite the logfile instead.
1352 @item set logging redirect [on|off]
1353 By default, @value{GDBN} output will go to both the terminal and the logfile.
1354 Set @code{redirect} if you want output to go only to the log file.
1355 @kindex show logging
1356 @item show logging
1357 Show the current values of the logging settings.
1358 @end table
1359
1360 @node Commands
1361 @chapter @value{GDBN} Commands
1362
1363 You can abbreviate a @value{GDBN} command to the first few letters of the command
1364 name, if that abbreviation is unambiguous; and you can repeat certain
1365 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1366 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1367 show you the alternatives available, if there is more than one possibility).
1368
1369 @menu
1370 * Command Syntax:: How to give commands to @value{GDBN}
1371 * Completion:: Command completion
1372 * Help:: How to ask @value{GDBN} for help
1373 @end menu
1374
1375 @node Command Syntax
1376 @section Command Syntax
1377
1378 A @value{GDBN} command is a single line of input. There is no limit on
1379 how long it can be. It starts with a command name, which is followed by
1380 arguments whose meaning depends on the command name. For example, the
1381 command @code{step} accepts an argument which is the number of times to
1382 step, as in @samp{step 5}. You can also use the @code{step} command
1383 with no arguments. Some commands do not allow any arguments.
1384
1385 @cindex abbreviation
1386 @value{GDBN} command names may always be truncated if that abbreviation is
1387 unambiguous. Other possible command abbreviations are listed in the
1388 documentation for individual commands. In some cases, even ambiguous
1389 abbreviations are allowed; for example, @code{s} is specially defined as
1390 equivalent to @code{step} even though there are other commands whose
1391 names start with @code{s}. You can test abbreviations by using them as
1392 arguments to the @code{help} command.
1393
1394 @cindex repeating commands
1395 @kindex RET @r{(repeat last command)}
1396 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1397 repeat the previous command. Certain commands (for example, @code{run})
1398 will not repeat this way; these are commands whose unintentional
1399 repetition might cause trouble and which you are unlikely to want to
1400 repeat. User-defined commands can disable this feature; see
1401 @ref{Define, dont-repeat}.
1402
1403 The @code{list} and @code{x} commands, when you repeat them with
1404 @key{RET}, construct new arguments rather than repeating
1405 exactly as typed. This permits easy scanning of source or memory.
1406
1407 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1408 output, in a way similar to the common utility @code{more}
1409 (@pxref{Screen Size,,Screen Size}). Since it is easy to press one
1410 @key{RET} too many in this situation, @value{GDBN} disables command
1411 repetition after any command that generates this sort of display.
1412
1413 @kindex # @r{(a comment)}
1414 @cindex comment
1415 Any text from a @kbd{#} to the end of the line is a comment; it does
1416 nothing. This is useful mainly in command files (@pxref{Command
1417 Files,,Command Files}).
1418
1419 @cindex repeating command sequences
1420 @kindex Ctrl-o @r{(operate-and-get-next)}
1421 The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1422 commands. This command accepts the current line, like @key{RET}, and
1423 then fetches the next line relative to the current line from the history
1424 for editing.
1425
1426 @node Completion
1427 @section Command Completion
1428
1429 @cindex completion
1430 @cindex word completion
1431 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1432 only one possibility; it can also show you what the valid possibilities
1433 are for the next word in a command, at any time. This works for @value{GDBN}
1434 commands, @value{GDBN} subcommands, and the names of symbols in your program.
1435
1436 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1437 of a word. If there is only one possibility, @value{GDBN} fills in the
1438 word, and waits for you to finish the command (or press @key{RET} to
1439 enter it). For example, if you type
1440
1441 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1442 @c complete accuracy in these examples; space introduced for clarity.
1443 @c If texinfo enhancements make it unnecessary, it would be nice to
1444 @c replace " @key" by "@key" in the following...
1445 @smallexample
1446 (@value{GDBP}) info bre @key{TAB}
1447 @end smallexample
1448
1449 @noindent
1450 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1451 the only @code{info} subcommand beginning with @samp{bre}:
1452
1453 @smallexample
1454 (@value{GDBP}) info breakpoints
1455 @end smallexample
1456
1457 @noindent
1458 You can either press @key{RET} at this point, to run the @code{info
1459 breakpoints} command, or backspace and enter something else, if
1460 @samp{breakpoints} does not look like the command you expected. (If you
1461 were sure you wanted @code{info breakpoints} in the first place, you
1462 might as well just type @key{RET} immediately after @samp{info bre},
1463 to exploit command abbreviations rather than command completion).
1464
1465 If there is more than one possibility for the next word when you press
1466 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1467 characters and try again, or just press @key{TAB} a second time;
1468 @value{GDBN} displays all the possible completions for that word. For
1469 example, you might want to set a breakpoint on a subroutine whose name
1470 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1471 just sounds the bell. Typing @key{TAB} again displays all the
1472 function names in your program that begin with those characters, for
1473 example:
1474
1475 @smallexample
1476 (@value{GDBP}) b make_ @key{TAB}
1477 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1478 make_a_section_from_file make_environ
1479 make_abs_section make_function_type
1480 make_blockvector make_pointer_type
1481 make_cleanup make_reference_type
1482 make_command make_symbol_completion_list
1483 (@value{GDBP}) b make_
1484 @end smallexample
1485
1486 @noindent
1487 After displaying the available possibilities, @value{GDBN} copies your
1488 partial input (@samp{b make_} in the example) so you can finish the
1489 command.
1490
1491 If you just want to see the list of alternatives in the first place, you
1492 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1493 means @kbd{@key{META} ?}. You can type this either by holding down a
1494 key designated as the @key{META} shift on your keyboard (if there is
1495 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1496
1497 @cindex quotes in commands
1498 @cindex completion of quoted strings
1499 Sometimes the string you need, while logically a ``word'', may contain
1500 parentheses or other characters that @value{GDBN} normally excludes from
1501 its notion of a word. To permit word completion to work in this
1502 situation, you may enclose words in @code{'} (single quote marks) in
1503 @value{GDBN} commands.
1504
1505 The most likely situation where you might need this is in typing the
1506 name of a C@t{++} function. This is because C@t{++} allows function
1507 overloading (multiple definitions of the same function, distinguished
1508 by argument type). For example, when you want to set a breakpoint you
1509 may need to distinguish whether you mean the version of @code{name}
1510 that takes an @code{int} parameter, @code{name(int)}, or the version
1511 that takes a @code{float} parameter, @code{name(float)}. To use the
1512 word-completion facilities in this situation, type a single quote
1513 @code{'} at the beginning of the function name. This alerts
1514 @value{GDBN} that it may need to consider more information than usual
1515 when you press @key{TAB} or @kbd{M-?} to request word completion:
1516
1517 @smallexample
1518 (@value{GDBP}) b 'bubble( @kbd{M-?}
1519 bubble(double,double) bubble(int,int)
1520 (@value{GDBP}) b 'bubble(
1521 @end smallexample
1522
1523 In some cases, @value{GDBN} can tell that completing a name requires using
1524 quotes. When this happens, @value{GDBN} inserts the quote for you (while
1525 completing as much as it can) if you do not type the quote in the first
1526 place:
1527
1528 @smallexample
1529 (@value{GDBP}) b bub @key{TAB}
1530 @exdent @value{GDBN} alters your input line to the following, and rings a bell:
1531 (@value{GDBP}) b 'bubble(
1532 @end smallexample
1533
1534 @noindent
1535 In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1536 you have not yet started typing the argument list when you ask for
1537 completion on an overloaded symbol.
1538
1539 For more information about overloaded functions, see @ref{C Plus Plus
1540 Expressions, ,C@t{++} Expressions}. You can use the command @code{set
1541 overload-resolution off} to disable overload resolution;
1542 see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
1543
1544 @cindex completion of structure field names
1545 @cindex structure field name completion
1546 @cindex completion of union field names
1547 @cindex union field name completion
1548 When completing in an expression which looks up a field in a
1549 structure, @value{GDBN} also tries@footnote{The completer can be
1550 confused by certain kinds of invalid expressions. Also, it only
1551 examines the static type of the expression, not the dynamic type.} to
1552 limit completions to the field names available in the type of the
1553 left-hand-side:
1554
1555 @smallexample
1556 (@value{GDBP}) p gdb_stdout.@kbd{M-?}
1557 magic to_delete to_fputs to_put to_rewind
1558 to_data to_flush to_isatty to_read to_write
1559 @end smallexample
1560
1561 @noindent
1562 This is because the @code{gdb_stdout} is a variable of the type
1563 @code{struct ui_file} that is defined in @value{GDBN} sources as
1564 follows:
1565
1566 @smallexample
1567 struct ui_file
1568 @{
1569 int *magic;
1570 ui_file_flush_ftype *to_flush;
1571 ui_file_write_ftype *to_write;
1572 ui_file_fputs_ftype *to_fputs;
1573 ui_file_read_ftype *to_read;
1574 ui_file_delete_ftype *to_delete;
1575 ui_file_isatty_ftype *to_isatty;
1576 ui_file_rewind_ftype *to_rewind;
1577 ui_file_put_ftype *to_put;
1578 void *to_data;
1579 @}
1580 @end smallexample
1581
1582
1583 @node Help
1584 @section Getting Help
1585 @cindex online documentation
1586 @kindex help
1587
1588 You can always ask @value{GDBN} itself for information on its commands,
1589 using the command @code{help}.
1590
1591 @table @code
1592 @kindex h @r{(@code{help})}
1593 @item help
1594 @itemx h
1595 You can use @code{help} (abbreviated @code{h}) with no arguments to
1596 display a short list of named classes of commands:
1597
1598 @smallexample
1599 (@value{GDBP}) help
1600 List of classes of commands:
1601
1602 aliases -- Aliases of other commands
1603 breakpoints -- Making program stop at certain points
1604 data -- Examining data
1605 files -- Specifying and examining files
1606 internals -- Maintenance commands
1607 obscure -- Obscure features
1608 running -- Running the program
1609 stack -- Examining the stack
1610 status -- Status inquiries
1611 support -- Support facilities
1612 tracepoints -- Tracing of program execution without
1613 stopping the program
1614 user-defined -- User-defined commands
1615
1616 Type "help" followed by a class name for a list of
1617 commands in that class.
1618 Type "help" followed by command name for full
1619 documentation.
1620 Command name abbreviations are allowed if unambiguous.
1621 (@value{GDBP})
1622 @end smallexample
1623 @c the above line break eliminates huge line overfull...
1624
1625 @item help @var{class}
1626 Using one of the general help classes as an argument, you can get a
1627 list of the individual commands in that class. For example, here is the
1628 help display for the class @code{status}:
1629
1630 @smallexample
1631 (@value{GDBP}) help status
1632 Status inquiries.
1633
1634 List of commands:
1635
1636 @c Line break in "show" line falsifies real output, but needed
1637 @c to fit in smallbook page size.
1638 info -- Generic command for showing things
1639 about the program being debugged
1640 show -- Generic command for showing things
1641 about the debugger
1642
1643 Type "help" followed by command name for full
1644 documentation.
1645 Command name abbreviations are allowed if unambiguous.
1646 (@value{GDBP})
1647 @end smallexample
1648
1649 @item help @var{command}
1650 With a command name as @code{help} argument, @value{GDBN} displays a
1651 short paragraph on how to use that command.
1652
1653 @kindex apropos
1654 @item apropos @var{args}
1655 The @code{apropos} command searches through all of the @value{GDBN}
1656 commands, and their documentation, for the regular expression specified in
1657 @var{args}. It prints out all matches found. For example:
1658
1659 @smallexample
1660 apropos reload
1661 @end smallexample
1662
1663 @noindent
1664 results in:
1665
1666 @smallexample
1667 @c @group
1668 set symbol-reloading -- Set dynamic symbol table reloading
1669 multiple times in one run
1670 show symbol-reloading -- Show dynamic symbol table reloading
1671 multiple times in one run
1672 @c @end group
1673 @end smallexample
1674
1675 @kindex complete
1676 @item complete @var{args}
1677 The @code{complete @var{args}} command lists all the possible completions
1678 for the beginning of a command. Use @var{args} to specify the beginning of the
1679 command you want completed. For example:
1680
1681 @smallexample
1682 complete i
1683 @end smallexample
1684
1685 @noindent results in:
1686
1687 @smallexample
1688 @group
1689 if
1690 ignore
1691 info
1692 inspect
1693 @end group
1694 @end smallexample
1695
1696 @noindent This is intended for use by @sc{gnu} Emacs.
1697 @end table
1698
1699 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1700 and @code{show} to inquire about the state of your program, or the state
1701 of @value{GDBN} itself. Each command supports many topics of inquiry; this
1702 manual introduces each of them in the appropriate context. The listings
1703 under @code{info} and under @code{show} in the Index point to
1704 all the sub-commands. @xref{Index}.
1705
1706 @c @group
1707 @table @code
1708 @kindex info
1709 @kindex i @r{(@code{info})}
1710 @item info
1711 This command (abbreviated @code{i}) is for describing the state of your
1712 program. For example, you can show the arguments passed to a function
1713 with @code{info args}, list the registers currently in use with @code{info
1714 registers}, or list the breakpoints you have set with @code{info breakpoints}.
1715 You can get a complete list of the @code{info} sub-commands with
1716 @w{@code{help info}}.
1717
1718 @kindex set
1719 @item set
1720 You can assign the result of an expression to an environment variable with
1721 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1722 @code{set prompt $}.
1723
1724 @kindex show
1725 @item show
1726 In contrast to @code{info}, @code{show} is for describing the state of
1727 @value{GDBN} itself.
1728 You can change most of the things you can @code{show}, by using the
1729 related command @code{set}; for example, you can control what number
1730 system is used for displays with @code{set radix}, or simply inquire
1731 which is currently in use with @code{show radix}.
1732
1733 @kindex info set
1734 To display all the settable parameters and their current
1735 values, you can use @code{show} with no arguments; you may also use
1736 @code{info set}. Both commands produce the same display.
1737 @c FIXME: "info set" violates the rule that "info" is for state of
1738 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1739 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1740 @end table
1741 @c @end group
1742
1743 Here are three miscellaneous @code{show} subcommands, all of which are
1744 exceptional in lacking corresponding @code{set} commands:
1745
1746 @table @code
1747 @kindex show version
1748 @cindex @value{GDBN} version number
1749 @item show version
1750 Show what version of @value{GDBN} is running. You should include this
1751 information in @value{GDBN} bug-reports. If multiple versions of
1752 @value{GDBN} are in use at your site, you may need to determine which
1753 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1754 commands are introduced, and old ones may wither away. Also, many
1755 system vendors ship variant versions of @value{GDBN}, and there are
1756 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
1757 The version number is the same as the one announced when you start
1758 @value{GDBN}.
1759
1760 @kindex show copying
1761 @kindex info copying
1762 @cindex display @value{GDBN} copyright
1763 @item show copying
1764 @itemx info copying
1765 Display information about permission for copying @value{GDBN}.
1766
1767 @kindex show warranty
1768 @kindex info warranty
1769 @item show warranty
1770 @itemx info warranty
1771 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
1772 if your version of @value{GDBN} comes with one.
1773
1774 @end table
1775
1776 @node Running
1777 @chapter Running Programs Under @value{GDBN}
1778
1779 When you run a program under @value{GDBN}, you must first generate
1780 debugging information when you compile it.
1781
1782 You may start @value{GDBN} with its arguments, if any, in an environment
1783 of your choice. If you are doing native debugging, you may redirect
1784 your program's input and output, debug an already running process, or
1785 kill a child process.
1786
1787 @menu
1788 * Compilation:: Compiling for debugging
1789 * Starting:: Starting your program
1790 * Arguments:: Your program's arguments
1791 * Environment:: Your program's environment
1792
1793 * Working Directory:: Your program's working directory
1794 * Input/Output:: Your program's input and output
1795 * Attach:: Debugging an already-running process
1796 * Kill Process:: Killing the child process
1797
1798 * Inferiors and Programs:: Debugging multiple inferiors and programs
1799 * Threads:: Debugging programs with multiple threads
1800 * Forks:: Debugging forks
1801 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
1802 @end menu
1803
1804 @node Compilation
1805 @section Compiling for Debugging
1806
1807 In order to debug a program effectively, you need to generate
1808 debugging information when you compile it. This debugging information
1809 is stored in the object file; it describes the data type of each
1810 variable or function and the correspondence between source line numbers
1811 and addresses in the executable code.
1812
1813 To request debugging information, specify the @samp{-g} option when you run
1814 the compiler.
1815
1816 Programs that are to be shipped to your customers are compiled with
1817 optimizations, using the @samp{-O} compiler option. However, some
1818 compilers are unable to handle the @samp{-g} and @samp{-O} options
1819 together. Using those compilers, you cannot generate optimized
1820 executables containing debugging information.
1821
1822 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
1823 without @samp{-O}, making it possible to debug optimized code. We
1824 recommend that you @emph{always} use @samp{-g} whenever you compile a
1825 program. You may think your program is correct, but there is no sense
1826 in pushing your luck. For more information, see @ref{Optimized Code}.
1827
1828 Older versions of the @sc{gnu} C compiler permitted a variant option
1829 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1830 format; if your @sc{gnu} C compiler has this option, do not use it.
1831
1832 @value{GDBN} knows about preprocessor macros and can show you their
1833 expansion (@pxref{Macros}). Most compilers do not include information
1834 about preprocessor macros in the debugging information if you specify
1835 the @option{-g} flag alone, because this information is rather large.
1836 Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1837 provides macro information if you specify the options
1838 @option{-gdwarf-2} and @option{-g3}; the former option requests
1839 debugging information in the Dwarf 2 format, and the latter requests
1840 ``extra information''. In the future, we hope to find more compact
1841 ways to represent macro information, so that it can be included with
1842 @option{-g} alone.
1843
1844 @need 2000
1845 @node Starting
1846 @section Starting your Program
1847 @cindex starting
1848 @cindex running
1849
1850 @table @code
1851 @kindex run
1852 @kindex r @r{(@code{run})}
1853 @item run
1854 @itemx r
1855 Use the @code{run} command to start your program under @value{GDBN}.
1856 You must first specify the program name (except on VxWorks) with an
1857 argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1858 @value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1859 (@pxref{Files, ,Commands to Specify Files}).
1860
1861 @end table
1862
1863 If you are running your program in an execution environment that
1864 supports processes, @code{run} creates an inferior process and makes
1865 that process run your program. In some environments without processes,
1866 @code{run} jumps to the start of your program. Other targets,
1867 like @samp{remote}, are always running. If you get an error
1868 message like this one:
1869
1870 @smallexample
1871 The "remote" target does not support "run".
1872 Try "help target" or "continue".
1873 @end smallexample
1874
1875 @noindent
1876 then use @code{continue} to run your program. You may need @code{load}
1877 first (@pxref{load}).
1878
1879 The execution of a program is affected by certain information it
1880 receives from its superior. @value{GDBN} provides ways to specify this
1881 information, which you must do @emph{before} starting your program. (You
1882 can change it after starting your program, but such changes only affect
1883 your program the next time you start it.) This information may be
1884 divided into four categories:
1885
1886 @table @asis
1887 @item The @emph{arguments.}
1888 Specify the arguments to give your program as the arguments of the
1889 @code{run} command. If a shell is available on your target, the shell
1890 is used to pass the arguments, so that you may use normal conventions
1891 (such as wildcard expansion or variable substitution) in describing
1892 the arguments.
1893 In Unix systems, you can control which shell is used with the
1894 @code{SHELL} environment variable.
1895 @xref{Arguments, ,Your Program's Arguments}.
1896
1897 @item The @emph{environment.}
1898 Your program normally inherits its environment from @value{GDBN}, but you can
1899 use the @value{GDBN} commands @code{set environment} and @code{unset
1900 environment} to change parts of the environment that affect
1901 your program. @xref{Environment, ,Your Program's Environment}.
1902
1903 @item The @emph{working directory.}
1904 Your program inherits its working directory from @value{GDBN}. You can set
1905 the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1906 @xref{Working Directory, ,Your Program's Working Directory}.
1907
1908 @item The @emph{standard input and output.}
1909 Your program normally uses the same device for standard input and
1910 standard output as @value{GDBN} is using. You can redirect input and output
1911 in the @code{run} command line, or you can use the @code{tty} command to
1912 set a different device for your program.
1913 @xref{Input/Output, ,Your Program's Input and Output}.
1914
1915 @cindex pipes
1916 @emph{Warning:} While input and output redirection work, you cannot use
1917 pipes to pass the output of the program you are debugging to another
1918 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1919 wrong program.
1920 @end table
1921
1922 When you issue the @code{run} command, your program begins to execute
1923 immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
1924 of how to arrange for your program to stop. Once your program has
1925 stopped, you may call functions in your program, using the @code{print}
1926 or @code{call} commands. @xref{Data, ,Examining Data}.
1927
1928 If the modification time of your symbol file has changed since the last
1929 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1930 table, and reads it again. When it does this, @value{GDBN} tries to retain
1931 your current breakpoints.
1932
1933 @table @code
1934 @kindex start
1935 @item start
1936 @cindex run to main procedure
1937 The name of the main procedure can vary from language to language.
1938 With C or C@t{++}, the main procedure name is always @code{main}, but
1939 other languages such as Ada do not require a specific name for their
1940 main procedure. The debugger provides a convenient way to start the
1941 execution of the program and to stop at the beginning of the main
1942 procedure, depending on the language used.
1943
1944 The @samp{start} command does the equivalent of setting a temporary
1945 breakpoint at the beginning of the main procedure and then invoking
1946 the @samp{run} command.
1947
1948 @cindex elaboration phase
1949 Some programs contain an @dfn{elaboration} phase where some startup code is
1950 executed before the main procedure is called. This depends on the
1951 languages used to write your program. In C@t{++}, for instance,
1952 constructors for static and global objects are executed before
1953 @code{main} is called. It is therefore possible that the debugger stops
1954 before reaching the main procedure. However, the temporary breakpoint
1955 will remain to halt execution.
1956
1957 Specify the arguments to give to your program as arguments to the
1958 @samp{start} command. These arguments will be given verbatim to the
1959 underlying @samp{run} command. Note that the same arguments will be
1960 reused if no argument is provided during subsequent calls to
1961 @samp{start} or @samp{run}.
1962
1963 It is sometimes necessary to debug the program during elaboration. In
1964 these cases, using the @code{start} command would stop the execution of
1965 your program too late, as the program would have already completed the
1966 elaboration phase. Under these circumstances, insert breakpoints in your
1967 elaboration code before running your program.
1968
1969 @kindex set exec-wrapper
1970 @item set exec-wrapper @var{wrapper}
1971 @itemx show exec-wrapper
1972 @itemx unset exec-wrapper
1973 When @samp{exec-wrapper} is set, the specified wrapper is used to
1974 launch programs for debugging. @value{GDBN} starts your program
1975 with a shell command of the form @kbd{exec @var{wrapper}
1976 @var{program}}. Quoting is added to @var{program} and its
1977 arguments, but not to @var{wrapper}, so you should add quotes if
1978 appropriate for your shell. The wrapper runs until it executes
1979 your program, and then @value{GDBN} takes control.
1980
1981 You can use any program that eventually calls @code{execve} with
1982 its arguments as a wrapper. Several standard Unix utilities do
1983 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
1984 with @code{exec "$@@"} will also work.
1985
1986 For example, you can use @code{env} to pass an environment variable to
1987 the debugged program, without setting the variable in your shell's
1988 environment:
1989
1990 @smallexample
1991 (@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
1992 (@value{GDBP}) run
1993 @end smallexample
1994
1995 This command is available when debugging locally on most targets, excluding
1996 @sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
1997
1998 @kindex set disable-randomization
1999 @item set disable-randomization
2000 @itemx set disable-randomization on
2001 This option (enabled by default in @value{GDBN}) will turn off the native
2002 randomization of the virtual address space of the started program. This option
2003 is useful for multiple debugging sessions to make the execution better
2004 reproducible and memory addresses reusable across debugging sessions.
2005
2006 This feature is implemented only on @sc{gnu}/Linux. You can get the same
2007 behavior using
2008
2009 @smallexample
2010 (@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2011 @end smallexample
2012
2013 @item set disable-randomization off
2014 Leave the behavior of the started executable unchanged. Some bugs rear their
2015 ugly heads only when the program is loaded at certain addresses. If your bug
2016 disappears when you run the program under @value{GDBN}, that might be because
2017 @value{GDBN} by default disables the address randomization on platforms, such
2018 as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2019 disable-randomization off} to try to reproduce such elusive bugs.
2020
2021 The virtual address space randomization is implemented only on @sc{gnu}/Linux.
2022 It protects the programs against some kinds of security attacks. In these
2023 cases the attacker needs to know the exact location of a concrete executable
2024 code. Randomizing its location makes it impossible to inject jumps misusing
2025 a code at its expected addresses.
2026
2027 Prelinking shared libraries provides a startup performance advantage but it
2028 makes addresses in these libraries predictable for privileged processes by
2029 having just unprivileged access at the target system. Reading the shared
2030 library binary gives enough information for assembling the malicious code
2031 misusing it. Still even a prelinked shared library can get loaded at a new
2032 random address just requiring the regular relocation process during the
2033 startup. Shared libraries not already prelinked are always loaded at
2034 a randomly chosen address.
2035
2036 Position independent executables (PIE) contain position independent code
2037 similar to the shared libraries and therefore such executables get loaded at
2038 a randomly chosen address upon startup. PIE executables always load even
2039 already prelinked shared libraries at a random address. You can build such
2040 executable using @command{gcc -fPIE -pie}.
2041
2042 Heap (malloc storage), stack and custom mmap areas are always placed randomly
2043 (as long as the randomization is enabled).
2044
2045 @item show disable-randomization
2046 Show the current setting of the explicit disable of the native randomization of
2047 the virtual address space of the started program.
2048
2049 @end table
2050
2051 @node Arguments
2052 @section Your Program's Arguments
2053
2054 @cindex arguments (to your program)
2055 The arguments to your program can be specified by the arguments of the
2056 @code{run} command.
2057 They are passed to a shell, which expands wildcard characters and
2058 performs redirection of I/O, and thence to your program. Your
2059 @code{SHELL} environment variable (if it exists) specifies what shell
2060 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
2061 the default shell (@file{/bin/sh} on Unix).
2062
2063 On non-Unix systems, the program is usually invoked directly by
2064 @value{GDBN}, which emulates I/O redirection via the appropriate system
2065 calls, and the wildcard characters are expanded by the startup code of
2066 the program, not by the shell.
2067
2068 @code{run} with no arguments uses the same arguments used by the previous
2069 @code{run}, or those set by the @code{set args} command.
2070
2071 @table @code
2072 @kindex set args
2073 @item set args
2074 Specify the arguments to be used the next time your program is run. If
2075 @code{set args} has no arguments, @code{run} executes your program
2076 with no arguments. Once you have run your program with arguments,
2077 using @code{set args} before the next @code{run} is the only way to run
2078 it again without arguments.
2079
2080 @kindex show args
2081 @item show args
2082 Show the arguments to give your program when it is started.
2083 @end table
2084
2085 @node Environment
2086 @section Your Program's Environment
2087
2088 @cindex environment (of your program)
2089 The @dfn{environment} consists of a set of environment variables and
2090 their values. Environment variables conventionally record such things as
2091 your user name, your home directory, your terminal type, and your search
2092 path for programs to run. Usually you set up environment variables with
2093 the shell and they are inherited by all the other programs you run. When
2094 debugging, it can be useful to try running your program with a modified
2095 environment without having to start @value{GDBN} over again.
2096
2097 @table @code
2098 @kindex path
2099 @item path @var{directory}
2100 Add @var{directory} to the front of the @code{PATH} environment variable
2101 (the search path for executables) that will be passed to your program.
2102 The value of @code{PATH} used by @value{GDBN} does not change.
2103 You may specify several directory names, separated by whitespace or by a
2104 system-dependent separator character (@samp{:} on Unix, @samp{;} on
2105 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2106 is moved to the front, so it is searched sooner.
2107
2108 You can use the string @samp{$cwd} to refer to whatever is the current
2109 working directory at the time @value{GDBN} searches the path. If you
2110 use @samp{.} instead, it refers to the directory where you executed the
2111 @code{path} command. @value{GDBN} replaces @samp{.} in the
2112 @var{directory} argument (with the current path) before adding
2113 @var{directory} to the search path.
2114 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2115 @c document that, since repeating it would be a no-op.
2116
2117 @kindex show paths
2118 @item show paths
2119 Display the list of search paths for executables (the @code{PATH}
2120 environment variable).
2121
2122 @kindex show environment
2123 @item show environment @r{[}@var{varname}@r{]}
2124 Print the value of environment variable @var{varname} to be given to
2125 your program when it starts. If you do not supply @var{varname},
2126 print the names and values of all environment variables to be given to
2127 your program. You can abbreviate @code{environment} as @code{env}.
2128
2129 @kindex set environment
2130 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2131 Set environment variable @var{varname} to @var{value}. The value
2132 changes for your program only, not for @value{GDBN} itself. @var{value} may
2133 be any string; the values of environment variables are just strings, and
2134 any interpretation is supplied by your program itself. The @var{value}
2135 parameter is optional; if it is eliminated, the variable is set to a
2136 null value.
2137 @c "any string" here does not include leading, trailing
2138 @c blanks. Gnu asks: does anyone care?
2139
2140 For example, this command:
2141
2142 @smallexample
2143 set env USER = foo
2144 @end smallexample
2145
2146 @noindent
2147 tells the debugged program, when subsequently run, that its user is named
2148 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2149 are not actually required.)
2150
2151 @kindex unset environment
2152 @item unset environment @var{varname}
2153 Remove variable @var{varname} from the environment to be passed to your
2154 program. This is different from @samp{set env @var{varname} =};
2155 @code{unset environment} removes the variable from the environment,
2156 rather than assigning it an empty value.
2157 @end table
2158
2159 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2160 the shell indicated
2161 by your @code{SHELL} environment variable if it exists (or
2162 @code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2163 that runs an initialization file---such as @file{.cshrc} for C-shell, or
2164 @file{.bashrc} for BASH---any variables you set in that file affect
2165 your program. You may wish to move setting of environment variables to
2166 files that are only run when you sign on, such as @file{.login} or
2167 @file{.profile}.
2168
2169 @node Working Directory
2170 @section Your Program's Working Directory
2171
2172 @cindex working directory (of your program)
2173 Each time you start your program with @code{run}, it inherits its
2174 working directory from the current working directory of @value{GDBN}.
2175 The @value{GDBN} working directory is initially whatever it inherited
2176 from its parent process (typically the shell), but you can specify a new
2177 working directory in @value{GDBN} with the @code{cd} command.
2178
2179 The @value{GDBN} working directory also serves as a default for the commands
2180 that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2181 Specify Files}.
2182
2183 @table @code
2184 @kindex cd
2185 @cindex change working directory
2186 @item cd @var{directory}
2187 Set the @value{GDBN} working directory to @var{directory}.
2188
2189 @kindex pwd
2190 @item pwd
2191 Print the @value{GDBN} working directory.
2192 @end table
2193
2194 It is generally impossible to find the current working directory of
2195 the process being debugged (since a program can change its directory
2196 during its run). If you work on a system where @value{GDBN} is
2197 configured with the @file{/proc} support, you can use the @code{info
2198 proc} command (@pxref{SVR4 Process Information}) to find out the
2199 current working directory of the debuggee.
2200
2201 @node Input/Output
2202 @section Your Program's Input and Output
2203
2204 @cindex redirection
2205 @cindex i/o
2206 @cindex terminal
2207 By default, the program you run under @value{GDBN} does input and output to
2208 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
2209 to its own terminal modes to interact with you, but it records the terminal
2210 modes your program was using and switches back to them when you continue
2211 running your program.
2212
2213 @table @code
2214 @kindex info terminal
2215 @item info terminal
2216 Displays information recorded by @value{GDBN} about the terminal modes your
2217 program is using.
2218 @end table
2219
2220 You can redirect your program's input and/or output using shell
2221 redirection with the @code{run} command. For example,
2222
2223 @smallexample
2224 run > outfile
2225 @end smallexample
2226
2227 @noindent
2228 starts your program, diverting its output to the file @file{outfile}.
2229
2230 @kindex tty
2231 @cindex controlling terminal
2232 Another way to specify where your program should do input and output is
2233 with the @code{tty} command. This command accepts a file name as
2234 argument, and causes this file to be the default for future @code{run}
2235 commands. It also resets the controlling terminal for the child
2236 process, for future @code{run} commands. For example,
2237
2238 @smallexample
2239 tty /dev/ttyb
2240 @end smallexample
2241
2242 @noindent
2243 directs that processes started with subsequent @code{run} commands
2244 default to do input and output on the terminal @file{/dev/ttyb} and have
2245 that as their controlling terminal.
2246
2247 An explicit redirection in @code{run} overrides the @code{tty} command's
2248 effect on the input/output device, but not its effect on the controlling
2249 terminal.
2250
2251 When you use the @code{tty} command or redirect input in the @code{run}
2252 command, only the input @emph{for your program} is affected. The input
2253 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2254 for @code{set inferior-tty}.
2255
2256 @cindex inferior tty
2257 @cindex set inferior controlling terminal
2258 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2259 display the name of the terminal that will be used for future runs of your
2260 program.
2261
2262 @table @code
2263 @item set inferior-tty /dev/ttyb
2264 @kindex set inferior-tty
2265 Set the tty for the program being debugged to /dev/ttyb.
2266
2267 @item show inferior-tty
2268 @kindex show inferior-tty
2269 Show the current tty for the program being debugged.
2270 @end table
2271
2272 @node Attach
2273 @section Debugging an Already-running Process
2274 @kindex attach
2275 @cindex attach
2276
2277 @table @code
2278 @item attach @var{process-id}
2279 This command attaches to a running process---one that was started
2280 outside @value{GDBN}. (@code{info files} shows your active
2281 targets.) The command takes as argument a process ID. The usual way to
2282 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
2283 or with the @samp{jobs -l} shell command.
2284
2285 @code{attach} does not repeat if you press @key{RET} a second time after
2286 executing the command.
2287 @end table
2288
2289 To use @code{attach}, your program must be running in an environment
2290 which supports processes; for example, @code{attach} does not work for
2291 programs on bare-board targets that lack an operating system. You must
2292 also have permission to send the process a signal.
2293
2294 When you use @code{attach}, the debugger finds the program running in
2295 the process first by looking in the current working directory, then (if
2296 the program is not found) by using the source file search path
2297 (@pxref{Source Path, ,Specifying Source Directories}). You can also use
2298 the @code{file} command to load the program. @xref{Files, ,Commands to
2299 Specify Files}.
2300
2301 The first thing @value{GDBN} does after arranging to debug the specified
2302 process is to stop it. You can examine and modify an attached process
2303 with all the @value{GDBN} commands that are ordinarily available when
2304 you start processes with @code{run}. You can insert breakpoints; you
2305 can step and continue; you can modify storage. If you would rather the
2306 process continue running, you may use the @code{continue} command after
2307 attaching @value{GDBN} to the process.
2308
2309 @table @code
2310 @kindex detach
2311 @item detach
2312 When you have finished debugging the attached process, you can use the
2313 @code{detach} command to release it from @value{GDBN} control. Detaching
2314 the process continues its execution. After the @code{detach} command,
2315 that process and @value{GDBN} become completely independent once more, and you
2316 are ready to @code{attach} another process or start one with @code{run}.
2317 @code{detach} does not repeat if you press @key{RET} again after
2318 executing the command.
2319 @end table
2320
2321 If you exit @value{GDBN} while you have an attached process, you detach
2322 that process. If you use the @code{run} command, you kill that process.
2323 By default, @value{GDBN} asks for confirmation if you try to do either of these
2324 things; you can control whether or not you need to confirm by using the
2325 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
2326 Messages}).
2327
2328 @node Kill Process
2329 @section Killing the Child Process
2330
2331 @table @code
2332 @kindex kill
2333 @item kill
2334 Kill the child process in which your program is running under @value{GDBN}.
2335 @end table
2336
2337 This command is useful if you wish to debug a core dump instead of a
2338 running process. @value{GDBN} ignores any core dump file while your program
2339 is running.
2340
2341 On some operating systems, a program cannot be executed outside @value{GDBN}
2342 while you have breakpoints set on it inside @value{GDBN}. You can use the
2343 @code{kill} command in this situation to permit running your program
2344 outside the debugger.
2345
2346 The @code{kill} command is also useful if you wish to recompile and
2347 relink your program, since on many systems it is impossible to modify an
2348 executable file while it is running in a process. In this case, when you
2349 next type @code{run}, @value{GDBN} notices that the file has changed, and
2350 reads the symbol table again (while trying to preserve your current
2351 breakpoint settings).
2352
2353 @node Inferiors and Programs
2354 @section Debugging Multiple Inferiors and Programs
2355
2356 @value{GDBN} lets you run and debug multiple programs in a single
2357 session. In addition, @value{GDBN} on some systems may let you run
2358 several programs simultaneously (otherwise you have to exit from one
2359 before starting another). In the most general case, you can have
2360 multiple threads of execution in each of multiple processes, launched
2361 from multiple executables.
2362
2363 @cindex inferior
2364 @value{GDBN} represents the state of each program execution with an
2365 object called an @dfn{inferior}. An inferior typically corresponds to
2366 a process, but is more general and applies also to targets that do not
2367 have processes. Inferiors may be created before a process runs, and
2368 may be retained after a process exits. Inferiors have unique
2369 identifiers that are different from process ids. Usually each
2370 inferior will also have its own distinct address space, although some
2371 embedded targets may have several inferiors running in different parts
2372 of a single address space. Each inferior may in turn have multiple
2373 threads running in it.
2374
2375 To find out what inferiors exist at any moment, use @w{@code{info
2376 inferiors}}:
2377
2378 @table @code
2379 @kindex info inferiors
2380 @item info inferiors
2381 Print a list of all inferiors currently being managed by @value{GDBN}.
2382
2383 @value{GDBN} displays for each inferior (in this order):
2384
2385 @enumerate
2386 @item
2387 the inferior number assigned by @value{GDBN}
2388
2389 @item
2390 the target system's inferior identifier
2391
2392 @item
2393 the name of the executable the inferior is running.
2394
2395 @end enumerate
2396
2397 @noindent
2398 An asterisk @samp{*} preceding the @value{GDBN} inferior number
2399 indicates the current inferior.
2400
2401 For example,
2402 @end table
2403 @c end table here to get a little more width for example
2404
2405 @smallexample
2406 (@value{GDBP}) info inferiors
2407 Num Description Executable
2408 2 process 2307 hello
2409 * 1 process 3401 goodbye
2410 @end smallexample
2411
2412 To switch focus between inferiors, use the @code{inferior} command:
2413
2414 @table @code
2415 @kindex inferior @var{infno}
2416 @item inferior @var{infno}
2417 Make inferior number @var{infno} the current inferior. The argument
2418 @var{infno} is the inferior number assigned by @value{GDBN}, as shown
2419 in the first field of the @samp{info inferiors} display.
2420 @end table
2421
2422
2423 You can get multiple executables into a debugging session via the
2424 @code{add-inferior} and @w{@code{clone-inferior}} commands. On some
2425 systems @value{GDBN} can add inferiors to the debug session
2426 automatically by following calls to @code{fork} and @code{exec}. To
2427 remove inferiors from the debugging session use the
2428 @w{@code{remove-inferior}} command.
2429
2430 @table @code
2431 @kindex add-inferior
2432 @item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ]
2433 Adds @var{n} inferiors to be run using @var{executable} as the
2434 executable. @var{n} defaults to 1. If no executable is specified,
2435 the inferiors begins empty, with no program. You can still assign or
2436 change the program assigned to the inferior at any time by using the
2437 @code{file} command with the executable name as its argument.
2438
2439 @kindex clone-inferior
2440 @item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
2441 Adds @var{n} inferiors ready to execute the same program as inferior
2442 @var{infno}. @var{n} defaults to 1. @var{infno} defaults to the
2443 number of the current inferior. This is a convenient command when you
2444 want to run another instance of the inferior you are debugging.
2445
2446 @smallexample
2447 (@value{GDBP}) info inferiors
2448 Num Description Executable
2449 * 1 process 29964 helloworld
2450 (@value{GDBP}) clone-inferior
2451 Added inferior 2.
2452 1 inferiors added.
2453 (@value{GDBP}) info inferiors
2454 Num Description Executable
2455 2 <null> helloworld
2456 * 1 process 29964 helloworld
2457 @end smallexample
2458
2459 You can now simply switch focus to inferior 2 and run it.
2460
2461 @kindex remove-inferior
2462 @item remove-inferior @var{infno}
2463 Removes the inferior @var{infno}. It is not possible to remove an
2464 inferior that is running with this command. For those, use the
2465 @code{kill} or @code{detach} command first.
2466
2467 @end table
2468
2469 To quit debugging one of the running inferiors that is not the current
2470 inferior, you can either detach from it by using the @w{@code{detach
2471 inferior}} command (allowing it to run independently), or kill it
2472 using the @w{@code{kill inferior}} command:
2473
2474 @table @code
2475 @kindex detach inferior @var{infno}
2476 @item detach inferior @var{infno}
2477 Detach from the inferior identified by @value{GDBN} inferior number
2478 @var{infno}, and remove it from the inferior list.
2479
2480 @kindex kill inferior @var{infno}
2481 @item kill inferior @var{infno}
2482 Kill the inferior identified by @value{GDBN} inferior number
2483 @var{infno}, and remove it from the inferior list.
2484 @end table
2485
2486 After the successful completion of a command such as @code{detach},
2487 @code{detach inferior}, @code{kill} or @code{kill inferior}, or after
2488 a normal process exit, the inferior is still valid and listed with
2489 @code{info inferiors}, ready to be restarted.
2490
2491
2492 To be notified when inferiors are started or exit under @value{GDBN}'s
2493 control use @w{@code{set print inferior-events}}:
2494
2495 @table @code
2496 @kindex set print inferior-events
2497 @cindex print messages on inferior start and exit
2498 @item set print inferior-events
2499 @itemx set print inferior-events on
2500 @itemx set print inferior-events off
2501 The @code{set print inferior-events} command allows you to enable or
2502 disable printing of messages when @value{GDBN} notices that new
2503 inferiors have started or that inferiors have exited or have been
2504 detached. By default, these messages will not be printed.
2505
2506 @kindex show print inferior-events
2507 @item show print inferior-events
2508 Show whether messages will be printed when @value{GDBN} detects that
2509 inferiors have started, exited or have been detached.
2510 @end table
2511
2512 Many commands will work the same with multiple programs as with a
2513 single program: e.g., @code{print myglobal} will simply display the
2514 value of @code{myglobal} in the current inferior.
2515
2516
2517 Occasionaly, when debugging @value{GDBN} itself, it may be useful to
2518 get more info about the relationship of inferiors, programs, address
2519 spaces in a debug session. You can do that with the @w{@code{maint
2520 info program-spaces}} command.
2521
2522 @table @code
2523 @kindex maint info program-spaces
2524 @item maint info program-spaces
2525 Print a list of all program spaces currently being managed by
2526 @value{GDBN}.
2527
2528 @value{GDBN} displays for each program space (in this order):
2529
2530 @enumerate
2531 @item
2532 the program space number assigned by @value{GDBN}
2533
2534 @item
2535 the name of the executable loaded into the program space, with e.g.,
2536 the @code{file} command.
2537
2538 @end enumerate
2539
2540 @noindent
2541 An asterisk @samp{*} preceding the @value{GDBN} program space number
2542 indicates the current program space.
2543
2544 In addition, below each program space line, @value{GDBN} prints extra
2545 information that isn't suitable to display in tabular form. For
2546 example, the list of inferiors bound to the program space.
2547
2548 @smallexample
2549 (@value{GDBP}) maint info program-spaces
2550 Id Executable
2551 2 goodbye
2552 Bound inferiors: ID 1 (process 21561)
2553 * 1 hello
2554 @end smallexample
2555
2556 Here we can see that no inferior is running the program @code{hello},
2557 while @code{process 21561} is running the program @code{goodbye}. On
2558 some targets, it is possible that multiple inferiors are bound to the
2559 same program space. The most common example is that of debugging both
2560 the parent and child processes of a @code{vfork} call. For example,
2561
2562 @smallexample
2563 (@value{GDBP}) maint info program-spaces
2564 Id Executable
2565 * 1 vfork-test
2566 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
2567 @end smallexample
2568
2569 Here, both inferior 2 and inferior 1 are running in the same program
2570 space as a result of inferior 1 having executed a @code{vfork} call.
2571 @end table
2572
2573 @node Threads
2574 @section Debugging Programs with Multiple Threads
2575
2576 @cindex threads of execution
2577 @cindex multiple threads
2578 @cindex switching threads
2579 In some operating systems, such as HP-UX and Solaris, a single program
2580 may have more than one @dfn{thread} of execution. The precise semantics
2581 of threads differ from one operating system to another, but in general
2582 the threads of a single program are akin to multiple processes---except
2583 that they share one address space (that is, they can all examine and
2584 modify the same variables). On the other hand, each thread has its own
2585 registers and execution stack, and perhaps private memory.
2586
2587 @value{GDBN} provides these facilities for debugging multi-thread
2588 programs:
2589
2590 @itemize @bullet
2591 @item automatic notification of new threads
2592 @item @samp{thread @var{threadno}}, a command to switch among threads
2593 @item @samp{info threads}, a command to inquire about existing threads
2594 @item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
2595 a command to apply a command to a list of threads
2596 @item thread-specific breakpoints
2597 @item @samp{set print thread-events}, which controls printing of
2598 messages on thread start and exit.
2599 @item @samp{set libthread-db-search-path @var{path}}, which lets
2600 the user specify which @code{libthread_db} to use if the default choice
2601 isn't compatible with the program.
2602 @end itemize
2603
2604 @quotation
2605 @emph{Warning:} These facilities are not yet available on every
2606 @value{GDBN} configuration where the operating system supports threads.
2607 If your @value{GDBN} does not support threads, these commands have no
2608 effect. For example, a system without thread support shows no output
2609 from @samp{info threads}, and always rejects the @code{thread} command,
2610 like this:
2611
2612 @smallexample
2613 (@value{GDBP}) info threads
2614 (@value{GDBP}) thread 1
2615 Thread ID 1 not known. Use the "info threads" command to
2616 see the IDs of currently known threads.
2617 @end smallexample
2618 @c FIXME to implementors: how hard would it be to say "sorry, this GDB
2619 @c doesn't support threads"?
2620 @end quotation
2621
2622 @cindex focus of debugging
2623 @cindex current thread
2624 The @value{GDBN} thread debugging facility allows you to observe all
2625 threads while your program runs---but whenever @value{GDBN} takes
2626 control, one thread in particular is always the focus of debugging.
2627 This thread is called the @dfn{current thread}. Debugging commands show
2628 program information from the perspective of the current thread.
2629
2630 @cindex @code{New} @var{systag} message
2631 @cindex thread identifier (system)
2632 @c FIXME-implementors!! It would be more helpful if the [New...] message
2633 @c included GDB's numeric thread handle, so you could just go to that
2634 @c thread without first checking `info threads'.
2635 Whenever @value{GDBN} detects a new thread in your program, it displays
2636 the target system's identification for the thread with a message in the
2637 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2638 whose form varies depending on the particular system. For example, on
2639 @sc{gnu}/Linux, you might see
2640
2641 @smallexample
2642 [New Thread 46912507313328 (LWP 25582)]
2643 @end smallexample
2644
2645 @noindent
2646 when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2647 the @var{systag} is simply something like @samp{process 368}, with no
2648 further qualifier.
2649
2650 @c FIXME!! (1) Does the [New...] message appear even for the very first
2651 @c thread of a program, or does it only appear for the
2652 @c second---i.e.@: when it becomes obvious we have a multithread
2653 @c program?
2654 @c (2) *Is* there necessarily a first thread always? Or do some
2655 @c multithread systems permit starting a program with multiple
2656 @c threads ab initio?
2657
2658 @cindex thread number
2659 @cindex thread identifier (GDB)
2660 For debugging purposes, @value{GDBN} associates its own thread
2661 number---always a single integer---with each thread in your program.
2662
2663 @table @code
2664 @kindex info threads
2665 @item info threads
2666 Display a summary of all threads currently in your
2667 program. @value{GDBN} displays for each thread (in this order):
2668
2669 @enumerate
2670 @item
2671 the thread number assigned by @value{GDBN}
2672
2673 @item
2674 the target system's thread identifier (@var{systag})
2675
2676 @item
2677 the current stack frame summary for that thread
2678 @end enumerate
2679
2680 @noindent
2681 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2682 indicates the current thread.
2683
2684 For example,
2685 @end table
2686 @c end table here to get a little more width for example
2687
2688 @smallexample
2689 (@value{GDBP}) info threads
2690 3 process 35 thread 27 0x34e5 in sigpause ()
2691 2 process 35 thread 23 0x34e5 in sigpause ()
2692 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2693 at threadtest.c:68
2694 @end smallexample
2695
2696 On HP-UX systems:
2697
2698 @cindex debugging multithreaded programs (on HP-UX)
2699 @cindex thread identifier (GDB), on HP-UX
2700 For debugging purposes, @value{GDBN} associates its own thread
2701 number---a small integer assigned in thread-creation order---with each
2702 thread in your program.
2703
2704 @cindex @code{New} @var{systag} message, on HP-UX
2705 @cindex thread identifier (system), on HP-UX
2706 @c FIXME-implementors!! It would be more helpful if the [New...] message
2707 @c included GDB's numeric thread handle, so you could just go to that
2708 @c thread without first checking `info threads'.
2709 Whenever @value{GDBN} detects a new thread in your program, it displays
2710 both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2711 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2712 whose form varies depending on the particular system. For example, on
2713 HP-UX, you see
2714
2715 @smallexample
2716 [New thread 2 (system thread 26594)]
2717 @end smallexample
2718
2719 @noindent
2720 when @value{GDBN} notices a new thread.
2721
2722 @table @code
2723 @kindex info threads (HP-UX)
2724 @item info threads
2725 Display a summary of all threads currently in your
2726 program. @value{GDBN} displays for each thread (in this order):
2727
2728 @enumerate
2729 @item the thread number assigned by @value{GDBN}
2730
2731 @item the target system's thread identifier (@var{systag})
2732
2733 @item the current stack frame summary for that thread
2734 @end enumerate
2735
2736 @noindent
2737 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2738 indicates the current thread.
2739
2740 For example,
2741 @end table
2742 @c end table here to get a little more width for example
2743
2744 @smallexample
2745 (@value{GDBP}) info threads
2746 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2747 at quicksort.c:137
2748 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2749 from /usr/lib/libc.2
2750 1 system thread 27905 0x7b003498 in _brk () \@*
2751 from /usr/lib/libc.2
2752 @end smallexample
2753
2754 On Solaris, you can display more information about user threads with a
2755 Solaris-specific command:
2756
2757 @table @code
2758 @item maint info sol-threads
2759 @kindex maint info sol-threads
2760 @cindex thread info (Solaris)
2761 Display info on Solaris user threads.
2762 @end table
2763
2764 @table @code
2765 @kindex thread @var{threadno}
2766 @item thread @var{threadno}
2767 Make thread number @var{threadno} the current thread. The command
2768 argument @var{threadno} is the internal @value{GDBN} thread number, as
2769 shown in the first field of the @samp{info threads} display.
2770 @value{GDBN} responds by displaying the system identifier of the thread
2771 you selected, and its current stack frame summary:
2772
2773 @smallexample
2774 @c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2775 (@value{GDBP}) thread 2
2776 [Switching to process 35 thread 23]
2777 0x34e5 in sigpause ()
2778 @end smallexample
2779
2780 @noindent
2781 As with the @samp{[New @dots{}]} message, the form of the text after
2782 @samp{Switching to} depends on your system's conventions for identifying
2783 threads.
2784
2785 @kindex thread apply
2786 @cindex apply command to several threads
2787 @item thread apply [@var{threadno}] [@var{all}] @var{command}
2788 The @code{thread apply} command allows you to apply the named
2789 @var{command} to one or more threads. Specify the numbers of the
2790 threads that you want affected with the command argument
2791 @var{threadno}. It can be a single thread number, one of the numbers
2792 shown in the first field of the @samp{info threads} display; or it
2793 could be a range of thread numbers, as in @code{2-4}. To apply a
2794 command to all threads, type @kbd{thread apply all @var{command}}.
2795
2796 @kindex set print thread-events
2797 @cindex print messages on thread start and exit
2798 @item set print thread-events
2799 @itemx set print thread-events on
2800 @itemx set print thread-events off
2801 The @code{set print thread-events} command allows you to enable or
2802 disable printing of messages when @value{GDBN} notices that new threads have
2803 started or that threads have exited. By default, these messages will
2804 be printed if detection of these events is supported by the target.
2805 Note that these messages cannot be disabled on all targets.
2806
2807 @kindex show print thread-events
2808 @item show print thread-events
2809 Show whether messages will be printed when @value{GDBN} detects that threads
2810 have started and exited.
2811 @end table
2812
2813 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
2814 more information about how @value{GDBN} behaves when you stop and start
2815 programs with multiple threads.
2816
2817 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
2818 watchpoints in programs with multiple threads.
2819
2820 @table @code
2821 @kindex set libthread-db-search-path
2822 @cindex search path for @code{libthread_db}
2823 @item set libthread-db-search-path @r{[}@var{path}@r{]}
2824 If this variable is set, @var{path} is a colon-separated list of
2825 directories @value{GDBN} will use to search for @code{libthread_db}.
2826 If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
2827 an empty list.
2828
2829 On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
2830 @code{libthread_db} library to obtain information about threads in the
2831 inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
2832 to find @code{libthread_db}. If that fails, @value{GDBN} will continue
2833 with default system shared library directories, and finally the directory
2834 from which @code{libpthread} was loaded in the inferior process.
2835
2836 For any @code{libthread_db} library @value{GDBN} finds in above directories,
2837 @value{GDBN} attempts to initialize it with the current inferior process.
2838 If this initialization fails (which could happen because of a version
2839 mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
2840 will unload @code{libthread_db}, and continue with the next directory.
2841 If none of @code{libthread_db} libraries initialize successfully,
2842 @value{GDBN} will issue a warning and thread debugging will be disabled.
2843
2844 Setting @code{libthread-db-search-path} is currently implemented
2845 only on some platforms.
2846
2847 @kindex show libthread-db-search-path
2848 @item show libthread-db-search-path
2849 Display current libthread_db search path.
2850 @end table
2851
2852 @node Forks
2853 @section Debugging Forks
2854
2855 @cindex fork, debugging programs which call
2856 @cindex multiple processes
2857 @cindex processes, multiple
2858 On most systems, @value{GDBN} has no special support for debugging
2859 programs which create additional processes using the @code{fork}
2860 function. When a program forks, @value{GDBN} will continue to debug the
2861 parent process and the child process will run unimpeded. If you have
2862 set a breakpoint in any code which the child then executes, the child
2863 will get a @code{SIGTRAP} signal which (unless it catches the signal)
2864 will cause it to terminate.
2865
2866 However, if you want to debug the child process there is a workaround
2867 which isn't too painful. Put a call to @code{sleep} in the code which
2868 the child process executes after the fork. It may be useful to sleep
2869 only if a certain environment variable is set, or a certain file exists,
2870 so that the delay need not occur when you don't want to run @value{GDBN}
2871 on the child. While the child is sleeping, use the @code{ps} program to
2872 get its process ID. Then tell @value{GDBN} (a new invocation of
2873 @value{GDBN} if you are also debugging the parent process) to attach to
2874 the child process (@pxref{Attach}). From that point on you can debug
2875 the child process just like any other process which you attached to.
2876
2877 On some systems, @value{GDBN} provides support for debugging programs that
2878 create additional processes using the @code{fork} or @code{vfork} functions.
2879 Currently, the only platforms with this feature are HP-UX (11.x and later
2880 only?) and @sc{gnu}/Linux (kernel version 2.5.60 and later).
2881
2882 By default, when a program forks, @value{GDBN} will continue to debug
2883 the parent process and the child process will run unimpeded.
2884
2885 If you want to follow the child process instead of the parent process,
2886 use the command @w{@code{set follow-fork-mode}}.
2887
2888 @table @code
2889 @kindex set follow-fork-mode
2890 @item set follow-fork-mode @var{mode}
2891 Set the debugger response to a program call of @code{fork} or
2892 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2893 process. The @var{mode} argument can be:
2894
2895 @table @code
2896 @item parent
2897 The original process is debugged after a fork. The child process runs
2898 unimpeded. This is the default.
2899
2900 @item child
2901 The new process is debugged after a fork. The parent process runs
2902 unimpeded.
2903
2904 @end table
2905
2906 @kindex show follow-fork-mode
2907 @item show follow-fork-mode
2908 Display the current debugger response to a @code{fork} or @code{vfork} call.
2909 @end table
2910
2911 @cindex debugging multiple processes
2912 On Linux, if you want to debug both the parent and child processes, use the
2913 command @w{@code{set detach-on-fork}}.
2914
2915 @table @code
2916 @kindex set detach-on-fork
2917 @item set detach-on-fork @var{mode}
2918 Tells gdb whether to detach one of the processes after a fork, or
2919 retain debugger control over them both.
2920
2921 @table @code
2922 @item on
2923 The child process (or parent process, depending on the value of
2924 @code{follow-fork-mode}) will be detached and allowed to run
2925 independently. This is the default.
2926
2927 @item off
2928 Both processes will be held under the control of @value{GDBN}.
2929 One process (child or parent, depending on the value of
2930 @code{follow-fork-mode}) is debugged as usual, while the other
2931 is held suspended.
2932
2933 @end table
2934
2935 @kindex show detach-on-fork
2936 @item show detach-on-fork
2937 Show whether detach-on-fork mode is on/off.
2938 @end table
2939
2940 If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
2941 will retain control of all forked processes (including nested forks).
2942 You can list the forked processes under the control of @value{GDBN} by
2943 using the @w{@code{info inferiors}} command, and switch from one fork
2944 to another by using the @code{inferior} command (@pxref{Inferiors and
2945 Programs, ,Debugging Multiple Inferiors and Programs}).
2946
2947 To quit debugging one of the forked processes, you can either detach
2948 from it by using the @w{@code{detach inferior}} command (allowing it
2949 to run independently), or kill it using the @w{@code{kill inferior}}
2950 command. @xref{Inferiors and Programs, ,Debugging Multiple Inferiors
2951 and Programs}.
2952
2953 If you ask to debug a child process and a @code{vfork} is followed by an
2954 @code{exec}, @value{GDBN} executes the new target up to the first
2955 breakpoint in the new target. If you have a breakpoint set on
2956 @code{main} in your original program, the breakpoint will also be set on
2957 the child process's @code{main}.
2958
2959 On some systems, when a child process is spawned by @code{vfork}, you
2960 cannot debug the child or parent until an @code{exec} call completes.
2961
2962 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2963 call executes, the new target restarts. To restart the parent
2964 process, use the @code{file} command with the parent executable name
2965 as its argument. By default, after an @code{exec} call executes,
2966 @value{GDBN} discards the symbols of the previous executable image.
2967 You can change this behaviour with the @w{@code{set follow-exec-mode}}
2968 command.
2969
2970 @table @code
2971 @kindex set follow-exec-mode
2972 @item set follow-exec-mode @var{mode}
2973
2974 Set debugger response to a program call of @code{exec}. An
2975 @code{exec} call replaces the program image of a process.
2976
2977 @code{follow-exec-mode} can be:
2978
2979 @table @code
2980 @item new
2981 @value{GDBN} creates a new inferior and rebinds the process to this
2982 new inferior. The program the process was running before the
2983 @code{exec} call can be restarted afterwards by restarting the
2984 original inferior.
2985
2986 For example:
2987
2988 @smallexample
2989 (@value{GDBP}) info inferiors
2990 (gdb) info inferior
2991 Id Description Executable
2992 * 1 <null> prog1
2993 (@value{GDBP}) run
2994 process 12020 is executing new program: prog2
2995 Program exited normally.
2996 (@value{GDBP}) info inferiors
2997 Id Description Executable
2998 * 2 <null> prog2
2999 1 <null> prog1
3000 @end smallexample
3001
3002 @item same
3003 @value{GDBN} keeps the process bound to the same inferior. The new
3004 executable image replaces the previous executable loaded in the
3005 inferior. Restarting the inferior after the @code{exec} call, with
3006 e.g., the @code{run} command, restarts the executable the process was
3007 running after the @code{exec} call. This is the default mode.
3008
3009 For example:
3010
3011 @smallexample
3012 (@value{GDBP}) info inferiors
3013 Id Description Executable
3014 * 1 <null> prog1
3015 (@value{GDBP}) run
3016 process 12020 is executing new program: prog2
3017 Program exited normally.
3018 (@value{GDBP}) info inferiors
3019 Id Description Executable
3020 * 1 <null> prog2
3021 @end smallexample
3022
3023 @end table
3024 @end table
3025
3026 You can use the @code{catch} command to make @value{GDBN} stop whenever
3027 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
3028 Catchpoints, ,Setting Catchpoints}.
3029
3030 @node Checkpoint/Restart
3031 @section Setting a @emph{Bookmark} to Return to Later
3032
3033 @cindex checkpoint
3034 @cindex restart
3035 @cindex bookmark
3036 @cindex snapshot of a process
3037 @cindex rewind program state
3038
3039 On certain operating systems@footnote{Currently, only
3040 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3041 program's state, called a @dfn{checkpoint}, and come back to it
3042 later.
3043
3044 Returning to a checkpoint effectively undoes everything that has
3045 happened in the program since the @code{checkpoint} was saved. This
3046 includes changes in memory, registers, and even (within some limits)
3047 system state. Effectively, it is like going back in time to the
3048 moment when the checkpoint was saved.
3049
3050 Thus, if you're stepping thru a program and you think you're
3051 getting close to the point where things go wrong, you can save
3052 a checkpoint. Then, if you accidentally go too far and miss
3053 the critical statement, instead of having to restart your program
3054 from the beginning, you can just go back to the checkpoint and
3055 start again from there.
3056
3057 This can be especially useful if it takes a lot of time or
3058 steps to reach the point where you think the bug occurs.
3059
3060 To use the @code{checkpoint}/@code{restart} method of debugging:
3061
3062 @table @code
3063 @kindex checkpoint
3064 @item checkpoint
3065 Save a snapshot of the debugged program's current execution state.
3066 The @code{checkpoint} command takes no arguments, but each checkpoint
3067 is assigned a small integer id, similar to a breakpoint id.
3068
3069 @kindex info checkpoints
3070 @item info checkpoints
3071 List the checkpoints that have been saved in the current debugging
3072 session. For each checkpoint, the following information will be
3073 listed:
3074
3075 @table @code
3076 @item Checkpoint ID
3077 @item Process ID
3078 @item Code Address
3079 @item Source line, or label
3080 @end table
3081
3082 @kindex restart @var{checkpoint-id}
3083 @item restart @var{checkpoint-id}
3084 Restore the program state that was saved as checkpoint number
3085 @var{checkpoint-id}. All program variables, registers, stack frames
3086 etc.@: will be returned to the values that they had when the checkpoint
3087 was saved. In essence, gdb will ``wind back the clock'' to the point
3088 in time when the checkpoint was saved.
3089
3090 Note that breakpoints, @value{GDBN} variables, command history etc.
3091 are not affected by restoring a checkpoint. In general, a checkpoint
3092 only restores things that reside in the program being debugged, not in
3093 the debugger.
3094
3095 @kindex delete checkpoint @var{checkpoint-id}
3096 @item delete checkpoint @var{checkpoint-id}
3097 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3098
3099 @end table
3100
3101 Returning to a previously saved checkpoint will restore the user state
3102 of the program being debugged, plus a significant subset of the system
3103 (OS) state, including file pointers. It won't ``un-write'' data from
3104 a file, but it will rewind the file pointer to the previous location,
3105 so that the previously written data can be overwritten. For files
3106 opened in read mode, the pointer will also be restored so that the
3107 previously read data can be read again.
3108
3109 Of course, characters that have been sent to a printer (or other
3110 external device) cannot be ``snatched back'', and characters received
3111 from eg.@: a serial device can be removed from internal program buffers,
3112 but they cannot be ``pushed back'' into the serial pipeline, ready to
3113 be received again. Similarly, the actual contents of files that have
3114 been changed cannot be restored (at this time).
3115
3116 However, within those constraints, you actually can ``rewind'' your
3117 program to a previously saved point in time, and begin debugging it
3118 again --- and you can change the course of events so as to debug a
3119 different execution path this time.
3120
3121 @cindex checkpoints and process id
3122 Finally, there is one bit of internal program state that will be
3123 different when you return to a checkpoint --- the program's process
3124 id. Each checkpoint will have a unique process id (or @var{pid}),
3125 and each will be different from the program's original @var{pid}.
3126 If your program has saved a local copy of its process id, this could
3127 potentially pose a problem.
3128
3129 @subsection A Non-obvious Benefit of Using Checkpoints
3130
3131 On some systems such as @sc{gnu}/Linux, address space randomization
3132 is performed on new processes for security reasons. This makes it
3133 difficult or impossible to set a breakpoint, or watchpoint, on an
3134 absolute address if you have to restart the program, since the
3135 absolute location of a symbol will change from one execution to the
3136 next.
3137
3138 A checkpoint, however, is an @emph{identical} copy of a process.
3139 Therefore if you create a checkpoint at (eg.@:) the start of main,
3140 and simply return to that checkpoint instead of restarting the
3141 process, you can avoid the effects of address randomization and
3142 your symbols will all stay in the same place.
3143
3144 @node Stopping
3145 @chapter Stopping and Continuing
3146
3147 The principal purposes of using a debugger are so that you can stop your
3148 program before it terminates; or so that, if your program runs into
3149 trouble, you can investigate and find out why.
3150
3151 Inside @value{GDBN}, your program may stop for any of several reasons,
3152 such as a signal, a breakpoint, or reaching a new line after a
3153 @value{GDBN} command such as @code{step}. You may then examine and
3154 change variables, set new breakpoints or remove old ones, and then
3155 continue execution. Usually, the messages shown by @value{GDBN} provide
3156 ample explanation of the status of your program---but you can also
3157 explicitly request this information at any time.
3158
3159 @table @code
3160 @kindex info program
3161 @item info program
3162 Display information about the status of your program: whether it is
3163 running or not, what process it is, and why it stopped.
3164 @end table
3165
3166 @menu
3167 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
3168 * Continuing and Stepping:: Resuming execution
3169 * Signals:: Signals
3170 * Thread Stops:: Stopping and starting multi-thread programs
3171 @end menu
3172
3173 @node Breakpoints
3174 @section Breakpoints, Watchpoints, and Catchpoints
3175
3176 @cindex breakpoints
3177 A @dfn{breakpoint} makes your program stop whenever a certain point in
3178 the program is reached. For each breakpoint, you can add conditions to
3179 control in finer detail whether your program stops. You can set
3180 breakpoints with the @code{break} command and its variants (@pxref{Set
3181 Breaks, ,Setting Breakpoints}), to specify the place where your program
3182 should stop by line number, function name or exact address in the
3183 program.
3184
3185 On some systems, you can set breakpoints in shared libraries before
3186 the executable is run. There is a minor limitation on HP-UX systems:
3187 you must wait until the executable is run in order to set breakpoints
3188 in shared library routines that are not called directly by the program
3189 (for example, routines that are arguments in a @code{pthread_create}
3190 call).
3191
3192 @cindex watchpoints
3193 @cindex data breakpoints
3194 @cindex memory tracing
3195 @cindex breakpoint on memory address
3196 @cindex breakpoint on variable modification
3197 A @dfn{watchpoint} is a special breakpoint that stops your program
3198 when the value of an expression changes. The expression may be a value
3199 of a variable, or it could involve values of one or more variables
3200 combined by operators, such as @samp{a + b}. This is sometimes called
3201 @dfn{data breakpoints}. You must use a different command to set
3202 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
3203 from that, you can manage a watchpoint like any other breakpoint: you
3204 enable, disable, and delete both breakpoints and watchpoints using the
3205 same commands.
3206
3207 You can arrange to have values from your program displayed automatically
3208 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
3209 Automatic Display}.
3210
3211 @cindex catchpoints
3212 @cindex breakpoint on events
3213 A @dfn{catchpoint} is another special breakpoint that stops your program
3214 when a certain kind of event occurs, such as the throwing of a C@t{++}
3215 exception or the loading of a library. As with watchpoints, you use a
3216 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
3217 Catchpoints}), but aside from that, you can manage a catchpoint like any
3218 other breakpoint. (To stop when your program receives a signal, use the
3219 @code{handle} command; see @ref{Signals, ,Signals}.)
3220
3221 @cindex breakpoint numbers
3222 @cindex numbers for breakpoints
3223 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
3224 catchpoint when you create it; these numbers are successive integers
3225 starting with one. In many of the commands for controlling various
3226 features of breakpoints you use the breakpoint number to say which
3227 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
3228 @dfn{disabled}; if disabled, it has no effect on your program until you
3229 enable it again.
3230
3231 @cindex breakpoint ranges
3232 @cindex ranges of breakpoints
3233 Some @value{GDBN} commands accept a range of breakpoints on which to
3234 operate. A breakpoint range is either a single breakpoint number, like
3235 @samp{5}, or two such numbers, in increasing order, separated by a
3236 hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
3237 all breakpoints in that range are operated on.
3238
3239 @menu
3240 * Set Breaks:: Setting breakpoints
3241 * Set Watchpoints:: Setting watchpoints
3242 * Set Catchpoints:: Setting catchpoints
3243 * Delete Breaks:: Deleting breakpoints
3244 * Disabling:: Disabling breakpoints
3245 * Conditions:: Break conditions
3246 * Break Commands:: Breakpoint command lists
3247 * Error in Breakpoints:: ``Cannot insert breakpoints''
3248 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
3249 @end menu
3250
3251 @node Set Breaks
3252 @subsection Setting Breakpoints
3253
3254 @c FIXME LMB what does GDB do if no code on line of breakpt?
3255 @c consider in particular declaration with/without initialization.
3256 @c
3257 @c FIXME 2 is there stuff on this already? break at fun start, already init?
3258
3259 @kindex break
3260 @kindex b @r{(@code{break})}
3261 @vindex $bpnum@r{, convenience variable}
3262 @cindex latest breakpoint
3263 Breakpoints are set with the @code{break} command (abbreviated
3264 @code{b}). The debugger convenience variable @samp{$bpnum} records the
3265 number of the breakpoint you've set most recently; see @ref{Convenience
3266 Vars,, Convenience Variables}, for a discussion of what you can do with
3267 convenience variables.
3268
3269 @table @code
3270 @item break @var{location}
3271 Set a breakpoint at the given @var{location}, which can specify a
3272 function name, a line number, or an address of an instruction.
3273 (@xref{Specify Location}, for a list of all the possible ways to
3274 specify a @var{location}.) The breakpoint will stop your program just
3275 before it executes any of the code in the specified @var{location}.
3276
3277 When using source languages that permit overloading of symbols, such as
3278 C@t{++}, a function name may refer to more than one possible place to break.
3279 @xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
3280 that situation.
3281
3282 It is also possible to insert a breakpoint that will stop the program
3283 only if a specific thread (@pxref{Thread-Specific Breakpoints})
3284 or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
3285
3286 @item break
3287 When called without any arguments, @code{break} sets a breakpoint at
3288 the next instruction to be executed in the selected stack frame
3289 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
3290 innermost, this makes your program stop as soon as control
3291 returns to that frame. This is similar to the effect of a
3292 @code{finish} command in the frame inside the selected frame---except
3293 that @code{finish} does not leave an active breakpoint. If you use
3294 @code{break} without an argument in the innermost frame, @value{GDBN} stops
3295 the next time it reaches the current location; this may be useful
3296 inside loops.
3297
3298 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
3299 least one instruction has been executed. If it did not do this, you
3300 would be unable to proceed past a breakpoint without first disabling the
3301 breakpoint. This rule applies whether or not the breakpoint already
3302 existed when your program stopped.
3303
3304 @item break @dots{} if @var{cond}
3305 Set a breakpoint with condition @var{cond}; evaluate the expression
3306 @var{cond} each time the breakpoint is reached, and stop only if the
3307 value is nonzero---that is, if @var{cond} evaluates as true.
3308 @samp{@dots{}} stands for one of the possible arguments described
3309 above (or no argument) specifying where to break. @xref{Conditions,
3310 ,Break Conditions}, for more information on breakpoint conditions.
3311
3312 @kindex tbreak
3313 @item tbreak @var{args}
3314 Set a breakpoint enabled only for one stop. @var{args} are the
3315 same as for the @code{break} command, and the breakpoint is set in the same
3316 way, but the breakpoint is automatically deleted after the first time your
3317 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
3318
3319 @kindex hbreak
3320 @cindex hardware breakpoints
3321 @item hbreak @var{args}
3322 Set a hardware-assisted breakpoint. @var{args} are the same as for the
3323 @code{break} command and the breakpoint is set in the same way, but the
3324 breakpoint requires hardware support and some target hardware may not
3325 have this support. The main purpose of this is EPROM/ROM code
3326 debugging, so you can set a breakpoint at an instruction without
3327 changing the instruction. This can be used with the new trap-generation
3328 provided by SPARClite DSU and most x86-based targets. These targets
3329 will generate traps when a program accesses some data or instruction
3330 address that is assigned to the debug registers. However the hardware
3331 breakpoint registers can take a limited number of breakpoints. For
3332 example, on the DSU, only two data breakpoints can be set at a time, and
3333 @value{GDBN} will reject this command if more than two are used. Delete
3334 or disable unused hardware breakpoints before setting new ones
3335 (@pxref{Disabling, ,Disabling Breakpoints}).
3336 @xref{Conditions, ,Break Conditions}.
3337 For remote targets, you can restrict the number of hardware
3338 breakpoints @value{GDBN} will use, see @ref{set remote
3339 hardware-breakpoint-limit}.
3340
3341 @kindex thbreak
3342 @item thbreak @var{args}
3343 Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
3344 are the same as for the @code{hbreak} command and the breakpoint is set in
3345 the same way. However, like the @code{tbreak} command,
3346 the breakpoint is automatically deleted after the
3347 first time your program stops there. Also, like the @code{hbreak}
3348 command, the breakpoint requires hardware support and some target hardware
3349 may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
3350 See also @ref{Conditions, ,Break Conditions}.
3351
3352 @kindex rbreak
3353 @cindex regular expression
3354 @cindex breakpoints in functions matching a regexp
3355 @cindex set breakpoints in many functions
3356 @item rbreak @var{regex}
3357 Set breakpoints on all functions matching the regular expression
3358 @var{regex}. This command sets an unconditional breakpoint on all
3359 matches, printing a list of all breakpoints it set. Once these
3360 breakpoints are set, they are treated just like the breakpoints set with
3361 the @code{break} command. You can delete them, disable them, or make
3362 them conditional the same way as any other breakpoint.
3363
3364 The syntax of the regular expression is the standard one used with tools
3365 like @file{grep}. Note that this is different from the syntax used by
3366 shells, so for instance @code{foo*} matches all functions that include
3367 an @code{fo} followed by zero or more @code{o}s. There is an implicit
3368 @code{.*} leading and trailing the regular expression you supply, so to
3369 match only functions that begin with @code{foo}, use @code{^foo}.
3370
3371 @cindex non-member C@t{++} functions, set breakpoint in
3372 When debugging C@t{++} programs, @code{rbreak} is useful for setting
3373 breakpoints on overloaded functions that are not members of any special
3374 classes.
3375
3376 @cindex set breakpoints on all functions
3377 The @code{rbreak} command can be used to set breakpoints in
3378 @strong{all} the functions in a program, like this:
3379
3380 @smallexample
3381 (@value{GDBP}) rbreak .
3382 @end smallexample
3383
3384 @kindex info breakpoints
3385 @cindex @code{$_} and @code{info breakpoints}
3386 @item info breakpoints @r{[}@var{n}@r{]}
3387 @itemx info break @r{[}@var{n}@r{]}
3388 @itemx info watchpoints @r{[}@var{n}@r{]}
3389 Print a table of all breakpoints, watchpoints, and catchpoints set and
3390 not deleted. Optional argument @var{n} means print information only
3391 about the specified breakpoint (or watchpoint or catchpoint). For
3392 each breakpoint, following columns are printed:
3393
3394 @table @emph
3395 @item Breakpoint Numbers
3396 @item Type
3397 Breakpoint, watchpoint, or catchpoint.
3398 @item Disposition
3399 Whether the breakpoint is marked to be disabled or deleted when hit.
3400 @item Enabled or Disabled
3401 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
3402 that are not enabled.
3403 @item Address
3404 Where the breakpoint is in your program, as a memory address. For a
3405 pending breakpoint whose address is not yet known, this field will
3406 contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
3407 library that has the symbol or line referred by breakpoint is loaded.
3408 See below for details. A breakpoint with several locations will
3409 have @samp{<MULTIPLE>} in this field---see below for details.
3410 @item What
3411 Where the breakpoint is in the source for your program, as a file and
3412 line number. For a pending breakpoint, the original string passed to
3413 the breakpoint command will be listed as it cannot be resolved until
3414 the appropriate shared library is loaded in the future.
3415 @end table
3416
3417 @noindent
3418 If a breakpoint is conditional, @code{info break} shows the condition on
3419 the line following the affected breakpoint; breakpoint commands, if any,
3420 are listed after that. A pending breakpoint is allowed to have a condition
3421 specified for it. The condition is not parsed for validity until a shared
3422 library is loaded that allows the pending breakpoint to resolve to a
3423 valid location.
3424
3425 @noindent
3426 @code{info break} with a breakpoint
3427 number @var{n} as argument lists only that breakpoint. The
3428 convenience variable @code{$_} and the default examining-address for
3429 the @code{x} command are set to the address of the last breakpoint
3430 listed (@pxref{Memory, ,Examining Memory}).
3431
3432 @noindent
3433 @code{info break} displays a count of the number of times the breakpoint
3434 has been hit. This is especially useful in conjunction with the
3435 @code{ignore} command. You can ignore a large number of breakpoint
3436 hits, look at the breakpoint info to see how many times the breakpoint
3437 was hit, and then run again, ignoring one less than that number. This
3438 will get you quickly to the last hit of that breakpoint.
3439 @end table
3440
3441 @value{GDBN} allows you to set any number of breakpoints at the same place in
3442 your program. There is nothing silly or meaningless about this. When
3443 the breakpoints are conditional, this is even useful
3444 (@pxref{Conditions, ,Break Conditions}).
3445
3446 @cindex multiple locations, breakpoints
3447 @cindex breakpoints, multiple locations
3448 It is possible that a breakpoint corresponds to several locations
3449 in your program. Examples of this situation are:
3450
3451 @itemize @bullet
3452 @item
3453 For a C@t{++} constructor, the @value{NGCC} compiler generates several
3454 instances of the function body, used in different cases.
3455
3456 @item
3457 For a C@t{++} template function, a given line in the function can
3458 correspond to any number of instantiations.
3459
3460 @item
3461 For an inlined function, a given source line can correspond to
3462 several places where that function is inlined.
3463 @end itemize
3464
3465 In all those cases, @value{GDBN} will insert a breakpoint at all
3466 the relevant locations@footnote{
3467 As of this writing, multiple-location breakpoints work only if there's
3468 line number information for all the locations. This means that they
3469 will generally not work in system libraries, unless you have debug
3470 info with line numbers for them.}.
3471
3472 A breakpoint with multiple locations is displayed in the breakpoint
3473 table using several rows---one header row, followed by one row for
3474 each breakpoint location. The header row has @samp{<MULTIPLE>} in the
3475 address column. The rows for individual locations contain the actual
3476 addresses for locations, and show the functions to which those
3477 locations belong. The number column for a location is of the form
3478 @var{breakpoint-number}.@var{location-number}.
3479
3480 For example:
3481
3482 @smallexample
3483 Num Type Disp Enb Address What
3484 1 breakpoint keep y <MULTIPLE>
3485 stop only if i==1
3486 breakpoint already hit 1 time
3487 1.1 y 0x080486a2 in void foo<int>() at t.cc:8
3488 1.2 y 0x080486ca in void foo<double>() at t.cc:8
3489 @end smallexample
3490
3491 Each location can be individually enabled or disabled by passing
3492 @var{breakpoint-number}.@var{location-number} as argument to the
3493 @code{enable} and @code{disable} commands. Note that you cannot
3494 delete the individual locations from the list, you can only delete the
3495 entire list of locations that belong to their parent breakpoint (with
3496 the @kbd{delete @var{num}} command, where @var{num} is the number of
3497 the parent breakpoint, 1 in the above example). Disabling or enabling
3498 the parent breakpoint (@pxref{Disabling}) affects all of the locations
3499 that belong to that breakpoint.
3500
3501 @cindex pending breakpoints
3502 It's quite common to have a breakpoint inside a shared library.
3503 Shared libraries can be loaded and unloaded explicitly,
3504 and possibly repeatedly, as the program is executed. To support
3505 this use case, @value{GDBN} updates breakpoint locations whenever
3506 any shared library is loaded or unloaded. Typically, you would
3507 set a breakpoint in a shared library at the beginning of your
3508 debugging session, when the library is not loaded, and when the
3509 symbols from the library are not available. When you try to set
3510 breakpoint, @value{GDBN} will ask you if you want to set
3511 a so called @dfn{pending breakpoint}---breakpoint whose address
3512 is not yet resolved.
3513
3514 After the program is run, whenever a new shared library is loaded,
3515 @value{GDBN} reevaluates all the breakpoints. When a newly loaded
3516 shared library contains the symbol or line referred to by some
3517 pending breakpoint, that breakpoint is resolved and becomes an
3518 ordinary breakpoint. When a library is unloaded, all breakpoints
3519 that refer to its symbols or source lines become pending again.
3520
3521 This logic works for breakpoints with multiple locations, too. For
3522 example, if you have a breakpoint in a C@t{++} template function, and
3523 a newly loaded shared library has an instantiation of that template,
3524 a new location is added to the list of locations for the breakpoint.
3525
3526 Except for having unresolved address, pending breakpoints do not
3527 differ from regular breakpoints. You can set conditions or commands,
3528 enable and disable them and perform other breakpoint operations.
3529
3530 @value{GDBN} provides some additional commands for controlling what
3531 happens when the @samp{break} command cannot resolve breakpoint
3532 address specification to an address:
3533
3534 @kindex set breakpoint pending
3535 @kindex show breakpoint pending
3536 @table @code
3537 @item set breakpoint pending auto
3538 This is the default behavior. When @value{GDBN} cannot find the breakpoint
3539 location, it queries you whether a pending breakpoint should be created.
3540
3541 @item set breakpoint pending on
3542 This indicates that an unrecognized breakpoint location should automatically
3543 result in a pending breakpoint being created.
3544
3545 @item set breakpoint pending off
3546 This indicates that pending breakpoints are not to be created. Any
3547 unrecognized breakpoint location results in an error. This setting does
3548 not affect any pending breakpoints previously created.
3549
3550 @item show breakpoint pending
3551 Show the current behavior setting for creating pending breakpoints.
3552 @end table
3553
3554 The settings above only affect the @code{break} command and its
3555 variants. Once breakpoint is set, it will be automatically updated
3556 as shared libraries are loaded and unloaded.
3557
3558 @cindex automatic hardware breakpoints
3559 For some targets, @value{GDBN} can automatically decide if hardware or
3560 software breakpoints should be used, depending on whether the
3561 breakpoint address is read-only or read-write. This applies to
3562 breakpoints set with the @code{break} command as well as to internal
3563 breakpoints set by commands like @code{next} and @code{finish}. For
3564 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
3565 breakpoints.
3566
3567 You can control this automatic behaviour with the following commands::
3568
3569 @kindex set breakpoint auto-hw
3570 @kindex show breakpoint auto-hw
3571 @table @code
3572 @item set breakpoint auto-hw on
3573 This is the default behavior. When @value{GDBN} sets a breakpoint, it
3574 will try to use the target memory map to decide if software or hardware
3575 breakpoint must be used.
3576
3577 @item set breakpoint auto-hw off
3578 This indicates @value{GDBN} should not automatically select breakpoint
3579 type. If the target provides a memory map, @value{GDBN} will warn when
3580 trying to set software breakpoint at a read-only address.
3581 @end table
3582
3583 @value{GDBN} normally implements breakpoints by replacing the program code
3584 at the breakpoint address with a special instruction, which, when
3585 executed, given control to the debugger. By default, the program
3586 code is so modified only when the program is resumed. As soon as
3587 the program stops, @value{GDBN} restores the original instructions. This
3588 behaviour guards against leaving breakpoints inserted in the
3589 target should gdb abrubptly disconnect. However, with slow remote
3590 targets, inserting and removing breakpoint can reduce the performance.
3591 This behavior can be controlled with the following commands::
3592
3593 @kindex set breakpoint always-inserted
3594 @kindex show breakpoint always-inserted
3595 @table @code
3596 @item set breakpoint always-inserted off
3597 All breakpoints, including newly added by the user, are inserted in
3598 the target only when the target is resumed. All breakpoints are
3599 removed from the target when it stops.
3600
3601 @item set breakpoint always-inserted on
3602 Causes all breakpoints to be inserted in the target at all times. If
3603 the user adds a new breakpoint, or changes an existing breakpoint, the
3604 breakpoints in the target are updated immediately. A breakpoint is
3605 removed from the target only when breakpoint itself is removed.
3606
3607 @cindex non-stop mode, and @code{breakpoint always-inserted}
3608 @item set breakpoint always-inserted auto
3609 This is the default mode. If @value{GDBN} is controlling the inferior
3610 in non-stop mode (@pxref{Non-Stop Mode}), gdb behaves as if
3611 @code{breakpoint always-inserted} mode is on. If @value{GDBN} is
3612 controlling the inferior in all-stop mode, @value{GDBN} behaves as if
3613 @code{breakpoint always-inserted} mode is off.
3614 @end table
3615
3616 @cindex negative breakpoint numbers
3617 @cindex internal @value{GDBN} breakpoints
3618 @value{GDBN} itself sometimes sets breakpoints in your program for
3619 special purposes, such as proper handling of @code{longjmp} (in C
3620 programs). These internal breakpoints are assigned negative numbers,
3621 starting with @code{-1}; @samp{info breakpoints} does not display them.
3622 You can see these breakpoints with the @value{GDBN} maintenance command
3623 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
3624
3625
3626 @node Set Watchpoints
3627 @subsection Setting Watchpoints
3628
3629 @cindex setting watchpoints
3630 You can use a watchpoint to stop execution whenever the value of an
3631 expression changes, without having to predict a particular place where
3632 this may happen. (This is sometimes called a @dfn{data breakpoint}.)
3633 The expression may be as simple as the value of a single variable, or
3634 as complex as many variables combined by operators. Examples include:
3635
3636 @itemize @bullet
3637 @item
3638 A reference to the value of a single variable.
3639
3640 @item
3641 An address cast to an appropriate data type. For example,
3642 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3643 address (assuming an @code{int} occupies 4 bytes).
3644
3645 @item
3646 An arbitrarily complex expression, such as @samp{a*b + c/d}. The
3647 expression can use any operators valid in the program's native
3648 language (@pxref{Languages}).
3649 @end itemize
3650
3651 You can set a watchpoint on an expression even if the expression can
3652 not be evaluated yet. For instance, you can set a watchpoint on
3653 @samp{*global_ptr} before @samp{global_ptr} is initialized.
3654 @value{GDBN} will stop when your program sets @samp{global_ptr} and
3655 the expression produces a valid value. If the expression becomes
3656 valid in some other way than changing a variable (e.g.@: if the memory
3657 pointed to by @samp{*global_ptr} becomes readable as the result of a
3658 @code{malloc} call), @value{GDBN} may not stop until the next time
3659 the expression changes.
3660
3661 @cindex software watchpoints
3662 @cindex hardware watchpoints
3663 Depending on your system, watchpoints may be implemented in software or
3664 hardware. @value{GDBN} does software watchpointing by single-stepping your
3665 program and testing the variable's value each time, which is hundreds of
3666 times slower than normal execution. (But this may still be worth it, to
3667 catch errors where you have no clue what part of your program is the
3668 culprit.)
3669
3670 On some systems, such as HP-UX, PowerPC, @sc{gnu}/Linux and most other
3671 x86-based targets, @value{GDBN} includes support for hardware
3672 watchpoints, which do not slow down the running of your program.
3673
3674 @table @code
3675 @kindex watch
3676 @item watch @var{expr} @r{[}thread @var{threadnum}@r{]}
3677 Set a watchpoint for an expression. @value{GDBN} will break when the
3678 expression @var{expr} is written into by the program and its value
3679 changes. The simplest (and the most popular) use of this command is
3680 to watch the value of a single variable:
3681
3682 @smallexample
3683 (@value{GDBP}) watch foo
3684 @end smallexample
3685
3686 If the command includes a @code{@r{[}thread @var{threadnum}@r{]}}
3687 clause, @value{GDBN} breaks only when the thread identified by
3688 @var{threadnum} changes the value of @var{expr}. If any other threads
3689 change the value of @var{expr}, @value{GDBN} will not break. Note
3690 that watchpoints restricted to a single thread in this way only work
3691 with Hardware Watchpoints.
3692
3693 @kindex rwatch
3694 @item rwatch @var{expr} @r{[}thread @var{threadnum}@r{]}
3695 Set a watchpoint that will break when the value of @var{expr} is read
3696 by the program.
3697
3698 @kindex awatch
3699 @item awatch @var{expr} @r{[}thread @var{threadnum}@r{]}
3700 Set a watchpoint that will break when @var{expr} is either read from
3701 or written into by the program.
3702
3703 @kindex info watchpoints @r{[}@var{n}@r{]}
3704 @item info watchpoints
3705 This command prints a list of watchpoints, breakpoints, and catchpoints;
3706 it is the same as @code{info break} (@pxref{Set Breaks}).
3707 @end table
3708
3709 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3710 watchpoints execute very quickly, and the debugger reports a change in
3711 value at the exact instruction where the change occurs. If @value{GDBN}
3712 cannot set a hardware watchpoint, it sets a software watchpoint, which
3713 executes more slowly and reports the change in value at the next
3714 @emph{statement}, not the instruction, after the change occurs.
3715
3716 @cindex use only software watchpoints
3717 You can force @value{GDBN} to use only software watchpoints with the
3718 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3719 zero, @value{GDBN} will never try to use hardware watchpoints, even if
3720 the underlying system supports them. (Note that hardware-assisted
3721 watchpoints that were set @emph{before} setting
3722 @code{can-use-hw-watchpoints} to zero will still use the hardware
3723 mechanism of watching expression values.)
3724
3725 @table @code
3726 @item set can-use-hw-watchpoints
3727 @kindex set can-use-hw-watchpoints
3728 Set whether or not to use hardware watchpoints.
3729
3730 @item show can-use-hw-watchpoints
3731 @kindex show can-use-hw-watchpoints
3732 Show the current mode of using hardware watchpoints.
3733 @end table
3734
3735 For remote targets, you can restrict the number of hardware
3736 watchpoints @value{GDBN} will use, see @ref{set remote
3737 hardware-breakpoint-limit}.
3738
3739 When you issue the @code{watch} command, @value{GDBN} reports
3740
3741 @smallexample
3742 Hardware watchpoint @var{num}: @var{expr}
3743 @end smallexample
3744
3745 @noindent
3746 if it was able to set a hardware watchpoint.
3747
3748 Currently, the @code{awatch} and @code{rwatch} commands can only set
3749 hardware watchpoints, because accesses to data that don't change the
3750 value of the watched expression cannot be detected without examining
3751 every instruction as it is being executed, and @value{GDBN} does not do
3752 that currently. If @value{GDBN} finds that it is unable to set a
3753 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3754 will print a message like this:
3755
3756 @smallexample
3757 Expression cannot be implemented with read/access watchpoint.
3758 @end smallexample
3759
3760 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3761 data type of the watched expression is wider than what a hardware
3762 watchpoint on the target machine can handle. For example, some systems
3763 can only watch regions that are up to 4 bytes wide; on such systems you
3764 cannot set hardware watchpoints for an expression that yields a
3765 double-precision floating-point number (which is typically 8 bytes
3766 wide). As a work-around, it might be possible to break the large region
3767 into a series of smaller ones and watch them with separate watchpoints.
3768
3769 If you set too many hardware watchpoints, @value{GDBN} might be unable
3770 to insert all of them when you resume the execution of your program.
3771 Since the precise number of active watchpoints is unknown until such
3772 time as the program is about to be resumed, @value{GDBN} might not be
3773 able to warn you about this when you set the watchpoints, and the
3774 warning will be printed only when the program is resumed:
3775
3776 @smallexample
3777 Hardware watchpoint @var{num}: Could not insert watchpoint
3778 @end smallexample
3779
3780 @noindent
3781 If this happens, delete or disable some of the watchpoints.
3782
3783 Watching complex expressions that reference many variables can also
3784 exhaust the resources available for hardware-assisted watchpoints.
3785 That's because @value{GDBN} needs to watch every variable in the
3786 expression with separately allocated resources.
3787
3788 If you call a function interactively using @code{print} or @code{call},
3789 any watchpoints you have set will be inactive until @value{GDBN} reaches another
3790 kind of breakpoint or the call completes.
3791
3792 @value{GDBN} automatically deletes watchpoints that watch local
3793 (automatic) variables, or expressions that involve such variables, when
3794 they go out of scope, that is, when the execution leaves the block in
3795 which these variables were defined. In particular, when the program
3796 being debugged terminates, @emph{all} local variables go out of scope,
3797 and so only watchpoints that watch global variables remain set. If you
3798 rerun the program, you will need to set all such watchpoints again. One
3799 way of doing that would be to set a code breakpoint at the entry to the
3800 @code{main} function and when it breaks, set all the watchpoints.
3801
3802 @cindex watchpoints and threads
3803 @cindex threads and watchpoints
3804 In multi-threaded programs, watchpoints will detect changes to the
3805 watched expression from every thread.
3806
3807 @quotation
3808 @emph{Warning:} In multi-threaded programs, software watchpoints
3809 have only limited usefulness. If @value{GDBN} creates a software
3810 watchpoint, it can only watch the value of an expression @emph{in a
3811 single thread}. If you are confident that the expression can only
3812 change due to the current thread's activity (and if you are also
3813 confident that no other thread can become current), then you can use
3814 software watchpoints as usual. However, @value{GDBN} may not notice
3815 when a non-current thread's activity changes the expression. (Hardware
3816 watchpoints, in contrast, watch an expression in all threads.)
3817 @end quotation
3818
3819 @xref{set remote hardware-watchpoint-limit}.
3820
3821 @node Set Catchpoints
3822 @subsection Setting Catchpoints
3823 @cindex catchpoints, setting
3824 @cindex exception handlers
3825 @cindex event handling
3826
3827 You can use @dfn{catchpoints} to cause the debugger to stop for certain
3828 kinds of program events, such as C@t{++} exceptions or the loading of a
3829 shared library. Use the @code{catch} command to set a catchpoint.
3830
3831 @table @code
3832 @kindex catch
3833 @item catch @var{event}
3834 Stop when @var{event} occurs. @var{event} can be any of the following:
3835 @table @code
3836 @item throw
3837 @cindex stop on C@t{++} exceptions
3838 The throwing of a C@t{++} exception.
3839
3840 @item catch
3841 The catching of a C@t{++} exception.
3842
3843 @item exception
3844 @cindex Ada exception catching
3845 @cindex catch Ada exceptions
3846 An Ada exception being raised. If an exception name is specified
3847 at the end of the command (eg @code{catch exception Program_Error}),
3848 the debugger will stop only when this specific exception is raised.
3849 Otherwise, the debugger stops execution when any Ada exception is raised.
3850
3851 When inserting an exception catchpoint on a user-defined exception whose
3852 name is identical to one of the exceptions defined by the language, the
3853 fully qualified name must be used as the exception name. Otherwise,
3854 @value{GDBN} will assume that it should stop on the pre-defined exception
3855 rather than the user-defined one. For instance, assuming an exception
3856 called @code{Constraint_Error} is defined in package @code{Pck}, then
3857 the command to use to catch such exceptions is @kbd{catch exception
3858 Pck.Constraint_Error}.
3859
3860 @item exception unhandled
3861 An exception that was raised but is not handled by the program.
3862
3863 @item assert
3864 A failed Ada assertion.
3865
3866 @item exec
3867 @cindex break on fork/exec
3868 A call to @code{exec}. This is currently only available for HP-UX
3869 and @sc{gnu}/Linux.
3870
3871 @item syscall
3872 @itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @r{...}
3873 @cindex break on a system call.
3874 A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
3875 syscall is a mechanism for application programs to request a service
3876 from the operating system (OS) or one of the OS system services.
3877 @value{GDBN} can catch some or all of the syscalls issued by the
3878 debuggee, and show the related information for each syscall. If no
3879 argument is specified, calls to and returns from all system calls
3880 will be caught.
3881
3882 @var{name} can be any system call name that is valid for the
3883 underlying OS. Just what syscalls are valid depends on the OS. On
3884 GNU and Unix systems, you can find the full list of valid syscall
3885 names on @file{/usr/include/asm/unistd.h}.
3886
3887 @c For MS-Windows, the syscall names and the corresponding numbers
3888 @c can be found, e.g., on this URL:
3889 @c http://www.metasploit.com/users/opcode/syscalls.html
3890 @c but we don't support Windows syscalls yet.
3891
3892 Normally, @value{GDBN} knows in advance which syscalls are valid for
3893 each OS, so you can use the @value{GDBN} command-line completion
3894 facilities (@pxref{Completion,, command completion}) to list the
3895 available choices.
3896
3897 You may also specify the system call numerically. A syscall's
3898 number is the value passed to the OS's syscall dispatcher to
3899 identify the requested service. When you specify the syscall by its
3900 name, @value{GDBN} uses its database of syscalls to convert the name
3901 into the corresponding numeric code, but using the number directly
3902 may be useful if @value{GDBN}'s database does not have the complete
3903 list of syscalls on your system (e.g., because @value{GDBN} lags
3904 behind the OS upgrades).
3905
3906 The example below illustrates how this command works if you don't provide
3907 arguments to it:
3908
3909 @smallexample
3910 (@value{GDBP}) catch syscall
3911 Catchpoint 1 (syscall)
3912 (@value{GDBP}) r
3913 Starting program: /tmp/catch-syscall
3914
3915 Catchpoint 1 (call to syscall 'close'), \
3916 0xffffe424 in __kernel_vsyscall ()
3917 (@value{GDBP}) c
3918 Continuing.
3919
3920 Catchpoint 1 (returned from syscall 'close'), \
3921 0xffffe424 in __kernel_vsyscall ()
3922 (@value{GDBP})
3923 @end smallexample
3924
3925 Here is an example of catching a system call by name:
3926
3927 @smallexample
3928 (@value{GDBP}) catch syscall chroot
3929 Catchpoint 1 (syscall 'chroot' [61])
3930 (@value{GDBP}) r
3931 Starting program: /tmp/catch-syscall
3932
3933 Catchpoint 1 (call to syscall 'chroot'), \
3934 0xffffe424 in __kernel_vsyscall ()
3935 (@value{GDBP}) c
3936 Continuing.
3937
3938 Catchpoint 1 (returned from syscall 'chroot'), \
3939 0xffffe424 in __kernel_vsyscall ()
3940 (@value{GDBP})
3941 @end smallexample
3942
3943 An example of specifying a system call numerically. In the case
3944 below, the syscall number has a corresponding entry in the XML
3945 file, so @value{GDBN} finds its name and prints it:
3946
3947 @smallexample
3948 (@value{GDBP}) catch syscall 252
3949 Catchpoint 1 (syscall(s) 'exit_group')
3950 (@value{GDBP}) r
3951 Starting program: /tmp/catch-syscall
3952
3953 Catchpoint 1 (call to syscall 'exit_group'), \
3954 0xffffe424 in __kernel_vsyscall ()
3955 (@value{GDBP}) c
3956 Continuing.
3957
3958 Program exited normally.
3959 (@value{GDBP})
3960 @end smallexample
3961
3962 However, there can be situations when there is no corresponding name
3963 in XML file for that syscall number. In this case, @value{GDBN} prints
3964 a warning message saying that it was not able to find the syscall name,
3965 but the catchpoint will be set anyway. See the example below:
3966
3967 @smallexample
3968 (@value{GDBP}) catch syscall 764
3969 warning: The number '764' does not represent a known syscall.
3970 Catchpoint 2 (syscall 764)
3971 (@value{GDBP})
3972 @end smallexample
3973
3974 If you configure @value{GDBN} using the @samp{--without-expat} option,
3975 it will not be able to display syscall names. Also, if your
3976 architecture does not have an XML file describing its system calls,
3977 you will not be able to see the syscall names. It is important to
3978 notice that these two features are used for accessing the syscall
3979 name database. In either case, you will see a warning like this:
3980
3981 @smallexample
3982 (@value{GDBP}) catch syscall
3983 warning: Could not open "syscalls/i386-linux.xml"
3984 warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
3985 GDB will not be able to display syscall names.
3986 Catchpoint 1 (syscall)
3987 (@value{GDBP})
3988 @end smallexample
3989
3990 Of course, the file name will change depending on your architecture and system.
3991
3992 Still using the example above, you can also try to catch a syscall by its
3993 number. In this case, you would see something like:
3994
3995 @smallexample
3996 (@value{GDBP}) catch syscall 252
3997 Catchpoint 1 (syscall(s) 252)
3998 @end smallexample
3999
4000 Again, in this case @value{GDBN} would not be able to display syscall's names.
4001
4002 @item fork
4003 A call to @code{fork}. This is currently only available for HP-UX
4004 and @sc{gnu}/Linux.
4005
4006 @item vfork
4007 A call to @code{vfork}. This is currently only available for HP-UX
4008 and @sc{gnu}/Linux.
4009
4010 @end table
4011
4012 @item tcatch @var{event}
4013 Set a catchpoint that is enabled only for one stop. The catchpoint is
4014 automatically deleted after the first time the event is caught.
4015
4016 @end table
4017
4018 Use the @code{info break} command to list the current catchpoints.
4019
4020 There are currently some limitations to C@t{++} exception handling
4021 (@code{catch throw} and @code{catch catch}) in @value{GDBN}:
4022
4023 @itemize @bullet
4024 @item
4025 If you call a function interactively, @value{GDBN} normally returns
4026 control to you when the function has finished executing. If the call
4027 raises an exception, however, the call may bypass the mechanism that
4028 returns control to you and cause your program either to abort or to
4029 simply continue running until it hits a breakpoint, catches a signal
4030 that @value{GDBN} is listening for, or exits. This is the case even if
4031 you set a catchpoint for the exception; catchpoints on exceptions are
4032 disabled within interactive calls.
4033
4034 @item
4035 You cannot raise an exception interactively.
4036
4037 @item
4038 You cannot install an exception handler interactively.
4039 @end itemize
4040
4041 @cindex raise exceptions
4042 Sometimes @code{catch} is not the best way to debug exception handling:
4043 if you need to know exactly where an exception is raised, it is better to
4044 stop @emph{before} the exception handler is called, since that way you
4045 can see the stack before any unwinding takes place. If you set a
4046 breakpoint in an exception handler instead, it may not be easy to find
4047 out where the exception was raised.
4048
4049 To stop just before an exception handler is called, you need some
4050 knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
4051 raised by calling a library function named @code{__raise_exception}
4052 which has the following ANSI C interface:
4053
4054 @smallexample
4055 /* @var{addr} is where the exception identifier is stored.
4056 @var{id} is the exception identifier. */
4057 void __raise_exception (void **addr, void *id);
4058 @end smallexample
4059
4060 @noindent
4061 To make the debugger catch all exceptions before any stack
4062 unwinding takes place, set a breakpoint on @code{__raise_exception}
4063 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Exceptions}).
4064
4065 With a conditional breakpoint (@pxref{Conditions, ,Break Conditions})
4066 that depends on the value of @var{id}, you can stop your program when
4067 a specific exception is raised. You can use multiple conditional
4068 breakpoints to stop your program when any of a number of exceptions are
4069 raised.
4070
4071
4072 @node Delete Breaks
4073 @subsection Deleting Breakpoints
4074
4075 @cindex clearing breakpoints, watchpoints, catchpoints
4076 @cindex deleting breakpoints, watchpoints, catchpoints
4077 It is often necessary to eliminate a breakpoint, watchpoint, or
4078 catchpoint once it has done its job and you no longer want your program
4079 to stop there. This is called @dfn{deleting} the breakpoint. A
4080 breakpoint that has been deleted no longer exists; it is forgotten.
4081
4082 With the @code{clear} command you can delete breakpoints according to
4083 where they are in your program. With the @code{delete} command you can
4084 delete individual breakpoints, watchpoints, or catchpoints by specifying
4085 their breakpoint numbers.
4086
4087 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
4088 automatically ignores breakpoints on the first instruction to be executed
4089 when you continue execution without changing the execution address.
4090
4091 @table @code
4092 @kindex clear
4093 @item clear
4094 Delete any breakpoints at the next instruction to be executed in the
4095 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
4096 the innermost frame is selected, this is a good way to delete a
4097 breakpoint where your program just stopped.
4098
4099 @item clear @var{location}
4100 Delete any breakpoints set at the specified @var{location}.
4101 @xref{Specify Location}, for the various forms of @var{location}; the
4102 most useful ones are listed below:
4103
4104 @table @code
4105 @item clear @var{function}
4106 @itemx clear @var{filename}:@var{function}
4107 Delete any breakpoints set at entry to the named @var{function}.
4108
4109 @item clear @var{linenum}
4110 @itemx clear @var{filename}:@var{linenum}
4111 Delete any breakpoints set at or within the code of the specified
4112 @var{linenum} of the specified @var{filename}.
4113 @end table
4114
4115 @cindex delete breakpoints
4116 @kindex delete
4117 @kindex d @r{(@code{delete})}
4118 @item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4119 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
4120 ranges specified as arguments. If no argument is specified, delete all
4121 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
4122 confirm off}). You can abbreviate this command as @code{d}.
4123 @end table
4124
4125 @node Disabling
4126 @subsection Disabling Breakpoints
4127
4128 @cindex enable/disable a breakpoint
4129 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
4130 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
4131 it had been deleted, but remembers the information on the breakpoint so
4132 that you can @dfn{enable} it again later.
4133
4134 You disable and enable breakpoints, watchpoints, and catchpoints with
4135 the @code{enable} and @code{disable} commands, optionally specifying one
4136 or more breakpoint numbers as arguments. Use @code{info break} or
4137 @code{info watch} to print a list of breakpoints, watchpoints, and
4138 catchpoints if you do not know which numbers to use.
4139
4140 Disabling and enabling a breakpoint that has multiple locations
4141 affects all of its locations.
4142
4143 A breakpoint, watchpoint, or catchpoint can have any of four different
4144 states of enablement:
4145
4146 @itemize @bullet
4147 @item
4148 Enabled. The breakpoint stops your program. A breakpoint set
4149 with the @code{break} command starts out in this state.
4150 @item
4151 Disabled. The breakpoint has no effect on your program.
4152 @item
4153 Enabled once. The breakpoint stops your program, but then becomes
4154 disabled.
4155 @item
4156 Enabled for deletion. The breakpoint stops your program, but
4157 immediately after it does so it is deleted permanently. A breakpoint
4158 set with the @code{tbreak} command starts out in this state.
4159 @end itemize
4160
4161 You can use the following commands to enable or disable breakpoints,
4162 watchpoints, and catchpoints:
4163
4164 @table @code
4165 @kindex disable
4166 @kindex dis @r{(@code{disable})}
4167 @item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4168 Disable the specified breakpoints---or all breakpoints, if none are
4169 listed. A disabled breakpoint has no effect but is not forgotten. All
4170 options such as ignore-counts, conditions and commands are remembered in
4171 case the breakpoint is enabled again later. You may abbreviate
4172 @code{disable} as @code{dis}.
4173
4174 @kindex enable
4175 @item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
4176 Enable the specified breakpoints (or all defined breakpoints). They
4177 become effective once again in stopping your program.
4178
4179 @item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
4180 Enable the specified breakpoints temporarily. @value{GDBN} disables any
4181 of these breakpoints immediately after stopping your program.
4182
4183 @item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
4184 Enable the specified breakpoints to work once, then die. @value{GDBN}
4185 deletes any of these breakpoints as soon as your program stops there.
4186 Breakpoints set by the @code{tbreak} command start out in this state.
4187 @end table
4188
4189 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
4190 @c confusing: tbreak is also initially enabled.
4191 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
4192 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
4193 subsequently, they become disabled or enabled only when you use one of
4194 the commands above. (The command @code{until} can set and delete a
4195 breakpoint of its own, but it does not change the state of your other
4196 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
4197 Stepping}.)
4198
4199 @node Conditions
4200 @subsection Break Conditions
4201 @cindex conditional breakpoints
4202 @cindex breakpoint conditions
4203
4204 @c FIXME what is scope of break condition expr? Context where wanted?
4205 @c in particular for a watchpoint?
4206 The simplest sort of breakpoint breaks every time your program reaches a
4207 specified place. You can also specify a @dfn{condition} for a
4208 breakpoint. A condition is just a Boolean expression in your
4209 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
4210 a condition evaluates the expression each time your program reaches it,
4211 and your program stops only if the condition is @emph{true}.
4212
4213 This is the converse of using assertions for program validation; in that
4214 situation, you want to stop when the assertion is violated---that is,
4215 when the condition is false. In C, if you want to test an assertion expressed
4216 by the condition @var{assert}, you should set the condition
4217 @samp{! @var{assert}} on the appropriate breakpoint.
4218
4219 Conditions are also accepted for watchpoints; you may not need them,
4220 since a watchpoint is inspecting the value of an expression anyhow---but
4221 it might be simpler, say, to just set a watchpoint on a variable name,
4222 and specify a condition that tests whether the new value is an interesting
4223 one.
4224
4225 Break conditions can have side effects, and may even call functions in
4226 your program. This can be useful, for example, to activate functions
4227 that log program progress, or to use your own print functions to
4228 format special data structures. The effects are completely predictable
4229 unless there is another enabled breakpoint at the same address. (In
4230 that case, @value{GDBN} might see the other breakpoint first and stop your
4231 program without checking the condition of this one.) Note that
4232 breakpoint commands are usually more convenient and flexible than break
4233 conditions for the
4234 purpose of performing side effects when a breakpoint is reached
4235 (@pxref{Break Commands, ,Breakpoint Command Lists}).
4236
4237 Break conditions can be specified when a breakpoint is set, by using
4238 @samp{if} in the arguments to the @code{break} command. @xref{Set
4239 Breaks, ,Setting Breakpoints}. They can also be changed at any time
4240 with the @code{condition} command.
4241
4242 You can also use the @code{if} keyword with the @code{watch} command.
4243 The @code{catch} command does not recognize the @code{if} keyword;
4244 @code{condition} is the only way to impose a further condition on a
4245 catchpoint.
4246
4247 @table @code
4248 @kindex condition
4249 @item condition @var{bnum} @var{expression}
4250 Specify @var{expression} as the break condition for breakpoint,
4251 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
4252 breakpoint @var{bnum} stops your program only if the value of
4253 @var{expression} is true (nonzero, in C). When you use
4254 @code{condition}, @value{GDBN} checks @var{expression} immediately for
4255 syntactic correctness, and to determine whether symbols in it have
4256 referents in the context of your breakpoint. If @var{expression} uses
4257 symbols not referenced in the context of the breakpoint, @value{GDBN}
4258 prints an error message:
4259
4260 @smallexample
4261 No symbol "foo" in current context.
4262 @end smallexample
4263
4264 @noindent
4265 @value{GDBN} does
4266 not actually evaluate @var{expression} at the time the @code{condition}
4267 command (or a command that sets a breakpoint with a condition, like
4268 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
4269
4270 @item condition @var{bnum}
4271 Remove the condition from breakpoint number @var{bnum}. It becomes
4272 an ordinary unconditional breakpoint.
4273 @end table
4274
4275 @cindex ignore count (of breakpoint)
4276 A special case of a breakpoint condition is to stop only when the
4277 breakpoint has been reached a certain number of times. This is so
4278 useful that there is a special way to do it, using the @dfn{ignore
4279 count} of the breakpoint. Every breakpoint has an ignore count, which
4280 is an integer. Most of the time, the ignore count is zero, and
4281 therefore has no effect. But if your program reaches a breakpoint whose
4282 ignore count is positive, then instead of stopping, it just decrements
4283 the ignore count by one and continues. As a result, if the ignore count
4284 value is @var{n}, the breakpoint does not stop the next @var{n} times
4285 your program reaches it.
4286
4287 @table @code
4288 @kindex ignore
4289 @item ignore @var{bnum} @var{count}
4290 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
4291 The next @var{count} times the breakpoint is reached, your program's
4292 execution does not stop; other than to decrement the ignore count, @value{GDBN}
4293 takes no action.
4294
4295 To make the breakpoint stop the next time it is reached, specify
4296 a count of zero.
4297
4298 When you use @code{continue} to resume execution of your program from a
4299 breakpoint, you can specify an ignore count directly as an argument to
4300 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
4301 Stepping,,Continuing and Stepping}.
4302
4303 If a breakpoint has a positive ignore count and a condition, the
4304 condition is not checked. Once the ignore count reaches zero,
4305 @value{GDBN} resumes checking the condition.
4306
4307 You could achieve the effect of the ignore count with a condition such
4308 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
4309 is decremented each time. @xref{Convenience Vars, ,Convenience
4310 Variables}.
4311 @end table
4312
4313 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
4314
4315
4316 @node Break Commands
4317 @subsection Breakpoint Command Lists
4318
4319 @cindex breakpoint commands
4320 You can give any breakpoint (or watchpoint or catchpoint) a series of
4321 commands to execute when your program stops due to that breakpoint. For
4322 example, you might want to print the values of certain expressions, or
4323 enable other breakpoints.
4324
4325 @table @code
4326 @kindex commands
4327 @kindex end@r{ (breakpoint commands)}
4328 @item commands @r{[}@var{bnum}@r{]}
4329 @itemx @dots{} @var{command-list} @dots{}
4330 @itemx end
4331 Specify a list of commands for breakpoint number @var{bnum}. The commands
4332 themselves appear on the following lines. Type a line containing just
4333 @code{end} to terminate the commands.
4334
4335 To remove all commands from a breakpoint, type @code{commands} and
4336 follow it immediately with @code{end}; that is, give no commands.
4337
4338 With no @var{bnum} argument, @code{commands} refers to the last
4339 breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
4340 recently encountered).
4341 @end table
4342
4343 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
4344 disabled within a @var{command-list}.
4345
4346 You can use breakpoint commands to start your program up again. Simply
4347 use the @code{continue} command, or @code{step}, or any other command
4348 that resumes execution.
4349
4350 Any other commands in the command list, after a command that resumes
4351 execution, are ignored. This is because any time you resume execution
4352 (even with a simple @code{next} or @code{step}), you may encounter
4353 another breakpoint---which could have its own command list, leading to
4354 ambiguities about which list to execute.
4355
4356 @kindex silent
4357 If the first command you specify in a command list is @code{silent}, the
4358 usual message about stopping at a breakpoint is not printed. This may
4359 be desirable for breakpoints that are to print a specific message and
4360 then continue. If none of the remaining commands print anything, you
4361 see no sign that the breakpoint was reached. @code{silent} is
4362 meaningful only at the beginning of a breakpoint command list.
4363
4364 The commands @code{echo}, @code{output}, and @code{printf} allow you to
4365 print precisely controlled output, and are often useful in silent
4366 breakpoints. @xref{Output, ,Commands for Controlled Output}.
4367
4368 For example, here is how you could use breakpoint commands to print the
4369 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
4370
4371 @smallexample
4372 break foo if x>0
4373 commands
4374 silent
4375 printf "x is %d\n",x
4376 cont
4377 end
4378 @end smallexample
4379
4380 One application for breakpoint commands is to compensate for one bug so
4381 you can test for another. Put a breakpoint just after the erroneous line
4382 of code, give it a condition to detect the case in which something
4383 erroneous has been done, and give it commands to assign correct values
4384 to any variables that need them. End with the @code{continue} command
4385 so that your program does not stop, and start with the @code{silent}
4386 command so that no output is produced. Here is an example:
4387
4388 @smallexample
4389 break 403
4390 commands
4391 silent
4392 set x = y + 4
4393 cont
4394 end
4395 @end smallexample
4396
4397 @c @ifclear BARETARGET
4398 @node Error in Breakpoints
4399 @subsection ``Cannot insert breakpoints''
4400
4401 If you request too many active hardware-assisted breakpoints and
4402 watchpoints, you will see this error message:
4403
4404 @c FIXME: the precise wording of this message may change; the relevant
4405 @c source change is not committed yet (Sep 3, 1999).
4406 @smallexample
4407 Stopped; cannot insert breakpoints.
4408 You may have requested too many hardware breakpoints and watchpoints.
4409 @end smallexample
4410
4411 @noindent
4412 This message is printed when you attempt to resume the program, since
4413 only then @value{GDBN} knows exactly how many hardware breakpoints and
4414 watchpoints it needs to insert.
4415
4416 When this message is printed, you need to disable or remove some of the
4417 hardware-assisted breakpoints and watchpoints, and then continue.
4418
4419 @node Breakpoint-related Warnings
4420 @subsection ``Breakpoint address adjusted...''
4421 @cindex breakpoint address adjusted
4422
4423 Some processor architectures place constraints on the addresses at
4424 which breakpoints may be placed. For architectures thus constrained,
4425 @value{GDBN} will attempt to adjust the breakpoint's address to comply
4426 with the constraints dictated by the architecture.
4427
4428 One example of such an architecture is the Fujitsu FR-V. The FR-V is
4429 a VLIW architecture in which a number of RISC-like instructions may be
4430 bundled together for parallel execution. The FR-V architecture
4431 constrains the location of a breakpoint instruction within such a
4432 bundle to the instruction with the lowest address. @value{GDBN}
4433 honors this constraint by adjusting a breakpoint's address to the
4434 first in the bundle.
4435
4436 It is not uncommon for optimized code to have bundles which contain
4437 instructions from different source statements, thus it may happen that
4438 a breakpoint's address will be adjusted from one source statement to
4439 another. Since this adjustment may significantly alter @value{GDBN}'s
4440 breakpoint related behavior from what the user expects, a warning is
4441 printed when the breakpoint is first set and also when the breakpoint
4442 is hit.
4443
4444 A warning like the one below is printed when setting a breakpoint
4445 that's been subject to address adjustment:
4446
4447 @smallexample
4448 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
4449 @end smallexample
4450
4451 Such warnings are printed both for user settable and @value{GDBN}'s
4452 internal breakpoints. If you see one of these warnings, you should
4453 verify that a breakpoint set at the adjusted address will have the
4454 desired affect. If not, the breakpoint in question may be removed and
4455 other breakpoints may be set which will have the desired behavior.
4456 E.g., it may be sufficient to place the breakpoint at a later
4457 instruction. A conditional breakpoint may also be useful in some
4458 cases to prevent the breakpoint from triggering too often.
4459
4460 @value{GDBN} will also issue a warning when stopping at one of these
4461 adjusted breakpoints:
4462
4463 @smallexample
4464 warning: Breakpoint 1 address previously adjusted from 0x00010414
4465 to 0x00010410.
4466 @end smallexample
4467
4468 When this warning is encountered, it may be too late to take remedial
4469 action except in cases where the breakpoint is hit earlier or more
4470 frequently than expected.
4471
4472 @node Continuing and Stepping
4473 @section Continuing and Stepping
4474
4475 @cindex stepping
4476 @cindex continuing
4477 @cindex resuming execution
4478 @dfn{Continuing} means resuming program execution until your program
4479 completes normally. In contrast, @dfn{stepping} means executing just
4480 one more ``step'' of your program, where ``step'' may mean either one
4481 line of source code, or one machine instruction (depending on what
4482 particular command you use). Either when continuing or when stepping,
4483 your program may stop even sooner, due to a breakpoint or a signal. (If
4484 it stops due to a signal, you may want to use @code{handle}, or use
4485 @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
4486
4487 @table @code
4488 @kindex continue
4489 @kindex c @r{(@code{continue})}
4490 @kindex fg @r{(resume foreground execution)}
4491 @item continue @r{[}@var{ignore-count}@r{]}
4492 @itemx c @r{[}@var{ignore-count}@r{]}
4493 @itemx fg @r{[}@var{ignore-count}@r{]}
4494 Resume program execution, at the address where your program last stopped;
4495 any breakpoints set at that address are bypassed. The optional argument
4496 @var{ignore-count} allows you to specify a further number of times to
4497 ignore a breakpoint at this location; its effect is like that of
4498 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
4499
4500 The argument @var{ignore-count} is meaningful only when your program
4501 stopped due to a breakpoint. At other times, the argument to
4502 @code{continue} is ignored.
4503
4504 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
4505 debugged program is deemed to be the foreground program) are provided
4506 purely for convenience, and have exactly the same behavior as
4507 @code{continue}.
4508 @end table
4509
4510 To resume execution at a different place, you can use @code{return}
4511 (@pxref{Returning, ,Returning from a Function}) to go back to the
4512 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
4513 Different Address}) to go to an arbitrary location in your program.
4514
4515 A typical technique for using stepping is to set a breakpoint
4516 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
4517 beginning of the function or the section of your program where a problem
4518 is believed to lie, run your program until it stops at that breakpoint,
4519 and then step through the suspect area, examining the variables that are
4520 interesting, until you see the problem happen.
4521
4522 @table @code
4523 @kindex step
4524 @kindex s @r{(@code{step})}
4525 @item step
4526 Continue running your program until control reaches a different source
4527 line, then stop it and return control to @value{GDBN}. This command is
4528 abbreviated @code{s}.
4529
4530 @quotation
4531 @c "without debugging information" is imprecise; actually "without line
4532 @c numbers in the debugging information". (gcc -g1 has debugging info but
4533 @c not line numbers). But it seems complex to try to make that
4534 @c distinction here.
4535 @emph{Warning:} If you use the @code{step} command while control is
4536 within a function that was compiled without debugging information,
4537 execution proceeds until control reaches a function that does have
4538 debugging information. Likewise, it will not step into a function which
4539 is compiled without debugging information. To step through functions
4540 without debugging information, use the @code{stepi} command, described
4541 below.
4542 @end quotation
4543
4544 The @code{step} command only stops at the first instruction of a source
4545 line. This prevents the multiple stops that could otherwise occur in
4546 @code{switch} statements, @code{for} loops, etc. @code{step} continues
4547 to stop if a function that has debugging information is called within
4548 the line. In other words, @code{step} @emph{steps inside} any functions
4549 called within the line.
4550
4551 Also, the @code{step} command only enters a function if there is line
4552 number information for the function. Otherwise it acts like the
4553 @code{next} command. This avoids problems when using @code{cc -gl}
4554 on MIPS machines. Previously, @code{step} entered subroutines if there
4555 was any debugging information about the routine.
4556
4557 @item step @var{count}
4558 Continue running as in @code{step}, but do so @var{count} times. If a
4559 breakpoint is reached, or a signal not related to stepping occurs before
4560 @var{count} steps, stepping stops right away.
4561
4562 @kindex next
4563 @kindex n @r{(@code{next})}
4564 @item next @r{[}@var{count}@r{]}
4565 Continue to the next source line in the current (innermost) stack frame.
4566 This is similar to @code{step}, but function calls that appear within
4567 the line of code are executed without stopping. Execution stops when
4568 control reaches a different line of code at the original stack level
4569 that was executing when you gave the @code{next} command. This command
4570 is abbreviated @code{n}.
4571
4572 An argument @var{count} is a repeat count, as for @code{step}.
4573
4574
4575 @c FIX ME!! Do we delete this, or is there a way it fits in with
4576 @c the following paragraph? --- Vctoria
4577 @c
4578 @c @code{next} within a function that lacks debugging information acts like
4579 @c @code{step}, but any function calls appearing within the code of the
4580 @c function are executed without stopping.
4581
4582 The @code{next} command only stops at the first instruction of a
4583 source line. This prevents multiple stops that could otherwise occur in
4584 @code{switch} statements, @code{for} loops, etc.
4585
4586 @kindex set step-mode
4587 @item set step-mode
4588 @cindex functions without line info, and stepping
4589 @cindex stepping into functions with no line info
4590 @itemx set step-mode on
4591 The @code{set step-mode on} command causes the @code{step} command to
4592 stop at the first instruction of a function which contains no debug line
4593 information rather than stepping over it.
4594
4595 This is useful in cases where you may be interested in inspecting the
4596 machine instructions of a function which has no symbolic info and do not
4597 want @value{GDBN} to automatically skip over this function.
4598
4599 @item set step-mode off
4600 Causes the @code{step} command to step over any functions which contains no
4601 debug information. This is the default.
4602
4603 @item show step-mode
4604 Show whether @value{GDBN} will stop in or step over functions without
4605 source line debug information.
4606
4607 @kindex finish
4608 @kindex fin @r{(@code{finish})}
4609 @item finish
4610 Continue running until just after function in the selected stack frame
4611 returns. Print the returned value (if any). This command can be
4612 abbreviated as @code{fin}.
4613
4614 Contrast this with the @code{return} command (@pxref{Returning,
4615 ,Returning from a Function}).
4616
4617 @kindex until
4618 @kindex u @r{(@code{until})}
4619 @cindex run until specified location
4620 @item until
4621 @itemx u
4622 Continue running until a source line past the current line, in the
4623 current stack frame, is reached. This command is used to avoid single
4624 stepping through a loop more than once. It is like the @code{next}
4625 command, except that when @code{until} encounters a jump, it
4626 automatically continues execution until the program counter is greater
4627 than the address of the jump.
4628
4629 This means that when you reach the end of a loop after single stepping
4630 though it, @code{until} makes your program continue execution until it
4631 exits the loop. In contrast, a @code{next} command at the end of a loop
4632 simply steps back to the beginning of the loop, which forces you to step
4633 through the next iteration.
4634
4635 @code{until} always stops your program if it attempts to exit the current
4636 stack frame.
4637
4638 @code{until} may produce somewhat counterintuitive results if the order
4639 of machine code does not match the order of the source lines. For
4640 example, in the following excerpt from a debugging session, the @code{f}
4641 (@code{frame}) command shows that execution is stopped at line
4642 @code{206}; yet when we use @code{until}, we get to line @code{195}:
4643
4644 @smallexample
4645 (@value{GDBP}) f
4646 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
4647 206 expand_input();
4648 (@value{GDBP}) until
4649 195 for ( ; argc > 0; NEXTARG) @{
4650 @end smallexample
4651
4652 This happened because, for execution efficiency, the compiler had
4653 generated code for the loop closure test at the end, rather than the
4654 start, of the loop---even though the test in a C @code{for}-loop is
4655 written before the body of the loop. The @code{until} command appeared
4656 to step back to the beginning of the loop when it advanced to this
4657 expression; however, it has not really gone to an earlier
4658 statement---not in terms of the actual machine code.
4659
4660 @code{until} with no argument works by means of single
4661 instruction stepping, and hence is slower than @code{until} with an
4662 argument.
4663
4664 @item until @var{location}
4665 @itemx u @var{location}
4666 Continue running your program until either the specified location is
4667 reached, or the current stack frame returns. @var{location} is any of
4668 the forms described in @ref{Specify Location}.
4669 This form of the command uses temporary breakpoints, and
4670 hence is quicker than @code{until} without an argument. The specified
4671 location is actually reached only if it is in the current frame. This
4672 implies that @code{until} can be used to skip over recursive function
4673 invocations. For instance in the code below, if the current location is
4674 line @code{96}, issuing @code{until 99} will execute the program up to
4675 line @code{99} in the same invocation of factorial, i.e., after the inner
4676 invocations have returned.
4677
4678 @smallexample
4679 94 int factorial (int value)
4680 95 @{
4681 96 if (value > 1) @{
4682 97 value *= factorial (value - 1);
4683 98 @}
4684 99 return (value);
4685 100 @}
4686 @end smallexample
4687
4688
4689 @kindex advance @var{location}
4690 @itemx advance @var{location}
4691 Continue running the program up to the given @var{location}. An argument is
4692 required, which should be of one of the forms described in
4693 @ref{Specify Location}.
4694 Execution will also stop upon exit from the current stack
4695 frame. This command is similar to @code{until}, but @code{advance} will
4696 not skip over recursive function calls, and the target location doesn't
4697 have to be in the same frame as the current one.
4698
4699
4700 @kindex stepi
4701 @kindex si @r{(@code{stepi})}
4702 @item stepi
4703 @itemx stepi @var{arg}
4704 @itemx si
4705 Execute one machine instruction, then stop and return to the debugger.
4706
4707 It is often useful to do @samp{display/i $pc} when stepping by machine
4708 instructions. This makes @value{GDBN} automatically display the next
4709 instruction to be executed, each time your program stops. @xref{Auto
4710 Display,, Automatic Display}.
4711
4712 An argument is a repeat count, as in @code{step}.
4713
4714 @need 750
4715 @kindex nexti
4716 @kindex ni @r{(@code{nexti})}
4717 @item nexti
4718 @itemx nexti @var{arg}
4719 @itemx ni
4720 Execute one machine instruction, but if it is a function call,
4721 proceed until the function returns.
4722
4723 An argument is a repeat count, as in @code{next}.
4724 @end table
4725
4726 @node Signals
4727 @section Signals
4728 @cindex signals
4729
4730 A signal is an asynchronous event that can happen in a program. The
4731 operating system defines the possible kinds of signals, and gives each
4732 kind a name and a number. For example, in Unix @code{SIGINT} is the
4733 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
4734 @code{SIGSEGV} is the signal a program gets from referencing a place in
4735 memory far away from all the areas in use; @code{SIGALRM} occurs when
4736 the alarm clock timer goes off (which happens only if your program has
4737 requested an alarm).
4738
4739 @cindex fatal signals
4740 Some signals, including @code{SIGALRM}, are a normal part of the
4741 functioning of your program. Others, such as @code{SIGSEGV}, indicate
4742 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
4743 program has not specified in advance some other way to handle the signal.
4744 @code{SIGINT} does not indicate an error in your program, but it is normally
4745 fatal so it can carry out the purpose of the interrupt: to kill the program.
4746
4747 @value{GDBN} has the ability to detect any occurrence of a signal in your
4748 program. You can tell @value{GDBN} in advance what to do for each kind of
4749 signal.
4750
4751 @cindex handling signals
4752 Normally, @value{GDBN} is set up to let the non-erroneous signals like
4753 @code{SIGALRM} be silently passed to your program
4754 (so as not to interfere with their role in the program's functioning)
4755 but to stop your program immediately whenever an error signal happens.
4756 You can change these settings with the @code{handle} command.
4757
4758 @table @code
4759 @kindex info signals
4760 @kindex info handle
4761 @item info signals
4762 @itemx info handle
4763 Print a table of all the kinds of signals and how @value{GDBN} has been told to
4764 handle each one. You can use this to see the signal numbers of all
4765 the defined types of signals.
4766
4767 @item info signals @var{sig}
4768 Similar, but print information only about the specified signal number.
4769
4770 @code{info handle} is an alias for @code{info signals}.
4771
4772 @kindex handle
4773 @item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
4774 Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
4775 can be the number of a signal or its name (with or without the
4776 @samp{SIG} at the beginning); a list of signal numbers of the form
4777 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
4778 known signals. Optional arguments @var{keywords}, described below,
4779 say what change to make.
4780 @end table
4781
4782 @c @group
4783 The keywords allowed by the @code{handle} command can be abbreviated.
4784 Their full names are:
4785
4786 @table @code
4787 @item nostop
4788 @value{GDBN} should not stop your program when this signal happens. It may
4789 still print a message telling you that the signal has come in.
4790
4791 @item stop
4792 @value{GDBN} should stop your program when this signal happens. This implies
4793 the @code{print} keyword as well.
4794
4795 @item print
4796 @value{GDBN} should print a message when this signal happens.
4797
4798 @item noprint
4799 @value{GDBN} should not mention the occurrence of the signal at all. This
4800 implies the @code{nostop} keyword as well.
4801
4802 @item pass
4803 @itemx noignore
4804 @value{GDBN} should allow your program to see this signal; your program
4805 can handle the signal, or else it may terminate if the signal is fatal
4806 and not handled. @code{pass} and @code{noignore} are synonyms.
4807
4808 @item nopass
4809 @itemx ignore
4810 @value{GDBN} should not allow your program to see this signal.
4811 @code{nopass} and @code{ignore} are synonyms.
4812 @end table
4813 @c @end group
4814
4815 When a signal stops your program, the signal is not visible to the
4816 program until you
4817 continue. Your program sees the signal then, if @code{pass} is in
4818 effect for the signal in question @emph{at that time}. In other words,
4819 after @value{GDBN} reports a signal, you can use the @code{handle}
4820 command with @code{pass} or @code{nopass} to control whether your
4821 program sees that signal when you continue.
4822
4823 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
4824 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
4825 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
4826 erroneous signals.
4827
4828 You can also use the @code{signal} command to prevent your program from
4829 seeing a signal, or cause it to see a signal it normally would not see,
4830 or to give it any signal at any time. For example, if your program stopped
4831 due to some sort of memory reference error, you might store correct
4832 values into the erroneous variables and continue, hoping to see more
4833 execution; but your program would probably terminate immediately as
4834 a result of the fatal signal once it saw the signal. To prevent this,
4835 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
4836 Program a Signal}.
4837
4838 @cindex extra signal information
4839 @anchor{extra signal information}
4840
4841 On some targets, @value{GDBN} can inspect extra signal information
4842 associated with the intercepted signal, before it is actually
4843 delivered to the program being debugged. This information is exported
4844 by the convenience variable @code{$_siginfo}, and consists of data
4845 that is passed by the kernel to the signal handler at the time of the
4846 receipt of a signal. The data type of the information itself is
4847 target dependent. You can see the data type using the @code{ptype
4848 $_siginfo} command. On Unix systems, it typically corresponds to the
4849 standard @code{siginfo_t} type, as defined in the @file{signal.h}
4850 system header.
4851
4852 Here's an example, on a @sc{gnu}/Linux system, printing the stray
4853 referenced address that raised a segmentation fault.
4854
4855 @smallexample
4856 @group
4857 (@value{GDBP}) continue
4858 Program received signal SIGSEGV, Segmentation fault.
4859 0x0000000000400766 in main ()
4860 69 *(int *)p = 0;
4861 (@value{GDBP}) ptype $_siginfo
4862 type = struct @{
4863 int si_signo;
4864 int si_errno;
4865 int si_code;
4866 union @{
4867 int _pad[28];
4868 struct @{...@} _kill;
4869 struct @{...@} _timer;
4870 struct @{...@} _rt;
4871 struct @{...@} _sigchld;
4872 struct @{...@} _sigfault;
4873 struct @{...@} _sigpoll;
4874 @} _sifields;
4875 @}
4876 (@value{GDBP}) ptype $_siginfo._sifields._sigfault
4877 type = struct @{
4878 void *si_addr;
4879 @}
4880 (@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
4881 $1 = (void *) 0x7ffff7ff7000
4882 @end group
4883 @end smallexample
4884
4885 Depending on target support, @code{$_siginfo} may also be writable.
4886
4887 @node Thread Stops
4888 @section Stopping and Starting Multi-thread Programs
4889
4890 @cindex stopped threads
4891 @cindex threads, stopped
4892
4893 @cindex continuing threads
4894 @cindex threads, continuing
4895
4896 @value{GDBN} supports debugging programs with multiple threads
4897 (@pxref{Threads,, Debugging Programs with Multiple Threads}). There
4898 are two modes of controlling execution of your program within the
4899 debugger. In the default mode, referred to as @dfn{all-stop mode},
4900 when any thread in your program stops (for example, at a breakpoint
4901 or while being stepped), all other threads in the program are also stopped by
4902 @value{GDBN}. On some targets, @value{GDBN} also supports
4903 @dfn{non-stop mode}, in which other threads can continue to run freely while
4904 you examine the stopped thread in the debugger.
4905
4906 @menu
4907 * All-Stop Mode:: All threads stop when GDB takes control
4908 * Non-Stop Mode:: Other threads continue to execute
4909 * Background Execution:: Running your program asynchronously
4910 * Thread-Specific Breakpoints:: Controlling breakpoints
4911 * Interrupted System Calls:: GDB may interfere with system calls
4912 @end menu
4913
4914 @node All-Stop Mode
4915 @subsection All-Stop Mode
4916
4917 @cindex all-stop mode
4918
4919 In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
4920 @emph{all} threads of execution stop, not just the current thread. This
4921 allows you to examine the overall state of the program, including
4922 switching between threads, without worrying that things may change
4923 underfoot.
4924
4925 Conversely, whenever you restart the program, @emph{all} threads start
4926 executing. @emph{This is true even when single-stepping} with commands
4927 like @code{step} or @code{next}.
4928
4929 In particular, @value{GDBN} cannot single-step all threads in lockstep.
4930 Since thread scheduling is up to your debugging target's operating
4931 system (not controlled by @value{GDBN}), other threads may
4932 execute more than one statement while the current thread completes a
4933 single step. Moreover, in general other threads stop in the middle of a
4934 statement, rather than at a clean statement boundary, when the program
4935 stops.
4936
4937 You might even find your program stopped in another thread after
4938 continuing or even single-stepping. This happens whenever some other
4939 thread runs into a breakpoint, a signal, or an exception before the
4940 first thread completes whatever you requested.
4941
4942 @cindex automatic thread selection
4943 @cindex switching threads automatically
4944 @cindex threads, automatic switching
4945 Whenever @value{GDBN} stops your program, due to a breakpoint or a
4946 signal, it automatically selects the thread where that breakpoint or
4947 signal happened. @value{GDBN} alerts you to the context switch with a
4948 message such as @samp{[Switching to Thread @var{n}]} to identify the
4949 thread.
4950
4951 On some OSes, you can modify @value{GDBN}'s default behavior by
4952 locking the OS scheduler to allow only a single thread to run.
4953
4954 @table @code
4955 @item set scheduler-locking @var{mode}
4956 @cindex scheduler locking mode
4957 @cindex lock scheduler
4958 Set the scheduler locking mode. If it is @code{off}, then there is no
4959 locking and any thread may run at any time. If @code{on}, then only the
4960 current thread may run when the inferior is resumed. The @code{step}
4961 mode optimizes for single-stepping; it prevents other threads
4962 from preempting the current thread while you are stepping, so that
4963 the focus of debugging does not change unexpectedly.
4964 Other threads only rarely (or never) get a chance to run
4965 when you step. They are more likely to run when you @samp{next} over a
4966 function call, and they are completely free to run when you use commands
4967 like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
4968 thread hits a breakpoint during its timeslice, @value{GDBN} does not change
4969 the current thread away from the thread that you are debugging.
4970
4971 @item show scheduler-locking
4972 Display the current scheduler locking mode.
4973 @end table
4974
4975 @cindex resume threads of multiple processes simultaneously
4976 By default, when you issue one of the execution commands such as
4977 @code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
4978 threads of the current inferior to run. For example, if @value{GDBN}
4979 is attached to two inferiors, each with two threads, the
4980 @code{continue} command resumes only the two threads of the current
4981 inferior. This is useful, for example, when you debug a program that
4982 forks and you want to hold the parent stopped (so that, for instance,
4983 it doesn't run to exit), while you debug the child. In other
4984 situations, you may not be interested in inspecting the current state
4985 of any of the processes @value{GDBN} is attached to, and you may want
4986 to resume them all until some breakpoint is hit. In the latter case,
4987 you can instruct @value{GDBN} to allow all threads of all the
4988 inferiors to run with the @w{@code{set schedule-multiple}} command.
4989
4990 @table @code
4991 @kindex set schedule-multiple
4992 @item set schedule-multiple
4993 Set the mode for allowing threads of multiple processes to be resumed
4994 when an execution command is issued. When @code{on}, all threads of
4995 all processes are allowed to run. When @code{off}, only the threads
4996 of the current process are resumed. The default is @code{off}. The
4997 @code{scheduler-locking} mode takes precedence when set to @code{on},
4998 or while you are stepping and set to @code{step}.
4999
5000 @item show schedule-multiple
5001 Display the current mode for resuming the execution of threads of
5002 multiple processes.
5003 @end table
5004
5005 @node Non-Stop Mode
5006 @subsection Non-Stop Mode
5007
5008 @cindex non-stop mode
5009
5010 @c This section is really only a place-holder, and needs to be expanded
5011 @c with more details.
5012
5013 For some multi-threaded targets, @value{GDBN} supports an optional
5014 mode of operation in which you can examine stopped program threads in
5015 the debugger while other threads continue to execute freely. This
5016 minimizes intrusion when debugging live systems, such as programs
5017 where some threads have real-time constraints or must continue to
5018 respond to external events. This is referred to as @dfn{non-stop} mode.
5019
5020 In non-stop mode, when a thread stops to report a debugging event,
5021 @emph{only} that thread is stopped; @value{GDBN} does not stop other
5022 threads as well, in contrast to the all-stop mode behavior. Additionally,
5023 execution commands such as @code{continue} and @code{step} apply by default
5024 only to the current thread in non-stop mode, rather than all threads as
5025 in all-stop mode. This allows you to control threads explicitly in
5026 ways that are not possible in all-stop mode --- for example, stepping
5027 one thread while allowing others to run freely, stepping
5028 one thread while holding all others stopped, or stepping several threads
5029 independently and simultaneously.
5030
5031 To enter non-stop mode, use this sequence of commands before you run
5032 or attach to your program:
5033
5034 @smallexample
5035 # Enable the async interface.
5036 set target-async 1
5037
5038 # If using the CLI, pagination breaks non-stop.
5039 set pagination off
5040
5041 # Finally, turn it on!
5042 set non-stop on
5043 @end smallexample
5044
5045 You can use these commands to manipulate the non-stop mode setting:
5046
5047 @table @code
5048 @kindex set non-stop
5049 @item set non-stop on
5050 Enable selection of non-stop mode.
5051 @item set non-stop off
5052 Disable selection of non-stop mode.
5053 @kindex show non-stop
5054 @item show non-stop
5055 Show the current non-stop enablement setting.
5056 @end table
5057
5058 Note these commands only reflect whether non-stop mode is enabled,
5059 not whether the currently-executing program is being run in non-stop mode.
5060 In particular, the @code{set non-stop} preference is only consulted when
5061 @value{GDBN} starts or connects to the target program, and it is generally
5062 not possible to switch modes once debugging has started. Furthermore,
5063 since not all targets support non-stop mode, even when you have enabled
5064 non-stop mode, @value{GDBN} may still fall back to all-stop operation by
5065 default.
5066
5067 In non-stop mode, all execution commands apply only to the current thread
5068 by default. That is, @code{continue} only continues one thread.
5069 To continue all threads, issue @code{continue -a} or @code{c -a}.
5070
5071 You can use @value{GDBN}'s background execution commands
5072 (@pxref{Background Execution}) to run some threads in the background
5073 while you continue to examine or step others from @value{GDBN}.
5074 The MI execution commands (@pxref{GDB/MI Program Execution}) are
5075 always executed asynchronously in non-stop mode.
5076
5077 Suspending execution is done with the @code{interrupt} command when
5078 running in the background, or @kbd{Ctrl-c} during foreground execution.
5079 In all-stop mode, this stops the whole process;
5080 but in non-stop mode the interrupt applies only to the current thread.
5081 To stop the whole program, use @code{interrupt -a}.
5082
5083 Other execution commands do not currently support the @code{-a} option.
5084
5085 In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
5086 that thread current, as it does in all-stop mode. This is because the
5087 thread stop notifications are asynchronous with respect to @value{GDBN}'s
5088 command interpreter, and it would be confusing if @value{GDBN} unexpectedly
5089 changed to a different thread just as you entered a command to operate on the
5090 previously current thread.
5091
5092 @node Background Execution
5093 @subsection Background Execution
5094
5095 @cindex foreground execution
5096 @cindex background execution
5097 @cindex asynchronous execution
5098 @cindex execution, foreground, background and asynchronous
5099
5100 @value{GDBN}'s execution commands have two variants: the normal
5101 foreground (synchronous) behavior, and a background
5102 (asynchronous) behavior. In foreground execution, @value{GDBN} waits for
5103 the program to report that some thread has stopped before prompting for
5104 another command. In background execution, @value{GDBN} immediately gives
5105 a command prompt so that you can issue other commands while your program runs.
5106
5107 You need to explicitly enable asynchronous mode before you can use
5108 background execution commands. You can use these commands to
5109 manipulate the asynchronous mode setting:
5110
5111 @table @code
5112 @kindex set target-async
5113 @item set target-async on
5114 Enable asynchronous mode.
5115 @item set target-async off
5116 Disable asynchronous mode.
5117 @kindex show target-async
5118 @item show target-async
5119 Show the current target-async setting.
5120 @end table
5121
5122 If the target doesn't support async mode, @value{GDBN} issues an error
5123 message if you attempt to use the background execution commands.
5124
5125 To specify background execution, add a @code{&} to the command. For example,
5126 the background form of the @code{continue} command is @code{continue&}, or
5127 just @code{c&}. The execution commands that accept background execution
5128 are:
5129
5130 @table @code
5131 @kindex run&
5132 @item run
5133 @xref{Starting, , Starting your Program}.
5134
5135 @item attach
5136 @kindex attach&
5137 @xref{Attach, , Debugging an Already-running Process}.
5138
5139 @item step
5140 @kindex step&
5141 @xref{Continuing and Stepping, step}.
5142
5143 @item stepi
5144 @kindex stepi&
5145 @xref{Continuing and Stepping, stepi}.
5146
5147 @item next
5148 @kindex next&
5149 @xref{Continuing and Stepping, next}.
5150
5151 @item nexti
5152 @kindex nexti&
5153 @xref{Continuing and Stepping, nexti}.
5154
5155 @item continue
5156 @kindex continue&
5157 @xref{Continuing and Stepping, continue}.
5158
5159 @item finish
5160 @kindex finish&
5161 @xref{Continuing and Stepping, finish}.
5162
5163 @item until
5164 @kindex until&
5165 @xref{Continuing and Stepping, until}.
5166
5167 @end table
5168
5169 Background execution is especially useful in conjunction with non-stop
5170 mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
5171 However, you can also use these commands in the normal all-stop mode with
5172 the restriction that you cannot issue another execution command until the
5173 previous one finishes. Examples of commands that are valid in all-stop
5174 mode while the program is running include @code{help} and @code{info break}.
5175
5176 You can interrupt your program while it is running in the background by
5177 using the @code{interrupt} command.
5178
5179 @table @code
5180 @kindex interrupt
5181 @item interrupt
5182 @itemx interrupt -a
5183
5184 Suspend execution of the running program. In all-stop mode,
5185 @code{interrupt} stops the whole process, but in non-stop mode, it stops
5186 only the current thread. To stop the whole program in non-stop mode,
5187 use @code{interrupt -a}.
5188 @end table
5189
5190 @node Thread-Specific Breakpoints
5191 @subsection Thread-Specific Breakpoints
5192
5193 When your program has multiple threads (@pxref{Threads,, Debugging
5194 Programs with Multiple Threads}), you can choose whether to set
5195 breakpoints on all threads, or on a particular thread.
5196
5197 @table @code
5198 @cindex breakpoints and threads
5199 @cindex thread breakpoints
5200 @kindex break @dots{} thread @var{threadno}
5201 @item break @var{linespec} thread @var{threadno}
5202 @itemx break @var{linespec} thread @var{threadno} if @dots{}
5203 @var{linespec} specifies source lines; there are several ways of
5204 writing them (@pxref{Specify Location}), but the effect is always to
5205 specify some source line.
5206
5207 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
5208 to specify that you only want @value{GDBN} to stop the program when a
5209 particular thread reaches this breakpoint. @var{threadno} is one of the
5210 numeric thread identifiers assigned by @value{GDBN}, shown in the first
5211 column of the @samp{info threads} display.
5212
5213 If you do not specify @samp{thread @var{threadno}} when you set a
5214 breakpoint, the breakpoint applies to @emph{all} threads of your
5215 program.
5216
5217 You can use the @code{thread} qualifier on conditional breakpoints as
5218 well; in this case, place @samp{thread @var{threadno}} before or
5219 after the breakpoint condition, like this:
5220
5221 @smallexample
5222 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
5223 @end smallexample
5224
5225 @end table
5226
5227 @node Interrupted System Calls
5228 @subsection Interrupted System Calls
5229
5230 @cindex thread breakpoints and system calls
5231 @cindex system calls and thread breakpoints
5232 @cindex premature return from system calls
5233 There is an unfortunate side effect when using @value{GDBN} to debug
5234 multi-threaded programs. If one thread stops for a
5235 breakpoint, or for some other reason, and another thread is blocked in a
5236 system call, then the system call may return prematurely. This is a
5237 consequence of the interaction between multiple threads and the signals
5238 that @value{GDBN} uses to implement breakpoints and other events that
5239 stop execution.
5240
5241 To handle this problem, your program should check the return value of
5242 each system call and react appropriately. This is good programming
5243 style anyways.
5244
5245 For example, do not write code like this:
5246
5247 @smallexample
5248 sleep (10);
5249 @end smallexample
5250
5251 The call to @code{sleep} will return early if a different thread stops
5252 at a breakpoint or for some other reason.
5253
5254 Instead, write this:
5255
5256 @smallexample
5257 int unslept = 10;
5258 while (unslept > 0)
5259 unslept = sleep (unslept);
5260 @end smallexample
5261
5262 A system call is allowed to return early, so the system is still
5263 conforming to its specification. But @value{GDBN} does cause your
5264 multi-threaded program to behave differently than it would without
5265 @value{GDBN}.
5266
5267 Also, @value{GDBN} uses internal breakpoints in the thread library to
5268 monitor certain events such as thread creation and thread destruction.
5269 When such an event happens, a system call in another thread may return
5270 prematurely, even though your program does not appear to stop.
5271
5272
5273 @node Reverse Execution
5274 @chapter Running programs backward
5275 @cindex reverse execution
5276 @cindex running programs backward
5277
5278 When you are debugging a program, it is not unusual to realize that
5279 you have gone too far, and some event of interest has already happened.
5280 If the target environment supports it, @value{GDBN} can allow you to
5281 ``rewind'' the program by running it backward.
5282
5283 A target environment that supports reverse execution should be able
5284 to ``undo'' the changes in machine state that have taken place as the
5285 program was executing normally. Variables, registers etc.@: should
5286 revert to their previous values. Obviously this requires a great
5287 deal of sophistication on the part of the target environment; not
5288 all target environments can support reverse execution.
5289
5290 When a program is executed in reverse, the instructions that
5291 have most recently been executed are ``un-executed'', in reverse
5292 order. The program counter runs backward, following the previous
5293 thread of execution in reverse. As each instruction is ``un-executed'',
5294 the values of memory and/or registers that were changed by that
5295 instruction are reverted to their previous states. After executing
5296 a piece of source code in reverse, all side effects of that code
5297 should be ``undone'', and all variables should be returned to their
5298 prior values@footnote{
5299 Note that some side effects are easier to undo than others. For instance,
5300 memory and registers are relatively easy, but device I/O is hard. Some
5301 targets may be able undo things like device I/O, and some may not.
5302
5303 The contract between @value{GDBN} and the reverse executing target
5304 requires only that the target do something reasonable when
5305 @value{GDBN} tells it to execute backwards, and then report the
5306 results back to @value{GDBN}. Whatever the target reports back to
5307 @value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
5308 assumes that the memory and registers that the target reports are in a
5309 consistant state, but @value{GDBN} accepts whatever it is given.
5310 }.
5311
5312 If you are debugging in a target environment that supports
5313 reverse execution, @value{GDBN} provides the following commands.
5314
5315 @table @code
5316 @kindex reverse-continue
5317 @kindex rc @r{(@code{reverse-continue})}
5318 @item reverse-continue @r{[}@var{ignore-count}@r{]}
5319 @itemx rc @r{[}@var{ignore-count}@r{]}
5320 Beginning at the point where your program last stopped, start executing
5321 in reverse. Reverse execution will stop for breakpoints and synchronous
5322 exceptions (signals), just like normal execution. Behavior of
5323 asynchronous signals depends on the target environment.
5324
5325 @kindex reverse-step
5326 @kindex rs @r{(@code{step})}
5327 @item reverse-step @r{[}@var{count}@r{]}
5328 Run the program backward until control reaches the start of a
5329 different source line; then stop it, and return control to @value{GDBN}.
5330
5331 Like the @code{step} command, @code{reverse-step} will only stop
5332 at the beginning of a source line. It ``un-executes'' the previously
5333 executed source line. If the previous source line included calls to
5334 debuggable functions, @code{reverse-step} will step (backward) into
5335 the called function, stopping at the beginning of the @emph{last}
5336 statement in the called function (typically a return statement).
5337
5338 Also, as with the @code{step} command, if non-debuggable functions are
5339 called, @code{reverse-step} will run thru them backward without stopping.
5340
5341 @kindex reverse-stepi
5342 @kindex rsi @r{(@code{reverse-stepi})}
5343 @item reverse-stepi @r{[}@var{count}@r{]}
5344 Reverse-execute one machine instruction. Note that the instruction
5345 to be reverse-executed is @emph{not} the one pointed to by the program
5346 counter, but the instruction executed prior to that one. For instance,
5347 if the last instruction was a jump, @code{reverse-stepi} will take you
5348 back from the destination of the jump to the jump instruction itself.
5349
5350 @kindex reverse-next
5351 @kindex rn @r{(@code{reverse-next})}
5352 @item reverse-next @r{[}@var{count}@r{]}
5353 Run backward to the beginning of the previous line executed in
5354 the current (innermost) stack frame. If the line contains function
5355 calls, they will be ``un-executed'' without stopping. Starting from
5356 the first line of a function, @code{reverse-next} will take you back
5357 to the caller of that function, @emph{before} the function was called,
5358 just as the normal @code{next} command would take you from the last
5359 line of a function back to its return to its caller
5360 @footnote{Unless the code is too heavily optimized.}.
5361
5362 @kindex reverse-nexti
5363 @kindex rni @r{(@code{reverse-nexti})}
5364 @item reverse-nexti @r{[}@var{count}@r{]}
5365 Like @code{nexti}, @code{reverse-nexti} executes a single instruction
5366 in reverse, except that called functions are ``un-executed'' atomically.
5367 That is, if the previously executed instruction was a return from
5368 another instruction, @code{reverse-nexti} will continue to execute
5369 in reverse until the call to that function (from the current stack
5370 frame) is reached.
5371
5372 @kindex reverse-finish
5373 @item reverse-finish
5374 Just as the @code{finish} command takes you to the point where the
5375 current function returns, @code{reverse-finish} takes you to the point
5376 where it was called. Instead of ending up at the end of the current
5377 function invocation, you end up at the beginning.
5378
5379 @kindex set exec-direction
5380 @item set exec-direction
5381 Set the direction of target execution.
5382 @itemx set exec-direction reverse
5383 @cindex execute forward or backward in time
5384 @value{GDBN} will perform all execution commands in reverse, until the
5385 exec-direction mode is changed to ``forward''. Affected commands include
5386 @code{step, stepi, next, nexti, continue, and finish}. The @code{return}
5387 command cannot be used in reverse mode.
5388 @item set exec-direction forward
5389 @value{GDBN} will perform all execution commands in the normal fashion.
5390 This is the default.
5391 @end table
5392
5393
5394 @node Process Record and Replay
5395 @chapter Recording Inferior's Execution and Replaying It
5396 @cindex process record and replay
5397 @cindex recording inferior's execution and replaying it
5398
5399 On some platforms, @value{GDBN} provides a special @dfn{process record
5400 and replay} target that can record a log of the process execution, and
5401 replay it later with both forward and reverse execution commands.
5402
5403 @cindex replay mode
5404 When this target is in use, if the execution log includes the record
5405 for the next instruction, @value{GDBN} will debug in @dfn{replay
5406 mode}. In the replay mode, the inferior does not really execute code
5407 instructions. Instead, all the events that normally happen during
5408 code execution are taken from the execution log. While code is not
5409 really executed in replay mode, the values of registers (including the
5410 program counter register) and the memory of the inferior are still
5411 changed as they normally would. Their contents are taken from the
5412 execution log.
5413
5414 @cindex record mode
5415 If the record for the next instruction is not in the execution log,
5416 @value{GDBN} will debug in @dfn{record mode}. In this mode, the
5417 inferior executes normally, and @value{GDBN} records the execution log
5418 for future replay.
5419
5420 The process record and replay target supports reverse execution
5421 (@pxref{Reverse Execution}), even if the platform on which the
5422 inferior runs does not. However, the reverse execution is limited in
5423 this case by the range of the instructions recorded in the execution
5424 log. In other words, reverse execution on platforms that don't
5425 support it directly can only be done in the replay mode.
5426
5427 When debugging in the reverse direction, @value{GDBN} will work in
5428 replay mode as long as the execution log includes the record for the
5429 previous instruction; otherwise, it will work in record mode, if the
5430 platform supports reverse execution, or stop if not.
5431
5432 For architecture environments that support process record and replay,
5433 @value{GDBN} provides the following commands:
5434
5435 @table @code
5436 @kindex target record
5437 @kindex record
5438 @kindex rec
5439 @item target record
5440 This command starts the process record and replay target. The process
5441 record and replay target can only debug a process that is already
5442 running. Therefore, you need first to start the process with the
5443 @kbd{run} or @kbd{start} commands, and then start the recording with
5444 the @kbd{target record} command.
5445
5446 Both @code{record} and @code{rec} are aliases of @code{target record}.
5447
5448 @cindex displaced stepping, and process record and replay
5449 Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
5450 will be automatically disabled when process record and replay target
5451 is started. That's because the process record and replay target
5452 doesn't support displaced stepping.
5453
5454 @cindex non-stop mode, and process record and replay
5455 @cindex asynchronous execution, and process record and replay
5456 If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
5457 the asynchronous execution mode (@pxref{Background Execution}), the
5458 process record and replay target cannot be started because it doesn't
5459 support these two modes.
5460
5461 @kindex record stop
5462 @kindex rec s
5463 @item record stop
5464 Stop the process record and replay target. When process record and
5465 replay target stops, the entire execution log will be deleted and the
5466 inferior will either be terminated, or will remain in its final state.
5467
5468 When you stop the process record and replay target in record mode (at
5469 the end of the execution log), the inferior will be stopped at the
5470 next instruction that would have been recorded. In other words, if
5471 you record for a while and then stop recording, the inferior process
5472 will be left in the same state as if the recording never happened.
5473
5474 On the other hand, if the process record and replay target is stopped
5475 while in replay mode (that is, not at the end of the execution log,
5476 but at some earlier point), the inferior process will become ``live''
5477 at that earlier state, and it will then be possible to continue the
5478 usual ``live'' debugging of the process from that state.
5479
5480 When the inferior process exits, or @value{GDBN} detaches from it,
5481 process record and replay target will automatically stop itself.
5482
5483 @kindex set record insn-number-max
5484 @item set record insn-number-max @var{limit}
5485 Set the limit of instructions to be recorded. Default value is 200000.
5486
5487 If @var{limit} is a positive number, then @value{GDBN} will start
5488 deleting instructions from the log once the number of the record
5489 instructions becomes greater than @var{limit}. For every new recorded
5490 instruction, @value{GDBN} will delete the earliest recorded
5491 instruction to keep the number of recorded instructions at the limit.
5492 (Since deleting recorded instructions loses information, @value{GDBN}
5493 lets you control what happens when the limit is reached, by means of
5494 the @code{stop-at-limit} option, described below.)
5495
5496 If @var{limit} is zero, @value{GDBN} will never delete recorded
5497 instructions from the execution log. The number of recorded
5498 instructions is unlimited in this case.
5499
5500 @kindex show record insn-number-max
5501 @item show record insn-number-max
5502 Show the limit of instructions to be recorded.
5503
5504 @kindex set record stop-at-limit
5505 @item set record stop-at-limit
5506 Control the behavior when the number of recorded instructions reaches
5507 the limit. If ON (the default), @value{GDBN} will stop when the limit
5508 is reached for the first time and ask you whether you want to stop the
5509 inferior or continue running it and recording the execution log. If
5510 you decide to continue recording, each new recorded instruction will
5511 cause the oldest one to be deleted.
5512
5513 If this option is OFF, @value{GDBN} will automatically delete the
5514 oldest record to make room for each new one, without asking.
5515
5516 @kindex show record stop-at-limit
5517 @item show record stop-at-limit
5518 Show the current setting of @code{stop-at-limit}.
5519
5520 @kindex info record
5521 @item info record
5522 Show various statistics about the state of process record and its
5523 in-memory execution log buffer, including:
5524
5525 @itemize @bullet
5526 @item
5527 Whether in record mode or replay mode.
5528 @item
5529 Lowest recorded instruction number (counting from when the current execution log started recording instructions).
5530 @item
5531 Highest recorded instruction number.
5532 @item
5533 Current instruction about to be replayed (if in replay mode).
5534 @item
5535 Number of instructions contained in the execution log.
5536 @item
5537 Maximum number of instructions that may be contained in the execution log.
5538 @end itemize
5539
5540 @kindex record delete
5541 @kindex rec del
5542 @item record delete
5543 When record target runs in replay mode (``in the past''), delete the
5544 subsequent execution log and begin to record a new execution log starting
5545 from the current address. This means you will abandon the previously
5546 recorded ``future'' and begin recording a new ``future''.
5547 @end table
5548
5549
5550 @node Stack
5551 @chapter Examining the Stack
5552
5553 When your program has stopped, the first thing you need to know is where it
5554 stopped and how it got there.
5555
5556 @cindex call stack
5557 Each time your program performs a function call, information about the call
5558 is generated.
5559 That information includes the location of the call in your program,
5560 the arguments of the call,
5561 and the local variables of the function being called.
5562 The information is saved in a block of data called a @dfn{stack frame}.
5563 The stack frames are allocated in a region of memory called the @dfn{call
5564 stack}.
5565
5566 When your program stops, the @value{GDBN} commands for examining the
5567 stack allow you to see all of this information.
5568
5569 @cindex selected frame
5570 One of the stack frames is @dfn{selected} by @value{GDBN} and many
5571 @value{GDBN} commands refer implicitly to the selected frame. In
5572 particular, whenever you ask @value{GDBN} for the value of a variable in
5573 your program, the value is found in the selected frame. There are
5574 special @value{GDBN} commands to select whichever frame you are
5575 interested in. @xref{Selection, ,Selecting a Frame}.
5576
5577 When your program stops, @value{GDBN} automatically selects the
5578 currently executing frame and describes it briefly, similar to the
5579 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
5580
5581 @menu
5582 * Frames:: Stack frames
5583 * Backtrace:: Backtraces
5584 * Selection:: Selecting a frame
5585 * Frame Info:: Information on a frame
5586
5587 @end menu
5588
5589 @node Frames
5590 @section Stack Frames
5591
5592 @cindex frame, definition
5593 @cindex stack frame
5594 The call stack is divided up into contiguous pieces called @dfn{stack
5595 frames}, or @dfn{frames} for short; each frame is the data associated
5596 with one call to one function. The frame contains the arguments given
5597 to the function, the function's local variables, and the address at
5598 which the function is executing.
5599
5600 @cindex initial frame
5601 @cindex outermost frame
5602 @cindex innermost frame
5603 When your program is started, the stack has only one frame, that of the
5604 function @code{main}. This is called the @dfn{initial} frame or the
5605 @dfn{outermost} frame. Each time a function is called, a new frame is
5606 made. Each time a function returns, the frame for that function invocation
5607 is eliminated. If a function is recursive, there can be many frames for
5608 the same function. The frame for the function in which execution is
5609 actually occurring is called the @dfn{innermost} frame. This is the most
5610 recently created of all the stack frames that still exist.
5611
5612 @cindex frame pointer
5613 Inside your program, stack frames are identified by their addresses. A
5614 stack frame consists of many bytes, each of which has its own address; each
5615 kind of computer has a convention for choosing one byte whose
5616 address serves as the address of the frame. Usually this address is kept
5617 in a register called the @dfn{frame pointer register}
5618 (@pxref{Registers, $fp}) while execution is going on in that frame.
5619
5620 @cindex frame number
5621 @value{GDBN} assigns numbers to all existing stack frames, starting with
5622 zero for the innermost frame, one for the frame that called it,
5623 and so on upward. These numbers do not really exist in your program;
5624 they are assigned by @value{GDBN} to give you a way of designating stack
5625 frames in @value{GDBN} commands.
5626
5627 @c The -fomit-frame-pointer below perennially causes hbox overflow
5628 @c underflow problems.
5629 @cindex frameless execution
5630 Some compilers provide a way to compile functions so that they operate
5631 without stack frames. (For example, the @value{NGCC} option
5632 @smallexample
5633 @samp{-fomit-frame-pointer}
5634 @end smallexample
5635 generates functions without a frame.)
5636 This is occasionally done with heavily used library functions to save
5637 the frame setup time. @value{GDBN} has limited facilities for dealing
5638 with these function invocations. If the innermost function invocation
5639 has no stack frame, @value{GDBN} nevertheless regards it as though
5640 it had a separate frame, which is numbered zero as usual, allowing
5641 correct tracing of the function call chain. However, @value{GDBN} has
5642 no provision for frameless functions elsewhere in the stack.
5643
5644 @table @code
5645 @kindex frame@r{, command}
5646 @cindex current stack frame
5647 @item frame @var{args}
5648 The @code{frame} command allows you to move from one stack frame to another,
5649 and to print the stack frame you select. @var{args} may be either the
5650 address of the frame or the stack frame number. Without an argument,
5651 @code{frame} prints the current stack frame.
5652
5653 @kindex select-frame
5654 @cindex selecting frame silently
5655 @item select-frame
5656 The @code{select-frame} command allows you to move from one stack frame
5657 to another without printing the frame. This is the silent version of
5658 @code{frame}.
5659 @end table
5660
5661 @node Backtrace
5662 @section Backtraces
5663
5664 @cindex traceback
5665 @cindex call stack traces
5666 A backtrace is a summary of how your program got where it is. It shows one
5667 line per frame, for many frames, starting with the currently executing
5668 frame (frame zero), followed by its caller (frame one), and on up the
5669 stack.
5670
5671 @table @code
5672 @kindex backtrace
5673 @kindex bt @r{(@code{backtrace})}
5674 @item backtrace
5675 @itemx bt
5676 Print a backtrace of the entire stack: one line per frame for all
5677 frames in the stack.
5678
5679 You can stop the backtrace at any time by typing the system interrupt
5680 character, normally @kbd{Ctrl-c}.
5681
5682 @item backtrace @var{n}
5683 @itemx bt @var{n}
5684 Similar, but print only the innermost @var{n} frames.
5685
5686 @item backtrace -@var{n}
5687 @itemx bt -@var{n}
5688 Similar, but print only the outermost @var{n} frames.
5689
5690 @item backtrace full
5691 @itemx bt full
5692 @itemx bt full @var{n}
5693 @itemx bt full -@var{n}
5694 Print the values of the local variables also. @var{n} specifies the
5695 number of frames to print, as described above.
5696 @end table
5697
5698 @kindex where
5699 @kindex info stack
5700 The names @code{where} and @code{info stack} (abbreviated @code{info s})
5701 are additional aliases for @code{backtrace}.
5702
5703 @cindex multiple threads, backtrace
5704 In a multi-threaded program, @value{GDBN} by default shows the
5705 backtrace only for the current thread. To display the backtrace for
5706 several or all of the threads, use the command @code{thread apply}
5707 (@pxref{Threads, thread apply}). For example, if you type @kbd{thread
5708 apply all backtrace}, @value{GDBN} will display the backtrace for all
5709 the threads; this is handy when you debug a core dump of a
5710 multi-threaded program.
5711
5712 Each line in the backtrace shows the frame number and the function name.
5713 The program counter value is also shown---unless you use @code{set
5714 print address off}. The backtrace also shows the source file name and
5715 line number, as well as the arguments to the function. The program
5716 counter value is omitted if it is at the beginning of the code for that
5717 line number.
5718
5719 Here is an example of a backtrace. It was made with the command
5720 @samp{bt 3}, so it shows the innermost three frames.
5721
5722 @smallexample
5723 @group
5724 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
5725 at builtin.c:993
5726 #1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
5727 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
5728 at macro.c:71
5729 (More stack frames follow...)
5730 @end group
5731 @end smallexample
5732
5733 @noindent
5734 The display for frame zero does not begin with a program counter
5735 value, indicating that your program has stopped at the beginning of the
5736 code for line @code{993} of @code{builtin.c}.
5737
5738 @noindent
5739 The value of parameter @code{data} in frame 1 has been replaced by
5740 @code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
5741 only if it is a scalar (integer, pointer, enumeration, etc). See command
5742 @kbd{set print frame-arguments} in @ref{Print Settings} for more details
5743 on how to configure the way function parameter values are printed.
5744
5745 @cindex value optimized out, in backtrace
5746 @cindex function call arguments, optimized out
5747 If your program was compiled with optimizations, some compilers will
5748 optimize away arguments passed to functions if those arguments are
5749 never used after the call. Such optimizations generate code that
5750 passes arguments through registers, but doesn't store those arguments
5751 in the stack frame. @value{GDBN} has no way of displaying such
5752 arguments in stack frames other than the innermost one. Here's what
5753 such a backtrace might look like:
5754
5755 @smallexample
5756 @group
5757 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
5758 at builtin.c:993
5759 #1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
5760 #2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
5761 at macro.c:71
5762 (More stack frames follow...)
5763 @end group
5764 @end smallexample
5765
5766 @noindent
5767 The values of arguments that were not saved in their stack frames are
5768 shown as @samp{<value optimized out>}.
5769
5770 If you need to display the values of such optimized-out arguments,
5771 either deduce that from other variables whose values depend on the one
5772 you are interested in, or recompile without optimizations.
5773
5774 @cindex backtrace beyond @code{main} function
5775 @cindex program entry point
5776 @cindex startup code, and backtrace
5777 Most programs have a standard user entry point---a place where system
5778 libraries and startup code transition into user code. For C this is
5779 @code{main}@footnote{
5780 Note that embedded programs (the so-called ``free-standing''
5781 environment) are not required to have a @code{main} function as the
5782 entry point. They could even have multiple entry points.}.
5783 When @value{GDBN} finds the entry function in a backtrace
5784 it will terminate the backtrace, to avoid tracing into highly
5785 system-specific (and generally uninteresting) code.
5786
5787 If you need to examine the startup code, or limit the number of levels
5788 in a backtrace, you can change this behavior:
5789
5790 @table @code
5791 @item set backtrace past-main
5792 @itemx set backtrace past-main on
5793 @kindex set backtrace
5794 Backtraces will continue past the user entry point.
5795
5796 @item set backtrace past-main off
5797 Backtraces will stop when they encounter the user entry point. This is the
5798 default.
5799
5800 @item show backtrace past-main
5801 @kindex show backtrace
5802 Display the current user entry point backtrace policy.
5803
5804 @item set backtrace past-entry
5805 @itemx set backtrace past-entry on
5806 Backtraces will continue past the internal entry point of an application.
5807 This entry point is encoded by the linker when the application is built,
5808 and is likely before the user entry point @code{main} (or equivalent) is called.
5809
5810 @item set backtrace past-entry off
5811 Backtraces will stop when they encounter the internal entry point of an
5812 application. This is the default.
5813
5814 @item show backtrace past-entry
5815 Display the current internal entry point backtrace policy.
5816
5817 @item set backtrace limit @var{n}
5818 @itemx set backtrace limit 0
5819 @cindex backtrace limit
5820 Limit the backtrace to @var{n} levels. A value of zero means
5821 unlimited.
5822
5823 @item show backtrace limit
5824 Display the current limit on backtrace levels.
5825 @end table
5826
5827 @node Selection
5828 @section Selecting a Frame
5829
5830 Most commands for examining the stack and other data in your program work on
5831 whichever stack frame is selected at the moment. Here are the commands for
5832 selecting a stack frame; all of them finish by printing a brief description
5833 of the stack frame just selected.
5834
5835 @table @code
5836 @kindex frame@r{, selecting}
5837 @kindex f @r{(@code{frame})}
5838 @item frame @var{n}
5839 @itemx f @var{n}
5840 Select frame number @var{n}. Recall that frame zero is the innermost
5841 (currently executing) frame, frame one is the frame that called the
5842 innermost one, and so on. The highest-numbered frame is the one for
5843 @code{main}.
5844
5845 @item frame @var{addr}
5846 @itemx f @var{addr}
5847 Select the frame at address @var{addr}. This is useful mainly if the
5848 chaining of stack frames has been damaged by a bug, making it
5849 impossible for @value{GDBN} to assign numbers properly to all frames. In
5850 addition, this can be useful when your program has multiple stacks and
5851 switches between them.
5852
5853 On the SPARC architecture, @code{frame} needs two addresses to
5854 select an arbitrary frame: a frame pointer and a stack pointer.
5855
5856 On the MIPS and Alpha architecture, it needs two addresses: a stack
5857 pointer and a program counter.
5858
5859 On the 29k architecture, it needs three addresses: a register stack
5860 pointer, a program counter, and a memory stack pointer.
5861
5862 @kindex up
5863 @item up @var{n}
5864 Move @var{n} frames up the stack. For positive numbers @var{n}, this
5865 advances toward the outermost frame, to higher frame numbers, to frames
5866 that have existed longer. @var{n} defaults to one.
5867
5868 @kindex down
5869 @kindex do @r{(@code{down})}
5870 @item down @var{n}
5871 Move @var{n} frames down the stack. For positive numbers @var{n}, this
5872 advances toward the innermost frame, to lower frame numbers, to frames
5873 that were created more recently. @var{n} defaults to one. You may
5874 abbreviate @code{down} as @code{do}.
5875 @end table
5876
5877 All of these commands end by printing two lines of output describing the
5878 frame. The first line shows the frame number, the function name, the
5879 arguments, and the source file and line number of execution in that
5880 frame. The second line shows the text of that source line.
5881
5882 @need 1000
5883 For example:
5884
5885 @smallexample
5886 @group
5887 (@value{GDBP}) up
5888 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
5889 at env.c:10
5890 10 read_input_file (argv[i]);
5891 @end group
5892 @end smallexample
5893
5894 After such a printout, the @code{list} command with no arguments
5895 prints ten lines centered on the point of execution in the frame.
5896 You can also edit the program at the point of execution with your favorite
5897 editing program by typing @code{edit}.
5898 @xref{List, ,Printing Source Lines},
5899 for details.
5900
5901 @table @code
5902 @kindex down-silently
5903 @kindex up-silently
5904 @item up-silently @var{n}
5905 @itemx down-silently @var{n}
5906 These two commands are variants of @code{up} and @code{down},
5907 respectively; they differ in that they do their work silently, without
5908 causing display of the new frame. They are intended primarily for use
5909 in @value{GDBN} command scripts, where the output might be unnecessary and
5910 distracting.
5911 @end table
5912
5913 @node Frame Info
5914 @section Information About a Frame
5915
5916 There are several other commands to print information about the selected
5917 stack frame.
5918
5919 @table @code
5920 @item frame
5921 @itemx f
5922 When used without any argument, this command does not change which
5923 frame is selected, but prints a brief description of the currently
5924 selected stack frame. It can be abbreviated @code{f}. With an
5925 argument, this command is used to select a stack frame.
5926 @xref{Selection, ,Selecting a Frame}.
5927
5928 @kindex info frame
5929 @kindex info f @r{(@code{info frame})}
5930 @item info frame
5931 @itemx info f
5932 This command prints a verbose description of the selected stack frame,
5933 including:
5934
5935 @itemize @bullet
5936 @item
5937 the address of the frame
5938 @item
5939 the address of the next frame down (called by this frame)
5940 @item
5941 the address of the next frame up (caller of this frame)
5942 @item
5943 the language in which the source code corresponding to this frame is written
5944 @item
5945 the address of the frame's arguments
5946 @item
5947 the address of the frame's local variables
5948 @item
5949 the program counter saved in it (the address of execution in the caller frame)
5950 @item
5951 which registers were saved in the frame
5952 @end itemize
5953
5954 @noindent The verbose description is useful when
5955 something has gone wrong that has made the stack format fail to fit
5956 the usual conventions.
5957
5958 @item info frame @var{addr}
5959 @itemx info f @var{addr}
5960 Print a verbose description of the frame at address @var{addr}, without
5961 selecting that frame. The selected frame remains unchanged by this
5962 command. This requires the same kind of address (more than one for some
5963 architectures) that you specify in the @code{frame} command.
5964 @xref{Selection, ,Selecting a Frame}.
5965
5966 @kindex info args
5967 @item info args
5968 Print the arguments of the selected frame, each on a separate line.
5969
5970 @item info locals
5971 @kindex info locals
5972 Print the local variables of the selected frame, each on a separate
5973 line. These are all variables (declared either static or automatic)
5974 accessible at the point of execution of the selected frame.
5975
5976 @kindex info catch
5977 @cindex catch exceptions, list active handlers
5978 @cindex exception handlers, how to list
5979 @item info catch
5980 Print a list of all the exception handlers that are active in the
5981 current stack frame at the current point of execution. To see other
5982 exception handlers, visit the associated frame (using the @code{up},
5983 @code{down}, or @code{frame} commands); then type @code{info catch}.
5984 @xref{Set Catchpoints, , Setting Catchpoints}.
5985
5986 @end table
5987
5988
5989 @node Source
5990 @chapter Examining Source Files
5991
5992 @value{GDBN} can print parts of your program's source, since the debugging
5993 information recorded in the program tells @value{GDBN} what source files were
5994 used to build it. When your program stops, @value{GDBN} spontaneously prints
5995 the line where it stopped. Likewise, when you select a stack frame
5996 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
5997 execution in that frame has stopped. You can print other portions of
5998 source files by explicit command.
5999
6000 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
6001 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
6002 @value{GDBN} under @sc{gnu} Emacs}.
6003
6004 @menu
6005 * List:: Printing source lines
6006 * Specify Location:: How to specify code locations
6007 * Edit:: Editing source files
6008 * Search:: Searching source files
6009 * Source Path:: Specifying source directories
6010 * Machine Code:: Source and machine code
6011 @end menu
6012
6013 @node List
6014 @section Printing Source Lines
6015
6016 @kindex list
6017 @kindex l @r{(@code{list})}
6018 To print lines from a source file, use the @code{list} command
6019 (abbreviated @code{l}). By default, ten lines are printed.
6020 There are several ways to specify what part of the file you want to
6021 print; see @ref{Specify Location}, for the full list.
6022
6023 Here are the forms of the @code{list} command most commonly used:
6024
6025 @table @code
6026 @item list @var{linenum}
6027 Print lines centered around line number @var{linenum} in the
6028 current source file.
6029
6030 @item list @var{function}
6031 Print lines centered around the beginning of function
6032 @var{function}.
6033
6034 @item list
6035 Print more lines. If the last lines printed were printed with a
6036 @code{list} command, this prints lines following the last lines
6037 printed; however, if the last line printed was a solitary line printed
6038 as part of displaying a stack frame (@pxref{Stack, ,Examining the
6039 Stack}), this prints lines centered around that line.
6040
6041 @item list -
6042 Print lines just before the lines last printed.
6043 @end table
6044
6045 @cindex @code{list}, how many lines to display
6046 By default, @value{GDBN} prints ten source lines with any of these forms of
6047 the @code{list} command. You can change this using @code{set listsize}:
6048
6049 @table @code
6050 @kindex set listsize
6051 @item set listsize @var{count}
6052 Make the @code{list} command display @var{count} source lines (unless
6053 the @code{list} argument explicitly specifies some other number).
6054
6055 @kindex show listsize
6056 @item show listsize
6057 Display the number of lines that @code{list} prints.
6058 @end table
6059
6060 Repeating a @code{list} command with @key{RET} discards the argument,
6061 so it is equivalent to typing just @code{list}. This is more useful
6062 than listing the same lines again. An exception is made for an
6063 argument of @samp{-}; that argument is preserved in repetition so that
6064 each repetition moves up in the source file.
6065
6066 In general, the @code{list} command expects you to supply zero, one or two
6067 @dfn{linespecs}. Linespecs specify source lines; there are several ways
6068 of writing them (@pxref{Specify Location}), but the effect is always
6069 to specify some source line.
6070
6071 Here is a complete description of the possible arguments for @code{list}:
6072
6073 @table @code
6074 @item list @var{linespec}
6075 Print lines centered around the line specified by @var{linespec}.
6076
6077 @item list @var{first},@var{last}
6078 Print lines from @var{first} to @var{last}. Both arguments are
6079 linespecs. When a @code{list} command has two linespecs, and the
6080 source file of the second linespec is omitted, this refers to
6081 the same source file as the first linespec.
6082
6083 @item list ,@var{last}
6084 Print lines ending with @var{last}.
6085
6086 @item list @var{first},
6087 Print lines starting with @var{first}.
6088
6089 @item list +
6090 Print lines just after the lines last printed.
6091
6092 @item list -
6093 Print lines just before the lines last printed.
6094
6095 @item list
6096 As described in the preceding table.
6097 @end table
6098
6099 @node Specify Location
6100 @section Specifying a Location
6101 @cindex specifying location
6102 @cindex linespec
6103
6104 Several @value{GDBN} commands accept arguments that specify a location
6105 of your program's code. Since @value{GDBN} is a source-level
6106 debugger, a location usually specifies some line in the source code;
6107 for that reason, locations are also known as @dfn{linespecs}.
6108
6109 Here are all the different ways of specifying a code location that
6110 @value{GDBN} understands:
6111
6112 @table @code
6113 @item @var{linenum}
6114 Specifies the line number @var{linenum} of the current source file.
6115
6116 @item -@var{offset}
6117 @itemx +@var{offset}
6118 Specifies the line @var{offset} lines before or after the @dfn{current
6119 line}. For the @code{list} command, the current line is the last one
6120 printed; for the breakpoint commands, this is the line at which
6121 execution stopped in the currently selected @dfn{stack frame}
6122 (@pxref{Frames, ,Frames}, for a description of stack frames.) When
6123 used as the second of the two linespecs in a @code{list} command,
6124 this specifies the line @var{offset} lines up or down from the first
6125 linespec.
6126
6127 @item @var{filename}:@var{linenum}
6128 Specifies the line @var{linenum} in the source file @var{filename}.
6129
6130 @item @var{function}
6131 Specifies the line that begins the body of the function @var{function}.
6132 For example, in C, this is the line with the open brace.
6133
6134 @item @var{filename}:@var{function}
6135 Specifies the line that begins the body of the function @var{function}
6136 in the file @var{filename}. You only need the file name with a
6137 function name to avoid ambiguity when there are identically named
6138 functions in different source files.
6139
6140 @item *@var{address}
6141 Specifies the program address @var{address}. For line-oriented
6142 commands, such as @code{list} and @code{edit}, this specifies a source
6143 line that contains @var{address}. For @code{break} and other
6144 breakpoint oriented commands, this can be used to set breakpoints in
6145 parts of your program which do not have debugging information or
6146 source files.
6147
6148 Here @var{address} may be any expression valid in the current working
6149 language (@pxref{Languages, working language}) that specifies a code
6150 address. In addition, as a convenience, @value{GDBN} extends the
6151 semantics of expressions used in locations to cover the situations
6152 that frequently happen during debugging. Here are the various forms
6153 of @var{address}:
6154
6155 @table @code
6156 @item @var{expression}
6157 Any expression valid in the current working language.
6158
6159 @item @var{funcaddr}
6160 An address of a function or procedure derived from its name. In C,
6161 C@t{++}, Java, Objective-C, Fortran, minimal, and assembly, this is
6162 simply the function's name @var{function} (and actually a special case
6163 of a valid expression). In Pascal and Modula-2, this is
6164 @code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
6165 (although the Pascal form also works).
6166
6167 This form specifies the address of the function's first instruction,
6168 before the stack frame and arguments have been set up.
6169
6170 @item '@var{filename}'::@var{funcaddr}
6171 Like @var{funcaddr} above, but also specifies the name of the source
6172 file explicitly. This is useful if the name of the function does not
6173 specify the function unambiguously, e.g., if there are several
6174 functions with identical names in different source files.
6175 @end table
6176
6177 @end table
6178
6179
6180 @node Edit
6181 @section Editing Source Files
6182 @cindex editing source files
6183
6184 @kindex edit
6185 @kindex e @r{(@code{edit})}
6186 To edit the lines in a source file, use the @code{edit} command.
6187 The editing program of your choice
6188 is invoked with the current line set to
6189 the active line in the program.
6190 Alternatively, there are several ways to specify what part of the file you
6191 want to print if you want to see other parts of the program:
6192
6193 @table @code
6194 @item edit @var{location}
6195 Edit the source file specified by @code{location}. Editing starts at
6196 that @var{location}, e.g., at the specified source line of the
6197 specified file. @xref{Specify Location}, for all the possible forms
6198 of the @var{location} argument; here are the forms of the @code{edit}
6199 command most commonly used:
6200
6201 @table @code
6202 @item edit @var{number}
6203 Edit the current source file with @var{number} as the active line number.
6204
6205 @item edit @var{function}
6206 Edit the file containing @var{function} at the beginning of its definition.
6207 @end table
6208
6209 @end table
6210
6211 @subsection Choosing your Editor
6212 You can customize @value{GDBN} to use any editor you want
6213 @footnote{
6214 The only restriction is that your editor (say @code{ex}), recognizes the
6215 following command-line syntax:
6216 @smallexample
6217 ex +@var{number} file
6218 @end smallexample
6219 The optional numeric value +@var{number} specifies the number of the line in
6220 the file where to start editing.}.
6221 By default, it is @file{@value{EDITOR}}, but you can change this
6222 by setting the environment variable @code{EDITOR} before using
6223 @value{GDBN}. For example, to configure @value{GDBN} to use the
6224 @code{vi} editor, you could use these commands with the @code{sh} shell:
6225 @smallexample
6226 EDITOR=/usr/bin/vi
6227 export EDITOR
6228 gdb @dots{}
6229 @end smallexample
6230 or in the @code{csh} shell,
6231 @smallexample
6232 setenv EDITOR /usr/bin/vi
6233 gdb @dots{}
6234 @end smallexample
6235
6236 @node Search
6237 @section Searching Source Files
6238 @cindex searching source files
6239
6240 There are two commands for searching through the current source file for a
6241 regular expression.
6242
6243 @table @code
6244 @kindex search
6245 @kindex forward-search
6246 @item forward-search @var{regexp}
6247 @itemx search @var{regexp}
6248 The command @samp{forward-search @var{regexp}} checks each line,
6249 starting with the one following the last line listed, for a match for
6250 @var{regexp}. It lists the line that is found. You can use the
6251 synonym @samp{search @var{regexp}} or abbreviate the command name as
6252 @code{fo}.
6253
6254 @kindex reverse-search
6255 @item reverse-search @var{regexp}
6256 The command @samp{reverse-search @var{regexp}} checks each line, starting
6257 with the one before the last line listed and going backward, for a match
6258 for @var{regexp}. It lists the line that is found. You can abbreviate
6259 this command as @code{rev}.
6260 @end table
6261
6262 @node Source Path
6263 @section Specifying Source Directories
6264
6265 @cindex source path
6266 @cindex directories for source files
6267 Executable programs sometimes do not record the directories of the source
6268 files from which they were compiled, just the names. Even when they do,
6269 the directories could be moved between the compilation and your debugging
6270 session. @value{GDBN} has a list of directories to search for source files;
6271 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
6272 it tries all the directories in the list, in the order they are present
6273 in the list, until it finds a file with the desired name.
6274
6275 For example, suppose an executable references the file
6276 @file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
6277 @file{/mnt/cross}. The file is first looked up literally; if this
6278 fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
6279 fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
6280 message is printed. @value{GDBN} does not look up the parts of the
6281 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
6282 Likewise, the subdirectories of the source path are not searched: if
6283 the source path is @file{/mnt/cross}, and the binary refers to
6284 @file{foo.c}, @value{GDBN} would not find it under
6285 @file{/mnt/cross/usr/src/foo-1.0/lib}.
6286
6287 Plain file names, relative file names with leading directories, file
6288 names containing dots, etc.@: are all treated as described above; for
6289 instance, if the source path is @file{/mnt/cross}, and the source file
6290 is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
6291 @file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
6292 that---@file{/mnt/cross/foo.c}.
6293
6294 Note that the executable search path is @emph{not} used to locate the
6295 source files.
6296
6297 Whenever you reset or rearrange the source path, @value{GDBN} clears out
6298 any information it has cached about where source files are found and where
6299 each line is in the file.
6300
6301 @kindex directory
6302 @kindex dir
6303 When you start @value{GDBN}, its source path includes only @samp{cdir}
6304 and @samp{cwd}, in that order.
6305 To add other directories, use the @code{directory} command.
6306
6307 The search path is used to find both program source files and @value{GDBN}
6308 script files (read using the @samp{-command} option and @samp{source} command).
6309
6310 In addition to the source path, @value{GDBN} provides a set of commands
6311 that manage a list of source path substitution rules. A @dfn{substitution
6312 rule} specifies how to rewrite source directories stored in the program's
6313 debug information in case the sources were moved to a different
6314 directory between compilation and debugging. A rule is made of
6315 two strings, the first specifying what needs to be rewritten in
6316 the path, and the second specifying how it should be rewritten.
6317 In @ref{set substitute-path}, we name these two parts @var{from} and
6318 @var{to} respectively. @value{GDBN} does a simple string replacement
6319 of @var{from} with @var{to} at the start of the directory part of the
6320 source file name, and uses that result instead of the original file
6321 name to look up the sources.
6322
6323 Using the previous example, suppose the @file{foo-1.0} tree has been
6324 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
6325 @value{GDBN} to replace @file{/usr/src} in all source path names with
6326 @file{/mnt/cross}. The first lookup will then be
6327 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
6328 of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
6329 substitution rule, use the @code{set substitute-path} command
6330 (@pxref{set substitute-path}).
6331
6332 To avoid unexpected substitution results, a rule is applied only if the
6333 @var{from} part of the directory name ends at a directory separator.
6334 For instance, a rule substituting @file{/usr/source} into
6335 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
6336 not to @file{/usr/sourceware/foo-2.0}. And because the substitution
6337 is applied only at the beginning of the directory name, this rule will
6338 not be applied to @file{/root/usr/source/baz.c} either.
6339
6340 In many cases, you can achieve the same result using the @code{directory}
6341 command. However, @code{set substitute-path} can be more efficient in
6342 the case where the sources are organized in a complex tree with multiple
6343 subdirectories. With the @code{directory} command, you need to add each
6344 subdirectory of your project. If you moved the entire tree while
6345 preserving its internal organization, then @code{set substitute-path}
6346 allows you to direct the debugger to all the sources with one single
6347 command.
6348
6349 @code{set substitute-path} is also more than just a shortcut command.
6350 The source path is only used if the file at the original location no
6351 longer exists. On the other hand, @code{set substitute-path} modifies
6352 the debugger behavior to look at the rewritten location instead. So, if
6353 for any reason a source file that is not relevant to your executable is
6354 located at the original location, a substitution rule is the only
6355 method available to point @value{GDBN} at the new location.
6356
6357 @cindex @samp{--with-relocated-sources}
6358 @cindex default source path substitution
6359 You can configure a default source path substitution rule by
6360 configuring @value{GDBN} with the
6361 @samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
6362 should be the name of a directory under @value{GDBN}'s configured
6363 prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
6364 directory names in debug information under @var{dir} will be adjusted
6365 automatically if the installed @value{GDBN} is moved to a new
6366 location. This is useful if @value{GDBN}, libraries or executables
6367 with debug information and corresponding source code are being moved
6368 together.
6369
6370 @table @code
6371 @item directory @var{dirname} @dots{}
6372 @item dir @var{dirname} @dots{}
6373 Add directory @var{dirname} to the front of the source path. Several
6374 directory names may be given to this command, separated by @samp{:}
6375 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
6376 part of absolute file names) or
6377 whitespace. You may specify a directory that is already in the source
6378 path; this moves it forward, so @value{GDBN} searches it sooner.
6379
6380 @kindex cdir
6381 @kindex cwd
6382 @vindex $cdir@r{, convenience variable}
6383 @vindex $cwd@r{, convenience variable}
6384 @cindex compilation directory
6385 @cindex current directory
6386 @cindex working directory
6387 @cindex directory, current
6388 @cindex directory, compilation
6389 You can use the string @samp{$cdir} to refer to the compilation
6390 directory (if one is recorded), and @samp{$cwd} to refer to the current
6391 working directory. @samp{$cwd} is not the same as @samp{.}---the former
6392 tracks the current working directory as it changes during your @value{GDBN}
6393 session, while the latter is immediately expanded to the current
6394 directory at the time you add an entry to the source path.
6395
6396 @item directory
6397 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
6398
6399 @c RET-repeat for @code{directory} is explicitly disabled, but since
6400 @c repeating it would be a no-op we do not say that. (thanks to RMS)
6401
6402 @item show directories
6403 @kindex show directories
6404 Print the source path: show which directories it contains.
6405
6406 @anchor{set substitute-path}
6407 @item set substitute-path @var{from} @var{to}
6408 @kindex set substitute-path
6409 Define a source path substitution rule, and add it at the end of the
6410 current list of existing substitution rules. If a rule with the same
6411 @var{from} was already defined, then the old rule is also deleted.
6412
6413 For example, if the file @file{/foo/bar/baz.c} was moved to
6414 @file{/mnt/cross/baz.c}, then the command
6415
6416 @smallexample
6417 (@value{GDBP}) set substitute-path /usr/src /mnt/cross
6418 @end smallexample
6419
6420 @noindent
6421 will tell @value{GDBN} to replace @samp{/usr/src} with
6422 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
6423 @file{baz.c} even though it was moved.
6424
6425 In the case when more than one substitution rule have been defined,
6426 the rules are evaluated one by one in the order where they have been
6427 defined. The first one matching, if any, is selected to perform
6428 the substitution.
6429
6430 For instance, if we had entered the following commands:
6431
6432 @smallexample
6433 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
6434 (@value{GDBP}) set substitute-path /usr/src /mnt/src
6435 @end smallexample
6436
6437 @noindent
6438 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
6439 @file{/mnt/include/defs.h} by using the first rule. However, it would
6440 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
6441 @file{/mnt/src/lib/foo.c}.
6442
6443
6444 @item unset substitute-path [path]
6445 @kindex unset substitute-path
6446 If a path is specified, search the current list of substitution rules
6447 for a rule that would rewrite that path. Delete that rule if found.
6448 A warning is emitted by the debugger if no rule could be found.
6449
6450 If no path is specified, then all substitution rules are deleted.
6451
6452 @item show substitute-path [path]
6453 @kindex show substitute-path
6454 If a path is specified, then print the source path substitution rule
6455 which would rewrite that path, if any.
6456
6457 If no path is specified, then print all existing source path substitution
6458 rules.
6459
6460 @end table
6461
6462 If your source path is cluttered with directories that are no longer of
6463 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
6464 versions of source. You can correct the situation as follows:
6465
6466 @enumerate
6467 @item
6468 Use @code{directory} with no argument to reset the source path to its default value.
6469
6470 @item
6471 Use @code{directory} with suitable arguments to reinstall the
6472 directories you want in the source path. You can add all the
6473 directories in one command.
6474 @end enumerate
6475
6476 @node Machine Code
6477 @section Source and Machine Code
6478 @cindex source line and its code address
6479
6480 You can use the command @code{info line} to map source lines to program
6481 addresses (and vice versa), and the command @code{disassemble} to display
6482 a range of addresses as machine instructions. You can use the command
6483 @code{set disassemble-next-line} to set whether to disassemble next
6484 source line when execution stops. When run under @sc{gnu} Emacs
6485 mode, the @code{info line} command causes the arrow to point to the
6486 line specified. Also, @code{info line} prints addresses in symbolic form as
6487 well as hex.
6488
6489 @table @code
6490 @kindex info line
6491 @item info line @var{linespec}
6492 Print the starting and ending addresses of the compiled code for
6493 source line @var{linespec}. You can specify source lines in any of
6494 the ways documented in @ref{Specify Location}.
6495 @end table
6496
6497 For example, we can use @code{info line} to discover the location of
6498 the object code for the first line of function
6499 @code{m4_changequote}:
6500
6501 @c FIXME: I think this example should also show the addresses in
6502 @c symbolic form, as they usually would be displayed.
6503 @smallexample
6504 (@value{GDBP}) info line m4_changequote
6505 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
6506 @end smallexample
6507
6508 @noindent
6509 @cindex code address and its source line
6510 We can also inquire (using @code{*@var{addr}} as the form for
6511 @var{linespec}) what source line covers a particular address:
6512 @smallexample
6513 (@value{GDBP}) info line *0x63ff
6514 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
6515 @end smallexample
6516
6517 @cindex @code{$_} and @code{info line}
6518 @cindex @code{x} command, default address
6519 @kindex x@r{(examine), and} info line
6520 After @code{info line}, the default address for the @code{x} command
6521 is changed to the starting address of the line, so that @samp{x/i} is
6522 sufficient to begin examining the machine code (@pxref{Memory,
6523 ,Examining Memory}). Also, this address is saved as the value of the
6524 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
6525 Variables}).
6526
6527 @table @code
6528 @kindex disassemble
6529 @cindex assembly instructions
6530 @cindex instructions, assembly
6531 @cindex machine instructions
6532 @cindex listing machine instructions
6533 @item disassemble
6534 @itemx disassemble /m
6535 @itemx disassemble /r
6536 This specialized command dumps a range of memory as machine
6537 instructions. It can also print mixed source+disassembly by specifying
6538 the @code{/m} modifier and print the raw instructions in hex as well as
6539 in symbolic form by specifying the @code{/r}.
6540 The default memory range is the function surrounding the
6541 program counter of the selected frame. A single argument to this
6542 command is a program counter value; @value{GDBN} dumps the function
6543 surrounding this value. When two arguments are given, they should
6544 be separated by a comma, possibly surrounded by whitespace. The
6545 arguments specify a range of addresses (first inclusive, second exclusive)
6546 to dump. In that case, the name of the function is also printed (since
6547 there could be several functions in the given range).
6548
6549 The argument(s) can be any expression yielding a numeric value, such as
6550 @samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
6551
6552 If the range of memory being disassembled contains current program counter,
6553 the instruction at that location is shown with a @code{=>} marker.
6554 @end table
6555
6556 The following example shows the disassembly of a range of addresses of
6557 HP PA-RISC 2.0 code:
6558
6559 @smallexample
6560 (@value{GDBP}) disas 0x32c4, 0x32e4
6561 Dump of assembler code from 0x32c4 to 0x32e4:
6562 0x32c4 <main+204>: addil 0,dp
6563 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
6564 0x32cc <main+212>: ldil 0x3000,r31
6565 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
6566 0x32d4 <main+220>: ldo 0(r31),rp
6567 0x32d8 <main+224>: addil -0x800,dp
6568 0x32dc <main+228>: ldo 0x588(r1),r26
6569 0x32e0 <main+232>: ldil 0x3000,r31
6570 End of assembler dump.
6571 @end smallexample
6572
6573 Here is an example showing mixed source+assembly for Intel x86, when the
6574 program is stopped just after function prologue:
6575
6576 @smallexample
6577 (@value{GDBP}) disas /m main
6578 Dump of assembler code for function main:
6579 5 @{
6580 0x08048330 <+0>: push %ebp
6581 0x08048331 <+1>: mov %esp,%ebp
6582 0x08048333 <+3>: sub $0x8,%esp
6583 0x08048336 <+6>: and $0xfffffff0,%esp
6584 0x08048339 <+9>: sub $0x10,%esp
6585
6586 6 printf ("Hello.\n");
6587 => 0x0804833c <+12>: movl $0x8048440,(%esp)
6588 0x08048343 <+19>: call 0x8048284 <puts@@plt>
6589
6590 7 return 0;
6591 8 @}
6592 0x08048348 <+24>: mov $0x0,%eax
6593 0x0804834d <+29>: leave
6594 0x0804834e <+30>: ret
6595
6596 End of assembler dump.
6597 @end smallexample
6598
6599 Some architectures have more than one commonly-used set of instruction
6600 mnemonics or other syntax.
6601
6602 For programs that were dynamically linked and use shared libraries,
6603 instructions that call functions or branch to locations in the shared
6604 libraries might show a seemingly bogus location---it's actually a
6605 location of the relocation table. On some architectures, @value{GDBN}
6606 might be able to resolve these to actual function names.
6607
6608 @table @code
6609 @kindex set disassembly-flavor
6610 @cindex Intel disassembly flavor
6611 @cindex AT&T disassembly flavor
6612 @item set disassembly-flavor @var{instruction-set}
6613 Select the instruction set to use when disassembling the
6614 program via the @code{disassemble} or @code{x/i} commands.
6615
6616 Currently this command is only defined for the Intel x86 family. You
6617 can set @var{instruction-set} to either @code{intel} or @code{att}.
6618 The default is @code{att}, the AT&T flavor used by default by Unix
6619 assemblers for x86-based targets.
6620
6621 @kindex show disassembly-flavor
6622 @item show disassembly-flavor
6623 Show the current setting of the disassembly flavor.
6624 @end table
6625
6626 @table @code
6627 @kindex set disassemble-next-line
6628 @kindex show disassemble-next-line
6629 @item set disassemble-next-line
6630 @itemx show disassemble-next-line
6631 Control whether or not @value{GDBN} will disassemble the next source
6632 line or instruction when execution stops. If ON, @value{GDBN} will
6633 display disassembly of the next source line when execution of the
6634 program being debugged stops. This is @emph{in addition} to
6635 displaying the source line itself, which @value{GDBN} always does if
6636 possible. If the next source line cannot be displayed for some reason
6637 (e.g., if @value{GDBN} cannot find the source file, or there's no line
6638 info in the debug info), @value{GDBN} will display disassembly of the
6639 next @emph{instruction} instead of showing the next source line. If
6640 AUTO, @value{GDBN} will display disassembly of next instruction only
6641 if the source line cannot be displayed. This setting causes
6642 @value{GDBN} to display some feedback when you step through a function
6643 with no line info or whose source file is unavailable. The default is
6644 OFF, which means never display the disassembly of the next line or
6645 instruction.
6646 @end table
6647
6648
6649 @node Data
6650 @chapter Examining Data
6651
6652 @cindex printing data
6653 @cindex examining data
6654 @kindex print
6655 @kindex inspect
6656 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
6657 @c document because it is nonstandard... Under Epoch it displays in a
6658 @c different window or something like that.
6659 The usual way to examine data in your program is with the @code{print}
6660 command (abbreviated @code{p}), or its synonym @code{inspect}. It
6661 evaluates and prints the value of an expression of the language your
6662 program is written in (@pxref{Languages, ,Using @value{GDBN} with
6663 Different Languages}).
6664
6665 @table @code
6666 @item print @var{expr}
6667 @itemx print /@var{f} @var{expr}
6668 @var{expr} is an expression (in the source language). By default the
6669 value of @var{expr} is printed in a format appropriate to its data type;
6670 you can choose a different format by specifying @samp{/@var{f}}, where
6671 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
6672 Formats}.
6673
6674 @item print
6675 @itemx print /@var{f}
6676 @cindex reprint the last value
6677 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
6678 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
6679 conveniently inspect the same value in an alternative format.
6680 @end table
6681
6682 A more low-level way of examining data is with the @code{x} command.
6683 It examines data in memory at a specified address and prints it in a
6684 specified format. @xref{Memory, ,Examining Memory}.
6685
6686 If you are interested in information about types, or about how the
6687 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
6688 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
6689 Table}.
6690
6691 @menu
6692 * Expressions:: Expressions
6693 * Ambiguous Expressions:: Ambiguous Expressions
6694 * Variables:: Program variables
6695 * Arrays:: Artificial arrays
6696 * Output Formats:: Output formats
6697 * Memory:: Examining memory
6698 * Auto Display:: Automatic display
6699 * Print Settings:: Print settings
6700 * Value History:: Value history
6701 * Convenience Vars:: Convenience variables
6702 * Registers:: Registers
6703 * Floating Point Hardware:: Floating point hardware
6704 * Vector Unit:: Vector Unit
6705 * OS Information:: Auxiliary data provided by operating system
6706 * Memory Region Attributes:: Memory region attributes
6707 * Dump/Restore Files:: Copy between memory and a file
6708 * Core File Generation:: Cause a program dump its core
6709 * Character Sets:: Debugging programs that use a different
6710 character set than GDB does
6711 * Caching Remote Data:: Data caching for remote targets
6712 * Searching Memory:: Searching memory for a sequence of bytes
6713 @end menu
6714
6715 @node Expressions
6716 @section Expressions
6717
6718 @cindex expressions
6719 @code{print} and many other @value{GDBN} commands accept an expression and
6720 compute its value. Any kind of constant, variable or operator defined
6721 by the programming language you are using is valid in an expression in
6722 @value{GDBN}. This includes conditional expressions, function calls,
6723 casts, and string constants. It also includes preprocessor macros, if
6724 you compiled your program to include this information; see
6725 @ref{Compilation}.
6726
6727 @cindex arrays in expressions
6728 @value{GDBN} supports array constants in expressions input by
6729 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
6730 you can use the command @code{print @{1, 2, 3@}} to create an array
6731 of three integers. If you pass an array to a function or assign it
6732 to a program variable, @value{GDBN} copies the array to memory that
6733 is @code{malloc}ed in the target program.
6734
6735 Because C is so widespread, most of the expressions shown in examples in
6736 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
6737 Languages}, for information on how to use expressions in other
6738 languages.
6739
6740 In this section, we discuss operators that you can use in @value{GDBN}
6741 expressions regardless of your programming language.
6742
6743 @cindex casts, in expressions
6744 Casts are supported in all languages, not just in C, because it is so
6745 useful to cast a number into a pointer in order to examine a structure
6746 at that address in memory.
6747 @c FIXME: casts supported---Mod2 true?
6748
6749 @value{GDBN} supports these operators, in addition to those common
6750 to programming languages:
6751
6752 @table @code
6753 @item @@
6754 @samp{@@} is a binary operator for treating parts of memory as arrays.
6755 @xref{Arrays, ,Artificial Arrays}, for more information.
6756
6757 @item ::
6758 @samp{::} allows you to specify a variable in terms of the file or
6759 function where it is defined. @xref{Variables, ,Program Variables}.
6760
6761 @cindex @{@var{type}@}
6762 @cindex type casting memory
6763 @cindex memory, viewing as typed object
6764 @cindex casts, to view memory
6765 @item @{@var{type}@} @var{addr}
6766 Refers to an object of type @var{type} stored at address @var{addr} in
6767 memory. @var{addr} may be any expression whose value is an integer or
6768 pointer (but parentheses are required around binary operators, just as in
6769 a cast). This construct is allowed regardless of what kind of data is
6770 normally supposed to reside at @var{addr}.
6771 @end table
6772
6773 @node Ambiguous Expressions
6774 @section Ambiguous Expressions
6775 @cindex ambiguous expressions
6776
6777 Expressions can sometimes contain some ambiguous elements. For instance,
6778 some programming languages (notably Ada, C@t{++} and Objective-C) permit
6779 a single function name to be defined several times, for application in
6780 different contexts. This is called @dfn{overloading}. Another example
6781 involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
6782 templates and is typically instantiated several times, resulting in
6783 the same function name being defined in different contexts.
6784
6785 In some cases and depending on the language, it is possible to adjust
6786 the expression to remove the ambiguity. For instance in C@t{++}, you
6787 can specify the signature of the function you want to break on, as in
6788 @kbd{break @var{function}(@var{types})}. In Ada, using the fully
6789 qualified name of your function often makes the expression unambiguous
6790 as well.
6791
6792 When an ambiguity that needs to be resolved is detected, the debugger
6793 has the capability to display a menu of numbered choices for each
6794 possibility, and then waits for the selection with the prompt @samp{>}.
6795 The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
6796 aborts the current command. If the command in which the expression was
6797 used allows more than one choice to be selected, the next option in the
6798 menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
6799 choices.
6800
6801 For example, the following session excerpt shows an attempt to set a
6802 breakpoint at the overloaded symbol @code{String::after}.
6803 We choose three particular definitions of that function name:
6804
6805 @c FIXME! This is likely to change to show arg type lists, at least
6806 @smallexample
6807 @group
6808 (@value{GDBP}) b String::after
6809 [0] cancel
6810 [1] all
6811 [2] file:String.cc; line number:867
6812 [3] file:String.cc; line number:860
6813 [4] file:String.cc; line number:875
6814 [5] file:String.cc; line number:853
6815 [6] file:String.cc; line number:846
6816 [7] file:String.cc; line number:735
6817 > 2 4 6
6818 Breakpoint 1 at 0xb26c: file String.cc, line 867.
6819 Breakpoint 2 at 0xb344: file String.cc, line 875.
6820 Breakpoint 3 at 0xafcc: file String.cc, line 846.
6821 Multiple breakpoints were set.
6822 Use the "delete" command to delete unwanted
6823 breakpoints.
6824 (@value{GDBP})
6825 @end group
6826 @end smallexample
6827
6828 @table @code
6829 @kindex set multiple-symbols
6830 @item set multiple-symbols @var{mode}
6831 @cindex multiple-symbols menu
6832
6833 This option allows you to adjust the debugger behavior when an expression
6834 is ambiguous.
6835
6836 By default, @var{mode} is set to @code{all}. If the command with which
6837 the expression is used allows more than one choice, then @value{GDBN}
6838 automatically selects all possible choices. For instance, inserting
6839 a breakpoint on a function using an ambiguous name results in a breakpoint
6840 inserted on each possible match. However, if a unique choice must be made,
6841 then @value{GDBN} uses the menu to help you disambiguate the expression.
6842 For instance, printing the address of an overloaded function will result
6843 in the use of the menu.
6844
6845 When @var{mode} is set to @code{ask}, the debugger always uses the menu
6846 when an ambiguity is detected.
6847
6848 Finally, when @var{mode} is set to @code{cancel}, the debugger reports
6849 an error due to the ambiguity and the command is aborted.
6850
6851 @kindex show multiple-symbols
6852 @item show multiple-symbols
6853 Show the current value of the @code{multiple-symbols} setting.
6854 @end table
6855
6856 @node Variables
6857 @section Program Variables
6858
6859 The most common kind of expression to use is the name of a variable
6860 in your program.
6861
6862 Variables in expressions are understood in the selected stack frame
6863 (@pxref{Selection, ,Selecting a Frame}); they must be either:
6864
6865 @itemize @bullet
6866 @item
6867 global (or file-static)
6868 @end itemize
6869
6870 @noindent or
6871
6872 @itemize @bullet
6873 @item
6874 visible according to the scope rules of the
6875 programming language from the point of execution in that frame
6876 @end itemize
6877
6878 @noindent This means that in the function
6879
6880 @smallexample
6881 foo (a)
6882 int a;
6883 @{
6884 bar (a);
6885 @{
6886 int b = test ();
6887 bar (b);
6888 @}
6889 @}
6890 @end smallexample
6891
6892 @noindent
6893 you can examine and use the variable @code{a} whenever your program is
6894 executing within the function @code{foo}, but you can only use or
6895 examine the variable @code{b} while your program is executing inside
6896 the block where @code{b} is declared.
6897
6898 @cindex variable name conflict
6899 There is an exception: you can refer to a variable or function whose
6900 scope is a single source file even if the current execution point is not
6901 in this file. But it is possible to have more than one such variable or
6902 function with the same name (in different source files). If that
6903 happens, referring to that name has unpredictable effects. If you wish,
6904 you can specify a static variable in a particular function or file,
6905 using the colon-colon (@code{::}) notation:
6906
6907 @cindex colon-colon, context for variables/functions
6908 @ifnotinfo
6909 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
6910 @cindex @code{::}, context for variables/functions
6911 @end ifnotinfo
6912 @smallexample
6913 @var{file}::@var{variable}
6914 @var{function}::@var{variable}
6915 @end smallexample
6916
6917 @noindent
6918 Here @var{file} or @var{function} is the name of the context for the
6919 static @var{variable}. In the case of file names, you can use quotes to
6920 make sure @value{GDBN} parses the file name as a single word---for example,
6921 to print a global value of @code{x} defined in @file{f2.c}:
6922
6923 @smallexample
6924 (@value{GDBP}) p 'f2.c'::x
6925 @end smallexample
6926
6927 @cindex C@t{++} scope resolution
6928 This use of @samp{::} is very rarely in conflict with the very similar
6929 use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
6930 scope resolution operator in @value{GDBN} expressions.
6931 @c FIXME: Um, so what happens in one of those rare cases where it's in
6932 @c conflict?? --mew
6933
6934 @cindex wrong values
6935 @cindex variable values, wrong
6936 @cindex function entry/exit, wrong values of variables
6937 @cindex optimized code, wrong values of variables
6938 @quotation
6939 @emph{Warning:} Occasionally, a local variable may appear to have the
6940 wrong value at certain points in a function---just after entry to a new
6941 scope, and just before exit.
6942 @end quotation
6943 You may see this problem when you are stepping by machine instructions.
6944 This is because, on most machines, it takes more than one instruction to
6945 set up a stack frame (including local variable definitions); if you are
6946 stepping by machine instructions, variables may appear to have the wrong
6947 values until the stack frame is completely built. On exit, it usually
6948 also takes more than one machine instruction to destroy a stack frame;
6949 after you begin stepping through that group of instructions, local
6950 variable definitions may be gone.
6951
6952 This may also happen when the compiler does significant optimizations.
6953 To be sure of always seeing accurate values, turn off all optimization
6954 when compiling.
6955
6956 @cindex ``No symbol "foo" in current context''
6957 Another possible effect of compiler optimizations is to optimize
6958 unused variables out of existence, or assign variables to registers (as
6959 opposed to memory addresses). Depending on the support for such cases
6960 offered by the debug info format used by the compiler, @value{GDBN}
6961 might not be able to display values for such local variables. If that
6962 happens, @value{GDBN} will print a message like this:
6963
6964 @smallexample
6965 No symbol "foo" in current context.
6966 @end smallexample
6967
6968 To solve such problems, either recompile without optimizations, or use a
6969 different debug info format, if the compiler supports several such
6970 formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
6971 usually supports the @option{-gstabs+} option. @option{-gstabs+}
6972 produces debug info in a format that is superior to formats such as
6973 COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
6974 an effective form for debug info. @xref{Debugging Options,,Options
6975 for Debugging Your Program or GCC, gcc.info, Using the @sc{gnu}
6976 Compiler Collection (GCC)}.
6977 @xref{C, ,C and C@t{++}}, for more information about debug info formats
6978 that are best suited to C@t{++} programs.
6979
6980 If you ask to print an object whose contents are unknown to
6981 @value{GDBN}, e.g., because its data type is not completely specified
6982 by the debug information, @value{GDBN} will say @samp{<incomplete
6983 type>}. @xref{Symbols, incomplete type}, for more about this.
6984
6985 Strings are identified as arrays of @code{char} values without specified
6986 signedness. Arrays of either @code{signed char} or @code{unsigned char} get
6987 printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
6988 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
6989 defines literal string type @code{"char"} as @code{char} without a sign.
6990 For program code
6991
6992 @smallexample
6993 char var0[] = "A";
6994 signed char var1[] = "A";
6995 @end smallexample
6996
6997 You get during debugging
6998 @smallexample
6999 (gdb) print var0
7000 $1 = "A"
7001 (gdb) print var1
7002 $2 = @{65 'A', 0 '\0'@}
7003 @end smallexample
7004
7005 @node Arrays
7006 @section Artificial Arrays
7007
7008 @cindex artificial array
7009 @cindex arrays
7010 @kindex @@@r{, referencing memory as an array}
7011 It is often useful to print out several successive objects of the
7012 same type in memory; a section of an array, or an array of
7013 dynamically determined size for which only a pointer exists in the
7014 program.
7015
7016 You can do this by referring to a contiguous span of memory as an
7017 @dfn{artificial array}, using the binary operator @samp{@@}. The left
7018 operand of @samp{@@} should be the first element of the desired array
7019 and be an individual object. The right operand should be the desired length
7020 of the array. The result is an array value whose elements are all of
7021 the type of the left argument. The first element is actually the left
7022 argument; the second element comes from bytes of memory immediately
7023 following those that hold the first element, and so on. Here is an
7024 example. If a program says
7025
7026 @smallexample
7027 int *array = (int *) malloc (len * sizeof (int));
7028 @end smallexample
7029
7030 @noindent
7031 you can print the contents of @code{array} with
7032
7033 @smallexample
7034 p *array@@len
7035 @end smallexample
7036
7037 The left operand of @samp{@@} must reside in memory. Array values made
7038 with @samp{@@} in this way behave just like other arrays in terms of
7039 subscripting, and are coerced to pointers when used in expressions.
7040 Artificial arrays most often appear in expressions via the value history
7041 (@pxref{Value History, ,Value History}), after printing one out.
7042
7043 Another way to create an artificial array is to use a cast.
7044 This re-interprets a value as if it were an array.
7045 The value need not be in memory:
7046 @smallexample
7047 (@value{GDBP}) p/x (short[2])0x12345678
7048 $1 = @{0x1234, 0x5678@}
7049 @end smallexample
7050
7051 As a convenience, if you leave the array length out (as in
7052 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
7053 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
7054 @smallexample
7055 (@value{GDBP}) p/x (short[])0x12345678
7056 $2 = @{0x1234, 0x5678@}
7057 @end smallexample
7058
7059 Sometimes the artificial array mechanism is not quite enough; in
7060 moderately complex data structures, the elements of interest may not
7061 actually be adjacent---for example, if you are interested in the values
7062 of pointers in an array. One useful work-around in this situation is
7063 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
7064 Variables}) as a counter in an expression that prints the first
7065 interesting value, and then repeat that expression via @key{RET}. For
7066 instance, suppose you have an array @code{dtab} of pointers to
7067 structures, and you are interested in the values of a field @code{fv}
7068 in each structure. Here is an example of what you might type:
7069
7070 @smallexample
7071 set $i = 0
7072 p dtab[$i++]->fv
7073 @key{RET}
7074 @key{RET}
7075 @dots{}
7076 @end smallexample
7077
7078 @node Output Formats
7079 @section Output Formats
7080
7081 @cindex formatted output
7082 @cindex output formats
7083 By default, @value{GDBN} prints a value according to its data type. Sometimes
7084 this is not what you want. For example, you might want to print a number
7085 in hex, or a pointer in decimal. Or you might want to view data in memory
7086 at a certain address as a character string or as an instruction. To do
7087 these things, specify an @dfn{output format} when you print a value.
7088
7089 The simplest use of output formats is to say how to print a value
7090 already computed. This is done by starting the arguments of the
7091 @code{print} command with a slash and a format letter. The format
7092 letters supported are:
7093
7094 @table @code
7095 @item x
7096 Regard the bits of the value as an integer, and print the integer in
7097 hexadecimal.
7098
7099 @item d
7100 Print as integer in signed decimal.
7101
7102 @item u
7103 Print as integer in unsigned decimal.
7104
7105 @item o
7106 Print as integer in octal.
7107
7108 @item t
7109 Print as integer in binary. The letter @samp{t} stands for ``two''.
7110 @footnote{@samp{b} cannot be used because these format letters are also
7111 used with the @code{x} command, where @samp{b} stands for ``byte'';
7112 see @ref{Memory,,Examining Memory}.}
7113
7114 @item a
7115 @cindex unknown address, locating
7116 @cindex locate address
7117 Print as an address, both absolute in hexadecimal and as an offset from
7118 the nearest preceding symbol. You can use this format used to discover
7119 where (in what function) an unknown address is located:
7120
7121 @smallexample
7122 (@value{GDBP}) p/a 0x54320
7123 $3 = 0x54320 <_initialize_vx+396>
7124 @end smallexample
7125
7126 @noindent
7127 The command @code{info symbol 0x54320} yields similar results.
7128 @xref{Symbols, info symbol}.
7129
7130 @item c
7131 Regard as an integer and print it as a character constant. This
7132 prints both the numerical value and its character representation. The
7133 character representation is replaced with the octal escape @samp{\nnn}
7134 for characters outside the 7-bit @sc{ascii} range.
7135
7136 Without this format, @value{GDBN} displays @code{char},
7137 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
7138 constants. Single-byte members of vectors are displayed as integer
7139 data.
7140
7141 @item f
7142 Regard the bits of the value as a floating point number and print
7143 using typical floating point syntax.
7144
7145 @item s
7146 @cindex printing strings
7147 @cindex printing byte arrays
7148 Regard as a string, if possible. With this format, pointers to single-byte
7149 data are displayed as null-terminated strings and arrays of single-byte data
7150 are displayed as fixed-length strings. Other values are displayed in their
7151 natural types.
7152
7153 Without this format, @value{GDBN} displays pointers to and arrays of
7154 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
7155 strings. Single-byte members of a vector are displayed as an integer
7156 array.
7157
7158 @item r
7159 @cindex raw printing
7160 Print using the @samp{raw} formatting. By default, @value{GDBN} will
7161 use a type-specific pretty-printer. The @samp{r} format bypasses any
7162 pretty-printer which might exist for the value's type.
7163 @end table
7164
7165 For example, to print the program counter in hex (@pxref{Registers}), type
7166
7167 @smallexample
7168 p/x $pc
7169 @end smallexample
7170
7171 @noindent
7172 Note that no space is required before the slash; this is because command
7173 names in @value{GDBN} cannot contain a slash.
7174
7175 To reprint the last value in the value history with a different format,
7176 you can use the @code{print} command with just a format and no
7177 expression. For example, @samp{p/x} reprints the last value in hex.
7178
7179 @node Memory
7180 @section Examining Memory
7181
7182 You can use the command @code{x} (for ``examine'') to examine memory in
7183 any of several formats, independently of your program's data types.
7184
7185 @cindex examining memory
7186 @table @code
7187 @kindex x @r{(examine memory)}
7188 @item x/@var{nfu} @var{addr}
7189 @itemx x @var{addr}
7190 @itemx x
7191 Use the @code{x} command to examine memory.
7192 @end table
7193
7194 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
7195 much memory to display and how to format it; @var{addr} is an
7196 expression giving the address where you want to start displaying memory.
7197 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
7198 Several commands set convenient defaults for @var{addr}.
7199
7200 @table @r
7201 @item @var{n}, the repeat count
7202 The repeat count is a decimal integer; the default is 1. It specifies
7203 how much memory (counting by units @var{u}) to display.
7204 @c This really is **decimal**; unaffected by 'set radix' as of GDB
7205 @c 4.1.2.
7206
7207 @item @var{f}, the display format
7208 The display format is one of the formats used by @code{print}
7209 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
7210 @samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
7211 The default is @samp{x} (hexadecimal) initially. The default changes
7212 each time you use either @code{x} or @code{print}.
7213
7214 @item @var{u}, the unit size
7215 The unit size is any of
7216
7217 @table @code
7218 @item b
7219 Bytes.
7220 @item h
7221 Halfwords (two bytes).
7222 @item w
7223 Words (four bytes). This is the initial default.
7224 @item g
7225 Giant words (eight bytes).
7226 @end table
7227
7228 Each time you specify a unit size with @code{x}, that size becomes the
7229 default unit the next time you use @code{x}. (For the @samp{s} and
7230 @samp{i} formats, the unit size is ignored and is normally not written.)
7231
7232 @item @var{addr}, starting display address
7233 @var{addr} is the address where you want @value{GDBN} to begin displaying
7234 memory. The expression need not have a pointer value (though it may);
7235 it is always interpreted as an integer address of a byte of memory.
7236 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
7237 @var{addr} is usually just after the last address examined---but several
7238 other commands also set the default address: @code{info breakpoints} (to
7239 the address of the last breakpoint listed), @code{info line} (to the
7240 starting address of a line), and @code{print} (if you use it to display
7241 a value from memory).
7242 @end table
7243
7244 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
7245 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
7246 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
7247 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
7248 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
7249
7250 Since the letters indicating unit sizes are all distinct from the
7251 letters specifying output formats, you do not have to remember whether
7252 unit size or format comes first; either order works. The output
7253 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
7254 (However, the count @var{n} must come first; @samp{wx4} does not work.)
7255
7256 Even though the unit size @var{u} is ignored for the formats @samp{s}
7257 and @samp{i}, you might still want to use a count @var{n}; for example,
7258 @samp{3i} specifies that you want to see three machine instructions,
7259 including any operands. For convenience, especially when used with
7260 the @code{display} command, the @samp{i} format also prints branch delay
7261 slot instructions, if any, beyond the count specified, which immediately
7262 follow the last instruction that is within the count. The command
7263 @code{disassemble} gives an alternative way of inspecting machine
7264 instructions; see @ref{Machine Code,,Source and Machine Code}.
7265
7266 All the defaults for the arguments to @code{x} are designed to make it
7267 easy to continue scanning memory with minimal specifications each time
7268 you use @code{x}. For example, after you have inspected three machine
7269 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
7270 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
7271 the repeat count @var{n} is used again; the other arguments default as
7272 for successive uses of @code{x}.
7273
7274 When examining machine instructions, the instruction at current program
7275 counter is shown with a @code{=>} marker. For example:
7276
7277 @smallexample
7278 (@value{GDBP}) x/5i $pc-6
7279 0x804837f <main+11>: mov %esp,%ebp
7280 0x8048381 <main+13>: push %ecx
7281 0x8048382 <main+14>: sub $0x4,%esp
7282 => 0x8048385 <main+17>: movl $0x8048460,(%esp)
7283 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
7284 @end smallexample
7285
7286 @cindex @code{$_}, @code{$__}, and value history
7287 The addresses and contents printed by the @code{x} command are not saved
7288 in the value history because there is often too much of them and they
7289 would get in the way. Instead, @value{GDBN} makes these values available for
7290 subsequent use in expressions as values of the convenience variables
7291 @code{$_} and @code{$__}. After an @code{x} command, the last address
7292 examined is available for use in expressions in the convenience variable
7293 @code{$_}. The contents of that address, as examined, are available in
7294 the convenience variable @code{$__}.
7295
7296 If the @code{x} command has a repeat count, the address and contents saved
7297 are from the last memory unit printed; this is not the same as the last
7298 address printed if several units were printed on the last line of output.
7299
7300 @cindex remote memory comparison
7301 @cindex verify remote memory image
7302 When you are debugging a program running on a remote target machine
7303 (@pxref{Remote Debugging}), you may wish to verify the program's image in the
7304 remote machine's memory against the executable file you downloaded to
7305 the target. The @code{compare-sections} command is provided for such
7306 situations.
7307
7308 @table @code
7309 @kindex compare-sections
7310 @item compare-sections @r{[}@var{section-name}@r{]}
7311 Compare the data of a loadable section @var{section-name} in the
7312 executable file of the program being debugged with the same section in
7313 the remote machine's memory, and report any mismatches. With no
7314 arguments, compares all loadable sections. This command's
7315 availability depends on the target's support for the @code{"qCRC"}
7316 remote request.
7317 @end table
7318
7319 @node Auto Display
7320 @section Automatic Display
7321 @cindex automatic display
7322 @cindex display of expressions
7323
7324 If you find that you want to print the value of an expression frequently
7325 (to see how it changes), you might want to add it to the @dfn{automatic
7326 display list} so that @value{GDBN} prints its value each time your program stops.
7327 Each expression added to the list is given a number to identify it;
7328 to remove an expression from the list, you specify that number.
7329 The automatic display looks like this:
7330
7331 @smallexample
7332 2: foo = 38
7333 3: bar[5] = (struct hack *) 0x3804
7334 @end smallexample
7335
7336 @noindent
7337 This display shows item numbers, expressions and their current values. As with
7338 displays you request manually using @code{x} or @code{print}, you can
7339 specify the output format you prefer; in fact, @code{display} decides
7340 whether to use @code{print} or @code{x} depending your format
7341 specification---it uses @code{x} if you specify either the @samp{i}
7342 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
7343
7344 @table @code
7345 @kindex display
7346 @item display @var{expr}
7347 Add the expression @var{expr} to the list of expressions to display
7348 each time your program stops. @xref{Expressions, ,Expressions}.
7349
7350 @code{display} does not repeat if you press @key{RET} again after using it.
7351
7352 @item display/@var{fmt} @var{expr}
7353 For @var{fmt} specifying only a display format and not a size or
7354 count, add the expression @var{expr} to the auto-display list but
7355 arrange to display it each time in the specified format @var{fmt}.
7356 @xref{Output Formats,,Output Formats}.
7357
7358 @item display/@var{fmt} @var{addr}
7359 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
7360 number of units, add the expression @var{addr} as a memory address to
7361 be examined each time your program stops. Examining means in effect
7362 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
7363 @end table
7364
7365 For example, @samp{display/i $pc} can be helpful, to see the machine
7366 instruction about to be executed each time execution stops (@samp{$pc}
7367 is a common name for the program counter; @pxref{Registers, ,Registers}).
7368
7369 @table @code
7370 @kindex delete display
7371 @kindex undisplay
7372 @item undisplay @var{dnums}@dots{}
7373 @itemx delete display @var{dnums}@dots{}
7374 Remove item numbers @var{dnums} from the list of expressions to display.
7375
7376 @code{undisplay} does not repeat if you press @key{RET} after using it.
7377 (Otherwise you would just get the error @samp{No display number @dots{}}.)
7378
7379 @kindex disable display
7380 @item disable display @var{dnums}@dots{}
7381 Disable the display of item numbers @var{dnums}. A disabled display
7382 item is not printed automatically, but is not forgotten. It may be
7383 enabled again later.
7384
7385 @kindex enable display
7386 @item enable display @var{dnums}@dots{}
7387 Enable display of item numbers @var{dnums}. It becomes effective once
7388 again in auto display of its expression, until you specify otherwise.
7389
7390 @item display
7391 Display the current values of the expressions on the list, just as is
7392 done when your program stops.
7393
7394 @kindex info display
7395 @item info display
7396 Print the list of expressions previously set up to display
7397 automatically, each one with its item number, but without showing the
7398 values. This includes disabled expressions, which are marked as such.
7399 It also includes expressions which would not be displayed right now
7400 because they refer to automatic variables not currently available.
7401 @end table
7402
7403 @cindex display disabled out of scope
7404 If a display expression refers to local variables, then it does not make
7405 sense outside the lexical context for which it was set up. Such an
7406 expression is disabled when execution enters a context where one of its
7407 variables is not defined. For example, if you give the command
7408 @code{display last_char} while inside a function with an argument
7409 @code{last_char}, @value{GDBN} displays this argument while your program
7410 continues to stop inside that function. When it stops elsewhere---where
7411 there is no variable @code{last_char}---the display is disabled
7412 automatically. The next time your program stops where @code{last_char}
7413 is meaningful, you can enable the display expression once again.
7414
7415 @node Print Settings
7416 @section Print Settings
7417
7418 @cindex format options
7419 @cindex print settings
7420 @value{GDBN} provides the following ways to control how arrays, structures,
7421 and symbols are printed.
7422
7423 @noindent
7424 These settings are useful for debugging programs in any language:
7425
7426 @table @code
7427 @kindex set print
7428 @item set print address
7429 @itemx set print address on
7430 @cindex print/don't print memory addresses
7431 @value{GDBN} prints memory addresses showing the location of stack
7432 traces, structure values, pointer values, breakpoints, and so forth,
7433 even when it also displays the contents of those addresses. The default
7434 is @code{on}. For example, this is what a stack frame display looks like with
7435 @code{set print address on}:
7436
7437 @smallexample
7438 @group
7439 (@value{GDBP}) f
7440 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
7441 at input.c:530
7442 530 if (lquote != def_lquote)
7443 @end group
7444 @end smallexample
7445
7446 @item set print address off
7447 Do not print addresses when displaying their contents. For example,
7448 this is the same stack frame displayed with @code{set print address off}:
7449
7450 @smallexample
7451 @group
7452 (@value{GDBP}) set print addr off
7453 (@value{GDBP}) f
7454 #0 set_quotes (lq="<<", rq=">>") at input.c:530
7455 530 if (lquote != def_lquote)
7456 @end group
7457 @end smallexample
7458
7459 You can use @samp{set print address off} to eliminate all machine
7460 dependent displays from the @value{GDBN} interface. For example, with
7461 @code{print address off}, you should get the same text for backtraces on
7462 all machines---whether or not they involve pointer arguments.
7463
7464 @kindex show print
7465 @item show print address
7466 Show whether or not addresses are to be printed.
7467 @end table
7468
7469 When @value{GDBN} prints a symbolic address, it normally prints the
7470 closest earlier symbol plus an offset. If that symbol does not uniquely
7471 identify the address (for example, it is a name whose scope is a single
7472 source file), you may need to clarify. One way to do this is with
7473 @code{info line}, for example @samp{info line *0x4537}. Alternately,
7474 you can set @value{GDBN} to print the source file and line number when
7475 it prints a symbolic address:
7476
7477 @table @code
7478 @item set print symbol-filename on
7479 @cindex source file and line of a symbol
7480 @cindex symbol, source file and line
7481 Tell @value{GDBN} to print the source file name and line number of a
7482 symbol in the symbolic form of an address.
7483
7484 @item set print symbol-filename off
7485 Do not print source file name and line number of a symbol. This is the
7486 default.
7487
7488 @item show print symbol-filename
7489 Show whether or not @value{GDBN} will print the source file name and
7490 line number of a symbol in the symbolic form of an address.
7491 @end table
7492
7493 Another situation where it is helpful to show symbol filenames and line
7494 numbers is when disassembling code; @value{GDBN} shows you the line
7495 number and source file that corresponds to each instruction.
7496
7497 Also, you may wish to see the symbolic form only if the address being
7498 printed is reasonably close to the closest earlier symbol:
7499
7500 @table @code
7501 @item set print max-symbolic-offset @var{max-offset}
7502 @cindex maximum value for offset of closest symbol
7503 Tell @value{GDBN} to only display the symbolic form of an address if the
7504 offset between the closest earlier symbol and the address is less than
7505 @var{max-offset}. The default is 0, which tells @value{GDBN}
7506 to always print the symbolic form of an address if any symbol precedes it.
7507
7508 @item show print max-symbolic-offset
7509 Ask how large the maximum offset is that @value{GDBN} prints in a
7510 symbolic address.
7511 @end table
7512
7513 @cindex wild pointer, interpreting
7514 @cindex pointer, finding referent
7515 If you have a pointer and you are not sure where it points, try
7516 @samp{set print symbol-filename on}. Then you can determine the name
7517 and source file location of the variable where it points, using
7518 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
7519 For example, here @value{GDBN} shows that a variable @code{ptt} points
7520 at another variable @code{t}, defined in @file{hi2.c}:
7521
7522 @smallexample
7523 (@value{GDBP}) set print symbol-filename on
7524 (@value{GDBP}) p/a ptt
7525 $4 = 0xe008 <t in hi2.c>
7526 @end smallexample
7527
7528 @quotation
7529 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
7530 does not show the symbol name and filename of the referent, even with
7531 the appropriate @code{set print} options turned on.
7532 @end quotation
7533
7534 Other settings control how different kinds of objects are printed:
7535
7536 @table @code
7537 @item set print array
7538 @itemx set print array on
7539 @cindex pretty print arrays
7540 Pretty print arrays. This format is more convenient to read,
7541 but uses more space. The default is off.
7542
7543 @item set print array off
7544 Return to compressed format for arrays.
7545
7546 @item show print array
7547 Show whether compressed or pretty format is selected for displaying
7548 arrays.
7549
7550 @cindex print array indexes
7551 @item set print array-indexes
7552 @itemx set print array-indexes on
7553 Print the index of each element when displaying arrays. May be more
7554 convenient to locate a given element in the array or quickly find the
7555 index of a given element in that printed array. The default is off.
7556
7557 @item set print array-indexes off
7558 Stop printing element indexes when displaying arrays.
7559
7560 @item show print array-indexes
7561 Show whether the index of each element is printed when displaying
7562 arrays.
7563
7564 @item set print elements @var{number-of-elements}
7565 @cindex number of array elements to print
7566 @cindex limit on number of printed array elements
7567 Set a limit on how many elements of an array @value{GDBN} will print.
7568 If @value{GDBN} is printing a large array, it stops printing after it has
7569 printed the number of elements set by the @code{set print elements} command.
7570 This limit also applies to the display of strings.
7571 When @value{GDBN} starts, this limit is set to 200.
7572 Setting @var{number-of-elements} to zero means that the printing is unlimited.
7573
7574 @item show print elements
7575 Display the number of elements of a large array that @value{GDBN} will print.
7576 If the number is 0, then the printing is unlimited.
7577
7578 @item set print frame-arguments @var{value}
7579 @kindex set print frame-arguments
7580 @cindex printing frame argument values
7581 @cindex print all frame argument values
7582 @cindex print frame argument values for scalars only
7583 @cindex do not print frame argument values
7584 This command allows to control how the values of arguments are printed
7585 when the debugger prints a frame (@pxref{Frames}). The possible
7586 values are:
7587
7588 @table @code
7589 @item all
7590 The values of all arguments are printed.
7591
7592 @item scalars
7593 Print the value of an argument only if it is a scalar. The value of more
7594 complex arguments such as arrays, structures, unions, etc, is replaced
7595 by @code{@dots{}}. This is the default. Here is an example where
7596 only scalar arguments are shown:
7597
7598 @smallexample
7599 #1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
7600 at frame-args.c:23
7601 @end smallexample
7602
7603 @item none
7604 None of the argument values are printed. Instead, the value of each argument
7605 is replaced by @code{@dots{}}. In this case, the example above now becomes:
7606
7607 @smallexample
7608 #1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
7609 at frame-args.c:23
7610 @end smallexample
7611 @end table
7612
7613 By default, only scalar arguments are printed. This command can be used
7614 to configure the debugger to print the value of all arguments, regardless
7615 of their type. However, it is often advantageous to not print the value
7616 of more complex parameters. For instance, it reduces the amount of
7617 information printed in each frame, making the backtrace more readable.
7618 Also, it improves performance when displaying Ada frames, because
7619 the computation of large arguments can sometimes be CPU-intensive,
7620 especially in large applications. Setting @code{print frame-arguments}
7621 to @code{scalars} (the default) or @code{none} avoids this computation,
7622 thus speeding up the display of each Ada frame.
7623
7624 @item show print frame-arguments
7625 Show how the value of arguments should be displayed when printing a frame.
7626
7627 @item set print repeats
7628 @cindex repeated array elements
7629 Set the threshold for suppressing display of repeated array
7630 elements. When the number of consecutive identical elements of an
7631 array exceeds the threshold, @value{GDBN} prints the string
7632 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
7633 identical repetitions, instead of displaying the identical elements
7634 themselves. Setting the threshold to zero will cause all elements to
7635 be individually printed. The default threshold is 10.
7636
7637 @item show print repeats
7638 Display the current threshold for printing repeated identical
7639 elements.
7640
7641 @item set print null-stop
7642 @cindex @sc{null} elements in arrays
7643 Cause @value{GDBN} to stop printing the characters of an array when the first
7644 @sc{null} is encountered. This is useful when large arrays actually
7645 contain only short strings.
7646 The default is off.
7647
7648 @item show print null-stop
7649 Show whether @value{GDBN} stops printing an array on the first
7650 @sc{null} character.
7651
7652 @item set print pretty on
7653 @cindex print structures in indented form
7654 @cindex indentation in structure display
7655 Cause @value{GDBN} to print structures in an indented format with one member
7656 per line, like this:
7657
7658 @smallexample
7659 @group
7660 $1 = @{
7661 next = 0x0,
7662 flags = @{
7663 sweet = 1,
7664 sour = 1
7665 @},
7666 meat = 0x54 "Pork"
7667 @}
7668 @end group
7669 @end smallexample
7670
7671 @item set print pretty off
7672 Cause @value{GDBN} to print structures in a compact format, like this:
7673
7674 @smallexample
7675 @group
7676 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
7677 meat = 0x54 "Pork"@}
7678 @end group
7679 @end smallexample
7680
7681 @noindent
7682 This is the default format.
7683
7684 @item show print pretty
7685 Show which format @value{GDBN} is using to print structures.
7686
7687 @item set print sevenbit-strings on
7688 @cindex eight-bit characters in strings
7689 @cindex octal escapes in strings
7690 Print using only seven-bit characters; if this option is set,
7691 @value{GDBN} displays any eight-bit characters (in strings or
7692 character values) using the notation @code{\}@var{nnn}. This setting is
7693 best if you are working in English (@sc{ascii}) and you use the
7694 high-order bit of characters as a marker or ``meta'' bit.
7695
7696 @item set print sevenbit-strings off
7697 Print full eight-bit characters. This allows the use of more
7698 international character sets, and is the default.
7699
7700 @item show print sevenbit-strings
7701 Show whether or not @value{GDBN} is printing only seven-bit characters.
7702
7703 @item set print union on
7704 @cindex unions in structures, printing
7705 Tell @value{GDBN} to print unions which are contained in structures
7706 and other unions. This is the default setting.
7707
7708 @item set print union off
7709 Tell @value{GDBN} not to print unions which are contained in
7710 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
7711 instead.
7712
7713 @item show print union
7714 Ask @value{GDBN} whether or not it will print unions which are contained in
7715 structures and other unions.
7716
7717 For example, given the declarations
7718
7719 @smallexample
7720 typedef enum @{Tree, Bug@} Species;
7721 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
7722 typedef enum @{Caterpillar, Cocoon, Butterfly@}
7723 Bug_forms;
7724
7725 struct thing @{
7726 Species it;
7727 union @{
7728 Tree_forms tree;
7729 Bug_forms bug;
7730 @} form;
7731 @};
7732
7733 struct thing foo = @{Tree, @{Acorn@}@};
7734 @end smallexample
7735
7736 @noindent
7737 with @code{set print union on} in effect @samp{p foo} would print
7738
7739 @smallexample
7740 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
7741 @end smallexample
7742
7743 @noindent
7744 and with @code{set print union off} in effect it would print
7745
7746 @smallexample
7747 $1 = @{it = Tree, form = @{...@}@}
7748 @end smallexample
7749
7750 @noindent
7751 @code{set print union} affects programs written in C-like languages
7752 and in Pascal.
7753 @end table
7754
7755 @need 1000
7756 @noindent
7757 These settings are of interest when debugging C@t{++} programs:
7758
7759 @table @code
7760 @cindex demangling C@t{++} names
7761 @item set print demangle
7762 @itemx set print demangle on
7763 Print C@t{++} names in their source form rather than in the encoded
7764 (``mangled'') form passed to the assembler and linker for type-safe
7765 linkage. The default is on.
7766
7767 @item show print demangle
7768 Show whether C@t{++} names are printed in mangled or demangled form.
7769
7770 @item set print asm-demangle
7771 @itemx set print asm-demangle on
7772 Print C@t{++} names in their source form rather than their mangled form, even
7773 in assembler code printouts such as instruction disassemblies.
7774 The default is off.
7775
7776 @item show print asm-demangle
7777 Show whether C@t{++} names in assembly listings are printed in mangled
7778 or demangled form.
7779
7780 @cindex C@t{++} symbol decoding style
7781 @cindex symbol decoding style, C@t{++}
7782 @kindex set demangle-style
7783 @item set demangle-style @var{style}
7784 Choose among several encoding schemes used by different compilers to
7785 represent C@t{++} names. The choices for @var{style} are currently:
7786
7787 @table @code
7788 @item auto
7789 Allow @value{GDBN} to choose a decoding style by inspecting your program.
7790
7791 @item gnu
7792 Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
7793 This is the default.
7794
7795 @item hp
7796 Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
7797
7798 @item lucid
7799 Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
7800
7801 @item arm
7802 Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
7803 @strong{Warning:} this setting alone is not sufficient to allow
7804 debugging @code{cfront}-generated executables. @value{GDBN} would
7805 require further enhancement to permit that.
7806
7807 @end table
7808 If you omit @var{style}, you will see a list of possible formats.
7809
7810 @item show demangle-style
7811 Display the encoding style currently in use for decoding C@t{++} symbols.
7812
7813 @item set print object
7814 @itemx set print object on
7815 @cindex derived type of an object, printing
7816 @cindex display derived types
7817 When displaying a pointer to an object, identify the @emph{actual}
7818 (derived) type of the object rather than the @emph{declared} type, using
7819 the virtual function table.
7820
7821 @item set print object off
7822 Display only the declared type of objects, without reference to the
7823 virtual function table. This is the default setting.
7824
7825 @item show print object
7826 Show whether actual, or declared, object types are displayed.
7827
7828 @item set print static-members
7829 @itemx set print static-members on
7830 @cindex static members of C@t{++} objects
7831 Print static members when displaying a C@t{++} object. The default is on.
7832
7833 @item set print static-members off
7834 Do not print static members when displaying a C@t{++} object.
7835
7836 @item show print static-members
7837 Show whether C@t{++} static members are printed or not.
7838
7839 @item set print pascal_static-members
7840 @itemx set print pascal_static-members on
7841 @cindex static members of Pascal objects
7842 @cindex Pascal objects, static members display
7843 Print static members when displaying a Pascal object. The default is on.
7844
7845 @item set print pascal_static-members off
7846 Do not print static members when displaying a Pascal object.
7847
7848 @item show print pascal_static-members
7849 Show whether Pascal static members are printed or not.
7850
7851 @c These don't work with HP ANSI C++ yet.
7852 @item set print vtbl
7853 @itemx set print vtbl on
7854 @cindex pretty print C@t{++} virtual function tables
7855 @cindex virtual functions (C@t{++}) display
7856 @cindex VTBL display
7857 Pretty print C@t{++} virtual function tables. The default is off.
7858 (The @code{vtbl} commands do not work on programs compiled with the HP
7859 ANSI C@t{++} compiler (@code{aCC}).)
7860
7861 @item set print vtbl off
7862 Do not pretty print C@t{++} virtual function tables.
7863
7864 @item show print vtbl
7865 Show whether C@t{++} virtual function tables are pretty printed, or not.
7866 @end table
7867
7868 @node Value History
7869 @section Value History
7870
7871 @cindex value history
7872 @cindex history of values printed by @value{GDBN}
7873 Values printed by the @code{print} command are saved in the @value{GDBN}
7874 @dfn{value history}. This allows you to refer to them in other expressions.
7875 Values are kept until the symbol table is re-read or discarded
7876 (for example with the @code{file} or @code{symbol-file} commands).
7877 When the symbol table changes, the value history is discarded,
7878 since the values may contain pointers back to the types defined in the
7879 symbol table.
7880
7881 @cindex @code{$}
7882 @cindex @code{$$}
7883 @cindex history number
7884 The values printed are given @dfn{history numbers} by which you can
7885 refer to them. These are successive integers starting with one.
7886 @code{print} shows you the history number assigned to a value by
7887 printing @samp{$@var{num} = } before the value; here @var{num} is the
7888 history number.
7889
7890 To refer to any previous value, use @samp{$} followed by the value's
7891 history number. The way @code{print} labels its output is designed to
7892 remind you of this. Just @code{$} refers to the most recent value in
7893 the history, and @code{$$} refers to the value before that.
7894 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
7895 is the value just prior to @code{$$}, @code{$$1} is equivalent to
7896 @code{$$}, and @code{$$0} is equivalent to @code{$}.
7897
7898 For example, suppose you have just printed a pointer to a structure and
7899 want to see the contents of the structure. It suffices to type
7900
7901 @smallexample
7902 p *$
7903 @end smallexample
7904
7905 If you have a chain of structures where the component @code{next} points
7906 to the next one, you can print the contents of the next one with this:
7907
7908 @smallexample
7909 p *$.next
7910 @end smallexample
7911
7912 @noindent
7913 You can print successive links in the chain by repeating this
7914 command---which you can do by just typing @key{RET}.
7915
7916 Note that the history records values, not expressions. If the value of
7917 @code{x} is 4 and you type these commands:
7918
7919 @smallexample
7920 print x
7921 set x=5
7922 @end smallexample
7923
7924 @noindent
7925 then the value recorded in the value history by the @code{print} command
7926 remains 4 even though the value of @code{x} has changed.
7927
7928 @table @code
7929 @kindex show values
7930 @item show values
7931 Print the last ten values in the value history, with their item numbers.
7932 This is like @samp{p@ $$9} repeated ten times, except that @code{show
7933 values} does not change the history.
7934
7935 @item show values @var{n}
7936 Print ten history values centered on history item number @var{n}.
7937
7938 @item show values +
7939 Print ten history values just after the values last printed. If no more
7940 values are available, @code{show values +} produces no display.
7941 @end table
7942
7943 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
7944 same effect as @samp{show values +}.
7945
7946 @node Convenience Vars
7947 @section Convenience Variables
7948
7949 @cindex convenience variables
7950 @cindex user-defined variables
7951 @value{GDBN} provides @dfn{convenience variables} that you can use within
7952 @value{GDBN} to hold on to a value and refer to it later. These variables
7953 exist entirely within @value{GDBN}; they are not part of your program, and
7954 setting a convenience variable has no direct effect on further execution
7955 of your program. That is why you can use them freely.
7956
7957 Convenience variables are prefixed with @samp{$}. Any name preceded by
7958 @samp{$} can be used for a convenience variable, unless it is one of
7959 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
7960 (Value history references, in contrast, are @emph{numbers} preceded
7961 by @samp{$}. @xref{Value History, ,Value History}.)
7962
7963 You can save a value in a convenience variable with an assignment
7964 expression, just as you would set a variable in your program.
7965 For example:
7966
7967 @smallexample
7968 set $foo = *object_ptr
7969 @end smallexample
7970
7971 @noindent
7972 would save in @code{$foo} the value contained in the object pointed to by
7973 @code{object_ptr}.
7974
7975 Using a convenience variable for the first time creates it, but its
7976 value is @code{void} until you assign a new value. You can alter the
7977 value with another assignment at any time.
7978
7979 Convenience variables have no fixed types. You can assign a convenience
7980 variable any type of value, including structures and arrays, even if
7981 that variable already has a value of a different type. The convenience
7982 variable, when used as an expression, has the type of its current value.
7983
7984 @table @code
7985 @kindex show convenience
7986 @cindex show all user variables
7987 @item show convenience
7988 Print a list of convenience variables used so far, and their values.
7989 Abbreviated @code{show conv}.
7990
7991 @kindex init-if-undefined
7992 @cindex convenience variables, initializing
7993 @item init-if-undefined $@var{variable} = @var{expression}
7994 Set a convenience variable if it has not already been set. This is useful
7995 for user-defined commands that keep some state. It is similar, in concept,
7996 to using local static variables with initializers in C (except that
7997 convenience variables are global). It can also be used to allow users to
7998 override default values used in a command script.
7999
8000 If the variable is already defined then the expression is not evaluated so
8001 any side-effects do not occur.
8002 @end table
8003
8004 One of the ways to use a convenience variable is as a counter to be
8005 incremented or a pointer to be advanced. For example, to print
8006 a field from successive elements of an array of structures:
8007
8008 @smallexample
8009 set $i = 0
8010 print bar[$i++]->contents
8011 @end smallexample
8012
8013 @noindent
8014 Repeat that command by typing @key{RET}.
8015
8016 Some convenience variables are created automatically by @value{GDBN} and given
8017 values likely to be useful.
8018
8019 @table @code
8020 @vindex $_@r{, convenience variable}
8021 @item $_
8022 The variable @code{$_} is automatically set by the @code{x} command to
8023 the last address examined (@pxref{Memory, ,Examining Memory}). Other
8024 commands which provide a default address for @code{x} to examine also
8025 set @code{$_} to that address; these commands include @code{info line}
8026 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
8027 except when set by the @code{x} command, in which case it is a pointer
8028 to the type of @code{$__}.
8029
8030 @vindex $__@r{, convenience variable}
8031 @item $__
8032 The variable @code{$__} is automatically set by the @code{x} command
8033 to the value found in the last address examined. Its type is chosen
8034 to match the format in which the data was printed.
8035
8036 @item $_exitcode
8037 @vindex $_exitcode@r{, convenience variable}
8038 The variable @code{$_exitcode} is automatically set to the exit code when
8039 the program being debugged terminates.
8040
8041 @item $_siginfo
8042 @vindex $_siginfo@r{, convenience variable}
8043 The variable @code{$_siginfo} contains extra signal information
8044 (@pxref{extra signal information}). Note that @code{$_siginfo}
8045 could be empty, if the application has not yet received any signals.
8046 For example, it will be empty before you execute the @code{run} command.
8047 @end table
8048
8049 On HP-UX systems, if you refer to a function or variable name that
8050 begins with a dollar sign, @value{GDBN} searches for a user or system
8051 name first, before it searches for a convenience variable.
8052
8053 @cindex convenience functions
8054 @value{GDBN} also supplies some @dfn{convenience functions}. These
8055 have a syntax similar to convenience variables. A convenience
8056 function can be used in an expression just like an ordinary function;
8057 however, a convenience function is implemented internally to
8058 @value{GDBN}.
8059
8060 @table @code
8061 @item help function
8062 @kindex help function
8063 @cindex show all convenience functions
8064 Print a list of all convenience functions.
8065 @end table
8066
8067 @node Registers
8068 @section Registers
8069
8070 @cindex registers
8071 You can refer to machine register contents, in expressions, as variables
8072 with names starting with @samp{$}. The names of registers are different
8073 for each machine; use @code{info registers} to see the names used on
8074 your machine.
8075
8076 @table @code
8077 @kindex info registers
8078 @item info registers
8079 Print the names and values of all registers except floating-point
8080 and vector registers (in the selected stack frame).
8081
8082 @kindex info all-registers
8083 @cindex floating point registers
8084 @item info all-registers
8085 Print the names and values of all registers, including floating-point
8086 and vector registers (in the selected stack frame).
8087
8088 @item info registers @var{regname} @dots{}
8089 Print the @dfn{relativized} value of each specified register @var{regname}.
8090 As discussed in detail below, register values are normally relative to
8091 the selected stack frame. @var{regname} may be any register name valid on
8092 the machine you are using, with or without the initial @samp{$}.
8093 @end table
8094
8095 @cindex stack pointer register
8096 @cindex program counter register
8097 @cindex process status register
8098 @cindex frame pointer register
8099 @cindex standard registers
8100 @value{GDBN} has four ``standard'' register names that are available (in
8101 expressions) on most machines---whenever they do not conflict with an
8102 architecture's canonical mnemonics for registers. The register names
8103 @code{$pc} and @code{$sp} are used for the program counter register and
8104 the stack pointer. @code{$fp} is used for a register that contains a
8105 pointer to the current stack frame, and @code{$ps} is used for a
8106 register that contains the processor status. For example,
8107 you could print the program counter in hex with
8108
8109 @smallexample
8110 p/x $pc
8111 @end smallexample
8112
8113 @noindent
8114 or print the instruction to be executed next with
8115
8116 @smallexample
8117 x/i $pc
8118 @end smallexample
8119
8120 @noindent
8121 or add four to the stack pointer@footnote{This is a way of removing
8122 one word from the stack, on machines where stacks grow downward in
8123 memory (most machines, nowadays). This assumes that the innermost
8124 stack frame is selected; setting @code{$sp} is not allowed when other
8125 stack frames are selected. To pop entire frames off the stack,
8126 regardless of machine architecture, use @code{return};
8127 see @ref{Returning, ,Returning from a Function}.} with
8128
8129 @smallexample
8130 set $sp += 4
8131 @end smallexample
8132
8133 Whenever possible, these four standard register names are available on
8134 your machine even though the machine has different canonical mnemonics,
8135 so long as there is no conflict. The @code{info registers} command
8136 shows the canonical names. For example, on the SPARC, @code{info
8137 registers} displays the processor status register as @code{$psr} but you
8138 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
8139 is an alias for the @sc{eflags} register.
8140
8141 @value{GDBN} always considers the contents of an ordinary register as an
8142 integer when the register is examined in this way. Some machines have
8143 special registers which can hold nothing but floating point; these
8144 registers are considered to have floating point values. There is no way
8145 to refer to the contents of an ordinary register as floating point value
8146 (although you can @emph{print} it as a floating point value with
8147 @samp{print/f $@var{regname}}).
8148
8149 Some registers have distinct ``raw'' and ``virtual'' data formats. This
8150 means that the data format in which the register contents are saved by
8151 the operating system is not the same one that your program normally
8152 sees. For example, the registers of the 68881 floating point
8153 coprocessor are always saved in ``extended'' (raw) format, but all C
8154 programs expect to work with ``double'' (virtual) format. In such
8155 cases, @value{GDBN} normally works with the virtual format only (the format
8156 that makes sense for your program), but the @code{info registers} command
8157 prints the data in both formats.
8158
8159 @cindex SSE registers (x86)
8160 @cindex MMX registers (x86)
8161 Some machines have special registers whose contents can be interpreted
8162 in several different ways. For example, modern x86-based machines
8163 have SSE and MMX registers that can hold several values packed
8164 together in several different formats. @value{GDBN} refers to such
8165 registers in @code{struct} notation:
8166
8167 @smallexample
8168 (@value{GDBP}) print $xmm1
8169 $1 = @{
8170 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
8171 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
8172 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
8173 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
8174 v4_int32 = @{0, 20657912, 11, 13@},
8175 v2_int64 = @{88725056443645952, 55834574859@},
8176 uint128 = 0x0000000d0000000b013b36f800000000
8177 @}
8178 @end smallexample
8179
8180 @noindent
8181 To set values of such registers, you need to tell @value{GDBN} which
8182 view of the register you wish to change, as if you were assigning
8183 value to a @code{struct} member:
8184
8185 @smallexample
8186 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
8187 @end smallexample
8188
8189 Normally, register values are relative to the selected stack frame
8190 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
8191 value that the register would contain if all stack frames farther in
8192 were exited and their saved registers restored. In order to see the
8193 true contents of hardware registers, you must select the innermost
8194 frame (with @samp{frame 0}).
8195
8196 However, @value{GDBN} must deduce where registers are saved, from the machine
8197 code generated by your compiler. If some registers are not saved, or if
8198 @value{GDBN} is unable to locate the saved registers, the selected stack
8199 frame makes no difference.
8200
8201 @node Floating Point Hardware
8202 @section Floating Point Hardware
8203 @cindex floating point
8204
8205 Depending on the configuration, @value{GDBN} may be able to give
8206 you more information about the status of the floating point hardware.
8207
8208 @table @code
8209 @kindex info float
8210 @item info float
8211 Display hardware-dependent information about the floating
8212 point unit. The exact contents and layout vary depending on the
8213 floating point chip. Currently, @samp{info float} is supported on
8214 the ARM and x86 machines.
8215 @end table
8216
8217 @node Vector Unit
8218 @section Vector Unit
8219 @cindex vector unit
8220
8221 Depending on the configuration, @value{GDBN} may be able to give you
8222 more information about the status of the vector unit.
8223
8224 @table @code
8225 @kindex info vector
8226 @item info vector
8227 Display information about the vector unit. The exact contents and
8228 layout vary depending on the hardware.
8229 @end table
8230
8231 @node OS Information
8232 @section Operating System Auxiliary Information
8233 @cindex OS information
8234
8235 @value{GDBN} provides interfaces to useful OS facilities that can help
8236 you debug your program.
8237
8238 @cindex @code{ptrace} system call
8239 @cindex @code{struct user} contents
8240 When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
8241 machines), it interfaces with the inferior via the @code{ptrace}
8242 system call. The operating system creates a special sata structure,
8243 called @code{struct user}, for this interface. You can use the
8244 command @code{info udot} to display the contents of this data
8245 structure.
8246
8247 @table @code
8248 @item info udot
8249 @kindex info udot
8250 Display the contents of the @code{struct user} maintained by the OS
8251 kernel for the program being debugged. @value{GDBN} displays the
8252 contents of @code{struct user} as a list of hex numbers, similar to
8253 the @code{examine} command.
8254 @end table
8255
8256 @cindex auxiliary vector
8257 @cindex vector, auxiliary
8258 Some operating systems supply an @dfn{auxiliary vector} to programs at
8259 startup. This is akin to the arguments and environment that you
8260 specify for a program, but contains a system-dependent variety of
8261 binary values that tell system libraries important details about the
8262 hardware, operating system, and process. Each value's purpose is
8263 identified by an integer tag; the meanings are well-known but system-specific.
8264 Depending on the configuration and operating system facilities,
8265 @value{GDBN} may be able to show you this information. For remote
8266 targets, this functionality may further depend on the remote stub's
8267 support of the @samp{qXfer:auxv:read} packet, see
8268 @ref{qXfer auxiliary vector read}.
8269
8270 @table @code
8271 @kindex info auxv
8272 @item info auxv
8273 Display the auxiliary vector of the inferior, which can be either a
8274 live process or a core dump file. @value{GDBN} prints each tag value
8275 numerically, and also shows names and text descriptions for recognized
8276 tags. Some values in the vector are numbers, some bit masks, and some
8277 pointers to strings or other data. @value{GDBN} displays each value in the
8278 most appropriate form for a recognized tag, and in hexadecimal for
8279 an unrecognized tag.
8280 @end table
8281
8282 On some targets, @value{GDBN} can access operating-system-specific information
8283 and display it to user, without interpretation. For remote targets,
8284 this functionality depends on the remote stub's support of the
8285 @samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
8286
8287 @table @code
8288 @kindex info os processes
8289 @item info os processes
8290 Display the list of processes on the target. For each process,
8291 @value{GDBN} prints the process identifier, the name of the user, and
8292 the command corresponding to the process.
8293 @end table
8294
8295 @node Memory Region Attributes
8296 @section Memory Region Attributes
8297 @cindex memory region attributes
8298
8299 @dfn{Memory region attributes} allow you to describe special handling
8300 required by regions of your target's memory. @value{GDBN} uses
8301 attributes to determine whether to allow certain types of memory
8302 accesses; whether to use specific width accesses; and whether to cache
8303 target memory. By default the description of memory regions is
8304 fetched from the target (if the current target supports this), but the
8305 user can override the fetched regions.
8306
8307 Defined memory regions can be individually enabled and disabled. When a
8308 memory region is disabled, @value{GDBN} uses the default attributes when
8309 accessing memory in that region. Similarly, if no memory regions have
8310 been defined, @value{GDBN} uses the default attributes when accessing
8311 all memory.
8312
8313 When a memory region is defined, it is given a number to identify it;
8314 to enable, disable, or remove a memory region, you specify that number.
8315
8316 @table @code
8317 @kindex mem
8318 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
8319 Define a memory region bounded by @var{lower} and @var{upper} with
8320 attributes @var{attributes}@dots{}, and add it to the list of regions
8321 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
8322 case: it is treated as the target's maximum memory address.
8323 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
8324
8325 @item mem auto
8326 Discard any user changes to the memory regions and use target-supplied
8327 regions, if available, or no regions if the target does not support.
8328
8329 @kindex delete mem
8330 @item delete mem @var{nums}@dots{}
8331 Remove memory regions @var{nums}@dots{} from the list of regions
8332 monitored by @value{GDBN}.
8333
8334 @kindex disable mem
8335 @item disable mem @var{nums}@dots{}
8336 Disable monitoring of memory regions @var{nums}@dots{}.
8337 A disabled memory region is not forgotten.
8338 It may be enabled again later.
8339
8340 @kindex enable mem
8341 @item enable mem @var{nums}@dots{}
8342 Enable monitoring of memory regions @var{nums}@dots{}.
8343
8344 @kindex info mem
8345 @item info mem
8346 Print a table of all defined memory regions, with the following columns
8347 for each region:
8348
8349 @table @emph
8350 @item Memory Region Number
8351 @item Enabled or Disabled.
8352 Enabled memory regions are marked with @samp{y}.
8353 Disabled memory regions are marked with @samp{n}.
8354
8355 @item Lo Address
8356 The address defining the inclusive lower bound of the memory region.
8357
8358 @item Hi Address
8359 The address defining the exclusive upper bound of the memory region.
8360
8361 @item Attributes
8362 The list of attributes set for this memory region.
8363 @end table
8364 @end table
8365
8366
8367 @subsection Attributes
8368
8369 @subsubsection Memory Access Mode
8370 The access mode attributes set whether @value{GDBN} may make read or
8371 write accesses to a memory region.
8372
8373 While these attributes prevent @value{GDBN} from performing invalid
8374 memory accesses, they do nothing to prevent the target system, I/O DMA,
8375 etc.@: from accessing memory.
8376
8377 @table @code
8378 @item ro
8379 Memory is read only.
8380 @item wo
8381 Memory is write only.
8382 @item rw
8383 Memory is read/write. This is the default.
8384 @end table
8385
8386 @subsubsection Memory Access Size
8387 The access size attribute tells @value{GDBN} to use specific sized
8388 accesses in the memory region. Often memory mapped device registers
8389 require specific sized accesses. If no access size attribute is
8390 specified, @value{GDBN} may use accesses of any size.
8391
8392 @table @code
8393 @item 8
8394 Use 8 bit memory accesses.
8395 @item 16
8396 Use 16 bit memory accesses.
8397 @item 32
8398 Use 32 bit memory accesses.
8399 @item 64
8400 Use 64 bit memory accesses.
8401 @end table
8402
8403 @c @subsubsection Hardware/Software Breakpoints
8404 @c The hardware/software breakpoint attributes set whether @value{GDBN}
8405 @c will use hardware or software breakpoints for the internal breakpoints
8406 @c used by the step, next, finish, until, etc. commands.
8407 @c
8408 @c @table @code
8409 @c @item hwbreak
8410 @c Always use hardware breakpoints
8411 @c @item swbreak (default)
8412 @c @end table
8413
8414 @subsubsection Data Cache
8415 The data cache attributes set whether @value{GDBN} will cache target
8416 memory. While this generally improves performance by reducing debug
8417 protocol overhead, it can lead to incorrect results because @value{GDBN}
8418 does not know about volatile variables or memory mapped device
8419 registers.
8420
8421 @table @code
8422 @item cache
8423 Enable @value{GDBN} to cache target memory.
8424 @item nocache
8425 Disable @value{GDBN} from caching target memory. This is the default.
8426 @end table
8427
8428 @subsection Memory Access Checking
8429 @value{GDBN} can be instructed to refuse accesses to memory that is
8430 not explicitly described. This can be useful if accessing such
8431 regions has undesired effects for a specific target, or to provide
8432 better error checking. The following commands control this behaviour.
8433
8434 @table @code
8435 @kindex set mem inaccessible-by-default
8436 @item set mem inaccessible-by-default [on|off]
8437 If @code{on} is specified, make @value{GDBN} treat memory not
8438 explicitly described by the memory ranges as non-existent and refuse accesses
8439 to such memory. The checks are only performed if there's at least one
8440 memory range defined. If @code{off} is specified, make @value{GDBN}
8441 treat the memory not explicitly described by the memory ranges as RAM.
8442 The default value is @code{on}.
8443 @kindex show mem inaccessible-by-default
8444 @item show mem inaccessible-by-default
8445 Show the current handling of accesses to unknown memory.
8446 @end table
8447
8448
8449 @c @subsubsection Memory Write Verification
8450 @c The memory write verification attributes set whether @value{GDBN}
8451 @c will re-reads data after each write to verify the write was successful.
8452 @c
8453 @c @table @code
8454 @c @item verify
8455 @c @item noverify (default)
8456 @c @end table
8457
8458 @node Dump/Restore Files
8459 @section Copy Between Memory and a File
8460 @cindex dump/restore files
8461 @cindex append data to a file
8462 @cindex dump data to a file
8463 @cindex restore data from a file
8464
8465 You can use the commands @code{dump}, @code{append}, and
8466 @code{restore} to copy data between target memory and a file. The
8467 @code{dump} and @code{append} commands write data to a file, and the
8468 @code{restore} command reads data from a file back into the inferior's
8469 memory. Files may be in binary, Motorola S-record, Intel hex, or
8470 Tektronix Hex format; however, @value{GDBN} can only append to binary
8471 files.
8472
8473 @table @code
8474
8475 @kindex dump
8476 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
8477 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
8478 Dump the contents of memory from @var{start_addr} to @var{end_addr},
8479 or the value of @var{expr}, to @var{filename} in the given format.
8480
8481 The @var{format} parameter may be any one of:
8482 @table @code
8483 @item binary
8484 Raw binary form.
8485 @item ihex
8486 Intel hex format.
8487 @item srec
8488 Motorola S-record format.
8489 @item tekhex
8490 Tektronix Hex format.
8491 @end table
8492
8493 @value{GDBN} uses the same definitions of these formats as the
8494 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
8495 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
8496 form.
8497
8498 @kindex append
8499 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
8500 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
8501 Append the contents of memory from @var{start_addr} to @var{end_addr},
8502 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
8503 (@value{GDBN} can only append data to files in raw binary form.)
8504
8505 @kindex restore
8506 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
8507 Restore the contents of file @var{filename} into memory. The
8508 @code{restore} command can automatically recognize any known @sc{bfd}
8509 file format, except for raw binary. To restore a raw binary file you
8510 must specify the optional keyword @code{binary} after the filename.
8511
8512 If @var{bias} is non-zero, its value will be added to the addresses
8513 contained in the file. Binary files always start at address zero, so
8514 they will be restored at address @var{bias}. Other bfd files have
8515 a built-in location; they will be restored at offset @var{bias}
8516 from that location.
8517
8518 If @var{start} and/or @var{end} are non-zero, then only data between
8519 file offset @var{start} and file offset @var{end} will be restored.
8520 These offsets are relative to the addresses in the file, before
8521 the @var{bias} argument is applied.
8522
8523 @end table
8524
8525 @node Core File Generation
8526 @section How to Produce a Core File from Your Program
8527 @cindex dump core from inferior
8528
8529 A @dfn{core file} or @dfn{core dump} is a file that records the memory
8530 image of a running process and its process status (register values
8531 etc.). Its primary use is post-mortem debugging of a program that
8532 crashed while it ran outside a debugger. A program that crashes
8533 automatically produces a core file, unless this feature is disabled by
8534 the user. @xref{Files}, for information on invoking @value{GDBN} in
8535 the post-mortem debugging mode.
8536
8537 Occasionally, you may wish to produce a core file of the program you
8538 are debugging in order to preserve a snapshot of its state.
8539 @value{GDBN} has a special command for that.
8540
8541 @table @code
8542 @kindex gcore
8543 @kindex generate-core-file
8544 @item generate-core-file [@var{file}]
8545 @itemx gcore [@var{file}]
8546 Produce a core dump of the inferior process. The optional argument
8547 @var{file} specifies the file name where to put the core dump. If not
8548 specified, the file name defaults to @file{core.@var{pid}}, where
8549 @var{pid} is the inferior process ID.
8550
8551 Note that this command is implemented only for some systems (as of
8552 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
8553 @end table
8554
8555 @node Character Sets
8556 @section Character Sets
8557 @cindex character sets
8558 @cindex charset
8559 @cindex translating between character sets
8560 @cindex host character set
8561 @cindex target character set
8562
8563 If the program you are debugging uses a different character set to
8564 represent characters and strings than the one @value{GDBN} uses itself,
8565 @value{GDBN} can automatically translate between the character sets for
8566 you. The character set @value{GDBN} uses we call the @dfn{host
8567 character set}; the one the inferior program uses we call the
8568 @dfn{target character set}.
8569
8570 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
8571 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
8572 remote protocol (@pxref{Remote Debugging}) to debug a program
8573 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
8574 then the host character set is Latin-1, and the target character set is
8575 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
8576 target-charset EBCDIC-US}, then @value{GDBN} translates between
8577 @sc{ebcdic} and Latin 1 as you print character or string values, or use
8578 character and string literals in expressions.
8579
8580 @value{GDBN} has no way to automatically recognize which character set
8581 the inferior program uses; you must tell it, using the @code{set
8582 target-charset} command, described below.
8583
8584 Here are the commands for controlling @value{GDBN}'s character set
8585 support:
8586
8587 @table @code
8588 @item set target-charset @var{charset}
8589 @kindex set target-charset
8590 Set the current target character set to @var{charset}. To display the
8591 list of supported target character sets, type
8592 @kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
8593
8594 @item set host-charset @var{charset}
8595 @kindex set host-charset
8596 Set the current host character set to @var{charset}.
8597
8598 By default, @value{GDBN} uses a host character set appropriate to the
8599 system it is running on; you can override that default using the
8600 @code{set host-charset} command. On some systems, @value{GDBN} cannot
8601 automatically determine the appropriate host character set. In this
8602 case, @value{GDBN} uses @samp{UTF-8}.
8603
8604 @value{GDBN} can only use certain character sets as its host character
8605 set. If you type @kbd{@w{set target-charset @key{TAB}@key{TAB}}},
8606 @value{GDBN} will list the host character sets it supports.
8607
8608 @item set charset @var{charset}
8609 @kindex set charset
8610 Set the current host and target character sets to @var{charset}. As
8611 above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
8612 @value{GDBN} will list the names of the character sets that can be used
8613 for both host and target.
8614
8615 @item show charset
8616 @kindex show charset
8617 Show the names of the current host and target character sets.
8618
8619 @item show host-charset
8620 @kindex show host-charset
8621 Show the name of the current host character set.
8622
8623 @item show target-charset
8624 @kindex show target-charset
8625 Show the name of the current target character set.
8626
8627 @item set target-wide-charset @var{charset}
8628 @kindex set target-wide-charset
8629 Set the current target's wide character set to @var{charset}. This is
8630 the character set used by the target's @code{wchar_t} type. To
8631 display the list of supported wide character sets, type
8632 @kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
8633
8634 @item show target-wide-charset
8635 @kindex show target-wide-charset
8636 Show the name of the current target's wide character set.
8637 @end table
8638
8639 Here is an example of @value{GDBN}'s character set support in action.
8640 Assume that the following source code has been placed in the file
8641 @file{charset-test.c}:
8642
8643 @smallexample
8644 #include <stdio.h>
8645
8646 char ascii_hello[]
8647 = @{72, 101, 108, 108, 111, 44, 32, 119,
8648 111, 114, 108, 100, 33, 10, 0@};
8649 char ibm1047_hello[]
8650 = @{200, 133, 147, 147, 150, 107, 64, 166,
8651 150, 153, 147, 132, 90, 37, 0@};
8652
8653 main ()
8654 @{
8655 printf ("Hello, world!\n");
8656 @}
8657 @end smallexample
8658
8659 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
8660 containing the string @samp{Hello, world!} followed by a newline,
8661 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
8662
8663 We compile the program, and invoke the debugger on it:
8664
8665 @smallexample
8666 $ gcc -g charset-test.c -o charset-test
8667 $ gdb -nw charset-test
8668 GNU gdb 2001-12-19-cvs
8669 Copyright 2001 Free Software Foundation, Inc.
8670 @dots{}
8671 (@value{GDBP})
8672 @end smallexample
8673
8674 We can use the @code{show charset} command to see what character sets
8675 @value{GDBN} is currently using to interpret and display characters and
8676 strings:
8677
8678 @smallexample
8679 (@value{GDBP}) show charset
8680 The current host and target character set is `ISO-8859-1'.
8681 (@value{GDBP})
8682 @end smallexample
8683
8684 For the sake of printing this manual, let's use @sc{ascii} as our
8685 initial character set:
8686 @smallexample
8687 (@value{GDBP}) set charset ASCII
8688 (@value{GDBP}) show charset
8689 The current host and target character set is `ASCII'.
8690 (@value{GDBP})
8691 @end smallexample
8692
8693 Let's assume that @sc{ascii} is indeed the correct character set for our
8694 host system --- in other words, let's assume that if @value{GDBN} prints
8695 characters using the @sc{ascii} character set, our terminal will display
8696 them properly. Since our current target character set is also
8697 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
8698
8699 @smallexample
8700 (@value{GDBP}) print ascii_hello
8701 $1 = 0x401698 "Hello, world!\n"
8702 (@value{GDBP}) print ascii_hello[0]
8703 $2 = 72 'H'
8704 (@value{GDBP})
8705 @end smallexample
8706
8707 @value{GDBN} uses the target character set for character and string
8708 literals you use in expressions:
8709
8710 @smallexample
8711 (@value{GDBP}) print '+'
8712 $3 = 43 '+'
8713 (@value{GDBP})
8714 @end smallexample
8715
8716 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
8717 character.
8718
8719 @value{GDBN} relies on the user to tell it which character set the
8720 target program uses. If we print @code{ibm1047_hello} while our target
8721 character set is still @sc{ascii}, we get jibberish:
8722
8723 @smallexample
8724 (@value{GDBP}) print ibm1047_hello
8725 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
8726 (@value{GDBP}) print ibm1047_hello[0]
8727 $5 = 200 '\310'
8728 (@value{GDBP})
8729 @end smallexample
8730
8731 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
8732 @value{GDBN} tells us the character sets it supports:
8733
8734 @smallexample
8735 (@value{GDBP}) set target-charset
8736 ASCII EBCDIC-US IBM1047 ISO-8859-1
8737 (@value{GDBP}) set target-charset
8738 @end smallexample
8739
8740 We can select @sc{ibm1047} as our target character set, and examine the
8741 program's strings again. Now the @sc{ascii} string is wrong, but
8742 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
8743 target character set, @sc{ibm1047}, to the host character set,
8744 @sc{ascii}, and they display correctly:
8745
8746 @smallexample
8747 (@value{GDBP}) set target-charset IBM1047
8748 (@value{GDBP}) show charset
8749 The current host character set is `ASCII'.
8750 The current target character set is `IBM1047'.
8751 (@value{GDBP}) print ascii_hello
8752 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
8753 (@value{GDBP}) print ascii_hello[0]
8754 $7 = 72 '\110'
8755 (@value{GDBP}) print ibm1047_hello
8756 $8 = 0x4016a8 "Hello, world!\n"
8757 (@value{GDBP}) print ibm1047_hello[0]
8758 $9 = 200 'H'
8759 (@value{GDBP})
8760 @end smallexample
8761
8762 As above, @value{GDBN} uses the target character set for character and
8763 string literals you use in expressions:
8764
8765 @smallexample
8766 (@value{GDBP}) print '+'
8767 $10 = 78 '+'
8768 (@value{GDBP})
8769 @end smallexample
8770
8771 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
8772 character.
8773
8774 @node Caching Remote Data
8775 @section Caching Data of Remote Targets
8776 @cindex caching data of remote targets
8777
8778 @value{GDBN} caches data exchanged between the debugger and a
8779 remote target (@pxref{Remote Debugging}). Such caching generally improves
8780 performance, because it reduces the overhead of the remote protocol by
8781 bundling memory reads and writes into large chunks. Unfortunately, simply
8782 caching everything would lead to incorrect results, since @value{GDBN}
8783 does not necessarily know anything about volatile values, memory-mapped I/O
8784 addresses, etc. Furthermore, in non-stop mode (@pxref{Non-Stop Mode})
8785 memory can be changed @emph{while} a gdb command is executing.
8786 Therefore, by default, @value{GDBN} only caches data
8787 known to be on the stack@footnote{In non-stop mode, it is moderately
8788 rare for a running thread to modify the stack of a stopped thread
8789 in a way that would interfere with a backtrace, and caching of
8790 stack reads provides a significant speed up of remote backtraces.}.
8791 Other regions of memory can be explicitly marked as
8792 cacheable; see @pxref{Memory Region Attributes}.
8793
8794 @table @code
8795 @kindex set remotecache
8796 @item set remotecache on
8797 @itemx set remotecache off
8798 This option no longer does anything; it exists for compatibility
8799 with old scripts.
8800
8801 @kindex show remotecache
8802 @item show remotecache
8803 Show the current state of the obsolete remotecache flag.
8804
8805 @kindex set stack-cache
8806 @item set stack-cache on
8807 @itemx set stack-cache off
8808 Enable or disable caching of stack accesses. When @code{ON}, use
8809 caching. By default, this option is @code{ON}.
8810
8811 @kindex show stack-cache
8812 @item show stack-cache
8813 Show the current state of data caching for memory accesses.
8814
8815 @kindex info dcache
8816 @item info dcache @r{[}line@r{]}
8817 Print the information about the data cache performance. The
8818 information displayed includes the dcache width and depth, and for
8819 each cache line, its number, address, and how many times it was
8820 referenced. This command is useful for debugging the data cache
8821 operation.
8822
8823 If a line number is specified, the contents of that line will be
8824 printed in hex.
8825 @end table
8826
8827 @node Searching Memory
8828 @section Search Memory
8829 @cindex searching memory
8830
8831 Memory can be searched for a particular sequence of bytes with the
8832 @code{find} command.
8833
8834 @table @code
8835 @kindex find
8836 @item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
8837 @itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
8838 Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
8839 etc. The search begins at address @var{start_addr} and continues for either
8840 @var{len} bytes or through to @var{end_addr} inclusive.
8841 @end table
8842
8843 @var{s} and @var{n} are optional parameters.
8844 They may be specified in either order, apart or together.
8845
8846 @table @r
8847 @item @var{s}, search query size
8848 The size of each search query value.
8849
8850 @table @code
8851 @item b
8852 bytes
8853 @item h
8854 halfwords (two bytes)
8855 @item w
8856 words (four bytes)
8857 @item g
8858 giant words (eight bytes)
8859 @end table
8860
8861 All values are interpreted in the current language.
8862 This means, for example, that if the current source language is C/C@t{++}
8863 then searching for the string ``hello'' includes the trailing '\0'.
8864
8865 If the value size is not specified, it is taken from the
8866 value's type in the current language.
8867 This is useful when one wants to specify the search
8868 pattern as a mixture of types.
8869 Note that this means, for example, that in the case of C-like languages
8870 a search for an untyped 0x42 will search for @samp{(int) 0x42}
8871 which is typically four bytes.
8872
8873 @item @var{n}, maximum number of finds
8874 The maximum number of matches to print. The default is to print all finds.
8875 @end table
8876
8877 You can use strings as search values. Quote them with double-quotes
8878 (@code{"}).
8879 The string value is copied into the search pattern byte by byte,
8880 regardless of the endianness of the target and the size specification.
8881
8882 The address of each match found is printed as well as a count of the
8883 number of matches found.
8884
8885 The address of the last value found is stored in convenience variable
8886 @samp{$_}.
8887 A count of the number of matches is stored in @samp{$numfound}.
8888
8889 For example, if stopped at the @code{printf} in this function:
8890
8891 @smallexample
8892 void
8893 hello ()
8894 @{
8895 static char hello[] = "hello-hello";
8896 static struct @{ char c; short s; int i; @}
8897 __attribute__ ((packed)) mixed
8898 = @{ 'c', 0x1234, 0x87654321 @};
8899 printf ("%s\n", hello);
8900 @}
8901 @end smallexample
8902
8903 @noindent
8904 you get during debugging:
8905
8906 @smallexample
8907 (gdb) find &hello[0], +sizeof(hello), "hello"
8908 0x804956d <hello.1620+6>
8909 1 pattern found
8910 (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
8911 0x8049567 <hello.1620>
8912 0x804956d <hello.1620+6>
8913 2 patterns found
8914 (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
8915 0x8049567 <hello.1620>
8916 1 pattern found
8917 (gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
8918 0x8049560 <mixed.1625>
8919 1 pattern found
8920 (gdb) print $numfound
8921 $1 = 1
8922 (gdb) print $_
8923 $2 = (void *) 0x8049560
8924 @end smallexample
8925
8926 @node Optimized Code
8927 @chapter Debugging Optimized Code
8928 @cindex optimized code, debugging
8929 @cindex debugging optimized code
8930
8931 Almost all compilers support optimization. With optimization
8932 disabled, the compiler generates assembly code that corresponds
8933 directly to your source code, in a simplistic way. As the compiler
8934 applies more powerful optimizations, the generated assembly code
8935 diverges from your original source code. With help from debugging
8936 information generated by the compiler, @value{GDBN} can map from
8937 the running program back to constructs from your original source.
8938
8939 @value{GDBN} is more accurate with optimization disabled. If you
8940 can recompile without optimization, it is easier to follow the
8941 progress of your program during debugging. But, there are many cases
8942 where you may need to debug an optimized version.
8943
8944 When you debug a program compiled with @samp{-g -O}, remember that the
8945 optimizer has rearranged your code; the debugger shows you what is
8946 really there. Do not be too surprised when the execution path does not
8947 exactly match your source file! An extreme example: if you define a
8948 variable, but never use it, @value{GDBN} never sees that
8949 variable---because the compiler optimizes it out of existence.
8950
8951 Some things do not work as well with @samp{-g -O} as with just
8952 @samp{-g}, particularly on machines with instruction scheduling. If in
8953 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
8954 please report it to us as a bug (including a test case!).
8955 @xref{Variables}, for more information about debugging optimized code.
8956
8957 @menu
8958 * Inline Functions:: How @value{GDBN} presents inlining
8959 @end menu
8960
8961 @node Inline Functions
8962 @section Inline Functions
8963 @cindex inline functions, debugging
8964
8965 @dfn{Inlining} is an optimization that inserts a copy of the function
8966 body directly at each call site, instead of jumping to a shared
8967 routine. @value{GDBN} displays inlined functions just like
8968 non-inlined functions. They appear in backtraces. You can view their
8969 arguments and local variables, step into them with @code{step}, skip
8970 them with @code{next}, and escape from them with @code{finish}.
8971 You can check whether a function was inlined by using the
8972 @code{info frame} command.
8973
8974 For @value{GDBN} to support inlined functions, the compiler must
8975 record information about inlining in the debug information ---
8976 @value{NGCC} using the @sc{dwarf 2} format does this, and several
8977 other compilers do also. @value{GDBN} only supports inlined functions
8978 when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
8979 do not emit two required attributes (@samp{DW_AT_call_file} and
8980 @samp{DW_AT_call_line}); @value{GDBN} does not display inlined
8981 function calls with earlier versions of @value{NGCC}. It instead
8982 displays the arguments and local variables of inlined functions as
8983 local variables in the caller.
8984
8985 The body of an inlined function is directly included at its call site;
8986 unlike a non-inlined function, there are no instructions devoted to
8987 the call. @value{GDBN} still pretends that the call site and the
8988 start of the inlined function are different instructions. Stepping to
8989 the call site shows the call site, and then stepping again shows
8990 the first line of the inlined function, even though no additional
8991 instructions are executed.
8992
8993 This makes source-level debugging much clearer; you can see both the
8994 context of the call and then the effect of the call. Only stepping by
8995 a single instruction using @code{stepi} or @code{nexti} does not do
8996 this; single instruction steps always show the inlined body.
8997
8998 There are some ways that @value{GDBN} does not pretend that inlined
8999 function calls are the same as normal calls:
9000
9001 @itemize @bullet
9002 @item
9003 You cannot set breakpoints on inlined functions. @value{GDBN}
9004 either reports that there is no symbol with that name, or else sets the
9005 breakpoint only on non-inlined copies of the function. This limitation
9006 will be removed in a future version of @value{GDBN}; until then,
9007 set a breakpoint by line number on the first line of the inlined
9008 function instead.
9009
9010 @item
9011 Setting breakpoints at the call site of an inlined function may not
9012 work, because the call site does not contain any code. @value{GDBN}
9013 may incorrectly move the breakpoint to the next line of the enclosing
9014 function, after the call. This limitation will be removed in a future
9015 version of @value{GDBN}; until then, set a breakpoint on an earlier line
9016 or inside the inlined function instead.
9017
9018 @item
9019 @value{GDBN} cannot locate the return value of inlined calls after
9020 using the @code{finish} command. This is a limitation of compiler-generated
9021 debugging information; after @code{finish}, you can step to the next line
9022 and print a variable where your program stored the return value.
9023
9024 @end itemize
9025
9026
9027 @node Macros
9028 @chapter C Preprocessor Macros
9029
9030 Some languages, such as C and C@t{++}, provide a way to define and invoke
9031 ``preprocessor macros'' which expand into strings of tokens.
9032 @value{GDBN} can evaluate expressions containing macro invocations, show
9033 the result of macro expansion, and show a macro's definition, including
9034 where it was defined.
9035
9036 You may need to compile your program specially to provide @value{GDBN}
9037 with information about preprocessor macros. Most compilers do not
9038 include macros in their debugging information, even when you compile
9039 with the @option{-g} flag. @xref{Compilation}.
9040
9041 A program may define a macro at one point, remove that definition later,
9042 and then provide a different definition after that. Thus, at different
9043 points in the program, a macro may have different definitions, or have
9044 no definition at all. If there is a current stack frame, @value{GDBN}
9045 uses the macros in scope at that frame's source code line. Otherwise,
9046 @value{GDBN} uses the macros in scope at the current listing location;
9047 see @ref{List}.
9048
9049 Whenever @value{GDBN} evaluates an expression, it always expands any
9050 macro invocations present in the expression. @value{GDBN} also provides
9051 the following commands for working with macros explicitly.
9052
9053 @table @code
9054
9055 @kindex macro expand
9056 @cindex macro expansion, showing the results of preprocessor
9057 @cindex preprocessor macro expansion, showing the results of
9058 @cindex expanding preprocessor macros
9059 @item macro expand @var{expression}
9060 @itemx macro exp @var{expression}
9061 Show the results of expanding all preprocessor macro invocations in
9062 @var{expression}. Since @value{GDBN} simply expands macros, but does
9063 not parse the result, @var{expression} need not be a valid expression;
9064 it can be any string of tokens.
9065
9066 @kindex macro exp1
9067 @item macro expand-once @var{expression}
9068 @itemx macro exp1 @var{expression}
9069 @cindex expand macro once
9070 @i{(This command is not yet implemented.)} Show the results of
9071 expanding those preprocessor macro invocations that appear explicitly in
9072 @var{expression}. Macro invocations appearing in that expansion are
9073 left unchanged. This command allows you to see the effect of a
9074 particular macro more clearly, without being confused by further
9075 expansions. Since @value{GDBN} simply expands macros, but does not
9076 parse the result, @var{expression} need not be a valid expression; it
9077 can be any string of tokens.
9078
9079 @kindex info macro
9080 @cindex macro definition, showing
9081 @cindex definition, showing a macro's
9082 @item info macro @var{macro}
9083 Show the definition of the macro named @var{macro}, and describe the
9084 source location or compiler command-line where that definition was established.
9085
9086 @kindex macro define
9087 @cindex user-defined macros
9088 @cindex defining macros interactively
9089 @cindex macros, user-defined
9090 @item macro define @var{macro} @var{replacement-list}
9091 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
9092 Introduce a definition for a preprocessor macro named @var{macro},
9093 invocations of which are replaced by the tokens given in
9094 @var{replacement-list}. The first form of this command defines an
9095 ``object-like'' macro, which takes no arguments; the second form
9096 defines a ``function-like'' macro, which takes the arguments given in
9097 @var{arglist}.
9098
9099 A definition introduced by this command is in scope in every
9100 expression evaluated in @value{GDBN}, until it is removed with the
9101 @code{macro undef} command, described below. The definition overrides
9102 all definitions for @var{macro} present in the program being debugged,
9103 as well as any previous user-supplied definition.
9104
9105 @kindex macro undef
9106 @item macro undef @var{macro}
9107 Remove any user-supplied definition for the macro named @var{macro}.
9108 This command only affects definitions provided with the @code{macro
9109 define} command, described above; it cannot remove definitions present
9110 in the program being debugged.
9111
9112 @kindex macro list
9113 @item macro list
9114 List all the macros defined using the @code{macro define} command.
9115 @end table
9116
9117 @cindex macros, example of debugging with
9118 Here is a transcript showing the above commands in action. First, we
9119 show our source files:
9120
9121 @smallexample
9122 $ cat sample.c
9123 #include <stdio.h>
9124 #include "sample.h"
9125
9126 #define M 42
9127 #define ADD(x) (M + x)
9128
9129 main ()
9130 @{
9131 #define N 28
9132 printf ("Hello, world!\n");
9133 #undef N
9134 printf ("We're so creative.\n");
9135 #define N 1729
9136 printf ("Goodbye, world!\n");
9137 @}
9138 $ cat sample.h
9139 #define Q <
9140 $
9141 @end smallexample
9142
9143 Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
9144 We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
9145 compiler includes information about preprocessor macros in the debugging
9146 information.
9147
9148 @smallexample
9149 $ gcc -gdwarf-2 -g3 sample.c -o sample
9150 $
9151 @end smallexample
9152
9153 Now, we start @value{GDBN} on our sample program:
9154
9155 @smallexample
9156 $ gdb -nw sample
9157 GNU gdb 2002-05-06-cvs
9158 Copyright 2002 Free Software Foundation, Inc.
9159 GDB is free software, @dots{}
9160 (@value{GDBP})
9161 @end smallexample
9162
9163 We can expand macros and examine their definitions, even when the
9164 program is not running. @value{GDBN} uses the current listing position
9165 to decide which macro definitions are in scope:
9166
9167 @smallexample
9168 (@value{GDBP}) list main
9169 3
9170 4 #define M 42
9171 5 #define ADD(x) (M + x)
9172 6
9173 7 main ()
9174 8 @{
9175 9 #define N 28
9176 10 printf ("Hello, world!\n");
9177 11 #undef N
9178 12 printf ("We're so creative.\n");
9179 (@value{GDBP}) info macro ADD
9180 Defined at /home/jimb/gdb/macros/play/sample.c:5
9181 #define ADD(x) (M + x)
9182 (@value{GDBP}) info macro Q
9183 Defined at /home/jimb/gdb/macros/play/sample.h:1
9184 included at /home/jimb/gdb/macros/play/sample.c:2
9185 #define Q <
9186 (@value{GDBP}) macro expand ADD(1)
9187 expands to: (42 + 1)
9188 (@value{GDBP}) macro expand-once ADD(1)
9189 expands to: once (M + 1)
9190 (@value{GDBP})
9191 @end smallexample
9192
9193 In the example above, note that @code{macro expand-once} expands only
9194 the macro invocation explicit in the original text --- the invocation of
9195 @code{ADD} --- but does not expand the invocation of the macro @code{M},
9196 which was introduced by @code{ADD}.
9197
9198 Once the program is running, @value{GDBN} uses the macro definitions in
9199 force at the source line of the current stack frame:
9200
9201 @smallexample
9202 (@value{GDBP}) break main
9203 Breakpoint 1 at 0x8048370: file sample.c, line 10.
9204 (@value{GDBP}) run
9205 Starting program: /home/jimb/gdb/macros/play/sample
9206
9207 Breakpoint 1, main () at sample.c:10
9208 10 printf ("Hello, world!\n");
9209 (@value{GDBP})
9210 @end smallexample
9211
9212 At line 10, the definition of the macro @code{N} at line 9 is in force:
9213
9214 @smallexample
9215 (@value{GDBP}) info macro N
9216 Defined at /home/jimb/gdb/macros/play/sample.c:9
9217 #define N 28
9218 (@value{GDBP}) macro expand N Q M
9219 expands to: 28 < 42
9220 (@value{GDBP}) print N Q M
9221 $1 = 1
9222 (@value{GDBP})
9223 @end smallexample
9224
9225 As we step over directives that remove @code{N}'s definition, and then
9226 give it a new definition, @value{GDBN} finds the definition (or lack
9227 thereof) in force at each point:
9228
9229 @smallexample
9230 (@value{GDBP}) next
9231 Hello, world!
9232 12 printf ("We're so creative.\n");
9233 (@value{GDBP}) info macro N
9234 The symbol `N' has no definition as a C/C++ preprocessor macro
9235 at /home/jimb/gdb/macros/play/sample.c:12
9236 (@value{GDBP}) next
9237 We're so creative.
9238 14 printf ("Goodbye, world!\n");
9239 (@value{GDBP}) info macro N
9240 Defined at /home/jimb/gdb/macros/play/sample.c:13
9241 #define N 1729
9242 (@value{GDBP}) macro expand N Q M
9243 expands to: 1729 < 42
9244 (@value{GDBP}) print N Q M
9245 $2 = 0
9246 (@value{GDBP})
9247 @end smallexample
9248
9249 In addition to source files, macros can be defined on the compilation command
9250 line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
9251 such a way, @value{GDBN} displays the location of their definition as line zero
9252 of the source file submitted to the compiler.
9253
9254 @smallexample
9255 (@value{GDBP}) info macro __STDC__
9256 Defined at /home/jimb/gdb/macros/play/sample.c:0
9257 -D__STDC__=1
9258 (@value{GDBP})
9259 @end smallexample
9260
9261
9262 @node Tracepoints
9263 @chapter Tracepoints
9264 @c This chapter is based on the documentation written by Michael
9265 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
9266
9267 @cindex tracepoints
9268 In some applications, it is not feasible for the debugger to interrupt
9269 the program's execution long enough for the developer to learn
9270 anything helpful about its behavior. If the program's correctness
9271 depends on its real-time behavior, delays introduced by a debugger
9272 might cause the program to change its behavior drastically, or perhaps
9273 fail, even when the code itself is correct. It is useful to be able
9274 to observe the program's behavior without interrupting it.
9275
9276 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
9277 specify locations in the program, called @dfn{tracepoints}, and
9278 arbitrary expressions to evaluate when those tracepoints are reached.
9279 Later, using the @code{tfind} command, you can examine the values
9280 those expressions had when the program hit the tracepoints. The
9281 expressions may also denote objects in memory---structures or arrays,
9282 for example---whose values @value{GDBN} should record; while visiting
9283 a particular tracepoint, you may inspect those objects as if they were
9284 in memory at that moment. However, because @value{GDBN} records these
9285 values without interacting with you, it can do so quickly and
9286 unobtrusively, hopefully not disturbing the program's behavior.
9287
9288 The tracepoint facility is currently available only for remote
9289 targets. @xref{Targets}. In addition, your remote target must know
9290 how to collect trace data. This functionality is implemented in the
9291 remote stub; however, none of the stubs distributed with @value{GDBN}
9292 support tracepoints as of this writing. The format of the remote
9293 packets used to implement tracepoints are described in @ref{Tracepoint
9294 Packets}.
9295
9296 It is also possible to get trace data from a file, in a manner reminiscent
9297 of corefiles; you specify the filename, and use @code{tfind} to search
9298 through the file. @xref{Trace Files}, for more details.
9299
9300 This chapter describes the tracepoint commands and features.
9301
9302 @menu
9303 * Set Tracepoints::
9304 * Analyze Collected Data::
9305 * Tracepoint Variables::
9306 * Trace Files::
9307 @end menu
9308
9309 @node Set Tracepoints
9310 @section Commands to Set Tracepoints
9311
9312 Before running such a @dfn{trace experiment}, an arbitrary number of
9313 tracepoints can be set. A tracepoint is actually a special type of
9314 breakpoint (@pxref{Set Breaks}), so you can manipulate it using
9315 standard breakpoint commands. For instance, as with breakpoints,
9316 tracepoint numbers are successive integers starting from one, and many
9317 of the commands associated with tracepoints take the tracepoint number
9318 as their argument, to identify which tracepoint to work on.
9319
9320 For each tracepoint, you can specify, in advance, some arbitrary set
9321 of data that you want the target to collect in the trace buffer when
9322 it hits that tracepoint. The collected data can include registers,
9323 local variables, or global data. Later, you can use @value{GDBN}
9324 commands to examine the values these data had at the time the
9325 tracepoint was hit.
9326
9327 Tracepoints do not support every breakpoint feature. Conditional
9328 expressions and ignore counts on tracepoints have no effect, and
9329 tracepoints cannot run @value{GDBN} commands when they are
9330 hit. Tracepoints may not be thread-specific either.
9331
9332 @cindex fast tracepoints
9333 Some targets may support @dfn{fast tracepoints}, which are inserted in
9334 a different way (such as with a jump instead of a trap), that is
9335 faster but possibly restricted in where they may be installed.
9336
9337 This section describes commands to set tracepoints and associated
9338 conditions and actions.
9339
9340 @menu
9341 * Create and Delete Tracepoints::
9342 * Enable and Disable Tracepoints::
9343 * Tracepoint Passcounts::
9344 * Tracepoint Conditions::
9345 * Trace State Variables::
9346 * Tracepoint Actions::
9347 * Listing Tracepoints::
9348 * Starting and Stopping Trace Experiments::
9349 @end menu
9350
9351 @node Create and Delete Tracepoints
9352 @subsection Create and Delete Tracepoints
9353
9354 @table @code
9355 @cindex set tracepoint
9356 @kindex trace
9357 @item trace @var{location}
9358 The @code{trace} command is very similar to the @code{break} command.
9359 Its argument @var{location} can be a source line, a function name, or
9360 an address in the target program. @xref{Specify Location}. The
9361 @code{trace} command defines a tracepoint, which is a point in the
9362 target program where the debugger will briefly stop, collect some
9363 data, and then allow the program to continue. Setting a tracepoint or
9364 changing its actions doesn't take effect until the next @code{tstart}
9365 command, and once a trace experiment is running, further changes will
9366 not have any effect until the next trace experiment starts.
9367
9368 Here are some examples of using the @code{trace} command:
9369
9370 @smallexample
9371 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
9372
9373 (@value{GDBP}) @b{trace +2} // 2 lines forward
9374
9375 (@value{GDBP}) @b{trace my_function} // first source line of function
9376
9377 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
9378
9379 (@value{GDBP}) @b{trace *0x2117c4} // an address
9380 @end smallexample
9381
9382 @noindent
9383 You can abbreviate @code{trace} as @code{tr}.
9384
9385 @item trace @var{location} if @var{cond}
9386 Set a tracepoint with condition @var{cond}; evaluate the expression
9387 @var{cond} each time the tracepoint is reached, and collect data only
9388 if the value is nonzero---that is, if @var{cond} evaluates as true.
9389 @xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
9390 information on tracepoint conditions.
9391
9392 @item ftrace @var{location} [ if @var{cond} ]
9393 @cindex set fast tracepoint
9394 @kindex ftrace
9395 The @code{ftrace} command sets a fast tracepoint. For targets that
9396 support them, fast tracepoints will use a more efficient but possibly
9397 less general technique to trigger data collection, such as a jump
9398 instruction instead of a trap, or some sort of hardware support. It
9399 may not be possible to create a fast tracepoint at the desired
9400 location, in which case the command will exit with an explanatory
9401 message.
9402
9403 @value{GDBN} handles arguments to @code{ftrace} exactly as for
9404 @code{trace}.
9405
9406 @vindex $tpnum
9407 @cindex last tracepoint number
9408 @cindex recent tracepoint number
9409 @cindex tracepoint number
9410 The convenience variable @code{$tpnum} records the tracepoint number
9411 of the most recently set tracepoint.
9412
9413 @kindex delete tracepoint
9414 @cindex tracepoint deletion
9415 @item delete tracepoint @r{[}@var{num}@r{]}
9416 Permanently delete one or more tracepoints. With no argument, the
9417 default is to delete all tracepoints. Note that the regular
9418 @code{delete} command can remove tracepoints also.
9419
9420 Examples:
9421
9422 @smallexample
9423 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
9424
9425 (@value{GDBP}) @b{delete trace} // remove all tracepoints
9426 @end smallexample
9427
9428 @noindent
9429 You can abbreviate this command as @code{del tr}.
9430 @end table
9431
9432 @node Enable and Disable Tracepoints
9433 @subsection Enable and Disable Tracepoints
9434
9435 These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
9436
9437 @table @code
9438 @kindex disable tracepoint
9439 @item disable tracepoint @r{[}@var{num}@r{]}
9440 Disable tracepoint @var{num}, or all tracepoints if no argument
9441 @var{num} is given. A disabled tracepoint will have no effect during
9442 the next trace experiment, but it is not forgotten. You can re-enable
9443 a disabled tracepoint using the @code{enable tracepoint} command.
9444
9445 @kindex enable tracepoint
9446 @item enable tracepoint @r{[}@var{num}@r{]}
9447 Enable tracepoint @var{num}, or all tracepoints. The enabled
9448 tracepoints will become effective the next time a trace experiment is
9449 run.
9450 @end table
9451
9452 @node Tracepoint Passcounts
9453 @subsection Tracepoint Passcounts
9454
9455 @table @code
9456 @kindex passcount
9457 @cindex tracepoint pass count
9458 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
9459 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
9460 automatically stop a trace experiment. If a tracepoint's passcount is
9461 @var{n}, then the trace experiment will be automatically stopped on
9462 the @var{n}'th time that tracepoint is hit. If the tracepoint number
9463 @var{num} is not specified, the @code{passcount} command sets the
9464 passcount of the most recently defined tracepoint. If no passcount is
9465 given, the trace experiment will run until stopped explicitly by the
9466 user.
9467
9468 Examples:
9469
9470 @smallexample
9471 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
9472 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
9473
9474 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
9475 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
9476 (@value{GDBP}) @b{trace foo}
9477 (@value{GDBP}) @b{pass 3}
9478 (@value{GDBP}) @b{trace bar}
9479 (@value{GDBP}) @b{pass 2}
9480 (@value{GDBP}) @b{trace baz}
9481 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
9482 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
9483 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
9484 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
9485 @end smallexample
9486 @end table
9487
9488 @node Tracepoint Conditions
9489 @subsection Tracepoint Conditions
9490 @cindex conditional tracepoints
9491 @cindex tracepoint conditions
9492
9493 The simplest sort of tracepoint collects data every time your program
9494 reaches a specified place. You can also specify a @dfn{condition} for
9495 a tracepoint. A condition is just a Boolean expression in your
9496 programming language (@pxref{Expressions, ,Expressions}). A
9497 tracepoint with a condition evaluates the expression each time your
9498 program reaches it, and data collection happens only if the condition
9499 is true.
9500
9501 Tracepoint conditions can be specified when a tracepoint is set, by
9502 using @samp{if} in the arguments to the @code{trace} command.
9503 @xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
9504 also be set or changed at any time with the @code{condition} command,
9505 just as with breakpoints.
9506
9507 Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
9508 the conditional expression itself. Instead, @value{GDBN} encodes the
9509 expression into an agent expression (@pxref{Agent Expressions}
9510 suitable for execution on the target, independently of @value{GDBN}.
9511 Global variables become raw memory locations, locals become stack
9512 accesses, and so forth.
9513
9514 For instance, suppose you have a function that is usually called
9515 frequently, but should not be called after an error has occurred. You
9516 could use the following tracepoint command to collect data about calls
9517 of that function that happen while the error code is propagating
9518 through the program; an unconditional tracepoint could end up
9519 collecting thousands of useless trace frames that you would have to
9520 search through.
9521
9522 @smallexample
9523 (@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
9524 @end smallexample
9525
9526 @node Trace State Variables
9527 @subsection Trace State Variables
9528 @cindex trace state variables
9529
9530 A @dfn{trace state variable} is a special type of variable that is
9531 created and managed by target-side code. The syntax is the same as
9532 that for GDB's convenience variables (a string prefixed with ``$''),
9533 but they are stored on the target. They must be created explicitly,
9534 using a @code{tvariable} command. They are always 64-bit signed
9535 integers.
9536
9537 Trace state variables are remembered by @value{GDBN}, and downloaded
9538 to the target along with tracepoint information when the trace
9539 experiment starts. There are no intrinsic limits on the number of
9540 trace state variables, beyond memory limitations of the target.
9541
9542 @cindex convenience variables, and trace state variables
9543 Although trace state variables are managed by the target, you can use
9544 them in print commands and expressions as if they were convenience
9545 variables; @value{GDBN} will get the current value from the target
9546 while the trace experiment is running. Trace state variables share
9547 the same namespace as other ``$'' variables, which means that you
9548 cannot have trace state variables with names like @code{$23} or
9549 @code{$pc}, nor can you have a trace state variable and a convenience
9550 variable with the same name.
9551
9552 @table @code
9553
9554 @item tvariable $@var{name} [ = @var{expression} ]
9555 @kindex tvariable
9556 The @code{tvariable} command creates a new trace state variable named
9557 @code{$@var{name}}, and optionally gives it an initial value of
9558 @var{expression}. @var{expression} is evaluated when this command is
9559 entered; the result will be converted to an integer if possible,
9560 otherwise @value{GDBN} will report an error. A subsequent
9561 @code{tvariable} command specifying the same name does not create a
9562 variable, but instead assigns the supplied initial value to the
9563 existing variable of that name, overwriting any previous initial
9564 value. The default initial value is 0.
9565
9566 @item info tvariables
9567 @kindex info tvariables
9568 List all the trace state variables along with their initial values.
9569 Their current values may also be displayed, if the trace experiment is
9570 currently running.
9571
9572 @item delete tvariable @r{[} $@var{name} @dots{} @r{]}
9573 @kindex delete tvariable
9574 Delete the given trace state variables, or all of them if no arguments
9575 are specified.
9576
9577 @end table
9578
9579 @node Tracepoint Actions
9580 @subsection Tracepoint Action Lists
9581
9582 @table @code
9583 @kindex actions
9584 @cindex tracepoint actions
9585 @item actions @r{[}@var{num}@r{]}
9586 This command will prompt for a list of actions to be taken when the
9587 tracepoint is hit. If the tracepoint number @var{num} is not
9588 specified, this command sets the actions for the one that was most
9589 recently defined (so that you can define a tracepoint and then say
9590 @code{actions} without bothering about its number). You specify the
9591 actions themselves on the following lines, one action at a time, and
9592 terminate the actions list with a line containing just @code{end}. So
9593 far, the only defined actions are @code{collect} and
9594 @code{while-stepping}.
9595
9596 @cindex remove actions from a tracepoint
9597 To remove all actions from a tracepoint, type @samp{actions @var{num}}
9598 and follow it immediately with @samp{end}.
9599
9600 @smallexample
9601 (@value{GDBP}) @b{collect @var{data}} // collect some data
9602
9603 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
9604
9605 (@value{GDBP}) @b{end} // signals the end of actions.
9606 @end smallexample
9607
9608 In the following example, the action list begins with @code{collect}
9609 commands indicating the things to be collected when the tracepoint is
9610 hit. Then, in order to single-step and collect additional data
9611 following the tracepoint, a @code{while-stepping} command is used,
9612 followed by the list of things to be collected while stepping. The
9613 @code{while-stepping} command is terminated by its own separate
9614 @code{end} command. Lastly, the action list is terminated by an
9615 @code{end} command.
9616
9617 @smallexample
9618 (@value{GDBP}) @b{trace foo}
9619 (@value{GDBP}) @b{actions}
9620 Enter actions for tracepoint 1, one per line:
9621 > collect bar,baz
9622 > collect $regs
9623 > while-stepping 12
9624 > collect $fp, $sp
9625 > end
9626 end
9627 @end smallexample
9628
9629 @kindex collect @r{(tracepoints)}
9630 @item collect @var{expr1}, @var{expr2}, @dots{}
9631 Collect values of the given expressions when the tracepoint is hit.
9632 This command accepts a comma-separated list of any valid expressions.
9633 In addition to global, static, or local variables, the following
9634 special arguments are supported:
9635
9636 @table @code
9637 @item $regs
9638 collect all registers
9639
9640 @item $args
9641 collect all function arguments
9642
9643 @item $locals
9644 collect all local variables.
9645 @end table
9646
9647 You can give several consecutive @code{collect} commands, each one
9648 with a single argument, or one @code{collect} command with several
9649 arguments separated by commas: the effect is the same.
9650
9651 The command @code{info scope} (@pxref{Symbols, info scope}) is
9652 particularly useful for figuring out what data to collect.
9653
9654 @kindex teval @r{(tracepoints)}
9655 @item teval @var{expr1}, @var{expr2}, @dots{}
9656 Evaluate the given expressions when the tracepoint is hit. This
9657 command accepts a comma-separated list of expressions. The results
9658 are discarded, so this is mainly useful for assigning values to trace
9659 state variables (@pxref{Trace State Variables}) without adding those
9660 values to the trace buffer, as would be the case if the @code{collect}
9661 action were used.
9662
9663 @kindex while-stepping @r{(tracepoints)}
9664 @item while-stepping @var{n}
9665 Perform @var{n} single-step traces after the tracepoint, collecting
9666 new data at each step. The @code{while-stepping} command is
9667 followed by the list of what to collect while stepping (followed by
9668 its own @code{end} command):
9669
9670 @smallexample
9671 > while-stepping 12
9672 > collect $regs, myglobal
9673 > end
9674 >
9675 @end smallexample
9676
9677 @noindent
9678 You may abbreviate @code{while-stepping} as @code{ws} or
9679 @code{stepping}.
9680
9681 @item set default-collect @var{expr1}, @var{expr2}, @dots{}
9682 @kindex set default-collect
9683 @cindex default collection action
9684 This variable is a list of expressions to collect at each tracepoint
9685 hit. It is effectively an additional @code{collect} action prepended
9686 to every tracepoint action list. The expressions are parsed
9687 individually for each tracepoint, so for instance a variable named
9688 @code{xyz} may be interpreted as a global for one tracepoint, and a
9689 local for another, as appropriate to the tracepoint's location.
9690
9691 @item show default-collect
9692 @kindex show default-collect
9693 Show the list of expressions that are collected by default at each
9694 tracepoint hit.
9695
9696 @end table
9697
9698 @node Listing Tracepoints
9699 @subsection Listing Tracepoints
9700
9701 @table @code
9702 @kindex info tracepoints
9703 @kindex info tp
9704 @cindex information about tracepoints
9705 @item info tracepoints @r{[}@var{num}@r{]}
9706 Display information about the tracepoint @var{num}. If you don't
9707 specify a tracepoint number, displays information about all the
9708 tracepoints defined so far. The format is similar to that used for
9709 @code{info breakpoints}; in fact, @code{info tracepoints} is the same
9710 command, simply restricting itself to tracepoints.
9711
9712 A tracepoint's listing may include additional information specific to
9713 tracing:
9714
9715 @itemize @bullet
9716 @item
9717 its passcount as given by the @code{passcount @var{n}} command
9718 @item
9719 its step count as given by the @code{while-stepping @var{n}} command
9720 @item
9721 its action list as given by the @code{actions} command. The actions
9722 are prefixed with an @samp{A} so as to distinguish them from commands.
9723 @end itemize
9724
9725 @smallexample
9726 (@value{GDBP}) @b{info trace}
9727 Num Type Disp Enb Address What
9728 1 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
9729 pass count 1200
9730 step count 20
9731 A while-stepping 20
9732 A collect globfoo, $regs
9733 A end
9734 A collect globfoo2
9735 A end
9736 (@value{GDBP})
9737 @end smallexample
9738
9739 @noindent
9740 This command can be abbreviated @code{info tp}.
9741 @end table
9742
9743 @node Starting and Stopping Trace Experiments
9744 @subsection Starting and Stopping Trace Experiments
9745
9746 @table @code
9747 @kindex tstart
9748 @cindex start a new trace experiment
9749 @cindex collected data discarded
9750 @item tstart
9751 This command takes no arguments. It starts the trace experiment, and
9752 begins collecting data. This has the side effect of discarding all
9753 the data collected in the trace buffer during the previous trace
9754 experiment.
9755
9756 @kindex tstop
9757 @cindex stop a running trace experiment
9758 @item tstop
9759 This command takes no arguments. It ends the trace experiment, and
9760 stops collecting data.
9761
9762 @strong{Note}: a trace experiment and data collection may stop
9763 automatically if any tracepoint's passcount is reached
9764 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
9765
9766 @kindex tstatus
9767 @cindex status of trace data collection
9768 @cindex trace experiment, status of
9769 @item tstatus
9770 This command displays the status of the current trace data
9771 collection.
9772 @end table
9773
9774 Here is an example of the commands we described so far:
9775
9776 @smallexample
9777 (@value{GDBP}) @b{trace gdb_c_test}
9778 (@value{GDBP}) @b{actions}
9779 Enter actions for tracepoint #1, one per line.
9780 > collect $regs,$locals,$args
9781 > while-stepping 11
9782 > collect $regs
9783 > end
9784 > end
9785 (@value{GDBP}) @b{tstart}
9786 [time passes @dots{}]
9787 (@value{GDBP}) @b{tstop}
9788 @end smallexample
9789
9790 @cindex disconnected tracing
9791 You can choose to continue running the trace experiment even if
9792 @value{GDBN} disconnects from the target, voluntarily or
9793 involuntarily. For commands such as @code{detach}, the debugger will
9794 ask what you want to do with the trace. But for unexpected
9795 terminations (@value{GDBN} crash, network outage), it would be
9796 unfortunate to lose hard-won trace data, so the variable
9797 @code{disconnected-tracing} lets you decide whether the trace should
9798 continue running without @value{GDBN}.
9799
9800 @table @code
9801 @item set disconnected-tracing on
9802 @itemx set disconnected-tracing off
9803 @kindex set disconnected-tracing
9804 Choose whether a tracing run should continue to run if @value{GDBN}
9805 has disconnected from the target. Note that @code{detach} or
9806 @code{quit} will ask you directly what to do about a running trace no
9807 matter what this variable's setting, so the variable is mainly useful
9808 for handling unexpected situations, such as loss of the network.
9809
9810 @item show disconnected-tracing
9811 @kindex show disconnected-tracing
9812 Show the current choice for disconnected tracing.
9813
9814 @end table
9815
9816 When you reconnect to the target, the trace experiment may or may not
9817 still be running; it might have filled the trace buffer in the
9818 meantime, or stopped for one of the other reasons. If it is running,
9819 it will continue after reconnection.
9820
9821 Upon reconnection, the target will upload information about the
9822 tracepoints in effect. @value{GDBN} will then compare that
9823 information to the set of tracepoints currently defined, and attempt
9824 to match them up, allowing for the possibility that the numbers may
9825 have changed due to creation and deletion in the meantime. If one of
9826 the target's tracepoints does not match any in @value{GDBN}, the
9827 debugger will create a new tracepoint, so that you have a number with
9828 which to specify that tracepoint. This matching-up process is
9829 necessarily heuristic, and it may result in useless tracepoints being
9830 created; you may simply delete them if they are of no use.
9831
9832 @node Analyze Collected Data
9833 @section Using the Collected Data
9834
9835 After the tracepoint experiment ends, you use @value{GDBN} commands
9836 for examining the trace data. The basic idea is that each tracepoint
9837 collects a trace @dfn{snapshot} every time it is hit and another
9838 snapshot every time it single-steps. All these snapshots are
9839 consecutively numbered from zero and go into a buffer, and you can
9840 examine them later. The way you examine them is to @dfn{focus} on a
9841 specific trace snapshot. When the remote stub is focused on a trace
9842 snapshot, it will respond to all @value{GDBN} requests for memory and
9843 registers by reading from the buffer which belongs to that snapshot,
9844 rather than from @emph{real} memory or registers of the program being
9845 debugged. This means that @strong{all} @value{GDBN} commands
9846 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
9847 behave as if we were currently debugging the program state as it was
9848 when the tracepoint occurred. Any requests for data that are not in
9849 the buffer will fail.
9850
9851 @menu
9852 * tfind:: How to select a trace snapshot
9853 * tdump:: How to display all data for a snapshot
9854 * save-tracepoints:: How to save tracepoints for a future run
9855 @end menu
9856
9857 @node tfind
9858 @subsection @code{tfind @var{n}}
9859
9860 @kindex tfind
9861 @cindex select trace snapshot
9862 @cindex find trace snapshot
9863 The basic command for selecting a trace snapshot from the buffer is
9864 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
9865 counting from zero. If no argument @var{n} is given, the next
9866 snapshot is selected.
9867
9868 Here are the various forms of using the @code{tfind} command.
9869
9870 @table @code
9871 @item tfind start
9872 Find the first snapshot in the buffer. This is a synonym for
9873 @code{tfind 0} (since 0 is the number of the first snapshot).
9874
9875 @item tfind none
9876 Stop debugging trace snapshots, resume @emph{live} debugging.
9877
9878 @item tfind end
9879 Same as @samp{tfind none}.
9880
9881 @item tfind
9882 No argument means find the next trace snapshot.
9883
9884 @item tfind -
9885 Find the previous trace snapshot before the current one. This permits
9886 retracing earlier steps.
9887
9888 @item tfind tracepoint @var{num}
9889 Find the next snapshot associated with tracepoint @var{num}. Search
9890 proceeds forward from the last examined trace snapshot. If no
9891 argument @var{num} is given, it means find the next snapshot collected
9892 for the same tracepoint as the current snapshot.
9893
9894 @item tfind pc @var{addr}
9895 Find the next snapshot associated with the value @var{addr} of the
9896 program counter. Search proceeds forward from the last examined trace
9897 snapshot. If no argument @var{addr} is given, it means find the next
9898 snapshot with the same value of PC as the current snapshot.
9899
9900 @item tfind outside @var{addr1}, @var{addr2}
9901 Find the next snapshot whose PC is outside the given range of
9902 addresses.
9903
9904 @item tfind range @var{addr1}, @var{addr2}
9905 Find the next snapshot whose PC is between @var{addr1} and
9906 @var{addr2}. @c FIXME: Is the range inclusive or exclusive?
9907
9908 @item tfind line @r{[}@var{file}:@r{]}@var{n}
9909 Find the next snapshot associated with the source line @var{n}. If
9910 the optional argument @var{file} is given, refer to line @var{n} in
9911 that source file. Search proceeds forward from the last examined
9912 trace snapshot. If no argument @var{n} is given, it means find the
9913 next line other than the one currently being examined; thus saying
9914 @code{tfind line} repeatedly can appear to have the same effect as
9915 stepping from line to line in a @emph{live} debugging session.
9916 @end table
9917
9918 The default arguments for the @code{tfind} commands are specifically
9919 designed to make it easy to scan through the trace buffer. For
9920 instance, @code{tfind} with no argument selects the next trace
9921 snapshot, and @code{tfind -} with no argument selects the previous
9922 trace snapshot. So, by giving one @code{tfind} command, and then
9923 simply hitting @key{RET} repeatedly you can examine all the trace
9924 snapshots in order. Or, by saying @code{tfind -} and then hitting
9925 @key{RET} repeatedly you can examine the snapshots in reverse order.
9926 The @code{tfind line} command with no argument selects the snapshot
9927 for the next source line executed. The @code{tfind pc} command with
9928 no argument selects the next snapshot with the same program counter
9929 (PC) as the current frame. The @code{tfind tracepoint} command with
9930 no argument selects the next trace snapshot collected by the same
9931 tracepoint as the current one.
9932
9933 In addition to letting you scan through the trace buffer manually,
9934 these commands make it easy to construct @value{GDBN} scripts that
9935 scan through the trace buffer and print out whatever collected data
9936 you are interested in. Thus, if we want to examine the PC, FP, and SP
9937 registers from each trace frame in the buffer, we can say this:
9938
9939 @smallexample
9940 (@value{GDBP}) @b{tfind start}
9941 (@value{GDBP}) @b{while ($trace_frame != -1)}
9942 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
9943 $trace_frame, $pc, $sp, $fp
9944 > tfind
9945 > end
9946
9947 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
9948 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
9949 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
9950 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
9951 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
9952 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
9953 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
9954 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
9955 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
9956 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
9957 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
9958 @end smallexample
9959
9960 Or, if we want to examine the variable @code{X} at each source line in
9961 the buffer:
9962
9963 @smallexample
9964 (@value{GDBP}) @b{tfind start}
9965 (@value{GDBP}) @b{while ($trace_frame != -1)}
9966 > printf "Frame %d, X == %d\n", $trace_frame, X
9967 > tfind line
9968 > end
9969
9970 Frame 0, X = 1
9971 Frame 7, X = 2
9972 Frame 13, X = 255
9973 @end smallexample
9974
9975 @node tdump
9976 @subsection @code{tdump}
9977 @kindex tdump
9978 @cindex dump all data collected at tracepoint
9979 @cindex tracepoint data, display
9980
9981 This command takes no arguments. It prints all the data collected at
9982 the current trace snapshot.
9983
9984 @smallexample
9985 (@value{GDBP}) @b{trace 444}
9986 (@value{GDBP}) @b{actions}
9987 Enter actions for tracepoint #2, one per line:
9988 > collect $regs, $locals, $args, gdb_long_test
9989 > end
9990
9991 (@value{GDBP}) @b{tstart}
9992
9993 (@value{GDBP}) @b{tfind line 444}
9994 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
9995 at gdb_test.c:444
9996 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
9997
9998 (@value{GDBP}) @b{tdump}
9999 Data collected at tracepoint 2, trace frame 1:
10000 d0 0xc4aa0085 -995491707
10001 d1 0x18 24
10002 d2 0x80 128
10003 d3 0x33 51
10004 d4 0x71aea3d 119204413
10005 d5 0x22 34
10006 d6 0xe0 224
10007 d7 0x380035 3670069
10008 a0 0x19e24a 1696330
10009 a1 0x3000668 50333288
10010 a2 0x100 256
10011 a3 0x322000 3284992
10012 a4 0x3000698 50333336
10013 a5 0x1ad3cc 1758156
10014 fp 0x30bf3c 0x30bf3c
10015 sp 0x30bf34 0x30bf34
10016 ps 0x0 0
10017 pc 0x20b2c8 0x20b2c8
10018 fpcontrol 0x0 0
10019 fpstatus 0x0 0
10020 fpiaddr 0x0 0
10021 p = 0x20e5b4 "gdb-test"
10022 p1 = (void *) 0x11
10023 p2 = (void *) 0x22
10024 p3 = (void *) 0x33
10025 p4 = (void *) 0x44
10026 p5 = (void *) 0x55
10027 p6 = (void *) 0x66
10028 gdb_long_test = 17 '\021'
10029
10030 (@value{GDBP})
10031 @end smallexample
10032
10033 @node save-tracepoints
10034 @subsection @code{save-tracepoints @var{filename}}
10035 @kindex save-tracepoints
10036 @cindex save tracepoints for future sessions
10037
10038 This command saves all current tracepoint definitions together with
10039 their actions and passcounts, into a file @file{@var{filename}}
10040 suitable for use in a later debugging session. To read the saved
10041 tracepoint definitions, use the @code{source} command (@pxref{Command
10042 Files}).
10043
10044 @node Tracepoint Variables
10045 @section Convenience Variables for Tracepoints
10046 @cindex tracepoint variables
10047 @cindex convenience variables for tracepoints
10048
10049 @table @code
10050 @vindex $trace_frame
10051 @item (int) $trace_frame
10052 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
10053 snapshot is selected.
10054
10055 @vindex $tracepoint
10056 @item (int) $tracepoint
10057 The tracepoint for the current trace snapshot.
10058
10059 @vindex $trace_line
10060 @item (int) $trace_line
10061 The line number for the current trace snapshot.
10062
10063 @vindex $trace_file
10064 @item (char []) $trace_file
10065 The source file for the current trace snapshot.
10066
10067 @vindex $trace_func
10068 @item (char []) $trace_func
10069 The name of the function containing @code{$tracepoint}.
10070 @end table
10071
10072 Note: @code{$trace_file} is not suitable for use in @code{printf},
10073 use @code{output} instead.
10074
10075 Here's a simple example of using these convenience variables for
10076 stepping through all the trace snapshots and printing some of their
10077 data. Note that these are not the same as trace state variables,
10078 which are managed by the target.
10079
10080 @smallexample
10081 (@value{GDBP}) @b{tfind start}
10082
10083 (@value{GDBP}) @b{while $trace_frame != -1}
10084 > output $trace_file
10085 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
10086 > tfind
10087 > end
10088 @end smallexample
10089
10090 @node Trace Files
10091 @section Using Trace Files
10092 @cindex trace files
10093
10094 In some situations, the target running a trace experiment may no
10095 longer be available; perhaps it crashed, or the hardware was needed
10096 for a different activity. To handle these cases, you can arrange to
10097 dump the trace data into a file, and later use that file as a source
10098 of trace data, via the @code{target tfile} command.
10099
10100 @table @code
10101
10102 @kindex tsave
10103 @item tsave [ -r ] @var{filename}
10104 Save the trace data to @var{filename}. By default, this command
10105 assumes that @var{filename} refers to the host filesystem, so if
10106 necessary @value{GDBN} will copy raw trace data up from the target and
10107 then save it. If the target supports it, you can also supply the
10108 optional argument @code{-r} (``remote'') to direct the target to save
10109 the data directly into @var{filename} in its own filesystem, which may be
10110 more efficient if the trace buffer is very large. (Note, however, that
10111 @code{target tfile} can only read from files accessible to the host.)
10112
10113 @kindex target tfile
10114 @kindex tfile
10115 @item target tfile @var{filename}
10116 Use the file named @var{filename} as a source of trace data. Commands
10117 that examine data work as they do with a live target, but it is not
10118 possible to run any new trace experiments. @code{tstatus} will report
10119 the state of the trace run at the moment the data was saved, as well
10120 as the current trace frame you are examining. @var{filename} must be
10121 on a filesystem accessible to the host.
10122
10123 @end table
10124
10125 @node Overlays
10126 @chapter Debugging Programs That Use Overlays
10127 @cindex overlays
10128
10129 If your program is too large to fit completely in your target system's
10130 memory, you can sometimes use @dfn{overlays} to work around this
10131 problem. @value{GDBN} provides some support for debugging programs that
10132 use overlays.
10133
10134 @menu
10135 * How Overlays Work:: A general explanation of overlays.
10136 * Overlay Commands:: Managing overlays in @value{GDBN}.
10137 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
10138 mapped by asking the inferior.
10139 * Overlay Sample Program:: A sample program using overlays.
10140 @end menu
10141
10142 @node How Overlays Work
10143 @section How Overlays Work
10144 @cindex mapped overlays
10145 @cindex unmapped overlays
10146 @cindex load address, overlay's
10147 @cindex mapped address
10148 @cindex overlay area
10149
10150 Suppose you have a computer whose instruction address space is only 64
10151 kilobytes long, but which has much more memory which can be accessed by
10152 other means: special instructions, segment registers, or memory
10153 management hardware, for example. Suppose further that you want to
10154 adapt a program which is larger than 64 kilobytes to run on this system.
10155
10156 One solution is to identify modules of your program which are relatively
10157 independent, and need not call each other directly; call these modules
10158 @dfn{overlays}. Separate the overlays from the main program, and place
10159 their machine code in the larger memory. Place your main program in
10160 instruction memory, but leave at least enough space there to hold the
10161 largest overlay as well.
10162
10163 Now, to call a function located in an overlay, you must first copy that
10164 overlay's machine code from the large memory into the space set aside
10165 for it in the instruction memory, and then jump to its entry point
10166 there.
10167
10168 @c NB: In the below the mapped area's size is greater or equal to the
10169 @c size of all overlays. This is intentional to remind the developer
10170 @c that overlays don't necessarily need to be the same size.
10171
10172 @smallexample
10173 @group
10174 Data Instruction Larger
10175 Address Space Address Space Address Space
10176 +-----------+ +-----------+ +-----------+
10177 | | | | | |
10178 +-----------+ +-----------+ +-----------+<-- overlay 1
10179 | program | | main | .----| overlay 1 | load address
10180 | variables | | program | | +-----------+
10181 | and heap | | | | | |
10182 +-----------+ | | | +-----------+<-- overlay 2
10183 | | +-----------+ | | | load address
10184 +-----------+ | | | .-| overlay 2 |
10185 | | | | | |
10186 mapped --->+-----------+ | | +-----------+
10187 address | | | | | |
10188 | overlay | <-' | | |
10189 | area | <---' +-----------+<-- overlay 3
10190 | | <---. | | load address
10191 +-----------+ `--| overlay 3 |
10192 | | | |
10193 +-----------+ | |
10194 +-----------+
10195 | |
10196 +-----------+
10197
10198 @anchor{A code overlay}A code overlay
10199 @end group
10200 @end smallexample
10201
10202 The diagram (@pxref{A code overlay}) shows a system with separate data
10203 and instruction address spaces. To map an overlay, the program copies
10204 its code from the larger address space to the instruction address space.
10205 Since the overlays shown here all use the same mapped address, only one
10206 may be mapped at a time. For a system with a single address space for
10207 data and instructions, the diagram would be similar, except that the
10208 program variables and heap would share an address space with the main
10209 program and the overlay area.
10210
10211 An overlay loaded into instruction memory and ready for use is called a
10212 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
10213 instruction memory. An overlay not present (or only partially present)
10214 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
10215 is its address in the larger memory. The mapped address is also called
10216 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
10217 called the @dfn{load memory address}, or @dfn{LMA}.
10218
10219 Unfortunately, overlays are not a completely transparent way to adapt a
10220 program to limited instruction memory. They introduce a new set of
10221 global constraints you must keep in mind as you design your program:
10222
10223 @itemize @bullet
10224
10225 @item
10226 Before calling or returning to a function in an overlay, your program
10227 must make sure that overlay is actually mapped. Otherwise, the call or
10228 return will transfer control to the right address, but in the wrong
10229 overlay, and your program will probably crash.
10230
10231 @item
10232 If the process of mapping an overlay is expensive on your system, you
10233 will need to choose your overlays carefully to minimize their effect on
10234 your program's performance.
10235
10236 @item
10237 The executable file you load onto your system must contain each
10238 overlay's instructions, appearing at the overlay's load address, not its
10239 mapped address. However, each overlay's instructions must be relocated
10240 and its symbols defined as if the overlay were at its mapped address.
10241 You can use GNU linker scripts to specify different load and relocation
10242 addresses for pieces of your program; see @ref{Overlay Description,,,
10243 ld.info, Using ld: the GNU linker}.
10244
10245 @item
10246 The procedure for loading executable files onto your system must be able
10247 to load their contents into the larger address space as well as the
10248 instruction and data spaces.
10249
10250 @end itemize
10251
10252 The overlay system described above is rather simple, and could be
10253 improved in many ways:
10254
10255 @itemize @bullet
10256
10257 @item
10258 If your system has suitable bank switch registers or memory management
10259 hardware, you could use those facilities to make an overlay's load area
10260 contents simply appear at their mapped address in instruction space.
10261 This would probably be faster than copying the overlay to its mapped
10262 area in the usual way.
10263
10264 @item
10265 If your overlays are small enough, you could set aside more than one
10266 overlay area, and have more than one overlay mapped at a time.
10267
10268 @item
10269 You can use overlays to manage data, as well as instructions. In
10270 general, data overlays are even less transparent to your design than
10271 code overlays: whereas code overlays only require care when you call or
10272 return to functions, data overlays require care every time you access
10273 the data. Also, if you change the contents of a data overlay, you
10274 must copy its contents back out to its load address before you can copy a
10275 different data overlay into the same mapped area.
10276
10277 @end itemize
10278
10279
10280 @node Overlay Commands
10281 @section Overlay Commands
10282
10283 To use @value{GDBN}'s overlay support, each overlay in your program must
10284 correspond to a separate section of the executable file. The section's
10285 virtual memory address and load memory address must be the overlay's
10286 mapped and load addresses. Identifying overlays with sections allows
10287 @value{GDBN} to determine the appropriate address of a function or
10288 variable, depending on whether the overlay is mapped or not.
10289
10290 @value{GDBN}'s overlay commands all start with the word @code{overlay};
10291 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
10292
10293 @table @code
10294 @item overlay off
10295 @kindex overlay
10296 Disable @value{GDBN}'s overlay support. When overlay support is
10297 disabled, @value{GDBN} assumes that all functions and variables are
10298 always present at their mapped addresses. By default, @value{GDBN}'s
10299 overlay support is disabled.
10300
10301 @item overlay manual
10302 @cindex manual overlay debugging
10303 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
10304 relies on you to tell it which overlays are mapped, and which are not,
10305 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
10306 commands described below.
10307
10308 @item overlay map-overlay @var{overlay}
10309 @itemx overlay map @var{overlay}
10310 @cindex map an overlay
10311 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
10312 be the name of the object file section containing the overlay. When an
10313 overlay is mapped, @value{GDBN} assumes it can find the overlay's
10314 functions and variables at their mapped addresses. @value{GDBN} assumes
10315 that any other overlays whose mapped ranges overlap that of
10316 @var{overlay} are now unmapped.
10317
10318 @item overlay unmap-overlay @var{overlay}
10319 @itemx overlay unmap @var{overlay}
10320 @cindex unmap an overlay
10321 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
10322 must be the name of the object file section containing the overlay.
10323 When an overlay is unmapped, @value{GDBN} assumes it can find the
10324 overlay's functions and variables at their load addresses.
10325
10326 @item overlay auto
10327 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
10328 consults a data structure the overlay manager maintains in the inferior
10329 to see which overlays are mapped. For details, see @ref{Automatic
10330 Overlay Debugging}.
10331
10332 @item overlay load-target
10333 @itemx overlay load
10334 @cindex reloading the overlay table
10335 Re-read the overlay table from the inferior. Normally, @value{GDBN}
10336 re-reads the table @value{GDBN} automatically each time the inferior
10337 stops, so this command should only be necessary if you have changed the
10338 overlay mapping yourself using @value{GDBN}. This command is only
10339 useful when using automatic overlay debugging.
10340
10341 @item overlay list-overlays
10342 @itemx overlay list
10343 @cindex listing mapped overlays
10344 Display a list of the overlays currently mapped, along with their mapped
10345 addresses, load addresses, and sizes.
10346
10347 @end table
10348
10349 Normally, when @value{GDBN} prints a code address, it includes the name
10350 of the function the address falls in:
10351
10352 @smallexample
10353 (@value{GDBP}) print main
10354 $3 = @{int ()@} 0x11a0 <main>
10355 @end smallexample
10356 @noindent
10357 When overlay debugging is enabled, @value{GDBN} recognizes code in
10358 unmapped overlays, and prints the names of unmapped functions with
10359 asterisks around them. For example, if @code{foo} is a function in an
10360 unmapped overlay, @value{GDBN} prints it this way:
10361
10362 @smallexample
10363 (@value{GDBP}) overlay list
10364 No sections are mapped.
10365 (@value{GDBP}) print foo
10366 $5 = @{int (int)@} 0x100000 <*foo*>
10367 @end smallexample
10368 @noindent
10369 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
10370 name normally:
10371
10372 @smallexample
10373 (@value{GDBP}) overlay list
10374 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
10375 mapped at 0x1016 - 0x104a
10376 (@value{GDBP}) print foo
10377 $6 = @{int (int)@} 0x1016 <foo>
10378 @end smallexample
10379
10380 When overlay debugging is enabled, @value{GDBN} can find the correct
10381 address for functions and variables in an overlay, whether or not the
10382 overlay is mapped. This allows most @value{GDBN} commands, like
10383 @code{break} and @code{disassemble}, to work normally, even on unmapped
10384 code. However, @value{GDBN}'s breakpoint support has some limitations:
10385
10386 @itemize @bullet
10387 @item
10388 @cindex breakpoints in overlays
10389 @cindex overlays, setting breakpoints in
10390 You can set breakpoints in functions in unmapped overlays, as long as
10391 @value{GDBN} can write to the overlay at its load address.
10392 @item
10393 @value{GDBN} can not set hardware or simulator-based breakpoints in
10394 unmapped overlays. However, if you set a breakpoint at the end of your
10395 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
10396 you are using manual overlay management), @value{GDBN} will re-set its
10397 breakpoints properly.
10398 @end itemize
10399
10400
10401 @node Automatic Overlay Debugging
10402 @section Automatic Overlay Debugging
10403 @cindex automatic overlay debugging
10404
10405 @value{GDBN} can automatically track which overlays are mapped and which
10406 are not, given some simple co-operation from the overlay manager in the
10407 inferior. If you enable automatic overlay debugging with the
10408 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
10409 looks in the inferior's memory for certain variables describing the
10410 current state of the overlays.
10411
10412 Here are the variables your overlay manager must define to support
10413 @value{GDBN}'s automatic overlay debugging:
10414
10415 @table @asis
10416
10417 @item @code{_ovly_table}:
10418 This variable must be an array of the following structures:
10419
10420 @smallexample
10421 struct
10422 @{
10423 /* The overlay's mapped address. */
10424 unsigned long vma;
10425
10426 /* The size of the overlay, in bytes. */
10427 unsigned long size;
10428
10429 /* The overlay's load address. */
10430 unsigned long lma;
10431
10432 /* Non-zero if the overlay is currently mapped;
10433 zero otherwise. */
10434 unsigned long mapped;
10435 @}
10436 @end smallexample
10437
10438 @item @code{_novlys}:
10439 This variable must be a four-byte signed integer, holding the total
10440 number of elements in @code{_ovly_table}.
10441
10442 @end table
10443
10444 To decide whether a particular overlay is mapped or not, @value{GDBN}
10445 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
10446 @code{lma} members equal the VMA and LMA of the overlay's section in the
10447 executable file. When @value{GDBN} finds a matching entry, it consults
10448 the entry's @code{mapped} member to determine whether the overlay is
10449 currently mapped.
10450
10451 In addition, your overlay manager may define a function called
10452 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
10453 will silently set a breakpoint there. If the overlay manager then
10454 calls this function whenever it has changed the overlay table, this
10455 will enable @value{GDBN} to accurately keep track of which overlays
10456 are in program memory, and update any breakpoints that may be set
10457 in overlays. This will allow breakpoints to work even if the
10458 overlays are kept in ROM or other non-writable memory while they
10459 are not being executed.
10460
10461 @node Overlay Sample Program
10462 @section Overlay Sample Program
10463 @cindex overlay example program
10464
10465 When linking a program which uses overlays, you must place the overlays
10466 at their load addresses, while relocating them to run at their mapped
10467 addresses. To do this, you must write a linker script (@pxref{Overlay
10468 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
10469 since linker scripts are specific to a particular host system, target
10470 architecture, and target memory layout, this manual cannot provide
10471 portable sample code demonstrating @value{GDBN}'s overlay support.
10472
10473 However, the @value{GDBN} source distribution does contain an overlaid
10474 program, with linker scripts for a few systems, as part of its test
10475 suite. The program consists of the following files from
10476 @file{gdb/testsuite/gdb.base}:
10477
10478 @table @file
10479 @item overlays.c
10480 The main program file.
10481 @item ovlymgr.c
10482 A simple overlay manager, used by @file{overlays.c}.
10483 @item foo.c
10484 @itemx bar.c
10485 @itemx baz.c
10486 @itemx grbx.c
10487 Overlay modules, loaded and used by @file{overlays.c}.
10488 @item d10v.ld
10489 @itemx m32r.ld
10490 Linker scripts for linking the test program on the @code{d10v-elf}
10491 and @code{m32r-elf} targets.
10492 @end table
10493
10494 You can build the test program using the @code{d10v-elf} GCC
10495 cross-compiler like this:
10496
10497 @smallexample
10498 $ d10v-elf-gcc -g -c overlays.c
10499 $ d10v-elf-gcc -g -c ovlymgr.c
10500 $ d10v-elf-gcc -g -c foo.c
10501 $ d10v-elf-gcc -g -c bar.c
10502 $ d10v-elf-gcc -g -c baz.c
10503 $ d10v-elf-gcc -g -c grbx.c
10504 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
10505 baz.o grbx.o -Wl,-Td10v.ld -o overlays
10506 @end smallexample
10507
10508 The build process is identical for any other architecture, except that
10509 you must substitute the appropriate compiler and linker script for the
10510 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
10511
10512
10513 @node Languages
10514 @chapter Using @value{GDBN} with Different Languages
10515 @cindex languages
10516
10517 Although programming languages generally have common aspects, they are
10518 rarely expressed in the same manner. For instance, in ANSI C,
10519 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
10520 Modula-2, it is accomplished by @code{p^}. Values can also be
10521 represented (and displayed) differently. Hex numbers in C appear as
10522 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
10523
10524 @cindex working language
10525 Language-specific information is built into @value{GDBN} for some languages,
10526 allowing you to express operations like the above in your program's
10527 native language, and allowing @value{GDBN} to output values in a manner
10528 consistent with the syntax of your program's native language. The
10529 language you use to build expressions is called the @dfn{working
10530 language}.
10531
10532 @menu
10533 * Setting:: Switching between source languages
10534 * Show:: Displaying the language
10535 * Checks:: Type and range checks
10536 * Supported Languages:: Supported languages
10537 * Unsupported Languages:: Unsupported languages
10538 @end menu
10539
10540 @node Setting
10541 @section Switching Between Source Languages
10542
10543 There are two ways to control the working language---either have @value{GDBN}
10544 set it automatically, or select it manually yourself. You can use the
10545 @code{set language} command for either purpose. On startup, @value{GDBN}
10546 defaults to setting the language automatically. The working language is
10547 used to determine how expressions you type are interpreted, how values
10548 are printed, etc.
10549
10550 In addition to the working language, every source file that
10551 @value{GDBN} knows about has its own working language. For some object
10552 file formats, the compiler might indicate which language a particular
10553 source file is in. However, most of the time @value{GDBN} infers the
10554 language from the name of the file. The language of a source file
10555 controls whether C@t{++} names are demangled---this way @code{backtrace} can
10556 show each frame appropriately for its own language. There is no way to
10557 set the language of a source file from within @value{GDBN}, but you can
10558 set the language associated with a filename extension. @xref{Show, ,
10559 Displaying the Language}.
10560
10561 This is most commonly a problem when you use a program, such
10562 as @code{cfront} or @code{f2c}, that generates C but is written in
10563 another language. In that case, make the
10564 program use @code{#line} directives in its C output; that way
10565 @value{GDBN} will know the correct language of the source code of the original
10566 program, and will display that source code, not the generated C code.
10567
10568 @menu
10569 * Filenames:: Filename extensions and languages.
10570 * Manually:: Setting the working language manually
10571 * Automatically:: Having @value{GDBN} infer the source language
10572 @end menu
10573
10574 @node Filenames
10575 @subsection List of Filename Extensions and Languages
10576
10577 If a source file name ends in one of the following extensions, then
10578 @value{GDBN} infers that its language is the one indicated.
10579
10580 @table @file
10581 @item .ada
10582 @itemx .ads
10583 @itemx .adb
10584 @itemx .a
10585 Ada source file.
10586
10587 @item .c
10588 C source file
10589
10590 @item .C
10591 @itemx .cc
10592 @itemx .cp
10593 @itemx .cpp
10594 @itemx .cxx
10595 @itemx .c++
10596 C@t{++} source file
10597
10598 @item .m
10599 Objective-C source file
10600
10601 @item .f
10602 @itemx .F
10603 Fortran source file
10604
10605 @item .mod
10606 Modula-2 source file
10607
10608 @item .s
10609 @itemx .S
10610 Assembler source file. This actually behaves almost like C, but
10611 @value{GDBN} does not skip over function prologues when stepping.
10612 @end table
10613
10614 In addition, you may set the language associated with a filename
10615 extension. @xref{Show, , Displaying the Language}.
10616
10617 @node Manually
10618 @subsection Setting the Working Language
10619
10620 If you allow @value{GDBN} to set the language automatically,
10621 expressions are interpreted the same way in your debugging session and
10622 your program.
10623
10624 @kindex set language
10625 If you wish, you may set the language manually. To do this, issue the
10626 command @samp{set language @var{lang}}, where @var{lang} is the name of
10627 a language, such as
10628 @code{c} or @code{modula-2}.
10629 For a list of the supported languages, type @samp{set language}.
10630
10631 Setting the language manually prevents @value{GDBN} from updating the working
10632 language automatically. This can lead to confusion if you try
10633 to debug a program when the working language is not the same as the
10634 source language, when an expression is acceptable to both
10635 languages---but means different things. For instance, if the current
10636 source file were written in C, and @value{GDBN} was parsing Modula-2, a
10637 command such as:
10638
10639 @smallexample
10640 print a = b + c
10641 @end smallexample
10642
10643 @noindent
10644 might not have the effect you intended. In C, this means to add
10645 @code{b} and @code{c} and place the result in @code{a}. The result
10646 printed would be the value of @code{a}. In Modula-2, this means to compare
10647 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
10648
10649 @node Automatically
10650 @subsection Having @value{GDBN} Infer the Source Language
10651
10652 To have @value{GDBN} set the working language automatically, use
10653 @samp{set language local} or @samp{set language auto}. @value{GDBN}
10654 then infers the working language. That is, when your program stops in a
10655 frame (usually by encountering a breakpoint), @value{GDBN} sets the
10656 working language to the language recorded for the function in that
10657 frame. If the language for a frame is unknown (that is, if the function
10658 or block corresponding to the frame was defined in a source file that
10659 does not have a recognized extension), the current working language is
10660 not changed, and @value{GDBN} issues a warning.
10661
10662 This may not seem necessary for most programs, which are written
10663 entirely in one source language. However, program modules and libraries
10664 written in one source language can be used by a main program written in
10665 a different source language. Using @samp{set language auto} in this
10666 case frees you from having to set the working language manually.
10667
10668 @node Show
10669 @section Displaying the Language
10670
10671 The following commands help you find out which language is the
10672 working language, and also what language source files were written in.
10673
10674 @table @code
10675 @item show language
10676 @kindex show language
10677 Display the current working language. This is the
10678 language you can use with commands such as @code{print} to
10679 build and compute expressions that may involve variables in your program.
10680
10681 @item info frame
10682 @kindex info frame@r{, show the source language}
10683 Display the source language for this frame. This language becomes the
10684 working language if you use an identifier from this frame.
10685 @xref{Frame Info, ,Information about a Frame}, to identify the other
10686 information listed here.
10687
10688 @item info source
10689 @kindex info source@r{, show the source language}
10690 Display the source language of this source file.
10691 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
10692 information listed here.
10693 @end table
10694
10695 In unusual circumstances, you may have source files with extensions
10696 not in the standard list. You can then set the extension associated
10697 with a language explicitly:
10698
10699 @table @code
10700 @item set extension-language @var{ext} @var{language}
10701 @kindex set extension-language
10702 Tell @value{GDBN} that source files with extension @var{ext} are to be
10703 assumed as written in the source language @var{language}.
10704
10705 @item info extensions
10706 @kindex info extensions
10707 List all the filename extensions and the associated languages.
10708 @end table
10709
10710 @node Checks
10711 @section Type and Range Checking
10712
10713 @quotation
10714 @emph{Warning:} In this release, the @value{GDBN} commands for type and range
10715 checking are included, but they do not yet have any effect. This
10716 section documents the intended facilities.
10717 @end quotation
10718 @c FIXME remove warning when type/range code added
10719
10720 Some languages are designed to guard you against making seemingly common
10721 errors through a series of compile- and run-time checks. These include
10722 checking the type of arguments to functions and operators, and making
10723 sure mathematical overflows are caught at run time. Checks such as
10724 these help to ensure a program's correctness once it has been compiled
10725 by eliminating type mismatches, and providing active checks for range
10726 errors when your program is running.
10727
10728 @value{GDBN} can check for conditions like the above if you wish.
10729 Although @value{GDBN} does not check the statements in your program,
10730 it can check expressions entered directly into @value{GDBN} for
10731 evaluation via the @code{print} command, for example. As with the
10732 working language, @value{GDBN} can also decide whether or not to check
10733 automatically based on your program's source language.
10734 @xref{Supported Languages, ,Supported Languages}, for the default
10735 settings of supported languages.
10736
10737 @menu
10738 * Type Checking:: An overview of type checking
10739 * Range Checking:: An overview of range checking
10740 @end menu
10741
10742 @cindex type checking
10743 @cindex checks, type
10744 @node Type Checking
10745 @subsection An Overview of Type Checking
10746
10747 Some languages, such as Modula-2, are strongly typed, meaning that the
10748 arguments to operators and functions have to be of the correct type,
10749 otherwise an error occurs. These checks prevent type mismatch
10750 errors from ever causing any run-time problems. For example,
10751
10752 @smallexample
10753 1 + 2 @result{} 3
10754 @exdent but
10755 @error{} 1 + 2.3
10756 @end smallexample
10757
10758 The second example fails because the @code{CARDINAL} 1 is not
10759 type-compatible with the @code{REAL} 2.3.
10760
10761 For the expressions you use in @value{GDBN} commands, you can tell the
10762 @value{GDBN} type checker to skip checking;
10763 to treat any mismatches as errors and abandon the expression;
10764 or to only issue warnings when type mismatches occur,
10765 but evaluate the expression anyway. When you choose the last of
10766 these, @value{GDBN} evaluates expressions like the second example above, but
10767 also issues a warning.
10768
10769 Even if you turn type checking off, there may be other reasons
10770 related to type that prevent @value{GDBN} from evaluating an expression.
10771 For instance, @value{GDBN} does not know how to add an @code{int} and
10772 a @code{struct foo}. These particular type errors have nothing to do
10773 with the language in use, and usually arise from expressions, such as
10774 the one described above, which make little sense to evaluate anyway.
10775
10776 Each language defines to what degree it is strict about type. For
10777 instance, both Modula-2 and C require the arguments to arithmetical
10778 operators to be numbers. In C, enumerated types and pointers can be
10779 represented as numbers, so that they are valid arguments to mathematical
10780 operators. @xref{Supported Languages, ,Supported Languages}, for further
10781 details on specific languages.
10782
10783 @value{GDBN} provides some additional commands for controlling the type checker:
10784
10785 @kindex set check type
10786 @kindex show check type
10787 @table @code
10788 @item set check type auto
10789 Set type checking on or off based on the current working language.
10790 @xref{Supported Languages, ,Supported Languages}, for the default settings for
10791 each language.
10792
10793 @item set check type on
10794 @itemx set check type off
10795 Set type checking on or off, overriding the default setting for the
10796 current working language. Issue a warning if the setting does not
10797 match the language default. If any type mismatches occur in
10798 evaluating an expression while type checking is on, @value{GDBN} prints a
10799 message and aborts evaluation of the expression.
10800
10801 @item set check type warn
10802 Cause the type checker to issue warnings, but to always attempt to
10803 evaluate the expression. Evaluating the expression may still
10804 be impossible for other reasons. For example, @value{GDBN} cannot add
10805 numbers and structures.
10806
10807 @item show type
10808 Show the current setting of the type checker, and whether or not @value{GDBN}
10809 is setting it automatically.
10810 @end table
10811
10812 @cindex range checking
10813 @cindex checks, range
10814 @node Range Checking
10815 @subsection An Overview of Range Checking
10816
10817 In some languages (such as Modula-2), it is an error to exceed the
10818 bounds of a type; this is enforced with run-time checks. Such range
10819 checking is meant to ensure program correctness by making sure
10820 computations do not overflow, or indices on an array element access do
10821 not exceed the bounds of the array.
10822
10823 For expressions you use in @value{GDBN} commands, you can tell
10824 @value{GDBN} to treat range errors in one of three ways: ignore them,
10825 always treat them as errors and abandon the expression, or issue
10826 warnings but evaluate the expression anyway.
10827
10828 A range error can result from numerical overflow, from exceeding an
10829 array index bound, or when you type a constant that is not a member
10830 of any type. Some languages, however, do not treat overflows as an
10831 error. In many implementations of C, mathematical overflow causes the
10832 result to ``wrap around'' to lower values---for example, if @var{m} is
10833 the largest integer value, and @var{s} is the smallest, then
10834
10835 @smallexample
10836 @var{m} + 1 @result{} @var{s}
10837 @end smallexample
10838
10839 This, too, is specific to individual languages, and in some cases
10840 specific to individual compilers or machines. @xref{Supported Languages, ,
10841 Supported Languages}, for further details on specific languages.
10842
10843 @value{GDBN} provides some additional commands for controlling the range checker:
10844
10845 @kindex set check range
10846 @kindex show check range
10847 @table @code
10848 @item set check range auto
10849 Set range checking on or off based on the current working language.
10850 @xref{Supported Languages, ,Supported Languages}, for the default settings for
10851 each language.
10852
10853 @item set check range on
10854 @itemx set check range off
10855 Set range checking on or off, overriding the default setting for the
10856 current working language. A warning is issued if the setting does not
10857 match the language default. If a range error occurs and range checking is on,
10858 then a message is printed and evaluation of the expression is aborted.
10859
10860 @item set check range warn
10861 Output messages when the @value{GDBN} range checker detects a range error,
10862 but attempt to evaluate the expression anyway. Evaluating the
10863 expression may still be impossible for other reasons, such as accessing
10864 memory that the process does not own (a typical example from many Unix
10865 systems).
10866
10867 @item show range
10868 Show the current setting of the range checker, and whether or not it is
10869 being set automatically by @value{GDBN}.
10870 @end table
10871
10872 @node Supported Languages
10873 @section Supported Languages
10874
10875 @value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
10876 assembly, Modula-2, and Ada.
10877 @c This is false ...
10878 Some @value{GDBN} features may be used in expressions regardless of the
10879 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
10880 and the @samp{@{type@}addr} construct (@pxref{Expressions,
10881 ,Expressions}) can be used with the constructs of any supported
10882 language.
10883
10884 The following sections detail to what degree each source language is
10885 supported by @value{GDBN}. These sections are not meant to be language
10886 tutorials or references, but serve only as a reference guide to what the
10887 @value{GDBN} expression parser accepts, and what input and output
10888 formats should look like for different languages. There are many good
10889 books written on each of these languages; please look to these for a
10890 language reference or tutorial.
10891
10892 @menu
10893 * C:: C and C@t{++}
10894 * Objective-C:: Objective-C
10895 * Fortran:: Fortran
10896 * Pascal:: Pascal
10897 * Modula-2:: Modula-2
10898 * Ada:: Ada
10899 @end menu
10900
10901 @node C
10902 @subsection C and C@t{++}
10903
10904 @cindex C and C@t{++}
10905 @cindex expressions in C or C@t{++}
10906
10907 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
10908 to both languages. Whenever this is the case, we discuss those languages
10909 together.
10910
10911 @cindex C@t{++}
10912 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
10913 @cindex @sc{gnu} C@t{++}
10914 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
10915 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
10916 effectively, you must compile your C@t{++} programs with a supported
10917 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
10918 compiler (@code{aCC}).
10919
10920 For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
10921 format; if it doesn't work on your system, try the stabs+ debugging
10922 format. You can select those formats explicitly with the @code{g++}
10923 command-line options @option{-gdwarf-2} and @option{-gstabs+}.
10924 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
10925 gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}.
10926
10927 @menu
10928 * C Operators:: C and C@t{++} operators
10929 * C Constants:: C and C@t{++} constants
10930 * C Plus Plus Expressions:: C@t{++} expressions
10931 * C Defaults:: Default settings for C and C@t{++}
10932 * C Checks:: C and C@t{++} type and range checks
10933 * Debugging C:: @value{GDBN} and C
10934 * Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
10935 * Decimal Floating Point:: Numbers in Decimal Floating Point format
10936 @end menu
10937
10938 @node C Operators
10939 @subsubsection C and C@t{++} Operators
10940
10941 @cindex C and C@t{++} operators
10942
10943 Operators must be defined on values of specific types. For instance,
10944 @code{+} is defined on numbers, but not on structures. Operators are
10945 often defined on groups of types.
10946
10947 For the purposes of C and C@t{++}, the following definitions hold:
10948
10949 @itemize @bullet
10950
10951 @item
10952 @emph{Integral types} include @code{int} with any of its storage-class
10953 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
10954
10955 @item
10956 @emph{Floating-point types} include @code{float}, @code{double}, and
10957 @code{long double} (if supported by the target platform).
10958
10959 @item
10960 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
10961
10962 @item
10963 @emph{Scalar types} include all of the above.
10964
10965 @end itemize
10966
10967 @noindent
10968 The following operators are supported. They are listed here
10969 in order of increasing precedence:
10970
10971 @table @code
10972 @item ,
10973 The comma or sequencing operator. Expressions in a comma-separated list
10974 are evaluated from left to right, with the result of the entire
10975 expression being the last expression evaluated.
10976
10977 @item =
10978 Assignment. The value of an assignment expression is the value
10979 assigned. Defined on scalar types.
10980
10981 @item @var{op}=
10982 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
10983 and translated to @w{@code{@var{a} = @var{a op b}}}.
10984 @w{@code{@var{op}=}} and @code{=} have the same precedence.
10985 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
10986 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
10987
10988 @item ?:
10989 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
10990 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
10991 integral type.
10992
10993 @item ||
10994 Logical @sc{or}. Defined on integral types.
10995
10996 @item &&
10997 Logical @sc{and}. Defined on integral types.
10998
10999 @item |
11000 Bitwise @sc{or}. Defined on integral types.
11001
11002 @item ^
11003 Bitwise exclusive-@sc{or}. Defined on integral types.
11004
11005 @item &
11006 Bitwise @sc{and}. Defined on integral types.
11007
11008 @item ==@r{, }!=
11009 Equality and inequality. Defined on scalar types. The value of these
11010 expressions is 0 for false and non-zero for true.
11011
11012 @item <@r{, }>@r{, }<=@r{, }>=
11013 Less than, greater than, less than or equal, greater than or equal.
11014 Defined on scalar types. The value of these expressions is 0 for false
11015 and non-zero for true.
11016
11017 @item <<@r{, }>>
11018 left shift, and right shift. Defined on integral types.
11019
11020 @item @@
11021 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
11022
11023 @item +@r{, }-
11024 Addition and subtraction. Defined on integral types, floating-point types and
11025 pointer types.
11026
11027 @item *@r{, }/@r{, }%
11028 Multiplication, division, and modulus. Multiplication and division are
11029 defined on integral and floating-point types. Modulus is defined on
11030 integral types.
11031
11032 @item ++@r{, }--
11033 Increment and decrement. When appearing before a variable, the
11034 operation is performed before the variable is used in an expression;
11035 when appearing after it, the variable's value is used before the
11036 operation takes place.
11037
11038 @item *
11039 Pointer dereferencing. Defined on pointer types. Same precedence as
11040 @code{++}.
11041
11042 @item &
11043 Address operator. Defined on variables. Same precedence as @code{++}.
11044
11045 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
11046 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
11047 to examine the address
11048 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
11049 stored.
11050
11051 @item -
11052 Negative. Defined on integral and floating-point types. Same
11053 precedence as @code{++}.
11054
11055 @item !
11056 Logical negation. Defined on integral types. Same precedence as
11057 @code{++}.
11058
11059 @item ~
11060 Bitwise complement operator. Defined on integral types. Same precedence as
11061 @code{++}.
11062
11063
11064 @item .@r{, }->
11065 Structure member, and pointer-to-structure member. For convenience,
11066 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
11067 pointer based on the stored type information.
11068 Defined on @code{struct} and @code{union} data.
11069
11070 @item .*@r{, }->*
11071 Dereferences of pointers to members.
11072
11073 @item []
11074 Array indexing. @code{@var{a}[@var{i}]} is defined as
11075 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
11076
11077 @item ()
11078 Function parameter list. Same precedence as @code{->}.
11079
11080 @item ::
11081 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
11082 and @code{class} types.
11083
11084 @item ::
11085 Doubled colons also represent the @value{GDBN} scope operator
11086 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
11087 above.
11088 @end table
11089
11090 If an operator is redefined in the user code, @value{GDBN} usually
11091 attempts to invoke the redefined version instead of using the operator's
11092 predefined meaning.
11093
11094 @node C Constants
11095 @subsubsection C and C@t{++} Constants
11096
11097 @cindex C and C@t{++} constants
11098
11099 @value{GDBN} allows you to express the constants of C and C@t{++} in the
11100 following ways:
11101
11102 @itemize @bullet
11103 @item
11104 Integer constants are a sequence of digits. Octal constants are
11105 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
11106 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
11107 @samp{l}, specifying that the constant should be treated as a
11108 @code{long} value.
11109
11110 @item
11111 Floating point constants are a sequence of digits, followed by a decimal
11112 point, followed by a sequence of digits, and optionally followed by an
11113 exponent. An exponent is of the form:
11114 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
11115 sequence of digits. The @samp{+} is optional for positive exponents.
11116 A floating-point constant may also end with a letter @samp{f} or
11117 @samp{F}, specifying that the constant should be treated as being of
11118 the @code{float} (as opposed to the default @code{double}) type; or with
11119 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
11120 constant.
11121
11122 @item
11123 Enumerated constants consist of enumerated identifiers, or their
11124 integral equivalents.
11125
11126 @item
11127 Character constants are a single character surrounded by single quotes
11128 (@code{'}), or a number---the ordinal value of the corresponding character
11129 (usually its @sc{ascii} value). Within quotes, the single character may
11130 be represented by a letter or by @dfn{escape sequences}, which are of
11131 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
11132 of the character's ordinal value; or of the form @samp{\@var{x}}, where
11133 @samp{@var{x}} is a predefined special character---for example,
11134 @samp{\n} for newline.
11135
11136 @item
11137 String constants are a sequence of character constants surrounded by
11138 double quotes (@code{"}). Any valid character constant (as described
11139 above) may appear. Double quotes within the string must be preceded by
11140 a backslash, so for instance @samp{"a\"b'c"} is a string of five
11141 characters.
11142
11143 @item
11144 Pointer constants are an integral value. You can also write pointers
11145 to constants using the C operator @samp{&}.
11146
11147 @item
11148 Array constants are comma-separated lists surrounded by braces @samp{@{}
11149 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
11150 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
11151 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
11152 @end itemize
11153
11154 @node C Plus Plus Expressions
11155 @subsubsection C@t{++} Expressions
11156
11157 @cindex expressions in C@t{++}
11158 @value{GDBN} expression handling can interpret most C@t{++} expressions.
11159
11160 @cindex debugging C@t{++} programs
11161 @cindex C@t{++} compilers
11162 @cindex debug formats and C@t{++}
11163 @cindex @value{NGCC} and C@t{++}
11164 @quotation
11165 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
11166 proper compiler and the proper debug format. Currently, @value{GDBN}
11167 works best when debugging C@t{++} code that is compiled with
11168 @value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
11169 @option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
11170 stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
11171 stabs+ as their default debug format, so you usually don't need to
11172 specify a debug format explicitly. Other compilers and/or debug formats
11173 are likely to work badly or not at all when using @value{GDBN} to debug
11174 C@t{++} code.
11175 @end quotation
11176
11177 @enumerate
11178
11179 @cindex member functions
11180 @item
11181 Member function calls are allowed; you can use expressions like
11182
11183 @smallexample
11184 count = aml->GetOriginal(x, y)
11185 @end smallexample
11186
11187 @vindex this@r{, inside C@t{++} member functions}
11188 @cindex namespace in C@t{++}
11189 @item
11190 While a member function is active (in the selected stack frame), your
11191 expressions have the same namespace available as the member function;
11192 that is, @value{GDBN} allows implicit references to the class instance
11193 pointer @code{this} following the same rules as C@t{++}.
11194
11195 @cindex call overloaded functions
11196 @cindex overloaded functions, calling
11197 @cindex type conversions in C@t{++}
11198 @item
11199 You can call overloaded functions; @value{GDBN} resolves the function
11200 call to the right definition, with some restrictions. @value{GDBN} does not
11201 perform overload resolution involving user-defined type conversions,
11202 calls to constructors, or instantiations of templates that do not exist
11203 in the program. It also cannot handle ellipsis argument lists or
11204 default arguments.
11205
11206 It does perform integral conversions and promotions, floating-point
11207 promotions, arithmetic conversions, pointer conversions, conversions of
11208 class objects to base classes, and standard conversions such as those of
11209 functions or arrays to pointers; it requires an exact match on the
11210 number of function arguments.
11211
11212 Overload resolution is always performed, unless you have specified
11213 @code{set overload-resolution off}. @xref{Debugging C Plus Plus,
11214 ,@value{GDBN} Features for C@t{++}}.
11215
11216 You must specify @code{set overload-resolution off} in order to use an
11217 explicit function signature to call an overloaded function, as in
11218 @smallexample
11219 p 'foo(char,int)'('x', 13)
11220 @end smallexample
11221
11222 The @value{GDBN} command-completion facility can simplify this;
11223 see @ref{Completion, ,Command Completion}.
11224
11225 @cindex reference declarations
11226 @item
11227 @value{GDBN} understands variables declared as C@t{++} references; you can use
11228 them in expressions just as you do in C@t{++} source---they are automatically
11229 dereferenced.
11230
11231 In the parameter list shown when @value{GDBN} displays a frame, the values of
11232 reference variables are not displayed (unlike other variables); this
11233 avoids clutter, since references are often used for large structures.
11234 The @emph{address} of a reference variable is always shown, unless
11235 you have specified @samp{set print address off}.
11236
11237 @item
11238 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
11239 expressions can use it just as expressions in your program do. Since
11240 one scope may be defined in another, you can use @code{::} repeatedly if
11241 necessary, for example in an expression like
11242 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
11243 resolving name scope by reference to source files, in both C and C@t{++}
11244 debugging (@pxref{Variables, ,Program Variables}).
11245 @end enumerate
11246
11247 In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
11248 calling virtual functions correctly, printing out virtual bases of
11249 objects, calling functions in a base subobject, casting objects, and
11250 invoking user-defined operators.
11251
11252 @node C Defaults
11253 @subsubsection C and C@t{++} Defaults
11254
11255 @cindex C and C@t{++} defaults
11256
11257 If you allow @value{GDBN} to set type and range checking automatically, they
11258 both default to @code{off} whenever the working language changes to
11259 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
11260 selects the working language.
11261
11262 If you allow @value{GDBN} to set the language automatically, it
11263 recognizes source files whose names end with @file{.c}, @file{.C}, or
11264 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
11265 these files, it sets the working language to C or C@t{++}.
11266 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
11267 for further details.
11268
11269 @c Type checking is (a) primarily motivated by Modula-2, and (b)
11270 @c unimplemented. If (b) changes, it might make sense to let this node
11271 @c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
11272
11273 @node C Checks
11274 @subsubsection C and C@t{++} Type and Range Checks
11275
11276 @cindex C and C@t{++} checks
11277
11278 By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
11279 is not used. However, if you turn type checking on, @value{GDBN}
11280 considers two variables type equivalent if:
11281
11282 @itemize @bullet
11283 @item
11284 The two variables are structured and have the same structure, union, or
11285 enumerated tag.
11286
11287 @item
11288 The two variables have the same type name, or types that have been
11289 declared equivalent through @code{typedef}.
11290
11291 @ignore
11292 @c leaving this out because neither J Gilmore nor R Pesch understand it.
11293 @c FIXME--beers?
11294 @item
11295 The two @code{struct}, @code{union}, or @code{enum} variables are
11296 declared in the same declaration. (Note: this may not be true for all C
11297 compilers.)
11298 @end ignore
11299 @end itemize
11300
11301 Range checking, if turned on, is done on mathematical operations. Array
11302 indices are not checked, since they are often used to index a pointer
11303 that is not itself an array.
11304
11305 @node Debugging C
11306 @subsubsection @value{GDBN} and C
11307
11308 The @code{set print union} and @code{show print union} commands apply to
11309 the @code{union} type. When set to @samp{on}, any @code{union} that is
11310 inside a @code{struct} or @code{class} is also printed. Otherwise, it
11311 appears as @samp{@{...@}}.
11312
11313 The @code{@@} operator aids in the debugging of dynamic arrays, formed
11314 with pointers and a memory allocation function. @xref{Expressions,
11315 ,Expressions}.
11316
11317 @node Debugging C Plus Plus
11318 @subsubsection @value{GDBN} Features for C@t{++}
11319
11320 @cindex commands for C@t{++}
11321
11322 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
11323 designed specifically for use with C@t{++}. Here is a summary:
11324
11325 @table @code
11326 @cindex break in overloaded functions
11327 @item @r{breakpoint menus}
11328 When you want a breakpoint in a function whose name is overloaded,
11329 @value{GDBN} has the capability to display a menu of possible breakpoint
11330 locations to help you specify which function definition you want.
11331 @xref{Ambiguous Expressions,,Ambiguous Expressions}.
11332
11333 @cindex overloading in C@t{++}
11334 @item rbreak @var{regex}
11335 Setting breakpoints using regular expressions is helpful for setting
11336 breakpoints on overloaded functions that are not members of any special
11337 classes.
11338 @xref{Set Breaks, ,Setting Breakpoints}.
11339
11340 @cindex C@t{++} exception handling
11341 @item catch throw
11342 @itemx catch catch
11343 Debug C@t{++} exception handling using these commands. @xref{Set
11344 Catchpoints, , Setting Catchpoints}.
11345
11346 @cindex inheritance
11347 @item ptype @var{typename}
11348 Print inheritance relationships as well as other information for type
11349 @var{typename}.
11350 @xref{Symbols, ,Examining the Symbol Table}.
11351
11352 @cindex C@t{++} symbol display
11353 @item set print demangle
11354 @itemx show print demangle
11355 @itemx set print asm-demangle
11356 @itemx show print asm-demangle
11357 Control whether C@t{++} symbols display in their source form, both when
11358 displaying code as C@t{++} source and when displaying disassemblies.
11359 @xref{Print Settings, ,Print Settings}.
11360
11361 @item set print object
11362 @itemx show print object
11363 Choose whether to print derived (actual) or declared types of objects.
11364 @xref{Print Settings, ,Print Settings}.
11365
11366 @item set print vtbl
11367 @itemx show print vtbl
11368 Control the format for printing virtual function tables.
11369 @xref{Print Settings, ,Print Settings}.
11370 (The @code{vtbl} commands do not work on programs compiled with the HP
11371 ANSI C@t{++} compiler (@code{aCC}).)
11372
11373 @kindex set overload-resolution
11374 @cindex overloaded functions, overload resolution
11375 @item set overload-resolution on
11376 Enable overload resolution for C@t{++} expression evaluation. The default
11377 is on. For overloaded functions, @value{GDBN} evaluates the arguments
11378 and searches for a function whose signature matches the argument types,
11379 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
11380 Expressions, ,C@t{++} Expressions}, for details).
11381 If it cannot find a match, it emits a message.
11382
11383 @item set overload-resolution off
11384 Disable overload resolution for C@t{++} expression evaluation. For
11385 overloaded functions that are not class member functions, @value{GDBN}
11386 chooses the first function of the specified name that it finds in the
11387 symbol table, whether or not its arguments are of the correct type. For
11388 overloaded functions that are class member functions, @value{GDBN}
11389 searches for a function whose signature @emph{exactly} matches the
11390 argument types.
11391
11392 @kindex show overload-resolution
11393 @item show overload-resolution
11394 Show the current setting of overload resolution.
11395
11396 @item @r{Overloaded symbol names}
11397 You can specify a particular definition of an overloaded symbol, using
11398 the same notation that is used to declare such symbols in C@t{++}: type
11399 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
11400 also use the @value{GDBN} command-line word completion facilities to list the
11401 available choices, or to finish the type list for you.
11402 @xref{Completion,, Command Completion}, for details on how to do this.
11403 @end table
11404
11405 @node Decimal Floating Point
11406 @subsubsection Decimal Floating Point format
11407 @cindex decimal floating point format
11408
11409 @value{GDBN} can examine, set and perform computations with numbers in
11410 decimal floating point format, which in the C language correspond to the
11411 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
11412 specified by the extension to support decimal floating-point arithmetic.
11413
11414 There are two encodings in use, depending on the architecture: BID (Binary
11415 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
11416 PowerPC. @value{GDBN} will use the appropriate encoding for the configured
11417 target.
11418
11419 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
11420 to manipulate decimal floating point numbers, it is not possible to convert
11421 (using a cast, for example) integers wider than 32-bit to decimal float.
11422
11423 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
11424 point computations, error checking in decimal float operations ignores
11425 underflow, overflow and divide by zero exceptions.
11426
11427 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
11428 to inspect @code{_Decimal128} values stored in floating point registers.
11429 See @ref{PowerPC,,PowerPC} for more details.
11430
11431 @node Objective-C
11432 @subsection Objective-C
11433
11434 @cindex Objective-C
11435 This section provides information about some commands and command
11436 options that are useful for debugging Objective-C code. See also
11437 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
11438 few more commands specific to Objective-C support.
11439
11440 @menu
11441 * Method Names in Commands::
11442 * The Print Command with Objective-C::
11443 @end menu
11444
11445 @node Method Names in Commands
11446 @subsubsection Method Names in Commands
11447
11448 The following commands have been extended to accept Objective-C method
11449 names as line specifications:
11450
11451 @kindex clear@r{, and Objective-C}
11452 @kindex break@r{, and Objective-C}
11453 @kindex info line@r{, and Objective-C}
11454 @kindex jump@r{, and Objective-C}
11455 @kindex list@r{, and Objective-C}
11456 @itemize
11457 @item @code{clear}
11458 @item @code{break}
11459 @item @code{info line}
11460 @item @code{jump}
11461 @item @code{list}
11462 @end itemize
11463
11464 A fully qualified Objective-C method name is specified as
11465
11466 @smallexample
11467 -[@var{Class} @var{methodName}]
11468 @end smallexample
11469
11470 where the minus sign is used to indicate an instance method and a
11471 plus sign (not shown) is used to indicate a class method. The class
11472 name @var{Class} and method name @var{methodName} are enclosed in
11473 brackets, similar to the way messages are specified in Objective-C
11474 source code. For example, to set a breakpoint at the @code{create}
11475 instance method of class @code{Fruit} in the program currently being
11476 debugged, enter:
11477
11478 @smallexample
11479 break -[Fruit create]
11480 @end smallexample
11481
11482 To list ten program lines around the @code{initialize} class method,
11483 enter:
11484
11485 @smallexample
11486 list +[NSText initialize]
11487 @end smallexample
11488
11489 In the current version of @value{GDBN}, the plus or minus sign is
11490 required. In future versions of @value{GDBN}, the plus or minus
11491 sign will be optional, but you can use it to narrow the search. It
11492 is also possible to specify just a method name:
11493
11494 @smallexample
11495 break create
11496 @end smallexample
11497
11498 You must specify the complete method name, including any colons. If
11499 your program's source files contain more than one @code{create} method,
11500 you'll be presented with a numbered list of classes that implement that
11501 method. Indicate your choice by number, or type @samp{0} to exit if
11502 none apply.
11503
11504 As another example, to clear a breakpoint established at the
11505 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
11506
11507 @smallexample
11508 clear -[NSWindow makeKeyAndOrderFront:]
11509 @end smallexample
11510
11511 @node The Print Command with Objective-C
11512 @subsubsection The Print Command With Objective-C
11513 @cindex Objective-C, print objects
11514 @kindex print-object
11515 @kindex po @r{(@code{print-object})}
11516
11517 The print command has also been extended to accept methods. For example:
11518
11519 @smallexample
11520 print -[@var{object} hash]
11521 @end smallexample
11522
11523 @cindex print an Objective-C object description
11524 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
11525 @noindent
11526 will tell @value{GDBN} to send the @code{hash} message to @var{object}
11527 and print the result. Also, an additional command has been added,
11528 @code{print-object} or @code{po} for short, which is meant to print
11529 the description of an object. However, this command may only work
11530 with certain Objective-C libraries that have a particular hook
11531 function, @code{_NSPrintForDebugger}, defined.
11532
11533 @node Fortran
11534 @subsection Fortran
11535 @cindex Fortran-specific support in @value{GDBN}
11536
11537 @value{GDBN} can be used to debug programs written in Fortran, but it
11538 currently supports only the features of Fortran 77 language.
11539
11540 @cindex trailing underscore, in Fortran symbols
11541 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
11542 among them) append an underscore to the names of variables and
11543 functions. When you debug programs compiled by those compilers, you
11544 will need to refer to variables and functions with a trailing
11545 underscore.
11546
11547 @menu
11548 * Fortran Operators:: Fortran operators and expressions
11549 * Fortran Defaults:: Default settings for Fortran
11550 * Special Fortran Commands:: Special @value{GDBN} commands for Fortran
11551 @end menu
11552
11553 @node Fortran Operators
11554 @subsubsection Fortran Operators and Expressions
11555
11556 @cindex Fortran operators and expressions
11557
11558 Operators must be defined on values of specific types. For instance,
11559 @code{+} is defined on numbers, but not on characters or other non-
11560 arithmetic types. Operators are often defined on groups of types.
11561
11562 @table @code
11563 @item **
11564 The exponentiation operator. It raises the first operand to the power
11565 of the second one.
11566
11567 @item :
11568 The range operator. Normally used in the form of array(low:high) to
11569 represent a section of array.
11570
11571 @item %
11572 The access component operator. Normally used to access elements in derived
11573 types. Also suitable for unions. As unions aren't part of regular Fortran,
11574 this can only happen when accessing a register that uses a gdbarch-defined
11575 union type.
11576 @end table
11577
11578 @node Fortran Defaults
11579 @subsubsection Fortran Defaults
11580
11581 @cindex Fortran Defaults
11582
11583 Fortran symbols are usually case-insensitive, so @value{GDBN} by
11584 default uses case-insensitive matches for Fortran symbols. You can
11585 change that with the @samp{set case-insensitive} command, see
11586 @ref{Symbols}, for the details.
11587
11588 @node Special Fortran Commands
11589 @subsubsection Special Fortran Commands
11590
11591 @cindex Special Fortran commands
11592
11593 @value{GDBN} has some commands to support Fortran-specific features,
11594 such as displaying common blocks.
11595
11596 @table @code
11597 @cindex @code{COMMON} blocks, Fortran
11598 @kindex info common
11599 @item info common @r{[}@var{common-name}@r{]}
11600 This command prints the values contained in the Fortran @code{COMMON}
11601 block whose name is @var{common-name}. With no argument, the names of
11602 all @code{COMMON} blocks visible at the current program location are
11603 printed.
11604 @end table
11605
11606 @node Pascal
11607 @subsection Pascal
11608
11609 @cindex Pascal support in @value{GDBN}, limitations
11610 Debugging Pascal programs which use sets, subranges, file variables, or
11611 nested functions does not currently work. @value{GDBN} does not support
11612 entering expressions, printing values, or similar features using Pascal
11613 syntax.
11614
11615 The Pascal-specific command @code{set print pascal_static-members}
11616 controls whether static members of Pascal objects are displayed.
11617 @xref{Print Settings, pascal_static-members}.
11618
11619 @node Modula-2
11620 @subsection Modula-2
11621
11622 @cindex Modula-2, @value{GDBN} support
11623
11624 The extensions made to @value{GDBN} to support Modula-2 only support
11625 output from the @sc{gnu} Modula-2 compiler (which is currently being
11626 developed). Other Modula-2 compilers are not currently supported, and
11627 attempting to debug executables produced by them is most likely
11628 to give an error as @value{GDBN} reads in the executable's symbol
11629 table.
11630
11631 @cindex expressions in Modula-2
11632 @menu
11633 * M2 Operators:: Built-in operators
11634 * Built-In Func/Proc:: Built-in functions and procedures
11635 * M2 Constants:: Modula-2 constants
11636 * M2 Types:: Modula-2 types
11637 * M2 Defaults:: Default settings for Modula-2
11638 * Deviations:: Deviations from standard Modula-2
11639 * M2 Checks:: Modula-2 type and range checks
11640 * M2 Scope:: The scope operators @code{::} and @code{.}
11641 * GDB/M2:: @value{GDBN} and Modula-2
11642 @end menu
11643
11644 @node M2 Operators
11645 @subsubsection Operators
11646 @cindex Modula-2 operators
11647
11648 Operators must be defined on values of specific types. For instance,
11649 @code{+} is defined on numbers, but not on structures. Operators are
11650 often defined on groups of types. For the purposes of Modula-2, the
11651 following definitions hold:
11652
11653 @itemize @bullet
11654
11655 @item
11656 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
11657 their subranges.
11658
11659 @item
11660 @emph{Character types} consist of @code{CHAR} and its subranges.
11661
11662 @item
11663 @emph{Floating-point types} consist of @code{REAL}.
11664
11665 @item
11666 @emph{Pointer types} consist of anything declared as @code{POINTER TO
11667 @var{type}}.
11668
11669 @item
11670 @emph{Scalar types} consist of all of the above.
11671
11672 @item
11673 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
11674
11675 @item
11676 @emph{Boolean types} consist of @code{BOOLEAN}.
11677 @end itemize
11678
11679 @noindent
11680 The following operators are supported, and appear in order of
11681 increasing precedence:
11682
11683 @table @code
11684 @item ,
11685 Function argument or array index separator.
11686
11687 @item :=
11688 Assignment. The value of @var{var} @code{:=} @var{value} is
11689 @var{value}.
11690
11691 @item <@r{, }>
11692 Less than, greater than on integral, floating-point, or enumerated
11693 types.
11694
11695 @item <=@r{, }>=
11696 Less than or equal to, greater than or equal to
11697 on integral, floating-point and enumerated types, or set inclusion on
11698 set types. Same precedence as @code{<}.
11699
11700 @item =@r{, }<>@r{, }#
11701 Equality and two ways of expressing inequality, valid on scalar types.
11702 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
11703 available for inequality, since @code{#} conflicts with the script
11704 comment character.
11705
11706 @item IN
11707 Set membership. Defined on set types and the types of their members.
11708 Same precedence as @code{<}.
11709
11710 @item OR
11711 Boolean disjunction. Defined on boolean types.
11712
11713 @item AND@r{, }&
11714 Boolean conjunction. Defined on boolean types.
11715
11716 @item @@
11717 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
11718
11719 @item +@r{, }-
11720 Addition and subtraction on integral and floating-point types, or union
11721 and difference on set types.
11722
11723 @item *
11724 Multiplication on integral and floating-point types, or set intersection
11725 on set types.
11726
11727 @item /
11728 Division on floating-point types, or symmetric set difference on set
11729 types. Same precedence as @code{*}.
11730
11731 @item DIV@r{, }MOD
11732 Integer division and remainder. Defined on integral types. Same
11733 precedence as @code{*}.
11734
11735 @item -
11736 Negative. Defined on @code{INTEGER} and @code{REAL} data.
11737
11738 @item ^
11739 Pointer dereferencing. Defined on pointer types.
11740
11741 @item NOT
11742 Boolean negation. Defined on boolean types. Same precedence as
11743 @code{^}.
11744
11745 @item .
11746 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
11747 precedence as @code{^}.
11748
11749 @item []
11750 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
11751
11752 @item ()
11753 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
11754 as @code{^}.
11755
11756 @item ::@r{, }.
11757 @value{GDBN} and Modula-2 scope operators.
11758 @end table
11759
11760 @quotation
11761 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
11762 treats the use of the operator @code{IN}, or the use of operators
11763 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
11764 @code{<=}, and @code{>=} on sets as an error.
11765 @end quotation
11766
11767
11768 @node Built-In Func/Proc
11769 @subsubsection Built-in Functions and Procedures
11770 @cindex Modula-2 built-ins
11771
11772 Modula-2 also makes available several built-in procedures and functions.
11773 In describing these, the following metavariables are used:
11774
11775 @table @var
11776
11777 @item a
11778 represents an @code{ARRAY} variable.
11779
11780 @item c
11781 represents a @code{CHAR} constant or variable.
11782
11783 @item i
11784 represents a variable or constant of integral type.
11785
11786 @item m
11787 represents an identifier that belongs to a set. Generally used in the
11788 same function with the metavariable @var{s}. The type of @var{s} should
11789 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
11790
11791 @item n
11792 represents a variable or constant of integral or floating-point type.
11793
11794 @item r
11795 represents a variable or constant of floating-point type.
11796
11797 @item t
11798 represents a type.
11799
11800 @item v
11801 represents a variable.
11802
11803 @item x
11804 represents a variable or constant of one of many types. See the
11805 explanation of the function for details.
11806 @end table
11807
11808 All Modula-2 built-in procedures also return a result, described below.
11809
11810 @table @code
11811 @item ABS(@var{n})
11812 Returns the absolute value of @var{n}.
11813
11814 @item CAP(@var{c})
11815 If @var{c} is a lower case letter, it returns its upper case
11816 equivalent, otherwise it returns its argument.
11817
11818 @item CHR(@var{i})
11819 Returns the character whose ordinal value is @var{i}.
11820
11821 @item DEC(@var{v})
11822 Decrements the value in the variable @var{v} by one. Returns the new value.
11823
11824 @item DEC(@var{v},@var{i})
11825 Decrements the value in the variable @var{v} by @var{i}. Returns the
11826 new value.
11827
11828 @item EXCL(@var{m},@var{s})
11829 Removes the element @var{m} from the set @var{s}. Returns the new
11830 set.
11831
11832 @item FLOAT(@var{i})
11833 Returns the floating point equivalent of the integer @var{i}.
11834
11835 @item HIGH(@var{a})
11836 Returns the index of the last member of @var{a}.
11837
11838 @item INC(@var{v})
11839 Increments the value in the variable @var{v} by one. Returns the new value.
11840
11841 @item INC(@var{v},@var{i})
11842 Increments the value in the variable @var{v} by @var{i}. Returns the
11843 new value.
11844
11845 @item INCL(@var{m},@var{s})
11846 Adds the element @var{m} to the set @var{s} if it is not already
11847 there. Returns the new set.
11848
11849 @item MAX(@var{t})
11850 Returns the maximum value of the type @var{t}.
11851
11852 @item MIN(@var{t})
11853 Returns the minimum value of the type @var{t}.
11854
11855 @item ODD(@var{i})
11856 Returns boolean TRUE if @var{i} is an odd number.
11857
11858 @item ORD(@var{x})
11859 Returns the ordinal value of its argument. For example, the ordinal
11860 value of a character is its @sc{ascii} value (on machines supporting the
11861 @sc{ascii} character set). @var{x} must be of an ordered type, which include
11862 integral, character and enumerated types.
11863
11864 @item SIZE(@var{x})
11865 Returns the size of its argument. @var{x} can be a variable or a type.
11866
11867 @item TRUNC(@var{r})
11868 Returns the integral part of @var{r}.
11869
11870 @item TSIZE(@var{x})
11871 Returns the size of its argument. @var{x} can be a variable or a type.
11872
11873 @item VAL(@var{t},@var{i})
11874 Returns the member of the type @var{t} whose ordinal value is @var{i}.
11875 @end table
11876
11877 @quotation
11878 @emph{Warning:} Sets and their operations are not yet supported, so
11879 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
11880 an error.
11881 @end quotation
11882
11883 @cindex Modula-2 constants
11884 @node M2 Constants
11885 @subsubsection Constants
11886
11887 @value{GDBN} allows you to express the constants of Modula-2 in the following
11888 ways:
11889
11890 @itemize @bullet
11891
11892 @item
11893 Integer constants are simply a sequence of digits. When used in an
11894 expression, a constant is interpreted to be type-compatible with the
11895 rest of the expression. Hexadecimal integers are specified by a
11896 trailing @samp{H}, and octal integers by a trailing @samp{B}.
11897
11898 @item
11899 Floating point constants appear as a sequence of digits, followed by a
11900 decimal point and another sequence of digits. An optional exponent can
11901 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
11902 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
11903 digits of the floating point constant must be valid decimal (base 10)
11904 digits.
11905
11906 @item
11907 Character constants consist of a single character enclosed by a pair of
11908 like quotes, either single (@code{'}) or double (@code{"}). They may
11909 also be expressed by their ordinal value (their @sc{ascii} value, usually)
11910 followed by a @samp{C}.
11911
11912 @item
11913 String constants consist of a sequence of characters enclosed by a
11914 pair of like quotes, either single (@code{'}) or double (@code{"}).
11915 Escape sequences in the style of C are also allowed. @xref{C
11916 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
11917 sequences.
11918
11919 @item
11920 Enumerated constants consist of an enumerated identifier.
11921
11922 @item
11923 Boolean constants consist of the identifiers @code{TRUE} and
11924 @code{FALSE}.
11925
11926 @item
11927 Pointer constants consist of integral values only.
11928
11929 @item
11930 Set constants are not yet supported.
11931 @end itemize
11932
11933 @node M2 Types
11934 @subsubsection Modula-2 Types
11935 @cindex Modula-2 types
11936
11937 Currently @value{GDBN} can print the following data types in Modula-2
11938 syntax: array types, record types, set types, pointer types, procedure
11939 types, enumerated types, subrange types and base types. You can also
11940 print the contents of variables declared using these type.
11941 This section gives a number of simple source code examples together with
11942 sample @value{GDBN} sessions.
11943
11944 The first example contains the following section of code:
11945
11946 @smallexample
11947 VAR
11948 s: SET OF CHAR ;
11949 r: [20..40] ;
11950 @end smallexample
11951
11952 @noindent
11953 and you can request @value{GDBN} to interrogate the type and value of
11954 @code{r} and @code{s}.
11955
11956 @smallexample
11957 (@value{GDBP}) print s
11958 @{'A'..'C', 'Z'@}
11959 (@value{GDBP}) ptype s
11960 SET OF CHAR
11961 (@value{GDBP}) print r
11962 21
11963 (@value{GDBP}) ptype r
11964 [20..40]
11965 @end smallexample
11966
11967 @noindent
11968 Likewise if your source code declares @code{s} as:
11969
11970 @smallexample
11971 VAR
11972 s: SET ['A'..'Z'] ;
11973 @end smallexample
11974
11975 @noindent
11976 then you may query the type of @code{s} by:
11977
11978 @smallexample
11979 (@value{GDBP}) ptype s
11980 type = SET ['A'..'Z']
11981 @end smallexample
11982
11983 @noindent
11984 Note that at present you cannot interactively manipulate set
11985 expressions using the debugger.
11986
11987 The following example shows how you might declare an array in Modula-2
11988 and how you can interact with @value{GDBN} to print its type and contents:
11989
11990 @smallexample
11991 VAR
11992 s: ARRAY [-10..10] OF CHAR ;
11993 @end smallexample
11994
11995 @smallexample
11996 (@value{GDBP}) ptype s
11997 ARRAY [-10..10] OF CHAR
11998 @end smallexample
11999
12000 Note that the array handling is not yet complete and although the type
12001 is printed correctly, expression handling still assumes that all
12002 arrays have a lower bound of zero and not @code{-10} as in the example
12003 above.
12004
12005 Here are some more type related Modula-2 examples:
12006
12007 @smallexample
12008 TYPE
12009 colour = (blue, red, yellow, green) ;
12010 t = [blue..yellow] ;
12011 VAR
12012 s: t ;
12013 BEGIN
12014 s := blue ;
12015 @end smallexample
12016
12017 @noindent
12018 The @value{GDBN} interaction shows how you can query the data type
12019 and value of a variable.
12020
12021 @smallexample
12022 (@value{GDBP}) print s
12023 $1 = blue
12024 (@value{GDBP}) ptype t
12025 type = [blue..yellow]
12026 @end smallexample
12027
12028 @noindent
12029 In this example a Modula-2 array is declared and its contents
12030 displayed. Observe that the contents are written in the same way as
12031 their @code{C} counterparts.
12032
12033 @smallexample
12034 VAR
12035 s: ARRAY [1..5] OF CARDINAL ;
12036 BEGIN
12037 s[1] := 1 ;
12038 @end smallexample
12039
12040 @smallexample
12041 (@value{GDBP}) print s
12042 $1 = @{1, 0, 0, 0, 0@}
12043 (@value{GDBP}) ptype s
12044 type = ARRAY [1..5] OF CARDINAL
12045 @end smallexample
12046
12047 The Modula-2 language interface to @value{GDBN} also understands
12048 pointer types as shown in this example:
12049
12050 @smallexample
12051 VAR
12052 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
12053 BEGIN
12054 NEW(s) ;
12055 s^[1] := 1 ;
12056 @end smallexample
12057
12058 @noindent
12059 and you can request that @value{GDBN} describes the type of @code{s}.
12060
12061 @smallexample
12062 (@value{GDBP}) ptype s
12063 type = POINTER TO ARRAY [1..5] OF CARDINAL
12064 @end smallexample
12065
12066 @value{GDBN} handles compound types as we can see in this example.
12067 Here we combine array types, record types, pointer types and subrange
12068 types:
12069
12070 @smallexample
12071 TYPE
12072 foo = RECORD
12073 f1: CARDINAL ;
12074 f2: CHAR ;
12075 f3: myarray ;
12076 END ;
12077
12078 myarray = ARRAY myrange OF CARDINAL ;
12079 myrange = [-2..2] ;
12080 VAR
12081 s: POINTER TO ARRAY myrange OF foo ;
12082 @end smallexample
12083
12084 @noindent
12085 and you can ask @value{GDBN} to describe the type of @code{s} as shown
12086 below.
12087
12088 @smallexample
12089 (@value{GDBP}) ptype s
12090 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
12091 f1 : CARDINAL;
12092 f2 : CHAR;
12093 f3 : ARRAY [-2..2] OF CARDINAL;
12094 END
12095 @end smallexample
12096
12097 @node M2 Defaults
12098 @subsubsection Modula-2 Defaults
12099 @cindex Modula-2 defaults
12100
12101 If type and range checking are set automatically by @value{GDBN}, they
12102 both default to @code{on} whenever the working language changes to
12103 Modula-2. This happens regardless of whether you or @value{GDBN}
12104 selected the working language.
12105
12106 If you allow @value{GDBN} to set the language automatically, then entering
12107 code compiled from a file whose name ends with @file{.mod} sets the
12108 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
12109 Infer the Source Language}, for further details.
12110
12111 @node Deviations
12112 @subsubsection Deviations from Standard Modula-2
12113 @cindex Modula-2, deviations from
12114
12115 A few changes have been made to make Modula-2 programs easier to debug.
12116 This is done primarily via loosening its type strictness:
12117
12118 @itemize @bullet
12119 @item
12120 Unlike in standard Modula-2, pointer constants can be formed by
12121 integers. This allows you to modify pointer variables during
12122 debugging. (In standard Modula-2, the actual address contained in a
12123 pointer variable is hidden from you; it can only be modified
12124 through direct assignment to another pointer variable or expression that
12125 returned a pointer.)
12126
12127 @item
12128 C escape sequences can be used in strings and characters to represent
12129 non-printable characters. @value{GDBN} prints out strings with these
12130 escape sequences embedded. Single non-printable characters are
12131 printed using the @samp{CHR(@var{nnn})} format.
12132
12133 @item
12134 The assignment operator (@code{:=}) returns the value of its right-hand
12135 argument.
12136
12137 @item
12138 All built-in procedures both modify @emph{and} return their argument.
12139 @end itemize
12140
12141 @node M2 Checks
12142 @subsubsection Modula-2 Type and Range Checks
12143 @cindex Modula-2 checks
12144
12145 @quotation
12146 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
12147 range checking.
12148 @end quotation
12149 @c FIXME remove warning when type/range checks added
12150
12151 @value{GDBN} considers two Modula-2 variables type equivalent if:
12152
12153 @itemize @bullet
12154 @item
12155 They are of types that have been declared equivalent via a @code{TYPE
12156 @var{t1} = @var{t2}} statement
12157
12158 @item
12159 They have been declared on the same line. (Note: This is true of the
12160 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
12161 @end itemize
12162
12163 As long as type checking is enabled, any attempt to combine variables
12164 whose types are not equivalent is an error.
12165
12166 Range checking is done on all mathematical operations, assignment, array
12167 index bounds, and all built-in functions and procedures.
12168
12169 @node M2 Scope
12170 @subsubsection The Scope Operators @code{::} and @code{.}
12171 @cindex scope
12172 @cindex @code{.}, Modula-2 scope operator
12173 @cindex colon, doubled as scope operator
12174 @ifinfo
12175 @vindex colon-colon@r{, in Modula-2}
12176 @c Info cannot handle :: but TeX can.
12177 @end ifinfo
12178 @ifnotinfo
12179 @vindex ::@r{, in Modula-2}
12180 @end ifnotinfo
12181
12182 There are a few subtle differences between the Modula-2 scope operator
12183 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
12184 similar syntax:
12185
12186 @smallexample
12187
12188 @var{module} . @var{id}
12189 @var{scope} :: @var{id}
12190 @end smallexample
12191
12192 @noindent
12193 where @var{scope} is the name of a module or a procedure,
12194 @var{module} the name of a module, and @var{id} is any declared
12195 identifier within your program, except another module.
12196
12197 Using the @code{::} operator makes @value{GDBN} search the scope
12198 specified by @var{scope} for the identifier @var{id}. If it is not
12199 found in the specified scope, then @value{GDBN} searches all scopes
12200 enclosing the one specified by @var{scope}.
12201
12202 Using the @code{.} operator makes @value{GDBN} search the current scope for
12203 the identifier specified by @var{id} that was imported from the
12204 definition module specified by @var{module}. With this operator, it is
12205 an error if the identifier @var{id} was not imported from definition
12206 module @var{module}, or if @var{id} is not an identifier in
12207 @var{module}.
12208
12209 @node GDB/M2
12210 @subsubsection @value{GDBN} and Modula-2
12211
12212 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
12213 Five subcommands of @code{set print} and @code{show print} apply
12214 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
12215 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
12216 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
12217 analogue in Modula-2.
12218
12219 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
12220 with any language, is not useful with Modula-2. Its
12221 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
12222 created in Modula-2 as they can in C or C@t{++}. However, because an
12223 address can be specified by an integral constant, the construct
12224 @samp{@{@var{type}@}@var{adrexp}} is still useful.
12225
12226 @cindex @code{#} in Modula-2
12227 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
12228 interpreted as the beginning of a comment. Use @code{<>} instead.
12229
12230 @node Ada
12231 @subsection Ada
12232 @cindex Ada
12233
12234 The extensions made to @value{GDBN} for Ada only support
12235 output from the @sc{gnu} Ada (GNAT) compiler.
12236 Other Ada compilers are not currently supported, and
12237 attempting to debug executables produced by them is most likely
12238 to be difficult.
12239
12240
12241 @cindex expressions in Ada
12242 @menu
12243 * Ada Mode Intro:: General remarks on the Ada syntax
12244 and semantics supported by Ada mode
12245 in @value{GDBN}.
12246 * Omissions from Ada:: Restrictions on the Ada expression syntax.
12247 * Additions to Ada:: Extensions of the Ada expression syntax.
12248 * Stopping Before Main Program:: Debugging the program during elaboration.
12249 * Ada Tasks:: Listing and setting breakpoints in tasks.
12250 * Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
12251 * Ada Glitches:: Known peculiarities of Ada mode.
12252 @end menu
12253
12254 @node Ada Mode Intro
12255 @subsubsection Introduction
12256 @cindex Ada mode, general
12257
12258 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
12259 syntax, with some extensions.
12260 The philosophy behind the design of this subset is
12261
12262 @itemize @bullet
12263 @item
12264 That @value{GDBN} should provide basic literals and access to operations for
12265 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
12266 leaving more sophisticated computations to subprograms written into the
12267 program (which therefore may be called from @value{GDBN}).
12268
12269 @item
12270 That type safety and strict adherence to Ada language restrictions
12271 are not particularly important to the @value{GDBN} user.
12272
12273 @item
12274 That brevity is important to the @value{GDBN} user.
12275 @end itemize
12276
12277 Thus, for brevity, the debugger acts as if all names declared in
12278 user-written packages are directly visible, even if they are not visible
12279 according to Ada rules, thus making it unnecessary to fully qualify most
12280 names with their packages, regardless of context. Where this causes
12281 ambiguity, @value{GDBN} asks the user's intent.
12282
12283 The debugger will start in Ada mode if it detects an Ada main program.
12284 As for other languages, it will enter Ada mode when stopped in a program that
12285 was translated from an Ada source file.
12286
12287 While in Ada mode, you may use `@t{--}' for comments. This is useful
12288 mostly for documenting command files. The standard @value{GDBN} comment
12289 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
12290 middle (to allow based literals).
12291
12292 The debugger supports limited overloading. Given a subprogram call in which
12293 the function symbol has multiple definitions, it will use the number of
12294 actual parameters and some information about their types to attempt to narrow
12295 the set of definitions. It also makes very limited use of context, preferring
12296 procedures to functions in the context of the @code{call} command, and
12297 functions to procedures elsewhere.
12298
12299 @node Omissions from Ada
12300 @subsubsection Omissions from Ada
12301 @cindex Ada, omissions from
12302
12303 Here are the notable omissions from the subset:
12304
12305 @itemize @bullet
12306 @item
12307 Only a subset of the attributes are supported:
12308
12309 @itemize @minus
12310 @item
12311 @t{'First}, @t{'Last}, and @t{'Length}
12312 on array objects (not on types and subtypes).
12313
12314 @item
12315 @t{'Min} and @t{'Max}.
12316
12317 @item
12318 @t{'Pos} and @t{'Val}.
12319
12320 @item
12321 @t{'Tag}.
12322
12323 @item
12324 @t{'Range} on array objects (not subtypes), but only as the right
12325 operand of the membership (@code{in}) operator.
12326
12327 @item
12328 @t{'Access}, @t{'Unchecked_Access}, and
12329 @t{'Unrestricted_Access} (a GNAT extension).
12330
12331 @item
12332 @t{'Address}.
12333 @end itemize
12334
12335 @item
12336 The names in
12337 @code{Characters.Latin_1} are not available and
12338 concatenation is not implemented. Thus, escape characters in strings are
12339 not currently available.
12340
12341 @item
12342 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
12343 equality of representations. They will generally work correctly
12344 for strings and arrays whose elements have integer or enumeration types.
12345 They may not work correctly for arrays whose element
12346 types have user-defined equality, for arrays of real values
12347 (in particular, IEEE-conformant floating point, because of negative
12348 zeroes and NaNs), and for arrays whose elements contain unused bits with
12349 indeterminate values.
12350
12351 @item
12352 The other component-by-component array operations (@code{and}, @code{or},
12353 @code{xor}, @code{not}, and relational tests other than equality)
12354 are not implemented.
12355
12356 @item
12357 @cindex array aggregates (Ada)
12358 @cindex record aggregates (Ada)
12359 @cindex aggregates (Ada)
12360 There is limited support for array and record aggregates. They are
12361 permitted only on the right sides of assignments, as in these examples:
12362
12363 @smallexample
12364 (@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
12365 (@value{GDBP}) set An_Array := (1, others => 0)
12366 (@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
12367 (@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
12368 (@value{GDBP}) set A_Record := (1, "Peter", True);
12369 (@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
12370 @end smallexample
12371
12372 Changing a
12373 discriminant's value by assigning an aggregate has an
12374 undefined effect if that discriminant is used within the record.
12375 However, you can first modify discriminants by directly assigning to
12376 them (which normally would not be allowed in Ada), and then performing an
12377 aggregate assignment. For example, given a variable @code{A_Rec}
12378 declared to have a type such as:
12379
12380 @smallexample
12381 type Rec (Len : Small_Integer := 0) is record
12382 Id : Integer;
12383 Vals : IntArray (1 .. Len);
12384 end record;
12385 @end smallexample
12386
12387 you can assign a value with a different size of @code{Vals} with two
12388 assignments:
12389
12390 @smallexample
12391 (@value{GDBP}) set A_Rec.Len := 4
12392 (@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
12393 @end smallexample
12394
12395 As this example also illustrates, @value{GDBN} is very loose about the usual
12396 rules concerning aggregates. You may leave out some of the
12397 components of an array or record aggregate (such as the @code{Len}
12398 component in the assignment to @code{A_Rec} above); they will retain their
12399 original values upon assignment. You may freely use dynamic values as
12400 indices in component associations. You may even use overlapping or
12401 redundant component associations, although which component values are
12402 assigned in such cases is not defined.
12403
12404 @item
12405 Calls to dispatching subprograms are not implemented.
12406
12407 @item
12408 The overloading algorithm is much more limited (i.e., less selective)
12409 than that of real Ada. It makes only limited use of the context in
12410 which a subexpression appears to resolve its meaning, and it is much
12411 looser in its rules for allowing type matches. As a result, some
12412 function calls will be ambiguous, and the user will be asked to choose
12413 the proper resolution.
12414
12415 @item
12416 The @code{new} operator is not implemented.
12417
12418 @item
12419 Entry calls are not implemented.
12420
12421 @item
12422 Aside from printing, arithmetic operations on the native VAX floating-point
12423 formats are not supported.
12424
12425 @item
12426 It is not possible to slice a packed array.
12427
12428 @item
12429 The names @code{True} and @code{False}, when not part of a qualified name,
12430 are interpreted as if implicitly prefixed by @code{Standard}, regardless of
12431 context.
12432 Should your program
12433 redefine these names in a package or procedure (at best a dubious practice),
12434 you will have to use fully qualified names to access their new definitions.
12435 @end itemize
12436
12437 @node Additions to Ada
12438 @subsubsection Additions to Ada
12439 @cindex Ada, deviations from
12440
12441 As it does for other languages, @value{GDBN} makes certain generic
12442 extensions to Ada (@pxref{Expressions}):
12443
12444 @itemize @bullet
12445 @item
12446 If the expression @var{E} is a variable residing in memory (typically
12447 a local variable or array element) and @var{N} is a positive integer,
12448 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
12449 @var{N}-1 adjacent variables following it in memory as an array. In
12450 Ada, this operator is generally not necessary, since its prime use is
12451 in displaying parts of an array, and slicing will usually do this in
12452 Ada. However, there are occasional uses when debugging programs in
12453 which certain debugging information has been optimized away.
12454
12455 @item
12456 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
12457 appears in function or file @var{B}.'' When @var{B} is a file name,
12458 you must typically surround it in single quotes.
12459
12460 @item
12461 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
12462 @var{type} that appears at address @var{addr}.''
12463
12464 @item
12465 A name starting with @samp{$} is a convenience variable
12466 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
12467 @end itemize
12468
12469 In addition, @value{GDBN} provides a few other shortcuts and outright
12470 additions specific to Ada:
12471
12472 @itemize @bullet
12473 @item
12474 The assignment statement is allowed as an expression, returning
12475 its right-hand operand as its value. Thus, you may enter
12476
12477 @smallexample
12478 (@value{GDBP}) set x := y + 3
12479 (@value{GDBP}) print A(tmp := y + 1)
12480 @end smallexample
12481
12482 @item
12483 The semicolon is allowed as an ``operator,'' returning as its value
12484 the value of its right-hand operand.
12485 This allows, for example,
12486 complex conditional breaks:
12487
12488 @smallexample
12489 (@value{GDBP}) break f
12490 (@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
12491 @end smallexample
12492
12493 @item
12494 Rather than use catenation and symbolic character names to introduce special
12495 characters into strings, one may instead use a special bracket notation,
12496 which is also used to print strings. A sequence of characters of the form
12497 @samp{["@var{XX}"]} within a string or character literal denotes the
12498 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
12499 sequence of characters @samp{["""]} also denotes a single quotation mark
12500 in strings. For example,
12501 @smallexample
12502 "One line.["0a"]Next line.["0a"]"
12503 @end smallexample
12504 @noindent
12505 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
12506 after each period.
12507
12508 @item
12509 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
12510 @t{'Max} is optional (and is ignored in any case). For example, it is valid
12511 to write
12512
12513 @smallexample
12514 (@value{GDBP}) print 'max(x, y)
12515 @end smallexample
12516
12517 @item
12518 When printing arrays, @value{GDBN} uses positional notation when the
12519 array has a lower bound of 1, and uses a modified named notation otherwise.
12520 For example, a one-dimensional array of three integers with a lower bound
12521 of 3 might print as
12522
12523 @smallexample
12524 (3 => 10, 17, 1)
12525 @end smallexample
12526
12527 @noindent
12528 That is, in contrast to valid Ada, only the first component has a @code{=>}
12529 clause.
12530
12531 @item
12532 You may abbreviate attributes in expressions with any unique,
12533 multi-character subsequence of
12534 their names (an exact match gets preference).
12535 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
12536 in place of @t{a'length}.
12537
12538 @item
12539 @cindex quoting Ada internal identifiers
12540 Since Ada is case-insensitive, the debugger normally maps identifiers you type
12541 to lower case. The GNAT compiler uses upper-case characters for
12542 some of its internal identifiers, which are normally of no interest to users.
12543 For the rare occasions when you actually have to look at them,
12544 enclose them in angle brackets to avoid the lower-case mapping.
12545 For example,
12546 @smallexample
12547 (@value{GDBP}) print <JMPBUF_SAVE>[0]
12548 @end smallexample
12549
12550 @item
12551 Printing an object of class-wide type or dereferencing an
12552 access-to-class-wide value will display all the components of the object's
12553 specific type (as indicated by its run-time tag). Likewise, component
12554 selection on such a value will operate on the specific type of the
12555 object.
12556
12557 @end itemize
12558
12559 @node Stopping Before Main Program
12560 @subsubsection Stopping at the Very Beginning
12561
12562 @cindex breakpointing Ada elaboration code
12563 It is sometimes necessary to debug the program during elaboration, and
12564 before reaching the main procedure.
12565 As defined in the Ada Reference
12566 Manual, the elaboration code is invoked from a procedure called
12567 @code{adainit}. To run your program up to the beginning of
12568 elaboration, simply use the following two commands:
12569 @code{tbreak adainit} and @code{run}.
12570
12571 @node Ada Tasks
12572 @subsubsection Extensions for Ada Tasks
12573 @cindex Ada, tasking
12574
12575 Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
12576 @value{GDBN} provides the following task-related commands:
12577
12578 @table @code
12579 @kindex info tasks
12580 @item info tasks
12581 This command shows a list of current Ada tasks, as in the following example:
12582
12583
12584 @smallexample
12585 @iftex
12586 @leftskip=0.5cm
12587 @end iftex
12588 (@value{GDBP}) info tasks
12589 ID TID P-ID Pri State Name
12590 1 8088000 0 15 Child Activation Wait main_task
12591 2 80a4000 1 15 Accept Statement b
12592 3 809a800 1 15 Child Activation Wait a
12593 * 4 80ae800 3 15 Runnable c
12594
12595 @end smallexample
12596
12597 @noindent
12598 In this listing, the asterisk before the last task indicates it to be the
12599 task currently being inspected.
12600
12601 @table @asis
12602 @item ID
12603 Represents @value{GDBN}'s internal task number.
12604
12605 @item TID
12606 The Ada task ID.
12607
12608 @item P-ID
12609 The parent's task ID (@value{GDBN}'s internal task number).
12610
12611 @item Pri
12612 The base priority of the task.
12613
12614 @item State
12615 Current state of the task.
12616
12617 @table @code
12618 @item Unactivated
12619 The task has been created but has not been activated. It cannot be
12620 executing.
12621
12622 @item Runnable
12623 The task is not blocked for any reason known to Ada. (It may be waiting
12624 for a mutex, though.) It is conceptually "executing" in normal mode.
12625
12626 @item Terminated
12627 The task is terminated, in the sense of ARM 9.3 (5). Any dependents
12628 that were waiting on terminate alternatives have been awakened and have
12629 terminated themselves.
12630
12631 @item Child Activation Wait
12632 The task is waiting for created tasks to complete activation.
12633
12634 @item Accept Statement
12635 The task is waiting on an accept or selective wait statement.
12636
12637 @item Waiting on entry call
12638 The task is waiting on an entry call.
12639
12640 @item Async Select Wait
12641 The task is waiting to start the abortable part of an asynchronous
12642 select statement.
12643
12644 @item Delay Sleep
12645 The task is waiting on a select statement with only a delay
12646 alternative open.
12647
12648 @item Child Termination Wait
12649 The task is sleeping having completed a master within itself, and is
12650 waiting for the tasks dependent on that master to become terminated or
12651 waiting on a terminate Phase.
12652
12653 @item Wait Child in Term Alt
12654 The task is sleeping waiting for tasks on terminate alternatives to
12655 finish terminating.
12656
12657 @item Accepting RV with @var{taskno}
12658 The task is accepting a rendez-vous with the task @var{taskno}.
12659 @end table
12660
12661 @item Name
12662 Name of the task in the program.
12663
12664 @end table
12665
12666 @kindex info task @var{taskno}
12667 @item info task @var{taskno}
12668 This command shows detailled informations on the specified task, as in
12669 the following example:
12670 @smallexample
12671 @iftex
12672 @leftskip=0.5cm
12673 @end iftex
12674 (@value{GDBP}) info tasks
12675 ID TID P-ID Pri State Name
12676 1 8077880 0 15 Child Activation Wait main_task
12677 * 2 807c468 1 15 Runnable task_1
12678 (@value{GDBP}) info task 2
12679 Ada Task: 0x807c468
12680 Name: task_1
12681 Thread: 0x807f378
12682 Parent: 1 (main_task)
12683 Base Priority: 15
12684 State: Runnable
12685 @end smallexample
12686
12687 @item task
12688 @kindex task@r{ (Ada)}
12689 @cindex current Ada task ID
12690 This command prints the ID of the current task.
12691
12692 @smallexample
12693 @iftex
12694 @leftskip=0.5cm
12695 @end iftex
12696 (@value{GDBP}) info tasks
12697 ID TID P-ID Pri State Name
12698 1 8077870 0 15 Child Activation Wait main_task
12699 * 2 807c458 1 15 Runnable t
12700 (@value{GDBP}) task
12701 [Current task is 2]
12702 @end smallexample
12703
12704 @item task @var{taskno}
12705 @cindex Ada task switching
12706 This command is like the @code{thread @var{threadno}}
12707 command (@pxref{Threads}). It switches the context of debugging
12708 from the current task to the given task.
12709
12710 @smallexample
12711 @iftex
12712 @leftskip=0.5cm
12713 @end iftex
12714 (@value{GDBP}) info tasks
12715 ID TID P-ID Pri State Name
12716 1 8077870 0 15 Child Activation Wait main_task
12717 * 2 807c458 1 15 Runnable t
12718 (@value{GDBP}) task 1
12719 [Switching to task 1]
12720 #0 0x8067726 in pthread_cond_wait ()
12721 (@value{GDBP}) bt
12722 #0 0x8067726 in pthread_cond_wait ()
12723 #1 0x8056714 in system.os_interface.pthread_cond_wait ()
12724 #2 0x805cb63 in system.task_primitives.operations.sleep ()
12725 #3 0x806153e in system.tasking.stages.activate_tasks ()
12726 #4 0x804aacc in un () at un.adb:5
12727 @end smallexample
12728
12729 @item break @var{linespec} task @var{taskno}
12730 @itemx break @var{linespec} task @var{taskno} if @dots{}
12731 @cindex breakpoints and tasks, in Ada
12732 @cindex task breakpoints, in Ada
12733 @kindex break @dots{} task @var{taskno}@r{ (Ada)}
12734 These commands are like the @code{break @dots{} thread @dots{}}
12735 command (@pxref{Thread Stops}).
12736 @var{linespec} specifies source lines, as described
12737 in @ref{Specify Location}.
12738
12739 Use the qualifier @samp{task @var{taskno}} with a breakpoint command
12740 to specify that you only want @value{GDBN} to stop the program when a
12741 particular Ada task reaches this breakpoint. @var{taskno} is one of the
12742 numeric task identifiers assigned by @value{GDBN}, shown in the first
12743 column of the @samp{info tasks} display.
12744
12745 If you do not specify @samp{task @var{taskno}} when you set a
12746 breakpoint, the breakpoint applies to @emph{all} tasks of your
12747 program.
12748
12749 You can use the @code{task} qualifier on conditional breakpoints as
12750 well; in this case, place @samp{task @var{taskno}} before the
12751 breakpoint condition (before the @code{if}).
12752
12753 For example,
12754
12755 @smallexample
12756 @iftex
12757 @leftskip=0.5cm
12758 @end iftex
12759 (@value{GDBP}) info tasks
12760 ID TID P-ID Pri State Name
12761 1 140022020 0 15 Child Activation Wait main_task
12762 2 140045060 1 15 Accept/Select Wait t2
12763 3 140044840 1 15 Runnable t1
12764 * 4 140056040 1 15 Runnable t3
12765 (@value{GDBP}) b 15 task 2
12766 Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
12767 (@value{GDBP}) cont
12768 Continuing.
12769 task # 1 running
12770 task # 2 running
12771
12772 Breakpoint 5, test_task_debug () at test_task_debug.adb:15
12773 15 flush;
12774 (@value{GDBP}) info tasks
12775 ID TID P-ID Pri State Name
12776 1 140022020 0 15 Child Activation Wait main_task
12777 * 2 140045060 1 15 Runnable t2
12778 3 140044840 1 15 Runnable t1
12779 4 140056040 1 15 Delay Sleep t3
12780 @end smallexample
12781 @end table
12782
12783 @node Ada Tasks and Core Files
12784 @subsubsection Tasking Support when Debugging Core Files
12785 @cindex Ada tasking and core file debugging
12786
12787 When inspecting a core file, as opposed to debugging a live program,
12788 tasking support may be limited or even unavailable, depending on
12789 the platform being used.
12790 For instance, on x86-linux, the list of tasks is available, but task
12791 switching is not supported. On Tru64, however, task switching will work
12792 as usual.
12793
12794 On certain platforms, including Tru64, the debugger needs to perform some
12795 memory writes in order to provide Ada tasking support. When inspecting
12796 a core file, this means that the core file must be opened with read-write
12797 privileges, using the command @samp{"set write on"} (@pxref{Patching}).
12798 Under these circumstances, you should make a backup copy of the core
12799 file before inspecting it with @value{GDBN}.
12800
12801 @node Ada Glitches
12802 @subsubsection Known Peculiarities of Ada Mode
12803 @cindex Ada, problems
12804
12805 Besides the omissions listed previously (@pxref{Omissions from Ada}),
12806 we know of several problems with and limitations of Ada mode in
12807 @value{GDBN},
12808 some of which will be fixed with planned future releases of the debugger
12809 and the GNU Ada compiler.
12810
12811 @itemize @bullet
12812 @item
12813 Currently, the debugger
12814 has insufficient information to determine whether certain pointers represent
12815 pointers to objects or the objects themselves.
12816 Thus, the user may have to tack an extra @code{.all} after an expression
12817 to get it printed properly.
12818
12819 @item
12820 Static constants that the compiler chooses not to materialize as objects in
12821 storage are invisible to the debugger.
12822
12823 @item
12824 Named parameter associations in function argument lists are ignored (the
12825 argument lists are treated as positional).
12826
12827 @item
12828 Many useful library packages are currently invisible to the debugger.
12829
12830 @item
12831 Fixed-point arithmetic, conversions, input, and output is carried out using
12832 floating-point arithmetic, and may give results that only approximate those on
12833 the host machine.
12834
12835 @item
12836 The GNAT compiler never generates the prefix @code{Standard} for any of
12837 the standard symbols defined by the Ada language. @value{GDBN} knows about
12838 this: it will strip the prefix from names when you use it, and will never
12839 look for a name you have so qualified among local symbols, nor match against
12840 symbols in other packages or subprograms. If you have
12841 defined entities anywhere in your program other than parameters and
12842 local variables whose simple names match names in @code{Standard},
12843 GNAT's lack of qualification here can cause confusion. When this happens,
12844 you can usually resolve the confusion
12845 by qualifying the problematic names with package
12846 @code{Standard} explicitly.
12847 @end itemize
12848
12849 @node Unsupported Languages
12850 @section Unsupported Languages
12851
12852 @cindex unsupported languages
12853 @cindex minimal language
12854 In addition to the other fully-supported programming languages,
12855 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
12856 It does not represent a real programming language, but provides a set
12857 of capabilities close to what the C or assembly languages provide.
12858 This should allow most simple operations to be performed while debugging
12859 an application that uses a language currently not supported by @value{GDBN}.
12860
12861 If the language is set to @code{auto}, @value{GDBN} will automatically
12862 select this language if the current frame corresponds to an unsupported
12863 language.
12864
12865 @node Symbols
12866 @chapter Examining the Symbol Table
12867
12868 The commands described in this chapter allow you to inquire about the
12869 symbols (names of variables, functions and types) defined in your
12870 program. This information is inherent in the text of your program and
12871 does not change as your program executes. @value{GDBN} finds it in your
12872 program's symbol table, in the file indicated when you started @value{GDBN}
12873 (@pxref{File Options, ,Choosing Files}), or by one of the
12874 file-management commands (@pxref{Files, ,Commands to Specify Files}).
12875
12876 @cindex symbol names
12877 @cindex names of symbols
12878 @cindex quoting names
12879 Occasionally, you may need to refer to symbols that contain unusual
12880 characters, which @value{GDBN} ordinarily treats as word delimiters. The
12881 most frequent case is in referring to static variables in other
12882 source files (@pxref{Variables,,Program Variables}). File names
12883 are recorded in object files as debugging symbols, but @value{GDBN} would
12884 ordinarily parse a typical file name, like @file{foo.c}, as the three words
12885 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
12886 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
12887
12888 @smallexample
12889 p 'foo.c'::x
12890 @end smallexample
12891
12892 @noindent
12893 looks up the value of @code{x} in the scope of the file @file{foo.c}.
12894
12895 @table @code
12896 @cindex case-insensitive symbol names
12897 @cindex case sensitivity in symbol names
12898 @kindex set case-sensitive
12899 @item set case-sensitive on
12900 @itemx set case-sensitive off
12901 @itemx set case-sensitive auto
12902 Normally, when @value{GDBN} looks up symbols, it matches their names
12903 with case sensitivity determined by the current source language.
12904 Occasionally, you may wish to control that. The command @code{set
12905 case-sensitive} lets you do that by specifying @code{on} for
12906 case-sensitive matches or @code{off} for case-insensitive ones. If
12907 you specify @code{auto}, case sensitivity is reset to the default
12908 suitable for the source language. The default is case-sensitive
12909 matches for all languages except for Fortran, for which the default is
12910 case-insensitive matches.
12911
12912 @kindex show case-sensitive
12913 @item show case-sensitive
12914 This command shows the current setting of case sensitivity for symbols
12915 lookups.
12916
12917 @kindex info address
12918 @cindex address of a symbol
12919 @item info address @var{symbol}
12920 Describe where the data for @var{symbol} is stored. For a register
12921 variable, this says which register it is kept in. For a non-register
12922 local variable, this prints the stack-frame offset at which the variable
12923 is always stored.
12924
12925 Note the contrast with @samp{print &@var{symbol}}, which does not work
12926 at all for a register variable, and for a stack local variable prints
12927 the exact address of the current instantiation of the variable.
12928
12929 @kindex info symbol
12930 @cindex symbol from address
12931 @cindex closest symbol and offset for an address
12932 @item info symbol @var{addr}
12933 Print the name of a symbol which is stored at the address @var{addr}.
12934 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
12935 nearest symbol and an offset from it:
12936
12937 @smallexample
12938 (@value{GDBP}) info symbol 0x54320
12939 _initialize_vx + 396 in section .text
12940 @end smallexample
12941
12942 @noindent
12943 This is the opposite of the @code{info address} command. You can use
12944 it to find out the name of a variable or a function given its address.
12945
12946 For dynamically linked executables, the name of executable or shared
12947 library containing the symbol is also printed:
12948
12949 @smallexample
12950 (@value{GDBP}) info symbol 0x400225
12951 _start + 5 in section .text of /tmp/a.out
12952 (@value{GDBP}) info symbol 0x2aaaac2811cf
12953 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
12954 @end smallexample
12955
12956 @kindex whatis
12957 @item whatis [@var{arg}]
12958 Print the data type of @var{arg}, which can be either an expression or
12959 a data type. With no argument, print the data type of @code{$}, the
12960 last value in the value history. If @var{arg} is an expression, it is
12961 not actually evaluated, and any side-effecting operations (such as
12962 assignments or function calls) inside it do not take place. If
12963 @var{arg} is a type name, it may be the name of a type or typedef, or
12964 for C code it may have the form @samp{class @var{class-name}},
12965 @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
12966 @samp{enum @var{enum-tag}}.
12967 @xref{Expressions, ,Expressions}.
12968
12969 @kindex ptype
12970 @item ptype [@var{arg}]
12971 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
12972 detailed description of the type, instead of just the name of the type.
12973 @xref{Expressions, ,Expressions}.
12974
12975 For example, for this variable declaration:
12976
12977 @smallexample
12978 struct complex @{double real; double imag;@} v;
12979 @end smallexample
12980
12981 @noindent
12982 the two commands give this output:
12983
12984 @smallexample
12985 @group
12986 (@value{GDBP}) whatis v
12987 type = struct complex
12988 (@value{GDBP}) ptype v
12989 type = struct complex @{
12990 double real;
12991 double imag;
12992 @}
12993 @end group
12994 @end smallexample
12995
12996 @noindent
12997 As with @code{whatis}, using @code{ptype} without an argument refers to
12998 the type of @code{$}, the last value in the value history.
12999
13000 @cindex incomplete type
13001 Sometimes, programs use opaque data types or incomplete specifications
13002 of complex data structure. If the debug information included in the
13003 program does not allow @value{GDBN} to display a full declaration of
13004 the data type, it will say @samp{<incomplete type>}. For example,
13005 given these declarations:
13006
13007 @smallexample
13008 struct foo;
13009 struct foo *fooptr;
13010 @end smallexample
13011
13012 @noindent
13013 but no definition for @code{struct foo} itself, @value{GDBN} will say:
13014
13015 @smallexample
13016 (@value{GDBP}) ptype foo
13017 $1 = <incomplete type>
13018 @end smallexample
13019
13020 @noindent
13021 ``Incomplete type'' is C terminology for data types that are not
13022 completely specified.
13023
13024 @kindex info types
13025 @item info types @var{regexp}
13026 @itemx info types
13027 Print a brief description of all types whose names match the regular
13028 expression @var{regexp} (or all types in your program, if you supply
13029 no argument). Each complete typename is matched as though it were a
13030 complete line; thus, @samp{i type value} gives information on all
13031 types in your program whose names include the string @code{value}, but
13032 @samp{i type ^value$} gives information only on types whose complete
13033 name is @code{value}.
13034
13035 This command differs from @code{ptype} in two ways: first, like
13036 @code{whatis}, it does not print a detailed description; second, it
13037 lists all source files where a type is defined.
13038
13039 @kindex info scope
13040 @cindex local variables
13041 @item info scope @var{location}
13042 List all the variables local to a particular scope. This command
13043 accepts a @var{location} argument---a function name, a source line, or
13044 an address preceded by a @samp{*}, and prints all the variables local
13045 to the scope defined by that location. (@xref{Specify Location}, for
13046 details about supported forms of @var{location}.) For example:
13047
13048 @smallexample
13049 (@value{GDBP}) @b{info scope command_line_handler}
13050 Scope for command_line_handler:
13051 Symbol rl is an argument at stack/frame offset 8, length 4.
13052 Symbol linebuffer is in static storage at address 0x150a18, length 4.
13053 Symbol linelength is in static storage at address 0x150a1c, length 4.
13054 Symbol p is a local variable in register $esi, length 4.
13055 Symbol p1 is a local variable in register $ebx, length 4.
13056 Symbol nline is a local variable in register $edx, length 4.
13057 Symbol repeat is a local variable at frame offset -8, length 4.
13058 @end smallexample
13059
13060 @noindent
13061 This command is especially useful for determining what data to collect
13062 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
13063 collect}.
13064
13065 @kindex info source
13066 @item info source
13067 Show information about the current source file---that is, the source file for
13068 the function containing the current point of execution:
13069 @itemize @bullet
13070 @item
13071 the name of the source file, and the directory containing it,
13072 @item
13073 the directory it was compiled in,
13074 @item
13075 its length, in lines,
13076 @item
13077 which programming language it is written in,
13078 @item
13079 whether the executable includes debugging information for that file, and
13080 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
13081 @item
13082 whether the debugging information includes information about
13083 preprocessor macros.
13084 @end itemize
13085
13086
13087 @kindex info sources
13088 @item info sources
13089 Print the names of all source files in your program for which there is
13090 debugging information, organized into two lists: files whose symbols
13091 have already been read, and files whose symbols will be read when needed.
13092
13093 @kindex info functions
13094 @item info functions
13095 Print the names and data types of all defined functions.
13096
13097 @item info functions @var{regexp}
13098 Print the names and data types of all defined functions
13099 whose names contain a match for regular expression @var{regexp}.
13100 Thus, @samp{info fun step} finds all functions whose names
13101 include @code{step}; @samp{info fun ^step} finds those whose names
13102 start with @code{step}. If a function name contains characters
13103 that conflict with the regular expression language (e.g.@:
13104 @samp{operator*()}), they may be quoted with a backslash.
13105
13106 @kindex info variables
13107 @item info variables
13108 Print the names and data types of all variables that are defined
13109 outside of functions (i.e.@: excluding local variables).
13110
13111 @item info variables @var{regexp}
13112 Print the names and data types of all variables (except for local
13113 variables) whose names contain a match for regular expression
13114 @var{regexp}.
13115
13116 @kindex info classes
13117 @cindex Objective-C, classes and selectors
13118 @item info classes
13119 @itemx info classes @var{regexp}
13120 Display all Objective-C classes in your program, or
13121 (with the @var{regexp} argument) all those matching a particular regular
13122 expression.
13123
13124 @kindex info selectors
13125 @item info selectors
13126 @itemx info selectors @var{regexp}
13127 Display all Objective-C selectors in your program, or
13128 (with the @var{regexp} argument) all those matching a particular regular
13129 expression.
13130
13131 @ignore
13132 This was never implemented.
13133 @kindex info methods
13134 @item info methods
13135 @itemx info methods @var{regexp}
13136 The @code{info methods} command permits the user to examine all defined
13137 methods within C@t{++} program, or (with the @var{regexp} argument) a
13138 specific set of methods found in the various C@t{++} classes. Many
13139 C@t{++} classes provide a large number of methods. Thus, the output
13140 from the @code{ptype} command can be overwhelming and hard to use. The
13141 @code{info-methods} command filters the methods, printing only those
13142 which match the regular-expression @var{regexp}.
13143 @end ignore
13144
13145 @cindex reloading symbols
13146 Some systems allow individual object files that make up your program to
13147 be replaced without stopping and restarting your program. For example,
13148 in VxWorks you can simply recompile a defective object file and keep on
13149 running. If you are running on one of these systems, you can allow
13150 @value{GDBN} to reload the symbols for automatically relinked modules:
13151
13152 @table @code
13153 @kindex set symbol-reloading
13154 @item set symbol-reloading on
13155 Replace symbol definitions for the corresponding source file when an
13156 object file with a particular name is seen again.
13157
13158 @item set symbol-reloading off
13159 Do not replace symbol definitions when encountering object files of the
13160 same name more than once. This is the default state; if you are not
13161 running on a system that permits automatic relinking of modules, you
13162 should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
13163 may discard symbols when linking large programs, that may contain
13164 several modules (from different directories or libraries) with the same
13165 name.
13166
13167 @kindex show symbol-reloading
13168 @item show symbol-reloading
13169 Show the current @code{on} or @code{off} setting.
13170 @end table
13171
13172 @cindex opaque data types
13173 @kindex set opaque-type-resolution
13174 @item set opaque-type-resolution on
13175 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
13176 declared as a pointer to a @code{struct}, @code{class}, or
13177 @code{union}---for example, @code{struct MyType *}---that is used in one
13178 source file although the full declaration of @code{struct MyType} is in
13179 another source file. The default is on.
13180
13181 A change in the setting of this subcommand will not take effect until
13182 the next time symbols for a file are loaded.
13183
13184 @item set opaque-type-resolution off
13185 Tell @value{GDBN} not to resolve opaque types. In this case, the type
13186 is printed as follows:
13187 @smallexample
13188 @{<no data fields>@}
13189 @end smallexample
13190
13191 @kindex show opaque-type-resolution
13192 @item show opaque-type-resolution
13193 Show whether opaque types are resolved or not.
13194
13195 @kindex maint print symbols
13196 @cindex symbol dump
13197 @kindex maint print psymbols
13198 @cindex partial symbol dump
13199 @item maint print symbols @var{filename}
13200 @itemx maint print psymbols @var{filename}
13201 @itemx maint print msymbols @var{filename}
13202 Write a dump of debugging symbol data into the file @var{filename}.
13203 These commands are used to debug the @value{GDBN} symbol-reading code. Only
13204 symbols with debugging data are included. If you use @samp{maint print
13205 symbols}, @value{GDBN} includes all the symbols for which it has already
13206 collected full details: that is, @var{filename} reflects symbols for
13207 only those files whose symbols @value{GDBN} has read. You can use the
13208 command @code{info sources} to find out which files these are. If you
13209 use @samp{maint print psymbols} instead, the dump shows information about
13210 symbols that @value{GDBN} only knows partially---that is, symbols defined in
13211 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
13212 @samp{maint print msymbols} dumps just the minimal symbol information
13213 required for each object file from which @value{GDBN} has read some symbols.
13214 @xref{Files, ,Commands to Specify Files}, for a discussion of how
13215 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
13216
13217 @kindex maint info symtabs
13218 @kindex maint info psymtabs
13219 @cindex listing @value{GDBN}'s internal symbol tables
13220 @cindex symbol tables, listing @value{GDBN}'s internal
13221 @cindex full symbol tables, listing @value{GDBN}'s internal
13222 @cindex partial symbol tables, listing @value{GDBN}'s internal
13223 @item maint info symtabs @r{[} @var{regexp} @r{]}
13224 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
13225
13226 List the @code{struct symtab} or @code{struct partial_symtab}
13227 structures whose names match @var{regexp}. If @var{regexp} is not
13228 given, list them all. The output includes expressions which you can
13229 copy into a @value{GDBN} debugging this one to examine a particular
13230 structure in more detail. For example:
13231
13232 @smallexample
13233 (@value{GDBP}) maint info psymtabs dwarf2read
13234 @{ objfile /home/gnu/build/gdb/gdb
13235 ((struct objfile *) 0x82e69d0)
13236 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
13237 ((struct partial_symtab *) 0x8474b10)
13238 readin no
13239 fullname (null)
13240 text addresses 0x814d3c8 -- 0x8158074
13241 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
13242 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
13243 dependencies (none)
13244 @}
13245 @}
13246 (@value{GDBP}) maint info symtabs
13247 (@value{GDBP})
13248 @end smallexample
13249 @noindent
13250 We see that there is one partial symbol table whose filename contains
13251 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
13252 and we see that @value{GDBN} has not read in any symtabs yet at all.
13253 If we set a breakpoint on a function, that will cause @value{GDBN} to
13254 read the symtab for the compilation unit containing that function:
13255
13256 @smallexample
13257 (@value{GDBP}) break dwarf2_psymtab_to_symtab
13258 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
13259 line 1574.
13260 (@value{GDBP}) maint info symtabs
13261 @{ objfile /home/gnu/build/gdb/gdb
13262 ((struct objfile *) 0x82e69d0)
13263 @{ symtab /home/gnu/src/gdb/dwarf2read.c
13264 ((struct symtab *) 0x86c1f38)
13265 dirname (null)
13266 fullname (null)
13267 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
13268 linetable ((struct linetable *) 0x8370fa0)
13269 debugformat DWARF 2
13270 @}
13271 @}
13272 (@value{GDBP})
13273 @end smallexample
13274 @end table
13275
13276
13277 @node Altering
13278 @chapter Altering Execution
13279
13280 Once you think you have found an error in your program, you might want to
13281 find out for certain whether correcting the apparent error would lead to
13282 correct results in the rest of the run. You can find the answer by
13283 experiment, using the @value{GDBN} features for altering execution of the
13284 program.
13285
13286 For example, you can store new values into variables or memory
13287 locations, give your program a signal, restart it at a different
13288 address, or even return prematurely from a function.
13289
13290 @menu
13291 * Assignment:: Assignment to variables
13292 * Jumping:: Continuing at a different address
13293 * Signaling:: Giving your program a signal
13294 * Returning:: Returning from a function
13295 * Calling:: Calling your program's functions
13296 * Patching:: Patching your program
13297 @end menu
13298
13299 @node Assignment
13300 @section Assignment to Variables
13301
13302 @cindex assignment
13303 @cindex setting variables
13304 To alter the value of a variable, evaluate an assignment expression.
13305 @xref{Expressions, ,Expressions}. For example,
13306
13307 @smallexample
13308 print x=4
13309 @end smallexample
13310
13311 @noindent
13312 stores the value 4 into the variable @code{x}, and then prints the
13313 value of the assignment expression (which is 4).
13314 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
13315 information on operators in supported languages.
13316
13317 @kindex set variable
13318 @cindex variables, setting
13319 If you are not interested in seeing the value of the assignment, use the
13320 @code{set} command instead of the @code{print} command. @code{set} is
13321 really the same as @code{print} except that the expression's value is
13322 not printed and is not put in the value history (@pxref{Value History,
13323 ,Value History}). The expression is evaluated only for its effects.
13324
13325 If the beginning of the argument string of the @code{set} command
13326 appears identical to a @code{set} subcommand, use the @code{set
13327 variable} command instead of just @code{set}. This command is identical
13328 to @code{set} except for its lack of subcommands. For example, if your
13329 program has a variable @code{width}, you get an error if you try to set
13330 a new value with just @samp{set width=13}, because @value{GDBN} has the
13331 command @code{set width}:
13332
13333 @smallexample
13334 (@value{GDBP}) whatis width
13335 type = double
13336 (@value{GDBP}) p width
13337 $4 = 13
13338 (@value{GDBP}) set width=47
13339 Invalid syntax in expression.
13340 @end smallexample
13341
13342 @noindent
13343 The invalid expression, of course, is @samp{=47}. In
13344 order to actually set the program's variable @code{width}, use
13345
13346 @smallexample
13347 (@value{GDBP}) set var width=47
13348 @end smallexample
13349
13350 Because the @code{set} command has many subcommands that can conflict
13351 with the names of program variables, it is a good idea to use the
13352 @code{set variable} command instead of just @code{set}. For example, if
13353 your program has a variable @code{g}, you run into problems if you try
13354 to set a new value with just @samp{set g=4}, because @value{GDBN} has
13355 the command @code{set gnutarget}, abbreviated @code{set g}:
13356
13357 @smallexample
13358 @group
13359 (@value{GDBP}) whatis g
13360 type = double
13361 (@value{GDBP}) p g
13362 $1 = 1
13363 (@value{GDBP}) set g=4
13364 (@value{GDBP}) p g
13365 $2 = 1
13366 (@value{GDBP}) r
13367 The program being debugged has been started already.
13368 Start it from the beginning? (y or n) y
13369 Starting program: /home/smith/cc_progs/a.out
13370 "/home/smith/cc_progs/a.out": can't open to read symbols:
13371 Invalid bfd target.
13372 (@value{GDBP}) show g
13373 The current BFD target is "=4".
13374 @end group
13375 @end smallexample
13376
13377 @noindent
13378 The program variable @code{g} did not change, and you silently set the
13379 @code{gnutarget} to an invalid value. In order to set the variable
13380 @code{g}, use
13381
13382 @smallexample
13383 (@value{GDBP}) set var g=4
13384 @end smallexample
13385
13386 @value{GDBN} allows more implicit conversions in assignments than C; you can
13387 freely store an integer value into a pointer variable or vice versa,
13388 and you can convert any structure to any other structure that is the
13389 same length or shorter.
13390 @comment FIXME: how do structs align/pad in these conversions?
13391 @comment /doc@cygnus.com 18dec1990
13392
13393 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
13394 construct to generate a value of specified type at a specified address
13395 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
13396 to memory location @code{0x83040} as an integer (which implies a certain size
13397 and representation in memory), and
13398
13399 @smallexample
13400 set @{int@}0x83040 = 4
13401 @end smallexample
13402
13403 @noindent
13404 stores the value 4 into that memory location.
13405
13406 @node Jumping
13407 @section Continuing at a Different Address
13408
13409 Ordinarily, when you continue your program, you do so at the place where
13410 it stopped, with the @code{continue} command. You can instead continue at
13411 an address of your own choosing, with the following commands:
13412
13413 @table @code
13414 @kindex jump
13415 @item jump @var{linespec}
13416 @itemx jump @var{location}
13417 Resume execution at line @var{linespec} or at address given by
13418 @var{location}. Execution stops again immediately if there is a
13419 breakpoint there. @xref{Specify Location}, for a description of the
13420 different forms of @var{linespec} and @var{location}. It is common
13421 practice to use the @code{tbreak} command in conjunction with
13422 @code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
13423
13424 The @code{jump} command does not change the current stack frame, or
13425 the stack pointer, or the contents of any memory location or any
13426 register other than the program counter. If line @var{linespec} is in
13427 a different function from the one currently executing, the results may
13428 be bizarre if the two functions expect different patterns of arguments or
13429 of local variables. For this reason, the @code{jump} command requests
13430 confirmation if the specified line is not in the function currently
13431 executing. However, even bizarre results are predictable if you are
13432 well acquainted with the machine-language code of your program.
13433 @end table
13434
13435 @c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
13436 On many systems, you can get much the same effect as the @code{jump}
13437 command by storing a new value into the register @code{$pc}. The
13438 difference is that this does not start your program running; it only
13439 changes the address of where it @emph{will} run when you continue. For
13440 example,
13441
13442 @smallexample
13443 set $pc = 0x485
13444 @end smallexample
13445
13446 @noindent
13447 makes the next @code{continue} command or stepping command execute at
13448 address @code{0x485}, rather than at the address where your program stopped.
13449 @xref{Continuing and Stepping, ,Continuing and Stepping}.
13450
13451 The most common occasion to use the @code{jump} command is to back
13452 up---perhaps with more breakpoints set---over a portion of a program
13453 that has already executed, in order to examine its execution in more
13454 detail.
13455
13456 @c @group
13457 @node Signaling
13458 @section Giving your Program a Signal
13459 @cindex deliver a signal to a program
13460
13461 @table @code
13462 @kindex signal
13463 @item signal @var{signal}
13464 Resume execution where your program stopped, but immediately give it the
13465 signal @var{signal}. @var{signal} can be the name or the number of a
13466 signal. For example, on many systems @code{signal 2} and @code{signal
13467 SIGINT} are both ways of sending an interrupt signal.
13468
13469 Alternatively, if @var{signal} is zero, continue execution without
13470 giving a signal. This is useful when your program stopped on account of
13471 a signal and would ordinary see the signal when resumed with the
13472 @code{continue} command; @samp{signal 0} causes it to resume without a
13473 signal.
13474
13475 @code{signal} does not repeat when you press @key{RET} a second time
13476 after executing the command.
13477 @end table
13478 @c @end group
13479
13480 Invoking the @code{signal} command is not the same as invoking the
13481 @code{kill} utility from the shell. Sending a signal with @code{kill}
13482 causes @value{GDBN} to decide what to do with the signal depending on
13483 the signal handling tables (@pxref{Signals}). The @code{signal} command
13484 passes the signal directly to your program.
13485
13486
13487 @node Returning
13488 @section Returning from a Function
13489
13490 @table @code
13491 @cindex returning from a function
13492 @kindex return
13493 @item return
13494 @itemx return @var{expression}
13495 You can cancel execution of a function call with the @code{return}
13496 command. If you give an
13497 @var{expression} argument, its value is used as the function's return
13498 value.
13499 @end table
13500
13501 When you use @code{return}, @value{GDBN} discards the selected stack frame
13502 (and all frames within it). You can think of this as making the
13503 discarded frame return prematurely. If you wish to specify a value to
13504 be returned, give that value as the argument to @code{return}.
13505
13506 This pops the selected stack frame (@pxref{Selection, ,Selecting a
13507 Frame}), and any other frames inside of it, leaving its caller as the
13508 innermost remaining frame. That frame becomes selected. The
13509 specified value is stored in the registers used for returning values
13510 of functions.
13511
13512 The @code{return} command does not resume execution; it leaves the
13513 program stopped in the state that would exist if the function had just
13514 returned. In contrast, the @code{finish} command (@pxref{Continuing
13515 and Stepping, ,Continuing and Stepping}) resumes execution until the
13516 selected stack frame returns naturally.
13517
13518 @value{GDBN} needs to know how the @var{expression} argument should be set for
13519 the inferior. The concrete registers assignment depends on the OS ABI and the
13520 type being returned by the selected stack frame. For example it is common for
13521 OS ABI to return floating point values in FPU registers while integer values in
13522 CPU registers. Still some ABIs return even floating point values in CPU
13523 registers. Larger integer widths (such as @code{long long int}) also have
13524 specific placement rules. @value{GDBN} already knows the OS ABI from its
13525 current target so it needs to find out also the type being returned to make the
13526 assignment into the right register(s).
13527
13528 Normally, the selected stack frame has debug info. @value{GDBN} will always
13529 use the debug info instead of the implicit type of @var{expression} when the
13530 debug info is available. For example, if you type @kbd{return -1}, and the
13531 function in the current stack frame is declared to return a @code{long long
13532 int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
13533 into a @code{long long int}:
13534
13535 @smallexample
13536 Breakpoint 1, func () at gdb.base/return-nodebug.c:29
13537 29 return 31;
13538 (@value{GDBP}) return -1
13539 Make func return now? (y or n) y
13540 #0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
13541 43 printf ("result=%lld\n", func ());
13542 (@value{GDBP})
13543 @end smallexample
13544
13545 However, if the selected stack frame does not have a debug info, e.g., if the
13546 function was compiled without debug info, @value{GDBN} has to find out the type
13547 to return from user. Specifying a different type by mistake may set the value
13548 in different inferior registers than the caller code expects. For example,
13549 typing @kbd{return -1} with its implicit type @code{int} would set only a part
13550 of a @code{long long int} result for a debug info less function (on 32-bit
13551 architectures). Therefore the user is required to specify the return type by
13552 an appropriate cast explicitly:
13553
13554 @smallexample
13555 Breakpoint 2, 0x0040050b in func ()
13556 (@value{GDBP}) return -1
13557 Return value type not available for selected stack frame.
13558 Please use an explicit cast of the value to return.
13559 (@value{GDBP}) return (long long int) -1
13560 Make selected stack frame return now? (y or n) y
13561 #0 0x00400526 in main ()
13562 (@value{GDBP})
13563 @end smallexample
13564
13565 @node Calling
13566 @section Calling Program Functions
13567
13568 @table @code
13569 @cindex calling functions
13570 @cindex inferior functions, calling
13571 @item print @var{expr}
13572 Evaluate the expression @var{expr} and display the resulting value.
13573 @var{expr} may include calls to functions in the program being
13574 debugged.
13575
13576 @kindex call
13577 @item call @var{expr}
13578 Evaluate the expression @var{expr} without displaying @code{void}
13579 returned values.
13580
13581 You can use this variant of the @code{print} command if you want to
13582 execute a function from your program that does not return anything
13583 (a.k.a.@: @dfn{a void function}), but without cluttering the output
13584 with @code{void} returned values that @value{GDBN} will otherwise
13585 print. If the result is not void, it is printed and saved in the
13586 value history.
13587 @end table
13588
13589 It is possible for the function you call via the @code{print} or
13590 @code{call} command to generate a signal (e.g., if there's a bug in
13591 the function, or if you passed it incorrect arguments). What happens
13592 in that case is controlled by the @code{set unwindonsignal} command.
13593
13594 Similarly, with a C@t{++} program it is possible for the function you
13595 call via the @code{print} or @code{call} command to generate an
13596 exception that is not handled due to the constraints of the dummy
13597 frame. In this case, any exception that is raised in the frame, but has
13598 an out-of-frame exception handler will not be found. GDB builds a
13599 dummy-frame for the inferior function call, and the unwinder cannot
13600 seek for exception handlers outside of this dummy-frame. What happens
13601 in that case is controlled by the
13602 @code{set unwind-on-terminating-exception} command.
13603
13604 @table @code
13605 @item set unwindonsignal
13606 @kindex set unwindonsignal
13607 @cindex unwind stack in called functions
13608 @cindex call dummy stack unwinding
13609 Set unwinding of the stack if a signal is received while in a function
13610 that @value{GDBN} called in the program being debugged. If set to on,
13611 @value{GDBN} unwinds the stack it created for the call and restores
13612 the context to what it was before the call. If set to off (the
13613 default), @value{GDBN} stops in the frame where the signal was
13614 received.
13615
13616 @item show unwindonsignal
13617 @kindex show unwindonsignal
13618 Show the current setting of stack unwinding in the functions called by
13619 @value{GDBN}.
13620
13621 @item set unwind-on-terminating-exception
13622 @kindex set unwind-on-terminating-exception
13623 @cindex unwind stack in called functions with unhandled exceptions
13624 @cindex call dummy stack unwinding on unhandled exception.
13625 Set unwinding of the stack if a C@t{++} exception is raised, but left
13626 unhandled while in a function that @value{GDBN} called in the program being
13627 debugged. If set to on (the default), @value{GDBN} unwinds the stack
13628 it created for the call and restores the context to what it was before
13629 the call. If set to off, @value{GDBN} the exception is delivered to
13630 the default C@t{++} exception handler and the inferior terminated.
13631
13632 @item show unwind-on-terminating-exception
13633 @kindex show unwind-on-terminating-exception
13634 Show the current setting of stack unwinding in the functions called by
13635 @value{GDBN}.
13636
13637 @end table
13638
13639 @cindex weak alias functions
13640 Sometimes, a function you wish to call is actually a @dfn{weak alias}
13641 for another function. In such case, @value{GDBN} might not pick up
13642 the type information, including the types of the function arguments,
13643 which causes @value{GDBN} to call the inferior function incorrectly.
13644 As a result, the called function will function erroneously and may
13645 even crash. A solution to that is to use the name of the aliased
13646 function instead.
13647
13648 @node Patching
13649 @section Patching Programs
13650
13651 @cindex patching binaries
13652 @cindex writing into executables
13653 @cindex writing into corefiles
13654
13655 By default, @value{GDBN} opens the file containing your program's
13656 executable code (or the corefile) read-only. This prevents accidental
13657 alterations to machine code; but it also prevents you from intentionally
13658 patching your program's binary.
13659
13660 If you'd like to be able to patch the binary, you can specify that
13661 explicitly with the @code{set write} command. For example, you might
13662 want to turn on internal debugging flags, or even to make emergency
13663 repairs.
13664
13665 @table @code
13666 @kindex set write
13667 @item set write on
13668 @itemx set write off
13669 If you specify @samp{set write on}, @value{GDBN} opens executable and
13670 core files for both reading and writing; if you specify @kbd{set write
13671 off} (the default), @value{GDBN} opens them read-only.
13672
13673 If you have already loaded a file, you must load it again (using the
13674 @code{exec-file} or @code{core-file} command) after changing @code{set
13675 write}, for your new setting to take effect.
13676
13677 @item show write
13678 @kindex show write
13679 Display whether executable files and core files are opened for writing
13680 as well as reading.
13681 @end table
13682
13683 @node GDB Files
13684 @chapter @value{GDBN} Files
13685
13686 @value{GDBN} needs to know the file name of the program to be debugged,
13687 both in order to read its symbol table and in order to start your
13688 program. To debug a core dump of a previous run, you must also tell
13689 @value{GDBN} the name of the core dump file.
13690
13691 @menu
13692 * Files:: Commands to specify files
13693 * Separate Debug Files:: Debugging information in separate files
13694 * Symbol Errors:: Errors reading symbol files
13695 * Data Files:: GDB data files
13696 @end menu
13697
13698 @node Files
13699 @section Commands to Specify Files
13700
13701 @cindex symbol table
13702 @cindex core dump file
13703
13704 You may want to specify executable and core dump file names. The usual
13705 way to do this is at start-up time, using the arguments to
13706 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
13707 Out of @value{GDBN}}).
13708
13709 Occasionally it is necessary to change to a different file during a
13710 @value{GDBN} session. Or you may run @value{GDBN} and forget to
13711 specify a file you want to use. Or you are debugging a remote target
13712 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
13713 Program}). In these situations the @value{GDBN} commands to specify
13714 new files are useful.
13715
13716 @table @code
13717 @cindex executable file
13718 @kindex file
13719 @item file @var{filename}
13720 Use @var{filename} as the program to be debugged. It is read for its
13721 symbols and for the contents of pure memory. It is also the program
13722 executed when you use the @code{run} command. If you do not specify a
13723 directory and the file is not found in the @value{GDBN} working directory,
13724 @value{GDBN} uses the environment variable @code{PATH} as a list of
13725 directories to search, just as the shell does when looking for a program
13726 to run. You can change the value of this variable, for both @value{GDBN}
13727 and your program, using the @code{path} command.
13728
13729 @cindex unlinked object files
13730 @cindex patching object files
13731 You can load unlinked object @file{.o} files into @value{GDBN} using
13732 the @code{file} command. You will not be able to ``run'' an object
13733 file, but you can disassemble functions and inspect variables. Also,
13734 if the underlying BFD functionality supports it, you could use
13735 @kbd{gdb -write} to patch object files using this technique. Note
13736 that @value{GDBN} can neither interpret nor modify relocations in this
13737 case, so branches and some initialized variables will appear to go to
13738 the wrong place. But this feature is still handy from time to time.
13739
13740 @item file
13741 @code{file} with no argument makes @value{GDBN} discard any information it
13742 has on both executable file and the symbol table.
13743
13744 @kindex exec-file
13745 @item exec-file @r{[} @var{filename} @r{]}
13746 Specify that the program to be run (but not the symbol table) is found
13747 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
13748 if necessary to locate your program. Omitting @var{filename} means to
13749 discard information on the executable file.
13750
13751 @kindex symbol-file
13752 @item symbol-file @r{[} @var{filename} @r{]}
13753 Read symbol table information from file @var{filename}. @code{PATH} is
13754 searched when necessary. Use the @code{file} command to get both symbol
13755 table and program to run from the same file.
13756
13757 @code{symbol-file} with no argument clears out @value{GDBN} information on your
13758 program's symbol table.
13759
13760 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
13761 some breakpoints and auto-display expressions. This is because they may
13762 contain pointers to the internal data recording symbols and data types,
13763 which are part of the old symbol table data being discarded inside
13764 @value{GDBN}.
13765
13766 @code{symbol-file} does not repeat if you press @key{RET} again after
13767 executing it once.
13768
13769 When @value{GDBN} is configured for a particular environment, it
13770 understands debugging information in whatever format is the standard
13771 generated for that environment; you may use either a @sc{gnu} compiler, or
13772 other compilers that adhere to the local conventions.
13773 Best results are usually obtained from @sc{gnu} compilers; for example,
13774 using @code{@value{NGCC}} you can generate debugging information for
13775 optimized code.
13776
13777 For most kinds of object files, with the exception of old SVR3 systems
13778 using COFF, the @code{symbol-file} command does not normally read the
13779 symbol table in full right away. Instead, it scans the symbol table
13780 quickly to find which source files and which symbols are present. The
13781 details are read later, one source file at a time, as they are needed.
13782
13783 The purpose of this two-stage reading strategy is to make @value{GDBN}
13784 start up faster. For the most part, it is invisible except for
13785 occasional pauses while the symbol table details for a particular source
13786 file are being read. (The @code{set verbose} command can turn these
13787 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
13788 Warnings and Messages}.)
13789
13790 We have not implemented the two-stage strategy for COFF yet. When the
13791 symbol table is stored in COFF format, @code{symbol-file} reads the
13792 symbol table data in full right away. Note that ``stabs-in-COFF''
13793 still does the two-stage strategy, since the debug info is actually
13794 in stabs format.
13795
13796 @kindex readnow
13797 @cindex reading symbols immediately
13798 @cindex symbols, reading immediately
13799 @item symbol-file @var{filename} @r{[} -readnow @r{]}
13800 @itemx file @var{filename} @r{[} -readnow @r{]}
13801 You can override the @value{GDBN} two-stage strategy for reading symbol
13802 tables by using the @samp{-readnow} option with any of the commands that
13803 load symbol table information, if you want to be sure @value{GDBN} has the
13804 entire symbol table available.
13805
13806 @c FIXME: for now no mention of directories, since this seems to be in
13807 @c flux. 13mar1992 status is that in theory GDB would look either in
13808 @c current dir or in same dir as myprog; but issues like competing
13809 @c GDB's, or clutter in system dirs, mean that in practice right now
13810 @c only current dir is used. FFish says maybe a special GDB hierarchy
13811 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
13812 @c files.
13813
13814 @kindex core-file
13815 @item core-file @r{[}@var{filename}@r{]}
13816 @itemx core
13817 Specify the whereabouts of a core dump file to be used as the ``contents
13818 of memory''. Traditionally, core files contain only some parts of the
13819 address space of the process that generated them; @value{GDBN} can access the
13820 executable file itself for other parts.
13821
13822 @code{core-file} with no argument specifies that no core file is
13823 to be used.
13824
13825 Note that the core file is ignored when your program is actually running
13826 under @value{GDBN}. So, if you have been running your program and you
13827 wish to debug a core file instead, you must kill the subprocess in which
13828 the program is running. To do this, use the @code{kill} command
13829 (@pxref{Kill Process, ,Killing the Child Process}).
13830
13831 @kindex add-symbol-file
13832 @cindex dynamic linking
13833 @item add-symbol-file @var{filename} @var{address}
13834 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
13835 @itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
13836 The @code{add-symbol-file} command reads additional symbol table
13837 information from the file @var{filename}. You would use this command
13838 when @var{filename} has been dynamically loaded (by some other means)
13839 into the program that is running. @var{address} should be the memory
13840 address at which the file has been loaded; @value{GDBN} cannot figure
13841 this out for itself. You can additionally specify an arbitrary number
13842 of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
13843 section name and base address for that section. You can specify any
13844 @var{address} as an expression.
13845
13846 The symbol table of the file @var{filename} is added to the symbol table
13847 originally read with the @code{symbol-file} command. You can use the
13848 @code{add-symbol-file} command any number of times; the new symbol data
13849 thus read keeps adding to the old. To discard all old symbol data
13850 instead, use the @code{symbol-file} command without any arguments.
13851
13852 @cindex relocatable object files, reading symbols from
13853 @cindex object files, relocatable, reading symbols from
13854 @cindex reading symbols from relocatable object files
13855 @cindex symbols, reading from relocatable object files
13856 @cindex @file{.o} files, reading symbols from
13857 Although @var{filename} is typically a shared library file, an
13858 executable file, or some other object file which has been fully
13859 relocated for loading into a process, you can also load symbolic
13860 information from relocatable @file{.o} files, as long as:
13861
13862 @itemize @bullet
13863 @item
13864 the file's symbolic information refers only to linker symbols defined in
13865 that file, not to symbols defined by other object files,
13866 @item
13867 every section the file's symbolic information refers to has actually
13868 been loaded into the inferior, as it appears in the file, and
13869 @item
13870 you can determine the address at which every section was loaded, and
13871 provide these to the @code{add-symbol-file} command.
13872 @end itemize
13873
13874 @noindent
13875 Some embedded operating systems, like Sun Chorus and VxWorks, can load
13876 relocatable files into an already running program; such systems
13877 typically make the requirements above easy to meet. However, it's
13878 important to recognize that many native systems use complex link
13879 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
13880 assembly, for example) that make the requirements difficult to meet. In
13881 general, one cannot assume that using @code{add-symbol-file} to read a
13882 relocatable object file's symbolic information will have the same effect
13883 as linking the relocatable object file into the program in the normal
13884 way.
13885
13886 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
13887
13888 @kindex add-symbol-file-from-memory
13889 @cindex @code{syscall DSO}
13890 @cindex load symbols from memory
13891 @item add-symbol-file-from-memory @var{address}
13892 Load symbols from the given @var{address} in a dynamically loaded
13893 object file whose image is mapped directly into the inferior's memory.
13894 For example, the Linux kernel maps a @code{syscall DSO} into each
13895 process's address space; this DSO provides kernel-specific code for
13896 some system calls. The argument can be any expression whose
13897 evaluation yields the address of the file's shared object file header.
13898 For this command to work, you must have used @code{symbol-file} or
13899 @code{exec-file} commands in advance.
13900
13901 @kindex add-shared-symbol-files
13902 @kindex assf
13903 @item add-shared-symbol-files @var{library-file}
13904 @itemx assf @var{library-file}
13905 The @code{add-shared-symbol-files} command can currently be used only
13906 in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
13907 alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
13908 @value{GDBN} automatically looks for shared libraries, however if
13909 @value{GDBN} does not find yours, you can invoke
13910 @code{add-shared-symbol-files}. It takes one argument: the shared
13911 library's file name. @code{assf} is a shorthand alias for
13912 @code{add-shared-symbol-files}.
13913
13914 @kindex section
13915 @item section @var{section} @var{addr}
13916 The @code{section} command changes the base address of the named
13917 @var{section} of the exec file to @var{addr}. This can be used if the
13918 exec file does not contain section addresses, (such as in the
13919 @code{a.out} format), or when the addresses specified in the file
13920 itself are wrong. Each section must be changed separately. The
13921 @code{info files} command, described below, lists all the sections and
13922 their addresses.
13923
13924 @kindex info files
13925 @kindex info target
13926 @item info files
13927 @itemx info target
13928 @code{info files} and @code{info target} are synonymous; both print the
13929 current target (@pxref{Targets, ,Specifying a Debugging Target}),
13930 including the names of the executable and core dump files currently in
13931 use by @value{GDBN}, and the files from which symbols were loaded. The
13932 command @code{help target} lists all possible targets rather than
13933 current ones.
13934
13935 @kindex maint info sections
13936 @item maint info sections
13937 Another command that can give you extra information about program sections
13938 is @code{maint info sections}. In addition to the section information
13939 displayed by @code{info files}, this command displays the flags and file
13940 offset of each section in the executable and core dump files. In addition,
13941 @code{maint info sections} provides the following command options (which
13942 may be arbitrarily combined):
13943
13944 @table @code
13945 @item ALLOBJ
13946 Display sections for all loaded object files, including shared libraries.
13947 @item @var{sections}
13948 Display info only for named @var{sections}.
13949 @item @var{section-flags}
13950 Display info only for sections for which @var{section-flags} are true.
13951 The section flags that @value{GDBN} currently knows about are:
13952 @table @code
13953 @item ALLOC
13954 Section will have space allocated in the process when loaded.
13955 Set for all sections except those containing debug information.
13956 @item LOAD
13957 Section will be loaded from the file into the child process memory.
13958 Set for pre-initialized code and data, clear for @code{.bss} sections.
13959 @item RELOC
13960 Section needs to be relocated before loading.
13961 @item READONLY
13962 Section cannot be modified by the child process.
13963 @item CODE
13964 Section contains executable code only.
13965 @item DATA
13966 Section contains data only (no executable code).
13967 @item ROM
13968 Section will reside in ROM.
13969 @item CONSTRUCTOR
13970 Section contains data for constructor/destructor lists.
13971 @item HAS_CONTENTS
13972 Section is not empty.
13973 @item NEVER_LOAD
13974 An instruction to the linker to not output the section.
13975 @item COFF_SHARED_LIBRARY
13976 A notification to the linker that the section contains
13977 COFF shared library information.
13978 @item IS_COMMON
13979 Section contains common symbols.
13980 @end table
13981 @end table
13982 @kindex set trust-readonly-sections
13983 @cindex read-only sections
13984 @item set trust-readonly-sections on
13985 Tell @value{GDBN} that readonly sections in your object file
13986 really are read-only (i.e.@: that their contents will not change).
13987 In that case, @value{GDBN} can fetch values from these sections
13988 out of the object file, rather than from the target program.
13989 For some targets (notably embedded ones), this can be a significant
13990 enhancement to debugging performance.
13991
13992 The default is off.
13993
13994 @item set trust-readonly-sections off
13995 Tell @value{GDBN} not to trust readonly sections. This means that
13996 the contents of the section might change while the program is running,
13997 and must therefore be fetched from the target when needed.
13998
13999 @item show trust-readonly-sections
14000 Show the current setting of trusting readonly sections.
14001 @end table
14002
14003 All file-specifying commands allow both absolute and relative file names
14004 as arguments. @value{GDBN} always converts the file name to an absolute file
14005 name and remembers it that way.
14006
14007 @cindex shared libraries
14008 @anchor{Shared Libraries}
14009 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
14010 and IBM RS/6000 AIX shared libraries.
14011
14012 On MS-Windows @value{GDBN} must be linked with the Expat library to support
14013 shared libraries. @xref{Expat}.
14014
14015 @value{GDBN} automatically loads symbol definitions from shared libraries
14016 when you use the @code{run} command, or when you examine a core file.
14017 (Before you issue the @code{run} command, @value{GDBN} does not understand
14018 references to a function in a shared library, however---unless you are
14019 debugging a core file).
14020
14021 On HP-UX, if the program loads a library explicitly, @value{GDBN}
14022 automatically loads the symbols at the time of the @code{shl_load} call.
14023
14024 @c FIXME: some @value{GDBN} release may permit some refs to undef
14025 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
14026 @c FIXME...lib; check this from time to time when updating manual
14027
14028 There are times, however, when you may wish to not automatically load
14029 symbol definitions from shared libraries, such as when they are
14030 particularly large or there are many of them.
14031
14032 To control the automatic loading of shared library symbols, use the
14033 commands:
14034
14035 @table @code
14036 @kindex set auto-solib-add
14037 @item set auto-solib-add @var{mode}
14038 If @var{mode} is @code{on}, symbols from all shared object libraries
14039 will be loaded automatically when the inferior begins execution, you
14040 attach to an independently started inferior, or when the dynamic linker
14041 informs @value{GDBN} that a new library has been loaded. If @var{mode}
14042 is @code{off}, symbols must be loaded manually, using the
14043 @code{sharedlibrary} command. The default value is @code{on}.
14044
14045 @cindex memory used for symbol tables
14046 If your program uses lots of shared libraries with debug info that
14047 takes large amounts of memory, you can decrease the @value{GDBN}
14048 memory footprint by preventing it from automatically loading the
14049 symbols from shared libraries. To that end, type @kbd{set
14050 auto-solib-add off} before running the inferior, then load each
14051 library whose debug symbols you do need with @kbd{sharedlibrary
14052 @var{regexp}}, where @var{regexp} is a regular expression that matches
14053 the libraries whose symbols you want to be loaded.
14054
14055 @kindex show auto-solib-add
14056 @item show auto-solib-add
14057 Display the current autoloading mode.
14058 @end table
14059
14060 @cindex load shared library
14061 To explicitly load shared library symbols, use the @code{sharedlibrary}
14062 command:
14063
14064 @table @code
14065 @kindex info sharedlibrary
14066 @kindex info share
14067 @item info share @var{regex}
14068 @itemx info sharedlibrary @var{regex}
14069 Print the names of the shared libraries which are currently loaded
14070 that match @var{regex}. If @var{regex} is omitted then print
14071 all shared libraries that are loaded.
14072
14073 @kindex sharedlibrary
14074 @kindex share
14075 @item sharedlibrary @var{regex}
14076 @itemx share @var{regex}
14077 Load shared object library symbols for files matching a
14078 Unix regular expression.
14079 As with files loaded automatically, it only loads shared libraries
14080 required by your program for a core file or after typing @code{run}. If
14081 @var{regex} is omitted all shared libraries required by your program are
14082 loaded.
14083
14084 @item nosharedlibrary
14085 @kindex nosharedlibrary
14086 @cindex unload symbols from shared libraries
14087 Unload all shared object library symbols. This discards all symbols
14088 that have been loaded from all shared libraries. Symbols from shared
14089 libraries that were loaded by explicit user requests are not
14090 discarded.
14091 @end table
14092
14093 Sometimes you may wish that @value{GDBN} stops and gives you control
14094 when any of shared library events happen. Use the @code{set
14095 stop-on-solib-events} command for this:
14096
14097 @table @code
14098 @item set stop-on-solib-events
14099 @kindex set stop-on-solib-events
14100 This command controls whether @value{GDBN} should give you control
14101 when the dynamic linker notifies it about some shared library event.
14102 The most common event of interest is loading or unloading of a new
14103 shared library.
14104
14105 @item show stop-on-solib-events
14106 @kindex show stop-on-solib-events
14107 Show whether @value{GDBN} stops and gives you control when shared
14108 library events happen.
14109 @end table
14110
14111 Shared libraries are also supported in many cross or remote debugging
14112 configurations. @value{GDBN} needs to have access to the target's libraries;
14113 this can be accomplished either by providing copies of the libraries
14114 on the host system, or by asking @value{GDBN} to automatically retrieve the
14115 libraries from the target. If copies of the target libraries are
14116 provided, they need to be the same as the target libraries, although the
14117 copies on the target can be stripped as long as the copies on the host are
14118 not.
14119
14120 @cindex where to look for shared libraries
14121 For remote debugging, you need to tell @value{GDBN} where the target
14122 libraries are, so that it can load the correct copies---otherwise, it
14123 may try to load the host's libraries. @value{GDBN} has two variables
14124 to specify the search directories for target libraries.
14125
14126 @table @code
14127 @cindex prefix for shared library file names
14128 @cindex system root, alternate
14129 @kindex set solib-absolute-prefix
14130 @kindex set sysroot
14131 @item set sysroot @var{path}
14132 Use @var{path} as the system root for the program being debugged. Any
14133 absolute shared library paths will be prefixed with @var{path}; many
14134 runtime loaders store the absolute paths to the shared library in the
14135 target program's memory. If you use @code{set sysroot} to find shared
14136 libraries, they need to be laid out in the same way that they are on
14137 the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
14138 under @var{path}.
14139
14140 If @var{path} starts with the sequence @file{remote:}, @value{GDBN} will
14141 retrieve the target libraries from the remote system. This is only
14142 supported when using a remote target that supports the @code{remote get}
14143 command (@pxref{File Transfer,,Sending files to a remote system}).
14144 The part of @var{path} following the initial @file{remote:}
14145 (if present) is used as system root prefix on the remote file system.
14146 @footnote{If you want to specify a local system root using a directory
14147 that happens to be named @file{remote:}, you need to use some equivalent
14148 variant of the name like @file{./remote:}.}
14149
14150 The @code{set solib-absolute-prefix} command is an alias for @code{set
14151 sysroot}.
14152
14153 @cindex default system root
14154 @cindex @samp{--with-sysroot}
14155 You can set the default system root by using the configure-time
14156 @samp{--with-sysroot} option. If the system root is inside
14157 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
14158 @samp{--exec-prefix}), then the default system root will be updated
14159 automatically if the installed @value{GDBN} is moved to a new
14160 location.
14161
14162 @kindex show sysroot
14163 @item show sysroot
14164 Display the current shared library prefix.
14165
14166 @kindex set solib-search-path
14167 @item set solib-search-path @var{path}
14168 If this variable is set, @var{path} is a colon-separated list of
14169 directories to search for shared libraries. @samp{solib-search-path}
14170 is used after @samp{sysroot} fails to locate the library, or if the
14171 path to the library is relative instead of absolute. If you want to
14172 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
14173 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
14174 finding your host's libraries. @samp{sysroot} is preferred; setting
14175 it to a nonexistent directory may interfere with automatic loading
14176 of shared library symbols.
14177
14178 @kindex show solib-search-path
14179 @item show solib-search-path
14180 Display the current shared library search path.
14181 @end table
14182
14183
14184 @node Separate Debug Files
14185 @section Debugging Information in Separate Files
14186 @cindex separate debugging information files
14187 @cindex debugging information in separate files
14188 @cindex @file{.debug} subdirectories
14189 @cindex debugging information directory, global
14190 @cindex global debugging information directory
14191 @cindex build ID, and separate debugging files
14192 @cindex @file{.build-id} directory
14193
14194 @value{GDBN} allows you to put a program's debugging information in a
14195 file separate from the executable itself, in a way that allows
14196 @value{GDBN} to find and load the debugging information automatically.
14197 Since debugging information can be very large---sometimes larger
14198 than the executable code itself---some systems distribute debugging
14199 information for their executables in separate files, which users can
14200 install only when they need to debug a problem.
14201
14202 @value{GDBN} supports two ways of specifying the separate debug info
14203 file:
14204
14205 @itemize @bullet
14206 @item
14207 The executable contains a @dfn{debug link} that specifies the name of
14208 the separate debug info file. The separate debug file's name is
14209 usually @file{@var{executable}.debug}, where @var{executable} is the
14210 name of the corresponding executable file without leading directories
14211 (e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
14212 debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
14213 checksum for the debug file, which @value{GDBN} uses to validate that
14214 the executable and the debug file came from the same build.
14215
14216 @item
14217 The executable contains a @dfn{build ID}, a unique bit string that is
14218 also present in the corresponding debug info file. (This is supported
14219 only on some operating systems, notably those which use the ELF format
14220 for binary files and the @sc{gnu} Binutils.) For more details about
14221 this feature, see the description of the @option{--build-id}
14222 command-line option in @ref{Options, , Command Line Options, ld.info,
14223 The GNU Linker}. The debug info file's name is not specified
14224 explicitly by the build ID, but can be computed from the build ID, see
14225 below.
14226 @end itemize
14227
14228 Depending on the way the debug info file is specified, @value{GDBN}
14229 uses two different methods of looking for the debug file:
14230
14231 @itemize @bullet
14232 @item
14233 For the ``debug link'' method, @value{GDBN} looks up the named file in
14234 the directory of the executable file, then in a subdirectory of that
14235 directory named @file{.debug}, and finally under the global debug
14236 directory, in a subdirectory whose name is identical to the leading
14237 directories of the executable's absolute file name.
14238
14239 @item
14240 For the ``build ID'' method, @value{GDBN} looks in the
14241 @file{.build-id} subdirectory of the global debug directory for a file
14242 named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
14243 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
14244 are the rest of the bit string. (Real build ID strings are 32 or more
14245 hex characters, not 10.)
14246 @end itemize
14247
14248 So, for example, suppose you ask @value{GDBN} to debug
14249 @file{/usr/bin/ls}, which has a debug link that specifies the
14250 file @file{ls.debug}, and a build ID whose value in hex is
14251 @code{abcdef1234}. If the global debug directory is
14252 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
14253 debug information files, in the indicated order:
14254
14255 @itemize @minus
14256 @item
14257 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
14258 @item
14259 @file{/usr/bin/ls.debug}
14260 @item
14261 @file{/usr/bin/.debug/ls.debug}
14262 @item
14263 @file{/usr/lib/debug/usr/bin/ls.debug}.
14264 @end itemize
14265
14266 You can set the global debugging info directory's name, and view the
14267 name @value{GDBN} is currently using.
14268
14269 @table @code
14270
14271 @kindex set debug-file-directory
14272 @item set debug-file-directory @var{directories}
14273 Set the directories which @value{GDBN} searches for separate debugging
14274 information files to @var{directory}. Multiple directory components can be set
14275 concatenating them by a directory separator.
14276
14277 @kindex show debug-file-directory
14278 @item show debug-file-directory
14279 Show the directories @value{GDBN} searches for separate debugging
14280 information files.
14281
14282 @end table
14283
14284 @cindex @code{.gnu_debuglink} sections
14285 @cindex debug link sections
14286 A debug link is a special section of the executable file named
14287 @code{.gnu_debuglink}. The section must contain:
14288
14289 @itemize
14290 @item
14291 A filename, with any leading directory components removed, followed by
14292 a zero byte,
14293 @item
14294 zero to three bytes of padding, as needed to reach the next four-byte
14295 boundary within the section, and
14296 @item
14297 a four-byte CRC checksum, stored in the same endianness used for the
14298 executable file itself. The checksum is computed on the debugging
14299 information file's full contents by the function given below, passing
14300 zero as the @var{crc} argument.
14301 @end itemize
14302
14303 Any executable file format can carry a debug link, as long as it can
14304 contain a section named @code{.gnu_debuglink} with the contents
14305 described above.
14306
14307 @cindex @code{.note.gnu.build-id} sections
14308 @cindex build ID sections
14309 The build ID is a special section in the executable file (and in other
14310 ELF binary files that @value{GDBN} may consider). This section is
14311 often named @code{.note.gnu.build-id}, but that name is not mandatory.
14312 It contains unique identification for the built files---the ID remains
14313 the same across multiple builds of the same build tree. The default
14314 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
14315 content for the build ID string. The same section with an identical
14316 value is present in the original built binary with symbols, in its
14317 stripped variant, and in the separate debugging information file.
14318
14319 The debugging information file itself should be an ordinary
14320 executable, containing a full set of linker symbols, sections, and
14321 debugging information. The sections of the debugging information file
14322 should have the same names, addresses, and sizes as the original file,
14323 but they need not contain any data---much like a @code{.bss} section
14324 in an ordinary executable.
14325
14326 The @sc{gnu} binary utilities (Binutils) package includes the
14327 @samp{objcopy} utility that can produce
14328 the separated executable / debugging information file pairs using the
14329 following commands:
14330
14331 @smallexample
14332 @kbd{objcopy --only-keep-debug foo foo.debug}
14333 @kbd{strip -g foo}
14334 @end smallexample
14335
14336 @noindent
14337 These commands remove the debugging
14338 information from the executable file @file{foo} and place it in the file
14339 @file{foo.debug}. You can use the first, second or both methods to link the
14340 two files:
14341
14342 @itemize @bullet
14343 @item
14344 The debug link method needs the following additional command to also leave
14345 behind a debug link in @file{foo}:
14346
14347 @smallexample
14348 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
14349 @end smallexample
14350
14351 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
14352 a version of the @code{strip} command such that the command @kbd{strip foo -f
14353 foo.debug} has the same functionality as the two @code{objcopy} commands and
14354 the @code{ln -s} command above, together.
14355
14356 @item
14357 Build ID gets embedded into the main executable using @code{ld --build-id} or
14358 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
14359 compatibility fixes for debug files separation are present in @sc{gnu} binary
14360 utilities (Binutils) package since version 2.18.
14361 @end itemize
14362
14363 @noindent
14364
14365 @cindex CRC algorithm definition
14366 The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
14367 IEEE 802.3 using the polynomial:
14368
14369 @c TexInfo requires naked braces for multi-digit exponents for Tex
14370 @c output, but this causes HTML output to barf. HTML has to be set using
14371 @c raw commands. So we end up having to specify this equation in 2
14372 @c different ways!
14373 @ifhtml
14374 @display
14375 @html
14376 <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>
14377 + <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
14378 @end html
14379 @end display
14380 @end ifhtml
14381 @ifnothtml
14382 @display
14383 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
14384 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
14385 @end display
14386 @end ifnothtml
14387
14388 The function is computed byte at a time, taking the least
14389 significant bit of each byte first. The initial pattern
14390 @code{0xffffffff} is used, to ensure leading zeros affect the CRC and
14391 the final result is inverted to ensure trailing zeros also affect the
14392 CRC.
14393
14394 @emph{Note:} This is the same CRC polynomial as used in handling the
14395 @dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{Remote Protocol,
14396 , @value{GDBN} Remote Serial Protocol}). However in the
14397 case of the Remote Serial Protocol, the CRC is computed @emph{most}
14398 significant bit first, and the result is not inverted, so trailing
14399 zeros have no effect on the CRC value.
14400
14401 To complete the description, we show below the code of the function
14402 which produces the CRC used in @code{.gnu_debuglink}. Inverting the
14403 initially supplied @code{crc} argument means that an initial call to
14404 this function passing in zero will start computing the CRC using
14405 @code{0xffffffff}.
14406
14407 @kindex gnu_debuglink_crc32
14408 @smallexample
14409 unsigned long
14410 gnu_debuglink_crc32 (unsigned long crc,
14411 unsigned char *buf, size_t len)
14412 @{
14413 static const unsigned long crc32_table[256] =
14414 @{
14415 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
14416 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
14417 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
14418 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
14419 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
14420 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
14421 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
14422 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
14423 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
14424 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
14425 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
14426 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
14427 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
14428 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
14429 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
14430 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
14431 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
14432 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
14433 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
14434 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
14435 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
14436 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
14437 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
14438 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
14439 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
14440 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
14441 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
14442 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
14443 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
14444 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
14445 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
14446 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
14447 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
14448 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
14449 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
14450 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
14451 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
14452 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
14453 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
14454 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
14455 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
14456 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
14457 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
14458 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
14459 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
14460 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
14461 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
14462 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
14463 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
14464 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
14465 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
14466 0x2d02ef8d
14467 @};
14468 unsigned char *end;
14469
14470 crc = ~crc & 0xffffffff;
14471 for (end = buf + len; buf < end; ++buf)
14472 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
14473 return ~crc & 0xffffffff;
14474 @}
14475 @end smallexample
14476
14477 @noindent
14478 This computation does not apply to the ``build ID'' method.
14479
14480
14481 @node Symbol Errors
14482 @section Errors Reading Symbol Files
14483
14484 While reading a symbol file, @value{GDBN} occasionally encounters problems,
14485 such as symbol types it does not recognize, or known bugs in compiler
14486 output. By default, @value{GDBN} does not notify you of such problems, since
14487 they are relatively common and primarily of interest to people
14488 debugging compilers. If you are interested in seeing information
14489 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
14490 only one message about each such type of problem, no matter how many
14491 times the problem occurs; or you can ask @value{GDBN} to print more messages,
14492 to see how many times the problems occur, with the @code{set
14493 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
14494 Messages}).
14495
14496 The messages currently printed, and their meanings, include:
14497
14498 @table @code
14499 @item inner block not inside outer block in @var{symbol}
14500
14501 The symbol information shows where symbol scopes begin and end
14502 (such as at the start of a function or a block of statements). This
14503 error indicates that an inner scope block is not fully contained
14504 in its outer scope blocks.
14505
14506 @value{GDBN} circumvents the problem by treating the inner block as if it had
14507 the same scope as the outer block. In the error message, @var{symbol}
14508 may be shown as ``@code{(don't know)}'' if the outer block is not a
14509 function.
14510
14511 @item block at @var{address} out of order
14512
14513 The symbol information for symbol scope blocks should occur in
14514 order of increasing addresses. This error indicates that it does not
14515 do so.
14516
14517 @value{GDBN} does not circumvent this problem, and has trouble
14518 locating symbols in the source file whose symbols it is reading. (You
14519 can often determine what source file is affected by specifying
14520 @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
14521 Messages}.)
14522
14523 @item bad block start address patched
14524
14525 The symbol information for a symbol scope block has a start address
14526 smaller than the address of the preceding source line. This is known
14527 to occur in the SunOS 4.1.1 (and earlier) C compiler.
14528
14529 @value{GDBN} circumvents the problem by treating the symbol scope block as
14530 starting on the previous source line.
14531
14532 @item bad string table offset in symbol @var{n}
14533
14534 @cindex foo
14535 Symbol number @var{n} contains a pointer into the string table which is
14536 larger than the size of the string table.
14537
14538 @value{GDBN} circumvents the problem by considering the symbol to have the
14539 name @code{foo}, which may cause other problems if many symbols end up
14540 with this name.
14541
14542 @item unknown symbol type @code{0x@var{nn}}
14543
14544 The symbol information contains new data types that @value{GDBN} does
14545 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
14546 uncomprehended information, in hexadecimal.
14547
14548 @value{GDBN} circumvents the error by ignoring this symbol information.
14549 This usually allows you to debug your program, though certain symbols
14550 are not accessible. If you encounter such a problem and feel like
14551 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
14552 on @code{complain}, then go up to the function @code{read_dbx_symtab}
14553 and examine @code{*bufp} to see the symbol.
14554
14555 @item stub type has NULL name
14556
14557 @value{GDBN} could not find the full definition for a struct or class.
14558
14559 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
14560 The symbol information for a C@t{++} member function is missing some
14561 information that recent versions of the compiler should have output for
14562 it.
14563
14564 @item info mismatch between compiler and debugger
14565
14566 @value{GDBN} could not parse a type specification output by the compiler.
14567
14568 @end table
14569
14570 @node Data Files
14571 @section GDB Data Files
14572
14573 @cindex prefix for data files
14574 @value{GDBN} will sometimes read an auxiliary data file. These files
14575 are kept in a directory known as the @dfn{data directory}.
14576
14577 You can set the data directory's name, and view the name @value{GDBN}
14578 is currently using.
14579
14580 @table @code
14581 @kindex set data-directory
14582 @item set data-directory @var{directory}
14583 Set the directory which @value{GDBN} searches for auxiliary data files
14584 to @var{directory}.
14585
14586 @kindex show data-directory
14587 @item show data-directory
14588 Show the directory @value{GDBN} searches for auxiliary data files.
14589 @end table
14590
14591 @cindex default data directory
14592 @cindex @samp{--with-gdb-datadir}
14593 You can set the default data directory by using the configure-time
14594 @samp{--with-gdb-datadir} option. If the data directory is inside
14595 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
14596 @samp{--exec-prefix}), then the default data directory will be updated
14597 automatically if the installed @value{GDBN} is moved to a new
14598 location.
14599
14600 @node Targets
14601 @chapter Specifying a Debugging Target
14602
14603 @cindex debugging target
14604 A @dfn{target} is the execution environment occupied by your program.
14605
14606 Often, @value{GDBN} runs in the same host environment as your program;
14607 in that case, the debugging target is specified as a side effect when
14608 you use the @code{file} or @code{core} commands. When you need more
14609 flexibility---for example, running @value{GDBN} on a physically separate
14610 host, or controlling a standalone system over a serial port or a
14611 realtime system over a TCP/IP connection---you can use the @code{target}
14612 command to specify one of the target types configured for @value{GDBN}
14613 (@pxref{Target Commands, ,Commands for Managing Targets}).
14614
14615 @cindex target architecture
14616 It is possible to build @value{GDBN} for several different @dfn{target
14617 architectures}. When @value{GDBN} is built like that, you can choose
14618 one of the available architectures with the @kbd{set architecture}
14619 command.
14620
14621 @table @code
14622 @kindex set architecture
14623 @kindex show architecture
14624 @item set architecture @var{arch}
14625 This command sets the current target architecture to @var{arch}. The
14626 value of @var{arch} can be @code{"auto"}, in addition to one of the
14627 supported architectures.
14628
14629 @item show architecture
14630 Show the current target architecture.
14631
14632 @item set processor
14633 @itemx processor
14634 @kindex set processor
14635 @kindex show processor
14636 These are alias commands for, respectively, @code{set architecture}
14637 and @code{show architecture}.
14638 @end table
14639
14640 @menu
14641 * Active Targets:: Active targets
14642 * Target Commands:: Commands for managing targets
14643 * Byte Order:: Choosing target byte order
14644 @end menu
14645
14646 @node Active Targets
14647 @section Active Targets
14648
14649 @cindex stacking targets
14650 @cindex active targets
14651 @cindex multiple targets
14652
14653 There are three classes of targets: processes, core files, and
14654 executable files. @value{GDBN} can work concurrently on up to three
14655 active targets, one in each class. This allows you to (for example)
14656 start a process and inspect its activity without abandoning your work on
14657 a core file.
14658
14659 For example, if you execute @samp{gdb a.out}, then the executable file
14660 @code{a.out} is the only active target. If you designate a core file as
14661 well---presumably from a prior run that crashed and coredumped---then
14662 @value{GDBN} has two active targets and uses them in tandem, looking
14663 first in the corefile target, then in the executable file, to satisfy
14664 requests for memory addresses. (Typically, these two classes of target
14665 are complementary, since core files contain only a program's
14666 read-write memory---variables and so on---plus machine status, while
14667 executable files contain only the program text and initialized data.)
14668
14669 When you type @code{run}, your executable file becomes an active process
14670 target as well. When a process target is active, all @value{GDBN}
14671 commands requesting memory addresses refer to that target; addresses in
14672 an active core file or executable file target are obscured while the
14673 process target is active.
14674
14675 Use the @code{core-file} and @code{exec-file} commands to select a new
14676 core file or executable target (@pxref{Files, ,Commands to Specify
14677 Files}). To specify as a target a process that is already running, use
14678 the @code{attach} command (@pxref{Attach, ,Debugging an Already-running
14679 Process}).
14680
14681 @node Target Commands
14682 @section Commands for Managing Targets
14683
14684 @table @code
14685 @item target @var{type} @var{parameters}
14686 Connects the @value{GDBN} host environment to a target machine or
14687 process. A target is typically a protocol for talking to debugging
14688 facilities. You use the argument @var{type} to specify the type or
14689 protocol of the target machine.
14690
14691 Further @var{parameters} are interpreted by the target protocol, but
14692 typically include things like device names or host names to connect
14693 with, process numbers, and baud rates.
14694
14695 The @code{target} command does not repeat if you press @key{RET} again
14696 after executing the command.
14697
14698 @kindex help target
14699 @item help target
14700 Displays the names of all targets available. To display targets
14701 currently selected, use either @code{info target} or @code{info files}
14702 (@pxref{Files, ,Commands to Specify Files}).
14703
14704 @item help target @var{name}
14705 Describe a particular target, including any parameters necessary to
14706 select it.
14707
14708 @kindex set gnutarget
14709 @item set gnutarget @var{args}
14710 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
14711 knows whether it is reading an @dfn{executable},
14712 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
14713 with the @code{set gnutarget} command. Unlike most @code{target} commands,
14714 with @code{gnutarget} the @code{target} refers to a program, not a machine.
14715
14716 @quotation
14717 @emph{Warning:} To specify a file format with @code{set gnutarget},
14718 you must know the actual BFD name.
14719 @end quotation
14720
14721 @noindent
14722 @xref{Files, , Commands to Specify Files}.
14723
14724 @kindex show gnutarget
14725 @item show gnutarget
14726 Use the @code{show gnutarget} command to display what file format
14727 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
14728 @value{GDBN} will determine the file format for each file automatically,
14729 and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
14730 @end table
14731
14732 @cindex common targets
14733 Here are some common targets (available, or not, depending on the GDB
14734 configuration):
14735
14736 @table @code
14737 @kindex target
14738 @item target exec @var{program}
14739 @cindex executable file target
14740 An executable file. @samp{target exec @var{program}} is the same as
14741 @samp{exec-file @var{program}}.
14742
14743 @item target core @var{filename}
14744 @cindex core dump file target
14745 A core dump file. @samp{target core @var{filename}} is the same as
14746 @samp{core-file @var{filename}}.
14747
14748 @item target remote @var{medium}
14749 @cindex remote target
14750 A remote system connected to @value{GDBN} via a serial line or network
14751 connection. This command tells @value{GDBN} to use its own remote
14752 protocol over @var{medium} for debugging. @xref{Remote Debugging}.
14753
14754 For example, if you have a board connected to @file{/dev/ttya} on the
14755 machine running @value{GDBN}, you could say:
14756
14757 @smallexample
14758 target remote /dev/ttya
14759 @end smallexample
14760
14761 @code{target remote} supports the @code{load} command. This is only
14762 useful if you have some other way of getting the stub to the target
14763 system, and you can put it somewhere in memory where it won't get
14764 clobbered by the download.
14765
14766 @item target sim
14767 @cindex built-in simulator target
14768 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
14769 In general,
14770 @smallexample
14771 target sim
14772 load
14773 run
14774 @end smallexample
14775 @noindent
14776 works; however, you cannot assume that a specific memory map, device
14777 drivers, or even basic I/O is available, although some simulators do
14778 provide these. For info about any processor-specific simulator details,
14779 see the appropriate section in @ref{Embedded Processors, ,Embedded
14780 Processors}.
14781
14782 @end table
14783
14784 Some configurations may include these targets as well:
14785
14786 @table @code
14787
14788 @item target nrom @var{dev}
14789 @cindex NetROM ROM emulator target
14790 NetROM ROM emulator. This target only supports downloading.
14791
14792 @end table
14793
14794 Different targets are available on different configurations of @value{GDBN};
14795 your configuration may have more or fewer targets.
14796
14797 Many remote targets require you to download the executable's code once
14798 you've successfully established a connection. You may wish to control
14799 various aspects of this process.
14800
14801 @table @code
14802
14803 @item set hash
14804 @kindex set hash@r{, for remote monitors}
14805 @cindex hash mark while downloading
14806 This command controls whether a hash mark @samp{#} is displayed while
14807 downloading a file to the remote monitor. If on, a hash mark is
14808 displayed after each S-record is successfully downloaded to the
14809 monitor.
14810
14811 @item show hash
14812 @kindex show hash@r{, for remote monitors}
14813 Show the current status of displaying the hash mark.
14814
14815 @item set debug monitor
14816 @kindex set debug monitor
14817 @cindex display remote monitor communications
14818 Enable or disable display of communications messages between
14819 @value{GDBN} and the remote monitor.
14820
14821 @item show debug monitor
14822 @kindex show debug monitor
14823 Show the current status of displaying communications between
14824 @value{GDBN} and the remote monitor.
14825 @end table
14826
14827 @table @code
14828
14829 @kindex load @var{filename}
14830 @item load @var{filename}
14831 @anchor{load}
14832 Depending on what remote debugging facilities are configured into
14833 @value{GDBN}, the @code{load} command may be available. Where it exists, it
14834 is meant to make @var{filename} (an executable) available for debugging
14835 on the remote system---by downloading, or dynamic linking, for example.
14836 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
14837 the @code{add-symbol-file} command.
14838
14839 If your @value{GDBN} does not have a @code{load} command, attempting to
14840 execute it gets the error message ``@code{You can't do that when your
14841 target is @dots{}}''
14842
14843 The file is loaded at whatever address is specified in the executable.
14844 For some object file formats, you can specify the load address when you
14845 link the program; for other formats, like a.out, the object file format
14846 specifies a fixed address.
14847 @c FIXME! This would be a good place for an xref to the GNU linker doc.
14848
14849 Depending on the remote side capabilities, @value{GDBN} may be able to
14850 load programs into flash memory.
14851
14852 @code{load} does not repeat if you press @key{RET} again after using it.
14853 @end table
14854
14855 @node Byte Order
14856 @section Choosing Target Byte Order
14857
14858 @cindex choosing target byte order
14859 @cindex target byte order
14860
14861 Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
14862 offer the ability to run either big-endian or little-endian byte
14863 orders. Usually the executable or symbol will include a bit to
14864 designate the endian-ness, and you will not need to worry about
14865 which to use. However, you may still find it useful to adjust
14866 @value{GDBN}'s idea of processor endian-ness manually.
14867
14868 @table @code
14869 @kindex set endian
14870 @item set endian big
14871 Instruct @value{GDBN} to assume the target is big-endian.
14872
14873 @item set endian little
14874 Instruct @value{GDBN} to assume the target is little-endian.
14875
14876 @item set endian auto
14877 Instruct @value{GDBN} to use the byte order associated with the
14878 executable.
14879
14880 @item show endian
14881 Display @value{GDBN}'s current idea of the target byte order.
14882
14883 @end table
14884
14885 Note that these commands merely adjust interpretation of symbolic
14886 data on the host, and that they have absolutely no effect on the
14887 target system.
14888
14889
14890 @node Remote Debugging
14891 @chapter Debugging Remote Programs
14892 @cindex remote debugging
14893
14894 If you are trying to debug a program running on a machine that cannot run
14895 @value{GDBN} in the usual way, it is often useful to use remote debugging.
14896 For example, you might use remote debugging on an operating system kernel,
14897 or on a small system which does not have a general purpose operating system
14898 powerful enough to run a full-featured debugger.
14899
14900 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
14901 to make this work with particular debugging targets. In addition,
14902 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
14903 but not specific to any particular target system) which you can use if you
14904 write the remote stubs---the code that runs on the remote system to
14905 communicate with @value{GDBN}.
14906
14907 Other remote targets may be available in your
14908 configuration of @value{GDBN}; use @code{help target} to list them.
14909
14910 @menu
14911 * Connecting:: Connecting to a remote target
14912 * File Transfer:: Sending files to a remote system
14913 * Server:: Using the gdbserver program
14914 * Remote Configuration:: Remote configuration
14915 * Remote Stub:: Implementing a remote stub
14916 @end menu
14917
14918 @node Connecting
14919 @section Connecting to a Remote Target
14920
14921 On the @value{GDBN} host machine, you will need an unstripped copy of
14922 your program, since @value{GDBN} needs symbol and debugging information.
14923 Start up @value{GDBN} as usual, using the name of the local copy of your
14924 program as the first argument.
14925
14926 @cindex @code{target remote}
14927 @value{GDBN} can communicate with the target over a serial line, or
14928 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
14929 each case, @value{GDBN} uses the same protocol for debugging your
14930 program; only the medium carrying the debugging packets varies. The
14931 @code{target remote} command establishes a connection to the target.
14932 Its arguments indicate which medium to use:
14933
14934 @table @code
14935
14936 @item target remote @var{serial-device}
14937 @cindex serial line, @code{target remote}
14938 Use @var{serial-device} to communicate with the target. For example,
14939 to use a serial line connected to the device named @file{/dev/ttyb}:
14940
14941 @smallexample
14942 target remote /dev/ttyb
14943 @end smallexample
14944
14945 If you're using a serial line, you may want to give @value{GDBN} the
14946 @w{@samp{--baud}} option, or use the @code{set remotebaud} command
14947 (@pxref{Remote Configuration, set remotebaud}) before the
14948 @code{target} command.
14949
14950 @item target remote @code{@var{host}:@var{port}}
14951 @itemx target remote @code{tcp:@var{host}:@var{port}}
14952 @cindex @acronym{TCP} port, @code{target remote}
14953 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
14954 The @var{host} may be either a host name or a numeric @acronym{IP}
14955 address; @var{port} must be a decimal number. The @var{host} could be
14956 the target machine itself, if it is directly connected to the net, or
14957 it might be a terminal server which in turn has a serial line to the
14958 target.
14959
14960 For example, to connect to port 2828 on a terminal server named
14961 @code{manyfarms}:
14962
14963 @smallexample
14964 target remote manyfarms:2828
14965 @end smallexample
14966
14967 If your remote target is actually running on the same machine as your
14968 debugger session (e.g.@: a simulator for your target running on the
14969 same host), you can omit the hostname. For example, to connect to
14970 port 1234 on your local machine:
14971
14972 @smallexample
14973 target remote :1234
14974 @end smallexample
14975 @noindent
14976
14977 Note that the colon is still required here.
14978
14979 @item target remote @code{udp:@var{host}:@var{port}}
14980 @cindex @acronym{UDP} port, @code{target remote}
14981 Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
14982 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
14983
14984 @smallexample
14985 target remote udp:manyfarms:2828
14986 @end smallexample
14987
14988 When using a @acronym{UDP} connection for remote debugging, you should
14989 keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
14990 can silently drop packets on busy or unreliable networks, which will
14991 cause havoc with your debugging session.
14992
14993 @item target remote | @var{command}
14994 @cindex pipe, @code{target remote} to
14995 Run @var{command} in the background and communicate with it using a
14996 pipe. The @var{command} is a shell command, to be parsed and expanded
14997 by the system's command shell, @code{/bin/sh}; it should expect remote
14998 protocol packets on its standard input, and send replies on its
14999 standard output. You could use this to run a stand-alone simulator
15000 that speaks the remote debugging protocol, to make net connections
15001 using programs like @code{ssh}, or for other similar tricks.
15002
15003 If @var{command} closes its standard output (perhaps by exiting),
15004 @value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
15005 program has already exited, this will have no effect.)
15006
15007 @end table
15008
15009 Once the connection has been established, you can use all the usual
15010 commands to examine and change data. The remote program is already
15011 running; you can use @kbd{step} and @kbd{continue}, and you do not
15012 need to use @kbd{run}.
15013
15014 @cindex interrupting remote programs
15015 @cindex remote programs, interrupting
15016 Whenever @value{GDBN} is waiting for the remote program, if you type the
15017 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
15018 program. This may or may not succeed, depending in part on the hardware
15019 and the serial drivers the remote system uses. If you type the
15020 interrupt character once again, @value{GDBN} displays this prompt:
15021
15022 @smallexample
15023 Interrupted while waiting for the program.
15024 Give up (and stop debugging it)? (y or n)
15025 @end smallexample
15026
15027 If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
15028 (If you decide you want to try again later, you can use @samp{target
15029 remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
15030 goes back to waiting.
15031
15032 @table @code
15033 @kindex detach (remote)
15034 @item detach
15035 When you have finished debugging the remote program, you can use the
15036 @code{detach} command to release it from @value{GDBN} control.
15037 Detaching from the target normally resumes its execution, but the results
15038 will depend on your particular remote stub. After the @code{detach}
15039 command, @value{GDBN} is free to connect to another target.
15040
15041 @kindex disconnect
15042 @item disconnect
15043 The @code{disconnect} command behaves like @code{detach}, except that
15044 the target is generally not resumed. It will wait for @value{GDBN}
15045 (this instance or another one) to connect and continue debugging. After
15046 the @code{disconnect} command, @value{GDBN} is again free to connect to
15047 another target.
15048
15049 @cindex send command to remote monitor
15050 @cindex extend @value{GDBN} for remote targets
15051 @cindex add new commands for external monitor
15052 @kindex monitor
15053 @item monitor @var{cmd}
15054 This command allows you to send arbitrary commands directly to the
15055 remote monitor. Since @value{GDBN} doesn't care about the commands it
15056 sends like this, this command is the way to extend @value{GDBN}---you
15057 can add new commands that only the external monitor will understand
15058 and implement.
15059 @end table
15060
15061 @node File Transfer
15062 @section Sending files to a remote system
15063 @cindex remote target, file transfer
15064 @cindex file transfer
15065 @cindex sending files to remote systems
15066
15067 Some remote targets offer the ability to transfer files over the same
15068 connection used to communicate with @value{GDBN}. This is convenient
15069 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
15070 running @code{gdbserver} over a network interface. For other targets,
15071 e.g.@: embedded devices with only a single serial port, this may be
15072 the only way to upload or download files.
15073
15074 Not all remote targets support these commands.
15075
15076 @table @code
15077 @kindex remote put
15078 @item remote put @var{hostfile} @var{targetfile}
15079 Copy file @var{hostfile} from the host system (the machine running
15080 @value{GDBN}) to @var{targetfile} on the target system.
15081
15082 @kindex remote get
15083 @item remote get @var{targetfile} @var{hostfile}
15084 Copy file @var{targetfile} from the target system to @var{hostfile}
15085 on the host system.
15086
15087 @kindex remote delete
15088 @item remote delete @var{targetfile}
15089 Delete @var{targetfile} from the target system.
15090
15091 @end table
15092
15093 @node Server
15094 @section Using the @code{gdbserver} Program
15095
15096 @kindex gdbserver
15097 @cindex remote connection without stubs
15098 @code{gdbserver} is a control program for Unix-like systems, which
15099 allows you to connect your program with a remote @value{GDBN} via
15100 @code{target remote}---but without linking in the usual debugging stub.
15101
15102 @code{gdbserver} is not a complete replacement for the debugging stubs,
15103 because it requires essentially the same operating-system facilities
15104 that @value{GDBN} itself does. In fact, a system that can run
15105 @code{gdbserver} to connect to a remote @value{GDBN} could also run
15106 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
15107 because it is a much smaller program than @value{GDBN} itself. It is
15108 also easier to port than all of @value{GDBN}, so you may be able to get
15109 started more quickly on a new system by using @code{gdbserver}.
15110 Finally, if you develop code for real-time systems, you may find that
15111 the tradeoffs involved in real-time operation make it more convenient to
15112 do as much development work as possible on another system, for example
15113 by cross-compiling. You can use @code{gdbserver} to make a similar
15114 choice for debugging.
15115
15116 @value{GDBN} and @code{gdbserver} communicate via either a serial line
15117 or a TCP connection, using the standard @value{GDBN} remote serial
15118 protocol.
15119
15120 @quotation
15121 @emph{Warning:} @code{gdbserver} does not have any built-in security.
15122 Do not run @code{gdbserver} connected to any public network; a
15123 @value{GDBN} connection to @code{gdbserver} provides access to the
15124 target system with the same privileges as the user running
15125 @code{gdbserver}.
15126 @end quotation
15127
15128 @subsection Running @code{gdbserver}
15129 @cindex arguments, to @code{gdbserver}
15130
15131 Run @code{gdbserver} on the target system. You need a copy of the
15132 program you want to debug, including any libraries it requires.
15133 @code{gdbserver} does not need your program's symbol table, so you can
15134 strip the program if necessary to save space. @value{GDBN} on the host
15135 system does all the symbol handling.
15136
15137 To use the server, you must tell it how to communicate with @value{GDBN};
15138 the name of your program; and the arguments for your program. The usual
15139 syntax is:
15140
15141 @smallexample
15142 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
15143 @end smallexample
15144
15145 @var{comm} is either a device name (to use a serial line) or a TCP
15146 hostname and portnumber. For example, to debug Emacs with the argument
15147 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
15148 @file{/dev/com1}:
15149
15150 @smallexample
15151 target> gdbserver /dev/com1 emacs foo.txt
15152 @end smallexample
15153
15154 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
15155 with it.
15156
15157 To use a TCP connection instead of a serial line:
15158
15159 @smallexample
15160 target> gdbserver host:2345 emacs foo.txt
15161 @end smallexample
15162
15163 The only difference from the previous example is the first argument,
15164 specifying that you are communicating with the host @value{GDBN} via
15165 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
15166 expect a TCP connection from machine @samp{host} to local TCP port 2345.
15167 (Currently, the @samp{host} part is ignored.) You can choose any number
15168 you want for the port number as long as it does not conflict with any
15169 TCP ports already in use on the target system (for example, @code{23} is
15170 reserved for @code{telnet}).@footnote{If you choose a port number that
15171 conflicts with another service, @code{gdbserver} prints an error message
15172 and exits.} You must use the same port number with the host @value{GDBN}
15173 @code{target remote} command.
15174
15175 @subsubsection Attaching to a Running Program
15176
15177 On some targets, @code{gdbserver} can also attach to running programs.
15178 This is accomplished via the @code{--attach} argument. The syntax is:
15179
15180 @smallexample
15181 target> gdbserver --attach @var{comm} @var{pid}
15182 @end smallexample
15183
15184 @var{pid} is the process ID of a currently running process. It isn't necessary
15185 to point @code{gdbserver} at a binary for the running process.
15186
15187 @pindex pidof
15188 @cindex attach to a program by name
15189 You can debug processes by name instead of process ID if your target has the
15190 @code{pidof} utility:
15191
15192 @smallexample
15193 target> gdbserver --attach @var{comm} `pidof @var{program}`
15194 @end smallexample
15195
15196 In case more than one copy of @var{program} is running, or @var{program}
15197 has multiple threads, most versions of @code{pidof} support the
15198 @code{-s} option to only return the first process ID.
15199
15200 @subsubsection Multi-Process Mode for @code{gdbserver}
15201 @cindex gdbserver, multiple processes
15202 @cindex multiple processes with gdbserver
15203
15204 When you connect to @code{gdbserver} using @code{target remote},
15205 @code{gdbserver} debugs the specified program only once. When the
15206 program exits, or you detach from it, @value{GDBN} closes the connection
15207 and @code{gdbserver} exits.
15208
15209 If you connect using @kbd{target extended-remote}, @code{gdbserver}
15210 enters multi-process mode. When the debugged program exits, or you
15211 detach from it, @value{GDBN} stays connected to @code{gdbserver} even
15212 though no program is running. The @code{run} and @code{attach}
15213 commands instruct @code{gdbserver} to run or attach to a new program.
15214 The @code{run} command uses @code{set remote exec-file} (@pxref{set
15215 remote exec-file}) to select the program to run. Command line
15216 arguments are supported, except for wildcard expansion and I/O
15217 redirection (@pxref{Arguments}).
15218
15219 To start @code{gdbserver} without supplying an initial command to run
15220 or process ID to attach, use the @option{--multi} command line option.
15221 Then you can connect using @kbd{target extended-remote} and start
15222 the program you want to debug.
15223
15224 @code{gdbserver} does not automatically exit in multi-process mode.
15225 You can terminate it by using @code{monitor exit}
15226 (@pxref{Monitor Commands for gdbserver}).
15227
15228 @subsubsection Other Command-Line Arguments for @code{gdbserver}
15229
15230 The @option{--debug} option tells @code{gdbserver} to display extra
15231 status information about the debugging process. The
15232 @option{--remote-debug} option tells @code{gdbserver} to display
15233 remote protocol debug output. These options are intended for
15234 @code{gdbserver} development and for bug reports to the developers.
15235
15236 The @option{--wrapper} option specifies a wrapper to launch programs
15237 for debugging. The option should be followed by the name of the
15238 wrapper, then any command-line arguments to pass to the wrapper, then
15239 @kbd{--} indicating the end of the wrapper arguments.
15240
15241 @code{gdbserver} runs the specified wrapper program with a combined
15242 command line including the wrapper arguments, then the name of the
15243 program to debug, then any arguments to the program. The wrapper
15244 runs until it executes your program, and then @value{GDBN} gains control.
15245
15246 You can use any program that eventually calls @code{execve} with
15247 its arguments as a wrapper. Several standard Unix utilities do
15248 this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
15249 with @code{exec "$@@"} will also work.
15250
15251 For example, you can use @code{env} to pass an environment variable to
15252 the debugged program, without setting the variable in @code{gdbserver}'s
15253 environment:
15254
15255 @smallexample
15256 $ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
15257 @end smallexample
15258
15259 @subsection Connecting to @code{gdbserver}
15260
15261 Run @value{GDBN} on the host system.
15262
15263 First make sure you have the necessary symbol files. Load symbols for
15264 your application using the @code{file} command before you connect. Use
15265 @code{set sysroot} to locate target libraries (unless your @value{GDBN}
15266 was compiled with the correct sysroot using @code{--with-sysroot}).
15267
15268 The symbol file and target libraries must exactly match the executable
15269 and libraries on the target, with one exception: the files on the host
15270 system should not be stripped, even if the files on the target system
15271 are. Mismatched or missing files will lead to confusing results
15272 during debugging. On @sc{gnu}/Linux targets, mismatched or missing
15273 files may also prevent @code{gdbserver} from debugging multi-threaded
15274 programs.
15275
15276 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
15277 For TCP connections, you must start up @code{gdbserver} prior to using
15278 the @code{target remote} command. Otherwise you may get an error whose
15279 text depends on the host system, but which usually looks something like
15280 @samp{Connection refused}. Don't use the @code{load}
15281 command in @value{GDBN} when using @code{gdbserver}, since the program is
15282 already on the target.
15283
15284 @subsection Monitor Commands for @code{gdbserver}
15285 @cindex monitor commands, for @code{gdbserver}
15286 @anchor{Monitor Commands for gdbserver}
15287
15288 During a @value{GDBN} session using @code{gdbserver}, you can use the
15289 @code{monitor} command to send special requests to @code{gdbserver}.
15290 Here are the available commands.
15291
15292 @table @code
15293 @item monitor help
15294 List the available monitor commands.
15295
15296 @item monitor set debug 0
15297 @itemx monitor set debug 1
15298 Disable or enable general debugging messages.
15299
15300 @item monitor set remote-debug 0
15301 @itemx monitor set remote-debug 1
15302 Disable or enable specific debugging messages associated with the remote
15303 protocol (@pxref{Remote Protocol}).
15304
15305 @item monitor set libthread-db-search-path [PATH]
15306 @cindex gdbserver, search path for @code{libthread_db}
15307 When this command is issued, @var{path} is a colon-separated list of
15308 directories to search for @code{libthread_db} (@pxref{Threads,,set
15309 libthread-db-search-path}). If you omit @var{path},
15310 @samp{libthread-db-search-path} will be reset to an empty list.
15311
15312 @item monitor exit
15313 Tell gdbserver to exit immediately. This command should be followed by
15314 @code{disconnect} to close the debugging session. @code{gdbserver} will
15315 detach from any attached processes and kill any processes it created.
15316 Use @code{monitor exit} to terminate @code{gdbserver} at the end
15317 of a multi-process mode debug session.
15318
15319 @end table
15320
15321 @node Remote Configuration
15322 @section Remote Configuration
15323
15324 @kindex set remote
15325 @kindex show remote
15326 This section documents the configuration options available when
15327 debugging remote programs. For the options related to the File I/O
15328 extensions of the remote protocol, see @ref{system,
15329 system-call-allowed}.
15330
15331 @table @code
15332 @item set remoteaddresssize @var{bits}
15333 @cindex address size for remote targets
15334 @cindex bits in remote address
15335 Set the maximum size of address in a memory packet to the specified
15336 number of bits. @value{GDBN} will mask off the address bits above
15337 that number, when it passes addresses to the remote target. The
15338 default value is the number of bits in the target's address.
15339
15340 @item show remoteaddresssize
15341 Show the current value of remote address size in bits.
15342
15343 @item set remotebaud @var{n}
15344 @cindex baud rate for remote targets
15345 Set the baud rate for the remote serial I/O to @var{n} baud. The
15346 value is used to set the speed of the serial port used for debugging
15347 remote targets.
15348
15349 @item show remotebaud
15350 Show the current speed of the remote connection.
15351
15352 @item set remotebreak
15353 @cindex interrupt remote programs
15354 @cindex BREAK signal instead of Ctrl-C
15355 @anchor{set remotebreak}
15356 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
15357 when you type @kbd{Ctrl-c} to interrupt the program running
15358 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
15359 character instead. The default is off, since most remote systems
15360 expect to see @samp{Ctrl-C} as the interrupt signal.
15361
15362 @item show remotebreak
15363 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
15364 interrupt the remote program.
15365
15366 @item set remoteflow on
15367 @itemx set remoteflow off
15368 @kindex set remoteflow
15369 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
15370 on the serial port used to communicate to the remote target.
15371
15372 @item show remoteflow
15373 @kindex show remoteflow
15374 Show the current setting of hardware flow control.
15375
15376 @item set remotelogbase @var{base}
15377 Set the base (a.k.a.@: radix) of logging serial protocol
15378 communications to @var{base}. Supported values of @var{base} are:
15379 @code{ascii}, @code{octal}, and @code{hex}. The default is
15380 @code{ascii}.
15381
15382 @item show remotelogbase
15383 Show the current setting of the radix for logging remote serial
15384 protocol.
15385
15386 @item set remotelogfile @var{file}
15387 @cindex record serial communications on file
15388 Record remote serial communications on the named @var{file}. The
15389 default is not to record at all.
15390
15391 @item show remotelogfile.
15392 Show the current setting of the file name on which to record the
15393 serial communications.
15394
15395 @item set remotetimeout @var{num}
15396 @cindex timeout for serial communications
15397 @cindex remote timeout
15398 Set the timeout limit to wait for the remote target to respond to
15399 @var{num} seconds. The default is 2 seconds.
15400
15401 @item show remotetimeout
15402 Show the current number of seconds to wait for the remote target
15403 responses.
15404
15405 @cindex limit hardware breakpoints and watchpoints
15406 @cindex remote target, limit break- and watchpoints
15407 @anchor{set remote hardware-watchpoint-limit}
15408 @anchor{set remote hardware-breakpoint-limit}
15409 @item set remote hardware-watchpoint-limit @var{limit}
15410 @itemx set remote hardware-breakpoint-limit @var{limit}
15411 Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
15412 watchpoints. A limit of -1, the default, is treated as unlimited.
15413
15414 @item set remote exec-file @var{filename}
15415 @itemx show remote exec-file
15416 @anchor{set remote exec-file}
15417 @cindex executable file, for remote target
15418 Select the file used for @code{run} with @code{target
15419 extended-remote}. This should be set to a filename valid on the
15420 target system. If it is not set, the target will use a default
15421 filename (e.g.@: the last program run).
15422
15423 @item set remote interrupt-sequence
15424 @cindex interrupt remote programs
15425 @cindex select Ctrl-C, BREAK or BREAK-g
15426 Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
15427 @samp{BREAK-g} as the
15428 sequence to the remote target in order to interrupt the execution.
15429 @samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
15430 is high level of serial line for some certain time.
15431 Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
15432 It is @code{BREAK} signal followed by character @code{g}.
15433
15434 @item show interrupt-sequence
15435 Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
15436 is sent by @value{GDBN} to interrupt the remote program.
15437 @code{BREAK-g} is BREAK signal followed by @code{g} and
15438 also known as Magic SysRq g.
15439
15440 @item set remote interrupt-on-connect
15441 @cindex send interrupt-sequence on start
15442 Specify whether interrupt-sequence is sent to remote target when
15443 @value{GDBN} connects to it. This is mostly needed when you debug
15444 Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
15445 which is known as Magic SysRq g in order to connect @value{GDBN}.
15446
15447 @item show interrupt-on-connect
15448 Show whether interrupt-sequence is sent
15449 to remote target when @value{GDBN} connects to it.
15450
15451 @kindex set tcp
15452 @kindex show tcp
15453 @item set tcp auto-retry on
15454 @cindex auto-retry, for remote TCP target
15455 Enable auto-retry for remote TCP connections. This is useful if the remote
15456 debugging agent is launched in parallel with @value{GDBN}; there is a race
15457 condition because the agent may not become ready to accept the connection
15458 before @value{GDBN} attempts to connect. When auto-retry is
15459 enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
15460 to establish the connection using the timeout specified by
15461 @code{set tcp connect-timeout}.
15462
15463 @item set tcp auto-retry off
15464 Do not auto-retry failed TCP connections.
15465
15466 @item show tcp auto-retry
15467 Show the current auto-retry setting.
15468
15469 @item set tcp connect-timeout @var{seconds}
15470 @cindex connection timeout, for remote TCP target
15471 @cindex timeout, for remote target connection
15472 Set the timeout for establishing a TCP connection to the remote target to
15473 @var{seconds}. The timeout affects both polling to retry failed connections
15474 (enabled by @code{set tcp auto-retry on}) and waiting for connections
15475 that are merely slow to complete, and represents an approximate cumulative
15476 value.
15477
15478 @item show tcp connect-timeout
15479 Show the current connection timeout setting.
15480 @end table
15481
15482 @cindex remote packets, enabling and disabling
15483 The @value{GDBN} remote protocol autodetects the packets supported by
15484 your debugging stub. If you need to override the autodetection, you
15485 can use these commands to enable or disable individual packets. Each
15486 packet can be set to @samp{on} (the remote target supports this
15487 packet), @samp{off} (the remote target does not support this packet),
15488 or @samp{auto} (detect remote target support for this packet). They
15489 all default to @samp{auto}. For more information about each packet,
15490 see @ref{Remote Protocol}.
15491
15492 During normal use, you should not have to use any of these commands.
15493 If you do, that may be a bug in your remote debugging stub, or a bug
15494 in @value{GDBN}. You may want to report the problem to the
15495 @value{GDBN} developers.
15496
15497 For each packet @var{name}, the command to enable or disable the
15498 packet is @code{set remote @var{name}-packet}. The available settings
15499 are:
15500
15501 @multitable @columnfractions 0.28 0.32 0.25
15502 @item Command Name
15503 @tab Remote Packet
15504 @tab Related Features
15505
15506 @item @code{fetch-register}
15507 @tab @code{p}
15508 @tab @code{info registers}
15509
15510 @item @code{set-register}
15511 @tab @code{P}
15512 @tab @code{set}
15513
15514 @item @code{binary-download}
15515 @tab @code{X}
15516 @tab @code{load}, @code{set}
15517
15518 @item @code{read-aux-vector}
15519 @tab @code{qXfer:auxv:read}
15520 @tab @code{info auxv}
15521
15522 @item @code{symbol-lookup}
15523 @tab @code{qSymbol}
15524 @tab Detecting multiple threads
15525
15526 @item @code{attach}
15527 @tab @code{vAttach}
15528 @tab @code{attach}
15529
15530 @item @code{verbose-resume}
15531 @tab @code{vCont}
15532 @tab Stepping or resuming multiple threads
15533
15534 @item @code{run}
15535 @tab @code{vRun}
15536 @tab @code{run}
15537
15538 @item @code{software-breakpoint}
15539 @tab @code{Z0}
15540 @tab @code{break}
15541
15542 @item @code{hardware-breakpoint}
15543 @tab @code{Z1}
15544 @tab @code{hbreak}
15545
15546 @item @code{write-watchpoint}
15547 @tab @code{Z2}
15548 @tab @code{watch}
15549
15550 @item @code{read-watchpoint}
15551 @tab @code{Z3}
15552 @tab @code{rwatch}
15553
15554 @item @code{access-watchpoint}
15555 @tab @code{Z4}
15556 @tab @code{awatch}
15557
15558 @item @code{target-features}
15559 @tab @code{qXfer:features:read}
15560 @tab @code{set architecture}
15561
15562 @item @code{library-info}
15563 @tab @code{qXfer:libraries:read}
15564 @tab @code{info sharedlibrary}
15565
15566 @item @code{memory-map}
15567 @tab @code{qXfer:memory-map:read}
15568 @tab @code{info mem}
15569
15570 @item @code{read-spu-object}
15571 @tab @code{qXfer:spu:read}
15572 @tab @code{info spu}
15573
15574 @item @code{write-spu-object}
15575 @tab @code{qXfer:spu:write}
15576 @tab @code{info spu}
15577
15578 @item @code{read-siginfo-object}
15579 @tab @code{qXfer:siginfo:read}
15580 @tab @code{print $_siginfo}
15581
15582 @item @code{write-siginfo-object}
15583 @tab @code{qXfer:siginfo:write}
15584 @tab @code{set $_siginfo}
15585
15586 @item @code{threads}
15587 @tab @code{qXfer:threads:read}
15588 @tab @code{info threads}
15589
15590 @item @code{get-thread-local-@*storage-address}
15591 @tab @code{qGetTLSAddr}
15592 @tab Displaying @code{__thread} variables
15593
15594 @item @code{search-memory}
15595 @tab @code{qSearch:memory}
15596 @tab @code{find}
15597
15598 @item @code{supported-packets}
15599 @tab @code{qSupported}
15600 @tab Remote communications parameters
15601
15602 @item @code{pass-signals}
15603 @tab @code{QPassSignals}
15604 @tab @code{handle @var{signal}}
15605
15606 @item @code{hostio-close-packet}
15607 @tab @code{vFile:close}
15608 @tab @code{remote get}, @code{remote put}
15609
15610 @item @code{hostio-open-packet}
15611 @tab @code{vFile:open}
15612 @tab @code{remote get}, @code{remote put}
15613
15614 @item @code{hostio-pread-packet}
15615 @tab @code{vFile:pread}
15616 @tab @code{remote get}, @code{remote put}
15617
15618 @item @code{hostio-pwrite-packet}
15619 @tab @code{vFile:pwrite}
15620 @tab @code{remote get}, @code{remote put}
15621
15622 @item @code{hostio-unlink-packet}
15623 @tab @code{vFile:unlink}
15624 @tab @code{remote delete}
15625
15626 @item @code{noack-packet}
15627 @tab @code{QStartNoAckMode}
15628 @tab Packet acknowledgment
15629
15630 @item @code{osdata}
15631 @tab @code{qXfer:osdata:read}
15632 @tab @code{info os}
15633
15634 @item @code{query-attached}
15635 @tab @code{qAttached}
15636 @tab Querying remote process attach state.
15637 @end multitable
15638
15639 @node Remote Stub
15640 @section Implementing a Remote Stub
15641
15642 @cindex debugging stub, example
15643 @cindex remote stub, example
15644 @cindex stub example, remote debugging
15645 The stub files provided with @value{GDBN} implement the target side of the
15646 communication protocol, and the @value{GDBN} side is implemented in the
15647 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
15648 these subroutines to communicate, and ignore the details. (If you're
15649 implementing your own stub file, you can still ignore the details: start
15650 with one of the existing stub files. @file{sparc-stub.c} is the best
15651 organized, and therefore the easiest to read.)
15652
15653 @cindex remote serial debugging, overview
15654 To debug a program running on another machine (the debugging
15655 @dfn{target} machine), you must first arrange for all the usual
15656 prerequisites for the program to run by itself. For example, for a C
15657 program, you need:
15658
15659 @enumerate
15660 @item
15661 A startup routine to set up the C runtime environment; these usually
15662 have a name like @file{crt0}. The startup routine may be supplied by
15663 your hardware supplier, or you may have to write your own.
15664
15665 @item
15666 A C subroutine library to support your program's
15667 subroutine calls, notably managing input and output.
15668
15669 @item
15670 A way of getting your program to the other machine---for example, a
15671 download program. These are often supplied by the hardware
15672 manufacturer, but you may have to write your own from hardware
15673 documentation.
15674 @end enumerate
15675
15676 The next step is to arrange for your program to use a serial port to
15677 communicate with the machine where @value{GDBN} is running (the @dfn{host}
15678 machine). In general terms, the scheme looks like this:
15679
15680 @table @emph
15681 @item On the host,
15682 @value{GDBN} already understands how to use this protocol; when everything
15683 else is set up, you can simply use the @samp{target remote} command
15684 (@pxref{Targets,,Specifying a Debugging Target}).
15685
15686 @item On the target,
15687 you must link with your program a few special-purpose subroutines that
15688 implement the @value{GDBN} remote serial protocol. The file containing these
15689 subroutines is called a @dfn{debugging stub}.
15690
15691 On certain remote targets, you can use an auxiliary program
15692 @code{gdbserver} instead of linking a stub into your program.
15693 @xref{Server,,Using the @code{gdbserver} Program}, for details.
15694 @end table
15695
15696 The debugging stub is specific to the architecture of the remote
15697 machine; for example, use @file{sparc-stub.c} to debug programs on
15698 @sc{sparc} boards.
15699
15700 @cindex remote serial stub list
15701 These working remote stubs are distributed with @value{GDBN}:
15702
15703 @table @code
15704
15705 @item i386-stub.c
15706 @cindex @file{i386-stub.c}
15707 @cindex Intel
15708 @cindex i386
15709 For Intel 386 and compatible architectures.
15710
15711 @item m68k-stub.c
15712 @cindex @file{m68k-stub.c}
15713 @cindex Motorola 680x0
15714 @cindex m680x0
15715 For Motorola 680x0 architectures.
15716
15717 @item sh-stub.c
15718 @cindex @file{sh-stub.c}
15719 @cindex Renesas
15720 @cindex SH
15721 For Renesas SH architectures.
15722
15723 @item sparc-stub.c
15724 @cindex @file{sparc-stub.c}
15725 @cindex Sparc
15726 For @sc{sparc} architectures.
15727
15728 @item sparcl-stub.c
15729 @cindex @file{sparcl-stub.c}
15730 @cindex Fujitsu
15731 @cindex SparcLite
15732 For Fujitsu @sc{sparclite} architectures.
15733
15734 @end table
15735
15736 The @file{README} file in the @value{GDBN} distribution may list other
15737 recently added stubs.
15738
15739 @menu
15740 * Stub Contents:: What the stub can do for you
15741 * Bootstrapping:: What you must do for the stub
15742 * Debug Session:: Putting it all together
15743 @end menu
15744
15745 @node Stub Contents
15746 @subsection What the Stub Can Do for You
15747
15748 @cindex remote serial stub
15749 The debugging stub for your architecture supplies these three
15750 subroutines:
15751
15752 @table @code
15753 @item set_debug_traps
15754 @findex set_debug_traps
15755 @cindex remote serial stub, initialization
15756 This routine arranges for @code{handle_exception} to run when your
15757 program stops. You must call this subroutine explicitly near the
15758 beginning of your program.
15759
15760 @item handle_exception
15761 @findex handle_exception
15762 @cindex remote serial stub, main routine
15763 This is the central workhorse, but your program never calls it
15764 explicitly---the setup code arranges for @code{handle_exception} to
15765 run when a trap is triggered.
15766
15767 @code{handle_exception} takes control when your program stops during
15768 execution (for example, on a breakpoint), and mediates communications
15769 with @value{GDBN} on the host machine. This is where the communications
15770 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
15771 representative on the target machine. It begins by sending summary
15772 information on the state of your program, then continues to execute,
15773 retrieving and transmitting any information @value{GDBN} needs, until you
15774 execute a @value{GDBN} command that makes your program resume; at that point,
15775 @code{handle_exception} returns control to your own code on the target
15776 machine.
15777
15778 @item breakpoint
15779 @cindex @code{breakpoint} subroutine, remote
15780 Use this auxiliary subroutine to make your program contain a
15781 breakpoint. Depending on the particular situation, this may be the only
15782 way for @value{GDBN} to get control. For instance, if your target
15783 machine has some sort of interrupt button, you won't need to call this;
15784 pressing the interrupt button transfers control to
15785 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
15786 simply receiving characters on the serial port may also trigger a trap;
15787 again, in that situation, you don't need to call @code{breakpoint} from
15788 your own program---simply running @samp{target remote} from the host
15789 @value{GDBN} session gets control.
15790
15791 Call @code{breakpoint} if none of these is true, or if you simply want
15792 to make certain your program stops at a predetermined point for the
15793 start of your debugging session.
15794 @end table
15795
15796 @node Bootstrapping
15797 @subsection What You Must Do for the Stub
15798
15799 @cindex remote stub, support routines
15800 The debugging stubs that come with @value{GDBN} are set up for a particular
15801 chip architecture, but they have no information about the rest of your
15802 debugging target machine.
15803
15804 First of all you need to tell the stub how to communicate with the
15805 serial port.
15806
15807 @table @code
15808 @item int getDebugChar()
15809 @findex getDebugChar
15810 Write this subroutine to read a single character from the serial port.
15811 It may be identical to @code{getchar} for your target system; a
15812 different name is used to allow you to distinguish the two if you wish.
15813
15814 @item void putDebugChar(int)
15815 @findex putDebugChar
15816 Write this subroutine to write a single character to the serial port.
15817 It may be identical to @code{putchar} for your target system; a
15818 different name is used to allow you to distinguish the two if you wish.
15819 @end table
15820
15821 @cindex control C, and remote debugging
15822 @cindex interrupting remote targets
15823 If you want @value{GDBN} to be able to stop your program while it is
15824 running, you need to use an interrupt-driven serial driver, and arrange
15825 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
15826 character). That is the character which @value{GDBN} uses to tell the
15827 remote system to stop.
15828
15829 Getting the debugging target to return the proper status to @value{GDBN}
15830 probably requires changes to the standard stub; one quick and dirty way
15831 is to just execute a breakpoint instruction (the ``dirty'' part is that
15832 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
15833
15834 Other routines you need to supply are:
15835
15836 @table @code
15837 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
15838 @findex exceptionHandler
15839 Write this function to install @var{exception_address} in the exception
15840 handling tables. You need to do this because the stub does not have any
15841 way of knowing what the exception handling tables on your target system
15842 are like (for example, the processor's table might be in @sc{rom},
15843 containing entries which point to a table in @sc{ram}).
15844 @var{exception_number} is the exception number which should be changed;
15845 its meaning is architecture-dependent (for example, different numbers
15846 might represent divide by zero, misaligned access, etc). When this
15847 exception occurs, control should be transferred directly to
15848 @var{exception_address}, and the processor state (stack, registers,
15849 and so on) should be just as it is when a processor exception occurs. So if
15850 you want to use a jump instruction to reach @var{exception_address}, it
15851 should be a simple jump, not a jump to subroutine.
15852
15853 For the 386, @var{exception_address} should be installed as an interrupt
15854 gate so that interrupts are masked while the handler runs. The gate
15855 should be at privilege level 0 (the most privileged level). The
15856 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
15857 help from @code{exceptionHandler}.
15858
15859 @item void flush_i_cache()
15860 @findex flush_i_cache
15861 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
15862 instruction cache, if any, on your target machine. If there is no
15863 instruction cache, this subroutine may be a no-op.
15864
15865 On target machines that have instruction caches, @value{GDBN} requires this
15866 function to make certain that the state of your program is stable.
15867 @end table
15868
15869 @noindent
15870 You must also make sure this library routine is available:
15871
15872 @table @code
15873 @item void *memset(void *, int, int)
15874 @findex memset
15875 This is the standard library function @code{memset} that sets an area of
15876 memory to a known value. If you have one of the free versions of
15877 @code{libc.a}, @code{memset} can be found there; otherwise, you must
15878 either obtain it from your hardware manufacturer, or write your own.
15879 @end table
15880
15881 If you do not use the GNU C compiler, you may need other standard
15882 library subroutines as well; this varies from one stub to another,
15883 but in general the stubs are likely to use any of the common library
15884 subroutines which @code{@value{NGCC}} generates as inline code.
15885
15886
15887 @node Debug Session
15888 @subsection Putting it All Together
15889
15890 @cindex remote serial debugging summary
15891 In summary, when your program is ready to debug, you must follow these
15892 steps.
15893
15894 @enumerate
15895 @item
15896 Make sure you have defined the supporting low-level routines
15897 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
15898 @display
15899 @code{getDebugChar}, @code{putDebugChar},
15900 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
15901 @end display
15902
15903 @item
15904 Insert these lines near the top of your program:
15905
15906 @smallexample
15907 set_debug_traps();
15908 breakpoint();
15909 @end smallexample
15910
15911 @item
15912 For the 680x0 stub only, you need to provide a variable called
15913 @code{exceptionHook}. Normally you just use:
15914
15915 @smallexample
15916 void (*exceptionHook)() = 0;
15917 @end smallexample
15918
15919 @noindent
15920 but if before calling @code{set_debug_traps}, you set it to point to a
15921 function in your program, that function is called when
15922 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
15923 error). The function indicated by @code{exceptionHook} is called with
15924 one parameter: an @code{int} which is the exception number.
15925
15926 @item
15927 Compile and link together: your program, the @value{GDBN} debugging stub for
15928 your target architecture, and the supporting subroutines.
15929
15930 @item
15931 Make sure you have a serial connection between your target machine and
15932 the @value{GDBN} host, and identify the serial port on the host.
15933
15934 @item
15935 @c The "remote" target now provides a `load' command, so we should
15936 @c document that. FIXME.
15937 Download your program to your target machine (or get it there by
15938 whatever means the manufacturer provides), and start it.
15939
15940 @item
15941 Start @value{GDBN} on the host, and connect to the target
15942 (@pxref{Connecting,,Connecting to a Remote Target}).
15943
15944 @end enumerate
15945
15946 @node Configurations
15947 @chapter Configuration-Specific Information
15948
15949 While nearly all @value{GDBN} commands are available for all native and
15950 cross versions of the debugger, there are some exceptions. This chapter
15951 describes things that are only available in certain configurations.
15952
15953 There are three major categories of configurations: native
15954 configurations, where the host and target are the same, embedded
15955 operating system configurations, which are usually the same for several
15956 different processor architectures, and bare embedded processors, which
15957 are quite different from each other.
15958
15959 @menu
15960 * Native::
15961 * Embedded OS::
15962 * Embedded Processors::
15963 * Architectures::
15964 @end menu
15965
15966 @node Native
15967 @section Native
15968
15969 This section describes details specific to particular native
15970 configurations.
15971
15972 @menu
15973 * HP-UX:: HP-UX
15974 * BSD libkvm Interface:: Debugging BSD kernel memory images
15975 * SVR4 Process Information:: SVR4 process information
15976 * DJGPP Native:: Features specific to the DJGPP port
15977 * Cygwin Native:: Features specific to the Cygwin port
15978 * Hurd Native:: Features specific to @sc{gnu} Hurd
15979 * Neutrino:: Features specific to QNX Neutrino
15980 * Darwin:: Features specific to Darwin
15981 @end menu
15982
15983 @node HP-UX
15984 @subsection HP-UX
15985
15986 On HP-UX systems, if you refer to a function or variable name that
15987 begins with a dollar sign, @value{GDBN} searches for a user or system
15988 name first, before it searches for a convenience variable.
15989
15990
15991 @node BSD libkvm Interface
15992 @subsection BSD libkvm Interface
15993
15994 @cindex libkvm
15995 @cindex kernel memory image
15996 @cindex kernel crash dump
15997
15998 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
15999 interface that provides a uniform interface for accessing kernel virtual
16000 memory images, including live systems and crash dumps. @value{GDBN}
16001 uses this interface to allow you to debug live kernels and kernel crash
16002 dumps on many native BSD configurations. This is implemented as a
16003 special @code{kvm} debugging target. For debugging a live system, load
16004 the currently running kernel into @value{GDBN} and connect to the
16005 @code{kvm} target:
16006
16007 @smallexample
16008 (@value{GDBP}) @b{target kvm}
16009 @end smallexample
16010
16011 For debugging crash dumps, provide the file name of the crash dump as an
16012 argument:
16013
16014 @smallexample
16015 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
16016 @end smallexample
16017
16018 Once connected to the @code{kvm} target, the following commands are
16019 available:
16020
16021 @table @code
16022 @kindex kvm
16023 @item kvm pcb
16024 Set current context from the @dfn{Process Control Block} (PCB) address.
16025
16026 @item kvm proc
16027 Set current context from proc address. This command isn't available on
16028 modern FreeBSD systems.
16029 @end table
16030
16031 @node SVR4 Process Information
16032 @subsection SVR4 Process Information
16033 @cindex /proc
16034 @cindex examine process image
16035 @cindex process info via @file{/proc}
16036
16037 Many versions of SVR4 and compatible systems provide a facility called
16038 @samp{/proc} that can be used to examine the image of a running
16039 process using file-system subroutines. If @value{GDBN} is configured
16040 for an operating system with this facility, the command @code{info
16041 proc} is available to report information about the process running
16042 your program, or about any process running on your system. @code{info
16043 proc} works only on SVR4 systems that include the @code{procfs} code.
16044 This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
16045 Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
16046
16047 @table @code
16048 @kindex info proc
16049 @cindex process ID
16050 @item info proc
16051 @itemx info proc @var{process-id}
16052 Summarize available information about any running process. If a
16053 process ID is specified by @var{process-id}, display information about
16054 that process; otherwise display information about the program being
16055 debugged. The summary includes the debugged process ID, the command
16056 line used to invoke it, its current working directory, and its
16057 executable file's absolute file name.
16058
16059 On some systems, @var{process-id} can be of the form
16060 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
16061 within a process. If the optional @var{pid} part is missing, it means
16062 a thread from the process being debugged (the leading @samp{/} still
16063 needs to be present, or else @value{GDBN} will interpret the number as
16064 a process ID rather than a thread ID).
16065
16066 @item info proc mappings
16067 @cindex memory address space mappings
16068 Report the memory address space ranges accessible in the program, with
16069 information on whether the process has read, write, or execute access
16070 rights to each range. On @sc{gnu}/Linux systems, each memory range
16071 includes the object file which is mapped to that range, instead of the
16072 memory access rights to that range.
16073
16074 @item info proc stat
16075 @itemx info proc status
16076 @cindex process detailed status information
16077 These subcommands are specific to @sc{gnu}/Linux systems. They show
16078 the process-related information, including the user ID and group ID;
16079 how many threads are there in the process; its virtual memory usage;
16080 the signals that are pending, blocked, and ignored; its TTY; its
16081 consumption of system and user time; its stack size; its @samp{nice}
16082 value; etc. For more information, see the @samp{proc} man page
16083 (type @kbd{man 5 proc} from your shell prompt).
16084
16085 @item info proc all
16086 Show all the information about the process described under all of the
16087 above @code{info proc} subcommands.
16088
16089 @ignore
16090 @comment These sub-options of 'info proc' were not included when
16091 @comment procfs.c was re-written. Keep their descriptions around
16092 @comment against the day when someone finds the time to put them back in.
16093 @kindex info proc times
16094 @item info proc times
16095 Starting time, user CPU time, and system CPU time for your program and
16096 its children.
16097
16098 @kindex info proc id
16099 @item info proc id
16100 Report on the process IDs related to your program: its own process ID,
16101 the ID of its parent, the process group ID, and the session ID.
16102 @end ignore
16103
16104 @item set procfs-trace
16105 @kindex set procfs-trace
16106 @cindex @code{procfs} API calls
16107 This command enables and disables tracing of @code{procfs} API calls.
16108
16109 @item show procfs-trace
16110 @kindex show procfs-trace
16111 Show the current state of @code{procfs} API call tracing.
16112
16113 @item set procfs-file @var{file}
16114 @kindex set procfs-file
16115 Tell @value{GDBN} to write @code{procfs} API trace to the named
16116 @var{file}. @value{GDBN} appends the trace info to the previous
16117 contents of the file. The default is to display the trace on the
16118 standard output.
16119
16120 @item show procfs-file
16121 @kindex show procfs-file
16122 Show the file to which @code{procfs} API trace is written.
16123
16124 @item proc-trace-entry
16125 @itemx proc-trace-exit
16126 @itemx proc-untrace-entry
16127 @itemx proc-untrace-exit
16128 @kindex proc-trace-entry
16129 @kindex proc-trace-exit
16130 @kindex proc-untrace-entry
16131 @kindex proc-untrace-exit
16132 These commands enable and disable tracing of entries into and exits
16133 from the @code{syscall} interface.
16134
16135 @item info pidlist
16136 @kindex info pidlist
16137 @cindex process list, QNX Neutrino
16138 For QNX Neutrino only, this command displays the list of all the
16139 processes and all the threads within each process.
16140
16141 @item info meminfo
16142 @kindex info meminfo
16143 @cindex mapinfo list, QNX Neutrino
16144 For QNX Neutrino only, this command displays the list of all mapinfos.
16145 @end table
16146
16147 @node DJGPP Native
16148 @subsection Features for Debugging @sc{djgpp} Programs
16149 @cindex @sc{djgpp} debugging
16150 @cindex native @sc{djgpp} debugging
16151 @cindex MS-DOS-specific commands
16152
16153 @cindex DPMI
16154 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
16155 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
16156 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
16157 top of real-mode DOS systems and their emulations.
16158
16159 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
16160 defines a few commands specific to the @sc{djgpp} port. This
16161 subsection describes those commands.
16162
16163 @table @code
16164 @kindex info dos
16165 @item info dos
16166 This is a prefix of @sc{djgpp}-specific commands which print
16167 information about the target system and important OS structures.
16168
16169 @kindex sysinfo
16170 @cindex MS-DOS system info
16171 @cindex free memory information (MS-DOS)
16172 @item info dos sysinfo
16173 This command displays assorted information about the underlying
16174 platform: the CPU type and features, the OS version and flavor, the
16175 DPMI version, and the available conventional and DPMI memory.
16176
16177 @cindex GDT
16178 @cindex LDT
16179 @cindex IDT
16180 @cindex segment descriptor tables
16181 @cindex descriptor tables display
16182 @item info dos gdt
16183 @itemx info dos ldt
16184 @itemx info dos idt
16185 These 3 commands display entries from, respectively, Global, Local,
16186 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
16187 tables are data structures which store a descriptor for each segment
16188 that is currently in use. The segment's selector is an index into a
16189 descriptor table; the table entry for that index holds the
16190 descriptor's base address and limit, and its attributes and access
16191 rights.
16192
16193 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
16194 segment (used for both data and the stack), and a DOS segment (which
16195 allows access to DOS/BIOS data structures and absolute addresses in
16196 conventional memory). However, the DPMI host will usually define
16197 additional segments in order to support the DPMI environment.
16198
16199 @cindex garbled pointers
16200 These commands allow to display entries from the descriptor tables.
16201 Without an argument, all entries from the specified table are
16202 displayed. An argument, which should be an integer expression, means
16203 display a single entry whose index is given by the argument. For
16204 example, here's a convenient way to display information about the
16205 debugged program's data segment:
16206
16207 @smallexample
16208 @exdent @code{(@value{GDBP}) info dos ldt $ds}
16209 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
16210 @end smallexample
16211
16212 @noindent
16213 This comes in handy when you want to see whether a pointer is outside
16214 the data segment's limit (i.e.@: @dfn{garbled}).
16215
16216 @cindex page tables display (MS-DOS)
16217 @item info dos pde
16218 @itemx info dos pte
16219 These two commands display entries from, respectively, the Page
16220 Directory and the Page Tables. Page Directories and Page Tables are
16221 data structures which control how virtual memory addresses are mapped
16222 into physical addresses. A Page Table includes an entry for every
16223 page of memory that is mapped into the program's address space; there
16224 may be several Page Tables, each one holding up to 4096 entries. A
16225 Page Directory has up to 4096 entries, one each for every Page Table
16226 that is currently in use.
16227
16228 Without an argument, @kbd{info dos pde} displays the entire Page
16229 Directory, and @kbd{info dos pte} displays all the entries in all of
16230 the Page Tables. An argument, an integer expression, given to the
16231 @kbd{info dos pde} command means display only that entry from the Page
16232 Directory table. An argument given to the @kbd{info dos pte} command
16233 means display entries from a single Page Table, the one pointed to by
16234 the specified entry in the Page Directory.
16235
16236 @cindex direct memory access (DMA) on MS-DOS
16237 These commands are useful when your program uses @dfn{DMA} (Direct
16238 Memory Access), which needs physical addresses to program the DMA
16239 controller.
16240
16241 These commands are supported only with some DPMI servers.
16242
16243 @cindex physical address from linear address
16244 @item info dos address-pte @var{addr}
16245 This command displays the Page Table entry for a specified linear
16246 address. The argument @var{addr} is a linear address which should
16247 already have the appropriate segment's base address added to it,
16248 because this command accepts addresses which may belong to @emph{any}
16249 segment. For example, here's how to display the Page Table entry for
16250 the page where a variable @code{i} is stored:
16251
16252 @smallexample
16253 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
16254 @exdent @code{Page Table entry for address 0x11a00d30:}
16255 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
16256 @end smallexample
16257
16258 @noindent
16259 This says that @code{i} is stored at offset @code{0xd30} from the page
16260 whose physical base address is @code{0x02698000}, and shows all the
16261 attributes of that page.
16262
16263 Note that you must cast the addresses of variables to a @code{char *},
16264 since otherwise the value of @code{__djgpp_base_address}, the base
16265 address of all variables and functions in a @sc{djgpp} program, will
16266 be added using the rules of C pointer arithmetics: if @code{i} is
16267 declared an @code{int}, @value{GDBN} will add 4 times the value of
16268 @code{__djgpp_base_address} to the address of @code{i}.
16269
16270 Here's another example, it displays the Page Table entry for the
16271 transfer buffer:
16272
16273 @smallexample
16274 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
16275 @exdent @code{Page Table entry for address 0x29110:}
16276 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
16277 @end smallexample
16278
16279 @noindent
16280 (The @code{+ 3} offset is because the transfer buffer's address is the
16281 3rd member of the @code{_go32_info_block} structure.) The output
16282 clearly shows that this DPMI server maps the addresses in conventional
16283 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
16284 linear (@code{0x29110}) addresses are identical.
16285
16286 This command is supported only with some DPMI servers.
16287 @end table
16288
16289 @cindex DOS serial data link, remote debugging
16290 In addition to native debugging, the DJGPP port supports remote
16291 debugging via a serial data link. The following commands are specific
16292 to remote serial debugging in the DJGPP port of @value{GDBN}.
16293
16294 @table @code
16295 @kindex set com1base
16296 @kindex set com1irq
16297 @kindex set com2base
16298 @kindex set com2irq
16299 @kindex set com3base
16300 @kindex set com3irq
16301 @kindex set com4base
16302 @kindex set com4irq
16303 @item set com1base @var{addr}
16304 This command sets the base I/O port address of the @file{COM1} serial
16305 port.
16306
16307 @item set com1irq @var{irq}
16308 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
16309 for the @file{COM1} serial port.
16310
16311 There are similar commands @samp{set com2base}, @samp{set com3irq},
16312 etc.@: for setting the port address and the @code{IRQ} lines for the
16313 other 3 COM ports.
16314
16315 @kindex show com1base
16316 @kindex show com1irq
16317 @kindex show com2base
16318 @kindex show com2irq
16319 @kindex show com3base
16320 @kindex show com3irq
16321 @kindex show com4base
16322 @kindex show com4irq
16323 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
16324 display the current settings of the base address and the @code{IRQ}
16325 lines used by the COM ports.
16326
16327 @item info serial
16328 @kindex info serial
16329 @cindex DOS serial port status
16330 This command prints the status of the 4 DOS serial ports. For each
16331 port, it prints whether it's active or not, its I/O base address and
16332 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
16333 counts of various errors encountered so far.
16334 @end table
16335
16336
16337 @node Cygwin Native
16338 @subsection Features for Debugging MS Windows PE Executables
16339 @cindex MS Windows debugging
16340 @cindex native Cygwin debugging
16341 @cindex Cygwin-specific commands
16342
16343 @value{GDBN} supports native debugging of MS Windows programs, including
16344 DLLs with and without symbolic debugging information.
16345
16346 @cindex Ctrl-BREAK, MS-Windows
16347 @cindex interrupt debuggee on MS-Windows
16348 MS-Windows programs that call @code{SetConsoleMode} to switch off the
16349 special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
16350 by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
16351 supports @kbd{C-@key{BREAK}} as an alternative interrupt key
16352 sequence, which can be used to interrupt the debuggee even if it
16353 ignores @kbd{C-c}.
16354
16355 There are various additional Cygwin-specific commands, described in
16356 this section. Working with DLLs that have no debugging symbols is
16357 described in @ref{Non-debug DLL Symbols}.
16358
16359 @table @code
16360 @kindex info w32
16361 @item info w32
16362 This is a prefix of MS Windows-specific commands which print
16363 information about the target system and important OS structures.
16364
16365 @item info w32 selector
16366 This command displays information returned by
16367 the Win32 API @code{GetThreadSelectorEntry} function.
16368 It takes an optional argument that is evaluated to
16369 a long value to give the information about this given selector.
16370 Without argument, this command displays information
16371 about the six segment registers.
16372
16373 @kindex info dll
16374 @item info dll
16375 This is a Cygwin-specific alias of @code{info shared}.
16376
16377 @kindex dll-symbols
16378 @item dll-symbols
16379 This command loads symbols from a dll similarly to
16380 add-sym command but without the need to specify a base address.
16381
16382 @kindex set cygwin-exceptions
16383 @cindex debugging the Cygwin DLL
16384 @cindex Cygwin DLL, debugging
16385 @item set cygwin-exceptions @var{mode}
16386 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
16387 happen inside the Cygwin DLL. If @var{mode} is @code{off},
16388 @value{GDBN} will delay recognition of exceptions, and may ignore some
16389 exceptions which seem to be caused by internal Cygwin DLL
16390 ``bookkeeping''. This option is meant primarily for debugging the
16391 Cygwin DLL itself; the default value is @code{off} to avoid annoying
16392 @value{GDBN} users with false @code{SIGSEGV} signals.
16393
16394 @kindex show cygwin-exceptions
16395 @item show cygwin-exceptions
16396 Displays whether @value{GDBN} will break on exceptions that happen
16397 inside the Cygwin DLL itself.
16398
16399 @kindex set new-console
16400 @item set new-console @var{mode}
16401 If @var{mode} is @code{on} the debuggee will
16402 be started in a new console on next start.
16403 If @var{mode} is @code{off}i, the debuggee will
16404 be started in the same console as the debugger.
16405
16406 @kindex show new-console
16407 @item show new-console
16408 Displays whether a new console is used
16409 when the debuggee is started.
16410
16411 @kindex set new-group
16412 @item set new-group @var{mode}
16413 This boolean value controls whether the debuggee should
16414 start a new group or stay in the same group as the debugger.
16415 This affects the way the Windows OS handles
16416 @samp{Ctrl-C}.
16417
16418 @kindex show new-group
16419 @item show new-group
16420 Displays current value of new-group boolean.
16421
16422 @kindex set debugevents
16423 @item set debugevents
16424 This boolean value adds debug output concerning kernel events related
16425 to the debuggee seen by the debugger. This includes events that
16426 signal thread and process creation and exit, DLL loading and
16427 unloading, console interrupts, and debugging messages produced by the
16428 Windows @code{OutputDebugString} API call.
16429
16430 @kindex set debugexec
16431 @item set debugexec
16432 This boolean value adds debug output concerning execute events
16433 (such as resume thread) seen by the debugger.
16434
16435 @kindex set debugexceptions
16436 @item set debugexceptions
16437 This boolean value adds debug output concerning exceptions in the
16438 debuggee seen by the debugger.
16439
16440 @kindex set debugmemory
16441 @item set debugmemory
16442 This boolean value adds debug output concerning debuggee memory reads
16443 and writes by the debugger.
16444
16445 @kindex set shell
16446 @item set shell
16447 This boolean values specifies whether the debuggee is called
16448 via a shell or directly (default value is on).
16449
16450 @kindex show shell
16451 @item show shell
16452 Displays if the debuggee will be started with a shell.
16453
16454 @end table
16455
16456 @menu
16457 * Non-debug DLL Symbols:: Support for DLLs without debugging symbols
16458 @end menu
16459
16460 @node Non-debug DLL Symbols
16461 @subsubsection Support for DLLs without Debugging Symbols
16462 @cindex DLLs with no debugging symbols
16463 @cindex Minimal symbols and DLLs
16464
16465 Very often on windows, some of the DLLs that your program relies on do
16466 not include symbolic debugging information (for example,
16467 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
16468 symbols in a DLL, it relies on the minimal amount of symbolic
16469 information contained in the DLL's export table. This section
16470 describes working with such symbols, known internally to @value{GDBN} as
16471 ``minimal symbols''.
16472
16473 Note that before the debugged program has started execution, no DLLs
16474 will have been loaded. The easiest way around this problem is simply to
16475 start the program --- either by setting a breakpoint or letting the
16476 program run once to completion. It is also possible to force
16477 @value{GDBN} to load a particular DLL before starting the executable ---
16478 see the shared library information in @ref{Files}, or the
16479 @code{dll-symbols} command in @ref{Cygwin Native}. Currently,
16480 explicitly loading symbols from a DLL with no debugging information will
16481 cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
16482 which may adversely affect symbol lookup performance.
16483
16484 @subsubsection DLL Name Prefixes
16485
16486 In keeping with the naming conventions used by the Microsoft debugging
16487 tools, DLL export symbols are made available with a prefix based on the
16488 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
16489 also entered into the symbol table, so @code{CreateFileA} is often
16490 sufficient. In some cases there will be name clashes within a program
16491 (particularly if the executable itself includes full debugging symbols)
16492 necessitating the use of the fully qualified name when referring to the
16493 contents of the DLL. Use single-quotes around the name to avoid the
16494 exclamation mark (``!'') being interpreted as a language operator.
16495
16496 Note that the internal name of the DLL may be all upper-case, even
16497 though the file name of the DLL is lower-case, or vice-versa. Since
16498 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
16499 some confusion. If in doubt, try the @code{info functions} and
16500 @code{info variables} commands or even @code{maint print msymbols}
16501 (@pxref{Symbols}). Here's an example:
16502
16503 @smallexample
16504 (@value{GDBP}) info function CreateFileA
16505 All functions matching regular expression "CreateFileA":
16506
16507 Non-debugging symbols:
16508 0x77e885f4 CreateFileA
16509 0x77e885f4 KERNEL32!CreateFileA
16510 @end smallexample
16511
16512 @smallexample
16513 (@value{GDBP}) info function !
16514 All functions matching regular expression "!":
16515
16516 Non-debugging symbols:
16517 0x6100114c cygwin1!__assert
16518 0x61004034 cygwin1!_dll_crt0@@0
16519 0x61004240 cygwin1!dll_crt0(per_process *)
16520 [etc...]
16521 @end smallexample
16522
16523 @subsubsection Working with Minimal Symbols
16524
16525 Symbols extracted from a DLL's export table do not contain very much
16526 type information. All that @value{GDBN} can do is guess whether a symbol
16527 refers to a function or variable depending on the linker section that
16528 contains the symbol. Also note that the actual contents of the memory
16529 contained in a DLL are not available unless the program is running. This
16530 means that you cannot examine the contents of a variable or disassemble
16531 a function within a DLL without a running program.
16532
16533 Variables are generally treated as pointers and dereferenced
16534 automatically. For this reason, it is often necessary to prefix a
16535 variable name with the address-of operator (``&'') and provide explicit
16536 type information in the command. Here's an example of the type of
16537 problem:
16538
16539 @smallexample
16540 (@value{GDBP}) print 'cygwin1!__argv'
16541 $1 = 268572168
16542 @end smallexample
16543
16544 @smallexample
16545 (@value{GDBP}) x 'cygwin1!__argv'
16546 0x10021610: "\230y\""
16547 @end smallexample
16548
16549 And two possible solutions:
16550
16551 @smallexample
16552 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
16553 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
16554 @end smallexample
16555
16556 @smallexample
16557 (@value{GDBP}) x/2x &'cygwin1!__argv'
16558 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
16559 (@value{GDBP}) x/x 0x10021608
16560 0x10021608: 0x0022fd98
16561 (@value{GDBP}) x/s 0x0022fd98
16562 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
16563 @end smallexample
16564
16565 Setting a break point within a DLL is possible even before the program
16566 starts execution. However, under these circumstances, @value{GDBN} can't
16567 examine the initial instructions of the function in order to skip the
16568 function's frame set-up code. You can work around this by using ``*&''
16569 to set the breakpoint at a raw memory address:
16570
16571 @smallexample
16572 (@value{GDBP}) break *&'python22!PyOS_Readline'
16573 Breakpoint 1 at 0x1e04eff0
16574 @end smallexample
16575
16576 The author of these extensions is not entirely convinced that setting a
16577 break point within a shared DLL like @file{kernel32.dll} is completely
16578 safe.
16579
16580 @node Hurd Native
16581 @subsection Commands Specific to @sc{gnu} Hurd Systems
16582 @cindex @sc{gnu} Hurd debugging
16583
16584 This subsection describes @value{GDBN} commands specific to the
16585 @sc{gnu} Hurd native debugging.
16586
16587 @table @code
16588 @item set signals
16589 @itemx set sigs
16590 @kindex set signals@r{, Hurd command}
16591 @kindex set sigs@r{, Hurd command}
16592 This command toggles the state of inferior signal interception by
16593 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
16594 affected by this command. @code{sigs} is a shorthand alias for
16595 @code{signals}.
16596
16597 @item show signals
16598 @itemx show sigs
16599 @kindex show signals@r{, Hurd command}
16600 @kindex show sigs@r{, Hurd command}
16601 Show the current state of intercepting inferior's signals.
16602
16603 @item set signal-thread
16604 @itemx set sigthread
16605 @kindex set signal-thread
16606 @kindex set sigthread
16607 This command tells @value{GDBN} which thread is the @code{libc} signal
16608 thread. That thread is run when a signal is delivered to a running
16609 process. @code{set sigthread} is the shorthand alias of @code{set
16610 signal-thread}.
16611
16612 @item show signal-thread
16613 @itemx show sigthread
16614 @kindex show signal-thread
16615 @kindex show sigthread
16616 These two commands show which thread will run when the inferior is
16617 delivered a signal.
16618
16619 @item set stopped
16620 @kindex set stopped@r{, Hurd command}
16621 This commands tells @value{GDBN} that the inferior process is stopped,
16622 as with the @code{SIGSTOP} signal. The stopped process can be
16623 continued by delivering a signal to it.
16624
16625 @item show stopped
16626 @kindex show stopped@r{, Hurd command}
16627 This command shows whether @value{GDBN} thinks the debuggee is
16628 stopped.
16629
16630 @item set exceptions
16631 @kindex set exceptions@r{, Hurd command}
16632 Use this command to turn off trapping of exceptions in the inferior.
16633 When exception trapping is off, neither breakpoints nor
16634 single-stepping will work. To restore the default, set exception
16635 trapping on.
16636
16637 @item show exceptions
16638 @kindex show exceptions@r{, Hurd command}
16639 Show the current state of trapping exceptions in the inferior.
16640
16641 @item set task pause
16642 @kindex set task@r{, Hurd commands}
16643 @cindex task attributes (@sc{gnu} Hurd)
16644 @cindex pause current task (@sc{gnu} Hurd)
16645 This command toggles task suspension when @value{GDBN} has control.
16646 Setting it to on takes effect immediately, and the task is suspended
16647 whenever @value{GDBN} gets control. Setting it to off will take
16648 effect the next time the inferior is continued. If this option is set
16649 to off, you can use @code{set thread default pause on} or @code{set
16650 thread pause on} (see below) to pause individual threads.
16651
16652 @item show task pause
16653 @kindex show task@r{, Hurd commands}
16654 Show the current state of task suspension.
16655
16656 @item set task detach-suspend-count
16657 @cindex task suspend count
16658 @cindex detach from task, @sc{gnu} Hurd
16659 This command sets the suspend count the task will be left with when
16660 @value{GDBN} detaches from it.
16661
16662 @item show task detach-suspend-count
16663 Show the suspend count the task will be left with when detaching.
16664
16665 @item set task exception-port
16666 @itemx set task excp
16667 @cindex task exception port, @sc{gnu} Hurd
16668 This command sets the task exception port to which @value{GDBN} will
16669 forward exceptions. The argument should be the value of the @dfn{send
16670 rights} of the task. @code{set task excp} is a shorthand alias.
16671
16672 @item set noninvasive
16673 @cindex noninvasive task options
16674 This command switches @value{GDBN} to a mode that is the least
16675 invasive as far as interfering with the inferior is concerned. This
16676 is the same as using @code{set task pause}, @code{set exceptions}, and
16677 @code{set signals} to values opposite to the defaults.
16678
16679 @item info send-rights
16680 @itemx info receive-rights
16681 @itemx info port-rights
16682 @itemx info port-sets
16683 @itemx info dead-names
16684 @itemx info ports
16685 @itemx info psets
16686 @cindex send rights, @sc{gnu} Hurd
16687 @cindex receive rights, @sc{gnu} Hurd
16688 @cindex port rights, @sc{gnu} Hurd
16689 @cindex port sets, @sc{gnu} Hurd
16690 @cindex dead names, @sc{gnu} Hurd
16691 These commands display information about, respectively, send rights,
16692 receive rights, port rights, port sets, and dead names of a task.
16693 There are also shorthand aliases: @code{info ports} for @code{info
16694 port-rights} and @code{info psets} for @code{info port-sets}.
16695
16696 @item set thread pause
16697 @kindex set thread@r{, Hurd command}
16698 @cindex thread properties, @sc{gnu} Hurd
16699 @cindex pause current thread (@sc{gnu} Hurd)
16700 This command toggles current thread suspension when @value{GDBN} has
16701 control. Setting it to on takes effect immediately, and the current
16702 thread is suspended whenever @value{GDBN} gets control. Setting it to
16703 off will take effect the next time the inferior is continued.
16704 Normally, this command has no effect, since when @value{GDBN} has
16705 control, the whole task is suspended. However, if you used @code{set
16706 task pause off} (see above), this command comes in handy to suspend
16707 only the current thread.
16708
16709 @item show thread pause
16710 @kindex show thread@r{, Hurd command}
16711 This command shows the state of current thread suspension.
16712
16713 @item set thread run
16714 This command sets whether the current thread is allowed to run.
16715
16716 @item show thread run
16717 Show whether the current thread is allowed to run.
16718
16719 @item set thread detach-suspend-count
16720 @cindex thread suspend count, @sc{gnu} Hurd
16721 @cindex detach from thread, @sc{gnu} Hurd
16722 This command sets the suspend count @value{GDBN} will leave on a
16723 thread when detaching. This number is relative to the suspend count
16724 found by @value{GDBN} when it notices the thread; use @code{set thread
16725 takeover-suspend-count} to force it to an absolute value.
16726
16727 @item show thread detach-suspend-count
16728 Show the suspend count @value{GDBN} will leave on the thread when
16729 detaching.
16730
16731 @item set thread exception-port
16732 @itemx set thread excp
16733 Set the thread exception port to which to forward exceptions. This
16734 overrides the port set by @code{set task exception-port} (see above).
16735 @code{set thread excp} is the shorthand alias.
16736
16737 @item set thread takeover-suspend-count
16738 Normally, @value{GDBN}'s thread suspend counts are relative to the
16739 value @value{GDBN} finds when it notices each thread. This command
16740 changes the suspend counts to be absolute instead.
16741
16742 @item set thread default
16743 @itemx show thread default
16744 @cindex thread default settings, @sc{gnu} Hurd
16745 Each of the above @code{set thread} commands has a @code{set thread
16746 default} counterpart (e.g., @code{set thread default pause}, @code{set
16747 thread default exception-port}, etc.). The @code{thread default}
16748 variety of commands sets the default thread properties for all
16749 threads; you can then change the properties of individual threads with
16750 the non-default commands.
16751 @end table
16752
16753
16754 @node Neutrino
16755 @subsection QNX Neutrino
16756 @cindex QNX Neutrino
16757
16758 @value{GDBN} provides the following commands specific to the QNX
16759 Neutrino target:
16760
16761 @table @code
16762 @item set debug nto-debug
16763 @kindex set debug nto-debug
16764 When set to on, enables debugging messages specific to the QNX
16765 Neutrino support.
16766
16767 @item show debug nto-debug
16768 @kindex show debug nto-debug
16769 Show the current state of QNX Neutrino messages.
16770 @end table
16771
16772 @node Darwin
16773 @subsection Darwin
16774 @cindex Darwin
16775
16776 @value{GDBN} provides the following commands specific to the Darwin target:
16777
16778 @table @code
16779 @item set debug darwin @var{num}
16780 @kindex set debug darwin
16781 When set to a non zero value, enables debugging messages specific to
16782 the Darwin support. Higher values produce more verbose output.
16783
16784 @item show debug darwin
16785 @kindex show debug darwin
16786 Show the current state of Darwin messages.
16787
16788 @item set debug mach-o @var{num}
16789 @kindex set debug mach-o
16790 When set to a non zero value, enables debugging messages while
16791 @value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
16792 file format used on Darwin for object and executable files.) Higher
16793 values produce more verbose output. This is a command to diagnose
16794 problems internal to @value{GDBN} and should not be needed in normal
16795 usage.
16796
16797 @item show debug mach-o
16798 @kindex show debug mach-o
16799 Show the current state of Mach-O file messages.
16800
16801 @item set mach-exceptions on
16802 @itemx set mach-exceptions off
16803 @kindex set mach-exceptions
16804 On Darwin, faults are first reported as a Mach exception and are then
16805 mapped to a Posix signal. Use this command to turn on trapping of
16806 Mach exceptions in the inferior. This might be sometimes useful to
16807 better understand the cause of a fault. The default is off.
16808
16809 @item show mach-exceptions
16810 @kindex show mach-exceptions
16811 Show the current state of exceptions trapping.
16812 @end table
16813
16814
16815 @node Embedded OS
16816 @section Embedded Operating Systems
16817
16818 This section describes configurations involving the debugging of
16819 embedded operating systems that are available for several different
16820 architectures.
16821
16822 @menu
16823 * VxWorks:: Using @value{GDBN} with VxWorks
16824 @end menu
16825
16826 @value{GDBN} includes the ability to debug programs running on
16827 various real-time operating systems.
16828
16829 @node VxWorks
16830 @subsection Using @value{GDBN} with VxWorks
16831
16832 @cindex VxWorks
16833
16834 @table @code
16835
16836 @kindex target vxworks
16837 @item target vxworks @var{machinename}
16838 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
16839 is the target system's machine name or IP address.
16840
16841 @end table
16842
16843 On VxWorks, @code{load} links @var{filename} dynamically on the
16844 current target system as well as adding its symbols in @value{GDBN}.
16845
16846 @value{GDBN} enables developers to spawn and debug tasks running on networked
16847 VxWorks targets from a Unix host. Already-running tasks spawned from
16848 the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
16849 both the Unix host and on the VxWorks target. The program
16850 @code{@value{GDBP}} is installed and executed on the Unix host. (It may be
16851 installed with the name @code{vxgdb}, to distinguish it from a
16852 @value{GDBN} for debugging programs on the host itself.)
16853
16854 @table @code
16855 @item VxWorks-timeout @var{args}
16856 @kindex vxworks-timeout
16857 All VxWorks-based targets now support the option @code{vxworks-timeout}.
16858 This option is set by the user, and @var{args} represents the number of
16859 seconds @value{GDBN} waits for responses to rpc's. You might use this if
16860 your VxWorks target is a slow software simulator or is on the far side
16861 of a thin network line.
16862 @end table
16863
16864 The following information on connecting to VxWorks was current when
16865 this manual was produced; newer releases of VxWorks may use revised
16866 procedures.
16867
16868 @findex INCLUDE_RDB
16869 To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
16870 to include the remote debugging interface routines in the VxWorks
16871 library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
16872 VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
16873 kernel. The resulting kernel contains @file{rdb.a}, and spawns the
16874 source debugging task @code{tRdbTask} when VxWorks is booted. For more
16875 information on configuring and remaking VxWorks, see the manufacturer's
16876 manual.
16877 @c VxWorks, see the @cite{VxWorks Programmer's Guide}.
16878
16879 Once you have included @file{rdb.a} in your VxWorks system image and set
16880 your Unix execution search path to find @value{GDBN}, you are ready to
16881 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
16882 @code{vxgdb}, depending on your installation).
16883
16884 @value{GDBN} comes up showing the prompt:
16885
16886 @smallexample
16887 (vxgdb)
16888 @end smallexample
16889
16890 @menu
16891 * VxWorks Connection:: Connecting to VxWorks
16892 * VxWorks Download:: VxWorks download
16893 * VxWorks Attach:: Running tasks
16894 @end menu
16895
16896 @node VxWorks Connection
16897 @subsubsection Connecting to VxWorks
16898
16899 The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
16900 network. To connect to a target whose host name is ``@code{tt}'', type:
16901
16902 @smallexample
16903 (vxgdb) target vxworks tt
16904 @end smallexample
16905
16906 @need 750
16907 @value{GDBN} displays messages like these:
16908
16909 @smallexample
16910 Attaching remote machine across net...
16911 Connected to tt.
16912 @end smallexample
16913
16914 @need 1000
16915 @value{GDBN} then attempts to read the symbol tables of any object modules
16916 loaded into the VxWorks target since it was last booted. @value{GDBN} locates
16917 these files by searching the directories listed in the command search
16918 path (@pxref{Environment, ,Your Program's Environment}); if it fails
16919 to find an object file, it displays a message such as:
16920
16921 @smallexample
16922 prog.o: No such file or directory.
16923 @end smallexample
16924
16925 When this happens, add the appropriate directory to the search path with
16926 the @value{GDBN} command @code{path}, and execute the @code{target}
16927 command again.
16928
16929 @node VxWorks Download
16930 @subsubsection VxWorks Download
16931
16932 @cindex download to VxWorks
16933 If you have connected to the VxWorks target and you want to debug an
16934 object that has not yet been loaded, you can use the @value{GDBN}
16935 @code{load} command to download a file from Unix to VxWorks
16936 incrementally. The object file given as an argument to the @code{load}
16937 command is actually opened twice: first by the VxWorks target in order
16938 to download the code, then by @value{GDBN} in order to read the symbol
16939 table. This can lead to problems if the current working directories on
16940 the two systems differ. If both systems have NFS mounted the same
16941 filesystems, you can avoid these problems by using absolute paths.
16942 Otherwise, it is simplest to set the working directory on both systems
16943 to the directory in which the object file resides, and then to reference
16944 the file by its name, without any path. For instance, a program
16945 @file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
16946 and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
16947 program, type this on VxWorks:
16948
16949 @smallexample
16950 -> cd "@var{vxpath}/vw/demo/rdb"
16951 @end smallexample
16952
16953 @noindent
16954 Then, in @value{GDBN}, type:
16955
16956 @smallexample
16957 (vxgdb) cd @var{hostpath}/vw/demo/rdb
16958 (vxgdb) load prog.o
16959 @end smallexample
16960
16961 @value{GDBN} displays a response similar to this:
16962
16963 @smallexample
16964 Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
16965 @end smallexample
16966
16967 You can also use the @code{load} command to reload an object module
16968 after editing and recompiling the corresponding source file. Note that
16969 this makes @value{GDBN} delete all currently-defined breakpoints,
16970 auto-displays, and convenience variables, and to clear the value
16971 history. (This is necessary in order to preserve the integrity of
16972 debugger's data structures that reference the target system's symbol
16973 table.)
16974
16975 @node VxWorks Attach
16976 @subsubsection Running Tasks
16977
16978 @cindex running VxWorks tasks
16979 You can also attach to an existing task using the @code{attach} command as
16980 follows:
16981
16982 @smallexample
16983 (vxgdb) attach @var{task}
16984 @end smallexample
16985
16986 @noindent
16987 where @var{task} is the VxWorks hexadecimal task ID. The task can be running
16988 or suspended when you attach to it. Running tasks are suspended at
16989 the time of attachment.
16990
16991 @node Embedded Processors
16992 @section Embedded Processors
16993
16994 This section goes into details specific to particular embedded
16995 configurations.
16996
16997 @cindex send command to simulator
16998 Whenever a specific embedded processor has a simulator, @value{GDBN}
16999 allows to send an arbitrary command to the simulator.
17000
17001 @table @code
17002 @item sim @var{command}
17003 @kindex sim@r{, a command}
17004 Send an arbitrary @var{command} string to the simulator. Consult the
17005 documentation for the specific simulator in use for information about
17006 acceptable commands.
17007 @end table
17008
17009
17010 @menu
17011 * ARM:: ARM RDI
17012 * M32R/D:: Renesas M32R/D
17013 * M68K:: Motorola M68K
17014 * MicroBlaze:: Xilinx MicroBlaze
17015 * MIPS Embedded:: MIPS Embedded
17016 * OpenRISC 1000:: OpenRisc 1000
17017 * PA:: HP PA Embedded
17018 * PowerPC Embedded:: PowerPC Embedded
17019 * Sparclet:: Tsqware Sparclet
17020 * Sparclite:: Fujitsu Sparclite
17021 * Z8000:: Zilog Z8000
17022 * AVR:: Atmel AVR
17023 * CRIS:: CRIS
17024 * Super-H:: Renesas Super-H
17025 @end menu
17026
17027 @node ARM
17028 @subsection ARM
17029 @cindex ARM RDI
17030
17031 @table @code
17032 @kindex target rdi
17033 @item target rdi @var{dev}
17034 ARM Angel monitor, via RDI library interface to ADP protocol. You may
17035 use this target to communicate with both boards running the Angel
17036 monitor, or with the EmbeddedICE JTAG debug device.
17037
17038 @kindex target rdp
17039 @item target rdp @var{dev}
17040 ARM Demon monitor.
17041
17042 @end table
17043
17044 @value{GDBN} provides the following ARM-specific commands:
17045
17046 @table @code
17047 @item set arm disassembler
17048 @kindex set arm
17049 This commands selects from a list of disassembly styles. The
17050 @code{"std"} style is the standard style.
17051
17052 @item show arm disassembler
17053 @kindex show arm
17054 Show the current disassembly style.
17055
17056 @item set arm apcs32
17057 @cindex ARM 32-bit mode
17058 This command toggles ARM operation mode between 32-bit and 26-bit.
17059
17060 @item show arm apcs32
17061 Display the current usage of the ARM 32-bit mode.
17062
17063 @item set arm fpu @var{fputype}
17064 This command sets the ARM floating-point unit (FPU) type. The
17065 argument @var{fputype} can be one of these:
17066
17067 @table @code
17068 @item auto
17069 Determine the FPU type by querying the OS ABI.
17070 @item softfpa
17071 Software FPU, with mixed-endian doubles on little-endian ARM
17072 processors.
17073 @item fpa
17074 GCC-compiled FPA co-processor.
17075 @item softvfp
17076 Software FPU with pure-endian doubles.
17077 @item vfp
17078 VFP co-processor.
17079 @end table
17080
17081 @item show arm fpu
17082 Show the current type of the FPU.
17083
17084 @item set arm abi
17085 This command forces @value{GDBN} to use the specified ABI.
17086
17087 @item show arm abi
17088 Show the currently used ABI.
17089
17090 @item set arm fallback-mode (arm|thumb|auto)
17091 @value{GDBN} uses the symbol table, when available, to determine
17092 whether instructions are ARM or Thumb. This command controls
17093 @value{GDBN}'s default behavior when the symbol table is not
17094 available. The default is @samp{auto}, which causes @value{GDBN} to
17095 use the current execution mode (from the @code{T} bit in the @code{CPSR}
17096 register).
17097
17098 @item show arm fallback-mode
17099 Show the current fallback instruction mode.
17100
17101 @item set arm force-mode (arm|thumb|auto)
17102 This command overrides use of the symbol table to determine whether
17103 instructions are ARM or Thumb. The default is @samp{auto}, which
17104 causes @value{GDBN} to use the symbol table and then the setting
17105 of @samp{set arm fallback-mode}.
17106
17107 @item show arm force-mode
17108 Show the current forced instruction mode.
17109
17110 @item set debug arm
17111 Toggle whether to display ARM-specific debugging messages from the ARM
17112 target support subsystem.
17113
17114 @item show debug arm
17115 Show whether ARM-specific debugging messages are enabled.
17116 @end table
17117
17118 The following commands are available when an ARM target is debugged
17119 using the RDI interface:
17120
17121 @table @code
17122 @item rdilogfile @r{[}@var{file}@r{]}
17123 @kindex rdilogfile
17124 @cindex ADP (Angel Debugger Protocol) logging
17125 Set the filename for the ADP (Angel Debugger Protocol) packet log.
17126 With an argument, sets the log file to the specified @var{file}. With
17127 no argument, show the current log file name. The default log file is
17128 @file{rdi.log}.
17129
17130 @item rdilogenable @r{[}@var{arg}@r{]}
17131 @kindex rdilogenable
17132 Control logging of ADP packets. With an argument of 1 or @code{"yes"}
17133 enables logging, with an argument 0 or @code{"no"} disables it. With
17134 no arguments displays the current setting. When logging is enabled,
17135 ADP packets exchanged between @value{GDBN} and the RDI target device
17136 are logged to a file.
17137
17138 @item set rdiromatzero
17139 @kindex set rdiromatzero
17140 @cindex ROM at zero address, RDI
17141 Tell @value{GDBN} whether the target has ROM at address 0. If on,
17142 vector catching is disabled, so that zero address can be used. If off
17143 (the default), vector catching is enabled. For this command to take
17144 effect, it needs to be invoked prior to the @code{target rdi} command.
17145
17146 @item show rdiromatzero
17147 @kindex show rdiromatzero
17148 Show the current setting of ROM at zero address.
17149
17150 @item set rdiheartbeat
17151 @kindex set rdiheartbeat
17152 @cindex RDI heartbeat
17153 Enable or disable RDI heartbeat packets. It is not recommended to
17154 turn on this option, since it confuses ARM and EPI JTAG interface, as
17155 well as the Angel monitor.
17156
17157 @item show rdiheartbeat
17158 @kindex show rdiheartbeat
17159 Show the setting of RDI heartbeat packets.
17160 @end table
17161
17162
17163 @node M32R/D
17164 @subsection Renesas M32R/D and M32R/SDI
17165
17166 @table @code
17167 @kindex target m32r
17168 @item target m32r @var{dev}
17169 Renesas M32R/D ROM monitor.
17170
17171 @kindex target m32rsdi
17172 @item target m32rsdi @var{dev}
17173 Renesas M32R SDI server, connected via parallel port to the board.
17174 @end table
17175
17176 The following @value{GDBN} commands are specific to the M32R monitor:
17177
17178 @table @code
17179 @item set download-path @var{path}
17180 @kindex set download-path
17181 @cindex find downloadable @sc{srec} files (M32R)
17182 Set the default path for finding downloadable @sc{srec} files.
17183
17184 @item show download-path
17185 @kindex show download-path
17186 Show the default path for downloadable @sc{srec} files.
17187
17188 @item set board-address @var{addr}
17189 @kindex set board-address
17190 @cindex M32-EVA target board address
17191 Set the IP address for the M32R-EVA target board.
17192
17193 @item show board-address
17194 @kindex show board-address
17195 Show the current IP address of the target board.
17196
17197 @item set server-address @var{addr}
17198 @kindex set server-address
17199 @cindex download server address (M32R)
17200 Set the IP address for the download server, which is the @value{GDBN}'s
17201 host machine.
17202
17203 @item show server-address
17204 @kindex show server-address
17205 Display the IP address of the download server.
17206
17207 @item upload @r{[}@var{file}@r{]}
17208 @kindex upload@r{, M32R}
17209 Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
17210 upload capability. If no @var{file} argument is given, the current
17211 executable file is uploaded.
17212
17213 @item tload @r{[}@var{file}@r{]}
17214 @kindex tload@r{, M32R}
17215 Test the @code{upload} command.
17216 @end table
17217
17218 The following commands are available for M32R/SDI:
17219
17220 @table @code
17221 @item sdireset
17222 @kindex sdireset
17223 @cindex reset SDI connection, M32R
17224 This command resets the SDI connection.
17225
17226 @item sdistatus
17227 @kindex sdistatus
17228 This command shows the SDI connection status.
17229
17230 @item debug_chaos
17231 @kindex debug_chaos
17232 @cindex M32R/Chaos debugging
17233 Instructs the remote that M32R/Chaos debugging is to be used.
17234
17235 @item use_debug_dma
17236 @kindex use_debug_dma
17237 Instructs the remote to use the DEBUG_DMA method of accessing memory.
17238
17239 @item use_mon_code
17240 @kindex use_mon_code
17241 Instructs the remote to use the MON_CODE method of accessing memory.
17242
17243 @item use_ib_break
17244 @kindex use_ib_break
17245 Instructs the remote to set breakpoints by IB break.
17246
17247 @item use_dbt_break
17248 @kindex use_dbt_break
17249 Instructs the remote to set breakpoints by DBT.
17250 @end table
17251
17252 @node M68K
17253 @subsection M68k
17254
17255 The Motorola m68k configuration includes ColdFire support, and a
17256 target command for the following ROM monitor.
17257
17258 @table @code
17259
17260 @kindex target dbug
17261 @item target dbug @var{dev}
17262 dBUG ROM monitor for Motorola ColdFire.
17263
17264 @end table
17265
17266 @node MicroBlaze
17267 @subsection MicroBlaze
17268 @cindex Xilinx MicroBlaze
17269 @cindex XMD, Xilinx Microprocessor Debugger
17270
17271 The MicroBlaze is a soft-core processor supported on various Xilinx
17272 FPGAs, such as Spartan or Virtex series. Boards with these processors
17273 usually have JTAG ports which connect to a host system running the Xilinx
17274 Embedded Development Kit (EDK) or Software Development Kit (SDK).
17275 This host system is used to download the configuration bitstream to
17276 the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
17277 communicates with the target board using the JTAG interface and
17278 presents a @code{gdbserver} interface to the board. By default
17279 @code{xmd} uses port @code{1234}. (While it is possible to change
17280 this default port, it requires the use of undocumented @code{xmd}
17281 commands. Contact Xilinx support if you need to do this.)
17282
17283 Use these GDB commands to connect to the MicroBlaze target processor.
17284
17285 @table @code
17286 @item target remote :1234
17287 Use this command to connect to the target if you are running @value{GDBN}
17288 on the same system as @code{xmd}.
17289
17290 @item target remote @var{xmd-host}:1234
17291 Use this command to connect to the target if it is connected to @code{xmd}
17292 running on a different system named @var{xmd-host}.
17293
17294 @item load
17295 Use this command to download a program to the MicroBlaze target.
17296
17297 @item set debug microblaze @var{n}
17298 Enable MicroBlaze-specific debugging messages if non-zero.
17299
17300 @item show debug microblaze @var{n}
17301 Show MicroBlaze-specific debugging level.
17302 @end table
17303
17304 @node MIPS Embedded
17305 @subsection MIPS Embedded
17306
17307 @cindex MIPS boards
17308 @value{GDBN} can use the MIPS remote debugging protocol to talk to a
17309 MIPS board attached to a serial line. This is available when
17310 you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
17311
17312 @need 1000
17313 Use these @value{GDBN} commands to specify the connection to your target board:
17314
17315 @table @code
17316 @item target mips @var{port}
17317 @kindex target mips @var{port}
17318 To run a program on the board, start up @code{@value{GDBP}} with the
17319 name of your program as the argument. To connect to the board, use the
17320 command @samp{target mips @var{port}}, where @var{port} is the name of
17321 the serial port connected to the board. If the program has not already
17322 been downloaded to the board, you may use the @code{load} command to
17323 download it. You can then use all the usual @value{GDBN} commands.
17324
17325 For example, this sequence connects to the target board through a serial
17326 port, and loads and runs a program called @var{prog} through the
17327 debugger:
17328
17329 @smallexample
17330 host$ @value{GDBP} @var{prog}
17331 @value{GDBN} is free software and @dots{}
17332 (@value{GDBP}) target mips /dev/ttyb
17333 (@value{GDBP}) load @var{prog}
17334 (@value{GDBP}) run
17335 @end smallexample
17336
17337 @item target mips @var{hostname}:@var{portnumber}
17338 On some @value{GDBN} host configurations, you can specify a TCP
17339 connection (for instance, to a serial line managed by a terminal
17340 concentrator) instead of a serial port, using the syntax
17341 @samp{@var{hostname}:@var{portnumber}}.
17342
17343 @item target pmon @var{port}
17344 @kindex target pmon @var{port}
17345 PMON ROM monitor.
17346
17347 @item target ddb @var{port}
17348 @kindex target ddb @var{port}
17349 NEC's DDB variant of PMON for Vr4300.
17350
17351 @item target lsi @var{port}
17352 @kindex target lsi @var{port}
17353 LSI variant of PMON.
17354
17355 @kindex target r3900
17356 @item target r3900 @var{dev}
17357 Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
17358
17359 @kindex target array
17360 @item target array @var{dev}
17361 Array Tech LSI33K RAID controller board.
17362
17363 @end table
17364
17365
17366 @noindent
17367 @value{GDBN} also supports these special commands for MIPS targets:
17368
17369 @table @code
17370 @item set mipsfpu double
17371 @itemx set mipsfpu single
17372 @itemx set mipsfpu none
17373 @itemx set mipsfpu auto
17374 @itemx show mipsfpu
17375 @kindex set mipsfpu
17376 @kindex show mipsfpu
17377 @cindex MIPS remote floating point
17378 @cindex floating point, MIPS remote
17379 If your target board does not support the MIPS floating point
17380 coprocessor, you should use the command @samp{set mipsfpu none} (if you
17381 need this, you may wish to put the command in your @value{GDBN} init
17382 file). This tells @value{GDBN} how to find the return value of
17383 functions which return floating point values. It also allows
17384 @value{GDBN} to avoid saving the floating point registers when calling
17385 functions on the board. If you are using a floating point coprocessor
17386 with only single precision floating point support, as on the @sc{r4650}
17387 processor, use the command @samp{set mipsfpu single}. The default
17388 double precision floating point coprocessor may be selected using
17389 @samp{set mipsfpu double}.
17390
17391 In previous versions the only choices were double precision or no
17392 floating point, so @samp{set mipsfpu on} will select double precision
17393 and @samp{set mipsfpu off} will select no floating point.
17394
17395 As usual, you can inquire about the @code{mipsfpu} variable with
17396 @samp{show mipsfpu}.
17397
17398 @item set timeout @var{seconds}
17399 @itemx set retransmit-timeout @var{seconds}
17400 @itemx show timeout
17401 @itemx show retransmit-timeout
17402 @cindex @code{timeout}, MIPS protocol
17403 @cindex @code{retransmit-timeout}, MIPS protocol
17404 @kindex set timeout
17405 @kindex show timeout
17406 @kindex set retransmit-timeout
17407 @kindex show retransmit-timeout
17408 You can control the timeout used while waiting for a packet, in the MIPS
17409 remote protocol, with the @code{set timeout @var{seconds}} command. The
17410 default is 5 seconds. Similarly, you can control the timeout used while
17411 waiting for an acknowledgment of a packet with the @code{set
17412 retransmit-timeout @var{seconds}} command. The default is 3 seconds.
17413 You can inspect both values with @code{show timeout} and @code{show
17414 retransmit-timeout}. (These commands are @emph{only} available when
17415 @value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
17416
17417 The timeout set by @code{set timeout} does not apply when @value{GDBN}
17418 is waiting for your program to stop. In that case, @value{GDBN} waits
17419 forever because it has no way of knowing how long the program is going
17420 to run before stopping.
17421
17422 @item set syn-garbage-limit @var{num}
17423 @kindex set syn-garbage-limit@r{, MIPS remote}
17424 @cindex synchronize with remote MIPS target
17425 Limit the maximum number of characters @value{GDBN} should ignore when
17426 it tries to synchronize with the remote target. The default is 10
17427 characters. Setting the limit to -1 means there's no limit.
17428
17429 @item show syn-garbage-limit
17430 @kindex show syn-garbage-limit@r{, MIPS remote}
17431 Show the current limit on the number of characters to ignore when
17432 trying to synchronize with the remote system.
17433
17434 @item set monitor-prompt @var{prompt}
17435 @kindex set monitor-prompt@r{, MIPS remote}
17436 @cindex remote monitor prompt
17437 Tell @value{GDBN} to expect the specified @var{prompt} string from the
17438 remote monitor. The default depends on the target:
17439 @table @asis
17440 @item pmon target
17441 @samp{PMON}
17442 @item ddb target
17443 @samp{NEC010}
17444 @item lsi target
17445 @samp{PMON>}
17446 @end table
17447
17448 @item show monitor-prompt
17449 @kindex show monitor-prompt@r{, MIPS remote}
17450 Show the current strings @value{GDBN} expects as the prompt from the
17451 remote monitor.
17452
17453 @item set monitor-warnings
17454 @kindex set monitor-warnings@r{, MIPS remote}
17455 Enable or disable monitor warnings about hardware breakpoints. This
17456 has effect only for the @code{lsi} target. When on, @value{GDBN} will
17457 display warning messages whose codes are returned by the @code{lsi}
17458 PMON monitor for breakpoint commands.
17459
17460 @item show monitor-warnings
17461 @kindex show monitor-warnings@r{, MIPS remote}
17462 Show the current setting of printing monitor warnings.
17463
17464 @item pmon @var{command}
17465 @kindex pmon@r{, MIPS remote}
17466 @cindex send PMON command
17467 This command allows sending an arbitrary @var{command} string to the
17468 monitor. The monitor must be in debug mode for this to work.
17469 @end table
17470
17471 @node OpenRISC 1000
17472 @subsection OpenRISC 1000
17473 @cindex OpenRISC 1000
17474
17475 @cindex or1k boards
17476 See OR1k Architecture document (@uref{www.opencores.org}) for more information
17477 about platform and commands.
17478
17479 @table @code
17480
17481 @kindex target jtag
17482 @item target jtag jtag://@var{host}:@var{port}
17483
17484 Connects to remote JTAG server.
17485 JTAG remote server can be either an or1ksim or JTAG server,
17486 connected via parallel port to the board.
17487
17488 Example: @code{target jtag jtag://localhost:9999}
17489
17490 @kindex or1ksim
17491 @item or1ksim @var{command}
17492 If connected to @code{or1ksim} OpenRISC 1000 Architectural
17493 Simulator, proprietary commands can be executed.
17494
17495 @kindex info or1k spr
17496 @item info or1k spr
17497 Displays spr groups.
17498
17499 @item info or1k spr @var{group}
17500 @itemx info or1k spr @var{groupno}
17501 Displays register names in selected group.
17502
17503 @item info or1k spr @var{group} @var{register}
17504 @itemx info or1k spr @var{register}
17505 @itemx info or1k spr @var{groupno} @var{registerno}
17506 @itemx info or1k spr @var{registerno}
17507 Shows information about specified spr register.
17508
17509 @kindex spr
17510 @item spr @var{group} @var{register} @var{value}
17511 @itemx spr @var{register @var{value}}
17512 @itemx spr @var{groupno} @var{registerno @var{value}}
17513 @itemx spr @var{registerno @var{value}}
17514 Writes @var{value} to specified spr register.
17515 @end table
17516
17517 Some implementations of OpenRISC 1000 Architecture also have hardware trace.
17518 It is very similar to @value{GDBN} trace, except it does not interfere with normal
17519 program execution and is thus much faster. Hardware breakpoints/watchpoint
17520 triggers can be set using:
17521 @table @code
17522 @item $LEA/$LDATA
17523 Load effective address/data
17524 @item $SEA/$SDATA
17525 Store effective address/data
17526 @item $AEA/$ADATA
17527 Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
17528 @item $FETCH
17529 Fetch data
17530 @end table
17531
17532 When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
17533 @code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
17534
17535 @code{htrace} commands:
17536 @cindex OpenRISC 1000 htrace
17537 @table @code
17538 @kindex hwatch
17539 @item hwatch @var{conditional}
17540 Set hardware watchpoint on combination of Load/Store Effective Address(es)
17541 or Data. For example:
17542
17543 @code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
17544
17545 @code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
17546
17547 @kindex htrace
17548 @item htrace info
17549 Display information about current HW trace configuration.
17550
17551 @item htrace trigger @var{conditional}
17552 Set starting criteria for HW trace.
17553
17554 @item htrace qualifier @var{conditional}
17555 Set acquisition qualifier for HW trace.
17556
17557 @item htrace stop @var{conditional}
17558 Set HW trace stopping criteria.
17559
17560 @item htrace record [@var{data}]*
17561 Selects the data to be recorded, when qualifier is met and HW trace was
17562 triggered.
17563
17564 @item htrace enable
17565 @itemx htrace disable
17566 Enables/disables the HW trace.
17567
17568 @item htrace rewind [@var{filename}]
17569 Clears currently recorded trace data.
17570
17571 If filename is specified, new trace file is made and any newly collected data
17572 will be written there.
17573
17574 @item htrace print [@var{start} [@var{len}]]
17575 Prints trace buffer, using current record configuration.
17576
17577 @item htrace mode continuous
17578 Set continuous trace mode.
17579
17580 @item htrace mode suspend
17581 Set suspend trace mode.
17582
17583 @end table
17584
17585 @node PowerPC Embedded
17586 @subsection PowerPC Embedded
17587
17588 @value{GDBN} provides the following PowerPC-specific commands:
17589
17590 @table @code
17591 @kindex set powerpc
17592 @item set powerpc soft-float
17593 @itemx show powerpc soft-float
17594 Force @value{GDBN} to use (or not use) a software floating point calling
17595 convention. By default, @value{GDBN} selects the calling convention based
17596 on the selected architecture and the provided executable file.
17597
17598 @item set powerpc vector-abi
17599 @itemx show powerpc vector-abi
17600 Force @value{GDBN} to use the specified calling convention for vector
17601 arguments and return values. The valid options are @samp{auto};
17602 @samp{generic}, to avoid vector registers even if they are present;
17603 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
17604 registers. By default, @value{GDBN} selects the calling convention
17605 based on the selected architecture and the provided executable file.
17606
17607 @kindex target dink32
17608 @item target dink32 @var{dev}
17609 DINK32 ROM monitor.
17610
17611 @kindex target ppcbug
17612 @item target ppcbug @var{dev}
17613 @kindex target ppcbug1
17614 @item target ppcbug1 @var{dev}
17615 PPCBUG ROM monitor for PowerPC.
17616
17617 @kindex target sds
17618 @item target sds @var{dev}
17619 SDS monitor, running on a PowerPC board (such as Motorola's ADS).
17620 @end table
17621
17622 @cindex SDS protocol
17623 The following commands specific to the SDS protocol are supported
17624 by @value{GDBN}:
17625
17626 @table @code
17627 @item set sdstimeout @var{nsec}
17628 @kindex set sdstimeout
17629 Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
17630 default is 2 seconds.
17631
17632 @item show sdstimeout
17633 @kindex show sdstimeout
17634 Show the current value of the SDS timeout.
17635
17636 @item sds @var{command}
17637 @kindex sds@r{, a command}
17638 Send the specified @var{command} string to the SDS monitor.
17639 @end table
17640
17641
17642 @node PA
17643 @subsection HP PA Embedded
17644
17645 @table @code
17646
17647 @kindex target op50n
17648 @item target op50n @var{dev}
17649 OP50N monitor, running on an OKI HPPA board.
17650
17651 @kindex target w89k
17652 @item target w89k @var{dev}
17653 W89K monitor, running on a Winbond HPPA board.
17654
17655 @end table
17656
17657 @node Sparclet
17658 @subsection Tsqware Sparclet
17659
17660 @cindex Sparclet
17661
17662 @value{GDBN} enables developers to debug tasks running on
17663 Sparclet targets from a Unix host.
17664 @value{GDBN} uses code that runs on
17665 both the Unix host and on the Sparclet target. The program
17666 @code{@value{GDBP}} is installed and executed on the Unix host.
17667
17668 @table @code
17669 @item remotetimeout @var{args}
17670 @kindex remotetimeout
17671 @value{GDBN} supports the option @code{remotetimeout}.
17672 This option is set by the user, and @var{args} represents the number of
17673 seconds @value{GDBN} waits for responses.
17674 @end table
17675
17676 @cindex compiling, on Sparclet
17677 When compiling for debugging, include the options @samp{-g} to get debug
17678 information and @samp{-Ttext} to relocate the program to where you wish to
17679 load it on the target. You may also want to add the options @samp{-n} or
17680 @samp{-N} in order to reduce the size of the sections. Example:
17681
17682 @smallexample
17683 sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
17684 @end smallexample
17685
17686 You can use @code{objdump} to verify that the addresses are what you intended:
17687
17688 @smallexample
17689 sparclet-aout-objdump --headers --syms prog
17690 @end smallexample
17691
17692 @cindex running, on Sparclet
17693 Once you have set
17694 your Unix execution search path to find @value{GDBN}, you are ready to
17695 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
17696 (or @code{sparclet-aout-gdb}, depending on your installation).
17697
17698 @value{GDBN} comes up showing the prompt:
17699
17700 @smallexample
17701 (gdbslet)
17702 @end smallexample
17703
17704 @menu
17705 * Sparclet File:: Setting the file to debug
17706 * Sparclet Connection:: Connecting to Sparclet
17707 * Sparclet Download:: Sparclet download
17708 * Sparclet Execution:: Running and debugging
17709 @end menu
17710
17711 @node Sparclet File
17712 @subsubsection Setting File to Debug
17713
17714 The @value{GDBN} command @code{file} lets you choose with program to debug.
17715
17716 @smallexample
17717 (gdbslet) file prog
17718 @end smallexample
17719
17720 @need 1000
17721 @value{GDBN} then attempts to read the symbol table of @file{prog}.
17722 @value{GDBN} locates
17723 the file by searching the directories listed in the command search
17724 path.
17725 If the file was compiled with debug information (option @samp{-g}), source
17726 files will be searched as well.
17727 @value{GDBN} locates
17728 the source files by searching the directories listed in the directory search
17729 path (@pxref{Environment, ,Your Program's Environment}).
17730 If it fails
17731 to find a file, it displays a message such as:
17732
17733 @smallexample
17734 prog: No such file or directory.
17735 @end smallexample
17736
17737 When this happens, add the appropriate directories to the search paths with
17738 the @value{GDBN} commands @code{path} and @code{dir}, and execute the
17739 @code{target} command again.
17740
17741 @node Sparclet Connection
17742 @subsubsection Connecting to Sparclet
17743
17744 The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
17745 To connect to a target on serial port ``@code{ttya}'', type:
17746
17747 @smallexample
17748 (gdbslet) target sparclet /dev/ttya
17749 Remote target sparclet connected to /dev/ttya
17750 main () at ../prog.c:3
17751 @end smallexample
17752
17753 @need 750
17754 @value{GDBN} displays messages like these:
17755
17756 @smallexample
17757 Connected to ttya.
17758 @end smallexample
17759
17760 @node Sparclet Download
17761 @subsubsection Sparclet Download
17762
17763 @cindex download to Sparclet
17764 Once connected to the Sparclet target,
17765 you can use the @value{GDBN}
17766 @code{load} command to download the file from the host to the target.
17767 The file name and load offset should be given as arguments to the @code{load}
17768 command.
17769 Since the file format is aout, the program must be loaded to the starting
17770 address. You can use @code{objdump} to find out what this value is. The load
17771 offset is an offset which is added to the VMA (virtual memory address)
17772 of each of the file's sections.
17773 For instance, if the program
17774 @file{prog} was linked to text address 0x1201000, with data at 0x12010160
17775 and bss at 0x12010170, in @value{GDBN}, type:
17776
17777 @smallexample
17778 (gdbslet) load prog 0x12010000
17779 Loading section .text, size 0xdb0 vma 0x12010000
17780 @end smallexample
17781
17782 If the code is loaded at a different address then what the program was linked
17783 to, you may need to use the @code{section} and @code{add-symbol-file} commands
17784 to tell @value{GDBN} where to map the symbol table.
17785
17786 @node Sparclet Execution
17787 @subsubsection Running and Debugging
17788
17789 @cindex running and debugging Sparclet programs
17790 You can now begin debugging the task using @value{GDBN}'s execution control
17791 commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
17792 manual for the list of commands.
17793
17794 @smallexample
17795 (gdbslet) b main
17796 Breakpoint 1 at 0x12010000: file prog.c, line 3.
17797 (gdbslet) run
17798 Starting program: prog
17799 Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
17800 3 char *symarg = 0;
17801 (gdbslet) step
17802 4 char *execarg = "hello!";
17803 (gdbslet)
17804 @end smallexample
17805
17806 @node Sparclite
17807 @subsection Fujitsu Sparclite
17808
17809 @table @code
17810
17811 @kindex target sparclite
17812 @item target sparclite @var{dev}
17813 Fujitsu sparclite boards, used only for the purpose of loading.
17814 You must use an additional command to debug the program.
17815 For example: target remote @var{dev} using @value{GDBN} standard
17816 remote protocol.
17817
17818 @end table
17819
17820 @node Z8000
17821 @subsection Zilog Z8000
17822
17823 @cindex Z8000
17824 @cindex simulator, Z8000
17825 @cindex Zilog Z8000 simulator
17826
17827 When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
17828 a Z8000 simulator.
17829
17830 For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
17831 unsegmented variant of the Z8000 architecture) or the Z8001 (the
17832 segmented variant). The simulator recognizes which architecture is
17833 appropriate by inspecting the object code.
17834
17835 @table @code
17836 @item target sim @var{args}
17837 @kindex sim
17838 @kindex target sim@r{, with Z8000}
17839 Debug programs on a simulated CPU. If the simulator supports setup
17840 options, specify them via @var{args}.
17841 @end table
17842
17843 @noindent
17844 After specifying this target, you can debug programs for the simulated
17845 CPU in the same style as programs for your host computer; use the
17846 @code{file} command to load a new program image, the @code{run} command
17847 to run your program, and so on.
17848
17849 As well as making available all the usual machine registers
17850 (@pxref{Registers, ,Registers}), the Z8000 simulator provides three
17851 additional items of information as specially named registers:
17852
17853 @table @code
17854
17855 @item cycles
17856 Counts clock-ticks in the simulator.
17857
17858 @item insts
17859 Counts instructions run in the simulator.
17860
17861 @item time
17862 Execution time in 60ths of a second.
17863
17864 @end table
17865
17866 You can refer to these values in @value{GDBN} expressions with the usual
17867 conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
17868 conditional breakpoint that suspends only after at least 5000
17869 simulated clock ticks.
17870
17871 @node AVR
17872 @subsection Atmel AVR
17873 @cindex AVR
17874
17875 When configured for debugging the Atmel AVR, @value{GDBN} supports the
17876 following AVR-specific commands:
17877
17878 @table @code
17879 @item info io_registers
17880 @kindex info io_registers@r{, AVR}
17881 @cindex I/O registers (Atmel AVR)
17882 This command displays information about the AVR I/O registers. For
17883 each register, @value{GDBN} prints its number and value.
17884 @end table
17885
17886 @node CRIS
17887 @subsection CRIS
17888 @cindex CRIS
17889
17890 When configured for debugging CRIS, @value{GDBN} provides the
17891 following CRIS-specific commands:
17892
17893 @table @code
17894 @item set cris-version @var{ver}
17895 @cindex CRIS version
17896 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
17897 The CRIS version affects register names and sizes. This command is useful in
17898 case autodetection of the CRIS version fails.
17899
17900 @item show cris-version
17901 Show the current CRIS version.
17902
17903 @item set cris-dwarf2-cfi
17904 @cindex DWARF-2 CFI and CRIS
17905 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
17906 Change to @samp{off} when using @code{gcc-cris} whose version is below
17907 @code{R59}.
17908
17909 @item show cris-dwarf2-cfi
17910 Show the current state of using DWARF-2 CFI.
17911
17912 @item set cris-mode @var{mode}
17913 @cindex CRIS mode
17914 Set the current CRIS mode to @var{mode}. It should only be changed when
17915 debugging in guru mode, in which case it should be set to
17916 @samp{guru} (the default is @samp{normal}).
17917
17918 @item show cris-mode
17919 Show the current CRIS mode.
17920 @end table
17921
17922 @node Super-H
17923 @subsection Renesas Super-H
17924 @cindex Super-H
17925
17926 For the Renesas Super-H processor, @value{GDBN} provides these
17927 commands:
17928
17929 @table @code
17930 @item regs
17931 @kindex regs@r{, Super-H}
17932 Show the values of all Super-H registers.
17933
17934 @item set sh calling-convention @var{convention}
17935 @kindex set sh calling-convention
17936 Set the calling-convention used when calling functions from @value{GDBN}.
17937 Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
17938 With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
17939 convention. If the DWARF-2 information of the called function specifies
17940 that the function follows the Renesas calling convention, the function
17941 is called using the Renesas calling convention. If the calling convention
17942 is set to @samp{renesas}, the Renesas calling convention is always used,
17943 regardless of the DWARF-2 information. This can be used to override the
17944 default of @samp{gcc} if debug information is missing, or the compiler
17945 does not emit the DWARF-2 calling convention entry for a function.
17946
17947 @item show sh calling-convention
17948 @kindex show sh calling-convention
17949 Show the current calling convention setting.
17950
17951 @end table
17952
17953
17954 @node Architectures
17955 @section Architectures
17956
17957 This section describes characteristics of architectures that affect
17958 all uses of @value{GDBN} with the architecture, both native and cross.
17959
17960 @menu
17961 * i386::
17962 * A29K::
17963 * Alpha::
17964 * MIPS::
17965 * HPPA:: HP PA architecture
17966 * SPU:: Cell Broadband Engine SPU architecture
17967 * PowerPC::
17968 @end menu
17969
17970 @node i386
17971 @subsection x86 Architecture-specific Issues
17972
17973 @table @code
17974 @item set struct-convention @var{mode}
17975 @kindex set struct-convention
17976 @cindex struct return convention
17977 @cindex struct/union returned in registers
17978 Set the convention used by the inferior to return @code{struct}s and
17979 @code{union}s from functions to @var{mode}. Possible values of
17980 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
17981 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
17982 are returned on the stack, while @code{"reg"} means that a
17983 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
17984 be returned in a register.
17985
17986 @item show struct-convention
17987 @kindex show struct-convention
17988 Show the current setting of the convention to return @code{struct}s
17989 from functions.
17990 @end table
17991
17992 @node A29K
17993 @subsection A29K
17994
17995 @table @code
17996
17997 @kindex set rstack_high_address
17998 @cindex AMD 29K register stack
17999 @cindex register stack, AMD29K
18000 @item set rstack_high_address @var{address}
18001 On AMD 29000 family processors, registers are saved in a separate
18002 @dfn{register stack}. There is no way for @value{GDBN} to determine the
18003 extent of this stack. Normally, @value{GDBN} just assumes that the
18004 stack is ``large enough''. This may result in @value{GDBN} referencing
18005 memory locations that do not exist. If necessary, you can get around
18006 this problem by specifying the ending address of the register stack with
18007 the @code{set rstack_high_address} command. The argument should be an
18008 address, which you probably want to precede with @samp{0x} to specify in
18009 hexadecimal.
18010
18011 @kindex show rstack_high_address
18012 @item show rstack_high_address
18013 Display the current limit of the register stack, on AMD 29000 family
18014 processors.
18015
18016 @end table
18017
18018 @node Alpha
18019 @subsection Alpha
18020
18021 See the following section.
18022
18023 @node MIPS
18024 @subsection MIPS
18025
18026 @cindex stack on Alpha
18027 @cindex stack on MIPS
18028 @cindex Alpha stack
18029 @cindex MIPS stack
18030 Alpha- and MIPS-based computers use an unusual stack frame, which
18031 sometimes requires @value{GDBN} to search backward in the object code to
18032 find the beginning of a function.
18033
18034 @cindex response time, MIPS debugging
18035 To improve response time (especially for embedded applications, where
18036 @value{GDBN} may be restricted to a slow serial line for this search)
18037 you may want to limit the size of this search, using one of these
18038 commands:
18039
18040 @table @code
18041 @cindex @code{heuristic-fence-post} (Alpha, MIPS)
18042 @item set heuristic-fence-post @var{limit}
18043 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
18044 search for the beginning of a function. A value of @var{0} (the
18045 default) means there is no limit. However, except for @var{0}, the
18046 larger the limit the more bytes @code{heuristic-fence-post} must search
18047 and therefore the longer it takes to run. You should only need to use
18048 this command when debugging a stripped executable.
18049
18050 @item show heuristic-fence-post
18051 Display the current limit.
18052 @end table
18053
18054 @noindent
18055 These commands are available @emph{only} when @value{GDBN} is configured
18056 for debugging programs on Alpha or MIPS processors.
18057
18058 Several MIPS-specific commands are available when debugging MIPS
18059 programs:
18060
18061 @table @code
18062 @item set mips abi @var{arg}
18063 @kindex set mips abi
18064 @cindex set ABI for MIPS
18065 Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
18066 values of @var{arg} are:
18067
18068 @table @samp
18069 @item auto
18070 The default ABI associated with the current binary (this is the
18071 default).
18072 @item o32
18073 @item o64
18074 @item n32
18075 @item n64
18076 @item eabi32
18077 @item eabi64
18078 @item auto
18079 @end table
18080
18081 @item show mips abi
18082 @kindex show mips abi
18083 Show the MIPS ABI used by @value{GDBN} to debug the inferior.
18084
18085 @item set mipsfpu
18086 @itemx show mipsfpu
18087 @xref{MIPS Embedded, set mipsfpu}.
18088
18089 @item set mips mask-address @var{arg}
18090 @kindex set mips mask-address
18091 @cindex MIPS addresses, masking
18092 This command determines whether the most-significant 32 bits of 64-bit
18093 MIPS addresses are masked off. The argument @var{arg} can be
18094 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
18095 setting, which lets @value{GDBN} determine the correct value.
18096
18097 @item show mips mask-address
18098 @kindex show mips mask-address
18099 Show whether the upper 32 bits of MIPS addresses are masked off or
18100 not.
18101
18102 @item set remote-mips64-transfers-32bit-regs
18103 @kindex set remote-mips64-transfers-32bit-regs
18104 This command controls compatibility with 64-bit MIPS targets that
18105 transfer data in 32-bit quantities. If you have an old MIPS 64 target
18106 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
18107 and 64 bits for other registers, set this option to @samp{on}.
18108
18109 @item show remote-mips64-transfers-32bit-regs
18110 @kindex show remote-mips64-transfers-32bit-regs
18111 Show the current setting of compatibility with older MIPS 64 targets.
18112
18113 @item set debug mips
18114 @kindex set debug mips
18115 This command turns on and off debugging messages for the MIPS-specific
18116 target code in @value{GDBN}.
18117
18118 @item show debug mips
18119 @kindex show debug mips
18120 Show the current setting of MIPS debugging messages.
18121 @end table
18122
18123
18124 @node HPPA
18125 @subsection HPPA
18126 @cindex HPPA support
18127
18128 When @value{GDBN} is debugging the HP PA architecture, it provides the
18129 following special commands:
18130
18131 @table @code
18132 @item set debug hppa
18133 @kindex set debug hppa
18134 This command determines whether HPPA architecture-specific debugging
18135 messages are to be displayed.
18136
18137 @item show debug hppa
18138 Show whether HPPA debugging messages are displayed.
18139
18140 @item maint print unwind @var{address}
18141 @kindex maint print unwind@r{, HPPA}
18142 This command displays the contents of the unwind table entry at the
18143 given @var{address}.
18144
18145 @end table
18146
18147
18148 @node SPU
18149 @subsection Cell Broadband Engine SPU architecture
18150 @cindex Cell Broadband Engine
18151 @cindex SPU
18152
18153 When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
18154 it provides the following special commands:
18155
18156 @table @code
18157 @item info spu event
18158 @kindex info spu
18159 Display SPU event facility status. Shows current event mask
18160 and pending event status.
18161
18162 @item info spu signal
18163 Display SPU signal notification facility status. Shows pending
18164 signal-control word and signal notification mode of both signal
18165 notification channels.
18166
18167 @item info spu mailbox
18168 Display SPU mailbox facility status. Shows all pending entries,
18169 in order of processing, in each of the SPU Write Outbound,
18170 SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
18171
18172 @item info spu dma
18173 Display MFC DMA status. Shows all pending commands in the MFC
18174 DMA queue. For each entry, opcode, tag, class IDs, effective
18175 and local store addresses and transfer size are shown.
18176
18177 @item info spu proxydma
18178 Display MFC Proxy-DMA status. Shows all pending commands in the MFC
18179 Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
18180 and local store addresses and transfer size are shown.
18181
18182 @end table
18183
18184 When @value{GDBN} is debugging a combined PowerPC/SPU application
18185 on the Cell Broadband Engine, it provides in addition the following
18186 special commands:
18187
18188 @table @code
18189 @item set spu stop-on-load @var{arg}
18190 @kindex set spu
18191 Set whether to stop for new SPE threads. When set to @code{on}, @value{GDBN}
18192 will give control to the user when a new SPE thread enters its @code{main}
18193 function. The default is @code{off}.
18194
18195 @item show spu stop-on-load
18196 @kindex show spu
18197 Show whether to stop for new SPE threads.
18198
18199 @item set spu auto-flush-cache @var{arg}
18200 Set whether to automatically flush the software-managed cache. When set to
18201 @code{on}, @value{GDBN} will automatically cause the SPE software-managed
18202 cache to be flushed whenever SPE execution stops. This provides a consistent
18203 view of PowerPC memory that is accessed via the cache. If an application
18204 does not use the software-managed cache, this option has no effect.
18205
18206 @item show spu auto-flush-cache
18207 Show whether to automatically flush the software-managed cache.
18208
18209 @end table
18210
18211 @node PowerPC
18212 @subsection PowerPC
18213 @cindex PowerPC architecture
18214
18215 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
18216 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
18217 numbers stored in the floating point registers. These values must be stored
18218 in two consecutive registers, always starting at an even register like
18219 @code{f0} or @code{f2}.
18220
18221 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
18222 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
18223 @code{f2} and @code{f3} for @code{$dl1} and so on.
18224
18225 For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
18226 wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
18227
18228
18229 @node Controlling GDB
18230 @chapter Controlling @value{GDBN}
18231
18232 You can alter the way @value{GDBN} interacts with you by using the
18233 @code{set} command. For commands controlling how @value{GDBN} displays
18234 data, see @ref{Print Settings, ,Print Settings}. Other settings are
18235 described here.
18236
18237 @menu
18238 * Prompt:: Prompt
18239 * Editing:: Command editing
18240 * Command History:: Command history
18241 * Screen Size:: Screen size
18242 * Numbers:: Numbers
18243 * ABI:: Configuring the current ABI
18244 * Messages/Warnings:: Optional warnings and messages
18245 * Debugging Output:: Optional messages about internal happenings
18246 * Other Misc Settings:: Other Miscellaneous Settings
18247 @end menu
18248
18249 @node Prompt
18250 @section Prompt
18251
18252 @cindex prompt
18253
18254 @value{GDBN} indicates its readiness to read a command by printing a string
18255 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
18256 can change the prompt string with the @code{set prompt} command. For
18257 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
18258 the prompt in one of the @value{GDBN} sessions so that you can always tell
18259 which one you are talking to.
18260
18261 @emph{Note:} @code{set prompt} does not add a space for you after the
18262 prompt you set. This allows you to set a prompt which ends in a space
18263 or a prompt that does not.
18264
18265 @table @code
18266 @kindex set prompt
18267 @item set prompt @var{newprompt}
18268 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
18269
18270 @kindex show prompt
18271 @item show prompt
18272 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
18273 @end table
18274
18275 @node Editing
18276 @section Command Editing
18277 @cindex readline
18278 @cindex command line editing
18279
18280 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
18281 @sc{gnu} library provides consistent behavior for programs which provide a
18282 command line interface to the user. Advantages are @sc{gnu} Emacs-style
18283 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
18284 substitution, and a storage and recall of command history across
18285 debugging sessions.
18286
18287 You may control the behavior of command line editing in @value{GDBN} with the
18288 command @code{set}.
18289
18290 @table @code
18291 @kindex set editing
18292 @cindex editing
18293 @item set editing
18294 @itemx set editing on
18295 Enable command line editing (enabled by default).
18296
18297 @item set editing off
18298 Disable command line editing.
18299
18300 @kindex show editing
18301 @item show editing
18302 Show whether command line editing is enabled.
18303 @end table
18304
18305 @xref{Command Line Editing}, for more details about the Readline
18306 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
18307 encouraged to read that chapter.
18308
18309 @node Command History
18310 @section Command History
18311 @cindex command history
18312
18313 @value{GDBN} can keep track of the commands you type during your
18314 debugging sessions, so that you can be certain of precisely what
18315 happened. Use these commands to manage the @value{GDBN} command
18316 history facility.
18317
18318 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
18319 package, to provide the history facility. @xref{Using History
18320 Interactively}, for the detailed description of the History library.
18321
18322 To issue a command to @value{GDBN} without affecting certain aspects of
18323 the state which is seen by users, prefix it with @samp{server }
18324 (@pxref{Server Prefix}). This
18325 means that this command will not affect the command history, nor will it
18326 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
18327 pressed on a line by itself.
18328
18329 @cindex @code{server}, command prefix
18330 The server prefix does not affect the recording of values into the value
18331 history; to print a value without recording it into the value history,
18332 use the @code{output} command instead of the @code{print} command.
18333
18334 Here is the description of @value{GDBN} commands related to command
18335 history.
18336
18337 @table @code
18338 @cindex history substitution
18339 @cindex history file
18340 @kindex set history filename
18341 @cindex @env{GDBHISTFILE}, environment variable
18342 @item set history filename @var{fname}
18343 Set the name of the @value{GDBN} command history file to @var{fname}.
18344 This is the file where @value{GDBN} reads an initial command history
18345 list, and where it writes the command history from this session when it
18346 exits. You can access this list through history expansion or through
18347 the history command editing characters listed below. This file defaults
18348 to the value of the environment variable @code{GDBHISTFILE}, or to
18349 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
18350 is not set.
18351
18352 @cindex save command history
18353 @kindex set history save
18354 @item set history save
18355 @itemx set history save on
18356 Record command history in a file, whose name may be specified with the
18357 @code{set history filename} command. By default, this option is disabled.
18358
18359 @item set history save off
18360 Stop recording command history in a file.
18361
18362 @cindex history size
18363 @kindex set history size
18364 @cindex @env{HISTSIZE}, environment variable
18365 @item set history size @var{size}
18366 Set the number of commands which @value{GDBN} keeps in its history list.
18367 This defaults to the value of the environment variable
18368 @code{HISTSIZE}, or to 256 if this variable is not set.
18369 @end table
18370
18371 History expansion assigns special meaning to the character @kbd{!}.
18372 @xref{Event Designators}, for more details.
18373
18374 @cindex history expansion, turn on/off
18375 Since @kbd{!} is also the logical not operator in C, history expansion
18376 is off by default. If you decide to enable history expansion with the
18377 @code{set history expansion on} command, you may sometimes need to
18378 follow @kbd{!} (when it is used as logical not, in an expression) with
18379 a space or a tab to prevent it from being expanded. The readline
18380 history facilities do not attempt substitution on the strings
18381 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
18382
18383 The commands to control history expansion are:
18384
18385 @table @code
18386 @item set history expansion on
18387 @itemx set history expansion
18388 @kindex set history expansion
18389 Enable history expansion. History expansion is off by default.
18390
18391 @item set history expansion off
18392 Disable history expansion.
18393
18394 @c @group
18395 @kindex show history
18396 @item show history
18397 @itemx show history filename
18398 @itemx show history save
18399 @itemx show history size
18400 @itemx show history expansion
18401 These commands display the state of the @value{GDBN} history parameters.
18402 @code{show history} by itself displays all four states.
18403 @c @end group
18404 @end table
18405
18406 @table @code
18407 @kindex show commands
18408 @cindex show last commands
18409 @cindex display command history
18410 @item show commands
18411 Display the last ten commands in the command history.
18412
18413 @item show commands @var{n}
18414 Print ten commands centered on command number @var{n}.
18415
18416 @item show commands +
18417 Print ten commands just after the commands last printed.
18418 @end table
18419
18420 @node Screen Size
18421 @section Screen Size
18422 @cindex size of screen
18423 @cindex pauses in output
18424
18425 Certain commands to @value{GDBN} may produce large amounts of
18426 information output to the screen. To help you read all of it,
18427 @value{GDBN} pauses and asks you for input at the end of each page of
18428 output. Type @key{RET} when you want to continue the output, or @kbd{q}
18429 to discard the remaining output. Also, the screen width setting
18430 determines when to wrap lines of output. Depending on what is being
18431 printed, @value{GDBN} tries to break the line at a readable place,
18432 rather than simply letting it overflow onto the following line.
18433
18434 Normally @value{GDBN} knows the size of the screen from the terminal
18435 driver software. For example, on Unix @value{GDBN} uses the termcap data base
18436 together with the value of the @code{TERM} environment variable and the
18437 @code{stty rows} and @code{stty cols} settings. If this is not correct,
18438 you can override it with the @code{set height} and @code{set
18439 width} commands:
18440
18441 @table @code
18442 @kindex set height
18443 @kindex set width
18444 @kindex show width
18445 @kindex show height
18446 @item set height @var{lpp}
18447 @itemx show height
18448 @itemx set width @var{cpl}
18449 @itemx show width
18450 These @code{set} commands specify a screen height of @var{lpp} lines and
18451 a screen width of @var{cpl} characters. The associated @code{show}
18452 commands display the current settings.
18453
18454 If you specify a height of zero lines, @value{GDBN} does not pause during
18455 output no matter how long the output is. This is useful if output is to a
18456 file or to an editor buffer.
18457
18458 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
18459 from wrapping its output.
18460
18461 @item set pagination on
18462 @itemx set pagination off
18463 @kindex set pagination
18464 Turn the output pagination on or off; the default is on. Turning
18465 pagination off is the alternative to @code{set height 0}.
18466
18467 @item show pagination
18468 @kindex show pagination
18469 Show the current pagination mode.
18470 @end table
18471
18472 @node Numbers
18473 @section Numbers
18474 @cindex number representation
18475 @cindex entering numbers
18476
18477 You can always enter numbers in octal, decimal, or hexadecimal in
18478 @value{GDBN} by the usual conventions: octal numbers begin with
18479 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
18480 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
18481 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
18482 10; likewise, the default display for numbers---when no particular
18483 format is specified---is base 10. You can change the default base for
18484 both input and output with the commands described below.
18485
18486 @table @code
18487 @kindex set input-radix
18488 @item set input-radix @var{base}
18489 Set the default base for numeric input. Supported choices
18490 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
18491 specified either unambiguously or using the current input radix; for
18492 example, any of
18493
18494 @smallexample
18495 set input-radix 012
18496 set input-radix 10.
18497 set input-radix 0xa
18498 @end smallexample
18499
18500 @noindent
18501 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
18502 leaves the input radix unchanged, no matter what it was, since
18503 @samp{10}, being without any leading or trailing signs of its base, is
18504 interpreted in the current radix. Thus, if the current radix is 16,
18505 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
18506 change the radix.
18507
18508 @kindex set output-radix
18509 @item set output-radix @var{base}
18510 Set the default base for numeric display. Supported choices
18511 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
18512 specified either unambiguously or using the current input radix.
18513
18514 @kindex show input-radix
18515 @item show input-radix
18516 Display the current default base for numeric input.
18517
18518 @kindex show output-radix
18519 @item show output-radix
18520 Display the current default base for numeric display.
18521
18522 @item set radix @r{[}@var{base}@r{]}
18523 @itemx show radix
18524 @kindex set radix
18525 @kindex show radix
18526 These commands set and show the default base for both input and output
18527 of numbers. @code{set radix} sets the radix of input and output to
18528 the same base; without an argument, it resets the radix back to its
18529 default value of 10.
18530
18531 @end table
18532
18533 @node ABI
18534 @section Configuring the Current ABI
18535
18536 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
18537 application automatically. However, sometimes you need to override its
18538 conclusions. Use these commands to manage @value{GDBN}'s view of the
18539 current ABI.
18540
18541 @cindex OS ABI
18542 @kindex set osabi
18543 @kindex show osabi
18544
18545 One @value{GDBN} configuration can debug binaries for multiple operating
18546 system targets, either via remote debugging or native emulation.
18547 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
18548 but you can override its conclusion using the @code{set osabi} command.
18549 One example where this is useful is in debugging of binaries which use
18550 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
18551 not have the same identifying marks that the standard C library for your
18552 platform provides.
18553
18554 @table @code
18555 @item show osabi
18556 Show the OS ABI currently in use.
18557
18558 @item set osabi
18559 With no argument, show the list of registered available OS ABI's.
18560
18561 @item set osabi @var{abi}
18562 Set the current OS ABI to @var{abi}.
18563 @end table
18564
18565 @cindex float promotion
18566
18567 Generally, the way that an argument of type @code{float} is passed to a
18568 function depends on whether the function is prototyped. For a prototyped
18569 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
18570 according to the architecture's convention for @code{float}. For unprototyped
18571 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
18572 @code{double} and then passed.
18573
18574 Unfortunately, some forms of debug information do not reliably indicate whether
18575 a function is prototyped. If @value{GDBN} calls a function that is not marked
18576 as prototyped, it consults @kbd{set coerce-float-to-double}.
18577
18578 @table @code
18579 @kindex set coerce-float-to-double
18580 @item set coerce-float-to-double
18581 @itemx set coerce-float-to-double on
18582 Arguments of type @code{float} will be promoted to @code{double} when passed
18583 to an unprototyped function. This is the default setting.
18584
18585 @item set coerce-float-to-double off
18586 Arguments of type @code{float} will be passed directly to unprototyped
18587 functions.
18588
18589 @kindex show coerce-float-to-double
18590 @item show coerce-float-to-double
18591 Show the current setting of promoting @code{float} to @code{double}.
18592 @end table
18593
18594 @kindex set cp-abi
18595 @kindex show cp-abi
18596 @value{GDBN} needs to know the ABI used for your program's C@t{++}
18597 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
18598 used to build your application. @value{GDBN} only fully supports
18599 programs with a single C@t{++} ABI; if your program contains code using
18600 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
18601 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
18602 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
18603 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
18604 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
18605 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
18606 ``auto''.
18607
18608 @table @code
18609 @item show cp-abi
18610 Show the C@t{++} ABI currently in use.
18611
18612 @item set cp-abi
18613 With no argument, show the list of supported C@t{++} ABI's.
18614
18615 @item set cp-abi @var{abi}
18616 @itemx set cp-abi auto
18617 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
18618 @end table
18619
18620 @node Messages/Warnings
18621 @section Optional Warnings and Messages
18622
18623 @cindex verbose operation
18624 @cindex optional warnings
18625 By default, @value{GDBN} is silent about its inner workings. If you are
18626 running on a slow machine, you may want to use the @code{set verbose}
18627 command. This makes @value{GDBN} tell you when it does a lengthy
18628 internal operation, so you will not think it has crashed.
18629
18630 Currently, the messages controlled by @code{set verbose} are those
18631 which announce that the symbol table for a source file is being read;
18632 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
18633
18634 @table @code
18635 @kindex set verbose
18636 @item set verbose on
18637 Enables @value{GDBN} output of certain informational messages.
18638
18639 @item set verbose off
18640 Disables @value{GDBN} output of certain informational messages.
18641
18642 @kindex show verbose
18643 @item show verbose
18644 Displays whether @code{set verbose} is on or off.
18645 @end table
18646
18647 By default, if @value{GDBN} encounters bugs in the symbol table of an
18648 object file, it is silent; but if you are debugging a compiler, you may
18649 find this information useful (@pxref{Symbol Errors, ,Errors Reading
18650 Symbol Files}).
18651
18652 @table @code
18653
18654 @kindex set complaints
18655 @item set complaints @var{limit}
18656 Permits @value{GDBN} to output @var{limit} complaints about each type of
18657 unusual symbols before becoming silent about the problem. Set
18658 @var{limit} to zero to suppress all complaints; set it to a large number
18659 to prevent complaints from being suppressed.
18660
18661 @kindex show complaints
18662 @item show complaints
18663 Displays how many symbol complaints @value{GDBN} is permitted to produce.
18664
18665 @end table
18666
18667 @anchor{confirmation requests}
18668 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
18669 lot of stupid questions to confirm certain commands. For example, if
18670 you try to run a program which is already running:
18671
18672 @smallexample
18673 (@value{GDBP}) run
18674 The program being debugged has been started already.
18675 Start it from the beginning? (y or n)
18676 @end smallexample
18677
18678 If you are willing to unflinchingly face the consequences of your own
18679 commands, you can disable this ``feature'':
18680
18681 @table @code
18682
18683 @kindex set confirm
18684 @cindex flinching
18685 @cindex confirmation
18686 @cindex stupid questions
18687 @item set confirm off
18688 Disables confirmation requests.
18689
18690 @item set confirm on
18691 Enables confirmation requests (the default).
18692
18693 @kindex show confirm
18694 @item show confirm
18695 Displays state of confirmation requests.
18696
18697 @end table
18698
18699 @cindex command tracing
18700 If you need to debug user-defined commands or sourced files you may find it
18701 useful to enable @dfn{command tracing}. In this mode each command will be
18702 printed as it is executed, prefixed with one or more @samp{+} symbols, the
18703 quantity denoting the call depth of each command.
18704
18705 @table @code
18706 @kindex set trace-commands
18707 @cindex command scripts, debugging
18708 @item set trace-commands on
18709 Enable command tracing.
18710 @item set trace-commands off
18711 Disable command tracing.
18712 @item show trace-commands
18713 Display the current state of command tracing.
18714 @end table
18715
18716 @node Debugging Output
18717 @section Optional Messages about Internal Happenings
18718 @cindex optional debugging messages
18719
18720 @value{GDBN} has commands that enable optional debugging messages from
18721 various @value{GDBN} subsystems; normally these commands are of
18722 interest to @value{GDBN} maintainers, or when reporting a bug. This
18723 section documents those commands.
18724
18725 @table @code
18726 @kindex set exec-done-display
18727 @item set exec-done-display
18728 Turns on or off the notification of asynchronous commands'
18729 completion. When on, @value{GDBN} will print a message when an
18730 asynchronous command finishes its execution. The default is off.
18731 @kindex show exec-done-display
18732 @item show exec-done-display
18733 Displays the current setting of asynchronous command completion
18734 notification.
18735 @kindex set debug
18736 @cindex gdbarch debugging info
18737 @cindex architecture debugging info
18738 @item set debug arch
18739 Turns on or off display of gdbarch debugging info. The default is off
18740 @kindex show debug
18741 @item show debug arch
18742 Displays the current state of displaying gdbarch debugging info.
18743 @item set debug aix-thread
18744 @cindex AIX threads
18745 Display debugging messages about inner workings of the AIX thread
18746 module.
18747 @item show debug aix-thread
18748 Show the current state of AIX thread debugging info display.
18749 @item set debug dwarf2-die
18750 @cindex DWARF2 DIEs
18751 Dump DWARF2 DIEs after they are read in.
18752 The value is the number of nesting levels to print.
18753 A value of zero turns off the display.
18754 @item show debug dwarf2-die
18755 Show the current state of DWARF2 DIE debugging.
18756 @item set debug displaced
18757 @cindex displaced stepping debugging info
18758 Turns on or off display of @value{GDBN} debugging info for the
18759 displaced stepping support. The default is off.
18760 @item show debug displaced
18761 Displays the current state of displaying @value{GDBN} debugging info
18762 related to displaced stepping.
18763 @item set debug event
18764 @cindex event debugging info
18765 Turns on or off display of @value{GDBN} event debugging info. The
18766 default is off.
18767 @item show debug event
18768 Displays the current state of displaying @value{GDBN} event debugging
18769 info.
18770 @item set debug expression
18771 @cindex expression debugging info
18772 Turns on or off display of debugging info about @value{GDBN}
18773 expression parsing. The default is off.
18774 @item show debug expression
18775 Displays the current state of displaying debugging info about
18776 @value{GDBN} expression parsing.
18777 @item set debug frame
18778 @cindex frame debugging info
18779 Turns on or off display of @value{GDBN} frame debugging info. The
18780 default is off.
18781 @item show debug frame
18782 Displays the current state of displaying @value{GDBN} frame debugging
18783 info.
18784 @item set debug gnu-nat
18785 @cindex @sc{gnu}/Hurd debug messages
18786 Turns on or off debugging messages from the @sc{gnu}/Hurd debug support.
18787 @item show debug gnu-nat
18788 Show the current state of @sc{gnu}/Hurd debugging messages.
18789 @item set debug infrun
18790 @cindex inferior debugging info
18791 Turns on or off display of @value{GDBN} debugging info for running the inferior.
18792 The default is off. @file{infrun.c} contains GDB's runtime state machine used
18793 for implementing operations such as single-stepping the inferior.
18794 @item show debug infrun
18795 Displays the current state of @value{GDBN} inferior debugging.
18796 @item set debug lin-lwp
18797 @cindex @sc{gnu}/Linux LWP debug messages
18798 @cindex Linux lightweight processes
18799 Turns on or off debugging messages from the Linux LWP debug support.
18800 @item show debug lin-lwp
18801 Show the current state of Linux LWP debugging messages.
18802 @item set debug lin-lwp-async
18803 @cindex @sc{gnu}/Linux LWP async debug messages
18804 @cindex Linux lightweight processes
18805 Turns on or off debugging messages from the Linux LWP async debug support.
18806 @item show debug lin-lwp-async
18807 Show the current state of Linux LWP async debugging messages.
18808 @item set debug observer
18809 @cindex observer debugging info
18810 Turns on or off display of @value{GDBN} observer debugging. This
18811 includes info such as the notification of observable events.
18812 @item show debug observer
18813 Displays the current state of observer debugging.
18814 @item set debug overload
18815 @cindex C@t{++} overload debugging info
18816 Turns on or off display of @value{GDBN} C@t{++} overload debugging
18817 info. This includes info such as ranking of functions, etc. The default
18818 is off.
18819 @item show debug overload
18820 Displays the current state of displaying @value{GDBN} C@t{++} overload
18821 debugging info.
18822 @cindex packets, reporting on stdout
18823 @cindex serial connections, debugging
18824 @cindex debug remote protocol
18825 @cindex remote protocol debugging
18826 @cindex display remote packets
18827 @item set debug remote
18828 Turns on or off display of reports on all packets sent back and forth across
18829 the serial line to the remote machine. The info is printed on the
18830 @value{GDBN} standard output stream. The default is off.
18831 @item show debug remote
18832 Displays the state of display of remote packets.
18833 @item set debug serial
18834 Turns on or off display of @value{GDBN} serial debugging info. The
18835 default is off.
18836 @item show debug serial
18837 Displays the current state of displaying @value{GDBN} serial debugging
18838 info.
18839 @item set debug solib-frv
18840 @cindex FR-V shared-library debugging
18841 Turns on or off debugging messages for FR-V shared-library code.
18842 @item show debug solib-frv
18843 Display the current state of FR-V shared-library code debugging
18844 messages.
18845 @item set debug target
18846 @cindex target debugging info
18847 Turns on or off display of @value{GDBN} target debugging info. This info
18848 includes what is going on at the target level of GDB, as it happens. The
18849 default is 0. Set it to 1 to track events, and to 2 to also track the
18850 value of large memory transfers. Changes to this flag do not take effect
18851 until the next time you connect to a target or use the @code{run} command.
18852 @item show debug target
18853 Displays the current state of displaying @value{GDBN} target debugging
18854 info.
18855 @item set debug timestamp
18856 @cindex timestampping debugging info
18857 Turns on or off display of timestamps with @value{GDBN} debugging info.
18858 When enabled, seconds and microseconds are displayed before each debugging
18859 message.
18860 @item show debug timestamp
18861 Displays the current state of displaying timestamps with @value{GDBN}
18862 debugging info.
18863 @item set debugvarobj
18864 @cindex variable object debugging info
18865 Turns on or off display of @value{GDBN} variable object debugging
18866 info. The default is off.
18867 @item show debugvarobj
18868 Displays the current state of displaying @value{GDBN} variable object
18869 debugging info.
18870 @item set debug xml
18871 @cindex XML parser debugging
18872 Turns on or off debugging messages for built-in XML parsers.
18873 @item show debug xml
18874 Displays the current state of XML debugging messages.
18875 @end table
18876
18877 @node Other Misc Settings
18878 @section Other Miscellaneous Settings
18879 @cindex miscellaneous settings
18880
18881 @table @code
18882 @kindex set interactive-mode
18883 @item set interactive-mode
18884 If @code{on}, forces @value{GDBN} to operate interactively.
18885 If @code{off}, forces @value{GDBN} to operate non-interactively,
18886 If @code{auto} (the default), @value{GDBN} guesses which mode to use,
18887 based on whether the debugger was started in a terminal or not.
18888
18889 In the vast majority of cases, the debugger should be able to guess
18890 correctly which mode should be used. But this setting can be useful
18891 in certain specific cases, such as running a MinGW @value{GDBN}
18892 inside a cygwin window.
18893
18894 @kindex show interactive-mode
18895 @item show interactive-mode
18896 Displays whether the debugger is operating in interactive mode or not.
18897 @end table
18898
18899 @node Extending GDB
18900 @chapter Extending @value{GDBN}
18901 @cindex extending GDB
18902
18903 @value{GDBN} provides two mechanisms for extension. The first is based
18904 on composition of @value{GDBN} commands, and the second is based on the
18905 Python scripting language.
18906
18907 @menu
18908 * Sequences:: Canned Sequences of Commands
18909 * Python:: Scripting @value{GDBN} using Python
18910 @end menu
18911
18912 @node Sequences
18913 @section Canned Sequences of Commands
18914
18915 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
18916 Command Lists}), @value{GDBN} provides two ways to store sequences of
18917 commands for execution as a unit: user-defined commands and command
18918 files.
18919
18920 @menu
18921 * Define:: How to define your own commands
18922 * Hooks:: Hooks for user-defined commands
18923 * Command Files:: How to write scripts of commands to be stored in a file
18924 * Output:: Commands for controlled output
18925 @end menu
18926
18927 @node Define
18928 @subsection User-defined Commands
18929
18930 @cindex user-defined command
18931 @cindex arguments, to user-defined commands
18932 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
18933 which you assign a new name as a command. This is done with the
18934 @code{define} command. User commands may accept up to 10 arguments
18935 separated by whitespace. Arguments are accessed within the user command
18936 via @code{$arg0@dots{}$arg9}. A trivial example:
18937
18938 @smallexample
18939 define adder
18940 print $arg0 + $arg1 + $arg2
18941 end
18942 @end smallexample
18943
18944 @noindent
18945 To execute the command use:
18946
18947 @smallexample
18948 adder 1 2 3
18949 @end smallexample
18950
18951 @noindent
18952 This defines the command @code{adder}, which prints the sum of
18953 its three arguments. Note the arguments are text substitutions, so they may
18954 reference variables, use complex expressions, or even perform inferior
18955 functions calls.
18956
18957 @cindex argument count in user-defined commands
18958 @cindex how many arguments (user-defined commands)
18959 In addition, @code{$argc} may be used to find out how many arguments have
18960 been passed. This expands to a number in the range 0@dots{}10.
18961
18962 @smallexample
18963 define adder
18964 if $argc == 2
18965 print $arg0 + $arg1
18966 end
18967 if $argc == 3
18968 print $arg0 + $arg1 + $arg2
18969 end
18970 end
18971 @end smallexample
18972
18973 @table @code
18974
18975 @kindex define
18976 @item define @var{commandname}
18977 Define a command named @var{commandname}. If there is already a command
18978 by that name, you are asked to confirm that you want to redefine it.
18979 @var{commandname} may be a bare command name consisting of letters,
18980 numbers, dashes, and underscores. It may also start with any predefined
18981 prefix command. For example, @samp{define target my-target} creates
18982 a user-defined @samp{target my-target} command.
18983
18984 The definition of the command is made up of other @value{GDBN} command lines,
18985 which are given following the @code{define} command. The end of these
18986 commands is marked by a line containing @code{end}.
18987
18988 @kindex document
18989 @kindex end@r{ (user-defined commands)}
18990 @item document @var{commandname}
18991 Document the user-defined command @var{commandname}, so that it can be
18992 accessed by @code{help}. The command @var{commandname} must already be
18993 defined. This command reads lines of documentation just as @code{define}
18994 reads the lines of the command definition, ending with @code{end}.
18995 After the @code{document} command is finished, @code{help} on command
18996 @var{commandname} displays the documentation you have written.
18997
18998 You may use the @code{document} command again to change the
18999 documentation of a command. Redefining the command with @code{define}
19000 does not change the documentation.
19001
19002 @kindex dont-repeat
19003 @cindex don't repeat command
19004 @item dont-repeat
19005 Used inside a user-defined command, this tells @value{GDBN} that this
19006 command should not be repeated when the user hits @key{RET}
19007 (@pxref{Command Syntax, repeat last command}).
19008
19009 @kindex help user-defined
19010 @item help user-defined
19011 List all user-defined commands, with the first line of the documentation
19012 (if any) for each.
19013
19014 @kindex show user
19015 @item show user
19016 @itemx show user @var{commandname}
19017 Display the @value{GDBN} commands used to define @var{commandname} (but
19018 not its documentation). If no @var{commandname} is given, display the
19019 definitions for all user-defined commands.
19020
19021 @cindex infinite recursion in user-defined commands
19022 @kindex show max-user-call-depth
19023 @kindex set max-user-call-depth
19024 @item show max-user-call-depth
19025 @itemx set max-user-call-depth
19026 The value of @code{max-user-call-depth} controls how many recursion
19027 levels are allowed in user-defined commands before @value{GDBN} suspects an
19028 infinite recursion and aborts the command.
19029 @end table
19030
19031 In addition to the above commands, user-defined commands frequently
19032 use control flow commands, described in @ref{Command Files}.
19033
19034 When user-defined commands are executed, the
19035 commands of the definition are not printed. An error in any command
19036 stops execution of the user-defined command.
19037
19038 If used interactively, commands that would ask for confirmation proceed
19039 without asking when used inside a user-defined command. Many @value{GDBN}
19040 commands that normally print messages to say what they are doing omit the
19041 messages when used in a user-defined command.
19042
19043 @node Hooks
19044 @subsection User-defined Command Hooks
19045 @cindex command hooks
19046 @cindex hooks, for commands
19047 @cindex hooks, pre-command
19048
19049 @kindex hook
19050 You may define @dfn{hooks}, which are a special kind of user-defined
19051 command. Whenever you run the command @samp{foo}, if the user-defined
19052 command @samp{hook-foo} exists, it is executed (with no arguments)
19053 before that command.
19054
19055 @cindex hooks, post-command
19056 @kindex hookpost
19057 A hook may also be defined which is run after the command you executed.
19058 Whenever you run the command @samp{foo}, if the user-defined command
19059 @samp{hookpost-foo} exists, it is executed (with no arguments) after
19060 that command. Post-execution hooks may exist simultaneously with
19061 pre-execution hooks, for the same command.
19062
19063 It is valid for a hook to call the command which it hooks. If this
19064 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
19065
19066 @c It would be nice if hookpost could be passed a parameter indicating
19067 @c if the command it hooks executed properly or not. FIXME!
19068
19069 @kindex stop@r{, a pseudo-command}
19070 In addition, a pseudo-command, @samp{stop} exists. Defining
19071 (@samp{hook-stop}) makes the associated commands execute every time
19072 execution stops in your program: before breakpoint commands are run,
19073 displays are printed, or the stack frame is printed.
19074
19075 For example, to ignore @code{SIGALRM} signals while
19076 single-stepping, but treat them normally during normal execution,
19077 you could define:
19078
19079 @smallexample
19080 define hook-stop
19081 handle SIGALRM nopass
19082 end
19083
19084 define hook-run
19085 handle SIGALRM pass
19086 end
19087
19088 define hook-continue
19089 handle SIGALRM pass
19090 end
19091 @end smallexample
19092
19093 As a further example, to hook at the beginning and end of the @code{echo}
19094 command, and to add extra text to the beginning and end of the message,
19095 you could define:
19096
19097 @smallexample
19098 define hook-echo
19099 echo <<<---
19100 end
19101
19102 define hookpost-echo
19103 echo --->>>\n
19104 end
19105
19106 (@value{GDBP}) echo Hello World
19107 <<<---Hello World--->>>
19108 (@value{GDBP})
19109
19110 @end smallexample
19111
19112 You can define a hook for any single-word command in @value{GDBN}, but
19113 not for command aliases; you should define a hook for the basic command
19114 name, e.g.@: @code{backtrace} rather than @code{bt}.
19115 @c FIXME! So how does Joe User discover whether a command is an alias
19116 @c or not?
19117 You can hook a multi-word command by adding @code{hook-} or
19118 @code{hookpost-} to the last word of the command, e.g.@:
19119 @samp{define target hook-remote} to add a hook to @samp{target remote}.
19120
19121 If an error occurs during the execution of your hook, execution of
19122 @value{GDBN} commands stops and @value{GDBN} issues a prompt
19123 (before the command that you actually typed had a chance to run).
19124
19125 If you try to define a hook which does not match any known command, you
19126 get a warning from the @code{define} command.
19127
19128 @node Command Files
19129 @subsection Command Files
19130
19131 @cindex command files
19132 @cindex scripting commands
19133 A command file for @value{GDBN} is a text file made of lines that are
19134 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
19135 also be included. An empty line in a command file does nothing; it
19136 does not mean to repeat the last command, as it would from the
19137 terminal.
19138
19139 You can request the execution of a command file with the @code{source}
19140 command:
19141
19142 @table @code
19143 @kindex source
19144 @cindex execute commands from a file
19145 @item source [@code{-v}] @var{filename}
19146 Execute the command file @var{filename}.
19147 @end table
19148
19149 The lines in a command file are generally executed sequentially,
19150 unless the order of execution is changed by one of the
19151 @emph{flow-control commands} described below. The commands are not
19152 printed as they are executed. An error in any command terminates
19153 execution of the command file and control is returned to the console.
19154
19155 @value{GDBN} searches for @var{filename} in the current directory and then
19156 on the search path (specified with the @samp{directory} command).
19157
19158 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
19159 each command as it is executed. The option must be given before
19160 @var{filename}, and is interpreted as part of the filename anywhere else.
19161
19162 Commands that would ask for confirmation if used interactively proceed
19163 without asking when used in a command file. Many @value{GDBN} commands that
19164 normally print messages to say what they are doing omit the messages
19165 when called from command files.
19166
19167 @value{GDBN} also accepts command input from standard input. In this
19168 mode, normal output goes to standard output and error output goes to
19169 standard error. Errors in a command file supplied on standard input do
19170 not terminate execution of the command file---execution continues with
19171 the next command.
19172
19173 @smallexample
19174 gdb < cmds > log 2>&1
19175 @end smallexample
19176
19177 (The syntax above will vary depending on the shell used.) This example
19178 will execute commands from the file @file{cmds}. All output and errors
19179 would be directed to @file{log}.
19180
19181 Since commands stored on command files tend to be more general than
19182 commands typed interactively, they frequently need to deal with
19183 complicated situations, such as different or unexpected values of
19184 variables and symbols, changes in how the program being debugged is
19185 built, etc. @value{GDBN} provides a set of flow-control commands to
19186 deal with these complexities. Using these commands, you can write
19187 complex scripts that loop over data structures, execute commands
19188 conditionally, etc.
19189
19190 @table @code
19191 @kindex if
19192 @kindex else
19193 @item if
19194 @itemx else
19195 This command allows to include in your script conditionally executed
19196 commands. The @code{if} command takes a single argument, which is an
19197 expression to evaluate. It is followed by a series of commands that
19198 are executed only if the expression is true (its value is nonzero).
19199 There can then optionally be an @code{else} line, followed by a series
19200 of commands that are only executed if the expression was false. The
19201 end of the list is marked by a line containing @code{end}.
19202
19203 @kindex while
19204 @item while
19205 This command allows to write loops. Its syntax is similar to
19206 @code{if}: the command takes a single argument, which is an expression
19207 to evaluate, and must be followed by the commands to execute, one per
19208 line, terminated by an @code{end}. These commands are called the
19209 @dfn{body} of the loop. The commands in the body of @code{while} are
19210 executed repeatedly as long as the expression evaluates to true.
19211
19212 @kindex loop_break
19213 @item loop_break
19214 This command exits the @code{while} loop in whose body it is included.
19215 Execution of the script continues after that @code{while}s @code{end}
19216 line.
19217
19218 @kindex loop_continue
19219 @item loop_continue
19220 This command skips the execution of the rest of the body of commands
19221 in the @code{while} loop in whose body it is included. Execution
19222 branches to the beginning of the @code{while} loop, where it evaluates
19223 the controlling expression.
19224
19225 @kindex end@r{ (if/else/while commands)}
19226 @item end
19227 Terminate the block of commands that are the body of @code{if},
19228 @code{else}, or @code{while} flow-control commands.
19229 @end table
19230
19231
19232 @node Output
19233 @subsection Commands for Controlled Output
19234
19235 During the execution of a command file or a user-defined command, normal
19236 @value{GDBN} output is suppressed; the only output that appears is what is
19237 explicitly printed by the commands in the definition. This section
19238 describes three commands useful for generating exactly the output you
19239 want.
19240
19241 @table @code
19242 @kindex echo
19243 @item echo @var{text}
19244 @c I do not consider backslash-space a standard C escape sequence
19245 @c because it is not in ANSI.
19246 Print @var{text}. Nonprinting characters can be included in
19247 @var{text} using C escape sequences, such as @samp{\n} to print a
19248 newline. @strong{No newline is printed unless you specify one.}
19249 In addition to the standard C escape sequences, a backslash followed
19250 by a space stands for a space. This is useful for displaying a
19251 string with spaces at the beginning or the end, since leading and
19252 trailing spaces are otherwise trimmed from all arguments.
19253 To print @samp{@w{ }and foo =@w{ }}, use the command
19254 @samp{echo \@w{ }and foo = \@w{ }}.
19255
19256 A backslash at the end of @var{text} can be used, as in C, to continue
19257 the command onto subsequent lines. For example,
19258
19259 @smallexample
19260 echo This is some text\n\
19261 which is continued\n\
19262 onto several lines.\n
19263 @end smallexample
19264
19265 produces the same output as
19266
19267 @smallexample
19268 echo This is some text\n
19269 echo which is continued\n
19270 echo onto several lines.\n
19271 @end smallexample
19272
19273 @kindex output
19274 @item output @var{expression}
19275 Print the value of @var{expression} and nothing but that value: no
19276 newlines, no @samp{$@var{nn} = }. The value is not entered in the
19277 value history either. @xref{Expressions, ,Expressions}, for more information
19278 on expressions.
19279
19280 @item output/@var{fmt} @var{expression}
19281 Print the value of @var{expression} in format @var{fmt}. You can use
19282 the same formats as for @code{print}. @xref{Output Formats,,Output
19283 Formats}, for more information.
19284
19285 @kindex printf
19286 @item printf @var{template}, @var{expressions}@dots{}
19287 Print the values of one or more @var{expressions} under the control of
19288 the string @var{template}. To print several values, make
19289 @var{expressions} be a comma-separated list of individual expressions,
19290 which may be either numbers or pointers. Their values are printed as
19291 specified by @var{template}, exactly as a C program would do by
19292 executing the code below:
19293
19294 @smallexample
19295 printf (@var{template}, @var{expressions}@dots{});
19296 @end smallexample
19297
19298 As in @code{C} @code{printf}, ordinary characters in @var{template}
19299 are printed verbatim, while @dfn{conversion specification} introduced
19300 by the @samp{%} character cause subsequent @var{expressions} to be
19301 evaluated, their values converted and formatted according to type and
19302 style information encoded in the conversion specifications, and then
19303 printed.
19304
19305 For example, you can print two values in hex like this:
19306
19307 @smallexample
19308 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
19309 @end smallexample
19310
19311 @code{printf} supports all the standard @code{C} conversion
19312 specifications, including the flags and modifiers between the @samp{%}
19313 character and the conversion letter, with the following exceptions:
19314
19315 @itemize @bullet
19316 @item
19317 The argument-ordering modifiers, such as @samp{2$}, are not supported.
19318
19319 @item
19320 The modifier @samp{*} is not supported for specifying precision or
19321 width.
19322
19323 @item
19324 The @samp{'} flag (for separation of digits into groups according to
19325 @code{LC_NUMERIC'}) is not supported.
19326
19327 @item
19328 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
19329 supported.
19330
19331 @item
19332 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
19333
19334 @item
19335 The conversion letters @samp{a} and @samp{A} are not supported.
19336 @end itemize
19337
19338 @noindent
19339 Note that the @samp{ll} type modifier is supported only if the
19340 underlying @code{C} implementation used to build @value{GDBN} supports
19341 the @code{long long int} type, and the @samp{L} type modifier is
19342 supported only if @code{long double} type is available.
19343
19344 As in @code{C}, @code{printf} supports simple backslash-escape
19345 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
19346 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
19347 single character. Octal and hexadecimal escape sequences are not
19348 supported.
19349
19350 Additionally, @code{printf} supports conversion specifications for DFP
19351 (@dfn{Decimal Floating Point}) types using the following length modifiers
19352 together with a floating point specifier.
19353 letters:
19354
19355 @itemize @bullet
19356 @item
19357 @samp{H} for printing @code{Decimal32} types.
19358
19359 @item
19360 @samp{D} for printing @code{Decimal64} types.
19361
19362 @item
19363 @samp{DD} for printing @code{Decimal128} types.
19364 @end itemize
19365
19366 If the underlying @code{C} implementation used to build @value{GDBN} has
19367 support for the three length modifiers for DFP types, other modifiers
19368 such as width and precision will also be available for @value{GDBN} to use.
19369
19370 In case there is no such @code{C} support, no additional modifiers will be
19371 available and the value will be printed in the standard way.
19372
19373 Here's an example of printing DFP types using the above conversion letters:
19374 @smallexample
19375 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
19376 @end smallexample
19377
19378 @end table
19379
19380 @node Python
19381 @section Scripting @value{GDBN} using Python
19382 @cindex python scripting
19383 @cindex scripting with python
19384
19385 You can script @value{GDBN} using the @uref{http://www.python.org/,
19386 Python programming language}. This feature is available only if
19387 @value{GDBN} was configured using @option{--with-python}.
19388
19389 @menu
19390 * Python Commands:: Accessing Python from @value{GDBN}.
19391 * Python API:: Accessing @value{GDBN} from Python.
19392 @end menu
19393
19394 @node Python Commands
19395 @subsection Python Commands
19396 @cindex python commands
19397 @cindex commands to access python
19398
19399 @value{GDBN} provides one command for accessing the Python interpreter,
19400 and one related setting:
19401
19402 @table @code
19403 @kindex python
19404 @item python @r{[}@var{code}@r{]}
19405 The @code{python} command can be used to evaluate Python code.
19406
19407 If given an argument, the @code{python} command will evaluate the
19408 argument as a Python command. For example:
19409
19410 @smallexample
19411 (@value{GDBP}) python print 23
19412 23
19413 @end smallexample
19414
19415 If you do not provide an argument to @code{python}, it will act as a
19416 multi-line command, like @code{define}. In this case, the Python
19417 script is made up of subsequent command lines, given after the
19418 @code{python} command. This command list is terminated using a line
19419 containing @code{end}. For example:
19420
19421 @smallexample
19422 (@value{GDBP}) python
19423 Type python script
19424 End with a line saying just "end".
19425 >print 23
19426 >end
19427 23
19428 @end smallexample
19429
19430 @kindex maint set python print-stack
19431 @item maint set python print-stack
19432 By default, @value{GDBN} will print a stack trace when an error occurs
19433 in a Python script. This can be controlled using @code{maint set
19434 python print-stack}: if @code{on}, the default, then Python stack
19435 printing is enabled; if @code{off}, then Python stack printing is
19436 disabled.
19437 @end table
19438
19439 @node Python API
19440 @subsection Python API
19441 @cindex python api
19442 @cindex programming in python
19443
19444 @cindex python stdout
19445 @cindex python pagination
19446 At startup, @value{GDBN} overrides Python's @code{sys.stdout} and
19447 @code{sys.stderr} to print using @value{GDBN}'s output-paging streams.
19448 A Python program which outputs to one of these streams may have its
19449 output interrupted by the user (@pxref{Screen Size}). In this
19450 situation, a Python @code{KeyboardInterrupt} exception is thrown.
19451
19452 @menu
19453 * Basic Python:: Basic Python Functions.
19454 * Exception Handling::
19455 * Auto-loading:: Automatically loading Python code.
19456 * Values From Inferior::
19457 * Types In Python:: Python representation of types.
19458 * Pretty Printing:: Pretty-printing values.
19459 * Selecting Pretty-Printers:: How GDB chooses a pretty-printer.
19460 * Commands In Python:: Implementing new commands in Python.
19461 * Functions In Python:: Writing new convenience functions.
19462 * Objfiles In Python:: Object files.
19463 * Frames In Python:: Acessing inferior stack frames from Python.
19464 * Lazy Strings In Python:: Python representation of lazy strings.
19465 @end menu
19466
19467 @node Basic Python
19468 @subsubsection Basic Python
19469
19470 @cindex python functions
19471 @cindex python module
19472 @cindex gdb module
19473 @value{GDBN} introduces a new Python module, named @code{gdb}. All
19474 methods and classes added by @value{GDBN} are placed in this module.
19475 @value{GDBN} automatically @code{import}s the @code{gdb} module for
19476 use in all scripts evaluated by the @code{python} command.
19477
19478 @findex gdb.execute
19479 @defun execute command [from_tty]
19480 Evaluate @var{command}, a string, as a @value{GDBN} CLI command.
19481 If a GDB exception happens while @var{command} runs, it is
19482 translated as described in @ref{Exception Handling,,Exception Handling}.
19483 If no exceptions occur, this function returns @code{None}.
19484
19485 @var{from_tty} specifies whether @value{GDBN} ought to consider this
19486 command as having originated from the user invoking it interactively.
19487 It must be a boolean value. If omitted, it defaults to @code{False}.
19488 @end defun
19489
19490 @findex gdb.parameter
19491 @defun parameter parameter
19492 Return the value of a @value{GDBN} parameter. @var{parameter} is a
19493 string naming the parameter to look up; @var{parameter} may contain
19494 spaces if the parameter has a multi-part name. For example,
19495 @samp{print object} is a valid parameter name.
19496
19497 If the named parameter does not exist, this function throws a
19498 @code{RuntimeError}. Otherwise, the parameter's value is converted to
19499 a Python value of the appropriate type, and returned.
19500 @end defun
19501
19502 @findex gdb.history
19503 @defun history number
19504 Return a value from @value{GDBN}'s value history (@pxref{Value
19505 History}). @var{number} indicates which history element to return.
19506 If @var{number} is negative, then @value{GDBN} will take its absolute value
19507 and count backward from the last element (i.e., the most recent element) to
19508 find the value to return. If @var{number} is zero, then @value{GDBN} will
19509 return the most recent element. If the element specified by @var{number}
19510 doesn't exist in the value history, a @code{RuntimeError} exception will be
19511 raised.
19512
19513 If no exception is raised, the return value is always an instance of
19514 @code{gdb.Value} (@pxref{Values From Inferior}).
19515 @end defun
19516
19517 @findex gdb.parse_and_eval
19518 @defun parse_and_eval expression
19519 Parse @var{expression} as an expression in the current language,
19520 evaluate it, and return the result as a @code{gdb.Value}.
19521 @var{expression} must be a string.
19522
19523 This function can be useful when implementing a new command
19524 (@pxref{Commands In Python}), as it provides a way to parse the
19525 command's argument as an expression. It is also useful simply to
19526 compute values, for example, it is the only way to get the value of a
19527 convenience variable (@pxref{Convenience Vars}) as a @code{gdb.Value}.
19528 @end defun
19529
19530 @findex gdb.write
19531 @defun write string
19532 Print a string to @value{GDBN}'s paginated standard output stream.
19533 Writing to @code{sys.stdout} or @code{sys.stderr} will automatically
19534 call this function.
19535 @end defun
19536
19537 @findex gdb.flush
19538 @defun flush
19539 Flush @value{GDBN}'s paginated standard output stream. Flushing
19540 @code{sys.stdout} or @code{sys.stderr} will automatically call this
19541 function.
19542 @end defun
19543
19544 @node Exception Handling
19545 @subsubsection Exception Handling
19546 @cindex python exceptions
19547 @cindex exceptions, python
19548
19549 When executing the @code{python} command, Python exceptions
19550 uncaught within the Python code are translated to calls to
19551 @value{GDBN} error-reporting mechanism. If the command that called
19552 @code{python} does not handle the error, @value{GDBN} will
19553 terminate it and print an error message containing the Python
19554 exception name, the associated value, and the Python call stack
19555 backtrace at the point where the exception was raised. Example:
19556
19557 @smallexample
19558 (@value{GDBP}) python print foo
19559 Traceback (most recent call last):
19560 File "<string>", line 1, in <module>
19561 NameError: name 'foo' is not defined
19562 @end smallexample
19563
19564 @value{GDBN} errors that happen in @value{GDBN} commands invoked by Python
19565 code are converted to Python @code{RuntimeError} exceptions. User
19566 interrupt (via @kbd{C-c} or by typing @kbd{q} at a pagination
19567 prompt) is translated to a Python @code{KeyboardInterrupt}
19568 exception. If you catch these exceptions in your Python code, your
19569 exception handler will see @code{RuntimeError} or
19570 @code{KeyboardInterrupt} as the exception type, the @value{GDBN} error
19571 message as its value, and the Python call stack backtrace at the
19572 Python statement closest to where the @value{GDBN} error occured as the
19573 traceback.
19574
19575 @node Auto-loading
19576 @subsubsection Auto-loading
19577 @cindex auto-loading, Python
19578
19579 When a new object file is read (for example, due to the @code{file}
19580 command, or because the inferior has loaded a shared library),
19581 @value{GDBN} will look for a file named @file{@var{objfile}-gdb.py},
19582 where @var{objfile} is the object file's real name, formed by ensuring
19583 that the file name is absolute, following all symlinks, and resolving
19584 @code{.} and @code{..} components. If this file exists and is
19585 readable, @value{GDBN} will evaluate it as a Python script.
19586
19587 If this file does not exist, and if the parameter
19588 @code{debug-file-directory} is set (@pxref{Separate Debug Files}),
19589 then @value{GDBN} will use for its each separated directory component
19590 @code{component} the file named @file{@code{component}/@var{real-name}}, where
19591 @var{real-name} is the object file's real name, as described above.
19592
19593 Finally, if this file does not exist, then @value{GDBN} will look for
19594 a file named @file{@var{data-directory}/python/auto-load/@var{real-name}}, where
19595 @var{data-directory} is @value{GDBN}'s data directory (available via
19596 @code{show data-directory}, @pxref{Data Files}), and @var{real-name}
19597 is the object file's real name, as described above.
19598
19599 When reading an auto-loaded file, @value{GDBN} sets the ``current
19600 objfile''. This is available via the @code{gdb.current_objfile}
19601 function (@pxref{Objfiles In Python}). This can be useful for
19602 registering objfile-specific pretty-printers.
19603
19604 The auto-loading feature is useful for supplying application-specific
19605 debugging commands and scripts. You can enable or disable this
19606 feature, and view its current state.
19607
19608 @table @code
19609 @kindex maint set python auto-load
19610 @item maint set python auto-load [yes|no]
19611 Enable or disable the Python auto-loading feature.
19612
19613 @kindex show python auto-load
19614 @item show python auto-load
19615 Show whether Python auto-loading is enabled or disabled.
19616 @end table
19617
19618 @value{GDBN} does not track which files it has already auto-loaded.
19619 So, your @samp{-gdb.py} file should take care to ensure that it may be
19620 evaluated multiple times without error.
19621
19622 @node Values From Inferior
19623 @subsubsection Values From Inferior
19624 @cindex values from inferior, with Python
19625 @cindex python, working with values from inferior
19626
19627 @cindex @code{gdb.Value}
19628 @value{GDBN} provides values it obtains from the inferior program in
19629 an object of type @code{gdb.Value}. @value{GDBN} uses this object
19630 for its internal bookkeeping of the inferior's values, and for
19631 fetching values when necessary.
19632
19633 Inferior values that are simple scalars can be used directly in
19634 Python expressions that are valid for the value's data type. Here's
19635 an example for an integer or floating-point value @code{some_val}:
19636
19637 @smallexample
19638 bar = some_val + 2
19639 @end smallexample
19640
19641 @noindent
19642 As result of this, @code{bar} will also be a @code{gdb.Value} object
19643 whose values are of the same type as those of @code{some_val}.
19644
19645 Inferior values that are structures or instances of some class can
19646 be accessed using the Python @dfn{dictionary syntax}. For example, if
19647 @code{some_val} is a @code{gdb.Value} instance holding a structure, you
19648 can access its @code{foo} element with:
19649
19650 @smallexample
19651 bar = some_val['foo']
19652 @end smallexample
19653
19654 Again, @code{bar} will also be a @code{gdb.Value} object.
19655
19656 The following attributes are provided:
19657
19658 @table @code
19659 @defivar Value address
19660 If this object is addressable, this read-only attribute holds a
19661 @code{gdb.Value} object representing the address. Otherwise,
19662 this attribute holds @code{None}.
19663 @end defivar
19664
19665 @cindex optimized out value in Python
19666 @defivar Value is_optimized_out
19667 This read-only boolean attribute is true if the compiler optimized out
19668 this value, thus it is not available for fetching from the inferior.
19669 @end defivar
19670
19671 @defivar Value type
19672 The type of this @code{gdb.Value}. The value of this attribute is a
19673 @code{gdb.Type} object.
19674 @end defivar
19675 @end table
19676
19677 The following methods are provided:
19678
19679 @table @code
19680 @defmethod Value cast type
19681 Return a new instance of @code{gdb.Value} that is the result of
19682 casting this instance to the type described by @var{type}, which must
19683 be a @code{gdb.Type} object. If the cast cannot be performed for some
19684 reason, this method throws an exception.
19685 @end defmethod
19686
19687 @defmethod Value dereference
19688 For pointer data types, this method returns a new @code{gdb.Value} object
19689 whose contents is the object pointed to by the pointer. For example, if
19690 @code{foo} is a C pointer to an @code{int}, declared in your C program as
19691
19692 @smallexample
19693 int *foo;
19694 @end smallexample
19695
19696 @noindent
19697 then you can use the corresponding @code{gdb.Value} to access what
19698 @code{foo} points to like this:
19699
19700 @smallexample
19701 bar = foo.dereference ()
19702 @end smallexample
19703
19704 The result @code{bar} will be a @code{gdb.Value} object holding the
19705 value pointed to by @code{foo}.
19706 @end defmethod
19707
19708 @defmethod Value string @r{[}encoding@r{]} @r{[}errors@r{]} @r{[}length@r{]}
19709 If this @code{gdb.Value} represents a string, then this method
19710 converts the contents to a Python string. Otherwise, this method will
19711 throw an exception.
19712
19713 Strings are recognized in a language-specific way; whether a given
19714 @code{gdb.Value} represents a string is determined by the current
19715 language.
19716
19717 For C-like languages, a value is a string if it is a pointer to or an
19718 array of characters or ints. The string is assumed to be terminated
19719 by a zero of the appropriate width. However if the optional length
19720 argument is given, the string will be converted to that given length,
19721 ignoring any embedded zeros that the string may contain.
19722
19723 If the optional @var{encoding} argument is given, it must be a string
19724 naming the encoding of the string in the @code{gdb.Value}, such as
19725 @code{"ascii"}, @code{"iso-8859-6"} or @code{"utf-8"}. It accepts
19726 the same encodings as the corresponding argument to Python's
19727 @code{string.decode} method, and the Python codec machinery will be used
19728 to convert the string. If @var{encoding} is not given, or if
19729 @var{encoding} is the empty string, then either the @code{target-charset}
19730 (@pxref{Character Sets}) will be used, or a language-specific encoding
19731 will be used, if the current language is able to supply one.
19732
19733 The optional @var{errors} argument is the same as the corresponding
19734 argument to Python's @code{string.decode} method.
19735
19736 If the optional @var{length} argument is given, the string will be
19737 fetched and converted to the given length.
19738 @end defmethod
19739
19740 @defmethod Value lazy_string @r{[}encoding@r{]} @r{[}length@r{]}
19741 If this @code{gdb.Value} represents a string, then this method
19742 converts the contents to a @code{gdb.LazyString} (@pxref{Lazy Strings
19743 In Python}). Otherwise, this method will throw an exception.
19744
19745 If the optional @var{encoding} argument is given, it must be a string
19746 naming the encoding of the @code{gdb.LazyString}. Some examples are:
19747 @samp{ascii}, @samp{iso-8859-6} or @samp{utf-8}. If the
19748 @var{encoding} argument is an encoding that @value{GDBN} does
19749 recognize, @value{GDBN} will raise an error.
19750
19751 When a lazy string is printed, the @value{GDBN} encoding machinery is
19752 used to convert the string during printing. If the optional
19753 @var{encoding} argument is not provided, or is an empty string,
19754 @value{GDBN} will automatically select the encoding most suitable for
19755 the string type. For further information on encoding in @value{GDBN}
19756 please see @ref{Character Sets}.
19757
19758 If the optional @var{length} argument is given, the string will be
19759 fetched and encoded to the length of characters specified. If
19760 the @var{length} argument is not provided, the string will be fetched
19761 and encoded until a null of appropriate width is found.
19762 @end defmethod
19763 @end table
19764
19765 @node Types In Python
19766 @subsubsection Types In Python
19767 @cindex types in Python
19768 @cindex Python, working with types
19769
19770 @tindex gdb.Type
19771 @value{GDBN} represents types from the inferior using the class
19772 @code{gdb.Type}.
19773
19774 The following type-related functions are available in the @code{gdb}
19775 module:
19776
19777 @findex gdb.lookup_type
19778 @defun lookup_type name [block]
19779 This function looks up a type by name. @var{name} is the name of the
19780 type to look up. It must be a string.
19781
19782 Ordinarily, this function will return an instance of @code{gdb.Type}.
19783 If the named type cannot be found, it will throw an exception.
19784 @end defun
19785
19786 An instance of @code{Type} has the following attributes:
19787
19788 @table @code
19789 @defivar Type code
19790 The type code for this type. The type code will be one of the
19791 @code{TYPE_CODE_} constants defined below.
19792 @end defivar
19793
19794 @defivar Type sizeof
19795 The size of this type, in target @code{char} units. Usually, a
19796 target's @code{char} type will be an 8-bit byte. However, on some
19797 unusual platforms, this type may have a different size.
19798 @end defivar
19799
19800 @defivar Type tag
19801 The tag name for this type. The tag name is the name after
19802 @code{struct}, @code{union}, or @code{enum} in C and C@t{++}; not all
19803 languages have this concept. If this type has no tag name, then
19804 @code{None} is returned.
19805 @end defivar
19806 @end table
19807
19808 The following methods are provided:
19809
19810 @table @code
19811 @defmethod Type fields
19812 For structure and union types, this method returns the fields. Range
19813 types have two fields, the minimum and maximum values. Enum types
19814 have one field per enum constant. Function and method types have one
19815 field per parameter. The base types of C@t{++} classes are also
19816 represented as fields. If the type has no fields, or does not fit
19817 into one of these categories, an empty sequence will be returned.
19818
19819 Each field is an object, with some pre-defined attributes:
19820 @table @code
19821 @item bitpos
19822 This attribute is not available for @code{static} fields (as in
19823 C@t{++} or Java). For non-@code{static} fields, the value is the bit
19824 position of the field.
19825
19826 @item name
19827 The name of the field, or @code{None} for anonymous fields.
19828
19829 @item artificial
19830 This is @code{True} if the field is artificial, usually meaning that
19831 it was provided by the compiler and not the user. This attribute is
19832 always provided, and is @code{False} if the field is not artificial.
19833
19834 @item is_base_class
19835 This is @code{True} if the field represents a base class of a C@t{++}
19836 structure. This attribute is always provided, and is @code{False}
19837 if the field is not a base class of the type that is the argument of
19838 @code{fields}, or if that type was not a C@t{++} class.
19839
19840 @item bitsize
19841 If the field is packed, or is a bitfield, then this will have a
19842 non-zero value, which is the size of the field in bits. Otherwise,
19843 this will be zero; in this case the field's size is given by its type.
19844
19845 @item type
19846 The type of the field. This is usually an instance of @code{Type},
19847 but it can be @code{None} in some situations.
19848 @end table
19849 @end defmethod
19850
19851 @defmethod Type const
19852 Return a new @code{gdb.Type} object which represents a
19853 @code{const}-qualified variant of this type.
19854 @end defmethod
19855
19856 @defmethod Type volatile
19857 Return a new @code{gdb.Type} object which represents a
19858 @code{volatile}-qualified variant of this type.
19859 @end defmethod
19860
19861 @defmethod Type unqualified
19862 Return a new @code{gdb.Type} object which represents an unqualified
19863 variant of this type. That is, the result is neither @code{const} nor
19864 @code{volatile}.
19865 @end defmethod
19866
19867 @defmethod Type range
19868 Return a Python @code{Tuple} object that contains two elements: the
19869 low bound of the argument type and the high bound of that type. If
19870 the type does not have a range, @value{GDBN} will raise a
19871 @code{RuntimeError} exception.
19872 @end defmethod
19873
19874 @defmethod Type reference
19875 Return a new @code{gdb.Type} object which represents a reference to this
19876 type.
19877 @end defmethod
19878
19879 @defmethod Type pointer
19880 Return a new @code{gdb.Type} object which represents a pointer to this
19881 type.
19882 @end defmethod
19883
19884 @defmethod Type strip_typedefs
19885 Return a new @code{gdb.Type} that represents the real type,
19886 after removing all layers of typedefs.
19887 @end defmethod
19888
19889 @defmethod Type target
19890 Return a new @code{gdb.Type} object which represents the target type
19891 of this type.
19892
19893 For a pointer type, the target type is the type of the pointed-to
19894 object. For an array type (meaning C-like arrays), the target type is
19895 the type of the elements of the array. For a function or method type,
19896 the target type is the type of the return value. For a complex type,
19897 the target type is the type of the elements. For a typedef, the
19898 target type is the aliased type.
19899
19900 If the type does not have a target, this method will throw an
19901 exception.
19902 @end defmethod
19903
19904 @defmethod Type template_argument n
19905 If this @code{gdb.Type} is an instantiation of a template, this will
19906 return a new @code{gdb.Type} which represents the type of the
19907 @var{n}th template argument.
19908
19909 If this @code{gdb.Type} is not a template type, this will throw an
19910 exception. Ordinarily, only C@t{++} code will have template types.
19911
19912 @var{name} is searched for globally.
19913 @end defmethod
19914 @end table
19915
19916
19917 Each type has a code, which indicates what category this type falls
19918 into. The available type categories are represented by constants
19919 defined in the @code{gdb} module:
19920
19921 @table @code
19922 @findex TYPE_CODE_PTR
19923 @findex gdb.TYPE_CODE_PTR
19924 @item TYPE_CODE_PTR
19925 The type is a pointer.
19926
19927 @findex TYPE_CODE_ARRAY
19928 @findex gdb.TYPE_CODE_ARRAY
19929 @item TYPE_CODE_ARRAY
19930 The type is an array.
19931
19932 @findex TYPE_CODE_STRUCT
19933 @findex gdb.TYPE_CODE_STRUCT
19934 @item TYPE_CODE_STRUCT
19935 The type is a structure.
19936
19937 @findex TYPE_CODE_UNION
19938 @findex gdb.TYPE_CODE_UNION
19939 @item TYPE_CODE_UNION
19940 The type is a union.
19941
19942 @findex TYPE_CODE_ENUM
19943 @findex gdb.TYPE_CODE_ENUM
19944 @item TYPE_CODE_ENUM
19945 The type is an enum.
19946
19947 @findex TYPE_CODE_FLAGS
19948 @findex gdb.TYPE_CODE_FLAGS
19949 @item TYPE_CODE_FLAGS
19950 A bit flags type, used for things such as status registers.
19951
19952 @findex TYPE_CODE_FUNC
19953 @findex gdb.TYPE_CODE_FUNC
19954 @item TYPE_CODE_FUNC
19955 The type is a function.
19956
19957 @findex TYPE_CODE_INT
19958 @findex gdb.TYPE_CODE_INT
19959 @item TYPE_CODE_INT
19960 The type is an integer type.
19961
19962 @findex TYPE_CODE_FLT
19963 @findex gdb.TYPE_CODE_FLT
19964 @item TYPE_CODE_FLT
19965 A floating point type.
19966
19967 @findex TYPE_CODE_VOID
19968 @findex gdb.TYPE_CODE_VOID
19969 @item TYPE_CODE_VOID
19970 The special type @code{void}.
19971
19972 @findex TYPE_CODE_SET
19973 @findex gdb.TYPE_CODE_SET
19974 @item TYPE_CODE_SET
19975 A Pascal set type.
19976
19977 @findex TYPE_CODE_RANGE
19978 @findex gdb.TYPE_CODE_RANGE
19979 @item TYPE_CODE_RANGE
19980 A range type, that is, an integer type with bounds.
19981
19982 @findex TYPE_CODE_STRING
19983 @findex gdb.TYPE_CODE_STRING
19984 @item TYPE_CODE_STRING
19985 A string type. Note that this is only used for certain languages with
19986 language-defined string types; C strings are not represented this way.
19987
19988 @findex TYPE_CODE_BITSTRING
19989 @findex gdb.TYPE_CODE_BITSTRING
19990 @item TYPE_CODE_BITSTRING
19991 A string of bits.
19992
19993 @findex TYPE_CODE_ERROR
19994 @findex gdb.TYPE_CODE_ERROR
19995 @item TYPE_CODE_ERROR
19996 An unknown or erroneous type.
19997
19998 @findex TYPE_CODE_METHOD
19999 @findex gdb.TYPE_CODE_METHOD
20000 @item TYPE_CODE_METHOD
20001 A method type, as found in C@t{++} or Java.
20002
20003 @findex TYPE_CODE_METHODPTR
20004 @findex gdb.TYPE_CODE_METHODPTR
20005 @item TYPE_CODE_METHODPTR
20006 A pointer-to-member-function.
20007
20008 @findex TYPE_CODE_MEMBERPTR
20009 @findex gdb.TYPE_CODE_MEMBERPTR
20010 @item TYPE_CODE_MEMBERPTR
20011 A pointer-to-member.
20012
20013 @findex TYPE_CODE_REF
20014 @findex gdb.TYPE_CODE_REF
20015 @item TYPE_CODE_REF
20016 A reference type.
20017
20018 @findex TYPE_CODE_CHAR
20019 @findex gdb.TYPE_CODE_CHAR
20020 @item TYPE_CODE_CHAR
20021 A character type.
20022
20023 @findex TYPE_CODE_BOOL
20024 @findex gdb.TYPE_CODE_BOOL
20025 @item TYPE_CODE_BOOL
20026 A boolean type.
20027
20028 @findex TYPE_CODE_COMPLEX
20029 @findex gdb.TYPE_CODE_COMPLEX
20030 @item TYPE_CODE_COMPLEX
20031 A complex float type.
20032
20033 @findex TYPE_CODE_TYPEDEF
20034 @findex gdb.TYPE_CODE_TYPEDEF
20035 @item TYPE_CODE_TYPEDEF
20036 A typedef to some other type.
20037
20038 @findex TYPE_CODE_NAMESPACE
20039 @findex gdb.TYPE_CODE_NAMESPACE
20040 @item TYPE_CODE_NAMESPACE
20041 A C@t{++} namespace.
20042
20043 @findex TYPE_CODE_DECFLOAT
20044 @findex gdb.TYPE_CODE_DECFLOAT
20045 @item TYPE_CODE_DECFLOAT
20046 A decimal floating point type.
20047
20048 @findex TYPE_CODE_INTERNAL_FUNCTION
20049 @findex gdb.TYPE_CODE_INTERNAL_FUNCTION
20050 @item TYPE_CODE_INTERNAL_FUNCTION
20051 A function internal to @value{GDBN}. This is the type used to represent
20052 convenience functions.
20053 @end table
20054
20055 @node Pretty Printing
20056 @subsubsection Pretty Printing
20057
20058 @value{GDBN} provides a mechanism to allow pretty-printing of values
20059 using Python code. The pretty-printer API allows application-specific
20060 code to greatly simplify the display of complex objects. This
20061 mechanism works for both MI and the CLI.
20062
20063 For example, here is how a C@t{++} @code{std::string} looks without a
20064 pretty-printer:
20065
20066 @smallexample
20067 (@value{GDBP}) print s
20068 $1 = @{
20069 static npos = 4294967295,
20070 _M_dataplus = @{
20071 <std::allocator<char>> = @{
20072 <__gnu_cxx::new_allocator<char>> = @{<No data fields>@}, <No data fields>@},
20073 members of std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Alloc_hider:
20074 _M_p = 0x804a014 "abcd"
20075 @}
20076 @}
20077 @end smallexample
20078
20079 After a pretty-printer for @code{std::string} has been installed, only
20080 the contents are printed:
20081
20082 @smallexample
20083 (@value{GDBP}) print s
20084 $2 = "abcd"
20085 @end smallexample
20086
20087 A pretty-printer is just an object that holds a value and implements a
20088 specific interface, defined here.
20089
20090 @defop Operation {pretty printer} children (self)
20091 @value{GDBN} will call this method on a pretty-printer to compute the
20092 children of the pretty-printer's value.
20093
20094 This method must return an object conforming to the Python iterator
20095 protocol. Each item returned by the iterator must be a tuple holding
20096 two elements. The first element is the ``name'' of the child; the
20097 second element is the child's value. The value can be any Python
20098 object which is convertible to a @value{GDBN} value.
20099
20100 This method is optional. If it does not exist, @value{GDBN} will act
20101 as though the value has no children.
20102 @end defop
20103
20104 @defop Operation {pretty printer} display_hint (self)
20105 The CLI may call this method and use its result to change the
20106 formatting of a value. The result will also be supplied to an MI
20107 consumer as a @samp{displayhint} attribute of the variable being
20108 printed.
20109
20110 This method is optional. If it does exist, this method must return a
20111 string.
20112
20113 Some display hints are predefined by @value{GDBN}:
20114
20115 @table @samp
20116 @item array
20117 Indicate that the object being printed is ``array-like''. The CLI
20118 uses this to respect parameters such as @code{set print elements} and
20119 @code{set print array}.
20120
20121 @item map
20122 Indicate that the object being printed is ``map-like'', and that the
20123 children of this value can be assumed to alternate between keys and
20124 values.
20125
20126 @item string
20127 Indicate that the object being printed is ``string-like''. If the
20128 printer's @code{to_string} method returns a Python string of some
20129 kind, then @value{GDBN} will call its internal language-specific
20130 string-printing function to format the string. For the CLI this means
20131 adding quotation marks, possibly escaping some characters, respecting
20132 @code{set print elements}, and the like.
20133 @end table
20134 @end defop
20135
20136 @defop Operation {pretty printer} to_string (self)
20137 @value{GDBN} will call this method to display the string
20138 representation of the value passed to the object's constructor.
20139
20140 When printing from the CLI, if the @code{to_string} method exists,
20141 then @value{GDBN} will prepend its result to the values returned by
20142 @code{children}. Exactly how this formatting is done is dependent on
20143 the display hint, and may change as more hints are added. Also,
20144 depending on the print settings (@pxref{Print Settings}), the CLI may
20145 print just the result of @code{to_string} in a stack trace, omitting
20146 the result of @code{children}.
20147
20148 If this method returns a string, it is printed verbatim.
20149
20150 Otherwise, if this method returns an instance of @code{gdb.Value},
20151 then @value{GDBN} prints this value. This may result in a call to
20152 another pretty-printer.
20153
20154 If instead the method returns a Python value which is convertible to a
20155 @code{gdb.Value}, then @value{GDBN} performs the conversion and prints
20156 the resulting value. Again, this may result in a call to another
20157 pretty-printer. Python scalars (integers, floats, and booleans) and
20158 strings are convertible to @code{gdb.Value}; other types are not.
20159
20160 If the result is not one of these types, an exception is raised.
20161 @end defop
20162
20163 @node Selecting Pretty-Printers
20164 @subsubsection Selecting Pretty-Printers
20165
20166 The Python list @code{gdb.pretty_printers} contains an array of
20167 functions that have been registered via addition as a pretty-printer.
20168 Each @code{gdb.Objfile} also contains a @code{pretty_printers}
20169 attribute.
20170
20171 A function on one of these lists is passed a single @code{gdb.Value}
20172 argument and should return a pretty-printer object conforming to the
20173 interface definition above (@pxref{Pretty Printing}). If a function
20174 cannot create a pretty-printer for the value, it should return
20175 @code{None}.
20176
20177 @value{GDBN} first checks the @code{pretty_printers} attribute of each
20178 @code{gdb.Objfile} and iteratively calls each function in the list for
20179 that @code{gdb.Objfile} until it receives a pretty-printer object.
20180 After these lists have been exhausted, it tries the global
20181 @code{gdb.pretty-printers} list, again calling each function until an
20182 object is returned.
20183
20184 The order in which the objfiles are searched is not specified. For a
20185 given list, functions are always invoked from the head of the list,
20186 and iterated over sequentially until the end of the list, or a printer
20187 object is returned.
20188
20189 Here is an example showing how a @code{std::string} printer might be
20190 written:
20191
20192 @smallexample
20193 class StdStringPrinter:
20194 "Print a std::string"
20195
20196 def __init__ (self, val):
20197 self.val = val
20198
20199 def to_string (self):
20200 return self.val['_M_dataplus']['_M_p']
20201
20202 def display_hint (self):
20203 return 'string'
20204 @end smallexample
20205
20206 And here is an example showing how a lookup function for the printer
20207 example above might be written.
20208
20209 @smallexample
20210 def str_lookup_function (val):
20211
20212 lookup_tag = val.type.tag
20213 regex = re.compile ("^std::basic_string<char,.*>$")
20214 if lookup_tag == None:
20215 return None
20216 if regex.match (lookup_tag):
20217 return StdStringPrinter (val)
20218
20219 return None
20220 @end smallexample
20221
20222 The example lookup function extracts the value's type, and attempts to
20223 match it to a type that it can pretty-print. If it is a type the
20224 printer can pretty-print, it will return a printer object. If not, it
20225 returns @code{None}.
20226
20227 We recommend that you put your core pretty-printers into a Python
20228 package. If your pretty-printers are for use with a library, we
20229 further recommend embedding a version number into the package name.
20230 This practice will enable @value{GDBN} to load multiple versions of
20231 your pretty-printers at the same time, because they will have
20232 different names.
20233
20234 You should write auto-loaded code (@pxref{Auto-loading}) such that it
20235 can be evaluated multiple times without changing its meaning. An
20236 ideal auto-load file will consist solely of @code{import}s of your
20237 printer modules, followed by a call to a register pretty-printers with
20238 the current objfile.
20239
20240 Taken as a whole, this approach will scale nicely to multiple
20241 inferiors, each potentially using a different library version.
20242 Embedding a version number in the Python package name will ensure that
20243 @value{GDBN} is able to load both sets of printers simultaneously.
20244 Then, because the search for pretty-printers is done by objfile, and
20245 because your auto-loaded code took care to register your library's
20246 printers with a specific objfile, @value{GDBN} will find the correct
20247 printers for the specific version of the library used by each
20248 inferior.
20249
20250 To continue the @code{std::string} example (@pxref{Pretty Printing}),
20251 this code might appear in @code{gdb.libstdcxx.v6}:
20252
20253 @smallexample
20254 def register_printers (objfile):
20255 objfile.pretty_printers.add (str_lookup_function)
20256 @end smallexample
20257
20258 @noindent
20259 And then the corresponding contents of the auto-load file would be:
20260
20261 @smallexample
20262 import gdb.libstdcxx.v6
20263 gdb.libstdcxx.v6.register_printers (gdb.current_objfile ())
20264 @end smallexample
20265
20266 @node Commands In Python
20267 @subsubsection Commands In Python
20268
20269 @cindex commands in python
20270 @cindex python commands
20271 You can implement new @value{GDBN} CLI commands in Python. A CLI
20272 command is implemented using an instance of the @code{gdb.Command}
20273 class, most commonly using a subclass.
20274
20275 @defmethod Command __init__ name @var{command_class} @r{[}@var{completer_class}@r{]} @r{[}@var{prefix}@r{]}
20276 The object initializer for @code{Command} registers the new command
20277 with @value{GDBN}. This initializer is normally invoked from the
20278 subclass' own @code{__init__} method.
20279
20280 @var{name} is the name of the command. If @var{name} consists of
20281 multiple words, then the initial words are looked for as prefix
20282 commands. In this case, if one of the prefix commands does not exist,
20283 an exception is raised.
20284
20285 There is no support for multi-line commands.
20286
20287 @var{command_class} should be one of the @samp{COMMAND_} constants
20288 defined below. This argument tells @value{GDBN} how to categorize the
20289 new command in the help system.
20290
20291 @var{completer_class} is an optional argument. If given, it should be
20292 one of the @samp{COMPLETE_} constants defined below. This argument
20293 tells @value{GDBN} how to perform completion for this command. If not
20294 given, @value{GDBN} will attempt to complete using the object's
20295 @code{complete} method (see below); if no such method is found, an
20296 error will occur when completion is attempted.
20297
20298 @var{prefix} is an optional argument. If @code{True}, then the new
20299 command is a prefix command; sub-commands of this command may be
20300 registered.
20301
20302 The help text for the new command is taken from the Python
20303 documentation string for the command's class, if there is one. If no
20304 documentation string is provided, the default value ``This command is
20305 not documented.'' is used.
20306 @end defmethod
20307
20308 @cindex don't repeat Python command
20309 @defmethod Command dont_repeat
20310 By default, a @value{GDBN} command is repeated when the user enters a
20311 blank line at the command prompt. A command can suppress this
20312 behavior by invoking the @code{dont_repeat} method. This is similar
20313 to the user command @code{dont-repeat}, see @ref{Define, dont-repeat}.
20314 @end defmethod
20315
20316 @defmethod Command invoke argument from_tty
20317 This method is called by @value{GDBN} when this command is invoked.
20318
20319 @var{argument} is a string. It is the argument to the command, after
20320 leading and trailing whitespace has been stripped.
20321
20322 @var{from_tty} is a boolean argument. When true, this means that the
20323 command was entered by the user at the terminal; when false it means
20324 that the command came from elsewhere.
20325
20326 If this method throws an exception, it is turned into a @value{GDBN}
20327 @code{error} call. Otherwise, the return value is ignored.
20328 @end defmethod
20329
20330 @cindex completion of Python commands
20331 @defmethod Command complete text word
20332 This method is called by @value{GDBN} when the user attempts
20333 completion on this command. All forms of completion are handled by
20334 this method, that is, the @key{TAB} and @key{M-?} key bindings
20335 (@pxref{Completion}), and the @code{complete} command (@pxref{Help,
20336 complete}).
20337
20338 The arguments @var{text} and @var{word} are both strings. @var{text}
20339 holds the complete command line up to the cursor's location.
20340 @var{word} holds the last word of the command line; this is computed
20341 using a word-breaking heuristic.
20342
20343 The @code{complete} method can return several values:
20344 @itemize @bullet
20345 @item
20346 If the return value is a sequence, the contents of the sequence are
20347 used as the completions. It is up to @code{complete} to ensure that the
20348 contents actually do complete the word. A zero-length sequence is
20349 allowed, it means that there were no completions available. Only
20350 string elements of the sequence are used; other elements in the
20351 sequence are ignored.
20352
20353 @item
20354 If the return value is one of the @samp{COMPLETE_} constants defined
20355 below, then the corresponding @value{GDBN}-internal completion
20356 function is invoked, and its result is used.
20357
20358 @item
20359 All other results are treated as though there were no available
20360 completions.
20361 @end itemize
20362 @end defmethod
20363
20364 When a new command is registered, it must be declared as a member of
20365 some general class of commands. This is used to classify top-level
20366 commands in the on-line help system; note that prefix commands are not
20367 listed under their own category but rather that of their top-level
20368 command. The available classifications are represented by constants
20369 defined in the @code{gdb} module:
20370
20371 @table @code
20372 @findex COMMAND_NONE
20373 @findex gdb.COMMAND_NONE
20374 @item COMMAND_NONE
20375 The command does not belong to any particular class. A command in
20376 this category will not be displayed in any of the help categories.
20377
20378 @findex COMMAND_RUNNING
20379 @findex gdb.COMMAND_RUNNING
20380 @item COMMAND_RUNNING
20381 The command is related to running the inferior. For example,
20382 @code{start}, @code{step}, and @code{continue} are in this category.
20383 Type @kbd{help running} at the @value{GDBN} prompt to see a list of
20384 commands in this category.
20385
20386 @findex COMMAND_DATA
20387 @findex gdb.COMMAND_DATA
20388 @item COMMAND_DATA
20389 The command is related to data or variables. For example,
20390 @code{call}, @code{find}, and @code{print} are in this category. Type
20391 @kbd{help data} at the @value{GDBN} prompt to see a list of commands
20392 in this category.
20393
20394 @findex COMMAND_STACK
20395 @findex gdb.COMMAND_STACK
20396 @item COMMAND_STACK
20397 The command has to do with manipulation of the stack. For example,
20398 @code{backtrace}, @code{frame}, and @code{return} are in this
20399 category. Type @kbd{help stack} at the @value{GDBN} prompt to see a
20400 list of commands in this category.
20401
20402 @findex COMMAND_FILES
20403 @findex gdb.COMMAND_FILES
20404 @item COMMAND_FILES
20405 This class is used for file-related commands. For example,
20406 @code{file}, @code{list} and @code{section} are in this category.
20407 Type @kbd{help files} at the @value{GDBN} prompt to see a list of
20408 commands in this category.
20409
20410 @findex COMMAND_SUPPORT
20411 @findex gdb.COMMAND_SUPPORT
20412 @item COMMAND_SUPPORT
20413 This should be used for ``support facilities'', generally meaning
20414 things that are useful to the user when interacting with @value{GDBN},
20415 but not related to the state of the inferior. For example,
20416 @code{help}, @code{make}, and @code{shell} are in this category. Type
20417 @kbd{help support} at the @value{GDBN} prompt to see a list of
20418 commands in this category.
20419
20420 @findex COMMAND_STATUS
20421 @findex gdb.COMMAND_STATUS
20422 @item COMMAND_STATUS
20423 The command is an @samp{info}-related command, that is, related to the
20424 state of @value{GDBN} itself. For example, @code{info}, @code{macro},
20425 and @code{show} are in this category. Type @kbd{help status} at the
20426 @value{GDBN} prompt to see a list of commands in this category.
20427
20428 @findex COMMAND_BREAKPOINTS
20429 @findex gdb.COMMAND_BREAKPOINTS
20430 @item COMMAND_BREAKPOINTS
20431 The command has to do with breakpoints. For example, @code{break},
20432 @code{clear}, and @code{delete} are in this category. Type @kbd{help
20433 breakpoints} at the @value{GDBN} prompt to see a list of commands in
20434 this category.
20435
20436 @findex COMMAND_TRACEPOINTS
20437 @findex gdb.COMMAND_TRACEPOINTS
20438 @item COMMAND_TRACEPOINTS
20439 The command has to do with tracepoints. For example, @code{trace},
20440 @code{actions}, and @code{tfind} are in this category. Type
20441 @kbd{help tracepoints} at the @value{GDBN} prompt to see a list of
20442 commands in this category.
20443
20444 @findex COMMAND_OBSCURE
20445 @findex gdb.COMMAND_OBSCURE
20446 @item COMMAND_OBSCURE
20447 The command is only used in unusual circumstances, or is not of
20448 general interest to users. For example, @code{checkpoint},
20449 @code{fork}, and @code{stop} are in this category. Type @kbd{help
20450 obscure} at the @value{GDBN} prompt to see a list of commands in this
20451 category.
20452
20453 @findex COMMAND_MAINTENANCE
20454 @findex gdb.COMMAND_MAINTENANCE
20455 @item COMMAND_MAINTENANCE
20456 The command is only useful to @value{GDBN} maintainers. The
20457 @code{maintenance} and @code{flushregs} commands are in this category.
20458 Type @kbd{help internals} at the @value{GDBN} prompt to see a list of
20459 commands in this category.
20460 @end table
20461
20462 A new command can use a predefined completion function, either by
20463 specifying it via an argument at initialization, or by returning it
20464 from the @code{complete} method. These predefined completion
20465 constants are all defined in the @code{gdb} module:
20466
20467 @table @code
20468 @findex COMPLETE_NONE
20469 @findex gdb.COMPLETE_NONE
20470 @item COMPLETE_NONE
20471 This constant means that no completion should be done.
20472
20473 @findex COMPLETE_FILENAME
20474 @findex gdb.COMPLETE_FILENAME
20475 @item COMPLETE_FILENAME
20476 This constant means that filename completion should be performed.
20477
20478 @findex COMPLETE_LOCATION
20479 @findex gdb.COMPLETE_LOCATION
20480 @item COMPLETE_LOCATION
20481 This constant means that location completion should be done.
20482 @xref{Specify Location}.
20483
20484 @findex COMPLETE_COMMAND
20485 @findex gdb.COMPLETE_COMMAND
20486 @item COMPLETE_COMMAND
20487 This constant means that completion should examine @value{GDBN}
20488 command names.
20489
20490 @findex COMPLETE_SYMBOL
20491 @findex gdb.COMPLETE_SYMBOL
20492 @item COMPLETE_SYMBOL
20493 This constant means that completion should be done using symbol names
20494 as the source.
20495 @end table
20496
20497 The following code snippet shows how a trivial CLI command can be
20498 implemented in Python:
20499
20500 @smallexample
20501 class HelloWorld (gdb.Command):
20502 """Greet the whole world."""
20503
20504 def __init__ (self):
20505 super (HelloWorld, self).__init__ ("hello-world", gdb.COMMAND_OBSCURE)
20506
20507 def invoke (self, arg, from_tty):
20508 print "Hello, World!"
20509
20510 HelloWorld ()
20511 @end smallexample
20512
20513 The last line instantiates the class, and is necessary to trigger the
20514 registration of the command with @value{GDBN}. Depending on how the
20515 Python code is read into @value{GDBN}, you may need to import the
20516 @code{gdb} module explicitly.
20517
20518 @node Functions In Python
20519 @subsubsection Writing new convenience functions
20520
20521 @cindex writing convenience functions
20522 @cindex convenience functions in python
20523 @cindex python convenience functions
20524 @tindex gdb.Function
20525 @tindex Function
20526 You can implement new convenience functions (@pxref{Convenience Vars})
20527 in Python. A convenience function is an instance of a subclass of the
20528 class @code{gdb.Function}.
20529
20530 @defmethod Function __init__ name
20531 The initializer for @code{Function} registers the new function with
20532 @value{GDBN}. The argument @var{name} is the name of the function,
20533 a string. The function will be visible to the user as a convenience
20534 variable of type @code{internal function}, whose name is the same as
20535 the given @var{name}.
20536
20537 The documentation for the new function is taken from the documentation
20538 string for the new class.
20539 @end defmethod
20540
20541 @defmethod Function invoke @var{*args}
20542 When a convenience function is evaluated, its arguments are converted
20543 to instances of @code{gdb.Value}, and then the function's
20544 @code{invoke} method is called. Note that @value{GDBN} does not
20545 predetermine the arity of convenience functions. Instead, all
20546 available arguments are passed to @code{invoke}, following the
20547 standard Python calling convention. In particular, a convenience
20548 function can have default values for parameters without ill effect.
20549
20550 The return value of this method is used as its value in the enclosing
20551 expression. If an ordinary Python value is returned, it is converted
20552 to a @code{gdb.Value} following the usual rules.
20553 @end defmethod
20554
20555 The following code snippet shows how a trivial convenience function can
20556 be implemented in Python:
20557
20558 @smallexample
20559 class Greet (gdb.Function):
20560 """Return string to greet someone.
20561 Takes a name as argument."""
20562
20563 def __init__ (self):
20564 super (Greet, self).__init__ ("greet")
20565
20566 def invoke (self, name):
20567 return "Hello, %s!" % name.string ()
20568
20569 Greet ()
20570 @end smallexample
20571
20572 The last line instantiates the class, and is necessary to trigger the
20573 registration of the function with @value{GDBN}. Depending on how the
20574 Python code is read into @value{GDBN}, you may need to import the
20575 @code{gdb} module explicitly.
20576
20577 @node Objfiles In Python
20578 @subsubsection Objfiles In Python
20579
20580 @cindex objfiles in python
20581 @tindex gdb.Objfile
20582 @tindex Objfile
20583 @value{GDBN} loads symbols for an inferior from various
20584 symbol-containing files (@pxref{Files}). These include the primary
20585 executable file, any shared libraries used by the inferior, and any
20586 separate debug info files (@pxref{Separate Debug Files}).
20587 @value{GDBN} calls these symbol-containing files @dfn{objfiles}.
20588
20589 The following objfile-related functions are available in the
20590 @code{gdb} module:
20591
20592 @findex gdb.current_objfile
20593 @defun current_objfile
20594 When auto-loading a Python script (@pxref{Auto-loading}), @value{GDBN}
20595 sets the ``current objfile'' to the corresponding objfile. This
20596 function returns the current objfile. If there is no current objfile,
20597 this function returns @code{None}.
20598 @end defun
20599
20600 @findex gdb.objfiles
20601 @defun objfiles
20602 Return a sequence of all the objfiles current known to @value{GDBN}.
20603 @xref{Objfiles In Python}.
20604 @end defun
20605
20606 Each objfile is represented by an instance of the @code{gdb.Objfile}
20607 class.
20608
20609 @defivar Objfile filename
20610 The file name of the objfile as a string.
20611 @end defivar
20612
20613 @defivar Objfile pretty_printers
20614 The @code{pretty_printers} attribute is a list of functions. It is
20615 used to look up pretty-printers. A @code{Value} is passed to each
20616 function in order; if the function returns @code{None}, then the
20617 search continues. Otherwise, the return value should be an object
20618 which is used to format the value. @xref{Pretty Printing}, for more
20619 information.
20620 @end defivar
20621
20622 @node Frames In Python
20623 @subsubsection Acessing inferior stack frames from Python.
20624
20625 @cindex frames in python
20626 When the debugged program stops, @value{GDBN} is able to analyze its call
20627 stack (@pxref{Frames,,Stack frames}). The @code{gdb.Frame} class
20628 represents a frame in the stack. A @code{gdb.Frame} object is only valid
20629 while its corresponding frame exists in the inferior's stack. If you try
20630 to use an invalid frame object, @value{GDBN} will throw a @code{RuntimeError}
20631 exception.
20632
20633 Two @code{gdb.Frame} objects can be compared for equality with the @code{==}
20634 operator, like:
20635
20636 @smallexample
20637 (@value{GDBP}) python print gdb.newest_frame() == gdb.selected_frame ()
20638 True
20639 @end smallexample
20640
20641 The following frame-related functions are available in the @code{gdb} module:
20642
20643 @findex gdb.selected_frame
20644 @defun selected_frame
20645 Return the selected frame object. (@pxref{Selection,,Selecting a Frame}).
20646 @end defun
20647
20648 @defun frame_stop_reason_string reason
20649 Return a string explaining the reason why @value{GDBN} stopped unwinding
20650 frames, as expressed by the given @var{reason} code (an integer, see the
20651 @code{unwind_stop_reason} method further down in this section).
20652 @end defun
20653
20654 A @code{gdb.Frame} object has the following methods:
20655
20656 @table @code
20657 @defmethod Frame is_valid
20658 Returns true if the @code{gdb.Frame} object is valid, false if not.
20659 A frame object can become invalid if the frame it refers to doesn't
20660 exist anymore in the inferior. All @code{gdb.Frame} methods will throw
20661 an exception if it is invalid at the time the method is called.
20662 @end defmethod
20663
20664 @defmethod Frame name
20665 Returns the function name of the frame, or @code{None} if it can't be
20666 obtained.
20667 @end defmethod
20668
20669 @defmethod Frame type
20670 Returns the type of the frame. The value can be one of
20671 @code{gdb.NORMAL_FRAME}, @code{gdb.DUMMY_FRAME}, @code{gdb.SIGTRAMP_FRAME}
20672 or @code{gdb.SENTINEL_FRAME}.
20673 @end defmethod
20674
20675 @defmethod Frame unwind_stop_reason
20676 Return an integer representing the reason why it's not possible to find
20677 more frames toward the outermost frame. Use
20678 @code{gdb.frame_stop_reason_string} to convert the value returned by this
20679 function to a string.
20680 @end defmethod
20681
20682 @defmethod Frame pc
20683 Returns the frame's resume address.
20684 @end defmethod
20685
20686 @defmethod Frame older
20687 Return the frame that called this frame.
20688 @end defmethod
20689
20690 @defmethod Frame newer
20691 Return the frame called by this frame.
20692 @end defmethod
20693
20694 @defmethod Frame read_var variable
20695 Return the value of the given variable in this frame. @var{variable} must
20696 be a string.
20697 @end defmethod
20698 @end table
20699
20700 @node Lazy Strings In Python
20701 @subsubsection Python representation of lazy strings.
20702
20703 @cindex lazy strings in python
20704 @tindex gdb.LazyString
20705
20706 A @dfn{lazy string} is a string whose contents is not retrieved or
20707 encoded until it is needed.
20708
20709 A @code{gdb.LazyString} is represented in @value{GDBN} as an
20710 @code{address} that points to a region of memory, an @code{encoding}
20711 that will be used to encode that region of memory, and a @code{length}
20712 to delimit the region of memory that represents the string. The
20713 difference between a @code{gdb.LazyString} and a string wrapped within
20714 a @code{gdb.Value} is that a @code{gdb.LazyString} will be treated
20715 differently by @value{GDBN} when printing. A @code{gdb.LazyString} is
20716 retrieved and encoded during printing, while a @code{gdb.Value}
20717 wrapping a string is immediately retrieved and encoded on creation.
20718
20719 A @code{gdb.LazyString} object has the following functions:
20720
20721 @defmethod LazyString value
20722 Convert the @code{gdb.LazyString} to a @code{gdb.Value}. This value
20723 will point to the string in memory, but will lose all the delayed
20724 retrieval, encoding and handling that @value{GDBN} applies to a
20725 @code{gdb.LazyString}.
20726 @end defmethod
20727
20728 @defivar LazyString address
20729 This attribute holds the address of the string. This attribute is not
20730 writable.
20731 @end defivar
20732
20733 @defivar LazyString length
20734 This attribute holds the length of the string in characters. If the
20735 length is -1, then the string will be fetched and encoded up to the
20736 first null of appropriate width. This attribute is not writable.
20737 @end defivar
20738
20739 @defivar LazyString encoding
20740 This attribute holds the encoding that will be applied to the string
20741 when the string is printed by @value{GDBN}. If the encoding is not
20742 set, or contains an empty string, then @value{GDBN} will select the
20743 most appropriate encoding when the string is printed. This attribute
20744 is not writable.
20745 @end defivar
20746
20747 @defivar LazyString type
20748 This attribute holds the type that is represented by the lazy string's
20749 type. For a lazy string this will always be a pointer type. To
20750 resolve this to the lazy string's character type, use the type's
20751 @code{target} method. @xref{Types In Python}. This attribute is not
20752 writable.
20753 @end defivar
20754
20755 @node Interpreters
20756 @chapter Command Interpreters
20757 @cindex command interpreters
20758
20759 @value{GDBN} supports multiple command interpreters, and some command
20760 infrastructure to allow users or user interface writers to switch
20761 between interpreters or run commands in other interpreters.
20762
20763 @value{GDBN} currently supports two command interpreters, the console
20764 interpreter (sometimes called the command-line interpreter or @sc{cli})
20765 and the machine interface interpreter (or @sc{gdb/mi}). This manual
20766 describes both of these interfaces in great detail.
20767
20768 By default, @value{GDBN} will start with the console interpreter.
20769 However, the user may choose to start @value{GDBN} with another
20770 interpreter by specifying the @option{-i} or @option{--interpreter}
20771 startup options. Defined interpreters include:
20772
20773 @table @code
20774 @item console
20775 @cindex console interpreter
20776 The traditional console or command-line interpreter. This is the most often
20777 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
20778 @value{GDBN} will use this interpreter.
20779
20780 @item mi
20781 @cindex mi interpreter
20782 The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
20783 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
20784 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
20785 Interface}.
20786
20787 @item mi2
20788 @cindex mi2 interpreter
20789 The current @sc{gdb/mi} interface.
20790
20791 @item mi1
20792 @cindex mi1 interpreter
20793 The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
20794
20795 @end table
20796
20797 @cindex invoke another interpreter
20798 The interpreter being used by @value{GDBN} may not be dynamically
20799 switched at runtime. Although possible, this could lead to a very
20800 precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
20801 enters the command "interpreter-set console" in a console view,
20802 @value{GDBN} would switch to using the console interpreter, rendering
20803 the IDE inoperable!
20804
20805 @kindex interpreter-exec
20806 Although you may only choose a single interpreter at startup, you may execute
20807 commands in any interpreter from the current interpreter using the appropriate
20808 command. If you are running the console interpreter, simply use the
20809 @code{interpreter-exec} command:
20810
20811 @smallexample
20812 interpreter-exec mi "-data-list-register-names"
20813 @end smallexample
20814
20815 @sc{gdb/mi} has a similar command, although it is only available in versions of
20816 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
20817
20818 @node TUI
20819 @chapter @value{GDBN} Text User Interface
20820 @cindex TUI
20821 @cindex Text User Interface
20822
20823 @menu
20824 * TUI Overview:: TUI overview
20825 * TUI Keys:: TUI key bindings
20826 * TUI Single Key Mode:: TUI single key mode
20827 * TUI Commands:: TUI-specific commands
20828 * TUI Configuration:: TUI configuration variables
20829 @end menu
20830
20831 The @value{GDBN} Text User Interface (TUI) is a terminal
20832 interface which uses the @code{curses} library to show the source
20833 file, the assembly output, the program registers and @value{GDBN}
20834 commands in separate text windows. The TUI mode is supported only
20835 on platforms where a suitable version of the @code{curses} library
20836 is available.
20837
20838 @pindex @value{GDBTUI}
20839 The TUI mode is enabled by default when you invoke @value{GDBN} as
20840 either @samp{@value{GDBTUI}} or @samp{@value{GDBP} -tui}.
20841 You can also switch in and out of TUI mode while @value{GDBN} runs by
20842 using various TUI commands and key bindings, such as @kbd{C-x C-a}.
20843 @xref{TUI Keys, ,TUI Key Bindings}.
20844
20845 @node TUI Overview
20846 @section TUI Overview
20847
20848 In TUI mode, @value{GDBN} can display several text windows:
20849
20850 @table @emph
20851 @item command
20852 This window is the @value{GDBN} command window with the @value{GDBN}
20853 prompt and the @value{GDBN} output. The @value{GDBN} input is still
20854 managed using readline.
20855
20856 @item source
20857 The source window shows the source file of the program. The current
20858 line and active breakpoints are displayed in this window.
20859
20860 @item assembly
20861 The assembly window shows the disassembly output of the program.
20862
20863 @item register
20864 This window shows the processor registers. Registers are highlighted
20865 when their values change.
20866 @end table
20867
20868 The source and assembly windows show the current program position
20869 by highlighting the current line and marking it with a @samp{>} marker.
20870 Breakpoints are indicated with two markers. The first marker
20871 indicates the breakpoint type:
20872
20873 @table @code
20874 @item B
20875 Breakpoint which was hit at least once.
20876
20877 @item b
20878 Breakpoint which was never hit.
20879
20880 @item H
20881 Hardware breakpoint which was hit at least once.
20882
20883 @item h
20884 Hardware breakpoint which was never hit.
20885 @end table
20886
20887 The second marker indicates whether the breakpoint is enabled or not:
20888
20889 @table @code
20890 @item +
20891 Breakpoint is enabled.
20892
20893 @item -
20894 Breakpoint is disabled.
20895 @end table
20896
20897 The source, assembly and register windows are updated when the current
20898 thread changes, when the frame changes, or when the program counter
20899 changes.
20900
20901 These windows are not all visible at the same time. The command
20902 window is always visible. The others can be arranged in several
20903 layouts:
20904
20905 @itemize @bullet
20906 @item
20907 source only,
20908
20909 @item
20910 assembly only,
20911
20912 @item
20913 source and assembly,
20914
20915 @item
20916 source and registers, or
20917
20918 @item
20919 assembly and registers.
20920 @end itemize
20921
20922 A status line above the command window shows the following information:
20923
20924 @table @emph
20925 @item target
20926 Indicates the current @value{GDBN} target.
20927 (@pxref{Targets, ,Specifying a Debugging Target}).
20928
20929 @item process
20930 Gives the current process or thread number.
20931 When no process is being debugged, this field is set to @code{No process}.
20932
20933 @item function
20934 Gives the current function name for the selected frame.
20935 The name is demangled if demangling is turned on (@pxref{Print Settings}).
20936 When there is no symbol corresponding to the current program counter,
20937 the string @code{??} is displayed.
20938
20939 @item line
20940 Indicates the current line number for the selected frame.
20941 When the current line number is not known, the string @code{??} is displayed.
20942
20943 @item pc
20944 Indicates the current program counter address.
20945 @end table
20946
20947 @node TUI Keys
20948 @section TUI Key Bindings
20949 @cindex TUI key bindings
20950
20951 The TUI installs several key bindings in the readline keymaps
20952 (@pxref{Command Line Editing}). The following key bindings
20953 are installed for both TUI mode and the @value{GDBN} standard mode.
20954
20955 @table @kbd
20956 @kindex C-x C-a
20957 @item C-x C-a
20958 @kindex C-x a
20959 @itemx C-x a
20960 @kindex C-x A
20961 @itemx C-x A
20962 Enter or leave the TUI mode. When leaving the TUI mode,
20963 the curses window management stops and @value{GDBN} operates using
20964 its standard mode, writing on the terminal directly. When reentering
20965 the TUI mode, control is given back to the curses windows.
20966 The screen is then refreshed.
20967
20968 @kindex C-x 1
20969 @item C-x 1
20970 Use a TUI layout with only one window. The layout will
20971 either be @samp{source} or @samp{assembly}. When the TUI mode
20972 is not active, it will switch to the TUI mode.
20973
20974 Think of this key binding as the Emacs @kbd{C-x 1} binding.
20975
20976 @kindex C-x 2
20977 @item C-x 2
20978 Use a TUI layout with at least two windows. When the current
20979 layout already has two windows, the next layout with two windows is used.
20980 When a new layout is chosen, one window will always be common to the
20981 previous layout and the new one.
20982
20983 Think of it as the Emacs @kbd{C-x 2} binding.
20984
20985 @kindex C-x o
20986 @item C-x o
20987 Change the active window. The TUI associates several key bindings
20988 (like scrolling and arrow keys) with the active window. This command
20989 gives the focus to the next TUI window.
20990
20991 Think of it as the Emacs @kbd{C-x o} binding.
20992
20993 @kindex C-x s
20994 @item C-x s
20995 Switch in and out of the TUI SingleKey mode that binds single
20996 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
20997 @end table
20998
20999 The following key bindings only work in the TUI mode:
21000
21001 @table @asis
21002 @kindex PgUp
21003 @item @key{PgUp}
21004 Scroll the active window one page up.
21005
21006 @kindex PgDn
21007 @item @key{PgDn}
21008 Scroll the active window one page down.
21009
21010 @kindex Up
21011 @item @key{Up}
21012 Scroll the active window one line up.
21013
21014 @kindex Down
21015 @item @key{Down}
21016 Scroll the active window one line down.
21017
21018 @kindex Left
21019 @item @key{Left}
21020 Scroll the active window one column left.
21021
21022 @kindex Right
21023 @item @key{Right}
21024 Scroll the active window one column right.
21025
21026 @kindex C-L
21027 @item @kbd{C-L}
21028 Refresh the screen.
21029 @end table
21030
21031 Because the arrow keys scroll the active window in the TUI mode, they
21032 are not available for their normal use by readline unless the command
21033 window has the focus. When another window is active, you must use
21034 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
21035 and @kbd{C-f} to control the command window.
21036
21037 @node TUI Single Key Mode
21038 @section TUI Single Key Mode
21039 @cindex TUI single key mode
21040
21041 The TUI also provides a @dfn{SingleKey} mode, which binds several
21042 frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
21043 switch into this mode, where the following key bindings are used:
21044
21045 @table @kbd
21046 @kindex c @r{(SingleKey TUI key)}
21047 @item c
21048 continue
21049
21050 @kindex d @r{(SingleKey TUI key)}
21051 @item d
21052 down
21053
21054 @kindex f @r{(SingleKey TUI key)}
21055 @item f
21056 finish
21057
21058 @kindex n @r{(SingleKey TUI key)}
21059 @item n
21060 next
21061
21062 @kindex q @r{(SingleKey TUI key)}
21063 @item q
21064 exit the SingleKey mode.
21065
21066 @kindex r @r{(SingleKey TUI key)}
21067 @item r
21068 run
21069
21070 @kindex s @r{(SingleKey TUI key)}
21071 @item s
21072 step
21073
21074 @kindex u @r{(SingleKey TUI key)}
21075 @item u
21076 up
21077
21078 @kindex v @r{(SingleKey TUI key)}
21079 @item v
21080 info locals
21081
21082 @kindex w @r{(SingleKey TUI key)}
21083 @item w
21084 where
21085 @end table
21086
21087 Other keys temporarily switch to the @value{GDBN} command prompt.
21088 The key that was pressed is inserted in the editing buffer so that
21089 it is possible to type most @value{GDBN} commands without interaction
21090 with the TUI SingleKey mode. Once the command is entered the TUI
21091 SingleKey mode is restored. The only way to permanently leave
21092 this mode is by typing @kbd{q} or @kbd{C-x s}.
21093
21094
21095 @node TUI Commands
21096 @section TUI-specific Commands
21097 @cindex TUI commands
21098
21099 The TUI has specific commands to control the text windows.
21100 These commands are always available, even when @value{GDBN} is not in
21101 the TUI mode. When @value{GDBN} is in the standard mode, most
21102 of these commands will automatically switch to the TUI mode.
21103
21104 @table @code
21105 @item info win
21106 @kindex info win
21107 List and give the size of all displayed windows.
21108
21109 @item layout next
21110 @kindex layout
21111 Display the next layout.
21112
21113 @item layout prev
21114 Display the previous layout.
21115
21116 @item layout src
21117 Display the source window only.
21118
21119 @item layout asm
21120 Display the assembly window only.
21121
21122 @item layout split
21123 Display the source and assembly window.
21124
21125 @item layout regs
21126 Display the register window together with the source or assembly window.
21127
21128 @item focus next
21129 @kindex focus
21130 Make the next window active for scrolling.
21131
21132 @item focus prev
21133 Make the previous window active for scrolling.
21134
21135 @item focus src
21136 Make the source window active for scrolling.
21137
21138 @item focus asm
21139 Make the assembly window active for scrolling.
21140
21141 @item focus regs
21142 Make the register window active for scrolling.
21143
21144 @item focus cmd
21145 Make the command window active for scrolling.
21146
21147 @item refresh
21148 @kindex refresh
21149 Refresh the screen. This is similar to typing @kbd{C-L}.
21150
21151 @item tui reg float
21152 @kindex tui reg
21153 Show the floating point registers in the register window.
21154
21155 @item tui reg general
21156 Show the general registers in the register window.
21157
21158 @item tui reg next
21159 Show the next register group. The list of register groups as well as
21160 their order is target specific. The predefined register groups are the
21161 following: @code{general}, @code{float}, @code{system}, @code{vector},
21162 @code{all}, @code{save}, @code{restore}.
21163
21164 @item tui reg system
21165 Show the system registers in the register window.
21166
21167 @item update
21168 @kindex update
21169 Update the source window and the current execution point.
21170
21171 @item winheight @var{name} +@var{count}
21172 @itemx winheight @var{name} -@var{count}
21173 @kindex winheight
21174 Change the height of the window @var{name} by @var{count}
21175 lines. Positive counts increase the height, while negative counts
21176 decrease it.
21177
21178 @item tabset @var{nchars}
21179 @kindex tabset
21180 Set the width of tab stops to be @var{nchars} characters.
21181 @end table
21182
21183 @node TUI Configuration
21184 @section TUI Configuration Variables
21185 @cindex TUI configuration variables
21186
21187 Several configuration variables control the appearance of TUI windows.
21188
21189 @table @code
21190 @item set tui border-kind @var{kind}
21191 @kindex set tui border-kind
21192 Select the border appearance for the source, assembly and register windows.
21193 The possible values are the following:
21194 @table @code
21195 @item space
21196 Use a space character to draw the border.
21197
21198 @item ascii
21199 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
21200
21201 @item acs
21202 Use the Alternate Character Set to draw the border. The border is
21203 drawn using character line graphics if the terminal supports them.
21204 @end table
21205
21206 @item set tui border-mode @var{mode}
21207 @kindex set tui border-mode
21208 @itemx set tui active-border-mode @var{mode}
21209 @kindex set tui active-border-mode
21210 Select the display attributes for the borders of the inactive windows
21211 or the active window. The @var{mode} can be one of the following:
21212 @table @code
21213 @item normal
21214 Use normal attributes to display the border.
21215
21216 @item standout
21217 Use standout mode.
21218
21219 @item reverse
21220 Use reverse video mode.
21221
21222 @item half
21223 Use half bright mode.
21224
21225 @item half-standout
21226 Use half bright and standout mode.
21227
21228 @item bold
21229 Use extra bright or bold mode.
21230
21231 @item bold-standout
21232 Use extra bright or bold and standout mode.
21233 @end table
21234 @end table
21235
21236 @node Emacs
21237 @chapter Using @value{GDBN} under @sc{gnu} Emacs
21238
21239 @cindex Emacs
21240 @cindex @sc{gnu} Emacs
21241 A special interface allows you to use @sc{gnu} Emacs to view (and
21242 edit) the source files for the program you are debugging with
21243 @value{GDBN}.
21244
21245 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
21246 executable file you want to debug as an argument. This command starts
21247 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
21248 created Emacs buffer.
21249 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
21250
21251 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
21252 things:
21253
21254 @itemize @bullet
21255 @item
21256 All ``terminal'' input and output goes through an Emacs buffer, called
21257 the GUD buffer.
21258
21259 This applies both to @value{GDBN} commands and their output, and to the input
21260 and output done by the program you are debugging.
21261
21262 This is useful because it means that you can copy the text of previous
21263 commands and input them again; you can even use parts of the output
21264 in this way.
21265
21266 All the facilities of Emacs' Shell mode are available for interacting
21267 with your program. In particular, you can send signals the usual
21268 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
21269 stop.
21270
21271 @item
21272 @value{GDBN} displays source code through Emacs.
21273
21274 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
21275 source file for that frame and puts an arrow (@samp{=>}) at the
21276 left margin of the current line. Emacs uses a separate buffer for
21277 source display, and splits the screen to show both your @value{GDBN} session
21278 and the source.
21279
21280 Explicit @value{GDBN} @code{list} or search commands still produce output as
21281 usual, but you probably have no reason to use them from Emacs.
21282 @end itemize
21283
21284 We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
21285 a graphical mode, enabled by default, which provides further buffers
21286 that can control the execution and describe the state of your program.
21287 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
21288
21289 If you specify an absolute file name when prompted for the @kbd{M-x
21290 gdb} argument, then Emacs sets your current working directory to where
21291 your program resides. If you only specify the file name, then Emacs
21292 sets your current working directory to to the directory associated
21293 with the previous buffer. In this case, @value{GDBN} may find your
21294 program by searching your environment's @code{PATH} variable, but on
21295 some operating systems it might not find the source. So, although the
21296 @value{GDBN} input and output session proceeds normally, the auxiliary
21297 buffer does not display the current source and line of execution.
21298
21299 The initial working directory of @value{GDBN} is printed on the top
21300 line of the GUD buffer and this serves as a default for the commands
21301 that specify files for @value{GDBN} to operate on. @xref{Files,
21302 ,Commands to Specify Files}.
21303
21304 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
21305 need to call @value{GDBN} by a different name (for example, if you
21306 keep several configurations around, with different names) you can
21307 customize the Emacs variable @code{gud-gdb-command-name} to run the
21308 one you want.
21309
21310 In the GUD buffer, you can use these special Emacs commands in
21311 addition to the standard Shell mode commands:
21312
21313 @table @kbd
21314 @item C-h m
21315 Describe the features of Emacs' GUD Mode.
21316
21317 @item C-c C-s
21318 Execute to another source line, like the @value{GDBN} @code{step} command; also
21319 update the display window to show the current file and location.
21320
21321 @item C-c C-n
21322 Execute to next source line in this function, skipping all function
21323 calls, like the @value{GDBN} @code{next} command. Then update the display window
21324 to show the current file and location.
21325
21326 @item C-c C-i
21327 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
21328 display window accordingly.
21329
21330 @item C-c C-f
21331 Execute until exit from the selected stack frame, like the @value{GDBN}
21332 @code{finish} command.
21333
21334 @item C-c C-r
21335 Continue execution of your program, like the @value{GDBN} @code{continue}
21336 command.
21337
21338 @item C-c <
21339 Go up the number of frames indicated by the numeric argument
21340 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
21341 like the @value{GDBN} @code{up} command.
21342
21343 @item C-c >
21344 Go down the number of frames indicated by the numeric argument, like the
21345 @value{GDBN} @code{down} command.
21346 @end table
21347
21348 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
21349 tells @value{GDBN} to set a breakpoint on the source line point is on.
21350
21351 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
21352 separate frame which shows a backtrace when the GUD buffer is current.
21353 Move point to any frame in the stack and type @key{RET} to make it
21354 become the current frame and display the associated source in the
21355 source buffer. Alternatively, click @kbd{Mouse-2} to make the
21356 selected frame become the current one. In graphical mode, the
21357 speedbar displays watch expressions.
21358
21359 If you accidentally delete the source-display buffer, an easy way to get
21360 it back is to type the command @code{f} in the @value{GDBN} buffer, to
21361 request a frame display; when you run under Emacs, this recreates
21362 the source buffer if necessary to show you the context of the current
21363 frame.
21364
21365 The source files displayed in Emacs are in ordinary Emacs buffers
21366 which are visiting the source files in the usual way. You can edit
21367 the files with these buffers if you wish; but keep in mind that @value{GDBN}
21368 communicates with Emacs in terms of line numbers. If you add or
21369 delete lines from the text, the line numbers that @value{GDBN} knows cease
21370 to correspond properly with the code.
21371
21372 A more detailed description of Emacs' interaction with @value{GDBN} is
21373 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
21374 Emacs Manual}).
21375
21376 @c The following dropped because Epoch is nonstandard. Reactivate
21377 @c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
21378 @ignore
21379 @kindex Emacs Epoch environment
21380 @kindex Epoch
21381 @kindex inspect
21382
21383 Version 18 of @sc{gnu} Emacs has a built-in window system
21384 called the @code{epoch}
21385 environment. Users of this environment can use a new command,
21386 @code{inspect} which performs identically to @code{print} except that
21387 each value is printed in its own window.
21388 @end ignore
21389
21390
21391 @node GDB/MI
21392 @chapter The @sc{gdb/mi} Interface
21393
21394 @unnumberedsec Function and Purpose
21395
21396 @cindex @sc{gdb/mi}, its purpose
21397 @sc{gdb/mi} is a line based machine oriented text interface to
21398 @value{GDBN} and is activated by specifying using the
21399 @option{--interpreter} command line option (@pxref{Mode Options}). It
21400 is specifically intended to support the development of systems which
21401 use the debugger as just one small component of a larger system.
21402
21403 This chapter is a specification of the @sc{gdb/mi} interface. It is written
21404 in the form of a reference manual.
21405
21406 Note that @sc{gdb/mi} is still under construction, so some of the
21407 features described below are incomplete and subject to change
21408 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
21409
21410 @unnumberedsec Notation and Terminology
21411
21412 @cindex notational conventions, for @sc{gdb/mi}
21413 This chapter uses the following notation:
21414
21415 @itemize @bullet
21416 @item
21417 @code{|} separates two alternatives.
21418
21419 @item
21420 @code{[ @var{something} ]} indicates that @var{something} is optional:
21421 it may or may not be given.
21422
21423 @item
21424 @code{( @var{group} )*} means that @var{group} inside the parentheses
21425 may repeat zero or more times.
21426
21427 @item
21428 @code{( @var{group} )+} means that @var{group} inside the parentheses
21429 may repeat one or more times.
21430
21431 @item
21432 @code{"@var{string}"} means a literal @var{string}.
21433 @end itemize
21434
21435 @ignore
21436 @heading Dependencies
21437 @end ignore
21438
21439 @menu
21440 * GDB/MI General Design::
21441 * GDB/MI Command Syntax::
21442 * GDB/MI Compatibility with CLI::
21443 * GDB/MI Development and Front Ends::
21444 * GDB/MI Output Records::
21445 * GDB/MI Simple Examples::
21446 * GDB/MI Command Description Format::
21447 * GDB/MI Breakpoint Commands::
21448 * GDB/MI Program Context::
21449 * GDB/MI Thread Commands::
21450 * GDB/MI Program Execution::
21451 * GDB/MI Stack Manipulation::
21452 * GDB/MI Variable Objects::
21453 * GDB/MI Data Manipulation::
21454 * GDB/MI Tracepoint Commands::
21455 * GDB/MI Symbol Query::
21456 * GDB/MI File Commands::
21457 @ignore
21458 * GDB/MI Kod Commands::
21459 * GDB/MI Memory Overlay Commands::
21460 * GDB/MI Signal Handling Commands::
21461 @end ignore
21462 * GDB/MI Target Manipulation::
21463 * GDB/MI File Transfer Commands::
21464 * GDB/MI Miscellaneous Commands::
21465 @end menu
21466
21467 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21468 @node GDB/MI General Design
21469 @section @sc{gdb/mi} General Design
21470 @cindex GDB/MI General Design
21471
21472 Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
21473 parts---commands sent to @value{GDBN}, responses to those commands
21474 and notifications. Each command results in exactly one response,
21475 indicating either successful completion of the command, or an error.
21476 For the commands that do not resume the target, the response contains the
21477 requested information. For the commands that resume the target, the
21478 response only indicates whether the target was successfully resumed.
21479 Notifications is the mechanism for reporting changes in the state of the
21480 target, or in @value{GDBN} state, that cannot conveniently be associated with
21481 a command and reported as part of that command response.
21482
21483 The important examples of notifications are:
21484 @itemize @bullet
21485
21486 @item
21487 Exec notifications. These are used to report changes in
21488 target state---when a target is resumed, or stopped. It would not
21489 be feasible to include this information in response of resuming
21490 commands, because one resume commands can result in multiple events in
21491 different threads. Also, quite some time may pass before any event
21492 happens in the target, while a frontend needs to know whether the resuming
21493 command itself was successfully executed.
21494
21495 @item
21496 Console output, and status notifications. Console output
21497 notifications are used to report output of CLI commands, as well as
21498 diagnostics for other commands. Status notifications are used to
21499 report the progress of a long-running operation. Naturally, including
21500 this information in command response would mean no output is produced
21501 until the command is finished, which is undesirable.
21502
21503 @item
21504 General notifications. Commands may have various side effects on
21505 the @value{GDBN} or target state beyond their official purpose. For example,
21506 a command may change the selected thread. Although such changes can
21507 be included in command response, using notification allows for more
21508 orthogonal frontend design.
21509
21510 @end itemize
21511
21512 There's no guarantee that whenever an MI command reports an error,
21513 @value{GDBN} or the target are in any specific state, and especially,
21514 the state is not reverted to the state before the MI command was
21515 processed. Therefore, whenever an MI command results in an error,
21516 we recommend that the frontend refreshes all the information shown in
21517 the user interface.
21518
21519
21520 @menu
21521 * Context management::
21522 * Asynchronous and non-stop modes::
21523 * Thread groups::
21524 @end menu
21525
21526 @node Context management
21527 @subsection Context management
21528
21529 In most cases when @value{GDBN} accesses the target, this access is
21530 done in context of a specific thread and frame (@pxref{Frames}).
21531 Often, even when accessing global data, the target requires that a thread
21532 be specified. The CLI interface maintains the selected thread and frame,
21533 and supplies them to target on each command. This is convenient,
21534 because a command line user would not want to specify that information
21535 explicitly on each command, and because user interacts with
21536 @value{GDBN} via a single terminal, so no confusion is possible as
21537 to what thread and frame are the current ones.
21538
21539 In the case of MI, the concept of selected thread and frame is less
21540 useful. First, a frontend can easily remember this information
21541 itself. Second, a graphical frontend can have more than one window,
21542 each one used for debugging a different thread, and the frontend might
21543 want to access additional threads for internal purposes. This
21544 increases the risk that by relying on implicitly selected thread, the
21545 frontend may be operating on a wrong one. Therefore, each MI command
21546 should explicitly specify which thread and frame to operate on. To
21547 make it possible, each MI command accepts the @samp{--thread} and
21548 @samp{--frame} options, the value to each is @value{GDBN} identifier
21549 for thread and frame to operate on.
21550
21551 Usually, each top-level window in a frontend allows the user to select
21552 a thread and a frame, and remembers the user selection for further
21553 operations. However, in some cases @value{GDBN} may suggest that the
21554 current thread be changed. For example, when stopping on a breakpoint
21555 it is reasonable to switch to the thread where breakpoint is hit. For
21556 another example, if the user issues the CLI @samp{thread} command via
21557 the frontend, it is desirable to change the frontend's selected thread to the
21558 one specified by user. @value{GDBN} communicates the suggestion to
21559 change current thread using the @samp{=thread-selected} notification.
21560 No such notification is available for the selected frame at the moment.
21561
21562 Note that historically, MI shares the selected thread with CLI, so
21563 frontends used the @code{-thread-select} to execute commands in the
21564 right context. However, getting this to work right is cumbersome. The
21565 simplest way is for frontend to emit @code{-thread-select} command
21566 before every command. This doubles the number of commands that need
21567 to be sent. The alternative approach is to suppress @code{-thread-select}
21568 if the selected thread in @value{GDBN} is supposed to be identical to the
21569 thread the frontend wants to operate on. However, getting this
21570 optimization right can be tricky. In particular, if the frontend
21571 sends several commands to @value{GDBN}, and one of the commands changes the
21572 selected thread, then the behaviour of subsequent commands will
21573 change. So, a frontend should either wait for response from such
21574 problematic commands, or explicitly add @code{-thread-select} for
21575 all subsequent commands. No frontend is known to do this exactly
21576 right, so it is suggested to just always pass the @samp{--thread} and
21577 @samp{--frame} options.
21578
21579 @node Asynchronous and non-stop modes
21580 @subsection Asynchronous command execution and non-stop mode
21581
21582 On some targets, @value{GDBN} is capable of processing MI commands
21583 even while the target is running. This is called @dfn{asynchronous
21584 command execution} (@pxref{Background Execution}). The frontend may
21585 specify a preferrence for asynchronous execution using the
21586 @code{-gdb-set target-async 1} command, which should be emitted before
21587 either running the executable or attaching to the target. After the
21588 frontend has started the executable or attached to the target, it can
21589 find if asynchronous execution is enabled using the
21590 @code{-list-target-features} command.
21591
21592 Even if @value{GDBN} can accept a command while target is running,
21593 many commands that access the target do not work when the target is
21594 running. Therefore, asynchronous command execution is most useful
21595 when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
21596 it is possible to examine the state of one thread, while other threads
21597 are running.
21598
21599 When a given thread is running, MI commands that try to access the
21600 target in the context of that thread may not work, or may work only on
21601 some targets. In particular, commands that try to operate on thread's
21602 stack will not work, on any target. Commands that read memory, or
21603 modify breakpoints, may work or not work, depending on the target. Note
21604 that even commands that operate on global state, such as @code{print},
21605 @code{set}, and breakpoint commands, still access the target in the
21606 context of a specific thread, so frontend should try to find a
21607 stopped thread and perform the operation on that thread (using the
21608 @samp{--thread} option).
21609
21610 Which commands will work in the context of a running thread is
21611 highly target dependent. However, the two commands
21612 @code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
21613 to find the state of a thread, will always work.
21614
21615 @node Thread groups
21616 @subsection Thread groups
21617 @value{GDBN} may be used to debug several processes at the same time.
21618 On some platfroms, @value{GDBN} may support debugging of several
21619 hardware systems, each one having several cores with several different
21620 processes running on each core. This section describes the MI
21621 mechanism to support such debugging scenarios.
21622
21623 The key observation is that regardless of the structure of the
21624 target, MI can have a global list of threads, because most commands that
21625 accept the @samp{--thread} option do not need to know what process that
21626 thread belongs to. Therefore, it is not necessary to introduce
21627 neither additional @samp{--process} option, nor an notion of the
21628 current process in the MI interface. The only strictly new feature
21629 that is required is the ability to find how the threads are grouped
21630 into processes.
21631
21632 To allow the user to discover such grouping, and to support arbitrary
21633 hierarchy of machines/cores/processes, MI introduces the concept of a
21634 @dfn{thread group}. Thread group is a collection of threads and other
21635 thread groups. A thread group always has a string identifier, a type,
21636 and may have additional attributes specific to the type. A new
21637 command, @code{-list-thread-groups}, returns the list of top-level
21638 thread groups, which correspond to processes that @value{GDBN} is
21639 debugging at the moment. By passing an identifier of a thread group
21640 to the @code{-list-thread-groups} command, it is possible to obtain
21641 the members of specific thread group.
21642
21643 To allow the user to easily discover processes, and other objects, he
21644 wishes to debug, a concept of @dfn{available thread group} is
21645 introduced. Available thread group is an thread group that
21646 @value{GDBN} is not debugging, but that can be attached to, using the
21647 @code{-target-attach} command. The list of available top-level thread
21648 groups can be obtained using @samp{-list-thread-groups --available}.
21649 In general, the content of a thread group may be only retrieved only
21650 after attaching to that thread group.
21651
21652 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21653 @node GDB/MI Command Syntax
21654 @section @sc{gdb/mi} Command Syntax
21655
21656 @menu
21657 * GDB/MI Input Syntax::
21658 * GDB/MI Output Syntax::
21659 @end menu
21660
21661 @node GDB/MI Input Syntax
21662 @subsection @sc{gdb/mi} Input Syntax
21663
21664 @cindex input syntax for @sc{gdb/mi}
21665 @cindex @sc{gdb/mi}, input syntax
21666 @table @code
21667 @item @var{command} @expansion{}
21668 @code{@var{cli-command} | @var{mi-command}}
21669
21670 @item @var{cli-command} @expansion{}
21671 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
21672 @var{cli-command} is any existing @value{GDBN} CLI command.
21673
21674 @item @var{mi-command} @expansion{}
21675 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
21676 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
21677
21678 @item @var{token} @expansion{}
21679 "any sequence of digits"
21680
21681 @item @var{option} @expansion{}
21682 @code{"-" @var{parameter} [ " " @var{parameter} ]}
21683
21684 @item @var{parameter} @expansion{}
21685 @code{@var{non-blank-sequence} | @var{c-string}}
21686
21687 @item @var{operation} @expansion{}
21688 @emph{any of the operations described in this chapter}
21689
21690 @item @var{non-blank-sequence} @expansion{}
21691 @emph{anything, provided it doesn't contain special characters such as
21692 "-", @var{nl}, """ and of course " "}
21693
21694 @item @var{c-string} @expansion{}
21695 @code{""" @var{seven-bit-iso-c-string-content} """}
21696
21697 @item @var{nl} @expansion{}
21698 @code{CR | CR-LF}
21699 @end table
21700
21701 @noindent
21702 Notes:
21703
21704 @itemize @bullet
21705 @item
21706 The CLI commands are still handled by the @sc{mi} interpreter; their
21707 output is described below.
21708
21709 @item
21710 The @code{@var{token}}, when present, is passed back when the command
21711 finishes.
21712
21713 @item
21714 Some @sc{mi} commands accept optional arguments as part of the parameter
21715 list. Each option is identified by a leading @samp{-} (dash) and may be
21716 followed by an optional argument parameter. Options occur first in the
21717 parameter list and can be delimited from normal parameters using
21718 @samp{--} (this is useful when some parameters begin with a dash).
21719 @end itemize
21720
21721 Pragmatics:
21722
21723 @itemize @bullet
21724 @item
21725 We want easy access to the existing CLI syntax (for debugging).
21726
21727 @item
21728 We want it to be easy to spot a @sc{mi} operation.
21729 @end itemize
21730
21731 @node GDB/MI Output Syntax
21732 @subsection @sc{gdb/mi} Output Syntax
21733
21734 @cindex output syntax of @sc{gdb/mi}
21735 @cindex @sc{gdb/mi}, output syntax
21736 The output from @sc{gdb/mi} consists of zero or more out-of-band records
21737 followed, optionally, by a single result record. This result record
21738 is for the most recent command. The sequence of output records is
21739 terminated by @samp{(gdb)}.
21740
21741 If an input command was prefixed with a @code{@var{token}} then the
21742 corresponding output for that command will also be prefixed by that same
21743 @var{token}.
21744
21745 @table @code
21746 @item @var{output} @expansion{}
21747 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
21748
21749 @item @var{result-record} @expansion{}
21750 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
21751
21752 @item @var{out-of-band-record} @expansion{}
21753 @code{@var{async-record} | @var{stream-record}}
21754
21755 @item @var{async-record} @expansion{}
21756 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
21757
21758 @item @var{exec-async-output} @expansion{}
21759 @code{[ @var{token} ] "*" @var{async-output}}
21760
21761 @item @var{status-async-output} @expansion{}
21762 @code{[ @var{token} ] "+" @var{async-output}}
21763
21764 @item @var{notify-async-output} @expansion{}
21765 @code{[ @var{token} ] "=" @var{async-output}}
21766
21767 @item @var{async-output} @expansion{}
21768 @code{@var{async-class} ( "," @var{result} )* @var{nl}}
21769
21770 @item @var{result-class} @expansion{}
21771 @code{"done" | "running" | "connected" | "error" | "exit"}
21772
21773 @item @var{async-class} @expansion{}
21774 @code{"stopped" | @var{others}} (where @var{others} will be added
21775 depending on the needs---this is still in development).
21776
21777 @item @var{result} @expansion{}
21778 @code{ @var{variable} "=" @var{value}}
21779
21780 @item @var{variable} @expansion{}
21781 @code{ @var{string} }
21782
21783 @item @var{value} @expansion{}
21784 @code{ @var{const} | @var{tuple} | @var{list} }
21785
21786 @item @var{const} @expansion{}
21787 @code{@var{c-string}}
21788
21789 @item @var{tuple} @expansion{}
21790 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
21791
21792 @item @var{list} @expansion{}
21793 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
21794 @var{result} ( "," @var{result} )* "]" }
21795
21796 @item @var{stream-record} @expansion{}
21797 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
21798
21799 @item @var{console-stream-output} @expansion{}
21800 @code{"~" @var{c-string}}
21801
21802 @item @var{target-stream-output} @expansion{}
21803 @code{"@@" @var{c-string}}
21804
21805 @item @var{log-stream-output} @expansion{}
21806 @code{"&" @var{c-string}}
21807
21808 @item @var{nl} @expansion{}
21809 @code{CR | CR-LF}
21810
21811 @item @var{token} @expansion{}
21812 @emph{any sequence of digits}.
21813 @end table
21814
21815 @noindent
21816 Notes:
21817
21818 @itemize @bullet
21819 @item
21820 All output sequences end in a single line containing a period.
21821
21822 @item
21823 The @code{@var{token}} is from the corresponding request. Note that
21824 for all async output, while the token is allowed by the grammar and
21825 may be output by future versions of @value{GDBN} for select async
21826 output messages, it is generally omitted. Frontends should treat
21827 all async output as reporting general changes in the state of the
21828 target and there should be no need to associate async output to any
21829 prior command.
21830
21831 @item
21832 @cindex status output in @sc{gdb/mi}
21833 @var{status-async-output} contains on-going status information about the
21834 progress of a slow operation. It can be discarded. All status output is
21835 prefixed by @samp{+}.
21836
21837 @item
21838 @cindex async output in @sc{gdb/mi}
21839 @var{exec-async-output} contains asynchronous state change on the target
21840 (stopped, started, disappeared). All async output is prefixed by
21841 @samp{*}.
21842
21843 @item
21844 @cindex notify output in @sc{gdb/mi}
21845 @var{notify-async-output} contains supplementary information that the
21846 client should handle (e.g., a new breakpoint information). All notify
21847 output is prefixed by @samp{=}.
21848
21849 @item
21850 @cindex console output in @sc{gdb/mi}
21851 @var{console-stream-output} is output that should be displayed as is in the
21852 console. It is the textual response to a CLI command. All the console
21853 output is prefixed by @samp{~}.
21854
21855 @item
21856 @cindex target output in @sc{gdb/mi}
21857 @var{target-stream-output} is the output produced by the target program.
21858 All the target output is prefixed by @samp{@@}.
21859
21860 @item
21861 @cindex log output in @sc{gdb/mi}
21862 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
21863 instance messages that should be displayed as part of an error log. All
21864 the log output is prefixed by @samp{&}.
21865
21866 @item
21867 @cindex list output in @sc{gdb/mi}
21868 New @sc{gdb/mi} commands should only output @var{lists} containing
21869 @var{values}.
21870
21871
21872 @end itemize
21873
21874 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
21875 details about the various output records.
21876
21877 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21878 @node GDB/MI Compatibility with CLI
21879 @section @sc{gdb/mi} Compatibility with CLI
21880
21881 @cindex compatibility, @sc{gdb/mi} and CLI
21882 @cindex @sc{gdb/mi}, compatibility with CLI
21883
21884 For the developers convenience CLI commands can be entered directly,
21885 but there may be some unexpected behaviour. For example, commands
21886 that query the user will behave as if the user replied yes, breakpoint
21887 command lists are not executed and some CLI commands, such as
21888 @code{if}, @code{when} and @code{define}, prompt for further input with
21889 @samp{>}, which is not valid MI output.
21890
21891 This feature may be removed at some stage in the future and it is
21892 recommended that front ends use the @code{-interpreter-exec} command
21893 (@pxref{-interpreter-exec}).
21894
21895 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21896 @node GDB/MI Development and Front Ends
21897 @section @sc{gdb/mi} Development and Front Ends
21898 @cindex @sc{gdb/mi} development
21899
21900 The application which takes the MI output and presents the state of the
21901 program being debugged to the user is called a @dfn{front end}.
21902
21903 Although @sc{gdb/mi} is still incomplete, it is currently being used
21904 by a variety of front ends to @value{GDBN}. This makes it difficult
21905 to introduce new functionality without breaking existing usage. This
21906 section tries to minimize the problems by describing how the protocol
21907 might change.
21908
21909 Some changes in MI need not break a carefully designed front end, and
21910 for these the MI version will remain unchanged. The following is a
21911 list of changes that may occur within one level, so front ends should
21912 parse MI output in a way that can handle them:
21913
21914 @itemize @bullet
21915 @item
21916 New MI commands may be added.
21917
21918 @item
21919 New fields may be added to the output of any MI command.
21920
21921 @item
21922 The range of values for fields with specified values, e.g.,
21923 @code{in_scope} (@pxref{-var-update}) may be extended.
21924
21925 @c The format of field's content e.g type prefix, may change so parse it
21926 @c at your own risk. Yes, in general?
21927
21928 @c The order of fields may change? Shouldn't really matter but it might
21929 @c resolve inconsistencies.
21930 @end itemize
21931
21932 If the changes are likely to break front ends, the MI version level
21933 will be increased by one. This will allow the front end to parse the
21934 output according to the MI version. Apart from mi0, new versions of
21935 @value{GDBN} will not support old versions of MI and it will be the
21936 responsibility of the front end to work with the new one.
21937
21938 @c Starting with mi3, add a new command -mi-version that prints the MI
21939 @c version?
21940
21941 The best way to avoid unexpected changes in MI that might break your front
21942 end is to make your project known to @value{GDBN} developers and
21943 follow development on @email{gdb@@sourceware.org} and
21944 @email{gdb-patches@@sourceware.org}.
21945 @cindex mailing lists
21946
21947 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21948 @node GDB/MI Output Records
21949 @section @sc{gdb/mi} Output Records
21950
21951 @menu
21952 * GDB/MI Result Records::
21953 * GDB/MI Stream Records::
21954 * GDB/MI Async Records::
21955 * GDB/MI Frame Information::
21956 * GDB/MI Thread Information::
21957 @end menu
21958
21959 @node GDB/MI Result Records
21960 @subsection @sc{gdb/mi} Result Records
21961
21962 @cindex result records in @sc{gdb/mi}
21963 @cindex @sc{gdb/mi}, result records
21964 In addition to a number of out-of-band notifications, the response to a
21965 @sc{gdb/mi} command includes one of the following result indications:
21966
21967 @table @code
21968 @findex ^done
21969 @item "^done" [ "," @var{results} ]
21970 The synchronous operation was successful, @code{@var{results}} are the return
21971 values.
21972
21973 @item "^running"
21974 @findex ^running
21975 @c Is this one correct? Should it be an out-of-band notification?
21976 The asynchronous operation was successfully started. The target is
21977 running.
21978
21979 @item "^connected"
21980 @findex ^connected
21981 @value{GDBN} has connected to a remote target.
21982
21983 @item "^error" "," @var{c-string}
21984 @findex ^error
21985 The operation failed. The @code{@var{c-string}} contains the corresponding
21986 error message.
21987
21988 @item "^exit"
21989 @findex ^exit
21990 @value{GDBN} has terminated.
21991
21992 @end table
21993
21994 @node GDB/MI Stream Records
21995 @subsection @sc{gdb/mi} Stream Records
21996
21997 @cindex @sc{gdb/mi}, stream records
21998 @cindex stream records in @sc{gdb/mi}
21999 @value{GDBN} internally maintains a number of output streams: the console, the
22000 target, and the log. The output intended for each of these streams is
22001 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
22002
22003 Each stream record begins with a unique @dfn{prefix character} which
22004 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
22005 Syntax}). In addition to the prefix, each stream record contains a
22006 @code{@var{string-output}}. This is either raw text (with an implicit new
22007 line) or a quoted C string (which does not contain an implicit newline).
22008
22009 @table @code
22010 @item "~" @var{string-output}
22011 The console output stream contains text that should be displayed in the
22012 CLI console window. It contains the textual responses to CLI commands.
22013
22014 @item "@@" @var{string-output}
22015 The target output stream contains any textual output from the running
22016 target. This is only present when GDB's event loop is truly
22017 asynchronous, which is currently only the case for remote targets.
22018
22019 @item "&" @var{string-output}
22020 The log stream contains debugging messages being produced by @value{GDBN}'s
22021 internals.
22022 @end table
22023
22024 @node GDB/MI Async Records
22025 @subsection @sc{gdb/mi} Async Records
22026
22027 @cindex async records in @sc{gdb/mi}
22028 @cindex @sc{gdb/mi}, async records
22029 @dfn{Async} records are used to notify the @sc{gdb/mi} client of
22030 additional changes that have occurred. Those changes can either be a
22031 consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
22032 target activity (e.g., target stopped).
22033
22034 The following is the list of possible async records:
22035
22036 @table @code
22037
22038 @item *running,thread-id="@var{thread}"
22039 The target is now running. The @var{thread} field tells which
22040 specific thread is now running, and can be @samp{all} if all threads
22041 are running. The frontend should assume that no interaction with a
22042 running thread is possible after this notification is produced.
22043 The frontend should not assume that this notification is output
22044 only once for any command. @value{GDBN} may emit this notification
22045 several times, either for different threads, because it cannot resume
22046 all threads together, or even for a single thread, if the thread must
22047 be stepped though some code before letting it run freely.
22048
22049 @item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
22050 The target has stopped. The @var{reason} field can have one of the
22051 following values:
22052
22053 @table @code
22054 @item breakpoint-hit
22055 A breakpoint was reached.
22056 @item watchpoint-trigger
22057 A watchpoint was triggered.
22058 @item read-watchpoint-trigger
22059 A read watchpoint was triggered.
22060 @item access-watchpoint-trigger
22061 An access watchpoint was triggered.
22062 @item function-finished
22063 An -exec-finish or similar CLI command was accomplished.
22064 @item location-reached
22065 An -exec-until or similar CLI command was accomplished.
22066 @item watchpoint-scope
22067 A watchpoint has gone out of scope.
22068 @item end-stepping-range
22069 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
22070 similar CLI command was accomplished.
22071 @item exited-signalled
22072 The inferior exited because of a signal.
22073 @item exited
22074 The inferior exited.
22075 @item exited-normally
22076 The inferior exited normally.
22077 @item signal-received
22078 A signal was received by the inferior.
22079 @end table
22080
22081 The @var{id} field identifies the thread that directly caused the stop
22082 -- for example by hitting a breakpoint. Depending on whether all-stop
22083 mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
22084 stop all threads, or only the thread that directly triggered the stop.
22085 If all threads are stopped, the @var{stopped} field will have the
22086 value of @code{"all"}. Otherwise, the value of the @var{stopped}
22087 field will be a list of thread identifiers. Presently, this list will
22088 always include a single thread, but frontend should be prepared to see
22089 several threads in the list. The @var{core} field reports the
22090 processor core on which the stop event has happened. This field may be absent
22091 if such information is not available.
22092
22093 @item =thread-group-created,id="@var{id}"
22094 @itemx =thread-group-exited,id="@var{id}"
22095 A thread thread group either was attached to, or has exited/detached
22096 from. The @var{id} field contains the @value{GDBN} identifier of the
22097 thread group.
22098
22099 @item =thread-created,id="@var{id}",group-id="@var{gid}"
22100 @itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
22101 A thread either was created, or has exited. The @var{id} field
22102 contains the @value{GDBN} identifier of the thread. The @var{gid}
22103 field identifies the thread group this thread belongs to.
22104
22105 @item =thread-selected,id="@var{id}"
22106 Informs that the selected thread was changed as result of the last
22107 command. This notification is not emitted as result of @code{-thread-select}
22108 command but is emitted whenever an MI command that is not documented
22109 to change the selected thread actually changes it. In particular,
22110 invoking, directly or indirectly (via user-defined command), the CLI
22111 @code{thread} command, will generate this notification.
22112
22113 We suggest that in response to this notification, front ends
22114 highlight the selected thread and cause subsequent commands to apply to
22115 that thread.
22116
22117 @item =library-loaded,...
22118 Reports that a new library file was loaded by the program. This
22119 notification has 4 fields---@var{id}, @var{target-name},
22120 @var{host-name}, and @var{symbols-loaded}. The @var{id} field is an
22121 opaque identifier of the library. For remote debugging case,
22122 @var{target-name} and @var{host-name} fields give the name of the
22123 library file on the target, and on the host respectively. For native
22124 debugging, both those fields have the same value. The
22125 @var{symbols-loaded} field reports if the debug symbols for this
22126 library are loaded.
22127
22128 @item =library-unloaded,...
22129 Reports that a library was unloaded by the program. This notification
22130 has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
22131 the same meaning as for the @code{=library-loaded} notification
22132
22133 @end table
22134
22135 @node GDB/MI Frame Information
22136 @subsection @sc{gdb/mi} Frame Information
22137
22138 Response from many MI commands includes an information about stack
22139 frame. This information is a tuple that may have the following
22140 fields:
22141
22142 @table @code
22143 @item level
22144 The level of the stack frame. The innermost frame has the level of
22145 zero. This field is always present.
22146
22147 @item func
22148 The name of the function corresponding to the frame. This field may
22149 be absent if @value{GDBN} is unable to determine the function name.
22150
22151 @item addr
22152 The code address for the frame. This field is always present.
22153
22154 @item file
22155 The name of the source files that correspond to the frame's code
22156 address. This field may be absent.
22157
22158 @item line
22159 The source line corresponding to the frames' code address. This field
22160 may be absent.
22161
22162 @item from
22163 The name of the binary file (either executable or shared library) the
22164 corresponds to the frame's code address. This field may be absent.
22165
22166 @end table
22167
22168 @node GDB/MI Thread Information
22169 @subsection @sc{gdb/mi} Thread Information
22170
22171 Whenever @value{GDBN} has to report an information about a thread, it
22172 uses a tuple with the following fields:
22173
22174 @table @code
22175 @item id
22176 The numeric id assigned to the thread by @value{GDBN}. This field is
22177 always present.
22178
22179 @item target-id
22180 Target-specific string identifying the thread. This field is always present.
22181
22182 @item details
22183 Additional information about the thread provided by the target.
22184 It is supposed to be human-readable and not interpreted by the
22185 frontend. This field is optional.
22186
22187 @item state
22188 Either @samp{stopped} or @samp{running}, depending on whether the
22189 thread is presently running. This field is always present.
22190
22191 @item core
22192 The value of this field is an integer number of the processor core the
22193 thread was last seen on. This field is optional.
22194 @end table
22195
22196
22197 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22198 @node GDB/MI Simple Examples
22199 @section Simple Examples of @sc{gdb/mi} Interaction
22200 @cindex @sc{gdb/mi}, simple examples
22201
22202 This subsection presents several simple examples of interaction using
22203 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
22204 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
22205 the output received from @sc{gdb/mi}.
22206
22207 Note the line breaks shown in the examples are here only for
22208 readability, they don't appear in the real output.
22209
22210 @subheading Setting a Breakpoint
22211
22212 Setting a breakpoint generates synchronous output which contains detailed
22213 information of the breakpoint.
22214
22215 @smallexample
22216 -> -break-insert main
22217 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
22218 enabled="y",addr="0x08048564",func="main",file="myprog.c",
22219 fullname="/home/nickrob/myprog.c",line="68",times="0"@}
22220 <- (gdb)
22221 @end smallexample
22222
22223 @subheading Program Execution
22224
22225 Program execution generates asynchronous records and MI gives the
22226 reason that execution stopped.
22227
22228 @smallexample
22229 -> -exec-run
22230 <- ^running
22231 <- (gdb)
22232 <- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
22233 frame=@{addr="0x08048564",func="main",
22234 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
22235 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
22236 <- (gdb)
22237 -> -exec-continue
22238 <- ^running
22239 <- (gdb)
22240 <- *stopped,reason="exited-normally"
22241 <- (gdb)
22242 @end smallexample
22243
22244 @subheading Quitting @value{GDBN}
22245
22246 Quitting @value{GDBN} just prints the result class @samp{^exit}.
22247
22248 @smallexample
22249 -> (gdb)
22250 <- -gdb-exit
22251 <- ^exit
22252 @end smallexample
22253
22254 Please note that @samp{^exit} is printed immediately, but it might
22255 take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
22256 performs necessary cleanups, including killing programs being debugged
22257 or disconnecting from debug hardware, so the frontend should wait till
22258 @value{GDBN} exits and should only forcibly kill @value{GDBN} if it
22259 fails to exit in reasonable time.
22260
22261 @subheading A Bad Command
22262
22263 Here's what happens if you pass a non-existent command:
22264
22265 @smallexample
22266 -> -rubbish
22267 <- ^error,msg="Undefined MI command: rubbish"
22268 <- (gdb)
22269 @end smallexample
22270
22271
22272 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22273 @node GDB/MI Command Description Format
22274 @section @sc{gdb/mi} Command Description Format
22275
22276 The remaining sections describe blocks of commands. Each block of
22277 commands is laid out in a fashion similar to this section.
22278
22279 @subheading Motivation
22280
22281 The motivation for this collection of commands.
22282
22283 @subheading Introduction
22284
22285 A brief introduction to this collection of commands as a whole.
22286
22287 @subheading Commands
22288
22289 For each command in the block, the following is described:
22290
22291 @subsubheading Synopsis
22292
22293 @smallexample
22294 -command @var{args}@dots{}
22295 @end smallexample
22296
22297 @subsubheading Result
22298
22299 @subsubheading @value{GDBN} Command
22300
22301 The corresponding @value{GDBN} CLI command(s), if any.
22302
22303 @subsubheading Example
22304
22305 Example(s) formatted for readability. Some of the described commands have
22306 not been implemented yet and these are labeled N.A.@: (not available).
22307
22308
22309 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22310 @node GDB/MI Breakpoint Commands
22311 @section @sc{gdb/mi} Breakpoint Commands
22312
22313 @cindex breakpoint commands for @sc{gdb/mi}
22314 @cindex @sc{gdb/mi}, breakpoint commands
22315 This section documents @sc{gdb/mi} commands for manipulating
22316 breakpoints.
22317
22318 @subheading The @code{-break-after} Command
22319 @findex -break-after
22320
22321 @subsubheading Synopsis
22322
22323 @smallexample
22324 -break-after @var{number} @var{count}
22325 @end smallexample
22326
22327 The breakpoint number @var{number} is not in effect until it has been
22328 hit @var{count} times. To see how this is reflected in the output of
22329 the @samp{-break-list} command, see the description of the
22330 @samp{-break-list} command below.
22331
22332 @subsubheading @value{GDBN} Command
22333
22334 The corresponding @value{GDBN} command is @samp{ignore}.
22335
22336 @subsubheading Example
22337
22338 @smallexample
22339 (gdb)
22340 -break-insert main
22341 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
22342 enabled="y",addr="0x000100d0",func="main",file="hello.c",
22343 fullname="/home/foo/hello.c",line="5",times="0"@}
22344 (gdb)
22345 -break-after 1 3
22346 ~
22347 ^done
22348 (gdb)
22349 -break-list
22350 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
22351 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
22352 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
22353 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
22354 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
22355 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
22356 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
22357 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
22358 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
22359 line="5",times="0",ignore="3"@}]@}
22360 (gdb)
22361 @end smallexample
22362
22363 @ignore
22364 @subheading The @code{-break-catch} Command
22365 @findex -break-catch
22366 @end ignore
22367
22368 @subheading The @code{-break-commands} Command
22369 @findex -break-commands
22370
22371 @subsubheading Synopsis
22372
22373 @smallexample
22374 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
22375 @end smallexample
22376
22377 Specifies the CLI commands that should be executed when breakpoint
22378 @var{number} is hit. The parameters @var{command1} to @var{commandN}
22379 are the commands. If no command is specified, any previously-set
22380 commands are cleared. @xref{Break Commands}. Typical use of this
22381 functionality is tracing a program, that is, printing of values of
22382 some variables whenever breakpoint is hit and then continuing.
22383
22384 @subsubheading @value{GDBN} Command
22385
22386 The corresponding @value{GDBN} command is @samp{commands}.
22387
22388 @subsubheading Example
22389
22390 @smallexample
22391 (gdb)
22392 -break-insert main
22393 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
22394 enabled="y",addr="0x000100d0",func="main",file="hello.c",
22395 fullname="/home/foo/hello.c",line="5",times="0"@}
22396 (gdb)
22397 -break-commands 1 "print v" "continue"
22398 ^done
22399 (gdb)
22400 @end smallexample
22401
22402 @subheading The @code{-break-condition} Command
22403 @findex -break-condition
22404
22405 @subsubheading Synopsis
22406
22407 @smallexample
22408 -break-condition @var{number} @var{expr}
22409 @end smallexample
22410
22411 Breakpoint @var{number} will stop the program only if the condition in
22412 @var{expr} is true. The condition becomes part of the
22413 @samp{-break-list} output (see the description of the @samp{-break-list}
22414 command below).
22415
22416 @subsubheading @value{GDBN} Command
22417
22418 The corresponding @value{GDBN} command is @samp{condition}.
22419
22420 @subsubheading Example
22421
22422 @smallexample
22423 (gdb)
22424 -break-condition 1 1
22425 ^done
22426 (gdb)
22427 -break-list
22428 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
22429 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
22430 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
22431 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
22432 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
22433 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
22434 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
22435 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
22436 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
22437 line="5",cond="1",times="0",ignore="3"@}]@}
22438 (gdb)
22439 @end smallexample
22440
22441 @subheading The @code{-break-delete} Command
22442 @findex -break-delete
22443
22444 @subsubheading Synopsis
22445
22446 @smallexample
22447 -break-delete ( @var{breakpoint} )+
22448 @end smallexample
22449
22450 Delete the breakpoint(s) whose number(s) are specified in the argument
22451 list. This is obviously reflected in the breakpoint list.
22452
22453 @subsubheading @value{GDBN} Command
22454
22455 The corresponding @value{GDBN} command is @samp{delete}.
22456
22457 @subsubheading Example
22458
22459 @smallexample
22460 (gdb)
22461 -break-delete 1
22462 ^done
22463 (gdb)
22464 -break-list
22465 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
22466 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
22467 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
22468 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
22469 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
22470 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
22471 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
22472 body=[]@}
22473 (gdb)
22474 @end smallexample
22475
22476 @subheading The @code{-break-disable} Command
22477 @findex -break-disable
22478
22479 @subsubheading Synopsis
22480
22481 @smallexample
22482 -break-disable ( @var{breakpoint} )+
22483 @end smallexample
22484
22485 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
22486 break list is now set to @samp{n} for the named @var{breakpoint}(s).
22487
22488 @subsubheading @value{GDBN} Command
22489
22490 The corresponding @value{GDBN} command is @samp{disable}.
22491
22492 @subsubheading Example
22493
22494 @smallexample
22495 (gdb)
22496 -break-disable 2
22497 ^done
22498 (gdb)
22499 -break-list
22500 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
22501 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
22502 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
22503 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
22504 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
22505 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
22506 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
22507 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
22508 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
22509 line="5",times="0"@}]@}
22510 (gdb)
22511 @end smallexample
22512
22513 @subheading The @code{-break-enable} Command
22514 @findex -break-enable
22515
22516 @subsubheading Synopsis
22517
22518 @smallexample
22519 -break-enable ( @var{breakpoint} )+
22520 @end smallexample
22521
22522 Enable (previously disabled) @var{breakpoint}(s).
22523
22524 @subsubheading @value{GDBN} Command
22525
22526 The corresponding @value{GDBN} command is @samp{enable}.
22527
22528 @subsubheading Example
22529
22530 @smallexample
22531 (gdb)
22532 -break-enable 2
22533 ^done
22534 (gdb)
22535 -break-list
22536 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
22537 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
22538 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
22539 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
22540 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
22541 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
22542 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
22543 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
22544 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
22545 line="5",times="0"@}]@}
22546 (gdb)
22547 @end smallexample
22548
22549 @subheading The @code{-break-info} Command
22550 @findex -break-info
22551
22552 @subsubheading Synopsis
22553
22554 @smallexample
22555 -break-info @var{breakpoint}
22556 @end smallexample
22557
22558 @c REDUNDANT???
22559 Get information about a single breakpoint.
22560
22561 @subsubheading @value{GDBN} Command
22562
22563 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
22564
22565 @subsubheading Example
22566 N.A.
22567
22568 @subheading The @code{-break-insert} Command
22569 @findex -break-insert
22570
22571 @subsubheading Synopsis
22572
22573 @smallexample
22574 -break-insert [ -t ] [ -h ] [ -f ] [ -d ]
22575 [ -c @var{condition} ] [ -i @var{ignore-count} ]
22576 [ -p @var{thread} ] [ @var{location} ]
22577 @end smallexample
22578
22579 @noindent
22580 If specified, @var{location}, can be one of:
22581
22582 @itemize @bullet
22583 @item function
22584 @c @item +offset
22585 @c @item -offset
22586 @c @item linenum
22587 @item filename:linenum
22588 @item filename:function
22589 @item *address
22590 @end itemize
22591
22592 The possible optional parameters of this command are:
22593
22594 @table @samp
22595 @item -t
22596 Insert a temporary breakpoint.
22597 @item -h
22598 Insert a hardware breakpoint.
22599 @item -c @var{condition}
22600 Make the breakpoint conditional on @var{condition}.
22601 @item -i @var{ignore-count}
22602 Initialize the @var{ignore-count}.
22603 @item -f
22604 If @var{location} cannot be parsed (for example if it
22605 refers to unknown files or functions), create a pending
22606 breakpoint. Without this flag, @value{GDBN} will report
22607 an error, and won't create a breakpoint, if @var{location}
22608 cannot be parsed.
22609 @item -d
22610 Create a disabled breakpoint.
22611 @end table
22612
22613 @subsubheading Result
22614
22615 The result is in the form:
22616
22617 @smallexample
22618 ^done,bkpt=@{number="@var{number}",type="@var{type}",disp="del"|"keep",
22619 enabled="y"|"n",addr="@var{hex}",func="@var{funcname}",file="@var{filename}",
22620 fullname="@var{full_filename}",line="@var{lineno}",[thread="@var{threadno},]
22621 times="@var{times}"@}
22622 @end smallexample
22623
22624 @noindent
22625 where @var{number} is the @value{GDBN} number for this breakpoint,
22626 @var{funcname} is the name of the function where the breakpoint was
22627 inserted, @var{filename} is the name of the source file which contains
22628 this function, @var{lineno} is the source line number within that file
22629 and @var{times} the number of times that the breakpoint has been hit
22630 (always 0 for -break-insert but may be greater for -break-info or -break-list
22631 which use the same output).
22632
22633 Note: this format is open to change.
22634 @c An out-of-band breakpoint instead of part of the result?
22635
22636 @subsubheading @value{GDBN} Command
22637
22638 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
22639 @samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
22640
22641 @subsubheading Example
22642
22643 @smallexample
22644 (gdb)
22645 -break-insert main
22646 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
22647 fullname="/home/foo/recursive2.c,line="4",times="0"@}
22648 (gdb)
22649 -break-insert -t foo
22650 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
22651 fullname="/home/foo/recursive2.c,line="11",times="0"@}
22652 (gdb)
22653 -break-list
22654 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
22655 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
22656 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
22657 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
22658 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
22659 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
22660 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
22661 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
22662 addr="0x0001072c", func="main",file="recursive2.c",
22663 fullname="/home/foo/recursive2.c,"line="4",times="0"@},
22664 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
22665 addr="0x00010774",func="foo",file="recursive2.c",
22666 fullname="/home/foo/recursive2.c",line="11",times="0"@}]@}
22667 (gdb)
22668 -break-insert -r foo.*
22669 ~int foo(int, int);
22670 ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
22671 "fullname="/home/foo/recursive2.c",line="11",times="0"@}
22672 (gdb)
22673 @end smallexample
22674
22675 @subheading The @code{-break-list} Command
22676 @findex -break-list
22677
22678 @subsubheading Synopsis
22679
22680 @smallexample
22681 -break-list
22682 @end smallexample
22683
22684 Displays the list of inserted breakpoints, showing the following fields:
22685
22686 @table @samp
22687 @item Number
22688 number of the breakpoint
22689 @item Type
22690 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
22691 @item Disposition
22692 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
22693 or @samp{nokeep}
22694 @item Enabled
22695 is the breakpoint enabled or no: @samp{y} or @samp{n}
22696 @item Address
22697 memory location at which the breakpoint is set
22698 @item What
22699 logical location of the breakpoint, expressed by function name, file
22700 name, line number
22701 @item Times
22702 number of times the breakpoint has been hit
22703 @end table
22704
22705 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
22706 @code{body} field is an empty list.
22707
22708 @subsubheading @value{GDBN} Command
22709
22710 The corresponding @value{GDBN} command is @samp{info break}.
22711
22712 @subsubheading Example
22713
22714 @smallexample
22715 (gdb)
22716 -break-list
22717 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
22718 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
22719 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
22720 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
22721 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
22722 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
22723 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
22724 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
22725 addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
22726 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
22727 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
22728 line="13",times="0"@}]@}
22729 (gdb)
22730 @end smallexample
22731
22732 Here's an example of the result when there are no breakpoints:
22733
22734 @smallexample
22735 (gdb)
22736 -break-list
22737 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
22738 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
22739 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
22740 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
22741 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
22742 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
22743 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
22744 body=[]@}
22745 (gdb)
22746 @end smallexample
22747
22748 @subheading The @code{-break-watch} Command
22749 @findex -break-watch
22750
22751 @subsubheading Synopsis
22752
22753 @smallexample
22754 -break-watch [ -a | -r ]
22755 @end smallexample
22756
22757 Create a watchpoint. With the @samp{-a} option it will create an
22758 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
22759 read from or on a write to the memory location. With the @samp{-r}
22760 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
22761 trigger only when the memory location is accessed for reading. Without
22762 either of the options, the watchpoint created is a regular watchpoint,
22763 i.e., it will trigger when the memory location is accessed for writing.
22764 @xref{Set Watchpoints, , Setting Watchpoints}.
22765
22766 Note that @samp{-break-list} will report a single list of watchpoints and
22767 breakpoints inserted.
22768
22769 @subsubheading @value{GDBN} Command
22770
22771 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
22772 @samp{rwatch}.
22773
22774 @subsubheading Example
22775
22776 Setting a watchpoint on a variable in the @code{main} function:
22777
22778 @smallexample
22779 (gdb)
22780 -break-watch x
22781 ^done,wpt=@{number="2",exp="x"@}
22782 (gdb)
22783 -exec-continue
22784 ^running
22785 (gdb)
22786 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
22787 value=@{old="-268439212",new="55"@},
22788 frame=@{func="main",args=[],file="recursive2.c",
22789 fullname="/home/foo/bar/recursive2.c",line="5"@}
22790 (gdb)
22791 @end smallexample
22792
22793 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
22794 the program execution twice: first for the variable changing value, then
22795 for the watchpoint going out of scope.
22796
22797 @smallexample
22798 (gdb)
22799 -break-watch C
22800 ^done,wpt=@{number="5",exp="C"@}
22801 (gdb)
22802 -exec-continue
22803 ^running
22804 (gdb)
22805 *stopped,reason="watchpoint-trigger",
22806 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
22807 frame=@{func="callee4",args=[],
22808 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
22809 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
22810 (gdb)
22811 -exec-continue
22812 ^running
22813 (gdb)
22814 *stopped,reason="watchpoint-scope",wpnum="5",
22815 frame=@{func="callee3",args=[@{name="strarg",
22816 value="0x11940 \"A string argument.\""@}],
22817 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
22818 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
22819 (gdb)
22820 @end smallexample
22821
22822 Listing breakpoints and watchpoints, at different points in the program
22823 execution. Note that once the watchpoint goes out of scope, it is
22824 deleted.
22825
22826 @smallexample
22827 (gdb)
22828 -break-watch C
22829 ^done,wpt=@{number="2",exp="C"@}
22830 (gdb)
22831 -break-list
22832 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
22833 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
22834 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
22835 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
22836 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
22837 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
22838 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
22839 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
22840 addr="0x00010734",func="callee4",
22841 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
22842 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",times="1"@},
22843 bkpt=@{number="2",type="watchpoint",disp="keep",
22844 enabled="y",addr="",what="C",times="0"@}]@}
22845 (gdb)
22846 -exec-continue
22847 ^running
22848 (gdb)
22849 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
22850 value=@{old="-276895068",new="3"@},
22851 frame=@{func="callee4",args=[],
22852 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
22853 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
22854 (gdb)
22855 -break-list
22856 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
22857 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
22858 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
22859 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
22860 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
22861 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
22862 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
22863 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
22864 addr="0x00010734",func="callee4",
22865 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
22866 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
22867 bkpt=@{number="2",type="watchpoint",disp="keep",
22868 enabled="y",addr="",what="C",times="-5"@}]@}
22869 (gdb)
22870 -exec-continue
22871 ^running
22872 ^done,reason="watchpoint-scope",wpnum="2",
22873 frame=@{func="callee3",args=[@{name="strarg",
22874 value="0x11940 \"A string argument.\""@}],
22875 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
22876 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
22877 (gdb)
22878 -break-list
22879 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
22880 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
22881 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
22882 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
22883 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
22884 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
22885 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
22886 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
22887 addr="0x00010734",func="callee4",
22888 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
22889 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
22890 times="1"@}]@}
22891 (gdb)
22892 @end smallexample
22893
22894 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22895 @node GDB/MI Program Context
22896 @section @sc{gdb/mi} Program Context
22897
22898 @subheading The @code{-exec-arguments} Command
22899 @findex -exec-arguments
22900
22901
22902 @subsubheading Synopsis
22903
22904 @smallexample
22905 -exec-arguments @var{args}
22906 @end smallexample
22907
22908 Set the inferior program arguments, to be used in the next
22909 @samp{-exec-run}.
22910
22911 @subsubheading @value{GDBN} Command
22912
22913 The corresponding @value{GDBN} command is @samp{set args}.
22914
22915 @subsubheading Example
22916
22917 @smallexample
22918 (gdb)
22919 -exec-arguments -v word
22920 ^done
22921 (gdb)
22922 @end smallexample
22923
22924
22925 @ignore
22926 @subheading The @code{-exec-show-arguments} Command
22927 @findex -exec-show-arguments
22928
22929 @subsubheading Synopsis
22930
22931 @smallexample
22932 -exec-show-arguments
22933 @end smallexample
22934
22935 Print the arguments of the program.
22936
22937 @subsubheading @value{GDBN} Command
22938
22939 The corresponding @value{GDBN} command is @samp{show args}.
22940
22941 @subsubheading Example
22942 N.A.
22943 @end ignore
22944
22945
22946 @subheading The @code{-environment-cd} Command
22947 @findex -environment-cd
22948
22949 @subsubheading Synopsis
22950
22951 @smallexample
22952 -environment-cd @var{pathdir}
22953 @end smallexample
22954
22955 Set @value{GDBN}'s working directory.
22956
22957 @subsubheading @value{GDBN} Command
22958
22959 The corresponding @value{GDBN} command is @samp{cd}.
22960
22961 @subsubheading Example
22962
22963 @smallexample
22964 (gdb)
22965 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
22966 ^done
22967 (gdb)
22968 @end smallexample
22969
22970
22971 @subheading The @code{-environment-directory} Command
22972 @findex -environment-directory
22973
22974 @subsubheading Synopsis
22975
22976 @smallexample
22977 -environment-directory [ -r ] [ @var{pathdir} ]+
22978 @end smallexample
22979
22980 Add directories @var{pathdir} to beginning of search path for source files.
22981 If the @samp{-r} option is used, the search path is reset to the default
22982 search path. If directories @var{pathdir} are supplied in addition to the
22983 @samp{-r} option, the search path is first reset and then addition
22984 occurs as normal.
22985 Multiple directories may be specified, separated by blanks. Specifying
22986 multiple directories in a single command
22987 results in the directories added to the beginning of the
22988 search path in the same order they were presented in the command.
22989 If blanks are needed as
22990 part of a directory name, double-quotes should be used around
22991 the name. In the command output, the path will show up separated
22992 by the system directory-separator character. The directory-separator
22993 character must not be used
22994 in any directory name.
22995 If no directories are specified, the current search path is displayed.
22996
22997 @subsubheading @value{GDBN} Command
22998
22999 The corresponding @value{GDBN} command is @samp{dir}.
23000
23001 @subsubheading Example
23002
23003 @smallexample
23004 (gdb)
23005 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
23006 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
23007 (gdb)
23008 -environment-directory ""
23009 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
23010 (gdb)
23011 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
23012 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
23013 (gdb)
23014 -environment-directory -r
23015 ^done,source-path="$cdir:$cwd"
23016 (gdb)
23017 @end smallexample
23018
23019
23020 @subheading The @code{-environment-path} Command
23021 @findex -environment-path
23022
23023 @subsubheading Synopsis
23024
23025 @smallexample
23026 -environment-path [ -r ] [ @var{pathdir} ]+
23027 @end smallexample
23028
23029 Add directories @var{pathdir} to beginning of search path for object files.
23030 If the @samp{-r} option is used, the search path is reset to the original
23031 search path that existed at gdb start-up. If directories @var{pathdir} are
23032 supplied in addition to the
23033 @samp{-r} option, the search path is first reset and then addition
23034 occurs as normal.
23035 Multiple directories may be specified, separated by blanks. Specifying
23036 multiple directories in a single command
23037 results in the directories added to the beginning of the
23038 search path in the same order they were presented in the command.
23039 If blanks are needed as
23040 part of a directory name, double-quotes should be used around
23041 the name. In the command output, the path will show up separated
23042 by the system directory-separator character. The directory-separator
23043 character must not be used
23044 in any directory name.
23045 If no directories are specified, the current path is displayed.
23046
23047
23048 @subsubheading @value{GDBN} Command
23049
23050 The corresponding @value{GDBN} command is @samp{path}.
23051
23052 @subsubheading Example
23053
23054 @smallexample
23055 (gdb)
23056 -environment-path
23057 ^done,path="/usr/bin"
23058 (gdb)
23059 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
23060 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
23061 (gdb)
23062 -environment-path -r /usr/local/bin
23063 ^done,path="/usr/local/bin:/usr/bin"
23064 (gdb)
23065 @end smallexample
23066
23067
23068 @subheading The @code{-environment-pwd} Command
23069 @findex -environment-pwd
23070
23071 @subsubheading Synopsis
23072
23073 @smallexample
23074 -environment-pwd
23075 @end smallexample
23076
23077 Show the current working directory.
23078
23079 @subsubheading @value{GDBN} Command
23080
23081 The corresponding @value{GDBN} command is @samp{pwd}.
23082
23083 @subsubheading Example
23084
23085 @smallexample
23086 (gdb)
23087 -environment-pwd
23088 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
23089 (gdb)
23090 @end smallexample
23091
23092 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23093 @node GDB/MI Thread Commands
23094 @section @sc{gdb/mi} Thread Commands
23095
23096
23097 @subheading The @code{-thread-info} Command
23098 @findex -thread-info
23099
23100 @subsubheading Synopsis
23101
23102 @smallexample
23103 -thread-info [ @var{thread-id} ]
23104 @end smallexample
23105
23106 Reports information about either a specific thread, if
23107 the @var{thread-id} parameter is present, or about all
23108 threads. When printing information about all threads,
23109 also reports the current thread.
23110
23111 @subsubheading @value{GDBN} Command
23112
23113 The @samp{info thread} command prints the same information
23114 about all threads.
23115
23116 @subsubheading Example
23117
23118 @smallexample
23119 -thread-info
23120 ^done,threads=[
23121 @{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
23122 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
23123 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
23124 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
23125 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}],
23126 current-thread-id="1"
23127 (gdb)
23128 @end smallexample
23129
23130 The @samp{state} field may have the following values:
23131
23132 @table @code
23133 @item stopped
23134 The thread is stopped. Frame information is available for stopped
23135 threads.
23136
23137 @item running
23138 The thread is running. There's no frame information for running
23139 threads.
23140
23141 @end table
23142
23143 @subheading The @code{-thread-list-ids} Command
23144 @findex -thread-list-ids
23145
23146 @subsubheading Synopsis
23147
23148 @smallexample
23149 -thread-list-ids
23150 @end smallexample
23151
23152 Produces a list of the currently known @value{GDBN} thread ids. At the
23153 end of the list it also prints the total number of such threads.
23154
23155 This command is retained for historical reasons, the
23156 @code{-thread-info} command should be used instead.
23157
23158 @subsubheading @value{GDBN} Command
23159
23160 Part of @samp{info threads} supplies the same information.
23161
23162 @subsubheading Example
23163
23164 @smallexample
23165 (gdb)
23166 -thread-list-ids
23167 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
23168 current-thread-id="1",number-of-threads="3"
23169 (gdb)
23170 @end smallexample
23171
23172
23173 @subheading The @code{-thread-select} Command
23174 @findex -thread-select
23175
23176 @subsubheading Synopsis
23177
23178 @smallexample
23179 -thread-select @var{threadnum}
23180 @end smallexample
23181
23182 Make @var{threadnum} the current thread. It prints the number of the new
23183 current thread, and the topmost frame for that thread.
23184
23185 This command is deprecated in favor of explicitly using the
23186 @samp{--thread} option to each command.
23187
23188 @subsubheading @value{GDBN} Command
23189
23190 The corresponding @value{GDBN} command is @samp{thread}.
23191
23192 @subsubheading Example
23193
23194 @smallexample
23195 (gdb)
23196 -exec-next
23197 ^running
23198 (gdb)
23199 *stopped,reason="end-stepping-range",thread-id="2",line="187",
23200 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
23201 (gdb)
23202 -thread-list-ids
23203 ^done,
23204 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
23205 number-of-threads="3"
23206 (gdb)
23207 -thread-select 3
23208 ^done,new-thread-id="3",
23209 frame=@{level="0",func="vprintf",
23210 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
23211 @{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
23212 (gdb)
23213 @end smallexample
23214
23215 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23216 @node GDB/MI Program Execution
23217 @section @sc{gdb/mi} Program Execution
23218
23219 These are the asynchronous commands which generate the out-of-band
23220 record @samp{*stopped}. Currently @value{GDBN} only really executes
23221 asynchronously with remote targets and this interaction is mimicked in
23222 other cases.
23223
23224 @subheading The @code{-exec-continue} Command
23225 @findex -exec-continue
23226
23227 @subsubheading Synopsis
23228
23229 @smallexample
23230 -exec-continue [--all|--thread-group N]
23231 @end smallexample
23232
23233 Resumes the execution of the inferior program until a breakpoint is
23234 encountered, or until the inferior exits. In all-stop mode
23235 (@pxref{All-Stop Mode}), may resume only one thread, or all threads,
23236 depending on the value of the @samp{scheduler-locking} variable. In
23237 non-stop mode (@pxref{Non-Stop Mode}), if the @samp{--all} is not
23238 specified, only the thread specified with the @samp{--thread} option
23239 (or current thread, if no @samp{--thread} is provided) is resumed. If
23240 @samp{--all} is specified, all threads will be resumed. The
23241 @samp{--all} option is ignored in all-stop mode. If the
23242 @samp{--thread-group} options is specified, then all threads in that
23243 thread group are resumed.
23244
23245 @subsubheading @value{GDBN} Command
23246
23247 The corresponding @value{GDBN} corresponding is @samp{continue}.
23248
23249 @subsubheading Example
23250
23251 @smallexample
23252 -exec-continue
23253 ^running
23254 (gdb)
23255 @@Hello world
23256 *stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
23257 func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
23258 line="13"@}
23259 (gdb)
23260 @end smallexample
23261
23262
23263 @subheading The @code{-exec-finish} Command
23264 @findex -exec-finish
23265
23266 @subsubheading Synopsis
23267
23268 @smallexample
23269 -exec-finish
23270 @end smallexample
23271
23272 Resumes the execution of the inferior program until the current
23273 function is exited. Displays the results returned by the function.
23274
23275 @subsubheading @value{GDBN} Command
23276
23277 The corresponding @value{GDBN} command is @samp{finish}.
23278
23279 @subsubheading Example
23280
23281 Function returning @code{void}.
23282
23283 @smallexample
23284 -exec-finish
23285 ^running
23286 (gdb)
23287 @@hello from foo
23288 *stopped,reason="function-finished",frame=@{func="main",args=[],
23289 file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
23290 (gdb)
23291 @end smallexample
23292
23293 Function returning other than @code{void}. The name of the internal
23294 @value{GDBN} variable storing the result is printed, together with the
23295 value itself.
23296
23297 @smallexample
23298 -exec-finish
23299 ^running
23300 (gdb)
23301 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
23302 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
23303 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
23304 gdb-result-var="$1",return-value="0"
23305 (gdb)
23306 @end smallexample
23307
23308
23309 @subheading The @code{-exec-interrupt} Command
23310 @findex -exec-interrupt
23311
23312 @subsubheading Synopsis
23313
23314 @smallexample
23315 -exec-interrupt [--all|--thread-group N]
23316 @end smallexample
23317
23318 Interrupts the background execution of the target. Note how the token
23319 associated with the stop message is the one for the execution command
23320 that has been interrupted. The token for the interrupt itself only
23321 appears in the @samp{^done} output. If the user is trying to
23322 interrupt a non-running program, an error message will be printed.
23323
23324 Note that when asynchronous execution is enabled, this command is
23325 asynchronous just like other execution commands. That is, first the
23326 @samp{^done} response will be printed, and the target stop will be
23327 reported after that using the @samp{*stopped} notification.
23328
23329 In non-stop mode, only the context thread is interrupted by default.
23330 All threads will be interrupted if the @samp{--all} option is
23331 specified. If the @samp{--thread-group} option is specified, all
23332 threads in that group will be interrupted.
23333
23334 @subsubheading @value{GDBN} Command
23335
23336 The corresponding @value{GDBN} command is @samp{interrupt}.
23337
23338 @subsubheading Example
23339
23340 @smallexample
23341 (gdb)
23342 111-exec-continue
23343 111^running
23344
23345 (gdb)
23346 222-exec-interrupt
23347 222^done
23348 (gdb)
23349 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
23350 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
23351 fullname="/home/foo/bar/try.c",line="13"@}
23352 (gdb)
23353
23354 (gdb)
23355 -exec-interrupt
23356 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
23357 (gdb)
23358 @end smallexample
23359
23360 @subheading The @code{-exec-jump} Command
23361 @findex -exec-jump
23362
23363 @subsubheading Synopsis
23364
23365 @smallexample
23366 -exec-jump @var{location}
23367 @end smallexample
23368
23369 Resumes execution of the inferior program at the location specified by
23370 parameter. @xref{Specify Location}, for a description of the
23371 different forms of @var{location}.
23372
23373 @subsubheading @value{GDBN} Command
23374
23375 The corresponding @value{GDBN} command is @samp{jump}.
23376
23377 @subsubheading Example
23378
23379 @smallexample
23380 -exec-jump foo.c:10
23381 *running,thread-id="all"
23382 ^running
23383 @end smallexample
23384
23385
23386 @subheading The @code{-exec-next} Command
23387 @findex -exec-next
23388
23389 @subsubheading Synopsis
23390
23391 @smallexample
23392 -exec-next
23393 @end smallexample
23394
23395 Resumes execution of the inferior program, stopping when the beginning
23396 of the next source line is reached.
23397
23398 @subsubheading @value{GDBN} Command
23399
23400 The corresponding @value{GDBN} command is @samp{next}.
23401
23402 @subsubheading Example
23403
23404 @smallexample
23405 -exec-next
23406 ^running
23407 (gdb)
23408 *stopped,reason="end-stepping-range",line="8",file="hello.c"
23409 (gdb)
23410 @end smallexample
23411
23412
23413 @subheading The @code{-exec-next-instruction} Command
23414 @findex -exec-next-instruction
23415
23416 @subsubheading Synopsis
23417
23418 @smallexample
23419 -exec-next-instruction
23420 @end smallexample
23421
23422 Executes one machine instruction. If the instruction is a function
23423 call, continues until the function returns. If the program stops at an
23424 instruction in the middle of a source line, the address will be
23425 printed as well.
23426
23427 @subsubheading @value{GDBN} Command
23428
23429 The corresponding @value{GDBN} command is @samp{nexti}.
23430
23431 @subsubheading Example
23432
23433 @smallexample
23434 (gdb)
23435 -exec-next-instruction
23436 ^running
23437
23438 (gdb)
23439 *stopped,reason="end-stepping-range",
23440 addr="0x000100d4",line="5",file="hello.c"
23441 (gdb)
23442 @end smallexample
23443
23444
23445 @subheading The @code{-exec-return} Command
23446 @findex -exec-return
23447
23448 @subsubheading Synopsis
23449
23450 @smallexample
23451 -exec-return
23452 @end smallexample
23453
23454 Makes current function return immediately. Doesn't execute the inferior.
23455 Displays the new current frame.
23456
23457 @subsubheading @value{GDBN} Command
23458
23459 The corresponding @value{GDBN} command is @samp{return}.
23460
23461 @subsubheading Example
23462
23463 @smallexample
23464 (gdb)
23465 200-break-insert callee4
23466 200^done,bkpt=@{number="1",addr="0x00010734",
23467 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
23468 (gdb)
23469 000-exec-run
23470 000^running
23471 (gdb)
23472 000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
23473 frame=@{func="callee4",args=[],
23474 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
23475 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
23476 (gdb)
23477 205-break-delete
23478 205^done
23479 (gdb)
23480 111-exec-return
23481 111^done,frame=@{level="0",func="callee3",
23482 args=[@{name="strarg",
23483 value="0x11940 \"A string argument.\""@}],
23484 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
23485 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
23486 (gdb)
23487 @end smallexample
23488
23489
23490 @subheading The @code{-exec-run} Command
23491 @findex -exec-run
23492
23493 @subsubheading Synopsis
23494
23495 @smallexample
23496 -exec-run
23497 @end smallexample
23498
23499 Starts execution of the inferior from the beginning. The inferior
23500 executes until either a breakpoint is encountered or the program
23501 exits. In the latter case the output will include an exit code, if
23502 the program has exited exceptionally.
23503
23504 @subsubheading @value{GDBN} Command
23505
23506 The corresponding @value{GDBN} command is @samp{run}.
23507
23508 @subsubheading Examples
23509
23510 @smallexample
23511 (gdb)
23512 -break-insert main
23513 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
23514 (gdb)
23515 -exec-run
23516 ^running
23517 (gdb)
23518 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
23519 frame=@{func="main",args=[],file="recursive2.c",
23520 fullname="/home/foo/bar/recursive2.c",line="4"@}
23521 (gdb)
23522 @end smallexample
23523
23524 @noindent
23525 Program exited normally:
23526
23527 @smallexample
23528 (gdb)
23529 -exec-run
23530 ^running
23531 (gdb)
23532 x = 55
23533 *stopped,reason="exited-normally"
23534 (gdb)
23535 @end smallexample
23536
23537 @noindent
23538 Program exited exceptionally:
23539
23540 @smallexample
23541 (gdb)
23542 -exec-run
23543 ^running
23544 (gdb)
23545 x = 55
23546 *stopped,reason="exited",exit-code="01"
23547 (gdb)
23548 @end smallexample
23549
23550 Another way the program can terminate is if it receives a signal such as
23551 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
23552
23553 @smallexample
23554 (gdb)
23555 *stopped,reason="exited-signalled",signal-name="SIGINT",
23556 signal-meaning="Interrupt"
23557 @end smallexample
23558
23559
23560 @c @subheading -exec-signal
23561
23562
23563 @subheading The @code{-exec-step} Command
23564 @findex -exec-step
23565
23566 @subsubheading Synopsis
23567
23568 @smallexample
23569 -exec-step
23570 @end smallexample
23571
23572 Resumes execution of the inferior program, stopping when the beginning
23573 of the next source line is reached, if the next source line is not a
23574 function call. If it is, stop at the first instruction of the called
23575 function.
23576
23577 @subsubheading @value{GDBN} Command
23578
23579 The corresponding @value{GDBN} command is @samp{step}.
23580
23581 @subsubheading Example
23582
23583 Stepping into a function:
23584
23585 @smallexample
23586 -exec-step
23587 ^running
23588 (gdb)
23589 *stopped,reason="end-stepping-range",
23590 frame=@{func="foo",args=[@{name="a",value="10"@},
23591 @{name="b",value="0"@}],file="recursive2.c",
23592 fullname="/home/foo/bar/recursive2.c",line="11"@}
23593 (gdb)
23594 @end smallexample
23595
23596 Regular stepping:
23597
23598 @smallexample
23599 -exec-step
23600 ^running
23601 (gdb)
23602 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
23603 (gdb)
23604 @end smallexample
23605
23606
23607 @subheading The @code{-exec-step-instruction} Command
23608 @findex -exec-step-instruction
23609
23610 @subsubheading Synopsis
23611
23612 @smallexample
23613 -exec-step-instruction
23614 @end smallexample
23615
23616 Resumes the inferior which executes one machine instruction. The
23617 output, once @value{GDBN} has stopped, will vary depending on whether
23618 we have stopped in the middle of a source line or not. In the former
23619 case, the address at which the program stopped will be printed as
23620 well.
23621
23622 @subsubheading @value{GDBN} Command
23623
23624 The corresponding @value{GDBN} command is @samp{stepi}.
23625
23626 @subsubheading Example
23627
23628 @smallexample
23629 (gdb)
23630 -exec-step-instruction
23631 ^running
23632
23633 (gdb)
23634 *stopped,reason="end-stepping-range",
23635 frame=@{func="foo",args=[],file="try.c",
23636 fullname="/home/foo/bar/try.c",line="10"@}
23637 (gdb)
23638 -exec-step-instruction
23639 ^running
23640
23641 (gdb)
23642 *stopped,reason="end-stepping-range",
23643 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
23644 fullname="/home/foo/bar/try.c",line="10"@}
23645 (gdb)
23646 @end smallexample
23647
23648
23649 @subheading The @code{-exec-until} Command
23650 @findex -exec-until
23651
23652 @subsubheading Synopsis
23653
23654 @smallexample
23655 -exec-until [ @var{location} ]
23656 @end smallexample
23657
23658 Executes the inferior until the @var{location} specified in the
23659 argument is reached. If there is no argument, the inferior executes
23660 until a source line greater than the current one is reached. The
23661 reason for stopping in this case will be @samp{location-reached}.
23662
23663 @subsubheading @value{GDBN} Command
23664
23665 The corresponding @value{GDBN} command is @samp{until}.
23666
23667 @subsubheading Example
23668
23669 @smallexample
23670 (gdb)
23671 -exec-until recursive2.c:6
23672 ^running
23673 (gdb)
23674 x = 55
23675 *stopped,reason="location-reached",frame=@{func="main",args=[],
23676 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
23677 (gdb)
23678 @end smallexample
23679
23680 @ignore
23681 @subheading -file-clear
23682 Is this going away????
23683 @end ignore
23684
23685 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23686 @node GDB/MI Stack Manipulation
23687 @section @sc{gdb/mi} Stack Manipulation Commands
23688
23689
23690 @subheading The @code{-stack-info-frame} Command
23691 @findex -stack-info-frame
23692
23693 @subsubheading Synopsis
23694
23695 @smallexample
23696 -stack-info-frame
23697 @end smallexample
23698
23699 Get info on the selected frame.
23700
23701 @subsubheading @value{GDBN} Command
23702
23703 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
23704 (without arguments).
23705
23706 @subsubheading Example
23707
23708 @smallexample
23709 (gdb)
23710 -stack-info-frame
23711 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
23712 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
23713 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
23714 (gdb)
23715 @end smallexample
23716
23717 @subheading The @code{-stack-info-depth} Command
23718 @findex -stack-info-depth
23719
23720 @subsubheading Synopsis
23721
23722 @smallexample
23723 -stack-info-depth [ @var{max-depth} ]
23724 @end smallexample
23725
23726 Return the depth of the stack. If the integer argument @var{max-depth}
23727 is specified, do not count beyond @var{max-depth} frames.
23728
23729 @subsubheading @value{GDBN} Command
23730
23731 There's no equivalent @value{GDBN} command.
23732
23733 @subsubheading Example
23734
23735 For a stack with frame levels 0 through 11:
23736
23737 @smallexample
23738 (gdb)
23739 -stack-info-depth
23740 ^done,depth="12"
23741 (gdb)
23742 -stack-info-depth 4
23743 ^done,depth="4"
23744 (gdb)
23745 -stack-info-depth 12
23746 ^done,depth="12"
23747 (gdb)
23748 -stack-info-depth 11
23749 ^done,depth="11"
23750 (gdb)
23751 -stack-info-depth 13
23752 ^done,depth="12"
23753 (gdb)
23754 @end smallexample
23755
23756 @subheading The @code{-stack-list-arguments} Command
23757 @findex -stack-list-arguments
23758
23759 @subsubheading Synopsis
23760
23761 @smallexample
23762 -stack-list-arguments @var{print-values}
23763 [ @var{low-frame} @var{high-frame} ]
23764 @end smallexample
23765
23766 Display a list of the arguments for the frames between @var{low-frame}
23767 and @var{high-frame} (inclusive). If @var{low-frame} and
23768 @var{high-frame} are not provided, list the arguments for the whole
23769 call stack. If the two arguments are equal, show the single frame
23770 at the corresponding level. It is an error if @var{low-frame} is
23771 larger than the actual number of frames. On the other hand,
23772 @var{high-frame} may be larger than the actual number of frames, in
23773 which case only existing frames will be returned.
23774
23775 If @var{print-values} is 0 or @code{--no-values}, print only the names of
23776 the variables; if it is 1 or @code{--all-values}, print also their
23777 values; and if it is 2 or @code{--simple-values}, print the name,
23778 type and value for simple data types, and the name and type for arrays,
23779 structures and unions.
23780
23781 Use of this command to obtain arguments in a single frame is
23782 deprecated in favor of the @samp{-stack-list-variables} command.
23783
23784 @subsubheading @value{GDBN} Command
23785
23786 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
23787 @samp{gdb_get_args} command which partially overlaps with the
23788 functionality of @samp{-stack-list-arguments}.
23789
23790 @subsubheading Example
23791
23792 @smallexample
23793 (gdb)
23794 -stack-list-frames
23795 ^done,
23796 stack=[
23797 frame=@{level="0",addr="0x00010734",func="callee4",
23798 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
23799 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
23800 frame=@{level="1",addr="0x0001076c",func="callee3",
23801 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
23802 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
23803 frame=@{level="2",addr="0x0001078c",func="callee2",
23804 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
23805 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
23806 frame=@{level="3",addr="0x000107b4",func="callee1",
23807 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
23808 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
23809 frame=@{level="4",addr="0x000107e0",func="main",
23810 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
23811 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
23812 (gdb)
23813 -stack-list-arguments 0
23814 ^done,
23815 stack-args=[
23816 frame=@{level="0",args=[]@},
23817 frame=@{level="1",args=[name="strarg"]@},
23818 frame=@{level="2",args=[name="intarg",name="strarg"]@},
23819 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
23820 frame=@{level="4",args=[]@}]
23821 (gdb)
23822 -stack-list-arguments 1
23823 ^done,
23824 stack-args=[
23825 frame=@{level="0",args=[]@},
23826 frame=@{level="1",
23827 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
23828 frame=@{level="2",args=[
23829 @{name="intarg",value="2"@},
23830 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
23831 @{frame=@{level="3",args=[
23832 @{name="intarg",value="2"@},
23833 @{name="strarg",value="0x11940 \"A string argument.\""@},
23834 @{name="fltarg",value="3.5"@}]@},
23835 frame=@{level="4",args=[]@}]
23836 (gdb)
23837 -stack-list-arguments 0 2 2
23838 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
23839 (gdb)
23840 -stack-list-arguments 1 2 2
23841 ^done,stack-args=[frame=@{level="2",
23842 args=[@{name="intarg",value="2"@},
23843 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
23844 (gdb)
23845 @end smallexample
23846
23847 @c @subheading -stack-list-exception-handlers
23848
23849
23850 @subheading The @code{-stack-list-frames} Command
23851 @findex -stack-list-frames
23852
23853 @subsubheading Synopsis
23854
23855 @smallexample
23856 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
23857 @end smallexample
23858
23859 List the frames currently on the stack. For each frame it displays the
23860 following info:
23861
23862 @table @samp
23863 @item @var{level}
23864 The frame number, 0 being the topmost frame, i.e., the innermost function.
23865 @item @var{addr}
23866 The @code{$pc} value for that frame.
23867 @item @var{func}
23868 Function name.
23869 @item @var{file}
23870 File name of the source file where the function lives.
23871 @item @var{line}
23872 Line number corresponding to the @code{$pc}.
23873 @end table
23874
23875 If invoked without arguments, this command prints a backtrace for the
23876 whole stack. If given two integer arguments, it shows the frames whose
23877 levels are between the two arguments (inclusive). If the two arguments
23878 are equal, it shows the single frame at the corresponding level. It is
23879 an error if @var{low-frame} is larger than the actual number of
23880 frames. On the other hand, @var{high-frame} may be larger than the
23881 actual number of frames, in which case only existing frames will be returned.
23882
23883 @subsubheading @value{GDBN} Command
23884
23885 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
23886
23887 @subsubheading Example
23888
23889 Full stack backtrace:
23890
23891 @smallexample
23892 (gdb)
23893 -stack-list-frames
23894 ^done,stack=
23895 [frame=@{level="0",addr="0x0001076c",func="foo",
23896 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
23897 frame=@{level="1",addr="0x000107a4",func="foo",
23898 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
23899 frame=@{level="2",addr="0x000107a4",func="foo",
23900 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
23901 frame=@{level="3",addr="0x000107a4",func="foo",
23902 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
23903 frame=@{level="4",addr="0x000107a4",func="foo",
23904 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
23905 frame=@{level="5",addr="0x000107a4",func="foo",
23906 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
23907 frame=@{level="6",addr="0x000107a4",func="foo",
23908 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
23909 frame=@{level="7",addr="0x000107a4",func="foo",
23910 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
23911 frame=@{level="8",addr="0x000107a4",func="foo",
23912 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
23913 frame=@{level="9",addr="0x000107a4",func="foo",
23914 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
23915 frame=@{level="10",addr="0x000107a4",func="foo",
23916 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
23917 frame=@{level="11",addr="0x00010738",func="main",
23918 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
23919 (gdb)
23920 @end smallexample
23921
23922 Show frames between @var{low_frame} and @var{high_frame}:
23923
23924 @smallexample
23925 (gdb)
23926 -stack-list-frames 3 5
23927 ^done,stack=
23928 [frame=@{level="3",addr="0x000107a4",func="foo",
23929 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
23930 frame=@{level="4",addr="0x000107a4",func="foo",
23931 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
23932 frame=@{level="5",addr="0x000107a4",func="foo",
23933 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
23934 (gdb)
23935 @end smallexample
23936
23937 Show a single frame:
23938
23939 @smallexample
23940 (gdb)
23941 -stack-list-frames 3 3
23942 ^done,stack=
23943 [frame=@{level="3",addr="0x000107a4",func="foo",
23944 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
23945 (gdb)
23946 @end smallexample
23947
23948
23949 @subheading The @code{-stack-list-locals} Command
23950 @findex -stack-list-locals
23951
23952 @subsubheading Synopsis
23953
23954 @smallexample
23955 -stack-list-locals @var{print-values}
23956 @end smallexample
23957
23958 Display the local variable names for the selected frame. If
23959 @var{print-values} is 0 or @code{--no-values}, print only the names of
23960 the variables; if it is 1 or @code{--all-values}, print also their
23961 values; and if it is 2 or @code{--simple-values}, print the name,
23962 type and value for simple data types, and the name and type for arrays,
23963 structures and unions. In this last case, a frontend can immediately
23964 display the value of simple data types and create variable objects for
23965 other data types when the user wishes to explore their values in
23966 more detail.
23967
23968 This command is deprecated in favor of the
23969 @samp{-stack-list-variables} command.
23970
23971 @subsubheading @value{GDBN} Command
23972
23973 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
23974
23975 @subsubheading Example
23976
23977 @smallexample
23978 (gdb)
23979 -stack-list-locals 0
23980 ^done,locals=[name="A",name="B",name="C"]
23981 (gdb)
23982 -stack-list-locals --all-values
23983 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
23984 @{name="C",value="@{1, 2, 3@}"@}]
23985 -stack-list-locals --simple-values
23986 ^done,locals=[@{name="A",type="int",value="1"@},
23987 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
23988 (gdb)
23989 @end smallexample
23990
23991 @subheading The @code{-stack-list-variables} Command
23992 @findex -stack-list-variables
23993
23994 @subsubheading Synopsis
23995
23996 @smallexample
23997 -stack-list-variables @var{print-values}
23998 @end smallexample
23999
24000 Display the names of local variables and function arguments for the selected frame. If
24001 @var{print-values} is 0 or @code{--no-values}, print only the names of
24002 the variables; if it is 1 or @code{--all-values}, print also their
24003 values; and if it is 2 or @code{--simple-values}, print the name,
24004 type and value for simple data types, and the name and type for arrays,
24005 structures and unions.
24006
24007 @subsubheading Example
24008
24009 @smallexample
24010 (gdb)
24011 -stack-list-variables --thread 1 --frame 0 --all-values
24012 ^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
24013 (gdb)
24014 @end smallexample
24015
24016
24017 @subheading The @code{-stack-select-frame} Command
24018 @findex -stack-select-frame
24019
24020 @subsubheading Synopsis
24021
24022 @smallexample
24023 -stack-select-frame @var{framenum}
24024 @end smallexample
24025
24026 Change the selected frame. Select a different frame @var{framenum} on
24027 the stack.
24028
24029 This command in deprecated in favor of passing the @samp{--frame}
24030 option to every command.
24031
24032 @subsubheading @value{GDBN} Command
24033
24034 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
24035 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
24036
24037 @subsubheading Example
24038
24039 @smallexample
24040 (gdb)
24041 -stack-select-frame 2
24042 ^done
24043 (gdb)
24044 @end smallexample
24045
24046 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24047 @node GDB/MI Variable Objects
24048 @section @sc{gdb/mi} Variable Objects
24049
24050 @ignore
24051
24052 @subheading Motivation for Variable Objects in @sc{gdb/mi}
24053
24054 For the implementation of a variable debugger window (locals, watched
24055 expressions, etc.), we are proposing the adaptation of the existing code
24056 used by @code{Insight}.
24057
24058 The two main reasons for that are:
24059
24060 @enumerate 1
24061 @item
24062 It has been proven in practice (it is already on its second generation).
24063
24064 @item
24065 It will shorten development time (needless to say how important it is
24066 now).
24067 @end enumerate
24068
24069 The original interface was designed to be used by Tcl code, so it was
24070 slightly changed so it could be used through @sc{gdb/mi}. This section
24071 describes the @sc{gdb/mi} operations that will be available and gives some
24072 hints about their use.
24073
24074 @emph{Note}: In addition to the set of operations described here, we
24075 expect the @sc{gui} implementation of a variable window to require, at
24076 least, the following operations:
24077
24078 @itemize @bullet
24079 @item @code{-gdb-show} @code{output-radix}
24080 @item @code{-stack-list-arguments}
24081 @item @code{-stack-list-locals}
24082 @item @code{-stack-select-frame}
24083 @end itemize
24084
24085 @end ignore
24086
24087 @subheading Introduction to Variable Objects
24088
24089 @cindex variable objects in @sc{gdb/mi}
24090
24091 Variable objects are "object-oriented" MI interface for examining and
24092 changing values of expressions. Unlike some other MI interfaces that
24093 work with expressions, variable objects are specifically designed for
24094 simple and efficient presentation in the frontend. A variable object
24095 is identified by string name. When a variable object is created, the
24096 frontend specifies the expression for that variable object. The
24097 expression can be a simple variable, or it can be an arbitrary complex
24098 expression, and can even involve CPU registers. After creating a
24099 variable object, the frontend can invoke other variable object
24100 operations---for example to obtain or change the value of a variable
24101 object, or to change display format.
24102
24103 Variable objects have hierarchical tree structure. Any variable object
24104 that corresponds to a composite type, such as structure in C, has
24105 a number of child variable objects, for example corresponding to each
24106 element of a structure. A child variable object can itself have
24107 children, recursively. Recursion ends when we reach
24108 leaf variable objects, which always have built-in types. Child variable
24109 objects are created only by explicit request, so if a frontend
24110 is not interested in the children of a particular variable object, no
24111 child will be created.
24112
24113 For a leaf variable object it is possible to obtain its value as a
24114 string, or set the value from a string. String value can be also
24115 obtained for a non-leaf variable object, but it's generally a string
24116 that only indicates the type of the object, and does not list its
24117 contents. Assignment to a non-leaf variable object is not allowed.
24118
24119 A frontend does not need to read the values of all variable objects each time
24120 the program stops. Instead, MI provides an update command that lists all
24121 variable objects whose values has changed since the last update
24122 operation. This considerably reduces the amount of data that must
24123 be transferred to the frontend. As noted above, children variable
24124 objects are created on demand, and only leaf variable objects have a
24125 real value. As result, gdb will read target memory only for leaf
24126 variables that frontend has created.
24127
24128 The automatic update is not always desirable. For example, a frontend
24129 might want to keep a value of some expression for future reference,
24130 and never update it. For another example, fetching memory is
24131 relatively slow for embedded targets, so a frontend might want
24132 to disable automatic update for the variables that are either not
24133 visible on the screen, or ``closed''. This is possible using so
24134 called ``frozen variable objects''. Such variable objects are never
24135 implicitly updated.
24136
24137 Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
24138 fixed variable object, the expression is parsed when the variable
24139 object is created, including associating identifiers to specific
24140 variables. The meaning of expression never changes. For a floating
24141 variable object the values of variables whose names appear in the
24142 expressions are re-evaluated every time in the context of the current
24143 frame. Consider this example:
24144
24145 @smallexample
24146 void do_work(...)
24147 @{
24148 struct work_state state;
24149
24150 if (...)
24151 do_work(...);
24152 @}
24153 @end smallexample
24154
24155 If a fixed variable object for the @code{state} variable is created in
24156 this function, and we enter the recursive call, the the variable
24157 object will report the value of @code{state} in the top-level
24158 @code{do_work} invocation. On the other hand, a floating variable
24159 object will report the value of @code{state} in the current frame.
24160
24161 If an expression specified when creating a fixed variable object
24162 refers to a local variable, the variable object becomes bound to the
24163 thread and frame in which the variable object is created. When such
24164 variable object is updated, @value{GDBN} makes sure that the
24165 thread/frame combination the variable object is bound to still exists,
24166 and re-evaluates the variable object in context of that thread/frame.
24167
24168 The following is the complete set of @sc{gdb/mi} operations defined to
24169 access this functionality:
24170
24171 @multitable @columnfractions .4 .6
24172 @item @strong{Operation}
24173 @tab @strong{Description}
24174
24175 @item @code{-enable-pretty-printing}
24176 @tab enable Python-based pretty-printing
24177 @item @code{-var-create}
24178 @tab create a variable object
24179 @item @code{-var-delete}
24180 @tab delete the variable object and/or its children
24181 @item @code{-var-set-format}
24182 @tab set the display format of this variable
24183 @item @code{-var-show-format}
24184 @tab show the display format of this variable
24185 @item @code{-var-info-num-children}
24186 @tab tells how many children this object has
24187 @item @code{-var-list-children}
24188 @tab return a list of the object's children
24189 @item @code{-var-info-type}
24190 @tab show the type of this variable object
24191 @item @code{-var-info-expression}
24192 @tab print parent-relative expression that this variable object represents
24193 @item @code{-var-info-path-expression}
24194 @tab print full expression that this variable object represents
24195 @item @code{-var-show-attributes}
24196 @tab is this variable editable? does it exist here?
24197 @item @code{-var-evaluate-expression}
24198 @tab get the value of this variable
24199 @item @code{-var-assign}
24200 @tab set the value of this variable
24201 @item @code{-var-update}
24202 @tab update the variable and its children
24203 @item @code{-var-set-frozen}
24204 @tab set frozeness attribute
24205 @item @code{-var-set-update-range}
24206 @tab set range of children to display on update
24207 @end multitable
24208
24209 In the next subsection we describe each operation in detail and suggest
24210 how it can be used.
24211
24212 @subheading Description And Use of Operations on Variable Objects
24213
24214 @subheading The @code{-enable-pretty-printing} Command
24215 @findex -enable-pretty-printing
24216
24217 @smallexample
24218 -enable-pretty-printing
24219 @end smallexample
24220
24221 @value{GDBN} allows Python-based visualizers to affect the output of the
24222 MI variable object commands. However, because there was no way to
24223 implement this in a fully backward-compatible way, a front end must
24224 request that this functionality be enabled.
24225
24226 Once enabled, this feature cannot be disabled.
24227
24228 Note that if Python support has not been compiled into @value{GDBN},
24229 this command will still succeed (and do nothing).
24230
24231 This feature is currently (as of @value{GDBN} 7.0) experimental, and
24232 may work differently in future versions of @value{GDBN}.
24233
24234 @subheading The @code{-var-create} Command
24235 @findex -var-create
24236
24237 @subsubheading Synopsis
24238
24239 @smallexample
24240 -var-create @{@var{name} | "-"@}
24241 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
24242 @end smallexample
24243
24244 This operation creates a variable object, which allows the monitoring of
24245 a variable, the result of an expression, a memory cell or a CPU
24246 register.
24247
24248 The @var{name} parameter is the string by which the object can be
24249 referenced. It must be unique. If @samp{-} is specified, the varobj
24250 system will generate a string ``varNNNNNN'' automatically. It will be
24251 unique provided that one does not specify @var{name} of that format.
24252 The command fails if a duplicate name is found.
24253
24254 The frame under which the expression should be evaluated can be
24255 specified by @var{frame-addr}. A @samp{*} indicates that the current
24256 frame should be used. A @samp{@@} indicates that a floating variable
24257 object must be created.
24258
24259 @var{expression} is any expression valid on the current language set (must not
24260 begin with a @samp{*}), or one of the following:
24261
24262 @itemize @bullet
24263 @item
24264 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
24265
24266 @item
24267 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
24268
24269 @item
24270 @samp{$@var{regname}} --- a CPU register name
24271 @end itemize
24272
24273 @cindex dynamic varobj
24274 A varobj's contents may be provided by a Python-based pretty-printer. In this
24275 case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
24276 have slightly different semantics in some cases. If the
24277 @code{-enable-pretty-printing} command is not sent, then @value{GDBN}
24278 will never create a dynamic varobj. This ensures backward
24279 compatibility for existing clients.
24280
24281 @subsubheading Result
24282
24283 This operation returns attributes of the newly-created varobj. These
24284 are:
24285
24286 @table @samp
24287 @item name
24288 The name of the varobj.
24289
24290 @item numchild
24291 The number of children of the varobj. This number is not necessarily
24292 reliable for a dynamic varobj. Instead, you must examine the
24293 @samp{has_more} attribute.
24294
24295 @item value
24296 The varobj's scalar value. For a varobj whose type is some sort of
24297 aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
24298 will not be interesting.
24299
24300 @item type
24301 The varobj's type. This is a string representation of the type, as
24302 would be printed by the @value{GDBN} CLI.
24303
24304 @item thread-id
24305 If a variable object is bound to a specific thread, then this is the
24306 thread's identifier.
24307
24308 @item has_more
24309 For a dynamic varobj, this indicates whether there appear to be any
24310 children available. For a non-dynamic varobj, this will be 0.
24311
24312 @item dynamic
24313 This attribute will be present and have the value @samp{1} if the
24314 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
24315 then this attribute will not be present.
24316
24317 @item displayhint
24318 A dynamic varobj can supply a display hint to the front end. The
24319 value comes directly from the Python pretty-printer object's
24320 @code{display_hint} method. @xref{Pretty Printing}.
24321 @end table
24322
24323 Typical output will look like this:
24324
24325 @smallexample
24326 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
24327 has_more="@var{has_more}"
24328 @end smallexample
24329
24330
24331 @subheading The @code{-var-delete} Command
24332 @findex -var-delete
24333
24334 @subsubheading Synopsis
24335
24336 @smallexample
24337 -var-delete [ -c ] @var{name}
24338 @end smallexample
24339
24340 Deletes a previously created variable object and all of its children.
24341 With the @samp{-c} option, just deletes the children.
24342
24343 Returns an error if the object @var{name} is not found.
24344
24345
24346 @subheading The @code{-var-set-format} Command
24347 @findex -var-set-format
24348
24349 @subsubheading Synopsis
24350
24351 @smallexample
24352 -var-set-format @var{name} @var{format-spec}
24353 @end smallexample
24354
24355 Sets the output format for the value of the object @var{name} to be
24356 @var{format-spec}.
24357
24358 @anchor{-var-set-format}
24359 The syntax for the @var{format-spec} is as follows:
24360
24361 @smallexample
24362 @var{format-spec} @expansion{}
24363 @{binary | decimal | hexadecimal | octal | natural@}
24364 @end smallexample
24365
24366 The natural format is the default format choosen automatically
24367 based on the variable type (like decimal for an @code{int}, hex
24368 for pointers, etc.).
24369
24370 For a variable with children, the format is set only on the
24371 variable itself, and the children are not affected.
24372
24373 @subheading The @code{-var-show-format} Command
24374 @findex -var-show-format
24375
24376 @subsubheading Synopsis
24377
24378 @smallexample
24379 -var-show-format @var{name}
24380 @end smallexample
24381
24382 Returns the format used to display the value of the object @var{name}.
24383
24384 @smallexample
24385 @var{format} @expansion{}
24386 @var{format-spec}
24387 @end smallexample
24388
24389
24390 @subheading The @code{-var-info-num-children} Command
24391 @findex -var-info-num-children
24392
24393 @subsubheading Synopsis
24394
24395 @smallexample
24396 -var-info-num-children @var{name}
24397 @end smallexample
24398
24399 Returns the number of children of a variable object @var{name}:
24400
24401 @smallexample
24402 numchild=@var{n}
24403 @end smallexample
24404
24405 Note that this number is not completely reliable for a dynamic varobj.
24406 It will return the current number of children, but more children may
24407 be available.
24408
24409
24410 @subheading The @code{-var-list-children} Command
24411 @findex -var-list-children
24412
24413 @subsubheading Synopsis
24414
24415 @smallexample
24416 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
24417 @end smallexample
24418 @anchor{-var-list-children}
24419
24420 Return a list of the children of the specified variable object and
24421 create variable objects for them, if they do not already exist. With
24422 a single argument or if @var{print-values} has a value for of 0 or
24423 @code{--no-values}, print only the names of the variables; if
24424 @var{print-values} is 1 or @code{--all-values}, also print their
24425 values; and if it is 2 or @code{--simple-values} print the name and
24426 value for simple data types and just the name for arrays, structures
24427 and unions.
24428
24429 @var{from} and @var{to}, if specified, indicate the range of children
24430 to report. If @var{from} or @var{to} is less than zero, the range is
24431 reset and all children will be reported. Otherwise, children starting
24432 at @var{from} (zero-based) and up to and excluding @var{to} will be
24433 reported.
24434
24435 If a child range is requested, it will only affect the current call to
24436 @code{-var-list-children}, but not future calls to @code{-var-update}.
24437 For this, you must instead use @code{-var-set-update-range}. The
24438 intent of this approach is to enable a front end to implement any
24439 update approach it likes; for example, scrolling a view may cause the
24440 front end to request more children with @code{-var-list-children}, and
24441 then the front end could call @code{-var-set-update-range} with a
24442 different range to ensure that future updates are restricted to just
24443 the visible items.
24444
24445 For each child the following results are returned:
24446
24447 @table @var
24448
24449 @item name
24450 Name of the variable object created for this child.
24451
24452 @item exp
24453 The expression to be shown to the user by the front end to designate this child.
24454 For example this may be the name of a structure member.
24455
24456 For a dynamic varobj, this value cannot be used to form an
24457 expression. There is no way to do this at all with a dynamic varobj.
24458
24459 For C/C@t{++} structures there are several pseudo children returned to
24460 designate access qualifiers. For these pseudo children @var{exp} is
24461 @samp{public}, @samp{private}, or @samp{protected}. In this case the
24462 type and value are not present.
24463
24464 A dynamic varobj will not report the access qualifying
24465 pseudo-children, regardless of the language. This information is not
24466 available at all with a dynamic varobj.
24467
24468 @item numchild
24469 Number of children this child has. For a dynamic varobj, this will be
24470 0.
24471
24472 @item type
24473 The type of the child.
24474
24475 @item value
24476 If values were requested, this is the value.
24477
24478 @item thread-id
24479 If this variable object is associated with a thread, this is the thread id.
24480 Otherwise this result is not present.
24481
24482 @item frozen
24483 If the variable object is frozen, this variable will be present with a value of 1.
24484 @end table
24485
24486 The result may have its own attributes:
24487
24488 @table @samp
24489 @item displayhint
24490 A dynamic varobj can supply a display hint to the front end. The
24491 value comes directly from the Python pretty-printer object's
24492 @code{display_hint} method. @xref{Pretty Printing}.
24493
24494 @item has_more
24495 This is an integer attribute which is nonzero if there are children
24496 remaining after the end of the selected range.
24497 @end table
24498
24499 @subsubheading Example
24500
24501 @smallexample
24502 (gdb)
24503 -var-list-children n
24504 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
24505 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
24506 (gdb)
24507 -var-list-children --all-values n
24508 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
24509 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
24510 @end smallexample
24511
24512
24513 @subheading The @code{-var-info-type} Command
24514 @findex -var-info-type
24515
24516 @subsubheading Synopsis
24517
24518 @smallexample
24519 -var-info-type @var{name}
24520 @end smallexample
24521
24522 Returns the type of the specified variable @var{name}. The type is
24523 returned as a string in the same format as it is output by the
24524 @value{GDBN} CLI:
24525
24526 @smallexample
24527 type=@var{typename}
24528 @end smallexample
24529
24530
24531 @subheading The @code{-var-info-expression} Command
24532 @findex -var-info-expression
24533
24534 @subsubheading Synopsis
24535
24536 @smallexample
24537 -var-info-expression @var{name}
24538 @end smallexample
24539
24540 Returns a string that is suitable for presenting this
24541 variable object in user interface. The string is generally
24542 not valid expression in the current language, and cannot be evaluated.
24543
24544 For example, if @code{a} is an array, and variable object
24545 @code{A} was created for @code{a}, then we'll get this output:
24546
24547 @smallexample
24548 (gdb) -var-info-expression A.1
24549 ^done,lang="C",exp="1"
24550 @end smallexample
24551
24552 @noindent
24553 Here, the values of @code{lang} can be @code{@{"C" | "C++" | "Java"@}}.
24554
24555 Note that the output of the @code{-var-list-children} command also
24556 includes those expressions, so the @code{-var-info-expression} command
24557 is of limited use.
24558
24559 @subheading The @code{-var-info-path-expression} Command
24560 @findex -var-info-path-expression
24561
24562 @subsubheading Synopsis
24563
24564 @smallexample
24565 -var-info-path-expression @var{name}
24566 @end smallexample
24567
24568 Returns an expression that can be evaluated in the current
24569 context and will yield the same value that a variable object has.
24570 Compare this with the @code{-var-info-expression} command, which
24571 result can be used only for UI presentation. Typical use of
24572 the @code{-var-info-path-expression} command is creating a
24573 watchpoint from a variable object.
24574
24575 This command is currently not valid for children of a dynamic varobj,
24576 and will give an error when invoked on one.
24577
24578 For example, suppose @code{C} is a C@t{++} class, derived from class
24579 @code{Base}, and that the @code{Base} class has a member called
24580 @code{m_size}. Assume a variable @code{c} is has the type of
24581 @code{C} and a variable object @code{C} was created for variable
24582 @code{c}. Then, we'll get this output:
24583 @smallexample
24584 (gdb) -var-info-path-expression C.Base.public.m_size
24585 ^done,path_expr=((Base)c).m_size)
24586 @end smallexample
24587
24588 @subheading The @code{-var-show-attributes} Command
24589 @findex -var-show-attributes
24590
24591 @subsubheading Synopsis
24592
24593 @smallexample
24594 -var-show-attributes @var{name}
24595 @end smallexample
24596
24597 List attributes of the specified variable object @var{name}:
24598
24599 @smallexample
24600 status=@var{attr} [ ( ,@var{attr} )* ]
24601 @end smallexample
24602
24603 @noindent
24604 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
24605
24606 @subheading The @code{-var-evaluate-expression} Command
24607 @findex -var-evaluate-expression
24608
24609 @subsubheading Synopsis
24610
24611 @smallexample
24612 -var-evaluate-expression [-f @var{format-spec}] @var{name}
24613 @end smallexample
24614
24615 Evaluates the expression that is represented by the specified variable
24616 object and returns its value as a string. The format of the string
24617 can be specified with the @samp{-f} option. The possible values of
24618 this option are the same as for @code{-var-set-format}
24619 (@pxref{-var-set-format}). If the @samp{-f} option is not specified,
24620 the current display format will be used. The current display format
24621 can be changed using the @code{-var-set-format} command.
24622
24623 @smallexample
24624 value=@var{value}
24625 @end smallexample
24626
24627 Note that one must invoke @code{-var-list-children} for a variable
24628 before the value of a child variable can be evaluated.
24629
24630 @subheading The @code{-var-assign} Command
24631 @findex -var-assign
24632
24633 @subsubheading Synopsis
24634
24635 @smallexample
24636 -var-assign @var{name} @var{expression}
24637 @end smallexample
24638
24639 Assigns the value of @var{expression} to the variable object specified
24640 by @var{name}. The object must be @samp{editable}. If the variable's
24641 value is altered by the assign, the variable will show up in any
24642 subsequent @code{-var-update} list.
24643
24644 @subsubheading Example
24645
24646 @smallexample
24647 (gdb)
24648 -var-assign var1 3
24649 ^done,value="3"
24650 (gdb)
24651 -var-update *
24652 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
24653 (gdb)
24654 @end smallexample
24655
24656 @subheading The @code{-var-update} Command
24657 @findex -var-update
24658
24659 @subsubheading Synopsis
24660
24661 @smallexample
24662 -var-update [@var{print-values}] @{@var{name} | "*"@}
24663 @end smallexample
24664
24665 Reevaluate the expressions corresponding to the variable object
24666 @var{name} and all its direct and indirect children, and return the
24667 list of variable objects whose values have changed; @var{name} must
24668 be a root variable object. Here, ``changed'' means that the result of
24669 @code{-var-evaluate-expression} before and after the
24670 @code{-var-update} is different. If @samp{*} is used as the variable
24671 object names, all existing variable objects are updated, except
24672 for frozen ones (@pxref{-var-set-frozen}). The option
24673 @var{print-values} determines whether both names and values, or just
24674 names are printed. The possible values of this option are the same
24675 as for @code{-var-list-children} (@pxref{-var-list-children}). It is
24676 recommended to use the @samp{--all-values} option, to reduce the
24677 number of MI commands needed on each program stop.
24678
24679 With the @samp{*} parameter, if a variable object is bound to a
24680 currently running thread, it will not be updated, without any
24681 diagnostic.
24682
24683 If @code{-var-set-update-range} was previously used on a varobj, then
24684 only the selected range of children will be reported.
24685
24686 @code{-var-update} reports all the changed varobjs in a tuple named
24687 @samp{changelist}.
24688
24689 Each item in the change list is itself a tuple holding:
24690
24691 @table @samp
24692 @item name
24693 The name of the varobj.
24694
24695 @item value
24696 If values were requested for this update, then this field will be
24697 present and will hold the value of the varobj.
24698
24699 @item in_scope
24700 @anchor{-var-update}
24701 This field is a string which may take one of three values:
24702
24703 @table @code
24704 @item "true"
24705 The variable object's current value is valid.
24706
24707 @item "false"
24708 The variable object does not currently hold a valid value but it may
24709 hold one in the future if its associated expression comes back into
24710 scope.
24711
24712 @item "invalid"
24713 The variable object no longer holds a valid value.
24714 This can occur when the executable file being debugged has changed,
24715 either through recompilation or by using the @value{GDBN} @code{file}
24716 command. The front end should normally choose to delete these variable
24717 objects.
24718 @end table
24719
24720 In the future new values may be added to this list so the front should
24721 be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
24722
24723 @item type_changed
24724 This is only present if the varobj is still valid. If the type
24725 changed, then this will be the string @samp{true}; otherwise it will
24726 be @samp{false}.
24727
24728 @item new_type
24729 If the varobj's type changed, then this field will be present and will
24730 hold the new type.
24731
24732 @item new_num_children
24733 For a dynamic varobj, if the number of children changed, or if the
24734 type changed, this will be the new number of children.
24735
24736 The @samp{numchild} field in other varobj responses is generally not
24737 valid for a dynamic varobj -- it will show the number of children that
24738 @value{GDBN} knows about, but because dynamic varobjs lazily
24739 instantiate their children, this will not reflect the number of
24740 children which may be available.
24741
24742 The @samp{new_num_children} attribute only reports changes to the
24743 number of children known by @value{GDBN}. This is the only way to
24744 detect whether an update has removed children (which necessarily can
24745 only happen at the end of the update range).
24746
24747 @item displayhint
24748 The display hint, if any.
24749
24750 @item has_more
24751 This is an integer value, which will be 1 if there are more children
24752 available outside the varobj's update range.
24753
24754 @item dynamic
24755 This attribute will be present and have the value @samp{1} if the
24756 varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
24757 then this attribute will not be present.
24758
24759 @item new_children
24760 If new children were added to a dynamic varobj within the selected
24761 update range (as set by @code{-var-set-update-range}), then they will
24762 be listed in this attribute.
24763 @end table
24764
24765 @subsubheading Example
24766
24767 @smallexample
24768 (gdb)
24769 -var-assign var1 3
24770 ^done,value="3"
24771 (gdb)
24772 -var-update --all-values var1
24773 ^done,changelist=[@{name="var1",value="3",in_scope="true",
24774 type_changed="false"@}]
24775 (gdb)
24776 @end smallexample
24777
24778 @subheading The @code{-var-set-frozen} Command
24779 @findex -var-set-frozen
24780 @anchor{-var-set-frozen}
24781
24782 @subsubheading Synopsis
24783
24784 @smallexample
24785 -var-set-frozen @var{name} @var{flag}
24786 @end smallexample
24787
24788 Set the frozenness flag on the variable object @var{name}. The
24789 @var{flag} parameter should be either @samp{1} to make the variable
24790 frozen or @samp{0} to make it unfrozen. If a variable object is
24791 frozen, then neither itself, nor any of its children, are
24792 implicitly updated by @code{-var-update} of
24793 a parent variable or by @code{-var-update *}. Only
24794 @code{-var-update} of the variable itself will update its value and
24795 values of its children. After a variable object is unfrozen, it is
24796 implicitly updated by all subsequent @code{-var-update} operations.
24797 Unfreezing a variable does not update it, only subsequent
24798 @code{-var-update} does.
24799
24800 @subsubheading Example
24801
24802 @smallexample
24803 (gdb)
24804 -var-set-frozen V 1
24805 ^done
24806 (gdb)
24807 @end smallexample
24808
24809 @subheading The @code{-var-set-update-range} command
24810 @findex -var-set-update-range
24811 @anchor{-var-set-update-range}
24812
24813 @subsubheading Synopsis
24814
24815 @smallexample
24816 -var-set-update-range @var{name} @var{from} @var{to}
24817 @end smallexample
24818
24819 Set the range of children to be returned by future invocations of
24820 @code{-var-update}.
24821
24822 @var{from} and @var{to} indicate the range of children to report. If
24823 @var{from} or @var{to} is less than zero, the range is reset and all
24824 children will be reported. Otherwise, children starting at @var{from}
24825 (zero-based) and up to and excluding @var{to} will be reported.
24826
24827 @subsubheading Example
24828
24829 @smallexample
24830 (gdb)
24831 -var-set-update-range V 1 2
24832 ^done
24833 @end smallexample
24834
24835 @subheading The @code{-var-set-visualizer} command
24836 @findex -var-set-visualizer
24837 @anchor{-var-set-visualizer}
24838
24839 @subsubheading Synopsis
24840
24841 @smallexample
24842 -var-set-visualizer @var{name} @var{visualizer}
24843 @end smallexample
24844
24845 Set a visualizer for the variable object @var{name}.
24846
24847 @var{visualizer} is the visualizer to use. The special value
24848 @samp{None} means to disable any visualizer in use.
24849
24850 If not @samp{None}, @var{visualizer} must be a Python expression.
24851 This expression must evaluate to a callable object which accepts a
24852 single argument. @value{GDBN} will call this object with the value of
24853 the varobj @var{name} as an argument (this is done so that the same
24854 Python pretty-printing code can be used for both the CLI and MI).
24855 When called, this object must return an object which conforms to the
24856 pretty-printing interface (@pxref{Pretty Printing}).
24857
24858 The pre-defined function @code{gdb.default_visualizer} may be used to
24859 select a visualizer by following the built-in process
24860 (@pxref{Selecting Pretty-Printers}). This is done automatically when
24861 a varobj is created, and so ordinarily is not needed.
24862
24863 This feature is only available if Python support is enabled. The MI
24864 command @code{-list-features} (@pxref{GDB/MI Miscellaneous Commands})
24865 can be used to check this.
24866
24867 @subsubheading Example
24868
24869 Resetting the visualizer:
24870
24871 @smallexample
24872 (gdb)
24873 -var-set-visualizer V None
24874 ^done
24875 @end smallexample
24876
24877 Reselecting the default (type-based) visualizer:
24878
24879 @smallexample
24880 (gdb)
24881 -var-set-visualizer V gdb.default_visualizer
24882 ^done
24883 @end smallexample
24884
24885 Suppose @code{SomeClass} is a visualizer class. A lambda expression
24886 can be used to instantiate this class for a varobj:
24887
24888 @smallexample
24889 (gdb)
24890 -var-set-visualizer V "lambda val: SomeClass()"
24891 ^done
24892 @end smallexample
24893
24894 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24895 @node GDB/MI Data Manipulation
24896 @section @sc{gdb/mi} Data Manipulation
24897
24898 @cindex data manipulation, in @sc{gdb/mi}
24899 @cindex @sc{gdb/mi}, data manipulation
24900 This section describes the @sc{gdb/mi} commands that manipulate data:
24901 examine memory and registers, evaluate expressions, etc.
24902
24903 @c REMOVED FROM THE INTERFACE.
24904 @c @subheading -data-assign
24905 @c Change the value of a program variable. Plenty of side effects.
24906 @c @subsubheading GDB Command
24907 @c set variable
24908 @c @subsubheading Example
24909 @c N.A.
24910
24911 @subheading The @code{-data-disassemble} Command
24912 @findex -data-disassemble
24913
24914 @subsubheading Synopsis
24915
24916 @smallexample
24917 -data-disassemble
24918 [ -s @var{start-addr} -e @var{end-addr} ]
24919 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
24920 -- @var{mode}
24921 @end smallexample
24922
24923 @noindent
24924 Where:
24925
24926 @table @samp
24927 @item @var{start-addr}
24928 is the beginning address (or @code{$pc})
24929 @item @var{end-addr}
24930 is the end address
24931 @item @var{filename}
24932 is the name of the file to disassemble
24933 @item @var{linenum}
24934 is the line number to disassemble around
24935 @item @var{lines}
24936 is the number of disassembly lines to be produced. If it is -1,
24937 the whole function will be disassembled, in case no @var{end-addr} is
24938 specified. If @var{end-addr} is specified as a non-zero value, and
24939 @var{lines} is lower than the number of disassembly lines between
24940 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
24941 displayed; if @var{lines} is higher than the number of lines between
24942 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
24943 are displayed.
24944 @item @var{mode}
24945 is either 0 (meaning only disassembly) or 1 (meaning mixed source and
24946 disassembly).
24947 @end table
24948
24949 @subsubheading Result
24950
24951 The output for each instruction is composed of four fields:
24952
24953 @itemize @bullet
24954 @item Address
24955 @item Func-name
24956 @item Offset
24957 @item Instruction
24958 @end itemize
24959
24960 Note that whatever included in the instruction field, is not manipulated
24961 directly by @sc{gdb/mi}, i.e., it is not possible to adjust its format.
24962
24963 @subsubheading @value{GDBN} Command
24964
24965 There's no direct mapping from this command to the CLI.
24966
24967 @subsubheading Example
24968
24969 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
24970
24971 @smallexample
24972 (gdb)
24973 -data-disassemble -s $pc -e "$pc + 20" -- 0
24974 ^done,
24975 asm_insns=[
24976 @{address="0x000107c0",func-name="main",offset="4",
24977 inst="mov 2, %o0"@},
24978 @{address="0x000107c4",func-name="main",offset="8",
24979 inst="sethi %hi(0x11800), %o2"@},
24980 @{address="0x000107c8",func-name="main",offset="12",
24981 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
24982 @{address="0x000107cc",func-name="main",offset="16",
24983 inst="sethi %hi(0x11800), %o2"@},
24984 @{address="0x000107d0",func-name="main",offset="20",
24985 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
24986 (gdb)
24987 @end smallexample
24988
24989 Disassemble the whole @code{main} function. Line 32 is part of
24990 @code{main}.
24991
24992 @smallexample
24993 -data-disassemble -f basics.c -l 32 -- 0
24994 ^done,asm_insns=[
24995 @{address="0x000107bc",func-name="main",offset="0",
24996 inst="save %sp, -112, %sp"@},
24997 @{address="0x000107c0",func-name="main",offset="4",
24998 inst="mov 2, %o0"@},
24999 @{address="0x000107c4",func-name="main",offset="8",
25000 inst="sethi %hi(0x11800), %o2"@},
25001 [@dots{}]
25002 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
25003 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
25004 (gdb)
25005 @end smallexample
25006
25007 Disassemble 3 instructions from the start of @code{main}:
25008
25009 @smallexample
25010 (gdb)
25011 -data-disassemble -f basics.c -l 32 -n 3 -- 0
25012 ^done,asm_insns=[
25013 @{address="0x000107bc",func-name="main",offset="0",
25014 inst="save %sp, -112, %sp"@},
25015 @{address="0x000107c0",func-name="main",offset="4",
25016 inst="mov 2, %o0"@},
25017 @{address="0x000107c4",func-name="main",offset="8",
25018 inst="sethi %hi(0x11800), %o2"@}]
25019 (gdb)
25020 @end smallexample
25021
25022 Disassemble 3 instructions from the start of @code{main} in mixed mode:
25023
25024 @smallexample
25025 (gdb)
25026 -data-disassemble -f basics.c -l 32 -n 3 -- 1
25027 ^done,asm_insns=[
25028 src_and_asm_line=@{line="31",
25029 file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
25030 testsuite/gdb.mi/basics.c",line_asm_insn=[
25031 @{address="0x000107bc",func-name="main",offset="0",
25032 inst="save %sp, -112, %sp"@}]@},
25033 src_and_asm_line=@{line="32",
25034 file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
25035 testsuite/gdb.mi/basics.c",line_asm_insn=[
25036 @{address="0x000107c0",func-name="main",offset="4",
25037 inst="mov 2, %o0"@},
25038 @{address="0x000107c4",func-name="main",offset="8",
25039 inst="sethi %hi(0x11800), %o2"@}]@}]
25040 (gdb)
25041 @end smallexample
25042
25043
25044 @subheading The @code{-data-evaluate-expression} Command
25045 @findex -data-evaluate-expression
25046
25047 @subsubheading Synopsis
25048
25049 @smallexample
25050 -data-evaluate-expression @var{expr}
25051 @end smallexample
25052
25053 Evaluate @var{expr} as an expression. The expression could contain an
25054 inferior function call. The function call will execute synchronously.
25055 If the expression contains spaces, it must be enclosed in double quotes.
25056
25057 @subsubheading @value{GDBN} Command
25058
25059 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
25060 @samp{call}. In @code{gdbtk} only, there's a corresponding
25061 @samp{gdb_eval} command.
25062
25063 @subsubheading Example
25064
25065 In the following example, the numbers that precede the commands are the
25066 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
25067 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
25068 output.
25069
25070 @smallexample
25071 211-data-evaluate-expression A
25072 211^done,value="1"
25073 (gdb)
25074 311-data-evaluate-expression &A
25075 311^done,value="0xefffeb7c"
25076 (gdb)
25077 411-data-evaluate-expression A+3
25078 411^done,value="4"
25079 (gdb)
25080 511-data-evaluate-expression "A + 3"
25081 511^done,value="4"
25082 (gdb)
25083 @end smallexample
25084
25085
25086 @subheading The @code{-data-list-changed-registers} Command
25087 @findex -data-list-changed-registers
25088
25089 @subsubheading Synopsis
25090
25091 @smallexample
25092 -data-list-changed-registers
25093 @end smallexample
25094
25095 Display a list of the registers that have changed.
25096
25097 @subsubheading @value{GDBN} Command
25098
25099 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
25100 has the corresponding command @samp{gdb_changed_register_list}.
25101
25102 @subsubheading Example
25103
25104 On a PPC MBX board:
25105
25106 @smallexample
25107 (gdb)
25108 -exec-continue
25109 ^running
25110
25111 (gdb)
25112 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
25113 func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
25114 line="5"@}
25115 (gdb)
25116 -data-list-changed-registers
25117 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
25118 "10","11","13","14","15","16","17","18","19","20","21","22","23",
25119 "24","25","26","27","28","30","31","64","65","66","67","69"]
25120 (gdb)
25121 @end smallexample
25122
25123
25124 @subheading The @code{-data-list-register-names} Command
25125 @findex -data-list-register-names
25126
25127 @subsubheading Synopsis
25128
25129 @smallexample
25130 -data-list-register-names [ ( @var{regno} )+ ]
25131 @end smallexample
25132
25133 Show a list of register names for the current target. If no arguments
25134 are given, it shows a list of the names of all the registers. If
25135 integer numbers are given as arguments, it will print a list of the
25136 names of the registers corresponding to the arguments. To ensure
25137 consistency between a register name and its number, the output list may
25138 include empty register names.
25139
25140 @subsubheading @value{GDBN} Command
25141
25142 @value{GDBN} does not have a command which corresponds to
25143 @samp{-data-list-register-names}. In @code{gdbtk} there is a
25144 corresponding command @samp{gdb_regnames}.
25145
25146 @subsubheading Example
25147
25148 For the PPC MBX board:
25149 @smallexample
25150 (gdb)
25151 -data-list-register-names
25152 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
25153 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
25154 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
25155 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
25156 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
25157 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
25158 "", "pc","ps","cr","lr","ctr","xer"]
25159 (gdb)
25160 -data-list-register-names 1 2 3
25161 ^done,register-names=["r1","r2","r3"]
25162 (gdb)
25163 @end smallexample
25164
25165 @subheading The @code{-data-list-register-values} Command
25166 @findex -data-list-register-values
25167
25168 @subsubheading Synopsis
25169
25170 @smallexample
25171 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
25172 @end smallexample
25173
25174 Display the registers' contents. @var{fmt} is the format according to
25175 which the registers' contents are to be returned, followed by an optional
25176 list of numbers specifying the registers to display. A missing list of
25177 numbers indicates that the contents of all the registers must be returned.
25178
25179 Allowed formats for @var{fmt} are:
25180
25181 @table @code
25182 @item x
25183 Hexadecimal
25184 @item o
25185 Octal
25186 @item t
25187 Binary
25188 @item d
25189 Decimal
25190 @item r
25191 Raw
25192 @item N
25193 Natural
25194 @end table
25195
25196 @subsubheading @value{GDBN} Command
25197
25198 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
25199 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
25200
25201 @subsubheading Example
25202
25203 For a PPC MBX board (note: line breaks are for readability only, they
25204 don't appear in the actual output):
25205
25206 @smallexample
25207 (gdb)
25208 -data-list-register-values r 64 65
25209 ^done,register-values=[@{number="64",value="0xfe00a300"@},
25210 @{number="65",value="0x00029002"@}]
25211 (gdb)
25212 -data-list-register-values x
25213 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
25214 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
25215 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
25216 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
25217 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
25218 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
25219 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
25220 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
25221 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
25222 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
25223 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
25224 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
25225 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
25226 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
25227 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
25228 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
25229 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
25230 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
25231 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
25232 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
25233 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
25234 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
25235 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
25236 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
25237 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
25238 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
25239 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
25240 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
25241 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
25242 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
25243 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
25244 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
25245 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
25246 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
25247 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
25248 @{number="69",value="0x20002b03"@}]
25249 (gdb)
25250 @end smallexample
25251
25252
25253 @subheading The @code{-data-read-memory} Command
25254 @findex -data-read-memory
25255
25256 @subsubheading Synopsis
25257
25258 @smallexample
25259 -data-read-memory [ -o @var{byte-offset} ]
25260 @var{address} @var{word-format} @var{word-size}
25261 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
25262 @end smallexample
25263
25264 @noindent
25265 where:
25266
25267 @table @samp
25268 @item @var{address}
25269 An expression specifying the address of the first memory word to be
25270 read. Complex expressions containing embedded white space should be
25271 quoted using the C convention.
25272
25273 @item @var{word-format}
25274 The format to be used to print the memory words. The notation is the
25275 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
25276 ,Output Formats}).
25277
25278 @item @var{word-size}
25279 The size of each memory word in bytes.
25280
25281 @item @var{nr-rows}
25282 The number of rows in the output table.
25283
25284 @item @var{nr-cols}
25285 The number of columns in the output table.
25286
25287 @item @var{aschar}
25288 If present, indicates that each row should include an @sc{ascii} dump. The
25289 value of @var{aschar} is used as a padding character when a byte is not a
25290 member of the printable @sc{ascii} character set (printable @sc{ascii}
25291 characters are those whose code is between 32 and 126, inclusively).
25292
25293 @item @var{byte-offset}
25294 An offset to add to the @var{address} before fetching memory.
25295 @end table
25296
25297 This command displays memory contents as a table of @var{nr-rows} by
25298 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
25299 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
25300 (returned as @samp{total-bytes}). Should less than the requested number
25301 of bytes be returned by the target, the missing words are identified
25302 using @samp{N/A}. The number of bytes read from the target is returned
25303 in @samp{nr-bytes} and the starting address used to read memory in
25304 @samp{addr}.
25305
25306 The address of the next/previous row or page is available in
25307 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
25308 @samp{prev-page}.
25309
25310 @subsubheading @value{GDBN} Command
25311
25312 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
25313 @samp{gdb_get_mem} memory read command.
25314
25315 @subsubheading Example
25316
25317 Read six bytes of memory starting at @code{bytes+6} but then offset by
25318 @code{-6} bytes. Format as three rows of two columns. One byte per
25319 word. Display each word in hex.
25320
25321 @smallexample
25322 (gdb)
25323 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
25324 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
25325 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
25326 prev-page="0x0000138a",memory=[
25327 @{addr="0x00001390",data=["0x00","0x01"]@},
25328 @{addr="0x00001392",data=["0x02","0x03"]@},
25329 @{addr="0x00001394",data=["0x04","0x05"]@}]
25330 (gdb)
25331 @end smallexample
25332
25333 Read two bytes of memory starting at address @code{shorts + 64} and
25334 display as a single word formatted in decimal.
25335
25336 @smallexample
25337 (gdb)
25338 5-data-read-memory shorts+64 d 2 1 1
25339 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
25340 next-row="0x00001512",prev-row="0x0000150e",
25341 next-page="0x00001512",prev-page="0x0000150e",memory=[
25342 @{addr="0x00001510",data=["128"]@}]
25343 (gdb)
25344 @end smallexample
25345
25346 Read thirty two bytes of memory starting at @code{bytes+16} and format
25347 as eight rows of four columns. Include a string encoding with @samp{x}
25348 used as the non-printable character.
25349
25350 @smallexample
25351 (gdb)
25352 4-data-read-memory bytes+16 x 1 8 4 x
25353 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
25354 next-row="0x000013c0",prev-row="0x0000139c",
25355 next-page="0x000013c0",prev-page="0x00001380",memory=[
25356 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
25357 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
25358 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
25359 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
25360 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
25361 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
25362 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
25363 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
25364 (gdb)
25365 @end smallexample
25366
25367 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25368 @node GDB/MI Tracepoint Commands
25369 @section @sc{gdb/mi} Tracepoint Commands
25370
25371 The tracepoint commands are not yet implemented.
25372
25373 @c @subheading -trace-actions
25374
25375 @c @subheading -trace-delete
25376
25377 @c @subheading -trace-disable
25378
25379 @c @subheading -trace-dump
25380
25381 @c @subheading -trace-enable
25382
25383 @c @subheading -trace-exists
25384
25385 @c @subheading -trace-find
25386
25387 @c @subheading -trace-frame-number
25388
25389 @c @subheading -trace-info
25390
25391 @c @subheading -trace-insert
25392
25393 @c @subheading -trace-list
25394
25395 @c @subheading -trace-pass-count
25396
25397 @c @subheading -trace-save
25398
25399 @c @subheading -trace-start
25400
25401 @c @subheading -trace-stop
25402
25403
25404 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25405 @node GDB/MI Symbol Query
25406 @section @sc{gdb/mi} Symbol Query Commands
25407
25408
25409 @ignore
25410 @subheading The @code{-symbol-info-address} Command
25411 @findex -symbol-info-address
25412
25413 @subsubheading Synopsis
25414
25415 @smallexample
25416 -symbol-info-address @var{symbol}
25417 @end smallexample
25418
25419 Describe where @var{symbol} is stored.
25420
25421 @subsubheading @value{GDBN} Command
25422
25423 The corresponding @value{GDBN} command is @samp{info address}.
25424
25425 @subsubheading Example
25426 N.A.
25427
25428
25429 @subheading The @code{-symbol-info-file} Command
25430 @findex -symbol-info-file
25431
25432 @subsubheading Synopsis
25433
25434 @smallexample
25435 -symbol-info-file
25436 @end smallexample
25437
25438 Show the file for the symbol.
25439
25440 @subsubheading @value{GDBN} Command
25441
25442 There's no equivalent @value{GDBN} command. @code{gdbtk} has
25443 @samp{gdb_find_file}.
25444
25445 @subsubheading Example
25446 N.A.
25447
25448
25449 @subheading The @code{-symbol-info-function} Command
25450 @findex -symbol-info-function
25451
25452 @subsubheading Synopsis
25453
25454 @smallexample
25455 -symbol-info-function
25456 @end smallexample
25457
25458 Show which function the symbol lives in.
25459
25460 @subsubheading @value{GDBN} Command
25461
25462 @samp{gdb_get_function} in @code{gdbtk}.
25463
25464 @subsubheading Example
25465 N.A.
25466
25467
25468 @subheading The @code{-symbol-info-line} Command
25469 @findex -symbol-info-line
25470
25471 @subsubheading Synopsis
25472
25473 @smallexample
25474 -symbol-info-line
25475 @end smallexample
25476
25477 Show the core addresses of the code for a source line.
25478
25479 @subsubheading @value{GDBN} Command
25480
25481 The corresponding @value{GDBN} command is @samp{info line}.
25482 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
25483
25484 @subsubheading Example
25485 N.A.
25486
25487
25488 @subheading The @code{-symbol-info-symbol} Command
25489 @findex -symbol-info-symbol
25490
25491 @subsubheading Synopsis
25492
25493 @smallexample
25494 -symbol-info-symbol @var{addr}
25495 @end smallexample
25496
25497 Describe what symbol is at location @var{addr}.
25498
25499 @subsubheading @value{GDBN} Command
25500
25501 The corresponding @value{GDBN} command is @samp{info symbol}.
25502
25503 @subsubheading Example
25504 N.A.
25505
25506
25507 @subheading The @code{-symbol-list-functions} Command
25508 @findex -symbol-list-functions
25509
25510 @subsubheading Synopsis
25511
25512 @smallexample
25513 -symbol-list-functions
25514 @end smallexample
25515
25516 List the functions in the executable.
25517
25518 @subsubheading @value{GDBN} Command
25519
25520 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
25521 @samp{gdb_search} in @code{gdbtk}.
25522
25523 @subsubheading Example
25524 N.A.
25525 @end ignore
25526
25527
25528 @subheading The @code{-symbol-list-lines} Command
25529 @findex -symbol-list-lines
25530
25531 @subsubheading Synopsis
25532
25533 @smallexample
25534 -symbol-list-lines @var{filename}
25535 @end smallexample
25536
25537 Print the list of lines that contain code and their associated program
25538 addresses for the given source filename. The entries are sorted in
25539 ascending PC order.
25540
25541 @subsubheading @value{GDBN} Command
25542
25543 There is no corresponding @value{GDBN} command.
25544
25545 @subsubheading Example
25546 @smallexample
25547 (gdb)
25548 -symbol-list-lines basics.c
25549 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
25550 (gdb)
25551 @end smallexample
25552
25553
25554 @ignore
25555 @subheading The @code{-symbol-list-types} Command
25556 @findex -symbol-list-types
25557
25558 @subsubheading Synopsis
25559
25560 @smallexample
25561 -symbol-list-types
25562 @end smallexample
25563
25564 List all the type names.
25565
25566 @subsubheading @value{GDBN} Command
25567
25568 The corresponding commands are @samp{info types} in @value{GDBN},
25569 @samp{gdb_search} in @code{gdbtk}.
25570
25571 @subsubheading Example
25572 N.A.
25573
25574
25575 @subheading The @code{-symbol-list-variables} Command
25576 @findex -symbol-list-variables
25577
25578 @subsubheading Synopsis
25579
25580 @smallexample
25581 -symbol-list-variables
25582 @end smallexample
25583
25584 List all the global and static variable names.
25585
25586 @subsubheading @value{GDBN} Command
25587
25588 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
25589
25590 @subsubheading Example
25591 N.A.
25592
25593
25594 @subheading The @code{-symbol-locate} Command
25595 @findex -symbol-locate
25596
25597 @subsubheading Synopsis
25598
25599 @smallexample
25600 -symbol-locate
25601 @end smallexample
25602
25603 @subsubheading @value{GDBN} Command
25604
25605 @samp{gdb_loc} in @code{gdbtk}.
25606
25607 @subsubheading Example
25608 N.A.
25609
25610
25611 @subheading The @code{-symbol-type} Command
25612 @findex -symbol-type
25613
25614 @subsubheading Synopsis
25615
25616 @smallexample
25617 -symbol-type @var{variable}
25618 @end smallexample
25619
25620 Show type of @var{variable}.
25621
25622 @subsubheading @value{GDBN} Command
25623
25624 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
25625 @samp{gdb_obj_variable}.
25626
25627 @subsubheading Example
25628 N.A.
25629 @end ignore
25630
25631
25632 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25633 @node GDB/MI File Commands
25634 @section @sc{gdb/mi} File Commands
25635
25636 This section describes the GDB/MI commands to specify executable file names
25637 and to read in and obtain symbol table information.
25638
25639 @subheading The @code{-file-exec-and-symbols} Command
25640 @findex -file-exec-and-symbols
25641
25642 @subsubheading Synopsis
25643
25644 @smallexample
25645 -file-exec-and-symbols @var{file}
25646 @end smallexample
25647
25648 Specify the executable file to be debugged. This file is the one from
25649 which the symbol table is also read. If no file is specified, the
25650 command clears the executable and symbol information. If breakpoints
25651 are set when using this command with no arguments, @value{GDBN} will produce
25652 error messages. Otherwise, no output is produced, except a completion
25653 notification.
25654
25655 @subsubheading @value{GDBN} Command
25656
25657 The corresponding @value{GDBN} command is @samp{file}.
25658
25659 @subsubheading Example
25660
25661 @smallexample
25662 (gdb)
25663 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
25664 ^done
25665 (gdb)
25666 @end smallexample
25667
25668
25669 @subheading The @code{-file-exec-file} Command
25670 @findex -file-exec-file
25671
25672 @subsubheading Synopsis
25673
25674 @smallexample
25675 -file-exec-file @var{file}
25676 @end smallexample
25677
25678 Specify the executable file to be debugged. Unlike
25679 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
25680 from this file. If used without argument, @value{GDBN} clears the information
25681 about the executable file. No output is produced, except a completion
25682 notification.
25683
25684 @subsubheading @value{GDBN} Command
25685
25686 The corresponding @value{GDBN} command is @samp{exec-file}.
25687
25688 @subsubheading Example
25689
25690 @smallexample
25691 (gdb)
25692 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
25693 ^done
25694 (gdb)
25695 @end smallexample
25696
25697
25698 @ignore
25699 @subheading The @code{-file-list-exec-sections} Command
25700 @findex -file-list-exec-sections
25701
25702 @subsubheading Synopsis
25703
25704 @smallexample
25705 -file-list-exec-sections
25706 @end smallexample
25707
25708 List the sections of the current executable file.
25709
25710 @subsubheading @value{GDBN} Command
25711
25712 The @value{GDBN} command @samp{info file} shows, among the rest, the same
25713 information as this command. @code{gdbtk} has a corresponding command
25714 @samp{gdb_load_info}.
25715
25716 @subsubheading Example
25717 N.A.
25718 @end ignore
25719
25720
25721 @subheading The @code{-file-list-exec-source-file} Command
25722 @findex -file-list-exec-source-file
25723
25724 @subsubheading Synopsis
25725
25726 @smallexample
25727 -file-list-exec-source-file
25728 @end smallexample
25729
25730 List the line number, the current source file, and the absolute path
25731 to the current source file for the current executable. The macro
25732 information field has a value of @samp{1} or @samp{0} depending on
25733 whether or not the file includes preprocessor macro information.
25734
25735 @subsubheading @value{GDBN} Command
25736
25737 The @value{GDBN} equivalent is @samp{info source}
25738
25739 @subsubheading Example
25740
25741 @smallexample
25742 (gdb)
25743 123-file-list-exec-source-file
25744 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
25745 (gdb)
25746 @end smallexample
25747
25748
25749 @subheading The @code{-file-list-exec-source-files} Command
25750 @findex -file-list-exec-source-files
25751
25752 @subsubheading Synopsis
25753
25754 @smallexample
25755 -file-list-exec-source-files
25756 @end smallexample
25757
25758 List the source files for the current executable.
25759
25760 It will always output the filename, but only when @value{GDBN} can find
25761 the absolute file name of a source file, will it output the fullname.
25762
25763 @subsubheading @value{GDBN} Command
25764
25765 The @value{GDBN} equivalent is @samp{info sources}.
25766 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
25767
25768 @subsubheading Example
25769 @smallexample
25770 (gdb)
25771 -file-list-exec-source-files
25772 ^done,files=[
25773 @{file=foo.c,fullname=/home/foo.c@},
25774 @{file=/home/bar.c,fullname=/home/bar.c@},
25775 @{file=gdb_could_not_find_fullpath.c@}]
25776 (gdb)
25777 @end smallexample
25778
25779 @ignore
25780 @subheading The @code{-file-list-shared-libraries} Command
25781 @findex -file-list-shared-libraries
25782
25783 @subsubheading Synopsis
25784
25785 @smallexample
25786 -file-list-shared-libraries
25787 @end smallexample
25788
25789 List the shared libraries in the program.
25790
25791 @subsubheading @value{GDBN} Command
25792
25793 The corresponding @value{GDBN} command is @samp{info shared}.
25794
25795 @subsubheading Example
25796 N.A.
25797
25798
25799 @subheading The @code{-file-list-symbol-files} Command
25800 @findex -file-list-symbol-files
25801
25802 @subsubheading Synopsis
25803
25804 @smallexample
25805 -file-list-symbol-files
25806 @end smallexample
25807
25808 List symbol files.
25809
25810 @subsubheading @value{GDBN} Command
25811
25812 The corresponding @value{GDBN} command is @samp{info file} (part of it).
25813
25814 @subsubheading Example
25815 N.A.
25816 @end ignore
25817
25818
25819 @subheading The @code{-file-symbol-file} Command
25820 @findex -file-symbol-file
25821
25822 @subsubheading Synopsis
25823
25824 @smallexample
25825 -file-symbol-file @var{file}
25826 @end smallexample
25827
25828 Read symbol table info from the specified @var{file} argument. When
25829 used without arguments, clears @value{GDBN}'s symbol table info. No output is
25830 produced, except for a completion notification.
25831
25832 @subsubheading @value{GDBN} Command
25833
25834 The corresponding @value{GDBN} command is @samp{symbol-file}.
25835
25836 @subsubheading Example
25837
25838 @smallexample
25839 (gdb)
25840 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
25841 ^done
25842 (gdb)
25843 @end smallexample
25844
25845 @ignore
25846 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25847 @node GDB/MI Memory Overlay Commands
25848 @section @sc{gdb/mi} Memory Overlay Commands
25849
25850 The memory overlay commands are not implemented.
25851
25852 @c @subheading -overlay-auto
25853
25854 @c @subheading -overlay-list-mapping-state
25855
25856 @c @subheading -overlay-list-overlays
25857
25858 @c @subheading -overlay-map
25859
25860 @c @subheading -overlay-off
25861
25862 @c @subheading -overlay-on
25863
25864 @c @subheading -overlay-unmap
25865
25866 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25867 @node GDB/MI Signal Handling Commands
25868 @section @sc{gdb/mi} Signal Handling Commands
25869
25870 Signal handling commands are not implemented.
25871
25872 @c @subheading -signal-handle
25873
25874 @c @subheading -signal-list-handle-actions
25875
25876 @c @subheading -signal-list-signal-types
25877 @end ignore
25878
25879
25880 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25881 @node GDB/MI Target Manipulation
25882 @section @sc{gdb/mi} Target Manipulation Commands
25883
25884
25885 @subheading The @code{-target-attach} Command
25886 @findex -target-attach
25887
25888 @subsubheading Synopsis
25889
25890 @smallexample
25891 -target-attach @var{pid} | @var{gid} | @var{file}
25892 @end smallexample
25893
25894 Attach to a process @var{pid} or a file @var{file} outside of
25895 @value{GDBN}, or a thread group @var{gid}. If attaching to a thread
25896 group, the id previously returned by
25897 @samp{-list-thread-groups --available} must be used.
25898
25899 @subsubheading @value{GDBN} Command
25900
25901 The corresponding @value{GDBN} command is @samp{attach}.
25902
25903 @subsubheading Example
25904 @smallexample
25905 (gdb)
25906 -target-attach 34
25907 =thread-created,id="1"
25908 *stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
25909 ^done
25910 (gdb)
25911 @end smallexample
25912
25913 @ignore
25914 @subheading The @code{-target-compare-sections} Command
25915 @findex -target-compare-sections
25916
25917 @subsubheading Synopsis
25918
25919 @smallexample
25920 -target-compare-sections [ @var{section} ]
25921 @end smallexample
25922
25923 Compare data of section @var{section} on target to the exec file.
25924 Without the argument, all sections are compared.
25925
25926 @subsubheading @value{GDBN} Command
25927
25928 The @value{GDBN} equivalent is @samp{compare-sections}.
25929
25930 @subsubheading Example
25931 N.A.
25932 @end ignore
25933
25934
25935 @subheading The @code{-target-detach} Command
25936 @findex -target-detach
25937
25938 @subsubheading Synopsis
25939
25940 @smallexample
25941 -target-detach [ @var{pid} | @var{gid} ]
25942 @end smallexample
25943
25944 Detach from the remote target which normally resumes its execution.
25945 If either @var{pid} or @var{gid} is specified, detaches from either
25946 the specified process, or specified thread group. There's no output.
25947
25948 @subsubheading @value{GDBN} Command
25949
25950 The corresponding @value{GDBN} command is @samp{detach}.
25951
25952 @subsubheading Example
25953
25954 @smallexample
25955 (gdb)
25956 -target-detach
25957 ^done
25958 (gdb)
25959 @end smallexample
25960
25961
25962 @subheading The @code{-target-disconnect} Command
25963 @findex -target-disconnect
25964
25965 @subsubheading Synopsis
25966
25967 @smallexample
25968 -target-disconnect
25969 @end smallexample
25970
25971 Disconnect from the remote target. There's no output and the target is
25972 generally not resumed.
25973
25974 @subsubheading @value{GDBN} Command
25975
25976 The corresponding @value{GDBN} command is @samp{disconnect}.
25977
25978 @subsubheading Example
25979
25980 @smallexample
25981 (gdb)
25982 -target-disconnect
25983 ^done
25984 (gdb)
25985 @end smallexample
25986
25987
25988 @subheading The @code{-target-download} Command
25989 @findex -target-download
25990
25991 @subsubheading Synopsis
25992
25993 @smallexample
25994 -target-download
25995 @end smallexample
25996
25997 Loads the executable onto the remote target.
25998 It prints out an update message every half second, which includes the fields:
25999
26000 @table @samp
26001 @item section
26002 The name of the section.
26003 @item section-sent
26004 The size of what has been sent so far for that section.
26005 @item section-size
26006 The size of the section.
26007 @item total-sent
26008 The total size of what was sent so far (the current and the previous sections).
26009 @item total-size
26010 The size of the overall executable to download.
26011 @end table
26012
26013 @noindent
26014 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
26015 @sc{gdb/mi} Output Syntax}).
26016
26017 In addition, it prints the name and size of the sections, as they are
26018 downloaded. These messages include the following fields:
26019
26020 @table @samp
26021 @item section
26022 The name of the section.
26023 @item section-size
26024 The size of the section.
26025 @item total-size
26026 The size of the overall executable to download.
26027 @end table
26028
26029 @noindent
26030 At the end, a summary is printed.
26031
26032 @subsubheading @value{GDBN} Command
26033
26034 The corresponding @value{GDBN} command is @samp{load}.
26035
26036 @subsubheading Example
26037
26038 Note: each status message appears on a single line. Here the messages
26039 have been broken down so that they can fit onto a page.
26040
26041 @smallexample
26042 (gdb)
26043 -target-download
26044 +download,@{section=".text",section-size="6668",total-size="9880"@}
26045 +download,@{section=".text",section-sent="512",section-size="6668",
26046 total-sent="512",total-size="9880"@}
26047 +download,@{section=".text",section-sent="1024",section-size="6668",
26048 total-sent="1024",total-size="9880"@}
26049 +download,@{section=".text",section-sent="1536",section-size="6668",
26050 total-sent="1536",total-size="9880"@}
26051 +download,@{section=".text",section-sent="2048",section-size="6668",
26052 total-sent="2048",total-size="9880"@}
26053 +download,@{section=".text",section-sent="2560",section-size="6668",
26054 total-sent="2560",total-size="9880"@}
26055 +download,@{section=".text",section-sent="3072",section-size="6668",
26056 total-sent="3072",total-size="9880"@}
26057 +download,@{section=".text",section-sent="3584",section-size="6668",
26058 total-sent="3584",total-size="9880"@}
26059 +download,@{section=".text",section-sent="4096",section-size="6668",
26060 total-sent="4096",total-size="9880"@}
26061 +download,@{section=".text",section-sent="4608",section-size="6668",
26062 total-sent="4608",total-size="9880"@}
26063 +download,@{section=".text",section-sent="5120",section-size="6668",
26064 total-sent="5120",total-size="9880"@}
26065 +download,@{section=".text",section-sent="5632",section-size="6668",
26066 total-sent="5632",total-size="9880"@}
26067 +download,@{section=".text",section-sent="6144",section-size="6668",
26068 total-sent="6144",total-size="9880"@}
26069 +download,@{section=".text",section-sent="6656",section-size="6668",
26070 total-sent="6656",total-size="9880"@}
26071 +download,@{section=".init",section-size="28",total-size="9880"@}
26072 +download,@{section=".fini",section-size="28",total-size="9880"@}
26073 +download,@{section=".data",section-size="3156",total-size="9880"@}
26074 +download,@{section=".data",section-sent="512",section-size="3156",
26075 total-sent="7236",total-size="9880"@}
26076 +download,@{section=".data",section-sent="1024",section-size="3156",
26077 total-sent="7748",total-size="9880"@}
26078 +download,@{section=".data",section-sent="1536",section-size="3156",
26079 total-sent="8260",total-size="9880"@}
26080 +download,@{section=".data",section-sent="2048",section-size="3156",
26081 total-sent="8772",total-size="9880"@}
26082 +download,@{section=".data",section-sent="2560",section-size="3156",
26083 total-sent="9284",total-size="9880"@}
26084 +download,@{section=".data",section-sent="3072",section-size="3156",
26085 total-sent="9796",total-size="9880"@}
26086 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
26087 write-rate="429"
26088 (gdb)
26089 @end smallexample
26090
26091
26092 @ignore
26093 @subheading The @code{-target-exec-status} Command
26094 @findex -target-exec-status
26095
26096 @subsubheading Synopsis
26097
26098 @smallexample
26099 -target-exec-status
26100 @end smallexample
26101
26102 Provide information on the state of the target (whether it is running or
26103 not, for instance).
26104
26105 @subsubheading @value{GDBN} Command
26106
26107 There's no equivalent @value{GDBN} command.
26108
26109 @subsubheading Example
26110 N.A.
26111
26112
26113 @subheading The @code{-target-list-available-targets} Command
26114 @findex -target-list-available-targets
26115
26116 @subsubheading Synopsis
26117
26118 @smallexample
26119 -target-list-available-targets
26120 @end smallexample
26121
26122 List the possible targets to connect to.
26123
26124 @subsubheading @value{GDBN} Command
26125
26126 The corresponding @value{GDBN} command is @samp{help target}.
26127
26128 @subsubheading Example
26129 N.A.
26130
26131
26132 @subheading The @code{-target-list-current-targets} Command
26133 @findex -target-list-current-targets
26134
26135 @subsubheading Synopsis
26136
26137 @smallexample
26138 -target-list-current-targets
26139 @end smallexample
26140
26141 Describe the current target.
26142
26143 @subsubheading @value{GDBN} Command
26144
26145 The corresponding information is printed by @samp{info file} (among
26146 other things).
26147
26148 @subsubheading Example
26149 N.A.
26150
26151
26152 @subheading The @code{-target-list-parameters} Command
26153 @findex -target-list-parameters
26154
26155 @subsubheading Synopsis
26156
26157 @smallexample
26158 -target-list-parameters
26159 @end smallexample
26160
26161 @c ????
26162 @end ignore
26163
26164 @subsubheading @value{GDBN} Command
26165
26166 No equivalent.
26167
26168 @subsubheading Example
26169 N.A.
26170
26171
26172 @subheading The @code{-target-select} Command
26173 @findex -target-select
26174
26175 @subsubheading Synopsis
26176
26177 @smallexample
26178 -target-select @var{type} @var{parameters @dots{}}
26179 @end smallexample
26180
26181 Connect @value{GDBN} to the remote target. This command takes two args:
26182
26183 @table @samp
26184 @item @var{type}
26185 The type of target, for instance @samp{remote}, etc.
26186 @item @var{parameters}
26187 Device names, host names and the like. @xref{Target Commands, ,
26188 Commands for Managing Targets}, for more details.
26189 @end table
26190
26191 The output is a connection notification, followed by the address at
26192 which the target program is, in the following form:
26193
26194 @smallexample
26195 ^connected,addr="@var{address}",func="@var{function name}",
26196 args=[@var{arg list}]
26197 @end smallexample
26198
26199 @subsubheading @value{GDBN} Command
26200
26201 The corresponding @value{GDBN} command is @samp{target}.
26202
26203 @subsubheading Example
26204
26205 @smallexample
26206 (gdb)
26207 -target-select remote /dev/ttya
26208 ^connected,addr="0xfe00a300",func="??",args=[]
26209 (gdb)
26210 @end smallexample
26211
26212 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26213 @node GDB/MI File Transfer Commands
26214 @section @sc{gdb/mi} File Transfer Commands
26215
26216
26217 @subheading The @code{-target-file-put} Command
26218 @findex -target-file-put
26219
26220 @subsubheading Synopsis
26221
26222 @smallexample
26223 -target-file-put @var{hostfile} @var{targetfile}
26224 @end smallexample
26225
26226 Copy file @var{hostfile} from the host system (the machine running
26227 @value{GDBN}) to @var{targetfile} on the target system.
26228
26229 @subsubheading @value{GDBN} Command
26230
26231 The corresponding @value{GDBN} command is @samp{remote put}.
26232
26233 @subsubheading Example
26234
26235 @smallexample
26236 (gdb)
26237 -target-file-put localfile remotefile
26238 ^done
26239 (gdb)
26240 @end smallexample
26241
26242
26243 @subheading The @code{-target-file-get} Command
26244 @findex -target-file-get
26245
26246 @subsubheading Synopsis
26247
26248 @smallexample
26249 -target-file-get @var{targetfile} @var{hostfile}
26250 @end smallexample
26251
26252 Copy file @var{targetfile} from the target system to @var{hostfile}
26253 on the host system.
26254
26255 @subsubheading @value{GDBN} Command
26256
26257 The corresponding @value{GDBN} command is @samp{remote get}.
26258
26259 @subsubheading Example
26260
26261 @smallexample
26262 (gdb)
26263 -target-file-get remotefile localfile
26264 ^done
26265 (gdb)
26266 @end smallexample
26267
26268
26269 @subheading The @code{-target-file-delete} Command
26270 @findex -target-file-delete
26271
26272 @subsubheading Synopsis
26273
26274 @smallexample
26275 -target-file-delete @var{targetfile}
26276 @end smallexample
26277
26278 Delete @var{targetfile} from the target system.
26279
26280 @subsubheading @value{GDBN} Command
26281
26282 The corresponding @value{GDBN} command is @samp{remote delete}.
26283
26284 @subsubheading Example
26285
26286 @smallexample
26287 (gdb)
26288 -target-file-delete remotefile
26289 ^done
26290 (gdb)
26291 @end smallexample
26292
26293
26294 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26295 @node GDB/MI Miscellaneous Commands
26296 @section Miscellaneous @sc{gdb/mi} Commands
26297
26298 @c @subheading -gdb-complete
26299
26300 @subheading The @code{-gdb-exit} Command
26301 @findex -gdb-exit
26302
26303 @subsubheading Synopsis
26304
26305 @smallexample
26306 -gdb-exit
26307 @end smallexample
26308
26309 Exit @value{GDBN} immediately.
26310
26311 @subsubheading @value{GDBN} Command
26312
26313 Approximately corresponds to @samp{quit}.
26314
26315 @subsubheading Example
26316
26317 @smallexample
26318 (gdb)
26319 -gdb-exit
26320 ^exit
26321 @end smallexample
26322
26323
26324 @ignore
26325 @subheading The @code{-exec-abort} Command
26326 @findex -exec-abort
26327
26328 @subsubheading Synopsis
26329
26330 @smallexample
26331 -exec-abort
26332 @end smallexample
26333
26334 Kill the inferior running program.
26335
26336 @subsubheading @value{GDBN} Command
26337
26338 The corresponding @value{GDBN} command is @samp{kill}.
26339
26340 @subsubheading Example
26341 N.A.
26342 @end ignore
26343
26344
26345 @subheading The @code{-gdb-set} Command
26346 @findex -gdb-set
26347
26348 @subsubheading Synopsis
26349
26350 @smallexample
26351 -gdb-set
26352 @end smallexample
26353
26354 Set an internal @value{GDBN} variable.
26355 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
26356
26357 @subsubheading @value{GDBN} Command
26358
26359 The corresponding @value{GDBN} command is @samp{set}.
26360
26361 @subsubheading Example
26362
26363 @smallexample
26364 (gdb)
26365 -gdb-set $foo=3
26366 ^done
26367 (gdb)
26368 @end smallexample
26369
26370
26371 @subheading The @code{-gdb-show} Command
26372 @findex -gdb-show
26373
26374 @subsubheading Synopsis
26375
26376 @smallexample
26377 -gdb-show
26378 @end smallexample
26379
26380 Show the current value of a @value{GDBN} variable.
26381
26382 @subsubheading @value{GDBN} Command
26383
26384 The corresponding @value{GDBN} command is @samp{show}.
26385
26386 @subsubheading Example
26387
26388 @smallexample
26389 (gdb)
26390 -gdb-show annotate
26391 ^done,value="0"
26392 (gdb)
26393 @end smallexample
26394
26395 @c @subheading -gdb-source
26396
26397
26398 @subheading The @code{-gdb-version} Command
26399 @findex -gdb-version
26400
26401 @subsubheading Synopsis
26402
26403 @smallexample
26404 -gdb-version
26405 @end smallexample
26406
26407 Show version information for @value{GDBN}. Used mostly in testing.
26408
26409 @subsubheading @value{GDBN} Command
26410
26411 The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
26412 default shows this information when you start an interactive session.
26413
26414 @subsubheading Example
26415
26416 @c This example modifies the actual output from GDB to avoid overfull
26417 @c box in TeX.
26418 @smallexample
26419 (gdb)
26420 -gdb-version
26421 ~GNU gdb 5.2.1
26422 ~Copyright 2000 Free Software Foundation, Inc.
26423 ~GDB is free software, covered by the GNU General Public License, and
26424 ~you are welcome to change it and/or distribute copies of it under
26425 ~ certain conditions.
26426 ~Type "show copying" to see the conditions.
26427 ~There is absolutely no warranty for GDB. Type "show warranty" for
26428 ~ details.
26429 ~This GDB was configured as
26430 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
26431 ^done
26432 (gdb)
26433 @end smallexample
26434
26435 @subheading The @code{-list-features} Command
26436 @findex -list-features
26437
26438 Returns a list of particular features of the MI protocol that
26439 this version of gdb implements. A feature can be a command,
26440 or a new field in an output of some command, or even an
26441 important bugfix. While a frontend can sometimes detect presence
26442 of a feature at runtime, it is easier to perform detection at debugger
26443 startup.
26444
26445 The command returns a list of strings, with each string naming an
26446 available feature. Each returned string is just a name, it does not
26447 have any internal structure. The list of possible feature names
26448 is given below.
26449
26450 Example output:
26451
26452 @smallexample
26453 (gdb) -list-features
26454 ^done,result=["feature1","feature2"]
26455 @end smallexample
26456
26457 The current list of features is:
26458
26459 @table @samp
26460 @item frozen-varobjs
26461 Indicates presence of the @code{-var-set-frozen} command, as well
26462 as possible presense of the @code{frozen} field in the output
26463 of @code{-varobj-create}.
26464 @item pending-breakpoints
26465 Indicates presence of the @option{-f} option to the @code{-break-insert} command.
26466 @item python
26467 Indicates presence of Python scripting support, Python-based
26468 pretty-printing commands, and possible presence of the
26469 @samp{display_hint} field in the output of @code{-var-list-children}
26470 @item thread-info
26471 Indicates presence of the @code{-thread-info} command.
26472
26473 @end table
26474
26475 @subheading The @code{-list-target-features} Command
26476 @findex -list-target-features
26477
26478 Returns a list of particular features that are supported by the
26479 target. Those features affect the permitted MI commands, but
26480 unlike the features reported by the @code{-list-features} command, the
26481 features depend on which target GDB is using at the moment. Whenever
26482 a target can change, due to commands such as @code{-target-select},
26483 @code{-target-attach} or @code{-exec-run}, the list of target features
26484 may change, and the frontend should obtain it again.
26485 Example output:
26486
26487 @smallexample
26488 (gdb) -list-features
26489 ^done,result=["async"]
26490 @end smallexample
26491
26492 The current list of features is:
26493
26494 @table @samp
26495 @item async
26496 Indicates that the target is capable of asynchronous command
26497 execution, which means that @value{GDBN} will accept further commands
26498 while the target is running.
26499
26500 @end table
26501
26502 @subheading The @code{-list-thread-groups} Command
26503 @findex -list-thread-groups
26504
26505 @subheading Synopsis
26506
26507 @smallexample
26508 -list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
26509 @end smallexample
26510
26511 Lists thread groups (@pxref{Thread groups}). When a single thread
26512 group is passed as the argument, lists the children of that group.
26513 When several thread group are passed, lists information about those
26514 thread groups. Without any parameters, lists information about all
26515 top-level thread groups.
26516
26517 Normally, thread groups that are being debugged are reported.
26518 With the @samp{--available} option, @value{GDBN} reports thread groups
26519 available on the target.
26520
26521 The output of this command may have either a @samp{threads} result or
26522 a @samp{groups} result. The @samp{thread} result has a list of tuples
26523 as value, with each tuple describing a thread (@pxref{GDB/MI Thread
26524 Information}). The @samp{groups} result has a list of tuples as value,
26525 each tuple describing a thread group. If top-level groups are
26526 requested (that is, no parameter is passed), or when several groups
26527 are passed, the output always has a @samp{groups} result. The format
26528 of the @samp{group} result is described below.
26529
26530 To reduce the number of roundtrips it's possible to list thread groups
26531 together with their children, by passing the @samp{--recurse} option
26532 and the recursion depth. Presently, only recursion depth of 1 is
26533 permitted. If this option is present, then every reported thread group
26534 will also include its children, either as @samp{group} or
26535 @samp{threads} field.
26536
26537 In general, any combination of option and parameters is permitted, with
26538 the following caveats:
26539
26540 @itemize @bullet
26541 @item
26542 When a single thread group is passed, the output will typically
26543 be the @samp{threads} result. Because threads may not contain
26544 anything, the @samp{recurse} option will be ignored.
26545
26546 @item
26547 When the @samp{--available} option is passed, limited information may
26548 be available. In particular, the list of threads of a process might
26549 be inaccessible. Further, specifying specific thread groups might
26550 not give any performance advantage over listing all thread groups.
26551 The frontend should assume that @samp{-list-thread-groups --available}
26552 is always an expensive operation and cache the results.
26553
26554 @end itemize
26555
26556 The @samp{groups} result is a list of tuples, where each tuple may
26557 have the following fields:
26558
26559 @table @code
26560 @item id
26561 Identifier of the thread group. This field is always present.
26562
26563 @item type
26564 The type of the thread group. At present, only @samp{process} is a
26565 valid type.
26566
26567 @item pid
26568 The target-specific process identifier. This field is only present
26569 for thread groups of type @samp{process}.
26570
26571 @item num_children
26572 The number of children this thread group has. This field may be
26573 absent for an available thread group.
26574
26575 @item threads
26576 This field has a list of tuples as value, each tuple describing a
26577 thread. It may be present if the @samp{--recurse} option is
26578 specified, and it's actually possible to obtain the threads.
26579
26580 @item cores
26581 This field is a list of integers, each identifying a core that one
26582 thread of the group is running on. This field may be absent if
26583 such information is not available.
26584
26585 @end table
26586
26587 @subheading Example
26588
26589 @smallexample
26590 @value{GDBP}
26591 -list-thread-groups
26592 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
26593 -list-thread-groups 17
26594 ^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
26595 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
26596 @{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
26597 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
26598 file="/tmp/a.c",fullname="/tmp/a.c",line="158"@},state="running"@}]]
26599 -list-thread-groups --available
26600 ^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
26601 -list-thread-groups --available --recurse 1
26602 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
26603 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
26604 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
26605 -list-thread-groups --available --recurse 1 17 18
26606 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
26607 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
26608 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
26609 @end smallexample
26610
26611 @subheading The @code{-interpreter-exec} Command
26612 @findex -interpreter-exec
26613
26614 @subheading Synopsis
26615
26616 @smallexample
26617 -interpreter-exec @var{interpreter} @var{command}
26618 @end smallexample
26619 @anchor{-interpreter-exec}
26620
26621 Execute the specified @var{command} in the given @var{interpreter}.
26622
26623 @subheading @value{GDBN} Command
26624
26625 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
26626
26627 @subheading Example
26628
26629 @smallexample
26630 (gdb)
26631 -interpreter-exec console "break main"
26632 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
26633 &"During symbol reading, bad structure-type format.\n"
26634 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
26635 ^done
26636 (gdb)
26637 @end smallexample
26638
26639 @subheading The @code{-inferior-tty-set} Command
26640 @findex -inferior-tty-set
26641
26642 @subheading Synopsis
26643
26644 @smallexample
26645 -inferior-tty-set /dev/pts/1
26646 @end smallexample
26647
26648 Set terminal for future runs of the program being debugged.
26649
26650 @subheading @value{GDBN} Command
26651
26652 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
26653
26654 @subheading Example
26655
26656 @smallexample
26657 (gdb)
26658 -inferior-tty-set /dev/pts/1
26659 ^done
26660 (gdb)
26661 @end smallexample
26662
26663 @subheading The @code{-inferior-tty-show} Command
26664 @findex -inferior-tty-show
26665
26666 @subheading Synopsis
26667
26668 @smallexample
26669 -inferior-tty-show
26670 @end smallexample
26671
26672 Show terminal for future runs of program being debugged.
26673
26674 @subheading @value{GDBN} Command
26675
26676 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
26677
26678 @subheading Example
26679
26680 @smallexample
26681 (gdb)
26682 -inferior-tty-set /dev/pts/1
26683 ^done
26684 (gdb)
26685 -inferior-tty-show
26686 ^done,inferior_tty_terminal="/dev/pts/1"
26687 (gdb)
26688 @end smallexample
26689
26690 @subheading The @code{-enable-timings} Command
26691 @findex -enable-timings
26692
26693 @subheading Synopsis
26694
26695 @smallexample
26696 -enable-timings [yes | no]
26697 @end smallexample
26698
26699 Toggle the printing of the wallclock, user and system times for an MI
26700 command as a field in its output. This command is to help frontend
26701 developers optimize the performance of their code. No argument is
26702 equivalent to @samp{yes}.
26703
26704 @subheading @value{GDBN} Command
26705
26706 No equivalent.
26707
26708 @subheading Example
26709
26710 @smallexample
26711 (gdb)
26712 -enable-timings
26713 ^done
26714 (gdb)
26715 -break-insert main
26716 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
26717 addr="0x080484ed",func="main",file="myprog.c",
26718 fullname="/home/nickrob/myprog.c",line="73",times="0"@},
26719 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
26720 (gdb)
26721 -enable-timings no
26722 ^done
26723 (gdb)
26724 -exec-run
26725 ^running
26726 (gdb)
26727 *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
26728 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
26729 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
26730 fullname="/home/nickrob/myprog.c",line="73"@}
26731 (gdb)
26732 @end smallexample
26733
26734 @node Annotations
26735 @chapter @value{GDBN} Annotations
26736
26737 This chapter describes annotations in @value{GDBN}. Annotations were
26738 designed to interface @value{GDBN} to graphical user interfaces or other
26739 similar programs which want to interact with @value{GDBN} at a
26740 relatively high level.
26741
26742 The annotation mechanism has largely been superseded by @sc{gdb/mi}
26743 (@pxref{GDB/MI}).
26744
26745 @ignore
26746 This is Edition @value{EDITION}, @value{DATE}.
26747 @end ignore
26748
26749 @menu
26750 * Annotations Overview:: What annotations are; the general syntax.
26751 * Server Prefix:: Issuing a command without affecting user state.
26752 * Prompting:: Annotations marking @value{GDBN}'s need for input.
26753 * Errors:: Annotations for error messages.
26754 * Invalidation:: Some annotations describe things now invalid.
26755 * Annotations for Running::
26756 Whether the program is running, how it stopped, etc.
26757 * Source Annotations:: Annotations describing source code.
26758 @end menu
26759
26760 @node Annotations Overview
26761 @section What is an Annotation?
26762 @cindex annotations
26763
26764 Annotations start with a newline character, two @samp{control-z}
26765 characters, and the name of the annotation. If there is no additional
26766 information associated with this annotation, the name of the annotation
26767 is followed immediately by a newline. If there is additional
26768 information, the name of the annotation is followed by a space, the
26769 additional information, and a newline. The additional information
26770 cannot contain newline characters.
26771
26772 Any output not beginning with a newline and two @samp{control-z}
26773 characters denotes literal output from @value{GDBN}. Currently there is
26774 no need for @value{GDBN} to output a newline followed by two
26775 @samp{control-z} characters, but if there was such a need, the
26776 annotations could be extended with an @samp{escape} annotation which
26777 means those three characters as output.
26778
26779 The annotation @var{level}, which is specified using the
26780 @option{--annotate} command line option (@pxref{Mode Options}), controls
26781 how much information @value{GDBN} prints together with its prompt,
26782 values of expressions, source lines, and other types of output. Level 0
26783 is for no annotations, level 1 is for use when @value{GDBN} is run as a
26784 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
26785 for programs that control @value{GDBN}, and level 2 annotations have
26786 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
26787 Interface, annotate, GDB's Obsolete Annotations}).
26788
26789 @table @code
26790 @kindex set annotate
26791 @item set annotate @var{level}
26792 The @value{GDBN} command @code{set annotate} sets the level of
26793 annotations to the specified @var{level}.
26794
26795 @item show annotate
26796 @kindex show annotate
26797 Show the current annotation level.
26798 @end table
26799
26800 This chapter describes level 3 annotations.
26801
26802 A simple example of starting up @value{GDBN} with annotations is:
26803
26804 @smallexample
26805 $ @kbd{gdb --annotate=3}
26806 GNU gdb 6.0
26807 Copyright 2003 Free Software Foundation, Inc.
26808 GDB is free software, covered by the GNU General Public License,
26809 and you are welcome to change it and/or distribute copies of it
26810 under certain conditions.
26811 Type "show copying" to see the conditions.
26812 There is absolutely no warranty for GDB. Type "show warranty"
26813 for details.
26814 This GDB was configured as "i386-pc-linux-gnu"
26815
26816 ^Z^Zpre-prompt
26817 (@value{GDBP})
26818 ^Z^Zprompt
26819 @kbd{quit}
26820
26821 ^Z^Zpost-prompt
26822 $
26823 @end smallexample
26824
26825 Here @samp{quit} is input to @value{GDBN}; the rest is output from
26826 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
26827 denotes a @samp{control-z} character) are annotations; the rest is
26828 output from @value{GDBN}.
26829
26830 @node Server Prefix
26831 @section The Server Prefix
26832 @cindex server prefix
26833
26834 If you prefix a command with @samp{server } then it will not affect
26835 the command history, nor will it affect @value{GDBN}'s notion of which
26836 command to repeat if @key{RET} is pressed on a line by itself. This
26837 means that commands can be run behind a user's back by a front-end in
26838 a transparent manner.
26839
26840 The @code{server } prefix does not affect the recording of values into
26841 the value history; to print a value without recording it into the
26842 value history, use the @code{output} command instead of the
26843 @code{print} command.
26844
26845 Using this prefix also disables confirmation requests
26846 (@pxref{confirmation requests}).
26847
26848 @node Prompting
26849 @section Annotation for @value{GDBN} Input
26850
26851 @cindex annotations for prompts
26852 When @value{GDBN} prompts for input, it annotates this fact so it is possible
26853 to know when to send output, when the output from a given command is
26854 over, etc.
26855
26856 Different kinds of input each have a different @dfn{input type}. Each
26857 input type has three annotations: a @code{pre-} annotation, which
26858 denotes the beginning of any prompt which is being output, a plain
26859 annotation, which denotes the end of the prompt, and then a @code{post-}
26860 annotation which denotes the end of any echo which may (or may not) be
26861 associated with the input. For example, the @code{prompt} input type
26862 features the following annotations:
26863
26864 @smallexample
26865 ^Z^Zpre-prompt
26866 ^Z^Zprompt
26867 ^Z^Zpost-prompt
26868 @end smallexample
26869
26870 The input types are
26871
26872 @table @code
26873 @findex pre-prompt annotation
26874 @findex prompt annotation
26875 @findex post-prompt annotation
26876 @item prompt
26877 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
26878
26879 @findex pre-commands annotation
26880 @findex commands annotation
26881 @findex post-commands annotation
26882 @item commands
26883 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
26884 command. The annotations are repeated for each command which is input.
26885
26886 @findex pre-overload-choice annotation
26887 @findex overload-choice annotation
26888 @findex post-overload-choice annotation
26889 @item overload-choice
26890 When @value{GDBN} wants the user to select between various overloaded functions.
26891
26892 @findex pre-query annotation
26893 @findex query annotation
26894 @findex post-query annotation
26895 @item query
26896 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
26897
26898 @findex pre-prompt-for-continue annotation
26899 @findex prompt-for-continue annotation
26900 @findex post-prompt-for-continue annotation
26901 @item prompt-for-continue
26902 When @value{GDBN} is asking the user to press return to continue. Note: Don't
26903 expect this to work well; instead use @code{set height 0} to disable
26904 prompting. This is because the counting of lines is buggy in the
26905 presence of annotations.
26906 @end table
26907
26908 @node Errors
26909 @section Errors
26910 @cindex annotations for errors, warnings and interrupts
26911
26912 @findex quit annotation
26913 @smallexample
26914 ^Z^Zquit
26915 @end smallexample
26916
26917 This annotation occurs right before @value{GDBN} responds to an interrupt.
26918
26919 @findex error annotation
26920 @smallexample
26921 ^Z^Zerror
26922 @end smallexample
26923
26924 This annotation occurs right before @value{GDBN} responds to an error.
26925
26926 Quit and error annotations indicate that any annotations which @value{GDBN} was
26927 in the middle of may end abruptly. For example, if a
26928 @code{value-history-begin} annotation is followed by a @code{error}, one
26929 cannot expect to receive the matching @code{value-history-end}. One
26930 cannot expect not to receive it either, however; an error annotation
26931 does not necessarily mean that @value{GDBN} is immediately returning all the way
26932 to the top level.
26933
26934 @findex error-begin annotation
26935 A quit or error annotation may be preceded by
26936
26937 @smallexample
26938 ^Z^Zerror-begin
26939 @end smallexample
26940
26941 Any output between that and the quit or error annotation is the error
26942 message.
26943
26944 Warning messages are not yet annotated.
26945 @c If we want to change that, need to fix warning(), type_error(),
26946 @c range_error(), and possibly other places.
26947
26948 @node Invalidation
26949 @section Invalidation Notices
26950
26951 @cindex annotations for invalidation messages
26952 The following annotations say that certain pieces of state may have
26953 changed.
26954
26955 @table @code
26956 @findex frames-invalid annotation
26957 @item ^Z^Zframes-invalid
26958
26959 The frames (for example, output from the @code{backtrace} command) may
26960 have changed.
26961
26962 @findex breakpoints-invalid annotation
26963 @item ^Z^Zbreakpoints-invalid
26964
26965 The breakpoints may have changed. For example, the user just added or
26966 deleted a breakpoint.
26967 @end table
26968
26969 @node Annotations for Running
26970 @section Running the Program
26971 @cindex annotations for running programs
26972
26973 @findex starting annotation
26974 @findex stopping annotation
26975 When the program starts executing due to a @value{GDBN} command such as
26976 @code{step} or @code{continue},
26977
26978 @smallexample
26979 ^Z^Zstarting
26980 @end smallexample
26981
26982 is output. When the program stops,
26983
26984 @smallexample
26985 ^Z^Zstopped
26986 @end smallexample
26987
26988 is output. Before the @code{stopped} annotation, a variety of
26989 annotations describe how the program stopped.
26990
26991 @table @code
26992 @findex exited annotation
26993 @item ^Z^Zexited @var{exit-status}
26994 The program exited, and @var{exit-status} is the exit status (zero for
26995 successful exit, otherwise nonzero).
26996
26997 @findex signalled annotation
26998 @findex signal-name annotation
26999 @findex signal-name-end annotation
27000 @findex signal-string annotation
27001 @findex signal-string-end annotation
27002 @item ^Z^Zsignalled
27003 The program exited with a signal. After the @code{^Z^Zsignalled}, the
27004 annotation continues:
27005
27006 @smallexample
27007 @var{intro-text}
27008 ^Z^Zsignal-name
27009 @var{name}
27010 ^Z^Zsignal-name-end
27011 @var{middle-text}
27012 ^Z^Zsignal-string
27013 @var{string}
27014 ^Z^Zsignal-string-end
27015 @var{end-text}
27016 @end smallexample
27017
27018 @noindent
27019 where @var{name} is the name of the signal, such as @code{SIGILL} or
27020 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
27021 as @code{Illegal Instruction} or @code{Segmentation fault}.
27022 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
27023 user's benefit and have no particular format.
27024
27025 @findex signal annotation
27026 @item ^Z^Zsignal
27027 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
27028 just saying that the program received the signal, not that it was
27029 terminated with it.
27030
27031 @findex breakpoint annotation
27032 @item ^Z^Zbreakpoint @var{number}
27033 The program hit breakpoint number @var{number}.
27034
27035 @findex watchpoint annotation
27036 @item ^Z^Zwatchpoint @var{number}
27037 The program hit watchpoint number @var{number}.
27038 @end table
27039
27040 @node Source Annotations
27041 @section Displaying Source
27042 @cindex annotations for source display
27043
27044 @findex source annotation
27045 The following annotation is used instead of displaying source code:
27046
27047 @smallexample
27048 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
27049 @end smallexample
27050
27051 where @var{filename} is an absolute file name indicating which source
27052 file, @var{line} is the line number within that file (where 1 is the
27053 first line in the file), @var{character} is the character position
27054 within the file (where 0 is the first character in the file) (for most
27055 debug formats this will necessarily point to the beginning of a line),
27056 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
27057 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
27058 @var{addr} is the address in the target program associated with the
27059 source which is being displayed. @var{addr} is in the form @samp{0x}
27060 followed by one or more lowercase hex digits (note that this does not
27061 depend on the language).
27062
27063 @node JIT Interface
27064 @chapter JIT Compilation Interface
27065 @cindex just-in-time compilation
27066 @cindex JIT compilation interface
27067
27068 This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
27069 interface. A JIT compiler is a program or library that generates native
27070 executable code at runtime and executes it, usually in order to achieve good
27071 performance while maintaining platform independence.
27072
27073 Programs that use JIT compilation are normally difficult to debug because
27074 portions of their code are generated at runtime, instead of being loaded from
27075 object files, which is where @value{GDBN} normally finds the program's symbols
27076 and debug information. In order to debug programs that use JIT compilation,
27077 @value{GDBN} has an interface that allows the program to register in-memory
27078 symbol files with @value{GDBN} at runtime.
27079
27080 If you are using @value{GDBN} to debug a program that uses this interface, then
27081 it should work transparently so long as you have not stripped the binary. If
27082 you are developing a JIT compiler, then the interface is documented in the rest
27083 of this chapter. At this time, the only known client of this interface is the
27084 LLVM JIT.
27085
27086 Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
27087 JIT compiler communicates with @value{GDBN} by writing data into a global
27088 variable and calling a fuction at a well-known symbol. When @value{GDBN}
27089 attaches, it reads a linked list of symbol files from the global variable to
27090 find existing code, and puts a breakpoint in the function so that it can find
27091 out about additional code.
27092
27093 @menu
27094 * Declarations:: Relevant C struct declarations
27095 * Registering Code:: Steps to register code
27096 * Unregistering Code:: Steps to unregister code
27097 @end menu
27098
27099 @node Declarations
27100 @section JIT Declarations
27101
27102 These are the relevant struct declarations that a C program should include to
27103 implement the interface:
27104
27105 @smallexample
27106 typedef enum
27107 @{
27108 JIT_NOACTION = 0,
27109 JIT_REGISTER_FN,
27110 JIT_UNREGISTER_FN
27111 @} jit_actions_t;
27112
27113 struct jit_code_entry
27114 @{
27115 struct jit_code_entry *next_entry;
27116 struct jit_code_entry *prev_entry;
27117 const char *symfile_addr;
27118 uint64_t symfile_size;
27119 @};
27120
27121 struct jit_descriptor
27122 @{
27123 uint32_t version;
27124 /* This type should be jit_actions_t, but we use uint32_t
27125 to be explicit about the bitwidth. */
27126 uint32_t action_flag;
27127 struct jit_code_entry *relevant_entry;
27128 struct jit_code_entry *first_entry;
27129 @};
27130
27131 /* GDB puts a breakpoint in this function. */
27132 void __attribute__((noinline)) __jit_debug_register_code() @{ @};
27133
27134 /* Make sure to specify the version statically, because the
27135 debugger may check the version before we can set it. */
27136 struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
27137 @end smallexample
27138
27139 If the JIT is multi-threaded, then it is important that the JIT synchronize any
27140 modifications to this global data properly, which can easily be done by putting
27141 a global mutex around modifications to these structures.
27142
27143 @node Registering Code
27144 @section Registering Code
27145
27146 To register code with @value{GDBN}, the JIT should follow this protocol:
27147
27148 @itemize @bullet
27149 @item
27150 Generate an object file in memory with symbols and other desired debug
27151 information. The file must include the virtual addresses of the sections.
27152
27153 @item
27154 Create a code entry for the file, which gives the start and size of the symbol
27155 file.
27156
27157 @item
27158 Add it to the linked list in the JIT descriptor.
27159
27160 @item
27161 Point the relevant_entry field of the descriptor at the entry.
27162
27163 @item
27164 Set @code{action_flag} to @code{JIT_REGISTER} and call
27165 @code{__jit_debug_register_code}.
27166 @end itemize
27167
27168 When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
27169 @code{relevant_entry} pointer so it doesn't have to walk the list looking for
27170 new code. However, the linked list must still be maintained in order to allow
27171 @value{GDBN} to attach to a running process and still find the symbol files.
27172
27173 @node Unregistering Code
27174 @section Unregistering Code
27175
27176 If code is freed, then the JIT should use the following protocol:
27177
27178 @itemize @bullet
27179 @item
27180 Remove the code entry corresponding to the code from the linked list.
27181
27182 @item
27183 Point the @code{relevant_entry} field of the descriptor at the code entry.
27184
27185 @item
27186 Set @code{action_flag} to @code{JIT_UNREGISTER} and call
27187 @code{__jit_debug_register_code}.
27188 @end itemize
27189
27190 If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
27191 and the JIT will leak the memory used for the associated symbol files.
27192
27193 @node GDB Bugs
27194 @chapter Reporting Bugs in @value{GDBN}
27195 @cindex bugs in @value{GDBN}
27196 @cindex reporting bugs in @value{GDBN}
27197
27198 Your bug reports play an essential role in making @value{GDBN} reliable.
27199
27200 Reporting a bug may help you by bringing a solution to your problem, or it
27201 may not. But in any case the principal function of a bug report is to help
27202 the entire community by making the next version of @value{GDBN} work better. Bug
27203 reports are your contribution to the maintenance of @value{GDBN}.
27204
27205 In order for a bug report to serve its purpose, you must include the
27206 information that enables us to fix the bug.
27207
27208 @menu
27209 * Bug Criteria:: Have you found a bug?
27210 * Bug Reporting:: How to report bugs
27211 @end menu
27212
27213 @node Bug Criteria
27214 @section Have You Found a Bug?
27215 @cindex bug criteria
27216
27217 If you are not sure whether you have found a bug, here are some guidelines:
27218
27219 @itemize @bullet
27220 @cindex fatal signal
27221 @cindex debugger crash
27222 @cindex crash of debugger
27223 @item
27224 If the debugger gets a fatal signal, for any input whatever, that is a
27225 @value{GDBN} bug. Reliable debuggers never crash.
27226
27227 @cindex error on valid input
27228 @item
27229 If @value{GDBN} produces an error message for valid input, that is a
27230 bug. (Note that if you're cross debugging, the problem may also be
27231 somewhere in the connection to the target.)
27232
27233 @cindex invalid input
27234 @item
27235 If @value{GDBN} does not produce an error message for invalid input,
27236 that is a bug. However, you should note that your idea of
27237 ``invalid input'' might be our idea of ``an extension'' or ``support
27238 for traditional practice''.
27239
27240 @item
27241 If you are an experienced user of debugging tools, your suggestions
27242 for improvement of @value{GDBN} are welcome in any case.
27243 @end itemize
27244
27245 @node Bug Reporting
27246 @section How to Report Bugs
27247 @cindex bug reports
27248 @cindex @value{GDBN} bugs, reporting
27249
27250 A number of companies and individuals offer support for @sc{gnu} products.
27251 If you obtained @value{GDBN} from a support organization, we recommend you
27252 contact that organization first.
27253
27254 You can find contact information for many support companies and
27255 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
27256 distribution.
27257 @c should add a web page ref...
27258
27259 @ifset BUGURL
27260 @ifset BUGURL_DEFAULT
27261 In any event, we also recommend that you submit bug reports for
27262 @value{GDBN}. The preferred method is to submit them directly using
27263 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
27264 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
27265 be used.
27266
27267 @strong{Do not send bug reports to @samp{info-gdb}, or to
27268 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
27269 not want to receive bug reports. Those that do have arranged to receive
27270 @samp{bug-gdb}.
27271
27272 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
27273 serves as a repeater. The mailing list and the newsgroup carry exactly
27274 the same messages. Often people think of posting bug reports to the
27275 newsgroup instead of mailing them. This appears to work, but it has one
27276 problem which can be crucial: a newsgroup posting often lacks a mail
27277 path back to the sender. Thus, if we need to ask for more information,
27278 we may be unable to reach you. For this reason, it is better to send
27279 bug reports to the mailing list.
27280 @end ifset
27281 @ifclear BUGURL_DEFAULT
27282 In any event, we also recommend that you submit bug reports for
27283 @value{GDBN} to @value{BUGURL}.
27284 @end ifclear
27285 @end ifset
27286
27287 The fundamental principle of reporting bugs usefully is this:
27288 @strong{report all the facts}. If you are not sure whether to state a
27289 fact or leave it out, state it!
27290
27291 Often people omit facts because they think they know what causes the
27292 problem and assume that some details do not matter. Thus, you might
27293 assume that the name of the variable you use in an example does not matter.
27294 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
27295 stray memory reference which happens to fetch from the location where that
27296 name is stored in memory; perhaps, if the name were different, the contents
27297 of that location would fool the debugger into doing the right thing despite
27298 the bug. Play it safe and give a specific, complete example. That is the
27299 easiest thing for you to do, and the most helpful.
27300
27301 Keep in mind that the purpose of a bug report is to enable us to fix the
27302 bug. It may be that the bug has been reported previously, but neither
27303 you nor we can know that unless your bug report is complete and
27304 self-contained.
27305
27306 Sometimes people give a few sketchy facts and ask, ``Does this ring a
27307 bell?'' Those bug reports are useless, and we urge everyone to
27308 @emph{refuse to respond to them} except to chide the sender to report
27309 bugs properly.
27310
27311 To enable us to fix the bug, you should include all these things:
27312
27313 @itemize @bullet
27314 @item
27315 The version of @value{GDBN}. @value{GDBN} announces it if you start
27316 with no arguments; you can also print it at any time using @code{show
27317 version}.
27318
27319 Without this, we will not know whether there is any point in looking for
27320 the bug in the current version of @value{GDBN}.
27321
27322 @item
27323 The type of machine you are using, and the operating system name and
27324 version number.
27325
27326 @item
27327 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
27328 ``@value{GCC}--2.8.1''.
27329
27330 @item
27331 What compiler (and its version) was used to compile the program you are
27332 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
27333 C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
27334 to get this information; for other compilers, see the documentation for
27335 those compilers.
27336
27337 @item
27338 The command arguments you gave the compiler to compile your example and
27339 observe the bug. For example, did you use @samp{-O}? To guarantee
27340 you will not omit something important, list them all. A copy of the
27341 Makefile (or the output from make) is sufficient.
27342
27343 If we were to try to guess the arguments, we would probably guess wrong
27344 and then we might not encounter the bug.
27345
27346 @item
27347 A complete input script, and all necessary source files, that will
27348 reproduce the bug.
27349
27350 @item
27351 A description of what behavior you observe that you believe is
27352 incorrect. For example, ``It gets a fatal signal.''
27353
27354 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
27355 will certainly notice it. But if the bug is incorrect output, we might
27356 not notice unless it is glaringly wrong. You might as well not give us
27357 a chance to make a mistake.
27358
27359 Even if the problem you experience is a fatal signal, you should still
27360 say so explicitly. Suppose something strange is going on, such as, your
27361 copy of @value{GDBN} is out of synch, or you have encountered a bug in
27362 the C library on your system. (This has happened!) Your copy might
27363 crash and ours would not. If you told us to expect a crash, then when
27364 ours fails to crash, we would know that the bug was not happening for
27365 us. If you had not told us to expect a crash, then we would not be able
27366 to draw any conclusion from our observations.
27367
27368 @pindex script
27369 @cindex recording a session script
27370 To collect all this information, you can use a session recording program
27371 such as @command{script}, which is available on many Unix systems.
27372 Just run your @value{GDBN} session inside @command{script} and then
27373 include the @file{typescript} file with your bug report.
27374
27375 Another way to record a @value{GDBN} session is to run @value{GDBN}
27376 inside Emacs and then save the entire buffer to a file.
27377
27378 @item
27379 If you wish to suggest changes to the @value{GDBN} source, send us context
27380 diffs. If you even discuss something in the @value{GDBN} source, refer to
27381 it by context, not by line number.
27382
27383 The line numbers in our development sources will not match those in your
27384 sources. Your line numbers would convey no useful information to us.
27385
27386 @end itemize
27387
27388 Here are some things that are not necessary:
27389
27390 @itemize @bullet
27391 @item
27392 A description of the envelope of the bug.
27393
27394 Often people who encounter a bug spend a lot of time investigating
27395 which changes to the input file will make the bug go away and which
27396 changes will not affect it.
27397
27398 This is often time consuming and not very useful, because the way we
27399 will find the bug is by running a single example under the debugger
27400 with breakpoints, not by pure deduction from a series of examples.
27401 We recommend that you save your time for something else.
27402
27403 Of course, if you can find a simpler example to report @emph{instead}
27404 of the original one, that is a convenience for us. Errors in the
27405 output will be easier to spot, running under the debugger will take
27406 less time, and so on.
27407
27408 However, simplification is not vital; if you do not want to do this,
27409 report the bug anyway and send us the entire test case you used.
27410
27411 @item
27412 A patch for the bug.
27413
27414 A patch for the bug does help us if it is a good one. But do not omit
27415 the necessary information, such as the test case, on the assumption that
27416 a patch is all we need. We might see problems with your patch and decide
27417 to fix the problem another way, or we might not understand it at all.
27418
27419 Sometimes with a program as complicated as @value{GDBN} it is very hard to
27420 construct an example that will make the program follow a certain path
27421 through the code. If you do not send us the example, we will not be able
27422 to construct one, so we will not be able to verify that the bug is fixed.
27423
27424 And if we cannot understand what bug you are trying to fix, or why your
27425 patch should be an improvement, we will not install it. A test case will
27426 help us to understand.
27427
27428 @item
27429 A guess about what the bug is or what it depends on.
27430
27431 Such guesses are usually wrong. Even we cannot guess right about such
27432 things without first using the debugger to find the facts.
27433 @end itemize
27434
27435 @c The readline documentation is distributed with the readline code
27436 @c and consists of the two following files:
27437 @c rluser.texinfo
27438 @c inc-hist.texinfo
27439 @c Use -I with makeinfo to point to the appropriate directory,
27440 @c environment var TEXINPUTS with TeX.
27441 @include rluser.texi
27442 @include inc-hist.texinfo
27443
27444
27445 @node Formatting Documentation
27446 @appendix Formatting Documentation
27447
27448 @cindex @value{GDBN} reference card
27449 @cindex reference card
27450 The @value{GDBN} 4 release includes an already-formatted reference card, ready
27451 for printing with PostScript or Ghostscript, in the @file{gdb}
27452 subdirectory of the main source directory@footnote{In
27453 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
27454 release.}. If you can use PostScript or Ghostscript with your printer,
27455 you can print the reference card immediately with @file{refcard.ps}.
27456
27457 The release also includes the source for the reference card. You
27458 can format it, using @TeX{}, by typing:
27459
27460 @smallexample
27461 make refcard.dvi
27462 @end smallexample
27463
27464 The @value{GDBN} reference card is designed to print in @dfn{landscape}
27465 mode on US ``letter'' size paper;
27466 that is, on a sheet 11 inches wide by 8.5 inches
27467 high. You will need to specify this form of printing as an option to
27468 your @sc{dvi} output program.
27469
27470 @cindex documentation
27471
27472 All the documentation for @value{GDBN} comes as part of the machine-readable
27473 distribution. The documentation is written in Texinfo format, which is
27474 a documentation system that uses a single source file to produce both
27475 on-line information and a printed manual. You can use one of the Info
27476 formatting commands to create the on-line version of the documentation
27477 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
27478
27479 @value{GDBN} includes an already formatted copy of the on-line Info
27480 version of this manual in the @file{gdb} subdirectory. The main Info
27481 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
27482 subordinate files matching @samp{gdb.info*} in the same directory. If
27483 necessary, you can print out these files, or read them with any editor;
27484 but they are easier to read using the @code{info} subsystem in @sc{gnu}
27485 Emacs or the standalone @code{info} program, available as part of the
27486 @sc{gnu} Texinfo distribution.
27487
27488 If you want to format these Info files yourself, you need one of the
27489 Info formatting programs, such as @code{texinfo-format-buffer} or
27490 @code{makeinfo}.
27491
27492 If you have @code{makeinfo} installed, and are in the top level
27493 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
27494 version @value{GDBVN}), you can make the Info file by typing:
27495
27496 @smallexample
27497 cd gdb
27498 make gdb.info
27499 @end smallexample
27500
27501 If you want to typeset and print copies of this manual, you need @TeX{},
27502 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
27503 Texinfo definitions file.
27504
27505 @TeX{} is a typesetting program; it does not print files directly, but
27506 produces output files called @sc{dvi} files. To print a typeset
27507 document, you need a program to print @sc{dvi} files. If your system
27508 has @TeX{} installed, chances are it has such a program. The precise
27509 command to use depends on your system; @kbd{lpr -d} is common; another
27510 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
27511 require a file name without any extension or a @samp{.dvi} extension.
27512
27513 @TeX{} also requires a macro definitions file called
27514 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
27515 written in Texinfo format. On its own, @TeX{} cannot either read or
27516 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
27517 and is located in the @file{gdb-@var{version-number}/texinfo}
27518 directory.
27519
27520 If you have @TeX{} and a @sc{dvi} printer program installed, you can
27521 typeset and print this manual. First switch to the @file{gdb}
27522 subdirectory of the main source directory (for example, to
27523 @file{gdb-@value{GDBVN}/gdb}) and type:
27524
27525 @smallexample
27526 make gdb.dvi
27527 @end smallexample
27528
27529 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
27530
27531 @node Installing GDB
27532 @appendix Installing @value{GDBN}
27533 @cindex installation
27534
27535 @menu
27536 * Requirements:: Requirements for building @value{GDBN}
27537 * Running Configure:: Invoking the @value{GDBN} @file{configure} script
27538 * Separate Objdir:: Compiling @value{GDBN} in another directory
27539 * Config Names:: Specifying names for hosts and targets
27540 * Configure Options:: Summary of options for configure
27541 * System-wide configuration:: Having a system-wide init file
27542 @end menu
27543
27544 @node Requirements
27545 @section Requirements for Building @value{GDBN}
27546 @cindex building @value{GDBN}, requirements for
27547
27548 Building @value{GDBN} requires various tools and packages to be available.
27549 Other packages will be used only if they are found.
27550
27551 @heading Tools/Packages Necessary for Building @value{GDBN}
27552 @table @asis
27553 @item ISO C90 compiler
27554 @value{GDBN} is written in ISO C90. It should be buildable with any
27555 working C90 compiler, e.g.@: GCC.
27556
27557 @end table
27558
27559 @heading Tools/Packages Optional for Building @value{GDBN}
27560 @table @asis
27561 @item Expat
27562 @anchor{Expat}
27563 @value{GDBN} can use the Expat XML parsing library. This library may be
27564 included with your operating system distribution; if it is not, you
27565 can get the latest version from @url{http://expat.sourceforge.net}.
27566 The @file{configure} script will search for this library in several
27567 standard locations; if it is installed in an unusual path, you can
27568 use the @option{--with-libexpat-prefix} option to specify its location.
27569
27570 Expat is used for:
27571
27572 @itemize @bullet
27573 @item
27574 Remote protocol memory maps (@pxref{Memory Map Format})
27575 @item
27576 Target descriptions (@pxref{Target Descriptions})
27577 @item
27578 Remote shared library lists (@pxref{Library List Format})
27579 @item
27580 MS-Windows shared libraries (@pxref{Shared Libraries})
27581 @end itemize
27582
27583 @item zlib
27584 @cindex compressed debug sections
27585 @value{GDBN} will use the @samp{zlib} library, if available, to read
27586 compressed debug sections. Some linkers, such as GNU gold, are capable
27587 of producing binaries with compressed debug sections. If @value{GDBN}
27588 is compiled with @samp{zlib}, it will be able to read the debug
27589 information in such binaries.
27590
27591 The @samp{zlib} library is likely included with your operating system
27592 distribution; if it is not, you can get the latest version from
27593 @url{http://zlib.net}.
27594
27595 @item iconv
27596 @value{GDBN}'s features related to character sets (@pxref{Character
27597 Sets}) require a functioning @code{iconv} implementation. If you are
27598 on a GNU system, then this is provided by the GNU C Library. Some
27599 other systems also provide a working @code{iconv}.
27600
27601 On systems with @code{iconv}, you can install GNU Libiconv. If you
27602 have previously installed Libiconv, you can use the
27603 @option{--with-libiconv-prefix} option to configure.
27604
27605 @value{GDBN}'s top-level @file{configure} and @file{Makefile} will
27606 arrange to build Libiconv if a directory named @file{libiconv} appears
27607 in the top-most source directory. If Libiconv is built this way, and
27608 if the operating system does not provide a suitable @code{iconv}
27609 implementation, then the just-built library will automatically be used
27610 by @value{GDBN}. One easy way to set this up is to download GNU
27611 Libiconv, unpack it, and then rename the directory holding the
27612 Libiconv source code to @samp{libiconv}.
27613 @end table
27614
27615 @node Running Configure
27616 @section Invoking the @value{GDBN} @file{configure} Script
27617 @cindex configuring @value{GDBN}
27618 @value{GDBN} comes with a @file{configure} script that automates the process
27619 of preparing @value{GDBN} for installation; you can then use @code{make} to
27620 build the @code{gdb} program.
27621 @iftex
27622 @c irrelevant in info file; it's as current as the code it lives with.
27623 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
27624 look at the @file{README} file in the sources; we may have improved the
27625 installation procedures since publishing this manual.}
27626 @end iftex
27627
27628 The @value{GDBN} distribution includes all the source code you need for
27629 @value{GDBN} in a single directory, whose name is usually composed by
27630 appending the version number to @samp{gdb}.
27631
27632 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
27633 @file{gdb-@value{GDBVN}} directory. That directory contains:
27634
27635 @table @code
27636 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
27637 script for configuring @value{GDBN} and all its supporting libraries
27638
27639 @item gdb-@value{GDBVN}/gdb
27640 the source specific to @value{GDBN} itself
27641
27642 @item gdb-@value{GDBVN}/bfd
27643 source for the Binary File Descriptor library
27644
27645 @item gdb-@value{GDBVN}/include
27646 @sc{gnu} include files
27647
27648 @item gdb-@value{GDBVN}/libiberty
27649 source for the @samp{-liberty} free software library
27650
27651 @item gdb-@value{GDBVN}/opcodes
27652 source for the library of opcode tables and disassemblers
27653
27654 @item gdb-@value{GDBVN}/readline
27655 source for the @sc{gnu} command-line interface
27656
27657 @item gdb-@value{GDBVN}/glob
27658 source for the @sc{gnu} filename pattern-matching subroutine
27659
27660 @item gdb-@value{GDBVN}/mmalloc
27661 source for the @sc{gnu} memory-mapped malloc package
27662 @end table
27663
27664 The simplest way to configure and build @value{GDBN} is to run @file{configure}
27665 from the @file{gdb-@var{version-number}} source directory, which in
27666 this example is the @file{gdb-@value{GDBVN}} directory.
27667
27668 First switch to the @file{gdb-@var{version-number}} source directory
27669 if you are not already in it; then run @file{configure}. Pass the
27670 identifier for the platform on which @value{GDBN} will run as an
27671 argument.
27672
27673 For example:
27674
27675 @smallexample
27676 cd gdb-@value{GDBVN}
27677 ./configure @var{host}
27678 make
27679 @end smallexample
27680
27681 @noindent
27682 where @var{host} is an identifier such as @samp{sun4} or
27683 @samp{decstation}, that identifies the platform where @value{GDBN} will run.
27684 (You can often leave off @var{host}; @file{configure} tries to guess the
27685 correct value by examining your system.)
27686
27687 Running @samp{configure @var{host}} and then running @code{make} builds the
27688 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
27689 libraries, then @code{gdb} itself. The configured source files, and the
27690 binaries, are left in the corresponding source directories.
27691
27692 @need 750
27693 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
27694 system does not recognize this automatically when you run a different
27695 shell, you may need to run @code{sh} on it explicitly:
27696
27697 @smallexample
27698 sh configure @var{host}
27699 @end smallexample
27700
27701 If you run @file{configure} from a directory that contains source
27702 directories for multiple libraries or programs, such as the
27703 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
27704 @file{configure}
27705 creates configuration files for every directory level underneath (unless
27706 you tell it not to, with the @samp{--norecursion} option).
27707
27708 You should run the @file{configure} script from the top directory in the
27709 source tree, the @file{gdb-@var{version-number}} directory. If you run
27710 @file{configure} from one of the subdirectories, you will configure only
27711 that subdirectory. That is usually not what you want. In particular,
27712 if you run the first @file{configure} from the @file{gdb} subdirectory
27713 of the @file{gdb-@var{version-number}} directory, you will omit the
27714 configuration of @file{bfd}, @file{readline}, and other sibling
27715 directories of the @file{gdb} subdirectory. This leads to build errors
27716 about missing include files such as @file{bfd/bfd.h}.
27717
27718 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
27719 However, you should make sure that the shell on your path (named by
27720 the @samp{SHELL} environment variable) is publicly readable. Remember
27721 that @value{GDBN} uses the shell to start your program---some systems refuse to
27722 let @value{GDBN} debug child processes whose programs are not readable.
27723
27724 @node Separate Objdir
27725 @section Compiling @value{GDBN} in Another Directory
27726
27727 If you want to run @value{GDBN} versions for several host or target machines,
27728 you need a different @code{gdb} compiled for each combination of
27729 host and target. @file{configure} is designed to make this easy by
27730 allowing you to generate each configuration in a separate subdirectory,
27731 rather than in the source directory. If your @code{make} program
27732 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
27733 @code{make} in each of these directories builds the @code{gdb}
27734 program specified there.
27735
27736 To build @code{gdb} in a separate directory, run @file{configure}
27737 with the @samp{--srcdir} option to specify where to find the source.
27738 (You also need to specify a path to find @file{configure}
27739 itself from your working directory. If the path to @file{configure}
27740 would be the same as the argument to @samp{--srcdir}, you can leave out
27741 the @samp{--srcdir} option; it is assumed.)
27742
27743 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
27744 separate directory for a Sun 4 like this:
27745
27746 @smallexample
27747 @group
27748 cd gdb-@value{GDBVN}
27749 mkdir ../gdb-sun4
27750 cd ../gdb-sun4
27751 ../gdb-@value{GDBVN}/configure sun4
27752 make
27753 @end group
27754 @end smallexample
27755
27756 When @file{configure} builds a configuration using a remote source
27757 directory, it creates a tree for the binaries with the same structure
27758 (and using the same names) as the tree under the source directory. In
27759 the example, you'd find the Sun 4 library @file{libiberty.a} in the
27760 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
27761 @file{gdb-sun4/gdb}.
27762
27763 Make sure that your path to the @file{configure} script has just one
27764 instance of @file{gdb} in it. If your path to @file{configure} looks
27765 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
27766 one subdirectory of @value{GDBN}, not the whole package. This leads to
27767 build errors about missing include files such as @file{bfd/bfd.h}.
27768
27769 One popular reason to build several @value{GDBN} configurations in separate
27770 directories is to configure @value{GDBN} for cross-compiling (where
27771 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
27772 programs that run on another machine---the @dfn{target}).
27773 You specify a cross-debugging target by
27774 giving the @samp{--target=@var{target}} option to @file{configure}.
27775
27776 When you run @code{make} to build a program or library, you must run
27777 it in a configured directory---whatever directory you were in when you
27778 called @file{configure} (or one of its subdirectories).
27779
27780 The @code{Makefile} that @file{configure} generates in each source
27781 directory also runs recursively. If you type @code{make} in a source
27782 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
27783 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
27784 will build all the required libraries, and then build GDB.
27785
27786 When you have multiple hosts or targets configured in separate
27787 directories, you can run @code{make} on them in parallel (for example,
27788 if they are NFS-mounted on each of the hosts); they will not interfere
27789 with each other.
27790
27791 @node Config Names
27792 @section Specifying Names for Hosts and Targets
27793
27794 The specifications used for hosts and targets in the @file{configure}
27795 script are based on a three-part naming scheme, but some short predefined
27796 aliases are also supported. The full naming scheme encodes three pieces
27797 of information in the following pattern:
27798
27799 @smallexample
27800 @var{architecture}-@var{vendor}-@var{os}
27801 @end smallexample
27802
27803 For example, you can use the alias @code{sun4} as a @var{host} argument,
27804 or as the value for @var{target} in a @code{--target=@var{target}}
27805 option. The equivalent full name is @samp{sparc-sun-sunos4}.
27806
27807 The @file{configure} script accompanying @value{GDBN} does not provide
27808 any query facility to list all supported host and target names or
27809 aliases. @file{configure} calls the Bourne shell script
27810 @code{config.sub} to map abbreviations to full names; you can read the
27811 script, if you wish, or you can use it to test your guesses on
27812 abbreviations---for example:
27813
27814 @smallexample
27815 % sh config.sub i386-linux
27816 i386-pc-linux-gnu
27817 % sh config.sub alpha-linux
27818 alpha-unknown-linux-gnu
27819 % sh config.sub hp9k700
27820 hppa1.1-hp-hpux
27821 % sh config.sub sun4
27822 sparc-sun-sunos4.1.1
27823 % sh config.sub sun3
27824 m68k-sun-sunos4.1.1
27825 % sh config.sub i986v
27826 Invalid configuration `i986v': machine `i986v' not recognized
27827 @end smallexample
27828
27829 @noindent
27830 @code{config.sub} is also distributed in the @value{GDBN} source
27831 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
27832
27833 @node Configure Options
27834 @section @file{configure} Options
27835
27836 Here is a summary of the @file{configure} options and arguments that
27837 are most often useful for building @value{GDBN}. @file{configure} also has
27838 several other options not listed here. @inforef{What Configure
27839 Does,,configure.info}, for a full explanation of @file{configure}.
27840
27841 @smallexample
27842 configure @r{[}--help@r{]}
27843 @r{[}--prefix=@var{dir}@r{]}
27844 @r{[}--exec-prefix=@var{dir}@r{]}
27845 @r{[}--srcdir=@var{dirname}@r{]}
27846 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
27847 @r{[}--target=@var{target}@r{]}
27848 @var{host}
27849 @end smallexample
27850
27851 @noindent
27852 You may introduce options with a single @samp{-} rather than
27853 @samp{--} if you prefer; but you may abbreviate option names if you use
27854 @samp{--}.
27855
27856 @table @code
27857 @item --help
27858 Display a quick summary of how to invoke @file{configure}.
27859
27860 @item --prefix=@var{dir}
27861 Configure the source to install programs and files under directory
27862 @file{@var{dir}}.
27863
27864 @item --exec-prefix=@var{dir}
27865 Configure the source to install programs under directory
27866 @file{@var{dir}}.
27867
27868 @c avoid splitting the warning from the explanation:
27869 @need 2000
27870 @item --srcdir=@var{dirname}
27871 @strong{Warning: using this option requires @sc{gnu} @code{make}, or another
27872 @code{make} that implements the @code{VPATH} feature.}@*
27873 Use this option to make configurations in directories separate from the
27874 @value{GDBN} source directories. Among other things, you can use this to
27875 build (or maintain) several configurations simultaneously, in separate
27876 directories. @file{configure} writes configuration-specific files in
27877 the current directory, but arranges for them to use the source in the
27878 directory @var{dirname}. @file{configure} creates directories under
27879 the working directory in parallel to the source directories below
27880 @var{dirname}.
27881
27882 @item --norecursion
27883 Configure only the directory level where @file{configure} is executed; do not
27884 propagate configuration to subdirectories.
27885
27886 @item --target=@var{target}
27887 Configure @value{GDBN} for cross-debugging programs running on the specified
27888 @var{target}. Without this option, @value{GDBN} is configured to debug
27889 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
27890
27891 There is no convenient way to generate a list of all available targets.
27892
27893 @item @var{host} @dots{}
27894 Configure @value{GDBN} to run on the specified @var{host}.
27895
27896 There is no convenient way to generate a list of all available hosts.
27897 @end table
27898
27899 There are many other options available as well, but they are generally
27900 needed for special purposes only.
27901
27902 @node System-wide configuration
27903 @section System-wide configuration and settings
27904 @cindex system-wide init file
27905
27906 @value{GDBN} can be configured to have a system-wide init file;
27907 this file will be read and executed at startup (@pxref{Startup, , What
27908 @value{GDBN} does during startup}).
27909
27910 Here is the corresponding configure option:
27911
27912 @table @code
27913 @item --with-system-gdbinit=@var{file}
27914 Specify that the default location of the system-wide init file is
27915 @var{file}.
27916 @end table
27917
27918 If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
27919 it may be subject to relocation. Two possible cases:
27920
27921 @itemize @bullet
27922 @item
27923 If the default location of this init file contains @file{$prefix},
27924 it will be subject to relocation. Suppose that the configure options
27925 are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
27926 if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
27927 init file is looked for as @file{$install/etc/gdbinit} instead of
27928 @file{$prefix/etc/gdbinit}.
27929
27930 @item
27931 By contrast, if the default location does not contain the prefix,
27932 it will not be relocated. E.g.@: if @value{GDBN} has been configured with
27933 @option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
27934 then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
27935 wherever @value{GDBN} is installed.
27936 @end itemize
27937
27938 @node Maintenance Commands
27939 @appendix Maintenance Commands
27940 @cindex maintenance commands
27941 @cindex internal commands
27942
27943 In addition to commands intended for @value{GDBN} users, @value{GDBN}
27944 includes a number of commands intended for @value{GDBN} developers,
27945 that are not documented elsewhere in this manual. These commands are
27946 provided here for reference. (For commands that turn on debugging
27947 messages, see @ref{Debugging Output}.)
27948
27949 @table @code
27950 @kindex maint agent
27951 @kindex maint agent-eval
27952 @item maint agent @var{expression}
27953 @itemx maint agent-eval @var{expression}
27954 Translate the given @var{expression} into remote agent bytecodes.
27955 This command is useful for debugging the Agent Expression mechanism
27956 (@pxref{Agent Expressions}). The @samp{agent} version produces an
27957 expression useful for data collection, such as by tracepoints, while
27958 @samp{maint agent-eval} produces an expression that evaluates directly
27959 to a result. For instance, a collection expression for @code{globa +
27960 globb} will include bytecodes to record four bytes of memory at each
27961 of the addresses of @code{globa} and @code{globb}, while discarding
27962 the result of the addition, while an evaluation expression will do the
27963 addition and return the sum.
27964
27965 @kindex maint info breakpoints
27966 @item @anchor{maint info breakpoints}maint info breakpoints
27967 Using the same format as @samp{info breakpoints}, display both the
27968 breakpoints you've set explicitly, and those @value{GDBN} is using for
27969 internal purposes. Internal breakpoints are shown with negative
27970 breakpoint numbers. The type column identifies what kind of breakpoint
27971 is shown:
27972
27973 @table @code
27974 @item breakpoint
27975 Normal, explicitly set breakpoint.
27976
27977 @item watchpoint
27978 Normal, explicitly set watchpoint.
27979
27980 @item longjmp
27981 Internal breakpoint, used to handle correctly stepping through
27982 @code{longjmp} calls.
27983
27984 @item longjmp resume
27985 Internal breakpoint at the target of a @code{longjmp}.
27986
27987 @item until
27988 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
27989
27990 @item finish
27991 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
27992
27993 @item shlib events
27994 Shared library events.
27995
27996 @end table
27997
27998 @kindex set displaced-stepping
27999 @kindex show displaced-stepping
28000 @cindex displaced stepping support
28001 @cindex out-of-line single-stepping
28002 @item set displaced-stepping
28003 @itemx show displaced-stepping
28004 Control whether or not @value{GDBN} will do @dfn{displaced stepping}
28005 if the target supports it. Displaced stepping is a way to single-step
28006 over breakpoints without removing them from the inferior, by executing
28007 an out-of-line copy of the instruction that was originally at the
28008 breakpoint location. It is also known as out-of-line single-stepping.
28009
28010 @table @code
28011 @item set displaced-stepping on
28012 If the target architecture supports it, @value{GDBN} will use
28013 displaced stepping to step over breakpoints.
28014
28015 @item set displaced-stepping off
28016 @value{GDBN} will not use displaced stepping to step over breakpoints,
28017 even if such is supported by the target architecture.
28018
28019 @cindex non-stop mode, and @samp{set displaced-stepping}
28020 @item set displaced-stepping auto
28021 This is the default mode. @value{GDBN} will use displaced stepping
28022 only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
28023 architecture supports displaced stepping.
28024 @end table
28025
28026 @kindex maint check-symtabs
28027 @item maint check-symtabs
28028 Check the consistency of psymtabs and symtabs.
28029
28030 @kindex maint cplus first_component
28031 @item maint cplus first_component @var{name}
28032 Print the first C@t{++} class/namespace component of @var{name}.
28033
28034 @kindex maint cplus namespace
28035 @item maint cplus namespace
28036 Print the list of possible C@t{++} namespaces.
28037
28038 @kindex maint demangle
28039 @item maint demangle @var{name}
28040 Demangle a C@t{++} or Objective-C mangled @var{name}.
28041
28042 @kindex maint deprecate
28043 @kindex maint undeprecate
28044 @cindex deprecated commands
28045 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
28046 @itemx maint undeprecate @var{command}
28047 Deprecate or undeprecate the named @var{command}. Deprecated commands
28048 cause @value{GDBN} to issue a warning when you use them. The optional
28049 argument @var{replacement} says which newer command should be used in
28050 favor of the deprecated one; if it is given, @value{GDBN} will mention
28051 the replacement as part of the warning.
28052
28053 @kindex maint dump-me
28054 @item maint dump-me
28055 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
28056 Cause a fatal signal in the debugger and force it to dump its core.
28057 This is supported only on systems which support aborting a program
28058 with the @code{SIGQUIT} signal.
28059
28060 @kindex maint internal-error
28061 @kindex maint internal-warning
28062 @item maint internal-error @r{[}@var{message-text}@r{]}
28063 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
28064 Cause @value{GDBN} to call the internal function @code{internal_error}
28065 or @code{internal_warning} and hence behave as though an internal error
28066 or internal warning has been detected. In addition to reporting the
28067 internal problem, these functions give the user the opportunity to
28068 either quit @value{GDBN} or create a core file of the current
28069 @value{GDBN} session.
28070
28071 These commands take an optional parameter @var{message-text} that is
28072 used as the text of the error or warning message.
28073
28074 Here's an example of using @code{internal-error}:
28075
28076 @smallexample
28077 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
28078 @dots{}/maint.c:121: internal-error: testing, 1, 2
28079 A problem internal to GDB has been detected. Further
28080 debugging may prove unreliable.
28081 Quit this debugging session? (y or n) @kbd{n}
28082 Create a core file? (y or n) @kbd{n}
28083 (@value{GDBP})
28084 @end smallexample
28085
28086 @cindex @value{GDBN} internal error
28087 @cindex internal errors, control of @value{GDBN} behavior
28088
28089 @kindex maint set internal-error
28090 @kindex maint show internal-error
28091 @kindex maint set internal-warning
28092 @kindex maint show internal-warning
28093 @item maint set internal-error @var{action} [ask|yes|no]
28094 @itemx maint show internal-error @var{action}
28095 @itemx maint set internal-warning @var{action} [ask|yes|no]
28096 @itemx maint show internal-warning @var{action}
28097 When @value{GDBN} reports an internal problem (error or warning) it
28098 gives the user the opportunity to both quit @value{GDBN} and create a
28099 core file of the current @value{GDBN} session. These commands let you
28100 override the default behaviour for each particular @var{action},
28101 described in the table below.
28102
28103 @table @samp
28104 @item quit
28105 You can specify that @value{GDBN} should always (yes) or never (no)
28106 quit. The default is to ask the user what to do.
28107
28108 @item corefile
28109 You can specify that @value{GDBN} should always (yes) or never (no)
28110 create a core file. The default is to ask the user what to do.
28111 @end table
28112
28113 @kindex maint packet
28114 @item maint packet @var{text}
28115 If @value{GDBN} is talking to an inferior via the serial protocol,
28116 then this command sends the string @var{text} to the inferior, and
28117 displays the response packet. @value{GDBN} supplies the initial
28118 @samp{$} character, the terminating @samp{#} character, and the
28119 checksum.
28120
28121 @kindex maint print architecture
28122 @item maint print architecture @r{[}@var{file}@r{]}
28123 Print the entire architecture configuration. The optional argument
28124 @var{file} names the file where the output goes.
28125
28126 @kindex maint print c-tdesc
28127 @item maint print c-tdesc
28128 Print the current target description (@pxref{Target Descriptions}) as
28129 a C source file. The created source file can be used in @value{GDBN}
28130 when an XML parser is not available to parse the description.
28131
28132 @kindex maint print dummy-frames
28133 @item maint print dummy-frames
28134 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
28135
28136 @smallexample
28137 (@value{GDBP}) @kbd{b add}
28138 @dots{}
28139 (@value{GDBP}) @kbd{print add(2,3)}
28140 Breakpoint 2, add (a=2, b=3) at @dots{}
28141 58 return (a + b);
28142 The program being debugged stopped while in a function called from GDB.
28143 @dots{}
28144 (@value{GDBP}) @kbd{maint print dummy-frames}
28145 0x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
28146 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
28147 call_lo=0x01014000 call_hi=0x01014001
28148 (@value{GDBP})
28149 @end smallexample
28150
28151 Takes an optional file parameter.
28152
28153 @kindex maint print registers
28154 @kindex maint print raw-registers
28155 @kindex maint print cooked-registers
28156 @kindex maint print register-groups
28157 @item maint print registers @r{[}@var{file}@r{]}
28158 @itemx maint print raw-registers @r{[}@var{file}@r{]}
28159 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
28160 @itemx maint print register-groups @r{[}@var{file}@r{]}
28161 Print @value{GDBN}'s internal register data structures.
28162
28163 The command @code{maint print raw-registers} includes the contents of
28164 the raw register cache; the command @code{maint print cooked-registers}
28165 includes the (cooked) value of all registers; and the command
28166 @code{maint print register-groups} includes the groups that each
28167 register is a member of. @xref{Registers,, Registers, gdbint,
28168 @value{GDBN} Internals}.
28169
28170 These commands take an optional parameter, a file name to which to
28171 write the information.
28172
28173 @kindex maint print reggroups
28174 @item maint print reggroups @r{[}@var{file}@r{]}
28175 Print @value{GDBN}'s internal register group data structures. The
28176 optional argument @var{file} tells to what file to write the
28177 information.
28178
28179 The register groups info looks like this:
28180
28181 @smallexample
28182 (@value{GDBP}) @kbd{maint print reggroups}
28183 Group Type
28184 general user
28185 float user
28186 all user
28187 vector user
28188 system user
28189 save internal
28190 restore internal
28191 @end smallexample
28192
28193 @kindex flushregs
28194 @item flushregs
28195 This command forces @value{GDBN} to flush its internal register cache.
28196
28197 @kindex maint print objfiles
28198 @cindex info for known object files
28199 @item maint print objfiles
28200 Print a dump of all known object files. For each object file, this
28201 command prints its name, address in memory, and all of its psymtabs
28202 and symtabs.
28203
28204 @kindex maint print statistics
28205 @cindex bcache statistics
28206 @item maint print statistics
28207 This command prints, for each object file in the program, various data
28208 about that object file followed by the byte cache (@dfn{bcache})
28209 statistics for the object file. The objfile data includes the number
28210 of minimal, partial, full, and stabs symbols, the number of types
28211 defined by the objfile, the number of as yet unexpanded psym tables,
28212 the number of line tables and string tables, and the amount of memory
28213 used by the various tables. The bcache statistics include the counts,
28214 sizes, and counts of duplicates of all and unique objects, max,
28215 average, and median entry size, total memory used and its overhead and
28216 savings, and various measures of the hash table size and chain
28217 lengths.
28218
28219 @kindex maint print target-stack
28220 @cindex target stack description
28221 @item maint print target-stack
28222 A @dfn{target} is an interface between the debugger and a particular
28223 kind of file or process. Targets can be stacked in @dfn{strata},
28224 so that more than one target can potentially respond to a request.
28225 In particular, memory accesses will walk down the stack of targets
28226 until they find a target that is interested in handling that particular
28227 address.
28228
28229 This command prints a short description of each layer that was pushed on
28230 the @dfn{target stack}, starting from the top layer down to the bottom one.
28231
28232 @kindex maint print type
28233 @cindex type chain of a data type
28234 @item maint print type @var{expr}
28235 Print the type chain for a type specified by @var{expr}. The argument
28236 can be either a type name or a symbol. If it is a symbol, the type of
28237 that symbol is described. The type chain produced by this command is
28238 a recursive definition of the data type as stored in @value{GDBN}'s
28239 data structures, including its flags and contained types.
28240
28241 @kindex maint set dwarf2 max-cache-age
28242 @kindex maint show dwarf2 max-cache-age
28243 @item maint set dwarf2 max-cache-age
28244 @itemx maint show dwarf2 max-cache-age
28245 Control the DWARF 2 compilation unit cache.
28246
28247 @cindex DWARF 2 compilation units cache
28248 In object files with inter-compilation-unit references, such as those
28249 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
28250 reader needs to frequently refer to previously read compilation units.
28251 This setting controls how long a compilation unit will remain in the
28252 cache if it is not referenced. A higher limit means that cached
28253 compilation units will be stored in memory longer, and more total
28254 memory will be used. Setting it to zero disables caching, which will
28255 slow down @value{GDBN} startup, but reduce memory consumption.
28256
28257 @kindex maint set profile
28258 @kindex maint show profile
28259 @cindex profiling GDB
28260 @item maint set profile
28261 @itemx maint show profile
28262 Control profiling of @value{GDBN}.
28263
28264 Profiling will be disabled until you use the @samp{maint set profile}
28265 command to enable it. When you enable profiling, the system will begin
28266 collecting timing and execution count data; when you disable profiling or
28267 exit @value{GDBN}, the results will be written to a log file. Remember that
28268 if you use profiling, @value{GDBN} will overwrite the profiling log file
28269 (often called @file{gmon.out}). If you have a record of important profiling
28270 data in a @file{gmon.out} file, be sure to move it to a safe location.
28271
28272 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
28273 compiled with the @samp{-pg} compiler option.
28274
28275 @kindex maint set show-debug-regs
28276 @kindex maint show show-debug-regs
28277 @cindex hardware debug registers
28278 @item maint set show-debug-regs
28279 @itemx maint show show-debug-regs
28280 Control whether to show variables that mirror the hardware debug
28281 registers. Use @code{ON} to enable, @code{OFF} to disable. If
28282 enabled, the debug registers values are shown when @value{GDBN} inserts or
28283 removes a hardware breakpoint or watchpoint, and when the inferior
28284 triggers a hardware-assisted breakpoint or watchpoint.
28285
28286 @kindex maint space
28287 @cindex memory used by commands
28288 @item maint space
28289 Control whether to display memory usage for each command. If set to a
28290 nonzero value, @value{GDBN} will display how much memory each command
28291 took, following the command's own output. This can also be requested
28292 by invoking @value{GDBN} with the @option{--statistics} command-line
28293 switch (@pxref{Mode Options}).
28294
28295 @kindex maint time
28296 @cindex time of command execution
28297 @item maint time
28298 Control whether to display the execution time for each command. If
28299 set to a nonzero value, @value{GDBN} will display how much time it
28300 took to execute each command, following the command's own output.
28301 The time is not printed for the commands that run the target, since
28302 there's no mechanism currently to compute how much time was spend
28303 by @value{GDBN} and how much time was spend by the program been debugged.
28304 it's not possibly currently
28305 This can also be requested by invoking @value{GDBN} with the
28306 @option{--statistics} command-line switch (@pxref{Mode Options}).
28307
28308 @kindex maint translate-address
28309 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
28310 Find the symbol stored at the location specified by the address
28311 @var{addr} and an optional section name @var{section}. If found,
28312 @value{GDBN} prints the name of the closest symbol and an offset from
28313 the symbol's location to the specified address. This is similar to
28314 the @code{info address} command (@pxref{Symbols}), except that this
28315 command also allows to find symbols in other sections.
28316
28317 If section was not specified, the section in which the symbol was found
28318 is also printed. For dynamically linked executables, the name of
28319 executable or shared library containing the symbol is printed as well.
28320
28321 @end table
28322
28323 The following command is useful for non-interactive invocations of
28324 @value{GDBN}, such as in the test suite.
28325
28326 @table @code
28327 @item set watchdog @var{nsec}
28328 @kindex set watchdog
28329 @cindex watchdog timer
28330 @cindex timeout for commands
28331 Set the maximum number of seconds @value{GDBN} will wait for the
28332 target operation to finish. If this time expires, @value{GDBN}
28333 reports and error and the command is aborted.
28334
28335 @item show watchdog
28336 Show the current setting of the target wait timeout.
28337 @end table
28338
28339 @node Remote Protocol
28340 @appendix @value{GDBN} Remote Serial Protocol
28341
28342 @menu
28343 * Overview::
28344 * Packets::
28345 * Stop Reply Packets::
28346 * General Query Packets::
28347 * Register Packet Format::
28348 * Tracepoint Packets::
28349 * Host I/O Packets::
28350 * Interrupts::
28351 * Notification Packets::
28352 * Remote Non-Stop::
28353 * Packet Acknowledgment::
28354 * Examples::
28355 * File-I/O Remote Protocol Extension::
28356 * Library List Format::
28357 * Memory Map Format::
28358 * Thread List Format::
28359 @end menu
28360
28361 @node Overview
28362 @section Overview
28363
28364 There may be occasions when you need to know something about the
28365 protocol---for example, if there is only one serial port to your target
28366 machine, you might want your program to do something special if it
28367 recognizes a packet meant for @value{GDBN}.
28368
28369 In the examples below, @samp{->} and @samp{<-} are used to indicate
28370 transmitted and received data, respectively.
28371
28372 @cindex protocol, @value{GDBN} remote serial
28373 @cindex serial protocol, @value{GDBN} remote
28374 @cindex remote serial protocol
28375 All @value{GDBN} commands and responses (other than acknowledgments
28376 and notifications, see @ref{Notification Packets}) are sent as a
28377 @var{packet}. A @var{packet} is introduced with the character
28378 @samp{$}, the actual @var{packet-data}, and the terminating character
28379 @samp{#} followed by a two-digit @var{checksum}:
28380
28381 @smallexample
28382 @code{$}@var{packet-data}@code{#}@var{checksum}
28383 @end smallexample
28384 @noindent
28385
28386 @cindex checksum, for @value{GDBN} remote
28387 @noindent
28388 The two-digit @var{checksum} is computed as the modulo 256 sum of all
28389 characters between the leading @samp{$} and the trailing @samp{#} (an
28390 eight bit unsigned checksum).
28391
28392 Implementors should note that prior to @value{GDBN} 5.0 the protocol
28393 specification also included an optional two-digit @var{sequence-id}:
28394
28395 @smallexample
28396 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
28397 @end smallexample
28398
28399 @cindex sequence-id, for @value{GDBN} remote
28400 @noindent
28401 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
28402 has never output @var{sequence-id}s. Stubs that handle packets added
28403 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
28404
28405 When either the host or the target machine receives a packet, the first
28406 response expected is an acknowledgment: either @samp{+} (to indicate
28407 the package was received correctly) or @samp{-} (to request
28408 retransmission):
28409
28410 @smallexample
28411 -> @code{$}@var{packet-data}@code{#}@var{checksum}
28412 <- @code{+}
28413 @end smallexample
28414 @noindent
28415
28416 The @samp{+}/@samp{-} acknowledgments can be disabled
28417 once a connection is established.
28418 @xref{Packet Acknowledgment}, for details.
28419
28420 The host (@value{GDBN}) sends @var{command}s, and the target (the
28421 debugging stub incorporated in your program) sends a @var{response}. In
28422 the case of step and continue @var{command}s, the response is only sent
28423 when the operation has completed, and the target has again stopped all
28424 threads in all attached processes. This is the default all-stop mode
28425 behavior, but the remote protocol also supports @value{GDBN}'s non-stop
28426 execution mode; see @ref{Remote Non-Stop}, for details.
28427
28428 @var{packet-data} consists of a sequence of characters with the
28429 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
28430 exceptions).
28431
28432 @cindex remote protocol, field separator
28433 Fields within the packet should be separated using @samp{,} @samp{;} or
28434 @samp{:}. Except where otherwise noted all numbers are represented in
28435 @sc{hex} with leading zeros suppressed.
28436
28437 Implementors should note that prior to @value{GDBN} 5.0, the character
28438 @samp{:} could not appear as the third character in a packet (as it
28439 would potentially conflict with the @var{sequence-id}).
28440
28441 @cindex remote protocol, binary data
28442 @anchor{Binary Data}
28443 Binary data in most packets is encoded either as two hexadecimal
28444 digits per byte of binary data. This allowed the traditional remote
28445 protocol to work over connections which were only seven-bit clean.
28446 Some packets designed more recently assume an eight-bit clean
28447 connection, and use a more efficient encoding to send and receive
28448 binary data.
28449
28450 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
28451 as an escape character. Any escaped byte is transmitted as the escape
28452 character followed by the original character XORed with @code{0x20}.
28453 For example, the byte @code{0x7d} would be transmitted as the two
28454 bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
28455 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
28456 @samp{@}}) must always be escaped. Responses sent by the stub
28457 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
28458 is not interpreted as the start of a run-length encoded sequence
28459 (described next).
28460
28461 Response @var{data} can be run-length encoded to save space.
28462 Run-length encoding replaces runs of identical characters with one
28463 instance of the repeated character, followed by a @samp{*} and a
28464 repeat count. The repeat count is itself sent encoded, to avoid
28465 binary characters in @var{data}: a value of @var{n} is sent as
28466 @code{@var{n}+29}. For a repeat count greater or equal to 3, this
28467 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
28468 code 32) for a repeat count of 3. (This is because run-length
28469 encoding starts to win for counts 3 or more.) Thus, for example,
28470 @samp{0* } is a run-length encoding of ``0000'': the space character
28471 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
28472 3}} more times.
28473
28474 The printable characters @samp{#} and @samp{$} or with a numeric value
28475 greater than 126 must not be used. Runs of six repeats (@samp{#}) or
28476 seven repeats (@samp{$}) can be expanded using a repeat count of only
28477 five (@samp{"}). For example, @samp{00000000} can be encoded as
28478 @samp{0*"00}.
28479
28480 The error response returned for some packets includes a two character
28481 error number. That number is not well defined.
28482
28483 @cindex empty response, for unsupported packets
28484 For any @var{command} not supported by the stub, an empty response
28485 (@samp{$#00}) should be returned. That way it is possible to extend the
28486 protocol. A newer @value{GDBN} can tell if a packet is supported based
28487 on that response.
28488
28489 A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
28490 @samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
28491 optional.
28492
28493 @node Packets
28494 @section Packets
28495
28496 The following table provides a complete list of all currently defined
28497 @var{command}s and their corresponding response @var{data}.
28498 @xref{File-I/O Remote Protocol Extension}, for details about the File
28499 I/O extension of the remote protocol.
28500
28501 Each packet's description has a template showing the packet's overall
28502 syntax, followed by an explanation of the packet's meaning. We
28503 include spaces in some of the templates for clarity; these are not
28504 part of the packet's syntax. No @value{GDBN} packet uses spaces to
28505 separate its components. For example, a template like @samp{foo
28506 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
28507 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
28508 @var{baz}. @value{GDBN} does not transmit a space character between the
28509 @samp{foo} and the @var{bar}, or between the @var{bar} and the
28510 @var{baz}.
28511
28512 @cindex @var{thread-id}, in remote protocol
28513 @anchor{thread-id syntax}
28514 Several packets and replies include a @var{thread-id} field to identify
28515 a thread. Normally these are positive numbers with a target-specific
28516 interpretation, formatted as big-endian hex strings. A @var{thread-id}
28517 can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
28518 pick any thread.
28519
28520 In addition, the remote protocol supports a multiprocess feature in
28521 which the @var{thread-id} syntax is extended to optionally include both
28522 process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
28523 The @var{pid} (process) and @var{tid} (thread) components each have the
28524 format described above: a positive number with target-specific
28525 interpretation formatted as a big-endian hex string, literal @samp{-1}
28526 to indicate all processes or threads (respectively), or @samp{0} to
28527 indicate an arbitrary process or thread. Specifying just a process, as
28528 @samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
28529 error to specify all processes but a specific thread, such as
28530 @samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
28531 for those packets and replies explicitly documented to include a process
28532 ID, rather than a @var{thread-id}.
28533
28534 The multiprocess @var{thread-id} syntax extensions are only used if both
28535 @value{GDBN} and the stub report support for the @samp{multiprocess}
28536 feature using @samp{qSupported}. @xref{multiprocess extensions}, for
28537 more information.
28538
28539 Note that all packet forms beginning with an upper- or lower-case
28540 letter, other than those described here, are reserved for future use.
28541
28542 Here are the packet descriptions.
28543
28544 @table @samp
28545
28546 @item !
28547 @cindex @samp{!} packet
28548 @anchor{extended mode}
28549 Enable extended mode. In extended mode, the remote server is made
28550 persistent. The @samp{R} packet is used to restart the program being
28551 debugged.
28552
28553 Reply:
28554 @table @samp
28555 @item OK
28556 The remote target both supports and has enabled extended mode.
28557 @end table
28558
28559 @item ?
28560 @cindex @samp{?} packet
28561 Indicate the reason the target halted. The reply is the same as for
28562 step and continue. This packet has a special interpretation when the
28563 target is in non-stop mode; see @ref{Remote Non-Stop}.
28564
28565 Reply:
28566 @xref{Stop Reply Packets}, for the reply specifications.
28567
28568 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
28569 @cindex @samp{A} packet
28570 Initialized @code{argv[]} array passed into program. @var{arglen}
28571 specifies the number of bytes in the hex encoded byte stream
28572 @var{arg}. See @code{gdbserver} for more details.
28573
28574 Reply:
28575 @table @samp
28576 @item OK
28577 The arguments were set.
28578 @item E @var{NN}
28579 An error occurred.
28580 @end table
28581
28582 @item b @var{baud}
28583 @cindex @samp{b} packet
28584 (Don't use this packet; its behavior is not well-defined.)
28585 Change the serial line speed to @var{baud}.
28586
28587 JTC: @emph{When does the transport layer state change? When it's
28588 received, or after the ACK is transmitted. In either case, there are
28589 problems if the command or the acknowledgment packet is dropped.}
28590
28591 Stan: @emph{If people really wanted to add something like this, and get
28592 it working for the first time, they ought to modify ser-unix.c to send
28593 some kind of out-of-band message to a specially-setup stub and have the
28594 switch happen "in between" packets, so that from remote protocol's point
28595 of view, nothing actually happened.}
28596
28597 @item B @var{addr},@var{mode}
28598 @cindex @samp{B} packet
28599 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
28600 breakpoint at @var{addr}.
28601
28602 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
28603 (@pxref{insert breakpoint or watchpoint packet}).
28604
28605 @cindex @samp{bc} packet
28606 @anchor{bc}
28607 @item bc
28608 Backward continue. Execute the target system in reverse. No parameter.
28609 @xref{Reverse Execution}, for more information.
28610
28611 Reply:
28612 @xref{Stop Reply Packets}, for the reply specifications.
28613
28614 @cindex @samp{bs} packet
28615 @anchor{bs}
28616 @item bs
28617 Backward single step. Execute one instruction in reverse. No parameter.
28618 @xref{Reverse Execution}, for more information.
28619
28620 Reply:
28621 @xref{Stop Reply Packets}, for the reply specifications.
28622
28623 @item c @r{[}@var{addr}@r{]}
28624 @cindex @samp{c} packet
28625 Continue. @var{addr} is address to resume. If @var{addr} is omitted,
28626 resume at current address.
28627
28628 Reply:
28629 @xref{Stop Reply Packets}, for the reply specifications.
28630
28631 @item C @var{sig}@r{[};@var{addr}@r{]}
28632 @cindex @samp{C} packet
28633 Continue with signal @var{sig} (hex signal number). If
28634 @samp{;@var{addr}} is omitted, resume at same address.
28635
28636 Reply:
28637 @xref{Stop Reply Packets}, for the reply specifications.
28638
28639 @item d
28640 @cindex @samp{d} packet
28641 Toggle debug flag.
28642
28643 Don't use this packet; instead, define a general set packet
28644 (@pxref{General Query Packets}).
28645
28646 @item D
28647 @itemx D;@var{pid}
28648 @cindex @samp{D} packet
28649 The first form of the packet is used to detach @value{GDBN} from the
28650 remote system. It is sent to the remote target
28651 before @value{GDBN} disconnects via the @code{detach} command.
28652
28653 The second form, including a process ID, is used when multiprocess
28654 protocol extensions are enabled (@pxref{multiprocess extensions}), to
28655 detach only a specific process. The @var{pid} is specified as a
28656 big-endian hex string.
28657
28658 Reply:
28659 @table @samp
28660 @item OK
28661 for success
28662 @item E @var{NN}
28663 for an error
28664 @end table
28665
28666 @item F @var{RC},@var{EE},@var{CF};@var{XX}
28667 @cindex @samp{F} packet
28668 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
28669 This is part of the File-I/O protocol extension. @xref{File-I/O
28670 Remote Protocol Extension}, for the specification.
28671
28672 @item g
28673 @anchor{read registers packet}
28674 @cindex @samp{g} packet
28675 Read general registers.
28676
28677 Reply:
28678 @table @samp
28679 @item @var{XX@dots{}}
28680 Each byte of register data is described by two hex digits. The bytes
28681 with the register are transmitted in target byte order. The size of
28682 each register and their position within the @samp{g} packet are
28683 determined by the @value{GDBN} internal gdbarch functions
28684 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}. The
28685 specification of several standard @samp{g} packets is specified below.
28686 @item E @var{NN}
28687 for an error.
28688 @end table
28689
28690 @item G @var{XX@dots{}}
28691 @cindex @samp{G} packet
28692 Write general registers. @xref{read registers packet}, for a
28693 description of the @var{XX@dots{}} data.
28694
28695 Reply:
28696 @table @samp
28697 @item OK
28698 for success
28699 @item E @var{NN}
28700 for an error
28701 @end table
28702
28703 @item H @var{c} @var{thread-id}
28704 @cindex @samp{H} packet
28705 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
28706 @samp{G}, et.al.). @var{c} depends on the operation to be performed: it
28707 should be @samp{c} for step and continue operations, @samp{g} for other
28708 operations. The thread designator @var{thread-id} has the format and
28709 interpretation described in @ref{thread-id syntax}.
28710
28711 Reply:
28712 @table @samp
28713 @item OK
28714 for success
28715 @item E @var{NN}
28716 for an error
28717 @end table
28718
28719 @c FIXME: JTC:
28720 @c 'H': How restrictive (or permissive) is the thread model. If a
28721 @c thread is selected and stopped, are other threads allowed
28722 @c to continue to execute? As I mentioned above, I think the
28723 @c semantics of each command when a thread is selected must be
28724 @c described. For example:
28725 @c
28726 @c 'g': If the stub supports threads and a specific thread is
28727 @c selected, returns the register block from that thread;
28728 @c otherwise returns current registers.
28729 @c
28730 @c 'G' If the stub supports threads and a specific thread is
28731 @c selected, sets the registers of the register block of
28732 @c that thread; otherwise sets current registers.
28733
28734 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
28735 @anchor{cycle step packet}
28736 @cindex @samp{i} packet
28737 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
28738 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
28739 step starting at that address.
28740
28741 @item I
28742 @cindex @samp{I} packet
28743 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
28744 step packet}.
28745
28746 @item k
28747 @cindex @samp{k} packet
28748 Kill request.
28749
28750 FIXME: @emph{There is no description of how to operate when a specific
28751 thread context has been selected (i.e.@: does 'k' kill only that
28752 thread?)}.
28753
28754 @item m @var{addr},@var{length}
28755 @cindex @samp{m} packet
28756 Read @var{length} bytes of memory starting at address @var{addr}.
28757 Note that @var{addr} may not be aligned to any particular boundary.
28758
28759 The stub need not use any particular size or alignment when gathering
28760 data from memory for the response; even if @var{addr} is word-aligned
28761 and @var{length} is a multiple of the word size, the stub is free to
28762 use byte accesses, or not. For this reason, this packet may not be
28763 suitable for accessing memory-mapped I/O devices.
28764 @cindex alignment of remote memory accesses
28765 @cindex size of remote memory accesses
28766 @cindex memory, alignment and size of remote accesses
28767
28768 Reply:
28769 @table @samp
28770 @item @var{XX@dots{}}
28771 Memory contents; each byte is transmitted as a two-digit hexadecimal
28772 number. The reply may contain fewer bytes than requested if the
28773 server was able to read only part of the region of memory.
28774 @item E @var{NN}
28775 @var{NN} is errno
28776 @end table
28777
28778 @item M @var{addr},@var{length}:@var{XX@dots{}}
28779 @cindex @samp{M} packet
28780 Write @var{length} bytes of memory starting at address @var{addr}.
28781 @var{XX@dots{}} is the data; each byte is transmitted as a two-digit
28782 hexadecimal number.
28783
28784 Reply:
28785 @table @samp
28786 @item OK
28787 for success
28788 @item E @var{NN}
28789 for an error (this includes the case where only part of the data was
28790 written).
28791 @end table
28792
28793 @item p @var{n}
28794 @cindex @samp{p} packet
28795 Read the value of register @var{n}; @var{n} is in hex.
28796 @xref{read registers packet}, for a description of how the returned
28797 register value is encoded.
28798
28799 Reply:
28800 @table @samp
28801 @item @var{XX@dots{}}
28802 the register's value
28803 @item E @var{NN}
28804 for an error
28805 @item
28806 Indicating an unrecognized @var{query}.
28807 @end table
28808
28809 @item P @var{n@dots{}}=@var{r@dots{}}
28810 @anchor{write register packet}
28811 @cindex @samp{P} packet
28812 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
28813 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
28814 digits for each byte in the register (target byte order).
28815
28816 Reply:
28817 @table @samp
28818 @item OK
28819 for success
28820 @item E @var{NN}
28821 for an error
28822 @end table
28823
28824 @item q @var{name} @var{params}@dots{}
28825 @itemx Q @var{name} @var{params}@dots{}
28826 @cindex @samp{q} packet
28827 @cindex @samp{Q} packet
28828 General query (@samp{q}) and set (@samp{Q}). These packets are
28829 described fully in @ref{General Query Packets}.
28830
28831 @item r
28832 @cindex @samp{r} packet
28833 Reset the entire system.
28834
28835 Don't use this packet; use the @samp{R} packet instead.
28836
28837 @item R @var{XX}
28838 @cindex @samp{R} packet
28839 Restart the program being debugged. @var{XX}, while needed, is ignored.
28840 This packet is only available in extended mode (@pxref{extended mode}).
28841
28842 The @samp{R} packet has no reply.
28843
28844 @item s @r{[}@var{addr}@r{]}
28845 @cindex @samp{s} packet
28846 Single step. @var{addr} is the address at which to resume. If
28847 @var{addr} is omitted, resume at same address.
28848
28849 Reply:
28850 @xref{Stop Reply Packets}, for the reply specifications.
28851
28852 @item S @var{sig}@r{[};@var{addr}@r{]}
28853 @anchor{step with signal packet}
28854 @cindex @samp{S} packet
28855 Step with signal. This is analogous to the @samp{C} packet, but
28856 requests a single-step, rather than a normal resumption of execution.
28857
28858 Reply:
28859 @xref{Stop Reply Packets}, for the reply specifications.
28860
28861 @item t @var{addr}:@var{PP},@var{MM}
28862 @cindex @samp{t} packet
28863 Search backwards starting at address @var{addr} for a match with pattern
28864 @var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
28865 @var{addr} must be at least 3 digits.
28866
28867 @item T @var{thread-id}
28868 @cindex @samp{T} packet
28869 Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
28870
28871 Reply:
28872 @table @samp
28873 @item OK
28874 thread is still alive
28875 @item E @var{NN}
28876 thread is dead
28877 @end table
28878
28879 @item v
28880 Packets starting with @samp{v} are identified by a multi-letter name,
28881 up to the first @samp{;} or @samp{?} (or the end of the packet).
28882
28883 @item vAttach;@var{pid}
28884 @cindex @samp{vAttach} packet
28885 Attach to a new process with the specified process ID @var{pid}.
28886 The process ID is a
28887 hexadecimal integer identifying the process. In all-stop mode, all
28888 threads in the attached process are stopped; in non-stop mode, it may be
28889 attached without being stopped if that is supported by the target.
28890
28891 @c In non-stop mode, on a successful vAttach, the stub should set the
28892 @c current thread to a thread of the newly-attached process. After
28893 @c attaching, GDB queries for the attached process's thread ID with qC.
28894 @c Also note that, from a user perspective, whether or not the
28895 @c target is stopped on attach in non-stop mode depends on whether you
28896 @c use the foreground or background version of the attach command, not
28897 @c on what vAttach does; GDB does the right thing with respect to either
28898 @c stopping or restarting threads.
28899
28900 This packet is only available in extended mode (@pxref{extended mode}).
28901
28902 Reply:
28903 @table @samp
28904 @item E @var{nn}
28905 for an error
28906 @item @r{Any stop packet}
28907 for success in all-stop mode (@pxref{Stop Reply Packets})
28908 @item OK
28909 for success in non-stop mode (@pxref{Remote Non-Stop})
28910 @end table
28911
28912 @item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
28913 @cindex @samp{vCont} packet
28914 Resume the inferior, specifying different actions for each thread.
28915 If an action is specified with no @var{thread-id}, then it is applied to any
28916 threads that don't have a specific action specified; if no default action is
28917 specified then other threads should remain stopped in all-stop mode and
28918 in their current state in non-stop mode.
28919 Specifying multiple
28920 default actions is an error; specifying no actions is also an error.
28921 Thread IDs are specified using the syntax described in @ref{thread-id syntax}.
28922
28923 Currently supported actions are:
28924
28925 @table @samp
28926 @item c
28927 Continue.
28928 @item C @var{sig}
28929 Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
28930 @item s
28931 Step.
28932 @item S @var{sig}
28933 Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
28934 @item t
28935 Stop.
28936 @end table
28937
28938 The optional argument @var{addr} normally associated with the
28939 @samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
28940 not supported in @samp{vCont}.
28941
28942 The @samp{t} action is only relevant in non-stop mode
28943 (@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
28944 A stop reply should be generated for any affected thread not already stopped.
28945 When a thread is stopped by means of a @samp{t} action,
28946 the corresponding stop reply should indicate that the thread has stopped with
28947 signal @samp{0}, regardless of whether the target uses some other signal
28948 as an implementation detail.
28949
28950 Reply:
28951 @xref{Stop Reply Packets}, for the reply specifications.
28952
28953 @item vCont?
28954 @cindex @samp{vCont?} packet
28955 Request a list of actions supported by the @samp{vCont} packet.
28956
28957 Reply:
28958 @table @samp
28959 @item vCont@r{[};@var{action}@dots{}@r{]}
28960 The @samp{vCont} packet is supported. Each @var{action} is a supported
28961 command in the @samp{vCont} packet.
28962 @item
28963 The @samp{vCont} packet is not supported.
28964 @end table
28965
28966 @item vFile:@var{operation}:@var{parameter}@dots{}
28967 @cindex @samp{vFile} packet
28968 Perform a file operation on the target system. For details,
28969 see @ref{Host I/O Packets}.
28970
28971 @item vFlashErase:@var{addr},@var{length}
28972 @cindex @samp{vFlashErase} packet
28973 Direct the stub to erase @var{length} bytes of flash starting at
28974 @var{addr}. The region may enclose any number of flash blocks, but
28975 its start and end must fall on block boundaries, as indicated by the
28976 flash block size appearing in the memory map (@pxref{Memory Map
28977 Format}). @value{GDBN} groups flash memory programming operations
28978 together, and sends a @samp{vFlashDone} request after each group; the
28979 stub is allowed to delay erase operation until the @samp{vFlashDone}
28980 packet is received.
28981
28982 The stub must support @samp{vCont} if it reports support for
28983 multiprocess extensions (@pxref{multiprocess extensions}). Note that in
28984 this case @samp{vCont} actions can be specified to apply to all threads
28985 in a process by using the @samp{p@var{pid}.-1} form of the
28986 @var{thread-id}.
28987
28988 Reply:
28989 @table @samp
28990 @item OK
28991 for success
28992 @item E @var{NN}
28993 for an error
28994 @end table
28995
28996 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
28997 @cindex @samp{vFlashWrite} packet
28998 Direct the stub to write data to flash address @var{addr}. The data
28999 is passed in binary form using the same encoding as for the @samp{X}
29000 packet (@pxref{Binary Data}). The memory ranges specified by
29001 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
29002 not overlap, and must appear in order of increasing addresses
29003 (although @samp{vFlashErase} packets for higher addresses may already
29004 have been received; the ordering is guaranteed only between
29005 @samp{vFlashWrite} packets). If a packet writes to an address that was
29006 neither erased by a preceding @samp{vFlashErase} packet nor by some other
29007 target-specific method, the results are unpredictable.
29008
29009
29010 Reply:
29011 @table @samp
29012 @item OK
29013 for success
29014 @item E.memtype
29015 for vFlashWrite addressing non-flash memory
29016 @item E @var{NN}
29017 for an error
29018 @end table
29019
29020 @item vFlashDone
29021 @cindex @samp{vFlashDone} packet
29022 Indicate to the stub that flash programming operation is finished.
29023 The stub is permitted to delay or batch the effects of a group of
29024 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
29025 @samp{vFlashDone} packet is received. The contents of the affected
29026 regions of flash memory are unpredictable until the @samp{vFlashDone}
29027 request is completed.
29028
29029 @item vKill;@var{pid}
29030 @cindex @samp{vKill} packet
29031 Kill the process with the specified process ID. @var{pid} is a
29032 hexadecimal integer identifying the process. This packet is used in
29033 preference to @samp{k} when multiprocess protocol extensions are
29034 supported; see @ref{multiprocess extensions}.
29035
29036 Reply:
29037 @table @samp
29038 @item E @var{nn}
29039 for an error
29040 @item OK
29041 for success
29042 @end table
29043
29044 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
29045 @cindex @samp{vRun} packet
29046 Run the program @var{filename}, passing it each @var{argument} on its
29047 command line. The file and arguments are hex-encoded strings. If
29048 @var{filename} is an empty string, the stub may use a default program
29049 (e.g.@: the last program run). The program is created in the stopped
29050 state.
29051
29052 @c FIXME: What about non-stop mode?
29053
29054 This packet is only available in extended mode (@pxref{extended mode}).
29055
29056 Reply:
29057 @table @samp
29058 @item E @var{nn}
29059 for an error
29060 @item @r{Any stop packet}
29061 for success (@pxref{Stop Reply Packets})
29062 @end table
29063
29064 @item vStopped
29065 @anchor{vStopped packet}
29066 @cindex @samp{vStopped} packet
29067
29068 In non-stop mode (@pxref{Remote Non-Stop}), acknowledge a previous stop
29069 reply and prompt for the stub to report another one.
29070
29071 Reply:
29072 @table @samp
29073 @item @r{Any stop packet}
29074 if there is another unreported stop event (@pxref{Stop Reply Packets})
29075 @item OK
29076 if there are no unreported stop events
29077 @end table
29078
29079 @item X @var{addr},@var{length}:@var{XX@dots{}}
29080 @anchor{X packet}
29081 @cindex @samp{X} packet
29082 Write data to memory, where the data is transmitted in binary.
29083 @var{addr} is address, @var{length} is number of bytes,
29084 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
29085
29086 Reply:
29087 @table @samp
29088 @item OK
29089 for success
29090 @item E @var{NN}
29091 for an error
29092 @end table
29093
29094 @item z @var{type},@var{addr},@var{length}
29095 @itemx Z @var{type},@var{addr},@var{length}
29096 @anchor{insert breakpoint or watchpoint packet}
29097 @cindex @samp{z} packet
29098 @cindex @samp{Z} packets
29099 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
29100 watchpoint starting at address @var{address} and covering the next
29101 @var{length} bytes.
29102
29103 Each breakpoint and watchpoint packet @var{type} is documented
29104 separately.
29105
29106 @emph{Implementation notes: A remote target shall return an empty string
29107 for an unrecognized breakpoint or watchpoint packet @var{type}. A
29108 remote target shall support either both or neither of a given
29109 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
29110 avoid potential problems with duplicate packets, the operations should
29111 be implemented in an idempotent way.}
29112
29113 @item z0,@var{addr},@var{length}
29114 @itemx Z0,@var{addr},@var{length}
29115 @cindex @samp{z0} packet
29116 @cindex @samp{Z0} packet
29117 Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
29118 @var{addr} of size @var{length}.
29119
29120 A memory breakpoint is implemented by replacing the instruction at
29121 @var{addr} with a software breakpoint or trap instruction. The
29122 @var{length} is used by targets that indicates the size of the
29123 breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
29124 @sc{mips} can insert either a 2 or 4 byte breakpoint).
29125
29126 @emph{Implementation note: It is possible for a target to copy or move
29127 code that contains memory breakpoints (e.g., when implementing
29128 overlays). The behavior of this packet, in the presence of such a
29129 target, is not defined.}
29130
29131 Reply:
29132 @table @samp
29133 @item OK
29134 success
29135 @item
29136 not supported
29137 @item E @var{NN}
29138 for an error
29139 @end table
29140
29141 @item z1,@var{addr},@var{length}
29142 @itemx Z1,@var{addr},@var{length}
29143 @cindex @samp{z1} packet
29144 @cindex @samp{Z1} packet
29145 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
29146 address @var{addr} of size @var{length}.
29147
29148 A hardware breakpoint is implemented using a mechanism that is not
29149 dependant on being able to modify the target's memory.
29150
29151 @emph{Implementation note: A hardware breakpoint is not affected by code
29152 movement.}
29153
29154 Reply:
29155 @table @samp
29156 @item OK
29157 success
29158 @item
29159 not supported
29160 @item E @var{NN}
29161 for an error
29162 @end table
29163
29164 @item z2,@var{addr},@var{length}
29165 @itemx Z2,@var{addr},@var{length}
29166 @cindex @samp{z2} packet
29167 @cindex @samp{Z2} packet
29168 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint.
29169
29170 Reply:
29171 @table @samp
29172 @item OK
29173 success
29174 @item
29175 not supported
29176 @item E @var{NN}
29177 for an error
29178 @end table
29179
29180 @item z3,@var{addr},@var{length}
29181 @itemx Z3,@var{addr},@var{length}
29182 @cindex @samp{z3} packet
29183 @cindex @samp{Z3} packet
29184 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint.
29185
29186 Reply:
29187 @table @samp
29188 @item OK
29189 success
29190 @item
29191 not supported
29192 @item E @var{NN}
29193 for an error
29194 @end table
29195
29196 @item z4,@var{addr},@var{length}
29197 @itemx Z4,@var{addr},@var{length}
29198 @cindex @samp{z4} packet
29199 @cindex @samp{Z4} packet
29200 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint.
29201
29202 Reply:
29203 @table @samp
29204 @item OK
29205 success
29206 @item
29207 not supported
29208 @item E @var{NN}
29209 for an error
29210 @end table
29211
29212 @end table
29213
29214 @node Stop Reply Packets
29215 @section Stop Reply Packets
29216 @cindex stop reply packets
29217
29218 The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
29219 @samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
29220 receive any of the below as a reply. Except for @samp{?}
29221 and @samp{vStopped}, that reply is only returned
29222 when the target halts. In the below the exact meaning of @dfn{signal
29223 number} is defined by the header @file{include/gdb/signals.h} in the
29224 @value{GDBN} source code.
29225
29226 As in the description of request packets, we include spaces in the
29227 reply templates for clarity; these are not part of the reply packet's
29228 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
29229 components.
29230
29231 @table @samp
29232
29233 @item S @var{AA}
29234 The program received signal number @var{AA} (a two-digit hexadecimal
29235 number). This is equivalent to a @samp{T} response with no
29236 @var{n}:@var{r} pairs.
29237
29238 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
29239 @cindex @samp{T} packet reply
29240 The program received signal number @var{AA} (a two-digit hexadecimal
29241 number). This is equivalent to an @samp{S} response, except that the
29242 @samp{@var{n}:@var{r}} pairs can carry values of important registers
29243 and other information directly in the stop reply packet, reducing
29244 round-trip latency. Single-step and breakpoint traps are reported
29245 this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
29246
29247 @itemize @bullet
29248 @item
29249 If @var{n} is a hexadecimal number, it is a register number, and the
29250 corresponding @var{r} gives that register's value. @var{r} is a
29251 series of bytes in target byte order, with each byte given by a
29252 two-digit hex number.
29253
29254 @item
29255 If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
29256 the stopped thread, as specified in @ref{thread-id syntax}.
29257
29258 @item
29259 If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
29260 the core on which the stop event was detected.
29261
29262 @item
29263 If @var{n} is a recognized @dfn{stop reason}, it describes a more
29264 specific event that stopped the target. The currently defined stop
29265 reasons are listed below. @var{aa} should be @samp{05}, the trap
29266 signal. At most one stop reason should be present.
29267
29268 @item
29269 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
29270 and go on to the next; this allows us to extend the protocol in the
29271 future.
29272 @end itemize
29273
29274 The currently defined stop reasons are:
29275
29276 @table @samp
29277 @item watch
29278 @itemx rwatch
29279 @itemx awatch
29280 The packet indicates a watchpoint hit, and @var{r} is the data address, in
29281 hex.
29282
29283 @cindex shared library events, remote reply
29284 @item library
29285 The packet indicates that the loaded libraries have changed.
29286 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
29287 list of loaded libraries. @var{r} is ignored.
29288
29289 @cindex replay log events, remote reply
29290 @item replaylog
29291 The packet indicates that the target cannot continue replaying
29292 logged execution events, because it has reached the end (or the
29293 beginning when executing backward) of the log. The value of @var{r}
29294 will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
29295 for more information.
29296 @end table
29297
29298 @item W @var{AA}
29299 @itemx W @var{AA} ; process:@var{pid}
29300 The process exited, and @var{AA} is the exit status. This is only
29301 applicable to certain targets.
29302
29303 The second form of the response, including the process ID of the exited
29304 process, can be used only when @value{GDBN} has reported support for
29305 multiprocess protocol extensions; see @ref{multiprocess extensions}.
29306 The @var{pid} is formatted as a big-endian hex string.
29307
29308 @item X @var{AA}
29309 @itemx X @var{AA} ; process:@var{pid}
29310 The process terminated with signal @var{AA}.
29311
29312 The second form of the response, including the process ID of the
29313 terminated process, can be used only when @value{GDBN} has reported
29314 support for multiprocess protocol extensions; see @ref{multiprocess
29315 extensions}. The @var{pid} is formatted as a big-endian hex string.
29316
29317 @item O @var{XX}@dots{}
29318 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
29319 written as the program's console output. This can happen at any time
29320 while the program is running and the debugger should continue to wait
29321 for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
29322
29323 @item F @var{call-id},@var{parameter}@dots{}
29324 @var{call-id} is the identifier which says which host system call should
29325 be called. This is just the name of the function. Translation into the
29326 correct system call is only applicable as it's defined in @value{GDBN}.
29327 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
29328 system calls.
29329
29330 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
29331 this very system call.
29332
29333 The target replies with this packet when it expects @value{GDBN} to
29334 call a host system call on behalf of the target. @value{GDBN} replies
29335 with an appropriate @samp{F} packet and keeps up waiting for the next
29336 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
29337 or @samp{s} action is expected to be continued. @xref{File-I/O Remote
29338 Protocol Extension}, for more details.
29339
29340 @end table
29341
29342 @node General Query Packets
29343 @section General Query Packets
29344 @cindex remote query requests
29345
29346 Packets starting with @samp{q} are @dfn{general query packets};
29347 packets starting with @samp{Q} are @dfn{general set packets}. General
29348 query and set packets are a semi-unified form for retrieving and
29349 sending information to and from the stub.
29350
29351 The initial letter of a query or set packet is followed by a name
29352 indicating what sort of thing the packet applies to. For example,
29353 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
29354 definitions with the stub. These packet names follow some
29355 conventions:
29356
29357 @itemize @bullet
29358 @item
29359 The name must not contain commas, colons or semicolons.
29360 @item
29361 Most @value{GDBN} query and set packets have a leading upper case
29362 letter.
29363 @item
29364 The names of custom vendor packets should use a company prefix, in
29365 lower case, followed by a period. For example, packets designed at
29366 the Acme Corporation might begin with @samp{qacme.foo} (for querying
29367 foos) or @samp{Qacme.bar} (for setting bars).
29368 @end itemize
29369
29370 The name of a query or set packet should be separated from any
29371 parameters by a @samp{:}; the parameters themselves should be
29372 separated by @samp{,} or @samp{;}. Stubs must be careful to match the
29373 full packet name, and check for a separator or the end of the packet,
29374 in case two packet names share a common prefix. New packets should not begin
29375 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
29376 packets predate these conventions, and have arguments without any terminator
29377 for the packet name; we suspect they are in widespread use in places that
29378 are difficult to upgrade. The @samp{qC} packet has no arguments, but some
29379 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
29380 packet.}.
29381
29382 Like the descriptions of the other packets, each description here
29383 has a template showing the packet's overall syntax, followed by an
29384 explanation of the packet's meaning. We include spaces in some of the
29385 templates for clarity; these are not part of the packet's syntax. No
29386 @value{GDBN} packet uses spaces to separate its components.
29387
29388 Here are the currently defined query and set packets:
29389
29390 @table @samp
29391
29392 @item qC
29393 @cindex current thread, remote request
29394 @cindex @samp{qC} packet
29395 Return the current thread ID.
29396
29397 Reply:
29398 @table @samp
29399 @item QC @var{thread-id}
29400 Where @var{thread-id} is a thread ID as documented in
29401 @ref{thread-id syntax}.
29402 @item @r{(anything else)}
29403 Any other reply implies the old thread ID.
29404 @end table
29405
29406 @item qCRC:@var{addr},@var{length}
29407 @cindex CRC of memory block, remote request
29408 @cindex @samp{qCRC} packet
29409 Compute the CRC checksum of a block of memory using CRC-32 defined in
29410 IEEE 802.3. The CRC is computed byte at a time, taking the most
29411 significant bit of each byte first. The initial pattern code
29412 @code{0xffffffff} is used to ensure leading zeros affect the CRC.
29413
29414 @emph{Note:} This is the same CRC used in validating separate debug
29415 files (@pxref{Separate Debug Files, , Debugging Information in Separate
29416 Files}). However the algorithm is slightly different. When validating
29417 separate debug files, the CRC is computed taking the @emph{least}
29418 significant bit of each byte first, and the final result is inverted to
29419 detect trailing zeros.
29420
29421 Reply:
29422 @table @samp
29423 @item E @var{NN}
29424 An error (such as memory fault)
29425 @item C @var{crc32}
29426 The specified memory region's checksum is @var{crc32}.
29427 @end table
29428
29429 @item qfThreadInfo
29430 @itemx qsThreadInfo
29431 @cindex list active threads, remote request
29432 @cindex @samp{qfThreadInfo} packet
29433 @cindex @samp{qsThreadInfo} packet
29434 Obtain a list of all active thread IDs from the target (OS). Since there
29435 may be too many active threads to fit into one reply packet, this query
29436 works iteratively: it may require more than one query/reply sequence to
29437 obtain the entire list of threads. The first query of the sequence will
29438 be the @samp{qfThreadInfo} query; subsequent queries in the
29439 sequence will be the @samp{qsThreadInfo} query.
29440
29441 NOTE: This packet replaces the @samp{qL} query (see below).
29442
29443 Reply:
29444 @table @samp
29445 @item m @var{thread-id}
29446 A single thread ID
29447 @item m @var{thread-id},@var{thread-id}@dots{}
29448 a comma-separated list of thread IDs
29449 @item l
29450 (lower case letter @samp{L}) denotes end of list.
29451 @end table
29452
29453 In response to each query, the target will reply with a list of one or
29454 more thread IDs, separated by commas.
29455 @value{GDBN} will respond to each reply with a request for more thread
29456 ids (using the @samp{qs} form of the query), until the target responds
29457 with @samp{l} (lower-case el, for @dfn{last}).
29458 Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
29459 fields.
29460
29461 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
29462 @cindex get thread-local storage address, remote request
29463 @cindex @samp{qGetTLSAddr} packet
29464 Fetch the address associated with thread local storage specified
29465 by @var{thread-id}, @var{offset}, and @var{lm}.
29466
29467 @var{thread-id} is the thread ID associated with the
29468 thread for which to fetch the TLS address. @xref{thread-id syntax}.
29469
29470 @var{offset} is the (big endian, hex encoded) offset associated with the
29471 thread local variable. (This offset is obtained from the debug
29472 information associated with the variable.)
29473
29474 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
29475 the load module associated with the thread local storage. For example,
29476 a @sc{gnu}/Linux system will pass the link map address of the shared
29477 object associated with the thread local storage under consideration.
29478 Other operating environments may choose to represent the load module
29479 differently, so the precise meaning of this parameter will vary.
29480
29481 Reply:
29482 @table @samp
29483 @item @var{XX}@dots{}
29484 Hex encoded (big endian) bytes representing the address of the thread
29485 local storage requested.
29486
29487 @item E @var{nn}
29488 An error occurred. @var{nn} are hex digits.
29489
29490 @item
29491 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
29492 @end table
29493
29494 @item qL @var{startflag} @var{threadcount} @var{nextthread}
29495 Obtain thread information from RTOS. Where: @var{startflag} (one hex
29496 digit) is one to indicate the first query and zero to indicate a
29497 subsequent query; @var{threadcount} (two hex digits) is the maximum
29498 number of threads the response packet can contain; and @var{nextthread}
29499 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
29500 returned in the response as @var{argthread}.
29501
29502 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
29503
29504 Reply:
29505 @table @samp
29506 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
29507 Where: @var{count} (two hex digits) is the number of threads being
29508 returned; @var{done} (one hex digit) is zero to indicate more threads
29509 and one indicates no further threads; @var{argthreadid} (eight hex
29510 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
29511 is a sequence of thread IDs from the target. @var{threadid} (eight hex
29512 digits). See @code{remote.c:parse_threadlist_response()}.
29513 @end table
29514
29515 @item qOffsets
29516 @cindex section offsets, remote request
29517 @cindex @samp{qOffsets} packet
29518 Get section offsets that the target used when relocating the downloaded
29519 image.
29520
29521 Reply:
29522 @table @samp
29523 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
29524 Relocate the @code{Text} section by @var{xxx} from its original address.
29525 Relocate the @code{Data} section by @var{yyy} from its original address.
29526 If the object file format provides segment information (e.g.@: @sc{elf}
29527 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
29528 segments by the supplied offsets.
29529
29530 @emph{Note: while a @code{Bss} offset may be included in the response,
29531 @value{GDBN} ignores this and instead applies the @code{Data} offset
29532 to the @code{Bss} section.}
29533
29534 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
29535 Relocate the first segment of the object file, which conventionally
29536 contains program code, to a starting address of @var{xxx}. If
29537 @samp{DataSeg} is specified, relocate the second segment, which
29538 conventionally contains modifiable data, to a starting address of
29539 @var{yyy}. @value{GDBN} will report an error if the object file
29540 does not contain segment information, or does not contain at least
29541 as many segments as mentioned in the reply. Extra segments are
29542 kept at fixed offsets relative to the last relocated segment.
29543 @end table
29544
29545 @item qP @var{mode} @var{thread-id}
29546 @cindex thread information, remote request
29547 @cindex @samp{qP} packet
29548 Returns information on @var{thread-id}. Where: @var{mode} is a hex
29549 encoded 32 bit mode; @var{thread-id} is a thread ID
29550 (@pxref{thread-id syntax}).
29551
29552 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
29553 (see below).
29554
29555 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
29556
29557 @item QNonStop:1
29558 @item QNonStop:0
29559 @cindex non-stop mode, remote request
29560 @cindex @samp{QNonStop} packet
29561 @anchor{QNonStop}
29562 Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
29563 @xref{Remote Non-Stop}, for more information.
29564
29565 Reply:
29566 @table @samp
29567 @item OK
29568 The request succeeded.
29569
29570 @item E @var{nn}
29571 An error occurred. @var{nn} are hex digits.
29572
29573 @item
29574 An empty reply indicates that @samp{QNonStop} is not supported by
29575 the stub.
29576 @end table
29577
29578 This packet is not probed by default; the remote stub must request it,
29579 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
29580 Use of this packet is controlled by the @code{set non-stop} command;
29581 @pxref{Non-Stop Mode}.
29582
29583 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
29584 @cindex pass signals to inferior, remote request
29585 @cindex @samp{QPassSignals} packet
29586 @anchor{QPassSignals}
29587 Each listed @var{signal} should be passed directly to the inferior process.
29588 Signals are numbered identically to continue packets and stop replies
29589 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
29590 strictly greater than the previous item. These signals do not need to stop
29591 the inferior, or be reported to @value{GDBN}. All other signals should be
29592 reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
29593 combine; any earlier @samp{QPassSignals} list is completely replaced by the
29594 new list. This packet improves performance when using @samp{handle
29595 @var{signal} nostop noprint pass}.
29596
29597 Reply:
29598 @table @samp
29599 @item OK
29600 The request succeeded.
29601
29602 @item E @var{nn}
29603 An error occurred. @var{nn} are hex digits.
29604
29605 @item
29606 An empty reply indicates that @samp{QPassSignals} is not supported by
29607 the stub.
29608 @end table
29609
29610 Use of this packet is controlled by the @code{set remote pass-signals}
29611 command (@pxref{Remote Configuration, set remote pass-signals}).
29612 This packet is not probed by default; the remote stub must request it,
29613 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
29614
29615 @item qRcmd,@var{command}
29616 @cindex execute remote command, remote request
29617 @cindex @samp{qRcmd} packet
29618 @var{command} (hex encoded) is passed to the local interpreter for
29619 execution. Invalid commands should be reported using the output
29620 string. Before the final result packet, the target may also respond
29621 with a number of intermediate @samp{O@var{output}} console output
29622 packets. @emph{Implementors should note that providing access to a
29623 stubs's interpreter may have security implications}.
29624
29625 Reply:
29626 @table @samp
29627 @item OK
29628 A command response with no output.
29629 @item @var{OUTPUT}
29630 A command response with the hex encoded output string @var{OUTPUT}.
29631 @item E @var{NN}
29632 Indicate a badly formed request.
29633 @item
29634 An empty reply indicates that @samp{qRcmd} is not recognized.
29635 @end table
29636
29637 (Note that the @code{qRcmd} packet's name is separated from the
29638 command by a @samp{,}, not a @samp{:}, contrary to the naming
29639 conventions above. Please don't use this packet as a model for new
29640 packets.)
29641
29642 @item qSearch:memory:@var{address};@var{length};@var{search-pattern}
29643 @cindex searching memory, in remote debugging
29644 @cindex @samp{qSearch:memory} packet
29645 @anchor{qSearch memory}
29646 Search @var{length} bytes at @var{address} for @var{search-pattern}.
29647 @var{address} and @var{length} are encoded in hex.
29648 @var{search-pattern} is a sequence of bytes, hex encoded.
29649
29650 Reply:
29651 @table @samp
29652 @item 0
29653 The pattern was not found.
29654 @item 1,address
29655 The pattern was found at @var{address}.
29656 @item E @var{NN}
29657 A badly formed request or an error was encountered while searching memory.
29658 @item
29659 An empty reply indicates that @samp{qSearch:memory} is not recognized.
29660 @end table
29661
29662 @item QStartNoAckMode
29663 @cindex @samp{QStartNoAckMode} packet
29664 @anchor{QStartNoAckMode}
29665 Request that the remote stub disable the normal @samp{+}/@samp{-}
29666 protocol acknowledgments (@pxref{Packet Acknowledgment}).
29667
29668 Reply:
29669 @table @samp
29670 @item OK
29671 The stub has switched to no-acknowledgment mode.
29672 @value{GDBN} acknowledges this reponse,
29673 but neither the stub nor @value{GDBN} shall send or expect further
29674 @samp{+}/@samp{-} acknowledgments in the current connection.
29675 @item
29676 An empty reply indicates that the stub does not support no-acknowledgment mode.
29677 @end table
29678
29679 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
29680 @cindex supported packets, remote query
29681 @cindex features of the remote protocol
29682 @cindex @samp{qSupported} packet
29683 @anchor{qSupported}
29684 Tell the remote stub about features supported by @value{GDBN}, and
29685 query the stub for features it supports. This packet allows
29686 @value{GDBN} and the remote stub to take advantage of each others'
29687 features. @samp{qSupported} also consolidates multiple feature probes
29688 at startup, to improve @value{GDBN} performance---a single larger
29689 packet performs better than multiple smaller probe packets on
29690 high-latency links. Some features may enable behavior which must not
29691 be on by default, e.g.@: because it would confuse older clients or
29692 stubs. Other features may describe packets which could be
29693 automatically probed for, but are not. These features must be
29694 reported before @value{GDBN} will use them. This ``default
29695 unsupported'' behavior is not appropriate for all packets, but it
29696 helps to keep the initial connection time under control with new
29697 versions of @value{GDBN} which support increasing numbers of packets.
29698
29699 Reply:
29700 @table @samp
29701 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
29702 The stub supports or does not support each returned @var{stubfeature},
29703 depending on the form of each @var{stubfeature} (see below for the
29704 possible forms).
29705 @item
29706 An empty reply indicates that @samp{qSupported} is not recognized,
29707 or that no features needed to be reported to @value{GDBN}.
29708 @end table
29709
29710 The allowed forms for each feature (either a @var{gdbfeature} in the
29711 @samp{qSupported} packet, or a @var{stubfeature} in the response)
29712 are:
29713
29714 @table @samp
29715 @item @var{name}=@var{value}
29716 The remote protocol feature @var{name} is supported, and associated
29717 with the specified @var{value}. The format of @var{value} depends
29718 on the feature, but it must not include a semicolon.
29719 @item @var{name}+
29720 The remote protocol feature @var{name} is supported, and does not
29721 need an associated value.
29722 @item @var{name}-
29723 The remote protocol feature @var{name} is not supported.
29724 @item @var{name}?
29725 The remote protocol feature @var{name} may be supported, and
29726 @value{GDBN} should auto-detect support in some other way when it is
29727 needed. This form will not be used for @var{gdbfeature} notifications,
29728 but may be used for @var{stubfeature} responses.
29729 @end table
29730
29731 Whenever the stub receives a @samp{qSupported} request, the
29732 supplied set of @value{GDBN} features should override any previous
29733 request. This allows @value{GDBN} to put the stub in a known
29734 state, even if the stub had previously been communicating with
29735 a different version of @value{GDBN}.
29736
29737 The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
29738 are defined:
29739
29740 @table @samp
29741 @item multiprocess
29742 This feature indicates whether @value{GDBN} supports multiprocess
29743 extensions to the remote protocol. @value{GDBN} does not use such
29744 extensions unless the stub also reports that it supports them by
29745 including @samp{multiprocess+} in its @samp{qSupported} reply.
29746 @xref{multiprocess extensions}, for details.
29747 @end table
29748
29749 Stubs should ignore any unknown values for
29750 @var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
29751 packet supports receiving packets of unlimited length (earlier
29752 versions of @value{GDBN} may reject overly long responses). Additional values
29753 for @var{gdbfeature} may be defined in the future to let the stub take
29754 advantage of new features in @value{GDBN}, e.g.@: incompatible
29755 improvements in the remote protocol---the @samp{multiprocess} feature is
29756 an example of such a feature. The stub's reply should be independent
29757 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
29758 describes all the features it supports, and then the stub replies with
29759 all the features it supports.
29760
29761 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
29762 responses, as long as each response uses one of the standard forms.
29763
29764 Some features are flags. A stub which supports a flag feature
29765 should respond with a @samp{+} form response. Other features
29766 require values, and the stub should respond with an @samp{=}
29767 form response.
29768
29769 Each feature has a default value, which @value{GDBN} will use if
29770 @samp{qSupported} is not available or if the feature is not mentioned
29771 in the @samp{qSupported} response. The default values are fixed; a
29772 stub is free to omit any feature responses that match the defaults.
29773
29774 Not all features can be probed, but for those which can, the probing
29775 mechanism is useful: in some cases, a stub's internal
29776 architecture may not allow the protocol layer to know some information
29777 about the underlying target in advance. This is especially common in
29778 stubs which may be configured for multiple targets.
29779
29780 These are the currently defined stub features and their properties:
29781
29782 @multitable @columnfractions 0.35 0.2 0.12 0.2
29783 @c NOTE: The first row should be @headitem, but we do not yet require
29784 @c a new enough version of Texinfo (4.7) to use @headitem.
29785 @item Feature Name
29786 @tab Value Required
29787 @tab Default
29788 @tab Probe Allowed
29789
29790 @item @samp{PacketSize}
29791 @tab Yes
29792 @tab @samp{-}
29793 @tab No
29794
29795 @item @samp{qXfer:auxv:read}
29796 @tab No
29797 @tab @samp{-}
29798 @tab Yes
29799
29800 @item @samp{qXfer:features:read}
29801 @tab No
29802 @tab @samp{-}
29803 @tab Yes
29804
29805 @item @samp{qXfer:libraries:read}
29806 @tab No
29807 @tab @samp{-}
29808 @tab Yes
29809
29810 @item @samp{qXfer:memory-map:read}
29811 @tab No
29812 @tab @samp{-}
29813 @tab Yes
29814
29815 @item @samp{qXfer:spu:read}
29816 @tab No
29817 @tab @samp{-}
29818 @tab Yes
29819
29820 @item @samp{qXfer:spu:write}
29821 @tab No
29822 @tab @samp{-}
29823 @tab Yes
29824
29825 @item @samp{qXfer:siginfo:read}
29826 @tab No
29827 @tab @samp{-}
29828 @tab Yes
29829
29830 @item @samp{qXfer:siginfo:write}
29831 @tab No
29832 @tab @samp{-}
29833 @tab Yes
29834
29835 @item @samp{qXfer:threads:read}
29836 @tab No
29837 @tab @samp{-}
29838 @tab Yes
29839
29840
29841 @item @samp{QNonStop}
29842 @tab No
29843 @tab @samp{-}
29844 @tab Yes
29845
29846 @item @samp{QPassSignals}
29847 @tab No
29848 @tab @samp{-}
29849 @tab Yes
29850
29851 @item @samp{QStartNoAckMode}
29852 @tab No
29853 @tab @samp{-}
29854 @tab Yes
29855
29856 @item @samp{multiprocess}
29857 @tab No
29858 @tab @samp{-}
29859 @tab No
29860
29861 @item @samp{ConditionalTracepoints}
29862 @tab No
29863 @tab @samp{-}
29864 @tab No
29865
29866 @item @samp{ReverseContinue}
29867 @tab No
29868 @tab @samp{-}
29869 @tab No
29870
29871 @item @samp{ReverseStep}
29872 @tab No
29873 @tab @samp{-}
29874 @tab No
29875
29876 @end multitable
29877
29878 These are the currently defined stub features, in more detail:
29879
29880 @table @samp
29881 @cindex packet size, remote protocol
29882 @item PacketSize=@var{bytes}
29883 The remote stub can accept packets up to at least @var{bytes} in
29884 length. @value{GDBN} will send packets up to this size for bulk
29885 transfers, and will never send larger packets. This is a limit on the
29886 data characters in the packet, including the frame and checksum.
29887 There is no trailing NUL byte in a remote protocol packet; if the stub
29888 stores packets in a NUL-terminated format, it should allow an extra
29889 byte in its buffer for the NUL. If this stub feature is not supported,
29890 @value{GDBN} guesses based on the size of the @samp{g} packet response.
29891
29892 @item qXfer:auxv:read
29893 The remote stub understands the @samp{qXfer:auxv:read} packet
29894 (@pxref{qXfer auxiliary vector read}).
29895
29896 @item qXfer:features:read
29897 The remote stub understands the @samp{qXfer:features:read} packet
29898 (@pxref{qXfer target description read}).
29899
29900 @item qXfer:libraries:read
29901 The remote stub understands the @samp{qXfer:libraries:read} packet
29902 (@pxref{qXfer library list read}).
29903
29904 @item qXfer:memory-map:read
29905 The remote stub understands the @samp{qXfer:memory-map:read} packet
29906 (@pxref{qXfer memory map read}).
29907
29908 @item qXfer:spu:read
29909 The remote stub understands the @samp{qXfer:spu:read} packet
29910 (@pxref{qXfer spu read}).
29911
29912 @item qXfer:spu:write
29913 The remote stub understands the @samp{qXfer:spu:write} packet
29914 (@pxref{qXfer spu write}).
29915
29916 @item qXfer:siginfo:read
29917 The remote stub understands the @samp{qXfer:siginfo:read} packet
29918 (@pxref{qXfer siginfo read}).
29919
29920 @item qXfer:siginfo:write
29921 The remote stub understands the @samp{qXfer:siginfo:write} packet
29922 (@pxref{qXfer siginfo write}).
29923
29924 @item qXfer:threads:read
29925 The remote stub understands the @samp{qXfer:threads:read} packet
29926 (@pxref{qXfer threads read}).
29927
29928 @item QNonStop
29929 The remote stub understands the @samp{QNonStop} packet
29930 (@pxref{QNonStop}).
29931
29932 @item QPassSignals
29933 The remote stub understands the @samp{QPassSignals} packet
29934 (@pxref{QPassSignals}).
29935
29936 @item QStartNoAckMode
29937 The remote stub understands the @samp{QStartNoAckMode} packet and
29938 prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
29939
29940 @item multiprocess
29941 @anchor{multiprocess extensions}
29942 @cindex multiprocess extensions, in remote protocol
29943 The remote stub understands the multiprocess extensions to the remote
29944 protocol syntax. The multiprocess extensions affect the syntax of
29945 thread IDs in both packets and replies (@pxref{thread-id syntax}), and
29946 add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
29947 replies. Note that reporting this feature indicates support for the
29948 syntactic extensions only, not that the stub necessarily supports
29949 debugging of more than one process at a time. The stub must not use
29950 multiprocess extensions in packet replies unless @value{GDBN} has also
29951 indicated it supports them in its @samp{qSupported} request.
29952
29953 @item qXfer:osdata:read
29954 The remote stub understands the @samp{qXfer:osdata:read} packet
29955 ((@pxref{qXfer osdata read}).
29956
29957 @item ConditionalTracepoints
29958 The remote stub accepts and implements conditional expressions defined
29959 for tracepoints (@pxref{Tracepoint Conditions}).
29960
29961 @item ReverseContinue
29962 The remote stub accepts and implements the reverse continue packet
29963 (@pxref{bc}).
29964
29965 @item ReverseStep
29966 The remote stub accepts and implements the reverse step packet
29967 (@pxref{bs}).
29968
29969 @end table
29970
29971 @item qSymbol::
29972 @cindex symbol lookup, remote request
29973 @cindex @samp{qSymbol} packet
29974 Notify the target that @value{GDBN} is prepared to serve symbol lookup
29975 requests. Accept requests from the target for the values of symbols.
29976
29977 Reply:
29978 @table @samp
29979 @item OK
29980 The target does not need to look up any (more) symbols.
29981 @item qSymbol:@var{sym_name}
29982 The target requests the value of symbol @var{sym_name} (hex encoded).
29983 @value{GDBN} may provide the value by using the
29984 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
29985 below.
29986 @end table
29987
29988 @item qSymbol:@var{sym_value}:@var{sym_name}
29989 Set the value of @var{sym_name} to @var{sym_value}.
29990
29991 @var{sym_name} (hex encoded) is the name of a symbol whose value the
29992 target has previously requested.
29993
29994 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
29995 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
29996 will be empty.
29997
29998 Reply:
29999 @table @samp
30000 @item OK
30001 The target does not need to look up any (more) symbols.
30002 @item qSymbol:@var{sym_name}
30003 The target requests the value of a new symbol @var{sym_name} (hex
30004 encoded). @value{GDBN} will continue to supply the values of symbols
30005 (if available), until the target ceases to request them.
30006 @end table
30007
30008 @item qTBuffer
30009 @item QTDisconnected
30010 @itemx QTDP
30011 @itemx QTDV
30012 @itemx qTfP
30013 @itemx qTfV
30014 @itemx QTFrame
30015 @xref{Tracepoint Packets}.
30016
30017 @item qThreadExtraInfo,@var{thread-id}
30018 @cindex thread attributes info, remote request
30019 @cindex @samp{qThreadExtraInfo} packet
30020 Obtain a printable string description of a thread's attributes from
30021 the target OS. @var{thread-id} is a thread ID;
30022 see @ref{thread-id syntax}. This
30023 string may contain anything that the target OS thinks is interesting
30024 for @value{GDBN} to tell the user about the thread. The string is
30025 displayed in @value{GDBN}'s @code{info threads} display. Some
30026 examples of possible thread extra info strings are @samp{Runnable}, or
30027 @samp{Blocked on Mutex}.
30028
30029 Reply:
30030 @table @samp
30031 @item @var{XX}@dots{}
30032 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
30033 comprising the printable string containing the extra information about
30034 the thread's attributes.
30035 @end table
30036
30037 (Note that the @code{qThreadExtraInfo} packet's name is separated from
30038 the command by a @samp{,}, not a @samp{:}, contrary to the naming
30039 conventions above. Please don't use this packet as a model for new
30040 packets.)
30041
30042 @item QTSave
30043 @item qTsP
30044 @item qTsV
30045 @itemx QTStart
30046 @itemx QTStop
30047 @itemx QTinit
30048 @itemx QTro
30049 @itemx qTStatus
30050 @itemx qTV
30051 @xref{Tracepoint Packets}.
30052
30053 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
30054 @cindex read special object, remote request
30055 @cindex @samp{qXfer} packet
30056 @anchor{qXfer read}
30057 Read uninterpreted bytes from the target's special data area
30058 identified by the keyword @var{object}. Request @var{length} bytes
30059 starting at @var{offset} bytes into the data. The content and
30060 encoding of @var{annex} is specific to @var{object}; it can supply
30061 additional details about what data to access.
30062
30063 Here are the specific requests of this form defined so far. All
30064 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
30065 formats, listed below.
30066
30067 @table @samp
30068 @item qXfer:auxv:read::@var{offset},@var{length}
30069 @anchor{qXfer auxiliary vector read}
30070 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
30071 auxiliary vector}. Note @var{annex} must be empty.
30072
30073 This packet is not probed by default; the remote stub must request it,
30074 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
30075
30076 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
30077 @anchor{qXfer target description read}
30078 Access the @dfn{target description}. @xref{Target Descriptions}. The
30079 annex specifies which XML document to access. The main description is
30080 always loaded from the @samp{target.xml} annex.
30081
30082 This packet is not probed by default; the remote stub must request it,
30083 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
30084
30085 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
30086 @anchor{qXfer library list read}
30087 Access the target's list of loaded libraries. @xref{Library List Format}.
30088 The annex part of the generic @samp{qXfer} packet must be empty
30089 (@pxref{qXfer read}).
30090
30091 Targets which maintain a list of libraries in the program's memory do
30092 not need to implement this packet; it is designed for platforms where
30093 the operating system manages the list of loaded libraries.
30094
30095 This packet is not probed by default; the remote stub must request it,
30096 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
30097
30098 @item qXfer:memory-map:read::@var{offset},@var{length}
30099 @anchor{qXfer memory map read}
30100 Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
30101 annex part of the generic @samp{qXfer} packet must be empty
30102 (@pxref{qXfer read}).
30103
30104 This packet is not probed by default; the remote stub must request it,
30105 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
30106
30107 @item qXfer:siginfo:read::@var{offset},@var{length}
30108 @anchor{qXfer siginfo read}
30109 Read contents of the extra signal information on the target
30110 system. The annex part of the generic @samp{qXfer} packet must be
30111 empty (@pxref{qXfer read}).
30112
30113 This packet is not probed by default; the remote stub must request it,
30114 by supplying an appropriate @samp{qSupported} response
30115 (@pxref{qSupported}).
30116
30117 @item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
30118 @anchor{qXfer spu read}
30119 Read contents of an @code{spufs} file on the target system. The
30120 annex specifies which file to read; it must be of the form
30121 @file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
30122 in the target process, and @var{name} identifes the @code{spufs} file
30123 in that context to be accessed.
30124
30125 This packet is not probed by default; the remote stub must request it,
30126 by supplying an appropriate @samp{qSupported} response
30127 (@pxref{qSupported}).
30128
30129 @item qXfer:threads:read::@var{offset},@var{length}
30130 @anchor{qXfer threads read}
30131 Access the list of threads on target. @xref{Thread List Format}. The
30132 annex part of the generic @samp{qXfer} packet must be empty
30133 (@pxref{qXfer read}).
30134
30135 This packet is not probed by default; the remote stub must request it,
30136 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
30137
30138 @item qXfer:osdata:read::@var{offset},@var{length}
30139 @anchor{qXfer osdata read}
30140 Access the target's @dfn{operating system information}.
30141 @xref{Operating System Information}.
30142
30143 @end table
30144
30145 Reply:
30146 @table @samp
30147 @item m @var{data}
30148 Data @var{data} (@pxref{Binary Data}) has been read from the
30149 target. There may be more data at a higher address (although
30150 it is permitted to return @samp{m} even for the last valid
30151 block of data, as long as at least one byte of data was read).
30152 @var{data} may have fewer bytes than the @var{length} in the
30153 request.
30154
30155 @item l @var{data}
30156 Data @var{data} (@pxref{Binary Data}) has been read from the target.
30157 There is no more data to be read. @var{data} may have fewer bytes
30158 than the @var{length} in the request.
30159
30160 @item l
30161 The @var{offset} in the request is at the end of the data.
30162 There is no more data to be read.
30163
30164 @item E00
30165 The request was malformed, or @var{annex} was invalid.
30166
30167 @item E @var{nn}
30168 The offset was invalid, or there was an error encountered reading the data.
30169 @var{nn} is a hex-encoded @code{errno} value.
30170
30171 @item
30172 An empty reply indicates the @var{object} string was not recognized by
30173 the stub, or that the object does not support reading.
30174 @end table
30175
30176 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
30177 @cindex write data into object, remote request
30178 @anchor{qXfer write}
30179 Write uninterpreted bytes into the target's special data area
30180 identified by the keyword @var{object}, starting at @var{offset} bytes
30181 into the data. @var{data}@dots{} is the binary-encoded data
30182 (@pxref{Binary Data}) to be written. The content and encoding of @var{annex}
30183 is specific to @var{object}; it can supply additional details about what data
30184 to access.
30185
30186 Here are the specific requests of this form defined so far. All
30187 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
30188 formats, listed below.
30189
30190 @table @samp
30191 @item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
30192 @anchor{qXfer siginfo write}
30193 Write @var{data} to the extra signal information on the target system.
30194 The annex part of the generic @samp{qXfer} packet must be
30195 empty (@pxref{qXfer write}).
30196
30197 This packet is not probed by default; the remote stub must request it,
30198 by supplying an appropriate @samp{qSupported} response
30199 (@pxref{qSupported}).
30200
30201 @item qXfer:spu:write:@var{annex}:@var{offset}:@var{data}@dots{}
30202 @anchor{qXfer spu write}
30203 Write @var{data} to an @code{spufs} file on the target system. The
30204 annex specifies which file to write; it must be of the form
30205 @file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
30206 in the target process, and @var{name} identifes the @code{spufs} file
30207 in that context to be accessed.
30208
30209 This packet is not probed by default; the remote stub must request it,
30210 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
30211 @end table
30212
30213 Reply:
30214 @table @samp
30215 @item @var{nn}
30216 @var{nn} (hex encoded) is the number of bytes written.
30217 This may be fewer bytes than supplied in the request.
30218
30219 @item E00
30220 The request was malformed, or @var{annex} was invalid.
30221
30222 @item E @var{nn}
30223 The offset was invalid, or there was an error encountered writing the data.
30224 @var{nn} is a hex-encoded @code{errno} value.
30225
30226 @item
30227 An empty reply indicates the @var{object} string was not
30228 recognized by the stub, or that the object does not support writing.
30229 @end table
30230
30231 @item qXfer:@var{object}:@var{operation}:@dots{}
30232 Requests of this form may be added in the future. When a stub does
30233 not recognize the @var{object} keyword, or its support for
30234 @var{object} does not recognize the @var{operation} keyword, the stub
30235 must respond with an empty packet.
30236
30237 @item qAttached:@var{pid}
30238 @cindex query attached, remote request
30239 @cindex @samp{qAttached} packet
30240 Return an indication of whether the remote server attached to an
30241 existing process or created a new process. When the multiprocess
30242 protocol extensions are supported (@pxref{multiprocess extensions}),
30243 @var{pid} is an integer in hexadecimal format identifying the target
30244 process. Otherwise, @value{GDBN} will omit the @var{pid} field and
30245 the query packet will be simplified as @samp{qAttached}.
30246
30247 This query is used, for example, to know whether the remote process
30248 should be detached or killed when a @value{GDBN} session is ended with
30249 the @code{quit} command.
30250
30251 Reply:
30252 @table @samp
30253 @item 1
30254 The remote server attached to an existing process.
30255 @item 0
30256 The remote server created a new process.
30257 @item E @var{NN}
30258 A badly formed request or an error was encountered.
30259 @end table
30260
30261 @end table
30262
30263 @node Register Packet Format
30264 @section Register Packet Format
30265
30266 The following @code{g}/@code{G} packets have previously been defined.
30267 In the below, some thirty-two bit registers are transferred as
30268 sixty-four bits. Those registers should be zero/sign extended (which?)
30269 to fill the space allocated. Register bytes are transferred in target
30270 byte order. The two nibbles within a register byte are transferred
30271 most-significant - least-significant.
30272
30273 @table @r
30274
30275 @item MIPS32
30276
30277 All registers are transferred as thirty-two bit quantities in the order:
30278 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
30279 registers; fsr; fir; fp.
30280
30281 @item MIPS64
30282
30283 All registers are transferred as sixty-four bit quantities (including
30284 thirty-two bit registers such as @code{sr}). The ordering is the same
30285 as @code{MIPS32}.
30286
30287 @end table
30288
30289 @node Tracepoint Packets
30290 @section Tracepoint Packets
30291 @cindex tracepoint packets
30292 @cindex packets, tracepoint
30293
30294 Here we describe the packets @value{GDBN} uses to implement
30295 tracepoints (@pxref{Tracepoints}).
30296
30297 @table @samp
30298
30299 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
30300 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
30301 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
30302 the tracepoint is disabled. @var{step} is the tracepoint's step
30303 count, and @var{pass} is its pass count. If an @samp{F} is present,
30304 then the tracepoint is to be a fast tracepoint, and the @var{flen} is
30305 the number of bytes that the target should copy elsewhere to make room
30306 for the tracepoint. If an @samp{X} is present, it introduces a
30307 tracepoint condition, which consists of a hexadecimal length, followed
30308 by a comma and hex-encoded bytes, in a manner similar to action
30309 encodings as described below. If the trailing @samp{-} is present,
30310 further @samp{QTDP} packets will follow to specify this tracepoint's
30311 actions.
30312
30313 Replies:
30314 @table @samp
30315 @item OK
30316 The packet was understood and carried out.
30317 @item
30318 The packet was not recognized.
30319 @end table
30320
30321 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
30322 Define actions to be taken when a tracepoint is hit. @var{n} and
30323 @var{addr} must be the same as in the initial @samp{QTDP} packet for
30324 this tracepoint. This packet may only be sent immediately after
30325 another @samp{QTDP} packet that ended with a @samp{-}. If the
30326 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
30327 specifying more actions for this tracepoint.
30328
30329 In the series of action packets for a given tracepoint, at most one
30330 can have an @samp{S} before its first @var{action}. If such a packet
30331 is sent, it and the following packets define ``while-stepping''
30332 actions. Any prior packets define ordinary actions --- that is, those
30333 taken when the tracepoint is first hit. If no action packet has an
30334 @samp{S}, then all the packets in the series specify ordinary
30335 tracepoint actions.
30336
30337 The @samp{@var{action}@dots{}} portion of the packet is a series of
30338 actions, concatenated without separators. Each action has one of the
30339 following forms:
30340
30341 @table @samp
30342
30343 @item R @var{mask}
30344 Collect the registers whose bits are set in @var{mask}. @var{mask} is
30345 a hexadecimal number whose @var{i}'th bit is set if register number
30346 @var{i} should be collected. (The least significant bit is numbered
30347 zero.) Note that @var{mask} may be any number of digits long; it may
30348 not fit in a 32-bit word.
30349
30350 @item M @var{basereg},@var{offset},@var{len}
30351 Collect @var{len} bytes of memory starting at the address in register
30352 number @var{basereg}, plus @var{offset}. If @var{basereg} is
30353 @samp{-1}, then the range has a fixed address: @var{offset} is the
30354 address of the lowest byte to collect. The @var{basereg},
30355 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
30356 values (the @samp{-1} value for @var{basereg} is a special case).
30357
30358 @item X @var{len},@var{expr}
30359 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
30360 it directs. @var{expr} is an agent expression, as described in
30361 @ref{Agent Expressions}. Each byte of the expression is encoded as a
30362 two-digit hex number in the packet; @var{len} is the number of bytes
30363 in the expression (and thus one-half the number of hex digits in the
30364 packet).
30365
30366 @end table
30367
30368 Any number of actions may be packed together in a single @samp{QTDP}
30369 packet, as long as the packet does not exceed the maximum packet
30370 length (400 bytes, for many stubs). There may be only one @samp{R}
30371 action per tracepoint, and it must precede any @samp{M} or @samp{X}
30372 actions. Any registers referred to by @samp{M} and @samp{X} actions
30373 must be collected by a preceding @samp{R} action. (The
30374 ``while-stepping'' actions are treated as if they were attached to a
30375 separate tracepoint, as far as these restrictions are concerned.)
30376
30377 Replies:
30378 @table @samp
30379 @item OK
30380 The packet was understood and carried out.
30381 @item
30382 The packet was not recognized.
30383 @end table
30384
30385 @item QTDV:@var{n}:@var{value}
30386 @cindex define trace state variable, remote request
30387 @cindex @samp{QTDV} packet
30388 Create a new trace state variable, number @var{n}, with an initial
30389 value of @var{value}, which is a 64-bit signed integer. Both @var{n}
30390 and @var{value} are encoded as hexadecimal values. @value{GDBN} has
30391 the option of not using this packet for initial values of zero; the
30392 target should simply create the trace state variables as they are
30393 mentioned in expressions.
30394
30395 @item QTFrame:@var{n}
30396 Select the @var{n}'th tracepoint frame from the buffer, and use the
30397 register and memory contents recorded there to answer subsequent
30398 request packets from @value{GDBN}.
30399
30400 A successful reply from the stub indicates that the stub has found the
30401 requested frame. The response is a series of parts, concatenated
30402 without separators, describing the frame we selected. Each part has
30403 one of the following forms:
30404
30405 @table @samp
30406 @item F @var{f}
30407 The selected frame is number @var{n} in the trace frame buffer;
30408 @var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
30409 was no frame matching the criteria in the request packet.
30410
30411 @item T @var{t}
30412 The selected trace frame records a hit of tracepoint number @var{t};
30413 @var{t} is a hexadecimal number.
30414
30415 @end table
30416
30417 @item QTFrame:pc:@var{addr}
30418 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
30419 currently selected frame whose PC is @var{addr};
30420 @var{addr} is a hexadecimal number.
30421
30422 @item QTFrame:tdp:@var{t}
30423 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
30424 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
30425 is a hexadecimal number.
30426
30427 @item QTFrame:range:@var{start}:@var{end}
30428 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
30429 currently selected frame whose PC is between @var{start} (inclusive)
30430 and @var{end} (exclusive); @var{start} and @var{end} are hexadecimal
30431 numbers.
30432
30433 @item QTFrame:outside:@var{start}:@var{end}
30434 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
30435 frame @emph{outside} the given range of addresses.
30436
30437 @item QTStart
30438 Begin the tracepoint experiment. Begin collecting data from tracepoint
30439 hits in the trace frame buffer.
30440
30441 @item QTStop
30442 End the tracepoint experiment. Stop collecting trace frames.
30443
30444 @item QTinit
30445 Clear the table of tracepoints, and empty the trace frame buffer.
30446
30447 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
30448 Establish the given ranges of memory as ``transparent''. The stub
30449 will answer requests for these ranges from memory's current contents,
30450 if they were not collected as part of the tracepoint hit.
30451
30452 @value{GDBN} uses this to mark read-only regions of memory, like those
30453 containing program code. Since these areas never change, they should
30454 still have the same contents they did when the tracepoint was hit, so
30455 there's no reason for the stub to refuse to provide their contents.
30456
30457 @item QTDisconnected:@var{value}
30458 Set the choice to what to do with the tracing run when @value{GDBN}
30459 disconnects from the target. A @var{value} of 1 directs the target to
30460 continue the tracing run, while 0 tells the target to stop tracing if
30461 @value{GDBN} is no longer in the picture.
30462
30463 @item qTStatus
30464 Ask the stub if there is a trace experiment running right now.
30465
30466 Replies:
30467 @table @samp
30468 @item T0
30469 There is no trace experiment running.
30470 @item T1
30471 There is a trace experiment running.
30472 @end table
30473
30474 @item qTV:@var{var}
30475 @cindex trace state variable value, remote request
30476 @cindex @samp{qTV} packet
30477 Ask the stub for the value of the trace state variable number @var{var}.
30478
30479 Replies:
30480 @table @samp
30481 @item V@var{value}
30482 The value of the variable is @var{value}. This will be the current
30483 value of the variable if the user is examining a running target, or a
30484 saved value if the variable was collected in the trace frame that the
30485 user is looking at. Note that multiple requests may result in
30486 different reply values, such as when requesting values while the
30487 program is running.
30488
30489 @item U
30490 The value of the variable is unknown. This would occur, for example,
30491 if the user is examining a trace frame in which the requested variable
30492 was not collected.
30493 @end table
30494
30495 @item qTfP
30496 @itemx qTsP
30497 These packets request data about tracepoints that are being used by
30498 the target. @value{GDBN} sends @code{qTfP} to get the first piece
30499 of data, and multiple @code{qTsP} to get additional pieces. Replies
30500 to these packets generally take the form of the @code{QTDP} packets
30501 that define tracepoints. (FIXME add detailed syntax)
30502
30503 @item qTfV
30504 @itemx qTsV
30505 These packets request data about trace state variables that are on the
30506 target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
30507 and multiple @code{qTsV} to get additional variables. Replies to
30508 these packets follow the syntax of the @code{QTDV} packets that define
30509 trace state variables.
30510
30511 @item QTSave:@var{filename}
30512 This packet directs the target to save trace data to the file name
30513 @var{filename} in the target's filesystem. @var{filename} is encoded
30514 as a hex string; the interpretation of the file name (relative vs
30515 absolute, wild cards, etc) is up to the target.
30516
30517 @item qTBuffer:@var{offset},@var{len}
30518 Return up to @var{len} bytes of the current contents of trace buffer,
30519 starting at @var{offset}. The trace buffer is treated as if it were
30520 a contiguous collection of traceframes, as per the trace file format.
30521 The reply consists as many hex-encoded bytes as the target can deliver
30522 in a packet; it is not an error to return fewer than were asked for.
30523 A reply consisting of just @code{l} indicates that no bytes are
30524 available.
30525
30526 @end table
30527
30528 @node Host I/O Packets
30529 @section Host I/O Packets
30530 @cindex Host I/O, remote protocol
30531 @cindex file transfer, remote protocol
30532
30533 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
30534 operations on the far side of a remote link. For example, Host I/O is
30535 used to upload and download files to a remote target with its own
30536 filesystem. Host I/O uses the same constant values and data structure
30537 layout as the target-initiated File-I/O protocol. However, the
30538 Host I/O packets are structured differently. The target-initiated
30539 protocol relies on target memory to store parameters and buffers.
30540 Host I/O requests are initiated by @value{GDBN}, and the
30541 target's memory is not involved. @xref{File-I/O Remote Protocol
30542 Extension}, for more details on the target-initiated protocol.
30543
30544 The Host I/O request packets all encode a single operation along with
30545 its arguments. They have this format:
30546
30547 @table @samp
30548
30549 @item vFile:@var{operation}: @var{parameter}@dots{}
30550 @var{operation} is the name of the particular request; the target
30551 should compare the entire packet name up to the second colon when checking
30552 for a supported operation. The format of @var{parameter} depends on
30553 the operation. Numbers are always passed in hexadecimal. Negative
30554 numbers have an explicit minus sign (i.e.@: two's complement is not
30555 used). Strings (e.g.@: filenames) are encoded as a series of
30556 hexadecimal bytes. The last argument to a system call may be a
30557 buffer of escaped binary data (@pxref{Binary Data}).
30558
30559 @end table
30560
30561 The valid responses to Host I/O packets are:
30562
30563 @table @samp
30564
30565 @item F @var{result} [, @var{errno}] [; @var{attachment}]
30566 @var{result} is the integer value returned by this operation, usually
30567 non-negative for success and -1 for errors. If an error has occured,
30568 @var{errno} will be included in the result. @var{errno} will have a
30569 value defined by the File-I/O protocol (@pxref{Errno Values}). For
30570 operations which return data, @var{attachment} supplies the data as a
30571 binary buffer. Binary buffers in response packets are escaped in the
30572 normal way (@pxref{Binary Data}). See the individual packet
30573 documentation for the interpretation of @var{result} and
30574 @var{attachment}.
30575
30576 @item
30577 An empty response indicates that this operation is not recognized.
30578
30579 @end table
30580
30581 These are the supported Host I/O operations:
30582
30583 @table @samp
30584 @item vFile:open: @var{pathname}, @var{flags}, @var{mode}
30585 Open a file at @var{pathname} and return a file descriptor for it, or
30586 return -1 if an error occurs. @var{pathname} is a string,
30587 @var{flags} is an integer indicating a mask of open flags
30588 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
30589 of mode bits to use if the file is created (@pxref{mode_t Values}).
30590 @xref{open}, for details of the open flags and mode values.
30591
30592 @item vFile:close: @var{fd}
30593 Close the open file corresponding to @var{fd} and return 0, or
30594 -1 if an error occurs.
30595
30596 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
30597 Read data from the open file corresponding to @var{fd}. Up to
30598 @var{count} bytes will be read from the file, starting at @var{offset}
30599 relative to the start of the file. The target may read fewer bytes;
30600 common reasons include packet size limits and an end-of-file
30601 condition. The number of bytes read is returned. Zero should only be
30602 returned for a successful read at the end of the file, or if
30603 @var{count} was zero.
30604
30605 The data read should be returned as a binary attachment on success.
30606 If zero bytes were read, the response should include an empty binary
30607 attachment (i.e.@: a trailing semicolon). The return value is the
30608 number of target bytes read; the binary attachment may be longer if
30609 some characters were escaped.
30610
30611 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
30612 Write @var{data} (a binary buffer) to the open file corresponding
30613 to @var{fd}. Start the write at @var{offset} from the start of the
30614 file. Unlike many @code{write} system calls, there is no
30615 separate @var{count} argument; the length of @var{data} in the
30616 packet is used. @samp{vFile:write} returns the number of bytes written,
30617 which may be shorter than the length of @var{data}, or -1 if an
30618 error occurred.
30619
30620 @item vFile:unlink: @var{pathname}
30621 Delete the file at @var{pathname} on the target. Return 0,
30622 or -1 if an error occurs. @var{pathname} is a string.
30623
30624 @end table
30625
30626 @node Interrupts
30627 @section Interrupts
30628 @cindex interrupts (remote protocol)
30629
30630 When a program on the remote target is running, @value{GDBN} may
30631 attempt to interrupt it by sending a @samp{Ctrl-C}, @code{BREAK} or
30632 a @code{BREAK} followed by @code{g},
30633 control of which is specified via @value{GDBN}'s @samp{interrupt-sequence}.
30634
30635 The precise meaning of @code{BREAK} is defined by the transport
30636 mechanism and may, in fact, be undefined. @value{GDBN} does not
30637 currently define a @code{BREAK} mechanism for any of the network
30638 interfaces except for TCP, in which case @value{GDBN} sends the
30639 @code{telnet} BREAK sequence.
30640
30641 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
30642 transport mechanisms. It is represented by sending the single byte
30643 @code{0x03} without any of the usual packet overhead described in
30644 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
30645 transmitted as part of a packet, it is considered to be packet data
30646 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
30647 (@pxref{X packet}), used for binary downloads, may include an unescaped
30648 @code{0x03} as part of its packet.
30649
30650 @code{BREAK} followed by @code{g} is also known as Magic SysRq g.
30651 When Linux kernel receives this sequence from serial port,
30652 it stops execution and connects to gdb.
30653
30654 Stubs are not required to recognize these interrupt mechanisms and the
30655 precise meaning associated with receipt of the interrupt is
30656 implementation defined. If the target supports debugging of multiple
30657 threads and/or processes, it should attempt to interrupt all
30658 currently-executing threads and processes.
30659 If the stub is successful at interrupting the
30660 running program, it should send one of the stop
30661 reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
30662 of successfully stopping the program in all-stop mode, and a stop reply
30663 for each stopped thread in non-stop mode.
30664 Interrupts received while the
30665 program is stopped are discarded.
30666
30667 @node Notification Packets
30668 @section Notification Packets
30669 @cindex notification packets
30670 @cindex packets, notification
30671
30672 The @value{GDBN} remote serial protocol includes @dfn{notifications},
30673 packets that require no acknowledgment. Both the GDB and the stub
30674 may send notifications (although the only notifications defined at
30675 present are sent by the stub). Notifications carry information
30676 without incurring the round-trip latency of an acknowledgment, and so
30677 are useful for low-impact communications where occasional packet loss
30678 is not a problem.
30679
30680 A notification packet has the form @samp{% @var{data} #
30681 @var{checksum}}, where @var{data} is the content of the notification,
30682 and @var{checksum} is a checksum of @var{data}, computed and formatted
30683 as for ordinary @value{GDBN} packets. A notification's @var{data}
30684 never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
30685 receiving a notification, the recipient sends no @samp{+} or @samp{-}
30686 to acknowledge the notification's receipt or to report its corruption.
30687
30688 Every notification's @var{data} begins with a name, which contains no
30689 colon characters, followed by a colon character.
30690
30691 Recipients should silently ignore corrupted notifications and
30692 notifications they do not understand. Recipients should restart
30693 timeout periods on receipt of a well-formed notification, whether or
30694 not they understand it.
30695
30696 Senders should only send the notifications described here when this
30697 protocol description specifies that they are permitted. In the
30698 future, we may extend the protocol to permit existing notifications in
30699 new contexts; this rule helps older senders avoid confusing newer
30700 recipients.
30701
30702 (Older versions of @value{GDBN} ignore bytes received until they see
30703 the @samp{$} byte that begins an ordinary packet, so new stubs may
30704 transmit notifications without fear of confusing older clients. There
30705 are no notifications defined for @value{GDBN} to send at the moment, but we
30706 assume that most older stubs would ignore them, as well.)
30707
30708 The following notification packets from the stub to @value{GDBN} are
30709 defined:
30710
30711 @table @samp
30712 @item Stop: @var{reply}
30713 Report an asynchronous stop event in non-stop mode.
30714 The @var{reply} has the form of a stop reply, as
30715 described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
30716 for information on how these notifications are acknowledged by
30717 @value{GDBN}.
30718 @end table
30719
30720 @node Remote Non-Stop
30721 @section Remote Protocol Support for Non-Stop Mode
30722
30723 @value{GDBN}'s remote protocol supports non-stop debugging of
30724 multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
30725 supports non-stop mode, it should report that to @value{GDBN} by including
30726 @samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
30727
30728 @value{GDBN} typically sends a @samp{QNonStop} packet only when
30729 establishing a new connection with the stub. Entering non-stop mode
30730 does not alter the state of any currently-running threads, but targets
30731 must stop all threads in any already-attached processes when entering
30732 all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
30733 probe the target state after a mode change.
30734
30735 In non-stop mode, when an attached process encounters an event that
30736 would otherwise be reported with a stop reply, it uses the
30737 asynchronous notification mechanism (@pxref{Notification Packets}) to
30738 inform @value{GDBN}. In contrast to all-stop mode, where all threads
30739 in all processes are stopped when a stop reply is sent, in non-stop
30740 mode only the thread reporting the stop event is stopped. That is,
30741 when reporting a @samp{S} or @samp{T} response to indicate completion
30742 of a step operation, hitting a breakpoint, or a fault, only the
30743 affected thread is stopped; any other still-running threads continue
30744 to run. When reporting a @samp{W} or @samp{X} response, all running
30745 threads belonging to other attached processes continue to run.
30746
30747 Only one stop reply notification at a time may be pending; if
30748 additional stop events occur before @value{GDBN} has acknowledged the
30749 previous notification, they must be queued by the stub for later
30750 synchronous transmission in response to @samp{vStopped} packets from
30751 @value{GDBN}. Because the notification mechanism is unreliable,
30752 the stub is permitted to resend a stop reply notification
30753 if it believes @value{GDBN} may not have received it. @value{GDBN}
30754 ignores additional stop reply notifications received before it has
30755 finished processing a previous notification and the stub has completed
30756 sending any queued stop events.
30757
30758 Otherwise, @value{GDBN} must be prepared to receive a stop reply
30759 notification at any time. Specifically, they may appear when
30760 @value{GDBN} is not otherwise reading input from the stub, or when
30761 @value{GDBN} is expecting to read a normal synchronous response or a
30762 @samp{+}/@samp{-} acknowledgment to a packet it has sent.
30763 Notification packets are distinct from any other communication from
30764 the stub so there is no ambiguity.
30765
30766 After receiving a stop reply notification, @value{GDBN} shall
30767 acknowledge it by sending a @samp{vStopped} packet (@pxref{vStopped packet})
30768 as a regular, synchronous request to the stub. Such acknowledgment
30769 is not required to happen immediately, as @value{GDBN} is permitted to
30770 send other, unrelated packets to the stub first, which the stub should
30771 process normally.
30772
30773 Upon receiving a @samp{vStopped} packet, if the stub has other queued
30774 stop events to report to @value{GDBN}, it shall respond by sending a
30775 normal stop reply response. @value{GDBN} shall then send another
30776 @samp{vStopped} packet to solicit further responses; again, it is
30777 permitted to send other, unrelated packets as well which the stub
30778 should process normally.
30779
30780 If the stub receives a @samp{vStopped} packet and there are no
30781 additional stop events to report, the stub shall return an @samp{OK}
30782 response. At this point, if further stop events occur, the stub shall
30783 send a new stop reply notification, @value{GDBN} shall accept the
30784 notification, and the process shall be repeated.
30785
30786 In non-stop mode, the target shall respond to the @samp{?} packet as
30787 follows. First, any incomplete stop reply notification/@samp{vStopped}
30788 sequence in progress is abandoned. The target must begin a new
30789 sequence reporting stop events for all stopped threads, whether or not
30790 it has previously reported those events to @value{GDBN}. The first
30791 stop reply is sent as a synchronous reply to the @samp{?} packet, and
30792 subsequent stop replies are sent as responses to @samp{vStopped} packets
30793 using the mechanism described above. The target must not send
30794 asynchronous stop reply notifications until the sequence is complete.
30795 If all threads are running when the target receives the @samp{?} packet,
30796 or if the target is not attached to any process, it shall respond
30797 @samp{OK}.
30798
30799 @node Packet Acknowledgment
30800 @section Packet Acknowledgment
30801
30802 @cindex acknowledgment, for @value{GDBN} remote
30803 @cindex packet acknowledgment, for @value{GDBN} remote
30804 By default, when either the host or the target machine receives a packet,
30805 the first response expected is an acknowledgment: either @samp{+} (to indicate
30806 the package was received correctly) or @samp{-} (to request retransmission).
30807 This mechanism allows the @value{GDBN} remote protocol to operate over
30808 unreliable transport mechanisms, such as a serial line.
30809
30810 In cases where the transport mechanism is itself reliable (such as a pipe or
30811 TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
30812 It may be desirable to disable them in that case to reduce communication
30813 overhead, or for other reasons. This can be accomplished by means of the
30814 @samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
30815
30816 When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
30817 expect @samp{+}/@samp{-} protocol acknowledgments. The packet
30818 and response format still includes the normal checksum, as described in
30819 @ref{Overview}, but the checksum may be ignored by the receiver.
30820
30821 If the stub supports @samp{QStartNoAckMode} and prefers to operate in
30822 no-acknowledgment mode, it should report that to @value{GDBN}
30823 by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
30824 @pxref{qSupported}.
30825 If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
30826 disabled via the @code{set remote noack-packet off} command
30827 (@pxref{Remote Configuration}),
30828 @value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
30829 Only then may the stub actually turn off packet acknowledgments.
30830 @value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
30831 response, which can be safely ignored by the stub.
30832
30833 Note that @code{set remote noack-packet} command only affects negotiation
30834 between @value{GDBN} and the stub when subsequent connections are made;
30835 it does not affect the protocol acknowledgment state for any current
30836 connection.
30837 Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
30838 new connection is established,
30839 there is also no protocol request to re-enable the acknowledgments
30840 for the current connection, once disabled.
30841
30842 @node Examples
30843 @section Examples
30844
30845 Example sequence of a target being re-started. Notice how the restart
30846 does not get any direct output:
30847
30848 @smallexample
30849 -> @code{R00}
30850 <- @code{+}
30851 @emph{target restarts}
30852 -> @code{?}
30853 <- @code{+}
30854 <- @code{T001:1234123412341234}
30855 -> @code{+}
30856 @end smallexample
30857
30858 Example sequence of a target being stepped by a single instruction:
30859
30860 @smallexample
30861 -> @code{G1445@dots{}}
30862 <- @code{+}
30863 -> @code{s}
30864 <- @code{+}
30865 @emph{time passes}
30866 <- @code{T001:1234123412341234}
30867 -> @code{+}
30868 -> @code{g}
30869 <- @code{+}
30870 <- @code{1455@dots{}}
30871 -> @code{+}
30872 @end smallexample
30873
30874 @node File-I/O Remote Protocol Extension
30875 @section File-I/O Remote Protocol Extension
30876 @cindex File-I/O remote protocol extension
30877
30878 @menu
30879 * File-I/O Overview::
30880 * Protocol Basics::
30881 * The F Request Packet::
30882 * The F Reply Packet::
30883 * The Ctrl-C Message::
30884 * Console I/O::
30885 * List of Supported Calls::
30886 * Protocol-specific Representation of Datatypes::
30887 * Constants::
30888 * File-I/O Examples::
30889 @end menu
30890
30891 @node File-I/O Overview
30892 @subsection File-I/O Overview
30893 @cindex file-i/o overview
30894
30895 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
30896 target to use the host's file system and console I/O to perform various
30897 system calls. System calls on the target system are translated into a
30898 remote protocol packet to the host system, which then performs the needed
30899 actions and returns a response packet to the target system.
30900 This simulates file system operations even on targets that lack file systems.
30901
30902 The protocol is defined to be independent of both the host and target systems.
30903 It uses its own internal representation of datatypes and values. Both
30904 @value{GDBN} and the target's @value{GDBN} stub are responsible for
30905 translating the system-dependent value representations into the internal
30906 protocol representations when data is transmitted.
30907
30908 The communication is synchronous. A system call is possible only when
30909 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
30910 or @samp{s} packets. While @value{GDBN} handles the request for a system call,
30911 the target is stopped to allow deterministic access to the target's
30912 memory. Therefore File-I/O is not interruptible by target signals. On
30913 the other hand, it is possible to interrupt File-I/O by a user interrupt
30914 (@samp{Ctrl-C}) within @value{GDBN}.
30915
30916 The target's request to perform a host system call does not finish
30917 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
30918 after finishing the system call, the target returns to continuing the
30919 previous activity (continue, step). No additional continue or step
30920 request from @value{GDBN} is required.
30921
30922 @smallexample
30923 (@value{GDBP}) continue
30924 <- target requests 'system call X'
30925 target is stopped, @value{GDBN} executes system call
30926 -> @value{GDBN} returns result
30927 ... target continues, @value{GDBN} returns to wait for the target
30928 <- target hits breakpoint and sends a Txx packet
30929 @end smallexample
30930
30931 The protocol only supports I/O on the console and to regular files on
30932 the host file system. Character or block special devices, pipes,
30933 named pipes, sockets or any other communication method on the host
30934 system are not supported by this protocol.
30935
30936 File I/O is not supported in non-stop mode.
30937
30938 @node Protocol Basics
30939 @subsection Protocol Basics
30940 @cindex protocol basics, file-i/o
30941
30942 The File-I/O protocol uses the @code{F} packet as the request as well
30943 as reply packet. Since a File-I/O system call can only occur when
30944 @value{GDBN} is waiting for a response from the continuing or stepping target,
30945 the File-I/O request is a reply that @value{GDBN} has to expect as a result
30946 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
30947 This @code{F} packet contains all information needed to allow @value{GDBN}
30948 to call the appropriate host system call:
30949
30950 @itemize @bullet
30951 @item
30952 A unique identifier for the requested system call.
30953
30954 @item
30955 All parameters to the system call. Pointers are given as addresses
30956 in the target memory address space. Pointers to strings are given as
30957 pointer/length pair. Numerical values are given as they are.
30958 Numerical control flags are given in a protocol-specific representation.
30959
30960 @end itemize
30961
30962 At this point, @value{GDBN} has to perform the following actions.
30963
30964 @itemize @bullet
30965 @item
30966 If the parameters include pointer values to data needed as input to a
30967 system call, @value{GDBN} requests this data from the target with a
30968 standard @code{m} packet request. This additional communication has to be
30969 expected by the target implementation and is handled as any other @code{m}
30970 packet.
30971
30972 @item
30973 @value{GDBN} translates all value from protocol representation to host
30974 representation as needed. Datatypes are coerced into the host types.
30975
30976 @item
30977 @value{GDBN} calls the system call.
30978
30979 @item
30980 It then coerces datatypes back to protocol representation.
30981
30982 @item
30983 If the system call is expected to return data in buffer space specified
30984 by pointer parameters to the call, the data is transmitted to the
30985 target using a @code{M} or @code{X} packet. This packet has to be expected
30986 by the target implementation and is handled as any other @code{M} or @code{X}
30987 packet.
30988
30989 @end itemize
30990
30991 Eventually @value{GDBN} replies with another @code{F} packet which contains all
30992 necessary information for the target to continue. This at least contains
30993
30994 @itemize @bullet
30995 @item
30996 Return value.
30997
30998 @item
30999 @code{errno}, if has been changed by the system call.
31000
31001 @item
31002 ``Ctrl-C'' flag.
31003
31004 @end itemize
31005
31006 After having done the needed type and value coercion, the target continues
31007 the latest continue or step action.
31008
31009 @node The F Request Packet
31010 @subsection The @code{F} Request Packet
31011 @cindex file-i/o request packet
31012 @cindex @code{F} request packet
31013
31014 The @code{F} request packet has the following format:
31015
31016 @table @samp
31017 @item F@var{call-id},@var{parameter@dots{}}
31018
31019 @var{call-id} is the identifier to indicate the host system call to be called.
31020 This is just the name of the function.
31021
31022 @var{parameter@dots{}} are the parameters to the system call.
31023 Parameters are hexadecimal integer values, either the actual values in case
31024 of scalar datatypes, pointers to target buffer space in case of compound
31025 datatypes and unspecified memory areas, or pointer/length pairs in case
31026 of string parameters. These are appended to the @var{call-id} as a
31027 comma-delimited list. All values are transmitted in ASCII
31028 string representation, pointer/length pairs separated by a slash.
31029
31030 @end table
31031
31032
31033
31034 @node The F Reply Packet
31035 @subsection The @code{F} Reply Packet
31036 @cindex file-i/o reply packet
31037 @cindex @code{F} reply packet
31038
31039 The @code{F} reply packet has the following format:
31040
31041 @table @samp
31042
31043 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
31044
31045 @var{retcode} is the return code of the system call as hexadecimal value.
31046
31047 @var{errno} is the @code{errno} set by the call, in protocol-specific
31048 representation.
31049 This parameter can be omitted if the call was successful.
31050
31051 @var{Ctrl-C flag} is only sent if the user requested a break. In this
31052 case, @var{errno} must be sent as well, even if the call was successful.
31053 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
31054
31055 @smallexample
31056 F0,0,C
31057 @end smallexample
31058
31059 @noindent
31060 or, if the call was interrupted before the host call has been performed:
31061
31062 @smallexample
31063 F-1,4,C
31064 @end smallexample
31065
31066 @noindent
31067 assuming 4 is the protocol-specific representation of @code{EINTR}.
31068
31069 @end table
31070
31071
31072 @node The Ctrl-C Message
31073 @subsection The @samp{Ctrl-C} Message
31074 @cindex ctrl-c message, in file-i/o protocol
31075
31076 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
31077 reply packet (@pxref{The F Reply Packet}),
31078 the target should behave as if it had
31079 gotten a break message. The meaning for the target is ``system call
31080 interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
31081 (as with a break message) and return to @value{GDBN} with a @code{T02}
31082 packet.
31083
31084 It's important for the target to know in which
31085 state the system call was interrupted. There are two possible cases:
31086
31087 @itemize @bullet
31088 @item
31089 The system call hasn't been performed on the host yet.
31090
31091 @item
31092 The system call on the host has been finished.
31093
31094 @end itemize
31095
31096 These two states can be distinguished by the target by the value of the
31097 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
31098 call hasn't been performed. This is equivalent to the @code{EINTR} handling
31099 on POSIX systems. In any other case, the target may presume that the
31100 system call has been finished --- successfully or not --- and should behave
31101 as if the break message arrived right after the system call.
31102
31103 @value{GDBN} must behave reliably. If the system call has not been called
31104 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
31105 @code{errno} in the packet. If the system call on the host has been finished
31106 before the user requests a break, the full action must be finished by
31107 @value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
31108 The @code{F} packet may only be sent when either nothing has happened
31109 or the full action has been completed.
31110
31111 @node Console I/O
31112 @subsection Console I/O
31113 @cindex console i/o as part of file-i/o
31114
31115 By default and if not explicitly closed by the target system, the file
31116 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
31117 on the @value{GDBN} console is handled as any other file output operation
31118 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
31119 by @value{GDBN} so that after the target read request from file descriptor
31120 0 all following typing is buffered until either one of the following
31121 conditions is met:
31122
31123 @itemize @bullet
31124 @item
31125 The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
31126 @code{read}
31127 system call is treated as finished.
31128
31129 @item
31130 The user presses @key{RET}. This is treated as end of input with a trailing
31131 newline.
31132
31133 @item
31134 The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
31135 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
31136
31137 @end itemize
31138
31139 If the user has typed more characters than fit in the buffer given to
31140 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
31141 either another @code{read(0, @dots{})} is requested by the target, or debugging
31142 is stopped at the user's request.
31143
31144
31145 @node List of Supported Calls
31146 @subsection List of Supported Calls
31147 @cindex list of supported file-i/o calls
31148
31149 @menu
31150 * open::
31151 * close::
31152 * read::
31153 * write::
31154 * lseek::
31155 * rename::
31156 * unlink::
31157 * stat/fstat::
31158 * gettimeofday::
31159 * isatty::
31160 * system::
31161 @end menu
31162
31163 @node open
31164 @unnumberedsubsubsec open
31165 @cindex open, file-i/o system call
31166
31167 @table @asis
31168 @item Synopsis:
31169 @smallexample
31170 int open(const char *pathname, int flags);
31171 int open(const char *pathname, int flags, mode_t mode);
31172 @end smallexample
31173
31174 @item Request:
31175 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
31176
31177 @noindent
31178 @var{flags} is the bitwise @code{OR} of the following values:
31179
31180 @table @code
31181 @item O_CREAT
31182 If the file does not exist it will be created. The host
31183 rules apply as far as file ownership and time stamps
31184 are concerned.
31185
31186 @item O_EXCL
31187 When used with @code{O_CREAT}, if the file already exists it is
31188 an error and open() fails.
31189
31190 @item O_TRUNC
31191 If the file already exists and the open mode allows
31192 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
31193 truncated to zero length.
31194
31195 @item O_APPEND
31196 The file is opened in append mode.
31197
31198 @item O_RDONLY
31199 The file is opened for reading only.
31200
31201 @item O_WRONLY
31202 The file is opened for writing only.
31203
31204 @item O_RDWR
31205 The file is opened for reading and writing.
31206 @end table
31207
31208 @noindent
31209 Other bits are silently ignored.
31210
31211
31212 @noindent
31213 @var{mode} is the bitwise @code{OR} of the following values:
31214
31215 @table @code
31216 @item S_IRUSR
31217 User has read permission.
31218
31219 @item S_IWUSR
31220 User has write permission.
31221
31222 @item S_IRGRP
31223 Group has read permission.
31224
31225 @item S_IWGRP
31226 Group has write permission.
31227
31228 @item S_IROTH
31229 Others have read permission.
31230
31231 @item S_IWOTH
31232 Others have write permission.
31233 @end table
31234
31235 @noindent
31236 Other bits are silently ignored.
31237
31238
31239 @item Return value:
31240 @code{open} returns the new file descriptor or -1 if an error
31241 occurred.
31242
31243 @item Errors:
31244
31245 @table @code
31246 @item EEXIST
31247 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
31248
31249 @item EISDIR
31250 @var{pathname} refers to a directory.
31251
31252 @item EACCES
31253 The requested access is not allowed.
31254
31255 @item ENAMETOOLONG
31256 @var{pathname} was too long.
31257
31258 @item ENOENT
31259 A directory component in @var{pathname} does not exist.
31260
31261 @item ENODEV
31262 @var{pathname} refers to a device, pipe, named pipe or socket.
31263
31264 @item EROFS
31265 @var{pathname} refers to a file on a read-only filesystem and
31266 write access was requested.
31267
31268 @item EFAULT
31269 @var{pathname} is an invalid pointer value.
31270
31271 @item ENOSPC
31272 No space on device to create the file.
31273
31274 @item EMFILE
31275 The process already has the maximum number of files open.
31276
31277 @item ENFILE
31278 The limit on the total number of files open on the system
31279 has been reached.
31280
31281 @item EINTR
31282 The call was interrupted by the user.
31283 @end table
31284
31285 @end table
31286
31287 @node close
31288 @unnumberedsubsubsec close
31289 @cindex close, file-i/o system call
31290
31291 @table @asis
31292 @item Synopsis:
31293 @smallexample
31294 int close(int fd);
31295 @end smallexample
31296
31297 @item Request:
31298 @samp{Fclose,@var{fd}}
31299
31300 @item Return value:
31301 @code{close} returns zero on success, or -1 if an error occurred.
31302
31303 @item Errors:
31304
31305 @table @code
31306 @item EBADF
31307 @var{fd} isn't a valid open file descriptor.
31308
31309 @item EINTR
31310 The call was interrupted by the user.
31311 @end table
31312
31313 @end table
31314
31315 @node read
31316 @unnumberedsubsubsec read
31317 @cindex read, file-i/o system call
31318
31319 @table @asis
31320 @item Synopsis:
31321 @smallexample
31322 int read(int fd, void *buf, unsigned int count);
31323 @end smallexample
31324
31325 @item Request:
31326 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
31327
31328 @item Return value:
31329 On success, the number of bytes read is returned.
31330 Zero indicates end of file. If count is zero, read
31331 returns zero as well. On error, -1 is returned.
31332
31333 @item Errors:
31334
31335 @table @code
31336 @item EBADF
31337 @var{fd} is not a valid file descriptor or is not open for
31338 reading.
31339
31340 @item EFAULT
31341 @var{bufptr} is an invalid pointer value.
31342
31343 @item EINTR
31344 The call was interrupted by the user.
31345 @end table
31346
31347 @end table
31348
31349 @node write
31350 @unnumberedsubsubsec write
31351 @cindex write, file-i/o system call
31352
31353 @table @asis
31354 @item Synopsis:
31355 @smallexample
31356 int write(int fd, const void *buf, unsigned int count);
31357 @end smallexample
31358
31359 @item Request:
31360 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
31361
31362 @item Return value:
31363 On success, the number of bytes written are returned.
31364 Zero indicates nothing was written. On error, -1
31365 is returned.
31366
31367 @item Errors:
31368
31369 @table @code
31370 @item EBADF
31371 @var{fd} is not a valid file descriptor or is not open for
31372 writing.
31373
31374 @item EFAULT
31375 @var{bufptr} is an invalid pointer value.
31376
31377 @item EFBIG
31378 An attempt was made to write a file that exceeds the
31379 host-specific maximum file size allowed.
31380
31381 @item ENOSPC
31382 No space on device to write the data.
31383
31384 @item EINTR
31385 The call was interrupted by the user.
31386 @end table
31387
31388 @end table
31389
31390 @node lseek
31391 @unnumberedsubsubsec lseek
31392 @cindex lseek, file-i/o system call
31393
31394 @table @asis
31395 @item Synopsis:
31396 @smallexample
31397 long lseek (int fd, long offset, int flag);
31398 @end smallexample
31399
31400 @item Request:
31401 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
31402
31403 @var{flag} is one of:
31404
31405 @table @code
31406 @item SEEK_SET
31407 The offset is set to @var{offset} bytes.
31408
31409 @item SEEK_CUR
31410 The offset is set to its current location plus @var{offset}
31411 bytes.
31412
31413 @item SEEK_END
31414 The offset is set to the size of the file plus @var{offset}
31415 bytes.
31416 @end table
31417
31418 @item Return value:
31419 On success, the resulting unsigned offset in bytes from
31420 the beginning of the file is returned. Otherwise, a
31421 value of -1 is returned.
31422
31423 @item Errors:
31424
31425 @table @code
31426 @item EBADF
31427 @var{fd} is not a valid open file descriptor.
31428
31429 @item ESPIPE
31430 @var{fd} is associated with the @value{GDBN} console.
31431
31432 @item EINVAL
31433 @var{flag} is not a proper value.
31434
31435 @item EINTR
31436 The call was interrupted by the user.
31437 @end table
31438
31439 @end table
31440
31441 @node rename
31442 @unnumberedsubsubsec rename
31443 @cindex rename, file-i/o system call
31444
31445 @table @asis
31446 @item Synopsis:
31447 @smallexample
31448 int rename(const char *oldpath, const char *newpath);
31449 @end smallexample
31450
31451 @item Request:
31452 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
31453
31454 @item Return value:
31455 On success, zero is returned. On error, -1 is returned.
31456
31457 @item Errors:
31458
31459 @table @code
31460 @item EISDIR
31461 @var{newpath} is an existing directory, but @var{oldpath} is not a
31462 directory.
31463
31464 @item EEXIST
31465 @var{newpath} is a non-empty directory.
31466
31467 @item EBUSY
31468 @var{oldpath} or @var{newpath} is a directory that is in use by some
31469 process.
31470
31471 @item EINVAL
31472 An attempt was made to make a directory a subdirectory
31473 of itself.
31474
31475 @item ENOTDIR
31476 A component used as a directory in @var{oldpath} or new
31477 path is not a directory. Or @var{oldpath} is a directory
31478 and @var{newpath} exists but is not a directory.
31479
31480 @item EFAULT
31481 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
31482
31483 @item EACCES
31484 No access to the file or the path of the file.
31485
31486 @item ENAMETOOLONG
31487
31488 @var{oldpath} or @var{newpath} was too long.
31489
31490 @item ENOENT
31491 A directory component in @var{oldpath} or @var{newpath} does not exist.
31492
31493 @item EROFS
31494 The file is on a read-only filesystem.
31495
31496 @item ENOSPC
31497 The device containing the file has no room for the new
31498 directory entry.
31499
31500 @item EINTR
31501 The call was interrupted by the user.
31502 @end table
31503
31504 @end table
31505
31506 @node unlink
31507 @unnumberedsubsubsec unlink
31508 @cindex unlink, file-i/o system call
31509
31510 @table @asis
31511 @item Synopsis:
31512 @smallexample
31513 int unlink(const char *pathname);
31514 @end smallexample
31515
31516 @item Request:
31517 @samp{Funlink,@var{pathnameptr}/@var{len}}
31518
31519 @item Return value:
31520 On success, zero is returned. On error, -1 is returned.
31521
31522 @item Errors:
31523
31524 @table @code
31525 @item EACCES
31526 No access to the file or the path of the file.
31527
31528 @item EPERM
31529 The system does not allow unlinking of directories.
31530
31531 @item EBUSY
31532 The file @var{pathname} cannot be unlinked because it's
31533 being used by another process.
31534
31535 @item EFAULT
31536 @var{pathnameptr} is an invalid pointer value.
31537
31538 @item ENAMETOOLONG
31539 @var{pathname} was too long.
31540
31541 @item ENOENT
31542 A directory component in @var{pathname} does not exist.
31543
31544 @item ENOTDIR
31545 A component of the path is not a directory.
31546
31547 @item EROFS
31548 The file is on a read-only filesystem.
31549
31550 @item EINTR
31551 The call was interrupted by the user.
31552 @end table
31553
31554 @end table
31555
31556 @node stat/fstat
31557 @unnumberedsubsubsec stat/fstat
31558 @cindex fstat, file-i/o system call
31559 @cindex stat, file-i/o system call
31560
31561 @table @asis
31562 @item Synopsis:
31563 @smallexample
31564 int stat(const char *pathname, struct stat *buf);
31565 int fstat(int fd, struct stat *buf);
31566 @end smallexample
31567
31568 @item Request:
31569 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
31570 @samp{Ffstat,@var{fd},@var{bufptr}}
31571
31572 @item Return value:
31573 On success, zero is returned. On error, -1 is returned.
31574
31575 @item Errors:
31576
31577 @table @code
31578 @item EBADF
31579 @var{fd} is not a valid open file.
31580
31581 @item ENOENT
31582 A directory component in @var{pathname} does not exist or the
31583 path is an empty string.
31584
31585 @item ENOTDIR
31586 A component of the path is not a directory.
31587
31588 @item EFAULT
31589 @var{pathnameptr} is an invalid pointer value.
31590
31591 @item EACCES
31592 No access to the file or the path of the file.
31593
31594 @item ENAMETOOLONG
31595 @var{pathname} was too long.
31596
31597 @item EINTR
31598 The call was interrupted by the user.
31599 @end table
31600
31601 @end table
31602
31603 @node gettimeofday
31604 @unnumberedsubsubsec gettimeofday
31605 @cindex gettimeofday, file-i/o system call
31606
31607 @table @asis
31608 @item Synopsis:
31609 @smallexample
31610 int gettimeofday(struct timeval *tv, void *tz);
31611 @end smallexample
31612
31613 @item Request:
31614 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
31615
31616 @item Return value:
31617 On success, 0 is returned, -1 otherwise.
31618
31619 @item Errors:
31620
31621 @table @code
31622 @item EINVAL
31623 @var{tz} is a non-NULL pointer.
31624
31625 @item EFAULT
31626 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
31627 @end table
31628
31629 @end table
31630
31631 @node isatty
31632 @unnumberedsubsubsec isatty
31633 @cindex isatty, file-i/o system call
31634
31635 @table @asis
31636 @item Synopsis:
31637 @smallexample
31638 int isatty(int fd);
31639 @end smallexample
31640
31641 @item Request:
31642 @samp{Fisatty,@var{fd}}
31643
31644 @item Return value:
31645 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
31646
31647 @item Errors:
31648
31649 @table @code
31650 @item EINTR
31651 The call was interrupted by the user.
31652 @end table
31653
31654 @end table
31655
31656 Note that the @code{isatty} call is treated as a special case: it returns
31657 1 to the target if the file descriptor is attached
31658 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
31659 would require implementing @code{ioctl} and would be more complex than
31660 needed.
31661
31662
31663 @node system
31664 @unnumberedsubsubsec system
31665 @cindex system, file-i/o system call
31666
31667 @table @asis
31668 @item Synopsis:
31669 @smallexample
31670 int system(const char *command);
31671 @end smallexample
31672
31673 @item Request:
31674 @samp{Fsystem,@var{commandptr}/@var{len}}
31675
31676 @item Return value:
31677 If @var{len} is zero, the return value indicates whether a shell is
31678 available. A zero return value indicates a shell is not available.
31679 For non-zero @var{len}, the value returned is -1 on error and the
31680 return status of the command otherwise. Only the exit status of the
31681 command is returned, which is extracted from the host's @code{system}
31682 return value by calling @code{WEXITSTATUS(retval)}. In case
31683 @file{/bin/sh} could not be executed, 127 is returned.
31684
31685 @item Errors:
31686
31687 @table @code
31688 @item EINTR
31689 The call was interrupted by the user.
31690 @end table
31691
31692 @end table
31693
31694 @value{GDBN} takes over the full task of calling the necessary host calls
31695 to perform the @code{system} call. The return value of @code{system} on
31696 the host is simplified before it's returned
31697 to the target. Any termination signal information from the child process
31698 is discarded, and the return value consists
31699 entirely of the exit status of the called command.
31700
31701 Due to security concerns, the @code{system} call is by default refused
31702 by @value{GDBN}. The user has to allow this call explicitly with the
31703 @code{set remote system-call-allowed 1} command.
31704
31705 @table @code
31706 @item set remote system-call-allowed
31707 @kindex set remote system-call-allowed
31708 Control whether to allow the @code{system} calls in the File I/O
31709 protocol for the remote target. The default is zero (disabled).
31710
31711 @item show remote system-call-allowed
31712 @kindex show remote system-call-allowed
31713 Show whether the @code{system} calls are allowed in the File I/O
31714 protocol.
31715 @end table
31716
31717 @node Protocol-specific Representation of Datatypes
31718 @subsection Protocol-specific Representation of Datatypes
31719 @cindex protocol-specific representation of datatypes, in file-i/o protocol
31720
31721 @menu
31722 * Integral Datatypes::
31723 * Pointer Values::
31724 * Memory Transfer::
31725 * struct stat::
31726 * struct timeval::
31727 @end menu
31728
31729 @node Integral Datatypes
31730 @unnumberedsubsubsec Integral Datatypes
31731 @cindex integral datatypes, in file-i/o protocol
31732
31733 The integral datatypes used in the system calls are @code{int},
31734 @code{unsigned int}, @code{long}, @code{unsigned long},
31735 @code{mode_t}, and @code{time_t}.
31736
31737 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
31738 implemented as 32 bit values in this protocol.
31739
31740 @code{long} and @code{unsigned long} are implemented as 64 bit types.
31741
31742 @xref{Limits}, for corresponding MIN and MAX values (similar to those
31743 in @file{limits.h}) to allow range checking on host and target.
31744
31745 @code{time_t} datatypes are defined as seconds since the Epoch.
31746
31747 All integral datatypes transferred as part of a memory read or write of a
31748 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
31749 byte order.
31750
31751 @node Pointer Values
31752 @unnumberedsubsubsec Pointer Values
31753 @cindex pointer values, in file-i/o protocol
31754
31755 Pointers to target data are transmitted as they are. An exception
31756 is made for pointers to buffers for which the length isn't
31757 transmitted as part of the function call, namely strings. Strings
31758 are transmitted as a pointer/length pair, both as hex values, e.g.@:
31759
31760 @smallexample
31761 @code{1aaf/12}
31762 @end smallexample
31763
31764 @noindent
31765 which is a pointer to data of length 18 bytes at position 0x1aaf.
31766 The length is defined as the full string length in bytes, including
31767 the trailing null byte. For example, the string @code{"hello world"}
31768 at address 0x123456 is transmitted as
31769
31770 @smallexample
31771 @code{123456/d}
31772 @end smallexample
31773
31774 @node Memory Transfer
31775 @unnumberedsubsubsec Memory Transfer
31776 @cindex memory transfer, in file-i/o protocol
31777
31778 Structured data which is transferred using a memory read or write (for
31779 example, a @code{struct stat}) is expected to be in a protocol-specific format
31780 with all scalar multibyte datatypes being big endian. Translation to
31781 this representation needs to be done both by the target before the @code{F}
31782 packet is sent, and by @value{GDBN} before
31783 it transfers memory to the target. Transferred pointers to structured
31784 data should point to the already-coerced data at any time.
31785
31786
31787 @node struct stat
31788 @unnumberedsubsubsec struct stat
31789 @cindex struct stat, in file-i/o protocol
31790
31791 The buffer of type @code{struct stat} used by the target and @value{GDBN}
31792 is defined as follows:
31793
31794 @smallexample
31795 struct stat @{
31796 unsigned int st_dev; /* device */
31797 unsigned int st_ino; /* inode */
31798 mode_t st_mode; /* protection */
31799 unsigned int st_nlink; /* number of hard links */
31800 unsigned int st_uid; /* user ID of owner */
31801 unsigned int st_gid; /* group ID of owner */
31802 unsigned int st_rdev; /* device type (if inode device) */
31803 unsigned long st_size; /* total size, in bytes */
31804 unsigned long st_blksize; /* blocksize for filesystem I/O */
31805 unsigned long st_blocks; /* number of blocks allocated */
31806 time_t st_atime; /* time of last access */
31807 time_t st_mtime; /* time of last modification */
31808 time_t st_ctime; /* time of last change */
31809 @};
31810 @end smallexample
31811
31812 The integral datatypes conform to the definitions given in the
31813 appropriate section (see @ref{Integral Datatypes}, for details) so this
31814 structure is of size 64 bytes.
31815
31816 The values of several fields have a restricted meaning and/or
31817 range of values.
31818
31819 @table @code
31820
31821 @item st_dev
31822 A value of 0 represents a file, 1 the console.
31823
31824 @item st_ino
31825 No valid meaning for the target. Transmitted unchanged.
31826
31827 @item st_mode
31828 Valid mode bits are described in @ref{Constants}. Any other
31829 bits have currently no meaning for the target.
31830
31831 @item st_uid
31832 @itemx st_gid
31833 @itemx st_rdev
31834 No valid meaning for the target. Transmitted unchanged.
31835
31836 @item st_atime
31837 @itemx st_mtime
31838 @itemx st_ctime
31839 These values have a host and file system dependent
31840 accuracy. Especially on Windows hosts, the file system may not
31841 support exact timing values.
31842 @end table
31843
31844 The target gets a @code{struct stat} of the above representation and is
31845 responsible for coercing it to the target representation before
31846 continuing.
31847
31848 Note that due to size differences between the host, target, and protocol
31849 representations of @code{struct stat} members, these members could eventually
31850 get truncated on the target.
31851
31852 @node struct timeval
31853 @unnumberedsubsubsec struct timeval
31854 @cindex struct timeval, in file-i/o protocol
31855
31856 The buffer of type @code{struct timeval} used by the File-I/O protocol
31857 is defined as follows:
31858
31859 @smallexample
31860 struct timeval @{
31861 time_t tv_sec; /* second */
31862 long tv_usec; /* microsecond */
31863 @};
31864 @end smallexample
31865
31866 The integral datatypes conform to the definitions given in the
31867 appropriate section (see @ref{Integral Datatypes}, for details) so this
31868 structure is of size 8 bytes.
31869
31870 @node Constants
31871 @subsection Constants
31872 @cindex constants, in file-i/o protocol
31873
31874 The following values are used for the constants inside of the
31875 protocol. @value{GDBN} and target are responsible for translating these
31876 values before and after the call as needed.
31877
31878 @menu
31879 * Open Flags::
31880 * mode_t Values::
31881 * Errno Values::
31882 * Lseek Flags::
31883 * Limits::
31884 @end menu
31885
31886 @node Open Flags
31887 @unnumberedsubsubsec Open Flags
31888 @cindex open flags, in file-i/o protocol
31889
31890 All values are given in hexadecimal representation.
31891
31892 @smallexample
31893 O_RDONLY 0x0
31894 O_WRONLY 0x1
31895 O_RDWR 0x2
31896 O_APPEND 0x8
31897 O_CREAT 0x200
31898 O_TRUNC 0x400
31899 O_EXCL 0x800
31900 @end smallexample
31901
31902 @node mode_t Values
31903 @unnumberedsubsubsec mode_t Values
31904 @cindex mode_t values, in file-i/o protocol
31905
31906 All values are given in octal representation.
31907
31908 @smallexample
31909 S_IFREG 0100000
31910 S_IFDIR 040000
31911 S_IRUSR 0400
31912 S_IWUSR 0200
31913 S_IXUSR 0100
31914 S_IRGRP 040
31915 S_IWGRP 020
31916 S_IXGRP 010
31917 S_IROTH 04
31918 S_IWOTH 02
31919 S_IXOTH 01
31920 @end smallexample
31921
31922 @node Errno Values
31923 @unnumberedsubsubsec Errno Values
31924 @cindex errno values, in file-i/o protocol
31925
31926 All values are given in decimal representation.
31927
31928 @smallexample
31929 EPERM 1
31930 ENOENT 2
31931 EINTR 4
31932 EBADF 9
31933 EACCES 13
31934 EFAULT 14
31935 EBUSY 16
31936 EEXIST 17
31937 ENODEV 19
31938 ENOTDIR 20
31939 EISDIR 21
31940 EINVAL 22
31941 ENFILE 23
31942 EMFILE 24
31943 EFBIG 27
31944 ENOSPC 28
31945 ESPIPE 29
31946 EROFS 30
31947 ENAMETOOLONG 91
31948 EUNKNOWN 9999
31949 @end smallexample
31950
31951 @code{EUNKNOWN} is used as a fallback error value if a host system returns
31952 any error value not in the list of supported error numbers.
31953
31954 @node Lseek Flags
31955 @unnumberedsubsubsec Lseek Flags
31956 @cindex lseek flags, in file-i/o protocol
31957
31958 @smallexample
31959 SEEK_SET 0
31960 SEEK_CUR 1
31961 SEEK_END 2
31962 @end smallexample
31963
31964 @node Limits
31965 @unnumberedsubsubsec Limits
31966 @cindex limits, in file-i/o protocol
31967
31968 All values are given in decimal representation.
31969
31970 @smallexample
31971 INT_MIN -2147483648
31972 INT_MAX 2147483647
31973 UINT_MAX 4294967295
31974 LONG_MIN -9223372036854775808
31975 LONG_MAX 9223372036854775807
31976 ULONG_MAX 18446744073709551615
31977 @end smallexample
31978
31979 @node File-I/O Examples
31980 @subsection File-I/O Examples
31981 @cindex file-i/o examples
31982
31983 Example sequence of a write call, file descriptor 3, buffer is at target
31984 address 0x1234, 6 bytes should be written:
31985
31986 @smallexample
31987 <- @code{Fwrite,3,1234,6}
31988 @emph{request memory read from target}
31989 -> @code{m1234,6}
31990 <- XXXXXX
31991 @emph{return "6 bytes written"}
31992 -> @code{F6}
31993 @end smallexample
31994
31995 Example sequence of a read call, file descriptor 3, buffer is at target
31996 address 0x1234, 6 bytes should be read:
31997
31998 @smallexample
31999 <- @code{Fread,3,1234,6}
32000 @emph{request memory write to target}
32001 -> @code{X1234,6:XXXXXX}
32002 @emph{return "6 bytes read"}
32003 -> @code{F6}
32004 @end smallexample
32005
32006 Example sequence of a read call, call fails on the host due to invalid
32007 file descriptor (@code{EBADF}):
32008
32009 @smallexample
32010 <- @code{Fread,3,1234,6}
32011 -> @code{F-1,9}
32012 @end smallexample
32013
32014 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
32015 host is called:
32016
32017 @smallexample
32018 <- @code{Fread,3,1234,6}
32019 -> @code{F-1,4,C}
32020 <- @code{T02}
32021 @end smallexample
32022
32023 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
32024 host is called:
32025
32026 @smallexample
32027 <- @code{Fread,3,1234,6}
32028 -> @code{X1234,6:XXXXXX}
32029 <- @code{T02}
32030 @end smallexample
32031
32032 @node Library List Format
32033 @section Library List Format
32034 @cindex library list format, remote protocol
32035
32036 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
32037 same process as your application to manage libraries. In this case,
32038 @value{GDBN} can use the loader's symbol table and normal memory
32039 operations to maintain a list of shared libraries. On other
32040 platforms, the operating system manages loaded libraries.
32041 @value{GDBN} can not retrieve the list of currently loaded libraries
32042 through memory operations, so it uses the @samp{qXfer:libraries:read}
32043 packet (@pxref{qXfer library list read}) instead. The remote stub
32044 queries the target's operating system and reports which libraries
32045 are loaded.
32046
32047 The @samp{qXfer:libraries:read} packet returns an XML document which
32048 lists loaded libraries and their offsets. Each library has an
32049 associated name and one or more segment or section base addresses,
32050 which report where the library was loaded in memory.
32051
32052 For the common case of libraries that are fully linked binaries, the
32053 library should have a list of segments. If the target supports
32054 dynamic linking of a relocatable object file, its library XML element
32055 should instead include a list of allocated sections. The segment or
32056 section bases are start addresses, not relocation offsets; they do not
32057 depend on the library's link-time base addresses.
32058
32059 @value{GDBN} must be linked with the Expat library to support XML
32060 library lists. @xref{Expat}.
32061
32062 A simple memory map, with one loaded library relocated by a single
32063 offset, looks like this:
32064
32065 @smallexample
32066 <library-list>
32067 <library name="/lib/libc.so.6">
32068 <segment address="0x10000000"/>
32069 </library>
32070 </library-list>
32071 @end smallexample
32072
32073 Another simple memory map, with one loaded library with three
32074 allocated sections (.text, .data, .bss), looks like this:
32075
32076 @smallexample
32077 <library-list>
32078 <library name="sharedlib.o">
32079 <section address="0x10000000"/>
32080 <section address="0x20000000"/>
32081 <section address="0x30000000"/>
32082 </library>
32083 </library-list>
32084 @end smallexample
32085
32086 The format of a library list is described by this DTD:
32087
32088 @smallexample
32089 <!-- library-list: Root element with versioning -->
32090 <!ELEMENT library-list (library)*>
32091 <!ATTLIST library-list version CDATA #FIXED "1.0">
32092 <!ELEMENT library (segment*, section*)>
32093 <!ATTLIST library name CDATA #REQUIRED>
32094 <!ELEMENT segment EMPTY>
32095 <!ATTLIST segment address CDATA #REQUIRED>
32096 <!ELEMENT section EMPTY>
32097 <!ATTLIST section address CDATA #REQUIRED>
32098 @end smallexample
32099
32100 In addition, segments and section descriptors cannot be mixed within a
32101 single library element, and you must supply at least one segment or
32102 section for each library.
32103
32104 @node Memory Map Format
32105 @section Memory Map Format
32106 @cindex memory map format
32107
32108 To be able to write into flash memory, @value{GDBN} needs to obtain a
32109 memory map from the target. This section describes the format of the
32110 memory map.
32111
32112 The memory map is obtained using the @samp{qXfer:memory-map:read}
32113 (@pxref{qXfer memory map read}) packet and is an XML document that
32114 lists memory regions.
32115
32116 @value{GDBN} must be linked with the Expat library to support XML
32117 memory maps. @xref{Expat}.
32118
32119 The top-level structure of the document is shown below:
32120
32121 @smallexample
32122 <?xml version="1.0"?>
32123 <!DOCTYPE memory-map
32124 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
32125 "http://sourceware.org/gdb/gdb-memory-map.dtd">
32126 <memory-map>
32127 region...
32128 </memory-map>
32129 @end smallexample
32130
32131 Each region can be either:
32132
32133 @itemize
32134
32135 @item
32136 A region of RAM starting at @var{addr} and extending for @var{length}
32137 bytes from there:
32138
32139 @smallexample
32140 <memory type="ram" start="@var{addr}" length="@var{length}"/>
32141 @end smallexample
32142
32143
32144 @item
32145 A region of read-only memory:
32146
32147 @smallexample
32148 <memory type="rom" start="@var{addr}" length="@var{length}"/>
32149 @end smallexample
32150
32151
32152 @item
32153 A region of flash memory, with erasure blocks @var{blocksize}
32154 bytes in length:
32155
32156 @smallexample
32157 <memory type="flash" start="@var{addr}" length="@var{length}">
32158 <property name="blocksize">@var{blocksize}</property>
32159 </memory>
32160 @end smallexample
32161
32162 @end itemize
32163
32164 Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
32165 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
32166 packets to write to addresses in such ranges.
32167
32168 The formal DTD for memory map format is given below:
32169
32170 @smallexample
32171 <!-- ................................................... -->
32172 <!-- Memory Map XML DTD ................................ -->
32173 <!-- File: memory-map.dtd .............................. -->
32174 <!-- .................................... .............. -->
32175 <!-- memory-map.dtd -->
32176 <!-- memory-map: Root element with versioning -->
32177 <!ELEMENT memory-map (memory | property)>
32178 <!ATTLIST memory-map version CDATA #FIXED "1.0.0">
32179 <!ELEMENT memory (property)>
32180 <!-- memory: Specifies a memory region,
32181 and its type, or device. -->
32182 <!ATTLIST memory type CDATA #REQUIRED
32183 start CDATA #REQUIRED
32184 length CDATA #REQUIRED
32185 device CDATA #IMPLIED>
32186 <!-- property: Generic attribute tag -->
32187 <!ELEMENT property (#PCDATA | property)*>
32188 <!ATTLIST property name CDATA #REQUIRED>
32189 @end smallexample
32190
32191 @node Thread List Format
32192 @section Thread List Format
32193 @cindex thread list format
32194
32195 To efficiently update the list of threads and their attributes,
32196 @value{GDBN} issues the @samp{qXfer:threads:read} packet
32197 (@pxref{qXfer threads read}) and obtains the XML document with
32198 the following structure:
32199
32200 @smallexample
32201 <?xml version="1.0"?>
32202 <threads>
32203 <thread id="id" core="0">
32204 ... description ...
32205 </thread>
32206 </threads>
32207 @end smallexample
32208
32209 Each @samp{thread} element must have the @samp{id} attribute that
32210 identifies the thread (@pxref{thread-id syntax}). The
32211 @samp{core} attribute, if present, specifies which processor core
32212 the thread was last executing on. The content of the of @samp{thread}
32213 element is interpreted as human-readable auxilliary information.
32214
32215 @include agentexpr.texi
32216
32217 @node Trace File Format
32218 @appendix Trace File Format
32219 @cindex trace file format
32220
32221 The trace file comes in three parts: a header, a textual description
32222 section, and a trace frame section with binary data.
32223
32224 The header has the form @code{\x7fTRACE0\n}. The first byte is
32225 @code{0x7f} so as to indicate that the file contains binary data,
32226 while the @code{0} is a version number that may have different values
32227 in the future.
32228
32229 The description section consists of multiple lines of @sc{ascii} text
32230 separated by newline characters (@code{0xa}). The lines may include a
32231 variety of optional descriptive or context-setting information, such
32232 as tracepoint definitions or register set size. @value{GDBN} will
32233 ignore any line that it does not recognize. An empty line marks the end
32234 of this section.
32235
32236 @c FIXME add some specific types of data
32237
32238 The trace frame section consists of a number of consecutive frames.
32239 Each frame begins with a two-byte tracepoint number, followed by a
32240 four-byte size giving the amount of data in the frame. The data in
32241 the frame consists of a number of blocks, each introduced by a
32242 character indicating its type (at least register, memory, and trace
32243 state variable). The data in this section is raw binary, not a
32244 hexadecimal or other encoding; its endianness matches the target's
32245 endianness.
32246
32247 @c FIXME bi-arch may require endianness/arch info in description section
32248
32249 @table @code
32250 @item R @var{bytes}
32251 Register block. The number and ordering of bytes matches that of a
32252 @code{g} packet in the remote protocol. Note that these are the
32253 actual bytes, in target order and @value{GDBN} register order, not a
32254 hexadecimal encoding.
32255
32256 @item M @var{address} @var{length} @var{bytes}...
32257 Memory block. This is a contiguous block of memory, at the 8-byte
32258 address @var{address}, with a 2-byte length @var{length}, followed by
32259 @var{length} bytes.
32260
32261 @item V @var{number} @var{value}
32262 Trace state variable block. This records the 8-byte signed value
32263 @var{value} of trace state variable numbered @var{number}.
32264
32265 @end table
32266
32267 Future enhancements of the trace file format may include additional types
32268 of blocks.
32269
32270 @node Target Descriptions
32271 @appendix Target Descriptions
32272 @cindex target descriptions
32273
32274 @strong{Warning:} target descriptions are still under active development,
32275 and the contents and format may change between @value{GDBN} releases.
32276 The format is expected to stabilize in the future.
32277
32278 One of the challenges of using @value{GDBN} to debug embedded systems
32279 is that there are so many minor variants of each processor
32280 architecture in use. It is common practice for vendors to start with
32281 a standard processor core --- ARM, PowerPC, or MIPS, for example ---
32282 and then make changes to adapt it to a particular market niche. Some
32283 architectures have hundreds of variants, available from dozens of
32284 vendors. This leads to a number of problems:
32285
32286 @itemize @bullet
32287 @item
32288 With so many different customized processors, it is difficult for
32289 the @value{GDBN} maintainers to keep up with the changes.
32290 @item
32291 Since individual variants may have short lifetimes or limited
32292 audiences, it may not be worthwhile to carry information about every
32293 variant in the @value{GDBN} source tree.
32294 @item
32295 When @value{GDBN} does support the architecture of the embedded system
32296 at hand, the task of finding the correct architecture name to give the
32297 @command{set architecture} command can be error-prone.
32298 @end itemize
32299
32300 To address these problems, the @value{GDBN} remote protocol allows a
32301 target system to not only identify itself to @value{GDBN}, but to
32302 actually describe its own features. This lets @value{GDBN} support
32303 processor variants it has never seen before --- to the extent that the
32304 descriptions are accurate, and that @value{GDBN} understands them.
32305
32306 @value{GDBN} must be linked with the Expat library to support XML
32307 target descriptions. @xref{Expat}.
32308
32309 @menu
32310 * Retrieving Descriptions:: How descriptions are fetched from a target.
32311 * Target Description Format:: The contents of a target description.
32312 * Predefined Target Types:: Standard types available for target
32313 descriptions.
32314 * Standard Target Features:: Features @value{GDBN} knows about.
32315 @end menu
32316
32317 @node Retrieving Descriptions
32318 @section Retrieving Descriptions
32319
32320 Target descriptions can be read from the target automatically, or
32321 specified by the user manually. The default behavior is to read the
32322 description from the target. @value{GDBN} retrieves it via the remote
32323 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
32324 qXfer}). The @var{annex} in the @samp{qXfer} packet will be
32325 @samp{target.xml}. The contents of the @samp{target.xml} annex are an
32326 XML document, of the form described in @ref{Target Description
32327 Format}.
32328
32329 Alternatively, you can specify a file to read for the target description.
32330 If a file is set, the target will not be queried. The commands to
32331 specify a file are:
32332
32333 @table @code
32334 @cindex set tdesc filename
32335 @item set tdesc filename @var{path}
32336 Read the target description from @var{path}.
32337
32338 @cindex unset tdesc filename
32339 @item unset tdesc filename
32340 Do not read the XML target description from a file. @value{GDBN}
32341 will use the description supplied by the current target.
32342
32343 @cindex show tdesc filename
32344 @item show tdesc filename
32345 Show the filename to read for a target description, if any.
32346 @end table
32347
32348
32349 @node Target Description Format
32350 @section Target Description Format
32351 @cindex target descriptions, XML format
32352
32353 A target description annex is an @uref{http://www.w3.org/XML/, XML}
32354 document which complies with the Document Type Definition provided in
32355 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
32356 means you can use generally available tools like @command{xmllint} to
32357 check that your feature descriptions are well-formed and valid.
32358 However, to help people unfamiliar with XML write descriptions for
32359 their targets, we also describe the grammar here.
32360
32361 Target descriptions can identify the architecture of the remote target
32362 and (for some architectures) provide information about custom register
32363 sets. They can also identify the OS ABI of the remote target.
32364 @value{GDBN} can use this information to autoconfigure for your
32365 target, or to warn you if you connect to an unsupported target.
32366
32367 Here is a simple target description:
32368
32369 @smallexample
32370 <target version="1.0">
32371 <architecture>i386:x86-64</architecture>
32372 </target>
32373 @end smallexample
32374
32375 @noindent
32376 This minimal description only says that the target uses
32377 the x86-64 architecture.
32378
32379 A target description has the following overall form, with [ ] marking
32380 optional elements and @dots{} marking repeatable elements. The elements
32381 are explained further below.
32382
32383 @smallexample
32384 <?xml version="1.0"?>
32385 <!DOCTYPE target SYSTEM "gdb-target.dtd">
32386 <target version="1.0">
32387 @r{[}@var{architecture}@r{]}
32388 @r{[}@var{osabi}@r{]}
32389 @r{[}@var{compatible}@r{]}
32390 @r{[}@var{feature}@dots{}@r{]}
32391 </target>
32392 @end smallexample
32393
32394 @noindent
32395 The description is generally insensitive to whitespace and line
32396 breaks, under the usual common-sense rules. The XML version
32397 declaration and document type declaration can generally be omitted
32398 (@value{GDBN} does not require them), but specifying them may be
32399 useful for XML validation tools. The @samp{version} attribute for
32400 @samp{<target>} may also be omitted, but we recommend
32401 including it; if future versions of @value{GDBN} use an incompatible
32402 revision of @file{gdb-target.dtd}, they will detect and report
32403 the version mismatch.
32404
32405 @subsection Inclusion
32406 @cindex target descriptions, inclusion
32407 @cindex XInclude
32408 @ifnotinfo
32409 @cindex <xi:include>
32410 @end ifnotinfo
32411
32412 It can sometimes be valuable to split a target description up into
32413 several different annexes, either for organizational purposes, or to
32414 share files between different possible target descriptions. You can
32415 divide a description into multiple files by replacing any element of
32416 the target description with an inclusion directive of the form:
32417
32418 @smallexample
32419 <xi:include href="@var{document}"/>
32420 @end smallexample
32421
32422 @noindent
32423 When @value{GDBN} encounters an element of this form, it will retrieve
32424 the named XML @var{document}, and replace the inclusion directive with
32425 the contents of that document. If the current description was read
32426 using @samp{qXfer}, then so will be the included document;
32427 @var{document} will be interpreted as the name of an annex. If the
32428 current description was read from a file, @value{GDBN} will look for
32429 @var{document} as a file in the same directory where it found the
32430 original description.
32431
32432 @subsection Architecture
32433 @cindex <architecture>
32434
32435 An @samp{<architecture>} element has this form:
32436
32437 @smallexample
32438 <architecture>@var{arch}</architecture>
32439 @end smallexample
32440
32441 @var{arch} is one of the architectures from the set accepted by
32442 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
32443
32444 @subsection OS ABI
32445 @cindex @code{<osabi>}
32446
32447 This optional field was introduced in @value{GDBN} version 7.0.
32448 Previous versions of @value{GDBN} ignore it.
32449
32450 An @samp{<osabi>} element has this form:
32451
32452 @smallexample
32453 <osabi>@var{abi-name}</osabi>
32454 @end smallexample
32455
32456 @var{abi-name} is an OS ABI name from the same selection accepted by
32457 @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
32458
32459 @subsection Compatible Architecture
32460 @cindex @code{<compatible>}
32461
32462 This optional field was introduced in @value{GDBN} version 7.0.
32463 Previous versions of @value{GDBN} ignore it.
32464
32465 A @samp{<compatible>} element has this form:
32466
32467 @smallexample
32468 <compatible>@var{arch}</compatible>
32469 @end smallexample
32470
32471 @var{arch} is one of the architectures from the set accepted by
32472 @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
32473
32474 A @samp{<compatible>} element is used to specify that the target
32475 is able to run binaries in some other than the main target architecture
32476 given by the @samp{<architecture>} element. For example, on the
32477 Cell Broadband Engine, the main architecture is @code{powerpc:common}
32478 or @code{powerpc:common64}, but the system is able to run binaries
32479 in the @code{spu} architecture as well. The way to describe this
32480 capability with @samp{<compatible>} is as follows:
32481
32482 @smallexample
32483 <architecture>powerpc:common</architecture>
32484 <compatible>spu</compatible>
32485 @end smallexample
32486
32487 @subsection Features
32488 @cindex <feature>
32489
32490 Each @samp{<feature>} describes some logical portion of the target
32491 system. Features are currently used to describe available CPU
32492 registers and the types of their contents. A @samp{<feature>} element
32493 has this form:
32494
32495 @smallexample
32496 <feature name="@var{name}">
32497 @r{[}@var{type}@dots{}@r{]}
32498 @var{reg}@dots{}
32499 </feature>
32500 @end smallexample
32501
32502 @noindent
32503 Each feature's name should be unique within the description. The name
32504 of a feature does not matter unless @value{GDBN} has some special
32505 knowledge of the contents of that feature; if it does, the feature
32506 should have its standard name. @xref{Standard Target Features}.
32507
32508 @subsection Types
32509
32510 Any register's value is a collection of bits which @value{GDBN} must
32511 interpret. The default interpretation is a two's complement integer,
32512 but other types can be requested by name in the register description.
32513 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
32514 Target Types}), and the description can define additional composite types.
32515
32516 Each type element must have an @samp{id} attribute, which gives
32517 a unique (within the containing @samp{<feature>}) name to the type.
32518 Types must be defined before they are used.
32519
32520 @cindex <vector>
32521 Some targets offer vector registers, which can be treated as arrays
32522 of scalar elements. These types are written as @samp{<vector>} elements,
32523 specifying the array element type, @var{type}, and the number of elements,
32524 @var{count}:
32525
32526 @smallexample
32527 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
32528 @end smallexample
32529
32530 @cindex <union>
32531 If a register's value is usefully viewed in multiple ways, define it
32532 with a union type containing the useful representations. The
32533 @samp{<union>} element contains one or more @samp{<field>} elements,
32534 each of which has a @var{name} and a @var{type}:
32535
32536 @smallexample
32537 <union id="@var{id}">
32538 <field name="@var{name}" type="@var{type}"/>
32539 @dots{}
32540 </union>
32541 @end smallexample
32542
32543 @subsection Registers
32544 @cindex <reg>
32545
32546 Each register is represented as an element with this form:
32547
32548 @smallexample
32549 <reg name="@var{name}"
32550 bitsize="@var{size}"
32551 @r{[}regnum="@var{num}"@r{]}
32552 @r{[}save-restore="@var{save-restore}"@r{]}
32553 @r{[}type="@var{type}"@r{]}
32554 @r{[}group="@var{group}"@r{]}/>
32555 @end smallexample
32556
32557 @noindent
32558 The components are as follows:
32559
32560 @table @var
32561
32562 @item name
32563 The register's name; it must be unique within the target description.
32564
32565 @item bitsize
32566 The register's size, in bits.
32567
32568 @item regnum
32569 The register's number. If omitted, a register's number is one greater
32570 than that of the previous register (either in the current feature or in
32571 a preceeding feature); the first register in the target description
32572 defaults to zero. This register number is used to read or write
32573 the register; e.g.@: it is used in the remote @code{p} and @code{P}
32574 packets, and registers appear in the @code{g} and @code{G} packets
32575 in order of increasing register number.
32576
32577 @item save-restore
32578 Whether the register should be preserved across inferior function
32579 calls; this must be either @code{yes} or @code{no}. The default is
32580 @code{yes}, which is appropriate for most registers except for
32581 some system control registers; this is not related to the target's
32582 ABI.
32583
32584 @item type
32585 The type of the register. @var{type} may be a predefined type, a type
32586 defined in the current feature, or one of the special types @code{int}
32587 and @code{float}. @code{int} is an integer type of the correct size
32588 for @var{bitsize}, and @code{float} is a floating point type (in the
32589 architecture's normal floating point format) of the correct size for
32590 @var{bitsize}. The default is @code{int}.
32591
32592 @item group
32593 The register group to which this register belongs. @var{group} must
32594 be either @code{general}, @code{float}, or @code{vector}. If no
32595 @var{group} is specified, @value{GDBN} will not display the register
32596 in @code{info registers}.
32597
32598 @end table
32599
32600 @node Predefined Target Types
32601 @section Predefined Target Types
32602 @cindex target descriptions, predefined types
32603
32604 Type definitions in the self-description can build up composite types
32605 from basic building blocks, but can not define fundamental types. Instead,
32606 standard identifiers are provided by @value{GDBN} for the fundamental
32607 types. The currently supported types are:
32608
32609 @table @code
32610
32611 @item int8
32612 @itemx int16
32613 @itemx int32
32614 @itemx int64
32615 @itemx int128
32616 Signed integer types holding the specified number of bits.
32617
32618 @item uint8
32619 @itemx uint16
32620 @itemx uint32
32621 @itemx uint64
32622 @itemx uint128
32623 Unsigned integer types holding the specified number of bits.
32624
32625 @item code_ptr
32626 @itemx data_ptr
32627 Pointers to unspecified code and data. The program counter and
32628 any dedicated return address register may be marked as code
32629 pointers; printing a code pointer converts it into a symbolic
32630 address. The stack pointer and any dedicated address registers
32631 may be marked as data pointers.
32632
32633 @item ieee_single
32634 Single precision IEEE floating point.
32635
32636 @item ieee_double
32637 Double precision IEEE floating point.
32638
32639 @item arm_fpa_ext
32640 The 12-byte extended precision format used by ARM FPA registers.
32641
32642 @end table
32643
32644 @node Standard Target Features
32645 @section Standard Target Features
32646 @cindex target descriptions, standard features
32647
32648 A target description must contain either no registers or all the
32649 target's registers. If the description contains no registers, then
32650 @value{GDBN} will assume a default register layout, selected based on
32651 the architecture. If the description contains any registers, the
32652 default layout will not be used; the standard registers must be
32653 described in the target description, in such a way that @value{GDBN}
32654 can recognize them.
32655
32656 This is accomplished by giving specific names to feature elements
32657 which contain standard registers. @value{GDBN} will look for features
32658 with those names and verify that they contain the expected registers;
32659 if any known feature is missing required registers, or if any required
32660 feature is missing, @value{GDBN} will reject the target
32661 description. You can add additional registers to any of the
32662 standard features --- @value{GDBN} will display them just as if
32663 they were added to an unrecognized feature.
32664
32665 This section lists the known features and their expected contents.
32666 Sample XML documents for these features are included in the
32667 @value{GDBN} source tree, in the directory @file{gdb/features}.
32668
32669 Names recognized by @value{GDBN} should include the name of the
32670 company or organization which selected the name, and the overall
32671 architecture to which the feature applies; so e.g.@: the feature
32672 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
32673
32674 The names of registers are not case sensitive for the purpose
32675 of recognizing standard features, but @value{GDBN} will only display
32676 registers using the capitalization used in the description.
32677
32678 @menu
32679 * ARM Features::
32680 * MIPS Features::
32681 * M68K Features::
32682 * PowerPC Features::
32683 @end menu
32684
32685
32686 @node ARM Features
32687 @subsection ARM Features
32688 @cindex target descriptions, ARM features
32689
32690 The @samp{org.gnu.gdb.arm.core} feature is required for ARM targets.
32691 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
32692 @samp{lr}, @samp{pc}, and @samp{cpsr}.
32693
32694 The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
32695 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
32696
32697 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
32698 it should contain at least registers @samp{wR0} through @samp{wR15} and
32699 @samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
32700 @samp{wCSSF}, and @samp{wCASF} registers are optional.
32701
32702 The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
32703 should contain at least registers @samp{d0} through @samp{d15}. If
32704 they are present, @samp{d16} through @samp{d31} should also be included.
32705 @value{GDBN} will synthesize the single-precision registers from
32706 halves of the double-precision registers.
32707
32708 The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
32709 need to contain registers; it instructs @value{GDBN} to display the
32710 VFP double-precision registers as vectors and to synthesize the
32711 quad-precision registers from pairs of double-precision registers.
32712 If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
32713 be present and include 32 double-precision registers.
32714
32715 @node MIPS Features
32716 @subsection MIPS Features
32717 @cindex target descriptions, MIPS features
32718
32719 The @samp{org.gnu.gdb.mips.cpu} feature is required for MIPS targets.
32720 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
32721 @samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
32722 on the target.
32723
32724 The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
32725 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
32726 registers. They may be 32-bit or 64-bit depending on the target.
32727
32728 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
32729 it may be optional in a future version of @value{GDBN}. It should
32730 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
32731 @samp{fir}. They may be 32-bit or 64-bit depending on the target.
32732
32733 The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
32734 contain a single register, @samp{restart}, which is used by the
32735 Linux kernel to control restartable syscalls.
32736
32737 @node M68K Features
32738 @subsection M68K Features
32739 @cindex target descriptions, M68K features
32740
32741 @table @code
32742 @item @samp{org.gnu.gdb.m68k.core}
32743 @itemx @samp{org.gnu.gdb.coldfire.core}
32744 @itemx @samp{org.gnu.gdb.fido.core}
32745 One of those features must be always present.
32746 The feature that is present determines which flavor of m68k is
32747 used. The feature that is present should contain registers
32748 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
32749 @samp{sp}, @samp{ps} and @samp{pc}.
32750
32751 @item @samp{org.gnu.gdb.coldfire.fp}
32752 This feature is optional. If present, it should contain registers
32753 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
32754 @samp{fpiaddr}.
32755 @end table
32756
32757 @node PowerPC Features
32758 @subsection PowerPC Features
32759 @cindex target descriptions, PowerPC features
32760
32761 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
32762 targets. It should contain registers @samp{r0} through @samp{r31},
32763 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
32764 @samp{xer}. They may be 32-bit or 64-bit depending on the target.
32765
32766 The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
32767 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
32768
32769 The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
32770 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
32771 and @samp{vrsave}.
32772
32773 The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
32774 contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN}
32775 will combine these registers with the floating point registers
32776 (@samp{f0} through @samp{f31}) and the altivec registers (@samp{vr0}
32777 through @samp{vr31}) to present the 128-bit wide registers @samp{vs0}
32778 through @samp{vs63}, the set of vector registers for POWER7.
32779
32780 The @samp{org.gnu.gdb.power.spe} feature is optional. It should
32781 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
32782 @samp{spefscr}. SPE targets should provide 32-bit registers in
32783 @samp{org.gnu.gdb.power.core} and provide the upper halves in
32784 @samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
32785 these to present registers @samp{ev0} through @samp{ev31} to the
32786 user.
32787
32788 @node Operating System Information
32789 @appendix Operating System Information
32790 @cindex operating system information
32791
32792 @menu
32793 * Process list::
32794 @end menu
32795
32796 Users of @value{GDBN} often wish to obtain information about the state of
32797 the operating system running on the target---for example the list of
32798 processes, or the list of open files. This section describes the
32799 mechanism that makes it possible. This mechanism is similar to the
32800 target features mechanism (@pxref{Target Descriptions}), but focuses
32801 on a different aspect of target.
32802
32803 Operating system information is retrived from the target via the
32804 remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
32805 read}). The object name in the request should be @samp{osdata}, and
32806 the @var{annex} identifies the data to be fetched.
32807
32808 @node Process list
32809 @appendixsection Process list
32810 @cindex operating system information, process list
32811
32812 When requesting the process list, the @var{annex} field in the
32813 @samp{qXfer} request should be @samp{processes}. The returned data is
32814 an XML document. The formal syntax of this document is defined in
32815 @file{gdb/features/osdata.dtd}.
32816
32817 An example document is:
32818
32819 @smallexample
32820 <?xml version="1.0"?>
32821 <!DOCTYPE target SYSTEM "osdata.dtd">
32822 <osdata type="processes">
32823 <item>
32824 <column name="pid">1</column>
32825 <column name="user">root</column>
32826 <column name="command">/sbin/init</column>
32827 <column name="cores">1,2,3</column>
32828 </item>
32829 </osdata>
32830 @end smallexample
32831
32832 Each item should include a column whose name is @samp{pid}. The value
32833 of that column should identify the process on the target. The
32834 @samp{user} and @samp{command} columns are optional, and will be
32835 displayed by @value{GDBN}. The @samp{cores} column, if present,
32836 should contain a comma-separated list of cores that this process
32837 is running on. Target may provide additional columns,
32838 which @value{GDBN} currently ignores.
32839
32840 @include gpl.texi
32841
32842 @raisesections
32843 @include fdl.texi
32844 @lowersections
32845
32846 @node Index
32847 @unnumbered Index
32848
32849 @printindex cp
32850
32851 @tex
32852 % I think something like @colophon should be in texinfo. In the
32853 % meantime:
32854 \long\def\colophon{\hbox to0pt{}\vfill
32855 \centerline{The body of this manual is set in}
32856 \centerline{\fontname\tenrm,}
32857 \centerline{with headings in {\bf\fontname\tenbf}}
32858 \centerline{and examples in {\tt\fontname\tentt}.}
32859 \centerline{{\it\fontname\tenit\/},}
32860 \centerline{{\bf\fontname\tenbf}, and}
32861 \centerline{{\sl\fontname\tensl\/}}
32862 \centerline{are used for emphasis.}\vfill}
32863 \page\colophon
32864 % Blame: doc@cygnus.com, 1991.
32865 @end tex
32866
32867 @bye
This page took 0.748377 seconds and 5 git commands to generate.