* infcmd.c (kill_if_already_running): Make static. Use
[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
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
25 @c readline appendices use @vindex, @findex and @ftable,
26 @c annotate.texi and gdbmi use @findex.
27 @syncodeindex vr cp
28 @syncodeindex fn cp
29
30 @c !!set GDB manual's edition---not the same as GDB version!
31 @c This is updated by GNU Press.
32 @set EDITION Ninth
33
34 @c !!set GDB edit command default editor
35 @set EDITOR /bin/ex
36
37 @c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
38
39 @c This is a dir.info fragment to support semi-automated addition of
40 @c manuals to an info tree.
41 @dircategory Software development
42 @direntry
43 * Gdb: (gdb). The GNU debugger.
44 @end direntry
45
46 @ifinfo
47 This file documents the @sc{gnu} debugger @value{GDBN}.
48
49
50 This is the @value{EDITION} Edition, of @cite{Debugging with
51 @value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
52 Version @value{GDBVN}.
53
54 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998,@*
55 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006@*
56 Free Software Foundation, Inc.
57
58 Permission is granted to copy, distribute and/or modify this document
59 under the terms of the GNU Free Documentation License, Version 1.1 or
60 any later version published by the Free Software Foundation; with the
61 Invariant Sections being ``Free Software'' and ``Free Software Needs
62 Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
63 and with the Back-Cover Texts as in (a) below.
64
65 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
66 this GNU Manual. Buying copies from GNU Press supports the FSF in
67 developing GNU and promoting software freedom.''
68 @end ifinfo
69
70 @titlepage
71 @title Debugging with @value{GDBN}
72 @subtitle The @sc{gnu} Source-Level Debugger
73 @sp 1
74 @subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
75 @author Richard Stallman, Roland Pesch, Stan Shebs, et al.
76 @page
77 @tex
78 {\parskip=0pt
79 \hfill (Send bugs and comments on @value{GDBN} to bug-gdb\@gnu.org.)\par
80 \hfill {\it Debugging with @value{GDBN}}\par
81 \hfill \TeX{}info \texinfoversion\par
82 }
83 @end tex
84
85 @vskip 0pt plus 1filll
86 Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
87 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2006
88 Free Software Foundation, Inc.
89 @sp 2
90 Published by the Free Software Foundation @*
91 51 Franklin Street, Fifth Floor,
92 Boston, MA 02110-1301, USA@*
93 ISBN 1-882114-77-9 @*
94
95 Permission is granted to copy, distribute and/or modify this document
96 under the terms of the GNU Free Documentation License, Version 1.1 or
97 any later version published by the Free Software Foundation; with the
98 Invariant Sections being ``Free Software'' and ``Free Software Needs
99 Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
100 and with the Back-Cover Texts as in (a) below.
101
102 (a) The FSF's Back-Cover Text is: ``You are free to copy and modify
103 this GNU Manual. Buying copies from GNU Press supports the FSF in
104 developing GNU and promoting software freedom.''
105 @page
106 This edition of the GDB manual is dedicated to the memory of Fred
107 Fish. Fred was a long-standing contributor to GDB and to Free
108 software in general. We will miss him.
109 @end titlepage
110 @page
111
112 @ifnottex
113 @node Top, Summary, (dir), (dir)
114
115 @top Debugging with @value{GDBN}
116
117 This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
118
119 This is the @value{EDITION} Edition, for @value{GDBN} Version
120 @value{GDBVN}.
121
122 Copyright (C) 1988-2006 Free Software Foundation, Inc.
123
124 This edition of the GDB manual is dedicated to the memory of Fred
125 Fish. Fred was a long-standing contributor to GDB and to Free
126 software in general. We will miss him.
127
128 @menu
129 * Summary:: Summary of @value{GDBN}
130 * Sample Session:: A sample @value{GDBN} session
131
132 * Invocation:: Getting in and out of @value{GDBN}
133 * Commands:: @value{GDBN} commands
134 * Running:: Running programs under @value{GDBN}
135 * Stopping:: Stopping and continuing
136 * Stack:: Examining the stack
137 * Source:: Examining source files
138 * Data:: Examining data
139 * Macros:: Preprocessor Macros
140 * Tracepoints:: Debugging remote targets non-intrusively
141 * Overlays:: Debugging programs that use overlays
142
143 * Languages:: Using @value{GDBN} with different languages
144
145 * Symbols:: Examining the symbol table
146 * Altering:: Altering execution
147 * GDB Files:: @value{GDBN} files
148 * Targets:: Specifying a debugging target
149 * Remote Debugging:: Debugging remote programs
150 * Configurations:: Configuration-specific information
151 * Controlling GDB:: Controlling @value{GDBN}
152 * Sequences:: Canned sequences of commands
153 * Interpreters:: Command Interpreters
154 * TUI:: @value{GDBN} Text User Interface
155 * Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
156 * GDB/MI:: @value{GDBN}'s Machine Interface.
157 * Annotations:: @value{GDBN}'s annotation interface.
158
159 * GDB Bugs:: Reporting bugs in @value{GDBN}
160
161 * Command Line Editing:: Command Line Editing
162 * Using History Interactively:: Using History Interactively
163 * Formatting Documentation:: How to format and print @value{GDBN} documentation
164 * Installing GDB:: Installing GDB
165 * Maintenance Commands:: Maintenance Commands
166 * Remote Protocol:: GDB Remote Serial Protocol
167 * Agent Expressions:: The GDB Agent Expression Mechanism
168 * Target Descriptions:: How targets can describe themselves to
169 @value{GDBN}
170 * Copying:: GNU General Public License says
171 how you can copy and share GDB
172 * GNU Free Documentation License:: The license for this documentation
173 * Index:: Index
174 @end menu
175
176 @end ifnottex
177
178 @contents
179
180 @node Summary
181 @unnumbered Summary of @value{GDBN}
182
183 The purpose of a debugger such as @value{GDBN} is to allow you to see what is
184 going on ``inside'' another program while it executes---or what another
185 program was doing at the moment it crashed.
186
187 @value{GDBN} can do four main kinds of things (plus other things in support of
188 these) to help you catch bugs in the act:
189
190 @itemize @bullet
191 @item
192 Start your program, specifying anything that might affect its behavior.
193
194 @item
195 Make your program stop on specified conditions.
196
197 @item
198 Examine what has happened, when your program has stopped.
199
200 @item
201 Change things in your program, so you can experiment with correcting the
202 effects of one bug and go on to learn about another.
203 @end itemize
204
205 You can use @value{GDBN} to debug programs written in C and C@t{++}.
206 For more information, see @ref{Supported Languages,,Supported Languages}.
207 For more information, see @ref{C,,C and C++}.
208
209 @cindex Modula-2
210 Support for Modula-2 is partial. For information on Modula-2, see
211 @ref{Modula-2,,Modula-2}.
212
213 @cindex Pascal
214 Debugging Pascal programs which use sets, subranges, file variables, or
215 nested functions does not currently work. @value{GDBN} does not support
216 entering expressions, printing values, or similar features using Pascal
217 syntax.
218
219 @cindex Fortran
220 @value{GDBN} can be used to debug programs written in Fortran, although
221 it may be necessary to refer to some variables with a trailing
222 underscore.
223
224 @value{GDBN} can be used to debug programs written in Objective-C,
225 using either the Apple/NeXT or the GNU Objective-C runtime.
226
227 @menu
228 * Free Software:: Freely redistributable software
229 * Contributors:: Contributors to GDB
230 @end menu
231
232 @node Free Software
233 @unnumberedsec Free Software
234
235 @value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
236 General Public License
237 (GPL). The GPL gives you the freedom to copy or adapt a licensed
238 program---but every person getting a copy also gets with it the
239 freedom to modify that copy (which means that they must get access to
240 the source code), and the freedom to distribute further copies.
241 Typical software companies use copyrights to limit your freedoms; the
242 Free Software Foundation uses the GPL to preserve these freedoms.
243
244 Fundamentally, the General Public License is a license which says that
245 you have these freedoms and that you cannot take these freedoms away
246 from anyone else.
247
248 @unnumberedsec Free Software Needs Free Documentation
249
250 The biggest deficiency in the free software community today is not in
251 the software---it is the lack of good free documentation that we can
252 include with the free software. Many of our most important
253 programs do not come with free reference manuals and free introductory
254 texts. Documentation is an essential part of any software package;
255 when an important free software package does not come with a free
256 manual and a free tutorial, that is a major gap. We have many such
257 gaps today.
258
259 Consider Perl, for instance. The tutorial manuals that people
260 normally use are non-free. How did this come about? Because the
261 authors of those manuals published them with restrictive terms---no
262 copying, no modification, source files not available---which exclude
263 them from the free software world.
264
265 That wasn't the first time this sort of thing happened, and it was far
266 from the last. Many times we have heard a GNU user eagerly describe a
267 manual that he is writing, his intended contribution to the community,
268 only to learn that he had ruined everything by signing a publication
269 contract to make it non-free.
270
271 Free documentation, like free software, is a matter of freedom, not
272 price. The problem with the non-free manual is not that publishers
273 charge a price for printed copies---that in itself is fine. (The Free
274 Software Foundation sells printed copies of manuals, too.) The
275 problem is the restrictions on the use of the manual. Free manuals
276 are available in source code form, and give you permission to copy and
277 modify. Non-free manuals do not allow this.
278
279 The criteria of freedom for a free manual are roughly the same as for
280 free software. Redistribution (including the normal kinds of
281 commercial redistribution) must be permitted, so that the manual can
282 accompany every copy of the program, both on-line and on paper.
283
284 Permission for modification of the technical content is crucial too.
285 When people modify the software, adding or changing features, if they
286 are conscientious they will change the manual too---so they can
287 provide accurate and clear documentation for the modified program. A
288 manual that leaves you no choice but to write a new manual to document
289 a changed version of the program is not really available to our
290 community.
291
292 Some kinds of limits on the way modification is handled are
293 acceptable. For example, requirements to preserve the original
294 author's copyright notice, the distribution terms, or the list of
295 authors, are ok. It is also no problem to require modified versions
296 to include notice that they were modified. Even entire sections that
297 may not be deleted or changed are acceptable, as long as they deal
298 with nontechnical topics (like this one). These kinds of restrictions
299 are acceptable because they don't obstruct the community's normal use
300 of the manual.
301
302 However, it must be possible to modify all the @emph{technical}
303 content of the manual, and then distribute the result in all the usual
304 media, through all the usual channels. Otherwise, the restrictions
305 obstruct the use of the manual, it is not free, and we need another
306 manual to replace it.
307
308 Please spread the word about this issue. Our community continues to
309 lose manuals to proprietary publishing. If we spread the word that
310 free software needs free reference manuals and free tutorials, perhaps
311 the next person who wants to contribute by writing documentation will
312 realize, before it is too late, that only free manuals contribute to
313 the free software community.
314
315 If you are writing documentation, please insist on publishing it under
316 the GNU Free Documentation License or another free documentation
317 license. Remember that this decision requires your approval---you
318 don't have to let the publisher decide. Some commercial publishers
319 will use a free license if you insist, but they will not propose the
320 option; it is up to you to raise the issue and say firmly that this is
321 what you want. If the publisher you are dealing with refuses, please
322 try other publishers. If you're not sure whether a proposed license
323 is free, write to @email{licensing@@gnu.org}.
324
325 You can encourage commercial publishers to sell more free, copylefted
326 manuals and tutorials by buying them, and particularly by buying
327 copies from the publishers that paid for their writing or for major
328 improvements. Meanwhile, try to avoid buying non-free documentation
329 at all. Check the distribution terms of a manual before you buy it,
330 and insist that whoever seeks your business must respect your freedom.
331 Check the history of the book, and try to reward the publishers that
332 have paid or pay the authors to work on it.
333
334 The Free Software Foundation maintains a list of free documentation
335 published by other publishers, at
336 @url{http://www.fsf.org/doc/other-free-books.html}.
337
338 @node Contributors
339 @unnumberedsec Contributors to @value{GDBN}
340
341 Richard Stallman was the original author of @value{GDBN}, and of many
342 other @sc{gnu} programs. Many others have contributed to its
343 development. This section attempts to credit major contributors. One
344 of the virtues of free software is that everyone is free to contribute
345 to it; with regret, we cannot actually acknowledge everyone here. The
346 file @file{ChangeLog} in the @value{GDBN} distribution approximates a
347 blow-by-blow account.
348
349 Changes much prior to version 2.0 are lost in the mists of time.
350
351 @quotation
352 @emph{Plea:} Additions to this section are particularly welcome. If you
353 or your friends (or enemies, to be evenhanded) have been unfairly
354 omitted from this list, we would like to add your names!
355 @end quotation
356
357 So that they may not regard their many labors as thankless, we
358 particularly thank those who shepherded @value{GDBN} through major
359 releases:
360 Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
361 Jim Blandy (release 4.18);
362 Jason Molenda (release 4.17);
363 Stan Shebs (release 4.14);
364 Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
365 Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
366 John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
367 Jim Kingdon (releases 3.5, 3.4, and 3.3);
368 and Randy Smith (releases 3.2, 3.1, and 3.0).
369
370 Richard Stallman, assisted at various times by Peter TerMaat, Chris
371 Hanson, and Richard Mlynarik, handled releases through 2.8.
372
373 Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
374 in @value{GDBN}, with significant additional contributions from Per
375 Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
376 demangler. Early work on C@t{++} was by Peter TerMaat (who also did
377 much general update work leading to release 3.0).
378
379 @value{GDBN} uses the BFD subroutine library to examine multiple
380 object-file formats; BFD was a joint project of David V.
381 Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
382
383 David Johnson wrote the original COFF support; Pace Willison did
384 the original support for encapsulated COFF.
385
386 Brent Benson of Harris Computer Systems contributed DWARF 2 support.
387
388 Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
389 Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
390 support.
391 Jean-Daniel Fekete contributed Sun 386i support.
392 Chris Hanson improved the HP9000 support.
393 Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
394 David Johnson contributed Encore Umax support.
395 Jyrki Kuoppala contributed Altos 3068 support.
396 Jeff Law contributed HP PA and SOM support.
397 Keith Packard contributed NS32K support.
398 Doug Rabson contributed Acorn Risc Machine support.
399 Bob Rusk contributed Harris Nighthawk CX-UX support.
400 Chris Smith contributed Convex support (and Fortran debugging).
401 Jonathan Stone contributed Pyramid support.
402 Michael Tiemann contributed SPARC support.
403 Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
404 Pace Willison contributed Intel 386 support.
405 Jay Vosburgh contributed Symmetry support.
406 Marko Mlinar contributed OpenRISC 1000 support.
407
408 Andreas Schwab contributed M68K @sc{gnu}/Linux support.
409
410 Rich Schaefer and Peter Schauer helped with support of SunOS shared
411 libraries.
412
413 Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
414 about several machine instruction sets.
415
416 Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
417 remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
418 contributed remote debugging modules for the i960, VxWorks, A29K UDI,
419 and RDI targets, respectively.
420
421 Brian Fox is the author of the readline libraries providing
422 command-line editing and command history.
423
424 Andrew Beers of SUNY Buffalo wrote the language-switching code, the
425 Modula-2 support, and contributed the Languages chapter of this manual.
426
427 Fred Fish wrote most of the support for Unix System Vr4.
428 He also enhanced the command-completion support to cover C@t{++} overloaded
429 symbols.
430
431 Hitachi America (now Renesas America), Ltd. sponsored the support for
432 H8/300, H8/500, and Super-H processors.
433
434 NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
435
436 Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
437 processors.
438
439 Toshiba sponsored the support for the TX39 Mips processor.
440
441 Matsushita sponsored the support for the MN10200 and MN10300 processors.
442
443 Fujitsu sponsored the support for SPARClite and FR30 processors.
444
445 Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
446 watchpoints.
447
448 Michael Snyder added support for tracepoints.
449
450 Stu Grossman wrote gdbserver.
451
452 Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
453 nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
454
455 The following people at the Hewlett-Packard Company contributed
456 support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
457 (narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
458 compiler, and the Text User Interface (nee Terminal User Interface):
459 Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
460 Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
461 provided HP-specific information in this manual.
462
463 DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
464 Robert Hoehne made significant contributions to the DJGPP port.
465
466 Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
467 development since 1991. Cygnus engineers who have worked on @value{GDBN}
468 fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
469 Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
470 Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
471 Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
472 Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
473 addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
474 JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
475 Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
476 Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
477 Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
478 Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
479 Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
480 Zuhn have made contributions both large and small.
481
482 Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
483 Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
484
485 Jim Blandy added support for preprocessor macros, while working for Red
486 Hat.
487
488 Andrew Cagney designed @value{GDBN}'s architecture vector. Many
489 people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
490 Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
491 Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
492 Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
493 with the migration of old architectures to this new framework.
494
495 Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
496 unwinder framework, this consisting of a fresh new design featuring
497 frame IDs, independent frame sniffers, and the sentinel frame. Mark
498 Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
499 libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
500 trad unwinders. The architecture-specific changes, each involving a
501 complete rewrite of the architecture's frame code, were carried out by
502 Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
503 Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
504 Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
505 Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
506 Weigand.
507
508 Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
509 Tensilica, Inc.@: contributed support for Xtensa processors. Others
510 who have worked on the Xtensa port of @value{GDBN} in the past include
511 Steve Tjiang, John Newlin, and Scott Foehner.
512
513 @node Sample Session
514 @chapter A Sample @value{GDBN} Session
515
516 You can use this manual at your leisure to read all about @value{GDBN}.
517 However, a handful of commands are enough to get started using the
518 debugger. This chapter illustrates those commands.
519
520 @iftex
521 In this sample session, we emphasize user input like this: @b{input},
522 to make it easier to pick out from the surrounding output.
523 @end iftex
524
525 @c FIXME: this example may not be appropriate for some configs, where
526 @c FIXME...primary interest is in remote use.
527
528 One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
529 processor) exhibits the following bug: sometimes, when we change its
530 quote strings from the default, the commands used to capture one macro
531 definition within another stop working. In the following short @code{m4}
532 session, we define a macro @code{foo} which expands to @code{0000}; we
533 then use the @code{m4} built-in @code{defn} to define @code{bar} as the
534 same thing. However, when we change the open quote string to
535 @code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
536 procedure fails to define a new synonym @code{baz}:
537
538 @smallexample
539 $ @b{cd gnu/m4}
540 $ @b{./m4}
541 @b{define(foo,0000)}
542
543 @b{foo}
544 0000
545 @b{define(bar,defn(`foo'))}
546
547 @b{bar}
548 0000
549 @b{changequote(<QUOTE>,<UNQUOTE>)}
550
551 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
552 @b{baz}
553 @b{Ctrl-d}
554 m4: End of input: 0: fatal error: EOF in string
555 @end smallexample
556
557 @noindent
558 Let us use @value{GDBN} to try to see what is going on.
559
560 @smallexample
561 $ @b{@value{GDBP} m4}
562 @c FIXME: this falsifies the exact text played out, to permit smallbook
563 @c FIXME... format to come out better.
564 @value{GDBN} is free software and you are welcome to distribute copies
565 of it under certain conditions; type "show copying" to see
566 the conditions.
567 There is absolutely no warranty for @value{GDBN}; type "show warranty"
568 for details.
569
570 @value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
571 (@value{GDBP})
572 @end smallexample
573
574 @noindent
575 @value{GDBN} reads only enough symbol data to know where to find the
576 rest when needed; as a result, the first prompt comes up very quickly.
577 We now tell @value{GDBN} to use a narrower display width than usual, so
578 that examples fit in this manual.
579
580 @smallexample
581 (@value{GDBP}) @b{set width 70}
582 @end smallexample
583
584 @noindent
585 We need to see how the @code{m4} built-in @code{changequote} works.
586 Having looked at the source, we know the relevant subroutine is
587 @code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
588 @code{break} command.
589
590 @smallexample
591 (@value{GDBP}) @b{break m4_changequote}
592 Breakpoint 1 at 0x62f4: file builtin.c, line 879.
593 @end smallexample
594
595 @noindent
596 Using the @code{run} command, we start @code{m4} running under @value{GDBN}
597 control; as long as control does not reach the @code{m4_changequote}
598 subroutine, the program runs as usual:
599
600 @smallexample
601 (@value{GDBP}) @b{run}
602 Starting program: /work/Editorial/gdb/gnu/m4/m4
603 @b{define(foo,0000)}
604
605 @b{foo}
606 0000
607 @end smallexample
608
609 @noindent
610 To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
611 suspends execution of @code{m4}, displaying information about the
612 context where it stops.
613
614 @smallexample
615 @b{changequote(<QUOTE>,<UNQUOTE>)}
616
617 Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
618 at builtin.c:879
619 879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
620 @end smallexample
621
622 @noindent
623 Now we use the command @code{n} (@code{next}) to advance execution to
624 the next line of the current function.
625
626 @smallexample
627 (@value{GDBP}) @b{n}
628 882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
629 : nil,
630 @end smallexample
631
632 @noindent
633 @code{set_quotes} looks like a promising subroutine. We can go into it
634 by using the command @code{s} (@code{step}) instead of @code{next}.
635 @code{step} goes to the next line to be executed in @emph{any}
636 subroutine, so it steps into @code{set_quotes}.
637
638 @smallexample
639 (@value{GDBP}) @b{s}
640 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
641 at input.c:530
642 530 if (lquote != def_lquote)
643 @end smallexample
644
645 @noindent
646 The display that shows the subroutine where @code{m4} is now
647 suspended (and its arguments) is called a stack frame display. It
648 shows a summary of the stack. We can use the @code{backtrace}
649 command (which can also be spelled @code{bt}), to see where we are
650 in the stack as a whole: the @code{backtrace} command displays a
651 stack frame for each active subroutine.
652
653 @smallexample
654 (@value{GDBP}) @b{bt}
655 #0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
656 at input.c:530
657 #1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
658 at builtin.c:882
659 #2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
660 #3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
661 at macro.c:71
662 #4 0x79dc in expand_input () at macro.c:40
663 #5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
664 @end smallexample
665
666 @noindent
667 We step through a few more lines to see what happens. The first two
668 times, we can use @samp{s}; the next two times we use @code{n} to avoid
669 falling into the @code{xstrdup} subroutine.
670
671 @smallexample
672 (@value{GDBP}) @b{s}
673 0x3b5c 532 if (rquote != def_rquote)
674 (@value{GDBP}) @b{s}
675 0x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
676 def_lquote : xstrdup(lq);
677 (@value{GDBP}) @b{n}
678 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
679 : xstrdup(rq);
680 (@value{GDBP}) @b{n}
681 538 len_lquote = strlen(rquote);
682 @end smallexample
683
684 @noindent
685 The last line displayed looks a little odd; we can examine the variables
686 @code{lquote} and @code{rquote} to see if they are in fact the new left
687 and right quotes we specified. We use the command @code{p}
688 (@code{print}) to see their values.
689
690 @smallexample
691 (@value{GDBP}) @b{p lquote}
692 $1 = 0x35d40 "<QUOTE>"
693 (@value{GDBP}) @b{p rquote}
694 $2 = 0x35d50 "<UNQUOTE>"
695 @end smallexample
696
697 @noindent
698 @code{lquote} and @code{rquote} are indeed the new left and right quotes.
699 To look at some context, we can display ten lines of source
700 surrounding the current line with the @code{l} (@code{list}) command.
701
702 @smallexample
703 (@value{GDBP}) @b{l}
704 533 xfree(rquote);
705 534
706 535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
707 : xstrdup (lq);
708 536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
709 : xstrdup (rq);
710 537
711 538 len_lquote = strlen(rquote);
712 539 len_rquote = strlen(lquote);
713 540 @}
714 541
715 542 void
716 @end smallexample
717
718 @noindent
719 Let us step past the two lines that set @code{len_lquote} and
720 @code{len_rquote}, and then examine the values of those variables.
721
722 @smallexample
723 (@value{GDBP}) @b{n}
724 539 len_rquote = strlen(lquote);
725 (@value{GDBP}) @b{n}
726 540 @}
727 (@value{GDBP}) @b{p len_lquote}
728 $3 = 9
729 (@value{GDBP}) @b{p len_rquote}
730 $4 = 7
731 @end smallexample
732
733 @noindent
734 That certainly looks wrong, assuming @code{len_lquote} and
735 @code{len_rquote} are meant to be the lengths of @code{lquote} and
736 @code{rquote} respectively. We can set them to better values using
737 the @code{p} command, since it can print the value of
738 any expression---and that expression can include subroutine calls and
739 assignments.
740
741 @smallexample
742 (@value{GDBP}) @b{p len_lquote=strlen(lquote)}
743 $5 = 7
744 (@value{GDBP}) @b{p len_rquote=strlen(rquote)}
745 $6 = 9
746 @end smallexample
747
748 @noindent
749 Is that enough to fix the problem of using the new quotes with the
750 @code{m4} built-in @code{defn}? We can allow @code{m4} to continue
751 executing with the @code{c} (@code{continue}) command, and then try the
752 example that caused trouble initially:
753
754 @smallexample
755 (@value{GDBP}) @b{c}
756 Continuing.
757
758 @b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
759
760 baz
761 0000
762 @end smallexample
763
764 @noindent
765 Success! The new quotes now work just as well as the default ones. The
766 problem seems to have been just the two typos defining the wrong
767 lengths. We allow @code{m4} exit by giving it an EOF as input:
768
769 @smallexample
770 @b{Ctrl-d}
771 Program exited normally.
772 @end smallexample
773
774 @noindent
775 The message @samp{Program exited normally.} is from @value{GDBN}; it
776 indicates @code{m4} has finished executing. We can end our @value{GDBN}
777 session with the @value{GDBN} @code{quit} command.
778
779 @smallexample
780 (@value{GDBP}) @b{quit}
781 @end smallexample
782
783 @node Invocation
784 @chapter Getting In and Out of @value{GDBN}
785
786 This chapter discusses how to start @value{GDBN}, and how to get out of it.
787 The essentials are:
788 @itemize @bullet
789 @item
790 type @samp{@value{GDBP}} to start @value{GDBN}.
791 @item
792 type @kbd{quit} or @kbd{Ctrl-d} to exit.
793 @end itemize
794
795 @menu
796 * Invoking GDB:: How to start @value{GDBN}
797 * Quitting GDB:: How to quit @value{GDBN}
798 * Shell Commands:: How to use shell commands inside @value{GDBN}
799 * Logging Output:: How to log @value{GDBN}'s output to a file
800 @end menu
801
802 @node Invoking GDB
803 @section Invoking @value{GDBN}
804
805 Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
806 @value{GDBN} reads commands from the terminal until you tell it to exit.
807
808 You can also run @code{@value{GDBP}} with a variety of arguments and options,
809 to specify more of your debugging environment at the outset.
810
811 The command-line options described here are designed
812 to cover a variety of situations; in some environments, some of these
813 options may effectively be unavailable.
814
815 The most usual way to start @value{GDBN} is with one argument,
816 specifying an executable program:
817
818 @smallexample
819 @value{GDBP} @var{program}
820 @end smallexample
821
822 @noindent
823 You can also start with both an executable program and a core file
824 specified:
825
826 @smallexample
827 @value{GDBP} @var{program} @var{core}
828 @end smallexample
829
830 You can, instead, specify a process ID as a second argument, if you want
831 to debug a running process:
832
833 @smallexample
834 @value{GDBP} @var{program} 1234
835 @end smallexample
836
837 @noindent
838 would attach @value{GDBN} to process @code{1234} (unless you also have a file
839 named @file{1234}; @value{GDBN} does check for a core file first).
840
841 Taking advantage of the second command-line argument requires a fairly
842 complete operating system; when you use @value{GDBN} as a remote
843 debugger attached to a bare board, there may not be any notion of
844 ``process'', and there is often no way to get a core dump. @value{GDBN}
845 will warn you if it is unable to attach or to read core dumps.
846
847 You can optionally have @code{@value{GDBP}} pass any arguments after the
848 executable file to the inferior using @code{--args}. This option stops
849 option processing.
850 @smallexample
851 @value{GDBP} --args gcc -O2 -c foo.c
852 @end smallexample
853 This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
854 @code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
855
856 You can run @code{@value{GDBP}} without printing the front material, which describes
857 @value{GDBN}'s non-warranty, by specifying @code{-silent}:
858
859 @smallexample
860 @value{GDBP} -silent
861 @end smallexample
862
863 @noindent
864 You can further control how @value{GDBN} starts up by using command-line
865 options. @value{GDBN} itself can remind you of the options available.
866
867 @noindent
868 Type
869
870 @smallexample
871 @value{GDBP} -help
872 @end smallexample
873
874 @noindent
875 to display all available options and briefly describe their use
876 (@samp{@value{GDBP} -h} is a shorter equivalent).
877
878 All options and command line arguments you give are processed
879 in sequential order. The order makes a difference when the
880 @samp{-x} option is used.
881
882
883 @menu
884 * File Options:: Choosing files
885 * Mode Options:: Choosing modes
886 * Startup:: What @value{GDBN} does during startup
887 @end menu
888
889 @node File Options
890 @subsection Choosing Files
891
892 When @value{GDBN} starts, it reads any arguments other than options as
893 specifying an executable file and core file (or process ID). This is
894 the same as if the arguments were specified by the @samp{-se} and
895 @samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
896 first argument that does not have an associated option flag as
897 equivalent to the @samp{-se} option followed by that argument; and the
898 second argument that does not have an associated option flag, if any, as
899 equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
900 If the second argument begins with a decimal digit, @value{GDBN} will
901 first attempt to attach to it as a process, and if that fails, attempt
902 to open it as a corefile. If you have a corefile whose name begins with
903 a digit, you can prevent @value{GDBN} from treating it as a pid by
904 prefixing it with @file{./}, e.g.@: @file{./12345}.
905
906 If @value{GDBN} has not been configured to included core file support,
907 such as for most embedded targets, then it will complain about a second
908 argument and ignore it.
909
910 Many options have both long and short forms; both are shown in the
911 following list. @value{GDBN} also recognizes the long forms if you truncate
912 them, so long as enough of the option is present to be unambiguous.
913 (If you prefer, you can flag option arguments with @samp{--} rather
914 than @samp{-}, though we illustrate the more usual convention.)
915
916 @c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
917 @c way, both those who look for -foo and --foo in the index, will find
918 @c it.
919
920 @table @code
921 @item -symbols @var{file}
922 @itemx -s @var{file}
923 @cindex @code{--symbols}
924 @cindex @code{-s}
925 Read symbol table from file @var{file}.
926
927 @item -exec @var{file}
928 @itemx -e @var{file}
929 @cindex @code{--exec}
930 @cindex @code{-e}
931 Use file @var{file} as the executable file to execute when appropriate,
932 and for examining pure data in conjunction with a core dump.
933
934 @item -se @var{file}
935 @cindex @code{--se}
936 Read symbol table from file @var{file} and use it as the executable
937 file.
938
939 @item -core @var{file}
940 @itemx -c @var{file}
941 @cindex @code{--core}
942 @cindex @code{-c}
943 Use file @var{file} as a core dump to examine.
944
945 @item -pid @var{number}
946 @itemx -p @var{number}
947 @cindex @code{--pid}
948 @cindex @code{-p}
949 Connect to process ID @var{number}, as with the @code{attach} command.
950
951 @item -command @var{file}
952 @itemx -x @var{file}
953 @cindex @code{--command}
954 @cindex @code{-x}
955 Execute @value{GDBN} commands from file @var{file}. @xref{Command
956 Files,, Command files}.
957
958 @item -eval-command @var{command}
959 @itemx -ex @var{command}
960 @cindex @code{--eval-command}
961 @cindex @code{-ex}
962 Execute a single @value{GDBN} command.
963
964 This option may be used multiple times to call multiple commands. It may
965 also be interleaved with @samp{-command} as required.
966
967 @smallexample
968 @value{GDBP} -ex 'target sim' -ex 'load' \
969 -x setbreakpoints -ex 'run' a.out
970 @end smallexample
971
972 @item -directory @var{directory}
973 @itemx -d @var{directory}
974 @cindex @code{--directory}
975 @cindex @code{-d}
976 Add @var{directory} to the path to search for source and script files.
977
978 @item -r
979 @itemx -readnow
980 @cindex @code{--readnow}
981 @cindex @code{-r}
982 Read each symbol file's entire symbol table immediately, rather than
983 the default, which is to read it incrementally as it is needed.
984 This makes startup slower, but makes future operations faster.
985
986 @end table
987
988 @node Mode Options
989 @subsection Choosing Modes
990
991 You can run @value{GDBN} in various alternative modes---for example, in
992 batch mode or quiet mode.
993
994 @table @code
995 @item -nx
996 @itemx -n
997 @cindex @code{--nx}
998 @cindex @code{-n}
999 Do not execute commands found in any initialization files. Normally,
1000 @value{GDBN} executes the commands in these files after all the command
1001 options and arguments have been processed. @xref{Command Files,,Command
1002 Files}.
1003
1004 @item -quiet
1005 @itemx -silent
1006 @itemx -q
1007 @cindex @code{--quiet}
1008 @cindex @code{--silent}
1009 @cindex @code{-q}
1010 ``Quiet''. Do not print the introductory and copyright messages. These
1011 messages are also suppressed in batch mode.
1012
1013 @item -batch
1014 @cindex @code{--batch}
1015 Run in batch mode. Exit with status @code{0} after processing all the
1016 command files specified with @samp{-x} (and all commands from
1017 initialization files, if not inhibited with @samp{-n}). Exit with
1018 nonzero status if an error occurs in executing the @value{GDBN} commands
1019 in the command files.
1020
1021 Batch mode may be useful for running @value{GDBN} as a filter, for
1022 example to download and run a program on another computer; in order to
1023 make this more useful, the message
1024
1025 @smallexample
1026 Program exited normally.
1027 @end smallexample
1028
1029 @noindent
1030 (which is ordinarily issued whenever a program running under
1031 @value{GDBN} control terminates) is not issued when running in batch
1032 mode.
1033
1034 @item -batch-silent
1035 @cindex @code{--batch-silent}
1036 Run in batch mode exactly like @samp{-batch}, but totally silently. All
1037 @value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1038 unaffected). This is much quieter than @samp{-silent} and would be useless
1039 for an interactive session.
1040
1041 This is particularly useful when using targets that give @samp{Loading section}
1042 messages, for example.
1043
1044 Note that targets that give their output via @value{GDBN}, as opposed to
1045 writing directly to @code{stdout}, will also be made silent.
1046
1047 @item -return-child-result
1048 @cindex @code{--return-child-result}
1049 The return code from @value{GDBN} will be the return code from the child
1050 process (the process being debugged), with the following exceptions:
1051
1052 @itemize @bullet
1053 @item
1054 @value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1055 internal error. In this case the exit code is the same as it would have been
1056 without @samp{-return-child-result}.
1057 @item
1058 The user quits with an explicit value. E.g., @samp{quit 1}.
1059 @item
1060 The child process never runs, or is not allowed to terminate, in which case
1061 the exit code will be -1.
1062 @end itemize
1063
1064 This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1065 when @value{GDBN} is being used as a remote program loader or simulator
1066 interface.
1067
1068 @item -nowindows
1069 @itemx -nw
1070 @cindex @code{--nowindows}
1071 @cindex @code{-nw}
1072 ``No windows''. If @value{GDBN} comes with a graphical user interface
1073 (GUI) built in, then this option tells @value{GDBN} to only use the command-line
1074 interface. If no GUI is available, this option has no effect.
1075
1076 @item -windows
1077 @itemx -w
1078 @cindex @code{--windows}
1079 @cindex @code{-w}
1080 If @value{GDBN} includes a GUI, then this option requires it to be
1081 used if possible.
1082
1083 @item -cd @var{directory}
1084 @cindex @code{--cd}
1085 Run @value{GDBN} using @var{directory} as its working directory,
1086 instead of the current directory.
1087
1088 @item -fullname
1089 @itemx -f
1090 @cindex @code{--fullname}
1091 @cindex @code{-f}
1092 @sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1093 subprocess. It tells @value{GDBN} to output the full file name and line
1094 number in a standard, recognizable fashion each time a stack frame is
1095 displayed (which includes each time your program stops). This
1096 recognizable format looks like two @samp{\032} characters, followed by
1097 the file name, line number and character position separated by colons,
1098 and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1099 @samp{\032} characters as a signal to display the source code for the
1100 frame.
1101
1102 @item -epoch
1103 @cindex @code{--epoch}
1104 The Epoch Emacs-@value{GDBN} interface sets this option when it runs
1105 @value{GDBN} as a subprocess. It tells @value{GDBN} to modify its print
1106 routines so as to allow Epoch to display values of expressions in a
1107 separate window.
1108
1109 @item -annotate @var{level}
1110 @cindex @code{--annotate}
1111 This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1112 effect is identical to using @samp{set annotate @var{level}}
1113 (@pxref{Annotations}). The annotation @var{level} controls how much
1114 information @value{GDBN} prints together with its prompt, values of
1115 expressions, source lines, and other types of output. Level 0 is the
1116 normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1117 @sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1118 that control @value{GDBN}, and level 2 has been deprecated.
1119
1120 The annotation mechanism has largely been superseded by @sc{gdb/mi}
1121 (@pxref{GDB/MI}).
1122
1123 @item --args
1124 @cindex @code{--args}
1125 Change interpretation of command line so that arguments following the
1126 executable file are passed as command line arguments to the inferior.
1127 This option stops option processing.
1128
1129 @item -baud @var{bps}
1130 @itemx -b @var{bps}
1131 @cindex @code{--baud}
1132 @cindex @code{-b}
1133 Set the line speed (baud rate or bits per second) of any serial
1134 interface used by @value{GDBN} for remote debugging.
1135
1136 @item -l @var{timeout}
1137 @cindex @code{-l}
1138 Set the timeout (in seconds) of any communication used by @value{GDBN}
1139 for remote debugging.
1140
1141 @item -tty @var{device}
1142 @itemx -t @var{device}
1143 @cindex @code{--tty}
1144 @cindex @code{-t}
1145 Run using @var{device} for your program's standard input and output.
1146 @c FIXME: kingdon thinks there is more to -tty. Investigate.
1147
1148 @c resolve the situation of these eventually
1149 @item -tui
1150 @cindex @code{--tui}
1151 Activate the @dfn{Text User Interface} when starting. The Text User
1152 Interface manages several text windows on the terminal, showing
1153 source, assembly, registers and @value{GDBN} command outputs
1154 (@pxref{TUI, ,@value{GDBN} Text User Interface}). Alternatively, the
1155 Text User Interface can be enabled by invoking the program
1156 @samp{@value{GDBTUI}}. Do not use this option if you run @value{GDBN} from
1157 Emacs (@pxref{Emacs, ,Using @value{GDBN} under @sc{gnu} Emacs}).
1158
1159 @c @item -xdb
1160 @c @cindex @code{--xdb}
1161 @c Run in XDB compatibility mode, allowing the use of certain XDB commands.
1162 @c For information, see the file @file{xdb_trans.html}, which is usually
1163 @c installed in the directory @code{/opt/langtools/wdb/doc} on HP-UX
1164 @c systems.
1165
1166 @item -interpreter @var{interp}
1167 @cindex @code{--interpreter}
1168 Use the interpreter @var{interp} for interface with the controlling
1169 program or device. This option is meant to be set by programs which
1170 communicate with @value{GDBN} using it as a back end.
1171 @xref{Interpreters, , Command Interpreters}.
1172
1173 @samp{--interpreter=mi} (or @samp{--interpreter=mi2}) causes
1174 @value{GDBN} to use the @dfn{@sc{gdb/mi} interface} (@pxref{GDB/MI, ,
1175 The @sc{gdb/mi} Interface}) included since @value{GDBN} version 6.0. The
1176 previous @sc{gdb/mi} interface, included in @value{GDBN} version 5.3 and
1177 selected with @samp{--interpreter=mi1}, is deprecated. Earlier
1178 @sc{gdb/mi} interfaces are no longer supported.
1179
1180 @item -write
1181 @cindex @code{--write}
1182 Open the executable and core files for both reading and writing. This
1183 is equivalent to the @samp{set write on} command inside @value{GDBN}
1184 (@pxref{Patching}).
1185
1186 @item -statistics
1187 @cindex @code{--statistics}
1188 This option causes @value{GDBN} to print statistics about time and
1189 memory usage after it completes each command and returns to the prompt.
1190
1191 @item -version
1192 @cindex @code{--version}
1193 This option causes @value{GDBN} to print its version number and
1194 no-warranty blurb, and exit.
1195
1196 @end table
1197
1198 @node Startup
1199 @subsection What @value{GDBN} Does During Startup
1200 @cindex @value{GDBN} startup
1201
1202 Here's the description of what @value{GDBN} does during session startup:
1203
1204 @enumerate
1205 @item
1206 Sets up the command interpreter as specified by the command line
1207 (@pxref{Mode Options, interpreter}).
1208
1209 @item
1210 @cindex init file
1211 Reads the @dfn{init file} (if any) in your home directory@footnote{On
1212 DOS/Windows systems, the home directory is the one pointed to by the
1213 @code{HOME} environment variable.} and executes all the commands in
1214 that file.
1215
1216 @item
1217 Processes command line options and operands.
1218
1219 @item
1220 Reads and executes the commands from init file (if any) in the current
1221 working directory. This is only done if the current directory is
1222 different from your home directory. Thus, you can have more than one
1223 init file, one generic in your home directory, and another, specific
1224 to the program you are debugging, in the directory where you invoke
1225 @value{GDBN}.
1226
1227 @item
1228 Reads command files specified by the @samp{-x} option. @xref{Command
1229 Files}, for more details about @value{GDBN} command files.
1230
1231 @item
1232 Reads the command history recorded in the @dfn{history file}.
1233 @xref{Command History}, for more details about the command history and the
1234 files where @value{GDBN} records it.
1235 @end enumerate
1236
1237 Init files use the same syntax as @dfn{command files} (@pxref{Command
1238 Files}) and are processed by @value{GDBN} in the same way. The init
1239 file in your home directory can set options (such as @samp{set
1240 complaints}) that affect subsequent processing of command line options
1241 and operands. Init files are not executed if you use the @samp{-nx}
1242 option (@pxref{Mode Options, ,Choosing Modes}).
1243
1244 @cindex init file name
1245 @cindex @file{.gdbinit}
1246 @cindex @file{gdb.ini}
1247 The @value{GDBN} init files are normally called @file{.gdbinit}.
1248 The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1249 the limitations of file names imposed by DOS filesystems. The Windows
1250 ports of @value{GDBN} use the standard name, but if they find a
1251 @file{gdb.ini} file, they warn you about that and suggest to rename
1252 the file to the standard name.
1253
1254
1255 @node Quitting GDB
1256 @section Quitting @value{GDBN}
1257 @cindex exiting @value{GDBN}
1258 @cindex leaving @value{GDBN}
1259
1260 @table @code
1261 @kindex quit @r{[}@var{expression}@r{]}
1262 @kindex q @r{(@code{quit})}
1263 @item quit @r{[}@var{expression}@r{]}
1264 @itemx q
1265 To exit @value{GDBN}, use the @code{quit} command (abbreviated
1266 @code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
1267 do not supply @var{expression}, @value{GDBN} will terminate normally;
1268 otherwise it will terminate using the result of @var{expression} as the
1269 error code.
1270 @end table
1271
1272 @cindex interrupt
1273 An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
1274 terminates the action of any @value{GDBN} command that is in progress and
1275 returns to @value{GDBN} command level. It is safe to type the interrupt
1276 character at any time because @value{GDBN} does not allow it to take effect
1277 until a time when it is safe.
1278
1279 If you have been using @value{GDBN} to control an attached process or
1280 device, you can release it with the @code{detach} command
1281 (@pxref{Attach, ,Debugging an Already-running Process}).
1282
1283 @node Shell Commands
1284 @section Shell Commands
1285
1286 If you need to execute occasional shell commands during your
1287 debugging session, there is no need to leave or suspend @value{GDBN}; you can
1288 just use the @code{shell} command.
1289
1290 @table @code
1291 @kindex shell
1292 @cindex shell escape
1293 @item shell @var{command string}
1294 Invoke a standard shell to execute @var{command string}.
1295 If it exists, the environment variable @code{SHELL} determines which
1296 shell to run. Otherwise @value{GDBN} uses the default shell
1297 (@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
1298 @end table
1299
1300 The utility @code{make} is often needed in development environments.
1301 You do not have to use the @code{shell} command for this purpose in
1302 @value{GDBN}:
1303
1304 @table @code
1305 @kindex make
1306 @cindex calling make
1307 @item make @var{make-args}
1308 Execute the @code{make} program with the specified
1309 arguments. This is equivalent to @samp{shell make @var{make-args}}.
1310 @end table
1311
1312 @node Logging Output
1313 @section Logging Output
1314 @cindex logging @value{GDBN} output
1315 @cindex save @value{GDBN} output to a file
1316
1317 You may want to save the output of @value{GDBN} commands to a file.
1318 There are several commands to control @value{GDBN}'s logging.
1319
1320 @table @code
1321 @kindex set logging
1322 @item set logging on
1323 Enable logging.
1324 @item set logging off
1325 Disable logging.
1326 @cindex logging file name
1327 @item set logging file @var{file}
1328 Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1329 @item set logging overwrite [on|off]
1330 By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1331 you want @code{set logging on} to overwrite the logfile instead.
1332 @item set logging redirect [on|off]
1333 By default, @value{GDBN} output will go to both the terminal and the logfile.
1334 Set @code{redirect} if you want output to go only to the log file.
1335 @kindex show logging
1336 @item show logging
1337 Show the current values of the logging settings.
1338 @end table
1339
1340 @node Commands
1341 @chapter @value{GDBN} Commands
1342
1343 You can abbreviate a @value{GDBN} command to the first few letters of the command
1344 name, if that abbreviation is unambiguous; and you can repeat certain
1345 @value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1346 key to get @value{GDBN} to fill out the rest of a word in a command (or to
1347 show you the alternatives available, if there is more than one possibility).
1348
1349 @menu
1350 * Command Syntax:: How to give commands to @value{GDBN}
1351 * Completion:: Command completion
1352 * Help:: How to ask @value{GDBN} for help
1353 @end menu
1354
1355 @node Command Syntax
1356 @section Command Syntax
1357
1358 A @value{GDBN} command is a single line of input. There is no limit on
1359 how long it can be. It starts with a command name, which is followed by
1360 arguments whose meaning depends on the command name. For example, the
1361 command @code{step} accepts an argument which is the number of times to
1362 step, as in @samp{step 5}. You can also use the @code{step} command
1363 with no arguments. Some commands do not allow any arguments.
1364
1365 @cindex abbreviation
1366 @value{GDBN} command names may always be truncated if that abbreviation is
1367 unambiguous. Other possible command abbreviations are listed in the
1368 documentation for individual commands. In some cases, even ambiguous
1369 abbreviations are allowed; for example, @code{s} is specially defined as
1370 equivalent to @code{step} even though there are other commands whose
1371 names start with @code{s}. You can test abbreviations by using them as
1372 arguments to the @code{help} command.
1373
1374 @cindex repeating commands
1375 @kindex RET @r{(repeat last command)}
1376 A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1377 repeat the previous command. Certain commands (for example, @code{run})
1378 will not repeat this way; these are commands whose unintentional
1379 repetition might cause trouble and which you are unlikely to want to
1380 repeat. User-defined commands can disable this feature; see
1381 @ref{Define, dont-repeat}.
1382
1383 The @code{list} and @code{x} commands, when you repeat them with
1384 @key{RET}, construct new arguments rather than repeating
1385 exactly as typed. This permits easy scanning of source or memory.
1386
1387 @value{GDBN} can also use @key{RET} in another way: to partition lengthy
1388 output, in a way similar to the common utility @code{more}
1389 (@pxref{Screen Size,,Screen Size}). Since it is easy to press one
1390 @key{RET} too many in this situation, @value{GDBN} disables command
1391 repetition after any command that generates this sort of display.
1392
1393 @kindex # @r{(a comment)}
1394 @cindex comment
1395 Any text from a @kbd{#} to the end of the line is a comment; it does
1396 nothing. This is useful mainly in command files (@pxref{Command
1397 Files,,Command Files}).
1398
1399 @cindex repeating command sequences
1400 @kindex Ctrl-o @r{(operate-and-get-next)}
1401 The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1402 commands. This command accepts the current line, like @key{RET}, and
1403 then fetches the next line relative to the current line from the history
1404 for editing.
1405
1406 @node Completion
1407 @section Command Completion
1408
1409 @cindex completion
1410 @cindex word completion
1411 @value{GDBN} can fill in the rest of a word in a command for you, if there is
1412 only one possibility; it can also show you what the valid possibilities
1413 are for the next word in a command, at any time. This works for @value{GDBN}
1414 commands, @value{GDBN} subcommands, and the names of symbols in your program.
1415
1416 Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1417 of a word. If there is only one possibility, @value{GDBN} fills in the
1418 word, and waits for you to finish the command (or press @key{RET} to
1419 enter it). For example, if you type
1420
1421 @c FIXME "@key" does not distinguish its argument sufficiently to permit
1422 @c complete accuracy in these examples; space introduced for clarity.
1423 @c If texinfo enhancements make it unnecessary, it would be nice to
1424 @c replace " @key" by "@key" in the following...
1425 @smallexample
1426 (@value{GDBP}) info bre @key{TAB}
1427 @end smallexample
1428
1429 @noindent
1430 @value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1431 the only @code{info} subcommand beginning with @samp{bre}:
1432
1433 @smallexample
1434 (@value{GDBP}) info breakpoints
1435 @end smallexample
1436
1437 @noindent
1438 You can either press @key{RET} at this point, to run the @code{info
1439 breakpoints} command, or backspace and enter something else, if
1440 @samp{breakpoints} does not look like the command you expected. (If you
1441 were sure you wanted @code{info breakpoints} in the first place, you
1442 might as well just type @key{RET} immediately after @samp{info bre},
1443 to exploit command abbreviations rather than command completion).
1444
1445 If there is more than one possibility for the next word when you press
1446 @key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1447 characters and try again, or just press @key{TAB} a second time;
1448 @value{GDBN} displays all the possible completions for that word. For
1449 example, you might want to set a breakpoint on a subroutine whose name
1450 begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1451 just sounds the bell. Typing @key{TAB} again displays all the
1452 function names in your program that begin with those characters, for
1453 example:
1454
1455 @smallexample
1456 (@value{GDBP}) b make_ @key{TAB}
1457 @exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1458 make_a_section_from_file make_environ
1459 make_abs_section make_function_type
1460 make_blockvector make_pointer_type
1461 make_cleanup make_reference_type
1462 make_command make_symbol_completion_list
1463 (@value{GDBP}) b make_
1464 @end smallexample
1465
1466 @noindent
1467 After displaying the available possibilities, @value{GDBN} copies your
1468 partial input (@samp{b make_} in the example) so you can finish the
1469 command.
1470
1471 If you just want to see the list of alternatives in the first place, you
1472 can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
1473 means @kbd{@key{META} ?}. You can type this either by holding down a
1474 key designated as the @key{META} shift on your keyboard (if there is
1475 one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1476
1477 @cindex quotes in commands
1478 @cindex completion of quoted strings
1479 Sometimes the string you need, while logically a ``word'', may contain
1480 parentheses or other characters that @value{GDBN} normally excludes from
1481 its notion of a word. To permit word completion to work in this
1482 situation, you may enclose words in @code{'} (single quote marks) in
1483 @value{GDBN} commands.
1484
1485 The most likely situation where you might need this is in typing the
1486 name of a C@t{++} function. This is because C@t{++} allows function
1487 overloading (multiple definitions of the same function, distinguished
1488 by argument type). For example, when you want to set a breakpoint you
1489 may need to distinguish whether you mean the version of @code{name}
1490 that takes an @code{int} parameter, @code{name(int)}, or the version
1491 that takes a @code{float} parameter, @code{name(float)}. To use the
1492 word-completion facilities in this situation, type a single quote
1493 @code{'} at the beginning of the function name. This alerts
1494 @value{GDBN} that it may need to consider more information than usual
1495 when you press @key{TAB} or @kbd{M-?} to request word completion:
1496
1497 @smallexample
1498 (@value{GDBP}) b 'bubble( @kbd{M-?}
1499 bubble(double,double) bubble(int,int)
1500 (@value{GDBP}) b 'bubble(
1501 @end smallexample
1502
1503 In some cases, @value{GDBN} can tell that completing a name requires using
1504 quotes. When this happens, @value{GDBN} inserts the quote for you (while
1505 completing as much as it can) if you do not type the quote in the first
1506 place:
1507
1508 @smallexample
1509 (@value{GDBP}) b bub @key{TAB}
1510 @exdent @value{GDBN} alters your input line to the following, and rings a bell:
1511 (@value{GDBP}) b 'bubble(
1512 @end smallexample
1513
1514 @noindent
1515 In general, @value{GDBN} can tell that a quote is needed (and inserts it) if
1516 you have not yet started typing the argument list when you ask for
1517 completion on an overloaded symbol.
1518
1519 For more information about overloaded functions, see @ref{C Plus Plus
1520 Expressions, ,C@t{++} Expressions}. You can use the command @code{set
1521 overload-resolution off} to disable overload resolution;
1522 see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
1523
1524
1525 @node Help
1526 @section Getting Help
1527 @cindex online documentation
1528 @kindex help
1529
1530 You can always ask @value{GDBN} itself for information on its commands,
1531 using the command @code{help}.
1532
1533 @table @code
1534 @kindex h @r{(@code{help})}
1535 @item help
1536 @itemx h
1537 You can use @code{help} (abbreviated @code{h}) with no arguments to
1538 display a short list of named classes of commands:
1539
1540 @smallexample
1541 (@value{GDBP}) help
1542 List of classes of commands:
1543
1544 aliases -- Aliases of other commands
1545 breakpoints -- Making program stop at certain points
1546 data -- Examining data
1547 files -- Specifying and examining files
1548 internals -- Maintenance commands
1549 obscure -- Obscure features
1550 running -- Running the program
1551 stack -- Examining the stack
1552 status -- Status inquiries
1553 support -- Support facilities
1554 tracepoints -- Tracing of program execution without
1555 stopping the program
1556 user-defined -- User-defined commands
1557
1558 Type "help" followed by a class name for a list of
1559 commands in that class.
1560 Type "help" followed by command name for full
1561 documentation.
1562 Command name abbreviations are allowed if unambiguous.
1563 (@value{GDBP})
1564 @end smallexample
1565 @c the above line break eliminates huge line overfull...
1566
1567 @item help @var{class}
1568 Using one of the general help classes as an argument, you can get a
1569 list of the individual commands in that class. For example, here is the
1570 help display for the class @code{status}:
1571
1572 @smallexample
1573 (@value{GDBP}) help status
1574 Status inquiries.
1575
1576 List of commands:
1577
1578 @c Line break in "show" line falsifies real output, but needed
1579 @c to fit in smallbook page size.
1580 info -- Generic command for showing things
1581 about the program being debugged
1582 show -- Generic command for showing things
1583 about the debugger
1584
1585 Type "help" followed by command name for full
1586 documentation.
1587 Command name abbreviations are allowed if unambiguous.
1588 (@value{GDBP})
1589 @end smallexample
1590
1591 @item help @var{command}
1592 With a command name as @code{help} argument, @value{GDBN} displays a
1593 short paragraph on how to use that command.
1594
1595 @kindex apropos
1596 @item apropos @var{args}
1597 The @code{apropos} command searches through all of the @value{GDBN}
1598 commands, and their documentation, for the regular expression specified in
1599 @var{args}. It prints out all matches found. For example:
1600
1601 @smallexample
1602 apropos reload
1603 @end smallexample
1604
1605 @noindent
1606 results in:
1607
1608 @smallexample
1609 @c @group
1610 set symbol-reloading -- Set dynamic symbol table reloading
1611 multiple times in one run
1612 show symbol-reloading -- Show dynamic symbol table reloading
1613 multiple times in one run
1614 @c @end group
1615 @end smallexample
1616
1617 @kindex complete
1618 @item complete @var{args}
1619 The @code{complete @var{args}} command lists all the possible completions
1620 for the beginning of a command. Use @var{args} to specify the beginning of the
1621 command you want completed. For example:
1622
1623 @smallexample
1624 complete i
1625 @end smallexample
1626
1627 @noindent results in:
1628
1629 @smallexample
1630 @group
1631 if
1632 ignore
1633 info
1634 inspect
1635 @end group
1636 @end smallexample
1637
1638 @noindent This is intended for use by @sc{gnu} Emacs.
1639 @end table
1640
1641 In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1642 and @code{show} to inquire about the state of your program, or the state
1643 of @value{GDBN} itself. Each command supports many topics of inquiry; this
1644 manual introduces each of them in the appropriate context. The listings
1645 under @code{info} and under @code{show} in the Index point to
1646 all the sub-commands. @xref{Index}.
1647
1648 @c @group
1649 @table @code
1650 @kindex info
1651 @kindex i @r{(@code{info})}
1652 @item info
1653 This command (abbreviated @code{i}) is for describing the state of your
1654 program. For example, you can show the arguments passed to a function
1655 with @code{info args}, list the registers currently in use with @code{info
1656 registers}, or list the breakpoints you have set with @code{info breakpoints}.
1657 You can get a complete list of the @code{info} sub-commands with
1658 @w{@code{help info}}.
1659
1660 @kindex set
1661 @item set
1662 You can assign the result of an expression to an environment variable with
1663 @code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1664 @code{set prompt $}.
1665
1666 @kindex show
1667 @item show
1668 In contrast to @code{info}, @code{show} is for describing the state of
1669 @value{GDBN} itself.
1670 You can change most of the things you can @code{show}, by using the
1671 related command @code{set}; for example, you can control what number
1672 system is used for displays with @code{set radix}, or simply inquire
1673 which is currently in use with @code{show radix}.
1674
1675 @kindex info set
1676 To display all the settable parameters and their current
1677 values, you can use @code{show} with no arguments; you may also use
1678 @code{info set}. Both commands produce the same display.
1679 @c FIXME: "info set" violates the rule that "info" is for state of
1680 @c FIXME...program. Ck w/ GNU: "info set" to be called something else,
1681 @c FIXME...or change desc of rule---eg "state of prog and debugging session"?
1682 @end table
1683 @c @end group
1684
1685 Here are three miscellaneous @code{show} subcommands, all of which are
1686 exceptional in lacking corresponding @code{set} commands:
1687
1688 @table @code
1689 @kindex show version
1690 @cindex @value{GDBN} version number
1691 @item show version
1692 Show what version of @value{GDBN} is running. You should include this
1693 information in @value{GDBN} bug-reports. If multiple versions of
1694 @value{GDBN} are in use at your site, you may need to determine which
1695 version of @value{GDBN} you are running; as @value{GDBN} evolves, new
1696 commands are introduced, and old ones may wither away. Also, many
1697 system vendors ship variant versions of @value{GDBN}, and there are
1698 variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
1699 The version number is the same as the one announced when you start
1700 @value{GDBN}.
1701
1702 @kindex show copying
1703 @kindex info copying
1704 @cindex display @value{GDBN} copyright
1705 @item show copying
1706 @itemx info copying
1707 Display information about permission for copying @value{GDBN}.
1708
1709 @kindex show warranty
1710 @kindex info warranty
1711 @item show warranty
1712 @itemx info warranty
1713 Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
1714 if your version of @value{GDBN} comes with one.
1715
1716 @end table
1717
1718 @node Running
1719 @chapter Running Programs Under @value{GDBN}
1720
1721 When you run a program under @value{GDBN}, you must first generate
1722 debugging information when you compile it.
1723
1724 You may start @value{GDBN} with its arguments, if any, in an environment
1725 of your choice. If you are doing native debugging, you may redirect
1726 your program's input and output, debug an already running process, or
1727 kill a child process.
1728
1729 @menu
1730 * Compilation:: Compiling for debugging
1731 * Starting:: Starting your program
1732 * Arguments:: Your program's arguments
1733 * Environment:: Your program's environment
1734
1735 * Working Directory:: Your program's working directory
1736 * Input/Output:: Your program's input and output
1737 * Attach:: Debugging an already-running process
1738 * Kill Process:: Killing the child process
1739
1740 * Threads:: Debugging programs with multiple threads
1741 * Processes:: Debugging programs with multiple processes
1742 * Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
1743 @end menu
1744
1745 @node Compilation
1746 @section Compiling for Debugging
1747
1748 In order to debug a program effectively, you need to generate
1749 debugging information when you compile it. This debugging information
1750 is stored in the object file; it describes the data type of each
1751 variable or function and the correspondence between source line numbers
1752 and addresses in the executable code.
1753
1754 To request debugging information, specify the @samp{-g} option when you run
1755 the compiler.
1756
1757 Programs that are to be shipped to your customers are compiled with
1758 optimizations, using the @samp{-O} compiler option. However, many
1759 compilers are unable to handle the @samp{-g} and @samp{-O} options
1760 together. Using those compilers, you cannot generate optimized
1761 executables containing debugging information.
1762
1763 @value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
1764 without @samp{-O}, making it possible to debug optimized code. We
1765 recommend that you @emph{always} use @samp{-g} whenever you compile a
1766 program. You may think your program is correct, but there is no sense
1767 in pushing your luck.
1768
1769 @cindex optimized code, debugging
1770 @cindex debugging optimized code
1771 When you debug a program compiled with @samp{-g -O}, remember that the
1772 optimizer is rearranging your code; the debugger shows you what is
1773 really there. Do not be too surprised when the execution path does not
1774 exactly match your source file! An extreme example: if you define a
1775 variable, but never use it, @value{GDBN} never sees that
1776 variable---because the compiler optimizes it out of existence.
1777
1778 Some things do not work as well with @samp{-g -O} as with just
1779 @samp{-g}, particularly on machines with instruction scheduling. If in
1780 doubt, recompile with @samp{-g} alone, and if this fixes the problem,
1781 please report it to us as a bug (including a test case!).
1782 @xref{Variables}, for more information about debugging optimized code.
1783
1784 Older versions of the @sc{gnu} C compiler permitted a variant option
1785 @w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
1786 format; if your @sc{gnu} C compiler has this option, do not use it.
1787
1788 @value{GDBN} knows about preprocessor macros and can show you their
1789 expansion (@pxref{Macros}). Most compilers do not include information
1790 about preprocessor macros in the debugging information if you specify
1791 the @option{-g} flag alone, because this information is rather large.
1792 Version 3.1 and later of @value{NGCC}, the @sc{gnu} C compiler,
1793 provides macro information if you specify the options
1794 @option{-gdwarf-2} and @option{-g3}; the former option requests
1795 debugging information in the Dwarf 2 format, and the latter requests
1796 ``extra information''. In the future, we hope to find more compact
1797 ways to represent macro information, so that it can be included with
1798 @option{-g} alone.
1799
1800 @need 2000
1801 @node Starting
1802 @section Starting your Program
1803 @cindex starting
1804 @cindex running
1805
1806 @table @code
1807 @kindex run
1808 @kindex r @r{(@code{run})}
1809 @item run
1810 @itemx r
1811 Use the @code{run} command to start your program under @value{GDBN}.
1812 You must first specify the program name (except on VxWorks) with an
1813 argument to @value{GDBN} (@pxref{Invocation, ,Getting In and Out of
1814 @value{GDBN}}), or by using the @code{file} or @code{exec-file} command
1815 (@pxref{Files, ,Commands to Specify Files}).
1816
1817 @end table
1818
1819 If you are running your program in an execution environment that
1820 supports processes, @code{run} creates an inferior process and makes
1821 that process run your program. In some environments without processes,
1822 @code{run} jumps to the start of your program. Other targets,
1823 like @samp{remote}, are always running. If you get an error
1824 message like this one:
1825
1826 @smallexample
1827 The "remote" target does not support "run".
1828 Try "help target" or "continue".
1829 @end smallexample
1830
1831 @noindent
1832 then use @code{continue} to run your program. You may need @code{load}
1833 first (@pxref{load}).
1834
1835 The execution of a program is affected by certain information it
1836 receives from its superior. @value{GDBN} provides ways to specify this
1837 information, which you must do @emph{before} starting your program. (You
1838 can change it after starting your program, but such changes only affect
1839 your program the next time you start it.) This information may be
1840 divided into four categories:
1841
1842 @table @asis
1843 @item The @emph{arguments.}
1844 Specify the arguments to give your program as the arguments of the
1845 @code{run} command. If a shell is available on your target, the shell
1846 is used to pass the arguments, so that you may use normal conventions
1847 (such as wildcard expansion or variable substitution) in describing
1848 the arguments.
1849 In Unix systems, you can control which shell is used with the
1850 @code{SHELL} environment variable.
1851 @xref{Arguments, ,Your Program's Arguments}.
1852
1853 @item The @emph{environment.}
1854 Your program normally inherits its environment from @value{GDBN}, but you can
1855 use the @value{GDBN} commands @code{set environment} and @code{unset
1856 environment} to change parts of the environment that affect
1857 your program. @xref{Environment, ,Your Program's Environment}.
1858
1859 @item The @emph{working directory.}
1860 Your program inherits its working directory from @value{GDBN}. You can set
1861 the @value{GDBN} working directory with the @code{cd} command in @value{GDBN}.
1862 @xref{Working Directory, ,Your Program's Working Directory}.
1863
1864 @item The @emph{standard input and output.}
1865 Your program normally uses the same device for standard input and
1866 standard output as @value{GDBN} is using. You can redirect input and output
1867 in the @code{run} command line, or you can use the @code{tty} command to
1868 set a different device for your program.
1869 @xref{Input/Output, ,Your Program's Input and Output}.
1870
1871 @cindex pipes
1872 @emph{Warning:} While input and output redirection work, you cannot use
1873 pipes to pass the output of the program you are debugging to another
1874 program; if you attempt this, @value{GDBN} is likely to wind up debugging the
1875 wrong program.
1876 @end table
1877
1878 When you issue the @code{run} command, your program begins to execute
1879 immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
1880 of how to arrange for your program to stop. Once your program has
1881 stopped, you may call functions in your program, using the @code{print}
1882 or @code{call} commands. @xref{Data, ,Examining Data}.
1883
1884 If the modification time of your symbol file has changed since the last
1885 time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
1886 table, and reads it again. When it does this, @value{GDBN} tries to retain
1887 your current breakpoints.
1888
1889 @table @code
1890 @kindex start
1891 @item start
1892 @cindex run to main procedure
1893 The name of the main procedure can vary from language to language.
1894 With C or C@t{++}, the main procedure name is always @code{main}, but
1895 other languages such as Ada do not require a specific name for their
1896 main procedure. The debugger provides a convenient way to start the
1897 execution of the program and to stop at the beginning of the main
1898 procedure, depending on the language used.
1899
1900 The @samp{start} command does the equivalent of setting a temporary
1901 breakpoint at the beginning of the main procedure and then invoking
1902 the @samp{run} command.
1903
1904 @cindex elaboration phase
1905 Some programs contain an @dfn{elaboration} phase where some startup code is
1906 executed before the main procedure is called. This depends on the
1907 languages used to write your program. In C@t{++}, for instance,
1908 constructors for static and global objects are executed before
1909 @code{main} is called. It is therefore possible that the debugger stops
1910 before reaching the main procedure. However, the temporary breakpoint
1911 will remain to halt execution.
1912
1913 Specify the arguments to give to your program as arguments to the
1914 @samp{start} command. These arguments will be given verbatim to the
1915 underlying @samp{run} command. Note that the same arguments will be
1916 reused if no argument is provided during subsequent calls to
1917 @samp{start} or @samp{run}.
1918
1919 It is sometimes necessary to debug the program during elaboration. In
1920 these cases, using the @code{start} command would stop the execution of
1921 your program too late, as the program would have already completed the
1922 elaboration phase. Under these circumstances, insert breakpoints in your
1923 elaboration code before running your program.
1924 @end table
1925
1926 @node Arguments
1927 @section Your Program's Arguments
1928
1929 @cindex arguments (to your program)
1930 The arguments to your program can be specified by the arguments of the
1931 @code{run} command.
1932 They are passed to a shell, which expands wildcard characters and
1933 performs redirection of I/O, and thence to your program. Your
1934 @code{SHELL} environment variable (if it exists) specifies what shell
1935 @value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
1936 the default shell (@file{/bin/sh} on Unix).
1937
1938 On non-Unix systems, the program is usually invoked directly by
1939 @value{GDBN}, which emulates I/O redirection via the appropriate system
1940 calls, and the wildcard characters are expanded by the startup code of
1941 the program, not by the shell.
1942
1943 @code{run} with no arguments uses the same arguments used by the previous
1944 @code{run}, or those set by the @code{set args} command.
1945
1946 @table @code
1947 @kindex set args
1948 @item set args
1949 Specify the arguments to be used the next time your program is run. If
1950 @code{set args} has no arguments, @code{run} executes your program
1951 with no arguments. Once you have run your program with arguments,
1952 using @code{set args} before the next @code{run} is the only way to run
1953 it again without arguments.
1954
1955 @kindex show args
1956 @item show args
1957 Show the arguments to give your program when it is started.
1958 @end table
1959
1960 @node Environment
1961 @section Your Program's Environment
1962
1963 @cindex environment (of your program)
1964 The @dfn{environment} consists of a set of environment variables and
1965 their values. Environment variables conventionally record such things as
1966 your user name, your home directory, your terminal type, and your search
1967 path for programs to run. Usually you set up environment variables with
1968 the shell and they are inherited by all the other programs you run. When
1969 debugging, it can be useful to try running your program with a modified
1970 environment without having to start @value{GDBN} over again.
1971
1972 @table @code
1973 @kindex path
1974 @item path @var{directory}
1975 Add @var{directory} to the front of the @code{PATH} environment variable
1976 (the search path for executables) that will be passed to your program.
1977 The value of @code{PATH} used by @value{GDBN} does not change.
1978 You may specify several directory names, separated by whitespace or by a
1979 system-dependent separator character (@samp{:} on Unix, @samp{;} on
1980 MS-DOS and MS-Windows). If @var{directory} is already in the path, it
1981 is moved to the front, so it is searched sooner.
1982
1983 You can use the string @samp{$cwd} to refer to whatever is the current
1984 working directory at the time @value{GDBN} searches the path. If you
1985 use @samp{.} instead, it refers to the directory where you executed the
1986 @code{path} command. @value{GDBN} replaces @samp{.} in the
1987 @var{directory} argument (with the current path) before adding
1988 @var{directory} to the search path.
1989 @c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
1990 @c document that, since repeating it would be a no-op.
1991
1992 @kindex show paths
1993 @item show paths
1994 Display the list of search paths for executables (the @code{PATH}
1995 environment variable).
1996
1997 @kindex show environment
1998 @item show environment @r{[}@var{varname}@r{]}
1999 Print the value of environment variable @var{varname} to be given to
2000 your program when it starts. If you do not supply @var{varname},
2001 print the names and values of all environment variables to be given to
2002 your program. You can abbreviate @code{environment} as @code{env}.
2003
2004 @kindex set environment
2005 @item set environment @var{varname} @r{[}=@var{value}@r{]}
2006 Set environment variable @var{varname} to @var{value}. The value
2007 changes for your program only, not for @value{GDBN} itself. @var{value} may
2008 be any string; the values of environment variables are just strings, and
2009 any interpretation is supplied by your program itself. The @var{value}
2010 parameter is optional; if it is eliminated, the variable is set to a
2011 null value.
2012 @c "any string" here does not include leading, trailing
2013 @c blanks. Gnu asks: does anyone care?
2014
2015 For example, this command:
2016
2017 @smallexample
2018 set env USER = foo
2019 @end smallexample
2020
2021 @noindent
2022 tells the debugged program, when subsequently run, that its user is named
2023 @samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2024 are not actually required.)
2025
2026 @kindex unset environment
2027 @item unset environment @var{varname}
2028 Remove variable @var{varname} from the environment to be passed to your
2029 program. This is different from @samp{set env @var{varname} =};
2030 @code{unset environment} removes the variable from the environment,
2031 rather than assigning it an empty value.
2032 @end table
2033
2034 @emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2035 the shell indicated
2036 by your @code{SHELL} environment variable if it exists (or
2037 @code{/bin/sh} if not). If your @code{SHELL} variable names a shell
2038 that runs an initialization file---such as @file{.cshrc} for C-shell, or
2039 @file{.bashrc} for BASH---any variables you set in that file affect
2040 your program. You may wish to move setting of environment variables to
2041 files that are only run when you sign on, such as @file{.login} or
2042 @file{.profile}.
2043
2044 @node Working Directory
2045 @section Your Program's Working Directory
2046
2047 @cindex working directory (of your program)
2048 Each time you start your program with @code{run}, it inherits its
2049 working directory from the current working directory of @value{GDBN}.
2050 The @value{GDBN} working directory is initially whatever it inherited
2051 from its parent process (typically the shell), but you can specify a new
2052 working directory in @value{GDBN} with the @code{cd} command.
2053
2054 The @value{GDBN} working directory also serves as a default for the commands
2055 that specify files for @value{GDBN} to operate on. @xref{Files, ,Commands to
2056 Specify Files}.
2057
2058 @table @code
2059 @kindex cd
2060 @cindex change working directory
2061 @item cd @var{directory}
2062 Set the @value{GDBN} working directory to @var{directory}.
2063
2064 @kindex pwd
2065 @item pwd
2066 Print the @value{GDBN} working directory.
2067 @end table
2068
2069 It is generally impossible to find the current working directory of
2070 the process being debugged (since a program can change its directory
2071 during its run). If you work on a system where @value{GDBN} is
2072 configured with the @file{/proc} support, you can use the @code{info
2073 proc} command (@pxref{SVR4 Process Information}) to find out the
2074 current working directory of the debuggee.
2075
2076 @node Input/Output
2077 @section Your Program's Input and Output
2078
2079 @cindex redirection
2080 @cindex i/o
2081 @cindex terminal
2082 By default, the program you run under @value{GDBN} does input and output to
2083 the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
2084 to its own terminal modes to interact with you, but it records the terminal
2085 modes your program was using and switches back to them when you continue
2086 running your program.
2087
2088 @table @code
2089 @kindex info terminal
2090 @item info terminal
2091 Displays information recorded by @value{GDBN} about the terminal modes your
2092 program is using.
2093 @end table
2094
2095 You can redirect your program's input and/or output using shell
2096 redirection with the @code{run} command. For example,
2097
2098 @smallexample
2099 run > outfile
2100 @end smallexample
2101
2102 @noindent
2103 starts your program, diverting its output to the file @file{outfile}.
2104
2105 @kindex tty
2106 @cindex controlling terminal
2107 Another way to specify where your program should do input and output is
2108 with the @code{tty} command. This command accepts a file name as
2109 argument, and causes this file to be the default for future @code{run}
2110 commands. It also resets the controlling terminal for the child
2111 process, for future @code{run} commands. For example,
2112
2113 @smallexample
2114 tty /dev/ttyb
2115 @end smallexample
2116
2117 @noindent
2118 directs that processes started with subsequent @code{run} commands
2119 default to do input and output on the terminal @file{/dev/ttyb} and have
2120 that as their controlling terminal.
2121
2122 An explicit redirection in @code{run} overrides the @code{tty} command's
2123 effect on the input/output device, but not its effect on the controlling
2124 terminal.
2125
2126 When you use the @code{tty} command or redirect input in the @code{run}
2127 command, only the input @emph{for your program} is affected. The input
2128 for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2129 for @code{set inferior-tty}.
2130
2131 @cindex inferior tty
2132 @cindex set inferior controlling terminal
2133 You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2134 display the name of the terminal that will be used for future runs of your
2135 program.
2136
2137 @table @code
2138 @item set inferior-tty /dev/ttyb
2139 @kindex set inferior-tty
2140 Set the tty for the program being debugged to /dev/ttyb.
2141
2142 @item show inferior-tty
2143 @kindex show inferior-tty
2144 Show the current tty for the program being debugged.
2145 @end table
2146
2147 @node Attach
2148 @section Debugging an Already-running Process
2149 @kindex attach
2150 @cindex attach
2151
2152 @table @code
2153 @item attach @var{process-id}
2154 This command attaches to a running process---one that was started
2155 outside @value{GDBN}. (@code{info files} shows your active
2156 targets.) The command takes as argument a process ID. The usual way to
2157 find out the @var{process-id} of a Unix process is with the @code{ps} utility,
2158 or with the @samp{jobs -l} shell command.
2159
2160 @code{attach} does not repeat if you press @key{RET} a second time after
2161 executing the command.
2162 @end table
2163
2164 To use @code{attach}, your program must be running in an environment
2165 which supports processes; for example, @code{attach} does not work for
2166 programs on bare-board targets that lack an operating system. You must
2167 also have permission to send the process a signal.
2168
2169 When you use @code{attach}, the debugger finds the program running in
2170 the process first by looking in the current working directory, then (if
2171 the program is not found) by using the source file search path
2172 (@pxref{Source Path, ,Specifying Source Directories}). You can also use
2173 the @code{file} command to load the program. @xref{Files, ,Commands to
2174 Specify Files}.
2175
2176 The first thing @value{GDBN} does after arranging to debug the specified
2177 process is to stop it. You can examine and modify an attached process
2178 with all the @value{GDBN} commands that are ordinarily available when
2179 you start processes with @code{run}. You can insert breakpoints; you
2180 can step and continue; you can modify storage. If you would rather the
2181 process continue running, you may use the @code{continue} command after
2182 attaching @value{GDBN} to the process.
2183
2184 @table @code
2185 @kindex detach
2186 @item detach
2187 When you have finished debugging the attached process, you can use the
2188 @code{detach} command to release it from @value{GDBN} control. Detaching
2189 the process continues its execution. After the @code{detach} command,
2190 that process and @value{GDBN} become completely independent once more, and you
2191 are ready to @code{attach} another process or start one with @code{run}.
2192 @code{detach} does not repeat if you press @key{RET} again after
2193 executing the command.
2194 @end table
2195
2196 If you exit @value{GDBN} while you have an attached process, you detach
2197 that process. If you use the @code{run} command, you kill that process.
2198 By default, @value{GDBN} asks for confirmation if you try to do either of these
2199 things; you can control whether or not you need to confirm by using the
2200 @code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
2201 Messages}).
2202
2203 @node Kill Process
2204 @section Killing the Child Process
2205
2206 @table @code
2207 @kindex kill
2208 @item kill
2209 Kill the child process in which your program is running under @value{GDBN}.
2210 @end table
2211
2212 This command is useful if you wish to debug a core dump instead of a
2213 running process. @value{GDBN} ignores any core dump file while your program
2214 is running.
2215
2216 On some operating systems, a program cannot be executed outside @value{GDBN}
2217 while you have breakpoints set on it inside @value{GDBN}. You can use the
2218 @code{kill} command in this situation to permit running your program
2219 outside the debugger.
2220
2221 The @code{kill} command is also useful if you wish to recompile and
2222 relink your program, since on many systems it is impossible to modify an
2223 executable file while it is running in a process. In this case, when you
2224 next type @code{run}, @value{GDBN} notices that the file has changed, and
2225 reads the symbol table again (while trying to preserve your current
2226 breakpoint settings).
2227
2228 @node Threads
2229 @section Debugging Programs with Multiple Threads
2230
2231 @cindex threads of execution
2232 @cindex multiple threads
2233 @cindex switching threads
2234 In some operating systems, such as HP-UX and Solaris, a single program
2235 may have more than one @dfn{thread} of execution. The precise semantics
2236 of threads differ from one operating system to another, but in general
2237 the threads of a single program are akin to multiple processes---except
2238 that they share one address space (that is, they can all examine and
2239 modify the same variables). On the other hand, each thread has its own
2240 registers and execution stack, and perhaps private memory.
2241
2242 @value{GDBN} provides these facilities for debugging multi-thread
2243 programs:
2244
2245 @itemize @bullet
2246 @item automatic notification of new threads
2247 @item @samp{thread @var{threadno}}, a command to switch among threads
2248 @item @samp{info threads}, a command to inquire about existing threads
2249 @item @samp{thread apply [@var{threadno}] [@var{all}] @var{args}},
2250 a command to apply a command to a list of threads
2251 @item thread-specific breakpoints
2252 @item @samp{set print thread-events}, which controls printing of
2253 messages on thread start and exit.
2254 @end itemize
2255
2256 @quotation
2257 @emph{Warning:} These facilities are not yet available on every
2258 @value{GDBN} configuration where the operating system supports threads.
2259 If your @value{GDBN} does not support threads, these commands have no
2260 effect. For example, a system without thread support shows no output
2261 from @samp{info threads}, and always rejects the @code{thread} command,
2262 like this:
2263
2264 @smallexample
2265 (@value{GDBP}) info threads
2266 (@value{GDBP}) thread 1
2267 Thread ID 1 not known. Use the "info threads" command to
2268 see the IDs of currently known threads.
2269 @end smallexample
2270 @c FIXME to implementors: how hard would it be to say "sorry, this GDB
2271 @c doesn't support threads"?
2272 @end quotation
2273
2274 @cindex focus of debugging
2275 @cindex current thread
2276 The @value{GDBN} thread debugging facility allows you to observe all
2277 threads while your program runs---but whenever @value{GDBN} takes
2278 control, one thread in particular is always the focus of debugging.
2279 This thread is called the @dfn{current thread}. Debugging commands show
2280 program information from the perspective of the current thread.
2281
2282 @cindex @code{New} @var{systag} message
2283 @cindex thread identifier (system)
2284 @c FIXME-implementors!! It would be more helpful if the [New...] message
2285 @c included GDB's numeric thread handle, so you could just go to that
2286 @c thread without first checking `info threads'.
2287 Whenever @value{GDBN} detects a new thread in your program, it displays
2288 the target system's identification for the thread with a message in the
2289 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2290 whose form varies depending on the particular system. For example, on
2291 @sc{gnu}/Linux, you might see
2292
2293 @smallexample
2294 [New Thread 46912507313328 (LWP 25582)]
2295 @end smallexample
2296
2297 @noindent
2298 when @value{GDBN} notices a new thread. In contrast, on an SGI system,
2299 the @var{systag} is simply something like @samp{process 368}, with no
2300 further qualifier.
2301
2302 @c FIXME!! (1) Does the [New...] message appear even for the very first
2303 @c thread of a program, or does it only appear for the
2304 @c second---i.e.@: when it becomes obvious we have a multithread
2305 @c program?
2306 @c (2) *Is* there necessarily a first thread always? Or do some
2307 @c multithread systems permit starting a program with multiple
2308 @c threads ab initio?
2309
2310 @cindex thread number
2311 @cindex thread identifier (GDB)
2312 For debugging purposes, @value{GDBN} associates its own thread
2313 number---always a single integer---with each thread in your program.
2314
2315 @table @code
2316 @kindex info threads
2317 @item info threads
2318 Display a summary of all threads currently in your
2319 program. @value{GDBN} displays for each thread (in this order):
2320
2321 @enumerate
2322 @item
2323 the thread number assigned by @value{GDBN}
2324
2325 @item
2326 the target system's thread identifier (@var{systag})
2327
2328 @item
2329 the current stack frame summary for that thread
2330 @end enumerate
2331
2332 @noindent
2333 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2334 indicates the current thread.
2335
2336 For example,
2337 @end table
2338 @c end table here to get a little more width for example
2339
2340 @smallexample
2341 (@value{GDBP}) info threads
2342 3 process 35 thread 27 0x34e5 in sigpause ()
2343 2 process 35 thread 23 0x34e5 in sigpause ()
2344 * 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
2345 at threadtest.c:68
2346 @end smallexample
2347
2348 On HP-UX systems:
2349
2350 @cindex debugging multithreaded programs (on HP-UX)
2351 @cindex thread identifier (GDB), on HP-UX
2352 For debugging purposes, @value{GDBN} associates its own thread
2353 number---a small integer assigned in thread-creation order---with each
2354 thread in your program.
2355
2356 @cindex @code{New} @var{systag} message, on HP-UX
2357 @cindex thread identifier (system), on HP-UX
2358 @c FIXME-implementors!! It would be more helpful if the [New...] message
2359 @c included GDB's numeric thread handle, so you could just go to that
2360 @c thread without first checking `info threads'.
2361 Whenever @value{GDBN} detects a new thread in your program, it displays
2362 both @value{GDBN}'s thread number and the target system's identification for the thread with a message in the
2363 form @samp{[New @var{systag}]}. @var{systag} is a thread identifier
2364 whose form varies depending on the particular system. For example, on
2365 HP-UX, you see
2366
2367 @smallexample
2368 [New thread 2 (system thread 26594)]
2369 @end smallexample
2370
2371 @noindent
2372 when @value{GDBN} notices a new thread.
2373
2374 @table @code
2375 @kindex info threads (HP-UX)
2376 @item info threads
2377 Display a summary of all threads currently in your
2378 program. @value{GDBN} displays for each thread (in this order):
2379
2380 @enumerate
2381 @item the thread number assigned by @value{GDBN}
2382
2383 @item the target system's thread identifier (@var{systag})
2384
2385 @item the current stack frame summary for that thread
2386 @end enumerate
2387
2388 @noindent
2389 An asterisk @samp{*} to the left of the @value{GDBN} thread number
2390 indicates the current thread.
2391
2392 For example,
2393 @end table
2394 @c end table here to get a little more width for example
2395
2396 @smallexample
2397 (@value{GDBP}) info threads
2398 * 3 system thread 26607 worker (wptr=0x7b09c318 "@@") \@*
2399 at quicksort.c:137
2400 2 system thread 26606 0x7b0030d8 in __ksleep () \@*
2401 from /usr/lib/libc.2
2402 1 system thread 27905 0x7b003498 in _brk () \@*
2403 from /usr/lib/libc.2
2404 @end smallexample
2405
2406 On Solaris, you can display more information about user threads with a
2407 Solaris-specific command:
2408
2409 @table @code
2410 @item maint info sol-threads
2411 @kindex maint info sol-threads
2412 @cindex thread info (Solaris)
2413 Display info on Solaris user threads.
2414 @end table
2415
2416 @table @code
2417 @kindex thread @var{threadno}
2418 @item thread @var{threadno}
2419 Make thread number @var{threadno} the current thread. The command
2420 argument @var{threadno} is the internal @value{GDBN} thread number, as
2421 shown in the first field of the @samp{info threads} display.
2422 @value{GDBN} responds by displaying the system identifier of the thread
2423 you selected, and its current stack frame summary:
2424
2425 @smallexample
2426 @c FIXME!! This example made up; find a @value{GDBN} w/threads and get real one
2427 (@value{GDBP}) thread 2
2428 [Switching to process 35 thread 23]
2429 0x34e5 in sigpause ()
2430 @end smallexample
2431
2432 @noindent
2433 As with the @samp{[New @dots{}]} message, the form of the text after
2434 @samp{Switching to} depends on your system's conventions for identifying
2435 threads.
2436
2437 @kindex thread apply
2438 @cindex apply command to several threads
2439 @item thread apply [@var{threadno}] [@var{all}] @var{command}
2440 The @code{thread apply} command allows you to apply the named
2441 @var{command} to one or more threads. Specify the numbers of the
2442 threads that you want affected with the command argument
2443 @var{threadno}. It can be a single thread number, one of the numbers
2444 shown in the first field of the @samp{info threads} display; or it
2445 could be a range of thread numbers, as in @code{2-4}. To apply a
2446 command to all threads, type @kbd{thread apply all @var{command}}.
2447
2448 @kindex set print thread-events
2449 @cindex print messages on thread start and exit
2450 @item set print thread-events
2451 @itemx set print thread-events on
2452 @itemx set print thread-events off
2453 The @code{set print thread-events} command allows you to enable or
2454 disable printing of messages when @value{GDBN} notices that new threads have
2455 started or that threads have exited. By default, these messages will
2456 be printed if detection of these events is supported by the target.
2457 Note that these messages cannot be disabled on all targets.
2458
2459 @kindex show print thread-events
2460 @item show print thread-events
2461 Show whether messages will be printed when @value{GDBN} detects that threads
2462 have started and exited.
2463 @end table
2464
2465 @cindex automatic thread selection
2466 @cindex switching threads automatically
2467 @cindex threads, automatic switching
2468 Whenever @value{GDBN} stops your program, due to a breakpoint or a
2469 signal, it automatically selects the thread where that breakpoint or
2470 signal happened. @value{GDBN} alerts you to the context switch with a
2471 message of the form @samp{[Switching to @var{systag}]} to identify the
2472 thread.
2473
2474 @xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
2475 more information about how @value{GDBN} behaves when you stop and start
2476 programs with multiple threads.
2477
2478 @xref{Set Watchpoints,,Setting Watchpoints}, for information about
2479 watchpoints in programs with multiple threads.
2480
2481 @node Processes
2482 @section Debugging Programs with Multiple Processes
2483
2484 @cindex fork, debugging programs which call
2485 @cindex multiple processes
2486 @cindex processes, multiple
2487 On most systems, @value{GDBN} has no special support for debugging
2488 programs which create additional processes using the @code{fork}
2489 function. When a program forks, @value{GDBN} will continue to debug the
2490 parent process and the child process will run unimpeded. If you have
2491 set a breakpoint in any code which the child then executes, the child
2492 will get a @code{SIGTRAP} signal which (unless it catches the signal)
2493 will cause it to terminate.
2494
2495 However, if you want to debug the child process there is a workaround
2496 which isn't too painful. Put a call to @code{sleep} in the code which
2497 the child process executes after the fork. It may be useful to sleep
2498 only if a certain environment variable is set, or a certain file exists,
2499 so that the delay need not occur when you don't want to run @value{GDBN}
2500 on the child. While the child is sleeping, use the @code{ps} program to
2501 get its process ID. Then tell @value{GDBN} (a new invocation of
2502 @value{GDBN} if you are also debugging the parent process) to attach to
2503 the child process (@pxref{Attach}). From that point on you can debug
2504 the child process just like any other process which you attached to.
2505
2506 On some systems, @value{GDBN} provides support for debugging programs that
2507 create additional processes using the @code{fork} or @code{vfork} functions.
2508 Currently, the only platforms with this feature are HP-UX (11.x and later
2509 only?) and @sc{gnu}/Linux (kernel version 2.5.60 and later).
2510
2511 By default, when a program forks, @value{GDBN} will continue to debug
2512 the parent process and the child process will run unimpeded.
2513
2514 If you want to follow the child process instead of the parent process,
2515 use the command @w{@code{set follow-fork-mode}}.
2516
2517 @table @code
2518 @kindex set follow-fork-mode
2519 @item set follow-fork-mode @var{mode}
2520 Set the debugger response to a program call of @code{fork} or
2521 @code{vfork}. A call to @code{fork} or @code{vfork} creates a new
2522 process. The @var{mode} argument can be:
2523
2524 @table @code
2525 @item parent
2526 The original process is debugged after a fork. The child process runs
2527 unimpeded. This is the default.
2528
2529 @item child
2530 The new process is debugged after a fork. The parent process runs
2531 unimpeded.
2532
2533 @end table
2534
2535 @kindex show follow-fork-mode
2536 @item show follow-fork-mode
2537 Display the current debugger response to a @code{fork} or @code{vfork} call.
2538 @end table
2539
2540 @cindex debugging multiple processes
2541 On Linux, if you want to debug both the parent and child processes, use the
2542 command @w{@code{set detach-on-fork}}.
2543
2544 @table @code
2545 @kindex set detach-on-fork
2546 @item set detach-on-fork @var{mode}
2547 Tells gdb whether to detach one of the processes after a fork, or
2548 retain debugger control over them both.
2549
2550 @table @code
2551 @item on
2552 The child process (or parent process, depending on the value of
2553 @code{follow-fork-mode}) will be detached and allowed to run
2554 independently. This is the default.
2555
2556 @item off
2557 Both processes will be held under the control of @value{GDBN}.
2558 One process (child or parent, depending on the value of
2559 @code{follow-fork-mode}) is debugged as usual, while the other
2560 is held suspended.
2561
2562 @end table
2563
2564 @kindex show detach-on-fork
2565 @item show detach-on-fork
2566 Show whether detach-on-fork mode is on/off.
2567 @end table
2568
2569 If you choose to set @samp{detach-on-fork} mode off, then
2570 @value{GDBN} will retain control of all forked processes (including
2571 nested forks). You can list the forked processes under the control of
2572 @value{GDBN} by using the @w{@code{info forks}} command, and switch
2573 from one fork to another by using the @w{@code{fork}} command.
2574
2575 @table @code
2576 @kindex info forks
2577 @item info forks
2578 Print a list of all forked processes under the control of @value{GDBN}.
2579 The listing will include a fork id, a process id, and the current
2580 position (program counter) of the process.
2581
2582 @kindex fork @var{fork-id}
2583 @item fork @var{fork-id}
2584 Make fork number @var{fork-id} the current process. The argument
2585 @var{fork-id} is the internal fork number assigned by @value{GDBN},
2586 as shown in the first field of the @samp{info forks} display.
2587
2588 @kindex process @var{process-id}
2589 @item process @var{process-id}
2590 Make process number @var{process-id} the current process. The
2591 argument @var{process-id} must be one that is listed in the output of
2592 @samp{info forks}.
2593
2594 @end table
2595
2596 To quit debugging one of the forked processes, you can either detach
2597 from it by using the @w{@code{detach fork}} command (allowing it to
2598 run independently), or delete (and kill) it using the
2599 @w{@code{delete fork}} command.
2600
2601 @table @code
2602 @kindex detach fork @var{fork-id}
2603 @item detach fork @var{fork-id}
2604 Detach from the process identified by @value{GDBN} fork number
2605 @var{fork-id}, and remove it from the fork list. The process will be
2606 allowed to run independently.
2607
2608 @kindex delete fork @var{fork-id}
2609 @item delete fork @var{fork-id}
2610 Kill the process identified by @value{GDBN} fork number @var{fork-id},
2611 and remove it from the fork list.
2612
2613 @end table
2614
2615 If you ask to debug a child process and a @code{vfork} is followed by an
2616 @code{exec}, @value{GDBN} executes the new target up to the first
2617 breakpoint in the new target. If you have a breakpoint set on
2618 @code{main} in your original program, the breakpoint will also be set on
2619 the child process's @code{main}.
2620
2621 When a child process is spawned by @code{vfork}, you cannot debug the
2622 child or parent until an @code{exec} call completes.
2623
2624 If you issue a @code{run} command to @value{GDBN} after an @code{exec}
2625 call executes, the new target restarts. To restart the parent process,
2626 use the @code{file} command with the parent executable name as its
2627 argument.
2628
2629 You can use the @code{catch} command to make @value{GDBN} stop whenever
2630 a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
2631 Catchpoints, ,Setting Catchpoints}.
2632
2633 @node Checkpoint/Restart
2634 @section Setting a @emph{Bookmark} to Return to Later
2635
2636 @cindex checkpoint
2637 @cindex restart
2638 @cindex bookmark
2639 @cindex snapshot of a process
2640 @cindex rewind program state
2641
2642 On certain operating systems@footnote{Currently, only
2643 @sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
2644 program's state, called a @dfn{checkpoint}, and come back to it
2645 later.
2646
2647 Returning to a checkpoint effectively undoes everything that has
2648 happened in the program since the @code{checkpoint} was saved. This
2649 includes changes in memory, registers, and even (within some limits)
2650 system state. Effectively, it is like going back in time to the
2651 moment when the checkpoint was saved.
2652
2653 Thus, if you're stepping thru a program and you think you're
2654 getting close to the point where things go wrong, you can save
2655 a checkpoint. Then, if you accidentally go too far and miss
2656 the critical statement, instead of having to restart your program
2657 from the beginning, you can just go back to the checkpoint and
2658 start again from there.
2659
2660 This can be especially useful if it takes a lot of time or
2661 steps to reach the point where you think the bug occurs.
2662
2663 To use the @code{checkpoint}/@code{restart} method of debugging:
2664
2665 @table @code
2666 @kindex checkpoint
2667 @item checkpoint
2668 Save a snapshot of the debugged program's current execution state.
2669 The @code{checkpoint} command takes no arguments, but each checkpoint
2670 is assigned a small integer id, similar to a breakpoint id.
2671
2672 @kindex info checkpoints
2673 @item info checkpoints
2674 List the checkpoints that have been saved in the current debugging
2675 session. For each checkpoint, the following information will be
2676 listed:
2677
2678 @table @code
2679 @item Checkpoint ID
2680 @item Process ID
2681 @item Code Address
2682 @item Source line, or label
2683 @end table
2684
2685 @kindex restart @var{checkpoint-id}
2686 @item restart @var{checkpoint-id}
2687 Restore the program state that was saved as checkpoint number
2688 @var{checkpoint-id}. All program variables, registers, stack frames
2689 etc.@: will be returned to the values that they had when the checkpoint
2690 was saved. In essence, gdb will ``wind back the clock'' to the point
2691 in time when the checkpoint was saved.
2692
2693 Note that breakpoints, @value{GDBN} variables, command history etc.
2694 are not affected by restoring a checkpoint. In general, a checkpoint
2695 only restores things that reside in the program being debugged, not in
2696 the debugger.
2697
2698 @kindex delete checkpoint @var{checkpoint-id}
2699 @item delete checkpoint @var{checkpoint-id}
2700 Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
2701
2702 @end table
2703
2704 Returning to a previously saved checkpoint will restore the user state
2705 of the program being debugged, plus a significant subset of the system
2706 (OS) state, including file pointers. It won't ``un-write'' data from
2707 a file, but it will rewind the file pointer to the previous location,
2708 so that the previously written data can be overwritten. For files
2709 opened in read mode, the pointer will also be restored so that the
2710 previously read data can be read again.
2711
2712 Of course, characters that have been sent to a printer (or other
2713 external device) cannot be ``snatched back'', and characters received
2714 from eg.@: a serial device can be removed from internal program buffers,
2715 but they cannot be ``pushed back'' into the serial pipeline, ready to
2716 be received again. Similarly, the actual contents of files that have
2717 been changed cannot be restored (at this time).
2718
2719 However, within those constraints, you actually can ``rewind'' your
2720 program to a previously saved point in time, and begin debugging it
2721 again --- and you can change the course of events so as to debug a
2722 different execution path this time.
2723
2724 @cindex checkpoints and process id
2725 Finally, there is one bit of internal program state that will be
2726 different when you return to a checkpoint --- the program's process
2727 id. Each checkpoint will have a unique process id (or @var{pid}),
2728 and each will be different from the program's original @var{pid}.
2729 If your program has saved a local copy of its process id, this could
2730 potentially pose a problem.
2731
2732 @subsection A Non-obvious Benefit of Using Checkpoints
2733
2734 On some systems such as @sc{gnu}/Linux, address space randomization
2735 is performed on new processes for security reasons. This makes it
2736 difficult or impossible to set a breakpoint, or watchpoint, on an
2737 absolute address if you have to restart the program, since the
2738 absolute location of a symbol will change from one execution to the
2739 next.
2740
2741 A checkpoint, however, is an @emph{identical} copy of a process.
2742 Therefore if you create a checkpoint at (eg.@:) the start of main,
2743 and simply return to that checkpoint instead of restarting the
2744 process, you can avoid the effects of address randomization and
2745 your symbols will all stay in the same place.
2746
2747 @node Stopping
2748 @chapter Stopping and Continuing
2749
2750 The principal purposes of using a debugger are so that you can stop your
2751 program before it terminates; or so that, if your program runs into
2752 trouble, you can investigate and find out why.
2753
2754 Inside @value{GDBN}, your program may stop for any of several reasons,
2755 such as a signal, a breakpoint, or reaching a new line after a
2756 @value{GDBN} command such as @code{step}. You may then examine and
2757 change variables, set new breakpoints or remove old ones, and then
2758 continue execution. Usually, the messages shown by @value{GDBN} provide
2759 ample explanation of the status of your program---but you can also
2760 explicitly request this information at any time.
2761
2762 @table @code
2763 @kindex info program
2764 @item info program
2765 Display information about the status of your program: whether it is
2766 running or not, what process it is, and why it stopped.
2767 @end table
2768
2769 @menu
2770 * Breakpoints:: Breakpoints, watchpoints, and catchpoints
2771 * Continuing and Stepping:: Resuming execution
2772 * Signals:: Signals
2773 * Thread Stops:: Stopping and starting multi-thread programs
2774 @end menu
2775
2776 @node Breakpoints
2777 @section Breakpoints, Watchpoints, and Catchpoints
2778
2779 @cindex breakpoints
2780 A @dfn{breakpoint} makes your program stop whenever a certain point in
2781 the program is reached. For each breakpoint, you can add conditions to
2782 control in finer detail whether your program stops. You can set
2783 breakpoints with the @code{break} command and its variants (@pxref{Set
2784 Breaks, ,Setting Breakpoints}), to specify the place where your program
2785 should stop by line number, function name or exact address in the
2786 program.
2787
2788 On some systems, you can set breakpoints in shared libraries before
2789 the executable is run. There is a minor limitation on HP-UX systems:
2790 you must wait until the executable is run in order to set breakpoints
2791 in shared library routines that are not called directly by the program
2792 (for example, routines that are arguments in a @code{pthread_create}
2793 call).
2794
2795 @cindex watchpoints
2796 @cindex data breakpoints
2797 @cindex memory tracing
2798 @cindex breakpoint on memory address
2799 @cindex breakpoint on variable modification
2800 A @dfn{watchpoint} is a special breakpoint that stops your program
2801 when the value of an expression changes. The expression may be a value
2802 of a variable, or it could involve values of one or more variables
2803 combined by operators, such as @samp{a + b}. This is sometimes called
2804 @dfn{data breakpoints}. You must use a different command to set
2805 watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
2806 from that, you can manage a watchpoint like any other breakpoint: you
2807 enable, disable, and delete both breakpoints and watchpoints using the
2808 same commands.
2809
2810 You can arrange to have values from your program displayed automatically
2811 whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
2812 Automatic Display}.
2813
2814 @cindex catchpoints
2815 @cindex breakpoint on events
2816 A @dfn{catchpoint} is another special breakpoint that stops your program
2817 when a certain kind of event occurs, such as the throwing of a C@t{++}
2818 exception or the loading of a library. As with watchpoints, you use a
2819 different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
2820 Catchpoints}), but aside from that, you can manage a catchpoint like any
2821 other breakpoint. (To stop when your program receives a signal, use the
2822 @code{handle} command; see @ref{Signals, ,Signals}.)
2823
2824 @cindex breakpoint numbers
2825 @cindex numbers for breakpoints
2826 @value{GDBN} assigns a number to each breakpoint, watchpoint, or
2827 catchpoint when you create it; these numbers are successive integers
2828 starting with one. In many of the commands for controlling various
2829 features of breakpoints you use the breakpoint number to say which
2830 breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
2831 @dfn{disabled}; if disabled, it has no effect on your program until you
2832 enable it again.
2833
2834 @cindex breakpoint ranges
2835 @cindex ranges of breakpoints
2836 Some @value{GDBN} commands accept a range of breakpoints on which to
2837 operate. A breakpoint range is either a single breakpoint number, like
2838 @samp{5}, or two such numbers, in increasing order, separated by a
2839 hyphen, like @samp{5-7}. When a breakpoint range is given to a command,
2840 all breakpoints in that range are operated on.
2841
2842 @menu
2843 * Set Breaks:: Setting breakpoints
2844 * Set Watchpoints:: Setting watchpoints
2845 * Set Catchpoints:: Setting catchpoints
2846 * Delete Breaks:: Deleting breakpoints
2847 * Disabling:: Disabling breakpoints
2848 * Conditions:: Break conditions
2849 * Break Commands:: Breakpoint command lists
2850 * Breakpoint Menus:: Breakpoint menus
2851 * Error in Breakpoints:: ``Cannot insert breakpoints''
2852 * Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
2853 @end menu
2854
2855 @node Set Breaks
2856 @subsection Setting Breakpoints
2857
2858 @c FIXME LMB what does GDB do if no code on line of breakpt?
2859 @c consider in particular declaration with/without initialization.
2860 @c
2861 @c FIXME 2 is there stuff on this already? break at fun start, already init?
2862
2863 @kindex break
2864 @kindex b @r{(@code{break})}
2865 @vindex $bpnum@r{, convenience variable}
2866 @cindex latest breakpoint
2867 Breakpoints are set with the @code{break} command (abbreviated
2868 @code{b}). The debugger convenience variable @samp{$bpnum} records the
2869 number of the breakpoint you've set most recently; see @ref{Convenience
2870 Vars,, Convenience Variables}, for a discussion of what you can do with
2871 convenience variables.
2872
2873 @table @code
2874 @item break @var{location}
2875 Set a breakpoint at the given @var{location}, which can specify a
2876 function name, a line number, or an address of an instruction.
2877 (@xref{Specify Location}, for a list of all the possible ways to
2878 specify a @var{location}.) The breakpoint will stop your program just
2879 before it executes any of the code in the specified @var{location}.
2880
2881 When using source languages that permit overloading of symbols, such as
2882 C@t{++}, a function name may refer to more than one possible place to break.
2883 @xref{Breakpoint Menus,,Breakpoint Menus}, for a discussion of that situation.
2884
2885 @item break
2886 When called without any arguments, @code{break} sets a breakpoint at
2887 the next instruction to be executed in the selected stack frame
2888 (@pxref{Stack, ,Examining the Stack}). In any selected frame but the
2889 innermost, this makes your program stop as soon as control
2890 returns to that frame. This is similar to the effect of a
2891 @code{finish} command in the frame inside the selected frame---except
2892 that @code{finish} does not leave an active breakpoint. If you use
2893 @code{break} without an argument in the innermost frame, @value{GDBN} stops
2894 the next time it reaches the current location; this may be useful
2895 inside loops.
2896
2897 @value{GDBN} normally ignores breakpoints when it resumes execution, until at
2898 least one instruction has been executed. If it did not do this, you
2899 would be unable to proceed past a breakpoint without first disabling the
2900 breakpoint. This rule applies whether or not the breakpoint already
2901 existed when your program stopped.
2902
2903 @item break @dots{} if @var{cond}
2904 Set a breakpoint with condition @var{cond}; evaluate the expression
2905 @var{cond} each time the breakpoint is reached, and stop only if the
2906 value is nonzero---that is, if @var{cond} evaluates as true.
2907 @samp{@dots{}} stands for one of the possible arguments described
2908 above (or no argument) specifying where to break. @xref{Conditions,
2909 ,Break Conditions}, for more information on breakpoint conditions.
2910
2911 @kindex tbreak
2912 @item tbreak @var{args}
2913 Set a breakpoint enabled only for one stop. @var{args} are the
2914 same as for the @code{break} command, and the breakpoint is set in the same
2915 way, but the breakpoint is automatically deleted after the first time your
2916 program stops there. @xref{Disabling, ,Disabling Breakpoints}.
2917
2918 @kindex hbreak
2919 @cindex hardware breakpoints
2920 @item hbreak @var{args}
2921 Set a hardware-assisted breakpoint. @var{args} are the same as for the
2922 @code{break} command and the breakpoint is set in the same way, but the
2923 breakpoint requires hardware support and some target hardware may not
2924 have this support. The main purpose of this is EPROM/ROM code
2925 debugging, so you can set a breakpoint at an instruction without
2926 changing the instruction. This can be used with the new trap-generation
2927 provided by SPARClite DSU and most x86-based targets. These targets
2928 will generate traps when a program accesses some data or instruction
2929 address that is assigned to the debug registers. However the hardware
2930 breakpoint registers can take a limited number of breakpoints. For
2931 example, on the DSU, only two data breakpoints can be set at a time, and
2932 @value{GDBN} will reject this command if more than two are used. Delete
2933 or disable unused hardware breakpoints before setting new ones
2934 (@pxref{Disabling, ,Disabling Breakpoints}).
2935 @xref{Conditions, ,Break Conditions}.
2936 For remote targets, you can restrict the number of hardware
2937 breakpoints @value{GDBN} will use, see @ref{set remote
2938 hardware-breakpoint-limit}.
2939
2940 @kindex thbreak
2941 @item thbreak @var{args}
2942 Set a hardware-assisted breakpoint enabled only for one stop. @var{args}
2943 are the same as for the @code{hbreak} command and the breakpoint is set in
2944 the same way. However, like the @code{tbreak} command,
2945 the breakpoint is automatically deleted after the
2946 first time your program stops there. Also, like the @code{hbreak}
2947 command, the breakpoint requires hardware support and some target hardware
2948 may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
2949 See also @ref{Conditions, ,Break Conditions}.
2950
2951 @kindex rbreak
2952 @cindex regular expression
2953 @cindex breakpoints in functions matching a regexp
2954 @cindex set breakpoints in many functions
2955 @item rbreak @var{regex}
2956 Set breakpoints on all functions matching the regular expression
2957 @var{regex}. This command sets an unconditional breakpoint on all
2958 matches, printing a list of all breakpoints it set. Once these
2959 breakpoints are set, they are treated just like the breakpoints set with
2960 the @code{break} command. You can delete them, disable them, or make
2961 them conditional the same way as any other breakpoint.
2962
2963 The syntax of the regular expression is the standard one used with tools
2964 like @file{grep}. Note that this is different from the syntax used by
2965 shells, so for instance @code{foo*} matches all functions that include
2966 an @code{fo} followed by zero or more @code{o}s. There is an implicit
2967 @code{.*} leading and trailing the regular expression you supply, so to
2968 match only functions that begin with @code{foo}, use @code{^foo}.
2969
2970 @cindex non-member C@t{++} functions, set breakpoint in
2971 When debugging C@t{++} programs, @code{rbreak} is useful for setting
2972 breakpoints on overloaded functions that are not members of any special
2973 classes.
2974
2975 @cindex set breakpoints on all functions
2976 The @code{rbreak} command can be used to set breakpoints in
2977 @strong{all} the functions in a program, like this:
2978
2979 @smallexample
2980 (@value{GDBP}) rbreak .
2981 @end smallexample
2982
2983 @kindex info breakpoints
2984 @cindex @code{$_} and @code{info breakpoints}
2985 @item info breakpoints @r{[}@var{n}@r{]}
2986 @itemx info break @r{[}@var{n}@r{]}
2987 @itemx info watchpoints @r{[}@var{n}@r{]}
2988 Print a table of all breakpoints, watchpoints, and catchpoints set and
2989 not deleted. Optional argument @var{n} means print information only
2990 about the specified breakpoint (or watchpoint or catchpoint). For
2991 each breakpoint, following columns are printed:
2992
2993 @table @emph
2994 @item Breakpoint Numbers
2995 @item Type
2996 Breakpoint, watchpoint, or catchpoint.
2997 @item Disposition
2998 Whether the breakpoint is marked to be disabled or deleted when hit.
2999 @item Enabled or Disabled
3000 Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
3001 that are not enabled.
3002 @item Address
3003 Where the breakpoint is in your program, as a memory address. For a
3004 pending breakpoint whose address is not yet known, this field will
3005 contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
3006 library that has the symbol or line referred by breakpoint is loaded.
3007 See below for details. A breakpoint with several locations will
3008 have @samp{<MULTIPLE>} in this field---see below for details.
3009 @item What
3010 Where the breakpoint is in the source for your program, as a file and
3011 line number. For a pending breakpoint, the original string passed to
3012 the breakpoint command will be listed as it cannot be resolved until
3013 the appropriate shared library is loaded in the future.
3014 @end table
3015
3016 @noindent
3017 If a breakpoint is conditional, @code{info break} shows the condition on
3018 the line following the affected breakpoint; breakpoint commands, if any,
3019 are listed after that. A pending breakpoint is allowed to have a condition
3020 specified for it. The condition is not parsed for validity until a shared
3021 library is loaded that allows the pending breakpoint to resolve to a
3022 valid location.
3023
3024 @noindent
3025 @code{info break} with a breakpoint
3026 number @var{n} as argument lists only that breakpoint. The
3027 convenience variable @code{$_} and the default examining-address for
3028 the @code{x} command are set to the address of the last breakpoint
3029 listed (@pxref{Memory, ,Examining Memory}).
3030
3031 @noindent
3032 @code{info break} displays a count of the number of times the breakpoint
3033 has been hit. This is especially useful in conjunction with the
3034 @code{ignore} command. You can ignore a large number of breakpoint
3035 hits, look at the breakpoint info to see how many times the breakpoint
3036 was hit, and then run again, ignoring one less than that number. This
3037 will get you quickly to the last hit of that breakpoint.
3038 @end table
3039
3040 @value{GDBN} allows you to set any number of breakpoints at the same place in
3041 your program. There is nothing silly or meaningless about this. When
3042 the breakpoints are conditional, this is even useful
3043 (@pxref{Conditions, ,Break Conditions}).
3044
3045 It is possible that a breakpoint corresponds to several locations
3046 in your program. Examples of this situation are:
3047
3048 @itemize @bullet
3049
3050 @item
3051 For a C@t{++} constructor, the @value{NGCC} compiler generates several
3052 instances of the function body, used in different cases.
3053
3054 @item
3055 For a C@t{++} template function, a given line in the function can
3056 correspond to any number of instantiations.
3057
3058 @item
3059 For an inlined function, a given source line can correspond to
3060 several places where that function is inlined.
3061
3062 @end itemize
3063
3064 In all those cases, @value{GDBN} will insert a breakpoint at all
3065 the relevant locations.
3066
3067 A breakpoint with multiple locations is displayed in the breakpoint
3068 table using several rows---one header row, followed by one row for
3069 each breakpoint location. The header row has @samp{<MULTIPLE>} in the
3070 address column. The rows for individual locations contain the actual
3071 addresses for locations, and show the functions to which those
3072 locations belong. The number column for a location is of the form
3073 @var{breakpoint-number}.@var{location-number}.
3074
3075 For example:
3076
3077 @smallexample
3078 Num Type Disp Enb Address What
3079 1 breakpoint keep y <MULTIPLE>
3080 stop only if i==1
3081 breakpoint already hit 1 time
3082 1.1 y 0x080486a2 in void foo<int>() at t.cc:8
3083 1.2 y 0x080486ca in void foo<double>() at t.cc:8
3084 @end smallexample
3085
3086 Each location can be individually enabled or disabled by passing
3087 @var{breakpoint-number}.@var{location-number} as argument to the
3088 @code{enable} and @code{disable} commands. Note that you cannot
3089 delete the individual locations from the list, you can only delete the
3090 entire list of locations that belong to their parent breakpoint (with
3091 the @kbd{delete @var{num}} command, where @var{num} is the number of
3092 the parent breakpoint, 1 in the above example). Disabling or enabling
3093 the parent breakpoint (@pxref{Disabling}) affects all of the locations
3094 that belong to that breakpoint.
3095
3096 @cindex pending breakpoints
3097 It's quite common to have a breakpoint inside a shared library.
3098 Shared libraries can be loaded and unloaded explicitly,
3099 and possibly repeatedly, as the program is executed. To support
3100 this use case, @value{GDBN} updates breakpoint locations whenever
3101 any shared library is loaded or unloaded. Typically, you would
3102 set a breakpoint in a shared library at the beginning of your
3103 debugging session, when the library is not loaded, and when the
3104 symbols from the library are not available. When you try to set
3105 breakpoint, @value{GDBN} will ask you if you want to set
3106 a so called @dfn{pending breakpoint}---breakpoint whose address
3107 is not yet resolved.
3108
3109 After the program is run, whenever a new shared library is loaded,
3110 @value{GDBN} reevaluates all the breakpoints. When a newly loaded
3111 shared library contains the symbol or line referred to by some
3112 pending breakpoint, that breakpoint is resolved and becomes an
3113 ordinary breakpoint. When a library is unloaded, all breakpoints
3114 that refer to its symbols or source lines become pending again.
3115
3116 This logic works for breakpoints with multiple locations, too. For
3117 example, if you have a breakpoint in a C@t{++} template function, and
3118 a newly loaded shared library has an instantiation of that template,
3119 a new location is added to the list of locations for the breakpoint.
3120
3121 Except for having unresolved address, pending breakpoints do not
3122 differ from regular breakpoints. You can set conditions or commands,
3123 enable and disable them and perform other breakpoint operations.
3124
3125 @value{GDBN} provides some additional commands for controlling what
3126 happens when the @samp{break} command cannot resolve breakpoint
3127 address specification to an address:
3128
3129 @kindex set breakpoint pending
3130 @kindex show breakpoint pending
3131 @table @code
3132 @item set breakpoint pending auto
3133 This is the default behavior. When @value{GDBN} cannot find the breakpoint
3134 location, it queries you whether a pending breakpoint should be created.
3135
3136 @item set breakpoint pending on
3137 This indicates that an unrecognized breakpoint location should automatically
3138 result in a pending breakpoint being created.
3139
3140 @item set breakpoint pending off
3141 This indicates that pending breakpoints are not to be created. Any
3142 unrecognized breakpoint location results in an error. This setting does
3143 not affect any pending breakpoints previously created.
3144
3145 @item show breakpoint pending
3146 Show the current behavior setting for creating pending breakpoints.
3147 @end table
3148
3149 The settings above only affect the @code{break} command and its
3150 variants. Once breakpoint is set, it will be automatically updated
3151 as shared libraries are loaded and unloaded.
3152
3153 @cindex automatic hardware breakpoints
3154 For some targets, @value{GDBN} can automatically decide if hardware or
3155 software breakpoints should be used, depending on whether the
3156 breakpoint address is read-only or read-write. This applies to
3157 breakpoints set with the @code{break} command as well as to internal
3158 breakpoints set by commands like @code{next} and @code{finish}. For
3159 breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
3160 breakpoints.
3161
3162 You can control this automatic behaviour with the following commands::
3163
3164 @kindex set breakpoint auto-hw
3165 @kindex show breakpoint auto-hw
3166 @table @code
3167 @item set breakpoint auto-hw on
3168 This is the default behavior. When @value{GDBN} sets a breakpoint, it
3169 will try to use the target memory map to decide if software or hardware
3170 breakpoint must be used.
3171
3172 @item set breakpoint auto-hw off
3173 This indicates @value{GDBN} should not automatically select breakpoint
3174 type. If the target provides a memory map, @value{GDBN} will warn when
3175 trying to set software breakpoint at a read-only address.
3176 @end table
3177
3178
3179 @cindex negative breakpoint numbers
3180 @cindex internal @value{GDBN} breakpoints
3181 @value{GDBN} itself sometimes sets breakpoints in your program for
3182 special purposes, such as proper handling of @code{longjmp} (in C
3183 programs). These internal breakpoints are assigned negative numbers,
3184 starting with @code{-1}; @samp{info breakpoints} does not display them.
3185 You can see these breakpoints with the @value{GDBN} maintenance command
3186 @samp{maint info breakpoints} (@pxref{maint info breakpoints}).
3187
3188
3189 @node Set Watchpoints
3190 @subsection Setting Watchpoints
3191
3192 @cindex setting watchpoints
3193 You can use a watchpoint to stop execution whenever the value of an
3194 expression changes, without having to predict a particular place where
3195 this may happen. (This is sometimes called a @dfn{data breakpoint}.)
3196 The expression may be as simple as the value of a single variable, or
3197 as complex as many variables combined by operators. Examples include:
3198
3199 @itemize @bullet
3200 @item
3201 A reference to the value of a single variable.
3202
3203 @item
3204 An address cast to an appropriate data type. For example,
3205 @samp{*(int *)0x12345678} will watch a 4-byte region at the specified
3206 address (assuming an @code{int} occupies 4 bytes).
3207
3208 @item
3209 An arbitrarily complex expression, such as @samp{a*b + c/d}. The
3210 expression can use any operators valid in the program's native
3211 language (@pxref{Languages}).
3212 @end itemize
3213
3214 @cindex software watchpoints
3215 @cindex hardware watchpoints
3216 Depending on your system, watchpoints may be implemented in software or
3217 hardware. @value{GDBN} does software watchpointing by single-stepping your
3218 program and testing the variable's value each time, which is hundreds of
3219 times slower than normal execution. (But this may still be worth it, to
3220 catch errors where you have no clue what part of your program is the
3221 culprit.)
3222
3223 On some systems, such as HP-UX, PowerPC, @sc{gnu}/Linux and most other
3224 x86-based targets, @value{GDBN} includes support for hardware
3225 watchpoints, which do not slow down the running of your program.
3226
3227 @table @code
3228 @kindex watch
3229 @item watch @var{expr} @r{[}thread @var{threadnum}@r{]}
3230 Set a watchpoint for an expression. @value{GDBN} will break when the
3231 expression @var{expr} is written into by the program and its value
3232 changes. The simplest (and the most popular) use of this command is
3233 to watch the value of a single variable:
3234
3235 @smallexample
3236 (@value{GDBP}) watch foo
3237 @end smallexample
3238
3239 If the command includes a @code{@r{[}thread @var{threadnum}@r{]}}
3240 clause, @value{GDBN} breaks only when the thread identified by
3241 @var{threadnum} changes the value of @var{expr}. If any other threads
3242 change the value of @var{expr}, @value{GDBN} will not break. Note
3243 that watchpoints restricted to a single thread in this way only work
3244 with Hardware Watchpoints.
3245
3246 @kindex rwatch
3247 @item rwatch @var{expr} @r{[}thread @var{threadnum}@r{]}
3248 Set a watchpoint that will break when the value of @var{expr} is read
3249 by the program.
3250
3251 @kindex awatch
3252 @item awatch @var{expr} @r{[}thread @var{threadnum}@r{]}
3253 Set a watchpoint that will break when @var{expr} is either read from
3254 or written into by the program.
3255
3256 @kindex info watchpoints @r{[}@var{n}@r{]}
3257 @item info watchpoints
3258 This command prints a list of watchpoints, breakpoints, and catchpoints;
3259 it is the same as @code{info break} (@pxref{Set Breaks}).
3260 @end table
3261
3262 @value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
3263 watchpoints execute very quickly, and the debugger reports a change in
3264 value at the exact instruction where the change occurs. If @value{GDBN}
3265 cannot set a hardware watchpoint, it sets a software watchpoint, which
3266 executes more slowly and reports the change in value at the next
3267 @emph{statement}, not the instruction, after the change occurs.
3268
3269 @cindex use only software watchpoints
3270 You can force @value{GDBN} to use only software watchpoints with the
3271 @kbd{set can-use-hw-watchpoints 0} command. With this variable set to
3272 zero, @value{GDBN} will never try to use hardware watchpoints, even if
3273 the underlying system supports them. (Note that hardware-assisted
3274 watchpoints that were set @emph{before} setting
3275 @code{can-use-hw-watchpoints} to zero will still use the hardware
3276 mechanism of watching expression values.)
3277
3278 @table @code
3279 @item set can-use-hw-watchpoints
3280 @kindex set can-use-hw-watchpoints
3281 Set whether or not to use hardware watchpoints.
3282
3283 @item show can-use-hw-watchpoints
3284 @kindex show can-use-hw-watchpoints
3285 Show the current mode of using hardware watchpoints.
3286 @end table
3287
3288 For remote targets, you can restrict the number of hardware
3289 watchpoints @value{GDBN} will use, see @ref{set remote
3290 hardware-breakpoint-limit}.
3291
3292 When you issue the @code{watch} command, @value{GDBN} reports
3293
3294 @smallexample
3295 Hardware watchpoint @var{num}: @var{expr}
3296 @end smallexample
3297
3298 @noindent
3299 if it was able to set a hardware watchpoint.
3300
3301 Currently, the @code{awatch} and @code{rwatch} commands can only set
3302 hardware watchpoints, because accesses to data that don't change the
3303 value of the watched expression cannot be detected without examining
3304 every instruction as it is being executed, and @value{GDBN} does not do
3305 that currently. If @value{GDBN} finds that it is unable to set a
3306 hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
3307 will print a message like this:
3308
3309 @smallexample
3310 Expression cannot be implemented with read/access watchpoint.
3311 @end smallexample
3312
3313 Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
3314 data type of the watched expression is wider than what a hardware
3315 watchpoint on the target machine can handle. For example, some systems
3316 can only watch regions that are up to 4 bytes wide; on such systems you
3317 cannot set hardware watchpoints for an expression that yields a
3318 double-precision floating-point number (which is typically 8 bytes
3319 wide). As a work-around, it might be possible to break the large region
3320 into a series of smaller ones and watch them with separate watchpoints.
3321
3322 If you set too many hardware watchpoints, @value{GDBN} might be unable
3323 to insert all of them when you resume the execution of your program.
3324 Since the precise number of active watchpoints is unknown until such
3325 time as the program is about to be resumed, @value{GDBN} might not be
3326 able to warn you about this when you set the watchpoints, and the
3327 warning will be printed only when the program is resumed:
3328
3329 @smallexample
3330 Hardware watchpoint @var{num}: Could not insert watchpoint
3331 @end smallexample
3332
3333 @noindent
3334 If this happens, delete or disable some of the watchpoints.
3335
3336 Watching complex expressions that reference many variables can also
3337 exhaust the resources available for hardware-assisted watchpoints.
3338 That's because @value{GDBN} needs to watch every variable in the
3339 expression with separately allocated resources.
3340
3341 The SPARClite DSU will generate traps when a program accesses some data
3342 or instruction address that is assigned to the debug registers. For the
3343 data addresses, DSU facilitates the @code{watch} command. However the
3344 hardware breakpoint registers can only take two data watchpoints, and
3345 both watchpoints must be the same kind. For example, you can set two
3346 watchpoints with @code{watch} commands, two with @code{rwatch} commands,
3347 @strong{or} two with @code{awatch} commands, but you cannot set one
3348 watchpoint with one command and the other with a different command.
3349 @value{GDBN} will reject the command if you try to mix watchpoints.
3350 Delete or disable unused watchpoint commands before setting new ones.
3351
3352 If you call a function interactively using @code{print} or @code{call},
3353 any watchpoints you have set will be inactive until @value{GDBN} reaches another
3354 kind of breakpoint or the call completes.
3355
3356 @value{GDBN} automatically deletes watchpoints that watch local
3357 (automatic) variables, or expressions that involve such variables, when
3358 they go out of scope, that is, when the execution leaves the block in
3359 which these variables were defined. In particular, when the program
3360 being debugged terminates, @emph{all} local variables go out of scope,
3361 and so only watchpoints that watch global variables remain set. If you
3362 rerun the program, you will need to set all such watchpoints again. One
3363 way of doing that would be to set a code breakpoint at the entry to the
3364 @code{main} function and when it breaks, set all the watchpoints.
3365
3366 @cindex watchpoints and threads
3367 @cindex threads and watchpoints
3368 In multi-threaded programs, watchpoints will detect changes to the
3369 watched expression from every thread.
3370
3371 @quotation
3372 @emph{Warning:} In multi-threaded programs, software watchpoints
3373 have only limited usefulness. If @value{GDBN} creates a software
3374 watchpoint, it can only watch the value of an expression @emph{in a
3375 single thread}. If you are confident that the expression can only
3376 change due to the current thread's activity (and if you are also
3377 confident that no other thread can become current), then you can use
3378 software watchpoints as usual. However, @value{GDBN} may not notice
3379 when a non-current thread's activity changes the expression. (Hardware
3380 watchpoints, in contrast, watch an expression in all threads.)
3381 @end quotation
3382
3383 @xref{set remote hardware-watchpoint-limit}.
3384
3385 @node Set Catchpoints
3386 @subsection Setting Catchpoints
3387 @cindex catchpoints, setting
3388 @cindex exception handlers
3389 @cindex event handling
3390
3391 You can use @dfn{catchpoints} to cause the debugger to stop for certain
3392 kinds of program events, such as C@t{++} exceptions or the loading of a
3393 shared library. Use the @code{catch} command to set a catchpoint.
3394
3395 @table @code
3396 @kindex catch
3397 @item catch @var{event}
3398 Stop when @var{event} occurs. @var{event} can be any of the following:
3399 @table @code
3400 @item throw
3401 @cindex stop on C@t{++} exceptions
3402 The throwing of a C@t{++} exception.
3403
3404 @item catch
3405 The catching of a C@t{++} exception.
3406
3407 @item exception
3408 @cindex Ada exception catching
3409 @cindex catch Ada exceptions
3410 An Ada exception being raised. If an exception name is specified
3411 at the end of the command (eg @code{catch exception Program_Error}),
3412 the debugger will stop only when this specific exception is raised.
3413 Otherwise, the debugger stops execution when any Ada exception is raised.
3414
3415 @item exception unhandled
3416 An exception that was raised but is not handled by the program.
3417
3418 @item assert
3419 A failed Ada assertion.
3420
3421 @item exec
3422 @cindex break on fork/exec
3423 A call to @code{exec}. This is currently only available for HP-UX
3424 and @sc{gnu}/Linux.
3425
3426 @item fork
3427 A call to @code{fork}. This is currently only available for HP-UX
3428 and @sc{gnu}/Linux.
3429
3430 @item vfork
3431 A call to @code{vfork}. This is currently only available for HP-UX
3432 and @sc{gnu}/Linux.
3433
3434 @item load
3435 @itemx load @var{libname}
3436 @cindex break on load/unload of shared library
3437 The dynamic loading of any shared library, or the loading of the library
3438 @var{libname}. This is currently only available for HP-UX.
3439
3440 @item unload
3441 @itemx unload @var{libname}
3442 The unloading of any dynamically loaded shared library, or the unloading
3443 of the library @var{libname}. This is currently only available for HP-UX.
3444 @end table
3445
3446 @item tcatch @var{event}
3447 Set a catchpoint that is enabled only for one stop. The catchpoint is
3448 automatically deleted after the first time the event is caught.
3449
3450 @end table
3451
3452 Use the @code{info break} command to list the current catchpoints.
3453
3454 There are currently some limitations to C@t{++} exception handling
3455 (@code{catch throw} and @code{catch catch}) in @value{GDBN}:
3456
3457 @itemize @bullet
3458 @item
3459 If you call a function interactively, @value{GDBN} normally returns
3460 control to you when the function has finished executing. If the call
3461 raises an exception, however, the call may bypass the mechanism that
3462 returns control to you and cause your program either to abort or to
3463 simply continue running until it hits a breakpoint, catches a signal
3464 that @value{GDBN} is listening for, or exits. This is the case even if
3465 you set a catchpoint for the exception; catchpoints on exceptions are
3466 disabled within interactive calls.
3467
3468 @item
3469 You cannot raise an exception interactively.
3470
3471 @item
3472 You cannot install an exception handler interactively.
3473 @end itemize
3474
3475 @cindex raise exceptions
3476 Sometimes @code{catch} is not the best way to debug exception handling:
3477 if you need to know exactly where an exception is raised, it is better to
3478 stop @emph{before} the exception handler is called, since that way you
3479 can see the stack before any unwinding takes place. If you set a
3480 breakpoint in an exception handler instead, it may not be easy to find
3481 out where the exception was raised.
3482
3483 To stop just before an exception handler is called, you need some
3484 knowledge of the implementation. In the case of @sc{gnu} C@t{++}, exceptions are
3485 raised by calling a library function named @code{__raise_exception}
3486 which has the following ANSI C interface:
3487
3488 @smallexample
3489 /* @var{addr} is where the exception identifier is stored.
3490 @var{id} is the exception identifier. */
3491 void __raise_exception (void **addr, void *id);
3492 @end smallexample
3493
3494 @noindent
3495 To make the debugger catch all exceptions before any stack
3496 unwinding takes place, set a breakpoint on @code{__raise_exception}
3497 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Exceptions}).
3498
3499 With a conditional breakpoint (@pxref{Conditions, ,Break Conditions})
3500 that depends on the value of @var{id}, you can stop your program when
3501 a specific exception is raised. You can use multiple conditional
3502 breakpoints to stop your program when any of a number of exceptions are
3503 raised.
3504
3505
3506 @node Delete Breaks
3507 @subsection Deleting Breakpoints
3508
3509 @cindex clearing breakpoints, watchpoints, catchpoints
3510 @cindex deleting breakpoints, watchpoints, catchpoints
3511 It is often necessary to eliminate a breakpoint, watchpoint, or
3512 catchpoint once it has done its job and you no longer want your program
3513 to stop there. This is called @dfn{deleting} the breakpoint. A
3514 breakpoint that has been deleted no longer exists; it is forgotten.
3515
3516 With the @code{clear} command you can delete breakpoints according to
3517 where they are in your program. With the @code{delete} command you can
3518 delete individual breakpoints, watchpoints, or catchpoints by specifying
3519 their breakpoint numbers.
3520
3521 It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
3522 automatically ignores breakpoints on the first instruction to be executed
3523 when you continue execution without changing the execution address.
3524
3525 @table @code
3526 @kindex clear
3527 @item clear
3528 Delete any breakpoints at the next instruction to be executed in the
3529 selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
3530 the innermost frame is selected, this is a good way to delete a
3531 breakpoint where your program just stopped.
3532
3533 @item clear @var{location}
3534 Delete any breakpoints set at the specified @var{location}.
3535 @xref{Specify Location}, for the various forms of @var{location}; the
3536 most useful ones are listed below:
3537
3538 @table @code
3539 @item clear @var{function}
3540 @itemx clear @var{filename}:@var{function}
3541 Delete any breakpoints set at entry to the named @var{function}.
3542
3543 @item clear @var{linenum}
3544 @itemx clear @var{filename}:@var{linenum}
3545 Delete any breakpoints set at or within the code of the specified
3546 @var{linenum} of the specified @var{filename}.
3547 @end table
3548
3549 @cindex delete breakpoints
3550 @kindex delete
3551 @kindex d @r{(@code{delete})}
3552 @item delete @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3553 Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
3554 ranges specified as arguments. If no argument is specified, delete all
3555 breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
3556 confirm off}). You can abbreviate this command as @code{d}.
3557 @end table
3558
3559 @node Disabling
3560 @subsection Disabling Breakpoints
3561
3562 @cindex enable/disable a breakpoint
3563 Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
3564 prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
3565 it had been deleted, but remembers the information on the breakpoint so
3566 that you can @dfn{enable} it again later.
3567
3568 You disable and enable breakpoints, watchpoints, and catchpoints with
3569 the @code{enable} and @code{disable} commands, optionally specifying one
3570 or more breakpoint numbers as arguments. Use @code{info break} or
3571 @code{info watch} to print a list of breakpoints, watchpoints, and
3572 catchpoints if you do not know which numbers to use.
3573
3574 Disabling and enabling a breakpoint that has multiple locations
3575 affects all of its locations.
3576
3577 A breakpoint, watchpoint, or catchpoint can have any of four different
3578 states of enablement:
3579
3580 @itemize @bullet
3581 @item
3582 Enabled. The breakpoint stops your program. A breakpoint set
3583 with the @code{break} command starts out in this state.
3584 @item
3585 Disabled. The breakpoint has no effect on your program.
3586 @item
3587 Enabled once. The breakpoint stops your program, but then becomes
3588 disabled.
3589 @item
3590 Enabled for deletion. The breakpoint stops your program, but
3591 immediately after it does so it is deleted permanently. A breakpoint
3592 set with the @code{tbreak} command starts out in this state.
3593 @end itemize
3594
3595 You can use the following commands to enable or disable breakpoints,
3596 watchpoints, and catchpoints:
3597
3598 @table @code
3599 @kindex disable
3600 @kindex dis @r{(@code{disable})}
3601 @item disable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3602 Disable the specified breakpoints---or all breakpoints, if none are
3603 listed. A disabled breakpoint has no effect but is not forgotten. All
3604 options such as ignore-counts, conditions and commands are remembered in
3605 case the breakpoint is enabled again later. You may abbreviate
3606 @code{disable} as @code{dis}.
3607
3608 @kindex enable
3609 @item enable @r{[}breakpoints@r{]} @r{[}@var{range}@dots{}@r{]}
3610 Enable the specified breakpoints (or all defined breakpoints). They
3611 become effective once again in stopping your program.
3612
3613 @item enable @r{[}breakpoints@r{]} once @var{range}@dots{}
3614 Enable the specified breakpoints temporarily. @value{GDBN} disables any
3615 of these breakpoints immediately after stopping your program.
3616
3617 @item enable @r{[}breakpoints@r{]} delete @var{range}@dots{}
3618 Enable the specified breakpoints to work once, then die. @value{GDBN}
3619 deletes any of these breakpoints as soon as your program stops there.
3620 Breakpoints set by the @code{tbreak} command start out in this state.
3621 @end table
3622
3623 @c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
3624 @c confusing: tbreak is also initially enabled.
3625 Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
3626 ,Setting Breakpoints}), breakpoints that you set are initially enabled;
3627 subsequently, they become disabled or enabled only when you use one of
3628 the commands above. (The command @code{until} can set and delete a
3629 breakpoint of its own, but it does not change the state of your other
3630 breakpoints; see @ref{Continuing and Stepping, ,Continuing and
3631 Stepping}.)
3632
3633 @node Conditions
3634 @subsection Break Conditions
3635 @cindex conditional breakpoints
3636 @cindex breakpoint conditions
3637
3638 @c FIXME what is scope of break condition expr? Context where wanted?
3639 @c in particular for a watchpoint?
3640 The simplest sort of breakpoint breaks every time your program reaches a
3641 specified place. You can also specify a @dfn{condition} for a
3642 breakpoint. A condition is just a Boolean expression in your
3643 programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
3644 a condition evaluates the expression each time your program reaches it,
3645 and your program stops only if the condition is @emph{true}.
3646
3647 This is the converse of using assertions for program validation; in that
3648 situation, you want to stop when the assertion is violated---that is,
3649 when the condition is false. In C, if you want to test an assertion expressed
3650 by the condition @var{assert}, you should set the condition
3651 @samp{! @var{assert}} on the appropriate breakpoint.
3652
3653 Conditions are also accepted for watchpoints; you may not need them,
3654 since a watchpoint is inspecting the value of an expression anyhow---but
3655 it might be simpler, say, to just set a watchpoint on a variable name,
3656 and specify a condition that tests whether the new value is an interesting
3657 one.
3658
3659 Break conditions can have side effects, and may even call functions in
3660 your program. This can be useful, for example, to activate functions
3661 that log program progress, or to use your own print functions to
3662 format special data structures. The effects are completely predictable
3663 unless there is another enabled breakpoint at the same address. (In
3664 that case, @value{GDBN} might see the other breakpoint first and stop your
3665 program without checking the condition of this one.) Note that
3666 breakpoint commands are usually more convenient and flexible than break
3667 conditions for the
3668 purpose of performing side effects when a breakpoint is reached
3669 (@pxref{Break Commands, ,Breakpoint Command Lists}).
3670
3671 Break conditions can be specified when a breakpoint is set, by using
3672 @samp{if} in the arguments to the @code{break} command. @xref{Set
3673 Breaks, ,Setting Breakpoints}. They can also be changed at any time
3674 with the @code{condition} command.
3675
3676 You can also use the @code{if} keyword with the @code{watch} command.
3677 The @code{catch} command does not recognize the @code{if} keyword;
3678 @code{condition} is the only way to impose a further condition on a
3679 catchpoint.
3680
3681 @table @code
3682 @kindex condition
3683 @item condition @var{bnum} @var{expression}
3684 Specify @var{expression} as the break condition for breakpoint,
3685 watchpoint, or catchpoint number @var{bnum}. After you set a condition,
3686 breakpoint @var{bnum} stops your program only if the value of
3687 @var{expression} is true (nonzero, in C). When you use
3688 @code{condition}, @value{GDBN} checks @var{expression} immediately for
3689 syntactic correctness, and to determine whether symbols in it have
3690 referents in the context of your breakpoint. If @var{expression} uses
3691 symbols not referenced in the context of the breakpoint, @value{GDBN}
3692 prints an error message:
3693
3694 @smallexample
3695 No symbol "foo" in current context.
3696 @end smallexample
3697
3698 @noindent
3699 @value{GDBN} does
3700 not actually evaluate @var{expression} at the time the @code{condition}
3701 command (or a command that sets a breakpoint with a condition, like
3702 @code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
3703
3704 @item condition @var{bnum}
3705 Remove the condition from breakpoint number @var{bnum}. It becomes
3706 an ordinary unconditional breakpoint.
3707 @end table
3708
3709 @cindex ignore count (of breakpoint)
3710 A special case of a breakpoint condition is to stop only when the
3711 breakpoint has been reached a certain number of times. This is so
3712 useful that there is a special way to do it, using the @dfn{ignore
3713 count} of the breakpoint. Every breakpoint has an ignore count, which
3714 is an integer. Most of the time, the ignore count is zero, and
3715 therefore has no effect. But if your program reaches a breakpoint whose
3716 ignore count is positive, then instead of stopping, it just decrements
3717 the ignore count by one and continues. As a result, if the ignore count
3718 value is @var{n}, the breakpoint does not stop the next @var{n} times
3719 your program reaches it.
3720
3721 @table @code
3722 @kindex ignore
3723 @item ignore @var{bnum} @var{count}
3724 Set the ignore count of breakpoint number @var{bnum} to @var{count}.
3725 The next @var{count} times the breakpoint is reached, your program's
3726 execution does not stop; other than to decrement the ignore count, @value{GDBN}
3727 takes no action.
3728
3729 To make the breakpoint stop the next time it is reached, specify
3730 a count of zero.
3731
3732 When you use @code{continue} to resume execution of your program from a
3733 breakpoint, you can specify an ignore count directly as an argument to
3734 @code{continue}, rather than using @code{ignore}. @xref{Continuing and
3735 Stepping,,Continuing and Stepping}.
3736
3737 If a breakpoint has a positive ignore count and a condition, the
3738 condition is not checked. Once the ignore count reaches zero,
3739 @value{GDBN} resumes checking the condition.
3740
3741 You could achieve the effect of the ignore count with a condition such
3742 as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
3743 is decremented each time. @xref{Convenience Vars, ,Convenience
3744 Variables}.
3745 @end table
3746
3747 Ignore counts apply to breakpoints, watchpoints, and catchpoints.
3748
3749
3750 @node Break Commands
3751 @subsection Breakpoint Command Lists
3752
3753 @cindex breakpoint commands
3754 You can give any breakpoint (or watchpoint or catchpoint) a series of
3755 commands to execute when your program stops due to that breakpoint. For
3756 example, you might want to print the values of certain expressions, or
3757 enable other breakpoints.
3758
3759 @table @code
3760 @kindex commands
3761 @kindex end@r{ (breakpoint commands)}
3762 @item commands @r{[}@var{bnum}@r{]}
3763 @itemx @dots{} @var{command-list} @dots{}
3764 @itemx end
3765 Specify a list of commands for breakpoint number @var{bnum}. The commands
3766 themselves appear on the following lines. Type a line containing just
3767 @code{end} to terminate the commands.
3768
3769 To remove all commands from a breakpoint, type @code{commands} and
3770 follow it immediately with @code{end}; that is, give no commands.
3771
3772 With no @var{bnum} argument, @code{commands} refers to the last
3773 breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
3774 recently encountered).
3775 @end table
3776
3777 Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
3778 disabled within a @var{command-list}.
3779
3780 You can use breakpoint commands to start your program up again. Simply
3781 use the @code{continue} command, or @code{step}, or any other command
3782 that resumes execution.
3783
3784 Any other commands in the command list, after a command that resumes
3785 execution, are ignored. This is because any time you resume execution
3786 (even with a simple @code{next} or @code{step}), you may encounter
3787 another breakpoint---which could have its own command list, leading to
3788 ambiguities about which list to execute.
3789
3790 @kindex silent
3791 If the first command you specify in a command list is @code{silent}, the
3792 usual message about stopping at a breakpoint is not printed. This may
3793 be desirable for breakpoints that are to print a specific message and
3794 then continue. If none of the remaining commands print anything, you
3795 see no sign that the breakpoint was reached. @code{silent} is
3796 meaningful only at the beginning of a breakpoint command list.
3797
3798 The commands @code{echo}, @code{output}, and @code{printf} allow you to
3799 print precisely controlled output, and are often useful in silent
3800 breakpoints. @xref{Output, ,Commands for Controlled Output}.
3801
3802 For example, here is how you could use breakpoint commands to print the
3803 value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
3804
3805 @smallexample
3806 break foo if x>0
3807 commands
3808 silent
3809 printf "x is %d\n",x
3810 cont
3811 end
3812 @end smallexample
3813
3814 One application for breakpoint commands is to compensate for one bug so
3815 you can test for another. Put a breakpoint just after the erroneous line
3816 of code, give it a condition to detect the case in which something
3817 erroneous has been done, and give it commands to assign correct values
3818 to any variables that need them. End with the @code{continue} command
3819 so that your program does not stop, and start with the @code{silent}
3820 command so that no output is produced. Here is an example:
3821
3822 @smallexample
3823 break 403
3824 commands
3825 silent
3826 set x = y + 4
3827 cont
3828 end
3829 @end smallexample
3830
3831 @node Breakpoint Menus
3832 @subsection Breakpoint Menus
3833 @cindex overloading
3834 @cindex symbol overloading
3835
3836 Some programming languages (notably C@t{++} and Objective-C) permit a
3837 single function name
3838 to be defined several times, for application in different contexts.
3839 This is called @dfn{overloading}. When a function name is overloaded,
3840 @samp{break @var{function}} is not enough to tell @value{GDBN} where you want
3841 a breakpoint. You can use explicit signature of the function, as in
3842 @samp{break @var{function}(@var{types})}, to specify which
3843 particular version of the function you want. Otherwise, @value{GDBN} offers
3844 you a menu of numbered choices for different possible breakpoints, and
3845 waits for your selection with the prompt @samp{>}. The first two
3846 options are always @samp{[0] cancel} and @samp{[1] all}. Typing @kbd{1}
3847 sets a breakpoint at each definition of @var{function}, and typing
3848 @kbd{0} aborts the @code{break} command without setting any new
3849 breakpoints.
3850
3851 For example, the following session excerpt shows an attempt to set a
3852 breakpoint at the overloaded symbol @code{String::after}.
3853 We choose three particular definitions of that function name:
3854
3855 @c FIXME! This is likely to change to show arg type lists, at least
3856 @smallexample
3857 @group
3858 (@value{GDBP}) b String::after
3859 [0] cancel
3860 [1] all
3861 [2] file:String.cc; line number:867
3862 [3] file:String.cc; line number:860
3863 [4] file:String.cc; line number:875
3864 [5] file:String.cc; line number:853
3865 [6] file:String.cc; line number:846
3866 [7] file:String.cc; line number:735
3867 > 2 4 6
3868 Breakpoint 1 at 0xb26c: file String.cc, line 867.
3869 Breakpoint 2 at 0xb344: file String.cc, line 875.
3870 Breakpoint 3 at 0xafcc: file String.cc, line 846.
3871 Multiple breakpoints were set.
3872 Use the "delete" command to delete unwanted
3873 breakpoints.
3874 (@value{GDBP})
3875 @end group
3876 @end smallexample
3877
3878 @c @ifclear BARETARGET
3879 @node Error in Breakpoints
3880 @subsection ``Cannot insert breakpoints''
3881 @c
3882 @c FIXME!! 14/6/95 Is there a real example of this? Let's use it.
3883 @c
3884 Under some operating systems, breakpoints cannot be used in a program if
3885 any other process is running that program. In this situation,
3886 attempting to run or continue a program with a breakpoint causes
3887 @value{GDBN} to print an error message:
3888
3889 @smallexample
3890 Cannot insert breakpoints.
3891 The same program may be running in another process.
3892 @end smallexample
3893
3894 When this happens, you have three ways to proceed:
3895
3896 @enumerate
3897 @item
3898 Remove or disable the breakpoints, then continue.
3899
3900 @item
3901 Suspend @value{GDBN}, and copy the file containing your program to a new
3902 name. Resume @value{GDBN} and use the @code{exec-file} command to specify
3903 that @value{GDBN} should run your program under that name.
3904 Then start your program again.
3905
3906 @item
3907 Relink your program so that the text segment is nonsharable, using the
3908 linker option @samp{-N}. The operating system limitation may not apply
3909 to nonsharable executables.
3910 @end enumerate
3911 @c @end ifclear
3912
3913 A similar message can be printed if you request too many active
3914 hardware-assisted breakpoints and watchpoints:
3915
3916 @c FIXME: the precise wording of this message may change; the relevant
3917 @c source change is not committed yet (Sep 3, 1999).
3918 @smallexample
3919 Stopped; cannot insert breakpoints.
3920 You may have requested too many hardware breakpoints and watchpoints.
3921 @end smallexample
3922
3923 @noindent
3924 This message is printed when you attempt to resume the program, since
3925 only then @value{GDBN} knows exactly how many hardware breakpoints and
3926 watchpoints it needs to insert.
3927
3928 When this message is printed, you need to disable or remove some of the
3929 hardware-assisted breakpoints and watchpoints, and then continue.
3930
3931 @node Breakpoint-related Warnings
3932 @subsection ``Breakpoint address adjusted...''
3933 @cindex breakpoint address adjusted
3934
3935 Some processor architectures place constraints on the addresses at
3936 which breakpoints may be placed. For architectures thus constrained,
3937 @value{GDBN} will attempt to adjust the breakpoint's address to comply
3938 with the constraints dictated by the architecture.
3939
3940 One example of such an architecture is the Fujitsu FR-V. The FR-V is
3941 a VLIW architecture in which a number of RISC-like instructions may be
3942 bundled together for parallel execution. The FR-V architecture
3943 constrains the location of a breakpoint instruction within such a
3944 bundle to the instruction with the lowest address. @value{GDBN}
3945 honors this constraint by adjusting a breakpoint's address to the
3946 first in the bundle.
3947
3948 It is not uncommon for optimized code to have bundles which contain
3949 instructions from different source statements, thus it may happen that
3950 a breakpoint's address will be adjusted from one source statement to
3951 another. Since this adjustment may significantly alter @value{GDBN}'s
3952 breakpoint related behavior from what the user expects, a warning is
3953 printed when the breakpoint is first set and also when the breakpoint
3954 is hit.
3955
3956 A warning like the one below is printed when setting a breakpoint
3957 that's been subject to address adjustment:
3958
3959 @smallexample
3960 warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
3961 @end smallexample
3962
3963 Such warnings are printed both for user settable and @value{GDBN}'s
3964 internal breakpoints. If you see one of these warnings, you should
3965 verify that a breakpoint set at the adjusted address will have the
3966 desired affect. If not, the breakpoint in question may be removed and
3967 other breakpoints may be set which will have the desired behavior.
3968 E.g., it may be sufficient to place the breakpoint at a later
3969 instruction. A conditional breakpoint may also be useful in some
3970 cases to prevent the breakpoint from triggering too often.
3971
3972 @value{GDBN} will also issue a warning when stopping at one of these
3973 adjusted breakpoints:
3974
3975 @smallexample
3976 warning: Breakpoint 1 address previously adjusted from 0x00010414
3977 to 0x00010410.
3978 @end smallexample
3979
3980 When this warning is encountered, it may be too late to take remedial
3981 action except in cases where the breakpoint is hit earlier or more
3982 frequently than expected.
3983
3984 @node Continuing and Stepping
3985 @section Continuing and Stepping
3986
3987 @cindex stepping
3988 @cindex continuing
3989 @cindex resuming execution
3990 @dfn{Continuing} means resuming program execution until your program
3991 completes normally. In contrast, @dfn{stepping} means executing just
3992 one more ``step'' of your program, where ``step'' may mean either one
3993 line of source code, or one machine instruction (depending on what
3994 particular command you use). Either when continuing or when stepping,
3995 your program may stop even sooner, due to a breakpoint or a signal. (If
3996 it stops due to a signal, you may want to use @code{handle}, or use
3997 @samp{signal 0} to resume execution. @xref{Signals, ,Signals}.)
3998
3999 @table @code
4000 @kindex continue
4001 @kindex c @r{(@code{continue})}
4002 @kindex fg @r{(resume foreground execution)}
4003 @item continue @r{[}@var{ignore-count}@r{]}
4004 @itemx c @r{[}@var{ignore-count}@r{]}
4005 @itemx fg @r{[}@var{ignore-count}@r{]}
4006 Resume program execution, at the address where your program last stopped;
4007 any breakpoints set at that address are bypassed. The optional argument
4008 @var{ignore-count} allows you to specify a further number of times to
4009 ignore a breakpoint at this location; its effect is like that of
4010 @code{ignore} (@pxref{Conditions, ,Break Conditions}).
4011
4012 The argument @var{ignore-count} is meaningful only when your program
4013 stopped due to a breakpoint. At other times, the argument to
4014 @code{continue} is ignored.
4015
4016 The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
4017 debugged program is deemed to be the foreground program) are provided
4018 purely for convenience, and have exactly the same behavior as
4019 @code{continue}.
4020 @end table
4021
4022 To resume execution at a different place, you can use @code{return}
4023 (@pxref{Returning, ,Returning from a Function}) to go back to the
4024 calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
4025 Different Address}) to go to an arbitrary location in your program.
4026
4027 A typical technique for using stepping is to set a breakpoint
4028 (@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
4029 beginning of the function or the section of your program where a problem
4030 is believed to lie, run your program until it stops at that breakpoint,
4031 and then step through the suspect area, examining the variables that are
4032 interesting, until you see the problem happen.
4033
4034 @table @code
4035 @kindex step
4036 @kindex s @r{(@code{step})}
4037 @item step
4038 Continue running your program until control reaches a different source
4039 line, then stop it and return control to @value{GDBN}. This command is
4040 abbreviated @code{s}.
4041
4042 @quotation
4043 @c "without debugging information" is imprecise; actually "without line
4044 @c numbers in the debugging information". (gcc -g1 has debugging info but
4045 @c not line numbers). But it seems complex to try to make that
4046 @c distinction here.
4047 @emph{Warning:} If you use the @code{step} command while control is
4048 within a function that was compiled without debugging information,
4049 execution proceeds until control reaches a function that does have
4050 debugging information. Likewise, it will not step into a function which
4051 is compiled without debugging information. To step through functions
4052 without debugging information, use the @code{stepi} command, described
4053 below.
4054 @end quotation
4055
4056 The @code{step} command only stops at the first instruction of a source
4057 line. This prevents the multiple stops that could otherwise occur in
4058 @code{switch} statements, @code{for} loops, etc. @code{step} continues
4059 to stop if a function that has debugging information is called within
4060 the line. In other words, @code{step} @emph{steps inside} any functions
4061 called within the line.
4062
4063 Also, the @code{step} command only enters a function if there is line
4064 number information for the function. Otherwise it acts like the
4065 @code{next} command. This avoids problems when using @code{cc -gl}
4066 on MIPS machines. Previously, @code{step} entered subroutines if there
4067 was any debugging information about the routine.
4068
4069 @item step @var{count}
4070 Continue running as in @code{step}, but do so @var{count} times. If a
4071 breakpoint is reached, or a signal not related to stepping occurs before
4072 @var{count} steps, stepping stops right away.
4073
4074 @kindex next
4075 @kindex n @r{(@code{next})}
4076 @item next @r{[}@var{count}@r{]}
4077 Continue to the next source line in the current (innermost) stack frame.
4078 This is similar to @code{step}, but function calls that appear within
4079 the line of code are executed without stopping. Execution stops when
4080 control reaches a different line of code at the original stack level
4081 that was executing when you gave the @code{next} command. This command
4082 is abbreviated @code{n}.
4083
4084 An argument @var{count} is a repeat count, as for @code{step}.
4085
4086
4087 @c FIX ME!! Do we delete this, or is there a way it fits in with
4088 @c the following paragraph? --- Vctoria
4089 @c
4090 @c @code{next} within a function that lacks debugging information acts like
4091 @c @code{step}, but any function calls appearing within the code of the
4092 @c function are executed without stopping.
4093
4094 The @code{next} command only stops at the first instruction of a
4095 source line. This prevents multiple stops that could otherwise occur in
4096 @code{switch} statements, @code{for} loops, etc.
4097
4098 @kindex set step-mode
4099 @item set step-mode
4100 @cindex functions without line info, and stepping
4101 @cindex stepping into functions with no line info
4102 @itemx set step-mode on
4103 The @code{set step-mode on} command causes the @code{step} command to
4104 stop at the first instruction of a function which contains no debug line
4105 information rather than stepping over it.
4106
4107 This is useful in cases where you may be interested in inspecting the
4108 machine instructions of a function which has no symbolic info and do not
4109 want @value{GDBN} to automatically skip over this function.
4110
4111 @item set step-mode off
4112 Causes the @code{step} command to step over any functions which contains no
4113 debug information. This is the default.
4114
4115 @item show step-mode
4116 Show whether @value{GDBN} will stop in or step over functions without
4117 source line debug information.
4118
4119 @kindex finish
4120 @item finish
4121 Continue running until just after function in the selected stack frame
4122 returns. Print the returned value (if any).
4123
4124 Contrast this with the @code{return} command (@pxref{Returning,
4125 ,Returning from a Function}).
4126
4127 @kindex until
4128 @kindex u @r{(@code{until})}
4129 @cindex run until specified location
4130 @item until
4131 @itemx u
4132 Continue running until a source line past the current line, in the
4133 current stack frame, is reached. This command is used to avoid single
4134 stepping through a loop more than once. It is like the @code{next}
4135 command, except that when @code{until} encounters a jump, it
4136 automatically continues execution until the program counter is greater
4137 than the address of the jump.
4138
4139 This means that when you reach the end of a loop after single stepping
4140 though it, @code{until} makes your program continue execution until it
4141 exits the loop. In contrast, a @code{next} command at the end of a loop
4142 simply steps back to the beginning of the loop, which forces you to step
4143 through the next iteration.
4144
4145 @code{until} always stops your program if it attempts to exit the current
4146 stack frame.
4147
4148 @code{until} may produce somewhat counterintuitive results if the order
4149 of machine code does not match the order of the source lines. For
4150 example, in the following excerpt from a debugging session, the @code{f}
4151 (@code{frame}) command shows that execution is stopped at line
4152 @code{206}; yet when we use @code{until}, we get to line @code{195}:
4153
4154 @smallexample
4155 (@value{GDBP}) f
4156 #0 main (argc=4, argv=0xf7fffae8) at m4.c:206
4157 206 expand_input();
4158 (@value{GDBP}) until
4159 195 for ( ; argc > 0; NEXTARG) @{
4160 @end smallexample
4161
4162 This happened because, for execution efficiency, the compiler had
4163 generated code for the loop closure test at the end, rather than the
4164 start, of the loop---even though the test in a C @code{for}-loop is
4165 written before the body of the loop. The @code{until} command appeared
4166 to step back to the beginning of the loop when it advanced to this
4167 expression; however, it has not really gone to an earlier
4168 statement---not in terms of the actual machine code.
4169
4170 @code{until} with no argument works by means of single
4171 instruction stepping, and hence is slower than @code{until} with an
4172 argument.
4173
4174 @item until @var{location}
4175 @itemx u @var{location}
4176 Continue running your program until either the specified location is
4177 reached, or the current stack frame returns. @var{location} is any of
4178 the forms described in @ref{Specify Location}.
4179 This form of the command uses temporary breakpoints, and
4180 hence is quicker than @code{until} without an argument. The specified
4181 location is actually reached only if it is in the current frame. This
4182 implies that @code{until} can be used to skip over recursive function
4183 invocations. For instance in the code below, if the current location is
4184 line @code{96}, issuing @code{until 99} will execute the program up to
4185 line @code{99} in the same invocation of factorial, i.e., after the inner
4186 invocations have returned.
4187
4188 @smallexample
4189 94 int factorial (int value)
4190 95 @{
4191 96 if (value > 1) @{
4192 97 value *= factorial (value - 1);
4193 98 @}
4194 99 return (value);
4195 100 @}
4196 @end smallexample
4197
4198
4199 @kindex advance @var{location}
4200 @itemx advance @var{location}
4201 Continue running the program up to the given @var{location}. An argument is
4202 required, which should be of one of the forms described in
4203 @ref{Specify Location}.
4204 Execution will also stop upon exit from the current stack
4205 frame. This command is similar to @code{until}, but @code{advance} will
4206 not skip over recursive function calls, and the target location doesn't
4207 have to be in the same frame as the current one.
4208
4209
4210 @kindex stepi
4211 @kindex si @r{(@code{stepi})}
4212 @item stepi
4213 @itemx stepi @var{arg}
4214 @itemx si
4215 Execute one machine instruction, then stop and return to the debugger.
4216
4217 It is often useful to do @samp{display/i $pc} when stepping by machine
4218 instructions. This makes @value{GDBN} automatically display the next
4219 instruction to be executed, each time your program stops. @xref{Auto
4220 Display,, Automatic Display}.
4221
4222 An argument is a repeat count, as in @code{step}.
4223
4224 @need 750
4225 @kindex nexti
4226 @kindex ni @r{(@code{nexti})}
4227 @item nexti
4228 @itemx nexti @var{arg}
4229 @itemx ni
4230 Execute one machine instruction, but if it is a function call,
4231 proceed until the function returns.
4232
4233 An argument is a repeat count, as in @code{next}.
4234 @end table
4235
4236 @node Signals
4237 @section Signals
4238 @cindex signals
4239
4240 A signal is an asynchronous event that can happen in a program. The
4241 operating system defines the possible kinds of signals, and gives each
4242 kind a name and a number. For example, in Unix @code{SIGINT} is the
4243 signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
4244 @code{SIGSEGV} is the signal a program gets from referencing a place in
4245 memory far away from all the areas in use; @code{SIGALRM} occurs when
4246 the alarm clock timer goes off (which happens only if your program has
4247 requested an alarm).
4248
4249 @cindex fatal signals
4250 Some signals, including @code{SIGALRM}, are a normal part of the
4251 functioning of your program. Others, such as @code{SIGSEGV}, indicate
4252 errors; these signals are @dfn{fatal} (they kill your program immediately) if the
4253 program has not specified in advance some other way to handle the signal.
4254 @code{SIGINT} does not indicate an error in your program, but it is normally
4255 fatal so it can carry out the purpose of the interrupt: to kill the program.
4256
4257 @value{GDBN} has the ability to detect any occurrence of a signal in your
4258 program. You can tell @value{GDBN} in advance what to do for each kind of
4259 signal.
4260
4261 @cindex handling signals
4262 Normally, @value{GDBN} is set up to let the non-erroneous signals like
4263 @code{SIGALRM} be silently passed to your program
4264 (so as not to interfere with their role in the program's functioning)
4265 but to stop your program immediately whenever an error signal happens.
4266 You can change these settings with the @code{handle} command.
4267
4268 @table @code
4269 @kindex info signals
4270 @kindex info handle
4271 @item info signals
4272 @itemx info handle
4273 Print a table of all the kinds of signals and how @value{GDBN} has been told to
4274 handle each one. You can use this to see the signal numbers of all
4275 the defined types of signals.
4276
4277 @item info signals @var{sig}
4278 Similar, but print information only about the specified signal number.
4279
4280 @code{info handle} is an alias for @code{info signals}.
4281
4282 @kindex handle
4283 @item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
4284 Change the way @value{GDBN} handles signal @var{signal}. @var{signal}
4285 can be the number of a signal or its name (with or without the
4286 @samp{SIG} at the beginning); a list of signal numbers of the form
4287 @samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
4288 known signals. Optional arguments @var{keywords}, described below,
4289 say what change to make.
4290 @end table
4291
4292 @c @group
4293 The keywords allowed by the @code{handle} command can be abbreviated.
4294 Their full names are:
4295
4296 @table @code
4297 @item nostop
4298 @value{GDBN} should not stop your program when this signal happens. It may
4299 still print a message telling you that the signal has come in.
4300
4301 @item stop
4302 @value{GDBN} should stop your program when this signal happens. This implies
4303 the @code{print} keyword as well.
4304
4305 @item print
4306 @value{GDBN} should print a message when this signal happens.
4307
4308 @item noprint
4309 @value{GDBN} should not mention the occurrence of the signal at all. This
4310 implies the @code{nostop} keyword as well.
4311
4312 @item pass
4313 @itemx noignore
4314 @value{GDBN} should allow your program to see this signal; your program
4315 can handle the signal, or else it may terminate if the signal is fatal
4316 and not handled. @code{pass} and @code{noignore} are synonyms.
4317
4318 @item nopass
4319 @itemx ignore
4320 @value{GDBN} should not allow your program to see this signal.
4321 @code{nopass} and @code{ignore} are synonyms.
4322 @end table
4323 @c @end group
4324
4325 When a signal stops your program, the signal is not visible to the
4326 program until you
4327 continue. Your program sees the signal then, if @code{pass} is in
4328 effect for the signal in question @emph{at that time}. In other words,
4329 after @value{GDBN} reports a signal, you can use the @code{handle}
4330 command with @code{pass} or @code{nopass} to control whether your
4331 program sees that signal when you continue.
4332
4333 The default is set to @code{nostop}, @code{noprint}, @code{pass} for
4334 non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
4335 @code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
4336 erroneous signals.
4337
4338 You can also use the @code{signal} command to prevent your program from
4339 seeing a signal, or cause it to see a signal it normally would not see,
4340 or to give it any signal at any time. For example, if your program stopped
4341 due to some sort of memory reference error, you might store correct
4342 values into the erroneous variables and continue, hoping to see more
4343 execution; but your program would probably terminate immediately as
4344 a result of the fatal signal once it saw the signal. To prevent this,
4345 you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
4346 Program a Signal}.
4347
4348 @node Thread Stops
4349 @section Stopping and Starting Multi-thread Programs
4350
4351 When your program has multiple threads (@pxref{Threads,, Debugging
4352 Programs with Multiple Threads}), you can choose whether to set
4353 breakpoints on all threads, or on a particular thread.
4354
4355 @table @code
4356 @cindex breakpoints and threads
4357 @cindex thread breakpoints
4358 @kindex break @dots{} thread @var{threadno}
4359 @item break @var{linespec} thread @var{threadno}
4360 @itemx break @var{linespec} thread @var{threadno} if @dots{}
4361 @var{linespec} specifies source lines; there are several ways of
4362 writing them (@pxref{Specify Location}), but the effect is always to
4363 specify some source line.
4364
4365 Use the qualifier @samp{thread @var{threadno}} with a breakpoint command
4366 to specify that you only want @value{GDBN} to stop the program when a
4367 particular thread reaches this breakpoint. @var{threadno} is one of the
4368 numeric thread identifiers assigned by @value{GDBN}, shown in the first
4369 column of the @samp{info threads} display.
4370
4371 If you do not specify @samp{thread @var{threadno}} when you set a
4372 breakpoint, the breakpoint applies to @emph{all} threads of your
4373 program.
4374
4375 You can use the @code{thread} qualifier on conditional breakpoints as
4376 well; in this case, place @samp{thread @var{threadno}} before the
4377 breakpoint condition, like this:
4378
4379 @smallexample
4380 (@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
4381 @end smallexample
4382
4383 @end table
4384
4385 @cindex stopped threads
4386 @cindex threads, stopped
4387 Whenever your program stops under @value{GDBN} for any reason,
4388 @emph{all} threads of execution stop, not just the current thread. This
4389 allows you to examine the overall state of the program, including
4390 switching between threads, without worrying that things may change
4391 underfoot.
4392
4393 @cindex thread breakpoints and system calls
4394 @cindex system calls and thread breakpoints
4395 @cindex premature return from system calls
4396 There is an unfortunate side effect. If one thread stops for a
4397 breakpoint, or for some other reason, and another thread is blocked in a
4398 system call, then the system call may return prematurely. This is a
4399 consequence of the interaction between multiple threads and the signals
4400 that @value{GDBN} uses to implement breakpoints and other events that
4401 stop execution.
4402
4403 To handle this problem, your program should check the return value of
4404 each system call and react appropriately. This is good programming
4405 style anyways.
4406
4407 For example, do not write code like this:
4408
4409 @smallexample
4410 sleep (10);
4411 @end smallexample
4412
4413 The call to @code{sleep} will return early if a different thread stops
4414 at a breakpoint or for some other reason.
4415
4416 Instead, write this:
4417
4418 @smallexample
4419 int unslept = 10;
4420 while (unslept > 0)
4421 unslept = sleep (unslept);
4422 @end smallexample
4423
4424 A system call is allowed to return early, so the system is still
4425 conforming to its specification. But @value{GDBN} does cause your
4426 multi-threaded program to behave differently than it would without
4427 @value{GDBN}.
4428
4429 Also, @value{GDBN} uses internal breakpoints in the thread library to
4430 monitor certain events such as thread creation and thread destruction.
4431 When such an event happens, a system call in another thread may return
4432 prematurely, even though your program does not appear to stop.
4433
4434 @cindex continuing threads
4435 @cindex threads, continuing
4436 Conversely, whenever you restart the program, @emph{all} threads start
4437 executing. @emph{This is true even when single-stepping} with commands
4438 like @code{step} or @code{next}.
4439
4440 In particular, @value{GDBN} cannot single-step all threads in lockstep.
4441 Since thread scheduling is up to your debugging target's operating
4442 system (not controlled by @value{GDBN}), other threads may
4443 execute more than one statement while the current thread completes a
4444 single step. Moreover, in general other threads stop in the middle of a
4445 statement, rather than at a clean statement boundary, when the program
4446 stops.
4447
4448 You might even find your program stopped in another thread after
4449 continuing or even single-stepping. This happens whenever some other
4450 thread runs into a breakpoint, a signal, or an exception before the
4451 first thread completes whatever you requested.
4452
4453 On some OSes, you can lock the OS scheduler and thus allow only a single
4454 thread to run.
4455
4456 @table @code
4457 @item set scheduler-locking @var{mode}
4458 @cindex scheduler locking mode
4459 @cindex lock scheduler
4460 Set the scheduler locking mode. If it is @code{off}, then there is no
4461 locking and any thread may run at any time. If @code{on}, then only the
4462 current thread may run when the inferior is resumed. The @code{step}
4463 mode optimizes for single-stepping. It stops other threads from
4464 ``seizing the prompt'' by preempting the current thread while you are
4465 stepping. Other threads will only rarely (or never) get a chance to run
4466 when you step. They are more likely to run when you @samp{next} over a
4467 function call, and they are completely free to run when you use commands
4468 like @samp{continue}, @samp{until}, or @samp{finish}. However, unless another
4469 thread hits a breakpoint during its timeslice, they will never steal the
4470 @value{GDBN} prompt away from the thread that you are debugging.
4471
4472 @item show scheduler-locking
4473 Display the current scheduler locking mode.
4474 @end table
4475
4476
4477 @node Stack
4478 @chapter Examining the Stack
4479
4480 When your program has stopped, the first thing you need to know is where it
4481 stopped and how it got there.
4482
4483 @cindex call stack
4484 Each time your program performs a function call, information about the call
4485 is generated.
4486 That information includes the location of the call in your program,
4487 the arguments of the call,
4488 and the local variables of the function being called.
4489 The information is saved in a block of data called a @dfn{stack frame}.
4490 The stack frames are allocated in a region of memory called the @dfn{call
4491 stack}.
4492
4493 When your program stops, the @value{GDBN} commands for examining the
4494 stack allow you to see all of this information.
4495
4496 @cindex selected frame
4497 One of the stack frames is @dfn{selected} by @value{GDBN} and many
4498 @value{GDBN} commands refer implicitly to the selected frame. In
4499 particular, whenever you ask @value{GDBN} for the value of a variable in
4500 your program, the value is found in the selected frame. There are
4501 special @value{GDBN} commands to select whichever frame you are
4502 interested in. @xref{Selection, ,Selecting a Frame}.
4503
4504 When your program stops, @value{GDBN} automatically selects the
4505 currently executing frame and describes it briefly, similar to the
4506 @code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
4507
4508 @menu
4509 * Frames:: Stack frames
4510 * Backtrace:: Backtraces
4511 * Selection:: Selecting a frame
4512 * Frame Info:: Information on a frame
4513
4514 @end menu
4515
4516 @node Frames
4517 @section Stack Frames
4518
4519 @cindex frame, definition
4520 @cindex stack frame
4521 The call stack is divided up into contiguous pieces called @dfn{stack
4522 frames}, or @dfn{frames} for short; each frame is the data associated
4523 with one call to one function. The frame contains the arguments given
4524 to the function, the function's local variables, and the address at
4525 which the function is executing.
4526
4527 @cindex initial frame
4528 @cindex outermost frame
4529 @cindex innermost frame
4530 When your program is started, the stack has only one frame, that of the
4531 function @code{main}. This is called the @dfn{initial} frame or the
4532 @dfn{outermost} frame. Each time a function is called, a new frame is
4533 made. Each time a function returns, the frame for that function invocation
4534 is eliminated. If a function is recursive, there can be many frames for
4535 the same function. The frame for the function in which execution is
4536 actually occurring is called the @dfn{innermost} frame. This is the most
4537 recently created of all the stack frames that still exist.
4538
4539 @cindex frame pointer
4540 Inside your program, stack frames are identified by their addresses. A
4541 stack frame consists of many bytes, each of which has its own address; each
4542 kind of computer has a convention for choosing one byte whose
4543 address serves as the address of the frame. Usually this address is kept
4544 in a register called the @dfn{frame pointer register}
4545 (@pxref{Registers, $fp}) while execution is going on in that frame.
4546
4547 @cindex frame number
4548 @value{GDBN} assigns numbers to all existing stack frames, starting with
4549 zero for the innermost frame, one for the frame that called it,
4550 and so on upward. These numbers do not really exist in your program;
4551 they are assigned by @value{GDBN} to give you a way of designating stack
4552 frames in @value{GDBN} commands.
4553
4554 @c The -fomit-frame-pointer below perennially causes hbox overflow
4555 @c underflow problems.
4556 @cindex frameless execution
4557 Some compilers provide a way to compile functions so that they operate
4558 without stack frames. (For example, the @value{NGCC} option
4559 @smallexample
4560 @samp{-fomit-frame-pointer}
4561 @end smallexample
4562 generates functions without a frame.)
4563 This is occasionally done with heavily used library functions to save
4564 the frame setup time. @value{GDBN} has limited facilities for dealing
4565 with these function invocations. If the innermost function invocation
4566 has no stack frame, @value{GDBN} nevertheless regards it as though
4567 it had a separate frame, which is numbered zero as usual, allowing
4568 correct tracing of the function call chain. However, @value{GDBN} has
4569 no provision for frameless functions elsewhere in the stack.
4570
4571 @table @code
4572 @kindex frame@r{, command}
4573 @cindex current stack frame
4574 @item frame @var{args}
4575 The @code{frame} command allows you to move from one stack frame to another,
4576 and to print the stack frame you select. @var{args} may be either the
4577 address of the frame or the stack frame number. Without an argument,
4578 @code{frame} prints the current stack frame.
4579
4580 @kindex select-frame
4581 @cindex selecting frame silently
4582 @item select-frame
4583 The @code{select-frame} command allows you to move from one stack frame
4584 to another without printing the frame. This is the silent version of
4585 @code{frame}.
4586 @end table
4587
4588 @node Backtrace
4589 @section Backtraces
4590
4591 @cindex traceback
4592 @cindex call stack traces
4593 A backtrace is a summary of how your program got where it is. It shows one
4594 line per frame, for many frames, starting with the currently executing
4595 frame (frame zero), followed by its caller (frame one), and on up the
4596 stack.
4597
4598 @table @code
4599 @kindex backtrace
4600 @kindex bt @r{(@code{backtrace})}
4601 @item backtrace
4602 @itemx bt
4603 Print a backtrace of the entire stack: one line per frame for all
4604 frames in the stack.
4605
4606 You can stop the backtrace at any time by typing the system interrupt
4607 character, normally @kbd{Ctrl-c}.
4608
4609 @item backtrace @var{n}
4610 @itemx bt @var{n}
4611 Similar, but print only the innermost @var{n} frames.
4612
4613 @item backtrace -@var{n}
4614 @itemx bt -@var{n}
4615 Similar, but print only the outermost @var{n} frames.
4616
4617 @item backtrace full
4618 @itemx bt full
4619 @itemx bt full @var{n}
4620 @itemx bt full -@var{n}
4621 Print the values of the local variables also. @var{n} specifies the
4622 number of frames to print, as described above.
4623 @end table
4624
4625 @kindex where
4626 @kindex info stack
4627 The names @code{where} and @code{info stack} (abbreviated @code{info s})
4628 are additional aliases for @code{backtrace}.
4629
4630 @cindex multiple threads, backtrace
4631 In a multi-threaded program, @value{GDBN} by default shows the
4632 backtrace only for the current thread. To display the backtrace for
4633 several or all of the threads, use the command @code{thread apply}
4634 (@pxref{Threads, thread apply}). For example, if you type @kbd{thread
4635 apply all backtrace}, @value{GDBN} will display the backtrace for all
4636 the threads; this is handy when you debug a core dump of a
4637 multi-threaded program.
4638
4639 Each line in the backtrace shows the frame number and the function name.
4640 The program counter value is also shown---unless you use @code{set
4641 print address off}. The backtrace also shows the source file name and
4642 line number, as well as the arguments to the function. The program
4643 counter value is omitted if it is at the beginning of the code for that
4644 line number.
4645
4646 Here is an example of a backtrace. It was made with the command
4647 @samp{bt 3}, so it shows the innermost three frames.
4648
4649 @smallexample
4650 @group
4651 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4652 at builtin.c:993
4653 #1 0x6e38 in expand_macro (sym=0x2b600) at macro.c:242
4654 #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
4655 at macro.c:71
4656 (More stack frames follow...)
4657 @end group
4658 @end smallexample
4659
4660 @noindent
4661 The display for frame zero does not begin with a program counter
4662 value, indicating that your program has stopped at the beginning of the
4663 code for line @code{993} of @code{builtin.c}.
4664
4665 @cindex value optimized out, in backtrace
4666 @cindex function call arguments, optimized out
4667 If your program was compiled with optimizations, some compilers will
4668 optimize away arguments passed to functions if those arguments are
4669 never used after the call. Such optimizations generate code that
4670 passes arguments through registers, but doesn't store those arguments
4671 in the stack frame. @value{GDBN} has no way of displaying such
4672 arguments in stack frames other than the innermost one. Here's what
4673 such a backtrace might look like:
4674
4675 @smallexample
4676 @group
4677 #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
4678 at builtin.c:993
4679 #1 0x6e38 in expand_macro (sym=<value optimized out>) at macro.c:242
4680 #2 0x6840 in expand_token (obs=0x0, t=<value optimized out>, td=0xf7fffb08)
4681 at macro.c:71
4682 (More stack frames follow...)
4683 @end group
4684 @end smallexample
4685
4686 @noindent
4687 The values of arguments that were not saved in their stack frames are
4688 shown as @samp{<value optimized out>}.
4689
4690 If you need to display the values of such optimized-out arguments,
4691 either deduce that from other variables whose values depend on the one
4692 you are interested in, or recompile without optimizations.
4693
4694 @cindex backtrace beyond @code{main} function
4695 @cindex program entry point
4696 @cindex startup code, and backtrace
4697 Most programs have a standard user entry point---a place where system
4698 libraries and startup code transition into user code. For C this is
4699 @code{main}@footnote{
4700 Note that embedded programs (the so-called ``free-standing''
4701 environment) are not required to have a @code{main} function as the
4702 entry point. They could even have multiple entry points.}.
4703 When @value{GDBN} finds the entry function in a backtrace
4704 it will terminate the backtrace, to avoid tracing into highly
4705 system-specific (and generally uninteresting) code.
4706
4707 If you need to examine the startup code, or limit the number of levels
4708 in a backtrace, you can change this behavior:
4709
4710 @table @code
4711 @item set backtrace past-main
4712 @itemx set backtrace past-main on
4713 @kindex set backtrace
4714 Backtraces will continue past the user entry point.
4715
4716 @item set backtrace past-main off
4717 Backtraces will stop when they encounter the user entry point. This is the
4718 default.
4719
4720 @item show backtrace past-main
4721 @kindex show backtrace
4722 Display the current user entry point backtrace policy.
4723
4724 @item set backtrace past-entry
4725 @itemx set backtrace past-entry on
4726 Backtraces will continue past the internal entry point of an application.
4727 This entry point is encoded by the linker when the application is built,
4728 and is likely before the user entry point @code{main} (or equivalent) is called.
4729
4730 @item set backtrace past-entry off
4731 Backtraces will stop when they encounter the internal entry point of an
4732 application. This is the default.
4733
4734 @item show backtrace past-entry
4735 Display the current internal entry point backtrace policy.
4736
4737 @item set backtrace limit @var{n}
4738 @itemx set backtrace limit 0
4739 @cindex backtrace limit
4740 Limit the backtrace to @var{n} levels. A value of zero means
4741 unlimited.
4742
4743 @item show backtrace limit
4744 Display the current limit on backtrace levels.
4745 @end table
4746
4747 @node Selection
4748 @section Selecting a Frame
4749
4750 Most commands for examining the stack and other data in your program work on
4751 whichever stack frame is selected at the moment. Here are the commands for
4752 selecting a stack frame; all of them finish by printing a brief description
4753 of the stack frame just selected.
4754
4755 @table @code
4756 @kindex frame@r{, selecting}
4757 @kindex f @r{(@code{frame})}
4758 @item frame @var{n}
4759 @itemx f @var{n}
4760 Select frame number @var{n}. Recall that frame zero is the innermost
4761 (currently executing) frame, frame one is the frame that called the
4762 innermost one, and so on. The highest-numbered frame is the one for
4763 @code{main}.
4764
4765 @item frame @var{addr}
4766 @itemx f @var{addr}
4767 Select the frame at address @var{addr}. This is useful mainly if the
4768 chaining of stack frames has been damaged by a bug, making it
4769 impossible for @value{GDBN} to assign numbers properly to all frames. In
4770 addition, this can be useful when your program has multiple stacks and
4771 switches between them.
4772
4773 On the SPARC architecture, @code{frame} needs two addresses to
4774 select an arbitrary frame: a frame pointer and a stack pointer.
4775
4776 On the MIPS and Alpha architecture, it needs two addresses: a stack
4777 pointer and a program counter.
4778
4779 On the 29k architecture, it needs three addresses: a register stack
4780 pointer, a program counter, and a memory stack pointer.
4781
4782 @kindex up
4783 @item up @var{n}
4784 Move @var{n} frames up the stack. For positive numbers @var{n}, this
4785 advances toward the outermost frame, to higher frame numbers, to frames
4786 that have existed longer. @var{n} defaults to one.
4787
4788 @kindex down
4789 @kindex do @r{(@code{down})}
4790 @item down @var{n}
4791 Move @var{n} frames down the stack. For positive numbers @var{n}, this
4792 advances toward the innermost frame, to lower frame numbers, to frames
4793 that were created more recently. @var{n} defaults to one. You may
4794 abbreviate @code{down} as @code{do}.
4795 @end table
4796
4797 All of these commands end by printing two lines of output describing the
4798 frame. The first line shows the frame number, the function name, the
4799 arguments, and the source file and line number of execution in that
4800 frame. The second line shows the text of that source line.
4801
4802 @need 1000
4803 For example:
4804
4805 @smallexample
4806 @group
4807 (@value{GDBP}) up
4808 #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
4809 at env.c:10
4810 10 read_input_file (argv[i]);
4811 @end group
4812 @end smallexample
4813
4814 After such a printout, the @code{list} command with no arguments
4815 prints ten lines centered on the point of execution in the frame.
4816 You can also edit the program at the point of execution with your favorite
4817 editing program by typing @code{edit}.
4818 @xref{List, ,Printing Source Lines},
4819 for details.
4820
4821 @table @code
4822 @kindex down-silently
4823 @kindex up-silently
4824 @item up-silently @var{n}
4825 @itemx down-silently @var{n}
4826 These two commands are variants of @code{up} and @code{down},
4827 respectively; they differ in that they do their work silently, without
4828 causing display of the new frame. They are intended primarily for use
4829 in @value{GDBN} command scripts, where the output might be unnecessary and
4830 distracting.
4831 @end table
4832
4833 @node Frame Info
4834 @section Information About a Frame
4835
4836 There are several other commands to print information about the selected
4837 stack frame.
4838
4839 @table @code
4840 @item frame
4841 @itemx f
4842 When used without any argument, this command does not change which
4843 frame is selected, but prints a brief description of the currently
4844 selected stack frame. It can be abbreviated @code{f}. With an
4845 argument, this command is used to select a stack frame.
4846 @xref{Selection, ,Selecting a Frame}.
4847
4848 @kindex info frame
4849 @kindex info f @r{(@code{info frame})}
4850 @item info frame
4851 @itemx info f
4852 This command prints a verbose description of the selected stack frame,
4853 including:
4854
4855 @itemize @bullet
4856 @item
4857 the address of the frame
4858 @item
4859 the address of the next frame down (called by this frame)
4860 @item
4861 the address of the next frame up (caller of this frame)
4862 @item
4863 the language in which the source code corresponding to this frame is written
4864 @item
4865 the address of the frame's arguments
4866 @item
4867 the address of the frame's local variables
4868 @item
4869 the program counter saved in it (the address of execution in the caller frame)
4870 @item
4871 which registers were saved in the frame
4872 @end itemize
4873
4874 @noindent The verbose description is useful when
4875 something has gone wrong that has made the stack format fail to fit
4876 the usual conventions.
4877
4878 @item info frame @var{addr}
4879 @itemx info f @var{addr}
4880 Print a verbose description of the frame at address @var{addr}, without
4881 selecting that frame. The selected frame remains unchanged by this
4882 command. This requires the same kind of address (more than one for some
4883 architectures) that you specify in the @code{frame} command.
4884 @xref{Selection, ,Selecting a Frame}.
4885
4886 @kindex info args
4887 @item info args
4888 Print the arguments of the selected frame, each on a separate line.
4889
4890 @item info locals
4891 @kindex info locals
4892 Print the local variables of the selected frame, each on a separate
4893 line. These are all variables (declared either static or automatic)
4894 accessible at the point of execution of the selected frame.
4895
4896 @kindex info catch
4897 @cindex catch exceptions, list active handlers
4898 @cindex exception handlers, how to list
4899 @item info catch
4900 Print a list of all the exception handlers that are active in the
4901 current stack frame at the current point of execution. To see other
4902 exception handlers, visit the associated frame (using the @code{up},
4903 @code{down}, or @code{frame} commands); then type @code{info catch}.
4904 @xref{Set Catchpoints, , Setting Catchpoints}.
4905
4906 @end table
4907
4908
4909 @node Source
4910 @chapter Examining Source Files
4911
4912 @value{GDBN} can print parts of your program's source, since the debugging
4913 information recorded in the program tells @value{GDBN} what source files were
4914 used to build it. When your program stops, @value{GDBN} spontaneously prints
4915 the line where it stopped. Likewise, when you select a stack frame
4916 (@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
4917 execution in that frame has stopped. You can print other portions of
4918 source files by explicit command.
4919
4920 If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
4921 prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
4922 @value{GDBN} under @sc{gnu} Emacs}.
4923
4924 @menu
4925 * List:: Printing source lines
4926 * Specify Location:: How to specify code locations
4927 * Edit:: Editing source files
4928 * Search:: Searching source files
4929 * Source Path:: Specifying source directories
4930 * Machine Code:: Source and machine code
4931 @end menu
4932
4933 @node List
4934 @section Printing Source Lines
4935
4936 @kindex list
4937 @kindex l @r{(@code{list})}
4938 To print lines from a source file, use the @code{list} command
4939 (abbreviated @code{l}). By default, ten lines are printed.
4940 There are several ways to specify what part of the file you want to
4941 print; see @ref{Specify Location}, for the full list.
4942
4943 Here are the forms of the @code{list} command most commonly used:
4944
4945 @table @code
4946 @item list @var{linenum}
4947 Print lines centered around line number @var{linenum} in the
4948 current source file.
4949
4950 @item list @var{function}
4951 Print lines centered around the beginning of function
4952 @var{function}.
4953
4954 @item list
4955 Print more lines. If the last lines printed were printed with a
4956 @code{list} command, this prints lines following the last lines
4957 printed; however, if the last line printed was a solitary line printed
4958 as part of displaying a stack frame (@pxref{Stack, ,Examining the
4959 Stack}), this prints lines centered around that line.
4960
4961 @item list -
4962 Print lines just before the lines last printed.
4963 @end table
4964
4965 @cindex @code{list}, how many lines to display
4966 By default, @value{GDBN} prints ten source lines with any of these forms of
4967 the @code{list} command. You can change this using @code{set listsize}:
4968
4969 @table @code
4970 @kindex set listsize
4971 @item set listsize @var{count}
4972 Make the @code{list} command display @var{count} source lines (unless
4973 the @code{list} argument explicitly specifies some other number).
4974
4975 @kindex show listsize
4976 @item show listsize
4977 Display the number of lines that @code{list} prints.
4978 @end table
4979
4980 Repeating a @code{list} command with @key{RET} discards the argument,
4981 so it is equivalent to typing just @code{list}. This is more useful
4982 than listing the same lines again. An exception is made for an
4983 argument of @samp{-}; that argument is preserved in repetition so that
4984 each repetition moves up in the source file.
4985
4986 In general, the @code{list} command expects you to supply zero, one or two
4987 @dfn{linespecs}. Linespecs specify source lines; there are several ways
4988 of writing them (@pxref{Specify Location}), but the effect is always
4989 to specify some source line.
4990
4991 Here is a complete description of the possible arguments for @code{list}:
4992
4993 @table @code
4994 @item list @var{linespec}
4995 Print lines centered around the line specified by @var{linespec}.
4996
4997 @item list @var{first},@var{last}
4998 Print lines from @var{first} to @var{last}. Both arguments are
4999 linespecs. When a @code{list} command has two linespecs, and the
5000 source file of the second linespec is omitted, this refers to
5001 the same source file as the first linespec.
5002
5003 @item list ,@var{last}
5004 Print lines ending with @var{last}.
5005
5006 @item list @var{first},
5007 Print lines starting with @var{first}.
5008
5009 @item list +
5010 Print lines just after the lines last printed.
5011
5012 @item list -
5013 Print lines just before the lines last printed.
5014
5015 @item list
5016 As described in the preceding table.
5017 @end table
5018
5019 @node Specify Location
5020 @section Specifying a Location
5021 @cindex specifying location
5022 @cindex linespec
5023
5024 Several @value{GDBN} commands accept arguments that specify a location
5025 of your program's code. Since @value{GDBN} is a source-level
5026 debugger, a location usually specifies some line in the source code;
5027 for that reason, locations are also known as @dfn{linespecs}.
5028
5029 Here are all the different ways of specifying a code location that
5030 @value{GDBN} understands:
5031
5032 @table @code
5033 @item @var{linenum}
5034 Specifies the line number @var{linenum} of the current source file.
5035
5036 @item -@var{offset}
5037 @itemx +@var{offset}
5038 Specifies the line @var{offset} lines before or after the @dfn{current
5039 line}. For the @code{list} command, the current line is the last one
5040 printed; for the breakpoint commands, this is the line at which
5041 execution stopped in the currently selected @dfn{stack frame}
5042 (@pxref{Frames, ,Frames}, for a description of stack frames.) When
5043 used as the second of the two linespecs in a @code{list} command,
5044 this specifies the line @var{offset} lines up or down from the first
5045 linespec.
5046
5047 @item @var{filename}:@var{linenum}
5048 Specifies the line @var{linenum} in the source file @var{filename}.
5049
5050 @item @var{function}
5051 Specifies the line that begins the body of the function @var{function}.
5052 For example, in C, this is the line with the open brace.
5053
5054 @item @var{filename}:@var{function}
5055 Specifies the line that begins the body of the function @var{function}
5056 in the file @var{filename}. You only need the file name with a
5057 function name to avoid ambiguity when there are identically named
5058 functions in different source files.
5059
5060 @item *@var{address}
5061 Specifies the program address @var{address}. For line-oriented
5062 commands, such as @code{list} and @code{edit}, this specifies a source
5063 line that contains @var{address}. For @code{break} and other
5064 breakpoint oriented commands, this can be used to set breakpoints in
5065 parts of your program which do not have debugging information or
5066 source files.
5067
5068 Here @var{address} may be any expression valid in the current working
5069 language (@pxref{Languages, working language}) that specifies a code
5070 address. In addition, as a convenience, @value{GDBN} extends the
5071 semantics of expressions used in locations to cover the situations
5072 that frequently happen during debugging. Here are the various forms
5073 of @var{address}:
5074
5075 @table @code
5076 @item @var{expression}
5077 Any expression valid in the current working language.
5078
5079 @item @var{funcaddr}
5080 An address of a function or procedure derived from its name. In C,
5081 C@t{++}, Java, Objective-C, Fortran, minimal, and assembly, this is
5082 simply the function's name @var{function} (and actually a special case
5083 of a valid expression). In Pascal and Modula-2, this is
5084 @code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
5085 (although the Pascal form also works).
5086
5087 This form specifies the address of the function's first instruction,
5088 before the stack frame and arguments have been set up.
5089
5090 @item '@var{filename}'::@var{funcaddr}
5091 Like @var{funcaddr} above, but also specifies the name of the source
5092 file explicitly. This is useful if the name of the function does not
5093 specify the function unambiguously, e.g., if there are several
5094 functions with identical names in different source files.
5095 @end table
5096
5097 @end table
5098
5099
5100 @node Edit
5101 @section Editing Source Files
5102 @cindex editing source files
5103
5104 @kindex edit
5105 @kindex e @r{(@code{edit})}
5106 To edit the lines in a source file, use the @code{edit} command.
5107 The editing program of your choice
5108 is invoked with the current line set to
5109 the active line in the program.
5110 Alternatively, there are several ways to specify what part of the file you
5111 want to print if you want to see other parts of the program:
5112
5113 @table @code
5114 @item edit @var{location}
5115 Edit the source file specified by @code{location}. Editing starts at
5116 that @var{location}, e.g., at the specified source line of the
5117 specified file. @xref{Specify Location}, for all the possible forms
5118 of the @var{location} argument; here are the forms of the @code{edit}
5119 command most commonly used:
5120
5121 @table @code
5122 @item edit @var{number}
5123 Edit the current source file with @var{number} as the active line number.
5124
5125 @item edit @var{function}
5126 Edit the file containing @var{function} at the beginning of its definition.
5127 @end table
5128
5129 @end table
5130
5131 @subsection Choosing your Editor
5132 You can customize @value{GDBN} to use any editor you want
5133 @footnote{
5134 The only restriction is that your editor (say @code{ex}), recognizes the
5135 following command-line syntax:
5136 @smallexample
5137 ex +@var{number} file
5138 @end smallexample
5139 The optional numeric value +@var{number} specifies the number of the line in
5140 the file where to start editing.}.
5141 By default, it is @file{@value{EDITOR}}, but you can change this
5142 by setting the environment variable @code{EDITOR} before using
5143 @value{GDBN}. For example, to configure @value{GDBN} to use the
5144 @code{vi} editor, you could use these commands with the @code{sh} shell:
5145 @smallexample
5146 EDITOR=/usr/bin/vi
5147 export EDITOR
5148 gdb @dots{}
5149 @end smallexample
5150 or in the @code{csh} shell,
5151 @smallexample
5152 setenv EDITOR /usr/bin/vi
5153 gdb @dots{}
5154 @end smallexample
5155
5156 @node Search
5157 @section Searching Source Files
5158 @cindex searching source files
5159
5160 There are two commands for searching through the current source file for a
5161 regular expression.
5162
5163 @table @code
5164 @kindex search
5165 @kindex forward-search
5166 @item forward-search @var{regexp}
5167 @itemx search @var{regexp}
5168 The command @samp{forward-search @var{regexp}} checks each line,
5169 starting with the one following the last line listed, for a match for
5170 @var{regexp}. It lists the line that is found. You can use the
5171 synonym @samp{search @var{regexp}} or abbreviate the command name as
5172 @code{fo}.
5173
5174 @kindex reverse-search
5175 @item reverse-search @var{regexp}
5176 The command @samp{reverse-search @var{regexp}} checks each line, starting
5177 with the one before the last line listed and going backward, for a match
5178 for @var{regexp}. It lists the line that is found. You can abbreviate
5179 this command as @code{rev}.
5180 @end table
5181
5182 @node Source Path
5183 @section Specifying Source Directories
5184
5185 @cindex source path
5186 @cindex directories for source files
5187 Executable programs sometimes do not record the directories of the source
5188 files from which they were compiled, just the names. Even when they do,
5189 the directories could be moved between the compilation and your debugging
5190 session. @value{GDBN} has a list of directories to search for source files;
5191 this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
5192 it tries all the directories in the list, in the order they are present
5193 in the list, until it finds a file with the desired name.
5194
5195 For example, suppose an executable references the file
5196 @file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
5197 @file{/mnt/cross}. The file is first looked up literally; if this
5198 fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
5199 fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
5200 message is printed. @value{GDBN} does not look up the parts of the
5201 source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
5202 Likewise, the subdirectories of the source path are not searched: if
5203 the source path is @file{/mnt/cross}, and the binary refers to
5204 @file{foo.c}, @value{GDBN} would not find it under
5205 @file{/mnt/cross/usr/src/foo-1.0/lib}.
5206
5207 Plain file names, relative file names with leading directories, file
5208 names containing dots, etc.@: are all treated as described above; for
5209 instance, if the source path is @file{/mnt/cross}, and the source file
5210 is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
5211 @file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
5212 that---@file{/mnt/cross/foo.c}.
5213
5214 Note that the executable search path is @emph{not} used to locate the
5215 source files.
5216
5217 Whenever you reset or rearrange the source path, @value{GDBN} clears out
5218 any information it has cached about where source files are found and where
5219 each line is in the file.
5220
5221 @kindex directory
5222 @kindex dir
5223 When you start @value{GDBN}, its source path includes only @samp{cdir}
5224 and @samp{cwd}, in that order.
5225 To add other directories, use the @code{directory} command.
5226
5227 The search path is used to find both program source files and @value{GDBN}
5228 script files (read using the @samp{-command} option and @samp{source} command).
5229
5230 In addition to the source path, @value{GDBN} provides a set of commands
5231 that manage a list of source path substitution rules. A @dfn{substitution
5232 rule} specifies how to rewrite source directories stored in the program's
5233 debug information in case the sources were moved to a different
5234 directory between compilation and debugging. A rule is made of
5235 two strings, the first specifying what needs to be rewritten in
5236 the path, and the second specifying how it should be rewritten.
5237 In @ref{set substitute-path}, we name these two parts @var{from} and
5238 @var{to} respectively. @value{GDBN} does a simple string replacement
5239 of @var{from} with @var{to} at the start of the directory part of the
5240 source file name, and uses that result instead of the original file
5241 name to look up the sources.
5242
5243 Using the previous example, suppose the @file{foo-1.0} tree has been
5244 moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
5245 @value{GDBN} to replace @file{/usr/src} in all source path names with
5246 @file{/mnt/cross}. The first lookup will then be
5247 @file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
5248 of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
5249 substitution rule, use the @code{set substitute-path} command
5250 (@pxref{set substitute-path}).
5251
5252 To avoid unexpected substitution results, a rule is applied only if the
5253 @var{from} part of the directory name ends at a directory separator.
5254 For instance, a rule substituting @file{/usr/source} into
5255 @file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
5256 not to @file{/usr/sourceware/foo-2.0}. And because the substitution
5257 is applied only at the beginning of the directory name, this rule will
5258 not be applied to @file{/root/usr/source/baz.c} either.
5259
5260 In many cases, you can achieve the same result using the @code{directory}
5261 command. However, @code{set substitute-path} can be more efficient in
5262 the case where the sources are organized in a complex tree with multiple
5263 subdirectories. With the @code{directory} command, you need to add each
5264 subdirectory of your project. If you moved the entire tree while
5265 preserving its internal organization, then @code{set substitute-path}
5266 allows you to direct the debugger to all the sources with one single
5267 command.
5268
5269 @code{set substitute-path} is also more than just a shortcut command.
5270 The source path is only used if the file at the original location no
5271 longer exists. On the other hand, @code{set substitute-path} modifies
5272 the debugger behavior to look at the rewritten location instead. So, if
5273 for any reason a source file that is not relevant to your executable is
5274 located at the original location, a substitution rule is the only
5275 method available to point @value{GDBN} at the new location.
5276
5277 @table @code
5278 @item directory @var{dirname} @dots{}
5279 @item dir @var{dirname} @dots{}
5280 Add directory @var{dirname} to the front of the source path. Several
5281 directory names may be given to this command, separated by @samp{:}
5282 (@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
5283 part of absolute file names) or
5284 whitespace. You may specify a directory that is already in the source
5285 path; this moves it forward, so @value{GDBN} searches it sooner.
5286
5287 @kindex cdir
5288 @kindex cwd
5289 @vindex $cdir@r{, convenience variable}
5290 @vindex $cwd@r{, convenience variable}
5291 @cindex compilation directory
5292 @cindex current directory
5293 @cindex working directory
5294 @cindex directory, current
5295 @cindex directory, compilation
5296 You can use the string @samp{$cdir} to refer to the compilation
5297 directory (if one is recorded), and @samp{$cwd} to refer to the current
5298 working directory. @samp{$cwd} is not the same as @samp{.}---the former
5299 tracks the current working directory as it changes during your @value{GDBN}
5300 session, while the latter is immediately expanded to the current
5301 directory at the time you add an entry to the source path.
5302
5303 @item directory
5304 Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
5305
5306 @c RET-repeat for @code{directory} is explicitly disabled, but since
5307 @c repeating it would be a no-op we do not say that. (thanks to RMS)
5308
5309 @item show directories
5310 @kindex show directories
5311 Print the source path: show which directories it contains.
5312
5313 @anchor{set substitute-path}
5314 @item set substitute-path @var{from} @var{to}
5315 @kindex set substitute-path
5316 Define a source path substitution rule, and add it at the end of the
5317 current list of existing substitution rules. If a rule with the same
5318 @var{from} was already defined, then the old rule is also deleted.
5319
5320 For example, if the file @file{/foo/bar/baz.c} was moved to
5321 @file{/mnt/cross/baz.c}, then the command
5322
5323 @smallexample
5324 (@value{GDBP}) set substitute-path /usr/src /mnt/cross
5325 @end smallexample
5326
5327 @noindent
5328 will tell @value{GDBN} to replace @samp{/usr/src} with
5329 @samp{/mnt/cross}, which will allow @value{GDBN} to find the file
5330 @file{baz.c} even though it was moved.
5331
5332 In the case when more than one substitution rule have been defined,
5333 the rules are evaluated one by one in the order where they have been
5334 defined. The first one matching, if any, is selected to perform
5335 the substitution.
5336
5337 For instance, if we had entered the following commands:
5338
5339 @smallexample
5340 (@value{GDBP}) set substitute-path /usr/src/include /mnt/include
5341 (@value{GDBP}) set substitute-path /usr/src /mnt/src
5342 @end smallexample
5343
5344 @noindent
5345 @value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
5346 @file{/mnt/include/defs.h} by using the first rule. However, it would
5347 use the second rule to rewrite @file{/usr/src/lib/foo.c} into
5348 @file{/mnt/src/lib/foo.c}.
5349
5350
5351 @item unset substitute-path [path]
5352 @kindex unset substitute-path
5353 If a path is specified, search the current list of substitution rules
5354 for a rule that would rewrite that path. Delete that rule if found.
5355 A warning is emitted by the debugger if no rule could be found.
5356
5357 If no path is specified, then all substitution rules are deleted.
5358
5359 @item show substitute-path [path]
5360 @kindex show substitute-path
5361 If a path is specified, then print the source path substitution rule
5362 which would rewrite that path, if any.
5363
5364 If no path is specified, then print all existing source path substitution
5365 rules.
5366
5367 @end table
5368
5369 If your source path is cluttered with directories that are no longer of
5370 interest, @value{GDBN} may sometimes cause confusion by finding the wrong
5371 versions of source. You can correct the situation as follows:
5372
5373 @enumerate
5374 @item
5375 Use @code{directory} with no argument to reset the source path to its default value.
5376
5377 @item
5378 Use @code{directory} with suitable arguments to reinstall the
5379 directories you want in the source path. You can add all the
5380 directories in one command.
5381 @end enumerate
5382
5383 @node Machine Code
5384 @section Source and Machine Code
5385 @cindex source line and its code address
5386
5387 You can use the command @code{info line} to map source lines to program
5388 addresses (and vice versa), and the command @code{disassemble} to display
5389 a range of addresses as machine instructions. When run under @sc{gnu} Emacs
5390 mode, the @code{info line} command causes the arrow to point to the
5391 line specified. Also, @code{info line} prints addresses in symbolic form as
5392 well as hex.
5393
5394 @table @code
5395 @kindex info line
5396 @item info line @var{linespec}
5397 Print the starting and ending addresses of the compiled code for
5398 source line @var{linespec}. You can specify source lines in any of
5399 the ways documented in @ref{Specify Location}.
5400 @end table
5401
5402 For example, we can use @code{info line} to discover the location of
5403 the object code for the first line of function
5404 @code{m4_changequote}:
5405
5406 @c FIXME: I think this example should also show the addresses in
5407 @c symbolic form, as they usually would be displayed.
5408 @smallexample
5409 (@value{GDBP}) info line m4_changequote
5410 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
5411 @end smallexample
5412
5413 @noindent
5414 @cindex code address and its source line
5415 We can also inquire (using @code{*@var{addr}} as the form for
5416 @var{linespec}) what source line covers a particular address:
5417 @smallexample
5418 (@value{GDBP}) info line *0x63ff
5419 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
5420 @end smallexample
5421
5422 @cindex @code{$_} and @code{info line}
5423 @cindex @code{x} command, default address
5424 @kindex x@r{(examine), and} info line
5425 After @code{info line}, the default address for the @code{x} command
5426 is changed to the starting address of the line, so that @samp{x/i} is
5427 sufficient to begin examining the machine code (@pxref{Memory,
5428 ,Examining Memory}). Also, this address is saved as the value of the
5429 convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
5430 Variables}).
5431
5432 @table @code
5433 @kindex disassemble
5434 @cindex assembly instructions
5435 @cindex instructions, assembly
5436 @cindex machine instructions
5437 @cindex listing machine instructions
5438 @item disassemble
5439 This specialized command dumps a range of memory as machine
5440 instructions. The default memory range is the function surrounding the
5441 program counter of the selected frame. A single argument to this
5442 command is a program counter value; @value{GDBN} dumps the function
5443 surrounding this value. Two arguments specify a range of addresses
5444 (first inclusive, second exclusive) to dump.
5445 @end table
5446
5447 The following example shows the disassembly of a range of addresses of
5448 HP PA-RISC 2.0 code:
5449
5450 @smallexample
5451 (@value{GDBP}) disas 0x32c4 0x32e4
5452 Dump of assembler code from 0x32c4 to 0x32e4:
5453 0x32c4 <main+204>: addil 0,dp
5454 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
5455 0x32cc <main+212>: ldil 0x3000,r31
5456 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
5457 0x32d4 <main+220>: ldo 0(r31),rp
5458 0x32d8 <main+224>: addil -0x800,dp
5459 0x32dc <main+228>: ldo 0x588(r1),r26
5460 0x32e0 <main+232>: ldil 0x3000,r31
5461 End of assembler dump.
5462 @end smallexample
5463
5464 Some architectures have more than one commonly-used set of instruction
5465 mnemonics or other syntax.
5466
5467 For programs that were dynamically linked and use shared libraries,
5468 instructions that call functions or branch to locations in the shared
5469 libraries might show a seemingly bogus location---it's actually a
5470 location of the relocation table. On some architectures, @value{GDBN}
5471 might be able to resolve these to actual function names.
5472
5473 @table @code
5474 @kindex set disassembly-flavor
5475 @cindex Intel disassembly flavor
5476 @cindex AT&T disassembly flavor
5477 @item set disassembly-flavor @var{instruction-set}
5478 Select the instruction set to use when disassembling the
5479 program via the @code{disassemble} or @code{x/i} commands.
5480
5481 Currently this command is only defined for the Intel x86 family. You
5482 can set @var{instruction-set} to either @code{intel} or @code{att}.
5483 The default is @code{att}, the AT&T flavor used by default by Unix
5484 assemblers for x86-based targets.
5485
5486 @kindex show disassembly-flavor
5487 @item show disassembly-flavor
5488 Show the current setting of the disassembly flavor.
5489 @end table
5490
5491
5492 @node Data
5493 @chapter Examining Data
5494
5495 @cindex printing data
5496 @cindex examining data
5497 @kindex print
5498 @kindex inspect
5499 @c "inspect" is not quite a synonym if you are using Epoch, which we do not
5500 @c document because it is nonstandard... Under Epoch it displays in a
5501 @c different window or something like that.
5502 The usual way to examine data in your program is with the @code{print}
5503 command (abbreviated @code{p}), or its synonym @code{inspect}. It
5504 evaluates and prints the value of an expression of the language your
5505 program is written in (@pxref{Languages, ,Using @value{GDBN} with
5506 Different Languages}).
5507
5508 @table @code
5509 @item print @var{expr}
5510 @itemx print /@var{f} @var{expr}
5511 @var{expr} is an expression (in the source language). By default the
5512 value of @var{expr} is printed in a format appropriate to its data type;
5513 you can choose a different format by specifying @samp{/@var{f}}, where
5514 @var{f} is a letter specifying the format; see @ref{Output Formats,,Output
5515 Formats}.
5516
5517 @item print
5518 @itemx print /@var{f}
5519 @cindex reprint the last value
5520 If you omit @var{expr}, @value{GDBN} displays the last value again (from the
5521 @dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
5522 conveniently inspect the same value in an alternative format.
5523 @end table
5524
5525 A more low-level way of examining data is with the @code{x} command.
5526 It examines data in memory at a specified address and prints it in a
5527 specified format. @xref{Memory, ,Examining Memory}.
5528
5529 If you are interested in information about types, or about how the
5530 fields of a struct or a class are declared, use the @code{ptype @var{exp}}
5531 command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
5532 Table}.
5533
5534 @menu
5535 * Expressions:: Expressions
5536 * Variables:: Program variables
5537 * Arrays:: Artificial arrays
5538 * Output Formats:: Output formats
5539 * Memory:: Examining memory
5540 * Auto Display:: Automatic display
5541 * Print Settings:: Print settings
5542 * Value History:: Value history
5543 * Convenience Vars:: Convenience variables
5544 * Registers:: Registers
5545 * Floating Point Hardware:: Floating point hardware
5546 * Vector Unit:: Vector Unit
5547 * OS Information:: Auxiliary data provided by operating system
5548 * Memory Region Attributes:: Memory region attributes
5549 * Dump/Restore Files:: Copy between memory and a file
5550 * Core File Generation:: Cause a program dump its core
5551 * Character Sets:: Debugging programs that use a different
5552 character set than GDB does
5553 * Caching Remote Data:: Data caching for remote targets
5554 @end menu
5555
5556 @node Expressions
5557 @section Expressions
5558
5559 @cindex expressions
5560 @code{print} and many other @value{GDBN} commands accept an expression and
5561 compute its value. Any kind of constant, variable or operator defined
5562 by the programming language you are using is valid in an expression in
5563 @value{GDBN}. This includes conditional expressions, function calls,
5564 casts, and string constants. It also includes preprocessor macros, if
5565 you compiled your program to include this information; see
5566 @ref{Compilation}.
5567
5568 @cindex arrays in expressions
5569 @value{GDBN} supports array constants in expressions input by
5570 the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
5571 you can use the command @code{print @{1, 2, 3@}} to build up an array in
5572 memory that is @code{malloc}ed in the target program.
5573
5574 Because C is so widespread, most of the expressions shown in examples in
5575 this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
5576 Languages}, for information on how to use expressions in other
5577 languages.
5578
5579 In this section, we discuss operators that you can use in @value{GDBN}
5580 expressions regardless of your programming language.
5581
5582 @cindex casts, in expressions
5583 Casts are supported in all languages, not just in C, because it is so
5584 useful to cast a number into a pointer in order to examine a structure
5585 at that address in memory.
5586 @c FIXME: casts supported---Mod2 true?
5587
5588 @value{GDBN} supports these operators, in addition to those common
5589 to programming languages:
5590
5591 @table @code
5592 @item @@
5593 @samp{@@} is a binary operator for treating parts of memory as arrays.
5594 @xref{Arrays, ,Artificial Arrays}, for more information.
5595
5596 @item ::
5597 @samp{::} allows you to specify a variable in terms of the file or
5598 function where it is defined. @xref{Variables, ,Program Variables}.
5599
5600 @cindex @{@var{type}@}
5601 @cindex type casting memory
5602 @cindex memory, viewing as typed object
5603 @cindex casts, to view memory
5604 @item @{@var{type}@} @var{addr}
5605 Refers to an object of type @var{type} stored at address @var{addr} in
5606 memory. @var{addr} may be any expression whose value is an integer or
5607 pointer (but parentheses are required around binary operators, just as in
5608 a cast). This construct is allowed regardless of what kind of data is
5609 normally supposed to reside at @var{addr}.
5610 @end table
5611
5612 @node Variables
5613 @section Program Variables
5614
5615 The most common kind of expression to use is the name of a variable
5616 in your program.
5617
5618 Variables in expressions are understood in the selected stack frame
5619 (@pxref{Selection, ,Selecting a Frame}); they must be either:
5620
5621 @itemize @bullet
5622 @item
5623 global (or file-static)
5624 @end itemize
5625
5626 @noindent or
5627
5628 @itemize @bullet
5629 @item
5630 visible according to the scope rules of the
5631 programming language from the point of execution in that frame
5632 @end itemize
5633
5634 @noindent This means that in the function
5635
5636 @smallexample
5637 foo (a)
5638 int a;
5639 @{
5640 bar (a);
5641 @{
5642 int b = test ();
5643 bar (b);
5644 @}
5645 @}
5646 @end smallexample
5647
5648 @noindent
5649 you can examine and use the variable @code{a} whenever your program is
5650 executing within the function @code{foo}, but you can only use or
5651 examine the variable @code{b} while your program is executing inside
5652 the block where @code{b} is declared.
5653
5654 @cindex variable name conflict
5655 There is an exception: you can refer to a variable or function whose
5656 scope is a single source file even if the current execution point is not
5657 in this file. But it is possible to have more than one such variable or
5658 function with the same name (in different source files). If that
5659 happens, referring to that name has unpredictable effects. If you wish,
5660 you can specify a static variable in a particular function or file,
5661 using the colon-colon (@code{::}) notation:
5662
5663 @cindex colon-colon, context for variables/functions
5664 @ifnotinfo
5665 @c info cannot cope with a :: index entry, but why deprive hard copy readers?
5666 @cindex @code{::}, context for variables/functions
5667 @end ifnotinfo
5668 @smallexample
5669 @var{file}::@var{variable}
5670 @var{function}::@var{variable}
5671 @end smallexample
5672
5673 @noindent
5674 Here @var{file} or @var{function} is the name of the context for the
5675 static @var{variable}. In the case of file names, you can use quotes to
5676 make sure @value{GDBN} parses the file name as a single word---for example,
5677 to print a global value of @code{x} defined in @file{f2.c}:
5678
5679 @smallexample
5680 (@value{GDBP}) p 'f2.c'::x
5681 @end smallexample
5682
5683 @cindex C@t{++} scope resolution
5684 This use of @samp{::} is very rarely in conflict with the very similar
5685 use of the same notation in C@t{++}. @value{GDBN} also supports use of the C@t{++}
5686 scope resolution operator in @value{GDBN} expressions.
5687 @c FIXME: Um, so what happens in one of those rare cases where it's in
5688 @c conflict?? --mew
5689
5690 @cindex wrong values
5691 @cindex variable values, wrong
5692 @cindex function entry/exit, wrong values of variables
5693 @cindex optimized code, wrong values of variables
5694 @quotation
5695 @emph{Warning:} Occasionally, a local variable may appear to have the
5696 wrong value at certain points in a function---just after entry to a new
5697 scope, and just before exit.
5698 @end quotation
5699 You may see this problem when you are stepping by machine instructions.
5700 This is because, on most machines, it takes more than one instruction to
5701 set up a stack frame (including local variable definitions); if you are
5702 stepping by machine instructions, variables may appear to have the wrong
5703 values until the stack frame is completely built. On exit, it usually
5704 also takes more than one machine instruction to destroy a stack frame;
5705 after you begin stepping through that group of instructions, local
5706 variable definitions may be gone.
5707
5708 This may also happen when the compiler does significant optimizations.
5709 To be sure of always seeing accurate values, turn off all optimization
5710 when compiling.
5711
5712 @cindex ``No symbol "foo" in current context''
5713 Another possible effect of compiler optimizations is to optimize
5714 unused variables out of existence, or assign variables to registers (as
5715 opposed to memory addresses). Depending on the support for such cases
5716 offered by the debug info format used by the compiler, @value{GDBN}
5717 might not be able to display values for such local variables. If that
5718 happens, @value{GDBN} will print a message like this:
5719
5720 @smallexample
5721 No symbol "foo" in current context.
5722 @end smallexample
5723
5724 To solve such problems, either recompile without optimizations, or use a
5725 different debug info format, if the compiler supports several such
5726 formats. For example, @value{NGCC}, the @sc{gnu} C/C@t{++} compiler,
5727 usually supports the @option{-gstabs+} option. @option{-gstabs+}
5728 produces debug info in a format that is superior to formats such as
5729 COFF. You may be able to use DWARF 2 (@option{-gdwarf-2}), which is also
5730 an effective form for debug info. @xref{Debugging Options,,Options
5731 for Debugging Your Program or GCC, gcc.info, Using the @sc{gnu}
5732 Compiler Collection (GCC)}.
5733 @xref{C, ,C and C@t{++}}, for more information about debug info formats
5734 that are best suited to C@t{++} programs.
5735
5736 If you ask to print an object whose contents are unknown to
5737 @value{GDBN}, e.g., because its data type is not completely specified
5738 by the debug information, @value{GDBN} will say @samp{<incomplete
5739 type>}. @xref{Symbols, incomplete type}, for more about this.
5740
5741 Strings are identified as arrays of @code{char} values without specified
5742 signedness. Arrays of either @code{signed char} or @code{unsigned char} get
5743 printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
5744 @code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
5745 defines literal string type @code{"char"} as @code{char} without a sign.
5746 For program code
5747
5748 @smallexample
5749 char var0[] = "A";
5750 signed char var1[] = "A";
5751 @end smallexample
5752
5753 You get during debugging
5754 @smallexample
5755 (gdb) print var0
5756 $1 = "A"
5757 (gdb) print var1
5758 $2 = @{65 'A', 0 '\0'@}
5759 @end smallexample
5760
5761 @node Arrays
5762 @section Artificial Arrays
5763
5764 @cindex artificial array
5765 @cindex arrays
5766 @kindex @@@r{, referencing memory as an array}
5767 It is often useful to print out several successive objects of the
5768 same type in memory; a section of an array, or an array of
5769 dynamically determined size for which only a pointer exists in the
5770 program.
5771
5772 You can do this by referring to a contiguous span of memory as an
5773 @dfn{artificial array}, using the binary operator @samp{@@}. The left
5774 operand of @samp{@@} should be the first element of the desired array
5775 and be an individual object. The right operand should be the desired length
5776 of the array. The result is an array value whose elements are all of
5777 the type of the left argument. The first element is actually the left
5778 argument; the second element comes from bytes of memory immediately
5779 following those that hold the first element, and so on. Here is an
5780 example. If a program says
5781
5782 @smallexample
5783 int *array = (int *) malloc (len * sizeof (int));
5784 @end smallexample
5785
5786 @noindent
5787 you can print the contents of @code{array} with
5788
5789 @smallexample
5790 p *array@@len
5791 @end smallexample
5792
5793 The left operand of @samp{@@} must reside in memory. Array values made
5794 with @samp{@@} in this way behave just like other arrays in terms of
5795 subscripting, and are coerced to pointers when used in expressions.
5796 Artificial arrays most often appear in expressions via the value history
5797 (@pxref{Value History, ,Value History}), after printing one out.
5798
5799 Another way to create an artificial array is to use a cast.
5800 This re-interprets a value as if it were an array.
5801 The value need not be in memory:
5802 @smallexample
5803 (@value{GDBP}) p/x (short[2])0x12345678
5804 $1 = @{0x1234, 0x5678@}
5805 @end smallexample
5806
5807 As a convenience, if you leave the array length out (as in
5808 @samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
5809 the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
5810 @smallexample
5811 (@value{GDBP}) p/x (short[])0x12345678
5812 $2 = @{0x1234, 0x5678@}
5813 @end smallexample
5814
5815 Sometimes the artificial array mechanism is not quite enough; in
5816 moderately complex data structures, the elements of interest may not
5817 actually be adjacent---for example, if you are interested in the values
5818 of pointers in an array. One useful work-around in this situation is
5819 to use a convenience variable (@pxref{Convenience Vars, ,Convenience
5820 Variables}) as a counter in an expression that prints the first
5821 interesting value, and then repeat that expression via @key{RET}. For
5822 instance, suppose you have an array @code{dtab} of pointers to
5823 structures, and you are interested in the values of a field @code{fv}
5824 in each structure. Here is an example of what you might type:
5825
5826 @smallexample
5827 set $i = 0
5828 p dtab[$i++]->fv
5829 @key{RET}
5830 @key{RET}
5831 @dots{}
5832 @end smallexample
5833
5834 @node Output Formats
5835 @section Output Formats
5836
5837 @cindex formatted output
5838 @cindex output formats
5839 By default, @value{GDBN} prints a value according to its data type. Sometimes
5840 this is not what you want. For example, you might want to print a number
5841 in hex, or a pointer in decimal. Or you might want to view data in memory
5842 at a certain address as a character string or as an instruction. To do
5843 these things, specify an @dfn{output format} when you print a value.
5844
5845 The simplest use of output formats is to say how to print a value
5846 already computed. This is done by starting the arguments of the
5847 @code{print} command with a slash and a format letter. The format
5848 letters supported are:
5849
5850 @table @code
5851 @item x
5852 Regard the bits of the value as an integer, and print the integer in
5853 hexadecimal.
5854
5855 @item d
5856 Print as integer in signed decimal.
5857
5858 @item u
5859 Print as integer in unsigned decimal.
5860
5861 @item o
5862 Print as integer in octal.
5863
5864 @item t
5865 Print as integer in binary. The letter @samp{t} stands for ``two''.
5866 @footnote{@samp{b} cannot be used because these format letters are also
5867 used with the @code{x} command, where @samp{b} stands for ``byte'';
5868 see @ref{Memory,,Examining Memory}.}
5869
5870 @item a
5871 @cindex unknown address, locating
5872 @cindex locate address
5873 Print as an address, both absolute in hexadecimal and as an offset from
5874 the nearest preceding symbol. You can use this format used to discover
5875 where (in what function) an unknown address is located:
5876
5877 @smallexample
5878 (@value{GDBP}) p/a 0x54320
5879 $3 = 0x54320 <_initialize_vx+396>
5880 @end smallexample
5881
5882 @noindent
5883 The command @code{info symbol 0x54320} yields similar results.
5884 @xref{Symbols, info symbol}.
5885
5886 @item c
5887 Regard as an integer and print it as a character constant. This
5888 prints both the numerical value and its character representation. The
5889 character representation is replaced with the octal escape @samp{\nnn}
5890 for characters outside the 7-bit @sc{ascii} range.
5891
5892 Without this format, @value{GDBN} displays @code{char},
5893 @w{@code{unsigned char}}, and @w{@code{signed char}} data as character
5894 constants. Single-byte members of vectors are displayed as integer
5895 data.
5896
5897 @item f
5898 Regard the bits of the value as a floating point number and print
5899 using typical floating point syntax.
5900
5901 @item s
5902 @cindex printing strings
5903 @cindex printing byte arrays
5904 Regard as a string, if possible. With this format, pointers to single-byte
5905 data are displayed as null-terminated strings and arrays of single-byte data
5906 are displayed as fixed-length strings. Other values are displayed in their
5907 natural types.
5908
5909 Without this format, @value{GDBN} displays pointers to and arrays of
5910 @code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
5911 strings. Single-byte members of a vector are displayed as an integer
5912 array.
5913 @end table
5914
5915 For example, to print the program counter in hex (@pxref{Registers}), type
5916
5917 @smallexample
5918 p/x $pc
5919 @end smallexample
5920
5921 @noindent
5922 Note that no space is required before the slash; this is because command
5923 names in @value{GDBN} cannot contain a slash.
5924
5925 To reprint the last value in the value history with a different format,
5926 you can use the @code{print} command with just a format and no
5927 expression. For example, @samp{p/x} reprints the last value in hex.
5928
5929 @node Memory
5930 @section Examining Memory
5931
5932 You can use the command @code{x} (for ``examine'') to examine memory in
5933 any of several formats, independently of your program's data types.
5934
5935 @cindex examining memory
5936 @table @code
5937 @kindex x @r{(examine memory)}
5938 @item x/@var{nfu} @var{addr}
5939 @itemx x @var{addr}
5940 @itemx x
5941 Use the @code{x} command to examine memory.
5942 @end table
5943
5944 @var{n}, @var{f}, and @var{u} are all optional parameters that specify how
5945 much memory to display and how to format it; @var{addr} is an
5946 expression giving the address where you want to start displaying memory.
5947 If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
5948 Several commands set convenient defaults for @var{addr}.
5949
5950 @table @r
5951 @item @var{n}, the repeat count
5952 The repeat count is a decimal integer; the default is 1. It specifies
5953 how much memory (counting by units @var{u}) to display.
5954 @c This really is **decimal**; unaffected by 'set radix' as of GDB
5955 @c 4.1.2.
5956
5957 @item @var{f}, the display format
5958 The display format is one of the formats used by @code{print}
5959 (@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
5960 @samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
5961 The default is @samp{x} (hexadecimal) initially. The default changes
5962 each time you use either @code{x} or @code{print}.
5963
5964 @item @var{u}, the unit size
5965 The unit size is any of
5966
5967 @table @code
5968 @item b
5969 Bytes.
5970 @item h
5971 Halfwords (two bytes).
5972 @item w
5973 Words (four bytes). This is the initial default.
5974 @item g
5975 Giant words (eight bytes).
5976 @end table
5977
5978 Each time you specify a unit size with @code{x}, that size becomes the
5979 default unit the next time you use @code{x}. (For the @samp{s} and
5980 @samp{i} formats, the unit size is ignored and is normally not written.)
5981
5982 @item @var{addr}, starting display address
5983 @var{addr} is the address where you want @value{GDBN} to begin displaying
5984 memory. The expression need not have a pointer value (though it may);
5985 it is always interpreted as an integer address of a byte of memory.
5986 @xref{Expressions, ,Expressions}, for more information on expressions. The default for
5987 @var{addr} is usually just after the last address examined---but several
5988 other commands also set the default address: @code{info breakpoints} (to
5989 the address of the last breakpoint listed), @code{info line} (to the
5990 starting address of a line), and @code{print} (if you use it to display
5991 a value from memory).
5992 @end table
5993
5994 For example, @samp{x/3uh 0x54320} is a request to display three halfwords
5995 (@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
5996 starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
5997 words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
5998 @pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
5999
6000 Since the letters indicating unit sizes are all distinct from the
6001 letters specifying output formats, you do not have to remember whether
6002 unit size or format comes first; either order works. The output
6003 specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
6004 (However, the count @var{n} must come first; @samp{wx4} does not work.)
6005
6006 Even though the unit size @var{u} is ignored for the formats @samp{s}
6007 and @samp{i}, you might still want to use a count @var{n}; for example,
6008 @samp{3i} specifies that you want to see three machine instructions,
6009 including any operands. For convenience, especially when used with
6010 the @code{display} command, the @samp{i} format also prints branch delay
6011 slot instructions, if any, beyond the count specified, which immediately
6012 follow the last instruction that is within the count. The command
6013 @code{disassemble} gives an alternative way of inspecting machine
6014 instructions; see @ref{Machine Code,,Source and Machine Code}.
6015
6016 All the defaults for the arguments to @code{x} are designed to make it
6017 easy to continue scanning memory with minimal specifications each time
6018 you use @code{x}. For example, after you have inspected three machine
6019 instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
6020 with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
6021 the repeat count @var{n} is used again; the other arguments default as
6022 for successive uses of @code{x}.
6023
6024 @cindex @code{$_}, @code{$__}, and value history
6025 The addresses and contents printed by the @code{x} command are not saved
6026 in the value history because there is often too much of them and they
6027 would get in the way. Instead, @value{GDBN} makes these values available for
6028 subsequent use in expressions as values of the convenience variables
6029 @code{$_} and @code{$__}. After an @code{x} command, the last address
6030 examined is available for use in expressions in the convenience variable
6031 @code{$_}. The contents of that address, as examined, are available in
6032 the convenience variable @code{$__}.
6033
6034 If the @code{x} command has a repeat count, the address and contents saved
6035 are from the last memory unit printed; this is not the same as the last
6036 address printed if several units were printed on the last line of output.
6037
6038 @cindex remote memory comparison
6039 @cindex verify remote memory image
6040 When you are debugging a program running on a remote target machine
6041 (@pxref{Remote Debugging}), you may wish to verify the program's image in the
6042 remote machine's memory against the executable file you downloaded to
6043 the target. The @code{compare-sections} command is provided for such
6044 situations.
6045
6046 @table @code
6047 @kindex compare-sections
6048 @item compare-sections @r{[}@var{section-name}@r{]}
6049 Compare the data of a loadable section @var{section-name} in the
6050 executable file of the program being debugged with the same section in
6051 the remote machine's memory, and report any mismatches. With no
6052 arguments, compares all loadable sections. This command's
6053 availability depends on the target's support for the @code{"qCRC"}
6054 remote request.
6055 @end table
6056
6057 @node Auto Display
6058 @section Automatic Display
6059 @cindex automatic display
6060 @cindex display of expressions
6061
6062 If you find that you want to print the value of an expression frequently
6063 (to see how it changes), you might want to add it to the @dfn{automatic
6064 display list} so that @value{GDBN} prints its value each time your program stops.
6065 Each expression added to the list is given a number to identify it;
6066 to remove an expression from the list, you specify that number.
6067 The automatic display looks like this:
6068
6069 @smallexample
6070 2: foo = 38
6071 3: bar[5] = (struct hack *) 0x3804
6072 @end smallexample
6073
6074 @noindent
6075 This display shows item numbers, expressions and their current values. As with
6076 displays you request manually using @code{x} or @code{print}, you can
6077 specify the output format you prefer; in fact, @code{display} decides
6078 whether to use @code{print} or @code{x} depending your format
6079 specification---it uses @code{x} if you specify either the @samp{i}
6080 or @samp{s} format, or a unit size; otherwise it uses @code{print}.
6081
6082 @table @code
6083 @kindex display
6084 @item display @var{expr}
6085 Add the expression @var{expr} to the list of expressions to display
6086 each time your program stops. @xref{Expressions, ,Expressions}.
6087
6088 @code{display} does not repeat if you press @key{RET} again after using it.
6089
6090 @item display/@var{fmt} @var{expr}
6091 For @var{fmt} specifying only a display format and not a size or
6092 count, add the expression @var{expr} to the auto-display list but
6093 arrange to display it each time in the specified format @var{fmt}.
6094 @xref{Output Formats,,Output Formats}.
6095
6096 @item display/@var{fmt} @var{addr}
6097 For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
6098 number of units, add the expression @var{addr} as a memory address to
6099 be examined each time your program stops. Examining means in effect
6100 doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
6101 @end table
6102
6103 For example, @samp{display/i $pc} can be helpful, to see the machine
6104 instruction about to be executed each time execution stops (@samp{$pc}
6105 is a common name for the program counter; @pxref{Registers, ,Registers}).
6106
6107 @table @code
6108 @kindex delete display
6109 @kindex undisplay
6110 @item undisplay @var{dnums}@dots{}
6111 @itemx delete display @var{dnums}@dots{}
6112 Remove item numbers @var{dnums} from the list of expressions to display.
6113
6114 @code{undisplay} does not repeat if you press @key{RET} after using it.
6115 (Otherwise you would just get the error @samp{No display number @dots{}}.)
6116
6117 @kindex disable display
6118 @item disable display @var{dnums}@dots{}
6119 Disable the display of item numbers @var{dnums}. A disabled display
6120 item is not printed automatically, but is not forgotten. It may be
6121 enabled again later.
6122
6123 @kindex enable display
6124 @item enable display @var{dnums}@dots{}
6125 Enable display of item numbers @var{dnums}. It becomes effective once
6126 again in auto display of its expression, until you specify otherwise.
6127
6128 @item display
6129 Display the current values of the expressions on the list, just as is
6130 done when your program stops.
6131
6132 @kindex info display
6133 @item info display
6134 Print the list of expressions previously set up to display
6135 automatically, each one with its item number, but without showing the
6136 values. This includes disabled expressions, which are marked as such.
6137 It also includes expressions which would not be displayed right now
6138 because they refer to automatic variables not currently available.
6139 @end table
6140
6141 @cindex display disabled out of scope
6142 If a display expression refers to local variables, then it does not make
6143 sense outside the lexical context for which it was set up. Such an
6144 expression is disabled when execution enters a context where one of its
6145 variables is not defined. For example, if you give the command
6146 @code{display last_char} while inside a function with an argument
6147 @code{last_char}, @value{GDBN} displays this argument while your program
6148 continues to stop inside that function. When it stops elsewhere---where
6149 there is no variable @code{last_char}---the display is disabled
6150 automatically. The next time your program stops where @code{last_char}
6151 is meaningful, you can enable the display expression once again.
6152
6153 @node Print Settings
6154 @section Print Settings
6155
6156 @cindex format options
6157 @cindex print settings
6158 @value{GDBN} provides the following ways to control how arrays, structures,
6159 and symbols are printed.
6160
6161 @noindent
6162 These settings are useful for debugging programs in any language:
6163
6164 @table @code
6165 @kindex set print
6166 @item set print address
6167 @itemx set print address on
6168 @cindex print/don't print memory addresses
6169 @value{GDBN} prints memory addresses showing the location of stack
6170 traces, structure values, pointer values, breakpoints, and so forth,
6171 even when it also displays the contents of those addresses. The default
6172 is @code{on}. For example, this is what a stack frame display looks like with
6173 @code{set print address on}:
6174
6175 @smallexample
6176 @group
6177 (@value{GDBP}) f
6178 #0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
6179 at input.c:530
6180 530 if (lquote != def_lquote)
6181 @end group
6182 @end smallexample
6183
6184 @item set print address off
6185 Do not print addresses when displaying their contents. For example,
6186 this is the same stack frame displayed with @code{set print address off}:
6187
6188 @smallexample
6189 @group
6190 (@value{GDBP}) set print addr off
6191 (@value{GDBP}) f
6192 #0 set_quotes (lq="<<", rq=">>") at input.c:530
6193 530 if (lquote != def_lquote)
6194 @end group
6195 @end smallexample
6196
6197 You can use @samp{set print address off} to eliminate all machine
6198 dependent displays from the @value{GDBN} interface. For example, with
6199 @code{print address off}, you should get the same text for backtraces on
6200 all machines---whether or not they involve pointer arguments.
6201
6202 @kindex show print
6203 @item show print address
6204 Show whether or not addresses are to be printed.
6205 @end table
6206
6207 When @value{GDBN} prints a symbolic address, it normally prints the
6208 closest earlier symbol plus an offset. If that symbol does not uniquely
6209 identify the address (for example, it is a name whose scope is a single
6210 source file), you may need to clarify. One way to do this is with
6211 @code{info line}, for example @samp{info line *0x4537}. Alternately,
6212 you can set @value{GDBN} to print the source file and line number when
6213 it prints a symbolic address:
6214
6215 @table @code
6216 @item set print symbol-filename on
6217 @cindex source file and line of a symbol
6218 @cindex symbol, source file and line
6219 Tell @value{GDBN} to print the source file name and line number of a
6220 symbol in the symbolic form of an address.
6221
6222 @item set print symbol-filename off
6223 Do not print source file name and line number of a symbol. This is the
6224 default.
6225
6226 @item show print symbol-filename
6227 Show whether or not @value{GDBN} will print the source file name and
6228 line number of a symbol in the symbolic form of an address.
6229 @end table
6230
6231 Another situation where it is helpful to show symbol filenames and line
6232 numbers is when disassembling code; @value{GDBN} shows you the line
6233 number and source file that corresponds to each instruction.
6234
6235 Also, you may wish to see the symbolic form only if the address being
6236 printed is reasonably close to the closest earlier symbol:
6237
6238 @table @code
6239 @item set print max-symbolic-offset @var{max-offset}
6240 @cindex maximum value for offset of closest symbol
6241 Tell @value{GDBN} to only display the symbolic form of an address if the
6242 offset between the closest earlier symbol and the address is less than
6243 @var{max-offset}. The default is 0, which tells @value{GDBN}
6244 to always print the symbolic form of an address if any symbol precedes it.
6245
6246 @item show print max-symbolic-offset
6247 Ask how large the maximum offset is that @value{GDBN} prints in a
6248 symbolic address.
6249 @end table
6250
6251 @cindex wild pointer, interpreting
6252 @cindex pointer, finding referent
6253 If you have a pointer and you are not sure where it points, try
6254 @samp{set print symbol-filename on}. Then you can determine the name
6255 and source file location of the variable where it points, using
6256 @samp{p/a @var{pointer}}. This interprets the address in symbolic form.
6257 For example, here @value{GDBN} shows that a variable @code{ptt} points
6258 at another variable @code{t}, defined in @file{hi2.c}:
6259
6260 @smallexample
6261 (@value{GDBP}) set print symbol-filename on
6262 (@value{GDBP}) p/a ptt
6263 $4 = 0xe008 <t in hi2.c>
6264 @end smallexample
6265
6266 @quotation
6267 @emph{Warning:} For pointers that point to a local variable, @samp{p/a}
6268 does not show the symbol name and filename of the referent, even with
6269 the appropriate @code{set print} options turned on.
6270 @end quotation
6271
6272 Other settings control how different kinds of objects are printed:
6273
6274 @table @code
6275 @item set print array
6276 @itemx set print array on
6277 @cindex pretty print arrays
6278 Pretty print arrays. This format is more convenient to read,
6279 but uses more space. The default is off.
6280
6281 @item set print array off
6282 Return to compressed format for arrays.
6283
6284 @item show print array
6285 Show whether compressed or pretty format is selected for displaying
6286 arrays.
6287
6288 @cindex print array indexes
6289 @item set print array-indexes
6290 @itemx set print array-indexes on
6291 Print the index of each element when displaying arrays. May be more
6292 convenient to locate a given element in the array or quickly find the
6293 index of a given element in that printed array. The default is off.
6294
6295 @item set print array-indexes off
6296 Stop printing element indexes when displaying arrays.
6297
6298 @item show print array-indexes
6299 Show whether the index of each element is printed when displaying
6300 arrays.
6301
6302 @item set print elements @var{number-of-elements}
6303 @cindex number of array elements to print
6304 @cindex limit on number of printed array elements
6305 Set a limit on how many elements of an array @value{GDBN} will print.
6306 If @value{GDBN} is printing a large array, it stops printing after it has
6307 printed the number of elements set by the @code{set print elements} command.
6308 This limit also applies to the display of strings.
6309 When @value{GDBN} starts, this limit is set to 200.
6310 Setting @var{number-of-elements} to zero means that the printing is unlimited.
6311
6312 @item show print elements
6313 Display the number of elements of a large array that @value{GDBN} will print.
6314 If the number is 0, then the printing is unlimited.
6315
6316 @item set print frame-arguments @var{value}
6317 @cindex printing frame argument values
6318 @cindex print all frame argument values
6319 @cindex print frame argument values for scalars only
6320 @cindex do not print frame argument values
6321 This command allows to control how the values of arguments are printed
6322 when the debugger prints a frame (@pxref{Frames}). The possible
6323 values are:
6324
6325 @table @code
6326 @item all
6327 The values of all arguments are printed. This is the default.
6328
6329 @item scalars
6330 Print the value of an argument only if it is a scalar. The value of more
6331 complex arguments such as arrays, structures, unions, etc, is replaced
6332 by @code{@dots{}}. Here is an example where only scalar arguments are shown:
6333
6334 @smallexample
6335 #1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
6336 at frame-args.c:23
6337 @end smallexample
6338
6339 @item none
6340 None of the argument values are printed. Instead, the value of each argument
6341 is replaced by @code{@dots{}}. In this case, the example above now becomes:
6342
6343 @smallexample
6344 #1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
6345 at frame-args.c:23
6346 @end smallexample
6347 @end table
6348
6349 By default, all argument values are always printed. But this command
6350 can be useful in several cases. For instance, it can be used to reduce
6351 the amount of information printed in each frame, making the backtrace
6352 more readable. Also, this command can be used to improve performance
6353 when displaying Ada frames, because the computation of large arguments
6354 can sometimes be CPU-intensive, especiallly in large applications.
6355 Setting @code{print frame-arguments} to @code{scalars} or @code{none}
6356 avoids this computation, thus speeding up the display of each Ada frame.
6357
6358 @item show print frame-arguments
6359 Show how the value of arguments should be displayed when printing a frame.
6360
6361 @item set print repeats
6362 @cindex repeated array elements
6363 Set the threshold for suppressing display of repeated array
6364 elements. When the number of consecutive identical elements of an
6365 array exceeds the threshold, @value{GDBN} prints the string
6366 @code{"<repeats @var{n} times>"}, where @var{n} is the number of
6367 identical repetitions, instead of displaying the identical elements
6368 themselves. Setting the threshold to zero will cause all elements to
6369 be individually printed. The default threshold is 10.
6370
6371 @item show print repeats
6372 Display the current threshold for printing repeated identical
6373 elements.
6374
6375 @item set print null-stop
6376 @cindex @sc{null} elements in arrays
6377 Cause @value{GDBN} to stop printing the characters of an array when the first
6378 @sc{null} is encountered. This is useful when large arrays actually
6379 contain only short strings.
6380 The default is off.
6381
6382 @item show print null-stop
6383 Show whether @value{GDBN} stops printing an array on the first
6384 @sc{null} character.
6385
6386 @item set print pretty on
6387 @cindex print structures in indented form
6388 @cindex indentation in structure display
6389 Cause @value{GDBN} to print structures in an indented format with one member
6390 per line, like this:
6391
6392 @smallexample
6393 @group
6394 $1 = @{
6395 next = 0x0,
6396 flags = @{
6397 sweet = 1,
6398 sour = 1
6399 @},
6400 meat = 0x54 "Pork"
6401 @}
6402 @end group
6403 @end smallexample
6404
6405 @item set print pretty off
6406 Cause @value{GDBN} to print structures in a compact format, like this:
6407
6408 @smallexample
6409 @group
6410 $1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
6411 meat = 0x54 "Pork"@}
6412 @end group
6413 @end smallexample
6414
6415 @noindent
6416 This is the default format.
6417
6418 @item show print pretty
6419 Show which format @value{GDBN} is using to print structures.
6420
6421 @item set print sevenbit-strings on
6422 @cindex eight-bit characters in strings
6423 @cindex octal escapes in strings
6424 Print using only seven-bit characters; if this option is set,
6425 @value{GDBN} displays any eight-bit characters (in strings or
6426 character values) using the notation @code{\}@var{nnn}. This setting is
6427 best if you are working in English (@sc{ascii}) and you use the
6428 high-order bit of characters as a marker or ``meta'' bit.
6429
6430 @item set print sevenbit-strings off
6431 Print full eight-bit characters. This allows the use of more
6432 international character sets, and is the default.
6433
6434 @item show print sevenbit-strings
6435 Show whether or not @value{GDBN} is printing only seven-bit characters.
6436
6437 @item set print union on
6438 @cindex unions in structures, printing
6439 Tell @value{GDBN} to print unions which are contained in structures
6440 and other unions. This is the default setting.
6441
6442 @item set print union off
6443 Tell @value{GDBN} not to print unions which are contained in
6444 structures and other unions. @value{GDBN} will print @code{"@{...@}"}
6445 instead.
6446
6447 @item show print union
6448 Ask @value{GDBN} whether or not it will print unions which are contained in
6449 structures and other unions.
6450
6451 For example, given the declarations
6452
6453 @smallexample
6454 typedef enum @{Tree, Bug@} Species;
6455 typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
6456 typedef enum @{Caterpillar, Cocoon, Butterfly@}
6457 Bug_forms;
6458
6459 struct thing @{
6460 Species it;
6461 union @{
6462 Tree_forms tree;
6463 Bug_forms bug;
6464 @} form;
6465 @};
6466
6467 struct thing foo = @{Tree, @{Acorn@}@};
6468 @end smallexample
6469
6470 @noindent
6471 with @code{set print union on} in effect @samp{p foo} would print
6472
6473 @smallexample
6474 $1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
6475 @end smallexample
6476
6477 @noindent
6478 and with @code{set print union off} in effect it would print
6479
6480 @smallexample
6481 $1 = @{it = Tree, form = @{...@}@}
6482 @end smallexample
6483
6484 @noindent
6485 @code{set print union} affects programs written in C-like languages
6486 and in Pascal.
6487 @end table
6488
6489 @need 1000
6490 @noindent
6491 These settings are of interest when debugging C@t{++} programs:
6492
6493 @table @code
6494 @cindex demangling C@t{++} names
6495 @item set print demangle
6496 @itemx set print demangle on
6497 Print C@t{++} names in their source form rather than in the encoded
6498 (``mangled'') form passed to the assembler and linker for type-safe
6499 linkage. The default is on.
6500
6501 @item show print demangle
6502 Show whether C@t{++} names are printed in mangled or demangled form.
6503
6504 @item set print asm-demangle
6505 @itemx set print asm-demangle on
6506 Print C@t{++} names in their source form rather than their mangled form, even
6507 in assembler code printouts such as instruction disassemblies.
6508 The default is off.
6509
6510 @item show print asm-demangle
6511 Show whether C@t{++} names in assembly listings are printed in mangled
6512 or demangled form.
6513
6514 @cindex C@t{++} symbol decoding style
6515 @cindex symbol decoding style, C@t{++}
6516 @kindex set demangle-style
6517 @item set demangle-style @var{style}
6518 Choose among several encoding schemes used by different compilers to
6519 represent C@t{++} names. The choices for @var{style} are currently:
6520
6521 @table @code
6522 @item auto
6523 Allow @value{GDBN} to choose a decoding style by inspecting your program.
6524
6525 @item gnu
6526 Decode based on the @sc{gnu} C@t{++} compiler (@code{g++}) encoding algorithm.
6527 This is the default.
6528
6529 @item hp
6530 Decode based on the HP ANSI C@t{++} (@code{aCC}) encoding algorithm.
6531
6532 @item lucid
6533 Decode based on the Lucid C@t{++} compiler (@code{lcc}) encoding algorithm.
6534
6535 @item arm
6536 Decode using the algorithm in the @cite{C@t{++} Annotated Reference Manual}.
6537 @strong{Warning:} this setting alone is not sufficient to allow
6538 debugging @code{cfront}-generated executables. @value{GDBN} would
6539 require further enhancement to permit that.
6540
6541 @end table
6542 If you omit @var{style}, you will see a list of possible formats.
6543
6544 @item show demangle-style
6545 Display the encoding style currently in use for decoding C@t{++} symbols.
6546
6547 @item set print object
6548 @itemx set print object on
6549 @cindex derived type of an object, printing
6550 @cindex display derived types
6551 When displaying a pointer to an object, identify the @emph{actual}
6552 (derived) type of the object rather than the @emph{declared} type, using
6553 the virtual function table.
6554
6555 @item set print object off
6556 Display only the declared type of objects, without reference to the
6557 virtual function table. This is the default setting.
6558
6559 @item show print object
6560 Show whether actual, or declared, object types are displayed.
6561
6562 @item set print static-members
6563 @itemx set print static-members on
6564 @cindex static members of C@t{++} objects
6565 Print static members when displaying a C@t{++} object. The default is on.
6566
6567 @item set print static-members off
6568 Do not print static members when displaying a C@t{++} object.
6569
6570 @item show print static-members
6571 Show whether C@t{++} static members are printed or not.
6572
6573 @item set print pascal_static-members
6574 @itemx set print pascal_static-members on
6575 @cindex static members of Pascal objects
6576 @cindex Pascal objects, static members display
6577 Print static members when displaying a Pascal object. The default is on.
6578
6579 @item set print pascal_static-members off
6580 Do not print static members when displaying a Pascal object.
6581
6582 @item show print pascal_static-members
6583 Show whether Pascal static members are printed or not.
6584
6585 @c These don't work with HP ANSI C++ yet.
6586 @item set print vtbl
6587 @itemx set print vtbl on
6588 @cindex pretty print C@t{++} virtual function tables
6589 @cindex virtual functions (C@t{++}) display
6590 @cindex VTBL display
6591 Pretty print C@t{++} virtual function tables. The default is off.
6592 (The @code{vtbl} commands do not work on programs compiled with the HP
6593 ANSI C@t{++} compiler (@code{aCC}).)
6594
6595 @item set print vtbl off
6596 Do not pretty print C@t{++} virtual function tables.
6597
6598 @item show print vtbl
6599 Show whether C@t{++} virtual function tables are pretty printed, or not.
6600 @end table
6601
6602 @node Value History
6603 @section Value History
6604
6605 @cindex value history
6606 @cindex history of values printed by @value{GDBN}
6607 Values printed by the @code{print} command are saved in the @value{GDBN}
6608 @dfn{value history}. This allows you to refer to them in other expressions.
6609 Values are kept until the symbol table is re-read or discarded
6610 (for example with the @code{file} or @code{symbol-file} commands).
6611 When the symbol table changes, the value history is discarded,
6612 since the values may contain pointers back to the types defined in the
6613 symbol table.
6614
6615 @cindex @code{$}
6616 @cindex @code{$$}
6617 @cindex history number
6618 The values printed are given @dfn{history numbers} by which you can
6619 refer to them. These are successive integers starting with one.
6620 @code{print} shows you the history number assigned to a value by
6621 printing @samp{$@var{num} = } before the value; here @var{num} is the
6622 history number.
6623
6624 To refer to any previous value, use @samp{$} followed by the value's
6625 history number. The way @code{print} labels its output is designed to
6626 remind you of this. Just @code{$} refers to the most recent value in
6627 the history, and @code{$$} refers to the value before that.
6628 @code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
6629 is the value just prior to @code{$$}, @code{$$1} is equivalent to
6630 @code{$$}, and @code{$$0} is equivalent to @code{$}.
6631
6632 For example, suppose you have just printed a pointer to a structure and
6633 want to see the contents of the structure. It suffices to type
6634
6635 @smallexample
6636 p *$
6637 @end smallexample
6638
6639 If you have a chain of structures where the component @code{next} points
6640 to the next one, you can print the contents of the next one with this:
6641
6642 @smallexample
6643 p *$.next
6644 @end smallexample
6645
6646 @noindent
6647 You can print successive links in the chain by repeating this
6648 command---which you can do by just typing @key{RET}.
6649
6650 Note that the history records values, not expressions. If the value of
6651 @code{x} is 4 and you type these commands:
6652
6653 @smallexample
6654 print x
6655 set x=5
6656 @end smallexample
6657
6658 @noindent
6659 then the value recorded in the value history by the @code{print} command
6660 remains 4 even though the value of @code{x} has changed.
6661
6662 @table @code
6663 @kindex show values
6664 @item show values
6665 Print the last ten values in the value history, with their item numbers.
6666 This is like @samp{p@ $$9} repeated ten times, except that @code{show
6667 values} does not change the history.
6668
6669 @item show values @var{n}
6670 Print ten history values centered on history item number @var{n}.
6671
6672 @item show values +
6673 Print ten history values just after the values last printed. If no more
6674 values are available, @code{show values +} produces no display.
6675 @end table
6676
6677 Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
6678 same effect as @samp{show values +}.
6679
6680 @node Convenience Vars
6681 @section Convenience Variables
6682
6683 @cindex convenience variables
6684 @cindex user-defined variables
6685 @value{GDBN} provides @dfn{convenience variables} that you can use within
6686 @value{GDBN} to hold on to a value and refer to it later. These variables
6687 exist entirely within @value{GDBN}; they are not part of your program, and
6688 setting a convenience variable has no direct effect on further execution
6689 of your program. That is why you can use them freely.
6690
6691 Convenience variables are prefixed with @samp{$}. Any name preceded by
6692 @samp{$} can be used for a convenience variable, unless it is one of
6693 the predefined machine-specific register names (@pxref{Registers, ,Registers}).
6694 (Value history references, in contrast, are @emph{numbers} preceded
6695 by @samp{$}. @xref{Value History, ,Value History}.)
6696
6697 You can save a value in a convenience variable with an assignment
6698 expression, just as you would set a variable in your program.
6699 For example:
6700
6701 @smallexample
6702 set $foo = *object_ptr
6703 @end smallexample
6704
6705 @noindent
6706 would save in @code{$foo} the value contained in the object pointed to by
6707 @code{object_ptr}.
6708
6709 Using a convenience variable for the first time creates it, but its
6710 value is @code{void} until you assign a new value. You can alter the
6711 value with another assignment at any time.
6712
6713 Convenience variables have no fixed types. You can assign a convenience
6714 variable any type of value, including structures and arrays, even if
6715 that variable already has a value of a different type. The convenience
6716 variable, when used as an expression, has the type of its current value.
6717
6718 @table @code
6719 @kindex show convenience
6720 @cindex show all user variables
6721 @item show convenience
6722 Print a list of convenience variables used so far, and their values.
6723 Abbreviated @code{show conv}.
6724
6725 @kindex init-if-undefined
6726 @cindex convenience variables, initializing
6727 @item init-if-undefined $@var{variable} = @var{expression}
6728 Set a convenience variable if it has not already been set. This is useful
6729 for user-defined commands that keep some state. It is similar, in concept,
6730 to using local static variables with initializers in C (except that
6731 convenience variables are global). It can also be used to allow users to
6732 override default values used in a command script.
6733
6734 If the variable is already defined then the expression is not evaluated so
6735 any side-effects do not occur.
6736 @end table
6737
6738 One of the ways to use a convenience variable is as a counter to be
6739 incremented or a pointer to be advanced. For example, to print
6740 a field from successive elements of an array of structures:
6741
6742 @smallexample
6743 set $i = 0
6744 print bar[$i++]->contents
6745 @end smallexample
6746
6747 @noindent
6748 Repeat that command by typing @key{RET}.
6749
6750 Some convenience variables are created automatically by @value{GDBN} and given
6751 values likely to be useful.
6752
6753 @table @code
6754 @vindex $_@r{, convenience variable}
6755 @item $_
6756 The variable @code{$_} is automatically set by the @code{x} command to
6757 the last address examined (@pxref{Memory, ,Examining Memory}). Other
6758 commands which provide a default address for @code{x} to examine also
6759 set @code{$_} to that address; these commands include @code{info line}
6760 and @code{info breakpoint}. The type of @code{$_} is @code{void *}
6761 except when set by the @code{x} command, in which case it is a pointer
6762 to the type of @code{$__}.
6763
6764 @vindex $__@r{, convenience variable}
6765 @item $__
6766 The variable @code{$__} is automatically set by the @code{x} command
6767 to the value found in the last address examined. Its type is chosen
6768 to match the format in which the data was printed.
6769
6770 @item $_exitcode
6771 @vindex $_exitcode@r{, convenience variable}
6772 The variable @code{$_exitcode} is automatically set to the exit code when
6773 the program being debugged terminates.
6774 @end table
6775
6776 On HP-UX systems, if you refer to a function or variable name that
6777 begins with a dollar sign, @value{GDBN} searches for a user or system
6778 name first, before it searches for a convenience variable.
6779
6780 @node Registers
6781 @section Registers
6782
6783 @cindex registers
6784 You can refer to machine register contents, in expressions, as variables
6785 with names starting with @samp{$}. The names of registers are different
6786 for each machine; use @code{info registers} to see the names used on
6787 your machine.
6788
6789 @table @code
6790 @kindex info registers
6791 @item info registers
6792 Print the names and values of all registers except floating-point
6793 and vector registers (in the selected stack frame).
6794
6795 @kindex info all-registers
6796 @cindex floating point registers
6797 @item info all-registers
6798 Print the names and values of all registers, including floating-point
6799 and vector registers (in the selected stack frame).
6800
6801 @item info registers @var{regname} @dots{}
6802 Print the @dfn{relativized} value of each specified register @var{regname}.
6803 As discussed in detail below, register values are normally relative to
6804 the selected stack frame. @var{regname} may be any register name valid on
6805 the machine you are using, with or without the initial @samp{$}.
6806 @end table
6807
6808 @cindex stack pointer register
6809 @cindex program counter register
6810 @cindex process status register
6811 @cindex frame pointer register
6812 @cindex standard registers
6813 @value{GDBN} has four ``standard'' register names that are available (in
6814 expressions) on most machines---whenever they do not conflict with an
6815 architecture's canonical mnemonics for registers. The register names
6816 @code{$pc} and @code{$sp} are used for the program counter register and
6817 the stack pointer. @code{$fp} is used for a register that contains a
6818 pointer to the current stack frame, and @code{$ps} is used for a
6819 register that contains the processor status. For example,
6820 you could print the program counter in hex with
6821
6822 @smallexample
6823 p/x $pc
6824 @end smallexample
6825
6826 @noindent
6827 or print the instruction to be executed next with
6828
6829 @smallexample
6830 x/i $pc
6831 @end smallexample
6832
6833 @noindent
6834 or add four to the stack pointer@footnote{This is a way of removing
6835 one word from the stack, on machines where stacks grow downward in
6836 memory (most machines, nowadays). This assumes that the innermost
6837 stack frame is selected; setting @code{$sp} is not allowed when other
6838 stack frames are selected. To pop entire frames off the stack,
6839 regardless of machine architecture, use @code{return};
6840 see @ref{Returning, ,Returning from a Function}.} with
6841
6842 @smallexample
6843 set $sp += 4
6844 @end smallexample
6845
6846 Whenever possible, these four standard register names are available on
6847 your machine even though the machine has different canonical mnemonics,
6848 so long as there is no conflict. The @code{info registers} command
6849 shows the canonical names. For example, on the SPARC, @code{info
6850 registers} displays the processor status register as @code{$psr} but you
6851 can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
6852 is an alias for the @sc{eflags} register.
6853
6854 @value{GDBN} always considers the contents of an ordinary register as an
6855 integer when the register is examined in this way. Some machines have
6856 special registers which can hold nothing but floating point; these
6857 registers are considered to have floating point values. There is no way
6858 to refer to the contents of an ordinary register as floating point value
6859 (although you can @emph{print} it as a floating point value with
6860 @samp{print/f $@var{regname}}).
6861
6862 Some registers have distinct ``raw'' and ``virtual'' data formats. This
6863 means that the data format in which the register contents are saved by
6864 the operating system is not the same one that your program normally
6865 sees. For example, the registers of the 68881 floating point
6866 coprocessor are always saved in ``extended'' (raw) format, but all C
6867 programs expect to work with ``double'' (virtual) format. In such
6868 cases, @value{GDBN} normally works with the virtual format only (the format
6869 that makes sense for your program), but the @code{info registers} command
6870 prints the data in both formats.
6871
6872 @cindex SSE registers (x86)
6873 @cindex MMX registers (x86)
6874 Some machines have special registers whose contents can be interpreted
6875 in several different ways. For example, modern x86-based machines
6876 have SSE and MMX registers that can hold several values packed
6877 together in several different formats. @value{GDBN} refers to such
6878 registers in @code{struct} notation:
6879
6880 @smallexample
6881 (@value{GDBP}) print $xmm1
6882 $1 = @{
6883 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
6884 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
6885 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
6886 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
6887 v4_int32 = @{0, 20657912, 11, 13@},
6888 v2_int64 = @{88725056443645952, 55834574859@},
6889 uint128 = 0x0000000d0000000b013b36f800000000
6890 @}
6891 @end smallexample
6892
6893 @noindent
6894 To set values of such registers, you need to tell @value{GDBN} which
6895 view of the register you wish to change, as if you were assigning
6896 value to a @code{struct} member:
6897
6898 @smallexample
6899 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
6900 @end smallexample
6901
6902 Normally, register values are relative to the selected stack frame
6903 (@pxref{Selection, ,Selecting a Frame}). This means that you get the
6904 value that the register would contain if all stack frames farther in
6905 were exited and their saved registers restored. In order to see the
6906 true contents of hardware registers, you must select the innermost
6907 frame (with @samp{frame 0}).
6908
6909 However, @value{GDBN} must deduce where registers are saved, from the machine
6910 code generated by your compiler. If some registers are not saved, or if
6911 @value{GDBN} is unable to locate the saved registers, the selected stack
6912 frame makes no difference.
6913
6914 @node Floating Point Hardware
6915 @section Floating Point Hardware
6916 @cindex floating point
6917
6918 Depending on the configuration, @value{GDBN} may be able to give
6919 you more information about the status of the floating point hardware.
6920
6921 @table @code
6922 @kindex info float
6923 @item info float
6924 Display hardware-dependent information about the floating
6925 point unit. The exact contents and layout vary depending on the
6926 floating point chip. Currently, @samp{info float} is supported on
6927 the ARM and x86 machines.
6928 @end table
6929
6930 @node Vector Unit
6931 @section Vector Unit
6932 @cindex vector unit
6933
6934 Depending on the configuration, @value{GDBN} may be able to give you
6935 more information about the status of the vector unit.
6936
6937 @table @code
6938 @kindex info vector
6939 @item info vector
6940 Display information about the vector unit. The exact contents and
6941 layout vary depending on the hardware.
6942 @end table
6943
6944 @node OS Information
6945 @section Operating System Auxiliary Information
6946 @cindex OS information
6947
6948 @value{GDBN} provides interfaces to useful OS facilities that can help
6949 you debug your program.
6950
6951 @cindex @code{ptrace} system call
6952 @cindex @code{struct user} contents
6953 When @value{GDBN} runs on a @dfn{Posix system} (such as GNU or Unix
6954 machines), it interfaces with the inferior via the @code{ptrace}
6955 system call. The operating system creates a special sata structure,
6956 called @code{struct user}, for this interface. You can use the
6957 command @code{info udot} to display the contents of this data
6958 structure.
6959
6960 @table @code
6961 @item info udot
6962 @kindex info udot
6963 Display the contents of the @code{struct user} maintained by the OS
6964 kernel for the program being debugged. @value{GDBN} displays the
6965 contents of @code{struct user} as a list of hex numbers, similar to
6966 the @code{examine} command.
6967 @end table
6968
6969 @cindex auxiliary vector
6970 @cindex vector, auxiliary
6971 Some operating systems supply an @dfn{auxiliary vector} to programs at
6972 startup. This is akin to the arguments and environment that you
6973 specify for a program, but contains a system-dependent variety of
6974 binary values that tell system libraries important details about the
6975 hardware, operating system, and process. Each value's purpose is
6976 identified by an integer tag; the meanings are well-known but system-specific.
6977 Depending on the configuration and operating system facilities,
6978 @value{GDBN} may be able to show you this information. For remote
6979 targets, this functionality may further depend on the remote stub's
6980 support of the @samp{qXfer:auxv:read} packet, see
6981 @ref{qXfer auxiliary vector read}.
6982
6983 @table @code
6984 @kindex info auxv
6985 @item info auxv
6986 Display the auxiliary vector of the inferior, which can be either a
6987 live process or a core dump file. @value{GDBN} prints each tag value
6988 numerically, and also shows names and text descriptions for recognized
6989 tags. Some values in the vector are numbers, some bit masks, and some
6990 pointers to strings or other data. @value{GDBN} displays each value in the
6991 most appropriate form for a recognized tag, and in hexadecimal for
6992 an unrecognized tag.
6993 @end table
6994
6995
6996 @node Memory Region Attributes
6997 @section Memory Region Attributes
6998 @cindex memory region attributes
6999
7000 @dfn{Memory region attributes} allow you to describe special handling
7001 required by regions of your target's memory. @value{GDBN} uses
7002 attributes to determine whether to allow certain types of memory
7003 accesses; whether to use specific width accesses; and whether to cache
7004 target memory. By default the description of memory regions is
7005 fetched from the target (if the current target supports this), but the
7006 user can override the fetched regions.
7007
7008 Defined memory regions can be individually enabled and disabled. When a
7009 memory region is disabled, @value{GDBN} uses the default attributes when
7010 accessing memory in that region. Similarly, if no memory regions have
7011 been defined, @value{GDBN} uses the default attributes when accessing
7012 all memory.
7013
7014 When a memory region is defined, it is given a number to identify it;
7015 to enable, disable, or remove a memory region, you specify that number.
7016
7017 @table @code
7018 @kindex mem
7019 @item mem @var{lower} @var{upper} @var{attributes}@dots{}
7020 Define a memory region bounded by @var{lower} and @var{upper} with
7021 attributes @var{attributes}@dots{}, and add it to the list of regions
7022 monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
7023 case: it is treated as the target's maximum memory address.
7024 (0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
7025
7026 @item mem auto
7027 Discard any user changes to the memory regions and use target-supplied
7028 regions, if available, or no regions if the target does not support.
7029
7030 @kindex delete mem
7031 @item delete mem @var{nums}@dots{}
7032 Remove memory regions @var{nums}@dots{} from the list of regions
7033 monitored by @value{GDBN}.
7034
7035 @kindex disable mem
7036 @item disable mem @var{nums}@dots{}
7037 Disable monitoring of memory regions @var{nums}@dots{}.
7038 A disabled memory region is not forgotten.
7039 It may be enabled again later.
7040
7041 @kindex enable mem
7042 @item enable mem @var{nums}@dots{}
7043 Enable monitoring of memory regions @var{nums}@dots{}.
7044
7045 @kindex info mem
7046 @item info mem
7047 Print a table of all defined memory regions, with the following columns
7048 for each region:
7049
7050 @table @emph
7051 @item Memory Region Number
7052 @item Enabled or Disabled.
7053 Enabled memory regions are marked with @samp{y}.
7054 Disabled memory regions are marked with @samp{n}.
7055
7056 @item Lo Address
7057 The address defining the inclusive lower bound of the memory region.
7058
7059 @item Hi Address
7060 The address defining the exclusive upper bound of the memory region.
7061
7062 @item Attributes
7063 The list of attributes set for this memory region.
7064 @end table
7065 @end table
7066
7067
7068 @subsection Attributes
7069
7070 @subsubsection Memory Access Mode
7071 The access mode attributes set whether @value{GDBN} may make read or
7072 write accesses to a memory region.
7073
7074 While these attributes prevent @value{GDBN} from performing invalid
7075 memory accesses, they do nothing to prevent the target system, I/O DMA,
7076 etc.@: from accessing memory.
7077
7078 @table @code
7079 @item ro
7080 Memory is read only.
7081 @item wo
7082 Memory is write only.
7083 @item rw
7084 Memory is read/write. This is the default.
7085 @end table
7086
7087 @subsubsection Memory Access Size
7088 The access size attribute tells @value{GDBN} to use specific sized
7089 accesses in the memory region. Often memory mapped device registers
7090 require specific sized accesses. If no access size attribute is
7091 specified, @value{GDBN} may use accesses of any size.
7092
7093 @table @code
7094 @item 8
7095 Use 8 bit memory accesses.
7096 @item 16
7097 Use 16 bit memory accesses.
7098 @item 32
7099 Use 32 bit memory accesses.
7100 @item 64
7101 Use 64 bit memory accesses.
7102 @end table
7103
7104 @c @subsubsection Hardware/Software Breakpoints
7105 @c The hardware/software breakpoint attributes set whether @value{GDBN}
7106 @c will use hardware or software breakpoints for the internal breakpoints
7107 @c used by the step, next, finish, until, etc. commands.
7108 @c
7109 @c @table @code
7110 @c @item hwbreak
7111 @c Always use hardware breakpoints
7112 @c @item swbreak (default)
7113 @c @end table
7114
7115 @subsubsection Data Cache
7116 The data cache attributes set whether @value{GDBN} will cache target
7117 memory. While this generally improves performance by reducing debug
7118 protocol overhead, it can lead to incorrect results because @value{GDBN}
7119 does not know about volatile variables or memory mapped device
7120 registers.
7121
7122 @table @code
7123 @item cache
7124 Enable @value{GDBN} to cache target memory.
7125 @item nocache
7126 Disable @value{GDBN} from caching target memory. This is the default.
7127 @end table
7128
7129 @subsection Memory Access Checking
7130 @value{GDBN} can be instructed to refuse accesses to memory that is
7131 not explicitly described. This can be useful if accessing such
7132 regions has undesired effects for a specific target, or to provide
7133 better error checking. The following commands control this behaviour.
7134
7135 @table @code
7136 @kindex set mem inaccessible-by-default
7137 @item set mem inaccessible-by-default [on|off]
7138 If @code{on} is specified, make @value{GDBN} treat memory not
7139 explicitly described by the memory ranges as non-existent and refuse accesses
7140 to such memory. The checks are only performed if there's at least one
7141 memory range defined. If @code{off} is specified, make @value{GDBN}
7142 treat the memory not explicitly described by the memory ranges as RAM.
7143 The default value is @code{on}.
7144 @kindex show mem inaccessible-by-default
7145 @item show mem inaccessible-by-default
7146 Show the current handling of accesses to unknown memory.
7147 @end table
7148
7149
7150 @c @subsubsection Memory Write Verification
7151 @c The memory write verification attributes set whether @value{GDBN}
7152 @c will re-reads data after each write to verify the write was successful.
7153 @c
7154 @c @table @code
7155 @c @item verify
7156 @c @item noverify (default)
7157 @c @end table
7158
7159 @node Dump/Restore Files
7160 @section Copy Between Memory and a File
7161 @cindex dump/restore files
7162 @cindex append data to a file
7163 @cindex dump data to a file
7164 @cindex restore data from a file
7165
7166 You can use the commands @code{dump}, @code{append}, and
7167 @code{restore} to copy data between target memory and a file. The
7168 @code{dump} and @code{append} commands write data to a file, and the
7169 @code{restore} command reads data from a file back into the inferior's
7170 memory. Files may be in binary, Motorola S-record, Intel hex, or
7171 Tektronix Hex format; however, @value{GDBN} can only append to binary
7172 files.
7173
7174 @table @code
7175
7176 @kindex dump
7177 @item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
7178 @itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
7179 Dump the contents of memory from @var{start_addr} to @var{end_addr},
7180 or the value of @var{expr}, to @var{filename} in the given format.
7181
7182 The @var{format} parameter may be any one of:
7183 @table @code
7184 @item binary
7185 Raw binary form.
7186 @item ihex
7187 Intel hex format.
7188 @item srec
7189 Motorola S-record format.
7190 @item tekhex
7191 Tektronix Hex format.
7192 @end table
7193
7194 @value{GDBN} uses the same definitions of these formats as the
7195 @sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
7196 @var{format} is omitted, @value{GDBN} dumps the data in raw binary
7197 form.
7198
7199 @kindex append
7200 @item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
7201 @itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
7202 Append the contents of memory from @var{start_addr} to @var{end_addr},
7203 or the value of @var{expr}, to the file @var{filename}, in raw binary form.
7204 (@value{GDBN} can only append data to files in raw binary form.)
7205
7206 @kindex restore
7207 @item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
7208 Restore the contents of file @var{filename} into memory. The
7209 @code{restore} command can automatically recognize any known @sc{bfd}
7210 file format, except for raw binary. To restore a raw binary file you
7211 must specify the optional keyword @code{binary} after the filename.
7212
7213 If @var{bias} is non-zero, its value will be added to the addresses
7214 contained in the file. Binary files always start at address zero, so
7215 they will be restored at address @var{bias}. Other bfd files have
7216 a built-in location; they will be restored at offset @var{bias}
7217 from that location.
7218
7219 If @var{start} and/or @var{end} are non-zero, then only data between
7220 file offset @var{start} and file offset @var{end} will be restored.
7221 These offsets are relative to the addresses in the file, before
7222 the @var{bias} argument is applied.
7223
7224 @end table
7225
7226 @node Core File Generation
7227 @section How to Produce a Core File from Your Program
7228 @cindex dump core from inferior
7229
7230 A @dfn{core file} or @dfn{core dump} is a file that records the memory
7231 image of a running process and its process status (register values
7232 etc.). Its primary use is post-mortem debugging of a program that
7233 crashed while it ran outside a debugger. A program that crashes
7234 automatically produces a core file, unless this feature is disabled by
7235 the user. @xref{Files}, for information on invoking @value{GDBN} in
7236 the post-mortem debugging mode.
7237
7238 Occasionally, you may wish to produce a core file of the program you
7239 are debugging in order to preserve a snapshot of its state.
7240 @value{GDBN} has a special command for that.
7241
7242 @table @code
7243 @kindex gcore
7244 @kindex generate-core-file
7245 @item generate-core-file [@var{file}]
7246 @itemx gcore [@var{file}]
7247 Produce a core dump of the inferior process. The optional argument
7248 @var{file} specifies the file name where to put the core dump. If not
7249 specified, the file name defaults to @file{core.@var{pid}}, where
7250 @var{pid} is the inferior process ID.
7251
7252 Note that this command is implemented only for some systems (as of
7253 this writing, @sc{gnu}/Linux, FreeBSD, Solaris, Unixware, and S390).
7254 @end table
7255
7256 @node Character Sets
7257 @section Character Sets
7258 @cindex character sets
7259 @cindex charset
7260 @cindex translating between character sets
7261 @cindex host character set
7262 @cindex target character set
7263
7264 If the program you are debugging uses a different character set to
7265 represent characters and strings than the one @value{GDBN} uses itself,
7266 @value{GDBN} can automatically translate between the character sets for
7267 you. The character set @value{GDBN} uses we call the @dfn{host
7268 character set}; the one the inferior program uses we call the
7269 @dfn{target character set}.
7270
7271 For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
7272 uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
7273 remote protocol (@pxref{Remote Debugging}) to debug a program
7274 running on an IBM mainframe, which uses the @sc{ebcdic} character set,
7275 then the host character set is Latin-1, and the target character set is
7276 @sc{ebcdic}. If you give @value{GDBN} the command @code{set
7277 target-charset EBCDIC-US}, then @value{GDBN} translates between
7278 @sc{ebcdic} and Latin 1 as you print character or string values, or use
7279 character and string literals in expressions.
7280
7281 @value{GDBN} has no way to automatically recognize which character set
7282 the inferior program uses; you must tell it, using the @code{set
7283 target-charset} command, described below.
7284
7285 Here are the commands for controlling @value{GDBN}'s character set
7286 support:
7287
7288 @table @code
7289 @item set target-charset @var{charset}
7290 @kindex set target-charset
7291 Set the current target character set to @var{charset}. We list the
7292 character set names @value{GDBN} recognizes below, but if you type
7293 @code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
7294 list the target character sets it supports.
7295 @end table
7296
7297 @table @code
7298 @item set host-charset @var{charset}
7299 @kindex set host-charset
7300 Set the current host character set to @var{charset}.
7301
7302 By default, @value{GDBN} uses a host character set appropriate to the
7303 system it is running on; you can override that default using the
7304 @code{set host-charset} command.
7305
7306 @value{GDBN} can only use certain character sets as its host character
7307 set. We list the character set names @value{GDBN} recognizes below, and
7308 indicate which can be host character sets, but if you type
7309 @code{set target-charset} followed by @key{TAB}@key{TAB}, @value{GDBN} will
7310 list the host character sets it supports.
7311
7312 @item set charset @var{charset}
7313 @kindex set charset
7314 Set the current host and target character sets to @var{charset}. As
7315 above, if you type @code{set charset} followed by @key{TAB}@key{TAB},
7316 @value{GDBN} will list the name of the character sets that can be used
7317 for both host and target.
7318
7319
7320 @item show charset
7321 @kindex show charset
7322 Show the names of the current host and target charsets.
7323
7324 @itemx show host-charset
7325 @kindex show host-charset
7326 Show the name of the current host charset.
7327
7328 @itemx show target-charset
7329 @kindex show target-charset
7330 Show the name of the current target charset.
7331
7332 @end table
7333
7334 @value{GDBN} currently includes support for the following character
7335 sets:
7336
7337 @table @code
7338
7339 @item ASCII
7340 @cindex ASCII character set
7341 Seven-bit U.S. @sc{ascii}. @value{GDBN} can use this as its host
7342 character set.
7343
7344 @item ISO-8859-1
7345 @cindex ISO 8859-1 character set
7346 @cindex ISO Latin 1 character set
7347 The ISO Latin 1 character set. This extends @sc{ascii} with accented
7348 characters needed for French, German, and Spanish. @value{GDBN} can use
7349 this as its host character set.
7350
7351 @item EBCDIC-US
7352 @itemx IBM1047
7353 @cindex EBCDIC character set
7354 @cindex IBM1047 character set
7355 Variants of the @sc{ebcdic} character set, used on some of IBM's
7356 mainframe operating systems. (@sc{gnu}/Linux on the S/390 uses U.S. @sc{ascii}.)
7357 @value{GDBN} cannot use these as its host character set.
7358
7359 @end table
7360
7361 Note that these are all single-byte character sets. More work inside
7362 @value{GDBN} is needed to support multi-byte or variable-width character
7363 encodings, like the UTF-8 and UCS-2 encodings of Unicode.
7364
7365 Here is an example of @value{GDBN}'s character set support in action.
7366 Assume that the following source code has been placed in the file
7367 @file{charset-test.c}:
7368
7369 @smallexample
7370 #include <stdio.h>
7371
7372 char ascii_hello[]
7373 = @{72, 101, 108, 108, 111, 44, 32, 119,
7374 111, 114, 108, 100, 33, 10, 0@};
7375 char ibm1047_hello[]
7376 = @{200, 133, 147, 147, 150, 107, 64, 166,
7377 150, 153, 147, 132, 90, 37, 0@};
7378
7379 main ()
7380 @{
7381 printf ("Hello, world!\n");
7382 @}
7383 @end smallexample
7384
7385 In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
7386 containing the string @samp{Hello, world!} followed by a newline,
7387 encoded in the @sc{ascii} and @sc{ibm1047} character sets.
7388
7389 We compile the program, and invoke the debugger on it:
7390
7391 @smallexample
7392 $ gcc -g charset-test.c -o charset-test
7393 $ gdb -nw charset-test
7394 GNU gdb 2001-12-19-cvs
7395 Copyright 2001 Free Software Foundation, Inc.
7396 @dots{}
7397 (@value{GDBP})
7398 @end smallexample
7399
7400 We can use the @code{show charset} command to see what character sets
7401 @value{GDBN} is currently using to interpret and display characters and
7402 strings:
7403
7404 @smallexample
7405 (@value{GDBP}) show charset
7406 The current host and target character set is `ISO-8859-1'.
7407 (@value{GDBP})
7408 @end smallexample
7409
7410 For the sake of printing this manual, let's use @sc{ascii} as our
7411 initial character set:
7412 @smallexample
7413 (@value{GDBP}) set charset ASCII
7414 (@value{GDBP}) show charset
7415 The current host and target character set is `ASCII'.
7416 (@value{GDBP})
7417 @end smallexample
7418
7419 Let's assume that @sc{ascii} is indeed the correct character set for our
7420 host system --- in other words, let's assume that if @value{GDBN} prints
7421 characters using the @sc{ascii} character set, our terminal will display
7422 them properly. Since our current target character set is also
7423 @sc{ascii}, the contents of @code{ascii_hello} print legibly:
7424
7425 @smallexample
7426 (@value{GDBP}) print ascii_hello
7427 $1 = 0x401698 "Hello, world!\n"
7428 (@value{GDBP}) print ascii_hello[0]
7429 $2 = 72 'H'
7430 (@value{GDBP})
7431 @end smallexample
7432
7433 @value{GDBN} uses the target character set for character and string
7434 literals you use in expressions:
7435
7436 @smallexample
7437 (@value{GDBP}) print '+'
7438 $3 = 43 '+'
7439 (@value{GDBP})
7440 @end smallexample
7441
7442 The @sc{ascii} character set uses the number 43 to encode the @samp{+}
7443 character.
7444
7445 @value{GDBN} relies on the user to tell it which character set the
7446 target program uses. If we print @code{ibm1047_hello} while our target
7447 character set is still @sc{ascii}, we get jibberish:
7448
7449 @smallexample
7450 (@value{GDBP}) print ibm1047_hello
7451 $4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
7452 (@value{GDBP}) print ibm1047_hello[0]
7453 $5 = 200 '\310'
7454 (@value{GDBP})
7455 @end smallexample
7456
7457 If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
7458 @value{GDBN} tells us the character sets it supports:
7459
7460 @smallexample
7461 (@value{GDBP}) set target-charset
7462 ASCII EBCDIC-US IBM1047 ISO-8859-1
7463 (@value{GDBP}) set target-charset
7464 @end smallexample
7465
7466 We can select @sc{ibm1047} as our target character set, and examine the
7467 program's strings again. Now the @sc{ascii} string is wrong, but
7468 @value{GDBN} translates the contents of @code{ibm1047_hello} from the
7469 target character set, @sc{ibm1047}, to the host character set,
7470 @sc{ascii}, and they display correctly:
7471
7472 @smallexample
7473 (@value{GDBP}) set target-charset IBM1047
7474 (@value{GDBP}) show charset
7475 The current host character set is `ASCII'.
7476 The current target character set is `IBM1047'.
7477 (@value{GDBP}) print ascii_hello
7478 $6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
7479 (@value{GDBP}) print ascii_hello[0]
7480 $7 = 72 '\110'
7481 (@value{GDBP}) print ibm1047_hello
7482 $8 = 0x4016a8 "Hello, world!\n"
7483 (@value{GDBP}) print ibm1047_hello[0]
7484 $9 = 200 'H'
7485 (@value{GDBP})
7486 @end smallexample
7487
7488 As above, @value{GDBN} uses the target character set for character and
7489 string literals you use in expressions:
7490
7491 @smallexample
7492 (@value{GDBP}) print '+'
7493 $10 = 78 '+'
7494 (@value{GDBP})
7495 @end smallexample
7496
7497 The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
7498 character.
7499
7500 @node Caching Remote Data
7501 @section Caching Data of Remote Targets
7502 @cindex caching data of remote targets
7503
7504 @value{GDBN} can cache data exchanged between the debugger and a
7505 remote target (@pxref{Remote Debugging}). Such caching generally improves
7506 performance, because it reduces the overhead of the remote protocol by
7507 bundling memory reads and writes into large chunks. Unfortunately,
7508 @value{GDBN} does not currently know anything about volatile
7509 registers, and thus data caching will produce incorrect results when
7510 volatile registers are in use.
7511
7512 @table @code
7513 @kindex set remotecache
7514 @item set remotecache on
7515 @itemx set remotecache off
7516 Set caching state for remote targets. When @code{ON}, use data
7517 caching. By default, this option is @code{OFF}.
7518
7519 @kindex show remotecache
7520 @item show remotecache
7521 Show the current state of data caching for remote targets.
7522
7523 @kindex info dcache
7524 @item info dcache
7525 Print the information about the data cache performance. The
7526 information displayed includes: the dcache width and depth; and for
7527 each cache line, how many times it was referenced, and its data and
7528 state (dirty, bad, ok, etc.). This command is useful for debugging
7529 the data cache operation.
7530 @end table
7531
7532
7533 @node Macros
7534 @chapter C Preprocessor Macros
7535
7536 Some languages, such as C and C@t{++}, provide a way to define and invoke
7537 ``preprocessor macros'' which expand into strings of tokens.
7538 @value{GDBN} can evaluate expressions containing macro invocations, show
7539 the result of macro expansion, and show a macro's definition, including
7540 where it was defined.
7541
7542 You may need to compile your program specially to provide @value{GDBN}
7543 with information about preprocessor macros. Most compilers do not
7544 include macros in their debugging information, even when you compile
7545 with the @option{-g} flag. @xref{Compilation}.
7546
7547 A program may define a macro at one point, remove that definition later,
7548 and then provide a different definition after that. Thus, at different
7549 points in the program, a macro may have different definitions, or have
7550 no definition at all. If there is a current stack frame, @value{GDBN}
7551 uses the macros in scope at that frame's source code line. Otherwise,
7552 @value{GDBN} uses the macros in scope at the current listing location;
7553 see @ref{List}.
7554
7555 At the moment, @value{GDBN} does not support the @code{##}
7556 token-splicing operator, the @code{#} stringification operator, or
7557 variable-arity macros.
7558
7559 Whenever @value{GDBN} evaluates an expression, it always expands any
7560 macro invocations present in the expression. @value{GDBN} also provides
7561 the following commands for working with macros explicitly.
7562
7563 @table @code
7564
7565 @kindex macro expand
7566 @cindex macro expansion, showing the results of preprocessor
7567 @cindex preprocessor macro expansion, showing the results of
7568 @cindex expanding preprocessor macros
7569 @item macro expand @var{expression}
7570 @itemx macro exp @var{expression}
7571 Show the results of expanding all preprocessor macro invocations in
7572 @var{expression}. Since @value{GDBN} simply expands macros, but does
7573 not parse the result, @var{expression} need not be a valid expression;
7574 it can be any string of tokens.
7575
7576 @kindex macro exp1
7577 @item macro expand-once @var{expression}
7578 @itemx macro exp1 @var{expression}
7579 @cindex expand macro once
7580 @i{(This command is not yet implemented.)} Show the results of
7581 expanding those preprocessor macro invocations that appear explicitly in
7582 @var{expression}. Macro invocations appearing in that expansion are
7583 left unchanged. This command allows you to see the effect of a
7584 particular macro more clearly, without being confused by further
7585 expansions. Since @value{GDBN} simply expands macros, but does not
7586 parse the result, @var{expression} need not be a valid expression; it
7587 can be any string of tokens.
7588
7589 @kindex info macro
7590 @cindex macro definition, showing
7591 @cindex definition, showing a macro's
7592 @item info macro @var{macro}
7593 Show the definition of the macro named @var{macro}, and describe the
7594 source location where that definition was established.
7595
7596 @kindex macro define
7597 @cindex user-defined macros
7598 @cindex defining macros interactively
7599 @cindex macros, user-defined
7600 @item macro define @var{macro} @var{replacement-list}
7601 @itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
7602 @i{(This command is not yet implemented.)} Introduce a definition for a
7603 preprocessor macro named @var{macro}, invocations of which are replaced
7604 by the tokens given in @var{replacement-list}. The first form of this
7605 command defines an ``object-like'' macro, which takes no arguments; the
7606 second form defines a ``function-like'' macro, which takes the arguments
7607 given in @var{arglist}.
7608
7609 A definition introduced by this command is in scope in every expression
7610 evaluated in @value{GDBN}, until it is removed with the @command{macro
7611 undef} command, described below. The definition overrides all
7612 definitions for @var{macro} present in the program being debugged, as
7613 well as any previous user-supplied definition.
7614
7615 @kindex macro undef
7616 @item macro undef @var{macro}
7617 @i{(This command is not yet implemented.)} Remove any user-supplied
7618 definition for the macro named @var{macro}. This command only affects
7619 definitions provided with the @command{macro define} command, described
7620 above; it cannot remove definitions present in the program being
7621 debugged.
7622
7623 @kindex macro list
7624 @item macro list
7625 @i{(This command is not yet implemented.)} List all the macros
7626 defined using the @code{macro define} command.
7627 @end table
7628
7629 @cindex macros, example of debugging with
7630 Here is a transcript showing the above commands in action. First, we
7631 show our source files:
7632
7633 @smallexample
7634 $ cat sample.c
7635 #include <stdio.h>
7636 #include "sample.h"
7637
7638 #define M 42
7639 #define ADD(x) (M + x)
7640
7641 main ()
7642 @{
7643 #define N 28
7644 printf ("Hello, world!\n");
7645 #undef N
7646 printf ("We're so creative.\n");
7647 #define N 1729
7648 printf ("Goodbye, world!\n");
7649 @}
7650 $ cat sample.h
7651 #define Q <
7652 $
7653 @end smallexample
7654
7655 Now, we compile the program using the @sc{gnu} C compiler, @value{NGCC}.
7656 We pass the @option{-gdwarf-2} and @option{-g3} flags to ensure the
7657 compiler includes information about preprocessor macros in the debugging
7658 information.
7659
7660 @smallexample
7661 $ gcc -gdwarf-2 -g3 sample.c -o sample
7662 $
7663 @end smallexample
7664
7665 Now, we start @value{GDBN} on our sample program:
7666
7667 @smallexample
7668 $ gdb -nw sample
7669 GNU gdb 2002-05-06-cvs
7670 Copyright 2002 Free Software Foundation, Inc.
7671 GDB is free software, @dots{}
7672 (@value{GDBP})
7673 @end smallexample
7674
7675 We can expand macros and examine their definitions, even when the
7676 program is not running. @value{GDBN} uses the current listing position
7677 to decide which macro definitions are in scope:
7678
7679 @smallexample
7680 (@value{GDBP}) list main
7681 3
7682 4 #define M 42
7683 5 #define ADD(x) (M + x)
7684 6
7685 7 main ()
7686 8 @{
7687 9 #define N 28
7688 10 printf ("Hello, world!\n");
7689 11 #undef N
7690 12 printf ("We're so creative.\n");
7691 (@value{GDBP}) info macro ADD
7692 Defined at /home/jimb/gdb/macros/play/sample.c:5
7693 #define ADD(x) (M + x)
7694 (@value{GDBP}) info macro Q
7695 Defined at /home/jimb/gdb/macros/play/sample.h:1
7696 included at /home/jimb/gdb/macros/play/sample.c:2
7697 #define Q <
7698 (@value{GDBP}) macro expand ADD(1)
7699 expands to: (42 + 1)
7700 (@value{GDBP}) macro expand-once ADD(1)
7701 expands to: once (M + 1)
7702 (@value{GDBP})
7703 @end smallexample
7704
7705 In the example above, note that @command{macro expand-once} expands only
7706 the macro invocation explicit in the original text --- the invocation of
7707 @code{ADD} --- but does not expand the invocation of the macro @code{M},
7708 which was introduced by @code{ADD}.
7709
7710 Once the program is running, @value{GDBN} uses the macro definitions in
7711 force at the source line of the current stack frame:
7712
7713 @smallexample
7714 (@value{GDBP}) break main
7715 Breakpoint 1 at 0x8048370: file sample.c, line 10.
7716 (@value{GDBP}) run
7717 Starting program: /home/jimb/gdb/macros/play/sample
7718
7719 Breakpoint 1, main () at sample.c:10
7720 10 printf ("Hello, world!\n");
7721 (@value{GDBP})
7722 @end smallexample
7723
7724 At line 10, the definition of the macro @code{N} at line 9 is in force:
7725
7726 @smallexample
7727 (@value{GDBP}) info macro N
7728 Defined at /home/jimb/gdb/macros/play/sample.c:9
7729 #define N 28
7730 (@value{GDBP}) macro expand N Q M
7731 expands to: 28 < 42
7732 (@value{GDBP}) print N Q M
7733 $1 = 1
7734 (@value{GDBP})
7735 @end smallexample
7736
7737 As we step over directives that remove @code{N}'s definition, and then
7738 give it a new definition, @value{GDBN} finds the definition (or lack
7739 thereof) in force at each point:
7740
7741 @smallexample
7742 (@value{GDBP}) next
7743 Hello, world!
7744 12 printf ("We're so creative.\n");
7745 (@value{GDBP}) info macro N
7746 The symbol `N' has no definition as a C/C++ preprocessor macro
7747 at /home/jimb/gdb/macros/play/sample.c:12
7748 (@value{GDBP}) next
7749 We're so creative.
7750 14 printf ("Goodbye, world!\n");
7751 (@value{GDBP}) info macro N
7752 Defined at /home/jimb/gdb/macros/play/sample.c:13
7753 #define N 1729
7754 (@value{GDBP}) macro expand N Q M
7755 expands to: 1729 < 42
7756 (@value{GDBP}) print N Q M
7757 $2 = 0
7758 (@value{GDBP})
7759 @end smallexample
7760
7761
7762 @node Tracepoints
7763 @chapter Tracepoints
7764 @c This chapter is based on the documentation written by Michael
7765 @c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
7766
7767 @cindex tracepoints
7768 In some applications, it is not feasible for the debugger to interrupt
7769 the program's execution long enough for the developer to learn
7770 anything helpful about its behavior. If the program's correctness
7771 depends on its real-time behavior, delays introduced by a debugger
7772 might cause the program to change its behavior drastically, or perhaps
7773 fail, even when the code itself is correct. It is useful to be able
7774 to observe the program's behavior without interrupting it.
7775
7776 Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
7777 specify locations in the program, called @dfn{tracepoints}, and
7778 arbitrary expressions to evaluate when those tracepoints are reached.
7779 Later, using the @code{tfind} command, you can examine the values
7780 those expressions had when the program hit the tracepoints. The
7781 expressions may also denote objects in memory---structures or arrays,
7782 for example---whose values @value{GDBN} should record; while visiting
7783 a particular tracepoint, you may inspect those objects as if they were
7784 in memory at that moment. However, because @value{GDBN} records these
7785 values without interacting with you, it can do so quickly and
7786 unobtrusively, hopefully not disturbing the program's behavior.
7787
7788 The tracepoint facility is currently available only for remote
7789 targets. @xref{Targets}. In addition, your remote target must know
7790 how to collect trace data. This functionality is implemented in the
7791 remote stub; however, none of the stubs distributed with @value{GDBN}
7792 support tracepoints as of this writing. The format of the remote
7793 packets used to implement tracepoints are described in @ref{Tracepoint
7794 Packets}.
7795
7796 This chapter describes the tracepoint commands and features.
7797
7798 @menu
7799 * Set Tracepoints::
7800 * Analyze Collected Data::
7801 * Tracepoint Variables::
7802 @end menu
7803
7804 @node Set Tracepoints
7805 @section Commands to Set Tracepoints
7806
7807 Before running such a @dfn{trace experiment}, an arbitrary number of
7808 tracepoints can be set. Like a breakpoint (@pxref{Set Breaks}), a
7809 tracepoint has a number assigned to it by @value{GDBN}. Like with
7810 breakpoints, tracepoint numbers are successive integers starting from
7811 one. Many of the commands associated with tracepoints take the
7812 tracepoint number as their argument, to identify which tracepoint to
7813 work on.
7814
7815 For each tracepoint, you can specify, in advance, some arbitrary set
7816 of data that you want the target to collect in the trace buffer when
7817 it hits that tracepoint. The collected data can include registers,
7818 local variables, or global data. Later, you can use @value{GDBN}
7819 commands to examine the values these data had at the time the
7820 tracepoint was hit.
7821
7822 This section describes commands to set tracepoints and associated
7823 conditions and actions.
7824
7825 @menu
7826 * Create and Delete Tracepoints::
7827 * Enable and Disable Tracepoints::
7828 * Tracepoint Passcounts::
7829 * Tracepoint Actions::
7830 * Listing Tracepoints::
7831 * Starting and Stopping Trace Experiments::
7832 @end menu
7833
7834 @node Create and Delete Tracepoints
7835 @subsection Create and Delete Tracepoints
7836
7837 @table @code
7838 @cindex set tracepoint
7839 @kindex trace
7840 @item trace
7841 The @code{trace} command is very similar to the @code{break} command.
7842 Its argument can be a source line, a function name, or an address in
7843 the target program. @xref{Set Breaks}. The @code{trace} command
7844 defines a tracepoint, which is a point in the target program where the
7845 debugger will briefly stop, collect some data, and then allow the
7846 program to continue. Setting a tracepoint or changing its commands
7847 doesn't take effect until the next @code{tstart} command; thus, you
7848 cannot change the tracepoint attributes once a trace experiment is
7849 running.
7850
7851 Here are some examples of using the @code{trace} command:
7852
7853 @smallexample
7854 (@value{GDBP}) @b{trace foo.c:121} // a source file and line number
7855
7856 (@value{GDBP}) @b{trace +2} // 2 lines forward
7857
7858 (@value{GDBP}) @b{trace my_function} // first source line of function
7859
7860 (@value{GDBP}) @b{trace *my_function} // EXACT start address of function
7861
7862 (@value{GDBP}) @b{trace *0x2117c4} // an address
7863 @end smallexample
7864
7865 @noindent
7866 You can abbreviate @code{trace} as @code{tr}.
7867
7868 @vindex $tpnum
7869 @cindex last tracepoint number
7870 @cindex recent tracepoint number
7871 @cindex tracepoint number
7872 The convenience variable @code{$tpnum} records the tracepoint number
7873 of the most recently set tracepoint.
7874
7875 @kindex delete tracepoint
7876 @cindex tracepoint deletion
7877 @item delete tracepoint @r{[}@var{num}@r{]}
7878 Permanently delete one or more tracepoints. With no argument, the
7879 default is to delete all tracepoints.
7880
7881 Examples:
7882
7883 @smallexample
7884 (@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
7885
7886 (@value{GDBP}) @b{delete trace} // remove all tracepoints
7887 @end smallexample
7888
7889 @noindent
7890 You can abbreviate this command as @code{del tr}.
7891 @end table
7892
7893 @node Enable and Disable Tracepoints
7894 @subsection Enable and Disable Tracepoints
7895
7896 @table @code
7897 @kindex disable tracepoint
7898 @item disable tracepoint @r{[}@var{num}@r{]}
7899 Disable tracepoint @var{num}, or all tracepoints if no argument
7900 @var{num} is given. A disabled tracepoint will have no effect during
7901 the next trace experiment, but it is not forgotten. You can re-enable
7902 a disabled tracepoint using the @code{enable tracepoint} command.
7903
7904 @kindex enable tracepoint
7905 @item enable tracepoint @r{[}@var{num}@r{]}
7906 Enable tracepoint @var{num}, or all tracepoints. The enabled
7907 tracepoints will become effective the next time a trace experiment is
7908 run.
7909 @end table
7910
7911 @node Tracepoint Passcounts
7912 @subsection Tracepoint Passcounts
7913
7914 @table @code
7915 @kindex passcount
7916 @cindex tracepoint pass count
7917 @item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
7918 Set the @dfn{passcount} of a tracepoint. The passcount is a way to
7919 automatically stop a trace experiment. If a tracepoint's passcount is
7920 @var{n}, then the trace experiment will be automatically stopped on
7921 the @var{n}'th time that tracepoint is hit. If the tracepoint number
7922 @var{num} is not specified, the @code{passcount} command sets the
7923 passcount of the most recently defined tracepoint. If no passcount is
7924 given, the trace experiment will run until stopped explicitly by the
7925 user.
7926
7927 Examples:
7928
7929 @smallexample
7930 (@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
7931 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
7932
7933 (@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
7934 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
7935 (@value{GDBP}) @b{trace foo}
7936 (@value{GDBP}) @b{pass 3}
7937 (@value{GDBP}) @b{trace bar}
7938 (@value{GDBP}) @b{pass 2}
7939 (@value{GDBP}) @b{trace baz}
7940 (@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
7941 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
7942 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
7943 @exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
7944 @end smallexample
7945 @end table
7946
7947 @node Tracepoint Actions
7948 @subsection Tracepoint Action Lists
7949
7950 @table @code
7951 @kindex actions
7952 @cindex tracepoint actions
7953 @item actions @r{[}@var{num}@r{]}
7954 This command will prompt for a list of actions to be taken when the
7955 tracepoint is hit. If the tracepoint number @var{num} is not
7956 specified, this command sets the actions for the one that was most
7957 recently defined (so that you can define a tracepoint and then say
7958 @code{actions} without bothering about its number). You specify the
7959 actions themselves on the following lines, one action at a time, and
7960 terminate the actions list with a line containing just @code{end}. So
7961 far, the only defined actions are @code{collect} and
7962 @code{while-stepping}.
7963
7964 @cindex remove actions from a tracepoint
7965 To remove all actions from a tracepoint, type @samp{actions @var{num}}
7966 and follow it immediately with @samp{end}.
7967
7968 @smallexample
7969 (@value{GDBP}) @b{collect @var{data}} // collect some data
7970
7971 (@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
7972
7973 (@value{GDBP}) @b{end} // signals the end of actions.
7974 @end smallexample
7975
7976 In the following example, the action list begins with @code{collect}
7977 commands indicating the things to be collected when the tracepoint is
7978 hit. Then, in order to single-step and collect additional data
7979 following the tracepoint, a @code{while-stepping} command is used,
7980 followed by the list of things to be collected while stepping. The
7981 @code{while-stepping} command is terminated by its own separate
7982 @code{end} command. Lastly, the action list is terminated by an
7983 @code{end} command.
7984
7985 @smallexample
7986 (@value{GDBP}) @b{trace foo}
7987 (@value{GDBP}) @b{actions}
7988 Enter actions for tracepoint 1, one per line:
7989 > collect bar,baz
7990 > collect $regs
7991 > while-stepping 12
7992 > collect $fp, $sp
7993 > end
7994 end
7995 @end smallexample
7996
7997 @kindex collect @r{(tracepoints)}
7998 @item collect @var{expr1}, @var{expr2}, @dots{}
7999 Collect values of the given expressions when the tracepoint is hit.
8000 This command accepts a comma-separated list of any valid expressions.
8001 In addition to global, static, or local variables, the following
8002 special arguments are supported:
8003
8004 @table @code
8005 @item $regs
8006 collect all registers
8007
8008 @item $args
8009 collect all function arguments
8010
8011 @item $locals
8012 collect all local variables.
8013 @end table
8014
8015 You can give several consecutive @code{collect} commands, each one
8016 with a single argument, or one @code{collect} command with several
8017 arguments separated by commas: the effect is the same.
8018
8019 The command @code{info scope} (@pxref{Symbols, info scope}) is
8020 particularly useful for figuring out what data to collect.
8021
8022 @kindex while-stepping @r{(tracepoints)}
8023 @item while-stepping @var{n}
8024 Perform @var{n} single-step traces after the tracepoint, collecting
8025 new data at each step. The @code{while-stepping} command is
8026 followed by the list of what to collect while stepping (followed by
8027 its own @code{end} command):
8028
8029 @smallexample
8030 > while-stepping 12
8031 > collect $regs, myglobal
8032 > end
8033 >
8034 @end smallexample
8035
8036 @noindent
8037 You may abbreviate @code{while-stepping} as @code{ws} or
8038 @code{stepping}.
8039 @end table
8040
8041 @node Listing Tracepoints
8042 @subsection Listing Tracepoints
8043
8044 @table @code
8045 @kindex info tracepoints
8046 @kindex info tp
8047 @cindex information about tracepoints
8048 @item info tracepoints @r{[}@var{num}@r{]}
8049 Display information about the tracepoint @var{num}. If you don't specify
8050 a tracepoint number, displays information about all the tracepoints
8051 defined so far. For each tracepoint, the following information is
8052 shown:
8053
8054 @itemize @bullet
8055 @item
8056 its number
8057 @item
8058 whether it is enabled or disabled
8059 @item
8060 its address
8061 @item
8062 its passcount as given by the @code{passcount @var{n}} command
8063 @item
8064 its step count as given by the @code{while-stepping @var{n}} command
8065 @item
8066 where in the source files is the tracepoint set
8067 @item
8068 its action list as given by the @code{actions} command
8069 @end itemize
8070
8071 @smallexample
8072 (@value{GDBP}) @b{info trace}
8073 Num Enb Address PassC StepC What
8074 1 y 0x002117c4 0 0 <gdb_asm>
8075 2 y 0x0020dc64 0 0 in g_test at g_test.c:1375
8076 3 y 0x0020b1f4 0 0 in get_data at ../foo.c:41
8077 (@value{GDBP})
8078 @end smallexample
8079
8080 @noindent
8081 This command can be abbreviated @code{info tp}.
8082 @end table
8083
8084 @node Starting and Stopping Trace Experiments
8085 @subsection Starting and Stopping Trace Experiments
8086
8087 @table @code
8088 @kindex tstart
8089 @cindex start a new trace experiment
8090 @cindex collected data discarded
8091 @item tstart
8092 This command takes no arguments. It starts the trace experiment, and
8093 begins collecting data. This has the side effect of discarding all
8094 the data collected in the trace buffer during the previous trace
8095 experiment.
8096
8097 @kindex tstop
8098 @cindex stop a running trace experiment
8099 @item tstop
8100 This command takes no arguments. It ends the trace experiment, and
8101 stops collecting data.
8102
8103 @strong{Note}: a trace experiment and data collection may stop
8104 automatically if any tracepoint's passcount is reached
8105 (@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
8106
8107 @kindex tstatus
8108 @cindex status of trace data collection
8109 @cindex trace experiment, status of
8110 @item tstatus
8111 This command displays the status of the current trace data
8112 collection.
8113 @end table
8114
8115 Here is an example of the commands we described so far:
8116
8117 @smallexample
8118 (@value{GDBP}) @b{trace gdb_c_test}
8119 (@value{GDBP}) @b{actions}
8120 Enter actions for tracepoint #1, one per line.
8121 > collect $regs,$locals,$args
8122 > while-stepping 11
8123 > collect $regs
8124 > end
8125 > end
8126 (@value{GDBP}) @b{tstart}
8127 [time passes @dots{}]
8128 (@value{GDBP}) @b{tstop}
8129 @end smallexample
8130
8131
8132 @node Analyze Collected Data
8133 @section Using the Collected Data
8134
8135 After the tracepoint experiment ends, you use @value{GDBN} commands
8136 for examining the trace data. The basic idea is that each tracepoint
8137 collects a trace @dfn{snapshot} every time it is hit and another
8138 snapshot every time it single-steps. All these snapshots are
8139 consecutively numbered from zero and go into a buffer, and you can
8140 examine them later. The way you examine them is to @dfn{focus} on a
8141 specific trace snapshot. When the remote stub is focused on a trace
8142 snapshot, it will respond to all @value{GDBN} requests for memory and
8143 registers by reading from the buffer which belongs to that snapshot,
8144 rather than from @emph{real} memory or registers of the program being
8145 debugged. This means that @strong{all} @value{GDBN} commands
8146 (@code{print}, @code{info registers}, @code{backtrace}, etc.) will
8147 behave as if we were currently debugging the program state as it was
8148 when the tracepoint occurred. Any requests for data that are not in
8149 the buffer will fail.
8150
8151 @menu
8152 * tfind:: How to select a trace snapshot
8153 * tdump:: How to display all data for a snapshot
8154 * save-tracepoints:: How to save tracepoints for a future run
8155 @end menu
8156
8157 @node tfind
8158 @subsection @code{tfind @var{n}}
8159
8160 @kindex tfind
8161 @cindex select trace snapshot
8162 @cindex find trace snapshot
8163 The basic command for selecting a trace snapshot from the buffer is
8164 @code{tfind @var{n}}, which finds trace snapshot number @var{n},
8165 counting from zero. If no argument @var{n} is given, the next
8166 snapshot is selected.
8167
8168 Here are the various forms of using the @code{tfind} command.
8169
8170 @table @code
8171 @item tfind start
8172 Find the first snapshot in the buffer. This is a synonym for
8173 @code{tfind 0} (since 0 is the number of the first snapshot).
8174
8175 @item tfind none
8176 Stop debugging trace snapshots, resume @emph{live} debugging.
8177
8178 @item tfind end
8179 Same as @samp{tfind none}.
8180
8181 @item tfind
8182 No argument means find the next trace snapshot.
8183
8184 @item tfind -
8185 Find the previous trace snapshot before the current one. This permits
8186 retracing earlier steps.
8187
8188 @item tfind tracepoint @var{num}
8189 Find the next snapshot associated with tracepoint @var{num}. Search
8190 proceeds forward from the last examined trace snapshot. If no
8191 argument @var{num} is given, it means find the next snapshot collected
8192 for the same tracepoint as the current snapshot.
8193
8194 @item tfind pc @var{addr}
8195 Find the next snapshot associated with the value @var{addr} of the
8196 program counter. Search proceeds forward from the last examined trace
8197 snapshot. If no argument @var{addr} is given, it means find the next
8198 snapshot with the same value of PC as the current snapshot.
8199
8200 @item tfind outside @var{addr1}, @var{addr2}
8201 Find the next snapshot whose PC is outside the given range of
8202 addresses.
8203
8204 @item tfind range @var{addr1}, @var{addr2}
8205 Find the next snapshot whose PC is between @var{addr1} and
8206 @var{addr2}. @c FIXME: Is the range inclusive or exclusive?
8207
8208 @item tfind line @r{[}@var{file}:@r{]}@var{n}
8209 Find the next snapshot associated with the source line @var{n}. If
8210 the optional argument @var{file} is given, refer to line @var{n} in
8211 that source file. Search proceeds forward from the last examined
8212 trace snapshot. If no argument @var{n} is given, it means find the
8213 next line other than the one currently being examined; thus saying
8214 @code{tfind line} repeatedly can appear to have the same effect as
8215 stepping from line to line in a @emph{live} debugging session.
8216 @end table
8217
8218 The default arguments for the @code{tfind} commands are specifically
8219 designed to make it easy to scan through the trace buffer. For
8220 instance, @code{tfind} with no argument selects the next trace
8221 snapshot, and @code{tfind -} with no argument selects the previous
8222 trace snapshot. So, by giving one @code{tfind} command, and then
8223 simply hitting @key{RET} repeatedly you can examine all the trace
8224 snapshots in order. Or, by saying @code{tfind -} and then hitting
8225 @key{RET} repeatedly you can examine the snapshots in reverse order.
8226 The @code{tfind line} command with no argument selects the snapshot
8227 for the next source line executed. The @code{tfind pc} command with
8228 no argument selects the next snapshot with the same program counter
8229 (PC) as the current frame. The @code{tfind tracepoint} command with
8230 no argument selects the next trace snapshot collected by the same
8231 tracepoint as the current one.
8232
8233 In addition to letting you scan through the trace buffer manually,
8234 these commands make it easy to construct @value{GDBN} scripts that
8235 scan through the trace buffer and print out whatever collected data
8236 you are interested in. Thus, if we want to examine the PC, FP, and SP
8237 registers from each trace frame in the buffer, we can say this:
8238
8239 @smallexample
8240 (@value{GDBP}) @b{tfind start}
8241 (@value{GDBP}) @b{while ($trace_frame != -1)}
8242 > printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
8243 $trace_frame, $pc, $sp, $fp
8244 > tfind
8245 > end
8246
8247 Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
8248 Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
8249 Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
8250 Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
8251 Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
8252 Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
8253 Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
8254 Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
8255 Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
8256 Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
8257 Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
8258 @end smallexample
8259
8260 Or, if we want to examine the variable @code{X} at each source line in
8261 the buffer:
8262
8263 @smallexample
8264 (@value{GDBP}) @b{tfind start}
8265 (@value{GDBP}) @b{while ($trace_frame != -1)}
8266 > printf "Frame %d, X == %d\n", $trace_frame, X
8267 > tfind line
8268 > end
8269
8270 Frame 0, X = 1
8271 Frame 7, X = 2
8272 Frame 13, X = 255
8273 @end smallexample
8274
8275 @node tdump
8276 @subsection @code{tdump}
8277 @kindex tdump
8278 @cindex dump all data collected at tracepoint
8279 @cindex tracepoint data, display
8280
8281 This command takes no arguments. It prints all the data collected at
8282 the current trace snapshot.
8283
8284 @smallexample
8285 (@value{GDBP}) @b{trace 444}
8286 (@value{GDBP}) @b{actions}
8287 Enter actions for tracepoint #2, one per line:
8288 > collect $regs, $locals, $args, gdb_long_test
8289 > end
8290
8291 (@value{GDBP}) @b{tstart}
8292
8293 (@value{GDBP}) @b{tfind line 444}
8294 #0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
8295 at gdb_test.c:444
8296 444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
8297
8298 (@value{GDBP}) @b{tdump}
8299 Data collected at tracepoint 2, trace frame 1:
8300 d0 0xc4aa0085 -995491707
8301 d1 0x18 24
8302 d2 0x80 128
8303 d3 0x33 51
8304 d4 0x71aea3d 119204413
8305 d5 0x22 34
8306 d6 0xe0 224
8307 d7 0x380035 3670069
8308 a0 0x19e24a 1696330
8309 a1 0x3000668 50333288
8310 a2 0x100 256
8311 a3 0x322000 3284992
8312 a4 0x3000698 50333336
8313 a5 0x1ad3cc 1758156
8314 fp 0x30bf3c 0x30bf3c
8315 sp 0x30bf34 0x30bf34
8316 ps 0x0 0
8317 pc 0x20b2c8 0x20b2c8
8318 fpcontrol 0x0 0
8319 fpstatus 0x0 0
8320 fpiaddr 0x0 0
8321 p = 0x20e5b4 "gdb-test"
8322 p1 = (void *) 0x11
8323 p2 = (void *) 0x22
8324 p3 = (void *) 0x33
8325 p4 = (void *) 0x44
8326 p5 = (void *) 0x55
8327 p6 = (void *) 0x66
8328 gdb_long_test = 17 '\021'
8329
8330 (@value{GDBP})
8331 @end smallexample
8332
8333 @node save-tracepoints
8334 @subsection @code{save-tracepoints @var{filename}}
8335 @kindex save-tracepoints
8336 @cindex save tracepoints for future sessions
8337
8338 This command saves all current tracepoint definitions together with
8339 their actions and passcounts, into a file @file{@var{filename}}
8340 suitable for use in a later debugging session. To read the saved
8341 tracepoint definitions, use the @code{source} command (@pxref{Command
8342 Files}).
8343
8344 @node Tracepoint Variables
8345 @section Convenience Variables for Tracepoints
8346 @cindex tracepoint variables
8347 @cindex convenience variables for tracepoints
8348
8349 @table @code
8350 @vindex $trace_frame
8351 @item (int) $trace_frame
8352 The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
8353 snapshot is selected.
8354
8355 @vindex $tracepoint
8356 @item (int) $tracepoint
8357 The tracepoint for the current trace snapshot.
8358
8359 @vindex $trace_line
8360 @item (int) $trace_line
8361 The line number for the current trace snapshot.
8362
8363 @vindex $trace_file
8364 @item (char []) $trace_file
8365 The source file for the current trace snapshot.
8366
8367 @vindex $trace_func
8368 @item (char []) $trace_func
8369 The name of the function containing @code{$tracepoint}.
8370 @end table
8371
8372 Note: @code{$trace_file} is not suitable for use in @code{printf},
8373 use @code{output} instead.
8374
8375 Here's a simple example of using these convenience variables for
8376 stepping through all the trace snapshots and printing some of their
8377 data.
8378
8379 @smallexample
8380 (@value{GDBP}) @b{tfind start}
8381
8382 (@value{GDBP}) @b{while $trace_frame != -1}
8383 > output $trace_file
8384 > printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
8385 > tfind
8386 > end
8387 @end smallexample
8388
8389 @node Overlays
8390 @chapter Debugging Programs That Use Overlays
8391 @cindex overlays
8392
8393 If your program is too large to fit completely in your target system's
8394 memory, you can sometimes use @dfn{overlays} to work around this
8395 problem. @value{GDBN} provides some support for debugging programs that
8396 use overlays.
8397
8398 @menu
8399 * How Overlays Work:: A general explanation of overlays.
8400 * Overlay Commands:: Managing overlays in @value{GDBN}.
8401 * Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
8402 mapped by asking the inferior.
8403 * Overlay Sample Program:: A sample program using overlays.
8404 @end menu
8405
8406 @node How Overlays Work
8407 @section How Overlays Work
8408 @cindex mapped overlays
8409 @cindex unmapped overlays
8410 @cindex load address, overlay's
8411 @cindex mapped address
8412 @cindex overlay area
8413
8414 Suppose you have a computer whose instruction address space is only 64
8415 kilobytes long, but which has much more memory which can be accessed by
8416 other means: special instructions, segment registers, or memory
8417 management hardware, for example. Suppose further that you want to
8418 adapt a program which is larger than 64 kilobytes to run on this system.
8419
8420 One solution is to identify modules of your program which are relatively
8421 independent, and need not call each other directly; call these modules
8422 @dfn{overlays}. Separate the overlays from the main program, and place
8423 their machine code in the larger memory. Place your main program in
8424 instruction memory, but leave at least enough space there to hold the
8425 largest overlay as well.
8426
8427 Now, to call a function located in an overlay, you must first copy that
8428 overlay's machine code from the large memory into the space set aside
8429 for it in the instruction memory, and then jump to its entry point
8430 there.
8431
8432 @c NB: In the below the mapped area's size is greater or equal to the
8433 @c size of all overlays. This is intentional to remind the developer
8434 @c that overlays don't necessarily need to be the same size.
8435
8436 @smallexample
8437 @group
8438 Data Instruction Larger
8439 Address Space Address Space Address Space
8440 +-----------+ +-----------+ +-----------+
8441 | | | | | |
8442 +-----------+ +-----------+ +-----------+<-- overlay 1
8443 | program | | main | .----| overlay 1 | load address
8444 | variables | | program | | +-----------+
8445 | and heap | | | | | |
8446 +-----------+ | | | +-----------+<-- overlay 2
8447 | | +-----------+ | | | load address
8448 +-----------+ | | | .-| overlay 2 |
8449 | | | | | |
8450 mapped --->+-----------+ | | +-----------+
8451 address | | | | | |
8452 | overlay | <-' | | |
8453 | area | <---' +-----------+<-- overlay 3
8454 | | <---. | | load address
8455 +-----------+ `--| overlay 3 |
8456 | | | |
8457 +-----------+ | |
8458 +-----------+
8459 | |
8460 +-----------+
8461
8462 @anchor{A code overlay}A code overlay
8463 @end group
8464 @end smallexample
8465
8466 The diagram (@pxref{A code overlay}) shows a system with separate data
8467 and instruction address spaces. To map an overlay, the program copies
8468 its code from the larger address space to the instruction address space.
8469 Since the overlays shown here all use the same mapped address, only one
8470 may be mapped at a time. For a system with a single address space for
8471 data and instructions, the diagram would be similar, except that the
8472 program variables and heap would share an address space with the main
8473 program and the overlay area.
8474
8475 An overlay loaded into instruction memory and ready for use is called a
8476 @dfn{mapped} overlay; its @dfn{mapped address} is its address in the
8477 instruction memory. An overlay not present (or only partially present)
8478 in instruction memory is called @dfn{unmapped}; its @dfn{load address}
8479 is its address in the larger memory. The mapped address is also called
8480 the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
8481 called the @dfn{load memory address}, or @dfn{LMA}.
8482
8483 Unfortunately, overlays are not a completely transparent way to adapt a
8484 program to limited instruction memory. They introduce a new set of
8485 global constraints you must keep in mind as you design your program:
8486
8487 @itemize @bullet
8488
8489 @item
8490 Before calling or returning to a function in an overlay, your program
8491 must make sure that overlay is actually mapped. Otherwise, the call or
8492 return will transfer control to the right address, but in the wrong
8493 overlay, and your program will probably crash.
8494
8495 @item
8496 If the process of mapping an overlay is expensive on your system, you
8497 will need to choose your overlays carefully to minimize their effect on
8498 your program's performance.
8499
8500 @item
8501 The executable file you load onto your system must contain each
8502 overlay's instructions, appearing at the overlay's load address, not its
8503 mapped address. However, each overlay's instructions must be relocated
8504 and its symbols defined as if the overlay were at its mapped address.
8505 You can use GNU linker scripts to specify different load and relocation
8506 addresses for pieces of your program; see @ref{Overlay Description,,,
8507 ld.info, Using ld: the GNU linker}.
8508
8509 @item
8510 The procedure for loading executable files onto your system must be able
8511 to load their contents into the larger address space as well as the
8512 instruction and data spaces.
8513
8514 @end itemize
8515
8516 The overlay system described above is rather simple, and could be
8517 improved in many ways:
8518
8519 @itemize @bullet
8520
8521 @item
8522 If your system has suitable bank switch registers or memory management
8523 hardware, you could use those facilities to make an overlay's load area
8524 contents simply appear at their mapped address in instruction space.
8525 This would probably be faster than copying the overlay to its mapped
8526 area in the usual way.
8527
8528 @item
8529 If your overlays are small enough, you could set aside more than one
8530 overlay area, and have more than one overlay mapped at a time.
8531
8532 @item
8533 You can use overlays to manage data, as well as instructions. In
8534 general, data overlays are even less transparent to your design than
8535 code overlays: whereas code overlays only require care when you call or
8536 return to functions, data overlays require care every time you access
8537 the data. Also, if you change the contents of a data overlay, you
8538 must copy its contents back out to its load address before you can copy a
8539 different data overlay into the same mapped area.
8540
8541 @end itemize
8542
8543
8544 @node Overlay Commands
8545 @section Overlay Commands
8546
8547 To use @value{GDBN}'s overlay support, each overlay in your program must
8548 correspond to a separate section of the executable file. The section's
8549 virtual memory address and load memory address must be the overlay's
8550 mapped and load addresses. Identifying overlays with sections allows
8551 @value{GDBN} to determine the appropriate address of a function or
8552 variable, depending on whether the overlay is mapped or not.
8553
8554 @value{GDBN}'s overlay commands all start with the word @code{overlay};
8555 you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
8556
8557 @table @code
8558 @item overlay off
8559 @kindex overlay
8560 Disable @value{GDBN}'s overlay support. When overlay support is
8561 disabled, @value{GDBN} assumes that all functions and variables are
8562 always present at their mapped addresses. By default, @value{GDBN}'s
8563 overlay support is disabled.
8564
8565 @item overlay manual
8566 @cindex manual overlay debugging
8567 Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
8568 relies on you to tell it which overlays are mapped, and which are not,
8569 using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
8570 commands described below.
8571
8572 @item overlay map-overlay @var{overlay}
8573 @itemx overlay map @var{overlay}
8574 @cindex map an overlay
8575 Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
8576 be the name of the object file section containing the overlay. When an
8577 overlay is mapped, @value{GDBN} assumes it can find the overlay's
8578 functions and variables at their mapped addresses. @value{GDBN} assumes
8579 that any other overlays whose mapped ranges overlap that of
8580 @var{overlay} are now unmapped.
8581
8582 @item overlay unmap-overlay @var{overlay}
8583 @itemx overlay unmap @var{overlay}
8584 @cindex unmap an overlay
8585 Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
8586 must be the name of the object file section containing the overlay.
8587 When an overlay is unmapped, @value{GDBN} assumes it can find the
8588 overlay's functions and variables at their load addresses.
8589
8590 @item overlay auto
8591 Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
8592 consults a data structure the overlay manager maintains in the inferior
8593 to see which overlays are mapped. For details, see @ref{Automatic
8594 Overlay Debugging}.
8595
8596 @item overlay load-target
8597 @itemx overlay load
8598 @cindex reloading the overlay table
8599 Re-read the overlay table from the inferior. Normally, @value{GDBN}
8600 re-reads the table @value{GDBN} automatically each time the inferior
8601 stops, so this command should only be necessary if you have changed the
8602 overlay mapping yourself using @value{GDBN}. This command is only
8603 useful when using automatic overlay debugging.
8604
8605 @item overlay list-overlays
8606 @itemx overlay list
8607 @cindex listing mapped overlays
8608 Display a list of the overlays currently mapped, along with their mapped
8609 addresses, load addresses, and sizes.
8610
8611 @end table
8612
8613 Normally, when @value{GDBN} prints a code address, it includes the name
8614 of the function the address falls in:
8615
8616 @smallexample
8617 (@value{GDBP}) print main
8618 $3 = @{int ()@} 0x11a0 <main>
8619 @end smallexample
8620 @noindent
8621 When overlay debugging is enabled, @value{GDBN} recognizes code in
8622 unmapped overlays, and prints the names of unmapped functions with
8623 asterisks around them. For example, if @code{foo} is a function in an
8624 unmapped overlay, @value{GDBN} prints it this way:
8625
8626 @smallexample
8627 (@value{GDBP}) overlay list
8628 No sections are mapped.
8629 (@value{GDBP}) print foo
8630 $5 = @{int (int)@} 0x100000 <*foo*>
8631 @end smallexample
8632 @noindent
8633 When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
8634 name normally:
8635
8636 @smallexample
8637 (@value{GDBP}) overlay list
8638 Section .ov.foo.text, loaded at 0x100000 - 0x100034,
8639 mapped at 0x1016 - 0x104a
8640 (@value{GDBP}) print foo
8641 $6 = @{int (int)@} 0x1016 <foo>
8642 @end smallexample
8643
8644 When overlay debugging is enabled, @value{GDBN} can find the correct
8645 address for functions and variables in an overlay, whether or not the
8646 overlay is mapped. This allows most @value{GDBN} commands, like
8647 @code{break} and @code{disassemble}, to work normally, even on unmapped
8648 code. However, @value{GDBN}'s breakpoint support has some limitations:
8649
8650 @itemize @bullet
8651 @item
8652 @cindex breakpoints in overlays
8653 @cindex overlays, setting breakpoints in
8654 You can set breakpoints in functions in unmapped overlays, as long as
8655 @value{GDBN} can write to the overlay at its load address.
8656 @item
8657 @value{GDBN} can not set hardware or simulator-based breakpoints in
8658 unmapped overlays. However, if you set a breakpoint at the end of your
8659 overlay manager (and tell @value{GDBN} which overlays are now mapped, if
8660 you are using manual overlay management), @value{GDBN} will re-set its
8661 breakpoints properly.
8662 @end itemize
8663
8664
8665 @node Automatic Overlay Debugging
8666 @section Automatic Overlay Debugging
8667 @cindex automatic overlay debugging
8668
8669 @value{GDBN} can automatically track which overlays are mapped and which
8670 are not, given some simple co-operation from the overlay manager in the
8671 inferior. If you enable automatic overlay debugging with the
8672 @code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
8673 looks in the inferior's memory for certain variables describing the
8674 current state of the overlays.
8675
8676 Here are the variables your overlay manager must define to support
8677 @value{GDBN}'s automatic overlay debugging:
8678
8679 @table @asis
8680
8681 @item @code{_ovly_table}:
8682 This variable must be an array of the following structures:
8683
8684 @smallexample
8685 struct
8686 @{
8687 /* The overlay's mapped address. */
8688 unsigned long vma;
8689
8690 /* The size of the overlay, in bytes. */
8691 unsigned long size;
8692
8693 /* The overlay's load address. */
8694 unsigned long lma;
8695
8696 /* Non-zero if the overlay is currently mapped;
8697 zero otherwise. */
8698 unsigned long mapped;
8699 @}
8700 @end smallexample
8701
8702 @item @code{_novlys}:
8703 This variable must be a four-byte signed integer, holding the total
8704 number of elements in @code{_ovly_table}.
8705
8706 @end table
8707
8708 To decide whether a particular overlay is mapped or not, @value{GDBN}
8709 looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
8710 @code{lma} members equal the VMA and LMA of the overlay's section in the
8711 executable file. When @value{GDBN} finds a matching entry, it consults
8712 the entry's @code{mapped} member to determine whether the overlay is
8713 currently mapped.
8714
8715 In addition, your overlay manager may define a function called
8716 @code{_ovly_debug_event}. If this function is defined, @value{GDBN}
8717 will silently set a breakpoint there. If the overlay manager then
8718 calls this function whenever it has changed the overlay table, this
8719 will enable @value{GDBN} to accurately keep track of which overlays
8720 are in program memory, and update any breakpoints that may be set
8721 in overlays. This will allow breakpoints to work even if the
8722 overlays are kept in ROM or other non-writable memory while they
8723 are not being executed.
8724
8725 @node Overlay Sample Program
8726 @section Overlay Sample Program
8727 @cindex overlay example program
8728
8729 When linking a program which uses overlays, you must place the overlays
8730 at their load addresses, while relocating them to run at their mapped
8731 addresses. To do this, you must write a linker script (@pxref{Overlay
8732 Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
8733 since linker scripts are specific to a particular host system, target
8734 architecture, and target memory layout, this manual cannot provide
8735 portable sample code demonstrating @value{GDBN}'s overlay support.
8736
8737 However, the @value{GDBN} source distribution does contain an overlaid
8738 program, with linker scripts for a few systems, as part of its test
8739 suite. The program consists of the following files from
8740 @file{gdb/testsuite/gdb.base}:
8741
8742 @table @file
8743 @item overlays.c
8744 The main program file.
8745 @item ovlymgr.c
8746 A simple overlay manager, used by @file{overlays.c}.
8747 @item foo.c
8748 @itemx bar.c
8749 @itemx baz.c
8750 @itemx grbx.c
8751 Overlay modules, loaded and used by @file{overlays.c}.
8752 @item d10v.ld
8753 @itemx m32r.ld
8754 Linker scripts for linking the test program on the @code{d10v-elf}
8755 and @code{m32r-elf} targets.
8756 @end table
8757
8758 You can build the test program using the @code{d10v-elf} GCC
8759 cross-compiler like this:
8760
8761 @smallexample
8762 $ d10v-elf-gcc -g -c overlays.c
8763 $ d10v-elf-gcc -g -c ovlymgr.c
8764 $ d10v-elf-gcc -g -c foo.c
8765 $ d10v-elf-gcc -g -c bar.c
8766 $ d10v-elf-gcc -g -c baz.c
8767 $ d10v-elf-gcc -g -c grbx.c
8768 $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
8769 baz.o grbx.o -Wl,-Td10v.ld -o overlays
8770 @end smallexample
8771
8772 The build process is identical for any other architecture, except that
8773 you must substitute the appropriate compiler and linker script for the
8774 target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
8775
8776
8777 @node Languages
8778 @chapter Using @value{GDBN} with Different Languages
8779 @cindex languages
8780
8781 Although programming languages generally have common aspects, they are
8782 rarely expressed in the same manner. For instance, in ANSI C,
8783 dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
8784 Modula-2, it is accomplished by @code{p^}. Values can also be
8785 represented (and displayed) differently. Hex numbers in C appear as
8786 @samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
8787
8788 @cindex working language
8789 Language-specific information is built into @value{GDBN} for some languages,
8790 allowing you to express operations like the above in your program's
8791 native language, and allowing @value{GDBN} to output values in a manner
8792 consistent with the syntax of your program's native language. The
8793 language you use to build expressions is called the @dfn{working
8794 language}.
8795
8796 @menu
8797 * Setting:: Switching between source languages
8798 * Show:: Displaying the language
8799 * Checks:: Type and range checks
8800 * Supported Languages:: Supported languages
8801 * Unsupported Languages:: Unsupported languages
8802 @end menu
8803
8804 @node Setting
8805 @section Switching Between Source Languages
8806
8807 There are two ways to control the working language---either have @value{GDBN}
8808 set it automatically, or select it manually yourself. You can use the
8809 @code{set language} command for either purpose. On startup, @value{GDBN}
8810 defaults to setting the language automatically. The working language is
8811 used to determine how expressions you type are interpreted, how values
8812 are printed, etc.
8813
8814 In addition to the working language, every source file that
8815 @value{GDBN} knows about has its own working language. For some object
8816 file formats, the compiler might indicate which language a particular
8817 source file is in. However, most of the time @value{GDBN} infers the
8818 language from the name of the file. The language of a source file
8819 controls whether C@t{++} names are demangled---this way @code{backtrace} can
8820 show each frame appropriately for its own language. There is no way to
8821 set the language of a source file from within @value{GDBN}, but you can
8822 set the language associated with a filename extension. @xref{Show, ,
8823 Displaying the Language}.
8824
8825 This is most commonly a problem when you use a program, such
8826 as @code{cfront} or @code{f2c}, that generates C but is written in
8827 another language. In that case, make the
8828 program use @code{#line} directives in its C output; that way
8829 @value{GDBN} will know the correct language of the source code of the original
8830 program, and will display that source code, not the generated C code.
8831
8832 @menu
8833 * Filenames:: Filename extensions and languages.
8834 * Manually:: Setting the working language manually
8835 * Automatically:: Having @value{GDBN} infer the source language
8836 @end menu
8837
8838 @node Filenames
8839 @subsection List of Filename Extensions and Languages
8840
8841 If a source file name ends in one of the following extensions, then
8842 @value{GDBN} infers that its language is the one indicated.
8843
8844 @table @file
8845 @item .ada
8846 @itemx .ads
8847 @itemx .adb
8848 @itemx .a
8849 Ada source file.
8850
8851 @item .c
8852 C source file
8853
8854 @item .C
8855 @itemx .cc
8856 @itemx .cp
8857 @itemx .cpp
8858 @itemx .cxx
8859 @itemx .c++
8860 C@t{++} source file
8861
8862 @item .m
8863 Objective-C source file
8864
8865 @item .f
8866 @itemx .F
8867 Fortran source file
8868
8869 @item .mod
8870 Modula-2 source file
8871
8872 @item .s
8873 @itemx .S
8874 Assembler source file. This actually behaves almost like C, but
8875 @value{GDBN} does not skip over function prologues when stepping.
8876 @end table
8877
8878 In addition, you may set the language associated with a filename
8879 extension. @xref{Show, , Displaying the Language}.
8880
8881 @node Manually
8882 @subsection Setting the Working Language
8883
8884 If you allow @value{GDBN} to set the language automatically,
8885 expressions are interpreted the same way in your debugging session and
8886 your program.
8887
8888 @kindex set language
8889 If you wish, you may set the language manually. To do this, issue the
8890 command @samp{set language @var{lang}}, where @var{lang} is the name of
8891 a language, such as
8892 @code{c} or @code{modula-2}.
8893 For a list of the supported languages, type @samp{set language}.
8894
8895 Setting the language manually prevents @value{GDBN} from updating the working
8896 language automatically. This can lead to confusion if you try
8897 to debug a program when the working language is not the same as the
8898 source language, when an expression is acceptable to both
8899 languages---but means different things. For instance, if the current
8900 source file were written in C, and @value{GDBN} was parsing Modula-2, a
8901 command such as:
8902
8903 @smallexample
8904 print a = b + c
8905 @end smallexample
8906
8907 @noindent
8908 might not have the effect you intended. In C, this means to add
8909 @code{b} and @code{c} and place the result in @code{a}. The result
8910 printed would be the value of @code{a}. In Modula-2, this means to compare
8911 @code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
8912
8913 @node Automatically
8914 @subsection Having @value{GDBN} Infer the Source Language
8915
8916 To have @value{GDBN} set the working language automatically, use
8917 @samp{set language local} or @samp{set language auto}. @value{GDBN}
8918 then infers the working language. That is, when your program stops in a
8919 frame (usually by encountering a breakpoint), @value{GDBN} sets the
8920 working language to the language recorded for the function in that
8921 frame. If the language for a frame is unknown (that is, if the function
8922 or block corresponding to the frame was defined in a source file that
8923 does not have a recognized extension), the current working language is
8924 not changed, and @value{GDBN} issues a warning.
8925
8926 This may not seem necessary for most programs, which are written
8927 entirely in one source language. However, program modules and libraries
8928 written in one source language can be used by a main program written in
8929 a different source language. Using @samp{set language auto} in this
8930 case frees you from having to set the working language manually.
8931
8932 @node Show
8933 @section Displaying the Language
8934
8935 The following commands help you find out which language is the
8936 working language, and also what language source files were written in.
8937
8938 @table @code
8939 @item show language
8940 @kindex show language
8941 Display the current working language. This is the
8942 language you can use with commands such as @code{print} to
8943 build and compute expressions that may involve variables in your program.
8944
8945 @item info frame
8946 @kindex info frame@r{, show the source language}
8947 Display the source language for this frame. This language becomes the
8948 working language if you use an identifier from this frame.
8949 @xref{Frame Info, ,Information about a Frame}, to identify the other
8950 information listed here.
8951
8952 @item info source
8953 @kindex info source@r{, show the source language}
8954 Display the source language of this source file.
8955 @xref{Symbols, ,Examining the Symbol Table}, to identify the other
8956 information listed here.
8957 @end table
8958
8959 In unusual circumstances, you may have source files with extensions
8960 not in the standard list. You can then set the extension associated
8961 with a language explicitly:
8962
8963 @table @code
8964 @item set extension-language @var{ext} @var{language}
8965 @kindex set extension-language
8966 Tell @value{GDBN} that source files with extension @var{ext} are to be
8967 assumed as written in the source language @var{language}.
8968
8969 @item info extensions
8970 @kindex info extensions
8971 List all the filename extensions and the associated languages.
8972 @end table
8973
8974 @node Checks
8975 @section Type and Range Checking
8976
8977 @quotation
8978 @emph{Warning:} In this release, the @value{GDBN} commands for type and range
8979 checking are included, but they do not yet have any effect. This
8980 section documents the intended facilities.
8981 @end quotation
8982 @c FIXME remove warning when type/range code added
8983
8984 Some languages are designed to guard you against making seemingly common
8985 errors through a series of compile- and run-time checks. These include
8986 checking the type of arguments to functions and operators, and making
8987 sure mathematical overflows are caught at run time. Checks such as
8988 these help to ensure a program's correctness once it has been compiled
8989 by eliminating type mismatches, and providing active checks for range
8990 errors when your program is running.
8991
8992 @value{GDBN} can check for conditions like the above if you wish.
8993 Although @value{GDBN} does not check the statements in your program,
8994 it can check expressions entered directly into @value{GDBN} for
8995 evaluation via the @code{print} command, for example. As with the
8996 working language, @value{GDBN} can also decide whether or not to check
8997 automatically based on your program's source language.
8998 @xref{Supported Languages, ,Supported Languages}, for the default
8999 settings of supported languages.
9000
9001 @menu
9002 * Type Checking:: An overview of type checking
9003 * Range Checking:: An overview of range checking
9004 @end menu
9005
9006 @cindex type checking
9007 @cindex checks, type
9008 @node Type Checking
9009 @subsection An Overview of Type Checking
9010
9011 Some languages, such as Modula-2, are strongly typed, meaning that the
9012 arguments to operators and functions have to be of the correct type,
9013 otherwise an error occurs. These checks prevent type mismatch
9014 errors from ever causing any run-time problems. For example,
9015
9016 @smallexample
9017 1 + 2 @result{} 3
9018 @exdent but
9019 @error{} 1 + 2.3
9020 @end smallexample
9021
9022 The second example fails because the @code{CARDINAL} 1 is not
9023 type-compatible with the @code{REAL} 2.3.
9024
9025 For the expressions you use in @value{GDBN} commands, you can tell the
9026 @value{GDBN} type checker to skip checking;
9027 to treat any mismatches as errors and abandon the expression;
9028 or to only issue warnings when type mismatches occur,
9029 but evaluate the expression anyway. When you choose the last of
9030 these, @value{GDBN} evaluates expressions like the second example above, but
9031 also issues a warning.
9032
9033 Even if you turn type checking off, there may be other reasons
9034 related to type that prevent @value{GDBN} from evaluating an expression.
9035 For instance, @value{GDBN} does not know how to add an @code{int} and
9036 a @code{struct foo}. These particular type errors have nothing to do
9037 with the language in use, and usually arise from expressions, such as
9038 the one described above, which make little sense to evaluate anyway.
9039
9040 Each language defines to what degree it is strict about type. For
9041 instance, both Modula-2 and C require the arguments to arithmetical
9042 operators to be numbers. In C, enumerated types and pointers can be
9043 represented as numbers, so that they are valid arguments to mathematical
9044 operators. @xref{Supported Languages, ,Supported Languages}, for further
9045 details on specific languages.
9046
9047 @value{GDBN} provides some additional commands for controlling the type checker:
9048
9049 @kindex set check type
9050 @kindex show check type
9051 @table @code
9052 @item set check type auto
9053 Set type checking on or off based on the current working language.
9054 @xref{Supported Languages, ,Supported Languages}, for the default settings for
9055 each language.
9056
9057 @item set check type on
9058 @itemx set check type off
9059 Set type checking on or off, overriding the default setting for the
9060 current working language. Issue a warning if the setting does not
9061 match the language default. If any type mismatches occur in
9062 evaluating an expression while type checking is on, @value{GDBN} prints a
9063 message and aborts evaluation of the expression.
9064
9065 @item set check type warn
9066 Cause the type checker to issue warnings, but to always attempt to
9067 evaluate the expression. Evaluating the expression may still
9068 be impossible for other reasons. For example, @value{GDBN} cannot add
9069 numbers and structures.
9070
9071 @item show type
9072 Show the current setting of the type checker, and whether or not @value{GDBN}
9073 is setting it automatically.
9074 @end table
9075
9076 @cindex range checking
9077 @cindex checks, range
9078 @node Range Checking
9079 @subsection An Overview of Range Checking
9080
9081 In some languages (such as Modula-2), it is an error to exceed the
9082 bounds of a type; this is enforced with run-time checks. Such range
9083 checking is meant to ensure program correctness by making sure
9084 computations do not overflow, or indices on an array element access do
9085 not exceed the bounds of the array.
9086
9087 For expressions you use in @value{GDBN} commands, you can tell
9088 @value{GDBN} to treat range errors in one of three ways: ignore them,
9089 always treat them as errors and abandon the expression, or issue
9090 warnings but evaluate the expression anyway.
9091
9092 A range error can result from numerical overflow, from exceeding an
9093 array index bound, or when you type a constant that is not a member
9094 of any type. Some languages, however, do not treat overflows as an
9095 error. In many implementations of C, mathematical overflow causes the
9096 result to ``wrap around'' to lower values---for example, if @var{m} is
9097 the largest integer value, and @var{s} is the smallest, then
9098
9099 @smallexample
9100 @var{m} + 1 @result{} @var{s}
9101 @end smallexample
9102
9103 This, too, is specific to individual languages, and in some cases
9104 specific to individual compilers or machines. @xref{Supported Languages, ,
9105 Supported Languages}, for further details on specific languages.
9106
9107 @value{GDBN} provides some additional commands for controlling the range checker:
9108
9109 @kindex set check range
9110 @kindex show check range
9111 @table @code
9112 @item set check range auto
9113 Set range checking on or off based on the current working language.
9114 @xref{Supported Languages, ,Supported Languages}, for the default settings for
9115 each language.
9116
9117 @item set check range on
9118 @itemx set check range off
9119 Set range checking on or off, overriding the default setting for the
9120 current working language. A warning is issued if the setting does not
9121 match the language default. If a range error occurs and range checking is on,
9122 then a message is printed and evaluation of the expression is aborted.
9123
9124 @item set check range warn
9125 Output messages when the @value{GDBN} range checker detects a range error,
9126 but attempt to evaluate the expression anyway. Evaluating the
9127 expression may still be impossible for other reasons, such as accessing
9128 memory that the process does not own (a typical example from many Unix
9129 systems).
9130
9131 @item show range
9132 Show the current setting of the range checker, and whether or not it is
9133 being set automatically by @value{GDBN}.
9134 @end table
9135
9136 @node Supported Languages
9137 @section Supported Languages
9138
9139 @value{GDBN} supports C, C@t{++}, Objective-C, Fortran, Java, Pascal,
9140 assembly, Modula-2, and Ada.
9141 @c This is false ...
9142 Some @value{GDBN} features may be used in expressions regardless of the
9143 language you use: the @value{GDBN} @code{@@} and @code{::} operators,
9144 and the @samp{@{type@}addr} construct (@pxref{Expressions,
9145 ,Expressions}) can be used with the constructs of any supported
9146 language.
9147
9148 The following sections detail to what degree each source language is
9149 supported by @value{GDBN}. These sections are not meant to be language
9150 tutorials or references, but serve only as a reference guide to what the
9151 @value{GDBN} expression parser accepts, and what input and output
9152 formats should look like for different languages. There are many good
9153 books written on each of these languages; please look to these for a
9154 language reference or tutorial.
9155
9156 @menu
9157 * C:: C and C@t{++}
9158 * Objective-C:: Objective-C
9159 * Fortran:: Fortran
9160 * Pascal:: Pascal
9161 * Modula-2:: Modula-2
9162 * Ada:: Ada
9163 @end menu
9164
9165 @node C
9166 @subsection C and C@t{++}
9167
9168 @cindex C and C@t{++}
9169 @cindex expressions in C or C@t{++}
9170
9171 Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
9172 to both languages. Whenever this is the case, we discuss those languages
9173 together.
9174
9175 @cindex C@t{++}
9176 @cindex @code{g++}, @sc{gnu} C@t{++} compiler
9177 @cindex @sc{gnu} C@t{++}
9178 The C@t{++} debugging facilities are jointly implemented by the C@t{++}
9179 compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
9180 effectively, you must compile your C@t{++} programs with a supported
9181 C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
9182 compiler (@code{aCC}).
9183
9184 For best results when using @sc{gnu} C@t{++}, use the DWARF 2 debugging
9185 format; if it doesn't work on your system, try the stabs+ debugging
9186 format. You can select those formats explicitly with the @code{g++}
9187 command-line options @option{-gdwarf-2} and @option{-gstabs+}.
9188 @xref{Debugging Options,,Options for Debugging Your Program or GCC,
9189 gcc.info, Using the @sc{gnu} Compiler Collection (GCC)}.
9190
9191 @menu
9192 * C Operators:: C and C@t{++} operators
9193 * C Constants:: C and C@t{++} constants
9194 * C Plus Plus Expressions:: C@t{++} expressions
9195 * C Defaults:: Default settings for C and C@t{++}
9196 * C Checks:: C and C@t{++} type and range checks
9197 * Debugging C:: @value{GDBN} and C
9198 * Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
9199 * Decimal Floating Point:: Numbers in Decimal Floating Point format
9200 @end menu
9201
9202 @node C Operators
9203 @subsubsection C and C@t{++} Operators
9204
9205 @cindex C and C@t{++} operators
9206
9207 Operators must be defined on values of specific types. For instance,
9208 @code{+} is defined on numbers, but not on structures. Operators are
9209 often defined on groups of types.
9210
9211 For the purposes of C and C@t{++}, the following definitions hold:
9212
9213 @itemize @bullet
9214
9215 @item
9216 @emph{Integral types} include @code{int} with any of its storage-class
9217 specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
9218
9219 @item
9220 @emph{Floating-point types} include @code{float}, @code{double}, and
9221 @code{long double} (if supported by the target platform).
9222
9223 @item
9224 @emph{Pointer types} include all types defined as @code{(@var{type} *)}.
9225
9226 @item
9227 @emph{Scalar types} include all of the above.
9228
9229 @end itemize
9230
9231 @noindent
9232 The following operators are supported. They are listed here
9233 in order of increasing precedence:
9234
9235 @table @code
9236 @item ,
9237 The comma or sequencing operator. Expressions in a comma-separated list
9238 are evaluated from left to right, with the result of the entire
9239 expression being the last expression evaluated.
9240
9241 @item =
9242 Assignment. The value of an assignment expression is the value
9243 assigned. Defined on scalar types.
9244
9245 @item @var{op}=
9246 Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
9247 and translated to @w{@code{@var{a} = @var{a op b}}}.
9248 @w{@code{@var{op}=}} and @code{=} have the same precedence.
9249 @var{op} is any one of the operators @code{|}, @code{^}, @code{&},
9250 @code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
9251
9252 @item ?:
9253 The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
9254 of as: if @var{a} then @var{b} else @var{c}. @var{a} should be of an
9255 integral type.
9256
9257 @item ||
9258 Logical @sc{or}. Defined on integral types.
9259
9260 @item &&
9261 Logical @sc{and}. Defined on integral types.
9262
9263 @item |
9264 Bitwise @sc{or}. Defined on integral types.
9265
9266 @item ^
9267 Bitwise exclusive-@sc{or}. Defined on integral types.
9268
9269 @item &
9270 Bitwise @sc{and}. Defined on integral types.
9271
9272 @item ==@r{, }!=
9273 Equality and inequality. Defined on scalar types. The value of these
9274 expressions is 0 for false and non-zero for true.
9275
9276 @item <@r{, }>@r{, }<=@r{, }>=
9277 Less than, greater than, less than or equal, greater than or equal.
9278 Defined on scalar types. The value of these expressions is 0 for false
9279 and non-zero for true.
9280
9281 @item <<@r{, }>>
9282 left shift, and right shift. Defined on integral types.
9283
9284 @item @@
9285 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9286
9287 @item +@r{, }-
9288 Addition and subtraction. Defined on integral types, floating-point types and
9289 pointer types.
9290
9291 @item *@r{, }/@r{, }%
9292 Multiplication, division, and modulus. Multiplication and division are
9293 defined on integral and floating-point types. Modulus is defined on
9294 integral types.
9295
9296 @item ++@r{, }--
9297 Increment and decrement. When appearing before a variable, the
9298 operation is performed before the variable is used in an expression;
9299 when appearing after it, the variable's value is used before the
9300 operation takes place.
9301
9302 @item *
9303 Pointer dereferencing. Defined on pointer types. Same precedence as
9304 @code{++}.
9305
9306 @item &
9307 Address operator. Defined on variables. Same precedence as @code{++}.
9308
9309 For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
9310 allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
9311 to examine the address
9312 where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
9313 stored.
9314
9315 @item -
9316 Negative. Defined on integral and floating-point types. Same
9317 precedence as @code{++}.
9318
9319 @item !
9320 Logical negation. Defined on integral types. Same precedence as
9321 @code{++}.
9322
9323 @item ~
9324 Bitwise complement operator. Defined on integral types. Same precedence as
9325 @code{++}.
9326
9327
9328 @item .@r{, }->
9329 Structure member, and pointer-to-structure member. For convenience,
9330 @value{GDBN} regards the two as equivalent, choosing whether to dereference a
9331 pointer based on the stored type information.
9332 Defined on @code{struct} and @code{union} data.
9333
9334 @item .*@r{, }->*
9335 Dereferences of pointers to members.
9336
9337 @item []
9338 Array indexing. @code{@var{a}[@var{i}]} is defined as
9339 @code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
9340
9341 @item ()
9342 Function parameter list. Same precedence as @code{->}.
9343
9344 @item ::
9345 C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
9346 and @code{class} types.
9347
9348 @item ::
9349 Doubled colons also represent the @value{GDBN} scope operator
9350 (@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
9351 above.
9352 @end table
9353
9354 If an operator is redefined in the user code, @value{GDBN} usually
9355 attempts to invoke the redefined version instead of using the operator's
9356 predefined meaning.
9357
9358 @node C Constants
9359 @subsubsection C and C@t{++} Constants
9360
9361 @cindex C and C@t{++} constants
9362
9363 @value{GDBN} allows you to express the constants of C and C@t{++} in the
9364 following ways:
9365
9366 @itemize @bullet
9367 @item
9368 Integer constants are a sequence of digits. Octal constants are
9369 specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
9370 by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
9371 @samp{l}, specifying that the constant should be treated as a
9372 @code{long} value.
9373
9374 @item
9375 Floating point constants are a sequence of digits, followed by a decimal
9376 point, followed by a sequence of digits, and optionally followed by an
9377 exponent. An exponent is of the form:
9378 @samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
9379 sequence of digits. The @samp{+} is optional for positive exponents.
9380 A floating-point constant may also end with a letter @samp{f} or
9381 @samp{F}, specifying that the constant should be treated as being of
9382 the @code{float} (as opposed to the default @code{double}) type; or with
9383 a letter @samp{l} or @samp{L}, which specifies a @code{long double}
9384 constant.
9385
9386 @item
9387 Enumerated constants consist of enumerated identifiers, or their
9388 integral equivalents.
9389
9390 @item
9391 Character constants are a single character surrounded by single quotes
9392 (@code{'}), or a number---the ordinal value of the corresponding character
9393 (usually its @sc{ascii} value). Within quotes, the single character may
9394 be represented by a letter or by @dfn{escape sequences}, which are of
9395 the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
9396 of the character's ordinal value; or of the form @samp{\@var{x}}, where
9397 @samp{@var{x}} is a predefined special character---for example,
9398 @samp{\n} for newline.
9399
9400 @item
9401 String constants are a sequence of character constants surrounded by
9402 double quotes (@code{"}). Any valid character constant (as described
9403 above) may appear. Double quotes within the string must be preceded by
9404 a backslash, so for instance @samp{"a\"b'c"} is a string of five
9405 characters.
9406
9407 @item
9408 Pointer constants are an integral value. You can also write pointers
9409 to constants using the C operator @samp{&}.
9410
9411 @item
9412 Array constants are comma-separated lists surrounded by braces @samp{@{}
9413 and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
9414 integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
9415 and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
9416 @end itemize
9417
9418 @node C Plus Plus Expressions
9419 @subsubsection C@t{++} Expressions
9420
9421 @cindex expressions in C@t{++}
9422 @value{GDBN} expression handling can interpret most C@t{++} expressions.
9423
9424 @cindex debugging C@t{++} programs
9425 @cindex C@t{++} compilers
9426 @cindex debug formats and C@t{++}
9427 @cindex @value{NGCC} and C@t{++}
9428 @quotation
9429 @emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use the
9430 proper compiler and the proper debug format. Currently, @value{GDBN}
9431 works best when debugging C@t{++} code that is compiled with
9432 @value{NGCC} 2.95.3 or with @value{NGCC} 3.1 or newer, using the options
9433 @option{-gdwarf-2} or @option{-gstabs+}. DWARF 2 is preferred over
9434 stabs+. Most configurations of @value{NGCC} emit either DWARF 2 or
9435 stabs+ as their default debug format, so you usually don't need to
9436 specify a debug format explicitly. Other compilers and/or debug formats
9437 are likely to work badly or not at all when using @value{GDBN} to debug
9438 C@t{++} code.
9439 @end quotation
9440
9441 @enumerate
9442
9443 @cindex member functions
9444 @item
9445 Member function calls are allowed; you can use expressions like
9446
9447 @smallexample
9448 count = aml->GetOriginal(x, y)
9449 @end smallexample
9450
9451 @vindex this@r{, inside C@t{++} member functions}
9452 @cindex namespace in C@t{++}
9453 @item
9454 While a member function is active (in the selected stack frame), your
9455 expressions have the same namespace available as the member function;
9456 that is, @value{GDBN} allows implicit references to the class instance
9457 pointer @code{this} following the same rules as C@t{++}.
9458
9459 @cindex call overloaded functions
9460 @cindex overloaded functions, calling
9461 @cindex type conversions in C@t{++}
9462 @item
9463 You can call overloaded functions; @value{GDBN} resolves the function
9464 call to the right definition, with some restrictions. @value{GDBN} does not
9465 perform overload resolution involving user-defined type conversions,
9466 calls to constructors, or instantiations of templates that do not exist
9467 in the program. It also cannot handle ellipsis argument lists or
9468 default arguments.
9469
9470 It does perform integral conversions and promotions, floating-point
9471 promotions, arithmetic conversions, pointer conversions, conversions of
9472 class objects to base classes, and standard conversions such as those of
9473 functions or arrays to pointers; it requires an exact match on the
9474 number of function arguments.
9475
9476 Overload resolution is always performed, unless you have specified
9477 @code{set overload-resolution off}. @xref{Debugging C Plus Plus,
9478 ,@value{GDBN} Features for C@t{++}}.
9479
9480 You must specify @code{set overload-resolution off} in order to use an
9481 explicit function signature to call an overloaded function, as in
9482 @smallexample
9483 p 'foo(char,int)'('x', 13)
9484 @end smallexample
9485
9486 The @value{GDBN} command-completion facility can simplify this;
9487 see @ref{Completion, ,Command Completion}.
9488
9489 @cindex reference declarations
9490 @item
9491 @value{GDBN} understands variables declared as C@t{++} references; you can use
9492 them in expressions just as you do in C@t{++} source---they are automatically
9493 dereferenced.
9494
9495 In the parameter list shown when @value{GDBN} displays a frame, the values of
9496 reference variables are not displayed (unlike other variables); this
9497 avoids clutter, since references are often used for large structures.
9498 The @emph{address} of a reference variable is always shown, unless
9499 you have specified @samp{set print address off}.
9500
9501 @item
9502 @value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
9503 expressions can use it just as expressions in your program do. Since
9504 one scope may be defined in another, you can use @code{::} repeatedly if
9505 necessary, for example in an expression like
9506 @samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
9507 resolving name scope by reference to source files, in both C and C@t{++}
9508 debugging (@pxref{Variables, ,Program Variables}).
9509 @end enumerate
9510
9511 In addition, when used with HP's C@t{++} compiler, @value{GDBN} supports
9512 calling virtual functions correctly, printing out virtual bases of
9513 objects, calling functions in a base subobject, casting objects, and
9514 invoking user-defined operators.
9515
9516 @node C Defaults
9517 @subsubsection C and C@t{++} Defaults
9518
9519 @cindex C and C@t{++} defaults
9520
9521 If you allow @value{GDBN} to set type and range checking automatically, they
9522 both default to @code{off} whenever the working language changes to
9523 C or C@t{++}. This happens regardless of whether you or @value{GDBN}
9524 selects the working language.
9525
9526 If you allow @value{GDBN} to set the language automatically, it
9527 recognizes source files whose names end with @file{.c}, @file{.C}, or
9528 @file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
9529 these files, it sets the working language to C or C@t{++}.
9530 @xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
9531 for further details.
9532
9533 @c Type checking is (a) primarily motivated by Modula-2, and (b)
9534 @c unimplemented. If (b) changes, it might make sense to let this node
9535 @c appear even if Mod-2 does not, but meanwhile ignore it. roland 16jul93.
9536
9537 @node C Checks
9538 @subsubsection C and C@t{++} Type and Range Checks
9539
9540 @cindex C and C@t{++} checks
9541
9542 By default, when @value{GDBN} parses C or C@t{++} expressions, type checking
9543 is not used. However, if you turn type checking on, @value{GDBN}
9544 considers two variables type equivalent if:
9545
9546 @itemize @bullet
9547 @item
9548 The two variables are structured and have the same structure, union, or
9549 enumerated tag.
9550
9551 @item
9552 The two variables have the same type name, or types that have been
9553 declared equivalent through @code{typedef}.
9554
9555 @ignore
9556 @c leaving this out because neither J Gilmore nor R Pesch understand it.
9557 @c FIXME--beers?
9558 @item
9559 The two @code{struct}, @code{union}, or @code{enum} variables are
9560 declared in the same declaration. (Note: this may not be true for all C
9561 compilers.)
9562 @end ignore
9563 @end itemize
9564
9565 Range checking, if turned on, is done on mathematical operations. Array
9566 indices are not checked, since they are often used to index a pointer
9567 that is not itself an array.
9568
9569 @node Debugging C
9570 @subsubsection @value{GDBN} and C
9571
9572 The @code{set print union} and @code{show print union} commands apply to
9573 the @code{union} type. When set to @samp{on}, any @code{union} that is
9574 inside a @code{struct} or @code{class} is also printed. Otherwise, it
9575 appears as @samp{@{...@}}.
9576
9577 The @code{@@} operator aids in the debugging of dynamic arrays, formed
9578 with pointers and a memory allocation function. @xref{Expressions,
9579 ,Expressions}.
9580
9581 @node Debugging C Plus Plus
9582 @subsubsection @value{GDBN} Features for C@t{++}
9583
9584 @cindex commands for C@t{++}
9585
9586 Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
9587 designed specifically for use with C@t{++}. Here is a summary:
9588
9589 @table @code
9590 @cindex break in overloaded functions
9591 @item @r{breakpoint menus}
9592 When you want a breakpoint in a function whose name is overloaded,
9593 @value{GDBN} breakpoint menus help you specify which function definition
9594 you want. @xref{Breakpoint Menus,,Breakpoint Menus}.
9595
9596 @cindex overloading in C@t{++}
9597 @item rbreak @var{regex}
9598 Setting breakpoints using regular expressions is helpful for setting
9599 breakpoints on overloaded functions that are not members of any special
9600 classes.
9601 @xref{Set Breaks, ,Setting Breakpoints}.
9602
9603 @cindex C@t{++} exception handling
9604 @item catch throw
9605 @itemx catch catch
9606 Debug C@t{++} exception handling using these commands. @xref{Set
9607 Catchpoints, , Setting Catchpoints}.
9608
9609 @cindex inheritance
9610 @item ptype @var{typename}
9611 Print inheritance relationships as well as other information for type
9612 @var{typename}.
9613 @xref{Symbols, ,Examining the Symbol Table}.
9614
9615 @cindex C@t{++} symbol display
9616 @item set print demangle
9617 @itemx show print demangle
9618 @itemx set print asm-demangle
9619 @itemx show print asm-demangle
9620 Control whether C@t{++} symbols display in their source form, both when
9621 displaying code as C@t{++} source and when displaying disassemblies.
9622 @xref{Print Settings, ,Print Settings}.
9623
9624 @item set print object
9625 @itemx show print object
9626 Choose whether to print derived (actual) or declared types of objects.
9627 @xref{Print Settings, ,Print Settings}.
9628
9629 @item set print vtbl
9630 @itemx show print vtbl
9631 Control the format for printing virtual function tables.
9632 @xref{Print Settings, ,Print Settings}.
9633 (The @code{vtbl} commands do not work on programs compiled with the HP
9634 ANSI C@t{++} compiler (@code{aCC}).)
9635
9636 @kindex set overload-resolution
9637 @cindex overloaded functions, overload resolution
9638 @item set overload-resolution on
9639 Enable overload resolution for C@t{++} expression evaluation. The default
9640 is on. For overloaded functions, @value{GDBN} evaluates the arguments
9641 and searches for a function whose signature matches the argument types,
9642 using the standard C@t{++} conversion rules (see @ref{C Plus Plus
9643 Expressions, ,C@t{++} Expressions}, for details).
9644 If it cannot find a match, it emits a message.
9645
9646 @item set overload-resolution off
9647 Disable overload resolution for C@t{++} expression evaluation. For
9648 overloaded functions that are not class member functions, @value{GDBN}
9649 chooses the first function of the specified name that it finds in the
9650 symbol table, whether or not its arguments are of the correct type. For
9651 overloaded functions that are class member functions, @value{GDBN}
9652 searches for a function whose signature @emph{exactly} matches the
9653 argument types.
9654
9655 @kindex show overload-resolution
9656 @item show overload-resolution
9657 Show the current setting of overload resolution.
9658
9659 @item @r{Overloaded symbol names}
9660 You can specify a particular definition of an overloaded symbol, using
9661 the same notation that is used to declare such symbols in C@t{++}: type
9662 @code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
9663 also use the @value{GDBN} command-line word completion facilities to list the
9664 available choices, or to finish the type list for you.
9665 @xref{Completion,, Command Completion}, for details on how to do this.
9666 @end table
9667
9668 @node Decimal Floating Point
9669 @subsubsection Decimal Floating Point format
9670 @cindex decimal floating point format
9671
9672 @value{GDBN} can examine, set and perform computations with numbers in
9673 decimal floating point format, which in the C language correspond to the
9674 @code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
9675 specified by the extension to support decimal floating-point arithmetic.
9676
9677 There are two encodings in use, depending on the architecture: BID (Binary
9678 Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
9679 PowerPC. @value{GDBN} will use the appropriate encoding for the configured
9680 target.
9681
9682 Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
9683 to manipulate decimal floating point numbers, it is not possible to convert
9684 (using a cast, for example) integers wider than 32-bit to decimal float.
9685
9686 In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
9687 point computations, error checking in decimal float operations ignores
9688 underflow, overflow and divide by zero exceptions.
9689
9690 In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
9691 to inspect @code{_Decimal128} values stored in floating point registers. See
9692 @ref{PowerPC,,PowerPC} for more details.
9693
9694 @node Objective-C
9695 @subsection Objective-C
9696
9697 @cindex Objective-C
9698 This section provides information about some commands and command
9699 options that are useful for debugging Objective-C code. See also
9700 @ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
9701 few more commands specific to Objective-C support.
9702
9703 @menu
9704 * Method Names in Commands::
9705 * The Print Command with Objective-C::
9706 @end menu
9707
9708 @node Method Names in Commands
9709 @subsubsection Method Names in Commands
9710
9711 The following commands have been extended to accept Objective-C method
9712 names as line specifications:
9713
9714 @kindex clear@r{, and Objective-C}
9715 @kindex break@r{, and Objective-C}
9716 @kindex info line@r{, and Objective-C}
9717 @kindex jump@r{, and Objective-C}
9718 @kindex list@r{, and Objective-C}
9719 @itemize
9720 @item @code{clear}
9721 @item @code{break}
9722 @item @code{info line}
9723 @item @code{jump}
9724 @item @code{list}
9725 @end itemize
9726
9727 A fully qualified Objective-C method name is specified as
9728
9729 @smallexample
9730 -[@var{Class} @var{methodName}]
9731 @end smallexample
9732
9733 where the minus sign is used to indicate an instance method and a
9734 plus sign (not shown) is used to indicate a class method. The class
9735 name @var{Class} and method name @var{methodName} are enclosed in
9736 brackets, similar to the way messages are specified in Objective-C
9737 source code. For example, to set a breakpoint at the @code{create}
9738 instance method of class @code{Fruit} in the program currently being
9739 debugged, enter:
9740
9741 @smallexample
9742 break -[Fruit create]
9743 @end smallexample
9744
9745 To list ten program lines around the @code{initialize} class method,
9746 enter:
9747
9748 @smallexample
9749 list +[NSText initialize]
9750 @end smallexample
9751
9752 In the current version of @value{GDBN}, the plus or minus sign is
9753 required. In future versions of @value{GDBN}, the plus or minus
9754 sign will be optional, but you can use it to narrow the search. It
9755 is also possible to specify just a method name:
9756
9757 @smallexample
9758 break create
9759 @end smallexample
9760
9761 You must specify the complete method name, including any colons. If
9762 your program's source files contain more than one @code{create} method,
9763 you'll be presented with a numbered list of classes that implement that
9764 method. Indicate your choice by number, or type @samp{0} to exit if
9765 none apply.
9766
9767 As another example, to clear a breakpoint established at the
9768 @code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
9769
9770 @smallexample
9771 clear -[NSWindow makeKeyAndOrderFront:]
9772 @end smallexample
9773
9774 @node The Print Command with Objective-C
9775 @subsubsection The Print Command With Objective-C
9776 @cindex Objective-C, print objects
9777 @kindex print-object
9778 @kindex po @r{(@code{print-object})}
9779
9780 The print command has also been extended to accept methods. For example:
9781
9782 @smallexample
9783 print -[@var{object} hash]
9784 @end smallexample
9785
9786 @cindex print an Objective-C object description
9787 @cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
9788 @noindent
9789 will tell @value{GDBN} to send the @code{hash} message to @var{object}
9790 and print the result. Also, an additional command has been added,
9791 @code{print-object} or @code{po} for short, which is meant to print
9792 the description of an object. However, this command may only work
9793 with certain Objective-C libraries that have a particular hook
9794 function, @code{_NSPrintForDebugger}, defined.
9795
9796 @node Fortran
9797 @subsection Fortran
9798 @cindex Fortran-specific support in @value{GDBN}
9799
9800 @value{GDBN} can be used to debug programs written in Fortran, but it
9801 currently supports only the features of Fortran 77 language.
9802
9803 @cindex trailing underscore, in Fortran symbols
9804 Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
9805 among them) append an underscore to the names of variables and
9806 functions. When you debug programs compiled by those compilers, you
9807 will need to refer to variables and functions with a trailing
9808 underscore.
9809
9810 @menu
9811 * Fortran Operators:: Fortran operators and expressions
9812 * Fortran Defaults:: Default settings for Fortran
9813 * Special Fortran Commands:: Special @value{GDBN} commands for Fortran
9814 @end menu
9815
9816 @node Fortran Operators
9817 @subsubsection Fortran Operators and Expressions
9818
9819 @cindex Fortran operators and expressions
9820
9821 Operators must be defined on values of specific types. For instance,
9822 @code{+} is defined on numbers, but not on characters or other non-
9823 arithmetic types. Operators are often defined on groups of types.
9824
9825 @table @code
9826 @item **
9827 The exponentiation operator. It raises the first operand to the power
9828 of the second one.
9829
9830 @item :
9831 The range operator. Normally used in the form of array(low:high) to
9832 represent a section of array.
9833 @end table
9834
9835 @node Fortran Defaults
9836 @subsubsection Fortran Defaults
9837
9838 @cindex Fortran Defaults
9839
9840 Fortran symbols are usually case-insensitive, so @value{GDBN} by
9841 default uses case-insensitive matches for Fortran symbols. You can
9842 change that with the @samp{set case-insensitive} command, see
9843 @ref{Symbols}, for the details.
9844
9845 @node Special Fortran Commands
9846 @subsubsection Special Fortran Commands
9847
9848 @cindex Special Fortran commands
9849
9850 @value{GDBN} has some commands to support Fortran-specific features,
9851 such as displaying common blocks.
9852
9853 @table @code
9854 @cindex @code{COMMON} blocks, Fortran
9855 @kindex info common
9856 @item info common @r{[}@var{common-name}@r{]}
9857 This command prints the values contained in the Fortran @code{COMMON}
9858 block whose name is @var{common-name}. With no argument, the names of
9859 all @code{COMMON} blocks visible at the current program location are
9860 printed.
9861 @end table
9862
9863 @node Pascal
9864 @subsection Pascal
9865
9866 @cindex Pascal support in @value{GDBN}, limitations
9867 Debugging Pascal programs which use sets, subranges, file variables, or
9868 nested functions does not currently work. @value{GDBN} does not support
9869 entering expressions, printing values, or similar features using Pascal
9870 syntax.
9871
9872 The Pascal-specific command @code{set print pascal_static-members}
9873 controls whether static members of Pascal objects are displayed.
9874 @xref{Print Settings, pascal_static-members}.
9875
9876 @node Modula-2
9877 @subsection Modula-2
9878
9879 @cindex Modula-2, @value{GDBN} support
9880
9881 The extensions made to @value{GDBN} to support Modula-2 only support
9882 output from the @sc{gnu} Modula-2 compiler (which is currently being
9883 developed). Other Modula-2 compilers are not currently supported, and
9884 attempting to debug executables produced by them is most likely
9885 to give an error as @value{GDBN} reads in the executable's symbol
9886 table.
9887
9888 @cindex expressions in Modula-2
9889 @menu
9890 * M2 Operators:: Built-in operators
9891 * Built-In Func/Proc:: Built-in functions and procedures
9892 * M2 Constants:: Modula-2 constants
9893 * M2 Types:: Modula-2 types
9894 * M2 Defaults:: Default settings for Modula-2
9895 * Deviations:: Deviations from standard Modula-2
9896 * M2 Checks:: Modula-2 type and range checks
9897 * M2 Scope:: The scope operators @code{::} and @code{.}
9898 * GDB/M2:: @value{GDBN} and Modula-2
9899 @end menu
9900
9901 @node M2 Operators
9902 @subsubsection Operators
9903 @cindex Modula-2 operators
9904
9905 Operators must be defined on values of specific types. For instance,
9906 @code{+} is defined on numbers, but not on structures. Operators are
9907 often defined on groups of types. For the purposes of Modula-2, the
9908 following definitions hold:
9909
9910 @itemize @bullet
9911
9912 @item
9913 @emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
9914 their subranges.
9915
9916 @item
9917 @emph{Character types} consist of @code{CHAR} and its subranges.
9918
9919 @item
9920 @emph{Floating-point types} consist of @code{REAL}.
9921
9922 @item
9923 @emph{Pointer types} consist of anything declared as @code{POINTER TO
9924 @var{type}}.
9925
9926 @item
9927 @emph{Scalar types} consist of all of the above.
9928
9929 @item
9930 @emph{Set types} consist of @code{SET} and @code{BITSET} types.
9931
9932 @item
9933 @emph{Boolean types} consist of @code{BOOLEAN}.
9934 @end itemize
9935
9936 @noindent
9937 The following operators are supported, and appear in order of
9938 increasing precedence:
9939
9940 @table @code
9941 @item ,
9942 Function argument or array index separator.
9943
9944 @item :=
9945 Assignment. The value of @var{var} @code{:=} @var{value} is
9946 @var{value}.
9947
9948 @item <@r{, }>
9949 Less than, greater than on integral, floating-point, or enumerated
9950 types.
9951
9952 @item <=@r{, }>=
9953 Less than or equal to, greater than or equal to
9954 on integral, floating-point and enumerated types, or set inclusion on
9955 set types. Same precedence as @code{<}.
9956
9957 @item =@r{, }<>@r{, }#
9958 Equality and two ways of expressing inequality, valid on scalar types.
9959 Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
9960 available for inequality, since @code{#} conflicts with the script
9961 comment character.
9962
9963 @item IN
9964 Set membership. Defined on set types and the types of their members.
9965 Same precedence as @code{<}.
9966
9967 @item OR
9968 Boolean disjunction. Defined on boolean types.
9969
9970 @item AND@r{, }&
9971 Boolean conjunction. Defined on boolean types.
9972
9973 @item @@
9974 The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
9975
9976 @item +@r{, }-
9977 Addition and subtraction on integral and floating-point types, or union
9978 and difference on set types.
9979
9980 @item *
9981 Multiplication on integral and floating-point types, or set intersection
9982 on set types.
9983
9984 @item /
9985 Division on floating-point types, or symmetric set difference on set
9986 types. Same precedence as @code{*}.
9987
9988 @item DIV@r{, }MOD
9989 Integer division and remainder. Defined on integral types. Same
9990 precedence as @code{*}.
9991
9992 @item -
9993 Negative. Defined on @code{INTEGER} and @code{REAL} data.
9994
9995 @item ^
9996 Pointer dereferencing. Defined on pointer types.
9997
9998 @item NOT
9999 Boolean negation. Defined on boolean types. Same precedence as
10000 @code{^}.
10001
10002 @item .
10003 @code{RECORD} field selector. Defined on @code{RECORD} data. Same
10004 precedence as @code{^}.
10005
10006 @item []
10007 Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
10008
10009 @item ()
10010 Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
10011 as @code{^}.
10012
10013 @item ::@r{, }.
10014 @value{GDBN} and Modula-2 scope operators.
10015 @end table
10016
10017 @quotation
10018 @emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
10019 treats the use of the operator @code{IN}, or the use of operators
10020 @code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
10021 @code{<=}, and @code{>=} on sets as an error.
10022 @end quotation
10023
10024
10025 @node Built-In Func/Proc
10026 @subsubsection Built-in Functions and Procedures
10027 @cindex Modula-2 built-ins
10028
10029 Modula-2 also makes available several built-in procedures and functions.
10030 In describing these, the following metavariables are used:
10031
10032 @table @var
10033
10034 @item a
10035 represents an @code{ARRAY} variable.
10036
10037 @item c
10038 represents a @code{CHAR} constant or variable.
10039
10040 @item i
10041 represents a variable or constant of integral type.
10042
10043 @item m
10044 represents an identifier that belongs to a set. Generally used in the
10045 same function with the metavariable @var{s}. The type of @var{s} should
10046 be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
10047
10048 @item n
10049 represents a variable or constant of integral or floating-point type.
10050
10051 @item r
10052 represents a variable or constant of floating-point type.
10053
10054 @item t
10055 represents a type.
10056
10057 @item v
10058 represents a variable.
10059
10060 @item x
10061 represents a variable or constant of one of many types. See the
10062 explanation of the function for details.
10063 @end table
10064
10065 All Modula-2 built-in procedures also return a result, described below.
10066
10067 @table @code
10068 @item ABS(@var{n})
10069 Returns the absolute value of @var{n}.
10070
10071 @item CAP(@var{c})
10072 If @var{c} is a lower case letter, it returns its upper case
10073 equivalent, otherwise it returns its argument.
10074
10075 @item CHR(@var{i})
10076 Returns the character whose ordinal value is @var{i}.
10077
10078 @item DEC(@var{v})
10079 Decrements the value in the variable @var{v} by one. Returns the new value.
10080
10081 @item DEC(@var{v},@var{i})
10082 Decrements the value in the variable @var{v} by @var{i}. Returns the
10083 new value.
10084
10085 @item EXCL(@var{m},@var{s})
10086 Removes the element @var{m} from the set @var{s}. Returns the new
10087 set.
10088
10089 @item FLOAT(@var{i})
10090 Returns the floating point equivalent of the integer @var{i}.
10091
10092 @item HIGH(@var{a})
10093 Returns the index of the last member of @var{a}.
10094
10095 @item INC(@var{v})
10096 Increments the value in the variable @var{v} by one. Returns the new value.
10097
10098 @item INC(@var{v},@var{i})
10099 Increments the value in the variable @var{v} by @var{i}. Returns the
10100 new value.
10101
10102 @item INCL(@var{m},@var{s})
10103 Adds the element @var{m} to the set @var{s} if it is not already
10104 there. Returns the new set.
10105
10106 @item MAX(@var{t})
10107 Returns the maximum value of the type @var{t}.
10108
10109 @item MIN(@var{t})
10110 Returns the minimum value of the type @var{t}.
10111
10112 @item ODD(@var{i})
10113 Returns boolean TRUE if @var{i} is an odd number.
10114
10115 @item ORD(@var{x})
10116 Returns the ordinal value of its argument. For example, the ordinal
10117 value of a character is its @sc{ascii} value (on machines supporting the
10118 @sc{ascii} character set). @var{x} must be of an ordered type, which include
10119 integral, character and enumerated types.
10120
10121 @item SIZE(@var{x})
10122 Returns the size of its argument. @var{x} can be a variable or a type.
10123
10124 @item TRUNC(@var{r})
10125 Returns the integral part of @var{r}.
10126
10127 @item TSIZE(@var{x})
10128 Returns the size of its argument. @var{x} can be a variable or a type.
10129
10130 @item VAL(@var{t},@var{i})
10131 Returns the member of the type @var{t} whose ordinal value is @var{i}.
10132 @end table
10133
10134 @quotation
10135 @emph{Warning:} Sets and their operations are not yet supported, so
10136 @value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
10137 an error.
10138 @end quotation
10139
10140 @cindex Modula-2 constants
10141 @node M2 Constants
10142 @subsubsection Constants
10143
10144 @value{GDBN} allows you to express the constants of Modula-2 in the following
10145 ways:
10146
10147 @itemize @bullet
10148
10149 @item
10150 Integer constants are simply a sequence of digits. When used in an
10151 expression, a constant is interpreted to be type-compatible with the
10152 rest of the expression. Hexadecimal integers are specified by a
10153 trailing @samp{H}, and octal integers by a trailing @samp{B}.
10154
10155 @item
10156 Floating point constants appear as a sequence of digits, followed by a
10157 decimal point and another sequence of digits. An optional exponent can
10158 then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
10159 @samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
10160 digits of the floating point constant must be valid decimal (base 10)
10161 digits.
10162
10163 @item
10164 Character constants consist of a single character enclosed by a pair of
10165 like quotes, either single (@code{'}) or double (@code{"}). They may
10166 also be expressed by their ordinal value (their @sc{ascii} value, usually)
10167 followed by a @samp{C}.
10168
10169 @item
10170 String constants consist of a sequence of characters enclosed by a
10171 pair of like quotes, either single (@code{'}) or double (@code{"}).
10172 Escape sequences in the style of C are also allowed. @xref{C
10173 Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
10174 sequences.
10175
10176 @item
10177 Enumerated constants consist of an enumerated identifier.
10178
10179 @item
10180 Boolean constants consist of the identifiers @code{TRUE} and
10181 @code{FALSE}.
10182
10183 @item
10184 Pointer constants consist of integral values only.
10185
10186 @item
10187 Set constants are not yet supported.
10188 @end itemize
10189
10190 @node M2 Types
10191 @subsubsection Modula-2 Types
10192 @cindex Modula-2 types
10193
10194 Currently @value{GDBN} can print the following data types in Modula-2
10195 syntax: array types, record types, set types, pointer types, procedure
10196 types, enumerated types, subrange types and base types. You can also
10197 print the contents of variables declared using these type.
10198 This section gives a number of simple source code examples together with
10199 sample @value{GDBN} sessions.
10200
10201 The first example contains the following section of code:
10202
10203 @smallexample
10204 VAR
10205 s: SET OF CHAR ;
10206 r: [20..40] ;
10207 @end smallexample
10208
10209 @noindent
10210 and you can request @value{GDBN} to interrogate the type and value of
10211 @code{r} and @code{s}.
10212
10213 @smallexample
10214 (@value{GDBP}) print s
10215 @{'A'..'C', 'Z'@}
10216 (@value{GDBP}) ptype s
10217 SET OF CHAR
10218 (@value{GDBP}) print r
10219 21
10220 (@value{GDBP}) ptype r
10221 [20..40]
10222 @end smallexample
10223
10224 @noindent
10225 Likewise if your source code declares @code{s} as:
10226
10227 @smallexample
10228 VAR
10229 s: SET ['A'..'Z'] ;
10230 @end smallexample
10231
10232 @noindent
10233 then you may query the type of @code{s} by:
10234
10235 @smallexample
10236 (@value{GDBP}) ptype s
10237 type = SET ['A'..'Z']
10238 @end smallexample
10239
10240 @noindent
10241 Note that at present you cannot interactively manipulate set
10242 expressions using the debugger.
10243
10244 The following example shows how you might declare an array in Modula-2
10245 and how you can interact with @value{GDBN} to print its type and contents:
10246
10247 @smallexample
10248 VAR
10249 s: ARRAY [-10..10] OF CHAR ;
10250 @end smallexample
10251
10252 @smallexample
10253 (@value{GDBP}) ptype s
10254 ARRAY [-10..10] OF CHAR
10255 @end smallexample
10256
10257 Note that the array handling is not yet complete and although the type
10258 is printed correctly, expression handling still assumes that all
10259 arrays have a lower bound of zero and not @code{-10} as in the example
10260 above.
10261
10262 Here are some more type related Modula-2 examples:
10263
10264 @smallexample
10265 TYPE
10266 colour = (blue, red, yellow, green) ;
10267 t = [blue..yellow] ;
10268 VAR
10269 s: t ;
10270 BEGIN
10271 s := blue ;
10272 @end smallexample
10273
10274 @noindent
10275 The @value{GDBN} interaction shows how you can query the data type
10276 and value of a variable.
10277
10278 @smallexample
10279 (@value{GDBP}) print s
10280 $1 = blue
10281 (@value{GDBP}) ptype t
10282 type = [blue..yellow]
10283 @end smallexample
10284
10285 @noindent
10286 In this example a Modula-2 array is declared and its contents
10287 displayed. Observe that the contents are written in the same way as
10288 their @code{C} counterparts.
10289
10290 @smallexample
10291 VAR
10292 s: ARRAY [1..5] OF CARDINAL ;
10293 BEGIN
10294 s[1] := 1 ;
10295 @end smallexample
10296
10297 @smallexample
10298 (@value{GDBP}) print s
10299 $1 = @{1, 0, 0, 0, 0@}
10300 (@value{GDBP}) ptype s
10301 type = ARRAY [1..5] OF CARDINAL
10302 @end smallexample
10303
10304 The Modula-2 language interface to @value{GDBN} also understands
10305 pointer types as shown in this example:
10306
10307 @smallexample
10308 VAR
10309 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
10310 BEGIN
10311 NEW(s) ;
10312 s^[1] := 1 ;
10313 @end smallexample
10314
10315 @noindent
10316 and you can request that @value{GDBN} describes the type of @code{s}.
10317
10318 @smallexample
10319 (@value{GDBP}) ptype s
10320 type = POINTER TO ARRAY [1..5] OF CARDINAL
10321 @end smallexample
10322
10323 @value{GDBN} handles compound types as we can see in this example.
10324 Here we combine array types, record types, pointer types and subrange
10325 types:
10326
10327 @smallexample
10328 TYPE
10329 foo = RECORD
10330 f1: CARDINAL ;
10331 f2: CHAR ;
10332 f3: myarray ;
10333 END ;
10334
10335 myarray = ARRAY myrange OF CARDINAL ;
10336 myrange = [-2..2] ;
10337 VAR
10338 s: POINTER TO ARRAY myrange OF foo ;
10339 @end smallexample
10340
10341 @noindent
10342 and you can ask @value{GDBN} to describe the type of @code{s} as shown
10343 below.
10344
10345 @smallexample
10346 (@value{GDBP}) ptype s
10347 type = POINTER TO ARRAY [-2..2] OF foo = RECORD
10348 f1 : CARDINAL;
10349 f2 : CHAR;
10350 f3 : ARRAY [-2..2] OF CARDINAL;
10351 END
10352 @end smallexample
10353
10354 @node M2 Defaults
10355 @subsubsection Modula-2 Defaults
10356 @cindex Modula-2 defaults
10357
10358 If type and range checking are set automatically by @value{GDBN}, they
10359 both default to @code{on} whenever the working language changes to
10360 Modula-2. This happens regardless of whether you or @value{GDBN}
10361 selected the working language.
10362
10363 If you allow @value{GDBN} to set the language automatically, then entering
10364 code compiled from a file whose name ends with @file{.mod} sets the
10365 working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
10366 Infer the Source Language}, for further details.
10367
10368 @node Deviations
10369 @subsubsection Deviations from Standard Modula-2
10370 @cindex Modula-2, deviations from
10371
10372 A few changes have been made to make Modula-2 programs easier to debug.
10373 This is done primarily via loosening its type strictness:
10374
10375 @itemize @bullet
10376 @item
10377 Unlike in standard Modula-2, pointer constants can be formed by
10378 integers. This allows you to modify pointer variables during
10379 debugging. (In standard Modula-2, the actual address contained in a
10380 pointer variable is hidden from you; it can only be modified
10381 through direct assignment to another pointer variable or expression that
10382 returned a pointer.)
10383
10384 @item
10385 C escape sequences can be used in strings and characters to represent
10386 non-printable characters. @value{GDBN} prints out strings with these
10387 escape sequences embedded. Single non-printable characters are
10388 printed using the @samp{CHR(@var{nnn})} format.
10389
10390 @item
10391 The assignment operator (@code{:=}) returns the value of its right-hand
10392 argument.
10393
10394 @item
10395 All built-in procedures both modify @emph{and} return their argument.
10396 @end itemize
10397
10398 @node M2 Checks
10399 @subsubsection Modula-2 Type and Range Checks
10400 @cindex Modula-2 checks
10401
10402 @quotation
10403 @emph{Warning:} in this release, @value{GDBN} does not yet perform type or
10404 range checking.
10405 @end quotation
10406 @c FIXME remove warning when type/range checks added
10407
10408 @value{GDBN} considers two Modula-2 variables type equivalent if:
10409
10410 @itemize @bullet
10411 @item
10412 They are of types that have been declared equivalent via a @code{TYPE
10413 @var{t1} = @var{t2}} statement
10414
10415 @item
10416 They have been declared on the same line. (Note: This is true of the
10417 @sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
10418 @end itemize
10419
10420 As long as type checking is enabled, any attempt to combine variables
10421 whose types are not equivalent is an error.
10422
10423 Range checking is done on all mathematical operations, assignment, array
10424 index bounds, and all built-in functions and procedures.
10425
10426 @node M2 Scope
10427 @subsubsection The Scope Operators @code{::} and @code{.}
10428 @cindex scope
10429 @cindex @code{.}, Modula-2 scope operator
10430 @cindex colon, doubled as scope operator
10431 @ifinfo
10432 @vindex colon-colon@r{, in Modula-2}
10433 @c Info cannot handle :: but TeX can.
10434 @end ifinfo
10435 @iftex
10436 @vindex ::@r{, in Modula-2}
10437 @end iftex
10438
10439 There are a few subtle differences between the Modula-2 scope operator
10440 (@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
10441 similar syntax:
10442
10443 @smallexample
10444
10445 @var{module} . @var{id}
10446 @var{scope} :: @var{id}
10447 @end smallexample
10448
10449 @noindent
10450 where @var{scope} is the name of a module or a procedure,
10451 @var{module} the name of a module, and @var{id} is any declared
10452 identifier within your program, except another module.
10453
10454 Using the @code{::} operator makes @value{GDBN} search the scope
10455 specified by @var{scope} for the identifier @var{id}. If it is not
10456 found in the specified scope, then @value{GDBN} searches all scopes
10457 enclosing the one specified by @var{scope}.
10458
10459 Using the @code{.} operator makes @value{GDBN} search the current scope for
10460 the identifier specified by @var{id} that was imported from the
10461 definition module specified by @var{module}. With this operator, it is
10462 an error if the identifier @var{id} was not imported from definition
10463 module @var{module}, or if @var{id} is not an identifier in
10464 @var{module}.
10465
10466 @node GDB/M2
10467 @subsubsection @value{GDBN} and Modula-2
10468
10469 Some @value{GDBN} commands have little use when debugging Modula-2 programs.
10470 Five subcommands of @code{set print} and @code{show print} apply
10471 specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
10472 @samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
10473 apply to C@t{++}, and the last to the C @code{union} type, which has no direct
10474 analogue in Modula-2.
10475
10476 The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
10477 with any language, is not useful with Modula-2. Its
10478 intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
10479 created in Modula-2 as they can in C or C@t{++}. However, because an
10480 address can be specified by an integral constant, the construct
10481 @samp{@{@var{type}@}@var{adrexp}} is still useful.
10482
10483 @cindex @code{#} in Modula-2
10484 In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
10485 interpreted as the beginning of a comment. Use @code{<>} instead.
10486
10487 @node Ada
10488 @subsection Ada
10489 @cindex Ada
10490
10491 The extensions made to @value{GDBN} for Ada only support
10492 output from the @sc{gnu} Ada (GNAT) compiler.
10493 Other Ada compilers are not currently supported, and
10494 attempting to debug executables produced by them is most likely
10495 to be difficult.
10496
10497
10498 @cindex expressions in Ada
10499 @menu
10500 * Ada Mode Intro:: General remarks on the Ada syntax
10501 and semantics supported by Ada mode
10502 in @value{GDBN}.
10503 * Omissions from Ada:: Restrictions on the Ada expression syntax.
10504 * Additions to Ada:: Extensions of the Ada expression syntax.
10505 * Stopping Before Main Program:: Debugging the program during elaboration.
10506 * Ada Glitches:: Known peculiarities of Ada mode.
10507 @end menu
10508
10509 @node Ada Mode Intro
10510 @subsubsection Introduction
10511 @cindex Ada mode, general
10512
10513 The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
10514 syntax, with some extensions.
10515 The philosophy behind the design of this subset is
10516
10517 @itemize @bullet
10518 @item
10519 That @value{GDBN} should provide basic literals and access to operations for
10520 arithmetic, dereferencing, field selection, indexing, and subprogram calls,
10521 leaving more sophisticated computations to subprograms written into the
10522 program (which therefore may be called from @value{GDBN}).
10523
10524 @item
10525 That type safety and strict adherence to Ada language restrictions
10526 are not particularly important to the @value{GDBN} user.
10527
10528 @item
10529 That brevity is important to the @value{GDBN} user.
10530 @end itemize
10531
10532 Thus, for brevity, the debugger acts as if there were
10533 implicit @code{with} and @code{use} clauses in effect for all user-written
10534 packages, making it unnecessary to fully qualify most names with
10535 their packages, regardless of context. Where this causes ambiguity,
10536 @value{GDBN} asks the user's intent.
10537
10538 The debugger will start in Ada mode if it detects an Ada main program.
10539 As for other languages, it will enter Ada mode when stopped in a program that
10540 was translated from an Ada source file.
10541
10542 While in Ada mode, you may use `@t{--}' for comments. This is useful
10543 mostly for documenting command files. The standard @value{GDBN} comment
10544 (@samp{#}) still works at the beginning of a line in Ada mode, but not in the
10545 middle (to allow based literals).
10546
10547 The debugger supports limited overloading. Given a subprogram call in which
10548 the function symbol has multiple definitions, it will use the number of
10549 actual parameters and some information about their types to attempt to narrow
10550 the set of definitions. It also makes very limited use of context, preferring
10551 procedures to functions in the context of the @code{call} command, and
10552 functions to procedures elsewhere.
10553
10554 @node Omissions from Ada
10555 @subsubsection Omissions from Ada
10556 @cindex Ada, omissions from
10557
10558 Here are the notable omissions from the subset:
10559
10560 @itemize @bullet
10561 @item
10562 Only a subset of the attributes are supported:
10563
10564 @itemize @minus
10565 @item
10566 @t{'First}, @t{'Last}, and @t{'Length}
10567 on array objects (not on types and subtypes).
10568
10569 @item
10570 @t{'Min} and @t{'Max}.
10571
10572 @item
10573 @t{'Pos} and @t{'Val}.
10574
10575 @item
10576 @t{'Tag}.
10577
10578 @item
10579 @t{'Range} on array objects (not subtypes), but only as the right
10580 operand of the membership (@code{in}) operator.
10581
10582 @item
10583 @t{'Access}, @t{'Unchecked_Access}, and
10584 @t{'Unrestricted_Access} (a GNAT extension).
10585
10586 @item
10587 @t{'Address}.
10588 @end itemize
10589
10590 @item
10591 The names in
10592 @code{Characters.Latin_1} are not available and
10593 concatenation is not implemented. Thus, escape characters in strings are
10594 not currently available.
10595
10596 @item
10597 Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
10598 equality of representations. They will generally work correctly
10599 for strings and arrays whose elements have integer or enumeration types.
10600 They may not work correctly for arrays whose element
10601 types have user-defined equality, for arrays of real values
10602 (in particular, IEEE-conformant floating point, because of negative
10603 zeroes and NaNs), and for arrays whose elements contain unused bits with
10604 indeterminate values.
10605
10606 @item
10607 The other component-by-component array operations (@code{and}, @code{or},
10608 @code{xor}, @code{not}, and relational tests other than equality)
10609 are not implemented.
10610
10611 @item
10612 @cindex array aggregates (Ada)
10613 @cindex record aggregates (Ada)
10614 @cindex aggregates (Ada)
10615 There is limited support for array and record aggregates. They are
10616 permitted only on the right sides of assignments, as in these examples:
10617
10618 @smallexample
10619 set An_Array := (1, 2, 3, 4, 5, 6)
10620 set An_Array := (1, others => 0)
10621 set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
10622 set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
10623 set A_Record := (1, "Peter", True);
10624 set A_Record := (Name => "Peter", Id => 1, Alive => True)
10625 @end smallexample
10626
10627 Changing a
10628 discriminant's value by assigning an aggregate has an
10629 undefined effect if that discriminant is used within the record.
10630 However, you can first modify discriminants by directly assigning to
10631 them (which normally would not be allowed in Ada), and then performing an
10632 aggregate assignment. For example, given a variable @code{A_Rec}
10633 declared to have a type such as:
10634
10635 @smallexample
10636 type Rec (Len : Small_Integer := 0) is record
10637 Id : Integer;
10638 Vals : IntArray (1 .. Len);
10639 end record;
10640 @end smallexample
10641
10642 you can assign a value with a different size of @code{Vals} with two
10643 assignments:
10644
10645 @smallexample
10646 set A_Rec.Len := 4
10647 set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
10648 @end smallexample
10649
10650 As this example also illustrates, @value{GDBN} is very loose about the usual
10651 rules concerning aggregates. You may leave out some of the
10652 components of an array or record aggregate (such as the @code{Len}
10653 component in the assignment to @code{A_Rec} above); they will retain their
10654 original values upon assignment. You may freely use dynamic values as
10655 indices in component associations. You may even use overlapping or
10656 redundant component associations, although which component values are
10657 assigned in such cases is not defined.
10658
10659 @item
10660 Calls to dispatching subprograms are not implemented.
10661
10662 @item
10663 The overloading algorithm is much more limited (i.e., less selective)
10664 than that of real Ada. It makes only limited use of the context in
10665 which a subexpression appears to resolve its meaning, and it is much
10666 looser in its rules for allowing type matches. As a result, some
10667 function calls will be ambiguous, and the user will be asked to choose
10668 the proper resolution.
10669
10670 @item
10671 The @code{new} operator is not implemented.
10672
10673 @item
10674 Entry calls are not implemented.
10675
10676 @item
10677 Aside from printing, arithmetic operations on the native VAX floating-point
10678 formats are not supported.
10679
10680 @item
10681 It is not possible to slice a packed array.
10682 @end itemize
10683
10684 @node Additions to Ada
10685 @subsubsection Additions to Ada
10686 @cindex Ada, deviations from
10687
10688 As it does for other languages, @value{GDBN} makes certain generic
10689 extensions to Ada (@pxref{Expressions}):
10690
10691 @itemize @bullet
10692 @item
10693 If the expression @var{E} is a variable residing in memory (typically
10694 a local variable or array element) and @var{N} is a positive integer,
10695 then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
10696 @var{N}-1 adjacent variables following it in memory as an array. In
10697 Ada, this operator is generally not necessary, since its prime use is
10698 in displaying parts of an array, and slicing will usually do this in
10699 Ada. However, there are occasional uses when debugging programs in
10700 which certain debugging information has been optimized away.
10701
10702 @item
10703 @code{@var{B}::@var{var}} means ``the variable named @var{var} that
10704 appears in function or file @var{B}.'' When @var{B} is a file name,
10705 you must typically surround it in single quotes.
10706
10707 @item
10708 The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
10709 @var{type} that appears at address @var{addr}.''
10710
10711 @item
10712 A name starting with @samp{$} is a convenience variable
10713 (@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
10714 @end itemize
10715
10716 In addition, @value{GDBN} provides a few other shortcuts and outright
10717 additions specific to Ada:
10718
10719 @itemize @bullet
10720 @item
10721 The assignment statement is allowed as an expression, returning
10722 its right-hand operand as its value. Thus, you may enter
10723
10724 @smallexample
10725 set x := y + 3
10726 print A(tmp := y + 1)
10727 @end smallexample
10728
10729 @item
10730 The semicolon is allowed as an ``operator,'' returning as its value
10731 the value of its right-hand operand.
10732 This allows, for example,
10733 complex conditional breaks:
10734
10735 @smallexample
10736 break f
10737 condition 1 (report(i); k += 1; A(k) > 100)
10738 @end smallexample
10739
10740 @item
10741 Rather than use catenation and symbolic character names to introduce special
10742 characters into strings, one may instead use a special bracket notation,
10743 which is also used to print strings. A sequence of characters of the form
10744 @samp{["@var{XX}"]} within a string or character literal denotes the
10745 (single) character whose numeric encoding is @var{XX} in hexadecimal. The
10746 sequence of characters @samp{["""]} also denotes a single quotation mark
10747 in strings. For example,
10748 @smallexample
10749 "One line.["0a"]Next line.["0a"]"
10750 @end smallexample
10751 @noindent
10752 contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
10753 after each period.
10754
10755 @item
10756 The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
10757 @t{'Max} is optional (and is ignored in any case). For example, it is valid
10758 to write
10759
10760 @smallexample
10761 print 'max(x, y)
10762 @end smallexample
10763
10764 @item
10765 When printing arrays, @value{GDBN} uses positional notation when the
10766 array has a lower bound of 1, and uses a modified named notation otherwise.
10767 For example, a one-dimensional array of three integers with a lower bound
10768 of 3 might print as
10769
10770 @smallexample
10771 (3 => 10, 17, 1)
10772 @end smallexample
10773
10774 @noindent
10775 That is, in contrast to valid Ada, only the first component has a @code{=>}
10776 clause.
10777
10778 @item
10779 You may abbreviate attributes in expressions with any unique,
10780 multi-character subsequence of
10781 their names (an exact match gets preference).
10782 For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
10783 in place of @t{a'length}.
10784
10785 @item
10786 @cindex quoting Ada internal identifiers
10787 Since Ada is case-insensitive, the debugger normally maps identifiers you type
10788 to lower case. The GNAT compiler uses upper-case characters for
10789 some of its internal identifiers, which are normally of no interest to users.
10790 For the rare occasions when you actually have to look at them,
10791 enclose them in angle brackets to avoid the lower-case mapping.
10792 For example,
10793 @smallexample
10794 @value{GDBP} print <JMPBUF_SAVE>[0]
10795 @end smallexample
10796
10797 @item
10798 Printing an object of class-wide type or dereferencing an
10799 access-to-class-wide value will display all the components of the object's
10800 specific type (as indicated by its run-time tag). Likewise, component
10801 selection on such a value will operate on the specific type of the
10802 object.
10803
10804 @end itemize
10805
10806 @node Stopping Before Main Program
10807 @subsubsection Stopping at the Very Beginning
10808
10809 @cindex breakpointing Ada elaboration code
10810 It is sometimes necessary to debug the program during elaboration, and
10811 before reaching the main procedure.
10812 As defined in the Ada Reference
10813 Manual, the elaboration code is invoked from a procedure called
10814 @code{adainit}. To run your program up to the beginning of
10815 elaboration, simply use the following two commands:
10816 @code{tbreak adainit} and @code{run}.
10817
10818 @node Ada Glitches
10819 @subsubsection Known Peculiarities of Ada Mode
10820 @cindex Ada, problems
10821
10822 Besides the omissions listed previously (@pxref{Omissions from Ada}),
10823 we know of several problems with and limitations of Ada mode in
10824 @value{GDBN},
10825 some of which will be fixed with planned future releases of the debugger
10826 and the GNU Ada compiler.
10827
10828 @itemize @bullet
10829 @item
10830 Currently, the debugger
10831 has insufficient information to determine whether certain pointers represent
10832 pointers to objects or the objects themselves.
10833 Thus, the user may have to tack an extra @code{.all} after an expression
10834 to get it printed properly.
10835
10836 @item
10837 Static constants that the compiler chooses not to materialize as objects in
10838 storage are invisible to the debugger.
10839
10840 @item
10841 Named parameter associations in function argument lists are ignored (the
10842 argument lists are treated as positional).
10843
10844 @item
10845 Many useful library packages are currently invisible to the debugger.
10846
10847 @item
10848 Fixed-point arithmetic, conversions, input, and output is carried out using
10849 floating-point arithmetic, and may give results that only approximate those on
10850 the host machine.
10851
10852 @item
10853 The type of the @t{'Address} attribute may not be @code{System.Address}.
10854
10855 @item
10856 The GNAT compiler never generates the prefix @code{Standard} for any of
10857 the standard symbols defined by the Ada language. @value{GDBN} knows about
10858 this: it will strip the prefix from names when you use it, and will never
10859 look for a name you have so qualified among local symbols, nor match against
10860 symbols in other packages or subprograms. If you have
10861 defined entities anywhere in your program other than parameters and
10862 local variables whose simple names match names in @code{Standard},
10863 GNAT's lack of qualification here can cause confusion. When this happens,
10864 you can usually resolve the confusion
10865 by qualifying the problematic names with package
10866 @code{Standard} explicitly.
10867 @end itemize
10868
10869 @node Unsupported Languages
10870 @section Unsupported Languages
10871
10872 @cindex unsupported languages
10873 @cindex minimal language
10874 In addition to the other fully-supported programming languages,
10875 @value{GDBN} also provides a pseudo-language, called @code{minimal}.
10876 It does not represent a real programming language, but provides a set
10877 of capabilities close to what the C or assembly languages provide.
10878 This should allow most simple operations to be performed while debugging
10879 an application that uses a language currently not supported by @value{GDBN}.
10880
10881 If the language is set to @code{auto}, @value{GDBN} will automatically
10882 select this language if the current frame corresponds to an unsupported
10883 language.
10884
10885 @node Symbols
10886 @chapter Examining the Symbol Table
10887
10888 The commands described in this chapter allow you to inquire about the
10889 symbols (names of variables, functions and types) defined in your
10890 program. This information is inherent in the text of your program and
10891 does not change as your program executes. @value{GDBN} finds it in your
10892 program's symbol table, in the file indicated when you started @value{GDBN}
10893 (@pxref{File Options, ,Choosing Files}), or by one of the
10894 file-management commands (@pxref{Files, ,Commands to Specify Files}).
10895
10896 @cindex symbol names
10897 @cindex names of symbols
10898 @cindex quoting names
10899 Occasionally, you may need to refer to symbols that contain unusual
10900 characters, which @value{GDBN} ordinarily treats as word delimiters. The
10901 most frequent case is in referring to static variables in other
10902 source files (@pxref{Variables,,Program Variables}). File names
10903 are recorded in object files as debugging symbols, but @value{GDBN} would
10904 ordinarily parse a typical file name, like @file{foo.c}, as the three words
10905 @samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
10906 @samp{foo.c} as a single symbol, enclose it in single quotes; for example,
10907
10908 @smallexample
10909 p 'foo.c'::x
10910 @end smallexample
10911
10912 @noindent
10913 looks up the value of @code{x} in the scope of the file @file{foo.c}.
10914
10915 @table @code
10916 @cindex case-insensitive symbol names
10917 @cindex case sensitivity in symbol names
10918 @kindex set case-sensitive
10919 @item set case-sensitive on
10920 @itemx set case-sensitive off
10921 @itemx set case-sensitive auto
10922 Normally, when @value{GDBN} looks up symbols, it matches their names
10923 with case sensitivity determined by the current source language.
10924 Occasionally, you may wish to control that. The command @code{set
10925 case-sensitive} lets you do that by specifying @code{on} for
10926 case-sensitive matches or @code{off} for case-insensitive ones. If
10927 you specify @code{auto}, case sensitivity is reset to the default
10928 suitable for the source language. The default is case-sensitive
10929 matches for all languages except for Fortran, for which the default is
10930 case-insensitive matches.
10931
10932 @kindex show case-sensitive
10933 @item show case-sensitive
10934 This command shows the current setting of case sensitivity for symbols
10935 lookups.
10936
10937 @kindex info address
10938 @cindex address of a symbol
10939 @item info address @var{symbol}
10940 Describe where the data for @var{symbol} is stored. For a register
10941 variable, this says which register it is kept in. For a non-register
10942 local variable, this prints the stack-frame offset at which the variable
10943 is always stored.
10944
10945 Note the contrast with @samp{print &@var{symbol}}, which does not work
10946 at all for a register variable, and for a stack local variable prints
10947 the exact address of the current instantiation of the variable.
10948
10949 @kindex info symbol
10950 @cindex symbol from address
10951 @cindex closest symbol and offset for an address
10952 @item info symbol @var{addr}
10953 Print the name of a symbol which is stored at the address @var{addr}.
10954 If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
10955 nearest symbol and an offset from it:
10956
10957 @smallexample
10958 (@value{GDBP}) info symbol 0x54320
10959 _initialize_vx + 396 in section .text
10960 @end smallexample
10961
10962 @noindent
10963 This is the opposite of the @code{info address} command. You can use
10964 it to find out the name of a variable or a function given its address.
10965
10966 @kindex whatis
10967 @item whatis [@var{arg}]
10968 Print the data type of @var{arg}, which can be either an expression or
10969 a data type. With no argument, print the data type of @code{$}, the
10970 last value in the value history. If @var{arg} is an expression, it is
10971 not actually evaluated, and any side-effecting operations (such as
10972 assignments or function calls) inside it do not take place. If
10973 @var{arg} is a type name, it may be the name of a type or typedef, or
10974 for C code it may have the form @samp{class @var{class-name}},
10975 @samp{struct @var{struct-tag}}, @samp{union @var{union-tag}} or
10976 @samp{enum @var{enum-tag}}.
10977 @xref{Expressions, ,Expressions}.
10978
10979 @kindex ptype
10980 @item ptype [@var{arg}]
10981 @code{ptype} accepts the same arguments as @code{whatis}, but prints a
10982 detailed description of the type, instead of just the name of the type.
10983 @xref{Expressions, ,Expressions}.
10984
10985 For example, for this variable declaration:
10986
10987 @smallexample
10988 struct complex @{double real; double imag;@} v;
10989 @end smallexample
10990
10991 @noindent
10992 the two commands give this output:
10993
10994 @smallexample
10995 @group
10996 (@value{GDBP}) whatis v
10997 type = struct complex
10998 (@value{GDBP}) ptype v
10999 type = struct complex @{
11000 double real;
11001 double imag;
11002 @}
11003 @end group
11004 @end smallexample
11005
11006 @noindent
11007 As with @code{whatis}, using @code{ptype} without an argument refers to
11008 the type of @code{$}, the last value in the value history.
11009
11010 @cindex incomplete type
11011 Sometimes, programs use opaque data types or incomplete specifications
11012 of complex data structure. If the debug information included in the
11013 program does not allow @value{GDBN} to display a full declaration of
11014 the data type, it will say @samp{<incomplete type>}. For example,
11015 given these declarations:
11016
11017 @smallexample
11018 struct foo;
11019 struct foo *fooptr;
11020 @end smallexample
11021
11022 @noindent
11023 but no definition for @code{struct foo} itself, @value{GDBN} will say:
11024
11025 @smallexample
11026 (@value{GDBP}) ptype foo
11027 $1 = <incomplete type>
11028 @end smallexample
11029
11030 @noindent
11031 ``Incomplete type'' is C terminology for data types that are not
11032 completely specified.
11033
11034 @kindex info types
11035 @item info types @var{regexp}
11036 @itemx info types
11037 Print a brief description of all types whose names match the regular
11038 expression @var{regexp} (or all types in your program, if you supply
11039 no argument). Each complete typename is matched as though it were a
11040 complete line; thus, @samp{i type value} gives information on all
11041 types in your program whose names include the string @code{value}, but
11042 @samp{i type ^value$} gives information only on types whose complete
11043 name is @code{value}.
11044
11045 This command differs from @code{ptype} in two ways: first, like
11046 @code{whatis}, it does not print a detailed description; second, it
11047 lists all source files where a type is defined.
11048
11049 @kindex info scope
11050 @cindex local variables
11051 @item info scope @var{location}
11052 List all the variables local to a particular scope. This command
11053 accepts a @var{location} argument---a function name, a source line, or
11054 an address preceded by a @samp{*}, and prints all the variables local
11055 to the scope defined by that location. (@xref{Specify Location}, for
11056 details about supported forms of @var{location}.) For example:
11057
11058 @smallexample
11059 (@value{GDBP}) @b{info scope command_line_handler}
11060 Scope for command_line_handler:
11061 Symbol rl is an argument at stack/frame offset 8, length 4.
11062 Symbol linebuffer is in static storage at address 0x150a18, length 4.
11063 Symbol linelength is in static storage at address 0x150a1c, length 4.
11064 Symbol p is a local variable in register $esi, length 4.
11065 Symbol p1 is a local variable in register $ebx, length 4.
11066 Symbol nline is a local variable in register $edx, length 4.
11067 Symbol repeat is a local variable at frame offset -8, length 4.
11068 @end smallexample
11069
11070 @noindent
11071 This command is especially useful for determining what data to collect
11072 during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
11073 collect}.
11074
11075 @kindex info source
11076 @item info source
11077 Show information about the current source file---that is, the source file for
11078 the function containing the current point of execution:
11079 @itemize @bullet
11080 @item
11081 the name of the source file, and the directory containing it,
11082 @item
11083 the directory it was compiled in,
11084 @item
11085 its length, in lines,
11086 @item
11087 which programming language it is written in,
11088 @item
11089 whether the executable includes debugging information for that file, and
11090 if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
11091 @item
11092 whether the debugging information includes information about
11093 preprocessor macros.
11094 @end itemize
11095
11096
11097 @kindex info sources
11098 @item info sources
11099 Print the names of all source files in your program for which there is
11100 debugging information, organized into two lists: files whose symbols
11101 have already been read, and files whose symbols will be read when needed.
11102
11103 @kindex info functions
11104 @item info functions
11105 Print the names and data types of all defined functions.
11106
11107 @item info functions @var{regexp}
11108 Print the names and data types of all defined functions
11109 whose names contain a match for regular expression @var{regexp}.
11110 Thus, @samp{info fun step} finds all functions whose names
11111 include @code{step}; @samp{info fun ^step} finds those whose names
11112 start with @code{step}. If a function name contains characters
11113 that conflict with the regular expression language (e.g.@:
11114 @samp{operator*()}), they may be quoted with a backslash.
11115
11116 @kindex info variables
11117 @item info variables
11118 Print the names and data types of all variables that are declared
11119 outside of functions (i.e.@: excluding local variables).
11120
11121 @item info variables @var{regexp}
11122 Print the names and data types of all variables (except for local
11123 variables) whose names contain a match for regular expression
11124 @var{regexp}.
11125
11126 @kindex info classes
11127 @cindex Objective-C, classes and selectors
11128 @item info classes
11129 @itemx info classes @var{regexp}
11130 Display all Objective-C classes in your program, or
11131 (with the @var{regexp} argument) all those matching a particular regular
11132 expression.
11133
11134 @kindex info selectors
11135 @item info selectors
11136 @itemx info selectors @var{regexp}
11137 Display all Objective-C selectors in your program, or
11138 (with the @var{regexp} argument) all those matching a particular regular
11139 expression.
11140
11141 @ignore
11142 This was never implemented.
11143 @kindex info methods
11144 @item info methods
11145 @itemx info methods @var{regexp}
11146 The @code{info methods} command permits the user to examine all defined
11147 methods within C@t{++} program, or (with the @var{regexp} argument) a
11148 specific set of methods found in the various C@t{++} classes. Many
11149 C@t{++} classes provide a large number of methods. Thus, the output
11150 from the @code{ptype} command can be overwhelming and hard to use. The
11151 @code{info-methods} command filters the methods, printing only those
11152 which match the regular-expression @var{regexp}.
11153 @end ignore
11154
11155 @cindex reloading symbols
11156 Some systems allow individual object files that make up your program to
11157 be replaced without stopping and restarting your program. For example,
11158 in VxWorks you can simply recompile a defective object file and keep on
11159 running. If you are running on one of these systems, you can allow
11160 @value{GDBN} to reload the symbols for automatically relinked modules:
11161
11162 @table @code
11163 @kindex set symbol-reloading
11164 @item set symbol-reloading on
11165 Replace symbol definitions for the corresponding source file when an
11166 object file with a particular name is seen again.
11167
11168 @item set symbol-reloading off
11169 Do not replace symbol definitions when encountering object files of the
11170 same name more than once. This is the default state; if you are not
11171 running on a system that permits automatic relinking of modules, you
11172 should leave @code{symbol-reloading} off, since otherwise @value{GDBN}
11173 may discard symbols when linking large programs, that may contain
11174 several modules (from different directories or libraries) with the same
11175 name.
11176
11177 @kindex show symbol-reloading
11178 @item show symbol-reloading
11179 Show the current @code{on} or @code{off} setting.
11180 @end table
11181
11182 @cindex opaque data types
11183 @kindex set opaque-type-resolution
11184 @item set opaque-type-resolution on
11185 Tell @value{GDBN} to resolve opaque types. An opaque type is a type
11186 declared as a pointer to a @code{struct}, @code{class}, or
11187 @code{union}---for example, @code{struct MyType *}---that is used in one
11188 source file although the full declaration of @code{struct MyType} is in
11189 another source file. The default is on.
11190
11191 A change in the setting of this subcommand will not take effect until
11192 the next time symbols for a file are loaded.
11193
11194 @item set opaque-type-resolution off
11195 Tell @value{GDBN} not to resolve opaque types. In this case, the type
11196 is printed as follows:
11197 @smallexample
11198 @{<no data fields>@}
11199 @end smallexample
11200
11201 @kindex show opaque-type-resolution
11202 @item show opaque-type-resolution
11203 Show whether opaque types are resolved or not.
11204
11205 @kindex maint print symbols
11206 @cindex symbol dump
11207 @kindex maint print psymbols
11208 @cindex partial symbol dump
11209 @item maint print symbols @var{filename}
11210 @itemx maint print psymbols @var{filename}
11211 @itemx maint print msymbols @var{filename}
11212 Write a dump of debugging symbol data into the file @var{filename}.
11213 These commands are used to debug the @value{GDBN} symbol-reading code. Only
11214 symbols with debugging data are included. If you use @samp{maint print
11215 symbols}, @value{GDBN} includes all the symbols for which it has already
11216 collected full details: that is, @var{filename} reflects symbols for
11217 only those files whose symbols @value{GDBN} has read. You can use the
11218 command @code{info sources} to find out which files these are. If you
11219 use @samp{maint print psymbols} instead, the dump shows information about
11220 symbols that @value{GDBN} only knows partially---that is, symbols defined in
11221 files that @value{GDBN} has skimmed, but not yet read completely. Finally,
11222 @samp{maint print msymbols} dumps just the minimal symbol information
11223 required for each object file from which @value{GDBN} has read some symbols.
11224 @xref{Files, ,Commands to Specify Files}, for a discussion of how
11225 @value{GDBN} reads symbols (in the description of @code{symbol-file}).
11226
11227 @kindex maint info symtabs
11228 @kindex maint info psymtabs
11229 @cindex listing @value{GDBN}'s internal symbol tables
11230 @cindex symbol tables, listing @value{GDBN}'s internal
11231 @cindex full symbol tables, listing @value{GDBN}'s internal
11232 @cindex partial symbol tables, listing @value{GDBN}'s internal
11233 @item maint info symtabs @r{[} @var{regexp} @r{]}
11234 @itemx maint info psymtabs @r{[} @var{regexp} @r{]}
11235
11236 List the @code{struct symtab} or @code{struct partial_symtab}
11237 structures whose names match @var{regexp}. If @var{regexp} is not
11238 given, list them all. The output includes expressions which you can
11239 copy into a @value{GDBN} debugging this one to examine a particular
11240 structure in more detail. For example:
11241
11242 @smallexample
11243 (@value{GDBP}) maint info psymtabs dwarf2read
11244 @{ objfile /home/gnu/build/gdb/gdb
11245 ((struct objfile *) 0x82e69d0)
11246 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
11247 ((struct partial_symtab *) 0x8474b10)
11248 readin no
11249 fullname (null)
11250 text addresses 0x814d3c8 -- 0x8158074
11251 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
11252 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
11253 dependencies (none)
11254 @}
11255 @}
11256 (@value{GDBP}) maint info symtabs
11257 (@value{GDBP})
11258 @end smallexample
11259 @noindent
11260 We see that there is one partial symbol table whose filename contains
11261 the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
11262 and we see that @value{GDBN} has not read in any symtabs yet at all.
11263 If we set a breakpoint on a function, that will cause @value{GDBN} to
11264 read the symtab for the compilation unit containing that function:
11265
11266 @smallexample
11267 (@value{GDBP}) break dwarf2_psymtab_to_symtab
11268 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
11269 line 1574.
11270 (@value{GDBP}) maint info symtabs
11271 @{ objfile /home/gnu/build/gdb/gdb
11272 ((struct objfile *) 0x82e69d0)
11273 @{ symtab /home/gnu/src/gdb/dwarf2read.c
11274 ((struct symtab *) 0x86c1f38)
11275 dirname (null)
11276 fullname (null)
11277 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
11278 linetable ((struct linetable *) 0x8370fa0)
11279 debugformat DWARF 2
11280 @}
11281 @}
11282 (@value{GDBP})
11283 @end smallexample
11284 @end table
11285
11286
11287 @node Altering
11288 @chapter Altering Execution
11289
11290 Once you think you have found an error in your program, you might want to
11291 find out for certain whether correcting the apparent error would lead to
11292 correct results in the rest of the run. You can find the answer by
11293 experiment, using the @value{GDBN} features for altering execution of the
11294 program.
11295
11296 For example, you can store new values into variables or memory
11297 locations, give your program a signal, restart it at a different
11298 address, or even return prematurely from a function.
11299
11300 @menu
11301 * Assignment:: Assignment to variables
11302 * Jumping:: Continuing at a different address
11303 * Signaling:: Giving your program a signal
11304 * Returning:: Returning from a function
11305 * Calling:: Calling your program's functions
11306 * Patching:: Patching your program
11307 @end menu
11308
11309 @node Assignment
11310 @section Assignment to Variables
11311
11312 @cindex assignment
11313 @cindex setting variables
11314 To alter the value of a variable, evaluate an assignment expression.
11315 @xref{Expressions, ,Expressions}. For example,
11316
11317 @smallexample
11318 print x=4
11319 @end smallexample
11320
11321 @noindent
11322 stores the value 4 into the variable @code{x}, and then prints the
11323 value of the assignment expression (which is 4).
11324 @xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
11325 information on operators in supported languages.
11326
11327 @kindex set variable
11328 @cindex variables, setting
11329 If you are not interested in seeing the value of the assignment, use the
11330 @code{set} command instead of the @code{print} command. @code{set} is
11331 really the same as @code{print} except that the expression's value is
11332 not printed and is not put in the value history (@pxref{Value History,
11333 ,Value History}). The expression is evaluated only for its effects.
11334
11335 If the beginning of the argument string of the @code{set} command
11336 appears identical to a @code{set} subcommand, use the @code{set
11337 variable} command instead of just @code{set}. This command is identical
11338 to @code{set} except for its lack of subcommands. For example, if your
11339 program has a variable @code{width}, you get an error if you try to set
11340 a new value with just @samp{set width=13}, because @value{GDBN} has the
11341 command @code{set width}:
11342
11343 @smallexample
11344 (@value{GDBP}) whatis width
11345 type = double
11346 (@value{GDBP}) p width
11347 $4 = 13
11348 (@value{GDBP}) set width=47
11349 Invalid syntax in expression.
11350 @end smallexample
11351
11352 @noindent
11353 The invalid expression, of course, is @samp{=47}. In
11354 order to actually set the program's variable @code{width}, use
11355
11356 @smallexample
11357 (@value{GDBP}) set var width=47
11358 @end smallexample
11359
11360 Because the @code{set} command has many subcommands that can conflict
11361 with the names of program variables, it is a good idea to use the
11362 @code{set variable} command instead of just @code{set}. For example, if
11363 your program has a variable @code{g}, you run into problems if you try
11364 to set a new value with just @samp{set g=4}, because @value{GDBN} has
11365 the command @code{set gnutarget}, abbreviated @code{set g}:
11366
11367 @smallexample
11368 @group
11369 (@value{GDBP}) whatis g
11370 type = double
11371 (@value{GDBP}) p g
11372 $1 = 1
11373 (@value{GDBP}) set g=4
11374 (@value{GDBP}) p g
11375 $2 = 1
11376 (@value{GDBP}) r
11377 The program being debugged has been started already.
11378 Start it from the beginning? (y or n) y
11379 Starting program: /home/smith/cc_progs/a.out
11380 "/home/smith/cc_progs/a.out": can't open to read symbols:
11381 Invalid bfd target.
11382 (@value{GDBP}) show g
11383 The current BFD target is "=4".
11384 @end group
11385 @end smallexample
11386
11387 @noindent
11388 The program variable @code{g} did not change, and you silently set the
11389 @code{gnutarget} to an invalid value. In order to set the variable
11390 @code{g}, use
11391
11392 @smallexample
11393 (@value{GDBP}) set var g=4
11394 @end smallexample
11395
11396 @value{GDBN} allows more implicit conversions in assignments than C; you can
11397 freely store an integer value into a pointer variable or vice versa,
11398 and you can convert any structure to any other structure that is the
11399 same length or shorter.
11400 @comment FIXME: how do structs align/pad in these conversions?
11401 @comment /doc@cygnus.com 18dec1990
11402
11403 To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
11404 construct to generate a value of specified type at a specified address
11405 (@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
11406 to memory location @code{0x83040} as an integer (which implies a certain size
11407 and representation in memory), and
11408
11409 @smallexample
11410 set @{int@}0x83040 = 4
11411 @end smallexample
11412
11413 @noindent
11414 stores the value 4 into that memory location.
11415
11416 @node Jumping
11417 @section Continuing at a Different Address
11418
11419 Ordinarily, when you continue your program, you do so at the place where
11420 it stopped, with the @code{continue} command. You can instead continue at
11421 an address of your own choosing, with the following commands:
11422
11423 @table @code
11424 @kindex jump
11425 @item jump @var{linespec}
11426 @itemx jump @var{location}
11427 Resume execution at line @var{linespec} or at address given by
11428 @var{location}. Execution stops again immediately if there is a
11429 breakpoint there. @xref{Specify Location}, for a description of the
11430 different forms of @var{linespec} and @var{location}. It is common
11431 practice to use the @code{tbreak} command in conjunction with
11432 @code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
11433
11434 The @code{jump} command does not change the current stack frame, or
11435 the stack pointer, or the contents of any memory location or any
11436 register other than the program counter. If line @var{linespec} is in
11437 a different function from the one currently executing, the results may
11438 be bizarre if the two functions expect different patterns of arguments or
11439 of local variables. For this reason, the @code{jump} command requests
11440 confirmation if the specified line is not in the function currently
11441 executing. However, even bizarre results are predictable if you are
11442 well acquainted with the machine-language code of your program.
11443 @end table
11444
11445 @c Doesn't work on HP-UX; have to set $pcoqh and $pcoqt.
11446 On many systems, you can get much the same effect as the @code{jump}
11447 command by storing a new value into the register @code{$pc}. The
11448 difference is that this does not start your program running; it only
11449 changes the address of where it @emph{will} run when you continue. For
11450 example,
11451
11452 @smallexample
11453 set $pc = 0x485
11454 @end smallexample
11455
11456 @noindent
11457 makes the next @code{continue} command or stepping command execute at
11458 address @code{0x485}, rather than at the address where your program stopped.
11459 @xref{Continuing and Stepping, ,Continuing and Stepping}.
11460
11461 The most common occasion to use the @code{jump} command is to back
11462 up---perhaps with more breakpoints set---over a portion of a program
11463 that has already executed, in order to examine its execution in more
11464 detail.
11465
11466 @c @group
11467 @node Signaling
11468 @section Giving your Program a Signal
11469 @cindex deliver a signal to a program
11470
11471 @table @code
11472 @kindex signal
11473 @item signal @var{signal}
11474 Resume execution where your program stopped, but immediately give it the
11475 signal @var{signal}. @var{signal} can be the name or the number of a
11476 signal. For example, on many systems @code{signal 2} and @code{signal
11477 SIGINT} are both ways of sending an interrupt signal.
11478
11479 Alternatively, if @var{signal} is zero, continue execution without
11480 giving a signal. This is useful when your program stopped on account of
11481 a signal and would ordinary see the signal when resumed with the
11482 @code{continue} command; @samp{signal 0} causes it to resume without a
11483 signal.
11484
11485 @code{signal} does not repeat when you press @key{RET} a second time
11486 after executing the command.
11487 @end table
11488 @c @end group
11489
11490 Invoking the @code{signal} command is not the same as invoking the
11491 @code{kill} utility from the shell. Sending a signal with @code{kill}
11492 causes @value{GDBN} to decide what to do with the signal depending on
11493 the signal handling tables (@pxref{Signals}). The @code{signal} command
11494 passes the signal directly to your program.
11495
11496
11497 @node Returning
11498 @section Returning from a Function
11499
11500 @table @code
11501 @cindex returning from a function
11502 @kindex return
11503 @item return
11504 @itemx return @var{expression}
11505 You can cancel execution of a function call with the @code{return}
11506 command. If you give an
11507 @var{expression} argument, its value is used as the function's return
11508 value.
11509 @end table
11510
11511 When you use @code{return}, @value{GDBN} discards the selected stack frame
11512 (and all frames within it). You can think of this as making the
11513 discarded frame return prematurely. If you wish to specify a value to
11514 be returned, give that value as the argument to @code{return}.
11515
11516 This pops the selected stack frame (@pxref{Selection, ,Selecting a
11517 Frame}), and any other frames inside of it, leaving its caller as the
11518 innermost remaining frame. That frame becomes selected. The
11519 specified value is stored in the registers used for returning values
11520 of functions.
11521
11522 The @code{return} command does not resume execution; it leaves the
11523 program stopped in the state that would exist if the function had just
11524 returned. In contrast, the @code{finish} command (@pxref{Continuing
11525 and Stepping, ,Continuing and Stepping}) resumes execution until the
11526 selected stack frame returns naturally.
11527
11528 @node Calling
11529 @section Calling Program Functions
11530
11531 @table @code
11532 @cindex calling functions
11533 @cindex inferior functions, calling
11534 @item print @var{expr}
11535 Evaluate the expression @var{expr} and display the resulting value.
11536 @var{expr} may include calls to functions in the program being
11537 debugged.
11538
11539 @kindex call
11540 @item call @var{expr}
11541 Evaluate the expression @var{expr} without displaying @code{void}
11542 returned values.
11543
11544 You can use this variant of the @code{print} command if you want to
11545 execute a function from your program that does not return anything
11546 (a.k.a.@: @dfn{a void function}), but without cluttering the output
11547 with @code{void} returned values that @value{GDBN} will otherwise
11548 print. If the result is not void, it is printed and saved in the
11549 value history.
11550 @end table
11551
11552 It is possible for the function you call via the @code{print} or
11553 @code{call} command to generate a signal (e.g., if there's a bug in
11554 the function, or if you passed it incorrect arguments). What happens
11555 in that case is controlled by the @code{set unwindonsignal} command.
11556
11557 @table @code
11558 @item set unwindonsignal
11559 @kindex set unwindonsignal
11560 @cindex unwind stack in called functions
11561 @cindex call dummy stack unwinding
11562 Set unwinding of the stack if a signal is received while in a function
11563 that @value{GDBN} called in the program being debugged. If set to on,
11564 @value{GDBN} unwinds the stack it created for the call and restores
11565 the context to what it was before the call. If set to off (the
11566 default), @value{GDBN} stops in the frame where the signal was
11567 received.
11568
11569 @item show unwindonsignal
11570 @kindex show unwindonsignal
11571 Show the current setting of stack unwinding in the functions called by
11572 @value{GDBN}.
11573 @end table
11574
11575 @cindex weak alias functions
11576 Sometimes, a function you wish to call is actually a @dfn{weak alias}
11577 for another function. In such case, @value{GDBN} might not pick up
11578 the type information, including the types of the function arguments,
11579 which causes @value{GDBN} to call the inferior function incorrectly.
11580 As a result, the called function will function erroneously and may
11581 even crash. A solution to that is to use the name of the aliased
11582 function instead.
11583
11584 @node Patching
11585 @section Patching Programs
11586
11587 @cindex patching binaries
11588 @cindex writing into executables
11589 @cindex writing into corefiles
11590
11591 By default, @value{GDBN} opens the file containing your program's
11592 executable code (or the corefile) read-only. This prevents accidental
11593 alterations to machine code; but it also prevents you from intentionally
11594 patching your program's binary.
11595
11596 If you'd like to be able to patch the binary, you can specify that
11597 explicitly with the @code{set write} command. For example, you might
11598 want to turn on internal debugging flags, or even to make emergency
11599 repairs.
11600
11601 @table @code
11602 @kindex set write
11603 @item set write on
11604 @itemx set write off
11605 If you specify @samp{set write on}, @value{GDBN} opens executable and
11606 core files for both reading and writing; if you specify @samp{set write
11607 off} (the default), @value{GDBN} opens them read-only.
11608
11609 If you have already loaded a file, you must load it again (using the
11610 @code{exec-file} or @code{core-file} command) after changing @code{set
11611 write}, for your new setting to take effect.
11612
11613 @item show write
11614 @kindex show write
11615 Display whether executable files and core files are opened for writing
11616 as well as reading.
11617 @end table
11618
11619 @node GDB Files
11620 @chapter @value{GDBN} Files
11621
11622 @value{GDBN} needs to know the file name of the program to be debugged,
11623 both in order to read its symbol table and in order to start your
11624 program. To debug a core dump of a previous run, you must also tell
11625 @value{GDBN} the name of the core dump file.
11626
11627 @menu
11628 * Files:: Commands to specify files
11629 * Separate Debug Files:: Debugging information in separate files
11630 * Symbol Errors:: Errors reading symbol files
11631 @end menu
11632
11633 @node Files
11634 @section Commands to Specify Files
11635
11636 @cindex symbol table
11637 @cindex core dump file
11638
11639 You may want to specify executable and core dump file names. The usual
11640 way to do this is at start-up time, using the arguments to
11641 @value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
11642 Out of @value{GDBN}}).
11643
11644 Occasionally it is necessary to change to a different file during a
11645 @value{GDBN} session. Or you may run @value{GDBN} and forget to
11646 specify a file you want to use. Or you are debugging a remote target
11647 via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
11648 Program}). In these situations the @value{GDBN} commands to specify
11649 new files are useful.
11650
11651 @table @code
11652 @cindex executable file
11653 @kindex file
11654 @item file @var{filename}
11655 Use @var{filename} as the program to be debugged. It is read for its
11656 symbols and for the contents of pure memory. It is also the program
11657 executed when you use the @code{run} command. If you do not specify a
11658 directory and the file is not found in the @value{GDBN} working directory,
11659 @value{GDBN} uses the environment variable @code{PATH} as a list of
11660 directories to search, just as the shell does when looking for a program
11661 to run. You can change the value of this variable, for both @value{GDBN}
11662 and your program, using the @code{path} command.
11663
11664 @cindex unlinked object files
11665 @cindex patching object files
11666 You can load unlinked object @file{.o} files into @value{GDBN} using
11667 the @code{file} command. You will not be able to ``run'' an object
11668 file, but you can disassemble functions and inspect variables. Also,
11669 if the underlying BFD functionality supports it, you could use
11670 @kbd{gdb -write} to patch object files using this technique. Note
11671 that @value{GDBN} can neither interpret nor modify relocations in this
11672 case, so branches and some initialized variables will appear to go to
11673 the wrong place. But this feature is still handy from time to time.
11674
11675 @item file
11676 @code{file} with no argument makes @value{GDBN} discard any information it
11677 has on both executable file and the symbol table.
11678
11679 @kindex exec-file
11680 @item exec-file @r{[} @var{filename} @r{]}
11681 Specify that the program to be run (but not the symbol table) is found
11682 in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
11683 if necessary to locate your program. Omitting @var{filename} means to
11684 discard information on the executable file.
11685
11686 @kindex symbol-file
11687 @item symbol-file @r{[} @var{filename} @r{]}
11688 Read symbol table information from file @var{filename}. @code{PATH} is
11689 searched when necessary. Use the @code{file} command to get both symbol
11690 table and program to run from the same file.
11691
11692 @code{symbol-file} with no argument clears out @value{GDBN} information on your
11693 program's symbol table.
11694
11695 The @code{symbol-file} command causes @value{GDBN} to forget the contents of
11696 some breakpoints and auto-display expressions. This is because they may
11697 contain pointers to the internal data recording symbols and data types,
11698 which are part of the old symbol table data being discarded inside
11699 @value{GDBN}.
11700
11701 @code{symbol-file} does not repeat if you press @key{RET} again after
11702 executing it once.
11703
11704 When @value{GDBN} is configured for a particular environment, it
11705 understands debugging information in whatever format is the standard
11706 generated for that environment; you may use either a @sc{gnu} compiler, or
11707 other compilers that adhere to the local conventions.
11708 Best results are usually obtained from @sc{gnu} compilers; for example,
11709 using @code{@value{NGCC}} you can generate debugging information for
11710 optimized code.
11711
11712 For most kinds of object files, with the exception of old SVR3 systems
11713 using COFF, the @code{symbol-file} command does not normally read the
11714 symbol table in full right away. Instead, it scans the symbol table
11715 quickly to find which source files and which symbols are present. The
11716 details are read later, one source file at a time, as they are needed.
11717
11718 The purpose of this two-stage reading strategy is to make @value{GDBN}
11719 start up faster. For the most part, it is invisible except for
11720 occasional pauses while the symbol table details for a particular source
11721 file are being read. (The @code{set verbose} command can turn these
11722 pauses into messages if desired. @xref{Messages/Warnings, ,Optional
11723 Warnings and Messages}.)
11724
11725 We have not implemented the two-stage strategy for COFF yet. When the
11726 symbol table is stored in COFF format, @code{symbol-file} reads the
11727 symbol table data in full right away. Note that ``stabs-in-COFF''
11728 still does the two-stage strategy, since the debug info is actually
11729 in stabs format.
11730
11731 @kindex readnow
11732 @cindex reading symbols immediately
11733 @cindex symbols, reading immediately
11734 @item symbol-file @var{filename} @r{[} -readnow @r{]}
11735 @itemx file @var{filename} @r{[} -readnow @r{]}
11736 You can override the @value{GDBN} two-stage strategy for reading symbol
11737 tables by using the @samp{-readnow} option with any of the commands that
11738 load symbol table information, if you want to be sure @value{GDBN} has the
11739 entire symbol table available.
11740
11741 @c FIXME: for now no mention of directories, since this seems to be in
11742 @c flux. 13mar1992 status is that in theory GDB would look either in
11743 @c current dir or in same dir as myprog; but issues like competing
11744 @c GDB's, or clutter in system dirs, mean that in practice right now
11745 @c only current dir is used. FFish says maybe a special GDB hierarchy
11746 @c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
11747 @c files.
11748
11749 @kindex core-file
11750 @item core-file @r{[}@var{filename}@r{]}
11751 @itemx core
11752 Specify the whereabouts of a core dump file to be used as the ``contents
11753 of memory''. Traditionally, core files contain only some parts of the
11754 address space of the process that generated them; @value{GDBN} can access the
11755 executable file itself for other parts.
11756
11757 @code{core-file} with no argument specifies that no core file is
11758 to be used.
11759
11760 Note that the core file is ignored when your program is actually running
11761 under @value{GDBN}. So, if you have been running your program and you
11762 wish to debug a core file instead, you must kill the subprocess in which
11763 the program is running. To do this, use the @code{kill} command
11764 (@pxref{Kill Process, ,Killing the Child Process}).
11765
11766 @kindex add-symbol-file
11767 @cindex dynamic linking
11768 @item add-symbol-file @var{filename} @var{address}
11769 @itemx add-symbol-file @var{filename} @var{address} @r{[} -readnow @r{]}
11770 @itemx add-symbol-file @var{filename} @r{-s}@var{section} @var{address} @dots{}
11771 The @code{add-symbol-file} command reads additional symbol table
11772 information from the file @var{filename}. You would use this command
11773 when @var{filename} has been dynamically loaded (by some other means)
11774 into the program that is running. @var{address} should be the memory
11775 address at which the file has been loaded; @value{GDBN} cannot figure
11776 this out for itself. You can additionally specify an arbitrary number
11777 of @samp{@r{-s}@var{section} @var{address}} pairs, to give an explicit
11778 section name and base address for that section. You can specify any
11779 @var{address} as an expression.
11780
11781 The symbol table of the file @var{filename} is added to the symbol table
11782 originally read with the @code{symbol-file} command. You can use the
11783 @code{add-symbol-file} command any number of times; the new symbol data
11784 thus read keeps adding to the old. To discard all old symbol data
11785 instead, use the @code{symbol-file} command without any arguments.
11786
11787 @cindex relocatable object files, reading symbols from
11788 @cindex object files, relocatable, reading symbols from
11789 @cindex reading symbols from relocatable object files
11790 @cindex symbols, reading from relocatable object files
11791 @cindex @file{.o} files, reading symbols from
11792 Although @var{filename} is typically a shared library file, an
11793 executable file, or some other object file which has been fully
11794 relocated for loading into a process, you can also load symbolic
11795 information from relocatable @file{.o} files, as long as:
11796
11797 @itemize @bullet
11798 @item
11799 the file's symbolic information refers only to linker symbols defined in
11800 that file, not to symbols defined by other object files,
11801 @item
11802 every section the file's symbolic information refers to has actually
11803 been loaded into the inferior, as it appears in the file, and
11804 @item
11805 you can determine the address at which every section was loaded, and
11806 provide these to the @code{add-symbol-file} command.
11807 @end itemize
11808
11809 @noindent
11810 Some embedded operating systems, like Sun Chorus and VxWorks, can load
11811 relocatable files into an already running program; such systems
11812 typically make the requirements above easy to meet. However, it's
11813 important to recognize that many native systems use complex link
11814 procedures (@code{.linkonce} section factoring and C@t{++} constructor table
11815 assembly, for example) that make the requirements difficult to meet. In
11816 general, one cannot assume that using @code{add-symbol-file} to read a
11817 relocatable object file's symbolic information will have the same effect
11818 as linking the relocatable object file into the program in the normal
11819 way.
11820
11821 @code{add-symbol-file} does not repeat if you press @key{RET} after using it.
11822
11823 @kindex add-symbol-file-from-memory
11824 @cindex @code{syscall DSO}
11825 @cindex load symbols from memory
11826 @item add-symbol-file-from-memory @var{address}
11827 Load symbols from the given @var{address} in a dynamically loaded
11828 object file whose image is mapped directly into the inferior's memory.
11829 For example, the Linux kernel maps a @code{syscall DSO} into each
11830 process's address space; this DSO provides kernel-specific code for
11831 some system calls. The argument can be any expression whose
11832 evaluation yields the address of the file's shared object file header.
11833 For this command to work, you must have used @code{symbol-file} or
11834 @code{exec-file} commands in advance.
11835
11836 @kindex add-shared-symbol-files
11837 @kindex assf
11838 @item add-shared-symbol-files @var{library-file}
11839 @itemx assf @var{library-file}
11840 The @code{add-shared-symbol-files} command can currently be used only
11841 in the Cygwin build of @value{GDBN} on MS-Windows OS, where it is an
11842 alias for the @code{dll-symbols} command (@pxref{Cygwin Native}).
11843 @value{GDBN} automatically looks for shared libraries, however if
11844 @value{GDBN} does not find yours, you can invoke
11845 @code{add-shared-symbol-files}. It takes one argument: the shared
11846 library's file name. @code{assf} is a shorthand alias for
11847 @code{add-shared-symbol-files}.
11848
11849 @kindex section
11850 @item section @var{section} @var{addr}
11851 The @code{section} command changes the base address of the named
11852 @var{section} of the exec file to @var{addr}. This can be used if the
11853 exec file does not contain section addresses, (such as in the
11854 @code{a.out} format), or when the addresses specified in the file
11855 itself are wrong. Each section must be changed separately. The
11856 @code{info files} command, described below, lists all the sections and
11857 their addresses.
11858
11859 @kindex info files
11860 @kindex info target
11861 @item info files
11862 @itemx info target
11863 @code{info files} and @code{info target} are synonymous; both print the
11864 current target (@pxref{Targets, ,Specifying a Debugging Target}),
11865 including the names of the executable and core dump files currently in
11866 use by @value{GDBN}, and the files from which symbols were loaded. The
11867 command @code{help target} lists all possible targets rather than
11868 current ones.
11869
11870 @kindex maint info sections
11871 @item maint info sections
11872 Another command that can give you extra information about program sections
11873 is @code{maint info sections}. In addition to the section information
11874 displayed by @code{info files}, this command displays the flags and file
11875 offset of each section in the executable and core dump files. In addition,
11876 @code{maint info sections} provides the following command options (which
11877 may be arbitrarily combined):
11878
11879 @table @code
11880 @item ALLOBJ
11881 Display sections for all loaded object files, including shared libraries.
11882 @item @var{sections}
11883 Display info only for named @var{sections}.
11884 @item @var{section-flags}
11885 Display info only for sections for which @var{section-flags} are true.
11886 The section flags that @value{GDBN} currently knows about are:
11887 @table @code
11888 @item ALLOC
11889 Section will have space allocated in the process when loaded.
11890 Set for all sections except those containing debug information.
11891 @item LOAD
11892 Section will be loaded from the file into the child process memory.
11893 Set for pre-initialized code and data, clear for @code{.bss} sections.
11894 @item RELOC
11895 Section needs to be relocated before loading.
11896 @item READONLY
11897 Section cannot be modified by the child process.
11898 @item CODE
11899 Section contains executable code only.
11900 @item DATA
11901 Section contains data only (no executable code).
11902 @item ROM
11903 Section will reside in ROM.
11904 @item CONSTRUCTOR
11905 Section contains data for constructor/destructor lists.
11906 @item HAS_CONTENTS
11907 Section is not empty.
11908 @item NEVER_LOAD
11909 An instruction to the linker to not output the section.
11910 @item COFF_SHARED_LIBRARY
11911 A notification to the linker that the section contains
11912 COFF shared library information.
11913 @item IS_COMMON
11914 Section contains common symbols.
11915 @end table
11916 @end table
11917 @kindex set trust-readonly-sections
11918 @cindex read-only sections
11919 @item set trust-readonly-sections on
11920 Tell @value{GDBN} that readonly sections in your object file
11921 really are read-only (i.e.@: that their contents will not change).
11922 In that case, @value{GDBN} can fetch values from these sections
11923 out of the object file, rather than from the target program.
11924 For some targets (notably embedded ones), this can be a significant
11925 enhancement to debugging performance.
11926
11927 The default is off.
11928
11929 @item set trust-readonly-sections off
11930 Tell @value{GDBN} not to trust readonly sections. This means that
11931 the contents of the section might change while the program is running,
11932 and must therefore be fetched from the target when needed.
11933
11934 @item show trust-readonly-sections
11935 Show the current setting of trusting readonly sections.
11936 @end table
11937
11938 All file-specifying commands allow both absolute and relative file names
11939 as arguments. @value{GDBN} always converts the file name to an absolute file
11940 name and remembers it that way.
11941
11942 @cindex shared libraries
11943 @anchor{Shared Libraries}
11944 @value{GDBN} supports @sc{gnu}/Linux, MS-Windows, HP-UX, SunOS, SVr4, Irix,
11945 and IBM RS/6000 AIX shared libraries.
11946
11947 On MS-Windows @value{GDBN} must be linked with the Expat library to support
11948 shared libraries. @xref{Expat}.
11949
11950 @value{GDBN} automatically loads symbol definitions from shared libraries
11951 when you use the @code{run} command, or when you examine a core file.
11952 (Before you issue the @code{run} command, @value{GDBN} does not understand
11953 references to a function in a shared library, however---unless you are
11954 debugging a core file).
11955
11956 On HP-UX, if the program loads a library explicitly, @value{GDBN}
11957 automatically loads the symbols at the time of the @code{shl_load} call.
11958
11959 @c FIXME: some @value{GDBN} release may permit some refs to undef
11960 @c FIXME...symbols---eg in a break cmd---assuming they are from a shared
11961 @c FIXME...lib; check this from time to time when updating manual
11962
11963 There are times, however, when you may wish to not automatically load
11964 symbol definitions from shared libraries, such as when they are
11965 particularly large or there are many of them.
11966
11967 To control the automatic loading of shared library symbols, use the
11968 commands:
11969
11970 @table @code
11971 @kindex set auto-solib-add
11972 @item set auto-solib-add @var{mode}
11973 If @var{mode} is @code{on}, symbols from all shared object libraries
11974 will be loaded automatically when the inferior begins execution, you
11975 attach to an independently started inferior, or when the dynamic linker
11976 informs @value{GDBN} that a new library has been loaded. If @var{mode}
11977 is @code{off}, symbols must be loaded manually, using the
11978 @code{sharedlibrary} command. The default value is @code{on}.
11979
11980 @cindex memory used for symbol tables
11981 If your program uses lots of shared libraries with debug info that
11982 takes large amounts of memory, you can decrease the @value{GDBN}
11983 memory footprint by preventing it from automatically loading the
11984 symbols from shared libraries. To that end, type @kbd{set
11985 auto-solib-add off} before running the inferior, then load each
11986 library whose debug symbols you do need with @kbd{sharedlibrary
11987 @var{regexp}}, where @var{regexp} is a regular expression that matches
11988 the libraries whose symbols you want to be loaded.
11989
11990 @kindex show auto-solib-add
11991 @item show auto-solib-add
11992 Display the current autoloading mode.
11993 @end table
11994
11995 @cindex load shared library
11996 To explicitly load shared library symbols, use the @code{sharedlibrary}
11997 command:
11998
11999 @table @code
12000 @kindex info sharedlibrary
12001 @kindex info share
12002 @item info share
12003 @itemx info sharedlibrary
12004 Print the names of the shared libraries which are currently loaded.
12005
12006 @kindex sharedlibrary
12007 @kindex share
12008 @item sharedlibrary @var{regex}
12009 @itemx share @var{regex}
12010 Load shared object library symbols for files matching a
12011 Unix regular expression.
12012 As with files loaded automatically, it only loads shared libraries
12013 required by your program for a core file or after typing @code{run}. If
12014 @var{regex} is omitted all shared libraries required by your program are
12015 loaded.
12016
12017 @item nosharedlibrary
12018 @kindex nosharedlibrary
12019 @cindex unload symbols from shared libraries
12020 Unload all shared object library symbols. This discards all symbols
12021 that have been loaded from all shared libraries. Symbols from shared
12022 libraries that were loaded by explicit user requests are not
12023 discarded.
12024 @end table
12025
12026 Sometimes you may wish that @value{GDBN} stops and gives you control
12027 when any of shared library events happen. Use the @code{set
12028 stop-on-solib-events} command for this:
12029
12030 @table @code
12031 @item set stop-on-solib-events
12032 @kindex set stop-on-solib-events
12033 This command controls whether @value{GDBN} should give you control
12034 when the dynamic linker notifies it about some shared library event.
12035 The most common event of interest is loading or unloading of a new
12036 shared library.
12037
12038 @item show stop-on-solib-events
12039 @kindex show stop-on-solib-events
12040 Show whether @value{GDBN} stops and gives you control when shared
12041 library events happen.
12042 @end table
12043
12044 Shared libraries are also supported in many cross or remote debugging
12045 configurations. A copy of the target's libraries need to be present on the
12046 host system; they need to be the same as the target libraries, although the
12047 copies on the target can be stripped as long as the copies on the host are
12048 not.
12049
12050 @cindex where to look for shared libraries
12051 For remote debugging, you need to tell @value{GDBN} where the target
12052 libraries are, so that it can load the correct copies---otherwise, it
12053 may try to load the host's libraries. @value{GDBN} has two variables
12054 to specify the search directories for target libraries.
12055
12056 @table @code
12057 @cindex prefix for shared library file names
12058 @cindex system root, alternate
12059 @kindex set solib-absolute-prefix
12060 @kindex set sysroot
12061 @item set sysroot @var{path}
12062 Use @var{path} as the system root for the program being debugged. Any
12063 absolute shared library paths will be prefixed with @var{path}; many
12064 runtime loaders store the absolute paths to the shared library in the
12065 target program's memory. If you use @code{set sysroot} to find shared
12066 libraries, they need to be laid out in the same way that they are on
12067 the target, with e.g.@: a @file{/lib} and @file{/usr/lib} hierarchy
12068 under @var{path}.
12069
12070 The @code{set solib-absolute-prefix} command is an alias for @code{set
12071 sysroot}.
12072
12073 @cindex default system root
12074 @cindex @samp{--with-sysroot}
12075 You can set the default system root by using the configure-time
12076 @samp{--with-sysroot} option. If the system root is inside
12077 @value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
12078 @samp{--exec-prefix}), then the default system root will be updated
12079 automatically if the installed @value{GDBN} is moved to a new
12080 location.
12081
12082 @kindex show sysroot
12083 @item show sysroot
12084 Display the current shared library prefix.
12085
12086 @kindex set solib-search-path
12087 @item set solib-search-path @var{path}
12088 If this variable is set, @var{path} is a colon-separated list of
12089 directories to search for shared libraries. @samp{solib-search-path}
12090 is used after @samp{sysroot} fails to locate the library, or if the
12091 path to the library is relative instead of absolute. If you want to
12092 use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
12093 @samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
12094 finding your host's libraries. @samp{sysroot} is preferred; setting
12095 it to a nonexistent directory may interfere with automatic loading
12096 of shared library symbols.
12097
12098 @kindex show solib-search-path
12099 @item show solib-search-path
12100 Display the current shared library search path.
12101 @end table
12102
12103
12104 @node Separate Debug Files
12105 @section Debugging Information in Separate Files
12106 @cindex separate debugging information files
12107 @cindex debugging information in separate files
12108 @cindex @file{.debug} subdirectories
12109 @cindex debugging information directory, global
12110 @cindex global debugging information directory
12111 @cindex build ID, and separate debugging files
12112 @cindex @file{.build-id} directory
12113
12114 @value{GDBN} allows you to put a program's debugging information in a
12115 file separate from the executable itself, in a way that allows
12116 @value{GDBN} to find and load the debugging information automatically.
12117 Since debugging information can be very large---sometimes larger
12118 than the executable code itself---some systems distribute debugging
12119 information for their executables in separate files, which users can
12120 install only when they need to debug a problem.
12121
12122 @value{GDBN} supports two ways of specifying the separate debug info
12123 file:
12124
12125 @itemize @bullet
12126 @item
12127 The executable contains a @dfn{debug link} that specifies the name of
12128 the separate debug info file. The separate debug file's name is
12129 usually @file{@var{executable}.debug}, where @var{executable} is the
12130 name of the corresponding executable file without leading directories
12131 (e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
12132 debug link specifies a CRC32 checksum for the debug file, which
12133 @value{GDBN} uses to validate that the executable and the debug file
12134 came from the same build.
12135
12136 @item
12137 The executable contains a @dfn{build ID}, a unique bit string that is
12138 also present in the corresponding debug info file. (This is supported
12139 only on some operating systems, notably those which use the ELF format
12140 for binary files and the @sc{gnu} Binutils.) For more details about
12141 this feature, see the description of the @option{--build-id}
12142 command-line option in @ref{Options, , Command Line Options, ld.info,
12143 The GNU Linker}. The debug info file's name is not specified
12144 explicitly by the build ID, but can be computed from the build ID, see
12145 below.
12146 @end itemize
12147
12148 Depending on the way the debug info file is specified, @value{GDBN}
12149 uses two different methods of looking for the debug file:
12150
12151 @itemize @bullet
12152 @item
12153 For the ``debug link'' method, @value{GDBN} looks up the named file in
12154 the directory of the executable file, then in a subdirectory of that
12155 directory named @file{.debug}, and finally under the global debug
12156 directory, in a subdirectory whose name is identical to the leading
12157 directories of the executable's absolute file name.
12158
12159 @item
12160 For the ``build ID'' method, @value{GDBN} looks in the
12161 @file{.build-id} subdirectory of the global debug directory for a file
12162 named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
12163 first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
12164 are the rest of the bit string. (Real build ID strings are 32 or more
12165 hex characters, not 10.)
12166 @end itemize
12167
12168 So, for example, suppose you ask @value{GDBN} to debug
12169 @file{/usr/bin/ls}, which has a debug link that specifies the
12170 file @file{ls.debug}, and a build ID whose value in hex is
12171 @code{abcdef1234}. If the global debug directory is
12172 @file{/usr/lib/debug}, then @value{GDBN} will look for the following
12173 debug information files, in the indicated order:
12174
12175 @itemize @minus
12176 @item
12177 @file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
12178 @item
12179 @file{/usr/bin/ls.debug}
12180 @item
12181 @file{/usr/bin/.debug/ls.debug}
12182 @item
12183 @file{/usr/lib/debug/usr/bin/ls.debug}.
12184 @end itemize
12185
12186 You can set the global debugging info directory's name, and view the
12187 name @value{GDBN} is currently using.
12188
12189 @table @code
12190
12191 @kindex set debug-file-directory
12192 @item set debug-file-directory @var{directory}
12193 Set the directory which @value{GDBN} searches for separate debugging
12194 information files to @var{directory}.
12195
12196 @kindex show debug-file-directory
12197 @item show debug-file-directory
12198 Show the directory @value{GDBN} searches for separate debugging
12199 information files.
12200
12201 @end table
12202
12203 @cindex @code{.gnu_debuglink} sections
12204 @cindex debug link sections
12205 A debug link is a special section of the executable file named
12206 @code{.gnu_debuglink}. The section must contain:
12207
12208 @itemize
12209 @item
12210 A filename, with any leading directory components removed, followed by
12211 a zero byte,
12212 @item
12213 zero to three bytes of padding, as needed to reach the next four-byte
12214 boundary within the section, and
12215 @item
12216 a four-byte CRC checksum, stored in the same endianness used for the
12217 executable file itself. The checksum is computed on the debugging
12218 information file's full contents by the function given below, passing
12219 zero as the @var{crc} argument.
12220 @end itemize
12221
12222 Any executable file format can carry a debug link, as long as it can
12223 contain a section named @code{.gnu_debuglink} with the contents
12224 described above.
12225
12226 @cindex @code{.note.gnu.build-id} sections
12227 @cindex build ID sections
12228 The build ID is a special section in the executable file (and in other
12229 ELF binary files that @value{GDBN} may consider). This section is
12230 often named @code{.note.gnu.build-id}, but that name is not mandatory.
12231 It contains unique identification for the built files---the ID remains
12232 the same across multiple builds of the same build tree. The default
12233 algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
12234 content for the build ID string. The same section with an identical
12235 value is present in the original built binary with symbols, in its
12236 stripped variant, and in the separate debugging information file.
12237
12238 The debugging information file itself should be an ordinary
12239 executable, containing a full set of linker symbols, sections, and
12240 debugging information. The sections of the debugging information file
12241 should have the same names, addresses, and sizes as the original file,
12242 but they need not contain any data---much like a @code{.bss} section
12243 in an ordinary executable.
12244
12245 The @sc{gnu} binary utilities (Binutils) package includes the
12246 @samp{objcopy} utility that can produce
12247 the separated executable / debugging information file pairs using the
12248 following commands:
12249
12250 @smallexample
12251 @kbd{objcopy --only-keep-debug foo foo.debug}
12252 @kbd{strip -g foo}
12253 @end smallexample
12254
12255 @noindent
12256 These commands remove the debugging
12257 information from the executable file @file{foo} and place it in the file
12258 @file{foo.debug}. You can use the first, second or both methods to link the
12259 two files:
12260
12261 @itemize @bullet
12262 @item
12263 The debug link method needs the following additional command to also leave
12264 behind a debug link in @file{foo}:
12265
12266 @smallexample
12267 @kbd{objcopy --add-gnu-debuglink=foo.debug foo}
12268 @end smallexample
12269
12270 Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
12271 a version of the @code{strip} command such that the command @kbd{strip foo -f
12272 foo.debug} has the same functionality as the two @code{objcopy} commands and
12273 the @code{ln -s} command above, together.
12274
12275 @item
12276 Build ID gets embedded into the main executable using @code{ld --build-id} or
12277 the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
12278 compatibility fixes for debug files separation are present in @sc{gnu} binary
12279 utilities (Binutils) package since version 2.18.
12280 @end itemize
12281
12282 @noindent
12283
12284 Since there are many different ways to compute CRC's for the debug
12285 link (different polynomials, reversals, byte ordering, etc.), the
12286 simplest way to describe the CRC used in @code{.gnu_debuglink}
12287 sections is to give the complete code for a function that computes it:
12288
12289 @kindex gnu_debuglink_crc32
12290 @smallexample
12291 unsigned long
12292 gnu_debuglink_crc32 (unsigned long crc,
12293 unsigned char *buf, size_t len)
12294 @{
12295 static const unsigned long crc32_table[256] =
12296 @{
12297 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
12298 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
12299 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
12300 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
12301 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
12302 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
12303 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
12304 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
12305 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
12306 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
12307 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
12308 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
12309 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
12310 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
12311 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
12312 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
12313 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
12314 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
12315 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
12316 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
12317 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
12318 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
12319 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
12320 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
12321 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
12322 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
12323 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
12324 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
12325 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
12326 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
12327 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
12328 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
12329 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
12330 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
12331 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
12332 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
12333 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
12334 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
12335 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
12336 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
12337 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
12338 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
12339 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
12340 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
12341 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
12342 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
12343 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
12344 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
12345 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
12346 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
12347 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
12348 0x2d02ef8d
12349 @};
12350 unsigned char *end;
12351
12352 crc = ~crc & 0xffffffff;
12353 for (end = buf + len; buf < end; ++buf)
12354 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
12355 return ~crc & 0xffffffff;
12356 @}
12357 @end smallexample
12358
12359 @noindent
12360 This computation does not apply to the ``build ID'' method.
12361
12362
12363 @node Symbol Errors
12364 @section Errors Reading Symbol Files
12365
12366 While reading a symbol file, @value{GDBN} occasionally encounters problems,
12367 such as symbol types it does not recognize, or known bugs in compiler
12368 output. By default, @value{GDBN} does not notify you of such problems, since
12369 they are relatively common and primarily of interest to people
12370 debugging compilers. If you are interested in seeing information
12371 about ill-constructed symbol tables, you can either ask @value{GDBN} to print
12372 only one message about each such type of problem, no matter how many
12373 times the problem occurs; or you can ask @value{GDBN} to print more messages,
12374 to see how many times the problems occur, with the @code{set
12375 complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
12376 Messages}).
12377
12378 The messages currently printed, and their meanings, include:
12379
12380 @table @code
12381 @item inner block not inside outer block in @var{symbol}
12382
12383 The symbol information shows where symbol scopes begin and end
12384 (such as at the start of a function or a block of statements). This
12385 error indicates that an inner scope block is not fully contained
12386 in its outer scope blocks.
12387
12388 @value{GDBN} circumvents the problem by treating the inner block as if it had
12389 the same scope as the outer block. In the error message, @var{symbol}
12390 may be shown as ``@code{(don't know)}'' if the outer block is not a
12391 function.
12392
12393 @item block at @var{address} out of order
12394
12395 The symbol information for symbol scope blocks should occur in
12396 order of increasing addresses. This error indicates that it does not
12397 do so.
12398
12399 @value{GDBN} does not circumvent this problem, and has trouble
12400 locating symbols in the source file whose symbols it is reading. (You
12401 can often determine what source file is affected by specifying
12402 @code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
12403 Messages}.)
12404
12405 @item bad block start address patched
12406
12407 The symbol information for a symbol scope block has a start address
12408 smaller than the address of the preceding source line. This is known
12409 to occur in the SunOS 4.1.1 (and earlier) C compiler.
12410
12411 @value{GDBN} circumvents the problem by treating the symbol scope block as
12412 starting on the previous source line.
12413
12414 @item bad string table offset in symbol @var{n}
12415
12416 @cindex foo
12417 Symbol number @var{n} contains a pointer into the string table which is
12418 larger than the size of the string table.
12419
12420 @value{GDBN} circumvents the problem by considering the symbol to have the
12421 name @code{foo}, which may cause other problems if many symbols end up
12422 with this name.
12423
12424 @item unknown symbol type @code{0x@var{nn}}
12425
12426 The symbol information contains new data types that @value{GDBN} does
12427 not yet know how to read. @code{0x@var{nn}} is the symbol type of the
12428 uncomprehended information, in hexadecimal.
12429
12430 @value{GDBN} circumvents the error by ignoring this symbol information.
12431 This usually allows you to debug your program, though certain symbols
12432 are not accessible. If you encounter such a problem and feel like
12433 debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
12434 on @code{complain}, then go up to the function @code{read_dbx_symtab}
12435 and examine @code{*bufp} to see the symbol.
12436
12437 @item stub type has NULL name
12438
12439 @value{GDBN} could not find the full definition for a struct or class.
12440
12441 @item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
12442 The symbol information for a C@t{++} member function is missing some
12443 information that recent versions of the compiler should have output for
12444 it.
12445
12446 @item info mismatch between compiler and debugger
12447
12448 @value{GDBN} could not parse a type specification output by the compiler.
12449
12450 @end table
12451
12452 @node Targets
12453 @chapter Specifying a Debugging Target
12454
12455 @cindex debugging target
12456 A @dfn{target} is the execution environment occupied by your program.
12457
12458 Often, @value{GDBN} runs in the same host environment as your program;
12459 in that case, the debugging target is specified as a side effect when
12460 you use the @code{file} or @code{core} commands. When you need more
12461 flexibility---for example, running @value{GDBN} on a physically separate
12462 host, or controlling a standalone system over a serial port or a
12463 realtime system over a TCP/IP connection---you can use the @code{target}
12464 command to specify one of the target types configured for @value{GDBN}
12465 (@pxref{Target Commands, ,Commands for Managing Targets}).
12466
12467 @cindex target architecture
12468 It is possible to build @value{GDBN} for several different @dfn{target
12469 architectures}. When @value{GDBN} is built like that, you can choose
12470 one of the available architectures with the @kbd{set architecture}
12471 command.
12472
12473 @table @code
12474 @kindex set architecture
12475 @kindex show architecture
12476 @item set architecture @var{arch}
12477 This command sets the current target architecture to @var{arch}. The
12478 value of @var{arch} can be @code{"auto"}, in addition to one of the
12479 supported architectures.
12480
12481 @item show architecture
12482 Show the current target architecture.
12483
12484 @item set processor
12485 @itemx processor
12486 @kindex set processor
12487 @kindex show processor
12488 These are alias commands for, respectively, @code{set architecture}
12489 and @code{show architecture}.
12490 @end table
12491
12492 @menu
12493 * Active Targets:: Active targets
12494 * Target Commands:: Commands for managing targets
12495 * Byte Order:: Choosing target byte order
12496 @end menu
12497
12498 @node Active Targets
12499 @section Active Targets
12500
12501 @cindex stacking targets
12502 @cindex active targets
12503 @cindex multiple targets
12504
12505 There are three classes of targets: processes, core files, and
12506 executable files. @value{GDBN} can work concurrently on up to three
12507 active targets, one in each class. This allows you to (for example)
12508 start a process and inspect its activity without abandoning your work on
12509 a core file.
12510
12511 For example, if you execute @samp{gdb a.out}, then the executable file
12512 @code{a.out} is the only active target. If you designate a core file as
12513 well---presumably from a prior run that crashed and coredumped---then
12514 @value{GDBN} has two active targets and uses them in tandem, looking
12515 first in the corefile target, then in the executable file, to satisfy
12516 requests for memory addresses. (Typically, these two classes of target
12517 are complementary, since core files contain only a program's
12518 read-write memory---variables and so on---plus machine status, while
12519 executable files contain only the program text and initialized data.)
12520
12521 When you type @code{run}, your executable file becomes an active process
12522 target as well. When a process target is active, all @value{GDBN}
12523 commands requesting memory addresses refer to that target; addresses in
12524 an active core file or executable file target are obscured while the
12525 process target is active.
12526
12527 Use the @code{core-file} and @code{exec-file} commands to select a new
12528 core file or executable target (@pxref{Files, ,Commands to Specify
12529 Files}). To specify as a target a process that is already running, use
12530 the @code{attach} command (@pxref{Attach, ,Debugging an Already-running
12531 Process}).
12532
12533 @node Target Commands
12534 @section Commands for Managing Targets
12535
12536 @table @code
12537 @item target @var{type} @var{parameters}
12538 Connects the @value{GDBN} host environment to a target machine or
12539 process. A target is typically a protocol for talking to debugging
12540 facilities. You use the argument @var{type} to specify the type or
12541 protocol of the target machine.
12542
12543 Further @var{parameters} are interpreted by the target protocol, but
12544 typically include things like device names or host names to connect
12545 with, process numbers, and baud rates.
12546
12547 The @code{target} command does not repeat if you press @key{RET} again
12548 after executing the command.
12549
12550 @kindex help target
12551 @item help target
12552 Displays the names of all targets available. To display targets
12553 currently selected, use either @code{info target} or @code{info files}
12554 (@pxref{Files, ,Commands to Specify Files}).
12555
12556 @item help target @var{name}
12557 Describe a particular target, including any parameters necessary to
12558 select it.
12559
12560 @kindex set gnutarget
12561 @item set gnutarget @var{args}
12562 @value{GDBN} uses its own library BFD to read your files. @value{GDBN}
12563 knows whether it is reading an @dfn{executable},
12564 a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
12565 with the @code{set gnutarget} command. Unlike most @code{target} commands,
12566 with @code{gnutarget} the @code{target} refers to a program, not a machine.
12567
12568 @quotation
12569 @emph{Warning:} To specify a file format with @code{set gnutarget},
12570 you must know the actual BFD name.
12571 @end quotation
12572
12573 @noindent
12574 @xref{Files, , Commands to Specify Files}.
12575
12576 @kindex show gnutarget
12577 @item show gnutarget
12578 Use the @code{show gnutarget} command to display what file format
12579 @code{gnutarget} is set to read. If you have not set @code{gnutarget},
12580 @value{GDBN} will determine the file format for each file automatically,
12581 and @code{show gnutarget} displays @samp{The current BDF target is "auto"}.
12582 @end table
12583
12584 @cindex common targets
12585 Here are some common targets (available, or not, depending on the GDB
12586 configuration):
12587
12588 @table @code
12589 @kindex target
12590 @item target exec @var{program}
12591 @cindex executable file target
12592 An executable file. @samp{target exec @var{program}} is the same as
12593 @samp{exec-file @var{program}}.
12594
12595 @item target core @var{filename}
12596 @cindex core dump file target
12597 A core dump file. @samp{target core @var{filename}} is the same as
12598 @samp{core-file @var{filename}}.
12599
12600 @item target remote @var{medium}
12601 @cindex remote target
12602 A remote system connected to @value{GDBN} via a serial line or network
12603 connection. This command tells @value{GDBN} to use its own remote
12604 protocol over @var{medium} for debugging. @xref{Remote Debugging}.
12605
12606 For example, if you have a board connected to @file{/dev/ttya} on the
12607 machine running @value{GDBN}, you could say:
12608
12609 @smallexample
12610 target remote /dev/ttya
12611 @end smallexample
12612
12613 @code{target remote} supports the @code{load} command. This is only
12614 useful if you have some other way of getting the stub to the target
12615 system, and you can put it somewhere in memory where it won't get
12616 clobbered by the download.
12617
12618 @item target sim
12619 @cindex built-in simulator target
12620 Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
12621 In general,
12622 @smallexample
12623 target sim
12624 load
12625 run
12626 @end smallexample
12627 @noindent
12628 works; however, you cannot assume that a specific memory map, device
12629 drivers, or even basic I/O is available, although some simulators do
12630 provide these. For info about any processor-specific simulator details,
12631 see the appropriate section in @ref{Embedded Processors, ,Embedded
12632 Processors}.
12633
12634 @end table
12635
12636 Some configurations may include these targets as well:
12637
12638 @table @code
12639
12640 @item target nrom @var{dev}
12641 @cindex NetROM ROM emulator target
12642 NetROM ROM emulator. This target only supports downloading.
12643
12644 @end table
12645
12646 Different targets are available on different configurations of @value{GDBN};
12647 your configuration may have more or fewer targets.
12648
12649 Many remote targets require you to download the executable's code once
12650 you've successfully established a connection. You may wish to control
12651 various aspects of this process.
12652
12653 @table @code
12654
12655 @item set hash
12656 @kindex set hash@r{, for remote monitors}
12657 @cindex hash mark while downloading
12658 This command controls whether a hash mark @samp{#} is displayed while
12659 downloading a file to the remote monitor. If on, a hash mark is
12660 displayed after each S-record is successfully downloaded to the
12661 monitor.
12662
12663 @item show hash
12664 @kindex show hash@r{, for remote monitors}
12665 Show the current status of displaying the hash mark.
12666
12667 @item set debug monitor
12668 @kindex set debug monitor
12669 @cindex display remote monitor communications
12670 Enable or disable display of communications messages between
12671 @value{GDBN} and the remote monitor.
12672
12673 @item show debug monitor
12674 @kindex show debug monitor
12675 Show the current status of displaying communications between
12676 @value{GDBN} and the remote monitor.
12677 @end table
12678
12679 @table @code
12680
12681 @kindex load @var{filename}
12682 @item load @var{filename}
12683 @anchor{load}
12684 Depending on what remote debugging facilities are configured into
12685 @value{GDBN}, the @code{load} command may be available. Where it exists, it
12686 is meant to make @var{filename} (an executable) available for debugging
12687 on the remote system---by downloading, or dynamic linking, for example.
12688 @code{load} also records the @var{filename} symbol table in @value{GDBN}, like
12689 the @code{add-symbol-file} command.
12690
12691 If your @value{GDBN} does not have a @code{load} command, attempting to
12692 execute it gets the error message ``@code{You can't do that when your
12693 target is @dots{}}''
12694
12695 The file is loaded at whatever address is specified in the executable.
12696 For some object file formats, you can specify the load address when you
12697 link the program; for other formats, like a.out, the object file format
12698 specifies a fixed address.
12699 @c FIXME! This would be a good place for an xref to the GNU linker doc.
12700
12701 Depending on the remote side capabilities, @value{GDBN} may be able to
12702 load programs into flash memory.
12703
12704 @code{load} does not repeat if you press @key{RET} again after using it.
12705 @end table
12706
12707 @node Byte Order
12708 @section Choosing Target Byte Order
12709
12710 @cindex choosing target byte order
12711 @cindex target byte order
12712
12713 Some types of processors, such as the MIPS, PowerPC, and Renesas SH,
12714 offer the ability to run either big-endian or little-endian byte
12715 orders. Usually the executable or symbol will include a bit to
12716 designate the endian-ness, and you will not need to worry about
12717 which to use. However, you may still find it useful to adjust
12718 @value{GDBN}'s idea of processor endian-ness manually.
12719
12720 @table @code
12721 @kindex set endian
12722 @item set endian big
12723 Instruct @value{GDBN} to assume the target is big-endian.
12724
12725 @item set endian little
12726 Instruct @value{GDBN} to assume the target is little-endian.
12727
12728 @item set endian auto
12729 Instruct @value{GDBN} to use the byte order associated with the
12730 executable.
12731
12732 @item show endian
12733 Display @value{GDBN}'s current idea of the target byte order.
12734
12735 @end table
12736
12737 Note that these commands merely adjust interpretation of symbolic
12738 data on the host, and that they have absolutely no effect on the
12739 target system.
12740
12741
12742 @node Remote Debugging
12743 @chapter Debugging Remote Programs
12744 @cindex remote debugging
12745
12746 If you are trying to debug a program running on a machine that cannot run
12747 @value{GDBN} in the usual way, it is often useful to use remote debugging.
12748 For example, you might use remote debugging on an operating system kernel,
12749 or on a small system which does not have a general purpose operating system
12750 powerful enough to run a full-featured debugger.
12751
12752 Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
12753 to make this work with particular debugging targets. In addition,
12754 @value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
12755 but not specific to any particular target system) which you can use if you
12756 write the remote stubs---the code that runs on the remote system to
12757 communicate with @value{GDBN}.
12758
12759 Other remote targets may be available in your
12760 configuration of @value{GDBN}; use @code{help target} to list them.
12761
12762 @menu
12763 * Connecting:: Connecting to a remote target
12764 * File Transfer:: Sending files to a remote system
12765 * Server:: Using the gdbserver program
12766 * Remote Configuration:: Remote configuration
12767 * Remote Stub:: Implementing a remote stub
12768 @end menu
12769
12770 @node Connecting
12771 @section Connecting to a Remote Target
12772
12773 On the @value{GDBN} host machine, you will need an unstripped copy of
12774 your program, since @value{GDBN} needs symbol and debugging information.
12775 Start up @value{GDBN} as usual, using the name of the local copy of your
12776 program as the first argument.
12777
12778 @cindex @code{target remote}
12779 @value{GDBN} can communicate with the target over a serial line, or
12780 over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
12781 each case, @value{GDBN} uses the same protocol for debugging your
12782 program; only the medium carrying the debugging packets varies. The
12783 @code{target remote} command establishes a connection to the target.
12784 Its arguments indicate which medium to use:
12785
12786 @table @code
12787
12788 @item target remote @var{serial-device}
12789 @cindex serial line, @code{target remote}
12790 Use @var{serial-device} to communicate with the target. For example,
12791 to use a serial line connected to the device named @file{/dev/ttyb}:
12792
12793 @smallexample
12794 target remote /dev/ttyb
12795 @end smallexample
12796
12797 If you're using a serial line, you may want to give @value{GDBN} the
12798 @w{@samp{--baud}} option, or use the @code{set remotebaud} command
12799 (@pxref{Remote Configuration, set remotebaud}) before the
12800 @code{target} command.
12801
12802 @item target remote @code{@var{host}:@var{port}}
12803 @itemx target remote @code{tcp:@var{host}:@var{port}}
12804 @cindex @acronym{TCP} port, @code{target remote}
12805 Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
12806 The @var{host} may be either a host name or a numeric @acronym{IP}
12807 address; @var{port} must be a decimal number. The @var{host} could be
12808 the target machine itself, if it is directly connected to the net, or
12809 it might be a terminal server which in turn has a serial line to the
12810 target.
12811
12812 For example, to connect to port 2828 on a terminal server named
12813 @code{manyfarms}:
12814
12815 @smallexample
12816 target remote manyfarms:2828
12817 @end smallexample
12818
12819 If your remote target is actually running on the same machine as your
12820 debugger session (e.g.@: a simulator for your target running on the
12821 same host), you can omit the hostname. For example, to connect to
12822 port 1234 on your local machine:
12823
12824 @smallexample
12825 target remote :1234
12826 @end smallexample
12827 @noindent
12828
12829 Note that the colon is still required here.
12830
12831 @item target remote @code{udp:@var{host}:@var{port}}
12832 @cindex @acronym{UDP} port, @code{target remote}
12833 Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
12834 connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
12835
12836 @smallexample
12837 target remote udp:manyfarms:2828
12838 @end smallexample
12839
12840 When using a @acronym{UDP} connection for remote debugging, you should
12841 keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
12842 can silently drop packets on busy or unreliable networks, which will
12843 cause havoc with your debugging session.
12844
12845 @item target remote | @var{command}
12846 @cindex pipe, @code{target remote} to
12847 Run @var{command} in the background and communicate with it using a
12848 pipe. The @var{command} is a shell command, to be parsed and expanded
12849 by the system's command shell, @code{/bin/sh}; it should expect remote
12850 protocol packets on its standard input, and send replies on its
12851 standard output. You could use this to run a stand-alone simulator
12852 that speaks the remote debugging protocol, to make net connections
12853 using programs like @code{ssh}, or for other similar tricks.
12854
12855 If @var{command} closes its standard output (perhaps by exiting),
12856 @value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
12857 program has already exited, this will have no effect.)
12858
12859 @end table
12860
12861 Once the connection has been established, you can use all the usual
12862 commands to examine and change data. The remote program is already
12863 running; you can use @kbd{step} and @kbd{continue}, and you do not
12864 need to use @kbd{run}.
12865
12866 @cindex interrupting remote programs
12867 @cindex remote programs, interrupting
12868 Whenever @value{GDBN} is waiting for the remote program, if you type the
12869 interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
12870 program. This may or may not succeed, depending in part on the hardware
12871 and the serial drivers the remote system uses. If you type the
12872 interrupt character once again, @value{GDBN} displays this prompt:
12873
12874 @smallexample
12875 Interrupted while waiting for the program.
12876 Give up (and stop debugging it)? (y or n)
12877 @end smallexample
12878
12879 If you type @kbd{y}, @value{GDBN} abandons the remote debugging session.
12880 (If you decide you want to try again later, you can use @samp{target
12881 remote} again to connect once more.) If you type @kbd{n}, @value{GDBN}
12882 goes back to waiting.
12883
12884 @table @code
12885 @kindex detach (remote)
12886 @item detach
12887 When you have finished debugging the remote program, you can use the
12888 @code{detach} command to release it from @value{GDBN} control.
12889 Detaching from the target normally resumes its execution, but the results
12890 will depend on your particular remote stub. After the @code{detach}
12891 command, @value{GDBN} is free to connect to another target.
12892
12893 @kindex disconnect
12894 @item disconnect
12895 The @code{disconnect} command behaves like @code{detach}, except that
12896 the target is generally not resumed. It will wait for @value{GDBN}
12897 (this instance or another one) to connect and continue debugging. After
12898 the @code{disconnect} command, @value{GDBN} is again free to connect to
12899 another target.
12900
12901 @cindex send command to remote monitor
12902 @cindex extend @value{GDBN} for remote targets
12903 @cindex add new commands for external monitor
12904 @kindex monitor
12905 @item monitor @var{cmd}
12906 This command allows you to send arbitrary commands directly to the
12907 remote monitor. Since @value{GDBN} doesn't care about the commands it
12908 sends like this, this command is the way to extend @value{GDBN}---you
12909 can add new commands that only the external monitor will understand
12910 and implement.
12911 @end table
12912
12913 @node File Transfer
12914 @section Sending files to a remote system
12915 @cindex remote target, file transfer
12916 @cindex file transfer
12917 @cindex sending files to remote systems
12918
12919 Some remote targets offer the ability to transfer files over the same
12920 connection used to communicate with @value{GDBN}. This is convenient
12921 for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
12922 running @code{gdbserver} over a network interface. For other targets,
12923 e.g.@: embedded devices with only a single serial port, this may be
12924 the only way to upload or download files.
12925
12926 Not all remote targets support these commands.
12927
12928 @table @code
12929 @kindex remote put
12930 @item remote put @var{hostfile} @var{targetfile}
12931 Copy file @var{hostfile} from the host system (the machine running
12932 @value{GDBN}) to @var{targetfile} on the target system.
12933
12934 @kindex remote get
12935 @item remote get @var{targetfile} @var{hostfile}
12936 Copy file @var{targetfile} from the target system to @var{hostfile}
12937 on the host system.
12938
12939 @kindex remote delete
12940 @item remote delete @var{targetfile}
12941 Delete @var{targetfile} from the target system.
12942
12943 @end table
12944
12945 @node Server
12946 @section Using the @code{gdbserver} Program
12947
12948 @kindex gdbserver
12949 @cindex remote connection without stubs
12950 @code{gdbserver} is a control program for Unix-like systems, which
12951 allows you to connect your program with a remote @value{GDBN} via
12952 @code{target remote}---but without linking in the usual debugging stub.
12953
12954 @code{gdbserver} is not a complete replacement for the debugging stubs,
12955 because it requires essentially the same operating-system facilities
12956 that @value{GDBN} itself does. In fact, a system that can run
12957 @code{gdbserver} to connect to a remote @value{GDBN} could also run
12958 @value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
12959 because it is a much smaller program than @value{GDBN} itself. It is
12960 also easier to port than all of @value{GDBN}, so you may be able to get
12961 started more quickly on a new system by using @code{gdbserver}.
12962 Finally, if you develop code for real-time systems, you may find that
12963 the tradeoffs involved in real-time operation make it more convenient to
12964 do as much development work as possible on another system, for example
12965 by cross-compiling. You can use @code{gdbserver} to make a similar
12966 choice for debugging.
12967
12968 @value{GDBN} and @code{gdbserver} communicate via either a serial line
12969 or a TCP connection, using the standard @value{GDBN} remote serial
12970 protocol.
12971
12972 @quotation
12973 @emph{Warning:} @code{gdbserver} does not have any built-in security.
12974 Do not run @code{gdbserver} connected to any public network; a
12975 @value{GDBN} connection to @code{gdbserver} provides access to the
12976 target system with the same privileges as the user running
12977 @code{gdbserver}.
12978 @end quotation
12979
12980 @subsection Running @code{gdbserver}
12981 @cindex arguments, to @code{gdbserver}
12982
12983 Run @code{gdbserver} on the target system. You need a copy of the
12984 program you want to debug, including any libraries it requires.
12985 @code{gdbserver} does not need your program's symbol table, so you can
12986 strip the program if necessary to save space. @value{GDBN} on the host
12987 system does all the symbol handling.
12988
12989 To use the server, you must tell it how to communicate with @value{GDBN};
12990 the name of your program; and the arguments for your program. The usual
12991 syntax is:
12992
12993 @smallexample
12994 target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
12995 @end smallexample
12996
12997 @var{comm} is either a device name (to use a serial line) or a TCP
12998 hostname and portnumber. For example, to debug Emacs with the argument
12999 @samp{foo.txt} and communicate with @value{GDBN} over the serial port
13000 @file{/dev/com1}:
13001
13002 @smallexample
13003 target> gdbserver /dev/com1 emacs foo.txt
13004 @end smallexample
13005
13006 @code{gdbserver} waits passively for the host @value{GDBN} to communicate
13007 with it.
13008
13009 To use a TCP connection instead of a serial line:
13010
13011 @smallexample
13012 target> gdbserver host:2345 emacs foo.txt
13013 @end smallexample
13014
13015 The only difference from the previous example is the first argument,
13016 specifying that you are communicating with the host @value{GDBN} via
13017 TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
13018 expect a TCP connection from machine @samp{host} to local TCP port 2345.
13019 (Currently, the @samp{host} part is ignored.) You can choose any number
13020 you want for the port number as long as it does not conflict with any
13021 TCP ports already in use on the target system (for example, @code{23} is
13022 reserved for @code{telnet}).@footnote{If you choose a port number that
13023 conflicts with another service, @code{gdbserver} prints an error message
13024 and exits.} You must use the same port number with the host @value{GDBN}
13025 @code{target remote} command.
13026
13027 @subsubsection Attaching to a Running Program
13028
13029 On some targets, @code{gdbserver} can also attach to running programs.
13030 This is accomplished via the @code{--attach} argument. The syntax is:
13031
13032 @smallexample
13033 target> gdbserver --attach @var{comm} @var{pid}
13034 @end smallexample
13035
13036 @var{pid} is the process ID of a currently running process. It isn't necessary
13037 to point @code{gdbserver} at a binary for the running process.
13038
13039 @pindex pidof
13040 @cindex attach to a program by name
13041 You can debug processes by name instead of process ID if your target has the
13042 @code{pidof} utility:
13043
13044 @smallexample
13045 target> gdbserver --attach @var{comm} `pidof @var{program}`
13046 @end smallexample
13047
13048 In case more than one copy of @var{program} is running, or @var{program}
13049 has multiple threads, most versions of @code{pidof} support the
13050 @code{-s} option to only return the first process ID.
13051
13052 @subsubsection Multi-Process Mode for @code{gdbserver}
13053 @cindex gdbserver, multiple processes
13054 @cindex multiple processes with gdbserver
13055
13056 When you connect to @code{gdbserver} using @code{target remote},
13057 @code{gdbserver} debugs the specified program only once. When the
13058 program exits, or you detach from it, @value{GDBN} closes the connection
13059 and @code{gdbserver} exits.
13060
13061 If you connect using @kbd{target extended-remote}, @code{gdbserver}
13062 enters multi-process mode. When the debugged program exits, or you
13063 detach from it, @value{GDBN} stays connected to @code{gdbserver} even
13064 though no program is running. The @code{run} and @code{attach}
13065 commands instruct @code{gdbserver} to run or attach to a new program.
13066 The @code{run} command uses @code{set remote exec-file} (@pxref{set
13067 remote exec-file}) to select the program to run. Command line
13068 arguments are supported, except for wildcard expansion and I/O
13069 redirection (@pxref{Arguments}).
13070
13071 To start @code{gdbserver} without supplying an initial command to run
13072 or process ID to attach, use the @option{--multi} command line option.
13073 Then you can connect using @kbd{target extended-remote} and start
13074 the program you want to debug.
13075
13076 @code{gdbserver} does not automatically exit in multi-process mode.
13077 You can terminate it by using @code{monitor exit}
13078 (@pxref{Monitor Commands for gdbserver}).
13079
13080 @subsubsection Other Command-Line Arguments for @code{gdbserver}
13081
13082 You can include @option{--debug} on the @code{gdbserver} command line.
13083 @code{gdbserver} will display extra status information about the debugging
13084 process. This option is intended for @code{gdbserver} development and
13085 for bug reports to the developers.
13086
13087 @subsection Connecting to @code{gdbserver}
13088
13089 Run @value{GDBN} on the host system.
13090
13091 First make sure you have the necessary symbol files. Load symbols for
13092 your application using the @code{file} command before you connect. Use
13093 @code{set sysroot} to locate target libraries (unless your @value{GDBN}
13094 was compiled with the correct sysroot using @code{--with-sysroot}).
13095
13096 The symbol file and target libraries must exactly match the executable
13097 and libraries on the target, with one exception: the files on the host
13098 system should not be stripped, even if the files on the target system
13099 are. Mismatched or missing files will lead to confusing results
13100 during debugging. On @sc{gnu}/Linux targets, mismatched or missing
13101 files may also prevent @code{gdbserver} from debugging multi-threaded
13102 programs.
13103
13104 Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
13105 For TCP connections, you must start up @code{gdbserver} prior to using
13106 the @code{target remote} command. Otherwise you may get an error whose
13107 text depends on the host system, but which usually looks something like
13108 @samp{Connection refused}. Don't use the @code{load}
13109 command in @value{GDBN} when using @code{gdbserver}, since the program is
13110 already on the target.
13111
13112 @subsection Monitor Commands for @code{gdbserver}
13113 @cindex monitor commands, for @code{gdbserver}
13114 @anchor{Monitor Commands for gdbserver}
13115
13116 During a @value{GDBN} session using @code{gdbserver}, you can use the
13117 @code{monitor} command to send special requests to @code{gdbserver}.
13118 Here are the available commands.
13119
13120 @table @code
13121 @item monitor help
13122 List the available monitor commands.
13123
13124 @item monitor set debug 0
13125 @itemx monitor set debug 1
13126 Disable or enable general debugging messages.
13127
13128 @item monitor set remote-debug 0
13129 @itemx monitor set remote-debug 1
13130 Disable or enable specific debugging messages associated with the remote
13131 protocol (@pxref{Remote Protocol}).
13132
13133 @item monitor exit
13134 Tell gdbserver to exit immediately. This command should be followed by
13135 @code{disconnect} to close the debugging session. @code{gdbserver} will
13136 detach from any attached processes and kill any processes it created.
13137 Use @code{monitor exit} to terminate @code{gdbserver} at the end
13138 of a multi-process mode debug session.
13139
13140 @end table
13141
13142 @node Remote Configuration
13143 @section Remote Configuration
13144
13145 @kindex set remote
13146 @kindex show remote
13147 This section documents the configuration options available when
13148 debugging remote programs. For the options related to the File I/O
13149 extensions of the remote protocol, see @ref{system,
13150 system-call-allowed}.
13151
13152 @table @code
13153 @item set remoteaddresssize @var{bits}
13154 @cindex address size for remote targets
13155 @cindex bits in remote address
13156 Set the maximum size of address in a memory packet to the specified
13157 number of bits. @value{GDBN} will mask off the address bits above
13158 that number, when it passes addresses to the remote target. The
13159 default value is the number of bits in the target's address.
13160
13161 @item show remoteaddresssize
13162 Show the current value of remote address size in bits.
13163
13164 @item set remotebaud @var{n}
13165 @cindex baud rate for remote targets
13166 Set the baud rate for the remote serial I/O to @var{n} baud. The
13167 value is used to set the speed of the serial port used for debugging
13168 remote targets.
13169
13170 @item show remotebaud
13171 Show the current speed of the remote connection.
13172
13173 @item set remotebreak
13174 @cindex interrupt remote programs
13175 @cindex BREAK signal instead of Ctrl-C
13176 @anchor{set remotebreak}
13177 If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
13178 when you type @kbd{Ctrl-c} to interrupt the program running
13179 on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
13180 character instead. The default is off, since most remote systems
13181 expect to see @samp{Ctrl-C} as the interrupt signal.
13182
13183 @item show remotebreak
13184 Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
13185 interrupt the remote program.
13186
13187 @item set remoteflow on
13188 @itemx set remoteflow off
13189 @kindex set remoteflow
13190 Enable or disable hardware flow control (@code{RTS}/@code{CTS})
13191 on the serial port used to communicate to the remote target.
13192
13193 @item show remoteflow
13194 @kindex show remoteflow
13195 Show the current setting of hardware flow control.
13196
13197 @item set remotelogbase @var{base}
13198 Set the base (a.k.a.@: radix) of logging serial protocol
13199 communications to @var{base}. Supported values of @var{base} are:
13200 @code{ascii}, @code{octal}, and @code{hex}. The default is
13201 @code{ascii}.
13202
13203 @item show remotelogbase
13204 Show the current setting of the radix for logging remote serial
13205 protocol.
13206
13207 @item set remotelogfile @var{file}
13208 @cindex record serial communications on file
13209 Record remote serial communications on the named @var{file}. The
13210 default is not to record at all.
13211
13212 @item show remotelogfile.
13213 Show the current setting of the file name on which to record the
13214 serial communications.
13215
13216 @item set remotetimeout @var{num}
13217 @cindex timeout for serial communications
13218 @cindex remote timeout
13219 Set the timeout limit to wait for the remote target to respond to
13220 @var{num} seconds. The default is 2 seconds.
13221
13222 @item show remotetimeout
13223 Show the current number of seconds to wait for the remote target
13224 responses.
13225
13226 @cindex limit hardware breakpoints and watchpoints
13227 @cindex remote target, limit break- and watchpoints
13228 @anchor{set remote hardware-watchpoint-limit}
13229 @anchor{set remote hardware-breakpoint-limit}
13230 @item set remote hardware-watchpoint-limit @var{limit}
13231 @itemx set remote hardware-breakpoint-limit @var{limit}
13232 Restrict @value{GDBN} to using @var{limit} remote hardware breakpoint or
13233 watchpoints. A limit of -1, the default, is treated as unlimited.
13234
13235 @item set remote exec-file @var{filename}
13236 @itemx show remote exec-file
13237 @anchor{set remote exec-file}
13238 @cindex executable file, for remote target
13239 Select the file used for @code{run} with @code{target
13240 extended-remote}. This should be set to a filename valid on the
13241 target system. If it is not set, the target will use a default
13242 filename (e.g.@: the last program run).
13243 @end table
13244
13245 @cindex remote packets, enabling and disabling
13246 The @value{GDBN} remote protocol autodetects the packets supported by
13247 your debugging stub. If you need to override the autodetection, you
13248 can use these commands to enable or disable individual packets. Each
13249 packet can be set to @samp{on} (the remote target supports this
13250 packet), @samp{off} (the remote target does not support this packet),
13251 or @samp{auto} (detect remote target support for this packet). They
13252 all default to @samp{auto}. For more information about each packet,
13253 see @ref{Remote Protocol}.
13254
13255 During normal use, you should not have to use any of these commands.
13256 If you do, that may be a bug in your remote debugging stub, or a bug
13257 in @value{GDBN}. You may want to report the problem to the
13258 @value{GDBN} developers.
13259
13260 For each packet @var{name}, the command to enable or disable the
13261 packet is @code{set remote @var{name}-packet}. The available settings
13262 are:
13263
13264 @multitable @columnfractions 0.28 0.32 0.25
13265 @item Command Name
13266 @tab Remote Packet
13267 @tab Related Features
13268
13269 @item @code{fetch-register}
13270 @tab @code{p}
13271 @tab @code{info registers}
13272
13273 @item @code{set-register}
13274 @tab @code{P}
13275 @tab @code{set}
13276
13277 @item @code{binary-download}
13278 @tab @code{X}
13279 @tab @code{load}, @code{set}
13280
13281 @item @code{read-aux-vector}
13282 @tab @code{qXfer:auxv:read}
13283 @tab @code{info auxv}
13284
13285 @item @code{symbol-lookup}
13286 @tab @code{qSymbol}
13287 @tab Detecting multiple threads
13288
13289 @item @code{attach}
13290 @tab @code{vAttach}
13291 @tab @code{attach}
13292
13293 @item @code{verbose-resume}
13294 @tab @code{vCont}
13295 @tab Stepping or resuming multiple threads
13296
13297 @item @code{run}
13298 @tab @code{vRun}
13299 @tab @code{run}
13300
13301 @item @code{software-breakpoint}
13302 @tab @code{Z0}
13303 @tab @code{break}
13304
13305 @item @code{hardware-breakpoint}
13306 @tab @code{Z1}
13307 @tab @code{hbreak}
13308
13309 @item @code{write-watchpoint}
13310 @tab @code{Z2}
13311 @tab @code{watch}
13312
13313 @item @code{read-watchpoint}
13314 @tab @code{Z3}
13315 @tab @code{rwatch}
13316
13317 @item @code{access-watchpoint}
13318 @tab @code{Z4}
13319 @tab @code{awatch}
13320
13321 @item @code{target-features}
13322 @tab @code{qXfer:features:read}
13323 @tab @code{set architecture}
13324
13325 @item @code{library-info}
13326 @tab @code{qXfer:libraries:read}
13327 @tab @code{info sharedlibrary}
13328
13329 @item @code{memory-map}
13330 @tab @code{qXfer:memory-map:read}
13331 @tab @code{info mem}
13332
13333 @item @code{read-spu-object}
13334 @tab @code{qXfer:spu:read}
13335 @tab @code{info spu}
13336
13337 @item @code{write-spu-object}
13338 @tab @code{qXfer:spu:write}
13339 @tab @code{info spu}
13340
13341 @item @code{get-thread-local-@*storage-address}
13342 @tab @code{qGetTLSAddr}
13343 @tab Displaying @code{__thread} variables
13344
13345 @item @code{supported-packets}
13346 @tab @code{qSupported}
13347 @tab Remote communications parameters
13348
13349 @item @code{pass-signals}
13350 @tab @code{QPassSignals}
13351 @tab @code{handle @var{signal}}
13352
13353 @item @code{hostio-close-packet}
13354 @tab @code{vFile:close}
13355 @tab @code{remote get}, @code{remote put}
13356
13357 @item @code{hostio-open-packet}
13358 @tab @code{vFile:open}
13359 @tab @code{remote get}, @code{remote put}
13360
13361 @item @code{hostio-pread-packet}
13362 @tab @code{vFile:pread}
13363 @tab @code{remote get}, @code{remote put}
13364
13365 @item @code{hostio-pwrite-packet}
13366 @tab @code{vFile:pwrite}
13367 @tab @code{remote get}, @code{remote put}
13368
13369 @item @code{hostio-unlink-packet}
13370 @tab @code{vFile:unlink}
13371 @tab @code{remote delete}
13372 @end multitable
13373
13374 @node Remote Stub
13375 @section Implementing a Remote Stub
13376
13377 @cindex debugging stub, example
13378 @cindex remote stub, example
13379 @cindex stub example, remote debugging
13380 The stub files provided with @value{GDBN} implement the target side of the
13381 communication protocol, and the @value{GDBN} side is implemented in the
13382 @value{GDBN} source file @file{remote.c}. Normally, you can simply allow
13383 these subroutines to communicate, and ignore the details. (If you're
13384 implementing your own stub file, you can still ignore the details: start
13385 with one of the existing stub files. @file{sparc-stub.c} is the best
13386 organized, and therefore the easiest to read.)
13387
13388 @cindex remote serial debugging, overview
13389 To debug a program running on another machine (the debugging
13390 @dfn{target} machine), you must first arrange for all the usual
13391 prerequisites for the program to run by itself. For example, for a C
13392 program, you need:
13393
13394 @enumerate
13395 @item
13396 A startup routine to set up the C runtime environment; these usually
13397 have a name like @file{crt0}. The startup routine may be supplied by
13398 your hardware supplier, or you may have to write your own.
13399
13400 @item
13401 A C subroutine library to support your program's
13402 subroutine calls, notably managing input and output.
13403
13404 @item
13405 A way of getting your program to the other machine---for example, a
13406 download program. These are often supplied by the hardware
13407 manufacturer, but you may have to write your own from hardware
13408 documentation.
13409 @end enumerate
13410
13411 The next step is to arrange for your program to use a serial port to
13412 communicate with the machine where @value{GDBN} is running (the @dfn{host}
13413 machine). In general terms, the scheme looks like this:
13414
13415 @table @emph
13416 @item On the host,
13417 @value{GDBN} already understands how to use this protocol; when everything
13418 else is set up, you can simply use the @samp{target remote} command
13419 (@pxref{Targets,,Specifying a Debugging Target}).
13420
13421 @item On the target,
13422 you must link with your program a few special-purpose subroutines that
13423 implement the @value{GDBN} remote serial protocol. The file containing these
13424 subroutines is called a @dfn{debugging stub}.
13425
13426 On certain remote targets, you can use an auxiliary program
13427 @code{gdbserver} instead of linking a stub into your program.
13428 @xref{Server,,Using the @code{gdbserver} Program}, for details.
13429 @end table
13430
13431 The debugging stub is specific to the architecture of the remote
13432 machine; for example, use @file{sparc-stub.c} to debug programs on
13433 @sc{sparc} boards.
13434
13435 @cindex remote serial stub list
13436 These working remote stubs are distributed with @value{GDBN}:
13437
13438 @table @code
13439
13440 @item i386-stub.c
13441 @cindex @file{i386-stub.c}
13442 @cindex Intel
13443 @cindex i386
13444 For Intel 386 and compatible architectures.
13445
13446 @item m68k-stub.c
13447 @cindex @file{m68k-stub.c}
13448 @cindex Motorola 680x0
13449 @cindex m680x0
13450 For Motorola 680x0 architectures.
13451
13452 @item sh-stub.c
13453 @cindex @file{sh-stub.c}
13454 @cindex Renesas
13455 @cindex SH
13456 For Renesas SH architectures.
13457
13458 @item sparc-stub.c
13459 @cindex @file{sparc-stub.c}
13460 @cindex Sparc
13461 For @sc{sparc} architectures.
13462
13463 @item sparcl-stub.c
13464 @cindex @file{sparcl-stub.c}
13465 @cindex Fujitsu
13466 @cindex SparcLite
13467 For Fujitsu @sc{sparclite} architectures.
13468
13469 @end table
13470
13471 The @file{README} file in the @value{GDBN} distribution may list other
13472 recently added stubs.
13473
13474 @menu
13475 * Stub Contents:: What the stub can do for you
13476 * Bootstrapping:: What you must do for the stub
13477 * Debug Session:: Putting it all together
13478 @end menu
13479
13480 @node Stub Contents
13481 @subsection What the Stub Can Do for You
13482
13483 @cindex remote serial stub
13484 The debugging stub for your architecture supplies these three
13485 subroutines:
13486
13487 @table @code
13488 @item set_debug_traps
13489 @findex set_debug_traps
13490 @cindex remote serial stub, initialization
13491 This routine arranges for @code{handle_exception} to run when your
13492 program stops. You must call this subroutine explicitly near the
13493 beginning of your program.
13494
13495 @item handle_exception
13496 @findex handle_exception
13497 @cindex remote serial stub, main routine
13498 This is the central workhorse, but your program never calls it
13499 explicitly---the setup code arranges for @code{handle_exception} to
13500 run when a trap is triggered.
13501
13502 @code{handle_exception} takes control when your program stops during
13503 execution (for example, on a breakpoint), and mediates communications
13504 with @value{GDBN} on the host machine. This is where the communications
13505 protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
13506 representative on the target machine. It begins by sending summary
13507 information on the state of your program, then continues to execute,
13508 retrieving and transmitting any information @value{GDBN} needs, until you
13509 execute a @value{GDBN} command that makes your program resume; at that point,
13510 @code{handle_exception} returns control to your own code on the target
13511 machine.
13512
13513 @item breakpoint
13514 @cindex @code{breakpoint} subroutine, remote
13515 Use this auxiliary subroutine to make your program contain a
13516 breakpoint. Depending on the particular situation, this may be the only
13517 way for @value{GDBN} to get control. For instance, if your target
13518 machine has some sort of interrupt button, you won't need to call this;
13519 pressing the interrupt button transfers control to
13520 @code{handle_exception}---in effect, to @value{GDBN}. On some machines,
13521 simply receiving characters on the serial port may also trigger a trap;
13522 again, in that situation, you don't need to call @code{breakpoint} from
13523 your own program---simply running @samp{target remote} from the host
13524 @value{GDBN} session gets control.
13525
13526 Call @code{breakpoint} if none of these is true, or if you simply want
13527 to make certain your program stops at a predetermined point for the
13528 start of your debugging session.
13529 @end table
13530
13531 @node Bootstrapping
13532 @subsection What You Must Do for the Stub
13533
13534 @cindex remote stub, support routines
13535 The debugging stubs that come with @value{GDBN} are set up for a particular
13536 chip architecture, but they have no information about the rest of your
13537 debugging target machine.
13538
13539 First of all you need to tell the stub how to communicate with the
13540 serial port.
13541
13542 @table @code
13543 @item int getDebugChar()
13544 @findex getDebugChar
13545 Write this subroutine to read a single character from the serial port.
13546 It may be identical to @code{getchar} for your target system; a
13547 different name is used to allow you to distinguish the two if you wish.
13548
13549 @item void putDebugChar(int)
13550 @findex putDebugChar
13551 Write this subroutine to write a single character to the serial port.
13552 It may be identical to @code{putchar} for your target system; a
13553 different name is used to allow you to distinguish the two if you wish.
13554 @end table
13555
13556 @cindex control C, and remote debugging
13557 @cindex interrupting remote targets
13558 If you want @value{GDBN} to be able to stop your program while it is
13559 running, you need to use an interrupt-driven serial driver, and arrange
13560 for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
13561 character). That is the character which @value{GDBN} uses to tell the
13562 remote system to stop.
13563
13564 Getting the debugging target to return the proper status to @value{GDBN}
13565 probably requires changes to the standard stub; one quick and dirty way
13566 is to just execute a breakpoint instruction (the ``dirty'' part is that
13567 @value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
13568
13569 Other routines you need to supply are:
13570
13571 @table @code
13572 @item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
13573 @findex exceptionHandler
13574 Write this function to install @var{exception_address} in the exception
13575 handling tables. You need to do this because the stub does not have any
13576 way of knowing what the exception handling tables on your target system
13577 are like (for example, the processor's table might be in @sc{rom},
13578 containing entries which point to a table in @sc{ram}).
13579 @var{exception_number} is the exception number which should be changed;
13580 its meaning is architecture-dependent (for example, different numbers
13581 might represent divide by zero, misaligned access, etc). When this
13582 exception occurs, control should be transferred directly to
13583 @var{exception_address}, and the processor state (stack, registers,
13584 and so on) should be just as it is when a processor exception occurs. So if
13585 you want to use a jump instruction to reach @var{exception_address}, it
13586 should be a simple jump, not a jump to subroutine.
13587
13588 For the 386, @var{exception_address} should be installed as an interrupt
13589 gate so that interrupts are masked while the handler runs. The gate
13590 should be at privilege level 0 (the most privileged level). The
13591 @sc{sparc} and 68k stubs are able to mask interrupts themselves without
13592 help from @code{exceptionHandler}.
13593
13594 @item void flush_i_cache()
13595 @findex flush_i_cache
13596 On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
13597 instruction cache, if any, on your target machine. If there is no
13598 instruction cache, this subroutine may be a no-op.
13599
13600 On target machines that have instruction caches, @value{GDBN} requires this
13601 function to make certain that the state of your program is stable.
13602 @end table
13603
13604 @noindent
13605 You must also make sure this library routine is available:
13606
13607 @table @code
13608 @item void *memset(void *, int, int)
13609 @findex memset
13610 This is the standard library function @code{memset} that sets an area of
13611 memory to a known value. If you have one of the free versions of
13612 @code{libc.a}, @code{memset} can be found there; otherwise, you must
13613 either obtain it from your hardware manufacturer, or write your own.
13614 @end table
13615
13616 If you do not use the GNU C compiler, you may need other standard
13617 library subroutines as well; this varies from one stub to another,
13618 but in general the stubs are likely to use any of the common library
13619 subroutines which @code{@value{NGCC}} generates as inline code.
13620
13621
13622 @node Debug Session
13623 @subsection Putting it All Together
13624
13625 @cindex remote serial debugging summary
13626 In summary, when your program is ready to debug, you must follow these
13627 steps.
13628
13629 @enumerate
13630 @item
13631 Make sure you have defined the supporting low-level routines
13632 (@pxref{Bootstrapping,,What You Must Do for the Stub}):
13633 @display
13634 @code{getDebugChar}, @code{putDebugChar},
13635 @code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
13636 @end display
13637
13638 @item
13639 Insert these lines near the top of your program:
13640
13641 @smallexample
13642 set_debug_traps();
13643 breakpoint();
13644 @end smallexample
13645
13646 @item
13647 For the 680x0 stub only, you need to provide a variable called
13648 @code{exceptionHook}. Normally you just use:
13649
13650 @smallexample
13651 void (*exceptionHook)() = 0;
13652 @end smallexample
13653
13654 @noindent
13655 but if before calling @code{set_debug_traps}, you set it to point to a
13656 function in your program, that function is called when
13657 @code{@value{GDBN}} continues after stopping on a trap (for example, bus
13658 error). The function indicated by @code{exceptionHook} is called with
13659 one parameter: an @code{int} which is the exception number.
13660
13661 @item
13662 Compile and link together: your program, the @value{GDBN} debugging stub for
13663 your target architecture, and the supporting subroutines.
13664
13665 @item
13666 Make sure you have a serial connection between your target machine and
13667 the @value{GDBN} host, and identify the serial port on the host.
13668
13669 @item
13670 @c The "remote" target now provides a `load' command, so we should
13671 @c document that. FIXME.
13672 Download your program to your target machine (or get it there by
13673 whatever means the manufacturer provides), and start it.
13674
13675 @item
13676 Start @value{GDBN} on the host, and connect to the target
13677 (@pxref{Connecting,,Connecting to a Remote Target}).
13678
13679 @end enumerate
13680
13681 @node Configurations
13682 @chapter Configuration-Specific Information
13683
13684 While nearly all @value{GDBN} commands are available for all native and
13685 cross versions of the debugger, there are some exceptions. This chapter
13686 describes things that are only available in certain configurations.
13687
13688 There are three major categories of configurations: native
13689 configurations, where the host and target are the same, embedded
13690 operating system configurations, which are usually the same for several
13691 different processor architectures, and bare embedded processors, which
13692 are quite different from each other.
13693
13694 @menu
13695 * Native::
13696 * Embedded OS::
13697 * Embedded Processors::
13698 * Architectures::
13699 @end menu
13700
13701 @node Native
13702 @section Native
13703
13704 This section describes details specific to particular native
13705 configurations.
13706
13707 @menu
13708 * HP-UX:: HP-UX
13709 * BSD libkvm Interface:: Debugging BSD kernel memory images
13710 * SVR4 Process Information:: SVR4 process information
13711 * DJGPP Native:: Features specific to the DJGPP port
13712 * Cygwin Native:: Features specific to the Cygwin port
13713 * Hurd Native:: Features specific to @sc{gnu} Hurd
13714 * Neutrino:: Features specific to QNX Neutrino
13715 @end menu
13716
13717 @node HP-UX
13718 @subsection HP-UX
13719
13720 On HP-UX systems, if you refer to a function or variable name that
13721 begins with a dollar sign, @value{GDBN} searches for a user or system
13722 name first, before it searches for a convenience variable.
13723
13724
13725 @node BSD libkvm Interface
13726 @subsection BSD libkvm Interface
13727
13728 @cindex libkvm
13729 @cindex kernel memory image
13730 @cindex kernel crash dump
13731
13732 BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
13733 interface that provides a uniform interface for accessing kernel virtual
13734 memory images, including live systems and crash dumps. @value{GDBN}
13735 uses this interface to allow you to debug live kernels and kernel crash
13736 dumps on many native BSD configurations. This is implemented as a
13737 special @code{kvm} debugging target. For debugging a live system, load
13738 the currently running kernel into @value{GDBN} and connect to the
13739 @code{kvm} target:
13740
13741 @smallexample
13742 (@value{GDBP}) @b{target kvm}
13743 @end smallexample
13744
13745 For debugging crash dumps, provide the file name of the crash dump as an
13746 argument:
13747
13748 @smallexample
13749 (@value{GDBP}) @b{target kvm /var/crash/bsd.0}
13750 @end smallexample
13751
13752 Once connected to the @code{kvm} target, the following commands are
13753 available:
13754
13755 @table @code
13756 @kindex kvm
13757 @item kvm pcb
13758 Set current context from the @dfn{Process Control Block} (PCB) address.
13759
13760 @item kvm proc
13761 Set current context from proc address. This command isn't available on
13762 modern FreeBSD systems.
13763 @end table
13764
13765 @node SVR4 Process Information
13766 @subsection SVR4 Process Information
13767 @cindex /proc
13768 @cindex examine process image
13769 @cindex process info via @file{/proc}
13770
13771 Many versions of SVR4 and compatible systems provide a facility called
13772 @samp{/proc} that can be used to examine the image of a running
13773 process using file-system subroutines. If @value{GDBN} is configured
13774 for an operating system with this facility, the command @code{info
13775 proc} is available to report information about the process running
13776 your program, or about any process running on your system. @code{info
13777 proc} works only on SVR4 systems that include the @code{procfs} code.
13778 This includes, as of this writing, @sc{gnu}/Linux, OSF/1 (Digital
13779 Unix), Solaris, Irix, and Unixware, but not HP-UX, for example.
13780
13781 @table @code
13782 @kindex info proc
13783 @cindex process ID
13784 @item info proc
13785 @itemx info proc @var{process-id}
13786 Summarize available information about any running process. If a
13787 process ID is specified by @var{process-id}, display information about
13788 that process; otherwise display information about the program being
13789 debugged. The summary includes the debugged process ID, the command
13790 line used to invoke it, its current working directory, and its
13791 executable file's absolute file name.
13792
13793 On some systems, @var{process-id} can be of the form
13794 @samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
13795 within a process. If the optional @var{pid} part is missing, it means
13796 a thread from the process being debugged (the leading @samp{/} still
13797 needs to be present, or else @value{GDBN} will interpret the number as
13798 a process ID rather than a thread ID).
13799
13800 @item info proc mappings
13801 @cindex memory address space mappings
13802 Report the memory address space ranges accessible in the program, with
13803 information on whether the process has read, write, or execute access
13804 rights to each range. On @sc{gnu}/Linux systems, each memory range
13805 includes the object file which is mapped to that range, instead of the
13806 memory access rights to that range.
13807
13808 @item info proc stat
13809 @itemx info proc status
13810 @cindex process detailed status information
13811 These subcommands are specific to @sc{gnu}/Linux systems. They show
13812 the process-related information, including the user ID and group ID;
13813 how many threads are there in the process; its virtual memory usage;
13814 the signals that are pending, blocked, and ignored; its TTY; its
13815 consumption of system and user time; its stack size; its @samp{nice}
13816 value; etc. For more information, see the @samp{proc} man page
13817 (type @kbd{man 5 proc} from your shell prompt).
13818
13819 @item info proc all
13820 Show all the information about the process described under all of the
13821 above @code{info proc} subcommands.
13822
13823 @ignore
13824 @comment These sub-options of 'info proc' were not included when
13825 @comment procfs.c was re-written. Keep their descriptions around
13826 @comment against the day when someone finds the time to put them back in.
13827 @kindex info proc times
13828 @item info proc times
13829 Starting time, user CPU time, and system CPU time for your program and
13830 its children.
13831
13832 @kindex info proc id
13833 @item info proc id
13834 Report on the process IDs related to your program: its own process ID,
13835 the ID of its parent, the process group ID, and the session ID.
13836 @end ignore
13837
13838 @item set procfs-trace
13839 @kindex set procfs-trace
13840 @cindex @code{procfs} API calls
13841 This command enables and disables tracing of @code{procfs} API calls.
13842
13843 @item show procfs-trace
13844 @kindex show procfs-trace
13845 Show the current state of @code{procfs} API call tracing.
13846
13847 @item set procfs-file @var{file}
13848 @kindex set procfs-file
13849 Tell @value{GDBN} to write @code{procfs} API trace to the named
13850 @var{file}. @value{GDBN} appends the trace info to the previous
13851 contents of the file. The default is to display the trace on the
13852 standard output.
13853
13854 @item show procfs-file
13855 @kindex show procfs-file
13856 Show the file to which @code{procfs} API trace is written.
13857
13858 @item proc-trace-entry
13859 @itemx proc-trace-exit
13860 @itemx proc-untrace-entry
13861 @itemx proc-untrace-exit
13862 @kindex proc-trace-entry
13863 @kindex proc-trace-exit
13864 @kindex proc-untrace-entry
13865 @kindex proc-untrace-exit
13866 These commands enable and disable tracing of entries into and exits
13867 from the @code{syscall} interface.
13868
13869 @item info pidlist
13870 @kindex info pidlist
13871 @cindex process list, QNX Neutrino
13872 For QNX Neutrino only, this command displays the list of all the
13873 processes and all the threads within each process.
13874
13875 @item info meminfo
13876 @kindex info meminfo
13877 @cindex mapinfo list, QNX Neutrino
13878 For QNX Neutrino only, this command displays the list of all mapinfos.
13879 @end table
13880
13881 @node DJGPP Native
13882 @subsection Features for Debugging @sc{djgpp} Programs
13883 @cindex @sc{djgpp} debugging
13884 @cindex native @sc{djgpp} debugging
13885 @cindex MS-DOS-specific commands
13886
13887 @cindex DPMI
13888 @sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
13889 MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
13890 that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
13891 top of real-mode DOS systems and their emulations.
13892
13893 @value{GDBN} supports native debugging of @sc{djgpp} programs, and
13894 defines a few commands specific to the @sc{djgpp} port. This
13895 subsection describes those commands.
13896
13897 @table @code
13898 @kindex info dos
13899 @item info dos
13900 This is a prefix of @sc{djgpp}-specific commands which print
13901 information about the target system and important OS structures.
13902
13903 @kindex sysinfo
13904 @cindex MS-DOS system info
13905 @cindex free memory information (MS-DOS)
13906 @item info dos sysinfo
13907 This command displays assorted information about the underlying
13908 platform: the CPU type and features, the OS version and flavor, the
13909 DPMI version, and the available conventional and DPMI memory.
13910
13911 @cindex GDT
13912 @cindex LDT
13913 @cindex IDT
13914 @cindex segment descriptor tables
13915 @cindex descriptor tables display
13916 @item info dos gdt
13917 @itemx info dos ldt
13918 @itemx info dos idt
13919 These 3 commands display entries from, respectively, Global, Local,
13920 and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
13921 tables are data structures which store a descriptor for each segment
13922 that is currently in use. The segment's selector is an index into a
13923 descriptor table; the table entry for that index holds the
13924 descriptor's base address and limit, and its attributes and access
13925 rights.
13926
13927 A typical @sc{djgpp} program uses 3 segments: a code segment, a data
13928 segment (used for both data and the stack), and a DOS segment (which
13929 allows access to DOS/BIOS data structures and absolute addresses in
13930 conventional memory). However, the DPMI host will usually define
13931 additional segments in order to support the DPMI environment.
13932
13933 @cindex garbled pointers
13934 These commands allow to display entries from the descriptor tables.
13935 Without an argument, all entries from the specified table are
13936 displayed. An argument, which should be an integer expression, means
13937 display a single entry whose index is given by the argument. For
13938 example, here's a convenient way to display information about the
13939 debugged program's data segment:
13940
13941 @smallexample
13942 @exdent @code{(@value{GDBP}) info dos ldt $ds}
13943 @exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
13944 @end smallexample
13945
13946 @noindent
13947 This comes in handy when you want to see whether a pointer is outside
13948 the data segment's limit (i.e.@: @dfn{garbled}).
13949
13950 @cindex page tables display (MS-DOS)
13951 @item info dos pde
13952 @itemx info dos pte
13953 These two commands display entries from, respectively, the Page
13954 Directory and the Page Tables. Page Directories and Page Tables are
13955 data structures which control how virtual memory addresses are mapped
13956 into physical addresses. A Page Table includes an entry for every
13957 page of memory that is mapped into the program's address space; there
13958 may be several Page Tables, each one holding up to 4096 entries. A
13959 Page Directory has up to 4096 entries, one each for every Page Table
13960 that is currently in use.
13961
13962 Without an argument, @kbd{info dos pde} displays the entire Page
13963 Directory, and @kbd{info dos pte} displays all the entries in all of
13964 the Page Tables. An argument, an integer expression, given to the
13965 @kbd{info dos pde} command means display only that entry from the Page
13966 Directory table. An argument given to the @kbd{info dos pte} command
13967 means display entries from a single Page Table, the one pointed to by
13968 the specified entry in the Page Directory.
13969
13970 @cindex direct memory access (DMA) on MS-DOS
13971 These commands are useful when your program uses @dfn{DMA} (Direct
13972 Memory Access), which needs physical addresses to program the DMA
13973 controller.
13974
13975 These commands are supported only with some DPMI servers.
13976
13977 @cindex physical address from linear address
13978 @item info dos address-pte @var{addr}
13979 This command displays the Page Table entry for a specified linear
13980 address. The argument @var{addr} is a linear address which should
13981 already have the appropriate segment's base address added to it,
13982 because this command accepts addresses which may belong to @emph{any}
13983 segment. For example, here's how to display the Page Table entry for
13984 the page where a variable @code{i} is stored:
13985
13986 @smallexample
13987 @exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
13988 @exdent @code{Page Table entry for address 0x11a00d30:}
13989 @exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
13990 @end smallexample
13991
13992 @noindent
13993 This says that @code{i} is stored at offset @code{0xd30} from the page
13994 whose physical base address is @code{0x02698000}, and shows all the
13995 attributes of that page.
13996
13997 Note that you must cast the addresses of variables to a @code{char *},
13998 since otherwise the value of @code{__djgpp_base_address}, the base
13999 address of all variables and functions in a @sc{djgpp} program, will
14000 be added using the rules of C pointer arithmetics: if @code{i} is
14001 declared an @code{int}, @value{GDBN} will add 4 times the value of
14002 @code{__djgpp_base_address} to the address of @code{i}.
14003
14004 Here's another example, it displays the Page Table entry for the
14005 transfer buffer:
14006
14007 @smallexample
14008 @exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
14009 @exdent @code{Page Table entry for address 0x29110:}
14010 @exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
14011 @end smallexample
14012
14013 @noindent
14014 (The @code{+ 3} offset is because the transfer buffer's address is the
14015 3rd member of the @code{_go32_info_block} structure.) The output
14016 clearly shows that this DPMI server maps the addresses in conventional
14017 memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
14018 linear (@code{0x29110}) addresses are identical.
14019
14020 This command is supported only with some DPMI servers.
14021 @end table
14022
14023 @cindex DOS serial data link, remote debugging
14024 In addition to native debugging, the DJGPP port supports remote
14025 debugging via a serial data link. The following commands are specific
14026 to remote serial debugging in the DJGPP port of @value{GDBN}.
14027
14028 @table @code
14029 @kindex set com1base
14030 @kindex set com1irq
14031 @kindex set com2base
14032 @kindex set com2irq
14033 @kindex set com3base
14034 @kindex set com3irq
14035 @kindex set com4base
14036 @kindex set com4irq
14037 @item set com1base @var{addr}
14038 This command sets the base I/O port address of the @file{COM1} serial
14039 port.
14040
14041 @item set com1irq @var{irq}
14042 This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
14043 for the @file{COM1} serial port.
14044
14045 There are similar commands @samp{set com2base}, @samp{set com3irq},
14046 etc.@: for setting the port address and the @code{IRQ} lines for the
14047 other 3 COM ports.
14048
14049 @kindex show com1base
14050 @kindex show com1irq
14051 @kindex show com2base
14052 @kindex show com2irq
14053 @kindex show com3base
14054 @kindex show com3irq
14055 @kindex show com4base
14056 @kindex show com4irq
14057 The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
14058 display the current settings of the base address and the @code{IRQ}
14059 lines used by the COM ports.
14060
14061 @item info serial
14062 @kindex info serial
14063 @cindex DOS serial port status
14064 This command prints the status of the 4 DOS serial ports. For each
14065 port, it prints whether it's active or not, its I/O base address and
14066 IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
14067 counts of various errors encountered so far.
14068 @end table
14069
14070
14071 @node Cygwin Native
14072 @subsection Features for Debugging MS Windows PE Executables
14073 @cindex MS Windows debugging
14074 @cindex native Cygwin debugging
14075 @cindex Cygwin-specific commands
14076
14077 @value{GDBN} supports native debugging of MS Windows programs, including
14078 DLLs with and without symbolic debugging information. There are various
14079 additional Cygwin-specific commands, described in this section.
14080 Working with DLLs that have no debugging symbols is described in
14081 @ref{Non-debug DLL Symbols}.
14082
14083 @table @code
14084 @kindex info w32
14085 @item info w32
14086 This is a prefix of MS Windows-specific commands which print
14087 information about the target system and important OS structures.
14088
14089 @item info w32 selector
14090 This command displays information returned by
14091 the Win32 API @code{GetThreadSelectorEntry} function.
14092 It takes an optional argument that is evaluated to
14093 a long value to give the information about this given selector.
14094 Without argument, this command displays information
14095 about the six segment registers.
14096
14097 @kindex info dll
14098 @item info dll
14099 This is a Cygwin-specific alias of @code{info shared}.
14100
14101 @kindex dll-symbols
14102 @item dll-symbols
14103 This command loads symbols from a dll similarly to
14104 add-sym command but without the need to specify a base address.
14105
14106 @kindex set cygwin-exceptions
14107 @cindex debugging the Cygwin DLL
14108 @cindex Cygwin DLL, debugging
14109 @item set cygwin-exceptions @var{mode}
14110 If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
14111 happen inside the Cygwin DLL. If @var{mode} is @code{off},
14112 @value{GDBN} will delay recognition of exceptions, and may ignore some
14113 exceptions which seem to be caused by internal Cygwin DLL
14114 ``bookkeeping''. This option is meant primarily for debugging the
14115 Cygwin DLL itself; the default value is @code{off} to avoid annoying
14116 @value{GDBN} users with false @code{SIGSEGV} signals.
14117
14118 @kindex show cygwin-exceptions
14119 @item show cygwin-exceptions
14120 Displays whether @value{GDBN} will break on exceptions that happen
14121 inside the Cygwin DLL itself.
14122
14123 @kindex set new-console
14124 @item set new-console @var{mode}
14125 If @var{mode} is @code{on} the debuggee will
14126 be started in a new console on next start.
14127 If @var{mode} is @code{off}i, the debuggee will
14128 be started in the same console as the debugger.
14129
14130 @kindex show new-console
14131 @item show new-console
14132 Displays whether a new console is used
14133 when the debuggee is started.
14134
14135 @kindex set new-group
14136 @item set new-group @var{mode}
14137 This boolean value controls whether the debuggee should
14138 start a new group or stay in the same group as the debugger.
14139 This affects the way the Windows OS handles
14140 @samp{Ctrl-C}.
14141
14142 @kindex show new-group
14143 @item show new-group
14144 Displays current value of new-group boolean.
14145
14146 @kindex set debugevents
14147 @item set debugevents
14148 This boolean value adds debug output concerning kernel events related
14149 to the debuggee seen by the debugger. This includes events that
14150 signal thread and process creation and exit, DLL loading and
14151 unloading, console interrupts, and debugging messages produced by the
14152 Windows @code{OutputDebugString} API call.
14153
14154 @kindex set debugexec
14155 @item set debugexec
14156 This boolean value adds debug output concerning execute events
14157 (such as resume thread) seen by the debugger.
14158
14159 @kindex set debugexceptions
14160 @item set debugexceptions
14161 This boolean value adds debug output concerning exceptions in the
14162 debuggee seen by the debugger.
14163
14164 @kindex set debugmemory
14165 @item set debugmemory
14166 This boolean value adds debug output concerning debuggee memory reads
14167 and writes by the debugger.
14168
14169 @kindex set shell
14170 @item set shell
14171 This boolean values specifies whether the debuggee is called
14172 via a shell or directly (default value is on).
14173
14174 @kindex show shell
14175 @item show shell
14176 Displays if the debuggee will be started with a shell.
14177
14178 @end table
14179
14180 @menu
14181 * Non-debug DLL Symbols:: Support for DLLs without debugging symbols
14182 @end menu
14183
14184 @node Non-debug DLL Symbols
14185 @subsubsection Support for DLLs without Debugging Symbols
14186 @cindex DLLs with no debugging symbols
14187 @cindex Minimal symbols and DLLs
14188
14189 Very often on windows, some of the DLLs that your program relies on do
14190 not include symbolic debugging information (for example,
14191 @file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
14192 symbols in a DLL, it relies on the minimal amount of symbolic
14193 information contained in the DLL's export table. This section
14194 describes working with such symbols, known internally to @value{GDBN} as
14195 ``minimal symbols''.
14196
14197 Note that before the debugged program has started execution, no DLLs
14198 will have been loaded. The easiest way around this problem is simply to
14199 start the program --- either by setting a breakpoint or letting the
14200 program run once to completion. It is also possible to force
14201 @value{GDBN} to load a particular DLL before starting the executable ---
14202 see the shared library information in @ref{Files}, or the
14203 @code{dll-symbols} command in @ref{Cygwin Native}. Currently,
14204 explicitly loading symbols from a DLL with no debugging information will
14205 cause the symbol names to be duplicated in @value{GDBN}'s lookup table,
14206 which may adversely affect symbol lookup performance.
14207
14208 @subsubsection DLL Name Prefixes
14209
14210 In keeping with the naming conventions used by the Microsoft debugging
14211 tools, DLL export symbols are made available with a prefix based on the
14212 DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
14213 also entered into the symbol table, so @code{CreateFileA} is often
14214 sufficient. In some cases there will be name clashes within a program
14215 (particularly if the executable itself includes full debugging symbols)
14216 necessitating the use of the fully qualified name when referring to the
14217 contents of the DLL. Use single-quotes around the name to avoid the
14218 exclamation mark (``!'') being interpreted as a language operator.
14219
14220 Note that the internal name of the DLL may be all upper-case, even
14221 though the file name of the DLL is lower-case, or vice-versa. Since
14222 symbols within @value{GDBN} are @emph{case-sensitive} this may cause
14223 some confusion. If in doubt, try the @code{info functions} and
14224 @code{info variables} commands or even @code{maint print msymbols}
14225 (@pxref{Symbols}). Here's an example:
14226
14227 @smallexample
14228 (@value{GDBP}) info function CreateFileA
14229 All functions matching regular expression "CreateFileA":
14230
14231 Non-debugging symbols:
14232 0x77e885f4 CreateFileA
14233 0x77e885f4 KERNEL32!CreateFileA
14234 @end smallexample
14235
14236 @smallexample
14237 (@value{GDBP}) info function !
14238 All functions matching regular expression "!":
14239
14240 Non-debugging symbols:
14241 0x6100114c cygwin1!__assert
14242 0x61004034 cygwin1!_dll_crt0@@0
14243 0x61004240 cygwin1!dll_crt0(per_process *)
14244 [etc...]
14245 @end smallexample
14246
14247 @subsubsection Working with Minimal Symbols
14248
14249 Symbols extracted from a DLL's export table do not contain very much
14250 type information. All that @value{GDBN} can do is guess whether a symbol
14251 refers to a function or variable depending on the linker section that
14252 contains the symbol. Also note that the actual contents of the memory
14253 contained in a DLL are not available unless the program is running. This
14254 means that you cannot examine the contents of a variable or disassemble
14255 a function within a DLL without a running program.
14256
14257 Variables are generally treated as pointers and dereferenced
14258 automatically. For this reason, it is often necessary to prefix a
14259 variable name with the address-of operator (``&'') and provide explicit
14260 type information in the command. Here's an example of the type of
14261 problem:
14262
14263 @smallexample
14264 (@value{GDBP}) print 'cygwin1!__argv'
14265 $1 = 268572168
14266 @end smallexample
14267
14268 @smallexample
14269 (@value{GDBP}) x 'cygwin1!__argv'
14270 0x10021610: "\230y\""
14271 @end smallexample
14272
14273 And two possible solutions:
14274
14275 @smallexample
14276 (@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
14277 $2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
14278 @end smallexample
14279
14280 @smallexample
14281 (@value{GDBP}) x/2x &'cygwin1!__argv'
14282 0x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
14283 (@value{GDBP}) x/x 0x10021608
14284 0x10021608: 0x0022fd98
14285 (@value{GDBP}) x/s 0x0022fd98
14286 0x22fd98: "/cygdrive/c/mydirectory/myprogram"
14287 @end smallexample
14288
14289 Setting a break point within a DLL is possible even before the program
14290 starts execution. However, under these circumstances, @value{GDBN} can't
14291 examine the initial instructions of the function in order to skip the
14292 function's frame set-up code. You can work around this by using ``*&''
14293 to set the breakpoint at a raw memory address:
14294
14295 @smallexample
14296 (@value{GDBP}) break *&'python22!PyOS_Readline'
14297 Breakpoint 1 at 0x1e04eff0
14298 @end smallexample
14299
14300 The author of these extensions is not entirely convinced that setting a
14301 break point within a shared DLL like @file{kernel32.dll} is completely
14302 safe.
14303
14304 @node Hurd Native
14305 @subsection Commands Specific to @sc{gnu} Hurd Systems
14306 @cindex @sc{gnu} Hurd debugging
14307
14308 This subsection describes @value{GDBN} commands specific to the
14309 @sc{gnu} Hurd native debugging.
14310
14311 @table @code
14312 @item set signals
14313 @itemx set sigs
14314 @kindex set signals@r{, Hurd command}
14315 @kindex set sigs@r{, Hurd command}
14316 This command toggles the state of inferior signal interception by
14317 @value{GDBN}. Mach exceptions, such as breakpoint traps, are not
14318 affected by this command. @code{sigs} is a shorthand alias for
14319 @code{signals}.
14320
14321 @item show signals
14322 @itemx show sigs
14323 @kindex show signals@r{, Hurd command}
14324 @kindex show sigs@r{, Hurd command}
14325 Show the current state of intercepting inferior's signals.
14326
14327 @item set signal-thread
14328 @itemx set sigthread
14329 @kindex set signal-thread
14330 @kindex set sigthread
14331 This command tells @value{GDBN} which thread is the @code{libc} signal
14332 thread. That thread is run when a signal is delivered to a running
14333 process. @code{set sigthread} is the shorthand alias of @code{set
14334 signal-thread}.
14335
14336 @item show signal-thread
14337 @itemx show sigthread
14338 @kindex show signal-thread
14339 @kindex show sigthread
14340 These two commands show which thread will run when the inferior is
14341 delivered a signal.
14342
14343 @item set stopped
14344 @kindex set stopped@r{, Hurd command}
14345 This commands tells @value{GDBN} that the inferior process is stopped,
14346 as with the @code{SIGSTOP} signal. The stopped process can be
14347 continued by delivering a signal to it.
14348
14349 @item show stopped
14350 @kindex show stopped@r{, Hurd command}
14351 This command shows whether @value{GDBN} thinks the debuggee is
14352 stopped.
14353
14354 @item set exceptions
14355 @kindex set exceptions@r{, Hurd command}
14356 Use this command to turn off trapping of exceptions in the inferior.
14357 When exception trapping is off, neither breakpoints nor
14358 single-stepping will work. To restore the default, set exception
14359 trapping on.
14360
14361 @item show exceptions
14362 @kindex show exceptions@r{, Hurd command}
14363 Show the current state of trapping exceptions in the inferior.
14364
14365 @item set task pause
14366 @kindex set task@r{, Hurd commands}
14367 @cindex task attributes (@sc{gnu} Hurd)
14368 @cindex pause current task (@sc{gnu} Hurd)
14369 This command toggles task suspension when @value{GDBN} has control.
14370 Setting it to on takes effect immediately, and the task is suspended
14371 whenever @value{GDBN} gets control. Setting it to off will take
14372 effect the next time the inferior is continued. If this option is set
14373 to off, you can use @code{set thread default pause on} or @code{set
14374 thread pause on} (see below) to pause individual threads.
14375
14376 @item show task pause
14377 @kindex show task@r{, Hurd commands}
14378 Show the current state of task suspension.
14379
14380 @item set task detach-suspend-count
14381 @cindex task suspend count
14382 @cindex detach from task, @sc{gnu} Hurd
14383 This command sets the suspend count the task will be left with when
14384 @value{GDBN} detaches from it.
14385
14386 @item show task detach-suspend-count
14387 Show the suspend count the task will be left with when detaching.
14388
14389 @item set task exception-port
14390 @itemx set task excp
14391 @cindex task exception port, @sc{gnu} Hurd
14392 This command sets the task exception port to which @value{GDBN} will
14393 forward exceptions. The argument should be the value of the @dfn{send
14394 rights} of the task. @code{set task excp} is a shorthand alias.
14395
14396 @item set noninvasive
14397 @cindex noninvasive task options
14398 This command switches @value{GDBN} to a mode that is the least
14399 invasive as far as interfering with the inferior is concerned. This
14400 is the same as using @code{set task pause}, @code{set exceptions}, and
14401 @code{set signals} to values opposite to the defaults.
14402
14403 @item info send-rights
14404 @itemx info receive-rights
14405 @itemx info port-rights
14406 @itemx info port-sets
14407 @itemx info dead-names
14408 @itemx info ports
14409 @itemx info psets
14410 @cindex send rights, @sc{gnu} Hurd
14411 @cindex receive rights, @sc{gnu} Hurd
14412 @cindex port rights, @sc{gnu} Hurd
14413 @cindex port sets, @sc{gnu} Hurd
14414 @cindex dead names, @sc{gnu} Hurd
14415 These commands display information about, respectively, send rights,
14416 receive rights, port rights, port sets, and dead names of a task.
14417 There are also shorthand aliases: @code{info ports} for @code{info
14418 port-rights} and @code{info psets} for @code{info port-sets}.
14419
14420 @item set thread pause
14421 @kindex set thread@r{, Hurd command}
14422 @cindex thread properties, @sc{gnu} Hurd
14423 @cindex pause current thread (@sc{gnu} Hurd)
14424 This command toggles current thread suspension when @value{GDBN} has
14425 control. Setting it to on takes effect immediately, and the current
14426 thread is suspended whenever @value{GDBN} gets control. Setting it to
14427 off will take effect the next time the inferior is continued.
14428 Normally, this command has no effect, since when @value{GDBN} has
14429 control, the whole task is suspended. However, if you used @code{set
14430 task pause off} (see above), this command comes in handy to suspend
14431 only the current thread.
14432
14433 @item show thread pause
14434 @kindex show thread@r{, Hurd command}
14435 This command shows the state of current thread suspension.
14436
14437 @item set thread run
14438 This command sets whether the current thread is allowed to run.
14439
14440 @item show thread run
14441 Show whether the current thread is allowed to run.
14442
14443 @item set thread detach-suspend-count
14444 @cindex thread suspend count, @sc{gnu} Hurd
14445 @cindex detach from thread, @sc{gnu} Hurd
14446 This command sets the suspend count @value{GDBN} will leave on a
14447 thread when detaching. This number is relative to the suspend count
14448 found by @value{GDBN} when it notices the thread; use @code{set thread
14449 takeover-suspend-count} to force it to an absolute value.
14450
14451 @item show thread detach-suspend-count
14452 Show the suspend count @value{GDBN} will leave on the thread when
14453 detaching.
14454
14455 @item set thread exception-port
14456 @itemx set thread excp
14457 Set the thread exception port to which to forward exceptions. This
14458 overrides the port set by @code{set task exception-port} (see above).
14459 @code{set thread excp} is the shorthand alias.
14460
14461 @item set thread takeover-suspend-count
14462 Normally, @value{GDBN}'s thread suspend counts are relative to the
14463 value @value{GDBN} finds when it notices each thread. This command
14464 changes the suspend counts to be absolute instead.
14465
14466 @item set thread default
14467 @itemx show thread default
14468 @cindex thread default settings, @sc{gnu} Hurd
14469 Each of the above @code{set thread} commands has a @code{set thread
14470 default} counterpart (e.g., @code{set thread default pause}, @code{set
14471 thread default exception-port}, etc.). The @code{thread default}
14472 variety of commands sets the default thread properties for all
14473 threads; you can then change the properties of individual threads with
14474 the non-default commands.
14475 @end table
14476
14477
14478 @node Neutrino
14479 @subsection QNX Neutrino
14480 @cindex QNX Neutrino
14481
14482 @value{GDBN} provides the following commands specific to the QNX
14483 Neutrino target:
14484
14485 @table @code
14486 @item set debug nto-debug
14487 @kindex set debug nto-debug
14488 When set to on, enables debugging messages specific to the QNX
14489 Neutrino support.
14490
14491 @item show debug nto-debug
14492 @kindex show debug nto-debug
14493 Show the current state of QNX Neutrino messages.
14494 @end table
14495
14496
14497 @node Embedded OS
14498 @section Embedded Operating Systems
14499
14500 This section describes configurations involving the debugging of
14501 embedded operating systems that are available for several different
14502 architectures.
14503
14504 @menu
14505 * VxWorks:: Using @value{GDBN} with VxWorks
14506 @end menu
14507
14508 @value{GDBN} includes the ability to debug programs running on
14509 various real-time operating systems.
14510
14511 @node VxWorks
14512 @subsection Using @value{GDBN} with VxWorks
14513
14514 @cindex VxWorks
14515
14516 @table @code
14517
14518 @kindex target vxworks
14519 @item target vxworks @var{machinename}
14520 A VxWorks system, attached via TCP/IP. The argument @var{machinename}
14521 is the target system's machine name or IP address.
14522
14523 @end table
14524
14525 On VxWorks, @code{load} links @var{filename} dynamically on the
14526 current target system as well as adding its symbols in @value{GDBN}.
14527
14528 @value{GDBN} enables developers to spawn and debug tasks running on networked
14529 VxWorks targets from a Unix host. Already-running tasks spawned from
14530 the VxWorks shell can also be debugged. @value{GDBN} uses code that runs on
14531 both the Unix host and on the VxWorks target. The program
14532 @code{@value{GDBP}} is installed and executed on the Unix host. (It may be
14533 installed with the name @code{vxgdb}, to distinguish it from a
14534 @value{GDBN} for debugging programs on the host itself.)
14535
14536 @table @code
14537 @item VxWorks-timeout @var{args}
14538 @kindex vxworks-timeout
14539 All VxWorks-based targets now support the option @code{vxworks-timeout}.
14540 This option is set by the user, and @var{args} represents the number of
14541 seconds @value{GDBN} waits for responses to rpc's. You might use this if
14542 your VxWorks target is a slow software simulator or is on the far side
14543 of a thin network line.
14544 @end table
14545
14546 The following information on connecting to VxWorks was current when
14547 this manual was produced; newer releases of VxWorks may use revised
14548 procedures.
14549
14550 @findex INCLUDE_RDB
14551 To use @value{GDBN} with VxWorks, you must rebuild your VxWorks kernel
14552 to include the remote debugging interface routines in the VxWorks
14553 library @file{rdb.a}. To do this, define @code{INCLUDE_RDB} in the
14554 VxWorks configuration file @file{configAll.h} and rebuild your VxWorks
14555 kernel. The resulting kernel contains @file{rdb.a}, and spawns the
14556 source debugging task @code{tRdbTask} when VxWorks is booted. For more
14557 information on configuring and remaking VxWorks, see the manufacturer's
14558 manual.
14559 @c VxWorks, see the @cite{VxWorks Programmer's Guide}.
14560
14561 Once you have included @file{rdb.a} in your VxWorks system image and set
14562 your Unix execution search path to find @value{GDBN}, you are ready to
14563 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}} (or
14564 @code{vxgdb}, depending on your installation).
14565
14566 @value{GDBN} comes up showing the prompt:
14567
14568 @smallexample
14569 (vxgdb)
14570 @end smallexample
14571
14572 @menu
14573 * VxWorks Connection:: Connecting to VxWorks
14574 * VxWorks Download:: VxWorks download
14575 * VxWorks Attach:: Running tasks
14576 @end menu
14577
14578 @node VxWorks Connection
14579 @subsubsection Connecting to VxWorks
14580
14581 The @value{GDBN} command @code{target} lets you connect to a VxWorks target on the
14582 network. To connect to a target whose host name is ``@code{tt}'', type:
14583
14584 @smallexample
14585 (vxgdb) target vxworks tt
14586 @end smallexample
14587
14588 @need 750
14589 @value{GDBN} displays messages like these:
14590
14591 @smallexample
14592 Attaching remote machine across net...
14593 Connected to tt.
14594 @end smallexample
14595
14596 @need 1000
14597 @value{GDBN} then attempts to read the symbol tables of any object modules
14598 loaded into the VxWorks target since it was last booted. @value{GDBN} locates
14599 these files by searching the directories listed in the command search
14600 path (@pxref{Environment, ,Your Program's Environment}); if it fails
14601 to find an object file, it displays a message such as:
14602
14603 @smallexample
14604 prog.o: No such file or directory.
14605 @end smallexample
14606
14607 When this happens, add the appropriate directory to the search path with
14608 the @value{GDBN} command @code{path}, and execute the @code{target}
14609 command again.
14610
14611 @node VxWorks Download
14612 @subsubsection VxWorks Download
14613
14614 @cindex download to VxWorks
14615 If you have connected to the VxWorks target and you want to debug an
14616 object that has not yet been loaded, you can use the @value{GDBN}
14617 @code{load} command to download a file from Unix to VxWorks
14618 incrementally. The object file given as an argument to the @code{load}
14619 command is actually opened twice: first by the VxWorks target in order
14620 to download the code, then by @value{GDBN} in order to read the symbol
14621 table. This can lead to problems if the current working directories on
14622 the two systems differ. If both systems have NFS mounted the same
14623 filesystems, you can avoid these problems by using absolute paths.
14624 Otherwise, it is simplest to set the working directory on both systems
14625 to the directory in which the object file resides, and then to reference
14626 the file by its name, without any path. For instance, a program
14627 @file{prog.o} may reside in @file{@var{vxpath}/vw/demo/rdb} in VxWorks
14628 and in @file{@var{hostpath}/vw/demo/rdb} on the host. To load this
14629 program, type this on VxWorks:
14630
14631 @smallexample
14632 -> cd "@var{vxpath}/vw/demo/rdb"
14633 @end smallexample
14634
14635 @noindent
14636 Then, in @value{GDBN}, type:
14637
14638 @smallexample
14639 (vxgdb) cd @var{hostpath}/vw/demo/rdb
14640 (vxgdb) load prog.o
14641 @end smallexample
14642
14643 @value{GDBN} displays a response similar to this:
14644
14645 @smallexample
14646 Reading symbol data from wherever/vw/demo/rdb/prog.o... done.
14647 @end smallexample
14648
14649 You can also use the @code{load} command to reload an object module
14650 after editing and recompiling the corresponding source file. Note that
14651 this makes @value{GDBN} delete all currently-defined breakpoints,
14652 auto-displays, and convenience variables, and to clear the value
14653 history. (This is necessary in order to preserve the integrity of
14654 debugger's data structures that reference the target system's symbol
14655 table.)
14656
14657 @node VxWorks Attach
14658 @subsubsection Running Tasks
14659
14660 @cindex running VxWorks tasks
14661 You can also attach to an existing task using the @code{attach} command as
14662 follows:
14663
14664 @smallexample
14665 (vxgdb) attach @var{task}
14666 @end smallexample
14667
14668 @noindent
14669 where @var{task} is the VxWorks hexadecimal task ID. The task can be running
14670 or suspended when you attach to it. Running tasks are suspended at
14671 the time of attachment.
14672
14673 @node Embedded Processors
14674 @section Embedded Processors
14675
14676 This section goes into details specific to particular embedded
14677 configurations.
14678
14679 @cindex send command to simulator
14680 Whenever a specific embedded processor has a simulator, @value{GDBN}
14681 allows to send an arbitrary command to the simulator.
14682
14683 @table @code
14684 @item sim @var{command}
14685 @kindex sim@r{, a command}
14686 Send an arbitrary @var{command} string to the simulator. Consult the
14687 documentation for the specific simulator in use for information about
14688 acceptable commands.
14689 @end table
14690
14691
14692 @menu
14693 * ARM:: ARM RDI
14694 * M32R/D:: Renesas M32R/D
14695 * M68K:: Motorola M68K
14696 * MIPS Embedded:: MIPS Embedded
14697 * OpenRISC 1000:: OpenRisc 1000
14698 * PA:: HP PA Embedded
14699 * PowerPC Embedded:: PowerPC Embedded
14700 * Sparclet:: Tsqware Sparclet
14701 * Sparclite:: Fujitsu Sparclite
14702 * Z8000:: Zilog Z8000
14703 * AVR:: Atmel AVR
14704 * CRIS:: CRIS
14705 * Super-H:: Renesas Super-H
14706 @end menu
14707
14708 @node ARM
14709 @subsection ARM
14710 @cindex ARM RDI
14711
14712 @table @code
14713 @kindex target rdi
14714 @item target rdi @var{dev}
14715 ARM Angel monitor, via RDI library interface to ADP protocol. You may
14716 use this target to communicate with both boards running the Angel
14717 monitor, or with the EmbeddedICE JTAG debug device.
14718
14719 @kindex target rdp
14720 @item target rdp @var{dev}
14721 ARM Demon monitor.
14722
14723 @end table
14724
14725 @value{GDBN} provides the following ARM-specific commands:
14726
14727 @table @code
14728 @item set arm disassembler
14729 @kindex set arm
14730 This commands selects from a list of disassembly styles. The
14731 @code{"std"} style is the standard style.
14732
14733 @item show arm disassembler
14734 @kindex show arm
14735 Show the current disassembly style.
14736
14737 @item set arm apcs32
14738 @cindex ARM 32-bit mode
14739 This command toggles ARM operation mode between 32-bit and 26-bit.
14740
14741 @item show arm apcs32
14742 Display the current usage of the ARM 32-bit mode.
14743
14744 @item set arm fpu @var{fputype}
14745 This command sets the ARM floating-point unit (FPU) type. The
14746 argument @var{fputype} can be one of these:
14747
14748 @table @code
14749 @item auto
14750 Determine the FPU type by querying the OS ABI.
14751 @item softfpa
14752 Software FPU, with mixed-endian doubles on little-endian ARM
14753 processors.
14754 @item fpa
14755 GCC-compiled FPA co-processor.
14756 @item softvfp
14757 Software FPU with pure-endian doubles.
14758 @item vfp
14759 VFP co-processor.
14760 @end table
14761
14762 @item show arm fpu
14763 Show the current type of the FPU.
14764
14765 @item set arm abi
14766 This command forces @value{GDBN} to use the specified ABI.
14767
14768 @item show arm abi
14769 Show the currently used ABI.
14770
14771 @item set debug arm
14772 Toggle whether to display ARM-specific debugging messages from the ARM
14773 target support subsystem.
14774
14775 @item show debug arm
14776 Show whether ARM-specific debugging messages are enabled.
14777 @end table
14778
14779 The following commands are available when an ARM target is debugged
14780 using the RDI interface:
14781
14782 @table @code
14783 @item rdilogfile @r{[}@var{file}@r{]}
14784 @kindex rdilogfile
14785 @cindex ADP (Angel Debugger Protocol) logging
14786 Set the filename for the ADP (Angel Debugger Protocol) packet log.
14787 With an argument, sets the log file to the specified @var{file}. With
14788 no argument, show the current log file name. The default log file is
14789 @file{rdi.log}.
14790
14791 @item rdilogenable @r{[}@var{arg}@r{]}
14792 @kindex rdilogenable
14793 Control logging of ADP packets. With an argument of 1 or @code{"yes"}
14794 enables logging, with an argument 0 or @code{"no"} disables it. With
14795 no arguments displays the current setting. When logging is enabled,
14796 ADP packets exchanged between @value{GDBN} and the RDI target device
14797 are logged to a file.
14798
14799 @item set rdiromatzero
14800 @kindex set rdiromatzero
14801 @cindex ROM at zero address, RDI
14802 Tell @value{GDBN} whether the target has ROM at address 0. If on,
14803 vector catching is disabled, so that zero address can be used. If off
14804 (the default), vector catching is enabled. For this command to take
14805 effect, it needs to be invoked prior to the @code{target rdi} command.
14806
14807 @item show rdiromatzero
14808 @kindex show rdiromatzero
14809 Show the current setting of ROM at zero address.
14810
14811 @item set rdiheartbeat
14812 @kindex set rdiheartbeat
14813 @cindex RDI heartbeat
14814 Enable or disable RDI heartbeat packets. It is not recommended to
14815 turn on this option, since it confuses ARM and EPI JTAG interface, as
14816 well as the Angel monitor.
14817
14818 @item show rdiheartbeat
14819 @kindex show rdiheartbeat
14820 Show the setting of RDI heartbeat packets.
14821 @end table
14822
14823
14824 @node M32R/D
14825 @subsection Renesas M32R/D and M32R/SDI
14826
14827 @table @code
14828 @kindex target m32r
14829 @item target m32r @var{dev}
14830 Renesas M32R/D ROM monitor.
14831
14832 @kindex target m32rsdi
14833 @item target m32rsdi @var{dev}
14834 Renesas M32R SDI server, connected via parallel port to the board.
14835 @end table
14836
14837 The following @value{GDBN} commands are specific to the M32R monitor:
14838
14839 @table @code
14840 @item set download-path @var{path}
14841 @kindex set download-path
14842 @cindex find downloadable @sc{srec} files (M32R)
14843 Set the default path for finding downloadable @sc{srec} files.
14844
14845 @item show download-path
14846 @kindex show download-path
14847 Show the default path for downloadable @sc{srec} files.
14848
14849 @item set board-address @var{addr}
14850 @kindex set board-address
14851 @cindex M32-EVA target board address
14852 Set the IP address for the M32R-EVA target board.
14853
14854 @item show board-address
14855 @kindex show board-address
14856 Show the current IP address of the target board.
14857
14858 @item set server-address @var{addr}
14859 @kindex set server-address
14860 @cindex download server address (M32R)
14861 Set the IP address for the download server, which is the @value{GDBN}'s
14862 host machine.
14863
14864 @item show server-address
14865 @kindex show server-address
14866 Display the IP address of the download server.
14867
14868 @item upload @r{[}@var{file}@r{]}
14869 @kindex upload@r{, M32R}
14870 Upload the specified @sc{srec} @var{file} via the monitor's Ethernet
14871 upload capability. If no @var{file} argument is given, the current
14872 executable file is uploaded.
14873
14874 @item tload @r{[}@var{file}@r{]}
14875 @kindex tload@r{, M32R}
14876 Test the @code{upload} command.
14877 @end table
14878
14879 The following commands are available for M32R/SDI:
14880
14881 @table @code
14882 @item sdireset
14883 @kindex sdireset
14884 @cindex reset SDI connection, M32R
14885 This command resets the SDI connection.
14886
14887 @item sdistatus
14888 @kindex sdistatus
14889 This command shows the SDI connection status.
14890
14891 @item debug_chaos
14892 @kindex debug_chaos
14893 @cindex M32R/Chaos debugging
14894 Instructs the remote that M32R/Chaos debugging is to be used.
14895
14896 @item use_debug_dma
14897 @kindex use_debug_dma
14898 Instructs the remote to use the DEBUG_DMA method of accessing memory.
14899
14900 @item use_mon_code
14901 @kindex use_mon_code
14902 Instructs the remote to use the MON_CODE method of accessing memory.
14903
14904 @item use_ib_break
14905 @kindex use_ib_break
14906 Instructs the remote to set breakpoints by IB break.
14907
14908 @item use_dbt_break
14909 @kindex use_dbt_break
14910 Instructs the remote to set breakpoints by DBT.
14911 @end table
14912
14913 @node M68K
14914 @subsection M68k
14915
14916 The Motorola m68k configuration includes ColdFire support, and a
14917 target command for the following ROM monitor.
14918
14919 @table @code
14920
14921 @kindex target dbug
14922 @item target dbug @var{dev}
14923 dBUG ROM monitor for Motorola ColdFire.
14924
14925 @end table
14926
14927 @node MIPS Embedded
14928 @subsection MIPS Embedded
14929
14930 @cindex MIPS boards
14931 @value{GDBN} can use the MIPS remote debugging protocol to talk to a
14932 MIPS board attached to a serial line. This is available when
14933 you configure @value{GDBN} with @samp{--target=mips-idt-ecoff}.
14934
14935 @need 1000
14936 Use these @value{GDBN} commands to specify the connection to your target board:
14937
14938 @table @code
14939 @item target mips @var{port}
14940 @kindex target mips @var{port}
14941 To run a program on the board, start up @code{@value{GDBP}} with the
14942 name of your program as the argument. To connect to the board, use the
14943 command @samp{target mips @var{port}}, where @var{port} is the name of
14944 the serial port connected to the board. If the program has not already
14945 been downloaded to the board, you may use the @code{load} command to
14946 download it. You can then use all the usual @value{GDBN} commands.
14947
14948 For example, this sequence connects to the target board through a serial
14949 port, and loads and runs a program called @var{prog} through the
14950 debugger:
14951
14952 @smallexample
14953 host$ @value{GDBP} @var{prog}
14954 @value{GDBN} is free software and @dots{}
14955 (@value{GDBP}) target mips /dev/ttyb
14956 (@value{GDBP}) load @var{prog}
14957 (@value{GDBP}) run
14958 @end smallexample
14959
14960 @item target mips @var{hostname}:@var{portnumber}
14961 On some @value{GDBN} host configurations, you can specify a TCP
14962 connection (for instance, to a serial line managed by a terminal
14963 concentrator) instead of a serial port, using the syntax
14964 @samp{@var{hostname}:@var{portnumber}}.
14965
14966 @item target pmon @var{port}
14967 @kindex target pmon @var{port}
14968 PMON ROM monitor.
14969
14970 @item target ddb @var{port}
14971 @kindex target ddb @var{port}
14972 NEC's DDB variant of PMON for Vr4300.
14973
14974 @item target lsi @var{port}
14975 @kindex target lsi @var{port}
14976 LSI variant of PMON.
14977
14978 @kindex target r3900
14979 @item target r3900 @var{dev}
14980 Densan DVE-R3900 ROM monitor for Toshiba R3900 Mips.
14981
14982 @kindex target array
14983 @item target array @var{dev}
14984 Array Tech LSI33K RAID controller board.
14985
14986 @end table
14987
14988
14989 @noindent
14990 @value{GDBN} also supports these special commands for MIPS targets:
14991
14992 @table @code
14993 @item set mipsfpu double
14994 @itemx set mipsfpu single
14995 @itemx set mipsfpu none
14996 @itemx set mipsfpu auto
14997 @itemx show mipsfpu
14998 @kindex set mipsfpu
14999 @kindex show mipsfpu
15000 @cindex MIPS remote floating point
15001 @cindex floating point, MIPS remote
15002 If your target board does not support the MIPS floating point
15003 coprocessor, you should use the command @samp{set mipsfpu none} (if you
15004 need this, you may wish to put the command in your @value{GDBN} init
15005 file). This tells @value{GDBN} how to find the return value of
15006 functions which return floating point values. It also allows
15007 @value{GDBN} to avoid saving the floating point registers when calling
15008 functions on the board. If you are using a floating point coprocessor
15009 with only single precision floating point support, as on the @sc{r4650}
15010 processor, use the command @samp{set mipsfpu single}. The default
15011 double precision floating point coprocessor may be selected using
15012 @samp{set mipsfpu double}.
15013
15014 In previous versions the only choices were double precision or no
15015 floating point, so @samp{set mipsfpu on} will select double precision
15016 and @samp{set mipsfpu off} will select no floating point.
15017
15018 As usual, you can inquire about the @code{mipsfpu} variable with
15019 @samp{show mipsfpu}.
15020
15021 @item set timeout @var{seconds}
15022 @itemx set retransmit-timeout @var{seconds}
15023 @itemx show timeout
15024 @itemx show retransmit-timeout
15025 @cindex @code{timeout}, MIPS protocol
15026 @cindex @code{retransmit-timeout}, MIPS protocol
15027 @kindex set timeout
15028 @kindex show timeout
15029 @kindex set retransmit-timeout
15030 @kindex show retransmit-timeout
15031 You can control the timeout used while waiting for a packet, in the MIPS
15032 remote protocol, with the @code{set timeout @var{seconds}} command. The
15033 default is 5 seconds. Similarly, you can control the timeout used while
15034 waiting for an acknowledgement of a packet with the @code{set
15035 retransmit-timeout @var{seconds}} command. The default is 3 seconds.
15036 You can inspect both values with @code{show timeout} and @code{show
15037 retransmit-timeout}. (These commands are @emph{only} available when
15038 @value{GDBN} is configured for @samp{--target=mips-idt-ecoff}.)
15039
15040 The timeout set by @code{set timeout} does not apply when @value{GDBN}
15041 is waiting for your program to stop. In that case, @value{GDBN} waits
15042 forever because it has no way of knowing how long the program is going
15043 to run before stopping.
15044
15045 @item set syn-garbage-limit @var{num}
15046 @kindex set syn-garbage-limit@r{, MIPS remote}
15047 @cindex synchronize with remote MIPS target
15048 Limit the maximum number of characters @value{GDBN} should ignore when
15049 it tries to synchronize with the remote target. The default is 10
15050 characters. Setting the limit to -1 means there's no limit.
15051
15052 @item show syn-garbage-limit
15053 @kindex show syn-garbage-limit@r{, MIPS remote}
15054 Show the current limit on the number of characters to ignore when
15055 trying to synchronize with the remote system.
15056
15057 @item set monitor-prompt @var{prompt}
15058 @kindex set monitor-prompt@r{, MIPS remote}
15059 @cindex remote monitor prompt
15060 Tell @value{GDBN} to expect the specified @var{prompt} string from the
15061 remote monitor. The default depends on the target:
15062 @table @asis
15063 @item pmon target
15064 @samp{PMON}
15065 @item ddb target
15066 @samp{NEC010}
15067 @item lsi target
15068 @samp{PMON>}
15069 @end table
15070
15071 @item show monitor-prompt
15072 @kindex show monitor-prompt@r{, MIPS remote}
15073 Show the current strings @value{GDBN} expects as the prompt from the
15074 remote monitor.
15075
15076 @item set monitor-warnings
15077 @kindex set monitor-warnings@r{, MIPS remote}
15078 Enable or disable monitor warnings about hardware breakpoints. This
15079 has effect only for the @code{lsi} target. When on, @value{GDBN} will
15080 display warning messages whose codes are returned by the @code{lsi}
15081 PMON monitor for breakpoint commands.
15082
15083 @item show monitor-warnings
15084 @kindex show monitor-warnings@r{, MIPS remote}
15085 Show the current setting of printing monitor warnings.
15086
15087 @item pmon @var{command}
15088 @kindex pmon@r{, MIPS remote}
15089 @cindex send PMON command
15090 This command allows sending an arbitrary @var{command} string to the
15091 monitor. The monitor must be in debug mode for this to work.
15092 @end table
15093
15094 @node OpenRISC 1000
15095 @subsection OpenRISC 1000
15096 @cindex OpenRISC 1000
15097
15098 @cindex or1k boards
15099 See OR1k Architecture document (@uref{www.opencores.org}) for more information
15100 about platform and commands.
15101
15102 @table @code
15103
15104 @kindex target jtag
15105 @item target jtag jtag://@var{host}:@var{port}
15106
15107 Connects to remote JTAG server.
15108 JTAG remote server can be either an or1ksim or JTAG server,
15109 connected via parallel port to the board.
15110
15111 Example: @code{target jtag jtag://localhost:9999}
15112
15113 @kindex or1ksim
15114 @item or1ksim @var{command}
15115 If connected to @code{or1ksim} OpenRISC 1000 Architectural
15116 Simulator, proprietary commands can be executed.
15117
15118 @kindex info or1k spr
15119 @item info or1k spr
15120 Displays spr groups.
15121
15122 @item info or1k spr @var{group}
15123 @itemx info or1k spr @var{groupno}
15124 Displays register names in selected group.
15125
15126 @item info or1k spr @var{group} @var{register}
15127 @itemx info or1k spr @var{register}
15128 @itemx info or1k spr @var{groupno} @var{registerno}
15129 @itemx info or1k spr @var{registerno}
15130 Shows information about specified spr register.
15131
15132 @kindex spr
15133 @item spr @var{group} @var{register} @var{value}
15134 @itemx spr @var{register @var{value}}
15135 @itemx spr @var{groupno} @var{registerno @var{value}}
15136 @itemx spr @var{registerno @var{value}}
15137 Writes @var{value} to specified spr register.
15138 @end table
15139
15140 Some implementations of OpenRISC 1000 Architecture also have hardware trace.
15141 It is very similar to @value{GDBN} trace, except it does not interfere with normal
15142 program execution and is thus much faster. Hardware breakpoints/watchpoint
15143 triggers can be set using:
15144 @table @code
15145 @item $LEA/$LDATA
15146 Load effective address/data
15147 @item $SEA/$SDATA
15148 Store effective address/data
15149 @item $AEA/$ADATA
15150 Access effective address ($SEA or $LEA) or data ($SDATA/$LDATA)
15151 @item $FETCH
15152 Fetch data
15153 @end table
15154
15155 When triggered, it can capture low level data, like: @code{PC}, @code{LSEA},
15156 @code{LDATA}, @code{SDATA}, @code{READSPR}, @code{WRITESPR}, @code{INSTR}.
15157
15158 @code{htrace} commands:
15159 @cindex OpenRISC 1000 htrace
15160 @table @code
15161 @kindex hwatch
15162 @item hwatch @var{conditional}
15163 Set hardware watchpoint on combination of Load/Store Effective Address(es)
15164 or Data. For example:
15165
15166 @code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
15167
15168 @code{hwatch ($LEA == my_var) && ($LDATA < 50) || ($SEA == my_var) && ($SDATA >= 50)}
15169
15170 @kindex htrace
15171 @item htrace info
15172 Display information about current HW trace configuration.
15173
15174 @item htrace trigger @var{conditional}
15175 Set starting criteria for HW trace.
15176
15177 @item htrace qualifier @var{conditional}
15178 Set acquisition qualifier for HW trace.
15179
15180 @item htrace stop @var{conditional}
15181 Set HW trace stopping criteria.
15182
15183 @item htrace record [@var{data}]*
15184 Selects the data to be recorded, when qualifier is met and HW trace was
15185 triggered.
15186
15187 @item htrace enable
15188 @itemx htrace disable
15189 Enables/disables the HW trace.
15190
15191 @item htrace rewind [@var{filename}]
15192 Clears currently recorded trace data.
15193
15194 If filename is specified, new trace file is made and any newly collected data
15195 will be written there.
15196
15197 @item htrace print [@var{start} [@var{len}]]
15198 Prints trace buffer, using current record configuration.
15199
15200 @item htrace mode continuous
15201 Set continuous trace mode.
15202
15203 @item htrace mode suspend
15204 Set suspend trace mode.
15205
15206 @end table
15207
15208 @node PowerPC Embedded
15209 @subsection PowerPC Embedded
15210
15211 @value{GDBN} provides the following PowerPC-specific commands:
15212
15213 @table @code
15214 @kindex set powerpc
15215 @item set powerpc soft-float
15216 @itemx show powerpc soft-float
15217 Force @value{GDBN} to use (or not use) a software floating point calling
15218 convention. By default, @value{GDBN} selects the calling convention based
15219 on the selected architecture and the provided executable file.
15220
15221 @item set powerpc vector-abi
15222 @itemx show powerpc vector-abi
15223 Force @value{GDBN} to use the specified calling convention for vector
15224 arguments and return values. The valid options are @samp{auto};
15225 @samp{generic}, to avoid vector registers even if they are present;
15226 @samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
15227 registers. By default, @value{GDBN} selects the calling convention
15228 based on the selected architecture and the provided executable file.
15229
15230 @kindex target dink32
15231 @item target dink32 @var{dev}
15232 DINK32 ROM monitor.
15233
15234 @kindex target ppcbug
15235 @item target ppcbug @var{dev}
15236 @kindex target ppcbug1
15237 @item target ppcbug1 @var{dev}
15238 PPCBUG ROM monitor for PowerPC.
15239
15240 @kindex target sds
15241 @item target sds @var{dev}
15242 SDS monitor, running on a PowerPC board (such as Motorola's ADS).
15243 @end table
15244
15245 @cindex SDS protocol
15246 The following commands specific to the SDS protocol are supported
15247 by @value{GDBN}:
15248
15249 @table @code
15250 @item set sdstimeout @var{nsec}
15251 @kindex set sdstimeout
15252 Set the timeout for SDS protocol reads to be @var{nsec} seconds. The
15253 default is 2 seconds.
15254
15255 @item show sdstimeout
15256 @kindex show sdstimeout
15257 Show the current value of the SDS timeout.
15258
15259 @item sds @var{command}
15260 @kindex sds@r{, a command}
15261 Send the specified @var{command} string to the SDS monitor.
15262 @end table
15263
15264
15265 @node PA
15266 @subsection HP PA Embedded
15267
15268 @table @code
15269
15270 @kindex target op50n
15271 @item target op50n @var{dev}
15272 OP50N monitor, running on an OKI HPPA board.
15273
15274 @kindex target w89k
15275 @item target w89k @var{dev}
15276 W89K monitor, running on a Winbond HPPA board.
15277
15278 @end table
15279
15280 @node Sparclet
15281 @subsection Tsqware Sparclet
15282
15283 @cindex Sparclet
15284
15285 @value{GDBN} enables developers to debug tasks running on
15286 Sparclet targets from a Unix host.
15287 @value{GDBN} uses code that runs on
15288 both the Unix host and on the Sparclet target. The program
15289 @code{@value{GDBP}} is installed and executed on the Unix host.
15290
15291 @table @code
15292 @item remotetimeout @var{args}
15293 @kindex remotetimeout
15294 @value{GDBN} supports the option @code{remotetimeout}.
15295 This option is set by the user, and @var{args} represents the number of
15296 seconds @value{GDBN} waits for responses.
15297 @end table
15298
15299 @cindex compiling, on Sparclet
15300 When compiling for debugging, include the options @samp{-g} to get debug
15301 information and @samp{-Ttext} to relocate the program to where you wish to
15302 load it on the target. You may also want to add the options @samp{-n} or
15303 @samp{-N} in order to reduce the size of the sections. Example:
15304
15305 @smallexample
15306 sparclet-aout-gcc prog.c -Ttext 0x12010000 -g -o prog -N
15307 @end smallexample
15308
15309 You can use @code{objdump} to verify that the addresses are what you intended:
15310
15311 @smallexample
15312 sparclet-aout-objdump --headers --syms prog
15313 @end smallexample
15314
15315 @cindex running, on Sparclet
15316 Once you have set
15317 your Unix execution search path to find @value{GDBN}, you are ready to
15318 run @value{GDBN}. From your Unix host, run @code{@value{GDBP}}
15319 (or @code{sparclet-aout-gdb}, depending on your installation).
15320
15321 @value{GDBN} comes up showing the prompt:
15322
15323 @smallexample
15324 (gdbslet)
15325 @end smallexample
15326
15327 @menu
15328 * Sparclet File:: Setting the file to debug
15329 * Sparclet Connection:: Connecting to Sparclet
15330 * Sparclet Download:: Sparclet download
15331 * Sparclet Execution:: Running and debugging
15332 @end menu
15333
15334 @node Sparclet File
15335 @subsubsection Setting File to Debug
15336
15337 The @value{GDBN} command @code{file} lets you choose with program to debug.
15338
15339 @smallexample
15340 (gdbslet) file prog
15341 @end smallexample
15342
15343 @need 1000
15344 @value{GDBN} then attempts to read the symbol table of @file{prog}.
15345 @value{GDBN} locates
15346 the file by searching the directories listed in the command search
15347 path.
15348 If the file was compiled with debug information (option @samp{-g}), source
15349 files will be searched as well.
15350 @value{GDBN} locates
15351 the source files by searching the directories listed in the directory search
15352 path (@pxref{Environment, ,Your Program's Environment}).
15353 If it fails
15354 to find a file, it displays a message such as:
15355
15356 @smallexample
15357 prog: No such file or directory.
15358 @end smallexample
15359
15360 When this happens, add the appropriate directories to the search paths with
15361 the @value{GDBN} commands @code{path} and @code{dir}, and execute the
15362 @code{target} command again.
15363
15364 @node Sparclet Connection
15365 @subsubsection Connecting to Sparclet
15366
15367 The @value{GDBN} command @code{target} lets you connect to a Sparclet target.
15368 To connect to a target on serial port ``@code{ttya}'', type:
15369
15370 @smallexample
15371 (gdbslet) target sparclet /dev/ttya
15372 Remote target sparclet connected to /dev/ttya
15373 main () at ../prog.c:3
15374 @end smallexample
15375
15376 @need 750
15377 @value{GDBN} displays messages like these:
15378
15379 @smallexample
15380 Connected to ttya.
15381 @end smallexample
15382
15383 @node Sparclet Download
15384 @subsubsection Sparclet Download
15385
15386 @cindex download to Sparclet
15387 Once connected to the Sparclet target,
15388 you can use the @value{GDBN}
15389 @code{load} command to download the file from the host to the target.
15390 The file name and load offset should be given as arguments to the @code{load}
15391 command.
15392 Since the file format is aout, the program must be loaded to the starting
15393 address. You can use @code{objdump} to find out what this value is. The load
15394 offset is an offset which is added to the VMA (virtual memory address)
15395 of each of the file's sections.
15396 For instance, if the program
15397 @file{prog} was linked to text address 0x1201000, with data at 0x12010160
15398 and bss at 0x12010170, in @value{GDBN}, type:
15399
15400 @smallexample
15401 (gdbslet) load prog 0x12010000
15402 Loading section .text, size 0xdb0 vma 0x12010000
15403 @end smallexample
15404
15405 If the code is loaded at a different address then what the program was linked
15406 to, you may need to use the @code{section} and @code{add-symbol-file} commands
15407 to tell @value{GDBN} where to map the symbol table.
15408
15409 @node Sparclet Execution
15410 @subsubsection Running and Debugging
15411
15412 @cindex running and debugging Sparclet programs
15413 You can now begin debugging the task using @value{GDBN}'s execution control
15414 commands, @code{b}, @code{step}, @code{run}, etc. See the @value{GDBN}
15415 manual for the list of commands.
15416
15417 @smallexample
15418 (gdbslet) b main
15419 Breakpoint 1 at 0x12010000: file prog.c, line 3.
15420 (gdbslet) run
15421 Starting program: prog
15422 Breakpoint 1, main (argc=1, argv=0xeffff21c) at prog.c:3
15423 3 char *symarg = 0;
15424 (gdbslet) step
15425 4 char *execarg = "hello!";
15426 (gdbslet)
15427 @end smallexample
15428
15429 @node Sparclite
15430 @subsection Fujitsu Sparclite
15431
15432 @table @code
15433
15434 @kindex target sparclite
15435 @item target sparclite @var{dev}
15436 Fujitsu sparclite boards, used only for the purpose of loading.
15437 You must use an additional command to debug the program.
15438 For example: target remote @var{dev} using @value{GDBN} standard
15439 remote protocol.
15440
15441 @end table
15442
15443 @node Z8000
15444 @subsection Zilog Z8000
15445
15446 @cindex Z8000
15447 @cindex simulator, Z8000
15448 @cindex Zilog Z8000 simulator
15449
15450 When configured for debugging Zilog Z8000 targets, @value{GDBN} includes
15451 a Z8000 simulator.
15452
15453 For the Z8000 family, @samp{target sim} simulates either the Z8002 (the
15454 unsegmented variant of the Z8000 architecture) or the Z8001 (the
15455 segmented variant). The simulator recognizes which architecture is
15456 appropriate by inspecting the object code.
15457
15458 @table @code
15459 @item target sim @var{args}
15460 @kindex sim
15461 @kindex target sim@r{, with Z8000}
15462 Debug programs on a simulated CPU. If the simulator supports setup
15463 options, specify them via @var{args}.
15464 @end table
15465
15466 @noindent
15467 After specifying this target, you can debug programs for the simulated
15468 CPU in the same style as programs for your host computer; use the
15469 @code{file} command to load a new program image, the @code{run} command
15470 to run your program, and so on.
15471
15472 As well as making available all the usual machine registers
15473 (@pxref{Registers, ,Registers}), the Z8000 simulator provides three
15474 additional items of information as specially named registers:
15475
15476 @table @code
15477
15478 @item cycles
15479 Counts clock-ticks in the simulator.
15480
15481 @item insts
15482 Counts instructions run in the simulator.
15483
15484 @item time
15485 Execution time in 60ths of a second.
15486
15487 @end table
15488
15489 You can refer to these values in @value{GDBN} expressions with the usual
15490 conventions; for example, @w{@samp{b fputc if $cycles>5000}} sets a
15491 conditional breakpoint that suspends only after at least 5000
15492 simulated clock ticks.
15493
15494 @node AVR
15495 @subsection Atmel AVR
15496 @cindex AVR
15497
15498 When configured for debugging the Atmel AVR, @value{GDBN} supports the
15499 following AVR-specific commands:
15500
15501 @table @code
15502 @item info io_registers
15503 @kindex info io_registers@r{, AVR}
15504 @cindex I/O registers (Atmel AVR)
15505 This command displays information about the AVR I/O registers. For
15506 each register, @value{GDBN} prints its number and value.
15507 @end table
15508
15509 @node CRIS
15510 @subsection CRIS
15511 @cindex CRIS
15512
15513 When configured for debugging CRIS, @value{GDBN} provides the
15514 following CRIS-specific commands:
15515
15516 @table @code
15517 @item set cris-version @var{ver}
15518 @cindex CRIS version
15519 Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
15520 The CRIS version affects register names and sizes. This command is useful in
15521 case autodetection of the CRIS version fails.
15522
15523 @item show cris-version
15524 Show the current CRIS version.
15525
15526 @item set cris-dwarf2-cfi
15527 @cindex DWARF-2 CFI and CRIS
15528 Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
15529 Change to @samp{off} when using @code{gcc-cris} whose version is below
15530 @code{R59}.
15531
15532 @item show cris-dwarf2-cfi
15533 Show the current state of using DWARF-2 CFI.
15534
15535 @item set cris-mode @var{mode}
15536 @cindex CRIS mode
15537 Set the current CRIS mode to @var{mode}. It should only be changed when
15538 debugging in guru mode, in which case it should be set to
15539 @samp{guru} (the default is @samp{normal}).
15540
15541 @item show cris-mode
15542 Show the current CRIS mode.
15543 @end table
15544
15545 @node Super-H
15546 @subsection Renesas Super-H
15547 @cindex Super-H
15548
15549 For the Renesas Super-H processor, @value{GDBN} provides these
15550 commands:
15551
15552 @table @code
15553 @item regs
15554 @kindex regs@r{, Super-H}
15555 Show the values of all Super-H registers.
15556 @end table
15557
15558
15559 @node Architectures
15560 @section Architectures
15561
15562 This section describes characteristics of architectures that affect
15563 all uses of @value{GDBN} with the architecture, both native and cross.
15564
15565 @menu
15566 * i386::
15567 * A29K::
15568 * Alpha::
15569 * MIPS::
15570 * HPPA:: HP PA architecture
15571 * SPU:: Cell Broadband Engine SPU architecture
15572 * PowerPC::
15573 @end menu
15574
15575 @node i386
15576 @subsection x86 Architecture-specific Issues
15577
15578 @table @code
15579 @item set struct-convention @var{mode}
15580 @kindex set struct-convention
15581 @cindex struct return convention
15582 @cindex struct/union returned in registers
15583 Set the convention used by the inferior to return @code{struct}s and
15584 @code{union}s from functions to @var{mode}. Possible values of
15585 @var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
15586 default). @code{"default"} or @code{"pcc"} means that @code{struct}s
15587 are returned on the stack, while @code{"reg"} means that a
15588 @code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
15589 be returned in a register.
15590
15591 @item show struct-convention
15592 @kindex show struct-convention
15593 Show the current setting of the convention to return @code{struct}s
15594 from functions.
15595 @end table
15596
15597 @node A29K
15598 @subsection A29K
15599
15600 @table @code
15601
15602 @kindex set rstack_high_address
15603 @cindex AMD 29K register stack
15604 @cindex register stack, AMD29K
15605 @item set rstack_high_address @var{address}
15606 On AMD 29000 family processors, registers are saved in a separate
15607 @dfn{register stack}. There is no way for @value{GDBN} to determine the
15608 extent of this stack. Normally, @value{GDBN} just assumes that the
15609 stack is ``large enough''. This may result in @value{GDBN} referencing
15610 memory locations that do not exist. If necessary, you can get around
15611 this problem by specifying the ending address of the register stack with
15612 the @code{set rstack_high_address} command. The argument should be an
15613 address, which you probably want to precede with @samp{0x} to specify in
15614 hexadecimal.
15615
15616 @kindex show rstack_high_address
15617 @item show rstack_high_address
15618 Display the current limit of the register stack, on AMD 29000 family
15619 processors.
15620
15621 @end table
15622
15623 @node Alpha
15624 @subsection Alpha
15625
15626 See the following section.
15627
15628 @node MIPS
15629 @subsection MIPS
15630
15631 @cindex stack on Alpha
15632 @cindex stack on MIPS
15633 @cindex Alpha stack
15634 @cindex MIPS stack
15635 Alpha- and MIPS-based computers use an unusual stack frame, which
15636 sometimes requires @value{GDBN} to search backward in the object code to
15637 find the beginning of a function.
15638
15639 @cindex response time, MIPS debugging
15640 To improve response time (especially for embedded applications, where
15641 @value{GDBN} may be restricted to a slow serial line for this search)
15642 you may want to limit the size of this search, using one of these
15643 commands:
15644
15645 @table @code
15646 @cindex @code{heuristic-fence-post} (Alpha, MIPS)
15647 @item set heuristic-fence-post @var{limit}
15648 Restrict @value{GDBN} to examining at most @var{limit} bytes in its
15649 search for the beginning of a function. A value of @var{0} (the
15650 default) means there is no limit. However, except for @var{0}, the
15651 larger the limit the more bytes @code{heuristic-fence-post} must search
15652 and therefore the longer it takes to run. You should only need to use
15653 this command when debugging a stripped executable.
15654
15655 @item show heuristic-fence-post
15656 Display the current limit.
15657 @end table
15658
15659 @noindent
15660 These commands are available @emph{only} when @value{GDBN} is configured
15661 for debugging programs on Alpha or MIPS processors.
15662
15663 Several MIPS-specific commands are available when debugging MIPS
15664 programs:
15665
15666 @table @code
15667 @item set mips abi @var{arg}
15668 @kindex set mips abi
15669 @cindex set ABI for MIPS
15670 Tell @value{GDBN} which MIPS ABI is used by the inferior. Possible
15671 values of @var{arg} are:
15672
15673 @table @samp
15674 @item auto
15675 The default ABI associated with the current binary (this is the
15676 default).
15677 @item o32
15678 @item o64
15679 @item n32
15680 @item n64
15681 @item eabi32
15682 @item eabi64
15683 @item auto
15684 @end table
15685
15686 @item show mips abi
15687 @kindex show mips abi
15688 Show the MIPS ABI used by @value{GDBN} to debug the inferior.
15689
15690 @item set mipsfpu
15691 @itemx show mipsfpu
15692 @xref{MIPS Embedded, set mipsfpu}.
15693
15694 @item set mips mask-address @var{arg}
15695 @kindex set mips mask-address
15696 @cindex MIPS addresses, masking
15697 This command determines whether the most-significant 32 bits of 64-bit
15698 MIPS addresses are masked off. The argument @var{arg} can be
15699 @samp{on}, @samp{off}, or @samp{auto}. The latter is the default
15700 setting, which lets @value{GDBN} determine the correct value.
15701
15702 @item show mips mask-address
15703 @kindex show mips mask-address
15704 Show whether the upper 32 bits of MIPS addresses are masked off or
15705 not.
15706
15707 @item set remote-mips64-transfers-32bit-regs
15708 @kindex set remote-mips64-transfers-32bit-regs
15709 This command controls compatibility with 64-bit MIPS targets that
15710 transfer data in 32-bit quantities. If you have an old MIPS 64 target
15711 that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
15712 and 64 bits for other registers, set this option to @samp{on}.
15713
15714 @item show remote-mips64-transfers-32bit-regs
15715 @kindex show remote-mips64-transfers-32bit-regs
15716 Show the current setting of compatibility with older MIPS 64 targets.
15717
15718 @item set debug mips
15719 @kindex set debug mips
15720 This command turns on and off debugging messages for the MIPS-specific
15721 target code in @value{GDBN}.
15722
15723 @item show debug mips
15724 @kindex show debug mips
15725 Show the current setting of MIPS debugging messages.
15726 @end table
15727
15728
15729 @node HPPA
15730 @subsection HPPA
15731 @cindex HPPA support
15732
15733 When @value{GDBN} is debugging the HP PA architecture, it provides the
15734 following special commands:
15735
15736 @table @code
15737 @item set debug hppa
15738 @kindex set debug hppa
15739 This command determines whether HPPA architecture-specific debugging
15740 messages are to be displayed.
15741
15742 @item show debug hppa
15743 Show whether HPPA debugging messages are displayed.
15744
15745 @item maint print unwind @var{address}
15746 @kindex maint print unwind@r{, HPPA}
15747 This command displays the contents of the unwind table entry at the
15748 given @var{address}.
15749
15750 @end table
15751
15752
15753 @node SPU
15754 @subsection Cell Broadband Engine SPU architecture
15755 @cindex Cell Broadband Engine
15756 @cindex SPU
15757
15758 When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
15759 it provides the following special commands:
15760
15761 @table @code
15762 @item info spu event
15763 @kindex info spu
15764 Display SPU event facility status. Shows current event mask
15765 and pending event status.
15766
15767 @item info spu signal
15768 Display SPU signal notification facility status. Shows pending
15769 signal-control word and signal notification mode of both signal
15770 notification channels.
15771
15772 @item info spu mailbox
15773 Display SPU mailbox facility status. Shows all pending entries,
15774 in order of processing, in each of the SPU Write Outbound,
15775 SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
15776
15777 @item info spu dma
15778 Display MFC DMA status. Shows all pending commands in the MFC
15779 DMA queue. For each entry, opcode, tag, class IDs, effective
15780 and local store addresses and transfer size are shown.
15781
15782 @item info spu proxydma
15783 Display MFC Proxy-DMA status. Shows all pending commands in the MFC
15784 Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
15785 and local store addresses and transfer size are shown.
15786
15787 @end table
15788
15789 @node PowerPC
15790 @subsection PowerPC
15791 @cindex PowerPC architecture
15792
15793 When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
15794 pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
15795 numbers stored in the floating point registers. These values must be stored
15796 in two consecutive registers, always starting at an even register like
15797 @code{f0} or @code{f2}.
15798
15799 The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
15800 by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
15801 @code{f2} and @code{f3} for @code{$dl1} and so on.
15802
15803
15804 @node Controlling GDB
15805 @chapter Controlling @value{GDBN}
15806
15807 You can alter the way @value{GDBN} interacts with you by using the
15808 @code{set} command. For commands controlling how @value{GDBN} displays
15809 data, see @ref{Print Settings, ,Print Settings}. Other settings are
15810 described here.
15811
15812 @menu
15813 * Prompt:: Prompt
15814 * Editing:: Command editing
15815 * Command History:: Command history
15816 * Screen Size:: Screen size
15817 * Numbers:: Numbers
15818 * ABI:: Configuring the current ABI
15819 * Messages/Warnings:: Optional warnings and messages
15820 * Debugging Output:: Optional messages about internal happenings
15821 @end menu
15822
15823 @node Prompt
15824 @section Prompt
15825
15826 @cindex prompt
15827
15828 @value{GDBN} indicates its readiness to read a command by printing a string
15829 called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
15830 can change the prompt string with the @code{set prompt} command. For
15831 instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
15832 the prompt in one of the @value{GDBN} sessions so that you can always tell
15833 which one you are talking to.
15834
15835 @emph{Note:} @code{set prompt} does not add a space for you after the
15836 prompt you set. This allows you to set a prompt which ends in a space
15837 or a prompt that does not.
15838
15839 @table @code
15840 @kindex set prompt
15841 @item set prompt @var{newprompt}
15842 Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
15843
15844 @kindex show prompt
15845 @item show prompt
15846 Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
15847 @end table
15848
15849 @node Editing
15850 @section Command Editing
15851 @cindex readline
15852 @cindex command line editing
15853
15854 @value{GDBN} reads its input commands via the @dfn{Readline} interface. This
15855 @sc{gnu} library provides consistent behavior for programs which provide a
15856 command line interface to the user. Advantages are @sc{gnu} Emacs-style
15857 or @dfn{vi}-style inline editing of commands, @code{csh}-like history
15858 substitution, and a storage and recall of command history across
15859 debugging sessions.
15860
15861 You may control the behavior of command line editing in @value{GDBN} with the
15862 command @code{set}.
15863
15864 @table @code
15865 @kindex set editing
15866 @cindex editing
15867 @item set editing
15868 @itemx set editing on
15869 Enable command line editing (enabled by default).
15870
15871 @item set editing off
15872 Disable command line editing.
15873
15874 @kindex show editing
15875 @item show editing
15876 Show whether command line editing is enabled.
15877 @end table
15878
15879 @xref{Command Line Editing}, for more details about the Readline
15880 interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
15881 encouraged to read that chapter.
15882
15883 @node Command History
15884 @section Command History
15885 @cindex command history
15886
15887 @value{GDBN} can keep track of the commands you type during your
15888 debugging sessions, so that you can be certain of precisely what
15889 happened. Use these commands to manage the @value{GDBN} command
15890 history facility.
15891
15892 @value{GDBN} uses the @sc{gnu} History library, a part of the Readline
15893 package, to provide the history facility. @xref{Using History
15894 Interactively}, for the detailed description of the History library.
15895
15896 To issue a command to @value{GDBN} without affecting certain aspects of
15897 the state which is seen by users, prefix it with @samp{server }
15898 (@pxref{Server Prefix}). This
15899 means that this command will not affect the command history, nor will it
15900 affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
15901 pressed on a line by itself.
15902
15903 @cindex @code{server}, command prefix
15904 The server prefix does not affect the recording of values into the value
15905 history; to print a value without recording it into the value history,
15906 use the @code{output} command instead of the @code{print} command.
15907
15908 Here is the description of @value{GDBN} commands related to command
15909 history.
15910
15911 @table @code
15912 @cindex history substitution
15913 @cindex history file
15914 @kindex set history filename
15915 @cindex @env{GDBHISTFILE}, environment variable
15916 @item set history filename @var{fname}
15917 Set the name of the @value{GDBN} command history file to @var{fname}.
15918 This is the file where @value{GDBN} reads an initial command history
15919 list, and where it writes the command history from this session when it
15920 exits. You can access this list through history expansion or through
15921 the history command editing characters listed below. This file defaults
15922 to the value of the environment variable @code{GDBHISTFILE}, or to
15923 @file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
15924 is not set.
15925
15926 @cindex save command history
15927 @kindex set history save
15928 @item set history save
15929 @itemx set history save on
15930 Record command history in a file, whose name may be specified with the
15931 @code{set history filename} command. By default, this option is disabled.
15932
15933 @item set history save off
15934 Stop recording command history in a file.
15935
15936 @cindex history size
15937 @kindex set history size
15938 @cindex @env{HISTSIZE}, environment variable
15939 @item set history size @var{size}
15940 Set the number of commands which @value{GDBN} keeps in its history list.
15941 This defaults to the value of the environment variable
15942 @code{HISTSIZE}, or to 256 if this variable is not set.
15943 @end table
15944
15945 History expansion assigns special meaning to the character @kbd{!}.
15946 @xref{Event Designators}, for more details.
15947
15948 @cindex history expansion, turn on/off
15949 Since @kbd{!} is also the logical not operator in C, history expansion
15950 is off by default. If you decide to enable history expansion with the
15951 @code{set history expansion on} command, you may sometimes need to
15952 follow @kbd{!} (when it is used as logical not, in an expression) with
15953 a space or a tab to prevent it from being expanded. The readline
15954 history facilities do not attempt substitution on the strings
15955 @kbd{!=} and @kbd{!(}, even when history expansion is enabled.
15956
15957 The commands to control history expansion are:
15958
15959 @table @code
15960 @item set history expansion on
15961 @itemx set history expansion
15962 @kindex set history expansion
15963 Enable history expansion. History expansion is off by default.
15964
15965 @item set history expansion off
15966 Disable history expansion.
15967
15968 @c @group
15969 @kindex show history
15970 @item show history
15971 @itemx show history filename
15972 @itemx show history save
15973 @itemx show history size
15974 @itemx show history expansion
15975 These commands display the state of the @value{GDBN} history parameters.
15976 @code{show history} by itself displays all four states.
15977 @c @end group
15978 @end table
15979
15980 @table @code
15981 @kindex show commands
15982 @cindex show last commands
15983 @cindex display command history
15984 @item show commands
15985 Display the last ten commands in the command history.
15986
15987 @item show commands @var{n}
15988 Print ten commands centered on command number @var{n}.
15989
15990 @item show commands +
15991 Print ten commands just after the commands last printed.
15992 @end table
15993
15994 @node Screen Size
15995 @section Screen Size
15996 @cindex size of screen
15997 @cindex pauses in output
15998
15999 Certain commands to @value{GDBN} may produce large amounts of
16000 information output to the screen. To help you read all of it,
16001 @value{GDBN} pauses and asks you for input at the end of each page of
16002 output. Type @key{RET} when you want to continue the output, or @kbd{q}
16003 to discard the remaining output. Also, the screen width setting
16004 determines when to wrap lines of output. Depending on what is being
16005 printed, @value{GDBN} tries to break the line at a readable place,
16006 rather than simply letting it overflow onto the following line.
16007
16008 Normally @value{GDBN} knows the size of the screen from the terminal
16009 driver software. For example, on Unix @value{GDBN} uses the termcap data base
16010 together with the value of the @code{TERM} environment variable and the
16011 @code{stty rows} and @code{stty cols} settings. If this is not correct,
16012 you can override it with the @code{set height} and @code{set
16013 width} commands:
16014
16015 @table @code
16016 @kindex set height
16017 @kindex set width
16018 @kindex show width
16019 @kindex show height
16020 @item set height @var{lpp}
16021 @itemx show height
16022 @itemx set width @var{cpl}
16023 @itemx show width
16024 These @code{set} commands specify a screen height of @var{lpp} lines and
16025 a screen width of @var{cpl} characters. The associated @code{show}
16026 commands display the current settings.
16027
16028 If you specify a height of zero lines, @value{GDBN} does not pause during
16029 output no matter how long the output is. This is useful if output is to a
16030 file or to an editor buffer.
16031
16032 Likewise, you can specify @samp{set width 0} to prevent @value{GDBN}
16033 from wrapping its output.
16034
16035 @item set pagination on
16036 @itemx set pagination off
16037 @kindex set pagination
16038 Turn the output pagination on or off; the default is on. Turning
16039 pagination off is the alternative to @code{set height 0}.
16040
16041 @item show pagination
16042 @kindex show pagination
16043 Show the current pagination mode.
16044 @end table
16045
16046 @node Numbers
16047 @section Numbers
16048 @cindex number representation
16049 @cindex entering numbers
16050
16051 You can always enter numbers in octal, decimal, or hexadecimal in
16052 @value{GDBN} by the usual conventions: octal numbers begin with
16053 @samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
16054 begin with @samp{0x}. Numbers that neither begin with @samp{0} or
16055 @samp{0x}, nor end with a @samp{.} are, by default, entered in base
16056 10; likewise, the default display for numbers---when no particular
16057 format is specified---is base 10. You can change the default base for
16058 both input and output with the commands described below.
16059
16060 @table @code
16061 @kindex set input-radix
16062 @item set input-radix @var{base}
16063 Set the default base for numeric input. Supported choices
16064 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
16065 specified either unambiguously or using the current input radix; for
16066 example, any of
16067
16068 @smallexample
16069 set input-radix 012
16070 set input-radix 10.
16071 set input-radix 0xa
16072 @end smallexample
16073
16074 @noindent
16075 sets the input base to decimal. On the other hand, @samp{set input-radix 10}
16076 leaves the input radix unchanged, no matter what it was, since
16077 @samp{10}, being without any leading or trailing signs of its base, is
16078 interpreted in the current radix. Thus, if the current radix is 16,
16079 @samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
16080 change the radix.
16081
16082 @kindex set output-radix
16083 @item set output-radix @var{base}
16084 Set the default base for numeric display. Supported choices
16085 for @var{base} are decimal 8, 10, or 16. @var{base} must itself be
16086 specified either unambiguously or using the current input radix.
16087
16088 @kindex show input-radix
16089 @item show input-radix
16090 Display the current default base for numeric input.
16091
16092 @kindex show output-radix
16093 @item show output-radix
16094 Display the current default base for numeric display.
16095
16096 @item set radix @r{[}@var{base}@r{]}
16097 @itemx show radix
16098 @kindex set radix
16099 @kindex show radix
16100 These commands set and show the default base for both input and output
16101 of numbers. @code{set radix} sets the radix of input and output to
16102 the same base; without an argument, it resets the radix back to its
16103 default value of 10.
16104
16105 @end table
16106
16107 @node ABI
16108 @section Configuring the Current ABI
16109
16110 @value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
16111 application automatically. However, sometimes you need to override its
16112 conclusions. Use these commands to manage @value{GDBN}'s view of the
16113 current ABI.
16114
16115 @cindex OS ABI
16116 @kindex set osabi
16117 @kindex show osabi
16118
16119 One @value{GDBN} configuration can debug binaries for multiple operating
16120 system targets, either via remote debugging or native emulation.
16121 @value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
16122 but you can override its conclusion using the @code{set osabi} command.
16123 One example where this is useful is in debugging of binaries which use
16124 an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
16125 not have the same identifying marks that the standard C library for your
16126 platform provides.
16127
16128 @table @code
16129 @item show osabi
16130 Show the OS ABI currently in use.
16131
16132 @item set osabi
16133 With no argument, show the list of registered available OS ABI's.
16134
16135 @item set osabi @var{abi}
16136 Set the current OS ABI to @var{abi}.
16137 @end table
16138
16139 @cindex float promotion
16140
16141 Generally, the way that an argument of type @code{float} is passed to a
16142 function depends on whether the function is prototyped. For a prototyped
16143 (i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
16144 according to the architecture's convention for @code{float}. For unprototyped
16145 (i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
16146 @code{double} and then passed.
16147
16148 Unfortunately, some forms of debug information do not reliably indicate whether
16149 a function is prototyped. If @value{GDBN} calls a function that is not marked
16150 as prototyped, it consults @kbd{set coerce-float-to-double}.
16151
16152 @table @code
16153 @kindex set coerce-float-to-double
16154 @item set coerce-float-to-double
16155 @itemx set coerce-float-to-double on
16156 Arguments of type @code{float} will be promoted to @code{double} when passed
16157 to an unprototyped function. This is the default setting.
16158
16159 @item set coerce-float-to-double off
16160 Arguments of type @code{float} will be passed directly to unprototyped
16161 functions.
16162
16163 @kindex show coerce-float-to-double
16164 @item show coerce-float-to-double
16165 Show the current setting of promoting @code{float} to @code{double}.
16166 @end table
16167
16168 @kindex set cp-abi
16169 @kindex show cp-abi
16170 @value{GDBN} needs to know the ABI used for your program's C@t{++}
16171 objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
16172 used to build your application. @value{GDBN} only fully supports
16173 programs with a single C@t{++} ABI; if your program contains code using
16174 multiple C@t{++} ABI's or if @value{GDBN} can not identify your
16175 program's ABI correctly, you can tell @value{GDBN} which ABI to use.
16176 Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
16177 before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
16178 ``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
16179 use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
16180 ``auto''.
16181
16182 @table @code
16183 @item show cp-abi
16184 Show the C@t{++} ABI currently in use.
16185
16186 @item set cp-abi
16187 With no argument, show the list of supported C@t{++} ABI's.
16188
16189 @item set cp-abi @var{abi}
16190 @itemx set cp-abi auto
16191 Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
16192 @end table
16193
16194 @node Messages/Warnings
16195 @section Optional Warnings and Messages
16196
16197 @cindex verbose operation
16198 @cindex optional warnings
16199 By default, @value{GDBN} is silent about its inner workings. If you are
16200 running on a slow machine, you may want to use the @code{set verbose}
16201 command. This makes @value{GDBN} tell you when it does a lengthy
16202 internal operation, so you will not think it has crashed.
16203
16204 Currently, the messages controlled by @code{set verbose} are those
16205 which announce that the symbol table for a source file is being read;
16206 see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
16207
16208 @table @code
16209 @kindex set verbose
16210 @item set verbose on
16211 Enables @value{GDBN} output of certain informational messages.
16212
16213 @item set verbose off
16214 Disables @value{GDBN} output of certain informational messages.
16215
16216 @kindex show verbose
16217 @item show verbose
16218 Displays whether @code{set verbose} is on or off.
16219 @end table
16220
16221 By default, if @value{GDBN} encounters bugs in the symbol table of an
16222 object file, it is silent; but if you are debugging a compiler, you may
16223 find this information useful (@pxref{Symbol Errors, ,Errors Reading
16224 Symbol Files}).
16225
16226 @table @code
16227
16228 @kindex set complaints
16229 @item set complaints @var{limit}
16230 Permits @value{GDBN} to output @var{limit} complaints about each type of
16231 unusual symbols before becoming silent about the problem. Set
16232 @var{limit} to zero to suppress all complaints; set it to a large number
16233 to prevent complaints from being suppressed.
16234
16235 @kindex show complaints
16236 @item show complaints
16237 Displays how many symbol complaints @value{GDBN} is permitted to produce.
16238
16239 @end table
16240
16241 By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
16242 lot of stupid questions to confirm certain commands. For example, if
16243 you try to run a program which is already running:
16244
16245 @smallexample
16246 (@value{GDBP}) run
16247 The program being debugged has been started already.
16248 Start it from the beginning? (y or n)
16249 @end smallexample
16250
16251 If you are willing to unflinchingly face the consequences of your own
16252 commands, you can disable this ``feature'':
16253
16254 @table @code
16255
16256 @kindex set confirm
16257 @cindex flinching
16258 @cindex confirmation
16259 @cindex stupid questions
16260 @item set confirm off
16261 Disables confirmation requests.
16262
16263 @item set confirm on
16264 Enables confirmation requests (the default).
16265
16266 @kindex show confirm
16267 @item show confirm
16268 Displays state of confirmation requests.
16269
16270 @end table
16271
16272 @cindex command tracing
16273 If you need to debug user-defined commands or sourced files you may find it
16274 useful to enable @dfn{command tracing}. In this mode each command will be
16275 printed as it is executed, prefixed with one or more @samp{+} symbols, the
16276 quantity denoting the call depth of each command.
16277
16278 @table @code
16279 @kindex set trace-commands
16280 @cindex command scripts, debugging
16281 @item set trace-commands on
16282 Enable command tracing.
16283 @item set trace-commands off
16284 Disable command tracing.
16285 @item show trace-commands
16286 Display the current state of command tracing.
16287 @end table
16288
16289 @node Debugging Output
16290 @section Optional Messages about Internal Happenings
16291 @cindex optional debugging messages
16292
16293 @value{GDBN} has commands that enable optional debugging messages from
16294 various @value{GDBN} subsystems; normally these commands are of
16295 interest to @value{GDBN} maintainers, or when reporting a bug. This
16296 section documents those commands.
16297
16298 @table @code
16299 @kindex set exec-done-display
16300 @item set exec-done-display
16301 Turns on or off the notification of asynchronous commands'
16302 completion. When on, @value{GDBN} will print a message when an
16303 asynchronous command finishes its execution. The default is off.
16304 @kindex show exec-done-display
16305 @item show exec-done-display
16306 Displays the current setting of asynchronous command completion
16307 notification.
16308 @kindex set debug
16309 @cindex gdbarch debugging info
16310 @cindex architecture debugging info
16311 @item set debug arch
16312 Turns on or off display of gdbarch debugging info. The default is off
16313 @kindex show debug
16314 @item show debug arch
16315 Displays the current state of displaying gdbarch debugging info.
16316 @item set debug aix-thread
16317 @cindex AIX threads
16318 Display debugging messages about inner workings of the AIX thread
16319 module.
16320 @item show debug aix-thread
16321 Show the current state of AIX thread debugging info display.
16322 @item set debug event
16323 @cindex event debugging info
16324 Turns on or off display of @value{GDBN} event debugging info. The
16325 default is off.
16326 @item show debug event
16327 Displays the current state of displaying @value{GDBN} event debugging
16328 info.
16329 @item set debug expression
16330 @cindex expression debugging info
16331 Turns on or off display of debugging info about @value{GDBN}
16332 expression parsing. The default is off.
16333 @item show debug expression
16334 Displays the current state of displaying debugging info about
16335 @value{GDBN} expression parsing.
16336 @item set debug frame
16337 @cindex frame debugging info
16338 Turns on or off display of @value{GDBN} frame debugging info. The
16339 default is off.
16340 @item show debug frame
16341 Displays the current state of displaying @value{GDBN} frame debugging
16342 info.
16343 @item set debug infrun
16344 @cindex inferior debugging info
16345 Turns on or off display of @value{GDBN} debugging info for running the inferior.
16346 The default is off. @file{infrun.c} contains GDB's runtime state machine used
16347 for implementing operations such as single-stepping the inferior.
16348 @item show debug infrun
16349 Displays the current state of @value{GDBN} inferior debugging.
16350 @item set debug lin-lwp
16351 @cindex @sc{gnu}/Linux LWP debug messages
16352 @cindex Linux lightweight processes
16353 Turns on or off debugging messages from the Linux LWP debug support.
16354 @item show debug lin-lwp
16355 Show the current state of Linux LWP debugging messages.
16356 @item set debug observer
16357 @cindex observer debugging info
16358 Turns on or off display of @value{GDBN} observer debugging. This
16359 includes info such as the notification of observable events.
16360 @item show debug observer
16361 Displays the current state of observer debugging.
16362 @item set debug overload
16363 @cindex C@t{++} overload debugging info
16364 Turns on or off display of @value{GDBN} C@t{++} overload debugging
16365 info. This includes info such as ranking of functions, etc. The default
16366 is off.
16367 @item show debug overload
16368 Displays the current state of displaying @value{GDBN} C@t{++} overload
16369 debugging info.
16370 @cindex packets, reporting on stdout
16371 @cindex serial connections, debugging
16372 @cindex debug remote protocol
16373 @cindex remote protocol debugging
16374 @cindex display remote packets
16375 @item set debug remote
16376 Turns on or off display of reports on all packets sent back and forth across
16377 the serial line to the remote machine. The info is printed on the
16378 @value{GDBN} standard output stream. The default is off.
16379 @item show debug remote
16380 Displays the state of display of remote packets.
16381 @item set debug serial
16382 Turns on or off display of @value{GDBN} serial debugging info. The
16383 default is off.
16384 @item show debug serial
16385 Displays the current state of displaying @value{GDBN} serial debugging
16386 info.
16387 @item set debug solib-frv
16388 @cindex FR-V shared-library debugging
16389 Turns on or off debugging messages for FR-V shared-library code.
16390 @item show debug solib-frv
16391 Display the current state of FR-V shared-library code debugging
16392 messages.
16393 @item set debug target
16394 @cindex target debugging info
16395 Turns on or off display of @value{GDBN} target debugging info. This info
16396 includes what is going on at the target level of GDB, as it happens. The
16397 default is 0. Set it to 1 to track events, and to 2 to also track the
16398 value of large memory transfers. Changes to this flag do not take effect
16399 until the next time you connect to a target or use the @code{run} command.
16400 @item show debug target
16401 Displays the current state of displaying @value{GDBN} target debugging
16402 info.
16403 @item set debug timestamp
16404 @cindex timestampping debugging info
16405 Turns on or off display of timestamps with @value{GDBN} debugging info.
16406 When enabled, seconds and microseconds are displayed before each debugging
16407 message.
16408 @item show debug timestamp
16409 Displays the current state of displaying timestamps with @value{GDBN}
16410 debugging info.
16411 @item set debugvarobj
16412 @cindex variable object debugging info
16413 Turns on or off display of @value{GDBN} variable object debugging
16414 info. The default is off.
16415 @item show debugvarobj
16416 Displays the current state of displaying @value{GDBN} variable object
16417 debugging info.
16418 @item set debug xml
16419 @cindex XML parser debugging
16420 Turns on or off debugging messages for built-in XML parsers.
16421 @item show debug xml
16422 Displays the current state of XML debugging messages.
16423 @end table
16424
16425 @node Sequences
16426 @chapter Canned Sequences of Commands
16427
16428 Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
16429 Command Lists}), @value{GDBN} provides two ways to store sequences of
16430 commands for execution as a unit: user-defined commands and command
16431 files.
16432
16433 @menu
16434 * Define:: How to define your own commands
16435 * Hooks:: Hooks for user-defined commands
16436 * Command Files:: How to write scripts of commands to be stored in a file
16437 * Output:: Commands for controlled output
16438 @end menu
16439
16440 @node Define
16441 @section User-defined Commands
16442
16443 @cindex user-defined command
16444 @cindex arguments, to user-defined commands
16445 A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
16446 which you assign a new name as a command. This is done with the
16447 @code{define} command. User commands may accept up to 10 arguments
16448 separated by whitespace. Arguments are accessed within the user command
16449 via @code{$arg0@dots{}$arg9}. A trivial example:
16450
16451 @smallexample
16452 define adder
16453 print $arg0 + $arg1 + $arg2
16454 end
16455 @end smallexample
16456
16457 @noindent
16458 To execute the command use:
16459
16460 @smallexample
16461 adder 1 2 3
16462 @end smallexample
16463
16464 @noindent
16465 This defines the command @code{adder}, which prints the sum of
16466 its three arguments. Note the arguments are text substitutions, so they may
16467 reference variables, use complex expressions, or even perform inferior
16468 functions calls.
16469
16470 @cindex argument count in user-defined commands
16471 @cindex how many arguments (user-defined commands)
16472 In addition, @code{$argc} may be used to find out how many arguments have
16473 been passed. This expands to a number in the range 0@dots{}10.
16474
16475 @smallexample
16476 define adder
16477 if $argc == 2
16478 print $arg0 + $arg1
16479 end
16480 if $argc == 3
16481 print $arg0 + $arg1 + $arg2
16482 end
16483 end
16484 @end smallexample
16485
16486 @table @code
16487
16488 @kindex define
16489 @item define @var{commandname}
16490 Define a command named @var{commandname}. If there is already a command
16491 by that name, you are asked to confirm that you want to redefine it.
16492
16493 The definition of the command is made up of other @value{GDBN} command lines,
16494 which are given following the @code{define} command. The end of these
16495 commands is marked by a line containing @code{end}.
16496
16497 @kindex document
16498 @kindex end@r{ (user-defined commands)}
16499 @item document @var{commandname}
16500 Document the user-defined command @var{commandname}, so that it can be
16501 accessed by @code{help}. The command @var{commandname} must already be
16502 defined. This command reads lines of documentation just as @code{define}
16503 reads the lines of the command definition, ending with @code{end}.
16504 After the @code{document} command is finished, @code{help} on command
16505 @var{commandname} displays the documentation you have written.
16506
16507 You may use the @code{document} command again to change the
16508 documentation of a command. Redefining the command with @code{define}
16509 does not change the documentation.
16510
16511 @kindex dont-repeat
16512 @cindex don't repeat command
16513 @item dont-repeat
16514 Used inside a user-defined command, this tells @value{GDBN} that this
16515 command should not be repeated when the user hits @key{RET}
16516 (@pxref{Command Syntax, repeat last command}).
16517
16518 @kindex help user-defined
16519 @item help user-defined
16520 List all user-defined commands, with the first line of the documentation
16521 (if any) for each.
16522
16523 @kindex show user
16524 @item show user
16525 @itemx show user @var{commandname}
16526 Display the @value{GDBN} commands used to define @var{commandname} (but
16527 not its documentation). If no @var{commandname} is given, display the
16528 definitions for all user-defined commands.
16529
16530 @cindex infinite recursion in user-defined commands
16531 @kindex show max-user-call-depth
16532 @kindex set max-user-call-depth
16533 @item show max-user-call-depth
16534 @itemx set max-user-call-depth
16535 The value of @code{max-user-call-depth} controls how many recursion
16536 levels are allowed in user-defined commands before @value{GDBN} suspects an
16537 infinite recursion and aborts the command.
16538 @end table
16539
16540 In addition to the above commands, user-defined commands frequently
16541 use control flow commands, described in @ref{Command Files}.
16542
16543 When user-defined commands are executed, the
16544 commands of the definition are not printed. An error in any command
16545 stops execution of the user-defined command.
16546
16547 If used interactively, commands that would ask for confirmation proceed
16548 without asking when used inside a user-defined command. Many @value{GDBN}
16549 commands that normally print messages to say what they are doing omit the
16550 messages when used in a user-defined command.
16551
16552 @node Hooks
16553 @section User-defined Command Hooks
16554 @cindex command hooks
16555 @cindex hooks, for commands
16556 @cindex hooks, pre-command
16557
16558 @kindex hook
16559 You may define @dfn{hooks}, which are a special kind of user-defined
16560 command. Whenever you run the command @samp{foo}, if the user-defined
16561 command @samp{hook-foo} exists, it is executed (with no arguments)
16562 before that command.
16563
16564 @cindex hooks, post-command
16565 @kindex hookpost
16566 A hook may also be defined which is run after the command you executed.
16567 Whenever you run the command @samp{foo}, if the user-defined command
16568 @samp{hookpost-foo} exists, it is executed (with no arguments) after
16569 that command. Post-execution hooks may exist simultaneously with
16570 pre-execution hooks, for the same command.
16571
16572 It is valid for a hook to call the command which it hooks. If this
16573 occurs, the hook is not re-executed, thereby avoiding infinite recursion.
16574
16575 @c It would be nice if hookpost could be passed a parameter indicating
16576 @c if the command it hooks executed properly or not. FIXME!
16577
16578 @kindex stop@r{, a pseudo-command}
16579 In addition, a pseudo-command, @samp{stop} exists. Defining
16580 (@samp{hook-stop}) makes the associated commands execute every time
16581 execution stops in your program: before breakpoint commands are run,
16582 displays are printed, or the stack frame is printed.
16583
16584 For example, to ignore @code{SIGALRM} signals while
16585 single-stepping, but treat them normally during normal execution,
16586 you could define:
16587
16588 @smallexample
16589 define hook-stop
16590 handle SIGALRM nopass
16591 end
16592
16593 define hook-run
16594 handle SIGALRM pass
16595 end
16596
16597 define hook-continue
16598 handle SIGALRM pass
16599 end
16600 @end smallexample
16601
16602 As a further example, to hook at the beginning and end of the @code{echo}
16603 command, and to add extra text to the beginning and end of the message,
16604 you could define:
16605
16606 @smallexample
16607 define hook-echo
16608 echo <<<---
16609 end
16610
16611 define hookpost-echo
16612 echo --->>>\n
16613 end
16614
16615 (@value{GDBP}) echo Hello World
16616 <<<---Hello World--->>>
16617 (@value{GDBP})
16618
16619 @end smallexample
16620
16621 You can define a hook for any single-word command in @value{GDBN}, but
16622 not for command aliases; you should define a hook for the basic command
16623 name, e.g.@: @code{backtrace} rather than @code{bt}.
16624 @c FIXME! So how does Joe User discover whether a command is an alias
16625 @c or not?
16626 If an error occurs during the execution of your hook, execution of
16627 @value{GDBN} commands stops and @value{GDBN} issues a prompt
16628 (before the command that you actually typed had a chance to run).
16629
16630 If you try to define a hook which does not match any known command, you
16631 get a warning from the @code{define} command.
16632
16633 @node Command Files
16634 @section Command Files
16635
16636 @cindex command files
16637 @cindex scripting commands
16638 A command file for @value{GDBN} is a text file made of lines that are
16639 @value{GDBN} commands. Comments (lines starting with @kbd{#}) may
16640 also be included. An empty line in a command file does nothing; it
16641 does not mean to repeat the last command, as it would from the
16642 terminal.
16643
16644 You can request the execution of a command file with the @code{source}
16645 command:
16646
16647 @table @code
16648 @kindex source
16649 @cindex execute commands from a file
16650 @item source [@code{-v}] @var{filename}
16651 Execute the command file @var{filename}.
16652 @end table
16653
16654 The lines in a command file are generally executed sequentially,
16655 unless the order of execution is changed by one of the
16656 @emph{flow-control commands} described below. The commands are not
16657 printed as they are executed. An error in any command terminates
16658 execution of the command file and control is returned to the console.
16659
16660 @value{GDBN} searches for @var{filename} in the current directory and then
16661 on the search path (specified with the @samp{directory} command).
16662
16663 If @code{-v}, for verbose mode, is given then @value{GDBN} displays
16664 each command as it is executed. The option must be given before
16665 @var{filename}, and is interpreted as part of the filename anywhere else.
16666
16667 Commands that would ask for confirmation if used interactively proceed
16668 without asking when used in a command file. Many @value{GDBN} commands that
16669 normally print messages to say what they are doing omit the messages
16670 when called from command files.
16671
16672 @value{GDBN} also accepts command input from standard input. In this
16673 mode, normal output goes to standard output and error output goes to
16674 standard error. Errors in a command file supplied on standard input do
16675 not terminate execution of the command file---execution continues with
16676 the next command.
16677
16678 @smallexample
16679 gdb < cmds > log 2>&1
16680 @end smallexample
16681
16682 (The syntax above will vary depending on the shell used.) This example
16683 will execute commands from the file @file{cmds}. All output and errors
16684 would be directed to @file{log}.
16685
16686 Since commands stored on command files tend to be more general than
16687 commands typed interactively, they frequently need to deal with
16688 complicated situations, such as different or unexpected values of
16689 variables and symbols, changes in how the program being debugged is
16690 built, etc. @value{GDBN} provides a set of flow-control commands to
16691 deal with these complexities. Using these commands, you can write
16692 complex scripts that loop over data structures, execute commands
16693 conditionally, etc.
16694
16695 @table @code
16696 @kindex if
16697 @kindex else
16698 @item if
16699 @itemx else
16700 This command allows to include in your script conditionally executed
16701 commands. The @code{if} command takes a single argument, which is an
16702 expression to evaluate. It is followed by a series of commands that
16703 are executed only if the expression is true (its value is nonzero).
16704 There can then optionally be an @code{else} line, followed by a series
16705 of commands that are only executed if the expression was false. The
16706 end of the list is marked by a line containing @code{end}.
16707
16708 @kindex while
16709 @item while
16710 This command allows to write loops. Its syntax is similar to
16711 @code{if}: the command takes a single argument, which is an expression
16712 to evaluate, and must be followed by the commands to execute, one per
16713 line, terminated by an @code{end}. These commands are called the
16714 @dfn{body} of the loop. The commands in the body of @code{while} are
16715 executed repeatedly as long as the expression evaluates to true.
16716
16717 @kindex loop_break
16718 @item loop_break
16719 This command exits the @code{while} loop in whose body it is included.
16720 Execution of the script continues after that @code{while}s @code{end}
16721 line.
16722
16723 @kindex loop_continue
16724 @item loop_continue
16725 This command skips the execution of the rest of the body of commands
16726 in the @code{while} loop in whose body it is included. Execution
16727 branches to the beginning of the @code{while} loop, where it evaluates
16728 the controlling expression.
16729
16730 @kindex end@r{ (if/else/while commands)}
16731 @item end
16732 Terminate the block of commands that are the body of @code{if},
16733 @code{else}, or @code{while} flow-control commands.
16734 @end table
16735
16736
16737 @node Output
16738 @section Commands for Controlled Output
16739
16740 During the execution of a command file or a user-defined command, normal
16741 @value{GDBN} output is suppressed; the only output that appears is what is
16742 explicitly printed by the commands in the definition. This section
16743 describes three commands useful for generating exactly the output you
16744 want.
16745
16746 @table @code
16747 @kindex echo
16748 @item echo @var{text}
16749 @c I do not consider backslash-space a standard C escape sequence
16750 @c because it is not in ANSI.
16751 Print @var{text}. Nonprinting characters can be included in
16752 @var{text} using C escape sequences, such as @samp{\n} to print a
16753 newline. @strong{No newline is printed unless you specify one.}
16754 In addition to the standard C escape sequences, a backslash followed
16755 by a space stands for a space. This is useful for displaying a
16756 string with spaces at the beginning or the end, since leading and
16757 trailing spaces are otherwise trimmed from all arguments.
16758 To print @samp{@w{ }and foo =@w{ }}, use the command
16759 @samp{echo \@w{ }and foo = \@w{ }}.
16760
16761 A backslash at the end of @var{text} can be used, as in C, to continue
16762 the command onto subsequent lines. For example,
16763
16764 @smallexample
16765 echo This is some text\n\
16766 which is continued\n\
16767 onto several lines.\n
16768 @end smallexample
16769
16770 produces the same output as
16771
16772 @smallexample
16773 echo This is some text\n
16774 echo which is continued\n
16775 echo onto several lines.\n
16776 @end smallexample
16777
16778 @kindex output
16779 @item output @var{expression}
16780 Print the value of @var{expression} and nothing but that value: no
16781 newlines, no @samp{$@var{nn} = }. The value is not entered in the
16782 value history either. @xref{Expressions, ,Expressions}, for more information
16783 on expressions.
16784
16785 @item output/@var{fmt} @var{expression}
16786 Print the value of @var{expression} in format @var{fmt}. You can use
16787 the same formats as for @code{print}. @xref{Output Formats,,Output
16788 Formats}, for more information.
16789
16790 @kindex printf
16791 @item printf @var{template}, @var{expressions}@dots{}
16792 Print the values of one or more @var{expressions} under the control of
16793 the string @var{template}. To print several values, make
16794 @var{expressions} be a comma-separated list of individual expressions,
16795 which may be either numbers or pointers. Their values are printed as
16796 specified by @var{template}, exactly as a C program would do by
16797 executing the code below:
16798
16799 @smallexample
16800 printf (@var{template}, @var{expressions}@dots{});
16801 @end smallexample
16802
16803 As in @code{C} @code{printf}, ordinary characters in @var{template}
16804 are printed verbatim, while @dfn{conversion specification} introduced
16805 by the @samp{%} character cause subsequent @var{expressions} to be
16806 evaluated, their values converted and formatted according to type and
16807 style information encoded in the conversion specifications, and then
16808 printed.
16809
16810 For example, you can print two values in hex like this:
16811
16812 @smallexample
16813 printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
16814 @end smallexample
16815
16816 @code{printf} supports all the standard @code{C} conversion
16817 specifications, including the flags and modifiers between the @samp{%}
16818 character and the conversion letter, with the following exceptions:
16819
16820 @itemize @bullet
16821 @item
16822 The argument-ordering modifiers, such as @samp{2$}, are not supported.
16823
16824 @item
16825 The modifier @samp{*} is not supported for specifying precision or
16826 width.
16827
16828 @item
16829 The @samp{'} flag (for separation of digits into groups according to
16830 @code{LC_NUMERIC'}) is not supported.
16831
16832 @item
16833 The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
16834 supported.
16835
16836 @item
16837 The conversion letter @samp{n} (as in @samp{%n}) is not supported.
16838
16839 @item
16840 The conversion letters @samp{a} and @samp{A} are not supported.
16841 @end itemize
16842
16843 @noindent
16844 Note that the @samp{ll} type modifier is supported only if the
16845 underlying @code{C} implementation used to build @value{GDBN} supports
16846 the @code{long long int} type, and the @samp{L} type modifier is
16847 supported only if @code{long double} type is available.
16848
16849 As in @code{C}, @code{printf} supports simple backslash-escape
16850 sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
16851 @samp{\a}, and @samp{\f}, that consist of backslash followed by a
16852 single character. Octal and hexadecimal escape sequences are not
16853 supported.
16854
16855 Additionally, @code{printf} supports conversion specifications for DFP
16856 (@dfn{Decimal Floating Point}) types using the following length modifiers
16857 together with a floating point specifier.
16858 letters:
16859
16860 @itemize @bullet
16861 @item
16862 @samp{H} for printing @code{Decimal32} types.
16863
16864 @item
16865 @samp{D} for printing @code{Decimal64} types.
16866
16867 @item
16868 @samp{DD} for printing @code{Decimal128} types.
16869 @end itemize
16870
16871 If the underlying @code{C} implementation used to build @value{GDBN} has
16872 support for the three length modifiers for DFP types, other modifiers
16873 such as width and precision will also be available for @value{GDBN} to use.
16874
16875 In case there is no such @code{C} support, no additional modifiers will be
16876 available and the value will be printed in the standard way.
16877
16878 Here's an example of printing DFP types using the above conversion letters:
16879 @smallexample
16880 printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
16881 @end smallexample
16882
16883 @end table
16884
16885 @node Interpreters
16886 @chapter Command Interpreters
16887 @cindex command interpreters
16888
16889 @value{GDBN} supports multiple command interpreters, and some command
16890 infrastructure to allow users or user interface writers to switch
16891 between interpreters or run commands in other interpreters.
16892
16893 @value{GDBN} currently supports two command interpreters, the console
16894 interpreter (sometimes called the command-line interpreter or @sc{cli})
16895 and the machine interface interpreter (or @sc{gdb/mi}). This manual
16896 describes both of these interfaces in great detail.
16897
16898 By default, @value{GDBN} will start with the console interpreter.
16899 However, the user may choose to start @value{GDBN} with another
16900 interpreter by specifying the @option{-i} or @option{--interpreter}
16901 startup options. Defined interpreters include:
16902
16903 @table @code
16904 @item console
16905 @cindex console interpreter
16906 The traditional console or command-line interpreter. This is the most often
16907 used interpreter with @value{GDBN}. With no interpreter specified at runtime,
16908 @value{GDBN} will use this interpreter.
16909
16910 @item mi
16911 @cindex mi interpreter
16912 The newest @sc{gdb/mi} interface (currently @code{mi2}). Used primarily
16913 by programs wishing to use @value{GDBN} as a backend for a debugger GUI
16914 or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
16915 Interface}.
16916
16917 @item mi2
16918 @cindex mi2 interpreter
16919 The current @sc{gdb/mi} interface.
16920
16921 @item mi1
16922 @cindex mi1 interpreter
16923 The @sc{gdb/mi} interface included in @value{GDBN} 5.1, 5.2, and 5.3.
16924
16925 @end table
16926
16927 @cindex invoke another interpreter
16928 The interpreter being used by @value{GDBN} may not be dynamically
16929 switched at runtime. Although possible, this could lead to a very
16930 precarious situation. Consider an IDE using @sc{gdb/mi}. If a user
16931 enters the command "interpreter-set console" in a console view,
16932 @value{GDBN} would switch to using the console interpreter, rendering
16933 the IDE inoperable!
16934
16935 @kindex interpreter-exec
16936 Although you may only choose a single interpreter at startup, you may execute
16937 commands in any interpreter from the current interpreter using the appropriate
16938 command. If you are running the console interpreter, simply use the
16939 @code{interpreter-exec} command:
16940
16941 @smallexample
16942 interpreter-exec mi "-data-list-register-names"
16943 @end smallexample
16944
16945 @sc{gdb/mi} has a similar command, although it is only available in versions of
16946 @value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
16947
16948 @node TUI
16949 @chapter @value{GDBN} Text User Interface
16950 @cindex TUI
16951 @cindex Text User Interface
16952
16953 @menu
16954 * TUI Overview:: TUI overview
16955 * TUI Keys:: TUI key bindings
16956 * TUI Single Key Mode:: TUI single key mode
16957 * TUI Commands:: TUI-specific commands
16958 * TUI Configuration:: TUI configuration variables
16959 @end menu
16960
16961 The @value{GDBN} Text User Interface (TUI) is a terminal
16962 interface which uses the @code{curses} library to show the source
16963 file, the assembly output, the program registers and @value{GDBN}
16964 commands in separate text windows. The TUI mode is supported only
16965 on platforms where a suitable version of the @code{curses} library
16966 is available.
16967
16968 @pindex @value{GDBTUI}
16969 The TUI mode is enabled by default when you invoke @value{GDBN} as
16970 either @samp{@value{GDBTUI}} or @samp{@value{GDBP} -tui}.
16971 You can also switch in and out of TUI mode while @value{GDBN} runs by
16972 using various TUI commands and key bindings, such as @kbd{C-x C-a}.
16973 @xref{TUI Keys, ,TUI Key Bindings}.
16974
16975 @node TUI Overview
16976 @section TUI Overview
16977
16978 In TUI mode, @value{GDBN} can display several text windows:
16979
16980 @table @emph
16981 @item command
16982 This window is the @value{GDBN} command window with the @value{GDBN}
16983 prompt and the @value{GDBN} output. The @value{GDBN} input is still
16984 managed using readline.
16985
16986 @item source
16987 The source window shows the source file of the program. The current
16988 line and active breakpoints are displayed in this window.
16989
16990 @item assembly
16991 The assembly window shows the disassembly output of the program.
16992
16993 @item register
16994 This window shows the processor registers. Registers are highlighted
16995 when their values change.
16996 @end table
16997
16998 The source and assembly windows show the current program position
16999 by highlighting the current line and marking it with a @samp{>} marker.
17000 Breakpoints are indicated with two markers. The first marker
17001 indicates the breakpoint type:
17002
17003 @table @code
17004 @item B
17005 Breakpoint which was hit at least once.
17006
17007 @item b
17008 Breakpoint which was never hit.
17009
17010 @item H
17011 Hardware breakpoint which was hit at least once.
17012
17013 @item h
17014 Hardware breakpoint which was never hit.
17015 @end table
17016
17017 The second marker indicates whether the breakpoint is enabled or not:
17018
17019 @table @code
17020 @item +
17021 Breakpoint is enabled.
17022
17023 @item -
17024 Breakpoint is disabled.
17025 @end table
17026
17027 The source, assembly and register windows are updated when the current
17028 thread changes, when the frame changes, or when the program counter
17029 changes.
17030
17031 These windows are not all visible at the same time. The command
17032 window is always visible. The others can be arranged in several
17033 layouts:
17034
17035 @itemize @bullet
17036 @item
17037 source only,
17038
17039 @item
17040 assembly only,
17041
17042 @item
17043 source and assembly,
17044
17045 @item
17046 source and registers, or
17047
17048 @item
17049 assembly and registers.
17050 @end itemize
17051
17052 A status line above the command window shows the following information:
17053
17054 @table @emph
17055 @item target
17056 Indicates the current @value{GDBN} target.
17057 (@pxref{Targets, ,Specifying a Debugging Target}).
17058
17059 @item process
17060 Gives the current process or thread number.
17061 When no process is being debugged, this field is set to @code{No process}.
17062
17063 @item function
17064 Gives the current function name for the selected frame.
17065 The name is demangled if demangling is turned on (@pxref{Print Settings}).
17066 When there is no symbol corresponding to the current program counter,
17067 the string @code{??} is displayed.
17068
17069 @item line
17070 Indicates the current line number for the selected frame.
17071 When the current line number is not known, the string @code{??} is displayed.
17072
17073 @item pc
17074 Indicates the current program counter address.
17075 @end table
17076
17077 @node TUI Keys
17078 @section TUI Key Bindings
17079 @cindex TUI key bindings
17080
17081 The TUI installs several key bindings in the readline keymaps
17082 (@pxref{Command Line Editing}). The following key bindings
17083 are installed for both TUI mode and the @value{GDBN} standard mode.
17084
17085 @table @kbd
17086 @kindex C-x C-a
17087 @item C-x C-a
17088 @kindex C-x a
17089 @itemx C-x a
17090 @kindex C-x A
17091 @itemx C-x A
17092 Enter or leave the TUI mode. When leaving the TUI mode,
17093 the curses window management stops and @value{GDBN} operates using
17094 its standard mode, writing on the terminal directly. When reentering
17095 the TUI mode, control is given back to the curses windows.
17096 The screen is then refreshed.
17097
17098 @kindex C-x 1
17099 @item C-x 1
17100 Use a TUI layout with only one window. The layout will
17101 either be @samp{source} or @samp{assembly}. When the TUI mode
17102 is not active, it will switch to the TUI mode.
17103
17104 Think of this key binding as the Emacs @kbd{C-x 1} binding.
17105
17106 @kindex C-x 2
17107 @item C-x 2
17108 Use a TUI layout with at least two windows. When the current
17109 layout already has two windows, the next layout with two windows is used.
17110 When a new layout is chosen, one window will always be common to the
17111 previous layout and the new one.
17112
17113 Think of it as the Emacs @kbd{C-x 2} binding.
17114
17115 @kindex C-x o
17116 @item C-x o
17117 Change the active window. The TUI associates several key bindings
17118 (like scrolling and arrow keys) with the active window. This command
17119 gives the focus to the next TUI window.
17120
17121 Think of it as the Emacs @kbd{C-x o} binding.
17122
17123 @kindex C-x s
17124 @item C-x s
17125 Switch in and out of the TUI SingleKey mode that binds single
17126 keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
17127 @end table
17128
17129 The following key bindings only work in the TUI mode:
17130
17131 @table @asis
17132 @kindex PgUp
17133 @item @key{PgUp}
17134 Scroll the active window one page up.
17135
17136 @kindex PgDn
17137 @item @key{PgDn}
17138 Scroll the active window one page down.
17139
17140 @kindex Up
17141 @item @key{Up}
17142 Scroll the active window one line up.
17143
17144 @kindex Down
17145 @item @key{Down}
17146 Scroll the active window one line down.
17147
17148 @kindex Left
17149 @item @key{Left}
17150 Scroll the active window one column left.
17151
17152 @kindex Right
17153 @item @key{Right}
17154 Scroll the active window one column right.
17155
17156 @kindex C-L
17157 @item @kbd{C-L}
17158 Refresh the screen.
17159 @end table
17160
17161 Because the arrow keys scroll the active window in the TUI mode, they
17162 are not available for their normal use by readline unless the command
17163 window has the focus. When another window is active, you must use
17164 other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
17165 and @kbd{C-f} to control the command window.
17166
17167 @node TUI Single Key Mode
17168 @section TUI Single Key Mode
17169 @cindex TUI single key mode
17170
17171 The TUI also provides a @dfn{SingleKey} mode, which binds several
17172 frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
17173 switch into this mode, where the following key bindings are used:
17174
17175 @table @kbd
17176 @kindex c @r{(SingleKey TUI key)}
17177 @item c
17178 continue
17179
17180 @kindex d @r{(SingleKey TUI key)}
17181 @item d
17182 down
17183
17184 @kindex f @r{(SingleKey TUI key)}
17185 @item f
17186 finish
17187
17188 @kindex n @r{(SingleKey TUI key)}
17189 @item n
17190 next
17191
17192 @kindex q @r{(SingleKey TUI key)}
17193 @item q
17194 exit the SingleKey mode.
17195
17196 @kindex r @r{(SingleKey TUI key)}
17197 @item r
17198 run
17199
17200 @kindex s @r{(SingleKey TUI key)}
17201 @item s
17202 step
17203
17204 @kindex u @r{(SingleKey TUI key)}
17205 @item u
17206 up
17207
17208 @kindex v @r{(SingleKey TUI key)}
17209 @item v
17210 info locals
17211
17212 @kindex w @r{(SingleKey TUI key)}
17213 @item w
17214 where
17215 @end table
17216
17217 Other keys temporarily switch to the @value{GDBN} command prompt.
17218 The key that was pressed is inserted in the editing buffer so that
17219 it is possible to type most @value{GDBN} commands without interaction
17220 with the TUI SingleKey mode. Once the command is entered the TUI
17221 SingleKey mode is restored. The only way to permanently leave
17222 this mode is by typing @kbd{q} or @kbd{C-x s}.
17223
17224
17225 @node TUI Commands
17226 @section TUI-specific Commands
17227 @cindex TUI commands
17228
17229 The TUI has specific commands to control the text windows.
17230 These commands are always available, even when @value{GDBN} is not in
17231 the TUI mode. When @value{GDBN} is in the standard mode, most
17232 of these commands will automatically switch to the TUI mode.
17233
17234 @table @code
17235 @item info win
17236 @kindex info win
17237 List and give the size of all displayed windows.
17238
17239 @item layout next
17240 @kindex layout
17241 Display the next layout.
17242
17243 @item layout prev
17244 Display the previous layout.
17245
17246 @item layout src
17247 Display the source window only.
17248
17249 @item layout asm
17250 Display the assembly window only.
17251
17252 @item layout split
17253 Display the source and assembly window.
17254
17255 @item layout regs
17256 Display the register window together with the source or assembly window.
17257
17258 @item focus next
17259 @kindex focus
17260 Make the next window active for scrolling.
17261
17262 @item focus prev
17263 Make the previous window active for scrolling.
17264
17265 @item focus src
17266 Make the source window active for scrolling.
17267
17268 @item focus asm
17269 Make the assembly window active for scrolling.
17270
17271 @item focus regs
17272 Make the register window active for scrolling.
17273
17274 @item focus cmd
17275 Make the command window active for scrolling.
17276
17277 @item refresh
17278 @kindex refresh
17279 Refresh the screen. This is similar to typing @kbd{C-L}.
17280
17281 @item tui reg float
17282 @kindex tui reg
17283 Show the floating point registers in the register window.
17284
17285 @item tui reg general
17286 Show the general registers in the register window.
17287
17288 @item tui reg next
17289 Show the next register group. The list of register groups as well as
17290 their order is target specific. The predefined register groups are the
17291 following: @code{general}, @code{float}, @code{system}, @code{vector},
17292 @code{all}, @code{save}, @code{restore}.
17293
17294 @item tui reg system
17295 Show the system registers in the register window.
17296
17297 @item update
17298 @kindex update
17299 Update the source window and the current execution point.
17300
17301 @item winheight @var{name} +@var{count}
17302 @itemx winheight @var{name} -@var{count}
17303 @kindex winheight
17304 Change the height of the window @var{name} by @var{count}
17305 lines. Positive counts increase the height, while negative counts
17306 decrease it.
17307
17308 @item tabset @var{nchars}
17309 @kindex tabset
17310 Set the width of tab stops to be @var{nchars} characters.
17311 @end table
17312
17313 @node TUI Configuration
17314 @section TUI Configuration Variables
17315 @cindex TUI configuration variables
17316
17317 Several configuration variables control the appearance of TUI windows.
17318
17319 @table @code
17320 @item set tui border-kind @var{kind}
17321 @kindex set tui border-kind
17322 Select the border appearance for the source, assembly and register windows.
17323 The possible values are the following:
17324 @table @code
17325 @item space
17326 Use a space character to draw the border.
17327
17328 @item ascii
17329 Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
17330
17331 @item acs
17332 Use the Alternate Character Set to draw the border. The border is
17333 drawn using character line graphics if the terminal supports them.
17334 @end table
17335
17336 @item set tui border-mode @var{mode}
17337 @kindex set tui border-mode
17338 @itemx set tui active-border-mode @var{mode}
17339 @kindex set tui active-border-mode
17340 Select the display attributes for the borders of the inactive windows
17341 or the active window. The @var{mode} can be one of the following:
17342 @table @code
17343 @item normal
17344 Use normal attributes to display the border.
17345
17346 @item standout
17347 Use standout mode.
17348
17349 @item reverse
17350 Use reverse video mode.
17351
17352 @item half
17353 Use half bright mode.
17354
17355 @item half-standout
17356 Use half bright and standout mode.
17357
17358 @item bold
17359 Use extra bright or bold mode.
17360
17361 @item bold-standout
17362 Use extra bright or bold and standout mode.
17363 @end table
17364 @end table
17365
17366 @node Emacs
17367 @chapter Using @value{GDBN} under @sc{gnu} Emacs
17368
17369 @cindex Emacs
17370 @cindex @sc{gnu} Emacs
17371 A special interface allows you to use @sc{gnu} Emacs to view (and
17372 edit) the source files for the program you are debugging with
17373 @value{GDBN}.
17374
17375 To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
17376 executable file you want to debug as an argument. This command starts
17377 @value{GDBN} as a subprocess of Emacs, with input and output through a newly
17378 created Emacs buffer.
17379 @c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
17380
17381 Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
17382 things:
17383
17384 @itemize @bullet
17385 @item
17386 All ``terminal'' input and output goes through an Emacs buffer, called
17387 the GUD buffer.
17388
17389 This applies both to @value{GDBN} commands and their output, and to the input
17390 and output done by the program you are debugging.
17391
17392 This is useful because it means that you can copy the text of previous
17393 commands and input them again; you can even use parts of the output
17394 in this way.
17395
17396 All the facilities of Emacs' Shell mode are available for interacting
17397 with your program. In particular, you can send signals the usual
17398 way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
17399 stop.
17400
17401 @item
17402 @value{GDBN} displays source code through Emacs.
17403
17404 Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
17405 source file for that frame and puts an arrow (@samp{=>}) at the
17406 left margin of the current line. Emacs uses a separate buffer for
17407 source display, and splits the screen to show both your @value{GDBN} session
17408 and the source.
17409
17410 Explicit @value{GDBN} @code{list} or search commands still produce output as
17411 usual, but you probably have no reason to use them from Emacs.
17412 @end itemize
17413
17414 We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
17415 a graphical mode, enabled by default, which provides further buffers
17416 that can control the execution and describe the state of your program.
17417 @xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
17418
17419 If you specify an absolute file name when prompted for the @kbd{M-x
17420 gdb} argument, then Emacs sets your current working directory to where
17421 your program resides. If you only specify the file name, then Emacs
17422 sets your current working directory to to the directory associated
17423 with the previous buffer. In this case, @value{GDBN} may find your
17424 program by searching your environment's @code{PATH} variable, but on
17425 some operating systems it might not find the source. So, although the
17426 @value{GDBN} input and output session proceeds normally, the auxiliary
17427 buffer does not display the current source and line of execution.
17428
17429 The initial working directory of @value{GDBN} is printed on the top
17430 line of the GUD buffer and this serves as a default for the commands
17431 that specify files for @value{GDBN} to operate on. @xref{Files,
17432 ,Commands to Specify Files}.
17433
17434 By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
17435 need to call @value{GDBN} by a different name (for example, if you
17436 keep several configurations around, with different names) you can
17437 customize the Emacs variable @code{gud-gdb-command-name} to run the
17438 one you want.
17439
17440 In the GUD buffer, you can use these special Emacs commands in
17441 addition to the standard Shell mode commands:
17442
17443 @table @kbd
17444 @item C-h m
17445 Describe the features of Emacs' GUD Mode.
17446
17447 @item C-c C-s
17448 Execute to another source line, like the @value{GDBN} @code{step} command; also
17449 update the display window to show the current file and location.
17450
17451 @item C-c C-n
17452 Execute to next source line in this function, skipping all function
17453 calls, like the @value{GDBN} @code{next} command. Then update the display window
17454 to show the current file and location.
17455
17456 @item C-c C-i
17457 Execute one instruction, like the @value{GDBN} @code{stepi} command; update
17458 display window accordingly.
17459
17460 @item C-c C-f
17461 Execute until exit from the selected stack frame, like the @value{GDBN}
17462 @code{finish} command.
17463
17464 @item C-c C-r
17465 Continue execution of your program, like the @value{GDBN} @code{continue}
17466 command.
17467
17468 @item C-c <
17469 Go up the number of frames indicated by the numeric argument
17470 (@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
17471 like the @value{GDBN} @code{up} command.
17472
17473 @item C-c >
17474 Go down the number of frames indicated by the numeric argument, like the
17475 @value{GDBN} @code{down} command.
17476 @end table
17477
17478 In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
17479 tells @value{GDBN} to set a breakpoint on the source line point is on.
17480
17481 In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
17482 separate frame which shows a backtrace when the GUD buffer is current.
17483 Move point to any frame in the stack and type @key{RET} to make it
17484 become the current frame and display the associated source in the
17485 source buffer. Alternatively, click @kbd{Mouse-2} to make the
17486 selected frame become the current one. In graphical mode, the
17487 speedbar displays watch expressions.
17488
17489 If you accidentally delete the source-display buffer, an easy way to get
17490 it back is to type the command @code{f} in the @value{GDBN} buffer, to
17491 request a frame display; when you run under Emacs, this recreates
17492 the source buffer if necessary to show you the context of the current
17493 frame.
17494
17495 The source files displayed in Emacs are in ordinary Emacs buffers
17496 which are visiting the source files in the usual way. You can edit
17497 the files with these buffers if you wish; but keep in mind that @value{GDBN}
17498 communicates with Emacs in terms of line numbers. If you add or
17499 delete lines from the text, the line numbers that @value{GDBN} knows cease
17500 to correspond properly with the code.
17501
17502 A more detailed description of Emacs' interaction with @value{GDBN} is
17503 given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
17504 Emacs Manual}).
17505
17506 @c The following dropped because Epoch is nonstandard. Reactivate
17507 @c if/when v19 does something similar. ---doc@cygnus.com 19dec1990
17508 @ignore
17509 @kindex Emacs Epoch environment
17510 @kindex Epoch
17511 @kindex inspect
17512
17513 Version 18 of @sc{gnu} Emacs has a built-in window system
17514 called the @code{epoch}
17515 environment. Users of this environment can use a new command,
17516 @code{inspect} which performs identically to @code{print} except that
17517 each value is printed in its own window.
17518 @end ignore
17519
17520
17521 @node GDB/MI
17522 @chapter The @sc{gdb/mi} Interface
17523
17524 @unnumberedsec Function and Purpose
17525
17526 @cindex @sc{gdb/mi}, its purpose
17527 @sc{gdb/mi} is a line based machine oriented text interface to
17528 @value{GDBN} and is activated by specifying using the
17529 @option{--interpreter} command line option (@pxref{Mode Options}). It
17530 is specifically intended to support the development of systems which
17531 use the debugger as just one small component of a larger system.
17532
17533 This chapter is a specification of the @sc{gdb/mi} interface. It is written
17534 in the form of a reference manual.
17535
17536 Note that @sc{gdb/mi} is still under construction, so some of the
17537 features described below are incomplete and subject to change
17538 (@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
17539
17540 @unnumberedsec Notation and Terminology
17541
17542 @cindex notational conventions, for @sc{gdb/mi}
17543 This chapter uses the following notation:
17544
17545 @itemize @bullet
17546 @item
17547 @code{|} separates two alternatives.
17548
17549 @item
17550 @code{[ @var{something} ]} indicates that @var{something} is optional:
17551 it may or may not be given.
17552
17553 @item
17554 @code{( @var{group} )*} means that @var{group} inside the parentheses
17555 may repeat zero or more times.
17556
17557 @item
17558 @code{( @var{group} )+} means that @var{group} inside the parentheses
17559 may repeat one or more times.
17560
17561 @item
17562 @code{"@var{string}"} means a literal @var{string}.
17563 @end itemize
17564
17565 @ignore
17566 @heading Dependencies
17567 @end ignore
17568
17569 @menu
17570 * GDB/MI Command Syntax::
17571 * GDB/MI Compatibility with CLI::
17572 * GDB/MI Development and Front Ends::
17573 * GDB/MI Output Records::
17574 * GDB/MI Simple Examples::
17575 * GDB/MI Command Description Format::
17576 * GDB/MI Breakpoint Commands::
17577 * GDB/MI Program Context::
17578 * GDB/MI Thread Commands::
17579 * GDB/MI Program Execution::
17580 * GDB/MI Stack Manipulation::
17581 * GDB/MI Variable Objects::
17582 * GDB/MI Data Manipulation::
17583 * GDB/MI Tracepoint Commands::
17584 * GDB/MI Symbol Query::
17585 * GDB/MI File Commands::
17586 @ignore
17587 * GDB/MI Kod Commands::
17588 * GDB/MI Memory Overlay Commands::
17589 * GDB/MI Signal Handling Commands::
17590 @end ignore
17591 * GDB/MI Target Manipulation::
17592 * GDB/MI File Transfer Commands::
17593 * GDB/MI Miscellaneous Commands::
17594 @end menu
17595
17596 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17597 @node GDB/MI Command Syntax
17598 @section @sc{gdb/mi} Command Syntax
17599
17600 @menu
17601 * GDB/MI Input Syntax::
17602 * GDB/MI Output Syntax::
17603 @end menu
17604
17605 @node GDB/MI Input Syntax
17606 @subsection @sc{gdb/mi} Input Syntax
17607
17608 @cindex input syntax for @sc{gdb/mi}
17609 @cindex @sc{gdb/mi}, input syntax
17610 @table @code
17611 @item @var{command} @expansion{}
17612 @code{@var{cli-command} | @var{mi-command}}
17613
17614 @item @var{cli-command} @expansion{}
17615 @code{[ @var{token} ] @var{cli-command} @var{nl}}, where
17616 @var{cli-command} is any existing @value{GDBN} CLI command.
17617
17618 @item @var{mi-command} @expansion{}
17619 @code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
17620 @code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
17621
17622 @item @var{token} @expansion{}
17623 "any sequence of digits"
17624
17625 @item @var{option} @expansion{}
17626 @code{"-" @var{parameter} [ " " @var{parameter} ]}
17627
17628 @item @var{parameter} @expansion{}
17629 @code{@var{non-blank-sequence} | @var{c-string}}
17630
17631 @item @var{operation} @expansion{}
17632 @emph{any of the operations described in this chapter}
17633
17634 @item @var{non-blank-sequence} @expansion{}
17635 @emph{anything, provided it doesn't contain special characters such as
17636 "-", @var{nl}, """ and of course " "}
17637
17638 @item @var{c-string} @expansion{}
17639 @code{""" @var{seven-bit-iso-c-string-content} """}
17640
17641 @item @var{nl} @expansion{}
17642 @code{CR | CR-LF}
17643 @end table
17644
17645 @noindent
17646 Notes:
17647
17648 @itemize @bullet
17649 @item
17650 The CLI commands are still handled by the @sc{mi} interpreter; their
17651 output is described below.
17652
17653 @item
17654 The @code{@var{token}}, when present, is passed back when the command
17655 finishes.
17656
17657 @item
17658 Some @sc{mi} commands accept optional arguments as part of the parameter
17659 list. Each option is identified by a leading @samp{-} (dash) and may be
17660 followed by an optional argument parameter. Options occur first in the
17661 parameter list and can be delimited from normal parameters using
17662 @samp{--} (this is useful when some parameters begin with a dash).
17663 @end itemize
17664
17665 Pragmatics:
17666
17667 @itemize @bullet
17668 @item
17669 We want easy access to the existing CLI syntax (for debugging).
17670
17671 @item
17672 We want it to be easy to spot a @sc{mi} operation.
17673 @end itemize
17674
17675 @node GDB/MI Output Syntax
17676 @subsection @sc{gdb/mi} Output Syntax
17677
17678 @cindex output syntax of @sc{gdb/mi}
17679 @cindex @sc{gdb/mi}, output syntax
17680 The output from @sc{gdb/mi} consists of zero or more out-of-band records
17681 followed, optionally, by a single result record. This result record
17682 is for the most recent command. The sequence of output records is
17683 terminated by @samp{(gdb)}.
17684
17685 If an input command was prefixed with a @code{@var{token}} then the
17686 corresponding output for that command will also be prefixed by that same
17687 @var{token}.
17688
17689 @table @code
17690 @item @var{output} @expansion{}
17691 @code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
17692
17693 @item @var{result-record} @expansion{}
17694 @code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
17695
17696 @item @var{out-of-band-record} @expansion{}
17697 @code{@var{async-record} | @var{stream-record}}
17698
17699 @item @var{async-record} @expansion{}
17700 @code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
17701
17702 @item @var{exec-async-output} @expansion{}
17703 @code{[ @var{token} ] "*" @var{async-output}}
17704
17705 @item @var{status-async-output} @expansion{}
17706 @code{[ @var{token} ] "+" @var{async-output}}
17707
17708 @item @var{notify-async-output} @expansion{}
17709 @code{[ @var{token} ] "=" @var{async-output}}
17710
17711 @item @var{async-output} @expansion{}
17712 @code{@var{async-class} ( "," @var{result} )* @var{nl}}
17713
17714 @item @var{result-class} @expansion{}
17715 @code{"done" | "running" | "connected" | "error" | "exit"}
17716
17717 @item @var{async-class} @expansion{}
17718 @code{"stopped" | @var{others}} (where @var{others} will be added
17719 depending on the needs---this is still in development).
17720
17721 @item @var{result} @expansion{}
17722 @code{ @var{variable} "=" @var{value}}
17723
17724 @item @var{variable} @expansion{}
17725 @code{ @var{string} }
17726
17727 @item @var{value} @expansion{}
17728 @code{ @var{const} | @var{tuple} | @var{list} }
17729
17730 @item @var{const} @expansion{}
17731 @code{@var{c-string}}
17732
17733 @item @var{tuple} @expansion{}
17734 @code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
17735
17736 @item @var{list} @expansion{}
17737 @code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
17738 @var{result} ( "," @var{result} )* "]" }
17739
17740 @item @var{stream-record} @expansion{}
17741 @code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
17742
17743 @item @var{console-stream-output} @expansion{}
17744 @code{"~" @var{c-string}}
17745
17746 @item @var{target-stream-output} @expansion{}
17747 @code{"@@" @var{c-string}}
17748
17749 @item @var{log-stream-output} @expansion{}
17750 @code{"&" @var{c-string}}
17751
17752 @item @var{nl} @expansion{}
17753 @code{CR | CR-LF}
17754
17755 @item @var{token} @expansion{}
17756 @emph{any sequence of digits}.
17757 @end table
17758
17759 @noindent
17760 Notes:
17761
17762 @itemize @bullet
17763 @item
17764 All output sequences end in a single line containing a period.
17765
17766 @item
17767 The @code{@var{token}} is from the corresponding request. If an execution
17768 command is interrupted by the @samp{-exec-interrupt} command, the
17769 @var{token} associated with the @samp{*stopped} message is the one of the
17770 original execution command, not the one of the interrupt command.
17771
17772 @item
17773 @cindex status output in @sc{gdb/mi}
17774 @var{status-async-output} contains on-going status information about the
17775 progress of a slow operation. It can be discarded. All status output is
17776 prefixed by @samp{+}.
17777
17778 @item
17779 @cindex async output in @sc{gdb/mi}
17780 @var{exec-async-output} contains asynchronous state change on the target
17781 (stopped, started, disappeared). All async output is prefixed by
17782 @samp{*}.
17783
17784 @item
17785 @cindex notify output in @sc{gdb/mi}
17786 @var{notify-async-output} contains supplementary information that the
17787 client should handle (e.g., a new breakpoint information). All notify
17788 output is prefixed by @samp{=}.
17789
17790 @item
17791 @cindex console output in @sc{gdb/mi}
17792 @var{console-stream-output} is output that should be displayed as is in the
17793 console. It is the textual response to a CLI command. All the console
17794 output is prefixed by @samp{~}.
17795
17796 @item
17797 @cindex target output in @sc{gdb/mi}
17798 @var{target-stream-output} is the output produced by the target program.
17799 All the target output is prefixed by @samp{@@}.
17800
17801 @item
17802 @cindex log output in @sc{gdb/mi}
17803 @var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
17804 instance messages that should be displayed as part of an error log. All
17805 the log output is prefixed by @samp{&}.
17806
17807 @item
17808 @cindex list output in @sc{gdb/mi}
17809 New @sc{gdb/mi} commands should only output @var{lists} containing
17810 @var{values}.
17811
17812
17813 @end itemize
17814
17815 @xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
17816 details about the various output records.
17817
17818 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17819 @node GDB/MI Compatibility with CLI
17820 @section @sc{gdb/mi} Compatibility with CLI
17821
17822 @cindex compatibility, @sc{gdb/mi} and CLI
17823 @cindex @sc{gdb/mi}, compatibility with CLI
17824
17825 For the developers convenience CLI commands can be entered directly,
17826 but there may be some unexpected behaviour. For example, commands
17827 that query the user will behave as if the user replied yes, breakpoint
17828 command lists are not executed and some CLI commands, such as
17829 @code{if}, @code{when} and @code{define}, prompt for further input with
17830 @samp{>}, which is not valid MI output.
17831
17832 This feature may be removed at some stage in the future and it is
17833 recommended that front ends use the @code{-interpreter-exec} command
17834 (@pxref{-interpreter-exec}).
17835
17836 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17837 @node GDB/MI Development and Front Ends
17838 @section @sc{gdb/mi} Development and Front Ends
17839 @cindex @sc{gdb/mi} development
17840
17841 The application which takes the MI output and presents the state of the
17842 program being debugged to the user is called a @dfn{front end}.
17843
17844 Although @sc{gdb/mi} is still incomplete, it is currently being used
17845 by a variety of front ends to @value{GDBN}. This makes it difficult
17846 to introduce new functionality without breaking existing usage. This
17847 section tries to minimize the problems by describing how the protocol
17848 might change.
17849
17850 Some changes in MI need not break a carefully designed front end, and
17851 for these the MI version will remain unchanged. The following is a
17852 list of changes that may occur within one level, so front ends should
17853 parse MI output in a way that can handle them:
17854
17855 @itemize @bullet
17856 @item
17857 New MI commands may be added.
17858
17859 @item
17860 New fields may be added to the output of any MI command.
17861
17862 @item
17863 The range of values for fields with specified values, e.g.,
17864 @code{in_scope} (@pxref{-var-update}) may be extended.
17865
17866 @c The format of field's content e.g type prefix, may change so parse it
17867 @c at your own risk. Yes, in general?
17868
17869 @c The order of fields may change? Shouldn't really matter but it might
17870 @c resolve inconsistencies.
17871 @end itemize
17872
17873 If the changes are likely to break front ends, the MI version level
17874 will be increased by one. This will allow the front end to parse the
17875 output according to the MI version. Apart from mi0, new versions of
17876 @value{GDBN} will not support old versions of MI and it will be the
17877 responsibility of the front end to work with the new one.
17878
17879 @c Starting with mi3, add a new command -mi-version that prints the MI
17880 @c version?
17881
17882 The best way to avoid unexpected changes in MI that might break your front
17883 end is to make your project known to @value{GDBN} developers and
17884 follow development on @email{gdb@@sourceware.org} and
17885 @email{gdb-patches@@sourceware.org}. There is also the mailing list
17886 @email{dmi-discuss@@lists.freestandards.org}, hosted by the Free Standards
17887 Group, which has the aim of creating a more general MI protocol
17888 called Debugger Machine Interface (DMI) that will become a standard
17889 for all debuggers, not just @value{GDBN}.
17890 @cindex mailing lists
17891
17892 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17893 @node GDB/MI Output Records
17894 @section @sc{gdb/mi} Output Records
17895
17896 @menu
17897 * GDB/MI Result Records::
17898 * GDB/MI Stream Records::
17899 * GDB/MI Out-of-band Records::
17900 @end menu
17901
17902 @node GDB/MI Result Records
17903 @subsection @sc{gdb/mi} Result Records
17904
17905 @cindex result records in @sc{gdb/mi}
17906 @cindex @sc{gdb/mi}, result records
17907 In addition to a number of out-of-band notifications, the response to a
17908 @sc{gdb/mi} command includes one of the following result indications:
17909
17910 @table @code
17911 @findex ^done
17912 @item "^done" [ "," @var{results} ]
17913 The synchronous operation was successful, @code{@var{results}} are the return
17914 values.
17915
17916 @item "^running"
17917 @findex ^running
17918 @c Is this one correct? Should it be an out-of-band notification?
17919 The asynchronous operation was successfully started. The target is
17920 running.
17921
17922 @item "^connected"
17923 @findex ^connected
17924 @value{GDBN} has connected to a remote target.
17925
17926 @item "^error" "," @var{c-string}
17927 @findex ^error
17928 The operation failed. The @code{@var{c-string}} contains the corresponding
17929 error message.
17930
17931 @item "^exit"
17932 @findex ^exit
17933 @value{GDBN} has terminated.
17934
17935 @end table
17936
17937 @node GDB/MI Stream Records
17938 @subsection @sc{gdb/mi} Stream Records
17939
17940 @cindex @sc{gdb/mi}, stream records
17941 @cindex stream records in @sc{gdb/mi}
17942 @value{GDBN} internally maintains a number of output streams: the console, the
17943 target, and the log. The output intended for each of these streams is
17944 funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
17945
17946 Each stream record begins with a unique @dfn{prefix character} which
17947 identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
17948 Syntax}). In addition to the prefix, each stream record contains a
17949 @code{@var{string-output}}. This is either raw text (with an implicit new
17950 line) or a quoted C string (which does not contain an implicit newline).
17951
17952 @table @code
17953 @item "~" @var{string-output}
17954 The console output stream contains text that should be displayed in the
17955 CLI console window. It contains the textual responses to CLI commands.
17956
17957 @item "@@" @var{string-output}
17958 The target output stream contains any textual output from the running
17959 target. This is only present when GDB's event loop is truly
17960 asynchronous, which is currently only the case for remote targets.
17961
17962 @item "&" @var{string-output}
17963 The log stream contains debugging messages being produced by @value{GDBN}'s
17964 internals.
17965 @end table
17966
17967 @node GDB/MI Out-of-band Records
17968 @subsection @sc{gdb/mi} Out-of-band Records
17969
17970 @cindex out-of-band records in @sc{gdb/mi}
17971 @cindex @sc{gdb/mi}, out-of-band records
17972 @dfn{Out-of-band} records are used to notify the @sc{gdb/mi} client of
17973 additional changes that have occurred. Those changes can either be a
17974 consequence of @sc{gdb/mi} (e.g., a breakpoint modified) or a result of
17975 target activity (e.g., target stopped).
17976
17977 The following is a preliminary list of possible out-of-band records.
17978 In particular, the @var{exec-async-output} records.
17979
17980 @table @code
17981 @item *stopped,reason="@var{reason}"
17982 @end table
17983
17984 @var{reason} can be one of the following:
17985
17986 @table @code
17987 @item breakpoint-hit
17988 A breakpoint was reached.
17989 @item watchpoint-trigger
17990 A watchpoint was triggered.
17991 @item read-watchpoint-trigger
17992 A read watchpoint was triggered.
17993 @item access-watchpoint-trigger
17994 An access watchpoint was triggered.
17995 @item function-finished
17996 An -exec-finish or similar CLI command was accomplished.
17997 @item location-reached
17998 An -exec-until or similar CLI command was accomplished.
17999 @item watchpoint-scope
18000 A watchpoint has gone out of scope.
18001 @item end-stepping-range
18002 An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
18003 similar CLI command was accomplished.
18004 @item exited-signalled
18005 The inferior exited because of a signal.
18006 @item exited
18007 The inferior exited.
18008 @item exited-normally
18009 The inferior exited normally.
18010 @item signal-received
18011 A signal was received by the inferior.
18012 @end table
18013
18014
18015 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18016 @node GDB/MI Simple Examples
18017 @section Simple Examples of @sc{gdb/mi} Interaction
18018 @cindex @sc{gdb/mi}, simple examples
18019
18020 This subsection presents several simple examples of interaction using
18021 the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
18022 following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
18023 the output received from @sc{gdb/mi}.
18024
18025 Note the line breaks shown in the examples are here only for
18026 readability, they don't appear in the real output.
18027
18028 @subheading Setting a Breakpoint
18029
18030 Setting a breakpoint generates synchronous output which contains detailed
18031 information of the breakpoint.
18032
18033 @smallexample
18034 -> -break-insert main
18035 <- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
18036 enabled="y",addr="0x08048564",func="main",file="myprog.c",
18037 fullname="/home/nickrob/myprog.c",line="68",times="0"@}
18038 <- (gdb)
18039 @end smallexample
18040
18041 @subheading Program Execution
18042
18043 Program execution generates asynchronous records and MI gives the
18044 reason that execution stopped.
18045
18046 @smallexample
18047 -> -exec-run
18048 <- ^running
18049 <- (gdb)
18050 <- *stopped,reason="breakpoint-hit",bkptno="1",thread-id="0",
18051 frame=@{addr="0x08048564",func="main",
18052 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
18053 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68"@}
18054 <- (gdb)
18055 -> -exec-continue
18056 <- ^running
18057 <- (gdb)
18058 <- *stopped,reason="exited-normally"
18059 <- (gdb)
18060 @end smallexample
18061
18062 @subheading Quitting @value{GDBN}
18063
18064 Quitting @value{GDBN} just prints the result class @samp{^exit}.
18065
18066 @smallexample
18067 -> (gdb)
18068 <- -gdb-exit
18069 <- ^exit
18070 @end smallexample
18071
18072 @subheading A Bad Command
18073
18074 Here's what happens if you pass a non-existent command:
18075
18076 @smallexample
18077 -> -rubbish
18078 <- ^error,msg="Undefined MI command: rubbish"
18079 <- (gdb)
18080 @end smallexample
18081
18082
18083 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18084 @node GDB/MI Command Description Format
18085 @section @sc{gdb/mi} Command Description Format
18086
18087 The remaining sections describe blocks of commands. Each block of
18088 commands is laid out in a fashion similar to this section.
18089
18090 @subheading Motivation
18091
18092 The motivation for this collection of commands.
18093
18094 @subheading Introduction
18095
18096 A brief introduction to this collection of commands as a whole.
18097
18098 @subheading Commands
18099
18100 For each command in the block, the following is described:
18101
18102 @subsubheading Synopsis
18103
18104 @smallexample
18105 -command @var{args}@dots{}
18106 @end smallexample
18107
18108 @subsubheading Result
18109
18110 @subsubheading @value{GDBN} Command
18111
18112 The corresponding @value{GDBN} CLI command(s), if any.
18113
18114 @subsubheading Example
18115
18116 Example(s) formatted for readability. Some of the described commands have
18117 not been implemented yet and these are labeled N.A.@: (not available).
18118
18119
18120 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18121 @node GDB/MI Breakpoint Commands
18122 @section @sc{gdb/mi} Breakpoint Commands
18123
18124 @cindex breakpoint commands for @sc{gdb/mi}
18125 @cindex @sc{gdb/mi}, breakpoint commands
18126 This section documents @sc{gdb/mi} commands for manipulating
18127 breakpoints.
18128
18129 @subheading The @code{-break-after} Command
18130 @findex -break-after
18131
18132 @subsubheading Synopsis
18133
18134 @smallexample
18135 -break-after @var{number} @var{count}
18136 @end smallexample
18137
18138 The breakpoint number @var{number} is not in effect until it has been
18139 hit @var{count} times. To see how this is reflected in the output of
18140 the @samp{-break-list} command, see the description of the
18141 @samp{-break-list} command below.
18142
18143 @subsubheading @value{GDBN} Command
18144
18145 The corresponding @value{GDBN} command is @samp{ignore}.
18146
18147 @subsubheading Example
18148
18149 @smallexample
18150 (gdb)
18151 -break-insert main
18152 ^done,bkpt=@{number="1",addr="0x000100d0",file="hello.c",
18153 fullname="/home/foo/hello.c",line="5",times="0"@}
18154 (gdb)
18155 -break-after 1 3
18156 ~
18157 ^done
18158 (gdb)
18159 -break-list
18160 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18161 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18162 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18163 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18164 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18165 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18166 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
18167 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18168 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
18169 line="5",times="0",ignore="3"@}]@}
18170 (gdb)
18171 @end smallexample
18172
18173 @ignore
18174 @subheading The @code{-break-catch} Command
18175 @findex -break-catch
18176
18177 @subheading The @code{-break-commands} Command
18178 @findex -break-commands
18179 @end ignore
18180
18181
18182 @subheading The @code{-break-condition} Command
18183 @findex -break-condition
18184
18185 @subsubheading Synopsis
18186
18187 @smallexample
18188 -break-condition @var{number} @var{expr}
18189 @end smallexample
18190
18191 Breakpoint @var{number} will stop the program only if the condition in
18192 @var{expr} is true. The condition becomes part of the
18193 @samp{-break-list} output (see the description of the @samp{-break-list}
18194 command below).
18195
18196 @subsubheading @value{GDBN} Command
18197
18198 The corresponding @value{GDBN} command is @samp{condition}.
18199
18200 @subsubheading Example
18201
18202 @smallexample
18203 (gdb)
18204 -break-condition 1 1
18205 ^done
18206 (gdb)
18207 -break-list
18208 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18209 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18210 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18211 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18212 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18213 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18214 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
18215 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18216 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
18217 line="5",cond="1",times="0",ignore="3"@}]@}
18218 (gdb)
18219 @end smallexample
18220
18221 @subheading The @code{-break-delete} Command
18222 @findex -break-delete
18223
18224 @subsubheading Synopsis
18225
18226 @smallexample
18227 -break-delete ( @var{breakpoint} )+
18228 @end smallexample
18229
18230 Delete the breakpoint(s) whose number(s) are specified in the argument
18231 list. This is obviously reflected in the breakpoint list.
18232
18233 @subsubheading @value{GDBN} Command
18234
18235 The corresponding @value{GDBN} command is @samp{delete}.
18236
18237 @subsubheading Example
18238
18239 @smallexample
18240 (gdb)
18241 -break-delete 1
18242 ^done
18243 (gdb)
18244 -break-list
18245 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
18246 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18247 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18248 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18249 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18250 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18251 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
18252 body=[]@}
18253 (gdb)
18254 @end smallexample
18255
18256 @subheading The @code{-break-disable} Command
18257 @findex -break-disable
18258
18259 @subsubheading Synopsis
18260
18261 @smallexample
18262 -break-disable ( @var{breakpoint} )+
18263 @end smallexample
18264
18265 Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
18266 break list is now set to @samp{n} for the named @var{breakpoint}(s).
18267
18268 @subsubheading @value{GDBN} Command
18269
18270 The corresponding @value{GDBN} command is @samp{disable}.
18271
18272 @subsubheading Example
18273
18274 @smallexample
18275 (gdb)
18276 -break-disable 2
18277 ^done
18278 (gdb)
18279 -break-list
18280 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18281 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18282 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18283 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18284 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18285 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18286 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
18287 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
18288 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
18289 line="5",times="0"@}]@}
18290 (gdb)
18291 @end smallexample
18292
18293 @subheading The @code{-break-enable} Command
18294 @findex -break-enable
18295
18296 @subsubheading Synopsis
18297
18298 @smallexample
18299 -break-enable ( @var{breakpoint} )+
18300 @end smallexample
18301
18302 Enable (previously disabled) @var{breakpoint}(s).
18303
18304 @subsubheading @value{GDBN} Command
18305
18306 The corresponding @value{GDBN} command is @samp{enable}.
18307
18308 @subsubheading Example
18309
18310 @smallexample
18311 (gdb)
18312 -break-enable 2
18313 ^done
18314 (gdb)
18315 -break-list
18316 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18317 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18318 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18319 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18320 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18321 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18322 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
18323 body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
18324 addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
18325 line="5",times="0"@}]@}
18326 (gdb)
18327 @end smallexample
18328
18329 @subheading The @code{-break-info} Command
18330 @findex -break-info
18331
18332 @subsubheading Synopsis
18333
18334 @smallexample
18335 -break-info @var{breakpoint}
18336 @end smallexample
18337
18338 @c REDUNDANT???
18339 Get information about a single breakpoint.
18340
18341 @subsubheading @value{GDBN} Command
18342
18343 The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
18344
18345 @subsubheading Example
18346 N.A.
18347
18348 @subheading The @code{-break-insert} Command
18349 @findex -break-insert
18350
18351 @subsubheading Synopsis
18352
18353 @smallexample
18354 -break-insert [ -t ] [ -h ] [ -f ]
18355 [ -c @var{condition} ] [ -i @var{ignore-count} ]
18356 [ -p @var{thread} ] [ @var{location} ]
18357 @end smallexample
18358
18359 @noindent
18360 If specified, @var{location}, can be one of:
18361
18362 @itemize @bullet
18363 @item function
18364 @c @item +offset
18365 @c @item -offset
18366 @c @item linenum
18367 @item filename:linenum
18368 @item filename:function
18369 @item *address
18370 @end itemize
18371
18372 The possible optional parameters of this command are:
18373
18374 @table @samp
18375 @item -t
18376 Insert a temporary breakpoint.
18377 @item -h
18378 Insert a hardware breakpoint.
18379 @item -c @var{condition}
18380 Make the breakpoint conditional on @var{condition}.
18381 @item -i @var{ignore-count}
18382 Initialize the @var{ignore-count}.
18383 @item -f
18384 If @var{location} cannot be parsed (for example if it
18385 refers to unknown files or functions), create a pending
18386 breakpoint. Without this flag, @value{GDBN} will report
18387 an error, and won't create a breakpoint, if @var{location}
18388 cannot be parsed.
18389 @end table
18390
18391 @subsubheading Result
18392
18393 The result is in the form:
18394
18395 @smallexample
18396 ^done,bkpt=@{number="@var{number}",type="@var{type}",disp="del"|"keep",
18397 enabled="y"|"n",addr="@var{hex}",func="@var{funcname}",file="@var{filename}",
18398 fullname="@var{full_filename}",line="@var{lineno}",[thread="@var{threadno},]
18399 times="@var{times}"@}
18400 @end smallexample
18401
18402 @noindent
18403 where @var{number} is the @value{GDBN} number for this breakpoint,
18404 @var{funcname} is the name of the function where the breakpoint was
18405 inserted, @var{filename} is the name of the source file which contains
18406 this function, @var{lineno} is the source line number within that file
18407 and @var{times} the number of times that the breakpoint has been hit
18408 (always 0 for -break-insert but may be greater for -break-info or -break-list
18409 which use the same output).
18410
18411 Note: this format is open to change.
18412 @c An out-of-band breakpoint instead of part of the result?
18413
18414 @subsubheading @value{GDBN} Command
18415
18416 The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
18417 @samp{hbreak}, @samp{thbreak}, and @samp{rbreak}.
18418
18419 @subsubheading Example
18420
18421 @smallexample
18422 (gdb)
18423 -break-insert main
18424 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
18425 fullname="/home/foo/recursive2.c,line="4",times="0"@}
18426 (gdb)
18427 -break-insert -t foo
18428 ^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
18429 fullname="/home/foo/recursive2.c,line="11",times="0"@}
18430 (gdb)
18431 -break-list
18432 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18433 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18434 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18435 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18436 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18437 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18438 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
18439 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18440 addr="0x0001072c", func="main",file="recursive2.c",
18441 fullname="/home/foo/recursive2.c,"line="4",times="0"@},
18442 bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
18443 addr="0x00010774",func="foo",file="recursive2.c",
18444 fullname="/home/foo/recursive2.c",line="11",times="0"@}]@}
18445 (gdb)
18446 -break-insert -r foo.*
18447 ~int foo(int, int);
18448 ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
18449 "fullname="/home/foo/recursive2.c",line="11",times="0"@}
18450 (gdb)
18451 @end smallexample
18452
18453 @subheading The @code{-break-list} Command
18454 @findex -break-list
18455
18456 @subsubheading Synopsis
18457
18458 @smallexample
18459 -break-list
18460 @end smallexample
18461
18462 Displays the list of inserted breakpoints, showing the following fields:
18463
18464 @table @samp
18465 @item Number
18466 number of the breakpoint
18467 @item Type
18468 type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
18469 @item Disposition
18470 should the breakpoint be deleted or disabled when it is hit: @samp{keep}
18471 or @samp{nokeep}
18472 @item Enabled
18473 is the breakpoint enabled or no: @samp{y} or @samp{n}
18474 @item Address
18475 memory location at which the breakpoint is set
18476 @item What
18477 logical location of the breakpoint, expressed by function name, file
18478 name, line number
18479 @item Times
18480 number of times the breakpoint has been hit
18481 @end table
18482
18483 If there are no breakpoints or watchpoints, the @code{BreakpointTable}
18484 @code{body} field is an empty list.
18485
18486 @subsubheading @value{GDBN} Command
18487
18488 The corresponding @value{GDBN} command is @samp{info break}.
18489
18490 @subsubheading Example
18491
18492 @smallexample
18493 (gdb)
18494 -break-list
18495 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18496 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18497 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18498 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18499 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18500 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18501 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
18502 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18503 addr="0x000100d0",func="main",file="hello.c",line="5",times="0"@},
18504 bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
18505 addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
18506 line="13",times="0"@}]@}
18507 (gdb)
18508 @end smallexample
18509
18510 Here's an example of the result when there are no breakpoints:
18511
18512 @smallexample
18513 (gdb)
18514 -break-list
18515 ^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
18516 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18517 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18518 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18519 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18520 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18521 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
18522 body=[]@}
18523 (gdb)
18524 @end smallexample
18525
18526 @subheading The @code{-break-watch} Command
18527 @findex -break-watch
18528
18529 @subsubheading Synopsis
18530
18531 @smallexample
18532 -break-watch [ -a | -r ]
18533 @end smallexample
18534
18535 Create a watchpoint. With the @samp{-a} option it will create an
18536 @dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
18537 read from or on a write to the memory location. With the @samp{-r}
18538 option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
18539 trigger only when the memory location is accessed for reading. Without
18540 either of the options, the watchpoint created is a regular watchpoint,
18541 i.e., it will trigger when the memory location is accessed for writing.
18542 @xref{Set Watchpoints, , Setting Watchpoints}.
18543
18544 Note that @samp{-break-list} will report a single list of watchpoints and
18545 breakpoints inserted.
18546
18547 @subsubheading @value{GDBN} Command
18548
18549 The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
18550 @samp{rwatch}.
18551
18552 @subsubheading Example
18553
18554 Setting a watchpoint on a variable in the @code{main} function:
18555
18556 @smallexample
18557 (gdb)
18558 -break-watch x
18559 ^done,wpt=@{number="2",exp="x"@}
18560 (gdb)
18561 -exec-continue
18562 ^running
18563 (gdb)
18564 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
18565 value=@{old="-268439212",new="55"@},
18566 frame=@{func="main",args=[],file="recursive2.c",
18567 fullname="/home/foo/bar/recursive2.c",line="5"@}
18568 (gdb)
18569 @end smallexample
18570
18571 Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
18572 the program execution twice: first for the variable changing value, then
18573 for the watchpoint going out of scope.
18574
18575 @smallexample
18576 (gdb)
18577 -break-watch C
18578 ^done,wpt=@{number="5",exp="C"@}
18579 (gdb)
18580 -exec-continue
18581 ^running
18582 (gdb)
18583 *stopped,reason="watchpoint-trigger",
18584 wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
18585 frame=@{func="callee4",args=[],
18586 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18587 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
18588 (gdb)
18589 -exec-continue
18590 ^running
18591 (gdb)
18592 *stopped,reason="watchpoint-scope",wpnum="5",
18593 frame=@{func="callee3",args=[@{name="strarg",
18594 value="0x11940 \"A string argument.\""@}],
18595 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18596 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
18597 (gdb)
18598 @end smallexample
18599
18600 Listing breakpoints and watchpoints, at different points in the program
18601 execution. Note that once the watchpoint goes out of scope, it is
18602 deleted.
18603
18604 @smallexample
18605 (gdb)
18606 -break-watch C
18607 ^done,wpt=@{number="2",exp="C"@}
18608 (gdb)
18609 -break-list
18610 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18611 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18612 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18613 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18614 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18615 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18616 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
18617 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18618 addr="0x00010734",func="callee4",
18619 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18620 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",times="1"@},
18621 bkpt=@{number="2",type="watchpoint",disp="keep",
18622 enabled="y",addr="",what="C",times="0"@}]@}
18623 (gdb)
18624 -exec-continue
18625 ^running
18626 (gdb)
18627 *stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
18628 value=@{old="-276895068",new="3"@},
18629 frame=@{func="callee4",args=[],
18630 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18631 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13"@}
18632 (gdb)
18633 -break-list
18634 ^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
18635 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18636 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18637 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18638 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18639 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18640 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
18641 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18642 addr="0x00010734",func="callee4",
18643 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18644 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",times="1"@},
18645 bkpt=@{number="2",type="watchpoint",disp="keep",
18646 enabled="y",addr="",what="C",times="-5"@}]@}
18647 (gdb)
18648 -exec-continue
18649 ^running
18650 ^done,reason="watchpoint-scope",wpnum="2",
18651 frame=@{func="callee3",args=[@{name="strarg",
18652 value="0x11940 \"A string argument.\""@}],
18653 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18654 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
18655 (gdb)
18656 -break-list
18657 ^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
18658 hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
18659 @{width="14",alignment="-1",col_name="type",colhdr="Type"@},
18660 @{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
18661 @{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
18662 @{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
18663 @{width="40",alignment="2",col_name="what",colhdr="What"@}],
18664 body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
18665 addr="0x00010734",func="callee4",
18666 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
18667 fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
18668 times="1"@}]@}
18669 (gdb)
18670 @end smallexample
18671
18672 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18673 @node GDB/MI Program Context
18674 @section @sc{gdb/mi} Program Context
18675
18676 @subheading The @code{-exec-arguments} Command
18677 @findex -exec-arguments
18678
18679
18680 @subsubheading Synopsis
18681
18682 @smallexample
18683 -exec-arguments @var{args}
18684 @end smallexample
18685
18686 Set the inferior program arguments, to be used in the next
18687 @samp{-exec-run}.
18688
18689 @subsubheading @value{GDBN} Command
18690
18691 The corresponding @value{GDBN} command is @samp{set args}.
18692
18693 @subsubheading Example
18694
18695 @c FIXME!
18696 Don't have one around.
18697
18698
18699 @subheading The @code{-exec-show-arguments} Command
18700 @findex -exec-show-arguments
18701
18702 @subsubheading Synopsis
18703
18704 @smallexample
18705 -exec-show-arguments
18706 @end smallexample
18707
18708 Print the arguments of the program.
18709
18710 @subsubheading @value{GDBN} Command
18711
18712 The corresponding @value{GDBN} command is @samp{show args}.
18713
18714 @subsubheading Example
18715 N.A.
18716
18717
18718 @subheading The @code{-environment-cd} Command
18719 @findex -environment-cd
18720
18721 @subsubheading Synopsis
18722
18723 @smallexample
18724 -environment-cd @var{pathdir}
18725 @end smallexample
18726
18727 Set @value{GDBN}'s working directory.
18728
18729 @subsubheading @value{GDBN} Command
18730
18731 The corresponding @value{GDBN} command is @samp{cd}.
18732
18733 @subsubheading Example
18734
18735 @smallexample
18736 (gdb)
18737 -environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18738 ^done
18739 (gdb)
18740 @end smallexample
18741
18742
18743 @subheading The @code{-environment-directory} Command
18744 @findex -environment-directory
18745
18746 @subsubheading Synopsis
18747
18748 @smallexample
18749 -environment-directory [ -r ] [ @var{pathdir} ]+
18750 @end smallexample
18751
18752 Add directories @var{pathdir} to beginning of search path for source files.
18753 If the @samp{-r} option is used, the search path is reset to the default
18754 search path. If directories @var{pathdir} are supplied in addition to the
18755 @samp{-r} option, the search path is first reset and then addition
18756 occurs as normal.
18757 Multiple directories may be specified, separated by blanks. Specifying
18758 multiple directories in a single command
18759 results in the directories added to the beginning of the
18760 search path in the same order they were presented in the command.
18761 If blanks are needed as
18762 part of a directory name, double-quotes should be used around
18763 the name. In the command output, the path will show up separated
18764 by the system directory-separator character. The directory-separator
18765 character must not be used
18766 in any directory name.
18767 If no directories are specified, the current search path is displayed.
18768
18769 @subsubheading @value{GDBN} Command
18770
18771 The corresponding @value{GDBN} command is @samp{dir}.
18772
18773 @subsubheading Example
18774
18775 @smallexample
18776 (gdb)
18777 -environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
18778 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18779 (gdb)
18780 -environment-directory ""
18781 ^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
18782 (gdb)
18783 -environment-directory -r /home/jjohnstn/src/gdb /usr/src
18784 ^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
18785 (gdb)
18786 -environment-directory -r
18787 ^done,source-path="$cdir:$cwd"
18788 (gdb)
18789 @end smallexample
18790
18791
18792 @subheading The @code{-environment-path} Command
18793 @findex -environment-path
18794
18795 @subsubheading Synopsis
18796
18797 @smallexample
18798 -environment-path [ -r ] [ @var{pathdir} ]+
18799 @end smallexample
18800
18801 Add directories @var{pathdir} to beginning of search path for object files.
18802 If the @samp{-r} option is used, the search path is reset to the original
18803 search path that existed at gdb start-up. If directories @var{pathdir} are
18804 supplied in addition to the
18805 @samp{-r} option, the search path is first reset and then addition
18806 occurs as normal.
18807 Multiple directories may be specified, separated by blanks. Specifying
18808 multiple directories in a single command
18809 results in the directories added to the beginning of the
18810 search path in the same order they were presented in the command.
18811 If blanks are needed as
18812 part of a directory name, double-quotes should be used around
18813 the name. In the command output, the path will show up separated
18814 by the system directory-separator character. The directory-separator
18815 character must not be used
18816 in any directory name.
18817 If no directories are specified, the current path is displayed.
18818
18819
18820 @subsubheading @value{GDBN} Command
18821
18822 The corresponding @value{GDBN} command is @samp{path}.
18823
18824 @subsubheading Example
18825
18826 @smallexample
18827 (gdb)
18828 -environment-path
18829 ^done,path="/usr/bin"
18830 (gdb)
18831 -environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
18832 ^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
18833 (gdb)
18834 -environment-path -r /usr/local/bin
18835 ^done,path="/usr/local/bin:/usr/bin"
18836 (gdb)
18837 @end smallexample
18838
18839
18840 @subheading The @code{-environment-pwd} Command
18841 @findex -environment-pwd
18842
18843 @subsubheading Synopsis
18844
18845 @smallexample
18846 -environment-pwd
18847 @end smallexample
18848
18849 Show the current working directory.
18850
18851 @subsubheading @value{GDBN} Command
18852
18853 The corresponding @value{GDBN} command is @samp{pwd}.
18854
18855 @subsubheading Example
18856
18857 @smallexample
18858 (gdb)
18859 -environment-pwd
18860 ^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
18861 (gdb)
18862 @end smallexample
18863
18864 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18865 @node GDB/MI Thread Commands
18866 @section @sc{gdb/mi} Thread Commands
18867
18868
18869 @subheading The @code{-thread-info} Command
18870 @findex -thread-info
18871
18872 @subsubheading Synopsis
18873
18874 @smallexample
18875 -thread-info
18876 @end smallexample
18877
18878 @subsubheading @value{GDBN} Command
18879
18880 No equivalent.
18881
18882 @subsubheading Example
18883 N.A.
18884
18885
18886 @subheading The @code{-thread-list-all-threads} Command
18887 @findex -thread-list-all-threads
18888
18889 @subsubheading Synopsis
18890
18891 @smallexample
18892 -thread-list-all-threads
18893 @end smallexample
18894
18895 @subsubheading @value{GDBN} Command
18896
18897 The equivalent @value{GDBN} command is @samp{info threads}.
18898
18899 @subsubheading Example
18900 N.A.
18901
18902
18903 @subheading The @code{-thread-list-ids} Command
18904 @findex -thread-list-ids
18905
18906 @subsubheading Synopsis
18907
18908 @smallexample
18909 -thread-list-ids
18910 @end smallexample
18911
18912 Produces a list of the currently known @value{GDBN} thread ids. At the
18913 end of the list it also prints the total number of such threads.
18914
18915 @subsubheading @value{GDBN} Command
18916
18917 Part of @samp{info threads} supplies the same information.
18918
18919 @subsubheading Example
18920
18921 No threads present, besides the main process:
18922
18923 @smallexample
18924 (gdb)
18925 -thread-list-ids
18926 ^done,thread-ids=@{@},number-of-threads="0"
18927 (gdb)
18928 @end smallexample
18929
18930
18931 Several threads:
18932
18933 @smallexample
18934 (gdb)
18935 -thread-list-ids
18936 ^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18937 number-of-threads="3"
18938 (gdb)
18939 @end smallexample
18940
18941
18942 @subheading The @code{-thread-select} Command
18943 @findex -thread-select
18944
18945 @subsubheading Synopsis
18946
18947 @smallexample
18948 -thread-select @var{threadnum}
18949 @end smallexample
18950
18951 Make @var{threadnum} the current thread. It prints the number of the new
18952 current thread, and the topmost frame for that thread.
18953
18954 @subsubheading @value{GDBN} Command
18955
18956 The corresponding @value{GDBN} command is @samp{thread}.
18957
18958 @subsubheading Example
18959
18960 @smallexample
18961 (gdb)
18962 -exec-next
18963 ^running
18964 (gdb)
18965 *stopped,reason="end-stepping-range",thread-id="2",line="187",
18966 file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
18967 (gdb)
18968 -thread-list-ids
18969 ^done,
18970 thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
18971 number-of-threads="3"
18972 (gdb)
18973 -thread-select 3
18974 ^done,new-thread-id="3",
18975 frame=@{level="0",func="vprintf",
18976 args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
18977 @{name="arg",value="0x2"@}],file="vprintf.c",line="31"@}
18978 (gdb)
18979 @end smallexample
18980
18981 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18982 @node GDB/MI Program Execution
18983 @section @sc{gdb/mi} Program Execution
18984
18985 These are the asynchronous commands which generate the out-of-band
18986 record @samp{*stopped}. Currently @value{GDBN} only really executes
18987 asynchronously with remote targets and this interaction is mimicked in
18988 other cases.
18989
18990 @subheading The @code{-exec-continue} Command
18991 @findex -exec-continue
18992
18993 @subsubheading Synopsis
18994
18995 @smallexample
18996 -exec-continue
18997 @end smallexample
18998
18999 Resumes the execution of the inferior program until a breakpoint is
19000 encountered, or until the inferior exits.
19001
19002 @subsubheading @value{GDBN} Command
19003
19004 The corresponding @value{GDBN} corresponding is @samp{continue}.
19005
19006 @subsubheading Example
19007
19008 @smallexample
19009 -exec-continue
19010 ^running
19011 (gdb)
19012 @@Hello world
19013 *stopped,reason="breakpoint-hit",bkptno="2",frame=@{func="foo",args=[],
19014 file="hello.c",fullname="/home/foo/bar/hello.c",line="13"@}
19015 (gdb)
19016 @end smallexample
19017
19018
19019 @subheading The @code{-exec-finish} Command
19020 @findex -exec-finish
19021
19022 @subsubheading Synopsis
19023
19024 @smallexample
19025 -exec-finish
19026 @end smallexample
19027
19028 Resumes the execution of the inferior program until the current
19029 function is exited. Displays the results returned by the function.
19030
19031 @subsubheading @value{GDBN} Command
19032
19033 The corresponding @value{GDBN} command is @samp{finish}.
19034
19035 @subsubheading Example
19036
19037 Function returning @code{void}.
19038
19039 @smallexample
19040 -exec-finish
19041 ^running
19042 (gdb)
19043 @@hello from foo
19044 *stopped,reason="function-finished",frame=@{func="main",args=[],
19045 file="hello.c",fullname="/home/foo/bar/hello.c",line="7"@}
19046 (gdb)
19047 @end smallexample
19048
19049 Function returning other than @code{void}. The name of the internal
19050 @value{GDBN} variable storing the result is printed, together with the
19051 value itself.
19052
19053 @smallexample
19054 -exec-finish
19055 ^running
19056 (gdb)
19057 *stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
19058 args=[@{name="a",value="1"],@{name="b",value="9"@}@},
19059 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19060 gdb-result-var="$1",return-value="0"
19061 (gdb)
19062 @end smallexample
19063
19064
19065 @subheading The @code{-exec-interrupt} Command
19066 @findex -exec-interrupt
19067
19068 @subsubheading Synopsis
19069
19070 @smallexample
19071 -exec-interrupt
19072 @end smallexample
19073
19074 Interrupts the background execution of the target. Note how the token
19075 associated with the stop message is the one for the execution command
19076 that has been interrupted. The token for the interrupt itself only
19077 appears in the @samp{^done} output. If the user is trying to
19078 interrupt a non-running program, an error message will be printed.
19079
19080 @subsubheading @value{GDBN} Command
19081
19082 The corresponding @value{GDBN} command is @samp{interrupt}.
19083
19084 @subsubheading Example
19085
19086 @smallexample
19087 (gdb)
19088 111-exec-continue
19089 111^running
19090
19091 (gdb)
19092 222-exec-interrupt
19093 222^done
19094 (gdb)
19095 111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
19096 frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
19097 fullname="/home/foo/bar/try.c",line="13"@}
19098 (gdb)
19099
19100 (gdb)
19101 -exec-interrupt
19102 ^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
19103 (gdb)
19104 @end smallexample
19105
19106
19107 @subheading The @code{-exec-next} Command
19108 @findex -exec-next
19109
19110 @subsubheading Synopsis
19111
19112 @smallexample
19113 -exec-next
19114 @end smallexample
19115
19116 Resumes execution of the inferior program, stopping when the beginning
19117 of the next source line is reached.
19118
19119 @subsubheading @value{GDBN} Command
19120
19121 The corresponding @value{GDBN} command is @samp{next}.
19122
19123 @subsubheading Example
19124
19125 @smallexample
19126 -exec-next
19127 ^running
19128 (gdb)
19129 *stopped,reason="end-stepping-range",line="8",file="hello.c"
19130 (gdb)
19131 @end smallexample
19132
19133
19134 @subheading The @code{-exec-next-instruction} Command
19135 @findex -exec-next-instruction
19136
19137 @subsubheading Synopsis
19138
19139 @smallexample
19140 -exec-next-instruction
19141 @end smallexample
19142
19143 Executes one machine instruction. If the instruction is a function
19144 call, continues until the function returns. If the program stops at an
19145 instruction in the middle of a source line, the address will be
19146 printed as well.
19147
19148 @subsubheading @value{GDBN} Command
19149
19150 The corresponding @value{GDBN} command is @samp{nexti}.
19151
19152 @subsubheading Example
19153
19154 @smallexample
19155 (gdb)
19156 -exec-next-instruction
19157 ^running
19158
19159 (gdb)
19160 *stopped,reason="end-stepping-range",
19161 addr="0x000100d4",line="5",file="hello.c"
19162 (gdb)
19163 @end smallexample
19164
19165
19166 @subheading The @code{-exec-return} Command
19167 @findex -exec-return
19168
19169 @subsubheading Synopsis
19170
19171 @smallexample
19172 -exec-return
19173 @end smallexample
19174
19175 Makes current function return immediately. Doesn't execute the inferior.
19176 Displays the new current frame.
19177
19178 @subsubheading @value{GDBN} Command
19179
19180 The corresponding @value{GDBN} command is @samp{return}.
19181
19182 @subsubheading Example
19183
19184 @smallexample
19185 (gdb)
19186 200-break-insert callee4
19187 200^done,bkpt=@{number="1",addr="0x00010734",
19188 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
19189 (gdb)
19190 000-exec-run
19191 000^running
19192 (gdb)
19193 000*stopped,reason="breakpoint-hit",bkptno="1",
19194 frame=@{func="callee4",args=[],
19195 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19196 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
19197 (gdb)
19198 205-break-delete
19199 205^done
19200 (gdb)
19201 111-exec-return
19202 111^done,frame=@{level="0",func="callee3",
19203 args=[@{name="strarg",
19204 value="0x11940 \"A string argument.\""@}],
19205 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19206 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18"@}
19207 (gdb)
19208 @end smallexample
19209
19210
19211 @subheading The @code{-exec-run} Command
19212 @findex -exec-run
19213
19214 @subsubheading Synopsis
19215
19216 @smallexample
19217 -exec-run
19218 @end smallexample
19219
19220 Starts execution of the inferior from the beginning. The inferior
19221 executes until either a breakpoint is encountered or the program
19222 exits. In the latter case the output will include an exit code, if
19223 the program has exited exceptionally.
19224
19225 @subsubheading @value{GDBN} Command
19226
19227 The corresponding @value{GDBN} command is @samp{run}.
19228
19229 @subsubheading Examples
19230
19231 @smallexample
19232 (gdb)
19233 -break-insert main
19234 ^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
19235 (gdb)
19236 -exec-run
19237 ^running
19238 (gdb)
19239 *stopped,reason="breakpoint-hit",bkptno="1",
19240 frame=@{func="main",args=[],file="recursive2.c",
19241 fullname="/home/foo/bar/recursive2.c",line="4"@}
19242 (gdb)
19243 @end smallexample
19244
19245 @noindent
19246 Program exited normally:
19247
19248 @smallexample
19249 (gdb)
19250 -exec-run
19251 ^running
19252 (gdb)
19253 x = 55
19254 *stopped,reason="exited-normally"
19255 (gdb)
19256 @end smallexample
19257
19258 @noindent
19259 Program exited exceptionally:
19260
19261 @smallexample
19262 (gdb)
19263 -exec-run
19264 ^running
19265 (gdb)
19266 x = 55
19267 *stopped,reason="exited",exit-code="01"
19268 (gdb)
19269 @end smallexample
19270
19271 Another way the program can terminate is if it receives a signal such as
19272 @code{SIGINT}. In this case, @sc{gdb/mi} displays this:
19273
19274 @smallexample
19275 (gdb)
19276 *stopped,reason="exited-signalled",signal-name="SIGINT",
19277 signal-meaning="Interrupt"
19278 @end smallexample
19279
19280
19281 @c @subheading -exec-signal
19282
19283
19284 @subheading The @code{-exec-step} Command
19285 @findex -exec-step
19286
19287 @subsubheading Synopsis
19288
19289 @smallexample
19290 -exec-step
19291 @end smallexample
19292
19293 Resumes execution of the inferior program, stopping when the beginning
19294 of the next source line is reached, if the next source line is not a
19295 function call. If it is, stop at the first instruction of the called
19296 function.
19297
19298 @subsubheading @value{GDBN} Command
19299
19300 The corresponding @value{GDBN} command is @samp{step}.
19301
19302 @subsubheading Example
19303
19304 Stepping into a function:
19305
19306 @smallexample
19307 -exec-step
19308 ^running
19309 (gdb)
19310 *stopped,reason="end-stepping-range",
19311 frame=@{func="foo",args=[@{name="a",value="10"@},
19312 @{name="b",value="0"@}],file="recursive2.c",
19313 fullname="/home/foo/bar/recursive2.c",line="11"@}
19314 (gdb)
19315 @end smallexample
19316
19317 Regular stepping:
19318
19319 @smallexample
19320 -exec-step
19321 ^running
19322 (gdb)
19323 *stopped,reason="end-stepping-range",line="14",file="recursive2.c"
19324 (gdb)
19325 @end smallexample
19326
19327
19328 @subheading The @code{-exec-step-instruction} Command
19329 @findex -exec-step-instruction
19330
19331 @subsubheading Synopsis
19332
19333 @smallexample
19334 -exec-step-instruction
19335 @end smallexample
19336
19337 Resumes the inferior which executes one machine instruction. The
19338 output, once @value{GDBN} has stopped, will vary depending on whether
19339 we have stopped in the middle of a source line or not. In the former
19340 case, the address at which the program stopped will be printed as
19341 well.
19342
19343 @subsubheading @value{GDBN} Command
19344
19345 The corresponding @value{GDBN} command is @samp{stepi}.
19346
19347 @subsubheading Example
19348
19349 @smallexample
19350 (gdb)
19351 -exec-step-instruction
19352 ^running
19353
19354 (gdb)
19355 *stopped,reason="end-stepping-range",
19356 frame=@{func="foo",args=[],file="try.c",
19357 fullname="/home/foo/bar/try.c",line="10"@}
19358 (gdb)
19359 -exec-step-instruction
19360 ^running
19361
19362 (gdb)
19363 *stopped,reason="end-stepping-range",
19364 frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
19365 fullname="/home/foo/bar/try.c",line="10"@}
19366 (gdb)
19367 @end smallexample
19368
19369
19370 @subheading The @code{-exec-until} Command
19371 @findex -exec-until
19372
19373 @subsubheading Synopsis
19374
19375 @smallexample
19376 -exec-until [ @var{location} ]
19377 @end smallexample
19378
19379 Executes the inferior until the @var{location} specified in the
19380 argument is reached. If there is no argument, the inferior executes
19381 until a source line greater than the current one is reached. The
19382 reason for stopping in this case will be @samp{location-reached}.
19383
19384 @subsubheading @value{GDBN} Command
19385
19386 The corresponding @value{GDBN} command is @samp{until}.
19387
19388 @subsubheading Example
19389
19390 @smallexample
19391 (gdb)
19392 -exec-until recursive2.c:6
19393 ^running
19394 (gdb)
19395 x = 55
19396 *stopped,reason="location-reached",frame=@{func="main",args=[],
19397 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6"@}
19398 (gdb)
19399 @end smallexample
19400
19401 @ignore
19402 @subheading -file-clear
19403 Is this going away????
19404 @end ignore
19405
19406 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19407 @node GDB/MI Stack Manipulation
19408 @section @sc{gdb/mi} Stack Manipulation Commands
19409
19410
19411 @subheading The @code{-stack-info-frame} Command
19412 @findex -stack-info-frame
19413
19414 @subsubheading Synopsis
19415
19416 @smallexample
19417 -stack-info-frame
19418 @end smallexample
19419
19420 Get info on the selected frame.
19421
19422 @subsubheading @value{GDBN} Command
19423
19424 The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
19425 (without arguments).
19426
19427 @subsubheading Example
19428
19429 @smallexample
19430 (gdb)
19431 -stack-info-frame
19432 ^done,frame=@{level="1",addr="0x0001076c",func="callee3",
19433 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19434 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@}
19435 (gdb)
19436 @end smallexample
19437
19438 @subheading The @code{-stack-info-depth} Command
19439 @findex -stack-info-depth
19440
19441 @subsubheading Synopsis
19442
19443 @smallexample
19444 -stack-info-depth [ @var{max-depth} ]
19445 @end smallexample
19446
19447 Return the depth of the stack. If the integer argument @var{max-depth}
19448 is specified, do not count beyond @var{max-depth} frames.
19449
19450 @subsubheading @value{GDBN} Command
19451
19452 There's no equivalent @value{GDBN} command.
19453
19454 @subsubheading Example
19455
19456 For a stack with frame levels 0 through 11:
19457
19458 @smallexample
19459 (gdb)
19460 -stack-info-depth
19461 ^done,depth="12"
19462 (gdb)
19463 -stack-info-depth 4
19464 ^done,depth="4"
19465 (gdb)
19466 -stack-info-depth 12
19467 ^done,depth="12"
19468 (gdb)
19469 -stack-info-depth 11
19470 ^done,depth="11"
19471 (gdb)
19472 -stack-info-depth 13
19473 ^done,depth="12"
19474 (gdb)
19475 @end smallexample
19476
19477 @subheading The @code{-stack-list-arguments} Command
19478 @findex -stack-list-arguments
19479
19480 @subsubheading Synopsis
19481
19482 @smallexample
19483 -stack-list-arguments @var{show-values}
19484 [ @var{low-frame} @var{high-frame} ]
19485 @end smallexample
19486
19487 Display a list of the arguments for the frames between @var{low-frame}
19488 and @var{high-frame} (inclusive). If @var{low-frame} and
19489 @var{high-frame} are not provided, list the arguments for the whole
19490 call stack. If the two arguments are equal, show the single frame
19491 at the corresponding level. It is an error if @var{low-frame} is
19492 larger than the actual number of frames. On the other hand,
19493 @var{high-frame} may be larger than the actual number of frames, in
19494 which case only existing frames will be returned.
19495
19496 The @var{show-values} argument must have a value of 0 or 1. A value of
19497 0 means that only the names of the arguments are listed, a value of 1
19498 means that both names and values of the arguments are printed.
19499
19500 @subsubheading @value{GDBN} Command
19501
19502 @value{GDBN} does not have an equivalent command. @code{gdbtk} has a
19503 @samp{gdb_get_args} command which partially overlaps with the
19504 functionality of @samp{-stack-list-arguments}.
19505
19506 @subsubheading Example
19507
19508 @smallexample
19509 (gdb)
19510 -stack-list-frames
19511 ^done,
19512 stack=[
19513 frame=@{level="0",addr="0x00010734",func="callee4",
19514 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19515 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8"@},
19516 frame=@{level="1",addr="0x0001076c",func="callee3",
19517 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19518 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17"@},
19519 frame=@{level="2",addr="0x0001078c",func="callee2",
19520 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19521 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22"@},
19522 frame=@{level="3",addr="0x000107b4",func="callee1",
19523 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19524 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27"@},
19525 frame=@{level="4",addr="0x000107e0",func="main",
19526 file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
19527 fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32"@}]
19528 (gdb)
19529 -stack-list-arguments 0
19530 ^done,
19531 stack-args=[
19532 frame=@{level="0",args=[]@},
19533 frame=@{level="1",args=[name="strarg"]@},
19534 frame=@{level="2",args=[name="intarg",name="strarg"]@},
19535 frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
19536 frame=@{level="4",args=[]@}]
19537 (gdb)
19538 -stack-list-arguments 1
19539 ^done,
19540 stack-args=[
19541 frame=@{level="0",args=[]@},
19542 frame=@{level="1",
19543 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19544 frame=@{level="2",args=[
19545 @{name="intarg",value="2"@},
19546 @{name="strarg",value="0x11940 \"A string argument.\""@}]@},
19547 @{frame=@{level="3",args=[
19548 @{name="intarg",value="2"@},
19549 @{name="strarg",value="0x11940 \"A string argument.\""@},
19550 @{name="fltarg",value="3.5"@}]@},
19551 frame=@{level="4",args=[]@}]
19552 (gdb)
19553 -stack-list-arguments 0 2 2
19554 ^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
19555 (gdb)
19556 -stack-list-arguments 1 2 2
19557 ^done,stack-args=[frame=@{level="2",
19558 args=[@{name="intarg",value="2"@},
19559 @{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
19560 (gdb)
19561 @end smallexample
19562
19563 @c @subheading -stack-list-exception-handlers
19564
19565
19566 @subheading The @code{-stack-list-frames} Command
19567 @findex -stack-list-frames
19568
19569 @subsubheading Synopsis
19570
19571 @smallexample
19572 -stack-list-frames [ @var{low-frame} @var{high-frame} ]
19573 @end smallexample
19574
19575 List the frames currently on the stack. For each frame it displays the
19576 following info:
19577
19578 @table @samp
19579 @item @var{level}
19580 The frame number, 0 being the topmost frame, i.e., the innermost function.
19581 @item @var{addr}
19582 The @code{$pc} value for that frame.
19583 @item @var{func}
19584 Function name.
19585 @item @var{file}
19586 File name of the source file where the function lives.
19587 @item @var{line}
19588 Line number corresponding to the @code{$pc}.
19589 @end table
19590
19591 If invoked without arguments, this command prints a backtrace for the
19592 whole stack. If given two integer arguments, it shows the frames whose
19593 levels are between the two arguments (inclusive). If the two arguments
19594 are equal, it shows the single frame at the corresponding level. It is
19595 an error if @var{low-frame} is larger than the actual number of
19596 frames. On the other hand, @var{high-frame} may be larger than the
19597 actual number of frames, in which case only existing frames will be returned.
19598
19599 @subsubheading @value{GDBN} Command
19600
19601 The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
19602
19603 @subsubheading Example
19604
19605 Full stack backtrace:
19606
19607 @smallexample
19608 (gdb)
19609 -stack-list-frames
19610 ^done,stack=
19611 [frame=@{level="0",addr="0x0001076c",func="foo",
19612 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11"@},
19613 frame=@{level="1",addr="0x000107a4",func="foo",
19614 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19615 frame=@{level="2",addr="0x000107a4",func="foo",
19616 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19617 frame=@{level="3",addr="0x000107a4",func="foo",
19618 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19619 frame=@{level="4",addr="0x000107a4",func="foo",
19620 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19621 frame=@{level="5",addr="0x000107a4",func="foo",
19622 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19623 frame=@{level="6",addr="0x000107a4",func="foo",
19624 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19625 frame=@{level="7",addr="0x000107a4",func="foo",
19626 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19627 frame=@{level="8",addr="0x000107a4",func="foo",
19628 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19629 frame=@{level="9",addr="0x000107a4",func="foo",
19630 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19631 frame=@{level="10",addr="0x000107a4",func="foo",
19632 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19633 frame=@{level="11",addr="0x00010738",func="main",
19634 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4"@}]
19635 (gdb)
19636 @end smallexample
19637
19638 Show frames between @var{low_frame} and @var{high_frame}:
19639
19640 @smallexample
19641 (gdb)
19642 -stack-list-frames 3 5
19643 ^done,stack=
19644 [frame=@{level="3",addr="0x000107a4",func="foo",
19645 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19646 frame=@{level="4",addr="0x000107a4",func="foo",
19647 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@},
19648 frame=@{level="5",addr="0x000107a4",func="foo",
19649 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
19650 (gdb)
19651 @end smallexample
19652
19653 Show a single frame:
19654
19655 @smallexample
19656 (gdb)
19657 -stack-list-frames 3 3
19658 ^done,stack=
19659 [frame=@{level="3",addr="0x000107a4",func="foo",
19660 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14"@}]
19661 (gdb)
19662 @end smallexample
19663
19664
19665 @subheading The @code{-stack-list-locals} Command
19666 @findex -stack-list-locals
19667
19668 @subsubheading Synopsis
19669
19670 @smallexample
19671 -stack-list-locals @var{print-values}
19672 @end smallexample
19673
19674 Display the local variable names for the selected frame. If
19675 @var{print-values} is 0 or @code{--no-values}, print only the names of
19676 the variables; if it is 1 or @code{--all-values}, print also their
19677 values; and if it is 2 or @code{--simple-values}, print the name,
19678 type and value for simple data types and the name and type for arrays,
19679 structures and unions. In this last case, a frontend can immediately
19680 display the value of simple data types and create variable objects for
19681 other data types when the user wishes to explore their values in
19682 more detail.
19683
19684 @subsubheading @value{GDBN} Command
19685
19686 @samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
19687
19688 @subsubheading Example
19689
19690 @smallexample
19691 (gdb)
19692 -stack-list-locals 0
19693 ^done,locals=[name="A",name="B",name="C"]
19694 (gdb)
19695 -stack-list-locals --all-values
19696 ^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
19697 @{name="C",value="@{1, 2, 3@}"@}]
19698 -stack-list-locals --simple-values
19699 ^done,locals=[@{name="A",type="int",value="1"@},
19700 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
19701 (gdb)
19702 @end smallexample
19703
19704
19705 @subheading The @code{-stack-select-frame} Command
19706 @findex -stack-select-frame
19707
19708 @subsubheading Synopsis
19709
19710 @smallexample
19711 -stack-select-frame @var{framenum}
19712 @end smallexample
19713
19714 Change the selected frame. Select a different frame @var{framenum} on
19715 the stack.
19716
19717 @subsubheading @value{GDBN} Command
19718
19719 The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
19720 @samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
19721
19722 @subsubheading Example
19723
19724 @smallexample
19725 (gdb)
19726 -stack-select-frame 2
19727 ^done
19728 (gdb)
19729 @end smallexample
19730
19731 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19732 @node GDB/MI Variable Objects
19733 @section @sc{gdb/mi} Variable Objects
19734
19735 @ignore
19736
19737 @subheading Motivation for Variable Objects in @sc{gdb/mi}
19738
19739 For the implementation of a variable debugger window (locals, watched
19740 expressions, etc.), we are proposing the adaptation of the existing code
19741 used by @code{Insight}.
19742
19743 The two main reasons for that are:
19744
19745 @enumerate 1
19746 @item
19747 It has been proven in practice (it is already on its second generation).
19748
19749 @item
19750 It will shorten development time (needless to say how important it is
19751 now).
19752 @end enumerate
19753
19754 The original interface was designed to be used by Tcl code, so it was
19755 slightly changed so it could be used through @sc{gdb/mi}. This section
19756 describes the @sc{gdb/mi} operations that will be available and gives some
19757 hints about their use.
19758
19759 @emph{Note}: In addition to the set of operations described here, we
19760 expect the @sc{gui} implementation of a variable window to require, at
19761 least, the following operations:
19762
19763 @itemize @bullet
19764 @item @code{-gdb-show} @code{output-radix}
19765 @item @code{-stack-list-arguments}
19766 @item @code{-stack-list-locals}
19767 @item @code{-stack-select-frame}
19768 @end itemize
19769
19770 @end ignore
19771
19772 @subheading Introduction to Variable Objects
19773
19774 @cindex variable objects in @sc{gdb/mi}
19775
19776 Variable objects are "object-oriented" MI interface for examining and
19777 changing values of expressions. Unlike some other MI interfaces that
19778 work with expressions, variable objects are specifically designed for
19779 simple and efficient presentation in the frontend. A variable object
19780 is identified by string name. When a variable object is created, the
19781 frontend specifies the expression for that variable object. The
19782 expression can be a simple variable, or it can be an arbitrary complex
19783 expression, and can even involve CPU registers. After creating a
19784 variable object, the frontend can invoke other variable object
19785 operations---for example to obtain or change the value of a variable
19786 object, or to change display format.
19787
19788 Variable objects have hierarchical tree structure. Any variable object
19789 that corresponds to a composite type, such as structure in C, has
19790 a number of child variable objects, for example corresponding to each
19791 element of a structure. A child variable object can itself have
19792 children, recursively. Recursion ends when we reach
19793 leaf variable objects, which always have built-in types. Child variable
19794 objects are created only by explicit request, so if a frontend
19795 is not interested in the children of a particular variable object, no
19796 child will be created.
19797
19798 For a leaf variable object it is possible to obtain its value as a
19799 string, or set the value from a string. String value can be also
19800 obtained for a non-leaf variable object, but it's generally a string
19801 that only indicates the type of the object, and does not list its
19802 contents. Assignment to a non-leaf variable object is not allowed.
19803
19804 A frontend does not need to read the values of all variable objects each time
19805 the program stops. Instead, MI provides an update command that lists all
19806 variable objects whose values has changed since the last update
19807 operation. This considerably reduces the amount of data that must
19808 be transferred to the frontend. As noted above, children variable
19809 objects are created on demand, and only leaf variable objects have a
19810 real value. As result, gdb will read target memory only for leaf
19811 variables that frontend has created.
19812
19813 The automatic update is not always desirable. For example, a frontend
19814 might want to keep a value of some expression for future reference,
19815 and never update it. For another example, fetching memory is
19816 relatively slow for embedded targets, so a frontend might want
19817 to disable automatic update for the variables that are either not
19818 visible on the screen, or ``closed''. This is possible using so
19819 called ``frozen variable objects''. Such variable objects are never
19820 implicitly updated.
19821
19822 The following is the complete set of @sc{gdb/mi} operations defined to
19823 access this functionality:
19824
19825 @multitable @columnfractions .4 .6
19826 @item @strong{Operation}
19827 @tab @strong{Description}
19828
19829 @item @code{-var-create}
19830 @tab create a variable object
19831 @item @code{-var-delete}
19832 @tab delete the variable object and/or its children
19833 @item @code{-var-set-format}
19834 @tab set the display format of this variable
19835 @item @code{-var-show-format}
19836 @tab show the display format of this variable
19837 @item @code{-var-info-num-children}
19838 @tab tells how many children this object has
19839 @item @code{-var-list-children}
19840 @tab return a list of the object's children
19841 @item @code{-var-info-type}
19842 @tab show the type of this variable object
19843 @item @code{-var-info-expression}
19844 @tab print parent-relative expression that this variable object represents
19845 @item @code{-var-info-path-expression}
19846 @tab print full expression that this variable object represents
19847 @item @code{-var-show-attributes}
19848 @tab is this variable editable? does it exist here?
19849 @item @code{-var-evaluate-expression}
19850 @tab get the value of this variable
19851 @item @code{-var-assign}
19852 @tab set the value of this variable
19853 @item @code{-var-update}
19854 @tab update the variable and its children
19855 @item @code{-var-set-frozen}
19856 @tab set frozeness attribute
19857 @end multitable
19858
19859 In the next subsection we describe each operation in detail and suggest
19860 how it can be used.
19861
19862 @subheading Description And Use of Operations on Variable Objects
19863
19864 @subheading The @code{-var-create} Command
19865 @findex -var-create
19866
19867 @subsubheading Synopsis
19868
19869 @smallexample
19870 -var-create @{@var{name} | "-"@}
19871 @{@var{frame-addr} | "*"@} @var{expression}
19872 @end smallexample
19873
19874 This operation creates a variable object, which allows the monitoring of
19875 a variable, the result of an expression, a memory cell or a CPU
19876 register.
19877
19878 The @var{name} parameter is the string by which the object can be
19879 referenced. It must be unique. If @samp{-} is specified, the varobj
19880 system will generate a string ``varNNNNNN'' automatically. It will be
19881 unique provided that one does not specify @var{name} on that format.
19882 The command fails if a duplicate name is found.
19883
19884 The frame under which the expression should be evaluated can be
19885 specified by @var{frame-addr}. A @samp{*} indicates that the current
19886 frame should be used.
19887
19888 @var{expression} is any expression valid on the current language set (must not
19889 begin with a @samp{*}), or one of the following:
19890
19891 @itemize @bullet
19892 @item
19893 @samp{*@var{addr}}, where @var{addr} is the address of a memory cell
19894
19895 @item
19896 @samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
19897
19898 @item
19899 @samp{$@var{regname}} --- a CPU register name
19900 @end itemize
19901
19902 @subsubheading Result
19903
19904 This operation returns the name, number of children and the type of the
19905 object created. Type is returned as a string as the ones generated by
19906 the @value{GDBN} CLI:
19907
19908 @smallexample
19909 name="@var{name}",numchild="N",type="@var{type}"
19910 @end smallexample
19911
19912
19913 @subheading The @code{-var-delete} Command
19914 @findex -var-delete
19915
19916 @subsubheading Synopsis
19917
19918 @smallexample
19919 -var-delete [ -c ] @var{name}
19920 @end smallexample
19921
19922 Deletes a previously created variable object and all of its children.
19923 With the @samp{-c} option, just deletes the children.
19924
19925 Returns an error if the object @var{name} is not found.
19926
19927
19928 @subheading The @code{-var-set-format} Command
19929 @findex -var-set-format
19930
19931 @subsubheading Synopsis
19932
19933 @smallexample
19934 -var-set-format @var{name} @var{format-spec}
19935 @end smallexample
19936
19937 Sets the output format for the value of the object @var{name} to be
19938 @var{format-spec}.
19939
19940 The syntax for the @var{format-spec} is as follows:
19941
19942 @smallexample
19943 @var{format-spec} @expansion{}
19944 @{binary | decimal | hexadecimal | octal | natural@}
19945 @end smallexample
19946
19947 The natural format is the default format choosen automatically
19948 based on the variable type (like decimal for an @code{int}, hex
19949 for pointers, etc.).
19950
19951 For a variable with children, the format is set only on the
19952 variable itself, and the children are not affected.
19953
19954 @subheading The @code{-var-show-format} Command
19955 @findex -var-show-format
19956
19957 @subsubheading Synopsis
19958
19959 @smallexample
19960 -var-show-format @var{name}
19961 @end smallexample
19962
19963 Returns the format used to display the value of the object @var{name}.
19964
19965 @smallexample
19966 @var{format} @expansion{}
19967 @var{format-spec}
19968 @end smallexample
19969
19970
19971 @subheading The @code{-var-info-num-children} Command
19972 @findex -var-info-num-children
19973
19974 @subsubheading Synopsis
19975
19976 @smallexample
19977 -var-info-num-children @var{name}
19978 @end smallexample
19979
19980 Returns the number of children of a variable object @var{name}:
19981
19982 @smallexample
19983 numchild=@var{n}
19984 @end smallexample
19985
19986
19987 @subheading The @code{-var-list-children} Command
19988 @findex -var-list-children
19989
19990 @subsubheading Synopsis
19991
19992 @smallexample
19993 -var-list-children [@var{print-values}] @var{name}
19994 @end smallexample
19995 @anchor{-var-list-children}
19996
19997 Return a list of the children of the specified variable object and
19998 create variable objects for them, if they do not already exist. With
19999 a single argument or if @var{print-values} has a value for of 0 or
20000 @code{--no-values}, print only the names of the variables; if
20001 @var{print-values} is 1 or @code{--all-values}, also print their
20002 values; and if it is 2 or @code{--simple-values} print the name and
20003 value for simple data types and just the name for arrays, structures
20004 and unions.
20005
20006 @subsubheading Example
20007
20008 @smallexample
20009 (gdb)
20010 -var-list-children n
20011 ^done,numchild=@var{n},children=[@{name=@var{name},
20012 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
20013 (gdb)
20014 -var-list-children --all-values n
20015 ^done,numchild=@var{n},children=[@{name=@var{name},
20016 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
20017 @end smallexample
20018
20019
20020 @subheading The @code{-var-info-type} Command
20021 @findex -var-info-type
20022
20023 @subsubheading Synopsis
20024
20025 @smallexample
20026 -var-info-type @var{name}
20027 @end smallexample
20028
20029 Returns the type of the specified variable @var{name}. The type is
20030 returned as a string in the same format as it is output by the
20031 @value{GDBN} CLI:
20032
20033 @smallexample
20034 type=@var{typename}
20035 @end smallexample
20036
20037
20038 @subheading The @code{-var-info-expression} Command
20039 @findex -var-info-expression
20040
20041 @subsubheading Synopsis
20042
20043 @smallexample
20044 -var-info-expression @var{name}
20045 @end smallexample
20046
20047 Returns a string that is suitable for presenting this
20048 variable object in user interface. The string is generally
20049 not valid expression in the current language, and cannot be evaluated.
20050
20051 For example, if @code{a} is an array, and variable object
20052 @code{A} was created for @code{a}, then we'll get this output:
20053
20054 @smallexample
20055 (gdb) -var-info-expression A.1
20056 ^done,lang="C",exp="1"
20057 @end smallexample
20058
20059 @noindent
20060 Here, the values of @code{lang} can be @code{@{"C" | "C++" | "Java"@}}.
20061
20062 Note that the output of the @code{-var-list-children} command also
20063 includes those expressions, so the @code{-var-info-expression} command
20064 is of limited use.
20065
20066 @subheading The @code{-var-info-path-expression} Command
20067 @findex -var-info-path-expression
20068
20069 @subsubheading Synopsis
20070
20071 @smallexample
20072 -var-info-path-expression @var{name}
20073 @end smallexample
20074
20075 Returns an expression that can be evaluated in the current
20076 context and will yield the same value that a variable object has.
20077 Compare this with the @code{-var-info-expression} command, which
20078 result can be used only for UI presentation. Typical use of
20079 the @code{-var-info-path-expression} command is creating a
20080 watchpoint from a variable object.
20081
20082 For example, suppose @code{C} is a C@t{++} class, derived from class
20083 @code{Base}, and that the @code{Base} class has a member called
20084 @code{m_size}. Assume a variable @code{c} is has the type of
20085 @code{C} and a variable object @code{C} was created for variable
20086 @code{c}. Then, we'll get this output:
20087 @smallexample
20088 (gdb) -var-info-path-expression C.Base.public.m_size
20089 ^done,path_expr=((Base)c).m_size)
20090 @end smallexample
20091
20092 @subheading The @code{-var-show-attributes} Command
20093 @findex -var-show-attributes
20094
20095 @subsubheading Synopsis
20096
20097 @smallexample
20098 -var-show-attributes @var{name}
20099 @end smallexample
20100
20101 List attributes of the specified variable object @var{name}:
20102
20103 @smallexample
20104 status=@var{attr} [ ( ,@var{attr} )* ]
20105 @end smallexample
20106
20107 @noindent
20108 where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
20109
20110 @subheading The @code{-var-evaluate-expression} Command
20111 @findex -var-evaluate-expression
20112
20113 @subsubheading Synopsis
20114
20115 @smallexample
20116 -var-evaluate-expression @var{name}
20117 @end smallexample
20118
20119 Evaluates the expression that is represented by the specified variable
20120 object and returns its value as a string. The format of the
20121 string can be changed using the @code{-var-set-format} command.
20122
20123 @smallexample
20124 value=@var{value}
20125 @end smallexample
20126
20127 Note that one must invoke @code{-var-list-children} for a variable
20128 before the value of a child variable can be evaluated.
20129
20130 @subheading The @code{-var-assign} Command
20131 @findex -var-assign
20132
20133 @subsubheading Synopsis
20134
20135 @smallexample
20136 -var-assign @var{name} @var{expression}
20137 @end smallexample
20138
20139 Assigns the value of @var{expression} to the variable object specified
20140 by @var{name}. The object must be @samp{editable}. If the variable's
20141 value is altered by the assign, the variable will show up in any
20142 subsequent @code{-var-update} list.
20143
20144 @subsubheading Example
20145
20146 @smallexample
20147 (gdb)
20148 -var-assign var1 3
20149 ^done,value="3"
20150 (gdb)
20151 -var-update *
20152 ^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
20153 (gdb)
20154 @end smallexample
20155
20156 @subheading The @code{-var-update} Command
20157 @findex -var-update
20158
20159 @subsubheading Synopsis
20160
20161 @smallexample
20162 -var-update [@var{print-values}] @{@var{name} | "*"@}
20163 @end smallexample
20164
20165 Reevaluate the expressions corresponding to the variable object
20166 @var{name} and all its direct and indirect children, and return the
20167 list of variable objects whose values have changed; @var{name} must
20168 be a root variable object. Here, ``changed'' means that the result of
20169 @code{-var-evaluate-expression} before and after the
20170 @code{-var-update} is different. If @samp{*} is used as the variable
20171 object names, all existing variable objects are updated, except
20172 for frozen ones (@pxref{-var-set-frozen}). The option
20173 @var{print-values} determines whether both names and values, or just
20174 names are printed. The possible values of this options are the same
20175 as for @code{-var-list-children} (@pxref{-var-list-children}). It is
20176 recommended to use the @samp{--all-values} option, to reduce the
20177 number of MI commands needed on each program stop.
20178
20179
20180 @subsubheading Example
20181
20182 @smallexample
20183 (gdb)
20184 -var-assign var1 3
20185 ^done,value="3"
20186 (gdb)
20187 -var-update --all-values var1
20188 ^done,changelist=[@{name="var1",value="3",in_scope="true",
20189 type_changed="false"@}]
20190 (gdb)
20191 @end smallexample
20192
20193 @anchor{-var-update}
20194 The field in_scope may take three values:
20195
20196 @table @code
20197 @item "true"
20198 The variable object's current value is valid.
20199
20200 @item "false"
20201 The variable object does not currently hold a valid value but it may
20202 hold one in the future if its associated expression comes back into
20203 scope.
20204
20205 @item "invalid"
20206 The variable object no longer holds a valid value.
20207 This can occur when the executable file being debugged has changed,
20208 either through recompilation or by using the @value{GDBN} @code{file}
20209 command. The front end should normally choose to delete these variable
20210 objects.
20211 @end table
20212
20213 In the future new values may be added to this list so the front should
20214 be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
20215
20216 @subheading The @code{-var-set-frozen} Command
20217 @findex -var-set-frozen
20218 @anchor{-var-set-frozen}
20219
20220 @subsubheading Synopsis
20221
20222 @smallexample
20223 -var-set-frozen @var{name} @var{flag}
20224 @end smallexample
20225
20226 Set the frozenness flag on the variable object @var{name}. The
20227 @var{flag} parameter should be either @samp{1} to make the variable
20228 frozen or @samp{0} to make it unfrozen. If a variable object is
20229 frozen, then neither itself, nor any of its children, are
20230 implicitly updated by @code{-var-update} of
20231 a parent variable or by @code{-var-update *}. Only
20232 @code{-var-update} of the variable itself will update its value and
20233 values of its children. After a variable object is unfrozen, it is
20234 implicitly updated by all subsequent @code{-var-update} operations.
20235 Unfreezing a variable does not update it, only subsequent
20236 @code{-var-update} does.
20237
20238 @subsubheading Example
20239
20240 @smallexample
20241 (gdb)
20242 -var-set-frozen V 1
20243 ^done
20244 (gdb)
20245 @end smallexample
20246
20247
20248 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20249 @node GDB/MI Data Manipulation
20250 @section @sc{gdb/mi} Data Manipulation
20251
20252 @cindex data manipulation, in @sc{gdb/mi}
20253 @cindex @sc{gdb/mi}, data manipulation
20254 This section describes the @sc{gdb/mi} commands that manipulate data:
20255 examine memory and registers, evaluate expressions, etc.
20256
20257 @c REMOVED FROM THE INTERFACE.
20258 @c @subheading -data-assign
20259 @c Change the value of a program variable. Plenty of side effects.
20260 @c @subsubheading GDB Command
20261 @c set variable
20262 @c @subsubheading Example
20263 @c N.A.
20264
20265 @subheading The @code{-data-disassemble} Command
20266 @findex -data-disassemble
20267
20268 @subsubheading Synopsis
20269
20270 @smallexample
20271 -data-disassemble
20272 [ -s @var{start-addr} -e @var{end-addr} ]
20273 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
20274 -- @var{mode}
20275 @end smallexample
20276
20277 @noindent
20278 Where:
20279
20280 @table @samp
20281 @item @var{start-addr}
20282 is the beginning address (or @code{$pc})
20283 @item @var{end-addr}
20284 is the end address
20285 @item @var{filename}
20286 is the name of the file to disassemble
20287 @item @var{linenum}
20288 is the line number to disassemble around
20289 @item @var{lines}
20290 is the number of disassembly lines to be produced. If it is -1,
20291 the whole function will be disassembled, in case no @var{end-addr} is
20292 specified. If @var{end-addr} is specified as a non-zero value, and
20293 @var{lines} is lower than the number of disassembly lines between
20294 @var{start-addr} and @var{end-addr}, only @var{lines} lines are
20295 displayed; if @var{lines} is higher than the number of lines between
20296 @var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
20297 are displayed.
20298 @item @var{mode}
20299 is either 0 (meaning only disassembly) or 1 (meaning mixed source and
20300 disassembly).
20301 @end table
20302
20303 @subsubheading Result
20304
20305 The output for each instruction is composed of four fields:
20306
20307 @itemize @bullet
20308 @item Address
20309 @item Func-name
20310 @item Offset
20311 @item Instruction
20312 @end itemize
20313
20314 Note that whatever included in the instruction field, is not manipulated
20315 directly by @sc{gdb/mi}, i.e., it is not possible to adjust its format.
20316
20317 @subsubheading @value{GDBN} Command
20318
20319 There's no direct mapping from this command to the CLI.
20320
20321 @subsubheading Example
20322
20323 Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
20324
20325 @smallexample
20326 (gdb)
20327 -data-disassemble -s $pc -e "$pc + 20" -- 0
20328 ^done,
20329 asm_insns=[
20330 @{address="0x000107c0",func-name="main",offset="4",
20331 inst="mov 2, %o0"@},
20332 @{address="0x000107c4",func-name="main",offset="8",
20333 inst="sethi %hi(0x11800), %o2"@},
20334 @{address="0x000107c8",func-name="main",offset="12",
20335 inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
20336 @{address="0x000107cc",func-name="main",offset="16",
20337 inst="sethi %hi(0x11800), %o2"@},
20338 @{address="0x000107d0",func-name="main",offset="20",
20339 inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
20340 (gdb)
20341 @end smallexample
20342
20343 Disassemble the whole @code{main} function. Line 32 is part of
20344 @code{main}.
20345
20346 @smallexample
20347 -data-disassemble -f basics.c -l 32 -- 0
20348 ^done,asm_insns=[
20349 @{address="0x000107bc",func-name="main",offset="0",
20350 inst="save %sp, -112, %sp"@},
20351 @{address="0x000107c0",func-name="main",offset="4",
20352 inst="mov 2, %o0"@},
20353 @{address="0x000107c4",func-name="main",offset="8",
20354 inst="sethi %hi(0x11800), %o2"@},
20355 [@dots{}]
20356 @{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
20357 @{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
20358 (gdb)
20359 @end smallexample
20360
20361 Disassemble 3 instructions from the start of @code{main}:
20362
20363 @smallexample
20364 (gdb)
20365 -data-disassemble -f basics.c -l 32 -n 3 -- 0
20366 ^done,asm_insns=[
20367 @{address="0x000107bc",func-name="main",offset="0",
20368 inst="save %sp, -112, %sp"@},
20369 @{address="0x000107c0",func-name="main",offset="4",
20370 inst="mov 2, %o0"@},
20371 @{address="0x000107c4",func-name="main",offset="8",
20372 inst="sethi %hi(0x11800), %o2"@}]
20373 (gdb)
20374 @end smallexample
20375
20376 Disassemble 3 instructions from the start of @code{main} in mixed mode:
20377
20378 @smallexample
20379 (gdb)
20380 -data-disassemble -f basics.c -l 32 -n 3 -- 1
20381 ^done,asm_insns=[
20382 src_and_asm_line=@{line="31",
20383 file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
20384 testsuite/gdb.mi/basics.c",line_asm_insn=[
20385 @{address="0x000107bc",func-name="main",offset="0",
20386 inst="save %sp, -112, %sp"@}]@},
20387 src_and_asm_line=@{line="32",
20388 file="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb/ \
20389 testsuite/gdb.mi/basics.c",line_asm_insn=[
20390 @{address="0x000107c0",func-name="main",offset="4",
20391 inst="mov 2, %o0"@},
20392 @{address="0x000107c4",func-name="main",offset="8",
20393 inst="sethi %hi(0x11800), %o2"@}]@}]
20394 (gdb)
20395 @end smallexample
20396
20397
20398 @subheading The @code{-data-evaluate-expression} Command
20399 @findex -data-evaluate-expression
20400
20401 @subsubheading Synopsis
20402
20403 @smallexample
20404 -data-evaluate-expression @var{expr}
20405 @end smallexample
20406
20407 Evaluate @var{expr} as an expression. The expression could contain an
20408 inferior function call. The function call will execute synchronously.
20409 If the expression contains spaces, it must be enclosed in double quotes.
20410
20411 @subsubheading @value{GDBN} Command
20412
20413 The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
20414 @samp{call}. In @code{gdbtk} only, there's a corresponding
20415 @samp{gdb_eval} command.
20416
20417 @subsubheading Example
20418
20419 In the following example, the numbers that precede the commands are the
20420 @dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
20421 Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
20422 output.
20423
20424 @smallexample
20425 211-data-evaluate-expression A
20426 211^done,value="1"
20427 (gdb)
20428 311-data-evaluate-expression &A
20429 311^done,value="0xefffeb7c"
20430 (gdb)
20431 411-data-evaluate-expression A+3
20432 411^done,value="4"
20433 (gdb)
20434 511-data-evaluate-expression "A + 3"
20435 511^done,value="4"
20436 (gdb)
20437 @end smallexample
20438
20439
20440 @subheading The @code{-data-list-changed-registers} Command
20441 @findex -data-list-changed-registers
20442
20443 @subsubheading Synopsis
20444
20445 @smallexample
20446 -data-list-changed-registers
20447 @end smallexample
20448
20449 Display a list of the registers that have changed.
20450
20451 @subsubheading @value{GDBN} Command
20452
20453 @value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
20454 has the corresponding command @samp{gdb_changed_register_list}.
20455
20456 @subsubheading Example
20457
20458 On a PPC MBX board:
20459
20460 @smallexample
20461 (gdb)
20462 -exec-continue
20463 ^running
20464
20465 (gdb)
20466 *stopped,reason="breakpoint-hit",bkptno="1",frame=@{func="main",
20467 args=[],file="try.c",fullname="/home/foo/bar/try.c",line="5"@}
20468 (gdb)
20469 -data-list-changed-registers
20470 ^done,changed-registers=["0","1","2","4","5","6","7","8","9",
20471 "10","11","13","14","15","16","17","18","19","20","21","22","23",
20472 "24","25","26","27","28","30","31","64","65","66","67","69"]
20473 (gdb)
20474 @end smallexample
20475
20476
20477 @subheading The @code{-data-list-register-names} Command
20478 @findex -data-list-register-names
20479
20480 @subsubheading Synopsis
20481
20482 @smallexample
20483 -data-list-register-names [ ( @var{regno} )+ ]
20484 @end smallexample
20485
20486 Show a list of register names for the current target. If no arguments
20487 are given, it shows a list of the names of all the registers. If
20488 integer numbers are given as arguments, it will print a list of the
20489 names of the registers corresponding to the arguments. To ensure
20490 consistency between a register name and its number, the output list may
20491 include empty register names.
20492
20493 @subsubheading @value{GDBN} Command
20494
20495 @value{GDBN} does not have a command which corresponds to
20496 @samp{-data-list-register-names}. In @code{gdbtk} there is a
20497 corresponding command @samp{gdb_regnames}.
20498
20499 @subsubheading Example
20500
20501 For the PPC MBX board:
20502 @smallexample
20503 (gdb)
20504 -data-list-register-names
20505 ^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
20506 "r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
20507 "r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
20508 "r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
20509 "f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
20510 "f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
20511 "", "pc","ps","cr","lr","ctr","xer"]
20512 (gdb)
20513 -data-list-register-names 1 2 3
20514 ^done,register-names=["r1","r2","r3"]
20515 (gdb)
20516 @end smallexample
20517
20518 @subheading The @code{-data-list-register-values} Command
20519 @findex -data-list-register-values
20520
20521 @subsubheading Synopsis
20522
20523 @smallexample
20524 -data-list-register-values @var{fmt} [ ( @var{regno} )*]
20525 @end smallexample
20526
20527 Display the registers' contents. @var{fmt} is the format according to
20528 which the registers' contents are to be returned, followed by an optional
20529 list of numbers specifying the registers to display. A missing list of
20530 numbers indicates that the contents of all the registers must be returned.
20531
20532 Allowed formats for @var{fmt} are:
20533
20534 @table @code
20535 @item x
20536 Hexadecimal
20537 @item o
20538 Octal
20539 @item t
20540 Binary
20541 @item d
20542 Decimal
20543 @item r
20544 Raw
20545 @item N
20546 Natural
20547 @end table
20548
20549 @subsubheading @value{GDBN} Command
20550
20551 The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
20552 all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
20553
20554 @subsubheading Example
20555
20556 For a PPC MBX board (note: line breaks are for readability only, they
20557 don't appear in the actual output):
20558
20559 @smallexample
20560 (gdb)
20561 -data-list-register-values r 64 65
20562 ^done,register-values=[@{number="64",value="0xfe00a300"@},
20563 @{number="65",value="0x00029002"@}]
20564 (gdb)
20565 -data-list-register-values x
20566 ^done,register-values=[@{number="0",value="0xfe0043c8"@},
20567 @{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
20568 @{number="3",value="0x0"@},@{number="4",value="0xa"@},
20569 @{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
20570 @{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
20571 @{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
20572 @{number="11",value="0x1"@},@{number="12",value="0x0"@},
20573 @{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
20574 @{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
20575 @{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
20576 @{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
20577 @{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
20578 @{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
20579 @{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
20580 @{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
20581 @{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
20582 @{number="31",value="0x0"@},@{number="32",value="0x0"@},
20583 @{number="33",value="0x0"@},@{number="34",value="0x0"@},
20584 @{number="35",value="0x0"@},@{number="36",value="0x0"@},
20585 @{number="37",value="0x0"@},@{number="38",value="0x0"@},
20586 @{number="39",value="0x0"@},@{number="40",value="0x0"@},
20587 @{number="41",value="0x0"@},@{number="42",value="0x0"@},
20588 @{number="43",value="0x0"@},@{number="44",value="0x0"@},
20589 @{number="45",value="0x0"@},@{number="46",value="0x0"@},
20590 @{number="47",value="0x0"@},@{number="48",value="0x0"@},
20591 @{number="49",value="0x0"@},@{number="50",value="0x0"@},
20592 @{number="51",value="0x0"@},@{number="52",value="0x0"@},
20593 @{number="53",value="0x0"@},@{number="54",value="0x0"@},
20594 @{number="55",value="0x0"@},@{number="56",value="0x0"@},
20595 @{number="57",value="0x0"@},@{number="58",value="0x0"@},
20596 @{number="59",value="0x0"@},@{number="60",value="0x0"@},
20597 @{number="61",value="0x0"@},@{number="62",value="0x0"@},
20598 @{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
20599 @{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
20600 @{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
20601 @{number="69",value="0x20002b03"@}]
20602 (gdb)
20603 @end smallexample
20604
20605
20606 @subheading The @code{-data-read-memory} Command
20607 @findex -data-read-memory
20608
20609 @subsubheading Synopsis
20610
20611 @smallexample
20612 -data-read-memory [ -o @var{byte-offset} ]
20613 @var{address} @var{word-format} @var{word-size}
20614 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
20615 @end smallexample
20616
20617 @noindent
20618 where:
20619
20620 @table @samp
20621 @item @var{address}
20622 An expression specifying the address of the first memory word to be
20623 read. Complex expressions containing embedded white space should be
20624 quoted using the C convention.
20625
20626 @item @var{word-format}
20627 The format to be used to print the memory words. The notation is the
20628 same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
20629 ,Output Formats}).
20630
20631 @item @var{word-size}
20632 The size of each memory word in bytes.
20633
20634 @item @var{nr-rows}
20635 The number of rows in the output table.
20636
20637 @item @var{nr-cols}
20638 The number of columns in the output table.
20639
20640 @item @var{aschar}
20641 If present, indicates that each row should include an @sc{ascii} dump. The
20642 value of @var{aschar} is used as a padding character when a byte is not a
20643 member of the printable @sc{ascii} character set (printable @sc{ascii}
20644 characters are those whose code is between 32 and 126, inclusively).
20645
20646 @item @var{byte-offset}
20647 An offset to add to the @var{address} before fetching memory.
20648 @end table
20649
20650 This command displays memory contents as a table of @var{nr-rows} by
20651 @var{nr-cols} words, each word being @var{word-size} bytes. In total,
20652 @code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
20653 (returned as @samp{total-bytes}). Should less than the requested number
20654 of bytes be returned by the target, the missing words are identified
20655 using @samp{N/A}. The number of bytes read from the target is returned
20656 in @samp{nr-bytes} and the starting address used to read memory in
20657 @samp{addr}.
20658
20659 The address of the next/previous row or page is available in
20660 @samp{next-row} and @samp{prev-row}, @samp{next-page} and
20661 @samp{prev-page}.
20662
20663 @subsubheading @value{GDBN} Command
20664
20665 The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
20666 @samp{gdb_get_mem} memory read command.
20667
20668 @subsubheading Example
20669
20670 Read six bytes of memory starting at @code{bytes+6} but then offset by
20671 @code{-6} bytes. Format as three rows of two columns. One byte per
20672 word. Display each word in hex.
20673
20674 @smallexample
20675 (gdb)
20676 9-data-read-memory -o -6 -- bytes+6 x 1 3 2
20677 9^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
20678 next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
20679 prev-page="0x0000138a",memory=[
20680 @{addr="0x00001390",data=["0x00","0x01"]@},
20681 @{addr="0x00001392",data=["0x02","0x03"]@},
20682 @{addr="0x00001394",data=["0x04","0x05"]@}]
20683 (gdb)
20684 @end smallexample
20685
20686 Read two bytes of memory starting at address @code{shorts + 64} and
20687 display as a single word formatted in decimal.
20688
20689 @smallexample
20690 (gdb)
20691 5-data-read-memory shorts+64 d 2 1 1
20692 5^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
20693 next-row="0x00001512",prev-row="0x0000150e",
20694 next-page="0x00001512",prev-page="0x0000150e",memory=[
20695 @{addr="0x00001510",data=["128"]@}]
20696 (gdb)
20697 @end smallexample
20698
20699 Read thirty two bytes of memory starting at @code{bytes+16} and format
20700 as eight rows of four columns. Include a string encoding with @samp{x}
20701 used as the non-printable character.
20702
20703 @smallexample
20704 (gdb)
20705 4-data-read-memory bytes+16 x 1 8 4 x
20706 4^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
20707 next-row="0x000013c0",prev-row="0x0000139c",
20708 next-page="0x000013c0",prev-page="0x00001380",memory=[
20709 @{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
20710 @{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
20711 @{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
20712 @{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
20713 @{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
20714 @{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
20715 @{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
20716 @{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
20717 (gdb)
20718 @end smallexample
20719
20720 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20721 @node GDB/MI Tracepoint Commands
20722 @section @sc{gdb/mi} Tracepoint Commands
20723
20724 The tracepoint commands are not yet implemented.
20725
20726 @c @subheading -trace-actions
20727
20728 @c @subheading -trace-delete
20729
20730 @c @subheading -trace-disable
20731
20732 @c @subheading -trace-dump
20733
20734 @c @subheading -trace-enable
20735
20736 @c @subheading -trace-exists
20737
20738 @c @subheading -trace-find
20739
20740 @c @subheading -trace-frame-number
20741
20742 @c @subheading -trace-info
20743
20744 @c @subheading -trace-insert
20745
20746 @c @subheading -trace-list
20747
20748 @c @subheading -trace-pass-count
20749
20750 @c @subheading -trace-save
20751
20752 @c @subheading -trace-start
20753
20754 @c @subheading -trace-stop
20755
20756
20757 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20758 @node GDB/MI Symbol Query
20759 @section @sc{gdb/mi} Symbol Query Commands
20760
20761
20762 @subheading The @code{-symbol-info-address} Command
20763 @findex -symbol-info-address
20764
20765 @subsubheading Synopsis
20766
20767 @smallexample
20768 -symbol-info-address @var{symbol}
20769 @end smallexample
20770
20771 Describe where @var{symbol} is stored.
20772
20773 @subsubheading @value{GDBN} Command
20774
20775 The corresponding @value{GDBN} command is @samp{info address}.
20776
20777 @subsubheading Example
20778 N.A.
20779
20780
20781 @subheading The @code{-symbol-info-file} Command
20782 @findex -symbol-info-file
20783
20784 @subsubheading Synopsis
20785
20786 @smallexample
20787 -symbol-info-file
20788 @end smallexample
20789
20790 Show the file for the symbol.
20791
20792 @subsubheading @value{GDBN} Command
20793
20794 There's no equivalent @value{GDBN} command. @code{gdbtk} has
20795 @samp{gdb_find_file}.
20796
20797 @subsubheading Example
20798 N.A.
20799
20800
20801 @subheading The @code{-symbol-info-function} Command
20802 @findex -symbol-info-function
20803
20804 @subsubheading Synopsis
20805
20806 @smallexample
20807 -symbol-info-function
20808 @end smallexample
20809
20810 Show which function the symbol lives in.
20811
20812 @subsubheading @value{GDBN} Command
20813
20814 @samp{gdb_get_function} in @code{gdbtk}.
20815
20816 @subsubheading Example
20817 N.A.
20818
20819
20820 @subheading The @code{-symbol-info-line} Command
20821 @findex -symbol-info-line
20822
20823 @subsubheading Synopsis
20824
20825 @smallexample
20826 -symbol-info-line
20827 @end smallexample
20828
20829 Show the core addresses of the code for a source line.
20830
20831 @subsubheading @value{GDBN} Command
20832
20833 The corresponding @value{GDBN} command is @samp{info line}.
20834 @code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
20835
20836 @subsubheading Example
20837 N.A.
20838
20839
20840 @subheading The @code{-symbol-info-symbol} Command
20841 @findex -symbol-info-symbol
20842
20843 @subsubheading Synopsis
20844
20845 @smallexample
20846 -symbol-info-symbol @var{addr}
20847 @end smallexample
20848
20849 Describe what symbol is at location @var{addr}.
20850
20851 @subsubheading @value{GDBN} Command
20852
20853 The corresponding @value{GDBN} command is @samp{info symbol}.
20854
20855 @subsubheading Example
20856 N.A.
20857
20858
20859 @subheading The @code{-symbol-list-functions} Command
20860 @findex -symbol-list-functions
20861
20862 @subsubheading Synopsis
20863
20864 @smallexample
20865 -symbol-list-functions
20866 @end smallexample
20867
20868 List the functions in the executable.
20869
20870 @subsubheading @value{GDBN} Command
20871
20872 @samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
20873 @samp{gdb_search} in @code{gdbtk}.
20874
20875 @subsubheading Example
20876 N.A.
20877
20878
20879 @subheading The @code{-symbol-list-lines} Command
20880 @findex -symbol-list-lines
20881
20882 @subsubheading Synopsis
20883
20884 @smallexample
20885 -symbol-list-lines @var{filename}
20886 @end smallexample
20887
20888 Print the list of lines that contain code and their associated program
20889 addresses for the given source filename. The entries are sorted in
20890 ascending PC order.
20891
20892 @subsubheading @value{GDBN} Command
20893
20894 There is no corresponding @value{GDBN} command.
20895
20896 @subsubheading Example
20897 @smallexample
20898 (gdb)
20899 -symbol-list-lines basics.c
20900 ^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
20901 (gdb)
20902 @end smallexample
20903
20904
20905 @subheading The @code{-symbol-list-types} Command
20906 @findex -symbol-list-types
20907
20908 @subsubheading Synopsis
20909
20910 @smallexample
20911 -symbol-list-types
20912 @end smallexample
20913
20914 List all the type names.
20915
20916 @subsubheading @value{GDBN} Command
20917
20918 The corresponding commands are @samp{info types} in @value{GDBN},
20919 @samp{gdb_search} in @code{gdbtk}.
20920
20921 @subsubheading Example
20922 N.A.
20923
20924
20925 @subheading The @code{-symbol-list-variables} Command
20926 @findex -symbol-list-variables
20927
20928 @subsubheading Synopsis
20929
20930 @smallexample
20931 -symbol-list-variables
20932 @end smallexample
20933
20934 List all the global and static variable names.
20935
20936 @subsubheading @value{GDBN} Command
20937
20938 @samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
20939
20940 @subsubheading Example
20941 N.A.
20942
20943
20944 @subheading The @code{-symbol-locate} Command
20945 @findex -symbol-locate
20946
20947 @subsubheading Synopsis
20948
20949 @smallexample
20950 -symbol-locate
20951 @end smallexample
20952
20953 @subsubheading @value{GDBN} Command
20954
20955 @samp{gdb_loc} in @code{gdbtk}.
20956
20957 @subsubheading Example
20958 N.A.
20959
20960
20961 @subheading The @code{-symbol-type} Command
20962 @findex -symbol-type
20963
20964 @subsubheading Synopsis
20965
20966 @smallexample
20967 -symbol-type @var{variable}
20968 @end smallexample
20969
20970 Show type of @var{variable}.
20971
20972 @subsubheading @value{GDBN} Command
20973
20974 The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
20975 @samp{gdb_obj_variable}.
20976
20977 @subsubheading Example
20978 N.A.
20979
20980
20981 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20982 @node GDB/MI File Commands
20983 @section @sc{gdb/mi} File Commands
20984
20985 This section describes the GDB/MI commands to specify executable file names
20986 and to read in and obtain symbol table information.
20987
20988 @subheading The @code{-file-exec-and-symbols} Command
20989 @findex -file-exec-and-symbols
20990
20991 @subsubheading Synopsis
20992
20993 @smallexample
20994 -file-exec-and-symbols @var{file}
20995 @end smallexample
20996
20997 Specify the executable file to be debugged. This file is the one from
20998 which the symbol table is also read. If no file is specified, the
20999 command clears the executable and symbol information. If breakpoints
21000 are set when using this command with no arguments, @value{GDBN} will produce
21001 error messages. Otherwise, no output is produced, except a completion
21002 notification.
21003
21004 @subsubheading @value{GDBN} Command
21005
21006 The corresponding @value{GDBN} command is @samp{file}.
21007
21008 @subsubheading Example
21009
21010 @smallexample
21011 (gdb)
21012 -file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
21013 ^done
21014 (gdb)
21015 @end smallexample
21016
21017
21018 @subheading The @code{-file-exec-file} Command
21019 @findex -file-exec-file
21020
21021 @subsubheading Synopsis
21022
21023 @smallexample
21024 -file-exec-file @var{file}
21025 @end smallexample
21026
21027 Specify the executable file to be debugged. Unlike
21028 @samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
21029 from this file. If used without argument, @value{GDBN} clears the information
21030 about the executable file. No output is produced, except a completion
21031 notification.
21032
21033 @subsubheading @value{GDBN} Command
21034
21035 The corresponding @value{GDBN} command is @samp{exec-file}.
21036
21037 @subsubheading Example
21038
21039 @smallexample
21040 (gdb)
21041 -file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
21042 ^done
21043 (gdb)
21044 @end smallexample
21045
21046
21047 @subheading The @code{-file-list-exec-sections} Command
21048 @findex -file-list-exec-sections
21049
21050 @subsubheading Synopsis
21051
21052 @smallexample
21053 -file-list-exec-sections
21054 @end smallexample
21055
21056 List the sections of the current executable file.
21057
21058 @subsubheading @value{GDBN} Command
21059
21060 The @value{GDBN} command @samp{info file} shows, among the rest, the same
21061 information as this command. @code{gdbtk} has a corresponding command
21062 @samp{gdb_load_info}.
21063
21064 @subsubheading Example
21065 N.A.
21066
21067
21068 @subheading The @code{-file-list-exec-source-file} Command
21069 @findex -file-list-exec-source-file
21070
21071 @subsubheading Synopsis
21072
21073 @smallexample
21074 -file-list-exec-source-file
21075 @end smallexample
21076
21077 List the line number, the current source file, and the absolute path
21078 to the current source file for the current executable. The macro
21079 information field has a value of @samp{1} or @samp{0} depending on
21080 whether or not the file includes preprocessor macro information.
21081
21082 @subsubheading @value{GDBN} Command
21083
21084 The @value{GDBN} equivalent is @samp{info source}
21085
21086 @subsubheading Example
21087
21088 @smallexample
21089 (gdb)
21090 123-file-list-exec-source-file
21091 123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
21092 (gdb)
21093 @end smallexample
21094
21095
21096 @subheading The @code{-file-list-exec-source-files} Command
21097 @findex -file-list-exec-source-files
21098
21099 @subsubheading Synopsis
21100
21101 @smallexample
21102 -file-list-exec-source-files
21103 @end smallexample
21104
21105 List the source files for the current executable.
21106
21107 It will always output the filename, but only when @value{GDBN} can find
21108 the absolute file name of a source file, will it output the fullname.
21109
21110 @subsubheading @value{GDBN} Command
21111
21112 The @value{GDBN} equivalent is @samp{info sources}.
21113 @code{gdbtk} has an analogous command @samp{gdb_listfiles}.
21114
21115 @subsubheading Example
21116 @smallexample
21117 (gdb)
21118 -file-list-exec-source-files
21119 ^done,files=[
21120 @{file=foo.c,fullname=/home/foo.c@},
21121 @{file=/home/bar.c,fullname=/home/bar.c@},
21122 @{file=gdb_could_not_find_fullpath.c@}]
21123 (gdb)
21124 @end smallexample
21125
21126 @subheading The @code{-file-list-shared-libraries} Command
21127 @findex -file-list-shared-libraries
21128
21129 @subsubheading Synopsis
21130
21131 @smallexample
21132 -file-list-shared-libraries
21133 @end smallexample
21134
21135 List the shared libraries in the program.
21136
21137 @subsubheading @value{GDBN} Command
21138
21139 The corresponding @value{GDBN} command is @samp{info shared}.
21140
21141 @subsubheading Example
21142 N.A.
21143
21144
21145 @subheading The @code{-file-list-symbol-files} Command
21146 @findex -file-list-symbol-files
21147
21148 @subsubheading Synopsis
21149
21150 @smallexample
21151 -file-list-symbol-files
21152 @end smallexample
21153
21154 List symbol files.
21155
21156 @subsubheading @value{GDBN} Command
21157
21158 The corresponding @value{GDBN} command is @samp{info file} (part of it).
21159
21160 @subsubheading Example
21161 N.A.
21162
21163
21164 @subheading The @code{-file-symbol-file} Command
21165 @findex -file-symbol-file
21166
21167 @subsubheading Synopsis
21168
21169 @smallexample
21170 -file-symbol-file @var{file}
21171 @end smallexample
21172
21173 Read symbol table info from the specified @var{file} argument. When
21174 used without arguments, clears @value{GDBN}'s symbol table info. No output is
21175 produced, except for a completion notification.
21176
21177 @subsubheading @value{GDBN} Command
21178
21179 The corresponding @value{GDBN} command is @samp{symbol-file}.
21180
21181 @subsubheading Example
21182
21183 @smallexample
21184 (gdb)
21185 -file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
21186 ^done
21187 (gdb)
21188 @end smallexample
21189
21190 @ignore
21191 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21192 @node GDB/MI Memory Overlay Commands
21193 @section @sc{gdb/mi} Memory Overlay Commands
21194
21195 The memory overlay commands are not implemented.
21196
21197 @c @subheading -overlay-auto
21198
21199 @c @subheading -overlay-list-mapping-state
21200
21201 @c @subheading -overlay-list-overlays
21202
21203 @c @subheading -overlay-map
21204
21205 @c @subheading -overlay-off
21206
21207 @c @subheading -overlay-on
21208
21209 @c @subheading -overlay-unmap
21210
21211 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21212 @node GDB/MI Signal Handling Commands
21213 @section @sc{gdb/mi} Signal Handling Commands
21214
21215 Signal handling commands are not implemented.
21216
21217 @c @subheading -signal-handle
21218
21219 @c @subheading -signal-list-handle-actions
21220
21221 @c @subheading -signal-list-signal-types
21222 @end ignore
21223
21224
21225 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21226 @node GDB/MI Target Manipulation
21227 @section @sc{gdb/mi} Target Manipulation Commands
21228
21229
21230 @subheading The @code{-target-attach} Command
21231 @findex -target-attach
21232
21233 @subsubheading Synopsis
21234
21235 @smallexample
21236 -target-attach @var{pid} | @var{file}
21237 @end smallexample
21238
21239 Attach to a process @var{pid} or a file @var{file} outside of @value{GDBN}.
21240
21241 @subsubheading @value{GDBN} Command
21242
21243 The corresponding @value{GDBN} command is @samp{attach}.
21244
21245 @subsubheading Example
21246 N.A.
21247
21248
21249 @subheading The @code{-target-compare-sections} Command
21250 @findex -target-compare-sections
21251
21252 @subsubheading Synopsis
21253
21254 @smallexample
21255 -target-compare-sections [ @var{section} ]
21256 @end smallexample
21257
21258 Compare data of section @var{section} on target to the exec file.
21259 Without the argument, all sections are compared.
21260
21261 @subsubheading @value{GDBN} Command
21262
21263 The @value{GDBN} equivalent is @samp{compare-sections}.
21264
21265 @subsubheading Example
21266 N.A.
21267
21268
21269 @subheading The @code{-target-detach} Command
21270 @findex -target-detach
21271
21272 @subsubheading Synopsis
21273
21274 @smallexample
21275 -target-detach
21276 @end smallexample
21277
21278 Detach from the remote target which normally resumes its execution.
21279 There's no output.
21280
21281 @subsubheading @value{GDBN} Command
21282
21283 The corresponding @value{GDBN} command is @samp{detach}.
21284
21285 @subsubheading Example
21286
21287 @smallexample
21288 (gdb)
21289 -target-detach
21290 ^done
21291 (gdb)
21292 @end smallexample
21293
21294
21295 @subheading The @code{-target-disconnect} Command
21296 @findex -target-disconnect
21297
21298 @subsubheading Synopsis
21299
21300 @smallexample
21301 -target-disconnect
21302 @end smallexample
21303
21304 Disconnect from the remote target. There's no output and the target is
21305 generally not resumed.
21306
21307 @subsubheading @value{GDBN} Command
21308
21309 The corresponding @value{GDBN} command is @samp{disconnect}.
21310
21311 @subsubheading Example
21312
21313 @smallexample
21314 (gdb)
21315 -target-disconnect
21316 ^done
21317 (gdb)
21318 @end smallexample
21319
21320
21321 @subheading The @code{-target-download} Command
21322 @findex -target-download
21323
21324 @subsubheading Synopsis
21325
21326 @smallexample
21327 -target-download
21328 @end smallexample
21329
21330 Loads the executable onto the remote target.
21331 It prints out an update message every half second, which includes the fields:
21332
21333 @table @samp
21334 @item section
21335 The name of the section.
21336 @item section-sent
21337 The size of what has been sent so far for that section.
21338 @item section-size
21339 The size of the section.
21340 @item total-sent
21341 The total size of what was sent so far (the current and the previous sections).
21342 @item total-size
21343 The size of the overall executable to download.
21344 @end table
21345
21346 @noindent
21347 Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
21348 @sc{gdb/mi} Output Syntax}).
21349
21350 In addition, it prints the name and size of the sections, as they are
21351 downloaded. These messages include the following fields:
21352
21353 @table @samp
21354 @item section
21355 The name of the section.
21356 @item section-size
21357 The size of the section.
21358 @item total-size
21359 The size of the overall executable to download.
21360 @end table
21361
21362 @noindent
21363 At the end, a summary is printed.
21364
21365 @subsubheading @value{GDBN} Command
21366
21367 The corresponding @value{GDBN} command is @samp{load}.
21368
21369 @subsubheading Example
21370
21371 Note: each status message appears on a single line. Here the messages
21372 have been broken down so that they can fit onto a page.
21373
21374 @smallexample
21375 (gdb)
21376 -target-download
21377 +download,@{section=".text",section-size="6668",total-size="9880"@}
21378 +download,@{section=".text",section-sent="512",section-size="6668",
21379 total-sent="512",total-size="9880"@}
21380 +download,@{section=".text",section-sent="1024",section-size="6668",
21381 total-sent="1024",total-size="9880"@}
21382 +download,@{section=".text",section-sent="1536",section-size="6668",
21383 total-sent="1536",total-size="9880"@}
21384 +download,@{section=".text",section-sent="2048",section-size="6668",
21385 total-sent="2048",total-size="9880"@}
21386 +download,@{section=".text",section-sent="2560",section-size="6668",
21387 total-sent="2560",total-size="9880"@}
21388 +download,@{section=".text",section-sent="3072",section-size="6668",
21389 total-sent="3072",total-size="9880"@}
21390 +download,@{section=".text",section-sent="3584",section-size="6668",
21391 total-sent="3584",total-size="9880"@}
21392 +download,@{section=".text",section-sent="4096",section-size="6668",
21393 total-sent="4096",total-size="9880"@}
21394 +download,@{section=".text",section-sent="4608",section-size="6668",
21395 total-sent="4608",total-size="9880"@}
21396 +download,@{section=".text",section-sent="5120",section-size="6668",
21397 total-sent="5120",total-size="9880"@}
21398 +download,@{section=".text",section-sent="5632",section-size="6668",
21399 total-sent="5632",total-size="9880"@}
21400 +download,@{section=".text",section-sent="6144",section-size="6668",
21401 total-sent="6144",total-size="9880"@}
21402 +download,@{section=".text",section-sent="6656",section-size="6668",
21403 total-sent="6656",total-size="9880"@}
21404 +download,@{section=".init",section-size="28",total-size="9880"@}
21405 +download,@{section=".fini",section-size="28",total-size="9880"@}
21406 +download,@{section=".data",section-size="3156",total-size="9880"@}
21407 +download,@{section=".data",section-sent="512",section-size="3156",
21408 total-sent="7236",total-size="9880"@}
21409 +download,@{section=".data",section-sent="1024",section-size="3156",
21410 total-sent="7748",total-size="9880"@}
21411 +download,@{section=".data",section-sent="1536",section-size="3156",
21412 total-sent="8260",total-size="9880"@}
21413 +download,@{section=".data",section-sent="2048",section-size="3156",
21414 total-sent="8772",total-size="9880"@}
21415 +download,@{section=".data",section-sent="2560",section-size="3156",
21416 total-sent="9284",total-size="9880"@}
21417 +download,@{section=".data",section-sent="3072",section-size="3156",
21418 total-sent="9796",total-size="9880"@}
21419 ^done,address="0x10004",load-size="9880",transfer-rate="6586",
21420 write-rate="429"
21421 (gdb)
21422 @end smallexample
21423
21424
21425 @subheading The @code{-target-exec-status} Command
21426 @findex -target-exec-status
21427
21428 @subsubheading Synopsis
21429
21430 @smallexample
21431 -target-exec-status
21432 @end smallexample
21433
21434 Provide information on the state of the target (whether it is running or
21435 not, for instance).
21436
21437 @subsubheading @value{GDBN} Command
21438
21439 There's no equivalent @value{GDBN} command.
21440
21441 @subsubheading Example
21442 N.A.
21443
21444
21445 @subheading The @code{-target-list-available-targets} Command
21446 @findex -target-list-available-targets
21447
21448 @subsubheading Synopsis
21449
21450 @smallexample
21451 -target-list-available-targets
21452 @end smallexample
21453
21454 List the possible targets to connect to.
21455
21456 @subsubheading @value{GDBN} Command
21457
21458 The corresponding @value{GDBN} command is @samp{help target}.
21459
21460 @subsubheading Example
21461 N.A.
21462
21463
21464 @subheading The @code{-target-list-current-targets} Command
21465 @findex -target-list-current-targets
21466
21467 @subsubheading Synopsis
21468
21469 @smallexample
21470 -target-list-current-targets
21471 @end smallexample
21472
21473 Describe the current target.
21474
21475 @subsubheading @value{GDBN} Command
21476
21477 The corresponding information is printed by @samp{info file} (among
21478 other things).
21479
21480 @subsubheading Example
21481 N.A.
21482
21483
21484 @subheading The @code{-target-list-parameters} Command
21485 @findex -target-list-parameters
21486
21487 @subsubheading Synopsis
21488
21489 @smallexample
21490 -target-list-parameters
21491 @end smallexample
21492
21493 @c ????
21494
21495 @subsubheading @value{GDBN} Command
21496
21497 No equivalent.
21498
21499 @subsubheading Example
21500 N.A.
21501
21502
21503 @subheading The @code{-target-select} Command
21504 @findex -target-select
21505
21506 @subsubheading Synopsis
21507
21508 @smallexample
21509 -target-select @var{type} @var{parameters @dots{}}
21510 @end smallexample
21511
21512 Connect @value{GDBN} to the remote target. This command takes two args:
21513
21514 @table @samp
21515 @item @var{type}
21516 The type of target, for instance @samp{async}, @samp{remote}, etc.
21517 @item @var{parameters}
21518 Device names, host names and the like. @xref{Target Commands, ,
21519 Commands for Managing Targets}, for more details.
21520 @end table
21521
21522 The output is a connection notification, followed by the address at
21523 which the target program is, in the following form:
21524
21525 @smallexample
21526 ^connected,addr="@var{address}",func="@var{function name}",
21527 args=[@var{arg list}]
21528 @end smallexample
21529
21530 @subsubheading @value{GDBN} Command
21531
21532 The corresponding @value{GDBN} command is @samp{target}.
21533
21534 @subsubheading Example
21535
21536 @smallexample
21537 (gdb)
21538 -target-select async /dev/ttya
21539 ^connected,addr="0xfe00a300",func="??",args=[]
21540 (gdb)
21541 @end smallexample
21542
21543 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21544 @node GDB/MI File Transfer Commands
21545 @section @sc{gdb/mi} File Transfer Commands
21546
21547
21548 @subheading The @code{-target-file-put} Command
21549 @findex -target-file-put
21550
21551 @subsubheading Synopsis
21552
21553 @smallexample
21554 -target-file-put @var{hostfile} @var{targetfile}
21555 @end smallexample
21556
21557 Copy file @var{hostfile} from the host system (the machine running
21558 @value{GDBN}) to @var{targetfile} on the target system.
21559
21560 @subsubheading @value{GDBN} Command
21561
21562 The corresponding @value{GDBN} command is @samp{remote put}.
21563
21564 @subsubheading Example
21565
21566 @smallexample
21567 (gdb)
21568 -target-file-put localfile remotefile
21569 ^done
21570 (gdb)
21571 @end smallexample
21572
21573
21574 @subheading The @code{-target-file-put} Command
21575 @findex -target-file-get
21576
21577 @subsubheading Synopsis
21578
21579 @smallexample
21580 -target-file-get @var{targetfile} @var{hostfile}
21581 @end smallexample
21582
21583 Copy file @var{targetfile} from the target system to @var{hostfile}
21584 on the host system.
21585
21586 @subsubheading @value{GDBN} Command
21587
21588 The corresponding @value{GDBN} command is @samp{remote get}.
21589
21590 @subsubheading Example
21591
21592 @smallexample
21593 (gdb)
21594 -target-file-get remotefile localfile
21595 ^done
21596 (gdb)
21597 @end smallexample
21598
21599
21600 @subheading The @code{-target-file-delete} Command
21601 @findex -target-file-delete
21602
21603 @subsubheading Synopsis
21604
21605 @smallexample
21606 -target-file-delete @var{targetfile}
21607 @end smallexample
21608
21609 Delete @var{targetfile} from the target system.
21610
21611 @subsubheading @value{GDBN} Command
21612
21613 The corresponding @value{GDBN} command is @samp{remote delete}.
21614
21615 @subsubheading Example
21616
21617 @smallexample
21618 (gdb)
21619 -target-file-delete remotefile
21620 ^done
21621 (gdb)
21622 @end smallexample
21623
21624
21625 @c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21626 @node GDB/MI Miscellaneous Commands
21627 @section Miscellaneous @sc{gdb/mi} Commands
21628
21629 @c @subheading -gdb-complete
21630
21631 @subheading The @code{-gdb-exit} Command
21632 @findex -gdb-exit
21633
21634 @subsubheading Synopsis
21635
21636 @smallexample
21637 -gdb-exit
21638 @end smallexample
21639
21640 Exit @value{GDBN} immediately.
21641
21642 @subsubheading @value{GDBN} Command
21643
21644 Approximately corresponds to @samp{quit}.
21645
21646 @subsubheading Example
21647
21648 @smallexample
21649 (gdb)
21650 -gdb-exit
21651 ^exit
21652 @end smallexample
21653
21654
21655 @subheading The @code{-exec-abort} Command
21656 @findex -exec-abort
21657
21658 @subsubheading Synopsis
21659
21660 @smallexample
21661 -exec-abort
21662 @end smallexample
21663
21664 Kill the inferior running program.
21665
21666 @subsubheading @value{GDBN} Command
21667
21668 The corresponding @value{GDBN} command is @samp{kill}.
21669
21670 @subsubheading Example
21671 N.A.
21672
21673
21674 @subheading The @code{-gdb-set} Command
21675 @findex -gdb-set
21676
21677 @subsubheading Synopsis
21678
21679 @smallexample
21680 -gdb-set
21681 @end smallexample
21682
21683 Set an internal @value{GDBN} variable.
21684 @c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
21685
21686 @subsubheading @value{GDBN} Command
21687
21688 The corresponding @value{GDBN} command is @samp{set}.
21689
21690 @subsubheading Example
21691
21692 @smallexample
21693 (gdb)
21694 -gdb-set $foo=3
21695 ^done
21696 (gdb)
21697 @end smallexample
21698
21699
21700 @subheading The @code{-gdb-show} Command
21701 @findex -gdb-show
21702
21703 @subsubheading Synopsis
21704
21705 @smallexample
21706 -gdb-show
21707 @end smallexample
21708
21709 Show the current value of a @value{GDBN} variable.
21710
21711 @subsubheading @value{GDBN} Command
21712
21713 The corresponding @value{GDBN} command is @samp{show}.
21714
21715 @subsubheading Example
21716
21717 @smallexample
21718 (gdb)
21719 -gdb-show annotate
21720 ^done,value="0"
21721 (gdb)
21722 @end smallexample
21723
21724 @c @subheading -gdb-source
21725
21726
21727 @subheading The @code{-gdb-version} Command
21728 @findex -gdb-version
21729
21730 @subsubheading Synopsis
21731
21732 @smallexample
21733 -gdb-version
21734 @end smallexample
21735
21736 Show version information for @value{GDBN}. Used mostly in testing.
21737
21738 @subsubheading @value{GDBN} Command
21739
21740 The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
21741 default shows this information when you start an interactive session.
21742
21743 @subsubheading Example
21744
21745 @c This example modifies the actual output from GDB to avoid overfull
21746 @c box in TeX.
21747 @smallexample
21748 (gdb)
21749 -gdb-version
21750 ~GNU gdb 5.2.1
21751 ~Copyright 2000 Free Software Foundation, Inc.
21752 ~GDB is free software, covered by the GNU General Public License, and
21753 ~you are welcome to change it and/or distribute copies of it under
21754 ~ certain conditions.
21755 ~Type "show copying" to see the conditions.
21756 ~There is absolutely no warranty for GDB. Type "show warranty" for
21757 ~ details.
21758 ~This GDB was configured as
21759 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
21760 ^done
21761 (gdb)
21762 @end smallexample
21763
21764 @subheading The @code{-list-features} Command
21765 @findex -list-features
21766
21767 Returns a list of particular features of the MI protocol that
21768 this version of gdb implements. A feature can be a command,
21769 or a new field in an output of some command, or even an
21770 important bugfix. While a frontend can sometimes detect presence
21771 of a feature at runtime, it is easier to perform detection at debugger
21772 startup.
21773
21774 The command returns a list of strings, with each string naming an
21775 available feature. Each returned string is just a name, it does not
21776 have any internal structure. The list of possible feature names
21777 is given below.
21778
21779 Example output:
21780
21781 @smallexample
21782 (gdb) -list-features
21783 ^done,result=["feature1","feature2"]
21784 @end smallexample
21785
21786 The current list of features is:
21787
21788 @itemize @minus
21789 @item
21790 @samp{frozen-varobjs}---indicates presence of the
21791 @code{-var-set-frozen} command, as well as possible presense of the
21792 @code{frozen} field in the output of @code{-varobj-create}.
21793 @item
21794 @samp{pending-breakpoints}---indicates presence of the @code{-f}
21795 option to the @code{-break-insert} command.
21796
21797 @end itemize
21798
21799 @subheading The @code{-interpreter-exec} Command
21800 @findex -interpreter-exec
21801
21802 @subheading Synopsis
21803
21804 @smallexample
21805 -interpreter-exec @var{interpreter} @var{command}
21806 @end smallexample
21807 @anchor{-interpreter-exec}
21808
21809 Execute the specified @var{command} in the given @var{interpreter}.
21810
21811 @subheading @value{GDBN} Command
21812
21813 The corresponding @value{GDBN} command is @samp{interpreter-exec}.
21814
21815 @subheading Example
21816
21817 @smallexample
21818 (gdb)
21819 -interpreter-exec console "break main"
21820 &"During symbol reading, couldn't parse type; debugger out of date?.\n"
21821 &"During symbol reading, bad structure-type format.\n"
21822 ~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
21823 ^done
21824 (gdb)
21825 @end smallexample
21826
21827 @subheading The @code{-inferior-tty-set} Command
21828 @findex -inferior-tty-set
21829
21830 @subheading Synopsis
21831
21832 @smallexample
21833 -inferior-tty-set /dev/pts/1
21834 @end smallexample
21835
21836 Set terminal for future runs of the program being debugged.
21837
21838 @subheading @value{GDBN} Command
21839
21840 The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
21841
21842 @subheading Example
21843
21844 @smallexample
21845 (gdb)
21846 -inferior-tty-set /dev/pts/1
21847 ^done
21848 (gdb)
21849 @end smallexample
21850
21851 @subheading The @code{-inferior-tty-show} Command
21852 @findex -inferior-tty-show
21853
21854 @subheading Synopsis
21855
21856 @smallexample
21857 -inferior-tty-show
21858 @end smallexample
21859
21860 Show terminal for future runs of program being debugged.
21861
21862 @subheading @value{GDBN} Command
21863
21864 The corresponding @value{GDBN} command is @samp{show inferior-tty}.
21865
21866 @subheading Example
21867
21868 @smallexample
21869 (gdb)
21870 -inferior-tty-set /dev/pts/1
21871 ^done
21872 (gdb)
21873 -inferior-tty-show
21874 ^done,inferior_tty_terminal="/dev/pts/1"
21875 (gdb)
21876 @end smallexample
21877
21878 @subheading The @code{-enable-timings} Command
21879 @findex -enable-timings
21880
21881 @subheading Synopsis
21882
21883 @smallexample
21884 -enable-timings [yes | no]
21885 @end smallexample
21886
21887 Toggle the printing of the wallclock, user and system times for an MI
21888 command as a field in its output. This command is to help frontend
21889 developers optimize the performance of their code. No argument is
21890 equivalent to @samp{yes}.
21891
21892 @subheading @value{GDBN} Command
21893
21894 No equivalent.
21895
21896 @subheading Example
21897
21898 @smallexample
21899 (gdb)
21900 -enable-timings
21901 ^done
21902 (gdb)
21903 -break-insert main
21904 ^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
21905 addr="0x080484ed",func="main",file="myprog.c",
21906 fullname="/home/nickrob/myprog.c",line="73",times="0"@},
21907 time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
21908 (gdb)
21909 -enable-timings no
21910 ^done
21911 (gdb)
21912 -exec-run
21913 ^running
21914 (gdb)
21915 *stopped,reason="breakpoint-hit",bkptno="1",thread-id="0",
21916 frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
21917 @{name="argv",value="0xbfb60364"@}],file="myprog.c",
21918 fullname="/home/nickrob/myprog.c",line="73"@}
21919 (gdb)
21920 @end smallexample
21921
21922 @node Annotations
21923 @chapter @value{GDBN} Annotations
21924
21925 This chapter describes annotations in @value{GDBN}. Annotations were
21926 designed to interface @value{GDBN} to graphical user interfaces or other
21927 similar programs which want to interact with @value{GDBN} at a
21928 relatively high level.
21929
21930 The annotation mechanism has largely been superseded by @sc{gdb/mi}
21931 (@pxref{GDB/MI}).
21932
21933 @ignore
21934 This is Edition @value{EDITION}, @value{DATE}.
21935 @end ignore
21936
21937 @menu
21938 * Annotations Overview:: What annotations are; the general syntax.
21939 * Server Prefix:: Issuing a command without affecting user state.
21940 * Prompting:: Annotations marking @value{GDBN}'s need for input.
21941 * Errors:: Annotations for error messages.
21942 * Invalidation:: Some annotations describe things now invalid.
21943 * Annotations for Running::
21944 Whether the program is running, how it stopped, etc.
21945 * Source Annotations:: Annotations describing source code.
21946 @end menu
21947
21948 @node Annotations Overview
21949 @section What is an Annotation?
21950 @cindex annotations
21951
21952 Annotations start with a newline character, two @samp{control-z}
21953 characters, and the name of the annotation. If there is no additional
21954 information associated with this annotation, the name of the annotation
21955 is followed immediately by a newline. If there is additional
21956 information, the name of the annotation is followed by a space, the
21957 additional information, and a newline. The additional information
21958 cannot contain newline characters.
21959
21960 Any output not beginning with a newline and two @samp{control-z}
21961 characters denotes literal output from @value{GDBN}. Currently there is
21962 no need for @value{GDBN} to output a newline followed by two
21963 @samp{control-z} characters, but if there was such a need, the
21964 annotations could be extended with an @samp{escape} annotation which
21965 means those three characters as output.
21966
21967 The annotation @var{level}, which is specified using the
21968 @option{--annotate} command line option (@pxref{Mode Options}), controls
21969 how much information @value{GDBN} prints together with its prompt,
21970 values of expressions, source lines, and other types of output. Level 0
21971 is for no annotations, level 1 is for use when @value{GDBN} is run as a
21972 subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
21973 for programs that control @value{GDBN}, and level 2 annotations have
21974 been made obsolete (@pxref{Limitations, , Limitations of the Annotation
21975 Interface, annotate, GDB's Obsolete Annotations}).
21976
21977 @table @code
21978 @kindex set annotate
21979 @item set annotate @var{level}
21980 The @value{GDBN} command @code{set annotate} sets the level of
21981 annotations to the specified @var{level}.
21982
21983 @item show annotate
21984 @kindex show annotate
21985 Show the current annotation level.
21986 @end table
21987
21988 This chapter describes level 3 annotations.
21989
21990 A simple example of starting up @value{GDBN} with annotations is:
21991
21992 @smallexample
21993 $ @kbd{gdb --annotate=3}
21994 GNU gdb 6.0
21995 Copyright 2003 Free Software Foundation, Inc.
21996 GDB is free software, covered by the GNU General Public License,
21997 and you are welcome to change it and/or distribute copies of it
21998 under certain conditions.
21999 Type "show copying" to see the conditions.
22000 There is absolutely no warranty for GDB. Type "show warranty"
22001 for details.
22002 This GDB was configured as "i386-pc-linux-gnu"
22003
22004 ^Z^Zpre-prompt
22005 (@value{GDBP})
22006 ^Z^Zprompt
22007 @kbd{quit}
22008
22009 ^Z^Zpost-prompt
22010 $
22011 @end smallexample
22012
22013 Here @samp{quit} is input to @value{GDBN}; the rest is output from
22014 @value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
22015 denotes a @samp{control-z} character) are annotations; the rest is
22016 output from @value{GDBN}.
22017
22018 @node Server Prefix
22019 @section The Server Prefix
22020 @cindex server prefix
22021
22022 If you prefix a command with @samp{server } then it will not affect
22023 the command history, nor will it affect @value{GDBN}'s notion of which
22024 command to repeat if @key{RET} is pressed on a line by itself. This
22025 means that commands can be run behind a user's back by a front-end in
22026 a transparent manner.
22027
22028 The server prefix does not affect the recording of values into the value
22029 history; to print a value without recording it into the value history,
22030 use the @code{output} command instead of the @code{print} command.
22031
22032 @node Prompting
22033 @section Annotation for @value{GDBN} Input
22034
22035 @cindex annotations for prompts
22036 When @value{GDBN} prompts for input, it annotates this fact so it is possible
22037 to know when to send output, when the output from a given command is
22038 over, etc.
22039
22040 Different kinds of input each have a different @dfn{input type}. Each
22041 input type has three annotations: a @code{pre-} annotation, which
22042 denotes the beginning of any prompt which is being output, a plain
22043 annotation, which denotes the end of the prompt, and then a @code{post-}
22044 annotation which denotes the end of any echo which may (or may not) be
22045 associated with the input. For example, the @code{prompt} input type
22046 features the following annotations:
22047
22048 @smallexample
22049 ^Z^Zpre-prompt
22050 ^Z^Zprompt
22051 ^Z^Zpost-prompt
22052 @end smallexample
22053
22054 The input types are
22055
22056 @table @code
22057 @findex pre-prompt annotation
22058 @findex prompt annotation
22059 @findex post-prompt annotation
22060 @item prompt
22061 When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
22062
22063 @findex pre-commands annotation
22064 @findex commands annotation
22065 @findex post-commands annotation
22066 @item commands
22067 When @value{GDBN} prompts for a set of commands, like in the @code{commands}
22068 command. The annotations are repeated for each command which is input.
22069
22070 @findex pre-overload-choice annotation
22071 @findex overload-choice annotation
22072 @findex post-overload-choice annotation
22073 @item overload-choice
22074 When @value{GDBN} wants the user to select between various overloaded functions.
22075
22076 @findex pre-query annotation
22077 @findex query annotation
22078 @findex post-query annotation
22079 @item query
22080 When @value{GDBN} wants the user to confirm a potentially dangerous operation.
22081
22082 @findex pre-prompt-for-continue annotation
22083 @findex prompt-for-continue annotation
22084 @findex post-prompt-for-continue annotation
22085 @item prompt-for-continue
22086 When @value{GDBN} is asking the user to press return to continue. Note: Don't
22087 expect this to work well; instead use @code{set height 0} to disable
22088 prompting. This is because the counting of lines is buggy in the
22089 presence of annotations.
22090 @end table
22091
22092 @node Errors
22093 @section Errors
22094 @cindex annotations for errors, warnings and interrupts
22095
22096 @findex quit annotation
22097 @smallexample
22098 ^Z^Zquit
22099 @end smallexample
22100
22101 This annotation occurs right before @value{GDBN} responds to an interrupt.
22102
22103 @findex error annotation
22104 @smallexample
22105 ^Z^Zerror
22106 @end smallexample
22107
22108 This annotation occurs right before @value{GDBN} responds to an error.
22109
22110 Quit and error annotations indicate that any annotations which @value{GDBN} was
22111 in the middle of may end abruptly. For example, if a
22112 @code{value-history-begin} annotation is followed by a @code{error}, one
22113 cannot expect to receive the matching @code{value-history-end}. One
22114 cannot expect not to receive it either, however; an error annotation
22115 does not necessarily mean that @value{GDBN} is immediately returning all the way
22116 to the top level.
22117
22118 @findex error-begin annotation
22119 A quit or error annotation may be preceded by
22120
22121 @smallexample
22122 ^Z^Zerror-begin
22123 @end smallexample
22124
22125 Any output between that and the quit or error annotation is the error
22126 message.
22127
22128 Warning messages are not yet annotated.
22129 @c If we want to change that, need to fix warning(), type_error(),
22130 @c range_error(), and possibly other places.
22131
22132 @node Invalidation
22133 @section Invalidation Notices
22134
22135 @cindex annotations for invalidation messages
22136 The following annotations say that certain pieces of state may have
22137 changed.
22138
22139 @table @code
22140 @findex frames-invalid annotation
22141 @item ^Z^Zframes-invalid
22142
22143 The frames (for example, output from the @code{backtrace} command) may
22144 have changed.
22145
22146 @findex breakpoints-invalid annotation
22147 @item ^Z^Zbreakpoints-invalid
22148
22149 The breakpoints may have changed. For example, the user just added or
22150 deleted a breakpoint.
22151 @end table
22152
22153 @node Annotations for Running
22154 @section Running the Program
22155 @cindex annotations for running programs
22156
22157 @findex starting annotation
22158 @findex stopping annotation
22159 When the program starts executing due to a @value{GDBN} command such as
22160 @code{step} or @code{continue},
22161
22162 @smallexample
22163 ^Z^Zstarting
22164 @end smallexample
22165
22166 is output. When the program stops,
22167
22168 @smallexample
22169 ^Z^Zstopped
22170 @end smallexample
22171
22172 is output. Before the @code{stopped} annotation, a variety of
22173 annotations describe how the program stopped.
22174
22175 @table @code
22176 @findex exited annotation
22177 @item ^Z^Zexited @var{exit-status}
22178 The program exited, and @var{exit-status} is the exit status (zero for
22179 successful exit, otherwise nonzero).
22180
22181 @findex signalled annotation
22182 @findex signal-name annotation
22183 @findex signal-name-end annotation
22184 @findex signal-string annotation
22185 @findex signal-string-end annotation
22186 @item ^Z^Zsignalled
22187 The program exited with a signal. After the @code{^Z^Zsignalled}, the
22188 annotation continues:
22189
22190 @smallexample
22191 @var{intro-text}
22192 ^Z^Zsignal-name
22193 @var{name}
22194 ^Z^Zsignal-name-end
22195 @var{middle-text}
22196 ^Z^Zsignal-string
22197 @var{string}
22198 ^Z^Zsignal-string-end
22199 @var{end-text}
22200 @end smallexample
22201
22202 @noindent
22203 where @var{name} is the name of the signal, such as @code{SIGILL} or
22204 @code{SIGSEGV}, and @var{string} is the explanation of the signal, such
22205 as @code{Illegal Instruction} or @code{Segmentation fault}.
22206 @var{intro-text}, @var{middle-text}, and @var{end-text} are for the
22207 user's benefit and have no particular format.
22208
22209 @findex signal annotation
22210 @item ^Z^Zsignal
22211 The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
22212 just saying that the program received the signal, not that it was
22213 terminated with it.
22214
22215 @findex breakpoint annotation
22216 @item ^Z^Zbreakpoint @var{number}
22217 The program hit breakpoint number @var{number}.
22218
22219 @findex watchpoint annotation
22220 @item ^Z^Zwatchpoint @var{number}
22221 The program hit watchpoint number @var{number}.
22222 @end table
22223
22224 @node Source Annotations
22225 @section Displaying Source
22226 @cindex annotations for source display
22227
22228 @findex source annotation
22229 The following annotation is used instead of displaying source code:
22230
22231 @smallexample
22232 ^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
22233 @end smallexample
22234
22235 where @var{filename} is an absolute file name indicating which source
22236 file, @var{line} is the line number within that file (where 1 is the
22237 first line in the file), @var{character} is the character position
22238 within the file (where 0 is the first character in the file) (for most
22239 debug formats this will necessarily point to the beginning of a line),
22240 @var{middle} is @samp{middle} if @var{addr} is in the middle of the
22241 line, or @samp{beg} if @var{addr} is at the beginning of the line, and
22242 @var{addr} is the address in the target program associated with the
22243 source which is being displayed. @var{addr} is in the form @samp{0x}
22244 followed by one or more lowercase hex digits (note that this does not
22245 depend on the language).
22246
22247 @node GDB Bugs
22248 @chapter Reporting Bugs in @value{GDBN}
22249 @cindex bugs in @value{GDBN}
22250 @cindex reporting bugs in @value{GDBN}
22251
22252 Your bug reports play an essential role in making @value{GDBN} reliable.
22253
22254 Reporting a bug may help you by bringing a solution to your problem, or it
22255 may not. But in any case the principal function of a bug report is to help
22256 the entire community by making the next version of @value{GDBN} work better. Bug
22257 reports are your contribution to the maintenance of @value{GDBN}.
22258
22259 In order for a bug report to serve its purpose, you must include the
22260 information that enables us to fix the bug.
22261
22262 @menu
22263 * Bug Criteria:: Have you found a bug?
22264 * Bug Reporting:: How to report bugs
22265 @end menu
22266
22267 @node Bug Criteria
22268 @section Have You Found a Bug?
22269 @cindex bug criteria
22270
22271 If you are not sure whether you have found a bug, here are some guidelines:
22272
22273 @itemize @bullet
22274 @cindex fatal signal
22275 @cindex debugger crash
22276 @cindex crash of debugger
22277 @item
22278 If the debugger gets a fatal signal, for any input whatever, that is a
22279 @value{GDBN} bug. Reliable debuggers never crash.
22280
22281 @cindex error on valid input
22282 @item
22283 If @value{GDBN} produces an error message for valid input, that is a
22284 bug. (Note that if you're cross debugging, the problem may also be
22285 somewhere in the connection to the target.)
22286
22287 @cindex invalid input
22288 @item
22289 If @value{GDBN} does not produce an error message for invalid input,
22290 that is a bug. However, you should note that your idea of
22291 ``invalid input'' might be our idea of ``an extension'' or ``support
22292 for traditional practice''.
22293
22294 @item
22295 If you are an experienced user of debugging tools, your suggestions
22296 for improvement of @value{GDBN} are welcome in any case.
22297 @end itemize
22298
22299 @node Bug Reporting
22300 @section How to Report Bugs
22301 @cindex bug reports
22302 @cindex @value{GDBN} bugs, reporting
22303
22304 A number of companies and individuals offer support for @sc{gnu} products.
22305 If you obtained @value{GDBN} from a support organization, we recommend you
22306 contact that organization first.
22307
22308 You can find contact information for many support companies and
22309 individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
22310 distribution.
22311 @c should add a web page ref...
22312
22313 In any event, we also recommend that you submit bug reports for
22314 @value{GDBN}. The preferred method is to submit them directly using
22315 @uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
22316 page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
22317 be used.
22318
22319 @strong{Do not send bug reports to @samp{info-gdb}, or to
22320 @samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
22321 not want to receive bug reports. Those that do have arranged to receive
22322 @samp{bug-gdb}.
22323
22324 The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
22325 serves as a repeater. The mailing list and the newsgroup carry exactly
22326 the same messages. Often people think of posting bug reports to the
22327 newsgroup instead of mailing them. This appears to work, but it has one
22328 problem which can be crucial: a newsgroup posting often lacks a mail
22329 path back to the sender. Thus, if we need to ask for more information,
22330 we may be unable to reach you. For this reason, it is better to send
22331 bug reports to the mailing list.
22332
22333 The fundamental principle of reporting bugs usefully is this:
22334 @strong{report all the facts}. If you are not sure whether to state a
22335 fact or leave it out, state it!
22336
22337 Often people omit facts because they think they know what causes the
22338 problem and assume that some details do not matter. Thus, you might
22339 assume that the name of the variable you use in an example does not matter.
22340 Well, probably it does not, but one cannot be sure. Perhaps the bug is a
22341 stray memory reference which happens to fetch from the location where that
22342 name is stored in memory; perhaps, if the name were different, the contents
22343 of that location would fool the debugger into doing the right thing despite
22344 the bug. Play it safe and give a specific, complete example. That is the
22345 easiest thing for you to do, and the most helpful.
22346
22347 Keep in mind that the purpose of a bug report is to enable us to fix the
22348 bug. It may be that the bug has been reported previously, but neither
22349 you nor we can know that unless your bug report is complete and
22350 self-contained.
22351
22352 Sometimes people give a few sketchy facts and ask, ``Does this ring a
22353 bell?'' Those bug reports are useless, and we urge everyone to
22354 @emph{refuse to respond to them} except to chide the sender to report
22355 bugs properly.
22356
22357 To enable us to fix the bug, you should include all these things:
22358
22359 @itemize @bullet
22360 @item
22361 The version of @value{GDBN}. @value{GDBN} announces it if you start
22362 with no arguments; you can also print it at any time using @code{show
22363 version}.
22364
22365 Without this, we will not know whether there is any point in looking for
22366 the bug in the current version of @value{GDBN}.
22367
22368 @item
22369 The type of machine you are using, and the operating system name and
22370 version number.
22371
22372 @item
22373 What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
22374 ``@value{GCC}--2.8.1''.
22375
22376 @item
22377 What compiler (and its version) was used to compile the program you are
22378 debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
22379 C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
22380 to get this information; for other compilers, see the documentation for
22381 those compilers.
22382
22383 @item
22384 The command arguments you gave the compiler to compile your example and
22385 observe the bug. For example, did you use @samp{-O}? To guarantee
22386 you will not omit something important, list them all. A copy of the
22387 Makefile (or the output from make) is sufficient.
22388
22389 If we were to try to guess the arguments, we would probably guess wrong
22390 and then we might not encounter the bug.
22391
22392 @item
22393 A complete input script, and all necessary source files, that will
22394 reproduce the bug.
22395
22396 @item
22397 A description of what behavior you observe that you believe is
22398 incorrect. For example, ``It gets a fatal signal.''
22399
22400 Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
22401 will certainly notice it. But if the bug is incorrect output, we might
22402 not notice unless it is glaringly wrong. You might as well not give us
22403 a chance to make a mistake.
22404
22405 Even if the problem you experience is a fatal signal, you should still
22406 say so explicitly. Suppose something strange is going on, such as, your
22407 copy of @value{GDBN} is out of synch, or you have encountered a bug in
22408 the C library on your system. (This has happened!) Your copy might
22409 crash and ours would not. If you told us to expect a crash, then when
22410 ours fails to crash, we would know that the bug was not happening for
22411 us. If you had not told us to expect a crash, then we would not be able
22412 to draw any conclusion from our observations.
22413
22414 @pindex script
22415 @cindex recording a session script
22416 To collect all this information, you can use a session recording program
22417 such as @command{script}, which is available on many Unix systems.
22418 Just run your @value{GDBN} session inside @command{script} and then
22419 include the @file{typescript} file with your bug report.
22420
22421 Another way to record a @value{GDBN} session is to run @value{GDBN}
22422 inside Emacs and then save the entire buffer to a file.
22423
22424 @item
22425 If you wish to suggest changes to the @value{GDBN} source, send us context
22426 diffs. If you even discuss something in the @value{GDBN} source, refer to
22427 it by context, not by line number.
22428
22429 The line numbers in our development sources will not match those in your
22430 sources. Your line numbers would convey no useful information to us.
22431
22432 @end itemize
22433
22434 Here are some things that are not necessary:
22435
22436 @itemize @bullet
22437 @item
22438 A description of the envelope of the bug.
22439
22440 Often people who encounter a bug spend a lot of time investigating
22441 which changes to the input file will make the bug go away and which
22442 changes will not affect it.
22443
22444 This is often time consuming and not very useful, because the way we
22445 will find the bug is by running a single example under the debugger
22446 with breakpoints, not by pure deduction from a series of examples.
22447 We recommend that you save your time for something else.
22448
22449 Of course, if you can find a simpler example to report @emph{instead}
22450 of the original one, that is a convenience for us. Errors in the
22451 output will be easier to spot, running under the debugger will take
22452 less time, and so on.
22453
22454 However, simplification is not vital; if you do not want to do this,
22455 report the bug anyway and send us the entire test case you used.
22456
22457 @item
22458 A patch for the bug.
22459
22460 A patch for the bug does help us if it is a good one. But do not omit
22461 the necessary information, such as the test case, on the assumption that
22462 a patch is all we need. We might see problems with your patch and decide
22463 to fix the problem another way, or we might not understand it at all.
22464
22465 Sometimes with a program as complicated as @value{GDBN} it is very hard to
22466 construct an example that will make the program follow a certain path
22467 through the code. If you do not send us the example, we will not be able
22468 to construct one, so we will not be able to verify that the bug is fixed.
22469
22470 And if we cannot understand what bug you are trying to fix, or why your
22471 patch should be an improvement, we will not install it. A test case will
22472 help us to understand.
22473
22474 @item
22475 A guess about what the bug is or what it depends on.
22476
22477 Such guesses are usually wrong. Even we cannot guess right about such
22478 things without first using the debugger to find the facts.
22479 @end itemize
22480
22481 @c The readline documentation is distributed with the readline code
22482 @c and consists of the two following files:
22483 @c rluser.texinfo
22484 @c inc-hist.texinfo
22485 @c Use -I with makeinfo to point to the appropriate directory,
22486 @c environment var TEXINPUTS with TeX.
22487 @include rluser.texi
22488 @include inc-hist.texinfo
22489
22490
22491 @node Formatting Documentation
22492 @appendix Formatting Documentation
22493
22494 @cindex @value{GDBN} reference card
22495 @cindex reference card
22496 The @value{GDBN} 4 release includes an already-formatted reference card, ready
22497 for printing with PostScript or Ghostscript, in the @file{gdb}
22498 subdirectory of the main source directory@footnote{In
22499 @file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
22500 release.}. If you can use PostScript or Ghostscript with your printer,
22501 you can print the reference card immediately with @file{refcard.ps}.
22502
22503 The release also includes the source for the reference card. You
22504 can format it, using @TeX{}, by typing:
22505
22506 @smallexample
22507 make refcard.dvi
22508 @end smallexample
22509
22510 The @value{GDBN} reference card is designed to print in @dfn{landscape}
22511 mode on US ``letter'' size paper;
22512 that is, on a sheet 11 inches wide by 8.5 inches
22513 high. You will need to specify this form of printing as an option to
22514 your @sc{dvi} output program.
22515
22516 @cindex documentation
22517
22518 All the documentation for @value{GDBN} comes as part of the machine-readable
22519 distribution. The documentation is written in Texinfo format, which is
22520 a documentation system that uses a single source file to produce both
22521 on-line information and a printed manual. You can use one of the Info
22522 formatting commands to create the on-line version of the documentation
22523 and @TeX{} (or @code{texi2roff}) to typeset the printed version.
22524
22525 @value{GDBN} includes an already formatted copy of the on-line Info
22526 version of this manual in the @file{gdb} subdirectory. The main Info
22527 file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
22528 subordinate files matching @samp{gdb.info*} in the same directory. If
22529 necessary, you can print out these files, or read them with any editor;
22530 but they are easier to read using the @code{info} subsystem in @sc{gnu}
22531 Emacs or the standalone @code{info} program, available as part of the
22532 @sc{gnu} Texinfo distribution.
22533
22534 If you want to format these Info files yourself, you need one of the
22535 Info formatting programs, such as @code{texinfo-format-buffer} or
22536 @code{makeinfo}.
22537
22538 If you have @code{makeinfo} installed, and are in the top level
22539 @value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
22540 version @value{GDBVN}), you can make the Info file by typing:
22541
22542 @smallexample
22543 cd gdb
22544 make gdb.info
22545 @end smallexample
22546
22547 If you want to typeset and print copies of this manual, you need @TeX{},
22548 a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
22549 Texinfo definitions file.
22550
22551 @TeX{} is a typesetting program; it does not print files directly, but
22552 produces output files called @sc{dvi} files. To print a typeset
22553 document, you need a program to print @sc{dvi} files. If your system
22554 has @TeX{} installed, chances are it has such a program. The precise
22555 command to use depends on your system; @kbd{lpr -d} is common; another
22556 (for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
22557 require a file name without any extension or a @samp{.dvi} extension.
22558
22559 @TeX{} also requires a macro definitions file called
22560 @file{texinfo.tex}. This file tells @TeX{} how to typeset a document
22561 written in Texinfo format. On its own, @TeX{} cannot either read or
22562 typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
22563 and is located in the @file{gdb-@var{version-number}/texinfo}
22564 directory.
22565
22566 If you have @TeX{} and a @sc{dvi} printer program installed, you can
22567 typeset and print this manual. First switch to the @file{gdb}
22568 subdirectory of the main source directory (for example, to
22569 @file{gdb-@value{GDBVN}/gdb}) and type:
22570
22571 @smallexample
22572 make gdb.dvi
22573 @end smallexample
22574
22575 Then give @file{gdb.dvi} to your @sc{dvi} printing program.
22576
22577 @node Installing GDB
22578 @appendix Installing @value{GDBN}
22579 @cindex installation
22580
22581 @menu
22582 * Requirements:: Requirements for building @value{GDBN}
22583 * Running Configure:: Invoking the @value{GDBN} @file{configure} script
22584 * Separate Objdir:: Compiling @value{GDBN} in another directory
22585 * Config Names:: Specifying names for hosts and targets
22586 * Configure Options:: Summary of options for configure
22587 @end menu
22588
22589 @node Requirements
22590 @section Requirements for Building @value{GDBN}
22591 @cindex building @value{GDBN}, requirements for
22592
22593 Building @value{GDBN} requires various tools and packages to be available.
22594 Other packages will be used only if they are found.
22595
22596 @heading Tools/Packages Necessary for Building @value{GDBN}
22597 @table @asis
22598 @item ISO C90 compiler
22599 @value{GDBN} is written in ISO C90. It should be buildable with any
22600 working C90 compiler, e.g.@: GCC.
22601
22602 @end table
22603
22604 @heading Tools/Packages Optional for Building @value{GDBN}
22605 @table @asis
22606 @item Expat
22607 @anchor{Expat}
22608 @value{GDBN} can use the Expat XML parsing library. This library may be
22609 included with your operating system distribution; if it is not, you
22610 can get the latest version from @url{http://expat.sourceforge.net}.
22611 The @file{configure} script will search for this library in several
22612 standard locations; if it is installed in an unusual path, you can
22613 use the @option{--with-libexpat-prefix} option to specify its location.
22614
22615 Expat is used for:
22616
22617 @itemize @bullet
22618 @item
22619 Remote protocol memory maps (@pxref{Memory Map Format})
22620 @item
22621 Target descriptions (@pxref{Target Descriptions})
22622 @item
22623 Remote shared library lists (@pxref{Library List Format})
22624 @item
22625 MS-Windows shared libraries (@pxref{Shared Libraries})
22626 @end itemize
22627
22628 @end table
22629
22630 @node Running Configure
22631 @section Invoking the @value{GDBN} @file{configure} Script
22632 @cindex configuring @value{GDBN}
22633 @value{GDBN} comes with a @file{configure} script that automates the process
22634 of preparing @value{GDBN} for installation; you can then use @code{make} to
22635 build the @code{gdb} program.
22636 @iftex
22637 @c irrelevant in info file; it's as current as the code it lives with.
22638 @footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
22639 look at the @file{README} file in the sources; we may have improved the
22640 installation procedures since publishing this manual.}
22641 @end iftex
22642
22643 The @value{GDBN} distribution includes all the source code you need for
22644 @value{GDBN} in a single directory, whose name is usually composed by
22645 appending the version number to @samp{gdb}.
22646
22647 For example, the @value{GDBN} version @value{GDBVN} distribution is in the
22648 @file{gdb-@value{GDBVN}} directory. That directory contains:
22649
22650 @table @code
22651 @item gdb-@value{GDBVN}/configure @r{(and supporting files)}
22652 script for configuring @value{GDBN} and all its supporting libraries
22653
22654 @item gdb-@value{GDBVN}/gdb
22655 the source specific to @value{GDBN} itself
22656
22657 @item gdb-@value{GDBVN}/bfd
22658 source for the Binary File Descriptor library
22659
22660 @item gdb-@value{GDBVN}/include
22661 @sc{gnu} include files
22662
22663 @item gdb-@value{GDBVN}/libiberty
22664 source for the @samp{-liberty} free software library
22665
22666 @item gdb-@value{GDBVN}/opcodes
22667 source for the library of opcode tables and disassemblers
22668
22669 @item gdb-@value{GDBVN}/readline
22670 source for the @sc{gnu} command-line interface
22671
22672 @item gdb-@value{GDBVN}/glob
22673 source for the @sc{gnu} filename pattern-matching subroutine
22674
22675 @item gdb-@value{GDBVN}/mmalloc
22676 source for the @sc{gnu} memory-mapped malloc package
22677 @end table
22678
22679 The simplest way to configure and build @value{GDBN} is to run @file{configure}
22680 from the @file{gdb-@var{version-number}} source directory, which in
22681 this example is the @file{gdb-@value{GDBVN}} directory.
22682
22683 First switch to the @file{gdb-@var{version-number}} source directory
22684 if you are not already in it; then run @file{configure}. Pass the
22685 identifier for the platform on which @value{GDBN} will run as an
22686 argument.
22687
22688 For example:
22689
22690 @smallexample
22691 cd gdb-@value{GDBVN}
22692 ./configure @var{host}
22693 make
22694 @end smallexample
22695
22696 @noindent
22697 where @var{host} is an identifier such as @samp{sun4} or
22698 @samp{decstation}, that identifies the platform where @value{GDBN} will run.
22699 (You can often leave off @var{host}; @file{configure} tries to guess the
22700 correct value by examining your system.)
22701
22702 Running @samp{configure @var{host}} and then running @code{make} builds the
22703 @file{bfd}, @file{readline}, @file{mmalloc}, and @file{libiberty}
22704 libraries, then @code{gdb} itself. The configured source files, and the
22705 binaries, are left in the corresponding source directories.
22706
22707 @need 750
22708 @file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
22709 system does not recognize this automatically when you run a different
22710 shell, you may need to run @code{sh} on it explicitly:
22711
22712 @smallexample
22713 sh configure @var{host}
22714 @end smallexample
22715
22716 If you run @file{configure} from a directory that contains source
22717 directories for multiple libraries or programs, such as the
22718 @file{gdb-@value{GDBVN}} source directory for version @value{GDBVN},
22719 @file{configure}
22720 creates configuration files for every directory level underneath (unless
22721 you tell it not to, with the @samp{--norecursion} option).
22722
22723 You should run the @file{configure} script from the top directory in the
22724 source tree, the @file{gdb-@var{version-number}} directory. If you run
22725 @file{configure} from one of the subdirectories, you will configure only
22726 that subdirectory. That is usually not what you want. In particular,
22727 if you run the first @file{configure} from the @file{gdb} subdirectory
22728 of the @file{gdb-@var{version-number}} directory, you will omit the
22729 configuration of @file{bfd}, @file{readline}, and other sibling
22730 directories of the @file{gdb} subdirectory. This leads to build errors
22731 about missing include files such as @file{bfd/bfd.h}.
22732
22733 You can install @code{@value{GDBP}} anywhere; it has no hardwired paths.
22734 However, you should make sure that the shell on your path (named by
22735 the @samp{SHELL} environment variable) is publicly readable. Remember
22736 that @value{GDBN} uses the shell to start your program---some systems refuse to
22737 let @value{GDBN} debug child processes whose programs are not readable.
22738
22739 @node Separate Objdir
22740 @section Compiling @value{GDBN} in Another Directory
22741
22742 If you want to run @value{GDBN} versions for several host or target machines,
22743 you need a different @code{gdb} compiled for each combination of
22744 host and target. @file{configure} is designed to make this easy by
22745 allowing you to generate each configuration in a separate subdirectory,
22746 rather than in the source directory. If your @code{make} program
22747 handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
22748 @code{make} in each of these directories builds the @code{gdb}
22749 program specified there.
22750
22751 To build @code{gdb} in a separate directory, run @file{configure}
22752 with the @samp{--srcdir} option to specify where to find the source.
22753 (You also need to specify a path to find @file{configure}
22754 itself from your working directory. If the path to @file{configure}
22755 would be the same as the argument to @samp{--srcdir}, you can leave out
22756 the @samp{--srcdir} option; it is assumed.)
22757
22758 For example, with version @value{GDBVN}, you can build @value{GDBN} in a
22759 separate directory for a Sun 4 like this:
22760
22761 @smallexample
22762 @group
22763 cd gdb-@value{GDBVN}
22764 mkdir ../gdb-sun4
22765 cd ../gdb-sun4
22766 ../gdb-@value{GDBVN}/configure sun4
22767 make
22768 @end group
22769 @end smallexample
22770
22771 When @file{configure} builds a configuration using a remote source
22772 directory, it creates a tree for the binaries with the same structure
22773 (and using the same names) as the tree under the source directory. In
22774 the example, you'd find the Sun 4 library @file{libiberty.a} in the
22775 directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
22776 @file{gdb-sun4/gdb}.
22777
22778 Make sure that your path to the @file{configure} script has just one
22779 instance of @file{gdb} in it. If your path to @file{configure} looks
22780 like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
22781 one subdirectory of @value{GDBN}, not the whole package. This leads to
22782 build errors about missing include files such as @file{bfd/bfd.h}.
22783
22784 One popular reason to build several @value{GDBN} configurations in separate
22785 directories is to configure @value{GDBN} for cross-compiling (where
22786 @value{GDBN} runs on one machine---the @dfn{host}---while debugging
22787 programs that run on another machine---the @dfn{target}).
22788 You specify a cross-debugging target by
22789 giving the @samp{--target=@var{target}} option to @file{configure}.
22790
22791 When you run @code{make} to build a program or library, you must run
22792 it in a configured directory---whatever directory you were in when you
22793 called @file{configure} (or one of its subdirectories).
22794
22795 The @code{Makefile} that @file{configure} generates in each source
22796 directory also runs recursively. If you type @code{make} in a source
22797 directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
22798 directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
22799 will build all the required libraries, and then build GDB.
22800
22801 When you have multiple hosts or targets configured in separate
22802 directories, you can run @code{make} on them in parallel (for example,
22803 if they are NFS-mounted on each of the hosts); they will not interfere
22804 with each other.
22805
22806 @node Config Names
22807 @section Specifying Names for Hosts and Targets
22808
22809 The specifications used for hosts and targets in the @file{configure}
22810 script are based on a three-part naming scheme, but some short predefined
22811 aliases are also supported. The full naming scheme encodes three pieces
22812 of information in the following pattern:
22813
22814 @smallexample
22815 @var{architecture}-@var{vendor}-@var{os}
22816 @end smallexample
22817
22818 For example, you can use the alias @code{sun4} as a @var{host} argument,
22819 or as the value for @var{target} in a @code{--target=@var{target}}
22820 option. The equivalent full name is @samp{sparc-sun-sunos4}.
22821
22822 The @file{configure} script accompanying @value{GDBN} does not provide
22823 any query facility to list all supported host and target names or
22824 aliases. @file{configure} calls the Bourne shell script
22825 @code{config.sub} to map abbreviations to full names; you can read the
22826 script, if you wish, or you can use it to test your guesses on
22827 abbreviations---for example:
22828
22829 @smallexample
22830 % sh config.sub i386-linux
22831 i386-pc-linux-gnu
22832 % sh config.sub alpha-linux
22833 alpha-unknown-linux-gnu
22834 % sh config.sub hp9k700
22835 hppa1.1-hp-hpux
22836 % sh config.sub sun4
22837 sparc-sun-sunos4.1.1
22838 % sh config.sub sun3
22839 m68k-sun-sunos4.1.1
22840 % sh config.sub i986v
22841 Invalid configuration `i986v': machine `i986v' not recognized
22842 @end smallexample
22843
22844 @noindent
22845 @code{config.sub} is also distributed in the @value{GDBN} source
22846 directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
22847
22848 @node Configure Options
22849 @section @file{configure} Options
22850
22851 Here is a summary of the @file{configure} options and arguments that
22852 are most often useful for building @value{GDBN}. @file{configure} also has
22853 several other options not listed here. @inforef{What Configure
22854 Does,,configure.info}, for a full explanation of @file{configure}.
22855
22856 @smallexample
22857 configure @r{[}--help@r{]}
22858 @r{[}--prefix=@var{dir}@r{]}
22859 @r{[}--exec-prefix=@var{dir}@r{]}
22860 @r{[}--srcdir=@var{dirname}@r{]}
22861 @r{[}--norecursion@r{]} @r{[}--rm@r{]}
22862 @r{[}--target=@var{target}@r{]}
22863 @var{host}
22864 @end smallexample
22865
22866 @noindent
22867 You may introduce options with a single @samp{-} rather than
22868 @samp{--} if you prefer; but you may abbreviate option names if you use
22869 @samp{--}.
22870
22871 @table @code
22872 @item --help
22873 Display a quick summary of how to invoke @file{configure}.
22874
22875 @item --prefix=@var{dir}
22876 Configure the source to install programs and files under directory
22877 @file{@var{dir}}.
22878
22879 @item --exec-prefix=@var{dir}
22880 Configure the source to install programs under directory
22881 @file{@var{dir}}.
22882
22883 @c avoid splitting the warning from the explanation:
22884 @need 2000
22885 @item --srcdir=@var{dirname}
22886 @strong{Warning: using this option requires @sc{gnu} @code{make}, or another
22887 @code{make} that implements the @code{VPATH} feature.}@*
22888 Use this option to make configurations in directories separate from the
22889 @value{GDBN} source directories. Among other things, you can use this to
22890 build (or maintain) several configurations simultaneously, in separate
22891 directories. @file{configure} writes configuration-specific files in
22892 the current directory, but arranges for them to use the source in the
22893 directory @var{dirname}. @file{configure} creates directories under
22894 the working directory in parallel to the source directories below
22895 @var{dirname}.
22896
22897 @item --norecursion
22898 Configure only the directory level where @file{configure} is executed; do not
22899 propagate configuration to subdirectories.
22900
22901 @item --target=@var{target}
22902 Configure @value{GDBN} for cross-debugging programs running on the specified
22903 @var{target}. Without this option, @value{GDBN} is configured to debug
22904 programs that run on the same machine (@var{host}) as @value{GDBN} itself.
22905
22906 There is no convenient way to generate a list of all available targets.
22907
22908 @item @var{host} @dots{}
22909 Configure @value{GDBN} to run on the specified @var{host}.
22910
22911 There is no convenient way to generate a list of all available hosts.
22912 @end table
22913
22914 There are many other options available as well, but they are generally
22915 needed for special purposes only.
22916
22917 @node Maintenance Commands
22918 @appendix Maintenance Commands
22919 @cindex maintenance commands
22920 @cindex internal commands
22921
22922 In addition to commands intended for @value{GDBN} users, @value{GDBN}
22923 includes a number of commands intended for @value{GDBN} developers,
22924 that are not documented elsewhere in this manual. These commands are
22925 provided here for reference. (For commands that turn on debugging
22926 messages, see @ref{Debugging Output}.)
22927
22928 @table @code
22929 @kindex maint agent
22930 @item maint agent @var{expression}
22931 Translate the given @var{expression} into remote agent bytecodes.
22932 This command is useful for debugging the Agent Expression mechanism
22933 (@pxref{Agent Expressions}).
22934
22935 @kindex maint info breakpoints
22936 @item @anchor{maint info breakpoints}maint info breakpoints
22937 Using the same format as @samp{info breakpoints}, display both the
22938 breakpoints you've set explicitly, and those @value{GDBN} is using for
22939 internal purposes. Internal breakpoints are shown with negative
22940 breakpoint numbers. The type column identifies what kind of breakpoint
22941 is shown:
22942
22943 @table @code
22944 @item breakpoint
22945 Normal, explicitly set breakpoint.
22946
22947 @item watchpoint
22948 Normal, explicitly set watchpoint.
22949
22950 @item longjmp
22951 Internal breakpoint, used to handle correctly stepping through
22952 @code{longjmp} calls.
22953
22954 @item longjmp resume
22955 Internal breakpoint at the target of a @code{longjmp}.
22956
22957 @item until
22958 Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
22959
22960 @item finish
22961 Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
22962
22963 @item shlib events
22964 Shared library events.
22965
22966 @end table
22967
22968 @kindex maint check-symtabs
22969 @item maint check-symtabs
22970 Check the consistency of psymtabs and symtabs.
22971
22972 @kindex maint cplus first_component
22973 @item maint cplus first_component @var{name}
22974 Print the first C@t{++} class/namespace component of @var{name}.
22975
22976 @kindex maint cplus namespace
22977 @item maint cplus namespace
22978 Print the list of possible C@t{++} namespaces.
22979
22980 @kindex maint demangle
22981 @item maint demangle @var{name}
22982 Demangle a C@t{++} or Objective-C mangled @var{name}.
22983
22984 @kindex maint deprecate
22985 @kindex maint undeprecate
22986 @cindex deprecated commands
22987 @item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
22988 @itemx maint undeprecate @var{command}
22989 Deprecate or undeprecate the named @var{command}. Deprecated commands
22990 cause @value{GDBN} to issue a warning when you use them. The optional
22991 argument @var{replacement} says which newer command should be used in
22992 favor of the deprecated one; if it is given, @value{GDBN} will mention
22993 the replacement as part of the warning.
22994
22995 @kindex maint dump-me
22996 @item maint dump-me
22997 @cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
22998 Cause a fatal signal in the debugger and force it to dump its core.
22999 This is supported only on systems which support aborting a program
23000 with the @code{SIGQUIT} signal.
23001
23002 @kindex maint internal-error
23003 @kindex maint internal-warning
23004 @item maint internal-error @r{[}@var{message-text}@r{]}
23005 @itemx maint internal-warning @r{[}@var{message-text}@r{]}
23006 Cause @value{GDBN} to call the internal function @code{internal_error}
23007 or @code{internal_warning} and hence behave as though an internal error
23008 or internal warning has been detected. In addition to reporting the
23009 internal problem, these functions give the user the opportunity to
23010 either quit @value{GDBN} or create a core file of the current
23011 @value{GDBN} session.
23012
23013 These commands take an optional parameter @var{message-text} that is
23014 used as the text of the error or warning message.
23015
23016 Here's an example of using @code{internal-error}:
23017
23018 @smallexample
23019 (@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
23020 @dots{}/maint.c:121: internal-error: testing, 1, 2
23021 A problem internal to GDB has been detected. Further
23022 debugging may prove unreliable.
23023 Quit this debugging session? (y or n) @kbd{n}
23024 Create a core file? (y or n) @kbd{n}
23025 (@value{GDBP})
23026 @end smallexample
23027
23028 @kindex maint packet
23029 @item maint packet @var{text}
23030 If @value{GDBN} is talking to an inferior via the serial protocol,
23031 then this command sends the string @var{text} to the inferior, and
23032 displays the response packet. @value{GDBN} supplies the initial
23033 @samp{$} character, the terminating @samp{#} character, and the
23034 checksum.
23035
23036 @kindex maint print architecture
23037 @item maint print architecture @r{[}@var{file}@r{]}
23038 Print the entire architecture configuration. The optional argument
23039 @var{file} names the file where the output goes.
23040
23041 @kindex maint print c-tdesc
23042 @item maint print c-tdesc
23043 Print the current target description (@pxref{Target Descriptions}) as
23044 a C source file. The created source file can be used in @value{GDBN}
23045 when an XML parser is not available to parse the description.
23046
23047 @kindex maint print dummy-frames
23048 @item maint print dummy-frames
23049 Prints the contents of @value{GDBN}'s internal dummy-frame stack.
23050
23051 @smallexample
23052 (@value{GDBP}) @kbd{b add}
23053 @dots{}
23054 (@value{GDBP}) @kbd{print add(2,3)}
23055 Breakpoint 2, add (a=2, b=3) at @dots{}
23056 58 return (a + b);
23057 The program being debugged stopped while in a function called from GDB.
23058 @dots{}
23059 (@value{GDBP}) @kbd{maint print dummy-frames}
23060 0x1a57c80: pc=0x01014068 fp=0x0200bddc sp=0x0200bdd6
23061 top=0x0200bdd4 id=@{stack=0x200bddc,code=0x101405c@}
23062 call_lo=0x01014000 call_hi=0x01014001
23063 (@value{GDBP})
23064 @end smallexample
23065
23066 Takes an optional file parameter.
23067
23068 @kindex maint print registers
23069 @kindex maint print raw-registers
23070 @kindex maint print cooked-registers
23071 @kindex maint print register-groups
23072 @item maint print registers @r{[}@var{file}@r{]}
23073 @itemx maint print raw-registers @r{[}@var{file}@r{]}
23074 @itemx maint print cooked-registers @r{[}@var{file}@r{]}
23075 @itemx maint print register-groups @r{[}@var{file}@r{]}
23076 Print @value{GDBN}'s internal register data structures.
23077
23078 The command @code{maint print raw-registers} includes the contents of
23079 the raw register cache; the command @code{maint print cooked-registers}
23080 includes the (cooked) value of all registers; and the command
23081 @code{maint print register-groups} includes the groups that each
23082 register is a member of. @xref{Registers,, Registers, gdbint,
23083 @value{GDBN} Internals}.
23084
23085 These commands take an optional parameter, a file name to which to
23086 write the information.
23087
23088 @kindex maint print reggroups
23089 @item maint print reggroups @r{[}@var{file}@r{]}
23090 Print @value{GDBN}'s internal register group data structures. The
23091 optional argument @var{file} tells to what file to write the
23092 information.
23093
23094 The register groups info looks like this:
23095
23096 @smallexample
23097 (@value{GDBP}) @kbd{maint print reggroups}
23098 Group Type
23099 general user
23100 float user
23101 all user
23102 vector user
23103 system user
23104 save internal
23105 restore internal
23106 @end smallexample
23107
23108 @kindex flushregs
23109 @item flushregs
23110 This command forces @value{GDBN} to flush its internal register cache.
23111
23112 @kindex maint print objfiles
23113 @cindex info for known object files
23114 @item maint print objfiles
23115 Print a dump of all known object files. For each object file, this
23116 command prints its name, address in memory, and all of its psymtabs
23117 and symtabs.
23118
23119 @kindex maint print statistics
23120 @cindex bcache statistics
23121 @item maint print statistics
23122 This command prints, for each object file in the program, various data
23123 about that object file followed by the byte cache (@dfn{bcache})
23124 statistics for the object file. The objfile data includes the number
23125 of minimal, partial, full, and stabs symbols, the number of types
23126 defined by the objfile, the number of as yet unexpanded psym tables,
23127 the number of line tables and string tables, and the amount of memory
23128 used by the various tables. The bcache statistics include the counts,
23129 sizes, and counts of duplicates of all and unique objects, max,
23130 average, and median entry size, total memory used and its overhead and
23131 savings, and various measures of the hash table size and chain
23132 lengths.
23133
23134 @kindex maint print target-stack
23135 @cindex target stack description
23136 @item maint print target-stack
23137 A @dfn{target} is an interface between the debugger and a particular
23138 kind of file or process. Targets can be stacked in @dfn{strata},
23139 so that more than one target can potentially respond to a request.
23140 In particular, memory accesses will walk down the stack of targets
23141 until they find a target that is interested in handling that particular
23142 address.
23143
23144 This command prints a short description of each layer that was pushed on
23145 the @dfn{target stack}, starting from the top layer down to the bottom one.
23146
23147 @kindex maint print type
23148 @cindex type chain of a data type
23149 @item maint print type @var{expr}
23150 Print the type chain for a type specified by @var{expr}. The argument
23151 can be either a type name or a symbol. If it is a symbol, the type of
23152 that symbol is described. The type chain produced by this command is
23153 a recursive definition of the data type as stored in @value{GDBN}'s
23154 data structures, including its flags and contained types.
23155
23156 @kindex maint set dwarf2 max-cache-age
23157 @kindex maint show dwarf2 max-cache-age
23158 @item maint set dwarf2 max-cache-age
23159 @itemx maint show dwarf2 max-cache-age
23160 Control the DWARF 2 compilation unit cache.
23161
23162 @cindex DWARF 2 compilation units cache
23163 In object files with inter-compilation-unit references, such as those
23164 produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF 2
23165 reader needs to frequently refer to previously read compilation units.
23166 This setting controls how long a compilation unit will remain in the
23167 cache if it is not referenced. A higher limit means that cached
23168 compilation units will be stored in memory longer, and more total
23169 memory will be used. Setting it to zero disables caching, which will
23170 slow down @value{GDBN} startup, but reduce memory consumption.
23171
23172 @kindex maint set profile
23173 @kindex maint show profile
23174 @cindex profiling GDB
23175 @item maint set profile
23176 @itemx maint show profile
23177 Control profiling of @value{GDBN}.
23178
23179 Profiling will be disabled until you use the @samp{maint set profile}
23180 command to enable it. When you enable profiling, the system will begin
23181 collecting timing and execution count data; when you disable profiling or
23182 exit @value{GDBN}, the results will be written to a log file. Remember that
23183 if you use profiling, @value{GDBN} will overwrite the profiling log file
23184 (often called @file{gmon.out}). If you have a record of important profiling
23185 data in a @file{gmon.out} file, be sure to move it to a safe location.
23186
23187 Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
23188 compiled with the @samp{-pg} compiler option.
23189
23190 @kindex maint show-debug-regs
23191 @cindex x86 hardware debug registers
23192 @item maint show-debug-regs
23193 Control whether to show variables that mirror the x86 hardware debug
23194 registers. Use @code{ON} to enable, @code{OFF} to disable. If
23195 enabled, the debug registers values are shown when @value{GDBN} inserts or
23196 removes a hardware breakpoint or watchpoint, and when the inferior
23197 triggers a hardware-assisted breakpoint or watchpoint.
23198
23199 @kindex maint space
23200 @cindex memory used by commands
23201 @item maint space
23202 Control whether to display memory usage for each command. If set to a
23203 nonzero value, @value{GDBN} will display how much memory each command
23204 took, following the command's own output. This can also be requested
23205 by invoking @value{GDBN} with the @option{--statistics} command-line
23206 switch (@pxref{Mode Options}).
23207
23208 @kindex maint time
23209 @cindex time of command execution
23210 @item maint time
23211 Control whether to display the execution time for each command. If
23212 set to a nonzero value, @value{GDBN} will display how much time it
23213 took to execute each command, following the command's own output.
23214 This can also be requested by invoking @value{GDBN} with the
23215 @option{--statistics} command-line switch (@pxref{Mode Options}).
23216
23217 @kindex maint translate-address
23218 @item maint translate-address @r{[}@var{section}@r{]} @var{addr}
23219 Find the symbol stored at the location specified by the address
23220 @var{addr} and an optional section name @var{section}. If found,
23221 @value{GDBN} prints the name of the closest symbol and an offset from
23222 the symbol's location to the specified address. This is similar to
23223 the @code{info address} command (@pxref{Symbols}), except that this
23224 command also allows to find symbols in other sections.
23225
23226 @end table
23227
23228 The following command is useful for non-interactive invocations of
23229 @value{GDBN}, such as in the test suite.
23230
23231 @table @code
23232 @item set watchdog @var{nsec}
23233 @kindex set watchdog
23234 @cindex watchdog timer
23235 @cindex timeout for commands
23236 Set the maximum number of seconds @value{GDBN} will wait for the
23237 target operation to finish. If this time expires, @value{GDBN}
23238 reports and error and the command is aborted.
23239
23240 @item show watchdog
23241 Show the current setting of the target wait timeout.
23242 @end table
23243
23244 @node Remote Protocol
23245 @appendix @value{GDBN} Remote Serial Protocol
23246
23247 @menu
23248 * Overview::
23249 * Packets::
23250 * Stop Reply Packets::
23251 * General Query Packets::
23252 * Register Packet Format::
23253 * Tracepoint Packets::
23254 * Host I/O Packets::
23255 * Interrupts::
23256 * Examples::
23257 * File-I/O Remote Protocol Extension::
23258 * Library List Format::
23259 * Memory Map Format::
23260 @end menu
23261
23262 @node Overview
23263 @section Overview
23264
23265 There may be occasions when you need to know something about the
23266 protocol---for example, if there is only one serial port to your target
23267 machine, you might want your program to do something special if it
23268 recognizes a packet meant for @value{GDBN}.
23269
23270 In the examples below, @samp{->} and @samp{<-} are used to indicate
23271 transmitted and received data, respectively.
23272
23273 @cindex protocol, @value{GDBN} remote serial
23274 @cindex serial protocol, @value{GDBN} remote
23275 @cindex remote serial protocol
23276 All @value{GDBN} commands and responses (other than acknowledgments) are
23277 sent as a @var{packet}. A @var{packet} is introduced with the character
23278 @samp{$}, the actual @var{packet-data}, and the terminating character
23279 @samp{#} followed by a two-digit @var{checksum}:
23280
23281 @smallexample
23282 @code{$}@var{packet-data}@code{#}@var{checksum}
23283 @end smallexample
23284 @noindent
23285
23286 @cindex checksum, for @value{GDBN} remote
23287 @noindent
23288 The two-digit @var{checksum} is computed as the modulo 256 sum of all
23289 characters between the leading @samp{$} and the trailing @samp{#} (an
23290 eight bit unsigned checksum).
23291
23292 Implementors should note that prior to @value{GDBN} 5.0 the protocol
23293 specification also included an optional two-digit @var{sequence-id}:
23294
23295 @smallexample
23296 @code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
23297 @end smallexample
23298
23299 @cindex sequence-id, for @value{GDBN} remote
23300 @noindent
23301 That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
23302 has never output @var{sequence-id}s. Stubs that handle packets added
23303 since @value{GDBN} 5.0 must not accept @var{sequence-id}.
23304
23305 @cindex acknowledgment, for @value{GDBN} remote
23306 When either the host or the target machine receives a packet, the first
23307 response expected is an acknowledgment: either @samp{+} (to indicate
23308 the package was received correctly) or @samp{-} (to request
23309 retransmission):
23310
23311 @smallexample
23312 -> @code{$}@var{packet-data}@code{#}@var{checksum}
23313 <- @code{+}
23314 @end smallexample
23315 @noindent
23316
23317 The host (@value{GDBN}) sends @var{command}s, and the target (the
23318 debugging stub incorporated in your program) sends a @var{response}. In
23319 the case of step and continue @var{command}s, the response is only sent
23320 when the operation has completed (the target has again stopped).
23321
23322 @var{packet-data} consists of a sequence of characters with the
23323 exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
23324 exceptions).
23325
23326 @cindex remote protocol, field separator
23327 Fields within the packet should be separated using @samp{,} @samp{;} or
23328 @samp{:}. Except where otherwise noted all numbers are represented in
23329 @sc{hex} with leading zeros suppressed.
23330
23331 Implementors should note that prior to @value{GDBN} 5.0, the character
23332 @samp{:} could not appear as the third character in a packet (as it
23333 would potentially conflict with the @var{sequence-id}).
23334
23335 @cindex remote protocol, binary data
23336 @anchor{Binary Data}
23337 Binary data in most packets is encoded either as two hexadecimal
23338 digits per byte of binary data. This allowed the traditional remote
23339 protocol to work over connections which were only seven-bit clean.
23340 Some packets designed more recently assume an eight-bit clean
23341 connection, and use a more efficient encoding to send and receive
23342 binary data.
23343
23344 The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
23345 as an escape character. Any escaped byte is transmitted as the escape
23346 character followed by the original character XORed with @code{0x20}.
23347 For example, the byte @code{0x7d} would be transmitted as the two
23348 bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
23349 @code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
23350 @samp{@}}) must always be escaped. Responses sent by the stub
23351 must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
23352 is not interpreted as the start of a run-length encoded sequence
23353 (described next).
23354
23355 Response @var{data} can be run-length encoded to save space.
23356 Run-length encoding replaces runs of identical characters with one
23357 instance of the repeated character, followed by a @samp{*} and a
23358 repeat count. The repeat count is itself sent encoded, to avoid
23359 binary characters in @var{data}: a value of @var{n} is sent as
23360 @code{@var{n}+29}. For a repeat count greater or equal to 3, this
23361 produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
23362 code 32) for a repeat count of 3. (This is because run-length
23363 encoding starts to win for counts 3 or more.) Thus, for example,
23364 @samp{0* } is a run-length encoding of ``0000'': the space character
23365 after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
23366 3}} more times.
23367
23368 The printable characters @samp{#} and @samp{$} or with a numeric value
23369 greater than 126 must not be used. Runs of six repeats (@samp{#}) or
23370 seven repeats (@samp{$}) can be expanded using a repeat count of only
23371 five (@samp{"}). For example, @samp{00000000} can be encoded as
23372 @samp{0*"00}.
23373
23374 The error response returned for some packets includes a two character
23375 error number. That number is not well defined.
23376
23377 @cindex empty response, for unsupported packets
23378 For any @var{command} not supported by the stub, an empty response
23379 (@samp{$#00}) should be returned. That way it is possible to extend the
23380 protocol. A newer @value{GDBN} can tell if a packet is supported based
23381 on that response.
23382
23383 A stub is required to support the @samp{g}, @samp{G}, @samp{m}, @samp{M},
23384 @samp{c}, and @samp{s} @var{command}s. All other @var{command}s are
23385 optional.
23386
23387 @node Packets
23388 @section Packets
23389
23390 The following table provides a complete list of all currently defined
23391 @var{command}s and their corresponding response @var{data}.
23392 @xref{File-I/O Remote Protocol Extension}, for details about the File
23393 I/O extension of the remote protocol.
23394
23395 Each packet's description has a template showing the packet's overall
23396 syntax, followed by an explanation of the packet's meaning. We
23397 include spaces in some of the templates for clarity; these are not
23398 part of the packet's syntax. No @value{GDBN} packet uses spaces to
23399 separate its components. For example, a template like @samp{foo
23400 @var{bar} @var{baz}} describes a packet beginning with the three ASCII
23401 bytes @samp{foo}, followed by a @var{bar}, followed directly by a
23402 @var{baz}. @value{GDBN} does not transmit a space character between the
23403 @samp{foo} and the @var{bar}, or between the @var{bar} and the
23404 @var{baz}.
23405
23406 Note that all packet forms beginning with an upper- or lower-case
23407 letter, other than those described here, are reserved for future use.
23408
23409 Here are the packet descriptions.
23410
23411 @table @samp
23412
23413 @item !
23414 @cindex @samp{!} packet
23415 @anchor{extended mode}
23416 Enable extended mode. In extended mode, the remote server is made
23417 persistent. The @samp{R} packet is used to restart the program being
23418 debugged.
23419
23420 Reply:
23421 @table @samp
23422 @item OK
23423 The remote target both supports and has enabled extended mode.
23424 @end table
23425
23426 @item ?
23427 @cindex @samp{?} packet
23428 Indicate the reason the target halted. The reply is the same as for
23429 step and continue.
23430
23431 Reply:
23432 @xref{Stop Reply Packets}, for the reply specifications.
23433
23434 @item A @var{arglen},@var{argnum},@var{arg},@dots{}
23435 @cindex @samp{A} packet
23436 Initialized @code{argv[]} array passed into program. @var{arglen}
23437 specifies the number of bytes in the hex encoded byte stream
23438 @var{arg}. See @code{gdbserver} for more details.
23439
23440 Reply:
23441 @table @samp
23442 @item OK
23443 The arguments were set.
23444 @item E @var{NN}
23445 An error occurred.
23446 @end table
23447
23448 @item b @var{baud}
23449 @cindex @samp{b} packet
23450 (Don't use this packet; its behavior is not well-defined.)
23451 Change the serial line speed to @var{baud}.
23452
23453 JTC: @emph{When does the transport layer state change? When it's
23454 received, or after the ACK is transmitted. In either case, there are
23455 problems if the command or the acknowledgment packet is dropped.}
23456
23457 Stan: @emph{If people really wanted to add something like this, and get
23458 it working for the first time, they ought to modify ser-unix.c to send
23459 some kind of out-of-band message to a specially-setup stub and have the
23460 switch happen "in between" packets, so that from remote protocol's point
23461 of view, nothing actually happened.}
23462
23463 @item B @var{addr},@var{mode}
23464 @cindex @samp{B} packet
23465 Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
23466 breakpoint at @var{addr}.
23467
23468 Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
23469 (@pxref{insert breakpoint or watchpoint packet}).
23470
23471 @item c @r{[}@var{addr}@r{]}
23472 @cindex @samp{c} packet
23473 Continue. @var{addr} is address to resume. If @var{addr} is omitted,
23474 resume at current address.
23475
23476 Reply:
23477 @xref{Stop Reply Packets}, for the reply specifications.
23478
23479 @item C @var{sig}@r{[};@var{addr}@r{]}
23480 @cindex @samp{C} packet
23481 Continue with signal @var{sig} (hex signal number). If
23482 @samp{;@var{addr}} is omitted, resume at same address.
23483
23484 Reply:
23485 @xref{Stop Reply Packets}, for the reply specifications.
23486
23487 @item d
23488 @cindex @samp{d} packet
23489 Toggle debug flag.
23490
23491 Don't use this packet; instead, define a general set packet
23492 (@pxref{General Query Packets}).
23493
23494 @item D
23495 @cindex @samp{D} packet
23496 Detach @value{GDBN} from the remote system. Sent to the remote target
23497 before @value{GDBN} disconnects via the @code{detach} command.
23498
23499 Reply:
23500 @table @samp
23501 @item OK
23502 for success
23503 @item E @var{NN}
23504 for an error
23505 @end table
23506
23507 @item F @var{RC},@var{EE},@var{CF};@var{XX}
23508 @cindex @samp{F} packet
23509 A reply from @value{GDBN} to an @samp{F} packet sent by the target.
23510 This is part of the File-I/O protocol extension. @xref{File-I/O
23511 Remote Protocol Extension}, for the specification.
23512
23513 @item g
23514 @anchor{read registers packet}
23515 @cindex @samp{g} packet
23516 Read general registers.
23517
23518 Reply:
23519 @table @samp
23520 @item @var{XX@dots{}}
23521 Each byte of register data is described by two hex digits. The bytes
23522 with the register are transmitted in target byte order. The size of
23523 each register and their position within the @samp{g} packet are
23524 determined by the @value{GDBN} internal gdbarch functions
23525 @code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}. The
23526 specification of several standard @samp{g} packets is specified below.
23527 @item E @var{NN}
23528 for an error.
23529 @end table
23530
23531 @item G @var{XX@dots{}}
23532 @cindex @samp{G} packet
23533 Write general registers. @xref{read registers packet}, for a
23534 description of the @var{XX@dots{}} data.
23535
23536 Reply:
23537 @table @samp
23538 @item OK
23539 for success
23540 @item E @var{NN}
23541 for an error
23542 @end table
23543
23544 @item H @var{c} @var{t}
23545 @cindex @samp{H} packet
23546 Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
23547 @samp{G}, et.al.). @var{c} depends on the operation to be performed: it
23548 should be @samp{c} for step and continue operations, @samp{g} for other
23549 operations. The thread designator @var{t} may be @samp{-1}, meaning all
23550 the threads, a thread number, or @samp{0} which means pick any thread.
23551
23552 Reply:
23553 @table @samp
23554 @item OK
23555 for success
23556 @item E @var{NN}
23557 for an error
23558 @end table
23559
23560 @c FIXME: JTC:
23561 @c 'H': How restrictive (or permissive) is the thread model. If a
23562 @c thread is selected and stopped, are other threads allowed
23563 @c to continue to execute? As I mentioned above, I think the
23564 @c semantics of each command when a thread is selected must be
23565 @c described. For example:
23566 @c
23567 @c 'g': If the stub supports threads and a specific thread is
23568 @c selected, returns the register block from that thread;
23569 @c otherwise returns current registers.
23570 @c
23571 @c 'G' If the stub supports threads and a specific thread is
23572 @c selected, sets the registers of the register block of
23573 @c that thread; otherwise sets current registers.
23574
23575 @item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
23576 @anchor{cycle step packet}
23577 @cindex @samp{i} packet
23578 Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
23579 present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
23580 step starting at that address.
23581
23582 @item I
23583 @cindex @samp{I} packet
23584 Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
23585 step packet}.
23586
23587 @item k
23588 @cindex @samp{k} packet
23589 Kill request.
23590
23591 FIXME: @emph{There is no description of how to operate when a specific
23592 thread context has been selected (i.e.@: does 'k' kill only that
23593 thread?)}.
23594
23595 @item m @var{addr},@var{length}
23596 @cindex @samp{m} packet
23597 Read @var{length} bytes of memory starting at address @var{addr}.
23598 Note that @var{addr} may not be aligned to any particular boundary.
23599
23600 The stub need not use any particular size or alignment when gathering
23601 data from memory for the response; even if @var{addr} is word-aligned
23602 and @var{length} is a multiple of the word size, the stub is free to
23603 use byte accesses, or not. For this reason, this packet may not be
23604 suitable for accessing memory-mapped I/O devices.
23605 @cindex alignment of remote memory accesses
23606 @cindex size of remote memory accesses
23607 @cindex memory, alignment and size of remote accesses
23608
23609 Reply:
23610 @table @samp
23611 @item @var{XX@dots{}}
23612 Memory contents; each byte is transmitted as a two-digit hexadecimal
23613 number. The reply may contain fewer bytes than requested if the
23614 server was able to read only part of the region of memory.
23615 @item E @var{NN}
23616 @var{NN} is errno
23617 @end table
23618
23619 @item M @var{addr},@var{length}:@var{XX@dots{}}
23620 @cindex @samp{M} packet
23621 Write @var{length} bytes of memory starting at address @var{addr}.
23622 @var{XX@dots{}} is the data; each byte is transmitted as a two-digit
23623 hexadecimal number.
23624
23625 Reply:
23626 @table @samp
23627 @item OK
23628 for success
23629 @item E @var{NN}
23630 for an error (this includes the case where only part of the data was
23631 written).
23632 @end table
23633
23634 @item p @var{n}
23635 @cindex @samp{p} packet
23636 Read the value of register @var{n}; @var{n} is in hex.
23637 @xref{read registers packet}, for a description of how the returned
23638 register value is encoded.
23639
23640 Reply:
23641 @table @samp
23642 @item @var{XX@dots{}}
23643 the register's value
23644 @item E @var{NN}
23645 for an error
23646 @item
23647 Indicating an unrecognized @var{query}.
23648 @end table
23649
23650 @item P @var{n@dots{}}=@var{r@dots{}}
23651 @anchor{write register packet}
23652 @cindex @samp{P} packet
23653 Write register @var{n@dots{}} with value @var{r@dots{}}. The register
23654 number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
23655 digits for each byte in the register (target byte order).
23656
23657 Reply:
23658 @table @samp
23659 @item OK
23660 for success
23661 @item E @var{NN}
23662 for an error
23663 @end table
23664
23665 @item q @var{name} @var{params}@dots{}
23666 @itemx Q @var{name} @var{params}@dots{}
23667 @cindex @samp{q} packet
23668 @cindex @samp{Q} packet
23669 General query (@samp{q}) and set (@samp{Q}). These packets are
23670 described fully in @ref{General Query Packets}.
23671
23672 @item r
23673 @cindex @samp{r} packet
23674 Reset the entire system.
23675
23676 Don't use this packet; use the @samp{R} packet instead.
23677
23678 @item R @var{XX}
23679 @cindex @samp{R} packet
23680 Restart the program being debugged. @var{XX}, while needed, is ignored.
23681 This packet is only available in extended mode (@pxref{extended mode}).
23682
23683 The @samp{R} packet has no reply.
23684
23685 @item s @r{[}@var{addr}@r{]}
23686 @cindex @samp{s} packet
23687 Single step. @var{addr} is the address at which to resume. If
23688 @var{addr} is omitted, resume at same address.
23689
23690 Reply:
23691 @xref{Stop Reply Packets}, for the reply specifications.
23692
23693 @item S @var{sig}@r{[};@var{addr}@r{]}
23694 @anchor{step with signal packet}
23695 @cindex @samp{S} packet
23696 Step with signal. This is analogous to the @samp{C} packet, but
23697 requests a single-step, rather than a normal resumption of execution.
23698
23699 Reply:
23700 @xref{Stop Reply Packets}, for the reply specifications.
23701
23702 @item t @var{addr}:@var{PP},@var{MM}
23703 @cindex @samp{t} packet
23704 Search backwards starting at address @var{addr} for a match with pattern
23705 @var{PP} and mask @var{MM}. @var{PP} and @var{MM} are 4 bytes.
23706 @var{addr} must be at least 3 digits.
23707
23708 @item T @var{XX}
23709 @cindex @samp{T} packet
23710 Find out if the thread XX is alive.
23711
23712 Reply:
23713 @table @samp
23714 @item OK
23715 thread is still alive
23716 @item E @var{NN}
23717 thread is dead
23718 @end table
23719
23720 @item v
23721 Packets starting with @samp{v} are identified by a multi-letter name,
23722 up to the first @samp{;} or @samp{?} (or the end of the packet).
23723
23724 @item vAttach;@var{pid}
23725 @cindex @samp{vAttach} packet
23726 Attach to a new process with the specified process ID. @var{pid} is a
23727 hexadecimal integer identifying the process. The attached process is
23728 stopped.
23729
23730 This packet is only available in extended mode (@pxref{extended mode}).
23731
23732 Reply:
23733 @table @samp
23734 @item E @var{nn}
23735 for an error
23736 @item @r{Any stop packet}
23737 for success (@pxref{Stop Reply Packets})
23738 @end table
23739
23740 @item vCont@r{[};@var{action}@r{[}:@var{tid}@r{]]}@dots{}
23741 @cindex @samp{vCont} packet
23742 Resume the inferior, specifying different actions for each thread.
23743 If an action is specified with no @var{tid}, then it is applied to any
23744 threads that don't have a specific action specified; if no default action is
23745 specified then other threads should remain stopped. Specifying multiple
23746 default actions is an error; specifying no actions is also an error.
23747 Thread IDs are specified in hexadecimal. Currently supported actions are:
23748
23749 @table @samp
23750 @item c
23751 Continue.
23752 @item C @var{sig}
23753 Continue with signal @var{sig}. @var{sig} should be two hex digits.
23754 @item s
23755 Step.
23756 @item S @var{sig}
23757 Step with signal @var{sig}. @var{sig} should be two hex digits.
23758 @end table
23759
23760 The optional @var{addr} argument normally associated with these packets is
23761 not supported in @samp{vCont}.
23762
23763 Reply:
23764 @xref{Stop Reply Packets}, for the reply specifications.
23765
23766 @item vCont?
23767 @cindex @samp{vCont?} packet
23768 Request a list of actions supported by the @samp{vCont} packet.
23769
23770 Reply:
23771 @table @samp
23772 @item vCont@r{[};@var{action}@dots{}@r{]}
23773 The @samp{vCont} packet is supported. Each @var{action} is a supported
23774 command in the @samp{vCont} packet.
23775 @item
23776 The @samp{vCont} packet is not supported.
23777 @end table
23778
23779 @item vFile:@var{operation}:@var{parameter}@dots{}
23780 @cindex @samp{vFile} packet
23781 Perform a file operation on the target system. For details,
23782 see @ref{Host I/O Packets}.
23783
23784 @item vFlashErase:@var{addr},@var{length}
23785 @cindex @samp{vFlashErase} packet
23786 Direct the stub to erase @var{length} bytes of flash starting at
23787 @var{addr}. The region may enclose any number of flash blocks, but
23788 its start and end must fall on block boundaries, as indicated by the
23789 flash block size appearing in the memory map (@pxref{Memory Map
23790 Format}). @value{GDBN} groups flash memory programming operations
23791 together, and sends a @samp{vFlashDone} request after each group; the
23792 stub is allowed to delay erase operation until the @samp{vFlashDone}
23793 packet is received.
23794
23795 Reply:
23796 @table @samp
23797 @item OK
23798 for success
23799 @item E @var{NN}
23800 for an error
23801 @end table
23802
23803 @item vFlashWrite:@var{addr}:@var{XX@dots{}}
23804 @cindex @samp{vFlashWrite} packet
23805 Direct the stub to write data to flash address @var{addr}. The data
23806 is passed in binary form using the same encoding as for the @samp{X}
23807 packet (@pxref{Binary Data}). The memory ranges specified by
23808 @samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
23809 not overlap, and must appear in order of increasing addresses
23810 (although @samp{vFlashErase} packets for higher addresses may already
23811 have been received; the ordering is guaranteed only between
23812 @samp{vFlashWrite} packets). If a packet writes to an address that was
23813 neither erased by a preceding @samp{vFlashErase} packet nor by some other
23814 target-specific method, the results are unpredictable.
23815
23816
23817 Reply:
23818 @table @samp
23819 @item OK
23820 for success
23821 @item E.memtype
23822 for vFlashWrite addressing non-flash memory
23823 @item E @var{NN}
23824 for an error
23825 @end table
23826
23827 @item vFlashDone
23828 @cindex @samp{vFlashDone} packet
23829 Indicate to the stub that flash programming operation is finished.
23830 The stub is permitted to delay or batch the effects of a group of
23831 @samp{vFlashErase} and @samp{vFlashWrite} packets until a
23832 @samp{vFlashDone} packet is received. The contents of the affected
23833 regions of flash memory are unpredictable until the @samp{vFlashDone}
23834 request is completed.
23835
23836 @item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
23837 @cindex @samp{vRun} packet
23838 Run the program @var{filename}, passing it each @var{argument} on its
23839 command line. The file and arguments are hex-encoded strings. If
23840 @var{filename} is an empty string, the stub may use a default program
23841 (e.g.@: the last program run). The program is created in the stopped
23842 state.
23843
23844 This packet is only available in extended mode (@pxref{extended mode}).
23845
23846 Reply:
23847 @table @samp
23848 @item E @var{nn}
23849 for an error
23850 @item @r{Any stop packet}
23851 for success (@pxref{Stop Reply Packets})
23852 @end table
23853
23854 @item X @var{addr},@var{length}:@var{XX@dots{}}
23855 @anchor{X packet}
23856 @cindex @samp{X} packet
23857 Write data to memory, where the data is transmitted in binary.
23858 @var{addr} is address, @var{length} is number of bytes,
23859 @samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
23860
23861 Reply:
23862 @table @samp
23863 @item OK
23864 for success
23865 @item E @var{NN}
23866 for an error
23867 @end table
23868
23869 @item z @var{type},@var{addr},@var{length}
23870 @itemx Z @var{type},@var{addr},@var{length}
23871 @anchor{insert breakpoint or watchpoint packet}
23872 @cindex @samp{z} packet
23873 @cindex @samp{Z} packets
23874 Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
23875 watchpoint starting at address @var{address} and covering the next
23876 @var{length} bytes.
23877
23878 Each breakpoint and watchpoint packet @var{type} is documented
23879 separately.
23880
23881 @emph{Implementation notes: A remote target shall return an empty string
23882 for an unrecognized breakpoint or watchpoint packet @var{type}. A
23883 remote target shall support either both or neither of a given
23884 @samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
23885 avoid potential problems with duplicate packets, the operations should
23886 be implemented in an idempotent way.}
23887
23888 @item z0,@var{addr},@var{length}
23889 @itemx Z0,@var{addr},@var{length}
23890 @cindex @samp{z0} packet
23891 @cindex @samp{Z0} packet
23892 Insert (@samp{Z0}) or remove (@samp{z0}) a memory breakpoint at address
23893 @var{addr} of size @var{length}.
23894
23895 A memory breakpoint is implemented by replacing the instruction at
23896 @var{addr} with a software breakpoint or trap instruction. The
23897 @var{length} is used by targets that indicates the size of the
23898 breakpoint (in bytes) that should be inserted (e.g., the @sc{arm} and
23899 @sc{mips} can insert either a 2 or 4 byte breakpoint).
23900
23901 @emph{Implementation note: It is possible for a target to copy or move
23902 code that contains memory breakpoints (e.g., when implementing
23903 overlays). The behavior of this packet, in the presence of such a
23904 target, is not defined.}
23905
23906 Reply:
23907 @table @samp
23908 @item OK
23909 success
23910 @item
23911 not supported
23912 @item E @var{NN}
23913 for an error
23914 @end table
23915
23916 @item z1,@var{addr},@var{length}
23917 @itemx Z1,@var{addr},@var{length}
23918 @cindex @samp{z1} packet
23919 @cindex @samp{Z1} packet
23920 Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
23921 address @var{addr} of size @var{length}.
23922
23923 A hardware breakpoint is implemented using a mechanism that is not
23924 dependant on being able to modify the target's memory.
23925
23926 @emph{Implementation note: A hardware breakpoint is not affected by code
23927 movement.}
23928
23929 Reply:
23930 @table @samp
23931 @item OK
23932 success
23933 @item
23934 not supported
23935 @item E @var{NN}
23936 for an error
23937 @end table
23938
23939 @item z2,@var{addr},@var{length}
23940 @itemx Z2,@var{addr},@var{length}
23941 @cindex @samp{z2} packet
23942 @cindex @samp{Z2} packet
23943 Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint.
23944
23945 Reply:
23946 @table @samp
23947 @item OK
23948 success
23949 @item
23950 not supported
23951 @item E @var{NN}
23952 for an error
23953 @end table
23954
23955 @item z3,@var{addr},@var{length}
23956 @itemx Z3,@var{addr},@var{length}
23957 @cindex @samp{z3} packet
23958 @cindex @samp{Z3} packet
23959 Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint.
23960
23961 Reply:
23962 @table @samp
23963 @item OK
23964 success
23965 @item
23966 not supported
23967 @item E @var{NN}
23968 for an error
23969 @end table
23970
23971 @item z4,@var{addr},@var{length}
23972 @itemx Z4,@var{addr},@var{length}
23973 @cindex @samp{z4} packet
23974 @cindex @samp{Z4} packet
23975 Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint.
23976
23977 Reply:
23978 @table @samp
23979 @item OK
23980 success
23981 @item
23982 not supported
23983 @item E @var{NN}
23984 for an error
23985 @end table
23986
23987 @end table
23988
23989 @node Stop Reply Packets
23990 @section Stop Reply Packets
23991 @cindex stop reply packets
23992
23993 The @samp{C}, @samp{c}, @samp{S}, @samp{s} and @samp{?} packets can
23994 receive any of the below as a reply. In the case of the @samp{C},
23995 @samp{c}, @samp{S} and @samp{s} packets, that reply is only returned
23996 when the target halts. In the below the exact meaning of @dfn{signal
23997 number} is defined by the header @file{include/gdb/signals.h} in the
23998 @value{GDBN} source code.
23999
24000 As in the description of request packets, we include spaces in the
24001 reply templates for clarity; these are not part of the reply packet's
24002 syntax. No @value{GDBN} stop reply packet uses spaces to separate its
24003 components.
24004
24005 @table @samp
24006
24007 @item S @var{AA}
24008 The program received signal number @var{AA} (a two-digit hexadecimal
24009 number). This is equivalent to a @samp{T} response with no
24010 @var{n}:@var{r} pairs.
24011
24012 @item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
24013 @cindex @samp{T} packet reply
24014 The program received signal number @var{AA} (a two-digit hexadecimal
24015 number). This is equivalent to an @samp{S} response, except that the
24016 @samp{@var{n}:@var{r}} pairs can carry values of important registers
24017 and other information directly in the stop reply packet, reducing
24018 round-trip latency. Single-step and breakpoint traps are reported
24019 this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
24020
24021 @itemize @bullet
24022 @item
24023 If @var{n} is a hexadecimal number, it is a register number, and the
24024 corresponding @var{r} gives that register's value. @var{r} is a
24025 series of bytes in target byte order, with each byte given by a
24026 two-digit hex number.
24027
24028 @item
24029 If @var{n} is @samp{thread}, then @var{r} is the thread process ID, in
24030 hex.
24031
24032 @item
24033 If @var{n} is a recognized @dfn{stop reason}, it describes a more
24034 specific event that stopped the target. The currently defined stop
24035 reasons are listed below. @var{aa} should be @samp{05}, the trap
24036 signal. At most one stop reason should be present.
24037
24038 @item
24039 Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
24040 and go on to the next; this allows us to extend the protocol in the
24041 future.
24042 @end itemize
24043
24044 The currently defined stop reasons are:
24045
24046 @table @samp
24047 @item watch
24048 @itemx rwatch
24049 @itemx awatch
24050 The packet indicates a watchpoint hit, and @var{r} is the data address, in
24051 hex.
24052
24053 @cindex shared library events, remote reply
24054 @item library
24055 The packet indicates that the loaded libraries have changed.
24056 @value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
24057 list of loaded libraries. @var{r} is ignored.
24058 @end table
24059
24060 @item W @var{AA}
24061 The process exited, and @var{AA} is the exit status. This is only
24062 applicable to certain targets.
24063
24064 @item X @var{AA}
24065 The process terminated with signal @var{AA}.
24066
24067 @item O @var{XX}@dots{}
24068 @samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
24069 written as the program's console output. This can happen at any time
24070 while the program is running and the debugger should continue to wait
24071 for @samp{W}, @samp{T}, etc.
24072
24073 @item F @var{call-id},@var{parameter}@dots{}
24074 @var{call-id} is the identifier which says which host system call should
24075 be called. This is just the name of the function. Translation into the
24076 correct system call is only applicable as it's defined in @value{GDBN}.
24077 @xref{File-I/O Remote Protocol Extension}, for a list of implemented
24078 system calls.
24079
24080 @samp{@var{parameter}@dots{}} is a list of parameters as defined for
24081 this very system call.
24082
24083 The target replies with this packet when it expects @value{GDBN} to
24084 call a host system call on behalf of the target. @value{GDBN} replies
24085 with an appropriate @samp{F} packet and keeps up waiting for the next
24086 reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
24087 or @samp{s} action is expected to be continued. @xref{File-I/O Remote
24088 Protocol Extension}, for more details.
24089
24090 @end table
24091
24092 @node General Query Packets
24093 @section General Query Packets
24094 @cindex remote query requests
24095
24096 Packets starting with @samp{q} are @dfn{general query packets};
24097 packets starting with @samp{Q} are @dfn{general set packets}. General
24098 query and set packets are a semi-unified form for retrieving and
24099 sending information to and from the stub.
24100
24101 The initial letter of a query or set packet is followed by a name
24102 indicating what sort of thing the packet applies to. For example,
24103 @value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
24104 definitions with the stub. These packet names follow some
24105 conventions:
24106
24107 @itemize @bullet
24108 @item
24109 The name must not contain commas, colons or semicolons.
24110 @item
24111 Most @value{GDBN} query and set packets have a leading upper case
24112 letter.
24113 @item
24114 The names of custom vendor packets should use a company prefix, in
24115 lower case, followed by a period. For example, packets designed at
24116 the Acme Corporation might begin with @samp{qacme.foo} (for querying
24117 foos) or @samp{Qacme.bar} (for setting bars).
24118 @end itemize
24119
24120 The name of a query or set packet should be separated from any
24121 parameters by a @samp{:}; the parameters themselves should be
24122 separated by @samp{,} or @samp{;}. Stubs must be careful to match the
24123 full packet name, and check for a separator or the end of the packet,
24124 in case two packet names share a common prefix. New packets should not begin
24125 with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
24126 packets predate these conventions, and have arguments without any terminator
24127 for the packet name; we suspect they are in widespread use in places that
24128 are difficult to upgrade. The @samp{qC} packet has no arguments, but some
24129 existing stubs (e.g.@: RedBoot) are known to not check for the end of the
24130 packet.}.
24131
24132 Like the descriptions of the other packets, each description here
24133 has a template showing the packet's overall syntax, followed by an
24134 explanation of the packet's meaning. We include spaces in some of the
24135 templates for clarity; these are not part of the packet's syntax. No
24136 @value{GDBN} packet uses spaces to separate its components.
24137
24138 Here are the currently defined query and set packets:
24139
24140 @table @samp
24141
24142 @item qC
24143 @cindex current thread, remote request
24144 @cindex @samp{qC} packet
24145 Return the current thread id.
24146
24147 Reply:
24148 @table @samp
24149 @item QC @var{pid}
24150 Where @var{pid} is an unsigned hexadecimal process id.
24151 @item @r{(anything else)}
24152 Any other reply implies the old pid.
24153 @end table
24154
24155 @item qCRC:@var{addr},@var{length}
24156 @cindex CRC of memory block, remote request
24157 @cindex @samp{qCRC} packet
24158 Compute the CRC checksum of a block of memory.
24159 Reply:
24160 @table @samp
24161 @item E @var{NN}
24162 An error (such as memory fault)
24163 @item C @var{crc32}
24164 The specified memory region's checksum is @var{crc32}.
24165 @end table
24166
24167 @item qfThreadInfo
24168 @itemx qsThreadInfo
24169 @cindex list active threads, remote request
24170 @cindex @samp{qfThreadInfo} packet
24171 @cindex @samp{qsThreadInfo} packet
24172 Obtain a list of all active thread ids from the target (OS). Since there
24173 may be too many active threads to fit into one reply packet, this query
24174 works iteratively: it may require more than one query/reply sequence to
24175 obtain the entire list of threads. The first query of the sequence will
24176 be the @samp{qfThreadInfo} query; subsequent queries in the
24177 sequence will be the @samp{qsThreadInfo} query.
24178
24179 NOTE: This packet replaces the @samp{qL} query (see below).
24180
24181 Reply:
24182 @table @samp
24183 @item m @var{id}
24184 A single thread id
24185 @item m @var{id},@var{id}@dots{}
24186 a comma-separated list of thread ids
24187 @item l
24188 (lower case letter @samp{L}) denotes end of list.
24189 @end table
24190
24191 In response to each query, the target will reply with a list of one or
24192 more thread ids, in big-endian unsigned hex, separated by commas.
24193 @value{GDBN} will respond to each reply with a request for more thread
24194 ids (using the @samp{qs} form of the query), until the target responds
24195 with @samp{l} (lower-case el, for @dfn{last}).
24196
24197 @item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
24198 @cindex get thread-local storage address, remote request
24199 @cindex @samp{qGetTLSAddr} packet
24200 Fetch the address associated with thread local storage specified
24201 by @var{thread-id}, @var{offset}, and @var{lm}.
24202
24203 @var{thread-id} is the (big endian, hex encoded) thread id associated with the
24204 thread for which to fetch the TLS address.
24205
24206 @var{offset} is the (big endian, hex encoded) offset associated with the
24207 thread local variable. (This offset is obtained from the debug
24208 information associated with the variable.)
24209
24210 @var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
24211 the load module associated with the thread local storage. For example,
24212 a @sc{gnu}/Linux system will pass the link map address of the shared
24213 object associated with the thread local storage under consideration.
24214 Other operating environments may choose to represent the load module
24215 differently, so the precise meaning of this parameter will vary.
24216
24217 Reply:
24218 @table @samp
24219 @item @var{XX}@dots{}
24220 Hex encoded (big endian) bytes representing the address of the thread
24221 local storage requested.
24222
24223 @item E @var{nn}
24224 An error occurred. @var{nn} are hex digits.
24225
24226 @item
24227 An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
24228 @end table
24229
24230 @item qL @var{startflag} @var{threadcount} @var{nextthread}
24231 Obtain thread information from RTOS. Where: @var{startflag} (one hex
24232 digit) is one to indicate the first query and zero to indicate a
24233 subsequent query; @var{threadcount} (two hex digits) is the maximum
24234 number of threads the response packet can contain; and @var{nextthread}
24235 (eight hex digits), for subsequent queries (@var{startflag} is zero), is
24236 returned in the response as @var{argthread}.
24237
24238 Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
24239
24240 Reply:
24241 @table @samp
24242 @item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
24243 Where: @var{count} (two hex digits) is the number of threads being
24244 returned; @var{done} (one hex digit) is zero to indicate more threads
24245 and one indicates no further threads; @var{argthreadid} (eight hex
24246 digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
24247 is a sequence of thread IDs from the target. @var{threadid} (eight hex
24248 digits). See @code{remote.c:parse_threadlist_response()}.
24249 @end table
24250
24251 @item qOffsets
24252 @cindex section offsets, remote request
24253 @cindex @samp{qOffsets} packet
24254 Get section offsets that the target used when relocating the downloaded
24255 image.
24256
24257 Reply:
24258 @table @samp
24259 @item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
24260 Relocate the @code{Text} section by @var{xxx} from its original address.
24261 Relocate the @code{Data} section by @var{yyy} from its original address.
24262 If the object file format provides segment information (e.g.@: @sc{elf}
24263 @samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
24264 segments by the supplied offsets.
24265
24266 @emph{Note: while a @code{Bss} offset may be included in the response,
24267 @value{GDBN} ignores this and instead applies the @code{Data} offset
24268 to the @code{Bss} section.}
24269
24270 @item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
24271 Relocate the first segment of the object file, which conventionally
24272 contains program code, to a starting address of @var{xxx}. If
24273 @samp{DataSeg} is specified, relocate the second segment, which
24274 conventionally contains modifiable data, to a starting address of
24275 @var{yyy}. @value{GDBN} will report an error if the object file
24276 does not contain segment information, or does not contain at least
24277 as many segments as mentioned in the reply. Extra segments are
24278 kept at fixed offsets relative to the last relocated segment.
24279 @end table
24280
24281 @item qP @var{mode} @var{threadid}
24282 @cindex thread information, remote request
24283 @cindex @samp{qP} packet
24284 Returns information on @var{threadid}. Where: @var{mode} is a hex
24285 encoded 32 bit mode; @var{threadid} is a hex encoded 64 bit thread ID.
24286
24287 Don't use this packet; use the @samp{qThreadExtraInfo} query instead
24288 (see below).
24289
24290 Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
24291
24292 @item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
24293 @cindex pass signals to inferior, remote request
24294 @cindex @samp{QPassSignals} packet
24295 @anchor{QPassSignals}
24296 Each listed @var{signal} should be passed directly to the inferior process.
24297 Signals are numbered identically to continue packets and stop replies
24298 (@pxref{Stop Reply Packets}). Each @var{signal} list item should be
24299 strictly greater than the previous item. These signals do not need to stop
24300 the inferior, or be reported to @value{GDBN}. All other signals should be
24301 reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
24302 combine; any earlier @samp{QPassSignals} list is completely replaced by the
24303 new list. This packet improves performance when using @samp{handle
24304 @var{signal} nostop noprint pass}.
24305
24306 Reply:
24307 @table @samp
24308 @item OK
24309 The request succeeded.
24310
24311 @item E @var{nn}
24312 An error occurred. @var{nn} are hex digits.
24313
24314 @item
24315 An empty reply indicates that @samp{QPassSignals} is not supported by
24316 the stub.
24317 @end table
24318
24319 Use of this packet is controlled by the @code{set remote pass-signals}
24320 command (@pxref{Remote Configuration, set remote pass-signals}).
24321 This packet is not probed by default; the remote stub must request it,
24322 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24323
24324 @item qRcmd,@var{command}
24325 @cindex execute remote command, remote request
24326 @cindex @samp{qRcmd} packet
24327 @var{command} (hex encoded) is passed to the local interpreter for
24328 execution. Invalid commands should be reported using the output
24329 string. Before the final result packet, the target may also respond
24330 with a number of intermediate @samp{O@var{output}} console output
24331 packets. @emph{Implementors should note that providing access to a
24332 stubs's interpreter may have security implications}.
24333
24334 Reply:
24335 @table @samp
24336 @item OK
24337 A command response with no output.
24338 @item @var{OUTPUT}
24339 A command response with the hex encoded output string @var{OUTPUT}.
24340 @item E @var{NN}
24341 Indicate a badly formed request.
24342 @item
24343 An empty reply indicates that @samp{qRcmd} is not recognized.
24344 @end table
24345
24346 (Note that the @code{qRcmd} packet's name is separated from the
24347 command by a @samp{,}, not a @samp{:}, contrary to the naming
24348 conventions above. Please don't use this packet as a model for new
24349 packets.)
24350
24351 @item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
24352 @cindex supported packets, remote query
24353 @cindex features of the remote protocol
24354 @cindex @samp{qSupported} packet
24355 @anchor{qSupported}
24356 Tell the remote stub about features supported by @value{GDBN}, and
24357 query the stub for features it supports. This packet allows
24358 @value{GDBN} and the remote stub to take advantage of each others'
24359 features. @samp{qSupported} also consolidates multiple feature probes
24360 at startup, to improve @value{GDBN} performance---a single larger
24361 packet performs better than multiple smaller probe packets on
24362 high-latency links. Some features may enable behavior which must not
24363 be on by default, e.g.@: because it would confuse older clients or
24364 stubs. Other features may describe packets which could be
24365 automatically probed for, but are not. These features must be
24366 reported before @value{GDBN} will use them. This ``default
24367 unsupported'' behavior is not appropriate for all packets, but it
24368 helps to keep the initial connection time under control with new
24369 versions of @value{GDBN} which support increasing numbers of packets.
24370
24371 Reply:
24372 @table @samp
24373 @item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
24374 The stub supports or does not support each returned @var{stubfeature},
24375 depending on the form of each @var{stubfeature} (see below for the
24376 possible forms).
24377 @item
24378 An empty reply indicates that @samp{qSupported} is not recognized,
24379 or that no features needed to be reported to @value{GDBN}.
24380 @end table
24381
24382 The allowed forms for each feature (either a @var{gdbfeature} in the
24383 @samp{qSupported} packet, or a @var{stubfeature} in the response)
24384 are:
24385
24386 @table @samp
24387 @item @var{name}=@var{value}
24388 The remote protocol feature @var{name} is supported, and associated
24389 with the specified @var{value}. The format of @var{value} depends
24390 on the feature, but it must not include a semicolon.
24391 @item @var{name}+
24392 The remote protocol feature @var{name} is supported, and does not
24393 need an associated value.
24394 @item @var{name}-
24395 The remote protocol feature @var{name} is not supported.
24396 @item @var{name}?
24397 The remote protocol feature @var{name} may be supported, and
24398 @value{GDBN} should auto-detect support in some other way when it is
24399 needed. This form will not be used for @var{gdbfeature} notifications,
24400 but may be used for @var{stubfeature} responses.
24401 @end table
24402
24403 Whenever the stub receives a @samp{qSupported} request, the
24404 supplied set of @value{GDBN} features should override any previous
24405 request. This allows @value{GDBN} to put the stub in a known
24406 state, even if the stub had previously been communicating with
24407 a different version of @value{GDBN}.
24408
24409 No values of @var{gdbfeature} (for the packet sent by @value{GDBN})
24410 are defined yet. Stubs should ignore any unknown values for
24411 @var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
24412 packet supports receiving packets of unlimited length (earlier
24413 versions of @value{GDBN} may reject overly long responses). Values
24414 for @var{gdbfeature} may be defined in the future to let the stub take
24415 advantage of new features in @value{GDBN}, e.g.@: incompatible
24416 improvements in the remote protocol---support for unlimited length
24417 responses would be a @var{gdbfeature} example, if it were not implied by
24418 the @samp{qSupported} query. The stub's reply should be independent
24419 of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
24420 describes all the features it supports, and then the stub replies with
24421 all the features it supports.
24422
24423 Similarly, @value{GDBN} will silently ignore unrecognized stub feature
24424 responses, as long as each response uses one of the standard forms.
24425
24426 Some features are flags. A stub which supports a flag feature
24427 should respond with a @samp{+} form response. Other features
24428 require values, and the stub should respond with an @samp{=}
24429 form response.
24430
24431 Each feature has a default value, which @value{GDBN} will use if
24432 @samp{qSupported} is not available or if the feature is not mentioned
24433 in the @samp{qSupported} response. The default values are fixed; a
24434 stub is free to omit any feature responses that match the defaults.
24435
24436 Not all features can be probed, but for those which can, the probing
24437 mechanism is useful: in some cases, a stub's internal
24438 architecture may not allow the protocol layer to know some information
24439 about the underlying target in advance. This is especially common in
24440 stubs which may be configured for multiple targets.
24441
24442 These are the currently defined stub features and their properties:
24443
24444 @multitable @columnfractions 0.35 0.2 0.12 0.2
24445 @c NOTE: The first row should be @headitem, but we do not yet require
24446 @c a new enough version of Texinfo (4.7) to use @headitem.
24447 @item Feature Name
24448 @tab Value Required
24449 @tab Default
24450 @tab Probe Allowed
24451
24452 @item @samp{PacketSize}
24453 @tab Yes
24454 @tab @samp{-}
24455 @tab No
24456
24457 @item @samp{qXfer:auxv:read}
24458 @tab No
24459 @tab @samp{-}
24460 @tab Yes
24461
24462 @item @samp{qXfer:features:read}
24463 @tab No
24464 @tab @samp{-}
24465 @tab Yes
24466
24467 @item @samp{qXfer:libraries:read}
24468 @tab No
24469 @tab @samp{-}
24470 @tab Yes
24471
24472 @item @samp{qXfer:memory-map:read}
24473 @tab No
24474 @tab @samp{-}
24475 @tab Yes
24476
24477 @item @samp{qXfer:spu:read}
24478 @tab No
24479 @tab @samp{-}
24480 @tab Yes
24481
24482 @item @samp{qXfer:spu:write}
24483 @tab No
24484 @tab @samp{-}
24485 @tab Yes
24486
24487 @item @samp{QPassSignals}
24488 @tab No
24489 @tab @samp{-}
24490 @tab Yes
24491
24492 @end multitable
24493
24494 These are the currently defined stub features, in more detail:
24495
24496 @table @samp
24497 @cindex packet size, remote protocol
24498 @item PacketSize=@var{bytes}
24499 The remote stub can accept packets up to at least @var{bytes} in
24500 length. @value{GDBN} will send packets up to this size for bulk
24501 transfers, and will never send larger packets. This is a limit on the
24502 data characters in the packet, including the frame and checksum.
24503 There is no trailing NUL byte in a remote protocol packet; if the stub
24504 stores packets in a NUL-terminated format, it should allow an extra
24505 byte in its buffer for the NUL. If this stub feature is not supported,
24506 @value{GDBN} guesses based on the size of the @samp{g} packet response.
24507
24508 @item qXfer:auxv:read
24509 The remote stub understands the @samp{qXfer:auxv:read} packet
24510 (@pxref{qXfer auxiliary vector read}).
24511
24512 @item qXfer:features:read
24513 The remote stub understands the @samp{qXfer:features:read} packet
24514 (@pxref{qXfer target description read}).
24515
24516 @item qXfer:libraries:read
24517 The remote stub understands the @samp{qXfer:libraries:read} packet
24518 (@pxref{qXfer library list read}).
24519
24520 @item qXfer:memory-map:read
24521 The remote stub understands the @samp{qXfer:memory-map:read} packet
24522 (@pxref{qXfer memory map read}).
24523
24524 @item qXfer:spu:read
24525 The remote stub understands the @samp{qXfer:spu:read} packet
24526 (@pxref{qXfer spu read}).
24527
24528 @item qXfer:spu:write
24529 The remote stub understands the @samp{qXfer:spu:write} packet
24530 (@pxref{qXfer spu write}).
24531
24532 @item QPassSignals
24533 The remote stub understands the @samp{QPassSignals} packet
24534 (@pxref{QPassSignals}).
24535
24536 @end table
24537
24538 @item qSymbol::
24539 @cindex symbol lookup, remote request
24540 @cindex @samp{qSymbol} packet
24541 Notify the target that @value{GDBN} is prepared to serve symbol lookup
24542 requests. Accept requests from the target for the values of symbols.
24543
24544 Reply:
24545 @table @samp
24546 @item OK
24547 The target does not need to look up any (more) symbols.
24548 @item qSymbol:@var{sym_name}
24549 The target requests the value of symbol @var{sym_name} (hex encoded).
24550 @value{GDBN} may provide the value by using the
24551 @samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
24552 below.
24553 @end table
24554
24555 @item qSymbol:@var{sym_value}:@var{sym_name}
24556 Set the value of @var{sym_name} to @var{sym_value}.
24557
24558 @var{sym_name} (hex encoded) is the name of a symbol whose value the
24559 target has previously requested.
24560
24561 @var{sym_value} (hex) is the value for symbol @var{sym_name}. If
24562 @value{GDBN} cannot supply a value for @var{sym_name}, then this field
24563 will be empty.
24564
24565 Reply:
24566 @table @samp
24567 @item OK
24568 The target does not need to look up any (more) symbols.
24569 @item qSymbol:@var{sym_name}
24570 The target requests the value of a new symbol @var{sym_name} (hex
24571 encoded). @value{GDBN} will continue to supply the values of symbols
24572 (if available), until the target ceases to request them.
24573 @end table
24574
24575 @item QTDP
24576 @itemx QTFrame
24577 @xref{Tracepoint Packets}.
24578
24579 @item qThreadExtraInfo,@var{id}
24580 @cindex thread attributes info, remote request
24581 @cindex @samp{qThreadExtraInfo} packet
24582 Obtain a printable string description of a thread's attributes from
24583 the target OS. @var{id} is a thread-id in big-endian hex. This
24584 string may contain anything that the target OS thinks is interesting
24585 for @value{GDBN} to tell the user about the thread. The string is
24586 displayed in @value{GDBN}'s @code{info threads} display. Some
24587 examples of possible thread extra info strings are @samp{Runnable}, or
24588 @samp{Blocked on Mutex}.
24589
24590 Reply:
24591 @table @samp
24592 @item @var{XX}@dots{}
24593 Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
24594 comprising the printable string containing the extra information about
24595 the thread's attributes.
24596 @end table
24597
24598 (Note that the @code{qThreadExtraInfo} packet's name is separated from
24599 the command by a @samp{,}, not a @samp{:}, contrary to the naming
24600 conventions above. Please don't use this packet as a model for new
24601 packets.)
24602
24603 @item QTStart
24604 @itemx QTStop
24605 @itemx QTinit
24606 @itemx QTro
24607 @itemx qTStatus
24608 @xref{Tracepoint Packets}.
24609
24610 @item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
24611 @cindex read special object, remote request
24612 @cindex @samp{qXfer} packet
24613 @anchor{qXfer read}
24614 Read uninterpreted bytes from the target's special data area
24615 identified by the keyword @var{object}. Request @var{length} bytes
24616 starting at @var{offset} bytes into the data. The content and
24617 encoding of @var{annex} is specific to @var{object}; it can supply
24618 additional details about what data to access.
24619
24620 Here are the specific requests of this form defined so far. All
24621 @samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
24622 formats, listed below.
24623
24624 @table @samp
24625 @item qXfer:auxv:read::@var{offset},@var{length}
24626 @anchor{qXfer auxiliary vector read}
24627 Access the target's @dfn{auxiliary vector}. @xref{OS Information,
24628 auxiliary vector}. Note @var{annex} must be empty.
24629
24630 This packet is not probed by default; the remote stub must request it,
24631 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24632
24633 @item qXfer:features:read:@var{annex}:@var{offset},@var{length}
24634 @anchor{qXfer target description read}
24635 Access the @dfn{target description}. @xref{Target Descriptions}. The
24636 annex specifies which XML document to access. The main description is
24637 always loaded from the @samp{target.xml} annex.
24638
24639 This packet is not probed by default; the remote stub must request it,
24640 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24641
24642 @item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
24643 @anchor{qXfer library list read}
24644 Access the target's list of loaded libraries. @xref{Library List Format}.
24645 The annex part of the generic @samp{qXfer} packet must be empty
24646 (@pxref{qXfer read}).
24647
24648 Targets which maintain a list of libraries in the program's memory do
24649 not need to implement this packet; it is designed for platforms where
24650 the operating system manages the list of loaded libraries.
24651
24652 This packet is not probed by default; the remote stub must request it,
24653 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24654
24655 @item qXfer:memory-map:read::@var{offset},@var{length}
24656 @anchor{qXfer memory map read}
24657 Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
24658 annex part of the generic @samp{qXfer} packet must be empty
24659 (@pxref{qXfer read}).
24660
24661 This packet is not probed by default; the remote stub must request it,
24662 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24663
24664 @item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
24665 @anchor{qXfer spu read}
24666 Read contents of an @code{spufs} file on the target system. The
24667 annex specifies which file to read; it must be of the form
24668 @file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
24669 in the target process, and @var{name} identifes the @code{spufs} file
24670 in that context to be accessed.
24671
24672 This packet is not probed by default; the remote stub must request it,
24673 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24674 @end table
24675
24676 Reply:
24677 @table @samp
24678 @item m @var{data}
24679 Data @var{data} (@pxref{Binary Data}) has been read from the
24680 target. There may be more data at a higher address (although
24681 it is permitted to return @samp{m} even for the last valid
24682 block of data, as long as at least one byte of data was read).
24683 @var{data} may have fewer bytes than the @var{length} in the
24684 request.
24685
24686 @item l @var{data}
24687 Data @var{data} (@pxref{Binary Data}) has been read from the target.
24688 There is no more data to be read. @var{data} may have fewer bytes
24689 than the @var{length} in the request.
24690
24691 @item l
24692 The @var{offset} in the request is at the end of the data.
24693 There is no more data to be read.
24694
24695 @item E00
24696 The request was malformed, or @var{annex} was invalid.
24697
24698 @item E @var{nn}
24699 The offset was invalid, or there was an error encountered reading the data.
24700 @var{nn} is a hex-encoded @code{errno} value.
24701
24702 @item
24703 An empty reply indicates the @var{object} string was not recognized by
24704 the stub, or that the object does not support reading.
24705 @end table
24706
24707 @item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
24708 @cindex write data into object, remote request
24709 Write uninterpreted bytes into the target's special data area
24710 identified by the keyword @var{object}, starting at @var{offset} bytes
24711 into the data. @var{data}@dots{} is the binary-encoded data
24712 (@pxref{Binary Data}) to be written. The content and encoding of @var{annex}
24713 is specific to @var{object}; it can supply additional details about what data
24714 to access.
24715
24716 Here are the specific requests of this form defined so far. All
24717 @samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
24718 formats, listed below.
24719
24720 @table @samp
24721 @item qXfer:@var{spu}:write:@var{annex}:@var{offset}:@var{data}@dots{}
24722 @anchor{qXfer spu write}
24723 Write @var{data} to an @code{spufs} file on the target system. The
24724 annex specifies which file to write; it must be of the form
24725 @file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
24726 in the target process, and @var{name} identifes the @code{spufs} file
24727 in that context to be accessed.
24728
24729 This packet is not probed by default; the remote stub must request it,
24730 by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
24731 @end table
24732
24733 Reply:
24734 @table @samp
24735 @item @var{nn}
24736 @var{nn} (hex encoded) is the number of bytes written.
24737 This may be fewer bytes than supplied in the request.
24738
24739 @item E00
24740 The request was malformed, or @var{annex} was invalid.
24741
24742 @item E @var{nn}
24743 The offset was invalid, or there was an error encountered writing the data.
24744 @var{nn} is a hex-encoded @code{errno} value.
24745
24746 @item
24747 An empty reply indicates the @var{object} string was not
24748 recognized by the stub, or that the object does not support writing.
24749 @end table
24750
24751 @item qXfer:@var{object}:@var{operation}:@dots{}
24752 Requests of this form may be added in the future. When a stub does
24753 not recognize the @var{object} keyword, or its support for
24754 @var{object} does not recognize the @var{operation} keyword, the stub
24755 must respond with an empty packet.
24756
24757 @end table
24758
24759 @node Register Packet Format
24760 @section Register Packet Format
24761
24762 The following @code{g}/@code{G} packets have previously been defined.
24763 In the below, some thirty-two bit registers are transferred as
24764 sixty-four bits. Those registers should be zero/sign extended (which?)
24765 to fill the space allocated. Register bytes are transferred in target
24766 byte order. The two nibbles within a register byte are transferred
24767 most-significant - least-significant.
24768
24769 @table @r
24770
24771 @item MIPS32
24772
24773 All registers are transferred as thirty-two bit quantities in the order:
24774 32 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
24775 registers; fsr; fir; fp.
24776
24777 @item MIPS64
24778
24779 All registers are transferred as sixty-four bit quantities (including
24780 thirty-two bit registers such as @code{sr}). The ordering is the same
24781 as @code{MIPS32}.
24782
24783 @end table
24784
24785 @node Tracepoint Packets
24786 @section Tracepoint Packets
24787 @cindex tracepoint packets
24788 @cindex packets, tracepoint
24789
24790 Here we describe the packets @value{GDBN} uses to implement
24791 tracepoints (@pxref{Tracepoints}).
24792
24793 @table @samp
24794
24795 @item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}@r{[}-@r{]}
24796 Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
24797 is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
24798 the tracepoint is disabled. @var{step} is the tracepoint's step
24799 count, and @var{pass} is its pass count. If the trailing @samp{-} is
24800 present, further @samp{QTDP} packets will follow to specify this
24801 tracepoint's actions.
24802
24803 Replies:
24804 @table @samp
24805 @item OK
24806 The packet was understood and carried out.
24807 @item
24808 The packet was not recognized.
24809 @end table
24810
24811 @item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
24812 Define actions to be taken when a tracepoint is hit. @var{n} and
24813 @var{addr} must be the same as in the initial @samp{QTDP} packet for
24814 this tracepoint. This packet may only be sent immediately after
24815 another @samp{QTDP} packet that ended with a @samp{-}. If the
24816 trailing @samp{-} is present, further @samp{QTDP} packets will follow,
24817 specifying more actions for this tracepoint.
24818
24819 In the series of action packets for a given tracepoint, at most one
24820 can have an @samp{S} before its first @var{action}. If such a packet
24821 is sent, it and the following packets define ``while-stepping''
24822 actions. Any prior packets define ordinary actions --- that is, those
24823 taken when the tracepoint is first hit. If no action packet has an
24824 @samp{S}, then all the packets in the series specify ordinary
24825 tracepoint actions.
24826
24827 The @samp{@var{action}@dots{}} portion of the packet is a series of
24828 actions, concatenated without separators. Each action has one of the
24829 following forms:
24830
24831 @table @samp
24832
24833 @item R @var{mask}
24834 Collect the registers whose bits are set in @var{mask}. @var{mask} is
24835 a hexadecimal number whose @var{i}'th bit is set if register number
24836 @var{i} should be collected. (The least significant bit is numbered
24837 zero.) Note that @var{mask} may be any number of digits long; it may
24838 not fit in a 32-bit word.
24839
24840 @item M @var{basereg},@var{offset},@var{len}
24841 Collect @var{len} bytes of memory starting at the address in register
24842 number @var{basereg}, plus @var{offset}. If @var{basereg} is
24843 @samp{-1}, then the range has a fixed address: @var{offset} is the
24844 address of the lowest byte to collect. The @var{basereg},
24845 @var{offset}, and @var{len} parameters are all unsigned hexadecimal
24846 values (the @samp{-1} value for @var{basereg} is a special case).
24847
24848 @item X @var{len},@var{expr}
24849 Evaluate @var{expr}, whose length is @var{len}, and collect memory as
24850 it directs. @var{expr} is an agent expression, as described in
24851 @ref{Agent Expressions}. Each byte of the expression is encoded as a
24852 two-digit hex number in the packet; @var{len} is the number of bytes
24853 in the expression (and thus one-half the number of hex digits in the
24854 packet).
24855
24856 @end table
24857
24858 Any number of actions may be packed together in a single @samp{QTDP}
24859 packet, as long as the packet does not exceed the maximum packet
24860 length (400 bytes, for many stubs). There may be only one @samp{R}
24861 action per tracepoint, and it must precede any @samp{M} or @samp{X}
24862 actions. Any registers referred to by @samp{M} and @samp{X} actions
24863 must be collected by a preceding @samp{R} action. (The
24864 ``while-stepping'' actions are treated as if they were attached to a
24865 separate tracepoint, as far as these restrictions are concerned.)
24866
24867 Replies:
24868 @table @samp
24869 @item OK
24870 The packet was understood and carried out.
24871 @item
24872 The packet was not recognized.
24873 @end table
24874
24875 @item QTFrame:@var{n}
24876 Select the @var{n}'th tracepoint frame from the buffer, and use the
24877 register and memory contents recorded there to answer subsequent
24878 request packets from @value{GDBN}.
24879
24880 A successful reply from the stub indicates that the stub has found the
24881 requested frame. The response is a series of parts, concatenated
24882 without separators, describing the frame we selected. Each part has
24883 one of the following forms:
24884
24885 @table @samp
24886 @item F @var{f}
24887 The selected frame is number @var{n} in the trace frame buffer;
24888 @var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
24889 was no frame matching the criteria in the request packet.
24890
24891 @item T @var{t}
24892 The selected trace frame records a hit of tracepoint number @var{t};
24893 @var{t} is a hexadecimal number.
24894
24895 @end table
24896
24897 @item QTFrame:pc:@var{addr}
24898 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
24899 currently selected frame whose PC is @var{addr};
24900 @var{addr} is a hexadecimal number.
24901
24902 @item QTFrame:tdp:@var{t}
24903 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
24904 currently selected frame that is a hit of tracepoint @var{t}; @var{t}
24905 is a hexadecimal number.
24906
24907 @item QTFrame:range:@var{start}:@var{end}
24908 Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
24909 currently selected frame whose PC is between @var{start} (inclusive)
24910 and @var{end} (exclusive); @var{start} and @var{end} are hexadecimal
24911 numbers.
24912
24913 @item QTFrame:outside:@var{start}:@var{end}
24914 Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
24915 frame @emph{outside} the given range of addresses.
24916
24917 @item QTStart
24918 Begin the tracepoint experiment. Begin collecting data from tracepoint
24919 hits in the trace frame buffer.
24920
24921 @item QTStop
24922 End the tracepoint experiment. Stop collecting trace frames.
24923
24924 @item QTinit
24925 Clear the table of tracepoints, and empty the trace frame buffer.
24926
24927 @item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
24928 Establish the given ranges of memory as ``transparent''. The stub
24929 will answer requests for these ranges from memory's current contents,
24930 if they were not collected as part of the tracepoint hit.
24931
24932 @value{GDBN} uses this to mark read-only regions of memory, like those
24933 containing program code. Since these areas never change, they should
24934 still have the same contents they did when the tracepoint was hit, so
24935 there's no reason for the stub to refuse to provide their contents.
24936
24937 @item qTStatus
24938 Ask the stub if there is a trace experiment running right now.
24939
24940 Replies:
24941 @table @samp
24942 @item T0
24943 There is no trace experiment running.
24944 @item T1
24945 There is a trace experiment running.
24946 @end table
24947
24948 @end table
24949
24950
24951 @node Host I/O Packets
24952 @section Host I/O Packets
24953 @cindex Host I/O, remote protocol
24954 @cindex file transfer, remote protocol
24955
24956 The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
24957 operations on the far side of a remote link. For example, Host I/O is
24958 used to upload and download files to a remote target with its own
24959 filesystem. Host I/O uses the same constant values and data structure
24960 layout as the target-initiated File-I/O protocol. However, the
24961 Host I/O packets are structured differently. The target-initiated
24962 protocol relies on target memory to store parameters and buffers.
24963 Host I/O requests are initiated by @value{GDBN}, and the
24964 target's memory is not involved. @xref{File-I/O Remote Protocol
24965 Extension}, for more details on the target-initiated protocol.
24966
24967 The Host I/O request packets all encode a single operation along with
24968 its arguments. They have this format:
24969
24970 @table @samp
24971
24972 @item vFile:@var{operation}: @var{parameter}@dots{}
24973 @var{operation} is the name of the particular request; the target
24974 should compare the entire packet name up to the second colon when checking
24975 for a supported operation. The format of @var{parameter} depends on
24976 the operation. Numbers are always passed in hexadecimal. Negative
24977 numbers have an explicit minus sign (i.e.@: two's complement is not
24978 used). Strings (e.g.@: filenames) are encoded as a series of
24979 hexadecimal bytes. The last argument to a system call may be a
24980 buffer of escaped binary data (@pxref{Binary Data}).
24981
24982 @end table
24983
24984 The valid responses to Host I/O packets are:
24985
24986 @table @samp
24987
24988 @item F @var{result} [, @var{errno}] [; @var{attachment}]
24989 @var{result} is the integer value returned by this operation, usually
24990 non-negative for success and -1 for errors. If an error has occured,
24991 @var{errno} will be included in the result. @var{errno} will have a
24992 value defined by the File-I/O protocol (@pxref{Errno Values}). For
24993 operations which return data, @var{attachment} supplies the data as a
24994 binary buffer. Binary buffers in response packets are escaped in the
24995 normal way (@pxref{Binary Data}). See the individual packet
24996 documentation for the interpretation of @var{result} and
24997 @var{attachment}.
24998
24999 @item
25000 An empty response indicates that this operation is not recognized.
25001
25002 @end table
25003
25004 These are the supported Host I/O operations:
25005
25006 @table @samp
25007 @item vFile:open: @var{pathname}, @var{flags}, @var{mode}
25008 Open a file at @var{pathname} and return a file descriptor for it, or
25009 return -1 if an error occurs. @var{pathname} is a string,
25010 @var{flags} is an integer indicating a mask of open flags
25011 (@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
25012 of mode bits to use if the file is created (@pxref{mode_t Values}).
25013 @xref{open}, for details of the open flags and mode values.
25014
25015 @item vFile:close: @var{fd}
25016 Close the open file corresponding to @var{fd} and return 0, or
25017 -1 if an error occurs.
25018
25019 @item vFile:pread: @var{fd}, @var{count}, @var{offset}
25020 Read data from the open file corresponding to @var{fd}. Up to
25021 @var{count} bytes will be read from the file, starting at @var{offset}
25022 relative to the start of the file. The target may read fewer bytes;
25023 common reasons include packet size limits and an end-of-file
25024 condition. The number of bytes read is returned. Zero should only be
25025 returned for a successful read at the end of the file, or if
25026 @var{count} was zero.
25027
25028 The data read should be returned as a binary attachment on success.
25029 If zero bytes were read, the response should include an empty binary
25030 attachment (i.e.@: a trailing semicolon). The return value is the
25031 number of target bytes read; the binary attachment may be longer if
25032 some characters were escaped.
25033
25034 @item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
25035 Write @var{data} (a binary buffer) to the open file corresponding
25036 to @var{fd}. Start the write at @var{offset} from the start of the
25037 file. Unlike many @code{write} system calls, there is no
25038 separate @var{count} argument; the length of @var{data} in the
25039 packet is used. @samp{vFile:write} returns the number of bytes written,
25040 which may be shorter than the length of @var{data}, or -1 if an
25041 error occurred.
25042
25043 @item vFile:unlink: @var{pathname}
25044 Delete the file at @var{pathname} on the target. Return 0,
25045 or -1 if an error occurs. @var{pathname} is a string.
25046
25047 @end table
25048
25049 @node Interrupts
25050 @section Interrupts
25051 @cindex interrupts (remote protocol)
25052
25053 When a program on the remote target is running, @value{GDBN} may
25054 attempt to interrupt it by sending a @samp{Ctrl-C} or a @code{BREAK},
25055 control of which is specified via @value{GDBN}'s @samp{remotebreak}
25056 setting (@pxref{set remotebreak}).
25057
25058 The precise meaning of @code{BREAK} is defined by the transport
25059 mechanism and may, in fact, be undefined. @value{GDBN} does
25060 not currently define a @code{BREAK} mechanism for any of the network
25061 interfaces.
25062
25063 @samp{Ctrl-C}, on the other hand, is defined and implemented for all
25064 transport mechanisms. It is represented by sending the single byte
25065 @code{0x03} without any of the usual packet overhead described in
25066 the Overview section (@pxref{Overview}). When a @code{0x03} byte is
25067 transmitted as part of a packet, it is considered to be packet data
25068 and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
25069 (@pxref{X packet}), used for binary downloads, may include an unescaped
25070 @code{0x03} as part of its packet.
25071
25072 Stubs are not required to recognize these interrupt mechanisms and the
25073 precise meaning associated with receipt of the interrupt is
25074 implementation defined. If the stub is successful at interrupting the
25075 running program, it is expected that it will send one of the Stop
25076 Reply Packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
25077 of successfully stopping the program. Interrupts received while the
25078 program is stopped will be discarded.
25079
25080 @node Examples
25081 @section Examples
25082
25083 Example sequence of a target being re-started. Notice how the restart
25084 does not get any direct output:
25085
25086 @smallexample
25087 -> @code{R00}
25088 <- @code{+}
25089 @emph{target restarts}
25090 -> @code{?}
25091 <- @code{+}
25092 <- @code{T001:1234123412341234}
25093 -> @code{+}
25094 @end smallexample
25095
25096 Example sequence of a target being stepped by a single instruction:
25097
25098 @smallexample
25099 -> @code{G1445@dots{}}
25100 <- @code{+}
25101 -> @code{s}
25102 <- @code{+}
25103 @emph{time passes}
25104 <- @code{T001:1234123412341234}
25105 -> @code{+}
25106 -> @code{g}
25107 <- @code{+}
25108 <- @code{1455@dots{}}
25109 -> @code{+}
25110 @end smallexample
25111
25112 @node File-I/O Remote Protocol Extension
25113 @section File-I/O Remote Protocol Extension
25114 @cindex File-I/O remote protocol extension
25115
25116 @menu
25117 * File-I/O Overview::
25118 * Protocol Basics::
25119 * The F Request Packet::
25120 * The F Reply Packet::
25121 * The Ctrl-C Message::
25122 * Console I/O::
25123 * List of Supported Calls::
25124 * Protocol-specific Representation of Datatypes::
25125 * Constants::
25126 * File-I/O Examples::
25127 @end menu
25128
25129 @node File-I/O Overview
25130 @subsection File-I/O Overview
25131 @cindex file-i/o overview
25132
25133 The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
25134 target to use the host's file system and console I/O to perform various
25135 system calls. System calls on the target system are translated into a
25136 remote protocol packet to the host system, which then performs the needed
25137 actions and returns a response packet to the target system.
25138 This simulates file system operations even on targets that lack file systems.
25139
25140 The protocol is defined to be independent of both the host and target systems.
25141 It uses its own internal representation of datatypes and values. Both
25142 @value{GDBN} and the target's @value{GDBN} stub are responsible for
25143 translating the system-dependent value representations into the internal
25144 protocol representations when data is transmitted.
25145
25146 The communication is synchronous. A system call is possible only when
25147 @value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
25148 or @samp{s} packets. While @value{GDBN} handles the request for a system call,
25149 the target is stopped to allow deterministic access to the target's
25150 memory. Therefore File-I/O is not interruptible by target signals. On
25151 the other hand, it is possible to interrupt File-I/O by a user interrupt
25152 (@samp{Ctrl-C}) within @value{GDBN}.
25153
25154 The target's request to perform a host system call does not finish
25155 the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
25156 after finishing the system call, the target returns to continuing the
25157 previous activity (continue, step). No additional continue or step
25158 request from @value{GDBN} is required.
25159
25160 @smallexample
25161 (@value{GDBP}) continue
25162 <- target requests 'system call X'
25163 target is stopped, @value{GDBN} executes system call
25164 -> @value{GDBN} returns result
25165 ... target continues, @value{GDBN} returns to wait for the target
25166 <- target hits breakpoint and sends a Txx packet
25167 @end smallexample
25168
25169 The protocol only supports I/O on the console and to regular files on
25170 the host file system. Character or block special devices, pipes,
25171 named pipes, sockets or any other communication method on the host
25172 system are not supported by this protocol.
25173
25174 @node Protocol Basics
25175 @subsection Protocol Basics
25176 @cindex protocol basics, file-i/o
25177
25178 The File-I/O protocol uses the @code{F} packet as the request as well
25179 as reply packet. Since a File-I/O system call can only occur when
25180 @value{GDBN} is waiting for a response from the continuing or stepping target,
25181 the File-I/O request is a reply that @value{GDBN} has to expect as a result
25182 of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
25183 This @code{F} packet contains all information needed to allow @value{GDBN}
25184 to call the appropriate host system call:
25185
25186 @itemize @bullet
25187 @item
25188 A unique identifier for the requested system call.
25189
25190 @item
25191 All parameters to the system call. Pointers are given as addresses
25192 in the target memory address space. Pointers to strings are given as
25193 pointer/length pair. Numerical values are given as they are.
25194 Numerical control flags are given in a protocol-specific representation.
25195
25196 @end itemize
25197
25198 At this point, @value{GDBN} has to perform the following actions.
25199
25200 @itemize @bullet
25201 @item
25202 If the parameters include pointer values to data needed as input to a
25203 system call, @value{GDBN} requests this data from the target with a
25204 standard @code{m} packet request. This additional communication has to be
25205 expected by the target implementation and is handled as any other @code{m}
25206 packet.
25207
25208 @item
25209 @value{GDBN} translates all value from protocol representation to host
25210 representation as needed. Datatypes are coerced into the host types.
25211
25212 @item
25213 @value{GDBN} calls the system call.
25214
25215 @item
25216 It then coerces datatypes back to protocol representation.
25217
25218 @item
25219 If the system call is expected to return data in buffer space specified
25220 by pointer parameters to the call, the data is transmitted to the
25221 target using a @code{M} or @code{X} packet. This packet has to be expected
25222 by the target implementation and is handled as any other @code{M} or @code{X}
25223 packet.
25224
25225 @end itemize
25226
25227 Eventually @value{GDBN} replies with another @code{F} packet which contains all
25228 necessary information for the target to continue. This at least contains
25229
25230 @itemize @bullet
25231 @item
25232 Return value.
25233
25234 @item
25235 @code{errno}, if has been changed by the system call.
25236
25237 @item
25238 ``Ctrl-C'' flag.
25239
25240 @end itemize
25241
25242 After having done the needed type and value coercion, the target continues
25243 the latest continue or step action.
25244
25245 @node The F Request Packet
25246 @subsection The @code{F} Request Packet
25247 @cindex file-i/o request packet
25248 @cindex @code{F} request packet
25249
25250 The @code{F} request packet has the following format:
25251
25252 @table @samp
25253 @item F@var{call-id},@var{parameter@dots{}}
25254
25255 @var{call-id} is the identifier to indicate the host system call to be called.
25256 This is just the name of the function.
25257
25258 @var{parameter@dots{}} are the parameters to the system call.
25259 Parameters are hexadecimal integer values, either the actual values in case
25260 of scalar datatypes, pointers to target buffer space in case of compound
25261 datatypes and unspecified memory areas, or pointer/length pairs in case
25262 of string parameters. These are appended to the @var{call-id} as a
25263 comma-delimited list. All values are transmitted in ASCII
25264 string representation, pointer/length pairs separated by a slash.
25265
25266 @end table
25267
25268
25269
25270 @node The F Reply Packet
25271 @subsection The @code{F} Reply Packet
25272 @cindex file-i/o reply packet
25273 @cindex @code{F} reply packet
25274
25275 The @code{F} reply packet has the following format:
25276
25277 @table @samp
25278
25279 @item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
25280
25281 @var{retcode} is the return code of the system call as hexadecimal value.
25282
25283 @var{errno} is the @code{errno} set by the call, in protocol-specific
25284 representation.
25285 This parameter can be omitted if the call was successful.
25286
25287 @var{Ctrl-C flag} is only sent if the user requested a break. In this
25288 case, @var{errno} must be sent as well, even if the call was successful.
25289 The @var{Ctrl-C flag} itself consists of the character @samp{C}:
25290
25291 @smallexample
25292 F0,0,C
25293 @end smallexample
25294
25295 @noindent
25296 or, if the call was interrupted before the host call has been performed:
25297
25298 @smallexample
25299 F-1,4,C
25300 @end smallexample
25301
25302 @noindent
25303 assuming 4 is the protocol-specific representation of @code{EINTR}.
25304
25305 @end table
25306
25307
25308 @node The Ctrl-C Message
25309 @subsection The @samp{Ctrl-C} Message
25310 @cindex ctrl-c message, in file-i/o protocol
25311
25312 If the @samp{Ctrl-C} flag is set in the @value{GDBN}
25313 reply packet (@pxref{The F Reply Packet}),
25314 the target should behave as if it had
25315 gotten a break message. The meaning for the target is ``system call
25316 interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
25317 (as with a break message) and return to @value{GDBN} with a @code{T02}
25318 packet.
25319
25320 It's important for the target to know in which
25321 state the system call was interrupted. There are two possible cases:
25322
25323 @itemize @bullet
25324 @item
25325 The system call hasn't been performed on the host yet.
25326
25327 @item
25328 The system call on the host has been finished.
25329
25330 @end itemize
25331
25332 These two states can be distinguished by the target by the value of the
25333 returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
25334 call hasn't been performed. This is equivalent to the @code{EINTR} handling
25335 on POSIX systems. In any other case, the target may presume that the
25336 system call has been finished --- successfully or not --- and should behave
25337 as if the break message arrived right after the system call.
25338
25339 @value{GDBN} must behave reliably. If the system call has not been called
25340 yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
25341 @code{errno} in the packet. If the system call on the host has been finished
25342 before the user requests a break, the full action must be finished by
25343 @value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
25344 The @code{F} packet may only be sent when either nothing has happened
25345 or the full action has been completed.
25346
25347 @node Console I/O
25348 @subsection Console I/O
25349 @cindex console i/o as part of file-i/o
25350
25351 By default and if not explicitly closed by the target system, the file
25352 descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
25353 on the @value{GDBN} console is handled as any other file output operation
25354 (@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
25355 by @value{GDBN} so that after the target read request from file descriptor
25356 0 all following typing is buffered until either one of the following
25357 conditions is met:
25358
25359 @itemize @bullet
25360 @item
25361 The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
25362 @code{read}
25363 system call is treated as finished.
25364
25365 @item
25366 The user presses @key{RET}. This is treated as end of input with a trailing
25367 newline.
25368
25369 @item
25370 The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
25371 character (neither newline nor @samp{Ctrl-D}) is appended to the input.
25372
25373 @end itemize
25374
25375 If the user has typed more characters than fit in the buffer given to
25376 the @code{read} call, the trailing characters are buffered in @value{GDBN} until
25377 either another @code{read(0, @dots{})} is requested by the target, or debugging
25378 is stopped at the user's request.
25379
25380
25381 @node List of Supported Calls
25382 @subsection List of Supported Calls
25383 @cindex list of supported file-i/o calls
25384
25385 @menu
25386 * open::
25387 * close::
25388 * read::
25389 * write::
25390 * lseek::
25391 * rename::
25392 * unlink::
25393 * stat/fstat::
25394 * gettimeofday::
25395 * isatty::
25396 * system::
25397 @end menu
25398
25399 @node open
25400 @unnumberedsubsubsec open
25401 @cindex open, file-i/o system call
25402
25403 @table @asis
25404 @item Synopsis:
25405 @smallexample
25406 int open(const char *pathname, int flags);
25407 int open(const char *pathname, int flags, mode_t mode);
25408 @end smallexample
25409
25410 @item Request:
25411 @samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
25412
25413 @noindent
25414 @var{flags} is the bitwise @code{OR} of the following values:
25415
25416 @table @code
25417 @item O_CREAT
25418 If the file does not exist it will be created. The host
25419 rules apply as far as file ownership and time stamps
25420 are concerned.
25421
25422 @item O_EXCL
25423 When used with @code{O_CREAT}, if the file already exists it is
25424 an error and open() fails.
25425
25426 @item O_TRUNC
25427 If the file already exists and the open mode allows
25428 writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
25429 truncated to zero length.
25430
25431 @item O_APPEND
25432 The file is opened in append mode.
25433
25434 @item O_RDONLY
25435 The file is opened for reading only.
25436
25437 @item O_WRONLY
25438 The file is opened for writing only.
25439
25440 @item O_RDWR
25441 The file is opened for reading and writing.
25442 @end table
25443
25444 @noindent
25445 Other bits are silently ignored.
25446
25447
25448 @noindent
25449 @var{mode} is the bitwise @code{OR} of the following values:
25450
25451 @table @code
25452 @item S_IRUSR
25453 User has read permission.
25454
25455 @item S_IWUSR
25456 User has write permission.
25457
25458 @item S_IRGRP
25459 Group has read permission.
25460
25461 @item S_IWGRP
25462 Group has write permission.
25463
25464 @item S_IROTH
25465 Others have read permission.
25466
25467 @item S_IWOTH
25468 Others have write permission.
25469 @end table
25470
25471 @noindent
25472 Other bits are silently ignored.
25473
25474
25475 @item Return value:
25476 @code{open} returns the new file descriptor or -1 if an error
25477 occurred.
25478
25479 @item Errors:
25480
25481 @table @code
25482 @item EEXIST
25483 @var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
25484
25485 @item EISDIR
25486 @var{pathname} refers to a directory.
25487
25488 @item EACCES
25489 The requested access is not allowed.
25490
25491 @item ENAMETOOLONG
25492 @var{pathname} was too long.
25493
25494 @item ENOENT
25495 A directory component in @var{pathname} does not exist.
25496
25497 @item ENODEV
25498 @var{pathname} refers to a device, pipe, named pipe or socket.
25499
25500 @item EROFS
25501 @var{pathname} refers to a file on a read-only filesystem and
25502 write access was requested.
25503
25504 @item EFAULT
25505 @var{pathname} is an invalid pointer value.
25506
25507 @item ENOSPC
25508 No space on device to create the file.
25509
25510 @item EMFILE
25511 The process already has the maximum number of files open.
25512
25513 @item ENFILE
25514 The limit on the total number of files open on the system
25515 has been reached.
25516
25517 @item EINTR
25518 The call was interrupted by the user.
25519 @end table
25520
25521 @end table
25522
25523 @node close
25524 @unnumberedsubsubsec close
25525 @cindex close, file-i/o system call
25526
25527 @table @asis
25528 @item Synopsis:
25529 @smallexample
25530 int close(int fd);
25531 @end smallexample
25532
25533 @item Request:
25534 @samp{Fclose,@var{fd}}
25535
25536 @item Return value:
25537 @code{close} returns zero on success, or -1 if an error occurred.
25538
25539 @item Errors:
25540
25541 @table @code
25542 @item EBADF
25543 @var{fd} isn't a valid open file descriptor.
25544
25545 @item EINTR
25546 The call was interrupted by the user.
25547 @end table
25548
25549 @end table
25550
25551 @node read
25552 @unnumberedsubsubsec read
25553 @cindex read, file-i/o system call
25554
25555 @table @asis
25556 @item Synopsis:
25557 @smallexample
25558 int read(int fd, void *buf, unsigned int count);
25559 @end smallexample
25560
25561 @item Request:
25562 @samp{Fread,@var{fd},@var{bufptr},@var{count}}
25563
25564 @item Return value:
25565 On success, the number of bytes read is returned.
25566 Zero indicates end of file. If count is zero, read
25567 returns zero as well. On error, -1 is returned.
25568
25569 @item Errors:
25570
25571 @table @code
25572 @item EBADF
25573 @var{fd} is not a valid file descriptor or is not open for
25574 reading.
25575
25576 @item EFAULT
25577 @var{bufptr} is an invalid pointer value.
25578
25579 @item EINTR
25580 The call was interrupted by the user.
25581 @end table
25582
25583 @end table
25584
25585 @node write
25586 @unnumberedsubsubsec write
25587 @cindex write, file-i/o system call
25588
25589 @table @asis
25590 @item Synopsis:
25591 @smallexample
25592 int write(int fd, const void *buf, unsigned int count);
25593 @end smallexample
25594
25595 @item Request:
25596 @samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
25597
25598 @item Return value:
25599 On success, the number of bytes written are returned.
25600 Zero indicates nothing was written. On error, -1
25601 is returned.
25602
25603 @item Errors:
25604
25605 @table @code
25606 @item EBADF
25607 @var{fd} is not a valid file descriptor or is not open for
25608 writing.
25609
25610 @item EFAULT
25611 @var{bufptr} is an invalid pointer value.
25612
25613 @item EFBIG
25614 An attempt was made to write a file that exceeds the
25615 host-specific maximum file size allowed.
25616
25617 @item ENOSPC
25618 No space on device to write the data.
25619
25620 @item EINTR
25621 The call was interrupted by the user.
25622 @end table
25623
25624 @end table
25625
25626 @node lseek
25627 @unnumberedsubsubsec lseek
25628 @cindex lseek, file-i/o system call
25629
25630 @table @asis
25631 @item Synopsis:
25632 @smallexample
25633 long lseek (int fd, long offset, int flag);
25634 @end smallexample
25635
25636 @item Request:
25637 @samp{Flseek,@var{fd},@var{offset},@var{flag}}
25638
25639 @var{flag} is one of:
25640
25641 @table @code
25642 @item SEEK_SET
25643 The offset is set to @var{offset} bytes.
25644
25645 @item SEEK_CUR
25646 The offset is set to its current location plus @var{offset}
25647 bytes.
25648
25649 @item SEEK_END
25650 The offset is set to the size of the file plus @var{offset}
25651 bytes.
25652 @end table
25653
25654 @item Return value:
25655 On success, the resulting unsigned offset in bytes from
25656 the beginning of the file is returned. Otherwise, a
25657 value of -1 is returned.
25658
25659 @item Errors:
25660
25661 @table @code
25662 @item EBADF
25663 @var{fd} is not a valid open file descriptor.
25664
25665 @item ESPIPE
25666 @var{fd} is associated with the @value{GDBN} console.
25667
25668 @item EINVAL
25669 @var{flag} is not a proper value.
25670
25671 @item EINTR
25672 The call was interrupted by the user.
25673 @end table
25674
25675 @end table
25676
25677 @node rename
25678 @unnumberedsubsubsec rename
25679 @cindex rename, file-i/o system call
25680
25681 @table @asis
25682 @item Synopsis:
25683 @smallexample
25684 int rename(const char *oldpath, const char *newpath);
25685 @end smallexample
25686
25687 @item Request:
25688 @samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
25689
25690 @item Return value:
25691 On success, zero is returned. On error, -1 is returned.
25692
25693 @item Errors:
25694
25695 @table @code
25696 @item EISDIR
25697 @var{newpath} is an existing directory, but @var{oldpath} is not a
25698 directory.
25699
25700 @item EEXIST
25701 @var{newpath} is a non-empty directory.
25702
25703 @item EBUSY
25704 @var{oldpath} or @var{newpath} is a directory that is in use by some
25705 process.
25706
25707 @item EINVAL
25708 An attempt was made to make a directory a subdirectory
25709 of itself.
25710
25711 @item ENOTDIR
25712 A component used as a directory in @var{oldpath} or new
25713 path is not a directory. Or @var{oldpath} is a directory
25714 and @var{newpath} exists but is not a directory.
25715
25716 @item EFAULT
25717 @var{oldpathptr} or @var{newpathptr} are invalid pointer values.
25718
25719 @item EACCES
25720 No access to the file or the path of the file.
25721
25722 @item ENAMETOOLONG
25723
25724 @var{oldpath} or @var{newpath} was too long.
25725
25726 @item ENOENT
25727 A directory component in @var{oldpath} or @var{newpath} does not exist.
25728
25729 @item EROFS
25730 The file is on a read-only filesystem.
25731
25732 @item ENOSPC
25733 The device containing the file has no room for the new
25734 directory entry.
25735
25736 @item EINTR
25737 The call was interrupted by the user.
25738 @end table
25739
25740 @end table
25741
25742 @node unlink
25743 @unnumberedsubsubsec unlink
25744 @cindex unlink, file-i/o system call
25745
25746 @table @asis
25747 @item Synopsis:
25748 @smallexample
25749 int unlink(const char *pathname);
25750 @end smallexample
25751
25752 @item Request:
25753 @samp{Funlink,@var{pathnameptr}/@var{len}}
25754
25755 @item Return value:
25756 On success, zero is returned. On error, -1 is returned.
25757
25758 @item Errors:
25759
25760 @table @code
25761 @item EACCES
25762 No access to the file or the path of the file.
25763
25764 @item EPERM
25765 The system does not allow unlinking of directories.
25766
25767 @item EBUSY
25768 The file @var{pathname} cannot be unlinked because it's
25769 being used by another process.
25770
25771 @item EFAULT
25772 @var{pathnameptr} is an invalid pointer value.
25773
25774 @item ENAMETOOLONG
25775 @var{pathname} was too long.
25776
25777 @item ENOENT
25778 A directory component in @var{pathname} does not exist.
25779
25780 @item ENOTDIR
25781 A component of the path is not a directory.
25782
25783 @item EROFS
25784 The file is on a read-only filesystem.
25785
25786 @item EINTR
25787 The call was interrupted by the user.
25788 @end table
25789
25790 @end table
25791
25792 @node stat/fstat
25793 @unnumberedsubsubsec stat/fstat
25794 @cindex fstat, file-i/o system call
25795 @cindex stat, file-i/o system call
25796
25797 @table @asis
25798 @item Synopsis:
25799 @smallexample
25800 int stat(const char *pathname, struct stat *buf);
25801 int fstat(int fd, struct stat *buf);
25802 @end smallexample
25803
25804 @item Request:
25805 @samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
25806 @samp{Ffstat,@var{fd},@var{bufptr}}
25807
25808 @item Return value:
25809 On success, zero is returned. On error, -1 is returned.
25810
25811 @item Errors:
25812
25813 @table @code
25814 @item EBADF
25815 @var{fd} is not a valid open file.
25816
25817 @item ENOENT
25818 A directory component in @var{pathname} does not exist or the
25819 path is an empty string.
25820
25821 @item ENOTDIR
25822 A component of the path is not a directory.
25823
25824 @item EFAULT
25825 @var{pathnameptr} is an invalid pointer value.
25826
25827 @item EACCES
25828 No access to the file or the path of the file.
25829
25830 @item ENAMETOOLONG
25831 @var{pathname} was too long.
25832
25833 @item EINTR
25834 The call was interrupted by the user.
25835 @end table
25836
25837 @end table
25838
25839 @node gettimeofday
25840 @unnumberedsubsubsec gettimeofday
25841 @cindex gettimeofday, file-i/o system call
25842
25843 @table @asis
25844 @item Synopsis:
25845 @smallexample
25846 int gettimeofday(struct timeval *tv, void *tz);
25847 @end smallexample
25848
25849 @item Request:
25850 @samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
25851
25852 @item Return value:
25853 On success, 0 is returned, -1 otherwise.
25854
25855 @item Errors:
25856
25857 @table @code
25858 @item EINVAL
25859 @var{tz} is a non-NULL pointer.
25860
25861 @item EFAULT
25862 @var{tvptr} and/or @var{tzptr} is an invalid pointer value.
25863 @end table
25864
25865 @end table
25866
25867 @node isatty
25868 @unnumberedsubsubsec isatty
25869 @cindex isatty, file-i/o system call
25870
25871 @table @asis
25872 @item Synopsis:
25873 @smallexample
25874 int isatty(int fd);
25875 @end smallexample
25876
25877 @item Request:
25878 @samp{Fisatty,@var{fd}}
25879
25880 @item Return value:
25881 Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
25882
25883 @item Errors:
25884
25885 @table @code
25886 @item EINTR
25887 The call was interrupted by the user.
25888 @end table
25889
25890 @end table
25891
25892 Note that the @code{isatty} call is treated as a special case: it returns
25893 1 to the target if the file descriptor is attached
25894 to the @value{GDBN} console, 0 otherwise. Implementing through system calls
25895 would require implementing @code{ioctl} and would be more complex than
25896 needed.
25897
25898
25899 @node system
25900 @unnumberedsubsubsec system
25901 @cindex system, file-i/o system call
25902
25903 @table @asis
25904 @item Synopsis:
25905 @smallexample
25906 int system(const char *command);
25907 @end smallexample
25908
25909 @item Request:
25910 @samp{Fsystem,@var{commandptr}/@var{len}}
25911
25912 @item Return value:
25913 If @var{len} is zero, the return value indicates whether a shell is
25914 available. A zero return value indicates a shell is not available.
25915 For non-zero @var{len}, the value returned is -1 on error and the
25916 return status of the command otherwise. Only the exit status of the
25917 command is returned, which is extracted from the host's @code{system}
25918 return value by calling @code{WEXITSTATUS(retval)}. In case
25919 @file{/bin/sh} could not be executed, 127 is returned.
25920
25921 @item Errors:
25922
25923 @table @code
25924 @item EINTR
25925 The call was interrupted by the user.
25926 @end table
25927
25928 @end table
25929
25930 @value{GDBN} takes over the full task of calling the necessary host calls
25931 to perform the @code{system} call. The return value of @code{system} on
25932 the host is simplified before it's returned
25933 to the target. Any termination signal information from the child process
25934 is discarded, and the return value consists
25935 entirely of the exit status of the called command.
25936
25937 Due to security concerns, the @code{system} call is by default refused
25938 by @value{GDBN}. The user has to allow this call explicitly with the
25939 @code{set remote system-call-allowed 1} command.
25940
25941 @table @code
25942 @item set remote system-call-allowed
25943 @kindex set remote system-call-allowed
25944 Control whether to allow the @code{system} calls in the File I/O
25945 protocol for the remote target. The default is zero (disabled).
25946
25947 @item show remote system-call-allowed
25948 @kindex show remote system-call-allowed
25949 Show whether the @code{system} calls are allowed in the File I/O
25950 protocol.
25951 @end table
25952
25953 @node Protocol-specific Representation of Datatypes
25954 @subsection Protocol-specific Representation of Datatypes
25955 @cindex protocol-specific representation of datatypes, in file-i/o protocol
25956
25957 @menu
25958 * Integral Datatypes::
25959 * Pointer Values::
25960 * Memory Transfer::
25961 * struct stat::
25962 * struct timeval::
25963 @end menu
25964
25965 @node Integral Datatypes
25966 @unnumberedsubsubsec Integral Datatypes
25967 @cindex integral datatypes, in file-i/o protocol
25968
25969 The integral datatypes used in the system calls are @code{int},
25970 @code{unsigned int}, @code{long}, @code{unsigned long},
25971 @code{mode_t}, and @code{time_t}.
25972
25973 @code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
25974 implemented as 32 bit values in this protocol.
25975
25976 @code{long} and @code{unsigned long} are implemented as 64 bit types.
25977
25978 @xref{Limits}, for corresponding MIN and MAX values (similar to those
25979 in @file{limits.h}) to allow range checking on host and target.
25980
25981 @code{time_t} datatypes are defined as seconds since the Epoch.
25982
25983 All integral datatypes transferred as part of a memory read or write of a
25984 structured datatype e.g.@: a @code{struct stat} have to be given in big endian
25985 byte order.
25986
25987 @node Pointer Values
25988 @unnumberedsubsubsec Pointer Values
25989 @cindex pointer values, in file-i/o protocol
25990
25991 Pointers to target data are transmitted as they are. An exception
25992 is made for pointers to buffers for which the length isn't
25993 transmitted as part of the function call, namely strings. Strings
25994 are transmitted as a pointer/length pair, both as hex values, e.g.@:
25995
25996 @smallexample
25997 @code{1aaf/12}
25998 @end smallexample
25999
26000 @noindent
26001 which is a pointer to data of length 18 bytes at position 0x1aaf.
26002 The length is defined as the full string length in bytes, including
26003 the trailing null byte. For example, the string @code{"hello world"}
26004 at address 0x123456 is transmitted as
26005
26006 @smallexample
26007 @code{123456/d}
26008 @end smallexample
26009
26010 @node Memory Transfer
26011 @unnumberedsubsubsec Memory Transfer
26012 @cindex memory transfer, in file-i/o protocol
26013
26014 Structured data which is transferred using a memory read or write (for
26015 example, a @code{struct stat}) is expected to be in a protocol-specific format
26016 with all scalar multibyte datatypes being big endian. Translation to
26017 this representation needs to be done both by the target before the @code{F}
26018 packet is sent, and by @value{GDBN} before
26019 it transfers memory to the target. Transferred pointers to structured
26020 data should point to the already-coerced data at any time.
26021
26022
26023 @node struct stat
26024 @unnumberedsubsubsec struct stat
26025 @cindex struct stat, in file-i/o protocol
26026
26027 The buffer of type @code{struct stat} used by the target and @value{GDBN}
26028 is defined as follows:
26029
26030 @smallexample
26031 struct stat @{
26032 unsigned int st_dev; /* device */
26033 unsigned int st_ino; /* inode */
26034 mode_t st_mode; /* protection */
26035 unsigned int st_nlink; /* number of hard links */
26036 unsigned int st_uid; /* user ID of owner */
26037 unsigned int st_gid; /* group ID of owner */
26038 unsigned int st_rdev; /* device type (if inode device) */
26039 unsigned long st_size; /* total size, in bytes */
26040 unsigned long st_blksize; /* blocksize for filesystem I/O */
26041 unsigned long st_blocks; /* number of blocks allocated */
26042 time_t st_atime; /* time of last access */
26043 time_t st_mtime; /* time of last modification */
26044 time_t st_ctime; /* time of last change */
26045 @};
26046 @end smallexample
26047
26048 The integral datatypes conform to the definitions given in the
26049 appropriate section (see @ref{Integral Datatypes}, for details) so this
26050 structure is of size 64 bytes.
26051
26052 The values of several fields have a restricted meaning and/or
26053 range of values.
26054
26055 @table @code
26056
26057 @item st_dev
26058 A value of 0 represents a file, 1 the console.
26059
26060 @item st_ino
26061 No valid meaning for the target. Transmitted unchanged.
26062
26063 @item st_mode
26064 Valid mode bits are described in @ref{Constants}. Any other
26065 bits have currently no meaning for the target.
26066
26067 @item st_uid
26068 @itemx st_gid
26069 @itemx st_rdev
26070 No valid meaning for the target. Transmitted unchanged.
26071
26072 @item st_atime
26073 @itemx st_mtime
26074 @itemx st_ctime
26075 These values have a host and file system dependent
26076 accuracy. Especially on Windows hosts, the file system may not
26077 support exact timing values.
26078 @end table
26079
26080 The target gets a @code{struct stat} of the above representation and is
26081 responsible for coercing it to the target representation before
26082 continuing.
26083
26084 Note that due to size differences between the host, target, and protocol
26085 representations of @code{struct stat} members, these members could eventually
26086 get truncated on the target.
26087
26088 @node struct timeval
26089 @unnumberedsubsubsec struct timeval
26090 @cindex struct timeval, in file-i/o protocol
26091
26092 The buffer of type @code{struct timeval} used by the File-I/O protocol
26093 is defined as follows:
26094
26095 @smallexample
26096 struct timeval @{
26097 time_t tv_sec; /* second */
26098 long tv_usec; /* microsecond */
26099 @};
26100 @end smallexample
26101
26102 The integral datatypes conform to the definitions given in the
26103 appropriate section (see @ref{Integral Datatypes}, for details) so this
26104 structure is of size 8 bytes.
26105
26106 @node Constants
26107 @subsection Constants
26108 @cindex constants, in file-i/o protocol
26109
26110 The following values are used for the constants inside of the
26111 protocol. @value{GDBN} and target are responsible for translating these
26112 values before and after the call as needed.
26113
26114 @menu
26115 * Open Flags::
26116 * mode_t Values::
26117 * Errno Values::
26118 * Lseek Flags::
26119 * Limits::
26120 @end menu
26121
26122 @node Open Flags
26123 @unnumberedsubsubsec Open Flags
26124 @cindex open flags, in file-i/o protocol
26125
26126 All values are given in hexadecimal representation.
26127
26128 @smallexample
26129 O_RDONLY 0x0
26130 O_WRONLY 0x1
26131 O_RDWR 0x2
26132 O_APPEND 0x8
26133 O_CREAT 0x200
26134 O_TRUNC 0x400
26135 O_EXCL 0x800
26136 @end smallexample
26137
26138 @node mode_t Values
26139 @unnumberedsubsubsec mode_t Values
26140 @cindex mode_t values, in file-i/o protocol
26141
26142 All values are given in octal representation.
26143
26144 @smallexample
26145 S_IFREG 0100000
26146 S_IFDIR 040000
26147 S_IRUSR 0400
26148 S_IWUSR 0200
26149 S_IXUSR 0100
26150 S_IRGRP 040
26151 S_IWGRP 020
26152 S_IXGRP 010
26153 S_IROTH 04
26154 S_IWOTH 02
26155 S_IXOTH 01
26156 @end smallexample
26157
26158 @node Errno Values
26159 @unnumberedsubsubsec Errno Values
26160 @cindex errno values, in file-i/o protocol
26161
26162 All values are given in decimal representation.
26163
26164 @smallexample
26165 EPERM 1
26166 ENOENT 2
26167 EINTR 4
26168 EBADF 9
26169 EACCES 13
26170 EFAULT 14
26171 EBUSY 16
26172 EEXIST 17
26173 ENODEV 19
26174 ENOTDIR 20
26175 EISDIR 21
26176 EINVAL 22
26177 ENFILE 23
26178 EMFILE 24
26179 EFBIG 27
26180 ENOSPC 28
26181 ESPIPE 29
26182 EROFS 30
26183 ENAMETOOLONG 91
26184 EUNKNOWN 9999
26185 @end smallexample
26186
26187 @code{EUNKNOWN} is used as a fallback error value if a host system returns
26188 any error value not in the list of supported error numbers.
26189
26190 @node Lseek Flags
26191 @unnumberedsubsubsec Lseek Flags
26192 @cindex lseek flags, in file-i/o protocol
26193
26194 @smallexample
26195 SEEK_SET 0
26196 SEEK_CUR 1
26197 SEEK_END 2
26198 @end smallexample
26199
26200 @node Limits
26201 @unnumberedsubsubsec Limits
26202 @cindex limits, in file-i/o protocol
26203
26204 All values are given in decimal representation.
26205
26206 @smallexample
26207 INT_MIN -2147483648
26208 INT_MAX 2147483647
26209 UINT_MAX 4294967295
26210 LONG_MIN -9223372036854775808
26211 LONG_MAX 9223372036854775807
26212 ULONG_MAX 18446744073709551615
26213 @end smallexample
26214
26215 @node File-I/O Examples
26216 @subsection File-I/O Examples
26217 @cindex file-i/o examples
26218
26219 Example sequence of a write call, file descriptor 3, buffer is at target
26220 address 0x1234, 6 bytes should be written:
26221
26222 @smallexample
26223 <- @code{Fwrite,3,1234,6}
26224 @emph{request memory read from target}
26225 -> @code{m1234,6}
26226 <- XXXXXX
26227 @emph{return "6 bytes written"}
26228 -> @code{F6}
26229 @end smallexample
26230
26231 Example sequence of a read call, file descriptor 3, buffer is at target
26232 address 0x1234, 6 bytes should be read:
26233
26234 @smallexample
26235 <- @code{Fread,3,1234,6}
26236 @emph{request memory write to target}
26237 -> @code{X1234,6:XXXXXX}
26238 @emph{return "6 bytes read"}
26239 -> @code{F6}
26240 @end smallexample
26241
26242 Example sequence of a read call, call fails on the host due to invalid
26243 file descriptor (@code{EBADF}):
26244
26245 @smallexample
26246 <- @code{Fread,3,1234,6}
26247 -> @code{F-1,9}
26248 @end smallexample
26249
26250 Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
26251 host is called:
26252
26253 @smallexample
26254 <- @code{Fread,3,1234,6}
26255 -> @code{F-1,4,C}
26256 <- @code{T02}
26257 @end smallexample
26258
26259 Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
26260 host is called:
26261
26262 @smallexample
26263 <- @code{Fread,3,1234,6}
26264 -> @code{X1234,6:XXXXXX}
26265 <- @code{T02}
26266 @end smallexample
26267
26268 @node Library List Format
26269 @section Library List Format
26270 @cindex library list format, remote protocol
26271
26272 On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
26273 same process as your application to manage libraries. In this case,
26274 @value{GDBN} can use the loader's symbol table and normal memory
26275 operations to maintain a list of shared libraries. On other
26276 platforms, the operating system manages loaded libraries.
26277 @value{GDBN} can not retrieve the list of currently loaded libraries
26278 through memory operations, so it uses the @samp{qXfer:libraries:read}
26279 packet (@pxref{qXfer library list read}) instead. The remote stub
26280 queries the target's operating system and reports which libraries
26281 are loaded.
26282
26283 The @samp{qXfer:libraries:read} packet returns an XML document which
26284 lists loaded libraries and their offsets. Each library has an
26285 associated name and one or more segment base addresses, which report
26286 where the library was loaded in memory. The segment bases are start
26287 addresses, not relocation offsets; they do not depend on the library's
26288 link-time base addresses.
26289
26290 @value{GDBN} must be linked with the Expat library to support XML
26291 library lists. @xref{Expat}.
26292
26293 A simple memory map, with one loaded library relocated by a single
26294 offset, looks like this:
26295
26296 @smallexample
26297 <library-list>
26298 <library name="/lib/libc.so.6">
26299 <segment address="0x10000000"/>
26300 </library>
26301 </library-list>
26302 @end smallexample
26303
26304 The format of a library list is described by this DTD:
26305
26306 @smallexample
26307 <!-- library-list: Root element with versioning -->
26308 <!ELEMENT library-list (library)*>
26309 <!ATTLIST library-list version CDATA #FIXED "1.0">
26310 <!ELEMENT library (segment)*>
26311 <!ATTLIST library name CDATA #REQUIRED>
26312 <!ELEMENT segment EMPTY>
26313 <!ATTLIST segment address CDATA #REQUIRED>
26314 @end smallexample
26315
26316 @node Memory Map Format
26317 @section Memory Map Format
26318 @cindex memory map format
26319
26320 To be able to write into flash memory, @value{GDBN} needs to obtain a
26321 memory map from the target. This section describes the format of the
26322 memory map.
26323
26324 The memory map is obtained using the @samp{qXfer:memory-map:read}
26325 (@pxref{qXfer memory map read}) packet and is an XML document that
26326 lists memory regions.
26327
26328 @value{GDBN} must be linked with the Expat library to support XML
26329 memory maps. @xref{Expat}.
26330
26331 The top-level structure of the document is shown below:
26332
26333 @smallexample
26334 <?xml version="1.0"?>
26335 <!DOCTYPE memory-map
26336 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
26337 "http://sourceware.org/gdb/gdb-memory-map.dtd">
26338 <memory-map>
26339 region...
26340 </memory-map>
26341 @end smallexample
26342
26343 Each region can be either:
26344
26345 @itemize
26346
26347 @item
26348 A region of RAM starting at @var{addr} and extending for @var{length}
26349 bytes from there:
26350
26351 @smallexample
26352 <memory type="ram" start="@var{addr}" length="@var{length}"/>
26353 @end smallexample
26354
26355
26356 @item
26357 A region of read-only memory:
26358
26359 @smallexample
26360 <memory type="rom" start="@var{addr}" length="@var{length}"/>
26361 @end smallexample
26362
26363
26364 @item
26365 A region of flash memory, with erasure blocks @var{blocksize}
26366 bytes in length:
26367
26368 @smallexample
26369 <memory type="flash" start="@var{addr}" length="@var{length}">
26370 <property name="blocksize">@var{blocksize}</property>
26371 </memory>
26372 @end smallexample
26373
26374 @end itemize
26375
26376 Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
26377 by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
26378 packets to write to addresses in such ranges.
26379
26380 The formal DTD for memory map format is given below:
26381
26382 @smallexample
26383 <!-- ................................................... -->
26384 <!-- Memory Map XML DTD ................................ -->
26385 <!-- File: memory-map.dtd .............................. -->
26386 <!-- .................................... .............. -->
26387 <!-- memory-map.dtd -->
26388 <!-- memory-map: Root element with versioning -->
26389 <!ELEMENT memory-map (memory | property)>
26390 <!ATTLIST memory-map version CDATA #FIXED "1.0.0">
26391 <!ELEMENT memory (property)>
26392 <!-- memory: Specifies a memory region,
26393 and its type, or device. -->
26394 <!ATTLIST memory type CDATA #REQUIRED
26395 start CDATA #REQUIRED
26396 length CDATA #REQUIRED
26397 device CDATA #IMPLIED>
26398 <!-- property: Generic attribute tag -->
26399 <!ELEMENT property (#PCDATA | property)*>
26400 <!ATTLIST property name CDATA #REQUIRED>
26401 @end smallexample
26402
26403 @include agentexpr.texi
26404
26405 @node Target Descriptions
26406 @appendix Target Descriptions
26407 @cindex target descriptions
26408
26409 @strong{Warning:} target descriptions are still under active development,
26410 and the contents and format may change between @value{GDBN} releases.
26411 The format is expected to stabilize in the future.
26412
26413 One of the challenges of using @value{GDBN} to debug embedded systems
26414 is that there are so many minor variants of each processor
26415 architecture in use. It is common practice for vendors to start with
26416 a standard processor core --- ARM, PowerPC, or MIPS, for example ---
26417 and then make changes to adapt it to a particular market niche. Some
26418 architectures have hundreds of variants, available from dozens of
26419 vendors. This leads to a number of problems:
26420
26421 @itemize @bullet
26422 @item
26423 With so many different customized processors, it is difficult for
26424 the @value{GDBN} maintainers to keep up with the changes.
26425 @item
26426 Since individual variants may have short lifetimes or limited
26427 audiences, it may not be worthwhile to carry information about every
26428 variant in the @value{GDBN} source tree.
26429 @item
26430 When @value{GDBN} does support the architecture of the embedded system
26431 at hand, the task of finding the correct architecture name to give the
26432 @command{set architecture} command can be error-prone.
26433 @end itemize
26434
26435 To address these problems, the @value{GDBN} remote protocol allows a
26436 target system to not only identify itself to @value{GDBN}, but to
26437 actually describe its own features. This lets @value{GDBN} support
26438 processor variants it has never seen before --- to the extent that the
26439 descriptions are accurate, and that @value{GDBN} understands them.
26440
26441 @value{GDBN} must be linked with the Expat library to support XML
26442 target descriptions. @xref{Expat}.
26443
26444 @menu
26445 * Retrieving Descriptions:: How descriptions are fetched from a target.
26446 * Target Description Format:: The contents of a target description.
26447 * Predefined Target Types:: Standard types available for target
26448 descriptions.
26449 * Standard Target Features:: Features @value{GDBN} knows about.
26450 @end menu
26451
26452 @node Retrieving Descriptions
26453 @section Retrieving Descriptions
26454
26455 Target descriptions can be read from the target automatically, or
26456 specified by the user manually. The default behavior is to read the
26457 description from the target. @value{GDBN} retrieves it via the remote
26458 protocol using @samp{qXfer} requests (@pxref{General Query Packets,
26459 qXfer}). The @var{annex} in the @samp{qXfer} packet will be
26460 @samp{target.xml}. The contents of the @samp{target.xml} annex are an
26461 XML document, of the form described in @ref{Target Description
26462 Format}.
26463
26464 Alternatively, you can specify a file to read for the target description.
26465 If a file is set, the target will not be queried. The commands to
26466 specify a file are:
26467
26468 @table @code
26469 @cindex set tdesc filename
26470 @item set tdesc filename @var{path}
26471 Read the target description from @var{path}.
26472
26473 @cindex unset tdesc filename
26474 @item unset tdesc filename
26475 Do not read the XML target description from a file. @value{GDBN}
26476 will use the description supplied by the current target.
26477
26478 @cindex show tdesc filename
26479 @item show tdesc filename
26480 Show the filename to read for a target description, if any.
26481 @end table
26482
26483
26484 @node Target Description Format
26485 @section Target Description Format
26486 @cindex target descriptions, XML format
26487
26488 A target description annex is an @uref{http://www.w3.org/XML/, XML}
26489 document which complies with the Document Type Definition provided in
26490 the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
26491 means you can use generally available tools like @command{xmllint} to
26492 check that your feature descriptions are well-formed and valid.
26493 However, to help people unfamiliar with XML write descriptions for
26494 their targets, we also describe the grammar here.
26495
26496 Target descriptions can identify the architecture of the remote target
26497 and (for some architectures) provide information about custom register
26498 sets. @value{GDBN} can use this information to autoconfigure for your
26499 target, or to warn you if you connect to an unsupported target.
26500
26501 Here is a simple target description:
26502
26503 @smallexample
26504 <target version="1.0">
26505 <architecture>i386:x86-64</architecture>
26506 </target>
26507 @end smallexample
26508
26509 @noindent
26510 This minimal description only says that the target uses
26511 the x86-64 architecture.
26512
26513 A target description has the following overall form, with [ ] marking
26514 optional elements and @dots{} marking repeatable elements. The elements
26515 are explained further below.
26516
26517 @smallexample
26518 <?xml version="1.0"?>
26519 <!DOCTYPE target SYSTEM "gdb-target.dtd">
26520 <target version="1.0">
26521 @r{[}@var{architecture}@r{]}
26522 @r{[}@var{feature}@dots{}@r{]}
26523 </target>
26524 @end smallexample
26525
26526 @noindent
26527 The description is generally insensitive to whitespace and line
26528 breaks, under the usual common-sense rules. The XML version
26529 declaration and document type declaration can generally be omitted
26530 (@value{GDBN} does not require them), but specifying them may be
26531 useful for XML validation tools. The @samp{version} attribute for
26532 @samp{<target>} may also be omitted, but we recommend
26533 including it; if future versions of @value{GDBN} use an incompatible
26534 revision of @file{gdb-target.dtd}, they will detect and report
26535 the version mismatch.
26536
26537 @subsection Inclusion
26538 @cindex target descriptions, inclusion
26539 @cindex XInclude
26540 @ifnotinfo
26541 @cindex <xi:include>
26542 @end ifnotinfo
26543
26544 It can sometimes be valuable to split a target description up into
26545 several different annexes, either for organizational purposes, or to
26546 share files between different possible target descriptions. You can
26547 divide a description into multiple files by replacing any element of
26548 the target description with an inclusion directive of the form:
26549
26550 @smallexample
26551 <xi:include href="@var{document}"/>
26552 @end smallexample
26553
26554 @noindent
26555 When @value{GDBN} encounters an element of this form, it will retrieve
26556 the named XML @var{document}, and replace the inclusion directive with
26557 the contents of that document. If the current description was read
26558 using @samp{qXfer}, then so will be the included document;
26559 @var{document} will be interpreted as the name of an annex. If the
26560 current description was read from a file, @value{GDBN} will look for
26561 @var{document} as a file in the same directory where it found the
26562 original description.
26563
26564 @subsection Architecture
26565 @cindex <architecture>
26566
26567 An @samp{<architecture>} element has this form:
26568
26569 @smallexample
26570 <architecture>@var{arch}</architecture>
26571 @end smallexample
26572
26573 @var{arch} is an architecture name from the same selection
26574 accepted by @code{set architecture} (@pxref{Targets, ,Specifying a
26575 Debugging Target}).
26576
26577 @subsection Features
26578 @cindex <feature>
26579
26580 Each @samp{<feature>} describes some logical portion of the target
26581 system. Features are currently used to describe available CPU
26582 registers and the types of their contents. A @samp{<feature>} element
26583 has this form:
26584
26585 @smallexample
26586 <feature name="@var{name}">
26587 @r{[}@var{type}@dots{}@r{]}
26588 @var{reg}@dots{}
26589 </feature>
26590 @end smallexample
26591
26592 @noindent
26593 Each feature's name should be unique within the description. The name
26594 of a feature does not matter unless @value{GDBN} has some special
26595 knowledge of the contents of that feature; if it does, the feature
26596 should have its standard name. @xref{Standard Target Features}.
26597
26598 @subsection Types
26599
26600 Any register's value is a collection of bits which @value{GDBN} must
26601 interpret. The default interpretation is a two's complement integer,
26602 but other types can be requested by name in the register description.
26603 Some predefined types are provided by @value{GDBN} (@pxref{Predefined
26604 Target Types}), and the description can define additional composite types.
26605
26606 Each type element must have an @samp{id} attribute, which gives
26607 a unique (within the containing @samp{<feature>}) name to the type.
26608 Types must be defined before they are used.
26609
26610 @cindex <vector>
26611 Some targets offer vector registers, which can be treated as arrays
26612 of scalar elements. These types are written as @samp{<vector>} elements,
26613 specifying the array element type, @var{type}, and the number of elements,
26614 @var{count}:
26615
26616 @smallexample
26617 <vector id="@var{id}" type="@var{type}" count="@var{count}"/>
26618 @end smallexample
26619
26620 @cindex <union>
26621 If a register's value is usefully viewed in multiple ways, define it
26622 with a union type containing the useful representations. The
26623 @samp{<union>} element contains one or more @samp{<field>} elements,
26624 each of which has a @var{name} and a @var{type}:
26625
26626 @smallexample
26627 <union id="@var{id}">
26628 <field name="@var{name}" type="@var{type}"/>
26629 @dots{}
26630 </union>
26631 @end smallexample
26632
26633 @subsection Registers
26634 @cindex <reg>
26635
26636 Each register is represented as an element with this form:
26637
26638 @smallexample
26639 <reg name="@var{name}"
26640 bitsize="@var{size}"
26641 @r{[}regnum="@var{num}"@r{]}
26642 @r{[}save-restore="@var{save-restore}"@r{]}
26643 @r{[}type="@var{type}"@r{]}
26644 @r{[}group="@var{group}"@r{]}/>
26645 @end smallexample
26646
26647 @noindent
26648 The components are as follows:
26649
26650 @table @var
26651
26652 @item name
26653 The register's name; it must be unique within the target description.
26654
26655 @item bitsize
26656 The register's size, in bits.
26657
26658 @item regnum
26659 The register's number. If omitted, a register's number is one greater
26660 than that of the previous register (either in the current feature or in
26661 a preceeding feature); the first register in the target description
26662 defaults to zero. This register number is used to read or write
26663 the register; e.g.@: it is used in the remote @code{p} and @code{P}
26664 packets, and registers appear in the @code{g} and @code{G} packets
26665 in order of increasing register number.
26666
26667 @item save-restore
26668 Whether the register should be preserved across inferior function
26669 calls; this must be either @code{yes} or @code{no}. The default is
26670 @code{yes}, which is appropriate for most registers except for
26671 some system control registers; this is not related to the target's
26672 ABI.
26673
26674 @item type
26675 The type of the register. @var{type} may be a predefined type, a type
26676 defined in the current feature, or one of the special types @code{int}
26677 and @code{float}. @code{int} is an integer type of the correct size
26678 for @var{bitsize}, and @code{float} is a floating point type (in the
26679 architecture's normal floating point format) of the correct size for
26680 @var{bitsize}. The default is @code{int}.
26681
26682 @item group
26683 The register group to which this register belongs. @var{group} must
26684 be either @code{general}, @code{float}, or @code{vector}. If no
26685 @var{group} is specified, @value{GDBN} will not display the register
26686 in @code{info registers}.
26687
26688 @end table
26689
26690 @node Predefined Target Types
26691 @section Predefined Target Types
26692 @cindex target descriptions, predefined types
26693
26694 Type definitions in the self-description can build up composite types
26695 from basic building blocks, but can not define fundamental types. Instead,
26696 standard identifiers are provided by @value{GDBN} for the fundamental
26697 types. The currently supported types are:
26698
26699 @table @code
26700
26701 @item int8
26702 @itemx int16
26703 @itemx int32
26704 @itemx int64
26705 @itemx int128
26706 Signed integer types holding the specified number of bits.
26707
26708 @item uint8
26709 @itemx uint16
26710 @itemx uint32
26711 @itemx uint64
26712 @itemx uint128
26713 Unsigned integer types holding the specified number of bits.
26714
26715 @item code_ptr
26716 @itemx data_ptr
26717 Pointers to unspecified code and data. The program counter and
26718 any dedicated return address register may be marked as code
26719 pointers; printing a code pointer converts it into a symbolic
26720 address. The stack pointer and any dedicated address registers
26721 may be marked as data pointers.
26722
26723 @item ieee_single
26724 Single precision IEEE floating point.
26725
26726 @item ieee_double
26727 Double precision IEEE floating point.
26728
26729 @item arm_fpa_ext
26730 The 12-byte extended precision format used by ARM FPA registers.
26731
26732 @end table
26733
26734 @node Standard Target Features
26735 @section Standard Target Features
26736 @cindex target descriptions, standard features
26737
26738 A target description must contain either no registers or all the
26739 target's registers. If the description contains no registers, then
26740 @value{GDBN} will assume a default register layout, selected based on
26741 the architecture. If the description contains any registers, the
26742 default layout will not be used; the standard registers must be
26743 described in the target description, in such a way that @value{GDBN}
26744 can recognize them.
26745
26746 This is accomplished by giving specific names to feature elements
26747 which contain standard registers. @value{GDBN} will look for features
26748 with those names and verify that they contain the expected registers;
26749 if any known feature is missing required registers, or if any required
26750 feature is missing, @value{GDBN} will reject the target
26751 description. You can add additional registers to any of the
26752 standard features --- @value{GDBN} will display them just as if
26753 they were added to an unrecognized feature.
26754
26755 This section lists the known features and their expected contents.
26756 Sample XML documents for these features are included in the
26757 @value{GDBN} source tree, in the directory @file{gdb/features}.
26758
26759 Names recognized by @value{GDBN} should include the name of the
26760 company or organization which selected the name, and the overall
26761 architecture to which the feature applies; so e.g.@: the feature
26762 containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
26763
26764 The names of registers are not case sensitive for the purpose
26765 of recognizing standard features, but @value{GDBN} will only display
26766 registers using the capitalization used in the description.
26767
26768 @menu
26769 * ARM Features::
26770 * M68K Features::
26771 @end menu
26772
26773
26774 @node ARM Features
26775 @subsection ARM Features
26776 @cindex target descriptions, ARM features
26777
26778 The @samp{org.gnu.gdb.arm.core} feature is required for ARM targets.
26779 It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
26780 @samp{lr}, @samp{pc}, and @samp{cpsr}.
26781
26782 The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
26783 should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
26784
26785 The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
26786 it should contain at least registers @samp{wR0} through @samp{wR15} and
26787 @samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
26788 @samp{wCSSF}, and @samp{wCASF} registers are optional.
26789
26790 @subsection MIPS Features
26791 @cindex target descriptions, MIPS features
26792
26793 The @samp{org.gnu.gdb.mips.cpu} feature is required for MIPS targets.
26794 It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
26795 @samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
26796 on the target.
26797
26798 The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
26799 contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
26800 registers. They may be 32-bit or 64-bit depending on the target.
26801
26802 The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
26803 it may be optional in a future version of @value{GDBN}. It should
26804 contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
26805 @samp{fir}. They may be 32-bit or 64-bit depending on the target.
26806
26807 The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
26808 contain a single register, @samp{restart}, which is used by the
26809 Linux kernel to control restartable syscalls.
26810
26811 @node M68K Features
26812 @subsection M68K Features
26813 @cindex target descriptions, M68K features
26814
26815 @table @code
26816 @item @samp{org.gnu.gdb.m68k.core}
26817 @itemx @samp{org.gnu.gdb.coldfire.core}
26818 @itemx @samp{org.gnu.gdb.fido.core}
26819 One of those features must be always present.
26820 The feature that is present determines which flavor of m86k is
26821 used. The feature that is present should contain registers
26822 @samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
26823 @samp{sp}, @samp{ps} and @samp{pc}.
26824
26825 @item @samp{org.gnu.gdb.coldfire.fp}
26826 This feature is optional. If present, it should contain registers
26827 @samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
26828 @samp{fpiaddr}.
26829 @end table
26830
26831 @subsection PowerPC Features
26832 @cindex target descriptions, PowerPC features
26833
26834 The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
26835 targets. It should contain registers @samp{r0} through @samp{r31},
26836 @samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
26837 @samp{xer}. They may be 32-bit or 64-bit depending on the target.
26838
26839 The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
26840 contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
26841
26842 The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
26843 contain registers @samp{vr0} through @samp{vr31}, @samp{vscr},
26844 and @samp{vrsave}.
26845
26846 The @samp{org.gnu.gdb.power.spe} feature is optional. It should
26847 contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
26848 @samp{spefscr}. SPE targets should provide 32-bit registers in
26849 @samp{org.gnu.gdb.power.core} and provide the upper halves in
26850 @samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
26851 these to present registers @samp{ev0} through @samp{ev31} to the
26852 user.
26853
26854 @include gpl.texi
26855
26856 @raisesections
26857 @include fdl.texi
26858 @lowersections
26859
26860 @node Index
26861 @unnumbered Index
26862
26863 @printindex cp
26864
26865 @tex
26866 % I think something like @colophon should be in texinfo. In the
26867 % meantime:
26868 \long\def\colophon{\hbox to0pt{}\vfill
26869 \centerline{The body of this manual is set in}
26870 \centerline{\fontname\tenrm,}
26871 \centerline{with headings in {\bf\fontname\tenbf}}
26872 \centerline{and examples in {\tt\fontname\tentt}.}
26873 \centerline{{\it\fontname\tenit\/},}
26874 \centerline{{\bf\fontname\tenbf}, and}
26875 \centerline{{\sl\fontname\tensl\/}}
26876 \centerline{are used for emphasis.}\vfill}
26877 \page\colophon
26878 % Blame: doc@cygnus.com, 1991.
26879 @end tex
26880
26881 @bye
This page took 0.557168 seconds and 5 git commands to generate.